Interface CodeBuilder
- All Superinterfaces:
ClassFileBuilder<CodeElement, CodeBuilder>
,Consumer<CodeElement>
- All Known Subinterfaces:
CodeBuilder.BlockCodeBuilder
Code
attributes (method bodies). MethodBuilder.withCode(java.util.function.Consumer<? super java.lang.classfile.CodeBuilder>)
is the basic way to obtain a code builder; ClassBuilder.withMethodBody(java.lang.classfile.constantpool.Utf8Entry, java.lang.classfile.constantpool.Utf8Entry, int, java.util.function.Consumer<? super java.lang.classfile.CodeBuilder>)
is a shortcut. There are also derived code
builders from block(java.util.function.Consumer<java.lang.classfile.CodeBuilder.BlockCodeBuilder>)
, which handles code blocks and transforming(java.lang.classfile.CodeTransform, java.util.function.Consumer<java.lang.classfile.CodeBuilder>)
, 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_w
orwide
, share their factories with their regular version likeldc(java.lang.constant.ConstantDesc)
. Note thatgoto_w
has its own factory to avoid short jumps. - The
goto
,instanceof
,new
, andreturn
instructions' 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
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
A builder for blocks of code.static interface
A builder to add catch blocks. -
Method Summary
Modifier and TypeMethodDescriptiondefault CodeBuilder
aaload()
Generates an instruction to load from areference
array.default CodeBuilder
aastore()
Generates an instruction to store into areference
array.default CodeBuilder
Generates an instruction pushing the null objectreference
onto the operand stack.int
allocateLocal
(TypeKind typeKind) Returns the local variable slot of a fresh local variable.default CodeBuilder
aload
(int slot) Generates an instruction to load areference
from a local variable.default CodeBuilder
anewarray
(ClassEntry classEntry) Generates an instruction to create a new array ofreference
.default CodeBuilder
Generates an instruction to create a new array ofreference
.default CodeBuilder
areturn()
Generates an instruction to return areference
from this method.default CodeBuilder
Generates an instruction to get the length of an array.default CodeBuilder
Generates an instruction to load from an array.default CodeBuilder
arrayStore
(TypeKind tk) Generates an instruction to store into an array.default CodeBuilder
astore
(int slot) Generates an instruction to store areference
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
(int b) default CodeBuilder
block
(Consumer<CodeBuilder.BlockCodeBuilder> handler) Adds a lexical block to the method being built.default CodeBuilder
Generates a branch instruction.default CodeBuilder
caload()
Generates an instruction to load from achar
array.default CodeBuilder
castore()
Generates an instruction to store into achar
array.default CodeBuilder
characterRange
(Label startScope, Label endScope, int characterRangeStart, int characterRangeEnd, int flags) Declares a character range entry.default CodeBuilder
checkcast
(ClassEntry type) Generates an instruction to check whether an object is of the given type, throwing aClassCastException
if the check fails.default CodeBuilder
Generates an instruction to check whether an object is of the given type, throwing aClassCastException
if the check fails.default CodeBuilder
conversion
(TypeKind fromType, TypeKind toType) Generates instruction(s) to convertfromType
totoType
.default CodeBuilder
d2f()
default CodeBuilder
d2i()
default CodeBuilder
d2l()
default CodeBuilder
dadd()
Generates an instruction to add twodoubles
.default CodeBuilder
daload()
Generates an instruction to load from adouble
array.default CodeBuilder
dastore()
Generates an instruction to store into adouble
array.default CodeBuilder
dcmpg()
default CodeBuilder
dcmpl()
default CodeBuilder
dconst_0()
Generates an instruction pushingdouble
constant 0 onto the operand stack.default CodeBuilder
dconst_1()
Generates an instruction pushingdouble
constant 1 onto the operand stack.default CodeBuilder
ddiv()
Generates an instruction to dividedoubles
.default CodeBuilder
dload
(int slot) Generates an instruction to load adouble
from a local variable.default CodeBuilder
dmul()
Generates an instruction to multiplydoubles
.default CodeBuilder
dneg()
Generates an instruction to negate adouble
.default CodeBuilder
drem()
Generates an instruction to calculatedouble
remainder.default CodeBuilder
dreturn()
Generates an instruction to return adouble
from this method.default CodeBuilder
dstore
(int slot) Generates an instruction to store adouble
into a local variable.default CodeBuilder
dsub()
Generates an instruction to subtractdoubles
.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.endLabel()
Returns the label associated with the end of the current block.default CodeBuilder
exceptionCatch
(Label start, Label end, Label handler, ClassEntry catchType) Declares an exception table entry.default CodeBuilder
exceptionCatch
(Label start, Label end, Label handler, ClassDesc catchType) Declares an exception table entry.default CodeBuilder
exceptionCatch
(Label start, Label end, Label handler, Optional<ClassEntry> catchType) Declares an exception table entry.default CodeBuilder
exceptionCatchAll
(Label start, Label end, Label handler) 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 twofloats
.default CodeBuilder
faload()
Generates an instruction to load from afloat
array.default CodeBuilder
fastore()
Generates an instruction to store into afloat
array.default CodeBuilder
fcmpg()
default CodeBuilder
fcmpl()
default CodeBuilder
fconst_0()
Generates an instruction pushingfloat
constant 0 onto the operand stack.default CodeBuilder
fconst_1()
Generates an instruction pushingfloat
constant 1 onto the operand stack.default CodeBuilder
fconst_2()
Generates an instruction pushingfloat
constant 2 onto the operand stack.default CodeBuilder
fdiv()
Generates an instruction to dividefloats
.default CodeBuilder
fieldAccess
(Opcode opcode, FieldRefEntry ref) Generates an instruction to access a field.default CodeBuilder
fieldAccess
(Opcode opcode, ClassDesc owner, String name, ClassDesc type) Generates an instruction to access a field.default CodeBuilder
fload
(int slot) Generates an instruction to load afloat
from a local variable.default CodeBuilder
fmul()
Generates an instruction to multiplyfloats
.default CodeBuilder
fneg()
Generates an instruction to negate afloat
.default CodeBuilder
frem()
Generates an instruction to calculatefloats
remainder.default CodeBuilder
freturn()
Generates an instruction to return afloat
from this method.default CodeBuilder
fstore
(int slot) Generates an instruction to store afloat
into a local variable.default CodeBuilder
fsub()
Generates an instruction to subtractfloats
.default CodeBuilder
getfield
(FieldRefEntry ref) Generates an instruction to fetch field from an object.default CodeBuilder
Generates an instruction to fetch field from an object.default CodeBuilder
getstatic
(FieldRefEntry ref) Generates an instruction to get static field from a class or interface.default CodeBuilder
Generates an instruction to get static field from a class or interface.default CodeBuilder
Generates an instruction to branch always.default CodeBuilder
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 twoints
.default CodeBuilder
iaload()
Generates an instruction to load from anint
array.default CodeBuilder
iand()
default CodeBuilder
iastore()
Generates an instruction to store into anint
array.default CodeBuilder
iconst_0()
Generates an instruction pushingint
constant 0 onto the operand stack.default CodeBuilder
iconst_1()
Generates an instruction pushingint
constant 1 onto the operand stack.default CodeBuilder
iconst_2()
Generates an instruction pushingint
constant 2 onto the operand stack.default CodeBuilder
iconst_3()
Generates an instruction pushingint
constant 3 onto the operand stack.default CodeBuilder
iconst_4()
Generates an instruction pushingint
constant 4 onto the operand stack.default CodeBuilder
iconst_5()
Generates an instruction pushingint
constant 5 onto the operand stack.default CodeBuilder
Generates an instruction pushingint
constant -1 onto the operand stack.default CodeBuilder
idiv()
Generates an instruction to divideints
.default CodeBuilder
Generates an instruction to branch ifreference
comparisonoperand1 == operand2
succeeds.default CodeBuilder
Generates an instruction to branch ifreference
comparisonoperand1 != operand2
succeeds.default CodeBuilder
Generates an instruction to branch ifint
comparisonoperand1 == operand2
succeeds.default CodeBuilder
Generates an instruction to branch ifint
comparisonoperand1 >= operand2
succeeds.default CodeBuilder
Generates an instruction to branch ifint
comparisonoperand1 > operand2
succeeds.default CodeBuilder
Generates an instruction to branch ifint
comparisonoperand1 <= operand2
succeeds.default CodeBuilder
Generates an instruction to branch ifint
comparisonoperand1 < operand2
succeeds.default CodeBuilder
Generates an instruction to branch ifint
comparisonoperand1 != operand2
succeeds.default CodeBuilder
Generates an instruction to branch ifint
comparison with zero== 0
succeeds.default CodeBuilder
Generates an instruction to branch ifint
comparison with zero>= 0
succeeds.default CodeBuilder
Generates an instruction to branch ifint
comparison with zero> 0
succeeds.default CodeBuilder
Generates an instruction to branch ifint
comparison with zero<= 0
succeeds.default CodeBuilder
Generates an instruction to branch ifint
comparison with zero< 0
succeeds.default CodeBuilder
Generates an instruction to branch ifint
comparison with zero!= 0
succeeds.default CodeBuilder
Generates an instruction to branch ifreference
is notnull
.default CodeBuilder
Generates an instruction to branch ifreference
isnull
.default CodeBuilder
ifThen
(Opcode opcode, Consumer<CodeBuilder.BlockCodeBuilder> thenHandler) 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
(Consumer<CodeBuilder.BlockCodeBuilder> thenHandler) Adds an "if-then" block that is conditional on theboolean
value on top of the operand stack.default CodeBuilder
ifThenElse
(Opcode opcode, Consumer<CodeBuilder.BlockCodeBuilder> thenHandler, Consumer<CodeBuilder.BlockCodeBuilder> elseHandler) 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
(Consumer<CodeBuilder.BlockCodeBuilder> thenHandler, Consumer<CodeBuilder.BlockCodeBuilder> elseHandler) Adds an "if-then-else" block that is conditional on theboolean
value on top of the operand stack.default CodeBuilder
iinc
(int slot, int val) Generates an instruction to increment anint
local variable by a constant.default CodeBuilder
iload
(int slot) Generates an instruction to load anint
from a local variable.default CodeBuilder
imul()
Generates an instruction to multiplyints
.default CodeBuilder
ineg()
Generates an instruction to negate anint
.default CodeBuilder
instanceOf
(ClassEntry target) Generates an instruction to determine if an object is of the given type, producing aboolean
result on the operand stack.default CodeBuilder
instanceOf
(ClassDesc target) Generates an instruction to determine if an object is of the given type, producing aboolean
result on the operand stack.default CodeBuilder
invoke
(Opcode opcode, MemberRefEntry ref) Generates an instruction to invoke a method.default CodeBuilder
invoke
(Opcode opcode, ClassDesc owner, String name, MethodTypeDesc desc, boolean isInterface) Generates an instruction to invoke a method.default CodeBuilder
Generates an instruction to invoke a dynamically-computed call site.default CodeBuilder
Generates an instruction to invoke a dynamically-computed call site.default CodeBuilder
Generates an instruction to invoke an interface method.default CodeBuilder
invokeinterface
(ClassDesc owner, String name, MethodTypeDesc type) Generates an instruction to invoke an interface method.default CodeBuilder
Generates an instruction to invoke an instance method in an interface; direct invocation of methods of the current class and its supertypes.default CodeBuilder
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
(ClassDesc owner, String name, MethodTypeDesc type) 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
(ClassDesc owner, String name, MethodTypeDesc type, boolean isInterface) 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
Generates an instruction to invoke a class (static) method of an interface.default CodeBuilder
Generates an instruction to invoke a class (static) method of a class.default CodeBuilder
invokestatic
(ClassDesc owner, String name, MethodTypeDesc type) Generates an instruction to invoke a class (static) method of a class.default CodeBuilder
invokestatic
(ClassDesc owner, String name, MethodTypeDesc type, boolean isInterface) Generates an instruction to invoke a class (static) method.default CodeBuilder
Generates an instruction to invoke an instance method; dispatch based on class.default CodeBuilder
invokevirtual
(ClassDesc owner, String name, MethodTypeDesc type) Generates an instruction to invoke an instance method; dispatch based on class.default CodeBuilder
ior()
default CodeBuilder
irem()
Generates an instruction to calculateints
remainder.default CodeBuilder
ireturn()
Generates an instruction to return anint
from this method.default CodeBuilder
ishl()
Generates an instruction to shift anint
left.default CodeBuilder
ishr()
Generates an instruction to shift anint
right.default CodeBuilder
istore
(int slot) Generates an instruction to store anint
into a local variable.default CodeBuilder
isub()
Generates an instruction to subtractints
.default CodeBuilder
iushr()
Generates an instruction to logical shift anint
right.default CodeBuilder
ixor()
Generates an instruction to calculate bitwise XOR ofints
.default CodeBuilder
l2d()
default CodeBuilder
l2f()
default CodeBuilder
l2i()
default CodeBuilder
labelBinding
(Label label) Binds a label to the current position.default CodeBuilder
ladd()
Generates an instruction to add twolongs
.default CodeBuilder
laload()
Generates an instruction to load from along
array.default CodeBuilder
land()
Generates an instruction to calculate bitwise AND oflongs
.default CodeBuilder
lastore()
Generates an instruction to store into along
array.default CodeBuilder
lcmp()
Generates an instruction to comparelongs
.default CodeBuilder
lconst_0()
Generates an instruction pushinglong
constant 0 onto the operand stack.default CodeBuilder
lconst_1()
Generates an instruction pushinglong
constant 1 onto the operand stack.default CodeBuilder
ldc
(LoadableConstantEntry entry) Generates an instruction pushing an item from the run-time constant pool onto the operand stack.default CodeBuilder
ldc
(ConstantDesc value) Generates an instruction pushing an item from the run-time constant pool onto the operand stack.default CodeBuilder
ldiv()
Generates an instruction to dividelongs
.default CodeBuilder
lineNumber
(int line) Declares a source line number beginning at the current position.default CodeBuilder
lload
(int slot) Generates an instruction to load along
from a local variable.default CodeBuilder
lmul()
Generates an instruction to multiplylongs
.default CodeBuilder
lneg()
Generates an instruction to negate along
.default CodeBuilder
loadConstant
(double value) Generates an instruction pushing a constantdouble
value onto the operand stack.default CodeBuilder
loadConstant
(float value) Generates an instruction pushing a constantfloat
value onto the operand stack.default CodeBuilder
loadConstant
(int value) Generates an instruction pushing a constantint
value onto the operand stack.default CodeBuilder
loadConstant
(long value) Generates an instruction pushing a constantlong
value onto the operand stack.default CodeBuilder
loadConstant
(ConstantDesc value) Generates an instruction pushing a constant onto the operand stack.default CodeBuilder
Generates an instruction to load a value from a local variable.default CodeBuilder
localVariable
(int slot, Utf8Entry nameEntry, Utf8Entry descriptorEntry, Label startScope, Label endScope) Declares a local variable entry.default CodeBuilder
localVariable
(int slot, String name, ClassDesc descriptor, Label startScope, Label endScope) Declares a local variable entry.default CodeBuilder
localVariableType
(int slot, Utf8Entry nameEntry, Utf8Entry signatureEntry, Label startScope, Label endScope) Declares a local variable type entry.default CodeBuilder
localVariableType
(int slot, String name, Signature signature, Label startScope, Label endScope) Declares a local variable type entry.default CodeBuilder
lookupswitch
(Label defaultTarget, List<SwitchCase> cases) Generates an instruction to access a jump table by key match and jump.default CodeBuilder
lor()
Generates an instruction to calculate bitwise OR oflongs
.default CodeBuilder
lrem()
Generates an instruction to calculatelongs
remainder.default CodeBuilder
lreturn()
Generates an instruction to return along
from this method.default CodeBuilder
lshl()
Generates an instruction to shift along
left.default CodeBuilder
lshr()
Generates an instruction to shift along
right.default CodeBuilder
lstore
(int slot) Generates an instruction to store along
into a local variable.default CodeBuilder
lsub()
Generates an instruction to subtractlongs
.default CodeBuilder
lushr()
Generates an instruction to logical shift along
right.default CodeBuilder
lxor()
Generates an instruction to calculate bitwise XOR oflongs
.default CodeBuilder
Generates an instruction to enter monitor for an object.default CodeBuilder
Generates an instruction to exit monitor for an object.default CodeBuilder
multianewarray
(ClassEntry array, int dims) Generates an instruction to create a new multidimensional array.default CodeBuilder
multianewarray
(ClassDesc array, int dims) Generates an instruction to create a new multidimensional array.default CodeBuilder
new_
(ClassEntry clazz) Generates an instruction to create a new object.default CodeBuilder
Generates an instruction to create a new object.default CodeBuilder
Generates an instruction to create a new array of a primitive type.default Label
Creates a new label bound at the current position.newLabel()
Returns a fresh unbound label.default CodeBuilder
nop()
Generates a do-nothing instruction.int
parameterSlot
(int paramNo) 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
(FieldRefEntry ref) Generates an instruction to set field in an object.default CodeBuilder
Generates an instruction to set field in an object.default CodeBuilder
putstatic
(FieldRefEntry ref) Generates an instruction to set static field in a class.default CodeBuilder
Generates an instruction to set static field in a class.int
Returns the local variable slot associated with the receiver.default CodeBuilder
return_()
Generates an instruction to returnvoid
from this method.default CodeBuilder
Generates a return instruction.default CodeBuilder
saload()
Generates an instruction to load from ashort
array.default CodeBuilder
sastore()
Generates an instruction to store into ashort
array.default CodeBuilder
sipush
(int s) Returns the label associated with the beginning of the current block.default CodeBuilder
storeLocal
(TypeKind tk, int slot) 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
(int low, int high, Label defaultTarget, List<SwitchCase> cases) Generates an instruction to access a jump table by index and jump.default CodeBuilder
tableswitch
(Label defaultTarget, List<SwitchCase> cases) Generates an instruction to access a jump table by index and jump.default CodeBuilder
transforming
(CodeTransform transform, Consumer<CodeBuilder> handler) Apply a transform to the code built by a handler, directing results to this builder.default CodeBuilder
trying
(Consumer<CodeBuilder.BlockCodeBuilder> tryHandler, Consumer<CodeBuilder.CatchBuilder> catchesHandler) Adds a "try-catch" block comprising one try block and zero or more catch blocks.Methods declared in interface java.lang.classfile.ClassFileBuilder
accept, constantPool, transform, with
-
Method Details
-
newLabel
Label newLabel()Returns a fresh unbound label. The label can be bound withlabelBinding(java.lang.classfile.Label)
.- Returns:
- a fresh unbound label
-
startLabel
Label startLabel()Returns the label associated with the beginning of the current block. If this builder is not a "block" builder, such as those provided byblock(Consumer)
orifThenElse(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()Returns the label associated with the end of the current block. If this builder is not a "block" builder, such as those provided byblock(Consumer)
orifThenElse(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.- Returns:
- the local variable slot associated with the receiver
- Throws:
IllegalStateException
- if this is a static method
-
parameterSlot
int parameterSlot(int paramNo) Returns the local variable slot associated with the specified parameter. The returned value is adjusted for the receiver slot (if the method is an instance method) and for the requirement thatlong
anddouble
values require two slots.- Parameters:
paramNo
- the index of the parameter- Returns:
- the local variable slot associated with the specified parameter
-
allocateLocal
Returns the local variable slot of a fresh local variable. This method makes reasonable efforts to determine which slots are in use and which are not. When transforming a method, fresh locals begin at themaxLocals
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
Apply a transform to the code built by a handler, directing results to this builder.- API Note:
- This is similar to
ClassFileBuilder.transform(java.lang.classfile.CompoundElement<E>, java.lang.classfile.ClassFileTransform<?, E, B>)
, but this does not require the code elements to be viewed as aCodeModel
first. - Parameters:
transform
- the transform to apply to the code built by the handlerhandler
- the handler that receives aCodeBuilder
to build the code- Returns:
- this builder
-
block
Adds a lexical block to the method being built.Within this block, the
startLabel()
andendLabel()
correspond to the start and end of the block, and theCodeBuilder.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.BlockCodeBuilder
to generate the body of the lexical block- Returns:
- this builder
-
ifThen
Adds an "if-then" block that is conditional on theboolean
value on top of the operand stack. Control flow enters the "then" block if the value representstrue
.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
Adds an "if-then" block that is conditional on the value(s) on top of the operand stack in accordance with the given opcode. Control flow enters the "then" block if the branching condition foropcode
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 stackthenHandler
- handler that receives aCodeBuilder.BlockCodeBuilder
to 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) Adds an "if-then-else" block that is conditional on theboolean
value on top of the operand stack. Control flow enters the "then" block if the value representstrue
, 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.BlockCodeBuilder
to generate the body of theif
elseHandler
- handler that receives aCodeBuilder.BlockCodeBuilder
to generate the body of theelse
- Returns:
- this builder
- See Also:
-
ifThenElse
default CodeBuilder ifThenElse(Opcode opcode, Consumer<CodeBuilder.BlockCodeBuilder> thenHandler, Consumer<CodeBuilder.BlockCodeBuilder> elseHandler) 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. Control flow enters the "then" block if the branching condition foropcode
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 stackthenHandler
- 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) Adds a "try-catch" block comprising one try block and zero or more catch blocks. Exceptions thrown by instructions in the try block may be caught by catch blocks.The
CodeBuilder.BlockCodeBuilder.breakLabel()
for the try block and all catch blocks in thecatchesHandler
correspond to the cursor position immediately after this call in this builder.- Parameters:
tryHandler
- handler that receives aCodeBuilder.BlockCodeBuilder
to generate the body of the try block.catchesHandler
- a handler that receives aCodeBuilder.CatchBuilder
to generate bodies of catch blocks- Returns:
- this builder
- Throws:
IllegalArgumentException
- if the try block is empty- See Also:
-
loadLocal
Generates an instruction to load a value from a local variable.- Parameters:
tk
- the load typeslot
- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException
- iftk
isvoid
orslot
is out of range- See Also:
-
storeLocal
Generates an instruction to store a value to a local variable.- Parameters:
tk
- the store typeslot
- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException
- iftk
isvoid
orslot
is out of range- See Also:
-
branch
Generates a branch instruction.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS
is set, the opcode has size 3, andtarget
cannot be encoded as a BCI offset in[-32768, 32767]
.- Parameters:
op
- the branch opcodetarget
- the branch target- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifop
is not ofOpcode.Kind.BRANCH
- See Also:
-
return_
Generates a return instruction.- Parameters:
tk
- the return type- Returns:
- this builder
- See Also:
-
fieldAccess
Generates an instruction to access a field.- Parameters:
opcode
- the field access opcoderef
- the field reference- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifopcode
is not ofOpcode.Kind.FIELD_ACCESS
- See Also:
-
fieldAccess
Generates an instruction to access a field.- Parameters:
opcode
- the field access opcodeowner
- the classname
- the field nametype
- the field type- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifopcode
is not ofOpcode.Kind.FIELD_ACCESS
, orowner
is primitive- See Also:
-
invoke
Generates an instruction to invoke a method.- Parameters:
opcode
- the invoke opcoderef
- the interface method or method reference- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifopcode
is not ofOpcode.Kind.INVOKE
- See Also:
-
invoke
default CodeBuilder invoke(Opcode opcode, ClassDesc owner, String name, MethodTypeDesc desc, boolean isInterface) Generates an instruction to invoke a method.- Parameters:
opcode
- the invoke opcodeowner
- the classname
- the method namedesc
- the method typeisInterface
- whether the owner class is an interface- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifopcode
is not ofOpcode.Kind.INVOKE
, orowner
is primitive- See Also:
-
arrayLoad
Generates an instruction to load from an array.- Parameters:
tk
- the array element type- Returns:
- this builder
- Throws:
IllegalArgumentException
- iftk
isvoid
- See Also:
-
arrayStore
Generates an instruction to store into an array.- Parameters:
tk
- the array element type- Returns:
- this builder
- Throws:
IllegalArgumentException
- iftk
isvoid
- See Also:
-
conversion
Generates instruction(s) to convertfromType
totoType
.- Parameters:
fromType
- the source typetoType
- the target type- Returns:
- this builder
- Throws:
IllegalArgumentException
- for conversions ofvoid
orreference
- See Also:
-
loadConstant
Generates an instruction pushing a constant onto the operand stack.- Parameters:
value
- the constant value, may benull
- Returns:
- this builder
- See Also:
-
loadConstant
Generates an instruction pushing a constantint
value onto the operand stack. This is equivalent toloadConstant(Integer.valueOf(value))
.- Parameters:
value
- the int value- Returns:
- this builder
- See Also:
-
loadConstant
Generates an instruction pushing a constantlong
value onto the operand stack. This is equivalent toloadConstant(Long.valueOf(value))
.- Parameters:
value
- the long value- Returns:
- this builder
- See Also:
-
loadConstant
Generates an instruction pushing a constantfloat
value onto the operand stack. This is equivalent toloadConstant(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
Generates an instruction pushing a constantdouble
value onto the operand stack. This is equivalent toloadConstant(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
-
newBoundLabel
Creates a new label bound at the current position.- Returns:
- this builder
- See Also:
-
labelBinding
Binds a label to the current position.- 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
Declares a source line number beginning at the current position.This call may be ignored according to
ClassFile.LineNumbersOption
.- Parameters:
line
- the line number- Returns:
- this builder
- See Also:
-
exceptionCatch
Declares an exception table entry.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 startend
- the try block endhandler
- the exception handler startcatchType
- the catch type, may benull
to catch all exceptions and errors- Returns:
- this builder
- See Also:
-
exceptionCatch
default CodeBuilder exceptionCatch(Label start, Label end, Label handler, Optional<ClassEntry> catchType) Declares an exception table entry.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 startend
- the try block endhandler
- the exception handler startcatchType
- the optional catch type, empty to catch all exceptions and errors- Returns:
- this builder
- See Also:
-
exceptionCatch
Declares an exception table entry.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 startend
- the try block endhandler
- the exception handler startcatchType
- the catch type- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifcatchType
is primitive- See Also:
-
exceptionCatchAll
Declares an exception table entry catching all exceptions and errors.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 startend
- the try block endhandler
- the exception handler start- Returns:
- this builder
- See Also:
-
characterRange
default CodeBuilder characterRange(Label startScope, Label endScope, int characterRangeStart, int characterRangeEnd, int flags) Declares a character range entry.This call may be ignored if
ClassFile.DebugElementsOption.DROP_DEBUG
is set, or if any of the argument labels is not bound andClassFile.DeadLabelsOption.DROP_DEAD_LABELS
is set.- Parameters:
startScope
- the start scope of the character rangeendScope
- the end scope of the character rangecharacterRangeStart
- 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
- See Also:
-
localVariable
default CodeBuilder localVariable(int slot, Utf8Entry nameEntry, Utf8Entry descriptorEntry, Label startScope, Label endScope) Declares a local variable entry.This call may be ignored if
ClassFile.DebugElementsOption.DROP_DEBUG
is set, or if any of the argument labels is not bound andClassFile.DeadLabelsOption.DROP_DEAD_LABELS
is set.- Parameters:
slot
- the local variable slotnameEntry
- the variable namedescriptorEntry
- the variable descriptorstartScope
- the start scope of the variableendScope
- the end scope of the variable- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifslot
is out of range- See Also:
-
localVariable
default CodeBuilder localVariable(int slot, String name, ClassDesc descriptor, Label startScope, Label endScope) Declares a local variable entry.This call may be ignored if
ClassFile.DebugElementsOption.DROP_DEBUG
is set, or if any of the argument labels is not bound andClassFile.DeadLabelsOption.DROP_DEAD_LABELS
is set.- Parameters:
slot
- the local variable slotname
- the variable namedescriptor
- the variable descriptorstartScope
- the start scope of the variableendScope
- the end scope of the variable- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifslot
is out of range- See Also:
-
localVariableType
default CodeBuilder localVariableType(int slot, Utf8Entry nameEntry, Utf8Entry signatureEntry, Label startScope, Label endScope) Declares a local variable type entry.This call may be ignored if
ClassFile.DebugElementsOption.DROP_DEBUG
is set, or if any of the argument labels is not bound andClassFile.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 slotnameEntry
- the variable namesignatureEntry
- the variable signaturestartScope
- the start scope of the variableendScope
- the end scope of the variable- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifslot
is out of range- See Also:
-
localVariableType
default CodeBuilder localVariableType(int slot, String name, Signature signature, Label startScope, Label endScope) Declares a local variable type entry.This call may be ignored if
ClassFile.DebugElementsOption.DROP_DEBUG
is set, or if any of the argument labels is not bound andClassFile.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 slotname
- the variable namesignature
- the variable signaturestartScope
- the start scope of the variableendScope
- the end scope of the variable- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifslot
is out of range- See Also:
-
aconst_null
Generates an instruction pushing the null objectreference
onto the operand stack.- Returns:
- this builder
- See Also:
-
aaload
Generates an instruction to load from areference
array.- Returns:
- this builder
- See Also:
-
aastore
Generates an instruction to store into areference
array.- Returns:
- this builder
- See Also:
-
aload
Generates an instruction to load areference
from a local variable.This may also generate
aload_<N>
andwide aload
instructions.- Parameters:
slot
- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifslot
is out of range- See Also:
-
anewarray
Generates an instruction to create a new array ofreference
.- Parameters:
classEntry
- the component type- Returns:
- this builder
- See Also:
-
anewarray
Generates an instruction to create a new array ofreference
.- Parameters:
className
- the component type- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifclassName
represents a primitive type- See Also:
-
areturn
Generates an instruction to return areference
from this method.- Returns:
- this builder
- See Also:
-
arraylength
Generates an instruction to get the length of an array.- Returns:
- this builder
- See Also:
-
astore
Generates an instruction to store areference
into a local variable. Such an instruction can also store areturnAddress
.This may also generate
astore_<N>
andwide astore
instructions.- Parameters:
slot
- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifslot
is out of range- See Also:
-
athrow
Generates an instruction to throw an exception or error.- Returns:
- this builder
- See Also:
-
baload
- Returns:
- this builder
- See Also:
-
bastore
- Returns:
- this builder
- See Also:
-
bipush
- Parameters:
b
- the int in the range of byte- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifb
is out of range of byte- See Also:
-
caload
Generates an instruction to load from achar
array.- Returns:
- this builder
- See Also:
-
castore
Generates an instruction to store into achar
array.- Returns:
- this builder
- See Also:
-
checkcast
Generates an instruction to check whether an object is of the given type, throwing aClassCastException
if the check fails.- Parameters:
type
- the object type- Returns:
- this builder
- See Also:
-
checkcast
Generates an instruction to check whether an object is of the given type, throwing aClassCastException
if the check fails.- Parameters:
type
- the object type- Returns:
- this builder
- Throws:
IllegalArgumentException
- iftype
represents a primitive type- See Also:
-
d2f
- Returns:
- this builder
- See Also:
-
d2i
- Returns:
- this builder
- See Also:
-
d2l
- Returns:
- this builder
- See Also:
-
dadd
Generates an instruction to add twodoubles
.- Returns:
- this builder
- See Also:
-
daload
Generates an instruction to load from adouble
array.- Returns:
- this builder
- See Also:
-
dastore
Generates an instruction to store into adouble
array.- Returns:
- this builder
- See Also:
-
dcmpg
- Returns:
- this builder
- See Also:
-
dcmpl
- Returns:
- this builder
- See Also:
-
dconst_0
Generates an instruction pushingdouble
constant 0 onto the operand stack.- Returns:
- this builder
- See Also:
-
dconst_1
Generates an instruction pushingdouble
constant 1 onto the operand stack.- Returns:
- this builder
- See Also:
-
ddiv
Generates an instruction to dividedoubles
.- Returns:
- this builder
- See Also:
-
dload
Generates an instruction to load adouble
from a local variable.This may also generate
dload_<N>
andwide dload
instructions.- Parameters:
slot
- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifslot
is out of range- See Also:
-
dmul
Generates an instruction to multiplydoubles
.- Returns:
- this builder
- See Also:
-
dneg
Generates an instruction to negate adouble
.- Returns:
- this builder
- See Also:
-
drem
Generates an instruction to calculatedouble
remainder.- Returns:
- this builder
- See Also:
-
dreturn
Generates an instruction to return adouble
from this method.- Returns:
- this builder
- See Also:
-
dstore
Generates an instruction to store adouble
into a local variable.This may also generate
dstore_<N>
andwide dstore
instructions.- Parameters:
slot
- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifslot
is out of range- See Also:
-
dsub
Generates an instruction to subtractdoubles
.- Returns:
- this builder
- See Also:
-
dup
Generates an instruction to duplicate the top operand stack value.- Returns:
- this builder
- See Also:
-
dup2
Generates an instruction to duplicate the top one or two operand stack value.- Returns:
- this builder
- See Also:
-
dup2_x1
Generates an instruction to duplicate the top one or two operand stack values and insert two or three values down.- Returns:
- this builder
- See Also:
-
dup2_x2
Generates an instruction to duplicate the top one or two operand stack values and insert two, three, or four values down.- Returns:
- this builder
- See Also:
-
dup_x1
Generates an instruction to duplicate the top operand stack value and insert two values down.- Returns:
- this builder
- See Also:
-
dup_x2
Generates an instruction to duplicate the top operand stack value and insert two or three values down.- Returns:
- this builder
- See Also:
-
f2d
- Returns:
- this builder
- See Also:
-
f2i
- Returns:
- this builder
- See Also:
-
f2l
- Returns:
- this builder
- See Also:
-
fadd
Generates an instruction to add twofloats
.- Returns:
- this builder
- See Also:
-
faload
Generates an instruction to load from afloat
array.- Returns:
- this builder
- See Also:
-
fastore
Generates an instruction to store into afloat
array.- Returns:
- this builder
- See Also:
-
fcmpg
- Returns:
- this builder
- See Also:
-
fcmpl
- Returns:
- this builder
- See Also:
-
fconst_0
Generates an instruction pushingfloat
constant 0 onto the operand stack.- Returns:
- this builder
- See Also:
-
fconst_1
Generates an instruction pushingfloat
constant 1 onto the operand stack.- Returns:
- this builder
- See Also:
-
fconst_2
Generates an instruction pushingfloat
constant 2 onto the operand stack.- Returns:
- this builder
- See Also:
-
fdiv
Generates an instruction to dividefloats
.- Returns:
- this builder
- See Also:
-
fload
Generates an instruction to load afloat
from a local variable.This may also generate
fload_<N>
andwide fload
instructions.- Parameters:
slot
- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifslot
is out of range- See Also:
-
fmul
Generates an instruction to multiplyfloats
.- Returns:
- this builder
- See Also:
-
fneg
Generates an instruction to negate afloat
.- Returns:
- this builder
- See Also:
-
frem
Generates an instruction to calculatefloats
remainder.- Returns:
- this builder
- See Also:
-
freturn
Generates an instruction to return afloat
from this method.- Returns:
- this builder
- See Also:
-
fstore
Generates an instruction to store afloat
into a local variable.This may also generate
fstore_<N>
andwide fstore
instructions.- Parameters:
slot
- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifslot
is out of range- See Also:
-
fsub
Generates an instruction to subtractfloats
.- Returns:
- this builder
- See Also:
-
getfield
Generates an instruction to fetch field from an object.- Parameters:
ref
- the field reference- Returns:
- this builder
- See Also:
-
getfield
Generates an instruction to fetch field from an object.- Parameters:
owner
- the owner classname
- the field nametype
- the field type- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifowner
represents a primitive type- See Also:
-
getstatic
Generates an instruction to get static field from a class or interface.- Parameters:
ref
- the field reference- Returns:
- this builder
- See Also:
-
getstatic
Generates an instruction to get static field from a class or interface.- Parameters:
owner
- the owner classname
- the field nametype
- the field type- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifowner
represents a primitive type- See Also:
-
goto_
Generates an instruction to branch always.This may also generate
goto_w
instructions ifClassFile.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
Generates an instruction to branch always with wide index.- Parameters:
target
- the branch target- Returns:
- this builder
- See Also:
-
i2b
- Returns:
- this builder
- See Also:
-
i2c
- Returns:
- this builder
- See Also:
-
i2d
- Returns:
- this builder
- See Also:
-
i2f
- Returns:
- this builder
- See Also:
-
i2l
- Returns:
- this builder
- See Also:
-
i2s
- Returns:
- this builder
- See Also:
-
iadd
Generates an instruction to add twoints
.- Returns:
- this builder
- See Also:
-
iaload
Generates an instruction to load from anint
array.- Returns:
- this builder
- See Also:
-
iand
- Returns:
- this builder
- See Also:
-
iastore
Generates an instruction to store into anint
array.- Returns:
- this builder
- See Also:
-
iconst_0
Generates an instruction pushingint
constant 0 onto the operand stack.- Returns:
- this builder
- See Also:
-
iconst_1
Generates an instruction pushingint
constant 1 onto the operand stack.- Returns:
- this builder
- See Also:
-
iconst_2
Generates an instruction pushingint
constant 2 onto the operand stack.- Returns:
- this builder
- See Also:
-
iconst_3
Generates an instruction pushingint
constant 3 onto the operand stack.- Returns:
- this builder
- See Also:
-
iconst_4
Generates an instruction pushingint
constant 4 onto the operand stack.- Returns:
- this builder
- See Also:
-
iconst_5
Generates an instruction pushingint
constant 5 onto the operand stack.- Returns:
- this builder
- See Also:
-
iconst_m1
Generates an instruction pushingint
constant -1 onto the operand stack.- Returns:
- this builder
- See Also:
-
idiv
-
if_acmpeq
Generates an instruction to branch ifreference
comparisonoperand1 == operand2
succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS
is set andtarget
cannot be encoded as a BCI offset in[-32768, 32767]
.- Parameters:
target
- the branch target- Returns:
- this builder
- See Also:
-
if_acmpne
Generates an instruction to branch ifreference
comparisonoperand1 != operand2
succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS
is set andtarget
cannot be encoded as a BCI offset in[-32768, 32767]
.- Parameters:
target
- the branch target- Returns:
- this builder
- See Also:
-
if_icmpeq
Generates an instruction to branch ifint
comparisonoperand1 == operand2
succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS
is set andtarget
cannot be encoded as a BCI offset in[-32768, 32767]
.- Parameters:
target
- the branch target- Returns:
- this builder
- See Also:
-
if_icmpge
Generates an instruction to branch ifint
comparisonoperand1 >= operand2
succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS
is set andtarget
cannot be encoded as a BCI offset in[-32768, 32767]
.- Parameters:
target
- the branch target- Returns:
- this builder
- See Also:
-
if_icmpgt
Generates an instruction to branch ifint
comparisonoperand1 > operand2
succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS
is set andtarget
cannot be encoded as a BCI offset in[-32768, 32767]
.- Parameters:
target
- the branch target- Returns:
- this builder
- See Also:
-
if_icmple
Generates an instruction to branch ifint
comparisonoperand1 <= operand2
succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS
is set andtarget
cannot be encoded as a BCI offset in[-32768, 32767]
.- Parameters:
target
- the branch target- Returns:
- this builder
- See Also:
-
if_icmplt
Generates an instruction to branch ifint
comparisonoperand1 < operand2
succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS
is set andtarget
cannot be encoded as a BCI offset in[-32768, 32767]
.- Parameters:
target
- the branch target- Returns:
- this builder
- See Also:
-
if_icmpne
Generates an instruction to branch ifint
comparisonoperand1 != operand2
succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS
is set andtarget
cannot be encoded as a BCI offset in[-32768, 32767]
.- Parameters:
target
- the branch target- Returns:
- this builder
- See Also:
-
ifnonnull
Generates an instruction to branch ifreference
is notnull
.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS
is set andtarget
cannot be encoded as a BCI offset in[-32768, 32767]
.- Parameters:
target
- the branch target- Returns:
- this builder
- See Also:
-
ifnull
Generates an instruction to branch ifreference
isnull
.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS
is set andtarget
cannot be encoded as a BCI offset in[-32768, 32767]
.- Parameters:
target
- the branch target- Returns:
- this builder
- See Also:
-
ifeq
Generates an instruction to branch ifint
comparison with zero== 0
succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS
is set andtarget
cannot be encoded as a BCI offset in[-32768, 32767]
.- Parameters:
target
- the branch target- Returns:
- this builder
- See Also:
-
ifge
Generates an instruction to branch ifint
comparison with zero>= 0
succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS
is set andtarget
cannot be encoded as a BCI offset in[-32768, 32767]
.- Parameters:
target
- the branch target- Returns:
- this builder
- See Also:
-
ifgt
Generates an instruction to branch ifint
comparison with zero> 0
succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS
is set andtarget
cannot be encoded as a BCI offset in[-32768, 32767]
.- Parameters:
target
- the branch target- Returns:
- this builder
- See Also:
-
ifle
Generates an instruction to branch ifint
comparison with zero<= 0
succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS
is set andtarget
cannot be encoded as a BCI offset in[-32768, 32767]
.- Parameters:
target
- the branch target- Returns:
- this builder
- See Also:
-
iflt
Generates an instruction to branch ifint
comparison with zero< 0
succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS
is set andtarget
cannot be encoded as a BCI offset in[-32768, 32767]
.- Parameters:
target
- the branch target- Returns:
- this builder
- See Also:
-
ifne
Generates an instruction to branch ifint
comparison with zero!= 0
succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS
is set andtarget
cannot be encoded as a BCI offset in[-32768, 32767]
.- Parameters:
target
- the branch target- Returns:
- this builder
- See Also:
-
iinc
Generates an instruction to increment anint
local variable by a constant.This may also generate
wide iinc
instructions ifslot
exceeds255
orval
exceeds the range ofbyte
.- Parameters:
slot
- the local variable slotval
- the increment value- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifslot
orval
is out of range- See Also:
-
iload
Generates an instruction to load anint
from a local variable.This may also generate
iload_<N>
andwide iload
instructions.- Parameters:
slot
- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifslot
is out of range- See Also:
-
imul
Generates an instruction to multiplyints
.- Returns:
- this builder
- See Also:
-
ineg
Generates an instruction to negate anint
.- Returns:
- this builder
- See Also:
-
instanceOf
Generates an instruction to determine if an object is of the given type, producing aboolean
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
Generates an instruction to determine if an object is of the given type, producing aboolean
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
- iftarget
represents a primitive type- See Also:
-
invokedynamic
Generates an instruction to invoke a dynamically-computed call site.- Parameters:
ref
- the dynamic call site- Returns:
- this builder
- See Also:
-
invokedynamic
Generates an instruction to invoke a dynamically-computed call site.- Parameters:
ref
- the dynamic call site- Returns:
- this builder
- See Also:
-
invokeinterface
Generates an instruction to invoke an interface method.- Parameters:
ref
- the interface method reference- Returns:
- this builder
- See Also:
-
invokeinterface
Generates an instruction to invoke an interface method.- Parameters:
owner
- the owner interfacename
- the method nametype
- the method type- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifowner
represents a primitive type- See Also:
-
invokespecial
Generates an instruction to invoke an instance method in an interface; direct invocation of methods of the current class and its supertypes.- Parameters:
ref
- the interface method reference- Returns:
- this builder
- See Also:
-
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.- Parameters:
ref
- the method reference- Returns:
- this builder
- See Also:
-
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.- Parameters:
owner
- the owner class, must not be an interfacename
- the method nametype
- the method type- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifowner
represents a primitive type- See Also:
-
invokespecial
default CodeBuilder invokespecial(ClassDesc owner, String name, MethodTypeDesc type, boolean isInterface) Generates an instruction to invoke an instance method; direct invocation of instance initialization methods and methods of the current class and its supertypes.- Parameters:
owner
- the owner class or interfacename
- the method nametype
- the method typeisInterface
- whether the owner is an interface- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifowner
represents a primitive type- See Also:
-
invokestatic
Generates an instruction to invoke a class (static) method of an interface.- Parameters:
ref
- the interface method reference- Returns:
- this builder
- See Also:
-
invokestatic
Generates an instruction to invoke a class (static) method of a class.- Parameters:
ref
- the method reference- Returns:
- this builder
- See Also:
-
invokestatic
Generates an instruction to invoke a class (static) method of a class.- Parameters:
owner
- the owner class, must not be an interfacename
- the method nametype
- the method type- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifowner
represents a primitive type- See Also:
-
invokestatic
default CodeBuilder invokestatic(ClassDesc owner, String name, MethodTypeDesc type, boolean isInterface) Generates an instruction to invoke a class (static) method.- Parameters:
owner
- the owner class or interfacename
- the method nametype
- the method typeisInterface
- whether the owner is an interface- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifowner
represents a primitive type- See Also:
-
invokevirtual
Generates an instruction to invoke an instance method; dispatch based on class.- Parameters:
ref
- the method reference- Returns:
- this builder
- See Also:
-
invokevirtual
Generates an instruction to invoke an instance method; dispatch based on class.- Parameters:
owner
- the owner class, must not be an interfacename
- the method nametype
- the method type- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifowner
represents a primitive type- See Also:
-
ior
- Returns:
- this builder
- See Also:
-
irem
Generates an instruction to calculateints
remainder.- Returns:
- this builder
- See Also:
-
ireturn
Generates an instruction to return anint
from this method.- Returns:
- this builder
- See Also:
-
ishl
Generates an instruction to shift anint
left.- Returns:
- this builder
- See Also:
-
ishr
-
istore
Generates an instruction to store anint
into a local variable.This may also generate
istore_<N>
andwide istore
instructions.- Parameters:
slot
- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifslot
is out of range- See Also:
-
isub
Generates an instruction to subtractints
.- Returns:
- this builder
- See Also:
-
iushr
-
ixor
- Returns:
- this builder
- See Also:
-
lookupswitch
Generates an instruction to access a jump table by key match and jump.- Parameters:
defaultTarget
- the default jump targetcases
- the switch cases- Returns:
- this builder
- See Also:
-
l2d
- Returns:
- this builder
- See Also:
-
l2f
- Returns:
- this builder
- See Also:
-
l2i
- Returns:
- this builder
- See Also:
-
ladd
Generates an instruction to add twolongs
.- Returns:
- this builder
- See Also:
-
laload
Generates an instruction to load from along
array.- Returns:
- this builder
- See Also:
-
land
Generates an instruction to calculate bitwise AND oflongs
.- Returns:
- this builder
- See Also:
-
lastore
Generates an instruction to store into along
array.- Returns:
- this builder
- See Also:
-
lcmp
Generates an instruction to comparelongs
.- Returns:
- this builder
- See Also:
-
lconst_0
Generates an instruction pushinglong
constant 0 onto the operand stack.- Returns:
- this builder
- See Also:
-
lconst_1
Generates an instruction pushinglong
constant 1 onto the operand stack.- Returns:
- this builder
- See Also:
-
ldc
Generates an instruction pushing an item from the run-time constant pool onto the operand stack.- API Note:
loadConstant
generates more optimal instructions and should be used for general constants if anldc
instruction is not strictly required.- Parameters:
value
- the constant value- Returns:
- this builder
- See Also:
-
ldc
Generates an instruction pushing an item from the run-time constant pool onto the operand stack.- Parameters:
entry
- the constant value- Returns:
- this builder
- See Also:
-
ldiv
Generates an instruction to dividelongs
.- Returns:
- this builder
- See Also:
-
lload
Generates an instruction to load along
from a local variable.This may also generate
lload_<N>
andwide lload
instructions.- Parameters:
slot
- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifslot
is out of range- See Also:
-
lmul
Generates an instruction to multiplylongs
.- Returns:
- this builder
- See Also:
-
lneg
Generates an instruction to negate along
.- Returns:
- this builder
- See Also:
-
lor
Generates an instruction to calculate bitwise OR oflongs
.- Returns:
- this builder
- See Also:
-
lrem
Generates an instruction to calculatelongs
remainder.- Returns:
- this builder
- See Also:
-
lreturn
Generates an instruction to return along
from this method.- Returns:
- this builder
- See Also:
-
lshl
Generates an instruction to shift along
left.- Returns:
- this builder
- See Also:
-
lshr
-
lstore
Generates an instruction to store along
into a local variable.This may also generate
lstore_<N>
andwide lstore
instructions.- Parameters:
slot
- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifslot
is out of range- See Also:
-
lsub
Generates an instruction to subtractlongs
.- Returns:
- this builder
- See Also:
-
lushr
-
lxor
Generates an instruction to calculate bitwise XOR oflongs
.- Returns:
- this builder
- See Also:
-
monitorenter
Generates an instruction to enter monitor for an object.- Returns:
- this builder
- See Also:
-
monitorexit
Generates an instruction to exit monitor for an object.- Returns:
- this builder
- See Also:
-
multianewarray
Generates an instruction to create a new multidimensional array.- Parameters:
array
- the array typedims
- the number of dimensions- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifdims
is out of range- See Also:
-
multianewarray
Generates an instruction to create a new multidimensional array.- Parameters:
array
- the array typedims
- the number of dimensions- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifarray
represents a primitive type or ifdims
is out of range- See Also:
-
new_
Generates an instruction to create a new object.- 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_
Generates an instruction to create a new object.- 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
- ifclazz
represents a primitive type- See Also:
-
newarray
Generates an instruction to create a new array of a primitive type.- Parameters:
typeKind
- the primitive array type- Returns:
- this builder
- Throws:
IllegalArgumentException
- when thetypeKind
is not a legal primitive array component type- See Also:
-
pop
Generates an instruction to pop the top operand stack value.- Returns:
- this builder
- See Also:
-
pop2
Generates an instruction to pop the top one or two operand stack values.- Returns:
- this builder
- See Also:
-
putfield
Generates an instruction to set field in an object.- Parameters:
ref
- the field reference- Returns:
- this builder
- See Also:
-
putfield
Generates an instruction to set field in an object.- Parameters:
owner
- the owner classname
- the field nametype
- the field type- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifowner
represents a primitive type- See Also:
-
putstatic
Generates an instruction to set static field in a class.- Parameters:
ref
- the field reference- Returns:
- this builder
- See Also:
-
putstatic
Generates an instruction to set static field in a class.- Parameters:
owner
- the owner class or interfacename
- the field nametype
- the field type- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifowner
represents a primitive type- See Also:
-
return_
Generates an instruction to returnvoid
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
Generates an instruction to load from ashort
array.- Returns:
- this builder
- See Also:
-
sastore
Generates an instruction to store into ashort
array.- Returns:
- this builder
- See Also:
-
sipush
Generates an instruction pushing anint
in the range ofshort
,[-32768, 32767]
, onto the operand stack.- Parameters:
s
- the int in the range of short- Returns:
- this builder
- Throws:
IllegalArgumentException
- ifs
is out of range of short- See Also:
-
swap
Generates an instruction to swap the top two operand stack values.- Returns:
- this builder
- See Also:
-
tableswitch
Generates an instruction to access a jump table by index and jump.- Parameters:
low
- the minimum key, inclusivehigh
- the maximum key, inclusivedefaultTarget
- the default jump targetcases
- the switch cases- Returns:
- this builder
- See Also:
-
tableswitch
Generates an instruction to access a jump table by index and jump. Computes the minimum and maximum keys from thecases
.- Parameters:
defaultTarget
- the default jump targetcases
- the switch cases- Returns:
- this builder
- See Also:
-