Skip to content

JAL Instructions Reference

Peyang edited this page Jul 21, 2025 · 4 revisions

JAL Instructions Reference

This document is the reference of the instructions of JAL (Java Assembler Language).

このページは日本語でもご覧いただけます。


Concept of Instructions

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.

Basic Structure of Instructions

InstructionName [Operand1 [, Operand2, ...]]
  • InstructionName is the name of the instruction defined by the JVM (e.g., iload, istore).
  • Operand is 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)

Especially, operands are not given directly as accepted by the JVM, but are interpreted by JAL in between.

Types of Operands

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

type

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:

  • I represents the int type.
  • Ljava/lang/String; represents the java.lang.String class object type.
  • [I represents an array of int.
  • [Ljava/lang/String; represents an array of java.lang.String.
  • [[I represents a two-dimensional array of int.

Instruction Examples

iconst_0  // Push integer 0 onto the stack
istore 1  // Store the value from the stack into local variable index 1

List of Instructions

Table of Contents

Format of This Section

InstructionName [Operand1 [, Operand2, ...]] (0xInstructionCode)

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 either lconst_0 or lconst_1.


Constant Push

nop (0x00)

Does nothing. Executing this does not affect the stack or local variables.

...
-> ...

aconst_null (0x01)

Pushes null onto the stack.

...,
-> ..., null

iconst_{m1, 0, 1, 2, 3, 4, 5} (0x02 - 0x07)

Pushes the integer -1, 0, 1, 2, 3, 4, or 5 onto the stack.

...,
-> ..., {-1, 0, 1, 2, 3, 4, 5}
  • iconst_m1 pushes -1.
  • iconst_0 pushes 0.
  • iconst_1 pushes 1.
  • iconst_2 pushes 2.
  • iconst_3 pushes 3.
  • iconst_4 pushes 4.
  • iconst_5 pushes 5.

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.)

lconst_{0, 1} (0x09, 0x0A)

Pushes the integer 0 or 1 as a long onto the stack.

...,
-> ..., {0, 1}L
  • lconst_0 pushes 0L.
  • lconst_1 pushes 1L.

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.

fconst_{0, 1, 2} (0x0B, 0x0C, 0x0D)

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_0 pushes 0.0F.
  • fconst_1 pushes 1.0F.
  • fconst_2 pushes 2.0F.

dconst_{0, 1} (0x0E, 0x0F)

Pushes the floating-point numbers 0.0 or 1.0 as double onto the stack.

...,
-> ..., {0.0, 1.0}D
  • dconst_0 pushes 0.0D.
  • dconst_1 pushes 1.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.

bipush byte (0x10)

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.

sipush short (0x11)

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.

ldc scalar (0x12)

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.

ldc_w scalar (0x13)

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.

ldc2_w scalar (0x14)

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.

Local Variable Operations / Load

iload local (0x15)

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.

lload local (0x16)

Loads a long value from the local variable table onto the stack.

...,
-> ..., long

fload local (0x17)

Loads a float value from the local variable table onto the stack.

...,
-> ..., float

dload local (0x18)

Loads a double value from the local variable table onto the stack.

...,
-> ..., double

aload local (0x19)

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

iload_{0, 1, 2, 3} (0x1A, 0x1B, 0x1C, 0x1D)

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

lload_{0, 1, 2, 3} (0x1E, 0x1F, 0x20, 0x21)

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

fload_{0, 1, 2, 3} (0x22, 0x23, 0x24, 0x25)

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

dload_{0, 1, 2, 3} (0x26, 0x27, 0x28, 0x29)

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

aload_{0, 1, 2, 3} (0x2A, 0x2B, 0x2C, 0x2D)

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

iaload (0x2E)

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.

laload (0x2F)

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.

faload (0x30)

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.

daload (0x31)

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.

aaload (0x32)

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.

baload (0x33)

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.

caload (0x34)

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.

saload (0x35)

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.

istore local (0x36)

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.

lstore local (0x37)

Stores a long value from the stack into the local variable table.

..., long
-> ...

fstore local (0x38)

Stores a float value from the stack into the local variable table.

..., float
-> ...

dstore local (0x39)

Stores a double value from the stack into the local variable table.

..., double
-> ...

astore local (0x3A)

Stores an object reference from the stack into the local variable table.

..., object_reference
-> ...

istore_{0, 1, 2, 3} (0x3B, 0x3C, 0x3D, 0x3E)

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
-> ...

lstore_{0, 1, 2, 3} (0x3F, 0x40, 0x41, 0x42)

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
-> ...

fstore_{0, 1, 2, 3} (0x43, 0x44, 0x45, 0x46)

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
-> ...

dstore_{0, 1, 2, 3} (0x47, 0x48, 0x49, 0x4A)

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
-> ...

astore_{0, 1, 2, 3} (0x4B, 0x4C, 0x4D, 0x4E)

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
-> ...

iastore (0x4F)

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.

lastore (0x50)

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.

fastore (0x51)

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.

dastore (0x52)

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.

aastore (0x53)

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.

bastore (0x54)

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.

castore (0x55)

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.

sastore (0x56)

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.

Stack Operations

pop (0x57)

Removes the top item from the stack.

..., item
-> ...

pop2 (0x58)

Removes the top two items from the stack.

..., item1, item2
-> ...

dup (0x59)

Duplicates the top item of the stack and pushes it onto the stack.

..., item
-> ..., item, item

dup_x1 (0x5A)

Duplicates the top item of the stack and inserts it two positions down.

..., item1, item2
-> ..., item2, item1, item2

dup_x2 (0x5B)

Duplicates the top item of the stack and inserts it three positions down.

..., item1, item2, item3
-> ..., item2, item3, item1, item2

dup2 (0x5C)

Duplicates the top two items of the stack and pushes them onto the stack.

..., item1, item2
-> ..., item1, item2, item1, item2

dup2_x1 (0x5D)

Duplicates the top two items of the stack and inserts them three positions down.

..., item1, item2, item3
-> ..., item2, item3, item1, item2, item3

dup2_x2 (0x5E)

Duplicates the top two items of the stack and inserts them four positions down.

..., item1, item2, item3, item4
-> ..., item3, item4, item1, item2, item3, item4

swap (0x5F)

Swaps the top two items of the stack.

..., item1, item2
-> ..., item2, item1

Arithmetic Operations

{iadd, ladd, fadd, dadd} (0x60, 0x61, 0x62, 0x63)

Adds the top two items of the stack and pushes the result.

  • iadd (0x60): integer addition
  • ladd (0x61): long addition
  • fadd (0x62): float addition
  • dadd (0x63): double addition

That is, value1 + value2 is pushed as result.

..., item1, item2
-> ..., result

{isub, lsub, fsub, dsub} (0x64, 0x65, 0x66, 0x67)

Subtracts the top two items of the stack and pushes the result.

  • isub (0x64): integer subtraction
  • lsub (0x65): long subtraction
  • fsub (0x66): float subtraction
  • dsub (0x67): double subtraction

That is, value1 - value2 is pushed as result.

..., item1, item2
-> ..., result

{imul, lmul, fmul, dmul} (0x68, 0x69, 0x6A, 0x6B)

Multiplies the top two items of the stack and pushes the result.

  • imul (0x68): integer multiplication
  • lmul (0x69): long multiplication
  • fmul (0x6A): float multiplication
  • dmul (0x6B): double multiplication

That is, value1 * value2 is pushed as result.

..., item1, item2
-> ..., result

{idiv, ldiv, fdiv, ddiv} (0x6C, 0x6D, 0x6E, 0x6F)

Divides the top two items of the stack and pushes the result.

  • idiv (0x6C): integer division
  • ldiv (0x6D): long division
  • fdiv (0x6E): float division
  • ddiv (0x6F): double division

That is, value1 / value2 is pushed as result.

..., item1, item2
-> ..., result

{irem, lrem, frem, drem} (0x70, 0x71, 0x72, 0x73)

Calculates the remainder of the top two items of the stack and pushes the result.

  • irem (0x70): integer remainder
  • lrem (0x71): long remainder
  • frem (0x72): float remainder
  • drem (0x73): double remainder

That is, value1 % value2 is pushed as result.

..., item1, item2
-> ..., result

{ineg, lneg, fneg, dneg} (0x74, 0x75, 0x76, 0x77)

Negates the top item of the stack and pushes the result.

  • ineg (0x74): integer negation
  • lneg (0x75): long negation
  • fneg (0x76): float negation
  • dneg (0x77): double negation

That is, -value is pushed as result.

..., item
-> ..., result

{ishl, lshl} (0x78, 0x79)

Left-shifts the top two items of the stack and pushes the result.

  • ishl (0x78): integer left shift
  • lshl (0x79): long left shift

That is, value1 << value2 is pushed as result.

..., item1, item2
-> ..., result

{ishr, lshr} (0x7A, 0x7B)

Right-shifts the top two items of the stack and pushes the result.

  • ishr (0x7A): integer right shift
  • lshr (0x7B): long right shift

That is, value1 >> value2 is pushed as result.

..., item1, item2
-> ..., result

{iushr, lushr} (0x7C, 0x7D)

Unsigned right-shifts the top two items of the stack and pushes the result.

  • iushr (0x7C): integer unsigned right shift
  • lushr (0x7D): long unsigned right shift

That is, value1 >>> value2 is pushed as result.

..., item1, item2
-> ..., result

{iand, land} (0x7E, 0x7F)

Bitwise ANDs the top two items of the stack and pushes the result.

  • iand (0x7E): integer bitwise AND
  • land (0x7F): long bitwise AND

That is, value1 & value2 is pushed as result.

..., item1, item2
-> ..., result

{ior, lor} (0x80, 0x81)

Bitwise ORs the top two items of the stack and pushes the result.

  • ior (0x80): integer bitwise OR
  • lor (0x81): long bitwise OR

That is, value1 | value2 is pushed as result.

..., item1, item2
-> ..., result

{ixor, lxor} (0x82, 0x83)

Bitwise XORs the top two items of the stack and pushes the result.

  • ixor (0x82): integer bitwise XOR
  • lxor (0x83): long bitwise XOR

That is, value1 ^ value2 is pushed as result.

..., item1, item2
-> ..., result

iinc local const (0x84)

Increments the integer value in the local variable table by the constant const without using the stack.

..., local_variable
-> ..., local_variable + const

Type Conversion

{i2l, i2f, i2d} (0x85, 0x86, 0x87)

Converts the top integer value on the stack to long, float, or double and pushes the result.

  • i2l (0x85): converts integer to long
  • i2f (0x86): converts integer to float
  • i2d (0x87): converts integer to double
..., integer
-> ..., converted_value

{l2i, l2f, l2d} (0x88, 0x89, 0x8A)

Converts the top long value on the stack to int, float, or double and pushes the result.

  • l2i (0x88): converts long to integer
  • l2f (0x89): converts long to float
  • l2d (0x8A): converts long to double
..., long
-> ..., converted_value

{f2i, f2l, f2d} (0x8B, 0x8C, 0x8D)

Converts the top float value on the stack to integer, long, or double and pushes the result.

  • f2i (0x8B): converts float to integer
  • f2l (0x8C): converts float to long
  • f2d (0x8D): converts float to double
..., float
-> ..., converted_value

{d2i, d2l, d2f} (0x8E, 0x8F, 0x90)

Converts the top double value on the stack to integer, long, or float and pushes the result.

  • d2i (0x8E): converts double to integer
  • d2l (0x8F): converts double to long
  • d2f (0x90): converts double to float
..., double
-> ..., converted_value

{i2b, i2c, i2s} (0x91, 0x92, 0x93)

Converts the top integer value on the stack to byte, char, or short and pushes the result.

  • i2b (0x91): converts integer to byte
  • i2c (0x92): converts integer to char
  • i2s (0x93): converts integer to short
..., integer
-> ..., converted_value

Comparison and Branch

lcmp (0x94)

Compares the top two long values on the stack and pushes the result.

The result is as follows:

  • 0 if the two values are equal
  • 1 if the first value is greater than the second
  • -1 if 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.

{fcmpl, fcmpg} (0x95, 0x96)

Compares the top two float values on the stack and pushes the result.

The result is as follows:

  • 0 if the two values are equal
  • 1 if the first value is greater than the second
  • -1 if 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

{dcmpl, dcmpg} (0x97, 0x98)

Compares the top two double values on the stack and pushes the result.

The result is as follows:

  • 0 if the two values are equal
  • 1 if the first value is greater than the second
  • -1 if 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

{ifeq, ifne, iflt, ifge, ifgt, ifle} label (0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E)

Compares the top integer value on the stack and jumps to the specified label if the condition is met.

  • ifeq (0x99): jump if value is 0
  • ifne (0x9A): jump if value is not 0
  • iflt (0x9B): jump if value is less than 0
  • ifge (0x9C): jump if value is greater than or equal to 0
  • ifgt (0x9D): jump if value is greater than 0
  • ifle (0x9E): jump if value is less than or equal to 0
..., 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)

{if_acmpeq, if_acmpne} label (0xA5, 0xA6)

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)

Control Flow

goto Label (0xA7)

Unconditionally jumps to the specified label.

..., stack item (n)
-> ..., stack item (n)

Warning

The target label must be within the same method.

jsr Label (0xA8)

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.

ret local (0xA9)

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.

tableswitch ... (0xAA)

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 to label0.
  • If the value is 1, it jumps to label1.
  • If the value is 2, it jumps to label2.
  • If none of these match, it jumps to label3.
..., integer
-> ... (jump)

lookupswitch ... (0xAB)

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 to label0.
  • If the value is 13, it jumps to label1.
  • If the value is 21, it jumps to label2.
  • If none of these match, it jumps to label3.
..., integer
-> ... (jump)

ireturn (0xAC)

Returns the integer value at the top of the stack as the return value and transfers control back to the caller.

..., integer
-> ... (return integer)

lreturn (0xAD)

Returns the long value at the top of the stack as the return value and transfers control back to the caller.

..., long
-> ... (return long)

freturn (0xAE)

Returns the float value at the top of the stack as the return value and transfers control back to the caller.

..., float
-> ... (return float)

dreturn (0xAF)

Returns the double value at the top of the stack as the return value and transfers control back to the caller.

..., double
-> ... (return double)

areturn (0xB0)

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)

return (0xB1)

Returns from the current method without a return value and transfers control back to the caller.

...
-> ... (return)

Reference Operations

getstatic fieldRef (0xB2)

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

putstatic fieldRef (0xB3)

Stores the value at the top of the stack into a static field.

For fieldRef, see getstatic.

..., fieldValue
-> ...

getfield fieldRef (0xB4)

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

putfield fieldRef (0xB5)

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
-> ...

invokevirtual methodRef (0xB6)

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

invokespecial methodRef (0xB7)

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.

invokestatic methodRef (0xB8)

Invokes a static method and pushes the return value onto the stack.
For methodRef, see invokevirtual.

..., [arg1, [arg2, ...]]
-> ..., returnValue

invokeinterface methodRef (0xB9)

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

invokedynamic methodName methodDescriptor methodHandle [bootstrapArg1, [bootstrapArg2, ...]] (0xBA)

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

new classRef (0xBB)

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.

newarray type (0xBC)

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

anewarray classRef (0xBD)

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

arraylength (0xBE)

Retrieves the length of the array referenced at the top of the stack and pushes it onto the stack.

..., array_reference
-> ..., length

athrow (0xBF)

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)

checkcast classRef (0xC0)

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)

instanceof classRef (0xC1)

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)

monitorenter (0xC2)

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)

monitorexit (0xC3)

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)

Extended Instructions

wide (0xC4)

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
  • ret
  • iinc

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.

multianewarray classRef dimensions (0xC5)

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

ifnull label (0xC6)

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)

ifnonnull label (0xC7)

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)

goto_w label (0xC8)

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.

jsr_w label (0xC9)

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.

Clone this wiki locally