Interface CodeBuilder
- All Superinterfaces:
ClassFileBuilder<CodeElement, CodeBuilder>, Consumer<CodeElement>
- All Known Subinterfaces:
CodeBuilder.BlockCodeBuilder
public sealed interface CodeBuilder extends ClassFileBuilder<CodeElement, CodeBuilder> permits CodeBuilder.BlockCodeBuilder (not exhaustive)
Code attributes (method bodies). MethodBuilder.withCode(Consumer) is the basic way to obtain a code builder; ClassBuilder.withMethodBody(Utf8Entry, Utf8Entry, int, Consumer) is a shortcut. There are also derived code builders from block(Consumer), which handles code blocks and transforming(CodeTransform, Consumer), which runs transforms on existing handlers, both of which requires a code builder to be available first. Refer to ClassFileBuilder for general guidance and caution around the use of builders for structures in the class file format. Unlike in other builders, the order of member elements in a code builder is significant: they affect the resulting bytecode. Many Class-File API options affect code builders: ClassFile.DeadCodeOption and ClassFile.ShortJumpsOption affect the resulting bytecode, and ClassFile.DeadLabelsOption, ClassFile.DebugElementsOption, ClassFile.LineNumbersOption, ClassFile.StackMapsOption, and ClassFile.AttributesProcessingOption affect the resulting attributes on the built Code attribute, that some elements sent to a code builder is otherwise ignored.
Instruction Factories
CodeBuilder provides convenience methods to create instructions (See JVMS §6.5 Instructions) by their mnemonic, taking necessary operands. - Instructions that encode their operands in their opcode, such as
aload_<n>, share their factories with their generic version likeaload. Note that some constant instructions, such asiconst_1, do not have generic versions, and thus have their own factories. - Instructions that accept wide operands, such as
ldc2_worwide, share their factories with their regular version likeldc(ConstantDesc). Note thatgoto_whas its own factory to avoid short jumps. - The
goto,instanceof,new, andreturninstructions' factories are namedgoto_,instanceOf,new_, andreturn_respectively, due to clashes with keywords in the Java programming language. - Factories are not provided for instructions
jsr,jsr_w,ret, andwide ret, which cannot appear in class files with major version 51 or higher. (JVMS §4.9.1) They can still be provided viaClassFileBuilder.with(E).
- Since:
- 24
- See Also:
Nested Class Summary
| Modifier and Type | Interface | Description |
|---|---|---|
static interface |
CodeBuilder.BlockCodeBuilder |
A builder for blocks of code. |
static interface |
CodeBuilder.CatchBuilder |
A builder to add catch blocks. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
default CodeBuilder |
aaload() |
Generates an instruction to load from a reference array. |
default CodeBuilder |
aastore() |
Generates an instruction to store into a reference array. |
default CodeBuilder |
aconst_null() |
Generates an instruction pushing the null object reference onto the operand stack. |
int |
allocateLocal |
Returns the local variable slot of a fresh local variable. |
default CodeBuilder |
aload |
Generates an instruction to load a reference from a local variable. |
default CodeBuilder |
anewarray |
Generates an instruction to create a new array of reference. |
default CodeBuilder |
anewarray |
Generates an instruction to create a new array of reference. |
default CodeBuilder |
areturn() |
Generates an instruction to return a reference from this method. |
default CodeBuilder |
arraylength() |
Generates an instruction to get the length of an array. |
default CodeBuilder |
arrayLoad |
Generates an instruction to load from an array. |
default CodeBuilder |
arrayStore |
Generates an instruction to store into an array. |
default CodeBuilder |
astore |
Generates an instruction to store a reference into a local variable. |
default CodeBuilder |
athrow() |
Generates an instruction to throw an exception or error. |
default CodeBuilder |
baload() |
|
default CodeBuilder |
bastore() |
|
default CodeBuilder |
bipush |
|
default CodeBuilder |
block |
Adds a lexical block to the method being built. |
default CodeBuilder |
branch |
Generates a branch instruction. |
default CodeBuilder |
caload() |
Generates an instruction to load from a char array. |
default CodeBuilder |
castore() |
Generates an instruction to store into a char array. |
default CodeBuilder |
characterRange |
Declares a character range entry. |
default CodeBuilder |
checkcast |
Generates an instruction to check whether an object is of the given type, throwing a ClassCastException if the check fails. |
default CodeBuilder |
checkcast |
Generates an instruction to check whether an object is of the given type, throwing a ClassCastException if the check fails. |
default CodeBuilder |
conversion |
Generates instruction(s) to convert fromType to toType. |
default CodeBuilder |
d2f() |
|
default CodeBuilder |
d2i() |
|
default CodeBuilder |
d2l() |
|
default CodeBuilder |
dadd() |
Generates an instruction to add two doubles. |
default CodeBuilder |
daload() |
Generates an instruction to load from a double array. |
default CodeBuilder |
dastore() |
Generates an instruction to store into a double array. |
default CodeBuilder |
dcmpg() |
|
default CodeBuilder |
dcmpl() |
|
default CodeBuilder |
dconst_0() |
Generates an instruction pushing double constant 0 onto the operand stack. |
default CodeBuilder |
dconst_1() |
Generates an instruction pushing double constant 1 onto the operand stack. |
default CodeBuilder |
ddiv() |
Generates an instruction to divide doubles. |
default CodeBuilder |
dload |
Generates an instruction to load a double from a local variable. |
default CodeBuilder |
dmul() |
Generates an instruction to multiply doubles. |
default CodeBuilder |
dneg() |
Generates an instruction to negate a double. |
default CodeBuilder |
drem() |
Generates an instruction to calculate double remainder. |
default CodeBuilder |
dreturn() |
Generates an instruction to return a double from this method. |
default CodeBuilder |
dstore |
Generates an instruction to store a double into a local variable. |
default CodeBuilder |
dsub() |
Generates an instruction to subtract doubles. |
default CodeBuilder |
dup() |
Generates an instruction to duplicate the top operand stack value. |
default CodeBuilder |
dup_x1() |
Generates an instruction to duplicate the top operand stack value and insert two values down. |
default CodeBuilder |
dup_x2() |
Generates an instruction to duplicate the top operand stack value and insert two or three values down. |
default CodeBuilder |
dup2() |
Generates an instruction to duplicate the top one or two operand stack value. |
default CodeBuilder |
dup2_x1() |
Generates an instruction to duplicate the top one or two operand stack values and insert two or three values down. |
default CodeBuilder |
dup2_x2() |
Generates an instruction to duplicate the top one or two operand stack values and insert two, three, or four values down. |
Label |
endLabel() |
Returns the label associated with the end of the current block. |
default CodeBuilder |
exceptionCatch |
Declares an exception table entry. |
default CodeBuilder |
exceptionCatch |
Declares an exception table entry. |
default CodeBuilder |
exceptionCatch |
Declares an exception table entry. |
default CodeBuilder |
exceptionCatchAll |
Declares an exception table entry catching all exceptions and errors. |
default CodeBuilder |
f2d() |
|
default CodeBuilder |
f2i() |
|
default CodeBuilder |
f2l() |
|
default CodeBuilder |
fadd() |
Generates an instruction to add two floats. |
default CodeBuilder |
faload() |
Generates an instruction to load from a float array. |
default CodeBuilder |
fastore() |
Generates an instruction to store into a float array. |
default CodeBuilder |
fcmpg() |
|
default CodeBuilder |
fcmpl() |
|
default CodeBuilder |
fconst_0() |
Generates an instruction pushing float constant 0 onto the operand stack. |
default CodeBuilder |
fconst_1() |
Generates an instruction pushing float constant 1 onto the operand stack. |
default CodeBuilder |
fconst_2() |
Generates an instruction pushing float constant 2 onto the operand stack. |
default CodeBuilder |
fdiv() |
Generates an instruction to divide floats. |
default CodeBuilder |
fieldAccess |
Generates an instruction to access a field. |
default CodeBuilder |
fieldAccess |
Generates an instruction to access a field. |
default CodeBuilder |
fload |
Generates an instruction to load a float from a local variable. |
default CodeBuilder |
fmul() |
Generates an instruction to multiply floats. |
default CodeBuilder |
fneg() |
Generates an instruction to negate a float. |
default CodeBuilder |
frem() |
Generates an instruction to calculate floats remainder. |
default CodeBuilder |
freturn() |
Generates an instruction to return a float from this method. |
default CodeBuilder |
fstore |
Generates an instruction to store a float into a local variable. |
default CodeBuilder |
fsub() |
Generates an instruction to subtract floats. |
default CodeBuilder |
getfield |
Generates an instruction to fetch field from an object. |
default CodeBuilder |
getfield |
Generates an instruction to fetch field from an object. |
default CodeBuilder |
getstatic |
Generates an instruction to get static field from a class or interface. |
default CodeBuilder |
getstatic |
Generates an instruction to get static field from a class or interface. |
default CodeBuilder |
goto_ |
Generates an instruction to branch always. |
default CodeBuilder |
goto_w |
Generates an instruction to branch always with wide index. |
default CodeBuilder |
i2b() |
|
default CodeBuilder |
i2c() |
|
default CodeBuilder |
i2d() |
|
default CodeBuilder |
i2f() |
|
default CodeBuilder |
i2l() |
|
default CodeBuilder |
i2s() |
|
default CodeBuilder |
iadd() |
Generates an instruction to add two ints. |
default CodeBuilder |
iaload() |
Generates an instruction to load from an int array. |
default CodeBuilder |
iand() |
|
default CodeBuilder |
iastore() |
Generates an instruction to store into an int array. |
default CodeBuilder |
iconst_0() |
Generates an instruction pushing int constant 0 onto the operand stack. |
default CodeBuilder |
iconst_1() |
Generates an instruction pushing int constant 1 onto the operand stack. |
default CodeBuilder |
iconst_2() |
Generates an instruction pushing int constant 2 onto the operand stack. |
default CodeBuilder |
iconst_3() |
Generates an instruction pushing int constant 3 onto the operand stack. |
default CodeBuilder |
iconst_4() |
Generates an instruction pushing int constant 4 onto the operand stack. |
default CodeBuilder |
iconst_5() |
Generates an instruction pushing int constant 5 onto the operand stack. |
default CodeBuilder |
iconst_m1() |
Generates an instruction pushing int constant -1 onto the operand stack. |
default CodeBuilder |
idiv() |
Generates an instruction to divide ints. |
default CodeBuilder |
if_acmpeq |
Generates an instruction to branch if reference comparison operand1 == operand2 succeeds. |
default CodeBuilder |
if_acmpne |
Generates an instruction to branch if reference comparison operand1 != operand2 succeeds. |
default CodeBuilder |
if_icmpeq |
Generates an instruction to branch if int comparison operand1 == operand2 succeeds. |
default CodeBuilder |
if_icmpge |
Generates an instruction to branch if int comparison operand1 >= operand2 succeeds. |
default CodeBuilder |
if_icmpgt |
Generates an instruction to branch if int comparison operand1 > operand2 succeeds. |
default CodeBuilder |
if_icmple |
Generates an instruction to branch if int comparison operand1 <= operand2 succeeds. |
default CodeBuilder |
if_icmplt |
Generates an instruction to branch if int comparison operand1 < operand2 succeeds. |
default CodeBuilder |
if_icmpne |
Generates an instruction to branch if int comparison operand1 != operand2 succeeds. |
default CodeBuilder |
ifeq |
Generates an instruction to branch if int comparison with zero == 0 succeeds. |
default CodeBuilder |
ifge |
Generates an instruction to branch if int comparison with zero >= 0 succeeds. |
default CodeBuilder |
ifgt |
Generates an instruction to branch if int comparison with zero > 0 succeeds. |
default CodeBuilder |
ifle |
Generates an instruction to branch if int comparison with zero <= 0 succeeds. |
default CodeBuilder |
iflt |
Generates an instruction to branch if int comparison with zero < 0 succeeds. |
default CodeBuilder |
ifne |
Generates an instruction to branch if int comparison with zero != 0 succeeds. |
default CodeBuilder |
ifnonnull |
Generates an instruction to branch if reference is not null. |
default CodeBuilder |
ifnull |
Generates an instruction to branch if reference is null. |
default CodeBuilder |
ifThen |
Adds an "if-then" block that is conditional on the value(s) on top of the operand stack in accordance with the given opcode. |
default CodeBuilder |
ifThen |
Adds an "if-then" block that is conditional on the boolean value on top of the operand stack. |
default CodeBuilder |
ifThenElse |
Adds an "if-then-else" block that is conditional on the value(s) on top of the operand stack in accordance with the given opcode. |
default CodeBuilder |
ifThenElse |
Adds an "if-then-else" block that is conditional on the boolean value on top of the operand stack. |
default CodeBuilder |
iinc |
Generates an instruction to increment an int local variable by a constant. |
default CodeBuilder |
iload |
Generates an instruction to load an int from a local variable. |
default CodeBuilder |
imul() |
Generates an instruction to multiply ints. |
default CodeBuilder |
ineg() |
Generates an instruction to negate an int. |
default CodeBuilder |
instanceOf |
Generates an instruction to determine if an object is of the given type, producing a boolean result on the operand stack. |
default CodeBuilder |
instanceOf |
Generates an instruction to determine if an object is of the given type, producing a boolean result on the operand stack. |
default CodeBuilder |
invoke |
Generates an instruction to invoke a method. |
default CodeBuilder |
invoke |
Generates an instruction to invoke a method. |
default CodeBuilder |
invokedynamic |
Generates an instruction to invoke a dynamically-computed call site. |
default CodeBuilder |
invokedynamic |
Generates an instruction to invoke a dynamically-computed call site. |
default CodeBuilder |
invokeinterface |
Generates an instruction to invoke an interface method. |
default CodeBuilder |
invokeinterface |
Generates an instruction to invoke an interface method. |
default CodeBuilder |
invokespecial |
Generates an instruction to invoke an instance method in an interface; direct invocation of methods of the current class and its supertypes. |
default CodeBuilder |
invokespecial |
Generates an instruction to invoke an instance method in a class; direct invocation of instance initialization methods and methods of the current class and its supertypes. |
default CodeBuilder |
invokespecial |
Generates an instruction to invoke an instance method in a class; direct invocation of instance initialization methods and methods of the current class and its supertypes. |
default CodeBuilder |
invokespecial |
Generates an instruction to invoke an instance method; direct invocation of instance initialization methods and methods of the current class and its supertypes. |
default CodeBuilder |
invokestatic |
Generates an instruction to invoke a class (static) method of an interface. |
default CodeBuilder |
invokestatic |
Generates an instruction to invoke a class (static) method of a class. |
default CodeBuilder |
invokestatic |
Generates an instruction to invoke a class (static) method of a class. |
default CodeBuilder |
invokestatic |
Generates an instruction to invoke a class (static) method. |
default CodeBuilder |
invokevirtual |
Generates an instruction to invoke an instance method; dispatch based on class. |
default CodeBuilder |
invokevirtual |
Generates an instruction to invoke an instance method; dispatch based on class. |
default CodeBuilder |
ior() |
|
default CodeBuilder |
irem() |
Generates an instruction to calculate ints remainder. |
default CodeBuilder |
ireturn() |
Generates an instruction to return an int from this method. |
default CodeBuilder |
ishl() |
Generates an instruction to shift an int left. |
default CodeBuilder |
ishr() |
Generates an instruction to shift an int right. |
default CodeBuilder |
istore |
Generates an instruction to store an int into a local variable. |
default CodeBuilder |
isub() |
Generates an instruction to subtract ints. |
default CodeBuilder |
iushr() |
Generates an instruction to logical shift an int right. |
default CodeBuilder |
ixor() |
Generates an instruction to calculate bitwise XOR of ints. |
default CodeBuilder |
l2d() |
|
default CodeBuilder |
l2f() |
|
default CodeBuilder |
l2i() |
|
default CodeBuilder |
labelBinding |
Binds a label to the current position. |
default CodeBuilder |
ladd() |
Generates an instruction to add two longs. |
default CodeBuilder |
laload() |
Generates an instruction to load from a long array. |
default CodeBuilder |
land() |
Generates an instruction to calculate bitwise AND of longs. |
default CodeBuilder |
lastore() |
Generates an instruction to store into a long array. |
default CodeBuilder |
lcmp() |
Generates an instruction to compare longs. |
default CodeBuilder |
lconst_0() |
Generates an instruction pushing long constant 0 onto the operand stack. |
default CodeBuilder |
lconst_1() |
Generates an instruction pushing long constant 1 onto the operand stack. |
default CodeBuilder |
ldc |
Generates an instruction pushing an item from the run-time constant pool onto the operand stack. |
default CodeBuilder |
ldc |
Generates an instruction pushing an item from the run-time constant pool onto the operand stack. |
default CodeBuilder |
ldiv() |
Generates an instruction to divide longs. |
default CodeBuilder |
lineNumber |
Declares a source line number beginning at the current position. |
default CodeBuilder |
lload |
Generates an instruction to load a long from a local variable. |
default CodeBuilder |
lmul() |
Generates an instruction to multiply longs. |
default CodeBuilder |
lneg() |
Generates an instruction to negate a long. |
default CodeBuilder |
loadConstant |
Generates an instruction pushing a constant double value onto the operand stack. |
default CodeBuilder |
loadConstant |
Generates an instruction pushing a constant float value onto the operand stack. |
default CodeBuilder |
loadConstant |
Generates an instruction pushing a constant int value onto the operand stack. |
default CodeBuilder |
loadConstant |
Generates an instruction pushing a constant long value onto the operand stack. |
default CodeBuilder |
loadConstant |
Generates an instruction pushing a constant onto the operand stack. |
default CodeBuilder |
loadLocal |
Generates an instruction to load a value from a local variable. |
default CodeBuilder |
localVariable |
Declares a local variable entry. |
default CodeBuilder |
localVariable |
Declares a local variable entry. |
default CodeBuilder |
localVariableType |
Declares a local variable type entry. |
default CodeBuilder |
localVariableType |
Declares a local variable type entry. |
default CodeBuilder |
lookupswitch |
Generates an instruction to access a jump table by key match and jump. |
default CodeBuilder |
lor() |
Generates an instruction to calculate bitwise OR of longs. |
default CodeBuilder |
lrem() |
Generates an instruction to calculate longs remainder. |
default CodeBuilder |
lreturn() |
Generates an instruction to return a long from this method. |
default CodeBuilder |
lshl() |
Generates an instruction to shift a long left. |
default CodeBuilder |
lshr() |
Generates an instruction to shift a long right. |
default CodeBuilder |
lstore |
Generates an instruction to store a long into a local variable. |
default CodeBuilder |
lsub() |
Generates an instruction to subtract longs. |
default CodeBuilder |
lushr() |
Generates an instruction to logical shift a long right. |
default CodeBuilder |
lxor() |
Generates an instruction to calculate bitwise XOR of longs. |
default CodeBuilder |
monitorenter() |
Generates an instruction to enter monitor for an object. |
default CodeBuilder |
monitorexit() |
Generates an instruction to exit monitor for an object. |
default CodeBuilder |
multianewarray |
Generates an instruction to create a new multidimensional array. |
default CodeBuilder |
multianewarray |
Generates an instruction to create a new multidimensional array. |
default CodeBuilder |
new_ |
Generates an instruction to create a new object. |
default CodeBuilder |
new_ |
Generates an instruction to create a new object. |
default CodeBuilder |
newarray |
Generates an instruction to create a new array of a primitive type. |
default Label |
newBoundLabel() |
Creates a new label bound at the current position. |
Label |
newLabel() |
Returns a fresh unbound label. |
default CodeBuilder |
nop() |
Generates a do-nothing instruction. |
int |
parameterSlot |
Returns the local variable slot associated with the specified parameter. |
default CodeBuilder |
pop() |
Generates an instruction to pop the top operand stack value. |
default CodeBuilder |
pop2() |
Generates an instruction to pop the top one or two operand stack values. |
default CodeBuilder |
putfield |
Generates an instruction to set field in an object. |
default CodeBuilder |
putfield |
Generates an instruction to set field in an object. |
default CodeBuilder |
putstatic |
Generates an instruction to set static field in a class. |
default CodeBuilder |
putstatic |
Generates an instruction to set static field in a class. |
int |
receiverSlot() |
Returns the local variable slot associated with the receiver. |
default CodeBuilder |
return_() |
Generates an instruction to return void from this method. |
default CodeBuilder |
return_ |
Generates a return instruction. |
default CodeBuilder |
saload() |
Generates an instruction to load from a short array. |
default CodeBuilder |
sastore() |
Generates an instruction to store into a short array. |
default CodeBuilder |
sipush |
|
Label |
startLabel() |
Returns the label associated with the beginning of the current block. |
default CodeBuilder |
storeLocal |
Generates an instruction to store a value to a local variable. |
default CodeBuilder |
swap() |
Generates an instruction to swap the top two operand stack values. |
default CodeBuilder |
tableswitch |
Generates an instruction to access a jump table by index and jump. |
default CodeBuilder |
tableswitch |
Generates an instruction to access a jump table by index and jump. |
default CodeBuilder |
transforming |
Apply a transform to the code built by a handler, directing results to this builder. |
default CodeBuilder |
trying |
Adds a "try-catch" block comprising one try block and zero or more catch blocks. |
Methods declared in interface ClassFileBuilder
accept, constantPool, transform, with | Modifier and Type | Method | Description |
|---|---|---|
default void |
accept |
Integrates the member element into the structure being built. |
ConstantPoolBuilder |
constantPool() |
Returns the constant pool builder associated with this builder. |
default CodeBuilder |
transform |
Applies a transform to a compound structure, directing results to this builder. |
CodeBuilder |
with |
Integrates the member element into the structure being built. |
Methods declared in interface Consumer
andThen | Modifier and Type | Method | Description |
|---|---|---|
default Consumer |
andThen |
Returns a composed Consumer that performs, in sequence, this operation followed by the after operation. |
Method Details
newLabel
Label newLabel()
labelBinding(Label).- Returns:
- a fresh unbound label
startLabel
Label startLabel()
block(Consumer) or ifThenElse(Consumer, Consumer), the current block will be the entire method body.- Returns:
- the label associated with the beginning of the current block
endLabel
Label endLabel()
block(Consumer) or ifThenElse(Consumer, Consumer), the current block will be the entire method body.- Returns:
- the label associated with the end of the current block
receiverSlot
int receiverSlot()
- Returns:
- the local variable slot associated with the receiver
- Throws:
-
IllegalStateException- if this is a static method
parameterSlot
int parameterSlot(int paramNo)
long and double values require two slots.- Parameters:
-
paramNo- the index of the parameter - Returns:
- the local variable slot associated with the specified parameter
- Throws:
-
IndexOutOfBoundsException- if the parameter index is out of bounds
allocateLocal
int allocateLocal(TypeKind typeKind)
maxLocals of the original method. For a method being built directly, fresh locals begin after the last parameter slot. If the current code builder is a CodeBuilder.BlockCodeBuilder, at the end of the block, locals are reset to their value at the beginning of the block.
- Parameters:
-
typeKind- the type of the local variable - Returns:
- the local variable slot of a fresh local variable
transforming
default CodeBuilder transforming(CodeTransform transform, Consumer<CodeBuilder> handler)
- API Note:
- This is similar to
ClassFileBuilder.transform(CompoundElement, ClassFileTransform), but this does not require the code elements to be viewed as aCodeModelfirst. - Parameters:
-
transform- the transform to apply to the code built by the handler -
handler- the handler that receives aCodeBuilderto build the code - Returns:
- this builder
block
default CodeBuilder block(Consumer<CodeBuilder.BlockCodeBuilder> handler)
Within this block, the startLabel() and endLabel() correspond to the start and end of the block, and the CodeBuilder.BlockCodeBuilder.breakLabel() also corresponds to the end of the block, or the cursor position immediately after this call in this builder.
- Parameters:
-
handler- handler that receives aCodeBuilder.BlockCodeBuilderto generate the body of the lexical block - Returns:
- this builder
ifThen
default CodeBuilder ifThen(Consumer<CodeBuilder.BlockCodeBuilder> thenHandler)
boolean value on top of the operand stack. Control flow enters the "then" block if the value represents true. The CodeBuilder.BlockCodeBuilder.breakLabel() for the "then" block corresponds to the cursor position immediately after this call in this builder.
- Parameters:
-
thenHandler- handler that receives a CodeBuilder.BlockCodeBuilder to generate the body of theif - Returns:
- this builder
- See Also:
ifThen
default CodeBuilder ifThen(Opcode opcode, Consumer<CodeBuilder.BlockCodeBuilder> thenHandler)
opcode succeeds. The CodeBuilder.BlockCodeBuilder.breakLabel() for the "then" block corresponds to the cursor position immediately after this call in this builder.
- Parameters:
-
opcode- the operation code for a branch instruction that accepts one or two operands on the stack -
thenHandler- handler that receives aCodeBuilder.BlockCodeBuilderto generate the body of theif - Returns:
- this builder
- Throws:
-
IllegalArgumentException- if the operation code is not for a branch instruction that accepts one or two operands
ifThenElse
default CodeBuilder ifThenElse(Consumer<CodeBuilder.BlockCodeBuilder> thenHandler, Consumer<CodeBuilder.BlockCodeBuilder> elseHandler)
boolean value on top of the operand stack. Control flow enters the "then" block if the value represents true, and enters the "else" block otherwise. The CodeBuilder.BlockCodeBuilder.breakLabel() for each block corresponds to the cursor position immediately after this call in this builder.
- Parameters:
-
thenHandler- handler that receives aCodeBuilder.BlockCodeBuilderto generate the body of theif -
elseHandler- handler that receives aCodeBuilder.BlockCodeBuilderto generate the body of theelse - Returns:
- this builder
- See Also:
ifThenElse
default CodeBuilder ifThenElse(Opcode opcode, Consumer<CodeBuilder.BlockCodeBuilder> thenHandler, Consumer<CodeBuilder.BlockCodeBuilder> elseHandler)
opcode succeeds, and enters the "else" block otherwise. The CodeBuilder.BlockCodeBuilder.breakLabel() for each block corresponds to the cursor position immediately after this call in this builder.
- Parameters:
-
opcode- the operation code for a branch instruction that accepts one or two operands on the stack -
thenHandler- handler that receives a CodeBuilder.BlockCodeBuilder to generate the body of theif -
elseHandler- handler that receives a CodeBuilder.BlockCodeBuilder to generate the body of theelse - Returns:
- this builder
- Throws:
-
IllegalArgumentException- if the operation code is not for a branch instruction that accepts one or two operands
trying
default CodeBuilder trying(Consumer<CodeBuilder.BlockCodeBuilder> tryHandler, Consumer<CodeBuilder.CatchBuilder> catchesHandler)
The CodeBuilder.BlockCodeBuilder.breakLabel() for the try block and all catch blocks in the catchesHandler correspond to the cursor position immediately after this call in this builder.
- Parameters:
-
tryHandler- handler that receives aCodeBuilder.BlockCodeBuilderto generate the body of the try block. -
catchesHandler- a handler that receives aCodeBuilder.CatchBuilderto generate bodies of catch blocks - Returns:
- this builder
- Throws:
-
IllegalArgumentException- if the try block is empty - See Also:
loadLocal
default CodeBuilder loadLocal(TypeKind tk, int slot)
- Parameters:
-
tk- the load type -
slot- the local variable slot - Returns:
- this builder
- Throws:
-
IllegalArgumentException- iftkisvoidorslotis notu2 - See Also:
storeLocal
default CodeBuilder storeLocal(TypeKind tk, int slot)
- Parameters:
-
tk- the store type -
slot- the local variable slot - Returns:
- this builder
- Throws:
-
IllegalArgumentException- iftkisvoidorslotis notu2 - See Also:
branch
default CodeBuilder branch(Opcode op, Label target)
This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set, the opcode has size 3, and target cannot be encoded as a BCI offset in [-32768, 32767].
- Parameters:
-
op- the branch opcode -
target- the branch target - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifopis not ofOpcode.Kind.BRANCH - See Also:
return_
default CodeBuilder return_(TypeKind tk)
- Parameters:
-
tk- the return type - Returns:
- this builder
- See Also:
fieldAccess
default CodeBuilder fieldAccess(Opcode opcode, FieldRefEntry ref)
- Parameters:
-
opcode- the field access opcode -
ref- the field reference - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifopcodeis not ofOpcode.Kind.FIELD_ACCESS - See Also:
fieldAccess
default CodeBuilder fieldAccess(Opcode opcode, ClassDesc owner, String name, ClassDesc type)
- Parameters:
-
opcode- the field access opcode -
owner- the class -
name- the field name -
type- the field type - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifopcodeis not ofOpcode.Kind.FIELD_ACCESS, orowneris primitive - See Also:
invoke
default CodeBuilder invoke(Opcode opcode, MemberRefEntry ref)
- Parameters:
-
opcode- the invoke opcode -
ref- the interface method or method reference - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifopcodeis not ofOpcode.Kind.INVOKE - See Also:
invoke
default CodeBuilder invoke(Opcode opcode, ClassDesc owner, String name, MethodTypeDesc desc, boolean isInterface)
- Parameters:
-
opcode- the invoke opcode -
owner- the class -
name- the method name -
desc- the method type -
isInterface- whether the owner class is an interface - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifopcodeis not ofOpcode.Kind.INVOKE, orowneris primitive - See Also:
arrayLoad
default CodeBuilder arrayLoad(TypeKind tk)
- Parameters:
-
tk- the array element type - Returns:
- this builder
- Throws:
-
IllegalArgumentException- iftkisvoid - See Also:
arrayStore
default CodeBuilder arrayStore(TypeKind tk)
- Parameters:
-
tk- the array element type - Returns:
- this builder
- Throws:
-
IllegalArgumentException- iftkisvoid - See Also:
conversion
default CodeBuilder conversion(TypeKind fromType, TypeKind toType)
fromType to toType.- Parameters:
-
fromType- the source type -
toType- the target type - Returns:
- this builder
- Throws:
-
IllegalArgumentException- for conversions ofvoidorreference - See Also:
loadConstant
default CodeBuilder loadConstant(ConstantDesc value)
- Parameters:
-
value- the constant value, may benull - Returns:
- this builder
- See Also:
loadConstant
default CodeBuilder loadConstant(int value)
int value onto the operand stack. This is equivalent to loadConstant(Integer.valueOf(value)).- Parameters:
-
value- the int value - Returns:
- this builder
- See Also:
loadConstant
default CodeBuilder loadConstant(long value)
long value onto the operand stack. This is equivalent to loadConstant(Long.valueOf(value)).- Parameters:
-
value- the long value - Returns:
- this builder
- See Also:
loadConstant
default CodeBuilder loadConstant(float value)
float value onto the operand stack. This is equivalent to loadConstant(Float.valueOf(value)). All NaN values of the float may or may not be collapsed into a single "canonical" NaN value.
- Parameters:
-
value- the float value - Returns:
- this builder
- See Also:
loadConstant
default CodeBuilder loadConstant(double value)
double value onto the operand stack. This is equivalent to loadConstant(Double.valueOf(value)). All NaN values of the double may or may not be collapsed into a single "canonical" NaN value.
- Parameters:
-
value- the double value - Returns:
- this builder
- See Also:
nop
default CodeBuilder nop()
- Returns:
- this builder
- See Also:
newBoundLabel
default Label newBoundLabel()
- Returns:
- this builder
- See Also:
labelBinding
default CodeBuilder labelBinding(Label label)
- API Note:
- The label to bind does not have to be from this builder; it can be from another parsed
CodeModel. - Parameters:
-
label- the label - Returns:
- this builder
- See Also:
lineNumber
default CodeBuilder lineNumber(int line)
This call may be ignored according to ClassFile.LineNumbersOption.
- Parameters:
-
line- the line number - Returns:
- this builder
- Throws:
-
IllegalArgumentException- iflineis notu2 - See Also:
exceptionCatch
default CodeBuilder exceptionCatch(Label start, Label end, Label handler, ClassEntry catchType)
This call may be ignored if any of the argument labels is not bound and ClassFile.DeadLabelsOption.DROP_DEAD_LABELS is set.
- Parameters:
-
start- the try block start -
end- the try block end -
handler- the exception handler start -
catchType- the catch type, may benullto catch all exceptions and errors - Returns:
- this builder
- See Also:
exceptionCatch
default CodeBuilder exceptionCatch(Label start, Label end, Label handler, Optional<ClassEntry> catchType)
This call may be ignored if any of the argument labels is not bound and ClassFile.DeadLabelsOption.DROP_DEAD_LABELS is set.
- Parameters:
-
start- the try block start -
end- the try block end -
handler- the exception handler start -
catchType- the optional catch type, empty to catch all exceptions and errors - Returns:
- this builder
- See Also:
exceptionCatch
default CodeBuilder exceptionCatch(Label start, Label end, Label handler, ClassDesc catchType)
This call may be ignored if any of the argument labels is not bound and ClassFile.DeadLabelsOption.DROP_DEAD_LABELS is set.
- Parameters:
-
start- the try block start -
end- the try block end -
handler- the exception handler start -
catchType- the catch type - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifcatchTypeis primitive - See Also:
exceptionCatchAll
default CodeBuilder exceptionCatchAll(Label start, Label end, Label handler)
This call may be ignored if any of the argument labels is not bound and ClassFile.DeadLabelsOption.DROP_DEAD_LABELS is set.
- Parameters:
-
start- the try block start -
end- the try block end -
handler- the exception handler start - Returns:
- this builder
- See Also:
characterRange
default CodeBuilder characterRange(Label startScope, Label endScope, int characterRangeStart, int characterRangeEnd, int flags)
This call may be ignored if ClassFile.DebugElementsOption.DROP_DEBUG is set, or if any of the argument labels is not bound and ClassFile.DeadLabelsOption.DROP_DEAD_LABELS is set.
- Parameters:
-
startScope- the start scope of the character range -
endScope- the end scope of the character range -
characterRangeStart- the encoded start of the character range region (inclusive) -
characterRangeEnd- the encoded end of the character range region (exclusive) -
flags- the flags word, indicating the kind of range - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifflagsis notu2 - See Also:
localVariable
default CodeBuilder localVariable(int slot, Utf8Entry nameEntry, Utf8Entry descriptorEntry, Label startScope, Label endScope)
This call may be ignored if ClassFile.DebugElementsOption.DROP_DEBUG is set, or if any of the argument labels is not bound and ClassFile.DeadLabelsOption.DROP_DEAD_LABELS is set.
- Parameters:
-
slot- the local variable slot -
nameEntry- the variable name -
descriptorEntry- the variable descriptor -
startScope- the start scope of the variable -
endScope- the end scope of the variable - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifslotis notu2 - See Also:
localVariable
default CodeBuilder localVariable(int slot, String name, ClassDesc descriptor, Label startScope, Label endScope)
This call may be ignored if ClassFile.DebugElementsOption.DROP_DEBUG is set, or if any of the argument labels is not bound and ClassFile.DeadLabelsOption.DROP_DEAD_LABELS is set.
- Parameters:
-
slot- the local variable slot -
name- the variable name -
descriptor- the variable descriptor -
startScope- the start scope of the variable -
endScope- the end scope of the variable - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifslotis notu2 - See Also:
localVariableType
default CodeBuilder localVariableType(int slot, Utf8Entry nameEntry, Utf8Entry signatureEntry, Label startScope, Label endScope)
This call may be ignored if ClassFile.DebugElementsOption.DROP_DEBUG is set, or if any of the argument labels is not bound and ClassFile.DeadLabelsOption.DROP_DEAD_LABELS is set.
- API Note:
- When a local variable type entry is declared, a local variable entry with the descriptor derived from erasure (JLS §4.6) of the signature should be declared as well.
- Parameters:
-
slot- the local variable slot -
nameEntry- the variable name -
signatureEntry- the variable signature -
startScope- the start scope of the variable -
endScope- the end scope of the variable - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifslotis notu2 - See Also:
localVariableType
default CodeBuilder localVariableType(int slot, String name, Signature signature, Label startScope, Label endScope)
This call may be ignored if ClassFile.DebugElementsOption.DROP_DEBUG is set, or if any of the argument labels is not bound and ClassFile.DeadLabelsOption.DROP_DEAD_LABELS is set.
- API Note:
- When a local variable type entry is declared, a local variable entry with the descriptor derived from erasure (JLS §4.6) of the signature should be declared as well.
- Parameters:
-
slot- the local variable slot -
name- the variable name -
signature- the variable signature -
startScope- the start scope of the variable -
endScope- the end scope of the variable - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifslotis notu2 - See Also:
aconst_null
default CodeBuilder aconst_null()
reference onto the operand stack.- Returns:
- this builder
- See Also:
aaload
default CodeBuilder aaload()
reference array.- Returns:
- this builder
- See Also:
aastore
default CodeBuilder aastore()
reference array.- Returns:
- this builder
- See Also:
aload
default CodeBuilder aload(int slot)
reference from a local variable. This may also generate aload_<N> and wide aload instructions.
- Parameters:
-
slot- the local variable slot - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifslotis notu2 - See Also:
anewarray
default CodeBuilder anewarray(ClassEntry classEntry)
reference.- Parameters:
-
classEntry- the component type - Returns:
- this builder
- See Also:
anewarray
default CodeBuilder anewarray(ClassDesc className)
reference.- Parameters:
-
className- the component type - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifclassNamerepresents a primitive type - See Also:
areturn
default CodeBuilder areturn()
reference from this method.- Returns:
- this builder
- See Also:
arraylength
default CodeBuilder arraylength()
- Returns:
- this builder
- See Also:
astore
default CodeBuilder astore(int slot)
reference into a local variable. Such an instruction can also store a returnAddress. This may also generate astore_<N> and wide astore instructions.
- Parameters:
-
slot- the local variable slot - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifslotis notu2 - See Also:
athrow
default CodeBuilder athrow()
- Returns:
- this builder
- See Also:
baload
bastore
bipush
default CodeBuilder bipush(int b)
- Parameters:
-
b- the int in the range of byte - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifbis out of range of byte - See Also:
caload
default CodeBuilder caload()
char array.- Returns:
- this builder
- See Also:
castore
default CodeBuilder castore()
char array.- Returns:
- this builder
- See Also:
checkcast
default CodeBuilder checkcast(ClassEntry type)
ClassCastException if the check fails.- Parameters:
-
type- the object type - Returns:
- this builder
- See Also:
checkcast
default CodeBuilder checkcast(ClassDesc type)
ClassCastException if the check fails.- Parameters:
-
type- the object type - Returns:
- this builder
- Throws:
-
IllegalArgumentException- iftyperepresents a primitive type - See Also:
d2f
d2i
d2l
dadd
default CodeBuilder dadd()
doubles.- Returns:
- this builder
- See Also:
daload
default CodeBuilder daload()
double array.- Returns:
- this builder
- See Also:
dastore
default CodeBuilder dastore()
double array.- Returns:
- this builder
- See Also:
dcmpg
dcmpl
dconst_0
default CodeBuilder dconst_0()
double constant 0 onto the operand stack.- Returns:
- this builder
- See Also:
dconst_1
default CodeBuilder dconst_1()
double constant 1 onto the operand stack.- Returns:
- this builder
- See Also:
ddiv
default CodeBuilder ddiv()
doubles.- Returns:
- this builder
- See Also:
dload
default CodeBuilder dload(int slot)
double from a local variable. This may also generate dload_<N> and wide dload instructions.
- Parameters:
-
slot- the local variable slot - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifslotis notu2 - See Also:
dmul
default CodeBuilder dmul()
doubles.- Returns:
- this builder
- See Also:
dneg
default CodeBuilder dneg()
double.- Returns:
- this builder
- See Also:
drem
default CodeBuilder drem()
double remainder.- Returns:
- this builder
- See Also:
dreturn
default CodeBuilder dreturn()
double from this method.- Returns:
- this builder
- See Also:
dstore
default CodeBuilder dstore(int slot)
double into a local variable. This may also generate dstore_<N> and wide dstore instructions.
- Parameters:
-
slot- the local variable slot - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifslotis notu2 - See Also:
dsub
default CodeBuilder dsub()
doubles.- Returns:
- this builder
- See Also:
dup
default CodeBuilder dup()
- Returns:
- this builder
- See Also:
dup2
default CodeBuilder dup2()
- Returns:
- this builder
- See Also:
dup2_x1
default CodeBuilder dup2_x1()
- Returns:
- this builder
- See Also:
dup2_x2
default CodeBuilder dup2_x2()
- Returns:
- this builder
- See Also:
dup_x1
default CodeBuilder dup_x1()
- Returns:
- this builder
- See Also:
dup_x2
default CodeBuilder dup_x2()
- Returns:
- this builder
- See Also:
f2d
f2i
f2l
fadd
default CodeBuilder fadd()
floats.- Returns:
- this builder
- See Also:
faload
default CodeBuilder faload()
float array.- Returns:
- this builder
- See Also:
fastore
default CodeBuilder fastore()
float array.- Returns:
- this builder
- See Also:
fcmpg
fcmpl
fconst_0
default CodeBuilder fconst_0()
float constant 0 onto the operand stack.- Returns:
- this builder
- See Also:
fconst_1
default CodeBuilder fconst_1()
float constant 1 onto the operand stack.- Returns:
- this builder
- See Also:
fconst_2
default CodeBuilder fconst_2()
float constant 2 onto the operand stack.- Returns:
- this builder
- See Also:
fdiv
default CodeBuilder fdiv()
floats.- Returns:
- this builder
- See Also:
fload
default CodeBuilder fload(int slot)
float from a local variable. This may also generate fload_<N> and wide fload instructions.
- Parameters:
-
slot- the local variable slot - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifslotis notu2 - See Also:
fmul
default CodeBuilder fmul()
floats.- Returns:
- this builder
- See Also:
fneg
default CodeBuilder fneg()
float.- Returns:
- this builder
- See Also:
frem
default CodeBuilder frem()
floats remainder.- Returns:
- this builder
- See Also:
freturn
default CodeBuilder freturn()
float from this method.- Returns:
- this builder
- See Also:
fstore
default CodeBuilder fstore(int slot)
float into a local variable. This may also generate fstore_<N> and wide fstore instructions.
- Parameters:
-
slot- the local variable slot - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifslotis notu2 - See Also:
fsub
default CodeBuilder fsub()
floats.- Returns:
- this builder
- See Also:
getfield
default CodeBuilder getfield(FieldRefEntry ref)
- Parameters:
-
ref- the field reference - Returns:
- this builder
- See Also:
getfield
default CodeBuilder getfield(ClassDesc owner, String name, ClassDesc type)
- Parameters:
-
owner- the owner class -
name- the field name -
type- the field type - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifownerrepresents a primitive type - See Also:
getstatic
default CodeBuilder getstatic(FieldRefEntry ref)
- Parameters:
-
ref- the field reference - Returns:
- this builder
- See Also:
getstatic
default CodeBuilder getstatic(ClassDesc owner, String name, ClassDesc type)
- Parameters:
-
owner- the owner class -
name- the field name -
type- the field type - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifownerrepresents a primitive type - See Also:
goto_
default CodeBuilder goto_(Label target)
This may also generate goto_w instructions if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set.
- API Note:
- The instruction's name is
goto, which coincides with a reserved keyword of the Java programming language, thus this method is named with an extra_suffix instead. - Parameters:
-
target- the branch target - Returns:
- this builder
- See Also:
goto_w
default CodeBuilder goto_w(Label target)
- Parameters:
-
target- the branch target - Returns:
- this builder
- See Also:
i2b
i2c
i2d
i2f
i2l
i2s
iadd
default CodeBuilder iadd()
ints.- Returns:
- this builder
- See Also:
iaload
default CodeBuilder iaload()
int array.- Returns:
- this builder
- See Also:
iand
iastore
default CodeBuilder iastore()
int array.- Returns:
- this builder
- See Also:
iconst_0
default CodeBuilder iconst_0()
int constant 0 onto the operand stack.- Returns:
- this builder
- See Also:
iconst_1
default CodeBuilder iconst_1()
int constant 1 onto the operand stack.- Returns:
- this builder
- See Also:
iconst_2
default CodeBuilder iconst_2()
int constant 2 onto the operand stack.- Returns:
- this builder
- See Also:
iconst_3
default CodeBuilder iconst_3()
int constant 3 onto the operand stack.- Returns:
- this builder
- See Also:
iconst_4
default CodeBuilder iconst_4()
int constant 4 onto the operand stack.- Returns:
- this builder
- See Also:
iconst_5
default CodeBuilder iconst_5()
int constant 5 onto the operand stack.- Returns:
- this builder
- See Also:
iconst_m1
default CodeBuilder iconst_m1()
int constant -1 onto the operand stack.- Returns:
- this builder
- See Also:
idiv
if_acmpeq
default CodeBuilder if_acmpeq(Label target)
reference comparison operand1 == operand2 succeeds. This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and
target cannot be encoded as a BCI offset in [-32768, 32767].
- Parameters:
-
target- the branch target - Returns:
- this builder
- See Also:
if_acmpne
default CodeBuilder if_acmpne(Label target)
reference comparison operand1 != operand2 succeeds. This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and
target cannot be encoded as a BCI offset in [-32768, 32767].
- Parameters:
-
target- the branch target - Returns:
- this builder
- See Also:
if_icmpeq
default CodeBuilder if_icmpeq(Label target)
int comparison operand1 == operand2 succeeds. This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and
target cannot be encoded as a BCI offset in [-32768, 32767].
- Parameters:
-
target- the branch target - Returns:
- this builder
- See Also:
if_icmpge
default CodeBuilder if_icmpge(Label target)
int comparison operand1 >= operand2 succeeds. This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and
target cannot be encoded as a BCI offset in [-32768, 32767].
- Parameters:
-
target- the branch target - Returns:
- this builder
- See Also:
if_icmpgt
default CodeBuilder if_icmpgt(Label target)
int comparison operand1 > operand2 succeeds. This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and
target cannot be encoded as a BCI offset in [-32768, 32767].
- Parameters:
-
target- the branch target - Returns:
- this builder
- See Also:
if_icmple
default CodeBuilder if_icmple(Label target)
int comparison operand1 <= operand2 succeeds. This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and
target cannot be encoded as a BCI offset in [-32768, 32767].
- Parameters:
-
target- the branch target - Returns:
- this builder
- See Also:
if_icmplt
default CodeBuilder if_icmplt(Label target)
int comparison operand1 < operand2 succeeds. This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and
target cannot be encoded as a BCI offset in [-32768, 32767].
- Parameters:
-
target- the branch target - Returns:
- this builder
- See Also:
if_icmpne
default CodeBuilder if_icmpne(Label target)
int comparison operand1 != operand2 succeeds. This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and
target cannot be encoded as a BCI offset in [-32768, 32767].
- Parameters:
-
target- the branch target - Returns:
- this builder
- See Also:
ifnonnull
default CodeBuilder ifnonnull(Label target)
reference is not null. This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and
target cannot be encoded as a BCI offset in [-32768, 32767].
- Parameters:
-
target- the branch target - Returns:
- this builder
- See Also:
ifnull
default CodeBuilder ifnull(Label target)
reference is null. This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and
target cannot be encoded as a BCI offset in [-32768, 32767].
- Parameters:
-
target- the branch target - Returns:
- this builder
- See Also:
ifeq
default CodeBuilder ifeq(Label target)
int comparison with zero == 0 succeeds. This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and
target cannot be encoded as a BCI offset in [-32768, 32767].
- Parameters:
-
target- the branch target - Returns:
- this builder
- See Also:
ifge
default CodeBuilder ifge(Label target)
int comparison with zero >= 0 succeeds. This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and
target cannot be encoded as a BCI offset in [-32768, 32767].
- Parameters:
-
target- the branch target - Returns:
- this builder
- See Also:
ifgt
default CodeBuilder ifgt(Label target)
int comparison with zero > 0 succeeds. This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and
target cannot be encoded as a BCI offset in [-32768, 32767].
- Parameters:
-
target- the branch target - Returns:
- this builder
- See Also:
ifle
default CodeBuilder ifle(Label target)
int comparison with zero <= 0 succeeds. This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and
target cannot be encoded as a BCI offset in [-32768, 32767].
- Parameters:
-
target- the branch target - Returns:
- this builder
- See Also:
iflt
default CodeBuilder iflt(Label target)
int comparison with zero < 0 succeeds. This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and
target cannot be encoded as a BCI offset in [-32768, 32767].
- Parameters:
-
target- the branch target - Returns:
- this builder
- See Also:
ifne
default CodeBuilder ifne(Label target)
int comparison with zero != 0 succeeds. This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and
target cannot be encoded as a BCI offset in [-32768, 32767].
- Parameters:
-
target- the branch target - Returns:
- this builder
- See Also:
iinc
default CodeBuilder iinc(int slot, int val)
int local variable by a constant. This may also generate wide iinc instructions if slot exceeds the limit of u1 or val exceeds the range of byte.
- Parameters:
-
slot- the local variable slot -
val- the increment value - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifslotis notu2orvalis out of range ofshort - See Also:
iload
default CodeBuilder iload(int slot)
int from a local variable. This may also generate iload_<N> and wide iload instructions.
- Parameters:
-
slot- the local variable slot - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifslotis notu2 - See Also:
imul
default CodeBuilder imul()
ints.- Returns:
- this builder
- See Also:
ineg
default CodeBuilder ineg()
int.- Returns:
- this builder
- See Also:
instanceOf
default CodeBuilder instanceOf(ClassEntry target)
boolean result on the operand stack.- API Note:
- The instruction's name is
instanceof, which coincides with a reserved keyword of the Java programming language, thus this method is named with camel case instead. - Parameters:
-
target- the target type - Returns:
- this builder
- See Also:
instanceOf
default CodeBuilder instanceOf(ClassDesc target)
boolean result on the operand stack.- API Note:
- The instruction's name is
instanceof, which coincides with a reserved keyword of the Java programming language, thus this method is named with camel case instead. - Parameters:
-
target- the target type - Returns:
- this builder
- Throws:
-
IllegalArgumentException- iftargetrepresents a primitive type - See Also:
invokedynamic
default CodeBuilder invokedynamic(InvokeDynamicEntry ref)
- Parameters:
-
ref- the dynamic call site - Returns:
- this builder
- See Also:
invokedynamic
default CodeBuilder invokedynamic(DynamicCallSiteDesc ref)
- Parameters:
-
ref- the dynamic call site - Returns:
- this builder
- See Also:
invokeinterface
default CodeBuilder invokeinterface(InterfaceMethodRefEntry ref)
- Parameters:
-
ref- the interface method reference - Returns:
- this builder
- See Also:
invokeinterface
default CodeBuilder invokeinterface(ClassDesc owner, String name, MethodTypeDesc type)
- Parameters:
-
owner- the owner interface -
name- the method name -
type- the method type - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifownerrepresents a primitive type - See Also:
invokespecial
default CodeBuilder invokespecial(InterfaceMethodRefEntry ref)
- Parameters:
-
ref- the interface method reference - Returns:
- this builder
- See Also:
invokespecial
default CodeBuilder invokespecial(MethodRefEntry ref)
- Parameters:
-
ref- the method reference - Returns:
- this builder
- See Also:
invokespecial
default CodeBuilder invokespecial(ClassDesc owner, String name, MethodTypeDesc type)
- Parameters:
-
owner- the owner class, must not be an interface -
name- the method name -
type- the method type - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifownerrepresents a primitive type - See Also:
invokespecial
default CodeBuilder invokespecial(ClassDesc owner, String name, MethodTypeDesc type, boolean isInterface)
- Parameters:
-
owner- the owner class or interface -
name- the method name -
type- the method type -
isInterface- whether the owner is an interface - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifownerrepresents a primitive type - See Also:
invokestatic
default CodeBuilder invokestatic(InterfaceMethodRefEntry ref)
- Parameters:
-
ref- the interface method reference - Returns:
- this builder
- See Also:
invokestatic
default CodeBuilder invokestatic(MethodRefEntry ref)
- Parameters:
-
ref- the method reference - Returns:
- this builder
- See Also:
invokestatic
default CodeBuilder invokestatic(ClassDesc owner, String name, MethodTypeDesc type)
- Parameters:
-
owner- the owner class, must not be an interface -
name- the method name -
type- the method type - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifownerrepresents a primitive type - See Also:
invokestatic
default CodeBuilder invokestatic(ClassDesc owner, String name, MethodTypeDesc type, boolean isInterface)
- Parameters:
-
owner- the owner class or interface -
name- the method name -
type- the method type -
isInterface- whether the owner is an interface - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifownerrepresents a primitive type - See Also:
invokevirtual
default CodeBuilder invokevirtual(MethodRefEntry ref)
- Parameters:
-
ref- the method reference - Returns:
- this builder
- See Also:
invokevirtual
default CodeBuilder invokevirtual(ClassDesc owner, String name, MethodTypeDesc type)
- Parameters:
-
owner- the owner class, must not be an interface -
name- the method name -
type- the method type - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifownerrepresents a primitive type - See Also:
ior
irem
default CodeBuilder irem()
ints remainder.- Returns:
- this builder
- See Also:
ireturn
default CodeBuilder ireturn()
int from this method.- Returns:
- this builder
- See Also:
ishl
default CodeBuilder ishl()
int left.- Returns:
- this builder
- See Also:
ishr
istore
default CodeBuilder istore(int slot)
int into a local variable. This may also generate istore_<N> and wide istore instructions.
- Parameters:
-
slot- the local variable slot - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifslotis notu2 - See Also:
isub
default CodeBuilder isub()
ints.- Returns:
- this builder
- See Also:
iushr
ixor
lookupswitch
default CodeBuilder lookupswitch(Label defaultTarget, List<SwitchCase> cases)
- Parameters:
-
defaultTarget- the default jump target -
cases- the switch cases - Returns:
- this builder
- See Also:
l2d
l2f
l2i
ladd
default CodeBuilder ladd()
longs.- Returns:
- this builder
- See Also:
laload
default CodeBuilder laload()
long array.- Returns:
- this builder
- See Also:
land
default CodeBuilder land()
longs.- Returns:
- this builder
- See Also:
lastore
default CodeBuilder lastore()
long array.- Returns:
- this builder
- See Also:
lcmp
default CodeBuilder lcmp()
longs.- Returns:
- this builder
- See Also:
lconst_0
default CodeBuilder lconst_0()
long constant 0 onto the operand stack.- Returns:
- this builder
- See Also:
lconst_1
default CodeBuilder lconst_1()
long constant 1 onto the operand stack.- Returns:
- this builder
- See Also:
ldc
default CodeBuilder ldc(ConstantDesc value)
- API Note:
-
loadConstantgenerates more optimal instructions and should be used for general constants if anldcinstruction is not strictly required. - Parameters:
-
value- the constant value - Returns:
- this builder
- See Also:
ldc
ldiv
default CodeBuilder ldiv()
longs.- Returns:
- this builder
- See Also:
lload
default CodeBuilder lload(int slot)
long from a local variable. This may also generate lload_<N> and wide lload instructions.
- Parameters:
-
slot- the local variable slot - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifslotis notu2 - See Also:
lmul
default CodeBuilder lmul()
longs.- Returns:
- this builder
- See Also:
lneg
default CodeBuilder lneg()
long.- Returns:
- this builder
- See Also:
lor
default CodeBuilder lor()
longs.- Returns:
- this builder
- See Also:
lrem
default CodeBuilder lrem()
longs remainder.- Returns:
- this builder
- See Also:
lreturn
default CodeBuilder lreturn()
long from this method.- Returns:
- this builder
- See Also:
lshl
default CodeBuilder lshl()
long left.- Returns:
- this builder
- See Also:
lshr
lstore
default CodeBuilder lstore(int slot)
long into a local variable. This may also generate lstore_<N> and wide lstore instructions.
- Parameters:
-
slot- the local variable slot - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifslotis notu2 - See Also:
lsub
default CodeBuilder lsub()
longs.- Returns:
- this builder
- See Also:
lushr
lxor
default CodeBuilder lxor()
longs.- Returns:
- this builder
- See Also:
monitorenter
default CodeBuilder monitorenter()
- Returns:
- this builder
- See Also:
monitorexit
default CodeBuilder monitorexit()
- Returns:
- this builder
- See Also:
multianewarray
default CodeBuilder multianewarray(ClassEntry array, int dims)
- Parameters:
-
array- the array type -
dims- the number of dimensions - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifdimsis out of range - See Also:
multianewarray
default CodeBuilder multianewarray(ClassDesc array, int dims)
- Parameters:
-
array- the array type -
dims- the number of dimensions - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifarrayrepresents a primitive type or ifdimsis out of range - See Also:
new_
default CodeBuilder new_(ClassEntry clazz)
- API Note:
- The instruction's name is
new, which coincides with a reserved keyword of the Java programming language, thus this method is named with an extra_suffix instead. - Parameters:
-
clazz- the new class type - Returns:
- this builder
- See Also:
new_
default CodeBuilder new_(ClassDesc clazz)
- API Note:
- The instruction's name is
new, which coincides with a reserved keyword of the Java programming language, thus this method is named with an extra_suffix instead. - Parameters:
-
clazz- the new class type - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifclazzrepresents a primitive type - See Also:
newarray
default CodeBuilder newarray(TypeKind typeKind)
- Parameters:
-
typeKind- the primitive array type - Returns:
- this builder
- Throws:
-
IllegalArgumentException- when thetypeKindis not a legal primitive array component type - See Also:
pop
default CodeBuilder pop()
- Returns:
- this builder
- See Also:
pop2
default CodeBuilder pop2()
- Returns:
- this builder
- See Also:
putfield
default CodeBuilder putfield(FieldRefEntry ref)
- Parameters:
-
ref- the field reference - Returns:
- this builder
- See Also:
putfield
default CodeBuilder putfield(ClassDesc owner, String name, ClassDesc type)
- Parameters:
-
owner- the owner class -
name- the field name -
type- the field type - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifownerrepresents a primitive type - See Also:
putstatic
default CodeBuilder putstatic(FieldRefEntry ref)
- Parameters:
-
ref- the field reference - Returns:
- this builder
- See Also:
putstatic
default CodeBuilder putstatic(ClassDesc owner, String name, ClassDesc type)
- Parameters:
-
owner- the owner class or interface -
name- the field name -
type- the field type - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifownerrepresents a primitive type - See Also:
return_
default CodeBuilder return_()
void from this method.- API Note:
- The instruction's name is
return, which coincides with a reserved keyword of the Java programming language, thus this method is named with an extra_suffix instead. - Returns:
- this builder
- See Also:
saload
default CodeBuilder saload()
short array.- Returns:
- this builder
- See Also:
sastore
default CodeBuilder sastore()
short array.- Returns:
- this builder
- See Also:
sipush
default CodeBuilder sipush(int s)
int in the range of short, [-32768, 32767], onto the operand stack.- Parameters:
-
s- the int in the range of short - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifsis out of range of short - See Also:
swap
default CodeBuilder swap()
- Returns:
- this builder
- See Also:
tableswitch
default CodeBuilder tableswitch(int low, int high, Label defaultTarget, List<SwitchCase> cases)
- Parameters:
-
low- the minimum key, inclusive -
high- the maximum key, inclusive -
defaultTarget- the default jump target -
cases- the switch cases - Returns:
- this builder
- Throws:
-
IllegalArgumentException- if the low value is greater than the high value, or if there are too many targets between the low and high values - See Also:
tableswitch
default CodeBuilder tableswitch(Label defaultTarget, List<SwitchCase> cases)
cases.- Parameters:
-
defaultTarget- the default jump target -
cases- the switch cases - Returns:
- this builder
- Throws:
-
IllegalArgumentException- ifcasesis empty - See Also:
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.