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 SummaryNested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA builder for blocks of code.static interfaceA builder to add catch blocks.
- 
Method SummaryModifier 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.ClassFileBuilderaccept, constantPool, transform, with
- 
Method Details- 
newLabelLabel newLabel()Returns a fresh unbound label. The label can be bound withlabelBinding(java.lang.classfile.Label).- Returns:
- a fresh unbound label
 
- 
startLabelLabel 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
 
- 
endLabelLabel 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
 
- 
receiverSlotint 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
 
- 
parameterSlotint 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
 
- 
allocateLocalReturns 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
 
- 
transformingApply 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 handler
- handler- the handler that receives a- CodeBuilderto build the code
- Returns:
- this builder
 
- 
blockAdds 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 a- CodeBuilder.BlockCodeBuilderto generate the body of the lexical block
- Returns:
- this builder
 
- 
ifThenAdds 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 the- if
- Returns:
- this builder
- See Also:
 
- 
ifThenAdds 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 stack
- thenHandler- handler that receives a- CodeBuilder.BlockCodeBuilderto generate the body of the- if
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if the operation code is not for a branch instruction that accepts one or two operands
 
- 
ifThenElsedefault 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 a- CodeBuilder.BlockCodeBuilderto generate the body of the- if
- elseHandler- handler that receives a- CodeBuilder.BlockCodeBuilderto generate the body of the- else
- Returns:
- this builder
- See Also:
 
- 
ifThenElsedefault 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 stack
- thenHandler- handler that receives a CodeBuilder.BlockCodeBuilder to generate the body of the- if
- elseHandler- handler that receives a CodeBuilder.BlockCodeBuilder to generate the body of the- else
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if the operation code is not for a branch instruction that accepts one or two operands
 
- 
tryingdefault 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 a- CodeBuilder.BlockCodeBuilderto generate the body of the try block.
- catchesHandler- a handler that receives a- CodeBuilder.CatchBuilderto generate bodies of catch blocks
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if the try block is empty
- See Also:
 
- 
loadLocalGenerates an instruction to load a value from a local variable.- Parameters:
- tk- the load type
- slot- the local variable slot
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- tkis- voidor- slotis out of range
- See Also:
 
- 
storeLocalGenerates an instruction to store a value to a local variable.- Parameters:
- tk- the store type
- slot- the local variable slot
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- tkis- voidor- slotis out of range
- See Also:
 
- 
branchGenerates 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 opcode
- target- the branch target
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- opis not of- Opcode.Kind.BRANCH
- See Also:
 
- 
return_Generates a return instruction.- Parameters:
- tk- the return type
- Returns:
- this builder
- See Also:
 
- 
fieldAccessGenerates an instruction to access a field.- Parameters:
- opcode- the field access opcode
- ref- the field reference
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- opcodeis not of- Opcode.Kind.FIELD_ACCESS
- See Also:
 
- 
fieldAccessGenerates an instruction to access a field.- Parameters:
- opcode- the field access opcode
- owner- the class
- name- the field name
- type- the field type
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- opcodeis not of- Opcode.Kind.FIELD_ACCESS, or- owneris primitive
- See Also:
 
- 
invokeGenerates an instruction to invoke a method.- Parameters:
- opcode- the invoke opcode
- ref- the interface method or method reference
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- opcodeis not of- Opcode.Kind.INVOKE
- See Also:
 
- 
invokedefault CodeBuilder invoke(Opcode opcode, ClassDesc owner, String name, MethodTypeDesc desc, boolean isInterface) Generates an instruction to invoke a method.- Parameters:
- opcode- the invoke opcode
- owner- the class
- name- the method name
- desc- the method type
- isInterface- whether the owner class is an interface
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- opcodeis not of- Opcode.Kind.INVOKE, or- owneris primitive
- See Also:
 
- 
arrayLoadGenerates an instruction to load from an array.- Parameters:
- tk- the array element type
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- tkis- void
- See Also:
 
- 
arrayStoreGenerates an instruction to store into an array.- Parameters:
- tk- the array element type
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- tkis- void
- See Also:
 
- 
conversionGenerates instruction(s) to convertfromTypetotoType.- Parameters:
- fromType- the source type
- toType- the target type
- Returns:
- this builder
- Throws:
- IllegalArgumentException- for conversions of- voidor- reference
- See Also:
 
- 
loadConstantGenerates an instruction pushing a constant onto the operand stack.- Parameters:
- value- the constant value, may be- null
- Returns:
- this builder
- See Also:
 
- 
loadConstantGenerates 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:
 
- 
loadConstantGenerates 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:
 
- 
loadConstantGenerates 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:
 
- 
loadConstantGenerates 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
- 
newBoundLabelCreates a new label bound at the current position.- Returns:
- this builder
- See Also:
 
- 
labelBindingBinds 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:
 
- 
lineNumberDeclares 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:
 
- 
exceptionCatchDeclares 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 start
- end- the try block end
- handler- the exception handler start
- catchType- the catch type, may be- nullto catch all exceptions and errors
- Returns:
- this builder
- See Also:
 
- 
exceptionCatchdefault 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 start
- end- the try block end
- handler- the exception handler start
- catchType- the optional catch type, empty to catch all exceptions and errors
- Returns:
- this builder
- See Also:
 
- 
exceptionCatchDeclares 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 start
- end- the try block end
- handler- the exception handler start
- catchType- the catch type
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- catchTypeis primitive
- See Also:
 
- 
exceptionCatchAllDeclares 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 start
- end- the try block end
- handler- the exception handler start
- Returns:
- this builder
- See Also:
 
- 
characterRangedefault 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 range
- endScope- the end scope of the character range
- characterRangeStart- the encoded start of the character range region (inclusive)
- characterRangeEnd- the encoded end of the character range region (exclusive)
- flags- the flags word, indicating the kind of range
- Returns:
- this builder
- See Also:
 
- 
localVariabledefault 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 slot
- nameEntry- the variable name
- descriptorEntry- the variable descriptor
- startScope- the start scope of the variable
- endScope- the end scope of the variable
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- slotis out of range
- See Also:
 
- 
localVariabledefault 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 slot
- name- the variable name
- descriptor- the variable descriptor
- startScope- the start scope of the variable
- endScope- the end scope of the variable
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- slotis out of range
- See Also:
 
- 
localVariableTypedefault 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 slot
- nameEntry- the variable name
- signatureEntry- the variable signature
- startScope- the start scope of the variable
- endScope- the end scope of the variable
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- slotis out of range
- See Also:
 
- 
localVariableTypedefault 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 slot
- name- the variable name
- signature- the variable signature
- startScope- the start scope of the variable
- endScope- the end scope of the variable
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- slotis out of range
- See Also:
 
- 
aconst_nullGenerates an instruction pushing the null objectreferenceonto the operand stack.- Returns:
- this builder
- See Also:
 
- 
aaloadGenerates an instruction to load from areferencearray.- Returns:
- this builder
- See Also:
 
- 
aastoreGenerates an instruction to store into areferencearray.- Returns:
- this builder
- See Also:
 
- 
aloadGenerates 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- if- slotis out of range
- See Also:
 
- 
anewarrayGenerates an instruction to create a new array ofreference.- Parameters:
- classEntry- the component type
- Returns:
- this builder
- See Also:
 
- 
anewarrayGenerates an instruction to create a new array ofreference.- Parameters:
- className- the component type
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- classNamerepresents a primitive type
- See Also:
 
- 
areturnGenerates an instruction to return areferencefrom this method.- Returns:
- this builder
- See Also:
 
- 
arraylengthGenerates an instruction to get the length of an array.- Returns:
- this builder
- See Also:
 
- 
astoreGenerates 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- if- slotis out of range
- See Also:
 
- 
athrowGenerates 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- if- bis out of range of byte
- See Also:
 
- 
caloadGenerates an instruction to load from achararray.- Returns:
- this builder
- See Also:
 
- 
castoreGenerates an instruction to store into achararray.- Returns:
- this builder
- See Also:
 
- 
checkcastGenerates 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:
 
- 
checkcastGenerates 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- if- typerepresents a primitive type
- See Also:
 
- 
d2f- Returns:
- this builder
- See Also:
 
- 
d2i- Returns:
- this builder
- See Also:
 
- 
d2l- Returns:
- this builder
- See Also:
 
- 
daddGenerates an instruction to add twodoubles.- Returns:
- this builder
- See Also:
 
- 
daloadGenerates an instruction to load from adoublearray.- Returns:
- this builder
- See Also:
 
- 
dastoreGenerates an instruction to store into adoublearray.- Returns:
- this builder
- See Also:
 
- 
dcmpg- Returns:
- this builder
- See Also:
 
- 
dcmpl- Returns:
- this builder
- See Also:
 
- 
dconst_0Generates an instruction pushingdoubleconstant 0 onto the operand stack.- Returns:
- this builder
- See Also:
 
- 
dconst_1Generates an instruction pushingdoubleconstant 1 onto the operand stack.- Returns:
- this builder
- See Also:
 
- 
ddivGenerates an instruction to dividedoubles.- Returns:
- this builder
- See Also:
 
- 
dloadGenerates 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- if- slotis out of range
- See Also:
 
- 
dmulGenerates an instruction to multiplydoubles.- Returns:
- this builder
- See Also:
 
- 
dnegGenerates an instruction to negate adouble.- Returns:
- this builder
- See Also:
 
- 
dremGenerates an instruction to calculatedoubleremainder.- Returns:
- this builder
- See Also:
 
- 
dreturnGenerates an instruction to return adoublefrom this method.- Returns:
- this builder
- See Also:
 
- 
dstoreGenerates 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- if- slotis out of range
- See Also:
 
- 
dsubGenerates an instruction to subtractdoubles.- Returns:
- this builder
- See Also:
 
- 
dupGenerates an instruction to duplicate the top operand stack value.- Returns:
- this builder
- See Also:
 
- 
dup2Generates an instruction to duplicate the top one or two operand stack value.- Returns:
- this builder
- See Also:
 
- 
dup2_x1Generates 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_x2Generates 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_x1Generates an instruction to duplicate the top operand stack value and insert two values down.- Returns:
- this builder
- See Also:
 
- 
dup_x2Generates 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:
 
- 
faddGenerates an instruction to add twofloats.- Returns:
- this builder
- See Also:
 
- 
faloadGenerates an instruction to load from afloatarray.- Returns:
- this builder
- See Also:
 
- 
fastoreGenerates an instruction to store into afloatarray.- Returns:
- this builder
- See Also:
 
- 
fcmpg- Returns:
- this builder
- See Also:
 
- 
fcmpl- Returns:
- this builder
- See Also:
 
- 
fconst_0Generates an instruction pushingfloatconstant 0 onto the operand stack.- Returns:
- this builder
- See Also:
 
- 
fconst_1Generates an instruction pushingfloatconstant 1 onto the operand stack.- Returns:
- this builder
- See Also:
 
- 
fconst_2Generates an instruction pushingfloatconstant 2 onto the operand stack.- Returns:
- this builder
- See Also:
 
- 
fdivGenerates an instruction to dividefloats.- Returns:
- this builder
- See Also:
 
- 
floadGenerates 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- if- slotis out of range
- See Also:
 
- 
fmulGenerates an instruction to multiplyfloats.- Returns:
- this builder
- See Also:
 
- 
fnegGenerates an instruction to negate afloat.- Returns:
- this builder
- See Also:
 
- 
fremGenerates an instruction to calculatefloatsremainder.- Returns:
- this builder
- See Also:
 
- 
freturnGenerates an instruction to return afloatfrom this method.- Returns:
- this builder
- See Also:
 
- 
fstoreGenerates 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- if- slotis out of range
- See Also:
 
- 
fsubGenerates an instruction to subtractfloats.- Returns:
- this builder
- See Also:
 
- 
getfieldGenerates an instruction to fetch field from an object.- Parameters:
- ref- the field reference
- Returns:
- this builder
- See Also:
 
- 
getfieldGenerates an instruction to fetch field from an object.- Parameters:
- owner- the owner class
- name- the field name
- type- the field type
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- ownerrepresents a primitive type
- See Also:
 
- 
getstaticGenerates an instruction to get static field from a class or interface.- Parameters:
- ref- the field reference
- Returns:
- this builder
- See Also:
 
- 
getstaticGenerates an instruction to get static field from a class or interface.- Parameters:
- owner- the owner class
- name- the field name
- type- the field type
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- ownerrepresents 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_wGenerates 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:
 
- 
iaddGenerates an instruction to add twoints.- Returns:
- this builder
- See Also:
 
- 
ialoadGenerates an instruction to load from anintarray.- Returns:
- this builder
- See Also:
 
- 
iand- Returns:
- this builder
- See Also:
 
- 
iastoreGenerates an instruction to store into anintarray.- Returns:
- this builder
- See Also:
 
- 
iconst_0Generates an instruction pushingintconstant 0 onto the operand stack.- Returns:
- this builder
- See Also:
 
- 
iconst_1Generates an instruction pushingintconstant 1 onto the operand stack.- Returns:
- this builder
- See Also:
 
- 
iconst_2Generates an instruction pushingintconstant 2 onto the operand stack.- Returns:
- this builder
- See Also:
 
- 
iconst_3Generates an instruction pushingintconstant 3 onto the operand stack.- Returns:
- this builder
- See Also:
 
- 
iconst_4Generates an instruction pushingintconstant 4 onto the operand stack.- Returns:
- this builder
- See Also:
 
- 
iconst_5Generates an instruction pushingintconstant 5 onto the operand stack.- Returns:
- this builder
- See Also:
 
- 
iconst_m1Generates an instruction pushingintconstant -1 onto the operand stack.- Returns:
- this builder
- See Also:
 
- 
idiv
- 
if_acmpeqGenerates 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_acmpneGenerates 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_icmpeqGenerates 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_icmpgeGenerates 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_icmpgtGenerates 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_icmpleGenerates 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_icmpltGenerates 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_icmpneGenerates 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:
 
- 
ifnonnullGenerates 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:
 
- 
ifnullGenerates 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:
 
- 
ifeqGenerates 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:
 
- 
ifgeGenerates 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:
 
- 
ifgtGenerates 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:
 
- 
ifleGenerates 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:
 
- 
ifltGenerates 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:
 
- 
ifneGenerates 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:
 
- 
iincGenerates an instruction to increment anintlocal variable by a constant.This may also generate wide iincinstructions ifslotexceeds255orvalexceeds the range ofbyte.- Parameters:
- slot- the local variable slot
- val- the increment value
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- slotor- valis out of range
- See Also:
 
- 
iloadGenerates 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- if- slotis out of range
- See Also:
 
- 
imulGenerates an instruction to multiplyints.- Returns:
- this builder
- See Also:
 
- 
inegGenerates an instruction to negate anint.- Returns:
- this builder
- See Also:
 
- 
instanceOfGenerates 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:
 
- 
instanceOfGenerates 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- if- targetrepresents a primitive type
- See Also:
 
- 
invokedynamicGenerates an instruction to invoke a dynamically-computed call site.- Parameters:
- ref- the dynamic call site
- Returns:
- this builder
- See Also:
 
- 
invokedynamicGenerates an instruction to invoke a dynamically-computed call site.- Parameters:
- ref- the dynamic call site
- Returns:
- this builder
- See Also:
 
- 
invokeinterfaceGenerates an instruction to invoke an interface method.- Parameters:
- ref- the interface method reference
- Returns:
- this builder
- See Also:
 
- 
invokeinterfaceGenerates an instruction to invoke an interface method.- Parameters:
- owner- the owner interface
- name- the method name
- type- the method type
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- ownerrepresents a primitive type
- See Also:
 
- 
invokespecialGenerates 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:
 
- 
invokespecialGenerates 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:
 
- 
invokespecialGenerates 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 interface
- name- the method name
- type- the method type
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- ownerrepresents a primitive type
- See Also:
 
- 
invokespecialdefault 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 interface
- name- the method name
- type- the method type
- isInterface- whether the owner is an interface
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- ownerrepresents a primitive type
- See Also:
 
- 
invokestaticGenerates an instruction to invoke a class (static) method of an interface.- Parameters:
- ref- the interface method reference
- Returns:
- this builder
- See Also:
 
- 
invokestaticGenerates an instruction to invoke a class (static) method of a class.- Parameters:
- ref- the method reference
- Returns:
- this builder
- See Also:
 
- 
invokestaticGenerates an instruction to invoke a class (static) method of a class.- Parameters:
- owner- the owner class, must not be an interface
- name- the method name
- type- the method type
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- ownerrepresents a primitive type
- See Also:
 
- 
invokestaticdefault 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 interface
- name- the method name
- type- the method type
- isInterface- whether the owner is an interface
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- ownerrepresents a primitive type
- See Also:
 
- 
invokevirtualGenerates an instruction to invoke an instance method; dispatch based on class.- Parameters:
- ref- the method reference
- Returns:
- this builder
- See Also:
 
- 
invokevirtualGenerates an instruction to invoke an instance method; dispatch based on class.- Parameters:
- owner- the owner class, must not be an interface
- name- the method name
- type- the method type
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- ownerrepresents a primitive type
- See Also:
 
- 
ior- Returns:
- this builder
- See Also:
 
- 
iremGenerates an instruction to calculateintsremainder.- Returns:
- this builder
- See Also:
 
- 
ireturnGenerates an instruction to return anintfrom this method.- Returns:
- this builder
- See Also:
 
- 
ishlGenerates an instruction to shift anintleft.- Returns:
- this builder
- See Also:
 
- 
ishr
- 
istoreGenerates 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- if- slotis out of range
- See Also:
 
- 
isubGenerates an instruction to subtractints.- Returns:
- this builder
- See Also:
 
- 
iushr
- 
ixor- Returns:
- this builder
- See Also:
 
- 
lookupswitchGenerates an instruction to access a jump table by key match and jump.- Parameters:
- defaultTarget- the default jump target
- cases- 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:
 
- 
laddGenerates an instruction to add twolongs.- Returns:
- this builder
- See Also:
 
- 
laloadGenerates an instruction to load from alongarray.- Returns:
- this builder
- See Also:
 
- 
landGenerates an instruction to calculate bitwise AND oflongs.- Returns:
- this builder
- See Also:
 
- 
lastoreGenerates an instruction to store into alongarray.- Returns:
- this builder
- See Also:
 
- 
lcmpGenerates an instruction to comparelongs.- Returns:
- this builder
- See Also:
 
- 
lconst_0Generates an instruction pushinglongconstant 0 onto the operand stack.- Returns:
- this builder
- See Also:
 
- 
lconst_1Generates an instruction pushinglongconstant 1 onto the operand stack.- Returns:
- this builder
- See Also:
 
- 
ldcGenerates 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 an- ldcinstruction is not strictly required.
- Parameters:
- value- the constant value
- Returns:
- this builder
- See Also:
 
- 
ldcGenerates 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:
 
- 
ldivGenerates an instruction to dividelongs.- Returns:
- this builder
- See Also:
 
- 
lloadGenerates 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- if- slotis out of range
- See Also:
 
- 
lmulGenerates an instruction to multiplylongs.- Returns:
- this builder
- See Also:
 
- 
lnegGenerates an instruction to negate along.- Returns:
- this builder
- See Also:
 
- 
lorGenerates an instruction to calculate bitwise OR oflongs.- Returns:
- this builder
- See Also:
 
- 
lremGenerates an instruction to calculatelongsremainder.- Returns:
- this builder
- See Also:
 
- 
lreturnGenerates an instruction to return alongfrom this method.- Returns:
- this builder
- See Also:
 
- 
lshlGenerates an instruction to shift alongleft.- Returns:
- this builder
- See Also:
 
- 
lshr
- 
lstoreGenerates 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- if- slotis out of range
- See Also:
 
- 
lsubGenerates an instruction to subtractlongs.- Returns:
- this builder
- See Also:
 
- 
lushr
- 
lxorGenerates an instruction to calculate bitwise XOR oflongs.- Returns:
- this builder
- See Also:
 
- 
monitorenterGenerates an instruction to enter monitor for an object.- Returns:
- this builder
- See Also:
 
- 
monitorexitGenerates an instruction to exit monitor for an object.- Returns:
- this builder
- See Also:
 
- 
multianewarrayGenerates an instruction to create a new multidimensional array.- Parameters:
- array- the array type
- dims- the number of dimensions
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- dimsis out of range
- See Also:
 
- 
multianewarrayGenerates an instruction to create a new multidimensional array.- Parameters:
- array- the array type
- dims- the number of dimensions
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- arrayrepresents a primitive type or if- dimsis 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- if- clazzrepresents a primitive type
- See Also:
 
- 
newarrayGenerates an instruction to create a new array of a primitive type.- Parameters:
- typeKind- the primitive array type
- Returns:
- this builder
- Throws:
- IllegalArgumentException- when the- typeKindis not a legal primitive array component type
- See Also:
 
- 
popGenerates an instruction to pop the top operand stack value.- Returns:
- this builder
- See Also:
 
- 
pop2Generates an instruction to pop the top one or two operand stack values.- Returns:
- this builder
- See Also:
 
- 
putfieldGenerates an instruction to set field in an object.- Parameters:
- ref- the field reference
- Returns:
- this builder
- See Also:
 
- 
putfieldGenerates an instruction to set field in an object.- Parameters:
- owner- the owner class
- name- the field name
- type- the field type
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- ownerrepresents a primitive type
- See Also:
 
- 
putstaticGenerates an instruction to set static field in a class.- Parameters:
- ref- the field reference
- Returns:
- this builder
- See Also:
 
- 
putstaticGenerates an instruction to set static field in a class.- Parameters:
- owner- the owner class or interface
- name- the field name
- type- the field type
- Returns:
- this builder
- Throws:
- IllegalArgumentException- if- ownerrepresents 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:
 
- 
saloadGenerates an instruction to load from ashortarray.- Returns:
- this builder
- See Also:
 
- 
sastoreGenerates an instruction to store into ashortarray.- Returns:
- this builder
- See Also:
 
- 
sipushGenerates 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- if- sis out of range of short
- See Also:
 
- 
swapGenerates an instruction to swap the top two operand stack values.- Returns:
- this builder
- See Also:
 
- 
tableswitchGenerates an instruction to access a jump table by index and jump.- Parameters:
- low- the minimum key, inclusive
- high- the maximum key, inclusive
- defaultTarget- the default jump target
- cases- the switch cases
- Returns:
- this builder
- See Also:
 
- 
tableswitchGenerates an instruction to access a jump table by index and jump. Computes the minimum and maximum keys from thecases.- Parameters:
- defaultTarget- the default jump target
- cases- the switch cases
- Returns:
- this builder
- See Also:
 
 
-