W3cubDocs

/OpenJDK 25

Interface CodeBuilder

All Superinterfaces:
ClassFileBuilder<CodeElement, CodeBuilder>, Consumer<CodeElement>
All Known Subinterfaces:
CodeBuilder.BlockCodeBuilder
public sealed interface CodeBuilder extends ClassFileBuilder<CodeElement, CodeBuilder> permits CodeBuilder.BlockCodeBuilder (not exhaustive)
A builder for Code attributes (method bodies). MethodBuilder.withCode(Consumer) is the basic way to obtain a code builder; ClassBuilder.withMethodBody(Utf8Entry, Utf8Entry, int, Consumer) is a shortcut. There are also derived code builders from block(Consumer), which handles code blocks and transforming(CodeTransform, Consumer), which runs transforms on existing handlers, both of which requires a code builder to be available first.

Refer to ClassFileBuilder for general guidance and caution around the use of builders for structures in the class file format. Unlike in other builders, the order of member elements in a code builder is significant: they affect the resulting bytecode. Many Class-File API options affect code builders: ClassFile.DeadCodeOption and ClassFile.ShortJumpsOption affect the resulting bytecode, and ClassFile.DeadLabelsOption, ClassFile.DebugElementsOption, ClassFile.LineNumbersOption, ClassFile.StackMapsOption, and ClassFile.AttributesProcessingOption affect the resulting attributes on the built Code attribute, that some elements sent to a code builder is otherwise ignored.

Instruction Factories

CodeBuilder provides convenience methods to create instructions (See JVMS 6.5 Instructions) by their mnemonic, taking necessary operands.
  • Instructions that encode their operands in their opcode, such as aload_<n>, share their factories with their generic version like aload. Note that some constant instructions, such as iconst_1, do not have generic versions, and thus have their own factories.
  • Instructions that accept wide operands, such as ldc2_w or wide, share their factories with their regular version like ldc(ConstantDesc). Note that goto_w has its own factory to avoid short jumps.
  • The goto, instanceof, new, and return instructions' factories are named goto_, instanceOf, new_, and return_ respectively, due to clashes with keywords in the Java programming language.
  • Factories are not provided for instructions jsr, jsr_w, ret, and wide ret, which cannot appear in class files with major version 51 or higher. (JVMS 4.9.1) They can still be provided via ClassFileBuilder.with(E).
Since:
24
See Also:

Nested Class Summary

Modifier and Type Interface Description
static interface  CodeBuilder.BlockCodeBuilder
A builder for blocks of code.
static interface  CodeBuilder.CatchBuilder
A builder to add catch blocks.

Method Summary

Modifier and Type Method Description
default CodeBuilder aaload()
Generates an instruction to load from a reference array.
default CodeBuilder aastore()
Generates an instruction to store into a reference array.
default CodeBuilder aconst_null()
Generates an instruction pushing the null object reference onto the operand stack.
int allocateLocal(TypeKind typeKind)
Returns the local variable slot of a fresh local variable.
default CodeBuilder aload(int slot)
Generates an instruction to load a reference from a local variable.
default CodeBuilder anewarray(ClassEntry classEntry)
Generates an instruction to create a new array of reference.
default CodeBuilder anewarray(ClassDesc className)
Generates an instruction to create a new array of reference.
default CodeBuilder areturn()
Generates an instruction to return a reference from this method.
default CodeBuilder arraylength()
Generates an instruction to get the length of an array.
default CodeBuilder arrayLoad(TypeKind tk)
Generates an instruction to load from an array.
default CodeBuilder arrayStore(TypeKind tk)
Generates an instruction to store into an array.
default CodeBuilder astore(int slot)
Generates an instruction to store a reference into a local variable.
default CodeBuilder athrow()
Generates an instruction to throw an exception or error.
default CodeBuilder baload()
Generates an instruction to load from a byte or boolean array.
default CodeBuilder bastore()
Generates an instruction to store into a byte or boolean array.
default CodeBuilder bipush(int b)
Generates an instruction pushing an int in the range of byte ([-128, 127]) onto the operand stack.
default CodeBuilder block(Consumer<CodeBuilder.BlockCodeBuilder> handler)
Adds a lexical block to the method being built.
default CodeBuilder branch(Opcode op, Label target)
Generates a branch instruction.
default CodeBuilder caload()
Generates an instruction to load from a char array.
default CodeBuilder castore()
Generates an instruction to store into a char array.
default CodeBuilder characterRange(Label startScope, Label endScope, int characterRangeStart, int characterRangeEnd, int flags)
Declares a character range entry.
default CodeBuilder checkcast(ClassEntry type)
Generates an instruction to check whether an object is of the given type, throwing a ClassCastException if the check fails.
default CodeBuilder checkcast(ClassDesc type)
Generates an instruction to check whether an object is of the given type, throwing a ClassCastException if the check fails.
default CodeBuilder conversion(TypeKind fromType, TypeKind toType)
Generates instruction(s) to convert fromType to toType.
default CodeBuilder d2f()
Generates an instruction to convert a double into a float.
default CodeBuilder d2i()
Generates an instruction to convert a double into an int.
default CodeBuilder d2l()
Generates an instruction to convert a double into a long.
default CodeBuilder dadd()
Generates an instruction to add two doubles.
default CodeBuilder daload()
Generates an instruction to load from a double array.
default CodeBuilder dastore()
Generates an instruction to store into a double array.
default CodeBuilder dcmpg()
Generates an instruction to compare two doubles, producing 1 if any operand is NaN.
default CodeBuilder dcmpl()
Generates an instruction to compare two doubles, producing -1 if any operand is NaN.
default CodeBuilder dconst_0()
Generates an instruction pushing double constant 0 onto the operand stack.
default CodeBuilder dconst_1()
Generates an instruction pushing double constant 1 onto the operand stack.
default CodeBuilder ddiv()
Generates an instruction to divide doubles.
default CodeBuilder dload(int slot)
Generates an instruction to load a double from a local variable.
default CodeBuilder dmul()
Generates an instruction to multiply doubles.
default CodeBuilder dneg()
Generates an instruction to negate a double.
default CodeBuilder drem()
Generates an instruction to calculate double remainder.
default CodeBuilder dreturn()
Generates an instruction to return a double from this method.
default CodeBuilder dstore(int slot)
Generates an instruction to store a double into a local variable.
default CodeBuilder dsub()
Generates an instruction to subtract doubles.
default CodeBuilder dup()
Generates an instruction to duplicate the top operand stack value.
default CodeBuilder dup_x1()
Generates an instruction to duplicate the top operand stack value and insert two values down.
default CodeBuilder dup_x2()
Generates an instruction to duplicate the top operand stack value and insert two or three values down.
default CodeBuilder dup2()
Generates an instruction to duplicate the top one or two operand stack value.
default CodeBuilder dup2_x1()
Generates an instruction to duplicate the top one or two operand stack values and insert two or three values down.
default CodeBuilder dup2_x2()
Generates an instruction to duplicate the top one or two operand stack values and insert two, three, or four values down.
Label endLabel()
Returns the label associated with the end of the current block.
default CodeBuilder exceptionCatch(Label start, Label end, Label handler, ClassEntry catchType)
Declares an exception table entry.
default CodeBuilder exceptionCatch(Label start, Label end, Label handler, ClassDesc catchType)
Declares an exception table entry.
default CodeBuilder exceptionCatch(Label start, Label end, Label handler, Optional<ClassEntry> catchType)
Declares an exception table entry.
default CodeBuilder exceptionCatchAll(Label start, Label end, Label handler)
Declares an exception table entry catching all exceptions and errors.
default CodeBuilder f2d()
Generates an instruction to convert a float into a double.
default CodeBuilder f2i()
Generates an instruction to convert a float into an int.
default CodeBuilder f2l()
Generates an instruction to convert a float into a long.
default CodeBuilder fadd()
Generates an instruction to add two floats.
default CodeBuilder faload()
Generates an instruction to load from a float array.
default CodeBuilder fastore()
Generates an instruction to store into a float array.
default CodeBuilder fcmpg()
Generates an instruction to compare floats, producing 1 if any operand is NaN.
default CodeBuilder fcmpl()
Generates an instruction to compare floats, producing -1 if any operand is NaN.
default CodeBuilder fconst_0()
Generates an instruction pushing float constant 0 onto the operand stack.
default CodeBuilder fconst_1()
Generates an instruction pushing float constant 1 onto the operand stack.
default CodeBuilder fconst_2()
Generates an instruction pushing float constant 2 onto the operand stack.
default CodeBuilder fdiv()
Generates an instruction to divide floats.
default CodeBuilder fieldAccess(Opcode opcode, FieldRefEntry ref)
Generates an instruction to access a field.
default CodeBuilder fieldAccess(Opcode opcode, ClassDesc owner, String name, ClassDesc type)
Generates an instruction to access a field.
default CodeBuilder fload(int slot)
Generates an instruction to load a float from a local variable.
default CodeBuilder fmul()
Generates an instruction to multiply floats.
default CodeBuilder fneg()
Generates an instruction to negate a float.
default CodeBuilder frem()
Generates an instruction to calculate floats remainder.
default CodeBuilder freturn()
Generates an instruction to return a float from this method.
default CodeBuilder fstore(int slot)
Generates an instruction to store a float into a local variable.
default CodeBuilder fsub()
Generates an instruction to subtract floats.
default CodeBuilder getfield(FieldRefEntry ref)
Generates an instruction to fetch field from an object.
default CodeBuilder getfield(ClassDesc owner, String name, ClassDesc type)
Generates an instruction to fetch field from an object.
default CodeBuilder getstatic(FieldRefEntry ref)
Generates an instruction to get static field from a class or interface.
default CodeBuilder getstatic(ClassDesc owner, String name, ClassDesc type)
Generates an instruction to get static field from a class or interface.
default CodeBuilder goto_(Label target)
Generates an instruction to branch always.
default CodeBuilder goto_w(Label target)
Generates an instruction to branch always with wide index.
default CodeBuilder i2b()
Generates an instruction to truncate an int into the range of byte and sign-extend it.
default CodeBuilder i2c()
Generates an instruction to truncate an int into the range of char and zero-extend it.
default CodeBuilder i2d()
Generates an instruction to convert an int into a double.
default CodeBuilder i2f()
Generates an instruction to convert an int into a float.
default CodeBuilder i2l()
Generates an instruction to convert an int into a long.
default CodeBuilder i2s()
Generates an instruction to truncate an int into the range of short and sign-extend it.
default CodeBuilder iadd()
Generates an instruction to add two ints.
default CodeBuilder iaload()
Generates an instruction to load from an int array.
default CodeBuilder iand()
Generates an instruction to calculate bitwise AND of ints, also used for boolean AND.
default CodeBuilder iastore()
Generates an instruction to store into an int array.
default CodeBuilder iconst_0()
Generates an instruction pushing int constant 0 onto the operand stack.
default CodeBuilder iconst_1()
Generates an instruction pushing int constant 1 onto the operand stack.
default CodeBuilder iconst_2()
Generates an instruction pushing int constant 2 onto the operand stack.
default CodeBuilder iconst_3()
Generates an instruction pushing int constant 3 onto the operand stack.
default CodeBuilder iconst_4()
Generates an instruction pushing int constant 4 onto the operand stack.
default CodeBuilder iconst_5()
Generates an instruction pushing int constant 5 onto the operand stack.
default CodeBuilder iconst_m1()
Generates an instruction pushing int constant -1 onto the operand stack.
default CodeBuilder idiv()
Generates an instruction to divide ints.
default CodeBuilder if_acmpeq(Label target)
Generates an instruction to branch if reference comparison operand1 == operand2 succeeds.
default CodeBuilder if_acmpne(Label target)
Generates an instruction to branch if reference comparison operand1 != operand2 succeeds.
default CodeBuilder if_icmpeq(Label target)
Generates an instruction to branch if int comparison operand1 == operand2 succeeds.
default CodeBuilder if_icmpge(Label target)
Generates an instruction to branch if int comparison operand1 >= operand2 succeeds.
default CodeBuilder if_icmpgt(Label target)
Generates an instruction to branch if int comparison operand1 > operand2 succeeds.
default CodeBuilder if_icmple(Label target)
Generates an instruction to branch if int comparison operand1 <= operand2 succeeds.
default CodeBuilder if_icmplt(Label target)
Generates an instruction to branch if int comparison operand1 < operand2 succeeds.
default CodeBuilder if_icmpne(Label target)
Generates an instruction to branch if int comparison operand1 != operand2 succeeds.
default CodeBuilder ifeq(Label target)
Generates an instruction to branch if int comparison with zero == 0 succeeds.
default CodeBuilder ifge(Label target)
Generates an instruction to branch if int comparison with zero >= 0 succeeds.
default CodeBuilder ifgt(Label target)
Generates an instruction to branch if int comparison with zero > 0 succeeds.
default CodeBuilder ifle(Label target)
Generates an instruction to branch if int comparison with zero <= 0 succeeds.
default CodeBuilder iflt(Label target)
Generates an instruction to branch if int comparison with zero < 0 succeeds.
default CodeBuilder ifne(Label target)
Generates an instruction to branch if int comparison with zero != 0 succeeds.
default CodeBuilder ifnonnull(Label target)
Generates an instruction to branch if reference is not null.
default CodeBuilder ifnull(Label target)
Generates an instruction to branch if reference is null.
default CodeBuilder ifThen(Opcode opcode, Consumer<CodeBuilder.BlockCodeBuilder> thenHandler)
Adds an "if-then" block that is conditional on the value(s) on top of the operand stack in accordance with the given opcode.
default CodeBuilder ifThen(Consumer<CodeBuilder.BlockCodeBuilder> thenHandler)
Adds an "if-then" block that is conditional on the boolean value on top of the operand stack.
default CodeBuilder ifThenElse(Opcode opcode, Consumer<CodeBuilder.BlockCodeBuilder> thenHandler, Consumer<CodeBuilder.BlockCodeBuilder> elseHandler)
Adds an "if-then-else" block that is conditional on the value(s) on top of the operand stack in accordance with the given opcode.
default CodeBuilder ifThenElse(Consumer<CodeBuilder.BlockCodeBuilder> thenHandler, Consumer<CodeBuilder.BlockCodeBuilder> elseHandler)
Adds an "if-then-else" block that is conditional on the boolean value on top of the operand stack.
default CodeBuilder iinc(int slot, int val)
Generates an instruction to increment an int local variable by a constant.
default CodeBuilder iload(int slot)
Generates an instruction to load an int from a local variable.
default CodeBuilder imul()
Generates an instruction to multiply ints.
default CodeBuilder ineg()
Generates an instruction to negate an int.
default CodeBuilder instanceOf(ClassEntry target)
Generates an instruction to determine if an object is of the given type, producing a boolean result on the operand stack.
default CodeBuilder instanceOf(ClassDesc target)
Generates an instruction to determine if an object is of the given type, producing a boolean result on the operand stack.
default CodeBuilder invoke(Opcode opcode, MemberRefEntry ref)
Generates an instruction to invoke a method.
default CodeBuilder invoke(Opcode opcode, ClassDesc owner, String name, MethodTypeDesc desc, boolean isInterface)
Generates an instruction to invoke a method.
default CodeBuilder invokedynamic(InvokeDynamicEntry ref)
Generates an instruction to invoke a dynamically-computed call site.
default CodeBuilder invokedynamic(DynamicCallSiteDesc ref)
Generates an instruction to invoke a dynamically-computed call site.
default CodeBuilder invokeinterface(InterfaceMethodRefEntry ref)
Generates an instruction to invoke an interface method.
default CodeBuilder invokeinterface(ClassDesc owner, String name, MethodTypeDesc type)
Generates an instruction to invoke an interface method.
default CodeBuilder invokespecial(InterfaceMethodRefEntry ref)
Generates an instruction to invoke an instance method in an interface; direct invocation of methods of the current class and its supertypes.
default CodeBuilder invokespecial(MethodRefEntry ref)
Generates an instruction to invoke an instance method in a class; direct invocation of instance initialization methods and methods of the current class and its supertypes.
default CodeBuilder invokespecial(ClassDesc owner, String name, MethodTypeDesc type)
Generates an instruction to invoke an instance method in a class; direct invocation of instance initialization methods and methods of the current class and its supertypes.
default CodeBuilder invokespecial(ClassDesc owner, String name, MethodTypeDesc type, boolean isInterface)
Generates an instruction to invoke an instance method; direct invocation of instance initialization methods and methods of the current class and its supertypes.
default CodeBuilder invokestatic(InterfaceMethodRefEntry ref)
Generates an instruction to invoke a class (static) method of an interface.
default CodeBuilder invokestatic(MethodRefEntry ref)
Generates an instruction to invoke a class (static) method of a class.
default CodeBuilder invokestatic(ClassDesc owner, String name, MethodTypeDesc type)
Generates an instruction to invoke a class (static) method of a class.
default CodeBuilder invokestatic(ClassDesc owner, String name, MethodTypeDesc type, boolean isInterface)
Generates an instruction to invoke a class (static) method.
default CodeBuilder invokevirtual(MethodRefEntry ref)
Generates an instruction to invoke an instance method; dispatch based on class.
default CodeBuilder invokevirtual(ClassDesc owner, String name, MethodTypeDesc type)
Generates an instruction to invoke an instance method; dispatch based on class.
default CodeBuilder ior()
Generates an instruction to calculate bitwise OR of ints, also used for boolean OR.
default CodeBuilder irem()
Generates an instruction to calculate ints remainder.
default CodeBuilder ireturn()
Generates an instruction to return an int from this method.
default CodeBuilder ishl()
Generates an instruction to shift an int left.
default CodeBuilder ishr()
Generates an instruction to shift an int right.
default CodeBuilder istore(int slot)
Generates an instruction to store an int into a local variable.
default CodeBuilder isub()
Generates an instruction to subtract ints.
default CodeBuilder iushr()
Generates an instruction to logical shift an int right.
default CodeBuilder ixor()
Generates an instruction to calculate bitwise XOR of ints.
default CodeBuilder l2d()
Generates an instruction to convert a long into a double.
default CodeBuilder l2f()
Generates an instruction to convert a long into a float.
default CodeBuilder l2i()
Generates an instruction to convert a long into an int.
default CodeBuilder labelBinding(Label label)
Binds a label to the current position.
default CodeBuilder ladd()
Generates an instruction to add two longs.
default CodeBuilder laload()
Generates an instruction to load from a long array.
default CodeBuilder land()
Generates an instruction to calculate bitwise AND of longs.
default CodeBuilder lastore()
Generates an instruction to store into a long array.
default CodeBuilder lcmp()
Generates an instruction to compare longs.
default CodeBuilder lconst_0()
Generates an instruction pushing long constant 0 onto the operand stack.
default CodeBuilder lconst_1()
Generates an instruction pushing long constant 1 onto the operand stack.
default CodeBuilder ldc(LoadableConstantEntry entry)
Generates an instruction pushing an item from the run-time constant pool onto the operand stack.
default CodeBuilder ldc(ConstantDesc value)
Generates an instruction pushing an item from the run-time constant pool onto the operand stack.
default CodeBuilder ldiv()
Generates an instruction to divide longs.
default CodeBuilder lineNumber(int line)
Declares a source line number beginning at the current position.
default CodeBuilder lload(int slot)
Generates an instruction to load a long from a local variable.
default CodeBuilder lmul()
Generates an instruction to multiply longs.
default CodeBuilder lneg()
Generates an instruction to negate a long.
default CodeBuilder loadConstant(double value)
Generates an instruction pushing a constant double value onto the operand stack.
default CodeBuilder loadConstant(float value)
Generates an instruction pushing a constant float value onto the operand stack.
default CodeBuilder loadConstant(int value)
Generates an instruction pushing a constant int value onto the operand stack.
default CodeBuilder loadConstant(long value)
Generates an instruction pushing a constant long value onto the operand stack.
default CodeBuilder loadConstant(ConstantDesc value)
Generates an instruction pushing a constant onto the operand stack.
default CodeBuilder loadLocal(TypeKind tk, int slot)
Generates an instruction to load a value from a local variable.
default CodeBuilder localVariable(int slot, Utf8Entry nameEntry, Utf8Entry descriptorEntry, Label startScope, Label endScope)
Declares a local variable entry.
default CodeBuilder localVariable(int slot, String name, ClassDesc descriptor, Label startScope, Label endScope)
Declares a local variable entry.
default CodeBuilder localVariableType(int slot, Utf8Entry nameEntry, Utf8Entry signatureEntry, Label startScope, Label endScope)
Declares a local variable type entry.
default CodeBuilder localVariableType(int slot, String name, Signature signature, Label startScope, Label endScope)
Declares a local variable type entry.
default CodeBuilder lookupswitch(Label defaultTarget, List<SwitchCase> cases)
Generates an instruction to access a jump table by key match and jump.
default CodeBuilder lor()
Generates an instruction to calculate bitwise OR of longs.
default CodeBuilder lrem()
Generates an instruction to calculate longs remainder.
default CodeBuilder lreturn()
Generates an instruction to return a long from this method.
default CodeBuilder lshl()
Generates an instruction to shift a long left.
default CodeBuilder lshr()
Generates an instruction to shift a long right.
default CodeBuilder lstore(int slot)
Generates an instruction to store a long into a local variable.
default CodeBuilder lsub()
Generates an instruction to subtract longs.
default CodeBuilder lushr()
Generates an instruction to logical shift a long right.
default CodeBuilder lxor()
Generates an instruction to calculate bitwise XOR of longs.
default CodeBuilder monitorenter()
Generates an instruction to enter monitor for an object.
default CodeBuilder monitorexit()
Generates an instruction to exit monitor for an object.
default CodeBuilder multianewarray(ClassEntry array, int dims)
Generates an instruction to create a new multidimensional array.
default CodeBuilder multianewarray(ClassDesc array, int dims)
Generates an instruction to create a new multidimensional array.
default CodeBuilder new_(ClassEntry clazz)
Generates an instruction to create a new object.
default CodeBuilder new_(ClassDesc clazz)
Generates an instruction to create a new object.
default CodeBuilder newarray(TypeKind typeKind)
Generates an instruction to create a new array of a primitive type.
default Label newBoundLabel()
Creates a new label bound at the current position.
Label newLabel()
Returns a fresh unbound label.
default CodeBuilder nop()
Generates a do-nothing instruction.
int parameterSlot(int paramNo)
Returns the local variable slot associated with the specified parameter.
default CodeBuilder pop()
Generates an instruction to pop the top operand stack value.
default CodeBuilder pop2()
Generates an instruction to pop the top one or two operand stack values.
default CodeBuilder putfield(FieldRefEntry ref)
Generates an instruction to set field in an object.
default CodeBuilder putfield(ClassDesc owner, String name, ClassDesc type)
Generates an instruction to set field in an object.
default CodeBuilder putstatic(FieldRefEntry ref)
Generates an instruction to set static field in a class.
default CodeBuilder putstatic(ClassDesc owner, String name, ClassDesc type)
Generates an instruction to set static field in a class.
int receiverSlot()
Returns the local variable slot associated with the receiver.
default CodeBuilder return_()
Generates an instruction to return void from this method.
default CodeBuilder return_(TypeKind tk)
Generates a return instruction.
default CodeBuilder saload()
Generates an instruction to load from a short array.
default CodeBuilder sastore()
Generates an instruction to store into a short array.
default CodeBuilder sipush(int s)
Generates an instruction pushing an int in the range of short, [-32768, 32767], onto the operand stack.
Label startLabel()
Returns the label associated with the beginning of the current block.
default CodeBuilder storeLocal(TypeKind tk, int slot)
Generates an instruction to store a value to a local variable.
default CodeBuilder swap()
Generates an instruction to swap the top two operand stack values.
default CodeBuilder tableswitch(int low, int high, Label defaultTarget, List<SwitchCase> cases)
Generates an instruction to access a jump table by index and jump.
default CodeBuilder tableswitch(Label defaultTarget, List<SwitchCase> cases)
Generates an instruction to access a jump table by index and jump.
default CodeBuilder transforming(CodeTransform transform, Consumer<CodeBuilder> handler)
Apply a transform to the code built by a handler, directing results to this builder.
default CodeBuilder trying(Consumer<CodeBuilder.BlockCodeBuilder> tryHandler, Consumer<CodeBuilder.CatchBuilder> catchesHandler)
Adds a "try-catch" block comprising one try block and zero or more catch blocks.

Methods declared in interface ClassFileBuilder

accept, constantPool, transform, with

Methods declared in interface Consumer

andThen

Method Details

newLabel

Label newLabel()
Returns a fresh unbound label. The label can be bound with labelBinding(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 by block(Consumer) or ifThenElse(Consumer, Consumer), the current block will be the entire method body.
Returns:
the label associated with the beginning of the current block

endLabel

Label endLabel()
Returns the label associated with the end of the current block. If this builder is not a "block" builder, such as those provided by block(Consumer) or ifThenElse(Consumer, Consumer), the current block will be the entire method body.
Returns:
the label associated with the end of the current block

receiverSlot

int receiverSlot()
Returns the local variable slot associated with the receiver.
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 that long and double values require two slots.
Parameters:
paramNo - the index of the parameter
Returns:
the local variable slot associated with the specified parameter
Throws:
IndexOutOfBoundsException - if the parameter index is out of bounds

allocateLocal

int allocateLocal(TypeKind typeKind)
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 the maxLocals of the original method. For a method being built directly, fresh locals begin after the last parameter slot.

If the current code builder is a CodeBuilder.BlockCodeBuilder, at the end of the block, locals are reset to their value at the beginning of the block.

Parameters:
typeKind - the type of the local variable
Returns:
the local variable slot of a fresh local variable

transforming

default CodeBuilder transforming(CodeTransform transform, Consumer<CodeBuilder> handler)
Apply a transform to the code built by a handler, directing results to this builder.
API Note:
This is similar to ClassFileBuilder.transform(CompoundElement, ClassFileTransform), but this does not require the code elements to be viewed as a CodeModel first.
Parameters:
transform - the transform to apply to the code built by the handler
handler - the handler that receives a CodeBuilder to build the code
Returns:
this builder

block

default CodeBuilder block(Consumer<CodeBuilder.BlockCodeBuilder> handler)
Adds a lexical block to the method being built.

Within this block, the startLabel() and endLabel() correspond to the start and end of the block, and the CodeBuilder.BlockCodeBuilder.breakLabel() also corresponds to the end of the block, or the cursor position immediately after this call in this builder.

Parameters:
handler - handler that receives a CodeBuilder.BlockCodeBuilder to generate the body of the lexical block
Returns:
this builder

ifThen

default CodeBuilder ifThen(Consumer<CodeBuilder.BlockCodeBuilder> thenHandler)
Adds an "if-then" block that is conditional on the boolean value on top of the operand stack. Control flow enters the "then" block if the value represents true.

The CodeBuilder.BlockCodeBuilder.breakLabel() for the "then" block corresponds to the cursor position immediately after this call in this builder.

Parameters:
thenHandler - handler that receives a CodeBuilder.BlockCodeBuilder to generate the body of the if
Returns:
this builder
See Also:

ifThen

default CodeBuilder ifThen(Opcode opcode, Consumer<CodeBuilder.BlockCodeBuilder> thenHandler)
Adds an "if-then" block that is conditional on the value(s) on top of the operand stack in accordance with the given opcode. Control flow enters the "then" block if the branching condition for opcode succeeds.

The CodeBuilder.BlockCodeBuilder.breakLabel() for the "then" block corresponds to the cursor position immediately after this call in this builder.

Parameters:
opcode - the operation code for a branch instruction that accepts one or two operands on the stack
thenHandler - handler that receives a CodeBuilder.BlockCodeBuilder to 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

ifThenElse

default CodeBuilder ifThenElse(Consumer<CodeBuilder.BlockCodeBuilder> thenHandler, Consumer<CodeBuilder.BlockCodeBuilder> elseHandler)
Adds an "if-then-else" block that is conditional on the boolean value on top of the operand stack. Control flow enters the "then" block if the value represents true, and enters the "else" block otherwise.

The CodeBuilder.BlockCodeBuilder.breakLabel() for each block corresponds to the cursor position immediately after this call in this builder.

Parameters:
thenHandler - handler that receives 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
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 for opcode succeeds, and enters the "else" block otherwise.

The CodeBuilder.BlockCodeBuilder.breakLabel() for each block corresponds to the cursor position immediately after this call in this builder.

Parameters:
opcode - the operation code for a branch instruction that accepts one or two operands on the stack
thenHandler - handler that receives a CodeBuilder.BlockCodeBuilder to generate the body of 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

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 the catchesHandler correspond to the cursor position immediately after this call in this builder.

Parameters:
tryHandler - handler that receives a CodeBuilder.BlockCodeBuilder to generate the body of the try block.
catchesHandler - a handler that receives a CodeBuilder.CatchBuilder to generate bodies of catch blocks
Returns:
this builder
Throws:
IllegalArgumentException - if the try block is empty
See Also:

loadLocal

default CodeBuilder loadLocal(TypeKind tk, int slot)
Generates 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 tk is void or slot is out of range
See Also:

storeLocal

default CodeBuilder storeLocal(TypeKind tk, int slot)
Generates 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 tk is void or slot is out of range
See Also:

branch

default CodeBuilder branch(Opcode op, Label target)
Generates a branch instruction.

This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set, the opcode has size 3, and target cannot be encoded as a BCI offset in [-32768, 32767].

Parameters:
op - the branch opcode
target - the branch target
Returns:
this builder
Throws:
IllegalArgumentException - if op is not of Opcode.Kind.BRANCH
See Also:

return_

default CodeBuilder return_(TypeKind tk)
Generates a return instruction.
Parameters:
tk - the return type
Returns:
this builder
See Also:

fieldAccess

default CodeBuilder fieldAccess(Opcode opcode, FieldRefEntry ref)
Generates an instruction to access a field.
Parameters:
opcode - the field access opcode
ref - the field reference
Returns:
this builder
Throws:
IllegalArgumentException - if opcode is not of Opcode.Kind.FIELD_ACCESS
See Also:

fieldAccess

default CodeBuilder fieldAccess(Opcode opcode, ClassDesc owner, String name, ClassDesc type)
Generates 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 opcode is not of Opcode.Kind.FIELD_ACCESS, or owner is primitive
See Also:

invoke

default CodeBuilder invoke(Opcode opcode, MemberRefEntry ref)
Generates an instruction to invoke a method.
Parameters:
opcode - the invoke opcode
ref - the interface method or method reference
Returns:
this builder
Throws:
IllegalArgumentException - if opcode is not of Opcode.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 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 opcode is not of Opcode.Kind.INVOKE, or owner is primitive
See Also:

arrayLoad

default CodeBuilder arrayLoad(TypeKind tk)
Generates an instruction to load from an array.
Parameters:
tk - the array element type
Returns:
this builder
Throws:
IllegalArgumentException - if tk is void
See Also:

arrayStore

default CodeBuilder arrayStore(TypeKind tk)
Generates an instruction to store into an array.
Parameters:
tk - the array element type
Returns:
this builder
Throws:
IllegalArgumentException - if tk is void
See Also:

conversion

default CodeBuilder conversion(TypeKind fromType, TypeKind toType)
Generates instruction(s) to convert fromType to toType.
Parameters:
fromType - the source type
toType - the target type
Returns:
this builder
Throws:
IllegalArgumentException - for conversions of void or reference
See Also:

loadConstant

default CodeBuilder loadConstant(ConstantDesc value)
Generates an instruction pushing a constant onto the operand stack.
Parameters:
value - the constant value, may be null
Returns:
this builder
See Also:

loadConstant

default CodeBuilder loadConstant(int value)
Generates an instruction pushing a constant int value onto the operand stack. This is equivalent to loadConstant(Integer.valueOf(value)).
Parameters:
value - the int value
Returns:
this builder
See Also:

loadConstant

default CodeBuilder loadConstant(long value)
Generates an instruction pushing a constant long value onto the operand stack. This is equivalent to loadConstant(Long.valueOf(value)).
Parameters:
value - the long value
Returns:
this builder
See Also:

loadConstant

default CodeBuilder loadConstant(float value)
Generates an instruction pushing a constant float value onto the operand stack. This is equivalent to loadConstant(Float.valueOf(value)).

All NaN values of the float may or may not be collapsed into a single "canonical" NaN value.

Parameters:
value - the float value
Returns:
this builder
See Also:

loadConstant

default CodeBuilder loadConstant(double value)
Generates an instruction pushing a constant double value onto the operand stack. This is equivalent to loadConstant(Double.valueOf(value)).

All NaN values of the double may or may not be collapsed into a single "canonical" NaN value.

Parameters:
value - the double value
Returns:
this builder
See Also:

nop

default CodeBuilder nop()
Generates a do-nothing instruction.
Returns:
this builder
See Also:

newBoundLabel

default Label newBoundLabel()
Creates a new label bound at the current position.
Returns:
this builder
See Also:

labelBinding

default CodeBuilder labelBinding(Label label)
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

default CodeBuilder lineNumber(int line)
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

default CodeBuilder exceptionCatch(Label start, Label end, Label handler, ClassEntry catchType)
Declares an exception table entry.

This call may be ignored if any of the argument labels is not bound and ClassFile.DeadLabelsOption.DROP_DEAD_LABELS is set.

Parameters:
start - the try block start
end - the try block end
handler - the exception handler start
catchType - the catch type, may be null to catch all exceptions and errors
Returns:
this builder
See Also:

exceptionCatch

default CodeBuilder exceptionCatch(Label start, Label end, Label handler, Optional<ClassEntry> catchType)
Declares an exception table entry.

This call may be ignored if any of the argument labels is not bound and ClassFile.DeadLabelsOption.DROP_DEAD_LABELS is set.

Parameters:
start - the try block start
end - the try block end
handler - the exception handler start
catchType - the optional catch type, empty to catch all exceptions and errors
Returns:
this builder
See Also:

exceptionCatch

default CodeBuilder exceptionCatch(Label start, Label end, Label handler, ClassDesc catchType)
Declares an exception table entry.

This call may be ignored if any of the argument labels is not bound and ClassFile.DeadLabelsOption.DROP_DEAD_LABELS is set.

Parameters:
start - the try block start
end - the try block end
handler - the exception handler start
catchType - the catch type
Returns:
this builder
Throws:
IllegalArgumentException - if catchType is primitive
See Also:

exceptionCatchAll

default CodeBuilder exceptionCatchAll(Label start, Label end, Label handler)
Declares an exception table entry catching all exceptions and errors.

This call may be ignored if any of the argument labels is not bound and ClassFile.DeadLabelsOption.DROP_DEAD_LABELS is set.

Parameters:
start - the try block start
end - the try block end
handler - the exception handler start
Returns:
this builder
See Also:

characterRange

default CodeBuilder characterRange(Label startScope, Label endScope, int characterRangeStart, int characterRangeEnd, int flags)
Declares a character range entry.

This call may be ignored if ClassFile.DebugElementsOption.DROP_DEBUG is set, or if any of the argument labels is not bound and ClassFile.DeadLabelsOption.DROP_DEAD_LABELS is set.

Parameters:
startScope - the start scope of the character range
endScope - the end scope of the character range
characterRangeStart - the encoded start of the character range region (inclusive)
characterRangeEnd - the encoded end of the character range region (exclusive)
flags - the flags word, indicating the kind of range
Returns:
this builder
See Also:

localVariable

default CodeBuilder localVariable(int slot, Utf8Entry nameEntry, Utf8Entry descriptorEntry, Label startScope, Label endScope)
Declares a local variable entry.

This call may be ignored if ClassFile.DebugElementsOption.DROP_DEBUG is set, or if any of the argument labels is not bound and ClassFile.DeadLabelsOption.DROP_DEAD_LABELS is set.

Parameters:
slot - the local variable slot
nameEntry - the variable name
descriptorEntry - the variable descriptor
startScope - the start scope of the variable
endScope - the end scope of the variable
Returns:
this builder
Throws:
IllegalArgumentException - if slot is out of range
See Also:

localVariable

default CodeBuilder localVariable(int slot, String name, ClassDesc descriptor, Label startScope, Label endScope)
Declares a local variable entry.

This call may be ignored if ClassFile.DebugElementsOption.DROP_DEBUG is set, or if any of the argument labels is not bound and ClassFile.DeadLabelsOption.DROP_DEAD_LABELS is set.

Parameters:
slot - the local variable slot
name - the variable name
descriptor - the variable descriptor
startScope - the start scope of the variable
endScope - the end scope of the variable
Returns:
this builder
Throws:
IllegalArgumentException - if slot is out of range
See Also:

localVariableType

default CodeBuilder localVariableType(int slot, Utf8Entry nameEntry, Utf8Entry signatureEntry, Label startScope, Label endScope)
Declares a local variable type entry.

This call may be ignored if ClassFile.DebugElementsOption.DROP_DEBUG is set, or if any of the argument labels is not bound and ClassFile.DeadLabelsOption.DROP_DEAD_LABELS is set.

API Note:
When a local variable type entry is declared, a local variable entry with the descriptor derived from erasure (JLS 4.6) of the signature should be declared as well.
Parameters:
slot - the local variable slot
nameEntry - the variable name
signatureEntry - the variable signature
startScope - the start scope of the variable
endScope - the end scope of the variable
Returns:
this builder
Throws:
IllegalArgumentException - if slot is out of range
See Also:

localVariableType

default CodeBuilder localVariableType(int slot, String name, Signature signature, Label startScope, Label endScope)
Declares a local variable type entry.

This call may be ignored if ClassFile.DebugElementsOption.DROP_DEBUG is set, or if any of the argument labels is not bound and ClassFile.DeadLabelsOption.DROP_DEAD_LABELS is set.

API Note:
When a local variable type entry is declared, a local variable entry with the descriptor derived from erasure (JLS 4.6) of the signature should be declared as well.
Parameters:
slot - the local variable slot
name - the variable name
signature - the variable signature
startScope - the start scope of the variable
endScope - the end scope of the variable
Returns:
this builder
Throws:
IllegalArgumentException - if slot is out of range
See Also:

aconst_null

default CodeBuilder aconst_null()
Generates an instruction pushing the null object reference onto the operand stack.
Returns:
this builder
See Also:

aaload

default CodeBuilder aaload()
Generates an instruction to load from a reference array.
Returns:
this builder
See Also:

aastore

default CodeBuilder aastore()
Generates an instruction to store into a reference array.
Returns:
this builder
See Also:

aload

default CodeBuilder aload(int slot)
Generates an instruction to load a reference from a local variable.

This may also generate aload_<N> and wide aload instructions.

Parameters:
slot - the local variable slot
Returns:
this builder
Throws:
IllegalArgumentException - if slot is out of range
See Also:

anewarray

default CodeBuilder anewarray(ClassEntry classEntry)
Generates an instruction to create a new array of reference.
Parameters:
classEntry - the component type
Returns:
this builder
See Also:

anewarray

default CodeBuilder anewarray(ClassDesc className)
Generates an instruction to create a new array of reference.
Parameters:
className - the component type
Returns:
this builder
Throws:
IllegalArgumentException - if className represents a primitive type
See Also:

areturn

default CodeBuilder areturn()
Generates an instruction to return a reference from this method.
Returns:
this builder
See Also:

arraylength

default CodeBuilder arraylength()
Generates an instruction to get the length of an array.
Returns:
this builder
See Also:

astore

default CodeBuilder astore(int slot)
Generates an instruction to store a reference into a local variable. Such an instruction can also store a returnAddress.

This may also generate astore_<N> and wide astore instructions.

Parameters:
slot - the local variable slot
Returns:
this builder
Throws:
IllegalArgumentException - if slot is out of range
See Also:

athrow

default CodeBuilder athrow()
Generates an instruction to throw an exception or error.
Returns:
this builder
See Also:

baload

default CodeBuilder baload()
Generates an instruction to load from a byte or boolean array.
Returns:
this builder
See Also:

bastore

default CodeBuilder bastore()
Generates an instruction to store into a byte or boolean array.
Returns:
this builder
See Also:

bipush

default CodeBuilder bipush(int b)
Generates an instruction pushing an int in the range of byte ([-128, 127]) onto the operand stack.
Parameters:
b - the int in the range of byte
Returns:
this builder
Throws:
IllegalArgumentException - if b is out of range of byte
See Also:

caload

default CodeBuilder caload()
Generates an instruction to load from a char array.
Returns:
this builder
See Also:

castore

default CodeBuilder castore()
Generates an instruction to store into a char array.
Returns:
this builder
See Also:

checkcast

default CodeBuilder checkcast(ClassEntry type)
Generates an instruction to check whether an object is of the given type, throwing a ClassCastException if the check fails.
Parameters:
type - the object type
Returns:
this builder
See Also:

checkcast

default CodeBuilder checkcast(ClassDesc type)
Generates an instruction to check whether an object is of the given type, throwing a ClassCastException if the check fails.
Parameters:
type - the object type
Returns:
this builder
Throws:
IllegalArgumentException - if type represents a primitive type
See Also:

d2f

default CodeBuilder d2f()
Generates an instruction to convert a double into a float.
Returns:
this builder
See Also:

d2i

default CodeBuilder d2i()
Generates an instruction to convert a double into an int.
Returns:
this builder
See Also:

d2l

default CodeBuilder d2l()
Generates an instruction to convert a double into a long.
Returns:
this builder
See Also:

dadd

default CodeBuilder dadd()
Generates an instruction to add two doubles.
Returns:
this builder
See Also:

daload

default CodeBuilder daload()
Generates an instruction to load from a double array.
Returns:
this builder
See Also:

dastore

default CodeBuilder dastore()
Generates an instruction to store into a double array.
Returns:
this builder
See Also:

dcmpg

default CodeBuilder dcmpg()
Generates an instruction to compare two doubles, producing 1 if any operand is NaN.
Returns:
this builder
See Also:

dcmpl

default CodeBuilder dcmpl()
Generates an instruction to compare two doubles, producing -1 if any operand is NaN.
Returns:
this builder
See Also:

dconst_0

default CodeBuilder dconst_0()
Generates an instruction pushing double constant 0 onto the operand stack.
Returns:
this builder
See Also:

dconst_1

default CodeBuilder dconst_1()
Generates an instruction pushing double constant 1 onto the operand stack.
Returns:
this builder
See Also:

ddiv

default CodeBuilder ddiv()
Generates an instruction to divide doubles.
Returns:
this builder
See Also:

dload

default CodeBuilder dload(int slot)
Generates an instruction to load a double from a local variable.

This may also generate dload_<N> and wide dload instructions.

Parameters:
slot - the local variable slot
Returns:
this builder
Throws:
IllegalArgumentException - if slot is out of range
See Also:

dmul

default CodeBuilder dmul()
Generates an instruction to multiply doubles.
Returns:
this builder
See Also:

dneg

default CodeBuilder dneg()
Generates an instruction to negate a double.
Returns:
this builder
See Also:

drem

default CodeBuilder drem()
Generates an instruction to calculate double remainder.
Returns:
this builder
See Also:

dreturn

default CodeBuilder dreturn()
Generates an instruction to return a double from this method.
Returns:
this builder
See Also:

dstore

default CodeBuilder dstore(int slot)
Generates an instruction to store a double into a local variable.

This may also generate dstore_<N> and wide dstore instructions.

Parameters:
slot - the local variable slot
Returns:
this builder
Throws:
IllegalArgumentException - if slot is out of range
See Also:

dsub

default CodeBuilder dsub()
Generates an instruction to subtract doubles.
Returns:
this builder
See Also:

dup

default CodeBuilder dup()
Generates an instruction to duplicate the top operand stack value.
Returns:
this builder
See Also:

dup2

default CodeBuilder dup2()
Generates an instruction to duplicate the top one or two operand stack value.
Returns:
this builder
See Also:

dup2_x1

default CodeBuilder 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

default CodeBuilder dup2_x2()
Generates an instruction to duplicate the top one or two operand stack values and insert two, three, or four values down.
Returns:
this builder
See Also:

dup_x1

default CodeBuilder dup_x1()
Generates an instruction to duplicate the top operand stack value and insert two values down.
Returns:
this builder
See Also:

dup_x2

default CodeBuilder 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

default CodeBuilder f2d()
Generates an instruction to convert a float into a double.
Returns:
this builder
See Also:

f2i

default CodeBuilder f2i()
Generates an instruction to convert a float into an int.
Returns:
this builder
See Also:

f2l

default CodeBuilder f2l()
Generates an instruction to convert a float into a long.
Returns:
this builder
See Also:

fadd

default CodeBuilder fadd()
Generates an instruction to add two floats.
Returns:
this builder
See Also:

faload

default CodeBuilder faload()
Generates an instruction to load from a float array.
Returns:
this builder
See Also:

fastore

default CodeBuilder fastore()
Generates an instruction to store into a float array.
Returns:
this builder
See Also:

fcmpg

default CodeBuilder fcmpg()
Generates an instruction to compare floats, producing 1 if any operand is NaN.
Returns:
this builder
See Also:

fcmpl

default CodeBuilder fcmpl()
Generates an instruction to compare floats, producing -1 if any operand is NaN.
Returns:
this builder
See Also:

fconst_0

default CodeBuilder fconst_0()
Generates an instruction pushing float constant 0 onto the operand stack.
Returns:
this builder
See Also:

fconst_1

default CodeBuilder fconst_1()
Generates an instruction pushing float constant 1 onto the operand stack.
Returns:
this builder
See Also:

fconst_2

default CodeBuilder fconst_2()
Generates an instruction pushing float constant 2 onto the operand stack.
Returns:
this builder
See Also:

fdiv

default CodeBuilder fdiv()
Generates an instruction to divide floats.
Returns:
this builder
See Also:

fload

default CodeBuilder fload(int slot)
Generates an instruction to load a float from a local variable.

This may also generate fload_<N> and wide fload instructions.

Parameters:
slot - the local variable slot
Returns:
this builder
Throws:
IllegalArgumentException - if slot is out of range
See Also:

fmul

default CodeBuilder fmul()
Generates an instruction to multiply floats.
Returns:
this builder
See Also:

fneg

default CodeBuilder fneg()
Generates an instruction to negate a float.
Returns:
this builder
See Also:

frem

default CodeBuilder frem()
Generates an instruction to calculate floats remainder.
Returns:
this builder
See Also:

freturn

default CodeBuilder freturn()
Generates an instruction to return a float from this method.
Returns:
this builder
See Also:

fstore

default CodeBuilder fstore(int slot)
Generates an instruction to store a float into a local variable.

This may also generate fstore_<N> and wide fstore instructions.

Parameters:
slot - the local variable slot
Returns:
this builder
Throws:
IllegalArgumentException - if slot is out of range
See Also:

fsub

default CodeBuilder fsub()
Generates an instruction to subtract floats.
Returns:
this builder
See Also:

getfield

default CodeBuilder getfield(FieldRefEntry ref)
Generates an instruction to fetch field from an object.
Parameters:
ref - the field reference
Returns:
this builder
See Also:

getfield

default CodeBuilder getfield(ClassDesc owner, String name, ClassDesc type)
Generates 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 owner represents a primitive type
See Also:

getstatic

default CodeBuilder getstatic(FieldRefEntry ref)
Generates an instruction to get static field from a class or interface.
Parameters:
ref - the field reference
Returns:
this builder
See Also:

getstatic

default CodeBuilder getstatic(ClassDesc owner, String name, ClassDesc type)
Generates 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 owner represents a primitive type
See Also:

goto_

default CodeBuilder goto_(Label target)
Generates an instruction to branch always.

This may also generate goto_w instructions if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set.

API Note:
The instruction's name is goto, which coincides with a reserved keyword of the Java programming language, thus this method is named with an extra _ suffix instead.
Parameters:
target - the branch target
Returns:
this builder
See Also:

goto_w

default CodeBuilder goto_w(Label target)
Generates an instruction to branch always with wide index.
Parameters:
target - the branch target
Returns:
this builder
See Also:

i2b

default CodeBuilder i2b()
Generates an instruction to truncate an int into the range of byte and sign-extend it.
Returns:
this builder
See Also:

i2c

default CodeBuilder i2c()
Generates an instruction to truncate an int into the range of char and zero-extend it.
Returns:
this builder
See Also:

i2d

default CodeBuilder i2d()
Generates an instruction to convert an int into a double.
Returns:
this builder
See Also:

i2f

default CodeBuilder i2f()
Generates an instruction to convert an int into a float.
Returns:
this builder
See Also:

i2l

default CodeBuilder i2l()
Generates an instruction to convert an int into a long.
Returns:
this builder
See Also:

i2s

default CodeBuilder i2s()
Generates an instruction to truncate an int into the range of short and sign-extend it.
Returns:
this builder
See Also:

iadd

default CodeBuilder iadd()
Generates an instruction to add two ints.
Returns:
this builder
See Also:

iaload

default CodeBuilder iaload()
Generates an instruction to load from an int array.
Returns:
this builder
See Also:

iand

default CodeBuilder iand()
Generates an instruction to calculate bitwise AND of ints, also used for boolean AND.
Returns:
this builder
See Also:

iastore

default CodeBuilder iastore()
Generates an instruction to store into an int array.
Returns:
this builder
See Also:

iconst_0

default CodeBuilder iconst_0()
Generates an instruction pushing int constant 0 onto the operand stack.
Returns:
this builder
See Also:

iconst_1

default CodeBuilder iconst_1()
Generates an instruction pushing int constant 1 onto the operand stack.
Returns:
this builder
See Also:

iconst_2

default CodeBuilder iconst_2()
Generates an instruction pushing int constant 2 onto the operand stack.
Returns:
this builder
See Also:

iconst_3

default CodeBuilder iconst_3()
Generates an instruction pushing int constant 3 onto the operand stack.
Returns:
this builder
See Also:

iconst_4

default CodeBuilder iconst_4()
Generates an instruction pushing int constant 4 onto the operand stack.
Returns:
this builder
See Also:

iconst_5

default CodeBuilder iconst_5()
Generates an instruction pushing int constant 5 onto the operand stack.
Returns:
this builder
See Also:

iconst_m1

default CodeBuilder iconst_m1()
Generates an instruction pushing int constant -1 onto the operand stack.
Returns:
this builder
See Also:

idiv

default CodeBuilder idiv()
Generates an instruction to divide ints.
Returns:
this builder
See Also:

if_acmpeq

default CodeBuilder if_acmpeq(Label target)
Generates an instruction to branch if reference comparison operand1 == operand2 succeeds.

This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and target cannot be encoded as a BCI offset in [-32768, 32767].

Parameters:
target - the branch target
Returns:
this builder
See Also:

if_acmpne

default CodeBuilder if_acmpne(Label target)
Generates an instruction to branch if reference comparison operand1 != operand2 succeeds.

This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and target cannot be encoded as a BCI offset in [-32768, 32767].

Parameters:
target - the branch target
Returns:
this builder
See Also:

if_icmpeq

default CodeBuilder if_icmpeq(Label target)
Generates an instruction to branch if int comparison operand1 == operand2 succeeds.

This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and target cannot be encoded as a BCI offset in [-32768, 32767].

Parameters:
target - the branch target
Returns:
this builder
See Also:

if_icmpge

default CodeBuilder if_icmpge(Label target)
Generates an instruction to branch if int comparison operand1 >= operand2 succeeds.

This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and target cannot be encoded as a BCI offset in [-32768, 32767].

Parameters:
target - the branch target
Returns:
this builder
See Also:

if_icmpgt

default CodeBuilder if_icmpgt(Label target)
Generates an instruction to branch if int comparison operand1 > operand2 succeeds.

This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and target cannot be encoded as a BCI offset in [-32768, 32767].

Parameters:
target - the branch target
Returns:
this builder
See Also:

if_icmple

default CodeBuilder if_icmple(Label target)
Generates an instruction to branch if int comparison operand1 <= operand2 succeeds.

This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and target cannot be encoded as a BCI offset in [-32768, 32767].

Parameters:
target - the branch target
Returns:
this builder
See Also:

if_icmplt

default CodeBuilder if_icmplt(Label target)
Generates an instruction to branch if int comparison operand1 < operand2 succeeds.

This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and target cannot be encoded as a BCI offset in [-32768, 32767].

Parameters:
target - the branch target
Returns:
this builder
See Also:

if_icmpne

default CodeBuilder if_icmpne(Label target)
Generates an instruction to branch if int comparison operand1 != operand2 succeeds.

This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and target cannot be encoded as a BCI offset in [-32768, 32767].

Parameters:
target - the branch target
Returns:
this builder
See Also:

ifnonnull

default CodeBuilder ifnonnull(Label target)
Generates an instruction to branch if reference is not null.

This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and target cannot be encoded as a BCI offset in [-32768, 32767].

Parameters:
target - the branch target
Returns:
this builder
See Also:

ifnull

default CodeBuilder ifnull(Label target)
Generates an instruction to branch if reference is null.

This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and target cannot be encoded as a BCI offset in [-32768, 32767].

Parameters:
target - the branch target
Returns:
this builder
See Also:

ifeq

default CodeBuilder ifeq(Label target)
Generates an instruction to branch if int comparison with zero == 0 succeeds.

This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and target cannot be encoded as a BCI offset in [-32768, 32767].

Parameters:
target - the branch target
Returns:
this builder
See Also:

ifge

default CodeBuilder ifge(Label target)
Generates an instruction to branch if int comparison with zero >= 0 succeeds.

This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and target cannot be encoded as a BCI offset in [-32768, 32767].

Parameters:
target - the branch target
Returns:
this builder
See Also:

ifgt

default CodeBuilder ifgt(Label target)
Generates an instruction to branch if int comparison with zero > 0 succeeds.

This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and target cannot be encoded as a BCI offset in [-32768, 32767].

Parameters:
target - the branch target
Returns:
this builder
See Also:

ifle

default CodeBuilder ifle(Label target)
Generates an instruction to branch if int comparison with zero <= 0 succeeds.

This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and target cannot be encoded as a BCI offset in [-32768, 32767].

Parameters:
target - the branch target
Returns:
this builder
See Also:

iflt

default CodeBuilder iflt(Label target)
Generates an instruction to branch if int comparison with zero < 0 succeeds.

This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and target cannot be encoded as a BCI offset in [-32768, 32767].

Parameters:
target - the branch target
Returns:
this builder
See Also:

ifne

default CodeBuilder ifne(Label target)
Generates an instruction to branch if int comparison with zero != 0 succeeds.

This may generate multiple instructions to accomplish the same effect if ClassFile.ShortJumpsOption.FIX_SHORT_JUMPS is set and target cannot be encoded as a BCI offset in [-32768, 32767].

Parameters:
target - the branch target
Returns:
this builder
See Also:

iinc

default CodeBuilder iinc(int slot, int val)
Generates an instruction to increment an int local variable by a constant.

This may also generate wide iinc instructions if slot exceeds 255 or val exceeds the range of byte.

Parameters:
slot - the local variable slot
val - the increment value
Returns:
this builder
Throws:
IllegalArgumentException - if slot or val is out of range
See Also:

iload

default CodeBuilder iload(int slot)
Generates an instruction to load an int from a local variable.

This may also generate iload_<N> and wide iload instructions.

Parameters:
slot - the local variable slot
Returns:
this builder
Throws:
IllegalArgumentException - if slot is out of range
See Also:

imul

default CodeBuilder imul()
Generates an instruction to multiply ints.
Returns:
this builder
See Also:

ineg

default CodeBuilder ineg()
Generates an instruction to negate an int.
Returns:
this builder
See Also:

instanceOf

default CodeBuilder instanceOf(ClassEntry target)
Generates an instruction to determine if an object is of the given type, producing a boolean result on the operand stack.
API Note:
The instruction's name is instanceof, which coincides with a reserved keyword of the Java programming language, thus this method is named with camel case instead.
Parameters:
target - the target type
Returns:
this builder
See Also:

instanceOf

default CodeBuilder instanceOf(ClassDesc target)
Generates an instruction to determine if an object is of the given type, producing a boolean result on the operand stack.
API Note:
The instruction's name is instanceof, which coincides with a reserved keyword of the Java programming language, thus this method is named with camel case instead.
Parameters:
target - the target type
Returns:
this builder
Throws:
IllegalArgumentException - if target represents a primitive type
See Also:

invokedynamic

default CodeBuilder invokedynamic(InvokeDynamicEntry ref)
Generates an instruction to invoke a dynamically-computed call site.
Parameters:
ref - the dynamic call site
Returns:
this builder
See Also:

invokedynamic

default CodeBuilder invokedynamic(DynamicCallSiteDesc ref)
Generates an instruction to invoke a dynamically-computed call site.
Parameters:
ref - the dynamic call site
Returns:
this builder
See Also:

invokeinterface

default CodeBuilder invokeinterface(InterfaceMethodRefEntry ref)
Generates an instruction to invoke an interface method.
Parameters:
ref - the interface method reference
Returns:
this builder
See Also:

invokeinterface

default CodeBuilder invokeinterface(ClassDesc owner, String name, MethodTypeDesc type)
Generates 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 owner represents a primitive type
See Also:

invokespecial

default CodeBuilder invokespecial(InterfaceMethodRefEntry ref)
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

default CodeBuilder invokespecial(MethodRefEntry ref)
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

default CodeBuilder invokespecial(ClassDesc owner, String name, MethodTypeDesc type)
Generates an instruction to invoke an instance method in a class; direct invocation of instance initialization methods and methods of the current class and its supertypes.
Parameters:
owner - the owner class, must not be an interface
name - the method name
type - the method type
Returns:
this builder
Throws:
IllegalArgumentException - if owner represents a primitive type
See Also:

invokespecial

default CodeBuilder invokespecial(ClassDesc owner, String name, MethodTypeDesc type, boolean isInterface)
Generates an instruction to invoke an instance method; direct invocation of instance initialization methods and methods of the current class and its supertypes.
Parameters:
owner - the owner class or interface
name - the method name
type - the method type
isInterface - whether the owner is an interface
Returns:
this builder
Throws:
IllegalArgumentException - if owner represents a primitive type
See Also:

invokestatic

default CodeBuilder invokestatic(InterfaceMethodRefEntry ref)
Generates an instruction to invoke a class (static) method of an interface.
Parameters:
ref - the interface method reference
Returns:
this builder
See Also:

invokestatic

default CodeBuilder invokestatic(MethodRefEntry ref)
Generates an instruction to invoke a class (static) method of a class.
Parameters:
ref - the method reference
Returns:
this builder
See Also:

invokestatic

default CodeBuilder invokestatic(ClassDesc owner, String name, MethodTypeDesc type)
Generates 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 owner represents a primitive type
See Also:

invokestatic

default CodeBuilder invokestatic(ClassDesc owner, String name, MethodTypeDesc type, boolean isInterface)
Generates an instruction to invoke a class (static) method.
Parameters:
owner - the owner class or interface
name - the method name
type - the method type
isInterface - whether the owner is an interface
Returns:
this builder
Throws:
IllegalArgumentException - if owner represents a primitive type
See Also:

invokevirtual

default CodeBuilder invokevirtual(MethodRefEntry ref)
Generates an instruction to invoke an instance method; dispatch based on class.
Parameters:
ref - the method reference
Returns:
this builder
See Also:

invokevirtual

default CodeBuilder invokevirtual(ClassDesc owner, String name, MethodTypeDesc type)
Generates 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 owner represents a primitive type
See Also:

ior

default CodeBuilder ior()
Generates an instruction to calculate bitwise OR of ints, also used for boolean OR.
Returns:
this builder
See Also:

irem

default CodeBuilder irem()
Generates an instruction to calculate ints remainder.
Returns:
this builder
See Also:

ireturn

default CodeBuilder ireturn()
Generates an instruction to return an int from this method.
Returns:
this builder
See Also:

ishl

default CodeBuilder ishl()
Generates an instruction to shift an int left.
Returns:
this builder
See Also:

ishr

default CodeBuilder ishr()
Generates an instruction to shift an int right. This carries the sign bit to the vacated most significant bits, as opposed to iushr() that fills vacated most significant bits with 0.
Returns:
this builder
See Also:

istore

default CodeBuilder istore(int slot)
Generates an instruction to store an int into a local variable.

This may also generate istore_<N> and wide istore instructions.

Parameters:
slot - the local variable slot
Returns:
this builder
Throws:
IllegalArgumentException - if slot is out of range
See Also:

isub

default CodeBuilder isub()
Generates an instruction to subtract ints.
Returns:
this builder
See Also:

iushr

default CodeBuilder iushr()
Generates an instruction to logical shift an int right. This fills vacated most significant bits with 0, as opposed to ishr() that carries the sign bit to the vacated most significant bits.
Returns:
this builder
See Also:

ixor

default CodeBuilder ixor()
Generates an instruction to calculate bitwise XOR of ints. This can also be used for boolean XOR.
Returns:
this builder
See Also:

lookupswitch

default CodeBuilder lookupswitch(Label defaultTarget, List<SwitchCase> cases)
Generates 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

default CodeBuilder l2d()
Generates an instruction to convert a long into a double.
Returns:
this builder
See Also:

l2f

default CodeBuilder l2f()
Generates an instruction to convert a long into a float.
Returns:
this builder
See Also:

l2i

default CodeBuilder l2i()
Generates an instruction to convert a long into an int.
Returns:
this builder
See Also:

ladd

default CodeBuilder ladd()
Generates an instruction to add two longs.
Returns:
this builder
See Also:

laload

default CodeBuilder laload()
Generates an instruction to load from a long array.
Returns:
this builder
See Also:

land

default CodeBuilder land()
Generates an instruction to calculate bitwise AND of longs.
Returns:
this builder
See Also:

lastore

default CodeBuilder lastore()
Generates an instruction to store into a long array.
Returns:
this builder
See Also:

lcmp

default CodeBuilder lcmp()
Generates an instruction to compare longs.
Returns:
this builder
See Also:

lconst_0

default CodeBuilder lconst_0()
Generates an instruction pushing long constant 0 onto the operand stack.
Returns:
this builder
See Also:

lconst_1

default CodeBuilder lconst_1()
Generates an instruction pushing long constant 1 onto the operand stack.
Returns:
this builder
See Also:

ldc

default CodeBuilder ldc(ConstantDesc value)
Generates an instruction pushing an item from the run-time constant pool onto the operand stack.

This may also generate ldc_w and ldc2_w instructions.

API Note:
loadConstant generates more optimal instructions and should be used for general constants if an ldc instruction is not strictly required.
Parameters:
value - the constant value
Returns:
this builder
See Also:

ldc

default CodeBuilder ldc(LoadableConstantEntry entry)
Generates an instruction pushing an item from the run-time constant pool onto the operand stack.

This may also generate ldc_w and ldc2_w instructions.

Parameters:
entry - the constant value
Returns:
this builder
See Also:

ldiv

default CodeBuilder ldiv()
Generates an instruction to divide longs.
Returns:
this builder
See Also:

lload

default CodeBuilder lload(int slot)
Generates an instruction to load a long from a local variable.

This may also generate lload_<N> and wide lload instructions.

Parameters:
slot - the local variable slot
Returns:
this builder
Throws:
IllegalArgumentException - if slot is out of range
See Also:

lmul

default CodeBuilder lmul()
Generates an instruction to multiply longs.
Returns:
this builder
See Also:

lneg

default CodeBuilder lneg()
Generates an instruction to negate a long.
Returns:
this builder
See Also:

lor

default CodeBuilder lor()
Generates an instruction to calculate bitwise OR of longs.
Returns:
this builder
See Also:

lrem

default CodeBuilder lrem()
Generates an instruction to calculate longs remainder.
Returns:
this builder
See Also:

lreturn

default CodeBuilder lreturn()
Generates an instruction to return a long from this method.
Returns:
this builder
See Also:

lshl

default CodeBuilder lshl()
Generates an instruction to shift a long left.
Returns:
this builder
See Also:

lshr

default CodeBuilder lshr()
Generates an instruction to shift a long right. This carries the sign bit to the vacated most significant bits, as opposed to lushr() that fills vacated most significant bits with 0.
Returns:
this builder
See Also:

lstore

default CodeBuilder lstore(int slot)
Generates an instruction to store a long into a local variable.

This may also generate lstore_<N> and wide lstore instructions.

Parameters:
slot - the local variable slot
Returns:
this builder
Throws:
IllegalArgumentException - if slot is out of range
See Also:

lsub

default CodeBuilder lsub()
Generates an instruction to subtract longs.
Returns:
this builder
See Also:

lushr

default CodeBuilder lushr()
Generates an instruction to logical shift a long right. This fills vacated most significant bits with 0, as opposed to lshr() that carries the sign bit to the vacated most significant bits.
Returns:
this builder
See Also:

lxor

default CodeBuilder lxor()
Generates an instruction to calculate bitwise XOR of longs.
Returns:
this builder
See Also:

monitorenter

default CodeBuilder monitorenter()
Generates an instruction to enter monitor for an object.
Returns:
this builder
See Also:

monitorexit

default CodeBuilder monitorexit()
Generates an instruction to exit monitor for an object.
Returns:
this builder
See Also:

multianewarray

default CodeBuilder multianewarray(ClassEntry array, int dims)
Generates an instruction to create a new multidimensional array.
Parameters:
array - the array type
dims - the number of dimensions
Returns:
this builder
Throws:
IllegalArgumentException - if dims is out of range
See Also:

multianewarray

default CodeBuilder multianewarray(ClassDesc array, int dims)
Generates an instruction to create a new multidimensional array.
Parameters:
array - the array type
dims - the number of dimensions
Returns:
this builder
Throws:
IllegalArgumentException - if array represents a primitive type or if dims is out of range
See Also:

new_

default CodeBuilder new_(ClassEntry clazz)
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_

default CodeBuilder new_(ClassDesc clazz)
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 clazz represents a primitive type
See Also:

newarray

default CodeBuilder newarray(TypeKind typeKind)
Generates an instruction to create a new array of a primitive type.
Parameters:
typeKind - the primitive array type
Returns:
this builder
Throws:
IllegalArgumentException - when the typeKind is not a legal primitive array component type
See Also:

pop

default CodeBuilder pop()
Generates an instruction to pop the top operand stack value.
Returns:
this builder
See Also:

pop2

default CodeBuilder pop2()
Generates an instruction to pop the top one or two operand stack values.
Returns:
this builder
See Also:

putfield

default CodeBuilder putfield(FieldRefEntry ref)
Generates an instruction to set field in an object.
Parameters:
ref - the field reference
Returns:
this builder
See Also:

putfield

default CodeBuilder putfield(ClassDesc owner, String name, ClassDesc type)
Generates 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 owner represents a primitive type
See Also:

putstatic

default CodeBuilder putstatic(FieldRefEntry ref)
Generates an instruction to set static field in a class.
Parameters:
ref - the field reference
Returns:
this builder
See Also:

putstatic

default CodeBuilder putstatic(ClassDesc owner, String name, ClassDesc type)
Generates 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 owner represents a primitive type
See Also:

return_

default CodeBuilder return_()
Generates an instruction to return void from this method.
API Note:
The instruction's name is return, which coincides with a reserved keyword of the Java programming language, thus this method is named with an extra _ suffix instead.
Returns:
this builder
See Also:

saload

default CodeBuilder saload()
Generates an instruction to load from a short array.
Returns:
this builder
See Also:

sastore

default CodeBuilder sastore()
Generates an instruction to store into a short array.
Returns:
this builder
See Also:

sipush

default CodeBuilder sipush(int s)
Generates an instruction pushing an int in the range of short, [-32768, 32767], onto the operand stack.
Parameters:
s - the int in the range of short
Returns:
this builder
Throws:
IllegalArgumentException - if s is out of range of short
See Also:

swap

default CodeBuilder swap()
Generates an instruction to swap the top two operand stack values.
Returns:
this builder
See Also:

tableswitch

default CodeBuilder tableswitch(int low, int high, Label defaultTarget, List<SwitchCase> cases)
Generates 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:

tableswitch

default CodeBuilder tableswitch(Label defaultTarget, List<SwitchCase> cases)
Generates an instruction to access a jump table by index and jump. Computes the minimum and maximum keys from the cases.
Parameters:
defaultTarget - the default jump target
cases - the switch cases
Returns:
this builder
See Also:

© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/classfile/CodeBuilder.html