Java Reference
In-Depth Information
optional attributes can be added by sending to the CLEmitter instance one of the following
messages:
publicvoidaddMethodAttribute(CLAttributeInfoattribute)
publicvoidaddFieldAttribute(CLAttributeInfoattribute)
publicvoidaddClassAttribute(CLAttributeInfoattribute)
publicvoidaddCodeAttribute(CLAttributeInfoattribute)
Note that for adding optional attributes, you need access to the constant pool table,
which the CLEmitter exposes through its constantPool() method, and also the program
counter pc , which it exposes through its pc() method. The abstractions for all the attributes
(code, method, field, and class) are defined in the CLAttributeInfo class.
Checking for Errors
The caller, at any point during the creation of the class, can check if there was an error, by
sending to the CLEmitter the following message:
publicbooleanerrorHasOccurred()
Write Class File
The in-memory representation of the class can be written to the file system by sending to
the CLEmitter instance the following message:
publicvoidwrite()
The destination directory for the class is either the default (current) directory or the one
specified by invoking destinationDir(StringdestDir) method. If the class specifies a
package, then the class will be written to the directory obtained by appending the package
information to the destination directory.
Alternatively, the representation can be converted to java.lang.Class representation
in memory by sending to the CLEmitter instance the following message:
publicClasstoClass()
D.5 JVM Instruction Set
The instructions supported by the JVM can be categorized into various groups: object,
field, method, array, arithmetic, bit, comparison, conversion, flow control, load and store,
and stack instructions. In this section, we provide a brief summary of the instructions
belonging to each group. The summary includes the mnemonic 11 for the instruction, a one-
line description of what the instruction does, and how the instruction affects the operand
stack. For each set of instructions, we also specify the CLEmitter method to invoke while
generating class files, to add instructions from that set to the code section of methods.
For each instruction, we represent the operand stack as follows:
;value1;value2 ) ;result
which means that the instruction begins by having value2 on top of the operand stack with
11 These mnemonics (symbolic opcodes) are defined in jminusminus.CLConstants .
 
Search WWH ::




Custom Search