Top Inners Fields Constructors Methods
jdk.internal.classfile.impl

public final Class DirectCodeBuilder

extends AbstractDirectBuilder<CodeModel>
implements TerminalCodeBuilder
Class Inheritance
All Implemented Interfaces
jdk.internal.classfile.impl.TerminalCodeBuilder, jdk.internal.classfile.impl.LabelContext, java.lang.classfile.CodeBuilder, java.lang.classfile.ClassFileBuilder, java.util.function.Consumer
Imports
java.lang.constant.MethodTypeDesc, java.util.ArrayList, .Comparator, .HashMap, .IdentityHashMap, .List, .Map, java.util.function.Consumer, .Function, java.lang.classfile.Attribute, .Attributes, .BufWriter, .ClassFile, .CodeBuilder, .CodeElement, .CodeModel, .CustomAttribute, .Instruction, .Label, .Opcode, .TypeKind, java.lang.classfile.instruction.SwitchCase, .CharacterRange, .ExceptionCatch, .LocalVariable, .LocalVariableType, java.lang.classfile.attribute.CodeAttribute, .LineNumberTableAttribute, .StackMapTableAttribute, java.lang.classfile.constantpool.ClassEntry, .ConstantPoolBuilder, .DoubleEntry, .FieldRefEntry, .InterfaceMethodRefEntry, .InvokeDynamicEntry, .LoadableConstantEntry, .LongEntry, .MemberRefEntry

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static record
private static class

Field Summary

Modifier and TypeField and Description
pack-priv final BufWriter
private final List<CharacterRange>
private Attribute<CodeAttribute>
pack-priv List<DirectCodeBuilder.DeferredLabel>
private final Label
pack-priv final List<AbstractPseudoInstruction.ExceptionCatchImpl>
private DirectCodeBuilder.DedupLineNumberTableAttribute
private final List<LocalVariable>
private final List<LocalVariableType>
pack-priv final MethodInfo
private CodeAttribute
private int[]
private Map<CodeAttribute, int[]>
private final Label
private int
private final boolean
private final boolean
Inherited from jdk.internal.classfile.impl.AbstractDirectBuilder:
attributesconstantPoolcontextoriginal

Constructor Summary

AccessConstructor and Description
private
DirectCodeBuilder(MethodInfo methodInfo, SplitConstantPool constantPool, ClassFileImpl context, CodeModel original, boolean transformFwdJumps)

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
public void
public int
allocateLocal(TypeKind
the type of the local variable
typeKind
)

Implements java.lang.classfile.CodeBuilder.allocateLocal.

Returns the local variable slot of a fresh local variable.

public static Attribute<CodeAttribute>
build(MethodInfo methodInfo, Consumer<? super CodeBuilder> handler, SplitConstantPool constantPool, ClassFileImpl context, CodeModel original)

private void
private boolean
codeAndExceptionsMatch(int codeLength)

public int
public int
public Label
endLabel()

Implements java.lang.classfile.CodeBuilder.endLabel.

Returns the label associated with the end of the current block.

public Label
public int
public MethodInfo
public Label
public int
parameterSlot(int
the index of the parameter
paramNo
)

Implements java.lang.classfile.CodeBuilder.parameterSlot.

Returns the local variable slot associated with the specified parameter.

private void
public int
receiverSlot()

Implements java.lang.classfile.CodeBuilder.receiverSlot.

Returns the local variable slot associated with the receiver.

public void
public void
public void
setLineNumber(int lineNo)

public Label
startLabel()

Implements java.lang.classfile.CodeBuilder.startLabel.

Returns the label associated with the beginning of the current block.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public CodeBuilder
with(CodeElement
the element
element
)

Implements java.lang.classfile.ClassFileBuilder.with.

Integrate the ClassFileElement into the entity being built.

public void
writeArgumentConstant(Opcode opcode, int value)

public void
writeBranch(Opcode op, Label target)

public void
private void
public void
public void
writeIncrement(int slot, int val)

public void
public void
public void
private void
writeLabelOffset(int nBytes, int instructionPc, Label label)

public void
public void
writeLocalVar(Opcode opcode, int localVar)

public void
writeLookupSwitch(Label defaultTarget, List<SwitchCase> cases)

public void
public void
public void
writeNewPrimitiveArray(int newArrayCode)

public void
public void
writeTableSwitch(int low, int high, Label defaultTarget, List<SwitchCase> cases)

public void
Inherited from jdk.internal.classfile.impl.AbstractDirectBuilder:
constantPooloriginalsetOriginalwriteAttribute

Field Detail

bytecodesBufWriterback to summary
pack-priv final BufWriter bytecodesBufWriter
characterRangesback to summary
private final List<CharacterRange> characterRanges
contentback to summary
private Attribute<CodeAttribute> content
deferredLabelsback to summary
pack-priv List<DirectCodeBuilder.DeferredLabel> deferredLabels
endLabelback to summary
private final Label endLabel
handlersback to summary
pack-priv final List<AbstractPseudoInstruction.ExceptionCatchImpl> handlers
lineNumberWriterback to summary
private DirectCodeBuilder.DedupLineNumberTableAttribute lineNumberWriter
localVariablesback to summary
private final List<LocalVariable> localVariables
localVariableTypesback to summary
private final List<LocalVariableType> localVariableTypes
methodInfoback to summary
pack-priv final MethodInfo methodInfo
mruParentback to summary
private CodeAttribute mruParent
mruParentTableback to summary
private int[] mruParentTable
parentMapback to summary
private Map<CodeAttribute, int[]> parentMap
startLabelback to summary
private final Label startLabel
topLocalback to summary
private int topLocal
transformBackJumpsback to summary
private final boolean transformBackJumps
transformFwdJumpsback to summary
private final boolean transformFwdJumps

Constructor Detail

DirectCodeBuilderback to summary
private DirectCodeBuilder(MethodInfo methodInfo, SplitConstantPool constantPool, ClassFileImpl context, CodeModel original, boolean transformFwdJumps)

Method Detail

addCharacterRangeback to summary
public void addCharacterRange(CharacterRange element)
addHandlerback to summary
public void addHandler(ExceptionCatch element)
addLocalVariableback to summary
public void addLocalVariable(LocalVariable element)
addLocalVariableTypeback to summary
public void addLocalVariableType(LocalVariableType element)
allocateLocalback to summary
public int allocateLocal(TypeKind typeKind)

Implements java.lang.classfile.CodeBuilder.allocateLocal.

Doc from java.lang.classfile.CodeBuilder.allocateLocal.

Returns the local variable slot of a fresh local variable. This method makes reasonable efforts to determine which slots are in use and which are not. When transforming a method, fresh locals begin at 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 "block" code builder provided by block(Consumer), ifThen(Consumer), or ifThenElse(Consumer, Consumer), at the end of the block, locals are reset to their value at the beginning of the block.

Parameters
typeKind:TypeKind

the type of the local variable

Returns:int

the local variable slot of a fresh local variable

Annotations
@Override
buildback to summary
public static Attribute<CodeAttribute> build(MethodInfo methodInfo, Consumer<? super CodeBuilder> handler, SplitConstantPool constantPool, ClassFileImpl context, CodeModel original)
buildContentback to summary
private void buildContent()
codeAndExceptionsMatchback to summary
private boolean codeAndExceptionsMatch(int codeLength)
curPcback to summary
public int curPc()
curTopLocalback to summary
public int curTopLocal()

Implements jdk.internal.classfile.impl.TerminalCodeBuilder.curTopLocal.

endLabelback to summary
public Label endLabel()

Implements java.lang.classfile.CodeBuilder.endLabel.

Doc from java.lang.classfile.CodeBuilder.endLabel.

Returns the label associated with the end of the current block. If the current CodeBuilder 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:Label

the label associated with the end of the current block

Annotations
@Override
getLabelback to summary
public Label getLabel(int bci)

Implements jdk.internal.classfile.impl.LabelContext.getLabel.

Annotations
@Override
labelToBciback to summary
public int labelToBci(Label label)

Implements jdk.internal.classfile.impl.LabelContext.labelToBci.

Annotations
@Override
methodInfoback to summary
public MethodInfo methodInfo()
newLabelback to summary
public Label newLabel()

Implements java.lang.classfile.CodeBuilder.newLabel, jdk.internal.classfile.impl.LabelContext.newLabel.

Doc from java.lang.classfile.CodeBuilder.newLabel.

Returns a fresh unbound label.

Returns:Label

a fresh unbound label

Annotations
@Override
parameterSlotback to summary
public int parameterSlot(int paramNo)

Implements java.lang.classfile.CodeBuilder.parameterSlot.

Doc from java.lang.classfile.CodeBuilder.parameterSlot.

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:int

the index of the parameter

Returns:int

the local variable slot associated with the specified parameter

Annotations
@Override
processDeferredLabelsback to summary
private void processDeferredLabels()
receiverSlotback to summary
public int receiverSlot()

Implements java.lang.classfile.CodeBuilder.receiverSlot.

Doc from java.lang.classfile.CodeBuilder.receiverSlot.

Returns the local variable slot associated with the receiver. .

Returns:int

the local variable slot associated with the receiver

Annotations
@Override
setLabelTargetback to summary
public void setLabelTarget(Label label)
setLabelTargetback to summary
public void setLabelTarget(Label label, int bci)

Implements jdk.internal.classfile.impl.LabelContext.setLabelTarget.

Annotations
@Override
setLineNumberback to summary
public void setLineNumber(int lineNo)
startLabelback to summary
public Label startLabel()

Implements java.lang.classfile.CodeBuilder.startLabel.

Doc from java.lang.classfile.CodeBuilder.startLabel.

Returns the label associated with the beginning of the current block. If the current CodeBuilder 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:Label

the label associated with the beginning of the current block

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
withback to summary
public CodeBuilder with(CodeElement element)

Implements java.lang.classfile.ClassFileBuilder.with.

Doc from java.lang.classfile.ClassFileBuilder.with.

Integrate the ClassFileElement into the entity being built.

Parameters
element:CodeElement

the element

Returns:CodeBuilder

this builder

Annotations
@Override
writeArgumentConstantback to summary
public void writeArgumentConstant(Opcode opcode, int value)
writeBranchback to summary
public void writeBranch(Opcode op, Label target)
writeBytecodeback to summary
public void writeBytecode(Opcode opcode)
writeExceptionHandlersback to summary
private void writeExceptionHandlers(BufWriter buf)
writeFieldAccessback to summary
public void writeFieldAccess(Opcode opcode, FieldRefEntry ref)
writeIncrementback to summary
public void writeIncrement(int slot, int val)
writeInvokeDynamicback to summary
public void writeInvokeDynamic(InvokeDynamicEntry ref)
writeInvokeInterfaceback to summary
public void writeInvokeInterface(Opcode opcode, InterfaceMethodRefEntry ref, int count)
writeInvokeNormalback to summary
public void writeInvokeNormal(Opcode opcode, MemberRefEntry ref)
writeLabelOffsetback to summary
private void writeLabelOffset(int nBytes, int instructionPc, Label label)
writeLoadConstantback to summary
public void writeLoadConstant(Opcode opcode, LoadableConstantEntry value)
writeLocalVarback to summary
public void writeLocalVar(Opcode opcode, int localVar)
writeLookupSwitchback to summary
public void writeLookupSwitch(Label defaultTarget, List<SwitchCase> cases)
writeNewMultidimensionalArrayback to summary
public void writeNewMultidimensionalArray(int dimensions, ClassEntry type)
writeNewObjectback to summary
public void writeNewObject(ClassEntry type)
writeNewPrimitiveArrayback to summary
public void writeNewPrimitiveArray(int newArrayCode)
writeNewReferenceArrayback to summary
public void writeNewReferenceArray(ClassEntry type)
writeTableSwitchback to summary
public void writeTableSwitch(int low, int high, Label defaultTarget, List<SwitchCase> cases)
writeTypeCheckback to summary
public void writeTypeCheck(Opcode opcode, ClassEntry type)
jdk.internal.classfile.impl back to summary

private Class DirectCodeBuilder.DedupLineNumberTableAttribute

extends UnboundAttribute.AdHocAttribute<LineNumberTableAttribute>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final BufWriterImpl
private int
private int
private int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
push()

public void
public void
writeLineNumber(int pc, int lineNo)

public void

Field Detail

bufback to summary
private final BufWriterImpl buf
lastLineback to summary
private int lastLine
lastPcback to summary
private int lastPc
writtenLineback to summary
private int writtenLine

Constructor Detail

DedupLineNumberTableAttributeback to summary
public DedupLineNumberTableAttribute(ConstantPoolBuilder constantPool, ClassFileImpl context)

Method Detail

pushback to summary
private void push()
writeBodyback to summary
public void writeBody(BufWriter b)

Implements abstract jdk.internal.classfile.impl.UnboundAttribute.AdHocAttribute.writeBody.

Annotations
@Override
writeLineNumberback to summary
public void writeLineNumber(int pc, int lineNo)
writeToback to summary
public void writeTo(BufWriter b)

Overrides jdk.internal.classfile.impl.UnboundAttribute.AdHocAttribute.writeTo.

Implements java.lang.classfile.WritableElement.writeTo.

Doc from java.lang.classfile.WritableElement.writeTo.

Writes the element to the specified writer

Parameters
b:BufWriter

the writer

Annotations
@Override
jdk.internal.classfile.impl back to summary

private final Record DirectCodeBuilder.DeferredLabel

extends Record
Class Inheritance
Record Components
labelPc:int 
size:int 
instructionPc:int 
label:Label

Field Summary

Modifier and TypeField and Description
private final int
instructionPc

Record Component accessed by instructionPc().

private final Label
label

Record Component accessed by label().

private final int
labelPc

Record Component accessed by labelPc().

private final int
size

Record Component accessed by size().

Constructor Summary

AccessConstructor and Description
private
DeferredLabel(int labelPc, int size, int instructionPc, Label label)

Method Summary

Modifier and TypeMethod and Description
public final boolean
equals(Object
the reference object with which to compare.
o
)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public int
instructionPc()

Record Component getter of instructionPc.

public Label
label()

Record Component getter of label.

public int
labelPc()

Record Component getter of labelPc.

public int
size()

Record Component getter of size.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

instructionPcback to summary
private final int instructionPc

Record Component accessed by instructionPc().

labelback to summary
private final Label label

Record Component accessed by label().

labelPcback to summary
private final int labelPc

Record Component accessed by labelPc().

sizeback to summary
private final int size

Record Component accessed by size().

Constructor Detail

DeferredLabelback to summary
private DeferredLabel(int labelPc, int size, int instructionPc, Label label)

Method Detail

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this record is equal to the argument; false otherwise.

hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

Returns:int

a hash code value for this record.

instructionPcback to summary
public int instructionPc()

Record Component getter of instructionPc.

labelback to summary
public Label label()

Record Component getter of label.

labelPcback to summary
public int labelPc()

Record Component getter of labelPc.

sizeback to summary
public int size()

Record Component getter of size.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

Returns:String

a string representation of the object.

jdk.internal.classfile.impl back to summary

private final Class DirectCodeBuilder.LabelOverflowException

extends IllegalArgumentException
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
public

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.lang.IllegalArgumentException.serialVersionUID.

Constructor Detail

LabelOverflowExceptionback to summary
public LabelOverflowException()