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_worwide, share their factories with their regular version likeldc(java.lang.constant.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
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA builder for blocks of code.static interfaceA builder to add catch blocks. -
Method Summary
Modifier and TypeMethodDescriptiondefault CodeBuilderaaload()Generates an instruction to load from areferencearray.default CodeBuilderaastore()Generates an instruction to store into areferencearray.default CodeBuilderGenerates an instruction pushing the null objectreferenceonto the operand stack.intallocateLocal(TypeKind typeKind) Returns the local variable slot of a fresh local variable.default CodeBuilderaload(int slot) Generates an instruction to load areferencefrom a local variable.default CodeBuilderanewarray(ClassEntry classEntry) Generates an instruction to create a new array ofreference.default CodeBuilderGenerates an instruction to create a new array ofreference.default CodeBuilderareturn()Generates an instruction to return areferencefrom this method.default CodeBuilderGenerates an instruction to get the length of an array.default CodeBuilderGenerates an instruction to load from an array.default CodeBuilderarrayStore(TypeKind tk) Generates an instruction to store into an array.default CodeBuilderastore(int slot) Generates an instruction to store areferenceinto a local variable.default CodeBuilderathrow()Generates an instruction to throw an exception or error.default CodeBuilderbaload()default CodeBuilderbastore()default CodeBuilderbipush(int b) default CodeBuilderblock(Consumer<CodeBuilder.BlockCodeBuilder> handler) Adds a lexical block to the method being built.default CodeBuilderGenerates a branch instruction.default CodeBuildercaload()Generates an instruction to load from achararray.default CodeBuildercastore()Generates an instruction to store into achararray.default CodeBuildercharacterRange(Label startScope, Label endScope, int characterRangeStart, int characterRangeEnd, int flags) Declares a character range entry.default CodeBuildercheckcast(ClassEntry type) Generates an instruction to check whether an object is of the given type, throwing aClassCastExceptionif the check fails.default CodeBuilderGenerates an instruction to check whether an object is of the given type, throwing aClassCastExceptionif the check fails.default CodeBuilderconversion(TypeKind fromType, TypeKind toType) Generates instruction(s) to convertfromTypetotoType.default CodeBuilderd2f()default CodeBuilderd2i()default CodeBuilderd2l()default CodeBuilderdadd()Generates an instruction to add twodoubles.default CodeBuilderdaload()Generates an instruction to load from adoublearray.default CodeBuilderdastore()Generates an instruction to store into adoublearray.default CodeBuilderdcmpg()default CodeBuilderdcmpl()default CodeBuilderdconst_0()Generates an instruction pushingdoubleconstant 0 onto the operand stack.default CodeBuilderdconst_1()Generates an instruction pushingdoubleconstant 1 onto the operand stack.default CodeBuilderddiv()Generates an instruction to dividedoubles.default CodeBuilderdload(int slot) Generates an instruction to load adoublefrom a local variable.default CodeBuilderdmul()Generates an instruction to multiplydoubles.default CodeBuilderdneg()Generates an instruction to negate adouble.default CodeBuilderdrem()Generates an instruction to calculatedoubleremainder.default CodeBuilderdreturn()Generates an instruction to return adoublefrom this method.default CodeBuilderdstore(int slot) Generates an instruction to store adoubleinto a local variable.default CodeBuilderdsub()Generates an instruction to subtractdoubles.default CodeBuilderdup()Generates an instruction to duplicate the top operand stack value.default CodeBuilderdup_x1()Generates an instruction to duplicate the top operand stack value and insert two values down.default CodeBuilderdup_x2()Generates an instruction to duplicate the top operand stack value and insert two or three values down.default CodeBuilderdup2()Generates an instruction to duplicate the top one or two operand stack value.default CodeBuilderdup2_x1()Generates an instruction to duplicate the top one or two operand stack values and insert two or three values down.default CodeBuilderdup2_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 CodeBuilderexceptionCatch(Label start, Label end, Label handler, ClassEntry catchType) Declares an exception table entry.default CodeBuilderexceptionCatch(Label start, Label end, Label handler, ClassDesc catchType) Declares an exception table entry.default CodeBuilderexceptionCatch(Label start, Label end, Label handler, Optional<ClassEntry> catchType) Declares an exception table entry.default CodeBuilderexceptionCatchAll(Label start, Label end, Label handler) Declares an exception table entry catching all exceptions and errors.default CodeBuilderf2d()default CodeBuilderf2i()default CodeBuilderf2l()default CodeBuilderfadd()Generates an instruction to add twofloats.default CodeBuilderfaload()Generates an instruction to load from afloatarray.default CodeBuilderfastore()Generates an instruction to store into afloatarray.default CodeBuilderfcmpg()default CodeBuilderfcmpl()default CodeBuilderfconst_0()Generates an instruction pushingfloatconstant 0 onto the operand stack.default CodeBuilderfconst_1()Generates an instruction pushingfloatconstant 1 onto the operand stack.default CodeBuilderfconst_2()Generates an instruction pushingfloatconstant 2 onto the operand stack.default CodeBuilderfdiv()Generates an instruction to dividefloats.default CodeBuilderfieldAccess(Opcode opcode, FieldRefEntry ref) Generates an instruction to access a field.default CodeBuilderfieldAccess(Opcode opcode, ClassDesc owner, String name, ClassDesc type) Generates an instruction to access a field.default CodeBuilderfload(int slot) Generates an instruction to load afloatfrom a local variable.default CodeBuilderfmul()Generates an instruction to multiplyfloats.default CodeBuilderfneg()Generates an instruction to negate afloat.default CodeBuilderfrem()Generates an instruction to calculatefloatsremainder.default CodeBuilderfreturn()Generates an instruction to return afloatfrom this method.default CodeBuilderfstore(int slot) Generates an instruction to store afloatinto a local variable.default CodeBuilderfsub()Generates an instruction to subtractfloats.default CodeBuildergetfield(FieldRefEntry ref) Generates an instruction to fetch field from an object.default CodeBuilderGenerates an instruction to fetch field from an object.default CodeBuildergetstatic(FieldRefEntry ref) Generates an instruction to get static field from a class or interface.default CodeBuilderGenerates an instruction to get static field from a class or interface.default CodeBuilderGenerates an instruction to branch always.default CodeBuilderGenerates an instruction to branch always with wide index.default CodeBuilderi2b()default CodeBuilderi2c()default CodeBuilderi2d()default CodeBuilderi2f()default CodeBuilderi2l()default CodeBuilderi2s()default CodeBuilderiadd()Generates an instruction to add twoints.default CodeBuilderiaload()Generates an instruction to load from anintarray.default CodeBuilderiand()default CodeBuilderiastore()Generates an instruction to store into anintarray.default CodeBuildericonst_0()Generates an instruction pushingintconstant 0 onto the operand stack.default CodeBuildericonst_1()Generates an instruction pushingintconstant 1 onto the operand stack.default CodeBuildericonst_2()Generates an instruction pushingintconstant 2 onto the operand stack.default CodeBuildericonst_3()Generates an instruction pushingintconstant 3 onto the operand stack.default CodeBuildericonst_4()Generates an instruction pushingintconstant 4 onto the operand stack.default CodeBuildericonst_5()Generates an instruction pushingintconstant 5 onto the operand stack.default CodeBuilderGenerates an instruction pushingintconstant -1 onto the operand stack.default CodeBuilderidiv()Generates an instruction to divideints.default CodeBuilderGenerates an instruction to branch ifreferencecomparisonoperand1 == operand2succeeds.default CodeBuilderGenerates an instruction to branch ifreferencecomparisonoperand1 != operand2succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparisonoperand1 == operand2succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparisonoperand1 >= operand2succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparisonoperand1 > operand2succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparisonoperand1 <= operand2succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparisonoperand1 < operand2succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparisonoperand1 != operand2succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparison with zero== 0succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparison with zero>= 0succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparison with zero> 0succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparison with zero<= 0succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparison with zero< 0succeeds.default CodeBuilderGenerates an instruction to branch ifintcomparison with zero!= 0succeeds.default CodeBuilderGenerates an instruction to branch ifreferenceis notnull.default CodeBuilderGenerates an instruction to branch ifreferenceisnull.default CodeBuilderifThen(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 CodeBuilderifThen(Consumer<CodeBuilder.BlockCodeBuilder> thenHandler) Adds an "if-then" block that is conditional on thebooleanvalue on top of the operand stack.default CodeBuilderifThenElse(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 CodeBuilderifThenElse(Consumer<CodeBuilder.BlockCodeBuilder> thenHandler, Consumer<CodeBuilder.BlockCodeBuilder> elseHandler) Adds an "if-then-else" block that is conditional on thebooleanvalue on top of the operand stack.default CodeBuilderiinc(int slot, int val) Generates an instruction to increment anintlocal variable by a constant.default CodeBuilderiload(int slot) Generates an instruction to load anintfrom a local variable.default CodeBuilderimul()Generates an instruction to multiplyints.default CodeBuilderineg()Generates an instruction to negate anint.default CodeBuilderinstanceOf(ClassEntry target) Generates an instruction to determine if an object is of the given type, producing abooleanresult on the operand stack.default CodeBuilderinstanceOf(ClassDesc target) Generates an instruction to determine if an object is of the given type, producing abooleanresult on the operand stack.default CodeBuilderinvoke(Opcode opcode, MemberRefEntry ref) Generates an instruction to invoke a method.default CodeBuilderinvoke(Opcode opcode, ClassDesc owner, String name, MethodTypeDesc desc, boolean isInterface) Generates an instruction to invoke a method.default CodeBuilderGenerates an instruction to invoke a dynamically-computed call site.default CodeBuilderGenerates an instruction to invoke a dynamically-computed call site.default CodeBuilderGenerates an instruction to invoke an interface method.default CodeBuilderinvokeinterface(ClassDesc owner, String name, MethodTypeDesc type) Generates an instruction to invoke an interface method.default CodeBuilderGenerates an instruction to invoke an instance method in an interface; direct invocation of methods of the current class and its supertypes.default CodeBuilderGenerates 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 CodeBuilderinvokespecial(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 CodeBuilderinvokespecial(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 CodeBuilderGenerates an instruction to invoke a class (static) method of an interface.default CodeBuilderGenerates an instruction to invoke a class (static) method of a class.default CodeBuilderinvokestatic(ClassDesc owner, String name, MethodTypeDesc type) Generates an instruction to invoke a class (static) method of a class.default CodeBuilderinvokestatic(ClassDesc owner, String name, MethodTypeDesc type, boolean isInterface) Generates an instruction to invoke a class (static) method.default CodeBuilderGenerates an instruction to invoke an instance method; dispatch based on class.default CodeBuilderinvokevirtual(ClassDesc owner, String name, MethodTypeDesc type) Generates an instruction to invoke an instance method; dispatch based on class.default CodeBuilderior()default CodeBuilderirem()Generates an instruction to calculateintsremainder.default CodeBuilderireturn()Generates an instruction to return anintfrom this method.default CodeBuilderishl()Generates an instruction to shift anintleft.default CodeBuilderishr()Generates an instruction to shift anintright.default CodeBuilderistore(int slot) Generates an instruction to store anintinto a local variable.default CodeBuilderisub()Generates an instruction to subtractints.default CodeBuilderiushr()Generates an instruction to logical shift anintright.default CodeBuilderixor()Generates an instruction to calculate bitwise XOR ofints.default CodeBuilderl2d()default CodeBuilderl2f()default CodeBuilderl2i()default CodeBuilderlabelBinding(Label label) Binds a label to the current position.default CodeBuilderladd()Generates an instruction to add twolongs.default CodeBuilderlaload()Generates an instruction to load from alongarray.default CodeBuilderland()Generates an instruction to calculate bitwise AND oflongs.default CodeBuilderlastore()Generates an instruction to store into alongarray.default CodeBuilderlcmp()Generates an instruction to comparelongs.default CodeBuilderlconst_0()Generates an instruction pushinglongconstant 0 onto the operand stack.default CodeBuilderlconst_1()Generates an instruction pushinglongconstant 1 onto the operand stack.default CodeBuilderldc(LoadableConstantEntry entry) Generates an instruction pushing an item from the run-time constant pool onto the operand stack.default CodeBuilderldc(ConstantDesc value) Generates an instruction pushing an item from the run-time constant pool onto the operand stack.default CodeBuilderldiv()Generates an instruction to dividelongs.default CodeBuilderlineNumber(int line) Declares a source line number beginning at the current position.default CodeBuilderlload(int slot) Generates an instruction to load alongfrom a local variable.default CodeBuilderlmul()Generates an instruction to multiplylongs.default CodeBuilderlneg()Generates an instruction to negate along.default CodeBuilderloadConstant(double value) Generates an instruction pushing a constantdoublevalue onto the operand stack.default CodeBuilderloadConstant(float value) Generates an instruction pushing a constantfloatvalue onto the operand stack.default CodeBuilderloadConstant(int value) Generates an instruction pushing a constantintvalue onto the operand stack.default CodeBuilderloadConstant(long value) Generates an instruction pushing a constantlongvalue onto the operand stack.default CodeBuilderloadConstant(ConstantDesc value) Generates an instruction pushing a constant onto the operand stack.default CodeBuilderGenerates an instruction to load a value from a local variable.default CodeBuilderlocalVariable(int slot, Utf8Entry nameEntry, Utf8Entry descriptorEntry, Label startScope, Label endScope) Declares a local variable entry.default CodeBuilderlocalVariable(int slot, String name, ClassDesc descriptor, Label startScope, Label endScope) Declares a local variable entry.default CodeBuilderlocalVariableType(int slot, Utf8Entry nameEntry, Utf8Entry signatureEntry, Label startScope, Label endScope) Declares a local variable type entry.default CodeBuilderlocalVariableType(int slot, String name, Signature signature, Label startScope, Label endScope) Declares a local variable type entry.default CodeBuilderlookupswitch(Label defaultTarget, List<SwitchCase> cases) Generates an instruction to access a jump table by key match and jump.default CodeBuilderlor()Generates an instruction to calculate bitwise OR oflongs.default CodeBuilderlrem()Generates an instruction to calculatelongsremainder.default CodeBuilderlreturn()Generates an instruction to return alongfrom this method.default CodeBuilderlshl()Generates an instruction to shift alongleft.default CodeBuilderlshr()Generates an instruction to shift alongright.default CodeBuilderlstore(int slot) Generates an instruction to store alonginto a local variable.default CodeBuilderlsub()Generates an instruction to subtractlongs.default CodeBuilderlushr()Generates an instruction to logical shift alongright.default CodeBuilderlxor()Generates an instruction to calculate bitwise XOR oflongs.default CodeBuilderGenerates an instruction to enter monitor for an object.default CodeBuilderGenerates an instruction to exit monitor for an object.default CodeBuildermultianewarray(ClassEntry array, int dims) Generates an instruction to create a new multidimensional array.default CodeBuildermultianewarray(ClassDesc array, int dims) Generates an instruction to create a new multidimensional array.default CodeBuildernew_(ClassEntry clazz) Generates an instruction to create a new object.default CodeBuilderGenerates an instruction to create a new object.default CodeBuilderGenerates an instruction to create a new array of a primitive type.default LabelCreates a new label bound at the current position.newLabel()Returns a fresh unbound label.default CodeBuildernop()Generates a do-nothing instruction.intparameterSlot(int paramNo) Returns the local variable slot associated with the specified parameter.default CodeBuilderpop()Generates an instruction to pop the top operand stack value.default CodeBuilderpop2()Generates an instruction to pop the top one or two operand stack values.default CodeBuilderputfield(FieldRefEntry ref) Generates an instruction to set field in an object.default CodeBuilderGenerates an instruction to set field in an object.default CodeBuilderputstatic(FieldRefEntry ref) Generates an instruction to set static field in a class.default CodeBuilderGenerates an instruction to set static field in a class.intReturns the local variable slot associated with the receiver.default CodeBuilderreturn_()Generates an instruction to returnvoidfrom this method.default CodeBuilderGenerates a return instruction.default CodeBuildersaload()Generates an instruction to load from ashortarray.default CodeBuildersastore()Generates an instruction to store into ashortarray.default CodeBuildersipush(int s) Returns the label associated with the beginning of the current block.default CodeBuilderstoreLocal(TypeKind tk, int slot) Generates an instruction to store a value to a local variable.default CodeBuilderswap()Generates an instruction to swap the top two operand stack values.default CodeBuildertableswitch(int low, int high, Label defaultTarget, List<SwitchCase> cases) Generates an instruction to access a jump table by index and jump.default CodeBuildertableswitch(Label defaultTarget, List<SwitchCase> cases) Generates an instruction to access a jump table by index and jump.default CodeBuildertransforming(CodeTransform transform, Consumer<CodeBuilder> handler) Apply a transform to the code built by a handler, directing results to this builder.default CodeBuildertrying(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 thatlonganddoublevalues 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 themaxLocalsof 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 aCodeModelfirst. - Parameters:
transform- the transform to apply to the code built by the handlerhandler- the handler that receives aCodeBuilderto 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.BlockCodeBuilderto generate the body of the lexical block- Returns:
- this builder
-
ifThen
Adds an "if-then" block that is conditional on thebooleanvalue 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 foropcodesucceeds.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.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) Adds an "if-then-else" block that is conditional on thebooleanvalue 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.BlockCodeBuilderto generate the body of theifelseHandler- 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) 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 foropcodesucceeds, 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 theifelseHandler- 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 thecatchesHandlercorrespond 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
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- iftkisvoidorslotis 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- iftkisvoidorslotis 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_JUMPSis set, the opcode has size 3, andtargetcannot be encoded as a BCI offset in[-32768, 32767].- Parameters:
op- the branch opcodetarget- the branch target- Returns:
- this builder
- Throws:
IllegalArgumentException- ifopis 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- ifopcodeis 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- ifopcodeis not ofOpcode.Kind.FIELD_ACCESS, orowneris 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- ifopcodeis 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- ifopcodeis not ofOpcode.Kind.INVOKE, orowneris primitive- See Also:
-
arrayLoad
Generates an instruction to load from an array.- Parameters:
tk- the array element type- Returns:
- this builder
- Throws:
IllegalArgumentException- iftkisvoid- See Also:
-
arrayStore
Generates an instruction to store into an array.- Parameters:
tk- the array element type- Returns:
- this builder
- Throws:
IllegalArgumentException- iftkisvoid- See Also:
-
conversion
Generates instruction(s) to convertfromTypetotoType.- Parameters:
fromType- the source typetoType- the target type- Returns:
- this builder
- Throws:
IllegalArgumentException- for conversions ofvoidorreference- 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 constantintvalue 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 constantlongvalue 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 constantfloatvalue onto the operand stack. This is equivalent toloadConstant(Float.valueOf(value)).All NaN values of the
floatmay 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 constantdoublevalue onto the operand stack. This is equivalent toloadConstant(Double.valueOf(value)).All NaN values of the
doublemay 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_LABELSis set.- Parameters:
start- the try block startend- the try block endhandler- the exception handler startcatchType- 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) Declares an exception table entry.This call may be ignored if any of the argument labels is not bound and
ClassFile.DeadLabelsOption.DROP_DEAD_LABELSis 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_LABELSis set.- Parameters:
start- the try block startend- the try block endhandler- the exception handler startcatchType- the catch type- Returns:
- this builder
- Throws:
IllegalArgumentException- ifcatchTypeis 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_LABELSis 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_DEBUGis set, or if any of the argument labels is not bound andClassFile.DeadLabelsOption.DROP_DEAD_LABELSis 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_DEBUGis set, or if any of the argument labels is not bound andClassFile.DeadLabelsOption.DROP_DEAD_LABELSis 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- ifslotis 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_DEBUGis set, or if any of the argument labels is not bound andClassFile.DeadLabelsOption.DROP_DEAD_LABELSis 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- ifslotis 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_DEBUGis set, or if any of the argument labels is not bound andClassFile.DeadLabelsOption.DROP_DEAD_LABELSis 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- ifslotis 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_DEBUGis set, or if any of the argument labels is not bound andClassFile.DeadLabelsOption.DROP_DEAD_LABELSis 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- ifslotis out of range- See Also:
-
aconst_null
Generates an instruction pushing the null objectreferenceonto the operand stack.- Returns:
- this builder
- See Also:
-
aaload
Generates an instruction to load from areferencearray.- Returns:
- this builder
- See Also:
-
aastore
Generates an instruction to store into areferencearray.- Returns:
- this builder
- See Also:
-
aload
Generates an instruction to load areferencefrom a local variable.This may also generate
aload_<N>andwide aloadinstructions.- Parameters:
slot- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException- ifslotis 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- ifclassNamerepresents a primitive type- See Also:
-
areturn
Generates an instruction to return areferencefrom 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 areferenceinto a local variable. Such an instruction can also store areturnAddress.This may also generate
astore_<N>andwide astoreinstructions.- Parameters:
slot- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException- ifslotis 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- ifbis out of range of byte- See Also:
-
caload
Generates an instruction to load from achararray.- Returns:
- this builder
- See Also:
-
castore
Generates an instruction to store into achararray.- Returns:
- this builder
- See Also:
-
checkcast
Generates an instruction to check whether an object is of the given type, throwing aClassCastExceptionif 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 aClassCastExceptionif the check fails.- Parameters:
type- the object type- Returns:
- this builder
- Throws:
IllegalArgumentException- iftyperepresents 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 adoublearray.- Returns:
- this builder
- See Also:
-
dastore
Generates an instruction to store into adoublearray.- Returns:
- this builder
- See Also:
-
dcmpg
- Returns:
- this builder
- See Also:
-
dcmpl
- Returns:
- this builder
- See Also:
-
dconst_0
Generates an instruction pushingdoubleconstant 0 onto the operand stack.- Returns:
- this builder
- See Also:
-
dconst_1
Generates an instruction pushingdoubleconstant 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 adoublefrom a local variable.This may also generate
dload_<N>andwide dloadinstructions.- Parameters:
slot- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException- ifslotis 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 calculatedoubleremainder.- Returns:
- this builder
- See Also:
-
dreturn
Generates an instruction to return adoublefrom this method.- Returns:
- this builder
- See Also:
-
dstore
Generates an instruction to store adoubleinto a local variable.This may also generate
dstore_<N>andwide dstoreinstructions.- Parameters:
slot- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException- ifslotis 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 afloatarray.- Returns:
- this builder
- See Also:
-
fastore
Generates an instruction to store into afloatarray.- Returns:
- this builder
- See Also:
-
fcmpg
- Returns:
- this builder
- See Also:
-
fcmpl
- Returns:
- this builder
- See Also:
-
fconst_0
Generates an instruction pushingfloatconstant 0 onto the operand stack.- Returns:
- this builder
- See Also:
-
fconst_1
Generates an instruction pushingfloatconstant 1 onto the operand stack.- Returns:
- this builder
- See Also:
-
fconst_2
Generates an instruction pushingfloatconstant 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 afloatfrom a local variable.This may also generate
fload_<N>andwide floadinstructions.- Parameters:
slot- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException- ifslotis 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 calculatefloatsremainder.- Returns:
- this builder
- See Also:
-
freturn
Generates an instruction to return afloatfrom this method.- Returns:
- this builder
- See Also:
-
fstore
Generates an instruction to store afloatinto a local variable.This may also generate
fstore_<N>andwide fstoreinstructions.- Parameters:
slot- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException- ifslotis 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- ifownerrepresents 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- ifownerrepresents a primitive type- See Also:
-
goto_
Generates an instruction to branch always.This may also generate
goto_winstructions ifClassFile.ShortJumpsOption.FIX_SHORT_JUMPSis 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 anintarray.- Returns:
- this builder
- See Also:
-
iand
- Returns:
- this builder
- See Also:
-
iastore
Generates an instruction to store into anintarray.- Returns:
- this builder
- See Also:
-
iconst_0
Generates an instruction pushingintconstant 0 onto the operand stack.- Returns:
- this builder
- See Also:
-
iconst_1
Generates an instruction pushingintconstant 1 onto the operand stack.- Returns:
- this builder
- See Also:
-
iconst_2
Generates an instruction pushingintconstant 2 onto the operand stack.- Returns:
- this builder
- See Also:
-
iconst_3
Generates an instruction pushingintconstant 3 onto the operand stack.- Returns:
- this builder
- See Also:
-
iconst_4
Generates an instruction pushingintconstant 4 onto the operand stack.- Returns:
- this builder
- See Also:
-
iconst_5
Generates an instruction pushingintconstant 5 onto the operand stack.- Returns:
- this builder
- See Also:
-
iconst_m1
Generates an instruction pushingintconstant -1 onto the operand stack.- Returns:
- this builder
- See Also:
-
idiv
-
if_acmpeq
Generates an instruction to branch ifreferencecomparisonoperand1 == operand2succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPSis set andtargetcannot 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 ifreferencecomparisonoperand1 != operand2succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPSis set andtargetcannot 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 ifintcomparisonoperand1 == operand2succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPSis set andtargetcannot 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 ifintcomparisonoperand1 >= operand2succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPSis set andtargetcannot 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 ifintcomparisonoperand1 > operand2succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPSis set andtargetcannot 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 ifintcomparisonoperand1 <= operand2succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPSis set andtargetcannot 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 ifintcomparisonoperand1 < operand2succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPSis set andtargetcannot 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 ifintcomparisonoperand1 != operand2succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPSis set andtargetcannot 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 ifreferenceis notnull.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPSis set andtargetcannot 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 ifreferenceisnull.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPSis set andtargetcannot 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 ifintcomparison with zero== 0succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPSis set andtargetcannot 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 ifintcomparison with zero>= 0succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPSis set andtargetcannot 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 ifintcomparison with zero> 0succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPSis set andtargetcannot 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 ifintcomparison with zero<= 0succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPSis set andtargetcannot 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 ifintcomparison with zero< 0succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPSis set andtargetcannot 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 ifintcomparison with zero!= 0succeeds.This may generate multiple instructions to accomplish the same effect if
ClassFile.ShortJumpsOption.FIX_SHORT_JUMPSis set andtargetcannot 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 anintlocal variable by a constant.This may also generate
wide iincinstructions ifslotexceeds255orvalexceeds the range ofbyte.- Parameters:
slot- the local variable slotval- the increment value- Returns:
- this builder
- Throws:
IllegalArgumentException- ifslotorvalis out of range- See Also:
-
iload
Generates an instruction to load anintfrom a local variable.This may also generate
iload_<N>andwide iloadinstructions.- Parameters:
slot- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException- ifslotis 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 abooleanresult 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 abooleanresult 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
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- ifownerrepresents 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- ifownerrepresents 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- ifownerrepresents 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- ifownerrepresents 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- ifownerrepresents 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- ifownerrepresents a primitive type- See Also:
-
ior
- Returns:
- this builder
- See Also:
-
irem
Generates an instruction to calculateintsremainder.- Returns:
- this builder
- See Also:
-
ireturn
Generates an instruction to return anintfrom this method.- Returns:
- this builder
- See Also:
-
ishl
Generates an instruction to shift anintleft.- Returns:
- this builder
- See Also:
-
ishr
-
istore
Generates an instruction to store anintinto a local variable.This may also generate
istore_<N>andwide istoreinstructions.- Parameters:
slot- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException- ifslotis 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 alongarray.- 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 alongarray.- Returns:
- this builder
- See Also:
-
lcmp
Generates an instruction to comparelongs.- Returns:
- this builder
- See Also:
-
lconst_0
Generates an instruction pushinglongconstant 0 onto the operand stack.- Returns:
- this builder
- See Also:
-
lconst_1
Generates an instruction pushinglongconstant 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:
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
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 alongfrom a local variable.This may also generate
lload_<N>andwide lloadinstructions.- Parameters:
slot- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException- ifslotis 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 calculatelongsremainder.- Returns:
- this builder
- See Also:
-
lreturn
Generates an instruction to return alongfrom this method.- Returns:
- this builder
- See Also:
-
lshl
Generates an instruction to shift alongleft.- Returns:
- this builder
- See Also:
-
lshr
-
lstore
Generates an instruction to store alonginto a local variable.This may also generate
lstore_<N>andwide lstoreinstructions.- Parameters:
slot- the local variable slot- Returns:
- this builder
- Throws:
IllegalArgumentException- ifslotis 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- ifdimsis 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- ifarrayrepresents a primitive type or ifdimsis 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- ifclazzrepresents 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 thetypeKindis 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- ifownerrepresents 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- ifownerrepresents a primitive type- See Also:
-
return_
Generates an instruction to returnvoidfrom 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 ashortarray.- Returns:
- this builder
- See Also:
-
sastore
Generates an instruction to store into ashortarray.- Returns:
- this builder
- See Also:
-
sipush
Generates an instruction pushing anintin the range ofshort,[-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
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:
-