Interface ConstantInstruction
- All Superinterfaces:
ClassFileElement, CodeElement, Instruction
- All Known Subinterfaces:
ConstantInstruction.ArgumentConstantInstruction, ConstantInstruction.IntrinsicConstantInstruction, ConstantInstruction.LoadConstantInstruction
public sealed interface ConstantInstruction extends Instruction permits ConstantInstruction.IntrinsicConstantInstruction, ConstantInstruction.ArgumentConstantInstruction, ConstantInstruction.LoadConstantInstruction
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)
Nested Class Summary
| Modifier and Type | Interface | Description |
|---|---|---|
static interface |
ConstantInstruction.ArgumentConstantInstruction |
Models an "argument constant" instruction, which encodes the constant value in the instruction directly. |
static interface |
ConstantInstruction.IntrinsicConstantInstruction |
Models an "intrinsic constant" instruction, which encodes the constant value in its opcode. |
static interface |
ConstantInstruction.LoadConstantInstruction |
Models a "load constant" instruction, which encodes the constant value in the constant pool. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
ConstantDesc |
constantValue() |
Returns the constant value. |
static ConstantInstruction.ArgumentConstantInstruction |
ofArgument |
Returns an argument constant instruction. |
static ConstantInstruction.IntrinsicConstantInstruction |
ofIntrinsic |
Returns an intrinsic constant instruction. |
static ConstantInstruction.LoadConstantInstruction |
ofLoad |
Returns a load constant instruction. |
TypeKind |
typeKind() |
Returns the computational type of the constant. |
Methods declared in interface Instruction
opcode, sizeInBytes | Modifier and Type | Method | Description |
|---|---|---|
Opcode |
opcode() |
Returns the operation of this instruction. |
int |
sizeInBytes() |
Returns the size in bytes of this instruction. |
Method Details
constantValue
ConstantDesc constantValue()
Returns the constant value.
- Returns:
- the constant value
typeKind
TypeKind typeKind()
Returns the computational type of the constant. This is derived from the
constantValue.- Returns:
- the computational type of the constant
ofIntrinsic
static ConstantInstruction.IntrinsicConstantInstruction ofIntrinsic(Opcode op)
Returns an intrinsic constant instruction.
- Parameters:
-
op- the opcode for the specific type of intrinsic constant instruction, which must be of kindOpcode.Kind.CONSTANT - Returns:
- an intrinsic constant instruction
- Throws:
-
IllegalArgumentException- if the opcode does not represent a constant with implicit value
ofArgument
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- the opcode for the specific type of argument constant instruction, which must beOpcode.BIPUSHorOpcode.SIPUSH -
value- the constant value - Returns:
- an argument constant instruction
- Throws:
-
IllegalArgumentException- if the opcode is notOpcode.BIPUSHorOpcode.SIPUSH, or if the constant value is out of range for the opcode
ofLoad
static ConstantInstruction.LoadConstantInstruction ofLoad(Opcode op, LoadableConstantEntry constant)
Returns a load constant instruction.
- Parameters:
-
op- the opcode for the specific type of load constant instruction, which must be of kindOpcode.Kind.CONSTANT -
constant- the constant value - Returns:
- a load constant instruction
- Throws:
-
IllegalArgumentException- if the opcode is notOpcode.LDC,Opcode.LDC_W, orOpcode.LDC2_W
© 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.