-
Notifications
You must be signed in to change notification settings - Fork 2
JAL Instructions Reference
This document is the reference of the instructions of JAL (Java Assembler Language).
An instruction is a directive, through the JAL language interface, that tells the JVM what operation to perform in the current frame. A frame consists of the local variables and stack state for each method, and each instruction manipulates these.
The effects on the stack and changes to local variables for each instruction are exactly the same as those defined in the Java Virtual Machine Specification SE 24. JAL is merely an interface for humans to write instructions.
InstructionName [Operand1 [, Operand2, ...]]
-
InstructionNameis the name of the instruction defined by the JVM (e.g.,iload,istore). -
Operandis an argument required by the instruction, such as:- Numeric or string literals (e.g.,
42,"Hello") - Class or method names (e.g.,
java/lang/String,java/lang/System->out:Ljava/io/PrintStream) - Labels (e.g.,
tryStart,catchStart)
- Numeric or string literals (e.g.,
Especially, operands are not given directly as accepted by the JVM, but are interpreted by JAL in between.
| Type | Description | Example |
|---|---|---|
index |
Constant pool index (16-bit int) |
10, 0x0A
|
byte |
8-bit integer (-127 ~ 127) |
-5, 127, -0x01
|
short |
16-bit integer (-32767 ~ 32767) |
300, -1024, 0x01
|
scalar |
Scalar value (int, float, string) |
42, 3.14, "Hello, World!"
|
branch |
Branch label or offset | Label1 |
local |
Local variable index or name |
0, 5, myLocalVariable1
|
type |
Class or type name (string) |
I, D, Ljava/lang/String;
|
| Others | Other specific operand formats | See the relevant instruction section |
A type operand is a type descriptor, a string used by the JVM to identify types. It is represented as follows:
| Type | Java Type | Description |
|---|---|---|
I |
int |
Integer type |
J |
long |
Long integer type |
F |
float |
Floating-point type |
D |
double |
Double precision floating-point type |
Z |
boolean |
Boolean type |
B |
byte |
8-bit integer type |
C |
char |
16-bit character type |
S |
short |
16-bit integer type |
V |
void |
No return value |
L..; |
Ljava/lang/Object; |
Object type (reference type) |
[ |
Array type | Represents an array. E.g., [I for int[] |
Examples:
-
Irepresents theinttype. -
Ljava/lang/String;represents thejava.lang.Stringclass object type. -
[Irepresents an array ofint. -
[Ljava/lang/String;represents an array ofjava.lang.String. -
[[Irepresents a two-dimensional array ofint.
iconst_0 // Push integer 0 onto the stack
istore 1 // Store the value from the stack into local variable index 1
- Constant Push
-
Local Variable Operations & Load
iload locallload localfload localdload localaload localiload_0iload_1iload_2iload_3lload_0lload_1lload_2lload_3fload_0fload_1fload_2fload_3dload_0dload_1dload_2dload_3aload_0aload_1aload_2aload_3ialoadlaloadfaloaddaloadaaloadbaloadcaloadsaloadistorelstorefstoredstoreastoreistore_0istore_1istore_2istore_3lstore_0lstore_1lstore_2lstore_3fstore_0fstore_1fstore_2fstore_3dstore_0dstore_1dstore_2dstore_3astore_0astore_1astore_2astore_3iastorelastorefastoredastoreaastorebastorecastoresastorepoppop2dupdup_x1dup_x2dup2dup2_x1dup2_x2swap
- Arithematic Operations
- Type Conversion
- Comparison and Branch
- Control Flow
- Reference Operations
- Extended Instructions
Description of the instruction. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
..., stack item before (2), stack item before (1), stack item before (0)
-> ..., stack item after (2), stack item after (1), stack item after (0)
[!IMPORTANT] The notation
{x, x2, x3}means that any one of them is allowed. For example,lconst_{0, 1}means eitherlconst_0orlconst_1.
Does nothing. Executing this does not affect the stack or local variables.
...
-> ...
Pushes null onto the stack.
...,
-> ..., null
Pushes the integer -1, 0, 1, 2, 3, 4, or 5 onto the stack.
...,
-> ..., {-1, 0, 1, 2, 3, 4, 5}
-
iconst_m1pushes-1. -
iconst_0pushes0. -
iconst_1pushes1. -
iconst_2pushes2. -
iconst_3pushes3. -
iconst_4pushes4. -
iconst_5pushes5.
Note
The JVM does not strictly distinguish types here. The value pushed is treated as int, but can also be used as short, byte, char, or boolean as long as the value is within their range.
(boolean only allows 0 and 1. Here, 0 is false, 1 is true.)
Pushes the integer 0 or 1 as a long onto the stack.
...,
-> ..., {0, 1}L
-
lconst_0pushes0L. -
lconst_1pushes1L.
Note
Long and Double constants are 64-bit values, so pushing them uses two stack items.
The same applies to local variables: the first slot holds the value, the second holds TOP.
Pushes the floating-point numbers 0.0, 1.0, or 2.0 as float onto the stack.
...,
-> ..., {0.0, 1.0, 2.0}F
-
fconst_0pushes0.0F. -
fconst_1pushes1.0F. -
fconst_2pushes2.0F.
Pushes the floating-point numbers 0.0 or 1.0 as double onto the stack.
...,
-> ..., {0.0, 1.0}D
-
dconst_0pushes0.0D. -
dconst_1pushes1.0D.
Note
Double and Long constants are 64-bit values, so pushing them uses two stack items.
The same applies to local variables: the first slot holds the value, the second holds TOP.
Pushes an 8-bit integer (byte) onto the stack.
That is, pushes a value from -128 to 127 onto the stack.
...,
-> ..., byte
Tip
If the value to be pushed is within -1 to 5, it is recommended to use iconst_{m1, 0, 1, 2, 3, 4, 5}.
These instructions are represented by shorter bytecode and are faster and lighter for the JVM to interpret.
Pushes a 16-bit integer (short) onto the stack.
That is, pushes a value from -32768 to 32767 onto the stack.
...,
-> ..., short
Tip
If the value to be pushed fits in an 8-bit integer (byte), use bipush.
If it fits in -1 to 5, use iconst_{m1, 0, 1, 2, 3, 4, 5}.
These instructions are represented by shorter bytecode and are faster and lighter for the JVM to interpret.
Pushes a scalar value (integer, floating-point, string, etc.) from the constant pool onto the stack.
For example, ldc "Hello, World!" pushes a string onto the stack.
For integers exceeding the range of sipush (-32768 to 32767), use this instruction.
...,
-> ..., scalar
Important
ldc originally fetches values from the constant pool, but in JAL, you do not need to intentionally use the constant pool.
You can simply specify the value to push as an operand.
Same as ldc, but used when the index exceeds 16 bits (255).
...,
-> ..., scalar
Important
You rarely use this instruction directly. JAL automatically manages constant pool indices,
so just using ldc is sufficient. Conversion to ldc_w or ldc2_w
is handled automatically by the JAL compiler.
Same as ldc_w, but pushes a long or double value onto the stack.
...,
-> ..., scalar
Important
You rarely use this instruction directly. JAL automatically manages constant pool indices,
so just using ldc is sufficient. Conversion to ldc2_w is automatic.
Loads an integer value from the local variable table onto the stack.
...,
-> ..., integer
Note
local specifies the index or name of the local variable table.
The index starts from 0 and corresponds to the order of local variables.
If the method has arguments, they are assigned to local variable indices 0, 1, ... in order.
For example, iload 0 loads the value into the first argument of the method.
Reference: Naming local variables
istore_0 [->name0]
This assigns a name to the local variable table index 0 and stores the integer value from the stack top.
Loads a long value from the local variable table onto the stack.
...,
-> ..., long
Loads a float value from the local variable table onto the stack.
...,
-> ..., float
Loads a double value from the local variable table onto the stack.
...,
-> ..., double
Loads an object reference from the local variable table onto the stack.
This can be any object type, including null and arrays like [Ljava/lang/Object;.
...,
-> ..., object_reference
Loads an integer value from the local variable table onto the stack.
This is a shortcut for iload, loading from indices 0, 1, 2, or 3.
For example, iload_0 is equivalent to iload 0.
...,
-> ..., integer
Loads a long value from the local variable table onto the stack.
This is a shortcut for lload, loading from indices 0, 1, 2, or 3.
For example, lload_0 is equivalent to lload 0.
...,
-> ..., long
Loads a float value from the local variable table onto the stack.
This is a shortcut for fload, loading from indices 0, 1, 2, or 3.
For example, fload_0 is equivalent to fload 0.
...,
-> ..., float
Loads a double value from the local variable table onto the stack.
This is a shortcut for dload, loading from indices 0, 1, 2, or 3.
For example, dload_0 is equivalent to dload 0.
...,
-> ..., double
Loads an object reference from the local variable table onto the stack.
This is a shortcut for aload, loading from indices 0, 1, 2, or 3.
For example, aload_0 is equivalent to aload 0.
...,
-> ..., object_reference
Pops an array reference and index from the stack, loads an integer value from the array, and pushes it onto the stack.
You must have pushed an integer array [I onto the stack beforehand.
..., array_reference, index
-> ..., integer
Important
The array and index to load from are taken from the stack, not as operands.
Pops an array reference and index from the stack, loads a long value from the array, and pushes it onto the stack.
You must have pushed a [J array onto the stack beforehand.
..., array_reference, index
-> ..., long
Important
The array and index to load from are taken from the stack, not as operands.
Pops an array reference and index from the stack, loads a float value from the array, and pushes it onto the stack.
You must have pushed a [F array onto the stack beforehand.
..., array_reference, index
-> ..., float
Important
The array and index to load from are taken from the stack, not as operands.
Pops an array reference and index from the stack, loads a double value from the array, and pushes it onto the stack.
You must have pushed a [D array onto the stack beforehand.
..., array_reference, index
-> ..., double
Important
The array and index to load from are taken from the stack, not as operands.
Pops an array reference and index from the stack, loads an object reference from the array, and pushes it onto the stack.
You must have pushed an object array like [Ljava/lang/Object; or [Ljava/lang/String; onto the stack beforehand.
..., array_reference, index
-> ..., object_reference
Important
The array and index to load from are taken from the stack, not as operands.
Pops an array reference and index from the stack, loads a byte value from the array, and pushes it onto the stack.
You must have pushed a [B array onto the stack beforehand.
..., array_reference, index
-> ..., byte
Warning
The array and index to load from are taken from the stack, not as operands.
Pops an array reference and index from the stack, loads a char value from the array, and pushes it onto the stack.
You must have pushed a [C array onto the stack beforehand.
..., array_reference, index
-> ..., char
Important
The array and index to load from are taken from the stack, not as operands.
Pops an array reference and index from the stack, loads a short value from the array, and pushes it onto the stack.
You must have pushed a [S array onto the stack beforehand.
..., array_reference, index
-> ..., short
Important
The array and index to load from are taken from the stack, not as operands.
Stores an integer value from the stack into the local variable table.
..., integer
-> ...
Note
local specifies the index or name of the local variable table.
The index starts from 0 and corresponds to the order of local variables.
If the method has arguments, they are assigned to local variable indices 0, 1, ... in order.
For example, istore 0 stores the value into the first argument of the method.
Stores a long value from the stack into the local variable table.
..., long
-> ...
Stores a float value from the stack into the local variable table.
..., float
-> ...
Stores a double value from the stack into the local variable table.
..., double
-> ...
Stores an object reference from the stack into the local variable table.
..., object_reference
-> ...
Stores an integer value from the stack into the local variable table.
This is a shortcut for istore, storing into local variable indices 0, 1, 2, or 3.
For example, istore_0 is equivalent to istore 0.
..., integer
-> ...
Stores a long value from the stack into the local variable table.
This is a shortcut for lstore, storing into local variable indices 0, 1, 2, or 3.
For example, lstore_0 is equivalent to lstore 0.
..., long
-> ...
Stores a float value from the stack into the local variable table.
This is a shortcut for fstore, storing into local variable indices 0, 1, 2, or 3.
For example, fstore_0 is equivalent to fstore 0.
..., float
-> ...
Stores a double value from the stack into the local variable table.
This is a shortcut for dstore, storing into local variable indices 0, 1, 2, or 3.
For example, dstore_0 is equivalent to dstore 0.
..., double
-> ...
Stores an object reference from the stack into the local variable table.
This is a shortcut for astore, storing into local variable indices 0, 1, 2, or 3.
For example, astore_0 is equivalent to astore 0.
..., object_reference
-> ...
Pops an array reference, index, and value from the stack, and stores the integer value into the array.
..., array_reference, index, integer
-> ...
Important
The array and index to store into are taken from the stack, not as operands.
Pops an array reference, index, and value from the stack, and stores the long value into the array.
..., array_reference, index, long
-> ...
Important
The array and index to store into are taken from the stack, not as operands.
Pops an array reference, index, and value from the stack, and stores the float value into the array.
..., array_reference, index, float
-> ...
Important
The array and index to store into are taken from the stack, not as operands.
Pops an array reference, index, and value from the stack, and stores the double value into the array.
..., array_reference, index, double
-> ...
Important
The array and index to store into are taken from the stack, not as operands.
Pops an array reference, index, and value from the stack, and stores the object reference into the array.
..., array_reference, index, object_reference
-> ...
Important
The array and index to store into are taken from the stack, not as operands.
Pops an array reference, index, and value from the stack, and stores the byte value into the array.
..., array_reference, index, byte
-> ...
Important
The array and index to store into are taken from the stack, not as operands.
Pops an array reference, index, and value from the stack, and stores the char value into the array.
..., array_reference, index, char
-> ...
Important
The array and index to store into are taken from the stack, not as operands.
Pops an array reference, index, and value from the stack, and stores the short value into the array.
..., array_reference, index, short
-> ...
Important
The array and index to store into are taken from the stack, not as operands.
Removes the top item from the stack.
..., item
-> ...
Removes the top two items from the stack.
..., item1, item2
-> ...
Duplicates the top item of the stack and pushes it onto the stack.
..., item
-> ..., item, item
Duplicates the top item of the stack and inserts it two positions down.
..., item1, item2
-> ..., item2, item1, item2
Duplicates the top item of the stack and inserts it three positions down.
..., item1, item2, item3
-> ..., item2, item3, item1, item2
Duplicates the top two items of the stack and pushes them onto the stack.
..., item1, item2
-> ..., item1, item2, item1, item2
Duplicates the top two items of the stack and inserts them three positions down.
..., item1, item2, item3
-> ..., item2, item3, item1, item2, item3
Duplicates the top two items of the stack and inserts them four positions down.
..., item1, item2, item3, item4
-> ..., item3, item4, item1, item2, item3, item4
Swaps the top two items of the stack.
..., item1, item2
-> ..., item2, item1
Adds the top two items of the stack and pushes the result.
-
iadd(0x60): integer addition -
ladd(0x61):longaddition -
fadd(0x62):floataddition -
dadd(0x63):doubleaddition
That is, value1 + value2 is pushed as result.
..., item1, item2
-> ..., result
Subtracts the top two items of the stack and pushes the result.
-
isub(0x64): integer subtraction -
lsub(0x65):longsubtraction -
fsub(0x66):floatsubtraction -
dsub(0x67):doublesubtraction
That is, value1 - value2 is pushed as result.
..., item1, item2
-> ..., result
Multiplies the top two items of the stack and pushes the result.
-
imul(0x68): integer multiplication -
lmul(0x69):longmultiplication -
fmul(0x6A):floatmultiplication -
dmul(0x6B):doublemultiplication
That is, value1 * value2 is pushed as result.
..., item1, item2
-> ..., result
Divides the top two items of the stack and pushes the result.
-
idiv(0x6C): integer division -
ldiv(0x6D):longdivision -
fdiv(0x6E):floatdivision -
ddiv(0x6F):doubledivision
That is, value1 / value2 is pushed as result.
..., item1, item2
-> ..., result
Calculates the remainder of the top two items of the stack and pushes the result.
-
irem(0x70): integer remainder -
lrem(0x71):longremainder -
frem(0x72):floatremainder -
drem(0x73):doubleremainder
That is, value1 % value2 is pushed as result.
..., item1, item2
-> ..., result
Negates the top item of the stack and pushes the result.
-
ineg(0x74): integer negation -
lneg(0x75):longnegation -
fneg(0x76):floatnegation -
dneg(0x77):doublenegation
That is, -value is pushed as result.
..., item
-> ..., result
Left-shifts the top two items of the stack and pushes the result.
-
ishl(0x78): integer left shift -
lshl(0x79):longleft shift
That is, value1 << value2 is pushed as result.
..., item1, item2
-> ..., result
Right-shifts the top two items of the stack and pushes the result.
-
ishr(0x7A): integer right shift -
lshr(0x7B):longright shift
That is, value1 >> value2 is pushed as result.
..., item1, item2
-> ..., result
Unsigned right-shifts the top two items of the stack and pushes the result.
-
iushr(0x7C): integer unsigned right shift -
lushr(0x7D):longunsigned right shift
That is, value1 >>> value2 is pushed as result.
..., item1, item2
-> ..., result
Bitwise ANDs the top two items of the stack and pushes the result.
-
iand(0x7E): integer bitwise AND -
land(0x7F):longbitwise AND
That is, value1 & value2 is pushed as result.
..., item1, item2
-> ..., result
Bitwise ORs the top two items of the stack and pushes the result.
-
ior(0x80): integer bitwise OR -
lor(0x81):longbitwise OR
That is, value1 | value2 is pushed as result.
..., item1, item2
-> ..., result
Bitwise XORs the top two items of the stack and pushes the result.
-
ixor(0x82): integer bitwise XOR -
lxor(0x83):longbitwise XOR
That is, value1 ^ value2 is pushed as result.
..., item1, item2
-> ..., result
Increments the integer value in the local variable table by the constant const without using the stack.
..., local_variable
-> ..., local_variable + const
Converts the top integer value on the stack to long, float, or double and pushes the result.
-
i2l(0x85): converts integer tolong -
i2f(0x86): converts integer tofloat -
i2d(0x87): converts integer todouble
..., integer
-> ..., converted_value
Converts the top long value on the stack to int, float, or double and pushes the result.
-
l2i(0x88): convertslongto integer -
l2f(0x89): convertslongtofloat -
l2d(0x8A): convertslongtodouble
..., long
-> ..., converted_value
Converts the top float value on the stack to integer, long, or double and pushes the result.
-
f2i(0x8B): convertsfloatto integer -
f2l(0x8C): convertsfloattolong -
f2d(0x8D): convertsfloattodouble
..., float
-> ..., converted_value
Converts the top double value on the stack to integer, long, or float and pushes the result.
-
d2i(0x8E): convertsdoubleto integer -
d2l(0x8F): convertsdoubletolong -
d2f(0x90): convertsdoubletofloat
..., double
-> ..., converted_value
Converts the top integer value on the stack to byte, char, or short and pushes the result.
-
i2b(0x91): converts integer tobyte -
i2c(0x92): converts integer tochar -
i2s(0x93): converts integer toshort
..., integer
-> ..., converted_value
Compares the top two long values on the stack and pushes the result.
The result is as follows:
-
0if the two values are equal -
1if the first value is greater than the second -
-1if the first value is less than the second
..., long1, long2
-> ..., result
Note
This instruction is often used for comparing long values before a jump, since long is 64-bit and cannot be directly compared with if_icmpeq etc.
Compares the top two float values on the stack and pushes the result.
The result is as follows:
-
0if the two values are equal -
1if the first value is greater than the second -
-1if the first value is less than the second
Note
fcmpl (0x95) returns -1 if either value is NaN.
fcmpg (0x96) returns 1 if either value is NaN.
..., float1, float2
-> ..., result
Compares the top two double values on the stack and pushes the result.
The result is as follows:
-
0if the two values are equal -
1if the first value is greater than the second -
-1if the first value is less than the second
Note
dcmpl (0x97) returns -1 if either value is NaN.
dcmpg (0x98) returns 1 if either value is NaN.
..., double1, double2
-> ..., result
Compares the top integer value on the stack and jumps to the specified label if the condition is met.
-
ifeq(0x99): jump if value is0 -
ifne(0x9A): jump if value is not0 -
iflt(0x9B): jump if value is less than0 -
ifge(0x9C): jump if value is greater than or equal to0 -
ifgt(0x9D): jump if value is greater than0 -
ifle(0x9E): jump if value is less than or equal to0
..., integer
-> ... (jump)
{if_icmpeq, if_icmpne, if_icmplt, if_icmpge, if_icmpgt, if_icmple} label (0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4)
Compares the top two integer values on the stack and jumps to the specified label if the condition is met.
-
if_icmpeq(0x9F): jump if equal -
if_icmpne(0xA0): jump if not equal -
if_icmplt(0xA1): jump if less than -
if_icmpge(0xA2): jump if greater than or equal -
if_icmpgt(0xA3): jump if greater than -
if_icmple(0xA4): jump if less than or equal
..., integer1, integer2
-> ... (jump)
Compares the top two object references on the stack and jumps to the specified label if the condition is met.
-
if_acmpeq(0xA5): jump if references are equal -
if_acmpne(0xA6): jump if references are not equal
..., object_reference1, object_reference2
-> ... (jump)
Unconditionally jumps to the specified label.
..., stack item (n)
-> ..., stack item (n)
Warning
The target label must be within the same method.
Jumps to the specified label or offset and saves the return address on the stack.
..., stack item (n)
-> ..., (goto Label or offset), stack item (n)
Warning
The target label must be within the same method.
Returns from a subroutine by jumping to the address stored in the specified local variable (used after jsr).
..., return_address
-> ... (goto return_address)
Note
This instruction is used in conjunction with the jsr instruction to implement subroutines.
It is rarely used in modern Java programming as subroutines are no longer a common practice.
Uses the integer value at the top of the stack to jump to a label within a continuous range.
Format:
tableswitch low_index {
label1,
label2,
...
} 'default' default_label
The tableswitch instruction defines a table of labels corresponding to a range of integer values starting from low_index.
If the integer value at the top of the stack is greater than or equal to low_index and matches an index in the table, it jumps to the corresponding label.
For example, if low_index is 3, label1 corresponds to 3, label2 corresponds to 4, and so on.
If no match is found, it jumps to the default label default_label.
Example:
tableswitch 0 {
label0,
label1,
label2
} default label3
In this case:
- If the integer value at the top of the stack is
0, it jumps tolabel0. - If the value is
1, it jumps tolabel1. - If the value is
2, it jumps tolabel2. - If none of these match, it jumps to
label3.
..., integer
-> ... (jump)
Uses the integer value at the top of the stack to jump to a label within a discrete set of values.
Format:
lookupswitch {
value1: label1,
value2: label2,
...
'default': default_label
}
The lookupswitch instruction defines pairs of integer values and labels.
If the integer value at the top of the stack matches any of these pairs, it jumps to the corresponding label.
If no match is found, it jumps to the default label default_label.
The default label is mandatory.
Example:
lookupswitch {
1: label0,
13: label1,
21: label2
default: label3
}
In this case:
- If the integer value at the top of the stack is
1, it jumps tolabel0. - If the value is
13, it jumps tolabel1. - If the value is
21, it jumps tolabel2. - If none of these match, it jumps to
label3.
..., integer
-> ... (jump)
Returns the integer value at the top of the stack as the return value and transfers control back to the caller.
..., integer
-> ... (return integer)
Returns the long value at the top of the stack as the return value and transfers control back to the caller.
..., long
-> ... (return long)
Returns the float value at the top of the stack as the return value and transfers control back to the caller.
..., float
-> ... (return float)
Returns the double value at the top of the stack as the return value and transfers control back to the caller.
..., double
-> ... (return double)
Returns the object reference at the top of the stack as the return value and transfers control back to the caller.
..., object_reference
-> ... (return object_reference)
Returns from the current method without a return value and transfers control back to the caller.
...
-> ... (return)
Pushes the value of a static field onto the stack.
fieldRef is a reference to the field in the following format:
fieldRef = className '->' fieldName ':' fieldType
Here, className is the fully qualified name of the class the field belongs to, fieldName is the name of the field, and fieldType is the type of the field.
className is a string with package and class names separated by slashes (/), and fieldType is a type descriptor (e.g., I for integer, J for long, etc.).
...
-> ..., fieldValue
Stores the value at the top of the stack into a static field.
For fieldRef, see getstatic.
..., fieldValue
-> ...
Fetches the value of an instance field from the object reference at the top of the stack and pushes it onto the stack.
For fieldRef, see getstatic.
..., object_reference
-> ..., fieldValue
Stores the value at the top of the stack into an instance field of the object reference below it.
For fieldRef, see getstatic.
..., object_reference, fieldValue
-> ...
Invokes an instance method on the object reference at the top of the stack.
methodRef is a reference to the method in the following format:
methodRef = (className '->')? methodName '(' parameterTypes ')' returnType
Here, className is the fully qualified name of the class the method belongs to, methodName is the name of the method, parameterTypes is a string representing the types of the method's parameters (type descriptors), and returnType is the type of the method's return value.
For example, the method void main(String[] args) is represented as:
mainMethodRef = "java/lang/System->main([Ljava/lang/String;)V"
Note
className is optional. If omitted, the current class (the class containing this instruction) is used.
..., object_reference, [arg1, [arg2, ...]]
-> ..., returnValue
Invokes a special instance method on the object reference at the top of the stack.
Special methods include constructors and superclass methods, such as methods named <init>.
For methodRef, see invokevirtual.
..., object_reference, [arg1, [arg2, ...]]
-> ..., returnValue
Warning
This instruction does not invoke the <clinit> (class initializer) method of a class.
The <clinit> method is automatically invoked by the JVM when the class is initialized.
Invokes a static method and pushes the return value onto the stack.
For methodRef, see invokevirtual.
..., [arg1, [arg2, ...]]
-> ..., returnValue
Invokes an interface method on the object reference at the top of the stack and pushes the return value onto the stack.
The object reference must point to an object that implements the interface.
For methodRef, see invokevirtual.
..., object_reference, [arg1, [arg2, ...]]
-> ..., returnValue
The invokedynamic instruction performs a dynamic method invocation.
That is, the JVM resolves the method at runtime and dynamically invokes it.
The JVM uses a special method called a Bootstrap Method to resolve the dynamic method invocation.
This instruction specifies a reference to the Bootstrap Method and the arguments required for it.
methodName is the name of the method, and methodDescriptor is a string representing the method's parameters and return type (type descriptor).
This is not the name of the Bootstrap Method.
methodHandle is a reference to the Bootstrap Method in the following format:
methodHandle = 'MethodHandle|' invokeType '|' (className '->')? methodName '(' parameterTypes ')' returnType
invokeType = 'getfield' | 'getstatic' | 'putfield' | 'putstatic' | 'invokevirtual'
| 'invokespecial' | 'invokestatic' | 'invokeinterface'
Here, className is the fully qualified name of the class the method belongs to, methodName is the name of the method, parameterTypes is a string representing the types of the method's parameters (type descriptors), and returnType is the type of the method's return value.
Note
The class name className is optional. If omitted, the current class (the class containing this instruction) is used.
Additionally, bootstrapArg1, bootstrapArg2, ... are arguments passed to the Bootstrap Method.
Their types can be methodHandle, methodType, or scalar.
methodtype = 'MethodType|' methodDescriptor
scalar = integer | long | float | double | object_reference
The stack must contain the arguments for the method being invoked.
..., [arg1, [arg2, ...]]
-> ..., returnValue
Creates a new object and pushes a reference to the uninitialized object onto the stack.
classRef is a reference to the class, represented as a fully qualified name with slashes (/) separating package and class names.
For example, the reference to the java.lang.String class is java/lang/String.
..., classRef
-> ..., uninitialized_object_reference
Warning
The pushed reference is to an uninitialized object and cannot be used as is.
You must initialize the object before using it.
To initialize, use the invokespecial instruction to call the constructor <init>()V of the object's class.
Creates a new array and pushes a reference to the array onto the stack.
type specifies the type of the array elements using an integer value corresponding to a type descriptor.
The following values can be used:
-
B(0x04) ->byte[] -
C(0x05) ->char[] -
D(0x06) ->double[] -
F(0x07) ->float[] -
I(0x08) ->int[] -
J(0x09) ->long[] -
S(0x0A) ->short[] -
Z(0x0B) ->boolean[]
Warning
This instruction cannot create arrays of object types (L...;) or the void type (V).
To create an array of object types, use the anewarray instruction.
The stack must contain an integer value representing the number of elements in the array.
..., length
-> ..., array_reference
Creates a new array of object types and pushes a reference to the array onto the stack.
classRef is a reference to the type of the array elements, represented as a fully qualified name with slashes (/) separating package and class names.
For example, the reference to the java.lang.String class is java/lang/String.
The stack must contain an integer value representing the number of elements in the array.
..., length
-> ..., array_reference
Retrieves the length of the array referenced at the top of the stack and pushes it onto the stack.
..., array_reference
-> ..., length
Throws the object reference at the top of the stack as an exception.
The object reference must be an instance of a class that extends java/lang/Throwable.
..., exception_object_reference
-> (jump)
Checks whether the object reference at the top of the stack is an instance of the specified class.
If it is, the object reference is pushed back onto the stack.
If it is not, a ClassCastException is thrown.
classRef is a reference to the class, represented as a fully qualified name with slashes (/) separating package and class names.
..., object_reference
-> ..., object_reference (if cast is successful)
Checks whether the object reference at the top of the stack is an instance of the specified class.
If it is, 1 is pushed onto the stack; otherwise, 0 is pushed.
classRef is a reference to the class, represented as a fully qualified name with slashes (/) separating package and class names.
..., object_reference
-> ..., result (1 or 0)
Acquires a monitor for the object reference at the top of the stack.
This instruction is used to implement thread synchronization.
..., object_reference
-> ..., object_reference (monitor acquired)
Releases the monitor for the object reference at the top of the stack.
This instruction is used to release thread synchronization.
..., object_reference
-> ..., object_reference (monitor released)
The wide instruction is used to extend the operand of another instruction.
It is used with the following instructions:
-
iload,lload,fload,dload,aload -
istore,lstore,fstore,dstore,astore retiinc
The wide instruction extends the operand of these instructions from 16 bits to 32 bits.
For example, the iload instruction normally uses an 8-bit index, but with the wide instruction, it can use a 16-bit index.
Example:
wide iload 256
This instruction pushes the integer value from local variable index 256 onto the stack.
..., item
-> ..., item
Note
In JAL, you do not need to explicitly use the wide instruction.
The JAL compiler automatically inserts the wide instruction when necessary to extend the operand.
Creates a new multidimensional array and pushes a reference to the array onto the stack.
classRef is a reference to the type of the array elements, represented as a fully qualified name with slashes (/) separating package and class names.
dimensions is an integer value representing the number of dimensions of the array.
The stack must contain integer values representing the size of each dimension.
..., [length1, length2, ..., lengthN]
-> ..., array_reference
Checks whether the object reference at the top of the stack is null.
If it is, the instruction jumps to the specified label.
..., object_reference
-> ... (jump if object_reference is null)
Checks whether the object reference at the top of the stack is not null.
If it is not, the instruction jumps to the specified label.
..., object_reference
-> ... (jump if object_reference is not null)
Unconditionally jumps to the specified label.
The goto_w instruction is similar to the goto instruction but supports a 32-bit offset instead of a 16-bit offset, allowing for larger jumps.
..., item
-> ... (jump)
Note
In JAL, you do not need to explicitly use the goto_w instruction.
The JAL compiler automatically uses goto_w when the label offset exceeds 16 bits.
Jumps to the specified label and pushes the return address onto the stack.
The jsr_w instruction is similar to the jsr instruction but supports a 32-bit offset instead of a 16-bit offset, allowing for larger jumps.
..., item
-> ..., item (jump)
Note
In JAL, you do not need to explicitly use the jsr_w instruction.
The JAL compiler automatically uses jsr_w when the label offset exceeds 16 bits.