APIdia Launch Partner
Top Description Inners Methods
java.lang.classfile.instruction

public sealed Interface ConstantInstruction

extends Instruction
permits IntrinsicConstantInstruction, ArgumentConstantInstruction, LoadConstantInstruction
Known Direct Subinterfaces
java.lang.classfile.instruction.ConstantInstruction.IntrinsicConstantInstruction, java.lang.classfile.instruction.ConstantInstruction.ArgumentConstantInstruction, java.lang.classfile.instruction.ConstantInstruction.LoadConstantInstruction
Imports
java.lang.classfile.CodeBuilder, .CodeElement, .CodeModel, .Instruction, .Opcode, .TypeKind, java.lang.classfile.constantpool.LoadableConstantEntry, java.lang.constant.ConstantDesc, jdk.internal.classfile.impl.AbstractInstruction, .BytecodeHelpers, .Util

Models a constant-load instruction in the code array of a Code attribute, including "intrinsic", "argument", and "load" constant instructions. Corresponding opcodes have a kind of Opcode.Kind#CONSTANT. Delivered as a CodeElement when traversing the elements of a CodeModel.

The loaded constant value is symbolically represented as a ConstantDesc:

ConstantInstruction(ConstantDesc constantValue)
ConstantInstruction(ConstantDesc constantValue)
Since
24
See Also
Opcode.Kind#CONSTANT, CodeBuilder::loadConstant

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ConstantInstruction.ArgumentConstantInstruction

Models an "argument constant" instruction, which encodes the constant value in the instruction directly.

public static interface
ConstantInstruction.IntrinsicConstantInstruction

Models an "intrinsic constant" instruction, which encodes the constant value in its opcode.

public static interface
ConstantInstruction.LoadConstantInstruction

Models a "load constant" instruction, which encodes the constant value in the constant pool.

Method Summary

Modifier and TypeMethod and Description
public ConstantDesc

Returns:

the constant value
constantValue
()

Returns the constant value.

public static ConstantInstruction.ArgumentConstantInstruction

Returns:

an argument constant instruction
ofArgument
(Opcode
the opcode for the specific type of argument constant instruction, which must be Opcode#BIPUSH or Opcode#SIPUSH
op
,
int
the constant value
value
)

Returns an argument constant instruction.

public static ConstantInstruction.IntrinsicConstantInstruction

Returns:

an intrinsic constant instruction
ofIntrinsic
(Opcode
the opcode for the specific type of intrinsic constant instruction, which must be of kind Opcode.Kind#CONSTANT
op
)

Returns an intrinsic constant instruction.

public static ConstantInstruction.LoadConstantInstruction

Returns:

a load constant instruction
ofLoad
(Opcode
the opcode for the specific type of load constant instruction, which must be of kind Opcode.Kind#CONSTANT
op
,
LoadableConstantEntry
the constant value
constant
)

Returns a load constant instruction.

public TypeKind

Returns:

the computational type of the constant
typeKind
()

Returns the computational type of the constant.

Inherited from java.lang.classfile.Instruction:
opcodesizeInBytes

Method Detail

constantValueback to summary
public ConstantDesc constantValue()

Returns the constant value.

Returns:ConstantDesc

the constant value

ofArgumentback to summary
public static ConstantInstruction.ArgumentConstantInstruction ofArgument(Opcode op, int value)

Returns an argument constant instruction.

value must be in the range of byte, [-128, 127], for Opcode#BIPUSH, and in the range of short, [-32768, 32767], for Opcode#SIPUSH.

Parameters
op:Opcode

the opcode for the specific type of argument constant instruction, which must be Opcode#BIPUSH or Opcode#SIPUSH

value:int

the constant value

Returns:ConstantInstruction.ArgumentConstantInstruction

an argument constant instruction

Exceptions
IllegalArgumentException:
if the opcode is not Opcode#BIPUSH or Opcode#SIPUSH, or if the constant value is out of range for the opcode
ofIntrinsicback to summary
public static ConstantInstruction.IntrinsicConstantInstruction ofIntrinsic(Opcode op)

Returns an intrinsic constant instruction.

Parameters
op:Opcode

the opcode for the specific type of intrinsic constant instruction, which must be of kind Opcode.Kind#CONSTANT

Returns:ConstantInstruction.IntrinsicConstantInstruction

an intrinsic constant instruction

Exceptions
IllegalArgumentException:
if the opcode does not represent a constant with implicit value
ofLoadback to summary
public static ConstantInstruction.LoadConstantInstruction ofLoad(Opcode op, LoadableConstantEntry constant)

Returns a load constant instruction.

Parameters
op:Opcode

the opcode for the specific type of load constant instruction, which must be of kind Opcode.Kind#CONSTANT

constant:LoadableConstantEntry

the constant value

Returns:ConstantInstruction.LoadConstantInstruction

a load constant instruction

Exceptions
IllegalArgumentException:
if the opcode is not Opcode#LDC, Opcode#LDC_W, or Opcode#LDC2_W
typeKindback to summary
public TypeKind typeKind()

Returns the computational type of the constant. This is derived from the constantValue.

Returns:TypeKind

the computational type of the constant

java.lang.classfile.instruction back to summary

public sealed Interface ConstantInstruction.ArgumentConstantInstruction

extends ConstantInstruction
permits BoundArgumentConstantInstruction, UnboundArgumentConstantInstruction
Known Direct Implementers
jdk.internal.classfile.impl.AbstractInstruction.BoundArgumentConstantInstruction, jdk.internal.classfile.impl.AbstractInstruction.UnboundArgumentConstantInstruction

Models an "argument constant" instruction, which encodes the constant value in the instruction directly. Includes bipush and sipush instructions.

An argument constant instruction is composite:

ArgumentConstantInstruction( Opcode opcode, int constantValue )
ArgumentConstantInstruction(
    Opcode opcode,
    int constantValue
)
where:
Since
24
See Also
Opcode.Kind#CONSTANT, ConstantInstruction::ofArgument, CodeBuilder::loadConstant(int), CodeBuilder::bipush, CodeBuilder::sipush

Method Summary

Modifier and TypeMethod and Description
public Integer
public default TypeKind
Inherited from java.lang.classfile.instruction.ConstantInstruction:
ofArgumentofIntrinsicofLoad

Method Detail

constantValueback to summary
public Integer constantValue()

Redeclares java.lang.classfile.instruction.ConstantInstruction.constantValue.

Doc from java.lang.classfile.instruction.ConstantInstruction.constantValue.

Returns the constant value.

Annotations
@Override
typeKindback to summary
public default TypeKind typeKind()

Implements java.lang.classfile.instruction.ConstantInstruction.typeKind.

Doc from java.lang.classfile.instruction.ConstantInstruction.typeKind.

Returns the computational type of the constant. This is derived from the constantValue.

Annotations
@Override
java.lang.classfile.instruction back to summary

public sealed Interface ConstantInstruction.IntrinsicConstantInstruction

extends ConstantInstruction
permits UnboundIntrinsicConstantInstruction
Known Direct Implementers
jdk.internal.classfile.impl.AbstractInstruction.UnboundIntrinsicConstantInstruction

Models an "intrinsic constant" instruction, which encodes the constant value in its opcode. Examples include aconst_null and iconst_0.

An intrinsic constant instruction is composite:

IntrinsicConstantInstruction(Opcode opcode)
IntrinsicConstantInstruction(Opcode opcode)
where:
opcode
Must be of the constant kind and have a fixed size of 1.
Since
24
See Also
Opcode.Kind#CONSTANT, ConstantInstruction::ofIntrinsic

Method Summary

Modifier and TypeMethod and Description
public default TypeKind
Inherited from java.lang.classfile.instruction.ConstantInstruction:
constantValueofArgumentofIntrinsicofLoad

Method Detail

typeKindback to summary
public default TypeKind typeKind()

Implements java.lang.classfile.instruction.ConstantInstruction.typeKind.

Doc from java.lang.classfile.instruction.ConstantInstruction.typeKind.

Returns the computational type of the constant. This is derived from the constantValue.

Annotations
@Override
java.lang.classfile.instruction back to summary

public sealed Interface ConstantInstruction.LoadConstantInstruction

extends ConstantInstruction
permits BoundLoadConstantInstruction, UnboundLoadConstantInstruction
Known Direct Implementers
jdk.internal.classfile.impl.AbstractInstruction.BoundLoadConstantInstruction, jdk.internal.classfile.impl.AbstractInstruction.UnboundLoadConstantInstruction

Models a "load constant" instruction, which encodes the constant value in the constant pool. Includes ldc and ldc_w, and ldc2_w instructions.

A load constant instruction is composite:

LoadConstantInstruction(LoadableConstantEntry constantEntry)
LoadConstantInstruction(LoadableConstantEntry constantEntry)

A "load constant" instruction can load any constant value supported by other constant-load instructions. However, other instructions are usually more optimized, avoiding extra constant pool entries and being smaller.

Since
24
See Also
Opcode.Kind#CONSTANT, ConstantInstruction::ofLoad, CodeBuilder::ldc

Method Summary

Modifier and TypeMethod and Description
public LoadableConstantEntry

Returns:

the constant value
constantEntry
()

Returns the constant value.

public default TypeKind
Inherited from java.lang.classfile.instruction.ConstantInstruction:
constantValueofArgumentofIntrinsicofLoad

Method Detail

constantEntryback to summary
public LoadableConstantEntry constantEntry()

Returns the constant value.

Returns:LoadableConstantEntry

the constant value

typeKindback to summary
public default TypeKind typeKind()

Implements java.lang.classfile.instruction.ConstantInstruction.typeKind.

Doc from java.lang.classfile.instruction.ConstantInstruction.typeKind.

Returns the computational type of the constant. This is derived from the constantValue.

Annotations
@Override