Java Virtual Machine - Online Instruction Reference Manual

Java Virtual Machine
Online Instruction Reference Manual

Jon Meyer, Troy Downing,
O'Reilly Associates.

This is an online DRAFT version of the instruction reference (Chapter 13) printed in Java Virtual Machine, by Jon Meyer and Troy Downing, published by O'Reilly Associates, ISBN 1-56592-194-1. See book details for further information on this book.

The material presented here probably has some typos and minor errors, but we felt that it would still be a useful reference source for people looking for details of the JVM. You can also see Jasmin Home Page for further information on Jasmin and the JVM.

This material is provided on an "AS IS" basis without warranty of any kind, including without limitation the warranties of merchantability, fitness for a purpose and non-infringement. The entire risk as to the quality and performance of the Software is borne by you. Should the Software prove defective, you and not Chris Hector assume the entire cost of any service and repair. SOME JURISDICTIONS DO NOT ALLOW EXCLUSIONS OF AN IMPLIED WARRANTY, SO THIS DISCLAIMER MAY NOT APPLY TO YOU AND YOU MAY HAVE OTHER LEGAL RIGHTS THATVARY BY JURISDICTION.

  • example
  • aaload
  • aastore
  • aconst_null
  • aload
  • aload_<n>
  • anewarray
  • areturn
  • arraylength
  • astore
  • astore_<n>
  • athrow
  • baload
  • bastore
  • bipush
  • breakpoint
  • caload
  • castore
  • checkcast
  • d2f
  • d2i
  • d2l
  • dadd
  • daload
  • dastore
  • dcmpg
  • dcmpl
  • dconst_<d>
  • ddiv
  • dload
  • dload_<n>
  • dmul
  • dneg
  • drem
  • dreturn
  • dstore
  • dstore_<n>
  • dsub
  • dup
  • dup2
  • dup2_x1
  • dup2_x2
  • dup_x1
  • dup_x2
  • f2d
  • f2i
  • f2l
  • fadd
  • faload
  • fastore
  • fcmpg
  • fcmpl
  • fconst_<f>
  • fdiv
  • fload
  • fload_<n>
  • fmul
  • fneg
  • frem
  • freturn
  • fstore
  • fstore_<n>
  • fsub
  • getfield
  • getstatic
  • goto
  • goto_w
  • i2b
  • i2c
  • i2d
  • i2f
  • i2l
  • i2s
  • iadd
  • iaload
  • iand
  • iastore
  • iconst_<n>
  • iconst_m1
  • idiv
  • if_acmpeq
  • if_acmpne
  • if_icmpeq
  • if_icmpge
  • if_icmpgt
  • if_icmple
  • if_icmplt
  • if_icmpne
  • ifeq
  • ifge
  • ifgt
  • ifle
  • iflt
  • ifne
  • ifnonnull
  • ifnull
  • iinc
  • iload
  • iload_<n>
  • impdep1
  • impdep2
  • imul
  • ineg
  • instanceof
  • invokeinterface
  • invokespecial
  • invokestatic
  • invokevirtual
  • ior
  • irem
  • ireturn
  • ishl
  • ishr
  • istore
  • istore_<n>
  • isub
  • iushr
  • ixor
  • jsr
  • jsr_w
  • l2d
  • l2f
  • l2i
  • ladd
  • laload
  • land
  • lastore
  • lcmp
  • lconst_<l>
  • ldc
  • ldc_w
  • ldc2_w
  • ldiv
  • lload
  • lload_<n>
  • lmul
  • lneg
  • lookupswitch
  • lor
  • lrem
  • lreturn
  • lshl
  • lshr
  • lstore
  • lstore_<n>
  • lsub
  • lushr
  • lxor
  • monitorenter
  • monitorexit
  • multianewarray
  • new
  • newarray
  • nop
  • pop
  • pop2
  • putfield
  • putstatic
  • ret
  • return
  • saload
  • sastore
  • sipush
  • swap
  • tableswitch
  • wide
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - Title

 next

Java Virtual Machine - Online Reference

  • Java Virtual Machine - Online Instruction Reference
  • Inhaltsverzeichnis
next
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - areturn

 prev next contents
areturn

return from method with object reference result

Jasmin Syntax

    areturn
Stack
Before | After
objectref | n/a
... |
Description

objectref is a reference to an object. It must be assignment compatible with the return type of the current method (See Chapter 7 for details of assignment compatibility). areturn pops objectref off the stack and pushes it onto the operand stack of the invoker (i.e. the method which used invokevirtual, invokespecial, invokestatic or invokeinterface to call the currently executing method). All other items on the current method's operand stack are discarded. If the current method is marked as synchronized, then an implicit monitorexit instruction is executed. Then the current method's frame is discarded, the invoker's frame is reinstated, and control returns to the invoker.

Example

.class Example
.super java/lang/Object

; This method takes an integer parameter n, and returns a new array of ints of length n.
.method public static makeIntArray(I)[I
    aload_0        ; push the array size (i.e. n) parameter onto the stack
    newarray int   ; make the array
    areturn        ; return the array
.endmethod

    ; an example of calling makeIntArray to make a 10 element array of ints:
    bipush 10
    invokestatic Example/makeIntArray(I)[I
    astore_1 ; store array in local variable 1
Bytecode
Type | Description
u1 | areturn opcode = 0xB0 (176)
See Also

lreturn, freturn, dreturn, ireturn, return, invokevirtual, invokespecial, invokestatic, invokeinterface

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - arraylength

arraylength

get length of array

Jasmin Syntax

    arraylength

Stack
Before | After
arrayref | length
... | ...
Description

Removes arrayref (a reference to an array) from the stack and replaces it with the length of the array (an int). For multi-dimensional arrays, the length of the first dimension is returned.

Exceptions

NullPointerException - arrayref is null.

Bytecode
Type | Description
u1 | arraylength opcode = 0xBE(190)

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - astore_<n>

astore_<n>

store object reference in local variable <n>

Jasmin Syntax

    astore_0
or
    astore_1
or
    astore_2
or
    astore_3
Stack
Before | After
objectref | ...
... |
Description

Pops objectref (a reference to an object or array) off the stack and stores it in local variable <n>, where <n> is 0, 1, 2 or 3. <n> must be a valid local variable number in the current frame.

'astore_<n>' is functionally equivalent to 'astore <n>', although it is typically more efficient and also takes fewer bytes in the bytecode.

Example

astore_0        ; store reference in local variable 0
astore_1        ; store reference in local variable 1
astore_2        ; store reference in local variable 2
astore_3        ; store reference in local variable 3
Bytecode
Type | Description
u1 | astore_0 opcode = 0x4B (75)
u1 | astore_1 opcode = 0x4C (76)
u1 | astore_2 opcode = 0x4D (77)
u1 | astore_3 opcode = 0x4E (78)
See Also

astore, istore, fstore, dstore, lstore, aload, iload, fload, dload, lload

Notes

astore can also be used to store a returnAddress in a local variable. See the jsr instruction for more details.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - bastore

bastore

store in byte/boolean array

Stack

    bastore
Stack
Before | After
value | ...
index |
arrayref |
... |
Description

Takes a 32-bit int from the stack, truncates it to an 8-bit signed byte, and stores it in an array of bytes. arrayref is a reference to an array of bytes. index is an int. value is the int value to be stored in the array. arrayref, index and value are removed from the stack, and value is truncated to 8 bits and stored in the array at the given index.

bastore is also used to store values in boolean arrays. In this case, arrayref is a reference to an array of booleans (see the newarray instruction) . If value is zero, false is stored at the given index in the array, otherwise true is stored at the given index. In Sun's implementation, boolean arrays are actually stored as byte arrays, using one byte per boolean value. Other implementations might use packed arrays - or even int arrays - this is invisible to programs running on the JVM, which always use baload and bastore to access and store values in boolean arrays.

Exceptions

NullPointerException - arrayref is null

ArrayIndexOutOfBoundsException - index is < 0 or >= arrayref.length

Bytecode
Type | Description
u1 | bastore opcode = 0x54 (84)
See Also

iastore, lastore, fastore, dastore, aastore, castore, sastore, iaload, laload, faload, daload, aaload, baload, caload, saload, newarray,

Notes

2. Array indices start at 0 (the first entry in the array is at index 0).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - breakpoint

breakpoint

reserved opcode

Jasmin Syntax

    n/a
Stack
Before | After
... | ...
Description

Opcode 0xCA (202) is a reserved opcode with the mnemonic breakpoint. This opcode is reserved for internal use by a Java implementation, and must not appear in any class file - methods containing a breakpoint will fail verification.

In Sun's implementation, the breakpoint opcode is used internally as a place-holder indicating a point in a method where control should pass to the Java debugger (jdb).

Bytecode
Type | Description
u1 | breakpoint opcode = 0xCA (202)
See Also

impdep1, impdep2.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - castore

castore

store in character array

Jasmin Syntax

    castore
Stack
Before | After
value | ...
index |
arrayref |
... |
Description

Pops a 32-bit integer from the stack, truncates it to a 16-bit unsigned value, and stores it in an array of characters. arrayref is a reference to an array of 16-bit Unicode characters. index is an int. value is the int value to be stored in the array. arrayref, index and value are removed from the stack, and value is stored in the array at the given index.

Exceptions

NullPointerException - arrayref is null

ArrayIndexOutOfBoundsException - index is < 0 or >= arrayref.length

Bytecode
Type | Description
u1 | castore opcode = 0x55 (85)
See Also

iastore, lastore, fastore, dastore, aastore, bastore, sastore, iaload, laload, faload, daload, aaload, baload, caload, saload

Notes

Array indices start at 0 (the first entry in the array is at index 0).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - checkcast

checkcast

ensure type of an object or array

Jasmin Syntax

    checkcast <type>
<type> is the name of a Java class or interface (e.g. java/lang/String), or the type descriptor of an array (e.g. [[Ljava/lang/String;).

Stack
Before | After
objectref | objectref
... | ...
Description

checkcast checks that the top item on the operand stack (a reference to an object or array) can be cast to a given type. For example, if you write in Java:

return ((String)obj);
then the Java compiler will generate something like:

aload_1                        ; push -obj- onto the stack
checkcast java/lang/String     ; check its a String
areturn                        ; return it
checkcast is actually a shortand for writing Java code like:

if (! (obj == null  ||  obj instanceof <class>)) {
    throw new ClassCastException();
}
// if this point is reached, then object is either null, or an instance of
// <class> or one of its superclasses.
In Jasmin, checkcast takes a single parameter, <type>. <type> is either the name of a Java class or interface, or it is the type descriptor of an array. At runtime, the symbolic name given by <type> is resolved to a Java class (see Chapter 7 for a description of how classes are resolved). Next, checkcast examines the top item on the stack. If objectref belongs to <type> (or one of its subclasses), or if it is null, the objectref is left on the stack and execution continues at the subsequent instruction. If not, a ClassCastException is thrown.

Example

; push object in local variable 1 onto stack
aload_1

; check if it is an instance of Throwable or one of its subclasses.
checkcast java/lang/Throwable

; if execution reaches here, the object in local variable 1
; is still on the stack, and is either null or a Throwable object.

; ---
; Note that checkcast can also be used to check that an array belongs to a given type,
; e.g. to check that local variable 1 contains an array of Strings, use:

aload_1
checkcast [Ljava/lang/String;

; if execution reaches here, the  object on the stack is an array of Strings, or it is null.
Exceptions

ClassCastException - the object on the stack is not an instance of the specified class

Bytecode

In bytecode, immediately following the checkcast opcode is a 16-bit unsigned short integer. This integer is the index of an entry in the constant pool of the current class. The entry is tagged a CONSTANT_Class entry. The name field of the CONSTANT_Class entry is the same as the string given by <type> parameter in Jasmin.
Type | Description
u1 | checkcast opcode = 0xC0 (192)
u2 | index
See Also

instanceof

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - dastore

dastore

store in double-precision float array

Jasmin Syntax

    dastore
Stack
Before | After
value-word1 | ...
value-word2 |
index |
arrayref |
... |
Description

Pops a two-word double precision floating point number from the stack and stores it in an array of doubles. arrayref is a reference to an array of doubles. index is an int. value is the double to be stored in the array. arrayref, index and value are removed from the stack, and value is stored in the array at the given index.

Exceptions

NullPointerException - arrayref is null

ArrayIndexOutOfBoundsException - index is < 0 or is >= arrayref.length

Bytecode
Type | Description
u1 | dastore opcode = 0x52 (82)
See Also

iastore, lastore, fastore, aastore, bastore, castore, sastore, iaload, laload, faload, daload, aaload, baload, caload, saload

Notes

Array indices start at 0 (the first entry in the array is at index 0).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - dconst_<d>

dconst_<d>

push the double 0.0 or 1.0

Jasmin Syntax

    dconst_0
or
    dconst_1

Stack
Before | After
... | <d>-word1
 | <d>-word2
 | ...
Description

dconst_<d> pushes the constant double precision floating point number <d> onto the stack, where <d> is either 0 or 1. For example, to push the double precision float 0.0 onto the stack, use:

    dconst_0 ; push the double 0.0 onto the stack
Note that you could also use:

    ldc2_w 0.0    ; push the double 0.0 onto the stack
although this instruction takes more space in the class file and is typically less efficient.

Example

dconst_0    ; push the double 0.0 onto the stack
dconst_1    ; push the double 1.0 onto the stack
Bytecode
Type | Description
u1 | dconst_0 opcode = 0x0E (14)
u1 | dconst_1 opcode = 0x0F (15)
See Also

bipush, sipush, ldc, ldc_w, ldc2_w, aconst_null, iconst_m1, iconst_<n>, lconst_<l>, fconst_<f>,

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - dload_<n>

dload_<n>

retrieve double from local variables <n> and <n> + 1

Jasmin Syntax

    dload_0
or
    dload_1
or
    dload_2
or
    dload_3
Stack
Before | After
... | result-word1
 | result-word2
 | ...
Description

Retrieves the double-precision float stored in local variables <n> and <n> + 1 and pushes it onto the operand stack. Both <n> and <n> + 1 must be valid local variable numbers in the current frame, and together they must be holding a double.

See the description of dload for more information on how doubles are retrieved from local variables.

'dload_<n>' is functionally equivalent to 'dload <n>', although it is typically more efficient and also takes fewer bytes in the bytecode.

Example

dload_0         ; push double in local variables 0 and 1 onto stack
dload_1         ; push double in local variables 1 and 2 onto stack
dload_2         ; push double in local variables 2 and 3 onto stack
dload_3         ; push double in local variables 3 and 4 onto stack
Bytecode
Type | Description
u1 | dload_0 opcode = 0x26 (38)
u1 | dload_1 opcode = 0x27 (39)
u1 | dload_2 opcode = 0x28 (40)
u1 | dload_3 opcode = 0x29 (41)
See Also

dload, fload, aload, iload, lload

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - dstore_<n>

dstore_<n>

store double in local variables <n> and <n> + 1

Jasmin Syntax

    dstore_0
or
    dstore_1
or
    dstore_2
or
    dstore_3
Stack
Before | After
value-word1 | ...
value-word2 |
... |
Description

Pops a double-precision float off of the operand stack and stores it in the local variables <n> and <n> + 1. Both <n> and <n> + 1 must be valid local variable numbers in the current frame.

See the description of dstore for more information on how doubles are stored in local variables.

'dstore_<n>' is functionally equivalent to 'dstore <n>', although it is typically more efficient and also takes fewer bytes in the bytecode.

Example

dstore_0        ;store double in local variable 0 and 1
dstore_1        ;store double in local variable 1 and 2
dstore_2        ;store double in local variable 2 and 3
dstore_3        ;store double in local variable 3 and 4
Bytecode
Type | Description
u1 | dstore_0 opcode = 0x47 (71)
u1 | dstore_1 opcode = 0x48 (72)
u1 | dstore_2 opcode = 0x49 (73)
u1 | dstore_3 opcode = 0x4A (74)
See Also

astore, dstore, istore, fstore, lstore

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - dup2_x1

dup2_x1

duplicate two words and insert beneath third word

Jasmin Syntax

    dup2_x1
Stack
Before | After
word1 | word1
word2 | word2
word3 | word3
... | word1
 | word2
 | ...

Description

Duplicates the top two-word item on the stack and inserts the duplicate before the previous (single-word) item on the stack. Alternatively, this instruction could also be used to duplicate two single-word items and insert them before the third single-word item on the stack.

Example

bipush 100
dconst_0

; stack now contains:
;     0.0 | double-word1
;     0.0 | double-word2
;     100   integer-word1

dup2_x1

; stack now contains:
;     0.0 | double-word1
;     0.0 | double-word2
;     100   integer-word1
;     0.0 | double-word1
;     0.0 | double-word2
Bytecode
Type | Description
u1 | dup2_x1 = 0x5D (93)
See Also

dup, dup2, dup_x1, dup2_x2

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - dup2_x2

dup2_x2

duplicate two words and insert beneath fourth word

Jasmin Syntax

    dup2_x2
Stack
Before | After
word1 | word1
word2 | word2
word3 | word3
word4 | word4
... | word1
 | word2
 | ...
Description

Duplicates the top two-word item on the stack and inserts the duplicate before the previous (two-word) item on the stack. Alternatively, this instruction could be used to duplicate two single-word items and insert them before the before the third two-word (or fourth single-word) item on the stack.

Example

bipush 100
bipush 200
dconst_0

; stack now contains:

;     0.0 | double-word1
;     0.0 | double-word2
;     200   integer2-word1
;     100   integer1-word1
dup2_x2

; stack now contains:
;     0.0 | double-word1
;     0.0 | double-word2
;     200   integer2-word1
;     100   integer1-word1
;     0.0 | double-word1
;     0.0 | double-word2
Bytecode
Type | Description
u1 | dup2_x2 opcode = 0x5E (94)
See Also

dup, dup2, dup_x1, dup2_x1

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - fastore

fastore

store in single-precision float array

Jasmin Syntax

    fastore
Stack
Before | After
value | ...
index |
arrayref |
... |
Description

Takes a single-precision float from the stack and stores it in an array of floats. arrayref is a reference to an array of single-precision floats. index is an int. value is the single-precision float value to be stored in the array. arrayref, index and value are removed from the stack, and value is stored in the array at the given index.

Exceptions

NullPointerException - arrayref is null

ArrayIndexOutOfBoundsException - index is < 0 or >= arrayref.length

Bytecode
Type | Description
u1 | fastore opcode = 0x51 (81)
See Also

iastore, lastore, dastore, aastore, bastore, castore, sastore iaload, laload, faload, daload, aaload, baload, caload, saload

Notes

Array indices start at 0 (the first entry in the array is at index 0).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - fconst_<f>

fconst_<f>

push the single float 0.0, 1.0 or 2.0

Jasmin Syntax

    fconst_0
or
    fconst_1
or
    fconst_2
Stack
Before | After
... | <f>
 | ...
Description

fconst_<f> represents the series of opcodes fconst_0, fconst_1, and fconst_2 that are used to push the constant single-precision floats 0.0, 1.0 and 2.0 onto the stack.

For example, to push the single-precision float zero onto the stack, use:

    fconst_0 ; push single-precision float 0 onto the stack
Note that you could also use:

    ldc 0.0  ; push the float 0.0 onto the stack
although this instruction takes more space in the class file and is also less efficient.

Example

fconst_0    ; push the float 0.0 onto the stack
fconst_1    ; push the float 1.0 onto the stack
fconst_2    ; push the float 2.0 onto the stack
Bytecode
Type | Description
u1 | fconst_0 opcode = 0x0B (11)
u1 | fconst_1 opcode = 0x0C (12)
u1 | fconst_2 opcode = 0x0D (13)
See Also

bipush, sipush, ldc, ldc_w, ldc2_w, aconst_null, iconst_m1, lconst_<l> iconst_<n>, lconst_<l>, dconst_<d>

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - freturn

freturn

return from method with float result

Jasmin Syntax

    freturn
Stack
Before | After
return-value | n/a
... |
Description

Pops a float from the top of the stack and pushes it onto the operand stack of the invoker (i.e. the method which used invokevirtual, invokespecial, invokestatic or invokeinterface to call the currently executing method). All other items on the current method's operand stack are discarded. If the current method is marked as synchronized, then an implicit monitorexit instruction is executed. Then the current method's frame is discarded, the invoker's frame is reinstated, and control returns to the invoker. This instruction can only be used in methods whose return type is float.

Bytecode
Type | Description
u1 | freturn opcode = 0xAE (174)
See Also

lreturn, ireturn, dreturn, areturn, return

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - fstore_<n>

fstore_<n>

store float in local variable <n>

Jasmin Syntax

    fstore_0
or
    fstore_1
or
    fstore_2
or
    fstore_3
Stack
Before | After
value | ...
... |
Description

Pops a single precision floating point number off the stack and stores it in local variable <n>, where <n> is 0, 1, 2 or 3. <n> must be a valid local variable number in the current frame.

'fstore_<n>' is functionally equivalent to 'fstore <n>', although it is typically more efficient and also takes fewer bytes in the bytecode.

Example

fstore_0        ;store float in local variable 0
fstore_1        ;store float in local variable 1
fstore_2        ;store float in local variable 2
fstore_3        ;store float in local variable 3
Bytecode
Type | Description
u1 | fstore_0 opcode = 0x43 (67)
u1 | fstore_1 opcode = 0x44 (68)
u1 | fstore_2 opcode = 0x45 (69)
u1 | fstore_3 opcode = 0x46 (70)
See Also

istore, fstore, astore, dstore, lstore

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - getfield

getfield

get value of object field

Jasmin Syntax

    getfield <field-spec> <descriptor>
e.g.
    getfield java/lang/System/out Ljava/io/PrintStream;
<field-spec> is composed of two parts, a classname and a fieldname. The classname is all of the characters in the <field-spec> up to the last '/' character, and the fieldname is the rest of the characters after the last '/'. For example:

    foo/baz/AnotherClass/aVeryLongFieldName
    -- classname -------/-- fieldname -----
{{JM - can we turn this into a nicer diagram?}}
<descriptor> is the Java type descriptor for the field, for example Ljava/io/PrintStream;

In Jasmin, the .field directive is used to add a field to a class. See Chapter 16 for a description of this and other Jasmin directives.

Stack
Before | After
objectref | value
... | ...
or, for fields that hold doubles or longs:
Before | After
objectref | value-word1
... | value-word2
 | ...
Description

getfield pops objectref (a reference to an object) from the stack, retrieves the value of the field identified by <field-spec> from objectref, and pushes the one-word or two-word value onto the operand stack.

For example, if you have the class:

    package xyz;
    class Point {
        public int xCoord, yCoord;
    };
Then, assuming p is an instance of the class Point, writing the Java expression:

    int x = p.xCoord;
generates a call to getfield like:

    aload_1                      ; push object in local varable 1 (i.e. p) onto the stack
    getfield xyz/Point/xCoord I  ; get the value of p.xCoord, which is an int
    istore_2                     ; store the int value in local variable 2 (x)
In Jasmin, getfield takes two parameters, <field-spec> and <descriptor>. <field-spec> gives classname, the name of the class that defines the field, as well as fieldname, as the name of the field itself. In the example above, the <field-spec> is "xyz/Point/xCoord", indicating that the classname is "xyz/Point" and the fieldname is "xCoord". <descriptor> describes the type of data held in the field, and is a standard Java type descriptor (see Chapter 4 for a full description of type descriptors). In the example above, <descriptor> is "I", since the field holds an integer.

getfield first resolves classname to a Java class. Then it locates the fieldname in that class, determining the width of the field (in bytes) and its offset (in bytes) from the base of the object data. The type of the field must match <descriptor>. See Chapter 7 for more on how fields are resolved

To retrieve the value for the field, getfield obtains the bytes starting at offset and extending for width bytes from the start of objectref's instance data, expands it to either a 4-byte or 8-byte value, and pushes the value onto the operand stack.

Exceptions

NullPointerException - objectref is null

Bytecode

In bytecode, the getstatic opcode is followed by a 16-bit unsigned integer index. This is the index of an entry in the constant pool of the current class. The entry is tagged a CONSTANT_Fieldref entry. It indicates a CONSTANT_Class entry that gives the name of the class containing the field (i.e. classname), and a CONSTANT_NameAndType entry that gives the fieldname, and the type <descriptor>.
Type | Description
u1 | getfield opcode = 0xB4 (180)
u2 | index
See Also

putfield, putstatic, getstatic

Notes

Fields cannot be overriden, although they can be 'shadowed'. For example, with the two classes:

    class A { int x; }
and
    class B extends A { int x; }
instances of B will have storage for both the field "A/x" and the field "B/x". Which field is accessed is determined by the class name given in <field-spec>.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - getstatic

getstatic

get value of static field

Jasmin Syntax

       getstatic <field-spec> <descriptor>
<field-spec> is composed of two parts, a classname and a fieldname. The classname is all of the characters in the <field-spec> up to the last '/' character, and the fieldname is the rest of the characters after the last '/'. For example:

    foo/baz/AnotherClass/aVeryLongFieldName
    -- classname -------/-- fieldname -----
{{JM - can we turn this into a nicer diagram?}}
<descriptor> is the Java type descriptor for the field, for example Ljava/io/PrintStream;

In Jasmin, the .field directive is used to add a field to a class. See Chapter 16 for a description of this and other Jasmin directives.

Stack
Before | After
... | value
 | ...
or, for static fields that hold doubles or longs:
Before | After
... | value-word1
 | value-word2
 | ...
Description

getstatic pops objectref (a reference to an object) from the stack, retrieves the value of the static field (also known as a class field) identified by <field-spec> from objectref, and pushes the one-word or two-word value onto the operand stack.

For example, when you write the Java expression:

    PrintStream obj = java.lang.System.out;
this generates a call to getstatic like:

    getstatic java/lang/System/out Ljava/io/PrintStream;
    astore_1   ; store the object reference result in local variable 1
In Jasmin, getstatic takes two parameters, <field-spec> and <descriptor>. <field-spec> provides classname, the name of the class that defines the static field, as well fieldname, as the name of the field. In the example above, the <field-spec> is "java/lang/System/out", indicating that the classname is "java/lang/System" and the fieldname is "out". <descriptor> indicates the type of data held in the field, and is a standard Java type descriptor (see Chapter 4). In the example above, <descriptor> is "Ljava/io/PrintStream;", i.e. a reference to a PrintStream object.

getstatic first resolves classname into a Java class. Then it locates the fieldname in that class, determining the width of the field (in bytes) and its offset (in bytes) from the base of the class's static data. The type of the field must match <descriptor>. See Chapter 7 for more on how fields are resolved

To retrieve the value for the field, getstatic obtains the bytes starting at offset and extending for width bytes from the start of the class's static data, expands it to either a 4-byte or 8-byte value, and pushes the value onto the operand stack.

Bytecode

In bytecode, the getstatic opcode is followed by a 16-bit unsigned integer index. This is the index of an entry in the constant pool of the current class. The entry is tagged a CONSTANT_Fieldref entry. The fieldref entry lists a CONSTANT_Class entry in the constant pool whose name is the classname given in <field-spec>, as well as a CONSTANT_NameAndType entry in the constant pool, whose name is the fieldname given in <field-spec>, and whose descriptor is the string given by <descriptor>.
Type | Description
u1 | getstatic opcode = 0xB2 (178)
u2 | index

See Also

putfield, getfield, putstatic

Notes

Fields cannot be overriden, although they can be 'shadowed'. For example, with the two classes:

    class A { static int x; }
and
    class B extends A { static int x; }
then the runtime system will allocate storage for both the static field "A/x" and the static field "B/x". Which field is accessed is determined by the class name given in <field-spec>.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - iastore

iastore

store in integer array

Jasmin Syntax

    iastore
Stack
Before | After
value | ...
index |
arrayref |
... |
Description

Takes an int from the stack and stores it in an array of ints. arrayref is a reference to an array of ints. index is an int. value is the int value to be stored in the array. arrayref, index and value are removed from the stack, and value is stored in the array at the given index.

Exceptions

NullPointerException - arrayref is null

ArrayIndexOutOfBoundsException - index is < 0 or >= arrayref.length

Bytecode
Type | Description
u1 | iastore opcode = 0x4F (79)
See Also

lastore, fastore, dastore, aastore, bastore, castore, sastore, iaload, laload, faload, daload, aaload, baload, caload, saload

Notes

Array indices start at 0 (the first entry in the array is at index 0).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - iconst_<n>

iconst_<n>

push the integer constant 0, 1, 2, 3, 4 or 5

Jasmin Syntax

    iconst_0
or
    iconst_1
or
    iconst_2
or
    iconst_3
or
    iconst_4
or
    iconst_5
Stack
Before | After
... | <n>
 | ...
Description

iconst_<n> represents the series of opcodes iconst_0, iconst_1, iconst_2, iconst_3, iconst_4 and iconst_5. These are used to push the constant ints 0 through 5 onto the stack. For example, to push the int zero onto the stack, use:

iconst_0 ; push 0 onto the stack.
Note that you could also use:

bipush 0 ; push 0 onto the stack
or

sipush 0 ; push 0 onto the stack
or

ldc 0 ; push 0 onto the stack
although these instructions are typically less efficient than the equivalent iconst_<n> and also take up more bytes in the class file.

Example

iconst_0  ; push 0 onto the stack
iconst_1  ; push 1 onto the stack
iconst_2  ; push 2 onto the stack
iconst_3  ; push 3 onto the stack
iconst_4  ; push 4 onto the stack
iconst_5  ; push 5 onto the stack
Bytecode
Type | Description
u1 | iconst_0 opcode = 0x03 (3)
u1 | iconst_1 opcode = 0x04 (4)
u1 | iconst_2 opcode = 0x05 (5)
u1 | iconst_3 opcode = 0x06 (6)
u1 | iconst_4 opcode = 0x07 (7)
u1 | iconst_5 opcode = 0x08 (8)
See Also

bipush, sipush, ldc, ldc_w, ldc2_w, aconst_null, iconst_m1, lconst_<l>, fconst_<f>, dconst_<d>

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - iconst_m1

iconst_m1

push the integer constant -1

Jasmin Syntax

    iconst_m1
Stack
Before | After
... | -1
 | ...
Description

This instruction pushes the int -1 onto the operand stack.

Bytecode
Type | Description
u1 | iconst_m1 opcode = 0x02 (2)
See Also

bipush, sipush, ldc, ldc_w, ldc2_w, aconst_null, iconst_<n>, lconst_<l>, fconst_<f>, dconst_<d>

Notes

You could also use bipush -1, sipush -1 or ldc -1 to achieve the same effect, although iconst_m1 is typically more efficient and uses fewer bytes in the bytecode.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - if_acmpeq

if_acmpeq

jump if two object references are equal

Jasmin Syntax

    if_acmpeq <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
value1 | ...
value2 |
... |
Description

if_acmpeq pops the top two object references off the stack and compares them. If the two object references are equal (i.e. if they both refer to the same object), execution branches to the address (pc + branchoffset), where pc is the address of the if_acmpeq opcode in the bytecode and branchoffset is a 16-bit signed integer parameter following the if_acmpeq opcode in the bytecode. If the object references refer to different objects, execution continues at the next instruction.

If you are using Jasmin, branchoffset is computed for you from the address of <label>.

Example

    aload_1         ; push the object reference in local variable 1 onto stack
    aload_2         ; push the object reference in local variable 2 onto stack
    if_acmpeq Label ; if the two references on the stack are identical, jump to Label
    return          ; return if not equal
Label:
    ; execution continues here if local variables 1 and 2 refer to the same object
Bytecode
Type | Description
u1 | if_acmpeq opcode = 0xA5 (165)
s2 | branchoffset
See Also

if_acmpne

Notes

Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - if_acmpne

if_acmpne

jump if two object references are not equal

Jasmin Syntax

    if_acmpne <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
value1 | ...
value2 |
... |
Description

if_acmpne pops the top two object references off the stack and compares them. If the two object references are not equal (i.e. if they refer to different objects), execution branches to the address (pc + branchoffset), where pc is the address of the if_acmpne opcode in the bytecode and branchoffset is a 16-bit signed integer parameter following the if_acmpne opcode in the bytecode. If the object references refer to the same object, execution continues at the next instruction.

If you are using Jasmin, branchoffset is computed for you from the address of <label>.

Example

    aload_1         ; push the object reference in local variable 1 onto stack
    aload_2         ; push the object reference in local variable 2 onto stack
    if_acmpne Label ; if the two references on the stack differ, jump to Label
    return          ; return if local variables 1 and 2 are the same object
Label:
    ; execution continues here if local variables 1 and 2 refer to the different  objects
Bytecode
Type | Description
u1 | if_acmpne opcode = 0xA6 (166)
s2 | branchoffset
See Also

if_icmpne, if_icmplt, if_icmpgt, if_icmple, if_icmpge

Notes

Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - if_icmpeq

if_icmpeq

jump if two integers are equal

Jasmin Syntax

    if_icmpeq <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
value1 | ...
value2 |
... |
Description

if_icmpeq pops the top two ints off the stack and compares them. If the two integers are equal, execution branches to the address (pc + branchoffset), where pc is the address of the if_icmpeq opcode in the bytecode and branchoffset is a 16-bit signed integer parameter following the if_icmpeq opcode in the bytecode. If the integers are not equal, execution continues at the next instruction.

If you are using Jasmin, branchoffset is computed for you from the address of <label>.

Example

    bipush 2        ; push the int 2 onto the stack
    iload_1         ; push the int value in local variable 1 onto the stack
    if_icmpeq Label ; if the value of local variable 1 equals 2, jump to Label
    return          ; return if not equal
Label:
    ; execution continues here if local variable 1 equals 2...
Bytecode
Type | Description
u1 | if_icmpeq opcode = 0x9F (159)
s2 | branchoffset
See Also

if_icmpne, if_icmplt, if_icmpgt, if_icmple, if_icmpge

Notes

Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - if_icmpge

if_icmpge

jump if one integer is greater than or equal to another

Jasmin Syntax

    if_icmpge <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
value1 | ...
value2 |
Description

if_icmpge pops the top two ints off the stack and compares them. If value2 is greater than or equal to value1, execution branches to the address (pc + branchoffset), where pc is the address of the if_icmpge opcode in the bytecode and branchoffset is a 16-bit signed integer parameter following the if_icmpge opcode in the bytecode. If value2 is less than value1, execution continues at the next instruction.

If you are using Jasmin, branchoffset is computed for you from the address of <label>.

Example

    iload_1         ; push the int value in local variable 1 onto the stack
    bipush 2        ; push the int 2 onto the stack
    if_icmpge Label ; if the value of local variable 1 >= 2, jump to Label
    return          ; return if local variable 1 < 2
Label:
    ; execution continues here if local variable 1 >= 2...
Bytecode
Type | Description
u1 | if_icmpge opcode = 0xA2 (162)
s2 | branchoffset
See Also

if_icmpeq, if_icmpne, if_icmplt, if_icmpgt, if_icmple

Notes

Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - if_icmpgt

if_icmpgt

jump if one integer is greater than another

Jasmin Syntax

    if_icmpgt <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
value1 | ...
value2 |
Description

if_icmpgt pops the top two ints off the stack and compares them. If value2 is greater than value1, execution branches to the address (pc + branchoffset), where pc is the address of the if_icmpgt opcode in the bytecode and branchoffset is a 16-bit signed integer parameter following the if_icmpgt opcode in the bytecode. If value2 is less than or equal to value1, execution continues at the next instruction.

If you are using Jasmin, branchoffset is computed for you from the address of <label>.

Example

    iload_1         ; push the integer value of local variable 1 onto the stack
    bipush 2        ; push the integer 2 onto the stack
    if_icmpgt Label ; if the value of local variable 1 is greater than 2, jump to Label
    return          ; return if local variable 1 <= 2
Label:
    ; execution continues here if local variable 1 is geater than 2...
Bytecode
Type | Description
u1 | if_icmpgt opcode = 0xA3 (163)
s2 | branchoffset

See Also

if_icmpeq, if_icmpne, if_icmplt, if_icmple, if_icmpge

Notes

Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - if_icmple

if_icmple

jump if one integer is less than or equal to another

Jasmin Syntax

    if_icmple <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
value1 | ...
value2 |
Description

if_icmple pops the top two ints off the stack and compares them. If value2 is less than or equal to value1, execution branches to the address (pc + branchoffset), where pc is the address of the if_icmple opcode in the bytecode and branchoffset is a 16-bit signed integer parameter following the if_icmple opcode in the bytecode. If value2 is greater than value1, execution continues at the next instruction.

If you are using Jasmin, branchoffset is computed for you from the address of <label>.

Example

    iload_1         ; push the int value in local variable 1 onto the stack
    bipush 2        ; push the int 2 onto the stack
    if_icmple Label ; if the value of local variable 1 is <= 2, jump to Label
    return          ; return if local variable 1 is greater than 2
Label:
    ; execution continues here if local variable 1 is less than or equal to 2...
Bytecode
Type | Description
u1 | if_icmple opcode = 0xA4 (164)
s2 | branchoffset

See Also

if_icmpeq, if_icmpne, if_icmplt, if_icmpgt, if_icmpge

Notes

Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - if_icmplt

if_icmplt

jump if one integer is less than another

Jasmin Syntax

    if_icmplt <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
value1 | ...
value2 |
Description

if_icmplt pops the top two ints off the stack and compares them. If value2 is less than value1, execution branches to the address (pc + branchoffset), where pc is the address of the if_icmplt opcode in the bytecode and branchoffset is a 16-bit signed integer parameter following the if_icmplt opcode in the bytecode. If value2 is greater than or equal to value1, execution continues at the next instruction.

If you are using Jasmin, branchoffset is computed for you from the address of <label>.

Example

    iload_1         ; push the int value in local variable 1 onto the stack
    bipush 2        ; push the int 2 onto the stack
    if_icmplt Label ; if the value of local variable 1 is <= 2, jump to Label
    return          ; return if local variable 1 is greater than 2
Label:
    ; execution continues here if local variable 1 is less than or equal to 2...
Bytecode
Type | Description
u1 | if_icmplt opcode = 0xA1 (161)
s2 | branchoffset
See Also

if_icmpeq, if_icmpne, if_icmpgt, if_icmple, if_icmpge

Notes

Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - if_icmpne

if_icmpne

jump if two integers are not equal

Jasmin Syntax

    if_icmpne <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
value1 | ...
value2 |
... |
Description

if_icmpne pops the top two ints off the stack and compares them. If the two integers are not equal, execution branches to the address (pc + branchoffset), where pc is the address of the if_icmpne opcode in the bytecode and branchoffset is a 16-bit signed integer parameter following the if_icmpne opcode in the bytecode. If the integers are equal, execution continues at the next instruction.

If you are using Jasmin, branchoffset is computed for you from the address of <label>.

Example

    bipush 2        ; push the int 2 onto the stack
    iload_1         ; push the int value in local variable 1 onto the stack
    if_icmpne Label ; if the value of local variable 1 does not equal 2, jump to Label
    return          ; return if local variable 1 equals 2
Label:
    ; execution continues here if local variable 1 does not equals 2...
Bytecode
Type | Description
u1 | if_icmpne opcode = 0xA0 (160)
s2 | branchoffset
See Also

if_icmpeq, if_icmplt, if_icmpgt, if_icmple, if_icmpge

Notes

Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - instanceof

instanceof

test class of object

Jasmin Syntax

    instanceof <type>
<type> is the name of a Java class, e.g. java/lang/String. Alternatively, to test for array references, <type> can be the type descriptor of an array, e.g. [[Ljava/lang/String;

Stack
Before | After
objectref | int-result
... | ...
Description

The instanceof instruction is used to implement the Java language's instanceof operator, which tests whether an object reference or array belongs to a given class.

instanceof takes a single parameter, <type>. <type> is either the name of a Java class, or it is the type descriptor of an array.

At runtime, <type> is resolved (Chapter 7 describes how classes are resolved). Next, instanceof pops objectref (a reference to an object) off the top of the operand stack. If objectref is an instance of <type> or one of <type>'s subclasses, the int 1 is pushed onto the stack, otherwise the int 0 is pushed onto the stack. If objectref is null, the result is always 0. If <type> is an interface, int-result will be 1 if objectref implements that interface, and 0 if objectref does not implement the interface.

Example

; using instanceof to test for a String:
    aload_1        ; push object reference in local variable 1 onto stack
    instanceof java/lang/String;      ; test if item on stack is a String
    ifne HaveString                   ; if so, goto HaveString
    return                            ; otherwise, return
HaveString:
    ; if this point is reached, local variable 1 holds a string

; this example uses instanceof to test if local variable 1 holds
; an integer array
    aload_1                  ; push local variable 1 onto the stack
    instanceof [I            ; test if the top item on the stack is an integer array
    ifne HaveIntegerArray    ; if so, jump to HaveIntegerArray
    return                   ; simply return if local variable 1 is not an int array
HaveIntegerArray:
    ; if this point is reached, local variable 1 holds an integer array

; you can also use instanceof to test that objects implement a given interface,
; e.g.
    aload_1                  ; push local variable 1 onto the stack
    instanceof java/lang/Runnable  ; test if it implements the Runnable interface
    ifne HaveARunnable       ; if so, jump to HaveARunnable
    return                   ; otherwise return
HaveARunnable:
    ; if this point is reached, local variable 1 holds a reference to an object
    ; that implements the Runnable interface.
Bytecode

In bytecode, immediately following the instanceof opcode is a 16-bit unsigned short integer. This integer is the index of an entry in the constant pool of the current class. The entry is tagged a CONSTANT_Class entry. The name field of the CONSTANT_Class entry is the same as the string given by <type> parameter in Jasmin.
Type | Description
u1 | instanceof opcode = 0xC1 (193)
u2 | index
See Also

checkcast

Chapter 7 gives a pseudo-code implementation of instanceof.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - invokeinterface

invokeinterface

invoke an interface method

Jasmin Syntax

    invokeinterface <method-spec> <n>
<method-spec> is a method specification and <n> is an integer in the range 0-255.

The <method-spec> is a single token made up of three parts: an interfacename, a methodname and a descriptor. e.g.

     java/util/Enumeration/hasMoreElements()Z
is the method called "hasMoreElements" in the interface called "java.util.Enumeration", and it has the descriptor "()Z" (i.e. it takes no arguments and returns a boolean result). In Jasmin, the characters up to the '(' character in <method-spec> form the interfacename and methodname (the interfacename is all the characters up to the last '/' character, and the methodname is all the characters between the last '/' and the '(' character). The characters from '(' to the end of the string are the descriptor. This is illustrated in the following diagram:

     foo/baz/MyInterface/myMethod(Ljava/lang/String;)V
     -------------------         ---------------------
             |           --------         |
     interfacename          |             |
                       methodname     descriptor

{{JM - can we have a nicer diagram?}}
Stack
Before | After
argN | [result]
--- | ...
arg2 |
arg1 |
objectref |
... |
Description

invokeinterface is used to invoke a method declared within a Java interface. For example, if you have the Java code:

void test(Enumeration enum) {
    boolean x = enum.hasMoreElements();
    ...
}
invokeinterface will be used to call the hasMoreElements() method, since Enumeration is a Java interface, and hasMoreElements() is a method declared in that interface. In this example, the Java compiler generates code like:

    aload_1            ; push local variable 1 (i.e. the enum object) onto the stack
    ; call hasMoreElements()
    invokeinterface java/util/Enumeration/hasMoreElements()Z 1
    istore_2           ; store the boolean result in local variable 2 (i.e. x)
Which particular implementation of hasMoreElements() is used will depend on the type of object held in local variable 1 at runtime.

Before performing the method invokation, the interface and the method identified by <method-spec> are resolved. See Chapter 9 for a description of how methods are resolved.

To invoke an interface method, the interpreter first pops <n> items off the operand stack, where <n> is an 8-bit unsigned integer parameter taken from the bytecode. The first of these items is objectref, a reference to the object whose method is being called. The rest of the items are the arguments for the method.

Then the class of the object referred to by objectref is retrieved. This class must implement the interface named in <method-spec>. The method table for this class is searched, and the method with the given methodname and descriptor is located.

Once the method has been located, invokeinterface calls the method. First, if the method is marked as synchronized, the monitor associated with objectref is entered. Next, a new stack frame is established on the callstack. Then the arguments for the method are placed in the local variable slots of the new stack frame structure. arg1 is stored in local variable 1, arg2 is stored in local variable 2 and so on. objectref is stored in local variable 0, the local variable used by the special Java variable this. Execution continues at the first instruction in the bytecode of the new method.

Methods marked as native are handled slightly differently. For native methods, the runtime system locates the platform-specific code for the method, loading it and linking it into the JVM if necessary. Then the native method code is executed with the arguments that were popped from the operand stack. The exact mechanism used to invoke native methods is implementation-specific.

When the method called by invokeinterface returns, any single (or double) word return result is placed on the operand stack of the current method. If the invoked method was marked as synchronized, the monitor associated with objectref is exited. Then execution continues at the instruction that follows invokeinterface in the bytecode.

Exceptions

NullPointerException - objectref is null

StackOverflowError - no more space in callstack for a new stack frame

Bytecode

In bytecode, after the invokeinterface opcode is a 16-bit unsigned integer index. This is the index of an entry in the constant pool. The entry is tagged as a CONSTANT_InterfaceMethodref entry. This entry has two fields. One field points to a CONSTANT_Class entry in the constant pool whose name is the interfacename from <method-spec>, and the other points to a CONSTANT_NameAndType entry in the constant pool whose name is the methodname from <method-spec> and whose descriptor is the type descriptor from <method-spec>.

invokeinterface takes an additional unsigned byte parameters in bytecode: <n>. <n> is the number of argument words the method takes plus one, (i.e. the second parameter given to the invokeinterface instruction in Jasmin). <n> must match the number of argument words given in the descriptor for the method.

After <n>, there follows a single byte, which must be zero (this byte location is in fact used at runtime by Sun's Java interpreter - it caches a hashing value in this byte, to speed up invokeinterface method lookup).
Type | Description
u1 | invokeinterface opcode = 0xB9 (185)
u2 | index
u1 | <n>
u1 | 0
See Also

invokevirtual, invokespecial, invokestatic

Notes

1. Of the instructions used to invoke instance methods, invokeinterface is the most complex to implement, and typically the least efficient. See Chapter 10 (Implementation) for more details on this.

2. invokevirtual cannot be used to invoke the special methods <init> or <clinit> - see invokespecial.

3. The <n> and 0 byte parameters in bytecode are present mostly for historical reasons.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - invokespecial

invokespecial

invoke method belonging to a specific class

Jasmin Syntax

    invokespecial <method-spec>
<method-spec> is a method specification. It is a single token made up of three parts: a classname, a methodname and a descriptor. e.g.

     java/lang/StringBuffer/<init>()V
is the method called "<init>" (the special name used for instance initialization methods) in the class called "java.lang.StringBuffer", and it has the descriptor "()V" (i.e. it takes no arguments and no results). In Jasmin, the characters up to the '(' character in <method-spec> form the classname and methodname (the classname is all the characters up to the last '/' character, and the methodname is all the characters between the last '/' and the '(' character). The characters from '(' to the end of the string are the descriptor. This is illustrated in the following diagram:

     foo/baz/Myclass/myMethod(Ljava/lang/String;)V
     ---------------         ---------------------
           |         --------         |
           |            |             |
         classname  methodname    descriptor
Stack
Before | After
argN | [result]
--- |
arg2 |
arg1 |
objectref |
... |
Description

invokespecial is used in certain special cases to invoke a method Specifically, invokespecial is used to invoke:

the instance initialization method, <init>

a private method of this

a method in a superclass of this

The main use of invokespecial is to invoke an object's instance initialization method, <init>, during the construction phase for a new object. For example, when you write in Java:

new StringBuffer()
code like the following is generated:

new java/lang/StringBuffer         ; create a new StringBuffer
dup                                ; make an extra reference to the new instance
                                   ; now call an instance initialization method
invokespecial java/lang/StringBuffer/<init>()V
                                   ; stack now contains an initialized StringBuffer.
invokespecial is also used by the Java language by the 'super' keyword to access a superclass's version of a method. For example, in the class:

   class Example {
       // override equals
       public boolean equals(Object x) {
            // call Object's version of equals
            return super.equals(x);
       }
   }
the 'super.equals(x)' expression is compiled to:

aload_0  ; push 'this' onto the stack
aload_1  ; push the first argument (i.e. x) onto the stack
; now invoke Object's equals() method.
invokespecial java/lang/Object/equals(Ljava/lang/Object;)Z
Finally, invokespecial is used to invoke a private method. Remember that private methods are only visible to other methods belonging the same class as the private method.

Before performing the method invokation, the class and the method identified by <method-spec> are resolved. See Chapter 9 for a description of how methods are resolved.

invokespecial first looks at the descriptor given in <method-spec>, and determines how many argument words the method takes (this may be zero). It pops these arguments off the operand stack. Next it pops objectref (a reference to an object) off the operand stack. objectref must be an instance of the class named in <method-spec>, or one of its subclasses. The interpreter searches the list of methods defined by the class named in <method-spec>, looking for a method called methodname whose descriptor is descriptor. This search is not based on the runtime type of objectref, but on the compile time type given in <method-spec>.

Once a method has been located, invokespecial calls the method. First, if the method is marked as synchronized, the monitor associated with objectref is entered. Next, a new stack frame structure is established on the call stack. Then the arguments for the method (which were popped off the current method's operand stack) are placed in local variables of the new stack frame structure. arg1 is stored in local variable 1, arg2 is stored in local variable 2 and so on. objectref is stored in local variable 0 (the local variable used for the special Java variable this). Finally, execution continues at the first instruction in the bytecode of the new method.

Methods marked as native are handled slightly differently. For native methods, the runtime system locates the platform-specific code for the method, loading it and linking it into the JVM if necessary. Then the native method code is executed with the arguments popped from the operand stack. The exact mechanism used to invoke native methods is implementation-specific.

When the method called by invokespecial returns, any single (or double) word return result is placed on the operand stack of the current method. If the invoked method was marked as synchronized, the monitor associated with objectref is exited. Execution continues at the instruction that follows invokespecial in the bytecode.

Exceptions

NullPointerException - objectref is null

StackOverflowError - no more space in callstack for a new stack frame

Bytecode

In bytecode, after the invokespecial opcode is a 16-bit unsigned integer index. This is the index of an entry in the constant pool. The entry is tagged as a CONSTANT_Methodref entry. This entry has two fields. One field points to a CONSTANT_Class entry in the constant pool whose name is the classname from <method-spec>, and the other points to a CONSTANT_NameAndType entry in the constant pool whose name is the methodname from <method-spec> and whose descriptor is the type descriptor from <method-spec>.
Type | Description
u1 | invokespecial opcode = 0xB7 (183)
u2 | index
See Also

invokevirtual, invokeinterface, invokestatic

Notes

1. In Java Virtual Machine implementations prior to version JDK 1.02, this instruction was called invokenonvirtual, and was less restrictive than invokespecial - it wasn't limited to invoking only superclass, private or <init> methods. The class access flag ACC_SUPER (see Chapter 4) is used to indicate which semantics are used by a class. In older class files, the ACC_SUPER flag is unset. In all new classes, the ACC_SUPER flag should be set, indicating that the restrictions enforced by invokespecial are obeyed. (In practice, all the common uses of invokenonvirtual continue to be supported by invokespecial, so this change should have little impact on JVM users).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - invokestatic

invokestatic

invoke a class (static) method

Jasmin Syntax

invokestatic <method-spec>
<method-spec> is a method specification. It is a single token made up of three parts: a classname, a methodname and a descriptor. e.g.

     java/lang/System/exit(I)V
is the method called "exit" in the class called "java.lang.System", and it has the descriptor "(I)V" (i.e. it takes an integer argument and returns no result). In Jasmin, the characters up to the '(' character in <method-spec> form the classname and methodname (the classname is all the characters up to the last '/' character, and the methodname is all the characters between the last '/' and the '(' character). The characters from '(' to the end of the string are the descriptor. This is illustrated in the following diagram:

     foo/baz/Myclass/myMethod(Ljava/lang/String;)V
     ---------------         ---------------------
           |         --------         |
           |            |             |
         classname  methodname    descriptor
Stack
Before | After
argN | [result]
... | ...
arg3 |
arg2 |
arg1 |
Description

invokestatic calls a static method (also known as a class method). For example, if you write in Java:

    System.exit(1);
this is compiled into the JVM code:

    iconst_1      ; push 1 onto the stack.
                  ; now call System.exit()
    invokestatic java/lang/System/exit(I)V
Before performing the method invokation, the class and the method identified by <method-spec> are resolved. See Chapter 9 for a description of how methods are resolved.

invokestatic looks at the descriptor given in <method-spec>, and determines how many arguments the method takes (this may be zero). It pops these arguments off the operand stack. Then it searches the list of static methods defined by the class, locating the method methodname with a descriptor descriptor.

Once the method has been located, invokestatic calls the method. First, if the method is marked as synchronized, the monitor associated with the class object for the method's class is entered. Next, a new stack frame structure is established on the call stack. Then the arguments for the method (which were popped off the current method's operand stack) are placed in local variables of the new stack frame structure. arg1 is stored in local variable 0, arg2 is stored in local variable 1 and so on. Finally, execution continues at the first instruction in the bytecode of the new method.

Methods marked as native are handled slightly differently. For native methods, the runtime system locates the platform-specific code for the method, loading it and linking it into the JVM if necessary. Then the native method code is executed with the arguments that were popped from the operand stack. The exact mechanism used to invoke native methods is implementation-specific.

When the method called by invokestatic returns, any single (or double) word return result is placed on the operand stack of the current method. If the invoked method was marked as synchronized, the monitor associated with the class named in <method-spec> is exited. Execution continues at the instruction that follows invokestatic in the bytecode.

Exceptions

StackOverflowError - no more space in callstack for a new stack frame

Bytecode

In bytecode, after the invokestatic opcode is a 16-bit unsigned integer index. This is the index of an entry in the constant pool. The entry is tagged as a CONSTANT_Methodref entry. This entry has two fields. One field points to a CONSTANT_Class entry in the constant pool whose name is the classname from <method-spec>, and the other points to a CONSTANT_NameAndType entry in the constant pool whose name is the methodname from <method-spec> and whose descriptor is the type descriptor from <method-spec>.
Type | Description
u1 | invokestatic opcode = 0xB8 (184)
u2 | index
See Also

invokevirtual, invokespecial, invokeinterface

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - invokevirtual

invokevirtual

call an instance method

Jasmin Syntax

    invokespecial <method-spec>
<method-spec> is a method specification. It is a single token made up of three parts: a classname, a methodname and a descriptor. e.g.

     java/lang/StringBuffer/charAt(I)C
is the method called "charAt" in the class called "java.lang.StringBuffer", and it has the descriptor "(I)C" (i.e. it takes an integer argument and returns a char result). In Jasmin, the characters up to the '(' character in <method-spec> form the classname and methodname (the classname is all the characters up to the last '/' character, and the methodname is all the characters between the last '/' and the '(' character). The characters from '(' to the end of the string are the descriptor. This is illustrated in the following diagram:

     foo/baz/Myclass/myMethod(Ljava/lang/String;)V
     ---------------         ---------------------
           |         --------         |
           |            |             |
         classname  methodname    descriptor
Stack
Before | After
arg1 | [result]
arg2 | ...
... |
argN |
objectref |
... |
Description

invokevirtual dispatches a Java method. It is used in Java to invoke all methods except interface methods (which use invokeinterface), static methods (which use invokestatic), and the few special cases handled by invokespecial.

For example, when you write in Java:

    Object x;
    ...
    x.equals("hello");
this is compiled into something like:

    aload_1       ; push local variable 1 (i.e. 'x') onto stack
    ldc "hello"   ; push the string "hello" onto stack

    ; invoke the equals method
    invokevirtual java/lang/Object/equals(Ljava/lang/Object;)Z
    ; the boolean result is now on the stack
Note that the actual method run depends on the runtime type of the object invokevirtual is used with. So in the example above, if x is an instance of a class that overrides Object's equal method, then the subclasses' overridden version of the equals method will be used.

Before performing the method invokation, the class and the method identified by <method-spec> are resolved. See Chapter 9 for a description of how methods are resolved.

invokevirtual looks at the descriptor given in <method-spec>, and determines how many arguments the method takes (this may be zero). It pops these arguments off the operand stack. Next it pops objectref off the stack. objectref is a reference to the object whose method is being called. invokevirtual retrieves the Java class for objectref, and searches the list of methods defined by that class and then its superclasses, looking for a method called methodname, whose descriptor is descriptor.

Once a method has been located, invokevirtual calls the method. First, if the method is marked as synchronized, the monitor associated with objectref is entered. Next, a new stack frame structure is established on the call stack. Then the arguments for the method (which were popped off the current method's operand stack) are placed in local variables of the new stack frame structure. arg1 is stored in local variable 1, arg2 is stored in local variable 2 and so on. objectref is stored in local variable 0 (the local variable used for the special Java variable this). Finally, execution continues at the first instruction in the bytecode of the new method.

When the method called by invokevirtual returns, any single (or double) word return result is placed on the operand stack of the current method and execution continues at the instruction that follows invokevirtual in the bytecode.

Exceptions

NullPointerException - objectref is null

StackOverflowError - no more space in callstack for a new stack frame

Bytecode

In bytecode, after the invokevirtual opcode is a 16-bit unsigned integer index. This is the index of an entry in the constant pool. The entry is tagged as a CONSTANT_Methodref entry. This entry has two fields. One field points to a CONSTANT_Class entry in the constant pool whose name is the classname from <method-spec>, and the other points to a CONSTANT_NameAndType entry in the constant pool whose name is the methodname from <method-spec> and whose descriptor is the type descriptor from <method-spec>.
Type | Description
u1 | invokevirtual opcode = 0xB6 (182)
u2 | index
See Also

invokespecial, invokestatic, invokeinterface

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - ireturn

ireturn

return from method with integer result

Jasmin Syntax

    ireturn
Stack
Before | After
return-value | n/a
... |
Description

Pops an int from the top of the stack and pushes it onto the operand stack of the invoker (i.e. the method which used invokevirtual, invokespecial, invokestatic or invokeinterface to call the currently executing method). All other items on the current method's operand stack are discarded. If the current method is marked as synchronized, then an implicit monitorexit instruction is executed. Then the current method's frame is discarded, the invoker's frame is reinstated, and control returns to the invoker. This instruction can only be used in methods whose return type is int.

Bytecode
Type | Description
u1 | ireturn opcode = 0xAC (172)
See Also

lreturn, freturn, dreturn, areturn, return

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - istore_<n>

istore_<n>

store integer in local variable <n>

Jasmin Syntax

    istore_0
or
    istore_1
or
    istore_2
or
    istore_3
Stack
Before | After
value | ...
... |
Description

Pops an int off the stack and stores it in local variable <n>, where <n> is 0, 1, 2 or 3. <n> must be a valid local variable number in the current frame.

'istore_<n>' is functionally equivalent to 'istore <n>', although it is typically more efficient and also takes fewer bytes in the bytecode.

Example

istore_0        ;store integer in local variable 0
istore_1        ;store integer in local variable 1
istore_2        ;store integer in local variable 2
istore_3        ;store integer in local variable 3

Bytecode
Type | Description
u1 | istore_0 opcode = 0x3C (59)
u1 | istore_1 opcode = 0x3D (60)
u1 | istore_2 opcode = 0x3E (61)
u1 | istore_3 opcode = 0x3F (62)
See Also

lstore, fstore, dstore, astore

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - lastore

lastore

store in long integer array

Jasmin Syntax

    lastore
Stack
Before | After
value-word1 | ...
value-word2 |
index |
arrayref |
... |
Description

Takes a two-word long integer from the stack and stores it in an array of long integers. arrayref is a reference to an array of long integers. index is an int. value is the long integer value to be stored in the array. arrayref, index and value are removed from the stack, and value is stored in the array at the given index.

Exceptions

NullPointerException - arrayref is null

ArrayIndexOutOfBoundsException - index is < 0 or >= arrayref.length

Bytecode
Type | Description
u1 | lastore opcode = 0x50 (80)
See Also

iastore, fastore, dastore, aastore, bastore, castore, sastore, iaload, laload, faload, daload, aaload, baload, caload, saload

Notes

Array indices start at 0 (the first entry in the array is at index 0).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - lconst_<l>

lconst_<l>

push the long integer 0 or 1

Jasmin Syntax

    lconst_0
or
    lconst_1
Stack
Before | After
... | <l>-word1
 | <l>-word2
 | ...
Description

lconst_<l> represents the two opcodes lconst_0, lconst_1 that are used to push the constant long integers 0 and 1 onto the stack. For example, to push the long integer zero onto the stack, use:

    lconst_0 ; push long integer 0 onto the stack
Note that you could also use:

    ldc2_w 0    ; push the long integer 0 onto the stack
although this instruction takes more space in the class file and is also slower.

Example

lconst_0    ; push the long int 0 onto the stack
lconst_1    ; push the long int 1 onto the stack
Bytecode
Type | Description
u1 | lconst_0 opcode = 0x09 (9)
u1 | lconst_1 opcode = 0x0A (10)
See Also

bipush, sipush, ldc, ldc_w, ldc2_w, aconst_null, iconst_m1 iconst_<n>, fconst_<f>, dconst_<d>

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - lload_<n>

lload_<n>

retrieve long integer from local variables <n> and <n> + 1

Jasmin Syntax

    lload_0
or
    lload_1
or
    lload_2
or
    lload_3
Stack
Before | After
... | result-word1
 | result-word2
 | ...
Description

Retrieves the two-word long integer stored in local variables <n> and <n> + 1 and pushes it onto the operand stack. Both <n> and <n> + 1 must be valid local variable numbers in the current frame, and together they must be holding a long.

See the description of lload for more information on how longs are retrieved from local variables.

'lload_<n>' is functionally equivalent to 'lload <n>', although it is typically more efficient and also takes fewer bytes in the bytecode.

Example

lload_0         ;push long integer in local variable 0 and 1 onto stack
lload_1         ;push long integer in local variable 1 and 2 onto stack
lload_2         ;push long integer in local variable 2 and 3 onto stack
lload_3         ;push long integer in local variable 3 and 4 onto stack
Bytecode
Type | Description
u1 | lload_0 opcode = 0x1E (30)
u1 | lload_1 opcode = 0x1F (31)
u1 | lload_2 opcode = 0x20 (32)
u1 | lload_3 opcode = 0x21 (33)
See Also

fload, iload, dload

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - lookupswitch

lookupswitch

match key in table and jump

Jasmin Syntax

    lookupswitch
        <key1>   : <label1>
        <key2>   : <label2>
        ...
        <keyN>   : <labelN>
        default  : <labelDefault>
<key1>, <key2> etc. are 32-bit integers. <label1>, <label2>, etc. are label names.

To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
item | ...
... |
Description

This is used to perform an efficient compare-and-jump, as might be needed for a switch statement. The table used by lookupswitch is given after the lookupswitch opcode in bytecode.

lookupswitch works as follows. First, an int, item, is taken from the top of the stack. Then, lookupswitch searches the table looking for an entry whose <key> field matches item. If a match is found, execution branches to the address of the corresponding <label>. If no match is found, execution branches to <labelDefault>.

Example

; this is like the Java code:
;      switch (i) {
;           case 1:     return(10);
;           case 10:    return(100);
;           default:    return(0);
;      }
    iload_1    ; push local variable 1 onto the stack (i.e. i)

    ; switch based on the value on the stack
    lookupswitch
        1       : Label1
        10      : Label2
        default : Dlabel
Label1:               ; local variable 1 holds the value 1
    bipush 10
    ireturn    ; return 10

Label2:               ; local variable 1 holds the value 10
    bipush 100
    ireturn    ; return 100

Dlabel:               ; local variable 1 holds something else
    bipush 0
    return    ; return 0
Bytecode

lookupswitch is a variable length instruction. After the lookupswitch opcode, between 0 to 3 bytes of padding zeros are inserted, so that the default_offset parameter starts at an offset in the bytecode which is a multiple of 4. Next, a 32-bit int n >= 0 is given, indicating the number of key/value integer pairs in the table. This is followed by n pairs of ints. For each pair, the first 32-bit int value is the key, and the second 32-bit int value is the relative offset to jump to if that key is matched. (the offset is relative to the address of the lookupswitch instruction in bytecode).
Type | Description
u1 | lookupswitch opcode = 0xAB (171)
- | ...0-3 bytes of padding ...
s4 | default_offset
s4 | n
s4 | key_1
s4 | offset_1
s4 | key_2
s4 | offset_2
... | ...
s4 | key_n
s4 | offset_n
See Also

tableswitch

Notes

1. Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).

2. Addresses given in the table are relative - the values in the table are added to the current pc (i.e. the address of this lookupswitch instruction) to obtain the new value for pc.

3. Keys in the table must be sorted in increasing order, so <key1> is less than <key2>, and so on up to <keyN>. Jasmin performs this sorting automatically.

4. Even though offsets in the table are given as 32-bit ints, the maximum address in a Java method is limited by other factors to 65535.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - lreturn

lreturn

return from method with long result

Jasmin Syntax

    lreturn
Stack
Before | After
value-word1 | n/a
value-word2 | ...
... |
Description

Pops a two-word long integer from the top of the stack and pushes it onto the operand stack of the invoker (i.e. the method which used invokevirtual, invokespecial, invokestatic or invokeinterface to call the currently executing method). All other items on the current method's operand stack are discarded. If the current method is marked as synchronized, then an implicit monitorexit instruction is executed. Then the current method's frame is discarded, the invoker's frame is reinstated, and control returns to the invoker. This instruction can only be used in methods whose return type is long.

Bytecode
Type | Description
u1 | lreturn opcode = 0xAD (173)
See Also

ireturn, freturn, dreturn, areturn, return

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - lstore_<n>

lstore_<n>

store long in local variables <n> and <n> + 1

Jasmin Syntax

    lstore_0
or
    lstore_1
or
    lstore_2
or
    lstore_3
Stack
Before | After
value-word1 | ...
value-word2 |
... |
Description

Retrieves the long integer stored in local variables <n> and <n> + 1 and pushes it onto the operand stack. Both <n> and <n> + 1 must be valid local variable numbers in the current frame, and together they must be holding a long.

See the description of lstore for more information on how doubles are retrieved from local variables.

'lstore_<n>' is functionally equivalent to 'lstore <n>', although it is typically more efficient and also takes fewer bytes in the bytecode.

Example

lstore_0        ;store long in local variable 0 and 1
lstore_1        ;store long in local variable 1 and 2
lstore_2        ;store long in local variable 2 and 3
lstore_3        ;store long in local variable 3 and 4
Bytecode
Type | Description
u1 | lstore_0 opcode = 0x3F (63)
u1 | lstore_1 opcode = 0x40 (64)
u1 | lstore_2 opcode = 0x41 (65)
u1 | lstore_3 opcode = 0x42 (66)
See Also

astore, istore, dstore, fstore

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - monitorenter

monitorenter

enter synchronized region of code

Jasmin Syntax

    monitorenter
Stack
Before | After
objectref | ...
... |
Description

The monitorenter/monitorexit mechanism is used by the Java synchronized statement to coordinate access to an object among multiple threads. For example, when you write in Java code:

static void Sort(int [] array) {
    // synchronize this operation so that some other thread can't
    // manipulate the array while we are sorting it. This assumes that other
    // threads also synchronize their accesses to the array.
    synchronized(array) {
        // now sort elements in array
    }
}
then JVM code like the following is generated:

.method static Sort([I)V
    aload_0
    monitorenter    ; lock object in local variable 0

    ; now sort elements in array

    aload_0
    monitorexit      ; finished with object in local variable 0
    return
.end method
monitorenter obtains an exclusive lock on the object referenced by objectref. There are three possible scenarios:

If no other thread has locked the object, a new lock is established on the object, and execution continues at the next instruction.

If the object is currently locked by another thread, monitorenter blocks, waiting for the other thread to unlock the object.

If the current thread already owns a lock on the object, a counter is incremented - the lock will only be released when the counter returns to zero (see monitorexit).

Exceptioms

NullPointerException - the object reference on the stack is null.

Bytecode
Type | Description
u1 | monitorenter opcode = 0xC2 (194)
See Also

monitorexit

The Java Language Specification provides a full account of how locks and threads are managed.

Notes

1. Methods which are marked as synchronized implicitly perform a monitorenter when invoked, and a monitorexit when they return.

2. Java's wait(), notify() and notifyAll() methods also interact with locks on objects.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - monitorexit

monitorexit

leave synchronized region of code

Jasmin Syntax

    monitorexit
Stack
Before | After
objectref | ...
... |
Description

This releases an exclusive lock that was previously obtained using monitorenter for the object objectref. If other threads are waiting for the object to become unlocked, one of the waiting threads will be able to acquire a lock on the object and proceed.

Note that a single thread can lock an object several times - the runtime system maintains a count of the number of times that the object was locked by the current thread, and only unlocks the object when the counter reaches zero (i.e. when the number of monitorenters and monitorexits applied to a given object are equal).

The monitorenter/monitorexit mechanism is used by the Java synchronized statement to coordinate access to an object among multiple threads.

Exceptioms

NullPointerException - objectref is null.

IllegalMonitorStateException - objectref was not previously locked by the current thread.

Bytecode
Type | Description
u1 | monitorexit opcode = 0xC3 (195)
See Also

monitorenter

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - multianewarray

multianewarray

allocate multi-dimensional array

Jasmin Syntax

    multianewarray <type> <n>
<type> is the type descriptor of the array, e.g. for an array holding arrays of integers <type> is [[I.

<n> is an integer in the range 1-255.

Stack
Before | After
sizeN | arrayref
--- | ...
size3 |
size2 |
size1 |
... |
Description

Allocates a multi-dimensional array. In Java, a multi-dimensional array is structured an array of arrays, i.e. an array whose elements are references to array objects. So constructing an array like:

new int [3][2]
produces a structure in memory like:

Click here for Picture

In this particular example the top level array is an array containing three 32-bit references. Each of these references identifies a two-element int array.

The same general approach applies to higher dimension arrays. For example, a three-dimensional array is structured as a top level array of arrayrefs, each of which refers to an array of arrayrefs, each of which refers to an array of items.

The lengths of each array within the multi-dimensional array are given as positive ints on the operand stack. The number of ints taken from the stack is specified by the unsigned byte parameter <n>. The type of the array is given as an array type descriptor by the <type> parameter.

The <type> is first resolved to a Java class (see Chapter 7 for a description of how array type descriptors are resolved). multianewarray then allocates the first <n> dimensions of a multidimensional array from the heap. If <n> is one, only the top-level array is created. So the statement:

new int [3][]
generates JVM code like:

bipush 3
multianewarray [[I 1    ; construct first dimension of the 2-D array
in this case only the three-element top-level array is created.

To construct both the top-level array and its sub-arrays, e.g. to fully construct

new int [3][2]
use the JVM code:

bipush 3
bipush 2
multianewarray [[I 2    ; construct both dimensions of the 2-D array
Here the second parameter given to multianewarray is 2, so the first and second dimensions are created (i.e. the top-level array and the array objects within the top-level array).

<n> must be less than or equal to the dimensionality given in the array's descriptor - i.e. it must be less than or equal to the number of '[' characters at the start of <type>.

The elements within the array are initialized to zero (for numeric and boolean arrays), or null for arrays of references. multianewarray leaves a reference to the newly constructed array on the operand stack.

Example

; to allocate an array like:
;     new String[2][5]

    bipush 2
    bipush 5
    multianewarray [[Ljava/lang/String; 2   ; construct both dimensions
    ; stack now hold a reference two the new two dimensional array.

;
; multianewarray can be used to allocate only some of the
; dimensions of an array. For example, you write:
;
;     x = new int[6][3][]
;
; using:

    bipush 6
    bipush 3
    multianewarray [[[I 2  ; allocate 2 of the 3 dimensions
    astore_1               ; store array in local variable 1

; then you can create the final dimensions later using
; newarray or anewarray. e.g.
;
;    x[0][1] = new int[50];
;
; would be:

    aload_1         ; push the array
    iconst_0
    aaload          ; get x[0] - an array of arrays of ints

    iconst_1
    bipush 50
    newarray int    ; allocate an array of 50 ints
    aastore         ; store this in x[0][1]

;
; You can also use multianewarray to create
; single-dimensional arrays. e.g.

    bipush 50
    multianewarray [Ljava/lang/Thread; 1

; is the same as writing:

    bipush 50
    anewarray java/lang/Thread

; except that the latter is more efficient.

Exceptions

NegativeArraySizeException - size is less than zero

OutOfMemoryError - insufficient memory to allocate the array

Bytecode

In bytecode, after the multianewarray opcode is a 16-bit unsigned integer index. This is the index of an entry in the constant pool of the current class. The entry at that index is tagged a CONSTANT_Class entry. The name field of the entry is a string containing the characters given by <type> in Jasmin.

After the index is a single unsigned byte, <n>, the number of dimensions of the array to allocate.
Type | Description
u1 | multianewarray opcode = 0xC5 (197)
u2 | index
u1 | <n>
See Also

newarray, anewarray, new

Notes

You can use multianewarray to allocate single-dimension arrays, though using anewarray or newarray is more efficient.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - astore

astore

store object reference in local variable

Jasmin Syntax

    astore <varnum>
or
    wide
    astore <varnum>
In the first form, <varnum> is an unsigned integer in the range 0 to 0xFF. In the second (wide) form, <varnum> is an unsigned integer in the range 0 to 0xFFFF.

Stack
Before | After
objectref | ...
... |
Description

Pops objectref (a reference to an object or array) off the stack and stores it in local variable <varnum>. The astore instruction takes a single parameter, <varnum>, an unsigned integer which indicates which local variable is used. <varnum> must be a valid local variable number in the current frame.

Example

aload 1    ; Push object reference in local variable 1 onto stack
astore 3	; and store it in local variable 3
Bytecode

For local variable numbers in the range 0-255, use:
Type | Description
u1 | astore opcode = 0x3A (58)
u1 | <varnum>
There is also a wide format for this instruction, which supports access to all local variables from 0 to 65535:
Type | Description
u1 | wide opcode = 0xC4 (196)
u1 | astore opcode = 0x3A (58)
u2 | <varnum>
See Also

lstore, istore, dstore, fstore, wide

Notes

astore can also be used to store a returnAddress in a local variable. See the jsr instruction for more details.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - baload

baload

retrieve byte/boolean from array

Jasmin Syntax

    baload
Stack
Before | After
index | value
arrayref | ...
... | ...
Description

Retrieves a byte from a byte array, expands it to an integer and places it on the operand stack. arrayref is a reference to an array of bytes. index is an int. The arrayref and index are removed from the stack, and the 8-bit signed byte at the given index in the array is retrieved, sign-extended to a 32-bit int, and pushed onto the stack.

baload is also used to retrieve values from boolean arrays. In this case, arrayref is a reference to an array of booleans (see the newarray instruction) . If the entry at the given index is true, then the int 1 is pushed onto the stack, otherwise the int 0 is pushed onto the stack. In Sun's implementation, boolean arrays are actually stored as byte arrays, using one byte per boolean value. Other implementations might use packed arrays - or even int arrays - this is invisible to programs running on the JVM, which always use baload and bastore to access and store values in boolean arrays.

Example

; This is like the Java code:
;     byte x = arr[0];
; where x is local variable 2 and arr is a byte array in local variable 1
aload_1       ; load local variable 1 onto the stack
iconst_0      ; push the integer 0 onto the stack
baload        ; retrieve the entry
istore_2      ; store the entry in local variable 2
Exceptions

NullPointerException - arrayref is null

ArrayIndexOutOfBoundsException - index is < 0 or >= arrayref.length

Bytecode
Type | Description
u1 | baload opcode = 0x33 (51)
See Also

iaload, laload, faload, daload, aaload, caload, saload, iastore, lastore, fastore, dastore, aastore, bastore, castore, sastore, newarray

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - bipush

bipush

push one-byte signed integer

Jasmin Syntax

    bipush <n>
<n> is an integer >= -128 and <= 127 that is pushed onto the stack.

Stack
Before | After
... | <n>
... | ...
Description

bipush takes a single parameter, <n> (an 8-bit signed integer), sign extends it to a 32-bit int, and pushes the resulting int value onto the operand stack.

bipush is typically more efficient than ldc. It also occupies fewer bytes in the class file.

Example

bipush    0x10    ; push the value 0x10 (16) onto the operand stack
Bytecode

The bipush opcode is followed in the bytecode by an 8-bit signed byte specifying the integer value to push.
Type | Description
u1 | bipush opcode = 0x10 (16)
s1 | <n>
See Also

sipush, ldc, ldc_w, ldc2_w, aconst_null, iconst_m1, iconst_<n>, lconst_<l>, fconst_<f>, dconst_<d>

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - d2f

d2f

convert double to float

Jasmin Syntax

    d2f
Stack
Before | After
double-word1 | float-result
double-word2 | ...
... |
Description

Pops a two-word double precision floating point number off of the operand stack, casts it into a single precision float, and pushes the resulting float back onto the stack. There is a loss of precision and range in the result.

This conversion is done in accordance with IEEE 754 specifications, with rounding using IEEE 754 round-to-nearest mode.

The sign of the value if preserved. A value which is too small to be represented as a float is converted to positive or negative zero. A value that is too large to be represented as a float is converted to positive infinity or negative infinity. If the value was NaN, the result is NaN.

Bytecode
Type | Description
u1 | d2f opcode = 0x90 (144)
See Also

d2i, d2l

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - d2i

d2i

convert double to integer

Jasmin Syntax

    d2i
Stack
Before | After
double-word1 | integer-result
double-word2 | ...
... |
Description

Pops a two-word double precision floating point number off of the operand stack, casts it into a 32-bit int, and pushes the resulting int onto the stack.

Rounding is done using IEEE 754 round-to-nearest mode. The fractional part is lost by rounding towards zero, so (int)-3.14 becomes -3.

If the original double value is NaN, the result is 0. If the value is too large to be represented as an integer, or if it is positive infinity, the result is the largest possible integer 0x7FFFFFFF. If the value is too small (i.e. a negative value of large magnitude, or negative infinity) then the result is the most negative integer 0x80000000.

Bytecode
Type | Description
u1 | d2i opcode = 0x8E (142)
See Also

d2l, d2f

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - d2l

d2l

convert double to long integer

Jasmin Syntax

    d2l
Stack
Before | After
double-word1 | long-word1
double-word2 | long-word2
... | ...
Description

Pops a two-word double precision floating point number off of the operand stack, converts it into a 64-bit long integer, and pushes the resulting two-word long onto the stack.

Rounding is done using IEEE 754 round-to-nearest mode. The fractional part is lost by rounding towards zero, so (long)-3.14 becomes -3.

If the original double value is NaN, the result is 0. If the value is too large to be represented as an integer, or if it is positive infinity, the result is the largest possible long integer Long.MAX_VALUE. If the value is too small (i.e. a negative value of large magnitude, or negative infinity) then the result is the most negative long integer Long.MIN_VALUE.

In some implementations, this may be coded using the C casting mechanism, e.g.

void d2l(double d, int &l_high, int &l_low)
{
    l_low = (unsigned int)d;
    l_high = (unsigned int)(d / 2**32);
}
where l_low and l_high are respectively the least significant and most significant 32-bit words of the long.

Bytecode
Type | Description
u1 | d2l opcode = 0x8F (143)
See Also

d2i, d2f

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - dadd

dadd

add two doubles

Jasmin Syntax

    dadd
Stack
Before | After
value1-word1 | result-word1
value1-word2 | result-word2
value2-word1 | ...
value2-word2 |
... |
Description

Takes the two top double-precision floating point numbers off of the operand stack, adds them, and pushes the result back onto the stack.

Bytecode
Type | Description
u1 | dadd opcode = 0x63 (99)
See Also

iadd, fadd, ladd

Notes

The addition is computed using IEEE 754 round-to-nearest mode and gradual underflow. Standard IEEE arithmetic rules are used for the special NaN, infinity, and zero values.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - daload

daload

retrieve double-precision float from array

Jasmin Syntax

    daload
Stack
Before | After
index | value-word1
arrayref | value-word2
... | ...
Description

Retrieves an entry from a double precision float array and places it on the stack. arrayref is a reference to an array of double-precision floating point numbers. index is an int. The arrayref and index are removed from the stack, and the two-word value at the given index in the array is pushed onto the stack.

Example

; This is like the Java code:
;     double x = arr[0];
; where x is local variable 2 and arr is a double array in local variable 1
aload_1       ; load local variable 1 onto the stack
iconst_0      ; push the integer 0 onto the stack
daload        ; retrieve the entry
dstore_2      ; store the entry in local variable 2
Exceptions

NullPointerException - arrayref is null

ArrayIndexOutOfBoundsException - index is < 0 or is >= arrayref.length

Bytecode
Type | Description
u1 | daload opcode = 0x31 (49)
See Also

iaload, faload, laload, aaload, baload, caload, saload, iastore, lastore, fastore, dastore, aastore, bastore, castore, sastore

Notes

Array indices start at 0 (the first entry in the array is at index 0).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - dcmpg

dcmpg

compare two doubles (1 on NaN)

Jasmin Syntax

    dcmpg

Stack
Before | After
value1-word1 | int-result
value1-word2 | ...
value2-word1 |
value2-word2 |
... |
Description

This takes two double-precision floating point numbers off the operand stack and compares them, using IEEE 754 rules.

If the two numbers are the same, the int 0 is pushed onto the stack. If value2 is greater than value1, the int 1 is pushed onto the stack. If value1 is greater than value2, -1 is pushed onto the stack. If either numbers is NaN, the int 1 is pushed onto the stack. +0.0 and -0.0 are treated as equal.

Example

dload_1       ; push the double in local variable 1
dconst_0      ; push the double 0.0 onto the stack
dcmpg         ; compare the two numbers

; The integer result on the stack is:
;     0 if local variable 1 equals 0
;     -1 if local variable 1 is less than 0
;     1 if local variable 1 is greater than 0
Bytecode
Type | Description
u1 | dcmpg opcode = 0x98 (152)
See Also

lcmp, fcmpl, fcmpg, dcmpl

Notes

This instruction is identical to dcmpl except for the treatment of NaN.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - dcmpl

dcmpl

compare two doubles (-1 on NaN)

Jasmin Syntax

    dcmpl

Stack
Before | After
value1-word1 | int-result
value1-word2 | ...
value2-word1 |
value2-word2 |
... |
Description

This takes two double-precision floating point numbers off the operand stack and compares them, using IEEE 754 rules.

If the two numbers are the same, the 32-bit integer 0 is pushed onto the stack. If value2 is greater than value1, the integer 1 is pushed onto the stack. If value1 is greater than value2, -1 is pushed onto the stack. If either numbers is NaN, the integer 1 is pushed onto the stack. +0.0 and -0.0 are treated as equal.

Example

dload_1       ; push the double in local variable 1
dconst_0      ; push the double 0.0 onto the stack
dcmpl         ; compare the two numbers

; The integer result on the stack is:
;     0 if local variable 1 equals 0
;     -1 if local variable 1 is less than 0
;     1 if local variable 1 is greater than 0
Bytecode
Type | Description
u1 | dcmpl opcode = 0x97 (151)
See Also

lcmp, fcmpl, fcmpg, dcmpg

Notes

This instruction is identical to dcmpg except for the treatment of NaN.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - ddiv

ddiv

divides two doubles

Jasmin Syntax

    ddiv
Stack
Before | After
value1-word1 | result-word1
value1-word2 | result-word2
value2-word1 | ...
value2-word2 |
... |
Description

Pops the top two double-precision floating point numbers off of the stack, divides by the top number (i.e. computes value2 / value1), and pushes the double precision quotient result back onto the stack.

Division by zero will result in an infinity result. The division is computed using IEEE 754 round-to-nearest mode and gradual underflow. Standard IEEE arithmetic rules are used for the special NaN, infinity, and zero values.

Bytecode
Type | Description
u1 | ddiv opcode = 0x6F (111)
See Also

idiv, ldiv, fdiv

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - dload

dload

retrieve double from local variable

Jasmin Syntax

    dload <varnum>
or
    wide
    dload <varnum>
In the first form, <varnum> is an unsigned integer in the range 0 to 0xFF. In the second (wide) form, <varnum> is an unsigned integer in the range 0 to 0xFFFE.

Stack
Before | After
... | result-word1
 | result-word2
 | ...
Description

dload retrieves a double-precision floating point number held in local variable and pushes it onto the operand stack.

Since double-precision floats are 64-bits wide, and each local variable only holds up to 32 bits, Java uses two consecutive local variables, <varnum> and <varnum> + 1 to store a double. So dload <varnum> actually places the values of both <varnum> and <varnum> + 1 onto the operand stack.

Both <varnum> and <varnum> + 1 must be valid local variable numbers in the current frame, and together they must be holding a double.

Remember that attempting to treat two-word values as two independent single-word values will produce a verification error. So trying to retrieve <varnum> or <varnum> + 1 independently (e.g. iload <varnum>) will produce a verification error. Similarly, if you store a non-double value in <varnum>, then <varnum> + 1 becomes invalidated until a new value is stored in it.

Example

dload 2         ; push the double held in local variables 2 and 3 onto the stack
Bytecode

For local variable numbers in the range 0-255, use:
Type | Description
u1 | dload opcode = 0x18 (24)
u1 | <varnum>
There is also a wide format for this instruction, which supports access to all local variables from 0 to 65535:
Type | Description
u1 | wide opcode = 0xC4 (196)
u1 | dload opcode = 0x18 (24)
u2 | <varnum>
See Also

fload, iload, aload, lload, wide

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - dstore

dstore

store double in local variable

Jasmin Syntax

    dstore <varnum>
or
    wide
    dstore <varnum>
In the first form, <varnum> is an unsigned integer in the range 0 to 0xFF. In the second (wide) form, <varnum> is an unsigned integer in the range 0 to 0xFFFE.

Stack
Before | After
doube-word1 | ...
double-word2 |
... |
Description

dstore pops a two-word double-precision float off the operand stack and stores it in a local variable. It takes a single parameter, <varnum>, an unsigned integer indicating which local variable to use.

Since double-precision floats are 64-bits wide, and each local variable can only hold up to 32 bits, Java uses two consecutive local variables, <varnum> and <varnum> + 1 to store a double. So dstore <varnum> actually modifies the values of both <varnum> (which is set to double-word1) and <varnum> + 1 (which is set to double-word2).

Both <varnum> and <varnum> + 1 must be valid local variable numbers in the current frame.

Example

ldc2_w 10.0      ; push the double 10.0 onto the stack
dstore 3        ; pop 10.0 off of the stack and store it in local variables 3 and 4
Bytecode

For local variables in the range 0-255, use:
Type | Description
u1 | dstore opcode = 0x39 (57)
u1 | <varnum>
There is also a wide format for this instruction, which supports access to all local variables from 0 to 65535:
Type | Description
u1 | wide opcode = 0xC4 (196)
u1 | dstore opcode = 0x39 (57)
u2 | <varnum>
See Also

lstore, fstore, istore, astore, wide

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - dsub

dsub

subtract two doubles

Jasmin Syntax

    dsub
Stack
Before | After
value1-word1 | result-word1
value1-word2 | result-word2
value2-word1 | ...
value2-word2 |
... |
Description

Takes the top two double-precision floating point numbers from the stack, subtracts the top one from the second (i.e. computes value2 - value1), and pushes the double-precision result back onto the stack. Subtraction is done according to IEEE 754 rules for double precision floating point numbers.

Bytecode
Type | Description
u1 | dsub opcode = 0x67 (103)
See Also

isub, lsub, fsub

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - dup

dup

duplicate top single-word item on the stack

Jasmin Syntax

    dup
Stack
Before | After
item | item
... | item
 | ...
Description

This pops the top single-word value off the operand stack, and then pushes that value twice - i.e. it makes an extra copy of the top item on the stack.

This instruction cannot be used to duplicate two-word items (longs or doubles) - use dup2 instead.

Example

; This is like the java expression:
;
;   StringBuffer x = new StringBuffer();
;

; Make a new StringBuffer object and leave a reference to it
; on the stack:
new java/lang/StringBuffer

; [ Stack now contains: objectref ]

; Duplicate the object reference:
dup

; [ Stack now contains: objectref objectref ]

; Invoke the object's initializer:
invokespecial java/lang/StringBuffer/<init>()V

; [ Stack now contains: objectref ]

; Store the objectref in local variable 1.
astore_1

; [ Stack is now empty. ]
Bytecode
Type | Description
u1 | dup opcode = 0x59 (89)
See Also

dup2, dup_x1, dup2_x1, dup2_x2

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - dup2

dup2

duplicate top two stack words

Jasmin Syntax

    dup2
Stack
Before | After
word1 | word1
word2 | word2
... | word1
 | word2
 | ...
Description

Duplicates the top two words on the stack and pushes the duplicates onto the stack in the same order. You can use this to duplicate two single-word items (e.g. two integers, or an integer and an object reference) or one two-word item (i.e. a double or a long).

Bytecode
Type | Description
u1 | dup2 opcode = 0x5C (92)
See Also

dup, dup_x1, dup2_x1, dup2_x2

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - dup_x1

dup_x1

duplicate top stack word and insert beneath second word

Jasmin Syntax

    dup_x1
Stack
Before | After
word1 | word1
word2 | word2
... | word1
Description

Duplicates the top item on the stack and inserts the duplicate below the second-from-top item. Both items must be single-word items.

Bytecode
Type | Description
u1 | dup_x1 = 0x5A (90)
See Also

dup, dup2, dup2_x1, dup2_x2

Notes

This instruction cannot be used if either of item1 or item2 are two-word items. To duplicate a two-word item (a long or a double) you must use dup2, dup2_x1 or dup2_x2.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - dup_x2

dup_x2

duplicate top stack word and insert beneath third word

Jasmin Syntax

    dup_x2
Stack
Before | After
word1 | word1
word2 | word2
word3 | word3
... | word1
 | ...
Description

Duplicates the top single-word stack item inserts the duplicate three words down.

Example

dconst_0
bipush 100
; stack now contains:
;     0.0 | double-word1
;     0.0 | double-word2
;     100   integer

dup_x2
; stack now contains:
;     100   integer1
;     0.0 | double-word1
;     0.0 | double-word2
;     100   integer1
Bytecode
Type | Description
u1 | dup_x2 = 0x5B (91)
See Also

dup, dup2, dup_x1, dup2_x2

Notes

This instruction cannot be used if the top item on the stack is a two-word item (i.e. a long or a double-precision float). Use dup2, dup2_x1 or dup2_x2 instead.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - f2d

f2d

convert float to double

Jasmin Syntax

    f2d
Stack
Before | After
float | double-word1
... | double-word2
 | ...
Description

Pops a single precision float off of the stack, casts it to a double, and pushes the double-precision floating point number back onto the stack. This conversion is done in accordance with IEEE 754 specifications. Note that nothing is lost in this conversion. If the original value is NaN, the result will be NaN. Similarly, if the original value is an infinity, the result will be the same infinity.

Bytecode
Type | Description
u1 | f2d opcode = 0x8D (141)
See Also

f2i, f2l

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - f2i

f2i

convert float to integer

Jasmin Syntax

    f2i
Stack
Before | After
float | integer
... | ...
Description

Pops a single precision float off of the stack, casts it to a 32-bit int, and pushes the int value back onto the stack.

Rounding is done using IEEE 754 round-to-nearest mode. The fractional part is lost by rounding towards zero, so (int)-3.14 becomes -3.

If the original float value is NaN, the result is 0. If the value is too large to be represented as an integer, or if it is positive infinity, the result is the largest possible integer 0x7FFFFFFF. If the value is too small (i.e. a negative value of large magnitude, or negative infinity) then the result is the most negative integer 0x80000000.

Bytecode
Type | Description
u1 | f2i opcode = 0x8B (139)
See Also

f2l, f2d

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - f2l

f2l

convert float to long integer

Jasmin Syntax

    f2l
Stack
Before | After
float | long-word1
... | long-word2
 | ...
Description

This is used to cast a single precision float value into a 64-bit long integer value. f2l removes a float from the stack, converts it to a long integer, and pushes the two-word long integer back onto the stack.

Rounding is done using IEEE 754 round-to-nearest mode. The fractional part is lost by rounding towards zero, so (long)-3.14 becomes -3.

If the original value is NaN, the result is 0. If the value is too large to be represented as an integer, or if it is positive infinity, the result is the largest possible long integer Long.MAX_VALUE. If the value is too small (i.e. a negative value of large magnitude, or negative infinity) then the result is the most negative long integer Long.MIN_VALUE.

Bytecode
Type | Description
u1 | f2l opcode = 0x8C (140)
See Also

f2i, f2d

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - fadd

fadd

add two floats

Jasmin Syntax

    fadd
Stack
Before | After
value1 | result
value2 | ...
... |
Description

Pops two single-precision floating point numbers off the operand stack, adds them, and pushes the result back onto the stack. Floating point addition follows IEEE rules.

Bytecode
Type | Description
u1 | fadd opcode = 0x62 (98)
See Also

dadd, iadd, ladd

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - faload

faload

retrieve float from array

Jasmin Syntax

    faload
Stack
Before | After
index | value
arrayref | ...
... |
Description

Retrieves an entry from a float array and places it on the stack. arrayref is a reference to an array of single-precision floats. index is an int. The arrayref and index are removed from the stack, and the single-precision float entry at the given index in the array is pushed onto the stack.

Example

; This is like the Java code:
;     float x = arr[0];
; where x is local variable 2 and arr is a float
; array in local variable 1
aload_1       ; load local variable 1 onto the stack
iconst_0      ; push the integer 0 onto the stack
faload        ; retrieve the entry
fstore_2      ; store the entry in local variable 2
Exceptions

NullPointerException - arrayref is null

ArrayIndexOutOfBoundsException - index is < 0 or >= arrayref.length

Bytecode
Type | Description
u1 | faload opcode = 0x30 (48)
See Also

iaload, laload, daload, aaload, baload, caload, saload, iastore, lastore, fastore, dastore, aastore, bastore, castore, sastore

Notes

Array indices start at 0 (the first entry in the array is at index 0).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - fcmpg

fcmpg

single-precision float comparison (1 on NaN)

Jasmin Syntax

    fcmpg
Stack
Before | After
value1 | int-result
value2 | ...
... |
Description

This takes two single-precision floating point numbers off the stack and compares them, using IEEE 754 rules.

If the two numbers are the same, the integer 0 is pushed onto the stack. If value2 is greater than value1, the integer 1 is pushed onto the stack. If value1 is greater than value2, the integer -1 is pushed onto the stack. If either number is NaN, the integer 1 is pushed onto the stack. +0.0 and -0.0 are treated as equal.

Example

fload_1       ; push the float in local variable 1
fconst_0      ; push the float 0 onto the stack
fcmpl         ; compare the two numbers

; The integer result on the stack is:
;     0 if local variable 1 equals 0
;     -1 if local variable 1 is less than 0
;     1 if local variable 1 is greater than 0

Bytecode
Type | Description
u1 | fcmpg opcode = 0x96 (150)
See Also

lcmp, fcmpl, dcmpl, dcmpg

Notes

This instruction is identical to fcmpl except for the treatment of NaN.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - fcmpl

fcmpl

single-precision float comparison (-1 on NaN)

Jasmin Syntax

    fcmpl
Stack
Before | After
value1 | result
value2 | ...
... |
Description

This takes two single-precision floating point numbers off the stack and compares them, using IEEE 754 rules.

If the two numbers are the same, the integer 0 is pushed onto the stack. If value2 is greater than value1, the integer 1 is pushed onto the stack. If value1 is greater than value2, the integer -1 is pushed onto the stack. If either number is NaN, the integer 1 is pushed onto the stack. +0.0 and -0.0 are treated as equal.

Example

fload_1       ; push the float in local variable 1
fconst_0      ; push the float 0 onto the stack
fcmpl         ; compare the two numbers

; The integer result on the stack is:
;     0 if local variable 1 equals 0
;     -1 if local variable 1 is less than 0
;     1 if local variable 1 is greater than 0
Bytecode
Type | Description
u1 | fcmpl opcode = 0x95 (149)
See Also

lcmp, fcmpg, dcmpl, dcmpg

Notes

This instruction is identical to fcmpg except for the treatment of NaN.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - fdiv

fdiv

divide two floats

Jasmin Syntax

    fdiv
Stack
Before | After
value1 | result
value2 | ...
... |
Description

Pops two single-precision floats from the stack, divide by the top float, and push the single-precision quotient result back onto the stack (i.e. computes value2 / value1). Division is carried out using IEEE 754 rules.

Bytecode
Type | Description
u1 | fdiv opcode = 0x6E (110)
See Also

idiv, ldiv, ddiv

Notes

Divide by zero results in the value NaN to be pushed onto the stack

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - fload

fload

retrieve float from local variable

Jasmin Syntax

    fload <varnum>
or
    wide
    fload <varnum>
In the first form, <varnum> is an unsigned integer in the range 0 to 0xFF. In the second (wide) form, <varnum> is an unsigned integer in the range 0 to 0xFFFF.

Stack
Before | After
... | float-value
 | ...
Description

Pushes the float value held in a local variable onto the operand stack. The fload instruction takes a single parameter, <varnum>, an unsigned integer which indicates which local variable to retrieve. The single-word float held in that local variable is retrieved and placed on the stack. <varnum> must be a valid local variable number in the current frame.

Example

fconst_2        ; push 2.0 onto the stack
fstore 1        ; pop 2.0 off of the stack and store in local variable 1
fload 1         ; push the value from local variable 1 (the value 2.0)
                ; back onto the stack
Bytecode

For local variable numbers in the range 0-255, use:
Type | Description
u1 | fload opcode = 0x17 (23)
u1 | <varnum>
There is also a wide format for this instruction, which supports access to all local variables from 0 to 65535:
Type | Description
u1 | wide opcode = 0xC4 (196)
u1 | fload opcode = 0x17 (23)
u2 | <varnum>
See Also

iload, lload, aload, dload, wide

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - fneg

fneg

negate a float

Jasmin Syntax

    fneg
Stack
Before | After
value | value
... | ...
Description

Removes the top single-precision float from the operand stack, negates it (i.e. inverts its sign), and pushes the negated result back onto the stack.

Note that, in IEEE floating point arithmetic, negation is not quite the same as subtracting from 0. IEEE has two zeros, +0.0 and -0.0. fneg applied to +0.0 is -0.0, whereas (+0.0 minus +0.0) is +0.0.

Bytecode
Type | Description
u1 | fneg opcode = 0x76 (118)
See Also

ineg, lneg, dneg

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - frem

frem

remainder of two floats

Jasmin Syntax

    frem
Stack
Before | After
value1 | result
value2 | ...
... |
Description

Pops two single-precision numbers off the operand stack, divides by the top float, computes the remainder and pushes the single-precision result back onto the stack. This is like the C function fmod. The remainder is computed using the equation:

remainder = value2 - (intof( value2 / value1 ) * value1)

where intof () rounds towards the nearest integer, or towards the nearest even integer if the number is half way between two integers.

Bytecode
Type | Description
u1 | frem opcode = 0x72 (114)
See Also

irem, lrem, drem

Notes

1. Divide by zero will result in NaN being pushed onto the stack as the result.

2. This operation is not the same as the IEEE-defined remainder operation, which uses slightly different rules for rounding. Use the Java library routine Math.IEEEremainder if you want the IEEE behavior.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - fstore

fstore

store float in local variable

Jasmin Syntax

    fstore <varnum>
or
    wide
    fstore <varnum>
In the first form, <varnum> is an unsigned integer in the range 0 to 0xFF. In the second (wide) form, <varnum> is an unsigned integer in the range 0 to 0xFFFF.

Stack
Before | After
value | ...
... |
Description

Pops a single-precision float off the stack and stores it in local variable <varnum>. The fstore instruction takes a single parameter, <varnum>, an unsigned integer which indicates which local variable is used. <varnum> must be a valid local variable number in the current frame.

Example

fconst_2        ; push 2.0 onto the stack
fstore 3        ; pop 2.0 off of the stack and store it in local variable 3
Bytecode

For local variable numbers in the range 0-255, use:
Type | Description
u1 | fstore opcode = 0x38 (56)
u1 | <varnum>
There is also a wide format for this instruction, which supports access to all local variables from 0 to 65535:
Type | Description
u1 | wide opcode = 0xC4 (196)
u1 | fstore opcode = 0x38 (56)
u2 | <varnum>
See Also

lstore, istore, dstore, astore, wide

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - fsub

fsub

subtract two floats

Jasmin Syntax

    fsub
Stack
Before | After
value1 | result
value2 | ...
... |
Description

Pops two single-precision floating point numbers off the operand stack, subtracts the top one from the second (i.e. computes value2 - value1), and pushes the single-precision result back onto the stack. Subtraction is done according to IEEE 754 rules for single precision floating point numbers.

Bytecode
Type | Description
u1 | fsub opcode = 0x66 (102)

See Also

isub, lsub, dsub

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - goto

goto

branch to address

Jasmin Syntax

    goto <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
... | ...
Description

Causes execution to branch to the instruction at the address (pc + branchoffset), where pc is the address of the goto opcode in the bytecode and branchoffset is a 16-bit signed integer parameter that immediately follows the goto opcode in the bytecode. In Jasmin, branchoffset is computed for you using the address associated with <label>.

Example

;
; This is like the Java code:
;     while (true) { i++; }

Label:
   incr 1 1       ; Increment local variable 1 by 1
   goto Label     ; jump back to Label

Bytecode
Type | Description
u1 | goto opcode = 0xA7 (167)
s2 | branchoffset
See Also

goto_w, jsr, jsr_w

Notes

Addresses are measured in bytes from the start of the bytecode - i.e. address 0 is the first byte in the bytecode of the currently executing method. The maximum address in a method is 65535.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - goto_w

goto_w

branch to address using wide offset

Jasmin Syntax

    goto_w <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
... | ...
Description

Causes execution to branch to the instruction at the address (pc + branchoffset), where pc is the address of the goto_w opcode in the bytecode and branchoffset is a 32-bit signed integer parameter that follows the goto_w opcode in the bytecode. If you are using Jasmin, branchoffset is determined for you from the address associated with <label>.

Bytecode
Type | Description
u1 | goto_w opcode = 0xC8 (200)
s4 | branchoffset
See Also

goto, jsr, jsr_w

Notes

1. goto_w is identical to goto, except that a 32-bit signed integer branchoffset is used instead of a 16-bit branchoffset.

2. In Jasmin, goto and goto_w are synonymous, since the Jasmin assembler automatically decides which version of the instruction to use, based on the address of the<label>.

3. Addresses are measured in bytes from the start of the bytecode - i.e. address 0 is the first byte in the bytecode of the currently executing method. The maximum address in a method is 65535.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - i2b

i2b

convert integer to byte

Jasmin Syntax

    i2b
Stack
Before | After
value | result
... | ...
Description

Converts an integer to a signed byte. A 32-bit int is popped off the stack, the top 24 bits are discarded (they are set to zero), then the resulting value is signed extended to an int. The int result is pushed back onto the stack.

i2b is used in Java where there is a cast between an int and a byte. Notice that i2b can cause a change in sign. For example, in the code:

    int x = -134;
    byte b = (byte)x;
The value of b is positive 122 - the sign bit of x is lost in the conversion.

Bytecode
Type | Description
u1 | i2b opcode = 0x91 (145)
See Also

i2c, i2s

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - i2c

i2c

convert integer to character

Jasmin Syntax

    i2c
Stack
Before | After
value | result
... | ...
Description

Converts an integer to a 16-bit unsigned char. A 32-bit int is popped off the stack, the top 16 bits are set to zero and the resulting int value is pushed back onto the stack.

i2c is used in Java when there is an explicit cast between an int and a char. Notice that i2c produces an unsigned value - any sign bit for the original number is lost. For example, in the code:

    int x = -1;
    char c = (char)x;
The value of c is positive 0xFFFF.

Bytecode
Type | Description
u1 | i2c opcode = 0x92 (146)
See Also

i2b, i2s

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - i2d

i2d

convert integer to double

Jasmin Syntax

    i2d
Stack
Before | After
int | double-word1
... | double-word2
 | ...
Description

Pops an int off the operand stack, casts it into a double precision floating point number, and pushes the two-word double precision result back onto the stack. This conversion is exact, since doubles have enough precision to represent all int values.

Bytecode
Type | Description
u1 | i2d opcode = 0x87 (135)
See Also

i2f, i2l

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - i2f

i2f

convert integer to float

Jasmin Syntax

    i2f
Stack
Before | After
int | float
... | ...
Description

Pops an int off the operand stack, casts it into a single-precision float, and pushes the float back onto the stack. Notice that there is may be a loss of precision (floats have 24 bits of significand, as compared to 32 bits for an int, so the least significant bits of int are lost). However, the magnitude of the result will be preserved (the range of a float is greater than the range of an int). Rounding is done using the IEEE 754 round-to-nearest mode.

Bytecode
Type | Description
u1 | i2f opcode = 0x86 (134)
See Also

i2l, i2d

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - i2l

i2l

convert integer to long integer

Jasmin Syntax

    i2l
Stack
Before | After
int | long-word1
... | long-word2
 | ...
Description

Pops an integer off the operand stack, sign extends it into a long integer, and pushes the two-word long back onto the stack.

Bytecode
Type | Description
u1 | i2l opcode = 0x85 (133)
See Also

i2f, i2d

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - i2s

i2s

convert integer to short integer

Jasmin Syntax

    i2s
Stack
Before | After
value | result
... | ...
Description

Converts an integer to a signed short. A 32-bit int is popped off the stack, the top 16 bits are set to zero, and the resulting value is then sign extended to an int. The int result is pushed back onto the stack.

i2s is used in Java where there is an explicit case between an int and a short. Notice that i2s can cause a change in sign. For example, in the code:

    int x = -40000;
    short s = (short)x;
The value of s is positive 25536, since the sign bit of x is lost in the conversion.

Bytecode
Type | Description
u1 | i2s opcode = 0x93 (147)
See Also

i2b, i2c

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - iadd

iadd

add two integers

Jasmin Syntax

    iadd
Stack
Before | After
value1 | result
value2 | ...
... |
Description

Pops two integers from the operand stack, adds them, and pushes the integer result back onto the stack. On overflow, iadd produces a result whose low order bits are correct, but whose sign bit may be incorrect.

Example

bipush  5       ; push first int
bipush  4       ; push second int
iadd            ; add integers

                ; the top of the stack now
                ; contains the integer 9

Bytecode
Type | Description
u1 | iadd opcode = 0x60 (96)
See Also

ladd, fadd, dadd

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - iaload

iaload

retrieve integer from array

Jasmin Syntax

    iaload
Stack
Before | After
index | value
arrayref | ...
... |
Description

Retrieves an entry from a int array and places it on the stack. arrayref is a reference to an array of ints. index is an int. The arrayref and index are removed from the stack, and the int value at the given index in the array is pushed onto the stack.

Example

; get x[1], where x is an int array stored in local variable 1
aload_1          ; push an integer array onto the stack
iconst_1         ; push the integer 1 onto the stack
iaload           ; get the int at index 1 from the array

                 ; the top item on the stack is now x[1]
Exceptions

NullPointerException - arrayref is null

ArrayIndexOutOfBoundsException - index is < 0 or >= arrayref.length

Bytecode
Type | Description
u1 | iaload opcode = 0x2E (46)
See Also

laload, faload, daload, aaload, baload, caload, saload, iastore, lastore, fastore, dastore, aastore, bastore, castore, sastore

Notes

Array indices start at 0 (the first entry in the array is at index 0).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - iand

iand

integer bitwise and

Jasmin Syntax

    iand
Stack
Before | After
value1 | result
value2 | ...
... |
Description

Computes the bitwise and of value1 and value2 (which must be ints). The int result replaces value1 and value2 on the stack.

Example

; This is like the Java code:
;       int x;
;       x &= 2;
;
iload_1          ; push integer in local variable 1 onto stack
iconst_2         ; push the integer 2 onto the stack
iand             ; compute the bitwise and
istore_1         ; store the result in local variable 1
Bytecode
Type | Description
u1 | iand opcode = 0x7E (126)
See Also

ishl, ishr, iushr, lshl, lshr, lushr, land, ior, lor, ixor, lxor

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - idiv

idiv

divide an integer by another integer

Jasmin Syntax

    idiv
Stack
Before | After
value1 | result
value2 | ...
... |
Description

Pops the top two integers from the operand stack and divides the second-from top integer (value2) by the top integer (value1), i.e. computes (value2 div value1). The quotient result is truncated to the nearest integer (with rounding going towards zero, so 1.7 becomes 1) and placed on the stack.

Exceptions

ArithmeticException - attempt to divide by 0 (i.e. value1 is 0)

Bytecode
Type | Description
u1 | idiv opcode = 0x6C (108)
See Also

ldiv, fdiv, ddiv

Notes

Because of the two's-complement representation used for negative numbers, dividing Integer.MIN_VALUE by -1 produces Integer.MIN_VALUE, not Integer.MAX_VALUE as you might expect.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - ifeq

ifeq

jump if zero

Jasmin Syntax

    ifeq <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
value | ...
... |
Description

ifeq pops the top int off the operand stack. If the int equals zero, execution branches to the address (pc + branchoffset), where pc is the address of the ifeq opcode in the bytecode and branchoffset is a 16-bit signed integer parameter following the ifeq opcode in the bytecode. If the int on the stack does not equal zero, execution continues at the next instruction.

If you are using Jasmin, branchoffset is computed for you from the address of <label>.

Example

    iload_1         ; push the int value in local variable 1 onto the stack
    ifeq Label      ; if the value of local variable 1 is zero, jump to Label
    return          ; return if local variable 1 is nonzero
Label:
    ; execution continues here if local variable 1 equals zero...
Bytecode
Type | Description
u1 | ifeq opcode = 0x99 (153)
s2 | branchoffset
See Also

ifnull, iflt, ifle, ifne, ifnonnull, ifgt, ifge

Notes

Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - ifge

ifge

jump if greater than or equal to zero

Jasmin Syntax

    ifge <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
value | ...
... |
Description

ifge pops the top int off the operand stack. If the int is greater than or equal to zero, execution branches to the address (pc + branchoffset), where pc is the address of the ifge opcode in the bytecode and branchoffset is a 16-bit signed integer parameter following the ifge opcode in the bytecode. If the int on the stack is less than zero, execution continues at the next instruction.

If you are using Jasmin, branchoffset is computed for you from the address of <label>.

Example

    iload_1         ; push the int value in local variable 1 onto the stack
    ifge Label      ; if the value on the stack is >= 0, jump to Label
    return          ; return if local variable 1 is less than zero
Label:
    ; execution continues here if local variable 1 is greater than or equals zero...
Bytecode
Type | Description
u1 | ifge opcode = 0x9C (156)
s2 | branchoffset
See Also

ifnull, ifeq, iflt, ifne, ifnonnull, ifgt, ifle

Notes

Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - ineg

ineg

negate an integer

Jasmin Syntax

    ineg
Stack
Before | After
value | -value
Description

Pops an int off the stack, negates it, and pushes the negated integer value back onto the stack. This is the same as multiplying the integer by -1.

Bytecode
Type | Description
u1 | ineg opcode = 0x74 (116)
See Also

lneg, fneg, dneg

Notes

Because of the two's-complement representation used for negative numbers, negating Integer.MIN_VALUE actually produces Integer.MIN_VALUE, not Integer.MAX_VALUE as you might expect.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - ior

ior

integer bitwise or

Jasmin Syntax

    ior
Stack
Before | After
value1 | result
value2 | ...
... |
Description

Computes the bitwise or of value1 and value2 (which must be ints). The int result replaces value1 and value2 on the stack.

Example

; This is like the Java code:
;       int x;
;       x |= 2;
;
iload_1          ; load local variable 1 onto stack
iconst_2         ; push the integer 2 onto the stack
ior              ; compute the bitwise or
istore_1         ; store the result in local variable 1
Bytecode
Type | Description
u1 | ior opcode = 0x80 (128)
See Also

ishl, ishr, iushr, lshl, lshr, lushr, iand, land, lor, ixor, lxor

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - irem

irem

remainder of two integers

Jasmin Syntax

    irem
Stack
Before | After
value1 | result
value2 | ...
... |
Description

Pops two ints off the operand stack, divides value2 by value1 (i.e. value2 / value1), computes the remainder and pushes the int remainder back onto the stack. The remainder is (value2 - ((value1 / value2) * value2)). This is used by the % operator in Java.

Exceptions

ArithmeticException - the divisor (value1) is zero.

Bytecode
Type | Description
u1 | irem opcode = 0x70 (112)
See Also

lrem, frem, drem

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - ishl

ishl

integer shift left

Jasmin Syntax

    ishl
Stack
Before | After
value1 | result
value2 | ...
... |
Description

Pops two ints off the stack. Shifts value2 left by the amount indicated in the five low bits of value1. The int result is then pushed back onto the stack.

This is the same as computing the expression:

x * 2s

where s is value1 and x is value2.

Example

; This is like the Java code:
;      int x;
;      x <<= 3;
;
iload_1          ; push integer in local variable 1 onto stack
iconst_3         ; push the integer 3 onto the stack
ishl             ; shift left
istore_1         ; store the result in local variable 1
Bytecode
Type | Description
u1 | ishl opcode = 0x78 (120)
See Also

ishr, iushr, lshl, lshr, lushr, iand, land, ior, lor, ixor, lxor

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - ishr

ishr

integer arithmetic shift right

Jasmin Syntax

    ishr
Stack
Before | After
value1 | result
value2 | ...
... |
Description

Pops two ints off the stack. Shifts value1 right by the amount indicated in the five low bits of value2. The int result is then pushed back onto the stack. value1 is shifted arithmetically (preserving the sign extension).

This is the same as computing the expression:

x / 2s

where s is value1 and x is value2.

Example

; This is like the Java code:
;      int x;
;      x >>= 3;
;
iload_1          ; load local variable 1 onto stack
iconst_3         ; push the integer 3 onto the stack
ishr             ; arithmetic shift right
istore_1         ; store the result in local variable 1
Bytecode
Type | Description
u1 | ishr opcode = 0x7A (122)
See Also

ishl, iushr, lshl, lshr, lushr, iand, land, ior, lor, ixor, lxor

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - istore

istore

store integer in local variable

Jasmin Syntax

    istore <varnum>
or
    wide
    istore <varnum>
In the first form, <varnum> is an unsigned integer in the range 0 to 0xFF. In the second (wide) form, <varnum> is an unsigned integer in the range 0 to 0xFFFF.

Stack
Before | After
value | ...
... |
Description

Pops an in off the stack and stores it in local variable <varnum>. The istore instruction takes a single parameter, <varnum>, an unsigned integer which indicates which local variable should be used. <varnum> must be a valid local variable number in the current frame.

Example

bipush 10       ; push 10 onto the stack
istore 3        ; pop 10 off of the stack and store it in local variable 3
Bytecode

For local variable numbers in the range 0-255, use:
Type | Description
u1 | istore opcode = 0x36 (54)
u1 | <varnum>
There is also a wide format for this instruction, which supports access to all local variables from 0 to 65535:
Type | Description
u1 | wide opcode = 0xC4 (196)
u1 | istore opcode = 0x36 (54)
u2 | <varnum>
See Also

lstore, fstore, dstore, astore, wide

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - isub

isub

subtract two integers

Jasmin Syntax

    isub
Stack
Before | After
value1 | result
value2 | ...
... |
Description

Pops two ints off the operand stack, subtracts the top one from the second (i.e. computes value2 - value1), and pushes the int result back onto the stack.

Bytecode
Type | Description
u1 | isub opcode = 0x64 (100)
See Also

lsub, fsub, dsub

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - iushr

iushr

integer logical shift right

Jasmin Syntax

    iushr
Stack
Before | After
value1 | result
value2 | ...
... |
Description

Pops two ints off the operand stack. Shifts value1 right by the amount indicated in the five low bits of value2. The int result is then pushed back onto the stack.

value1 is shifted logically (ignoring the sign extension - useful for unsigned values).

Example

; This is like the Java code:
;      int x;
;      x >>>= 3;
;
iload_1          ; load local variable 1 onto stack
iconst_3         ; push the integer 3 onto the stack
iushr            ; logical shift right
istore_1         ; store the result in local variable 1

Bytecode
Type | Description
u1 | iushr opcode = 0x7C (124)
See Also

ishl, ishr, lshl, lshr, lushr, iand, land, ior, lor, ixor, lxor

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - ixor

ixor

integer bitwise exclusive or

Jasmin Syntax

    ixor
Stack
Before | After
value1 | result
value2 | ...
... |
Description

Pops two integers off the operand stack. Computes the bitwise exclusive or of value1 and value2. The integer result replaces value1 and value2 on the stack.

Example

; This is like the Java code:
;       int x;
;       x ^= 2;
;
iload_1          ; load local variable 1 onto stack
iconst_2         ; push the integer 2 onto the stack
ixor             ; compute the bitwise exclusive or
istore_1         ; store the result in local variable 1

Bytecode
Type | Description
u1 | ixor opcode = 0x82 (130)
See Also

ishl, ishr, iushr, lshl, lshr, lushr, iand, land, ior, lor, lxor

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - jsr

jsr

jump to subroutine

Jasmin Syntax

    jsr <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
... | return-address
 | ...
Description

This calls a local subroutine defined within the body of a method. It is used to implement Java's finally clause.

jsr first pushes the address (pc + 3) onto the operand stack, where pc is the address of this jsr instruction in the bytecode. The address (pc + 3) is the address of instruction that immediately follows the jsr instruction in bytecode - it is used used by the ret instruction to return from the subroutine.

Next, execution branches to the address (pc + branchoffset), where pc is the address of the jsr opcode in the bytecode and branchoffset is the 16-bit signed integer parameter following the jsr opcode in the bytecode. If you are using Jasmin, branchoffset is computed for you from the address of <label>.

Example

; This example method uses a PrintMe subroutine to invoke the System.out.println() method.

.method usingSubroutine()V
    ldc "Message 1"
    jsr PrintMe          ; print "Message 1"

    ldc "Message 2"
    jsr PrintMe          ; print "Message 2"

    ldc "Message 3"
    jsr PrintMe          ; print "Message 3"

    return   ; now return from usingSubroutine

; define the PrintMe subroutine ...
PrintMe:
    astore_1            ; store return-address in local variable 1
    ; call System.out.println()
    getstatic java/lang/System/out Ljava/io/PrintStream;
    invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V

    ret 1               ; return to the return-address in local variable 1
.end method
Bytecode
Type | Description
u1 | jsr opcode = 0xA8 (168)
s2 | branchoffset
See Also

jsr_w, ret, goto, goto_w

Notes

1. Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).

2. Subroutines complicate the work of the class file verifier, so extensive use of subroutines may slow down verification speeds.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - jsr_w

jsr_w

jump to subroutine using wide offset

Jasmin Syntax

    jsr_w <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
... | return-address
 | ...
Description

This calls a local subroutine defined within the body of a method. It is used to implement Java's finally clause.

jsr_w first pushes the address (pc + 5) onto the operand stack, where pc is the address of this jsr_w instruction in the bytecode. The address (pc + 5) is the address of instruction that immediately follows the jsr_w instruction in bytecode - it is used used by the ret instruction to return from the subroutine.

Next, execution branches to the address (pc + branchoffset), where pc is the address of the jsr_w opcode in the bytecode and branchoffset is the 32-bit signed integer parameter following the jsr_w opcode in the bytecode. If you are using Jasmin, branchoffset is computed for you from the address of <label>.

Bytecode
Type | Description
u1 | jsr_w opcode = 0xC9 (201)
s4 | branchoffset
See Also

jsr, ret, goto, goto_w

Notes

1. jsr_w is identical to the jsr instruction except that it uses a 32-bit wide offset instead of a 16-bit wide offset.

2. Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method). The maximum address in a method is 65535.

3. In Jasmin, jsr and jsr_w are synonymous, since the Jasmin assembler automatically decides which version of the instruction to use, based on the address of the<label>.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - l2d

l2d

convert long to double

Jasmin Syntax

    l2d
Stack
Before | After
long-word1 | double-word1
long-word2 | double-word2
... | ...
Description

Pops a long integer off of the stack, casts it into a double precision floating point number, and pushes the double back onto the stack. Notice that this can cause loss of precision (the significand in a double is 54 bits, compared to 64 bits for the long) though not loss of magnitude (since the range of a double is greater than the range of a long). Rounding is done using the IEEE 754 round-to-nearest mode.

Bytecode
Type | Description
u1 | l2d opcode = 0x8A (138)
See Also

l2i, l2f

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - l2f

l2f

convert long to float

Jasmin Syntax

    l2f
Stack
Before | After
long-word1 | float
long-word2 | ...
... |
Description

Pops a long integer off of the stack, casts it into a single precision floating point number, and pushes the single float back onto the stack. Notice that this can cause loss of precision (the significand in a float is 24 bits, compared to 64 bits for the long) though not loss of magnitude (since the range of a float is greater than the range of a long). Rounding is done using the IEEE 754 round-to-nearest mode.

Bytecode
Type | Description
u1 | l2f opcode = 0x89 (137)
See Also

l2i, l2d

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - l2i

l2i

long to integer conversion

Jasmin Syntax

    l2i
Stack
Before | After
long-word1 | integer
long-word2 | ...
... |
Description

Pops a long integer off of the stack, discards the most significant 32 bits, and pushes the low 32 bits onto the stack as an int. This may cause the magnitude or sign of the value to change.

Bytecode
Type | Description
u1 | l2i opcode = 0x88 (136)
See Also

l2f, l2d

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - ladd

ladd

add two long integers

Jasmin Syntax

    ladd
Stack
Before | After
value1-word1 | result-word1
value1-word2 | result-word2
value2-word1 | ...
value2-word2 |
... |

Description

Pops two long integers from the operand stack, adds them and then pushes the result back onto the stack. On overflow, ladd produces a result whose low order bits are correct, but whose sign bit may be incorrect.

Bytecode
Type | Description
u1 | ladd 0x61 (97)
See Also

iadd, fadd, dadd

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - laload

laload

retrieve long integer from array

Jasmin Syntax

    laload
Stack
Before | After
index | value-word1
arrayrefref | value-word2
... | ...
Description

Retrieves a long integer from a long integer array and places it on the stack. arrayref is a reference to an array of long integers. index is an int. The arrayref and index are removed from the stack, and the long integer entry at the given index in the array is pushed onto the stack.

Example

; This is like the Java code:
;     long x = arr[0];
; where x is local variable 2 and arr is an array of longs in local variable 1
aload_1       ; load local variable 1 onto the stack
iconst_0      ; push the integer 0 onto the stack
laload        ; retrieve the entry
lstore_2      ; store the entry in local variables 2 and 3
Exceptions

NullPointerException - arrayref is null

ArrayIndexOutOfBoundsException - index is < 0 or >= arrayref.length

Bytecode
Type | Description
u1 | laload opcode = 0x2F (47)
See Also

iaload, faload, daload, aaload, baload, caload, saload, iastore, lastore, fastore, dastore, aastore, bastore, castore, sastore

Notes

Array indices start at 0 (the first entry in the array is at index 0).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - land

land

long integer bitwise and

Jasmin Syntax

    land
Stack
Before | After
value1-word1 | result-word1
value1-word2 | result-word2
value2-word1 | ...
value2-word2 |
... |
Description

Pops two long integers off the stack. Computes the bitwise and of value1 and value2. The long integer result replaces value1 and value2 on the stack.

Example

; This is like the Java code:
;       long x;
;       x &= 1;
;
lload_1          ; push the long integer in local variable 1
lconst_1         ; push the integer 1 onto the stack
land             ; compute the bitwise and
lstore_1         ; store the long result in local variable 1
Bytecode
Type | Description
u1 | land opcode = 0x7F (127)
See Also

ishl, ishr, iushr, lshl, lshr, lushr, iand, ior, lor, ixor, lxor

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - lcmp

lcmp

long integer comparison

Jasmin Syntax

    lcmp
Stack
Before | After
value1-word1 | int-result
value1-word2 | ...
value2-word1 |
value2-word2 |
... |
Description

Takes two two-word long integers off the stack and compares them. If the two integers are the same, the int 0 is pushed onto the stack. If value2 is greater than value1, the int 1 is pushed onto the stack. If value1 is greater than value2, the int -1 is pushed onto the stack.

Example

; This is like the Java expression:
;     (x > 0)
; where x is a long.

lload_1       ; push the long int in local variable 1
lconst_0      ; push the long integer 0 onto the stack
lcmp          ; compare the two long integers

; The integer result on the stack is:
;     0 if local variable 1 equals 0
;     -1 if local variable 1 is less than 0
;     1 if local variable 1 is greater than 0
Bytecode
Type | Description
u1 | lcmp opcode = 0x94 (148)
See Also

fcmpl, fcmpg, dcmpl, dcmpg

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - ldc

ldc

push single-word constant onto stack

Jasmin Syntax

    ldc <value>
<value> is an int, a float, or a quoted (i.e. literal) string.

Stack
Before | After
... | <value>
 | ...
Description

ldc pushes a one-word constant onto the operand stack. ldc takes a single parameter, <value>, which is the value to push. The following Java types can be pushed using ldc:

int
float
String

Pushing a String causes a reference to a java.lang.String object to be constructed and pushed onto the operand stack. Pusing an int or a float causes a primitive value to be pushed onto the stack.

Example

ldc "Hello World"     ; push string "Hello World" onto stack
ldc 10                ; push the integer 10
ldc 1.54              ; push the single-precision float 1.54
Exceptions

OutOfMemoryError - not enough memory to allocate a reference to a String

Bytecode

In bytecode, the ldc opcode is followed by an 8-bit unsigned integer. This integer is the index of an entry in the constant pool of the current class. The entry is tagged as a CONSTANT_Integer, a CONSTANT_Float or a CONSTANT_String entry. The data field of the entry contains <value> (in the case of a CONSTANT_String, the entry identifies a CONSTANT_Utf8 entry that contains the characters of the string).
Type | Description
u1 | ldc opcode = 0x12 (18)
u1 | index
See Also

bipush, sipush, ldc_w, ldc2_w, aconst_null, iconst_m1, iconst_<n>, lconst_<l>, fconst_<f>, dconst_<d>

Notes

1. Where possible, its more efficient to use one of bipush, sipush, or one of the const instructions instead of ldc.

2. If the same string constant (i.e. a string with the same sequence of characters) appears in several different class files, only one String instance is built for that constant. The String.intern() method can be used to retrieve the instance used for a given sequence of characters.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - ldc_w

ldc_w

push single-word constant onto stack (wide index)

Jasmin Syntax

    ldc_w <value>
<value> is an int, a float, or a quoted string.

Stack
Before | After
... | <value>
 | ...
Description

ldc_w pushes a one-word constant onto the operand stack. ldc_w takes a single parameter, <value>, which is the value to push. The following Java types can be pushed using ldc_w:

int
float
String

Pushing a String causes a reference to a java.lang.String object to be constructed and pushed onto the stack. Pusing an int or a float causes a primitive value to be pushed onto the stack.

ldc_w is identical to ldc except that, in bytecode, ldc_w uses a 16-bit index rather than an 8-bit index.

Exceptions

OutOfMemoryError - not enough memory to allocate a reference to a String

Bytecode

In bytecode, the ldc_w opcode is followed by a 16-bit unsigned integer. This integer is the index of an entry in the constant pool of the current class. The entry is tagged as a CONSTANT_Integer, a CONSTANT_Float or a CONSTANT_String entry. The data field of the entry contains <value> (in the case of a CONSTANT_String, the entry identifies a CONSTANT_Utf8 entry that contains the characters of the string).
Type | Description
u1 | ldc_w opcode = 0x13 (19)
u2 | index
See Also

bipush, sipush, ldc, ldc2_w, aconst_null, iconst_m1, iconst_<n>, lconst_<l>, fconst_<f>, dconst_<d>

Notes

1. Where possible, its more efficient to use one of bipush, sipush, or one of the const instructions instead of ldc_w.

2. If the same string constant (i.e. a string with the same sequence of characters) appears in several different class files, only one String instance is built for that constant. The String.intern() method can be used to retrieve the instance used for a given sequence of characters.

3. The Jasmin assembler automatically determines whether to use ldc or ldc_w, so in Jasmin assembly files these two instructions are synonymous.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - ldiv

ldiv

divide a long integer

Jasmin Syntax

    ldiv
Stack
Before | After
value1-word1 | result-word1
value1-word2 | result-word2
value2-word1 | ...
value2-word2 |
... |
Description

Pops the top two two-word long integers from the stack and divides by the top long integer (i.e. computes value2 / value1). The result is rounded to the nearest integer, with rounding going towards 0. The long integer quotient result is pushed back onto the stack.

Exceptions

ArithmeticException - the divisor (value2) is zero.

Bytecode
Type | Description
u1 | ldiv opcode = 0x6D (109)
See Also

idiv, fdiv, ddiv

Notes

Because of the two's-complement representation used for negative numbers, dividing Long.MIN_VALUE by -1 produces Long.MIN_VALUE, not Long.MAX_VALUE as you might expect.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - lmul

lmul

multiply two longs

Jasmin Syntax

    lmul
Stack
Before | After
value1-word1 | result-word1
value1-word2 | result-word2
value2-word1 | ...
value2-word2 |
... |
Description

Pops the top two long integers from the operand stack, multiplies them, and then pushes the long integer result back onto the stack. On overflow, lmul produces a result whose low order bits are correct, but whose sign bit may be incorrect.

Bytecode
Type | Description
u1 | lmul opcode = 0x69 (105)
See Also

imul, fmul, dmul

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - lneg

lneg

negate a long

Jasmin Syntax

    lneg
Stack
Before | After
value-word1 | result-word1
value-word2 | result-word2
... | ...
Description

Removes the top long integer from the operand stack, negates it, and pushes the negated result back onto the stack. This is the same as multiplying the long integer by -1, which is the same as (~value) + 1.

Bytecode
Type | Description
u1 | lneg opcode = 0x75 (117)
See Also

ineg, fneg, dneg

Notes

Because of the two's-complement representation used for negative numbers, negating Long.MIN_VALUE actually produces Long.MIN_VALUE, not Long.MAX_VALUE as you might expect.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - lor

lor

long integer bitwise or

Jasmin Syntax

    lor
Stack
Before | After
value1-word1 | result-word1
value1-word2 | result-word2
value2-word1 | ...
value2-word2 |
... |
Description

Pops two long integers off the stack. Computes the bitwise or of value1 and value2. The long integer result replaces value1 and value2 on the stack.

Example

; This is like the Java code:
;       long x;
;       x |= 1;
;
lload_1          ; load long integer in local variable 1 onto stack
lconst_1         ; push the integer 1 onto the stack
lor              ; compute the bitwise or
lstore_1         ; store the long result in local variable 1

Bytecode
Type | Description
u1 | lor opcode = 0x81 (129)
See Also

ishl, ishr, iushr, lshl, lshr, lushr, iand, land, ior, ixor, lxor

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - lrem

lrem

modulus of two longs

Jasmin Syntax

    lrem
Stack
Before | After
value1-word1 | result-word1
value1-word2 | result-word2
value2-word1 | ...
value2-word2 |
... |
Description

Pops two long integers off the operand stack, divides value2 by value1, computes the remainder and pushes the long integer remainder back onto the stack. The remainder is (value2 - ((value1 / value2) * value2)). This is used by the % operator in Java.

Exceptions

ArithmeticException - the divisor (value1) is zero

Bytecode
Type | Description
u1 | lrem opcode = 0x71 (113)
See Also

irem, frem, drem

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - lshl

lshl

long integer shift left

Jasmin Syntax

    lshl
Stack
Before | After
value1 | result-word1
value2-word1 | result-word2
value2-word2 | ...
... |
Description

Pops a long integer and an int from the stack. Shifts value2 (the long integer) left by the amount indicated in the low six bits of value1 (an int). The long integer result is then pushed back onto the stack.

This is the same as computing the expression:

x * 2s

where s is value1 and x is value2.

Example

; This is like the Java code:
;      long x;
;      x <<= 3;
;
lload_1          ; load long integer in local variable 1 onto stack
iconst_3         ; push the integer 3 onto the stack
lshl             ; shift left
lstore_1         ; store the long result in local variable 1
Bytecode
Type | Description
u1 | lshl opcode = 0x79 (121)
See Also

ishl, ishr, iushr, lshr, lushr, iand, land, ior, lor, ixor, lxor

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - lshr

lshr

long integer arithmetic shift right

Jasmin Syntax

    lshr
Stack
Before | After
value1 | result-word1
value2-word1 | result-word2
value2-word2 | ...
... |
Description

Pops an int and a long integer from the stack. Shifts value2 (the long integer) right by the amount indicated in the low six bits of value1 (an int). The long integer result is then pushed back onto the stack. The value is shifted arithmetically (preserving the sign extension).

This is the same as computing the expression:

x / 2s

where s is value1 and x is value2.

Example

; This is like the Java code:
;      long x;
;      x >>= 3;
;
lload_1          ; load long in local variable 1 onto stack
iconst_3         ; push the integer 3 onto the stack
lshr             ; arithmetic shift right
lstore_1         ; store the long result in local variable 1

Bytecode
Type | Description
u1 | lshr opcode = 0x7B (123)
See Also

ishl, ishr, iushr, lshl, lushr, iand, land, ior, lor, ixor, lxor

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - lstore

lstore

store long integer in local variable

Jasmin Syntax

    lstore <varnum>
or
    wide
    lstore <varnum>
In the first form, <varnum> is an unsigned integer in the range 0 to 0xFF. In the second (wide) form, <varnum> is an unsigned integer in the range 0 to 0xFFFE.

Stack
Before | After
long-word1 | ...
long-word2 |
... |
Description

lstore pops a two-word long integer off the operand stack and stores it in a local variable. It takes a single parameter, <varnum>, an unsigned integer indicating which local variable to use.

Since long integers are 64-bits wide, and each local variable can only hold up to 32 bits Java uses two consecutive local variables, <varnum> and <varnum> + 1 to store a long. So lstore <varnum> actually modifies the values of both <varnum> (which is set to long-word1) and <varnum> + 1 (which is set to long-word2).

Both <varnum> and <varnum> + 1 must be valid local variable numbers in the current frame, and together they must be holding a long.

Remember that attempting to treat two-word values as two independent single-word values will produce a verification error. So trying to retrieve <varnum> or <varnum> + 1 independently (e.g. iload <varnum>) will produce a verification error. Similarly, if you store a value other than a long in <varnum>, then <varnum> + 1 becomes invalidated until a new value is stored in it.

Example

ldc2_w 10       ; push the long integer 10 onto the stack
lstore 3        ; pop 10 off of the stack and store it in local variables 3 and 4
Bytecode

For local variable numbers in the range 0-255, use:
Type | Description
u1 | lstore opcode = 0x37 (55)
u1 | <varnum>
There is also a wide format for this instruction, which supports access to all local variables from 0 to 65535:
Type | Description
u1 | wide opcode = 0xC4 (196)
u1 | lstore opcode = 0x37 (55)
u2 | <varnum>
See Also

istore, fstore, dstore, astore, wide

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - lsub

lsub

subtract two longs

Jasmin Syntax

    lsub
Stack
Before | After
value1-word1 | result-word1
value1-word2 | result-word2
value2-word1 | ...
value2-word2 |
... |
Description

Pops two long integers from the stack, subtracts the top one from the second (i.e. computes value2 - value1), and pushes the result back onto the stack.

Bytecode
Type | Description
u1 | lsub opcode = 0x65 (101)
See Also

isub, fsub, dsub

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - lushr

lushr

long integer logical shift right

Jasmin Syntax

    lushr
Stack
Before | After
value1 | result-word1
value2-word1 | result-word2
value2-word2 | ...
... |
Description

Pops an integer and a long integer and from the stack. Shifts value2 (the long integer) right by the amount indicated in the low six bits of value1 (an int). The long integer result is then pushed back onto the stack. The value is shifted logically (ignoring the sign extension - useful for unsigned values).

Example

; This is like the Java code:
;      long x;
;      x >>>= 3;
;
lload_1          ; load long in local variable 1 onto stack
iconst_3         ; push the integer 3 onto the stack
lushr            ; logical shift right
lstore_1         ; store the long result in local variable 1

Bytecode
Type | Description
u1 | lushr opcode = 0x7D (125)
See Also

ishl, ishr, iushr, lshl, lshr, iand, land, ior, lor, ixor, lxor

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - lxor

lxor

long integer bitwise exclusive or

Jasmin Syntax

    lxor
Stack
Before | After
value1-word1 | result-word1
value1-word2 | result-word2
value2-word1 | ...
value2-word2 |
... |
Description

Pops two long integers off the stack. Computes the bitwise exclusive or of value1 and value2. The long integer result replaces value1 and value2 on the stack.

Example

; This is like the Java code:
;       long x;
;       x ^= 1;
;
lload_1          ; load long in local variable 1 onto stack
lconst_1         ; push the integer 1 onto the stack
lxor             ; compute the bitwise exclusive or
lstore_1         ; store the long result in local variable 1

Bytecode
Type | Description
u1 | lxor opcode = 0x83 (131)
See Also

ishl, ishr, iushr, lshl, lshr, lushr, iand, land, ior, lor, ixor

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - pop

pop

discard top word on stack

Jasmin Syntax

    pop
Stack
Before | After
item | ...
... |
Description

Pops the top single-word item off the stack and discards it.

Example

invokevirtual Myclass/test()Z  ; call boolean Myclass.test();
pop                            ; discard the boolean result

Bytecode
Type | Description
u1 | pop opcode = 0x57 (87)
See Also

pop2

Notes

1. Use pop2 to remove long integers and doubles from the stack (using pop when the top item on the stack is a long integer or double will cause a verification error).

2. Note there is no matching "push" instruction. Use bipush, sipush, one of the

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - aaload

aaload

retrieve object reference from array

Jasmin Syntax

    aaload
Stack
Before | After
index | value
arrayref | ...
... |
Description

Retrieves an object reference from an array of objects and places it on the stack. arrayref is a reference to an array of objects. index is an int. The arrayref and index are removed from the stack, and the object reference at the given index in the array is pushed onto the stack.

Example

; This is like the Java code:
;     Object x = arr[0];
; where x is local variable 2 and arr is an array of objects in local variable 1

aload_1       ; load local variable 1 onto the stack
iconst_0      ; push the integer 0 onto the stack
aaload        ; retrieve the entry
astore_2      ; store the entry in local variable 2
Exceptions

NullPointerException - arrayref is null

ArrayIndexOutOfBoundsException - index is < 0 or >= arrayref.length

Bytecode
Type | Description
u1 | aaload opcode = 0x32 (50)
See Also

iaload, faload, daload, laload, baload, caload, saload, iastore, lastore, fastore, dastore, aastore, bastore, castore, sastore

Notes

Array indices start at 0 (the first entry in the array is at index 0).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - aastore

aastore

store object reference in array

Jasmin Syntax

    aastore
Stack
Before | After
value | ...
index |
arrayref |
... |
Description

This stores an object reference it in an array of objects. arrayref is a reference to an array of object references. index is an int. value is the object reference to be stored in the array. arrayref, index and value are removed from the stack, and value is stored in the array at the given index.

The runtime type of value must be assignment-compatible with the type of the array. For example, if the array is declared as an array of Threads, then value must either be null or an instance of Thread or one of its subclasses. An ArrayStoreException is generated if you attempt to store an incompatible type of object in an array. Assignment compatibility is described in more detail in Chapter 7.

Exceptions

ArrayIndexOutOfBoundsException - index is < 0 or >= arrayref.length

ArrayStoreException - value is not compatible with the type of the array

NullPointerException - arrayref is null

Bytecode
Type | Description
u1 | aastore opcode = 0x53 (83)
See Also

iastore, lastore, fastore, dastore, bastore, castore, sastore, iaload, laload, faload, daload, aaload, baload, caload, saload

Notes

Array indices start at 0 (the first entry in the array is at index 0).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - aconst_null

aconst_null

push null

Jasmin Syntax

    aconst_null
Stack
Before | After
... | null
 | ...
Description

Pushes the special null object reference onto the stack. null is a reference to no object, and has no type (null can be cast to any reference type). null conventionally represents an invalid or uncreated object. Fields, variables and the elements of object reference arrays have null as their initial value.

Bytecode
Type | Description
u1 | aconst_null opcode = 0x01 (1)
See Also

bipush, sipush, ldc, ldc_w, ldc2_w, iconst_m1, iconst_<n>, lconst_<l>, fconst_<f>, dconst_<d>

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - aload

aload

retrieve object reference from local variable

Jasmin Syntax

    aload <varnum>
or
    wide
    aload <varnum>
In the first form, <varnum> is an unsigned integer in the range 0 to 0xFF. In the second (wide) form, <varnum> is an unsigned integer in the range 0 to 0xFFFF.

Stack
Before | After
... | objectref
 | ...
Description

Retrieves an object reference from a local variable and pushes it onto the operand stack. The aload instruction takes a single parameter, <varnum>, an unsigned integer which indicates which local variable to retrieve. The object reference in that local variable is retrieved and placed on the stack. <varnum> must be a valid local variable number in the current frame.

Example

aload 1         ; push object reference in local variable 1 onto the stack
Bytecode

To access to local variables in the range 0-255, use:
Type | Description
u1 | aload opcode = 0x19 (25)
u1 | <varnum>
There is also a wide format for this instruction, which supports access to all local variables from 0 to 65535:
Type | Description
u1 | wide opcode = 0xC4 (196)
u1 | aload opcode = 0x19 (25)
u2 | <varnum>
See Also

fload, iload, lload, dload, wide

Notes

If you use astore to store a returnAddress in a local variable, you cannot then use aload to retrieve the value of that local variable. Instead, if a local variable holds a returnAddress, your only choices are to (1) use ret to return to that address, or (2) use one of the store instructions to store some other value in the local variable.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - aload_<n>

aload_<n>

retrieve object reference from local variable <n>

Jasmin Syntax

    aload_0
or
    aload_1
or
    aload_2
or
    aload_3
Stack
Before | After
... | objectref
 | ...
Description

aload_<n> represents the series of opcodes aload_0, aload_1, aload_2, and aload_3 that retrieve an object reference held in local variables 0, 1, 2 or 3 and push it onto the stack. <n> must be a valid local variable number in the current frame.

'aload_<n>' is functionally equivalent to 'aload <n>', although it is typically more efficient and also takes fewer bytes in the bytecode.

Example

aload_0         ;push object in local variable 0
aload_1         ;push object in local variable 1
aload_2         ;push object in local variable 2
aload_3         ;push object in local variable 3
Bytecode
Type | Description
u1 | aload_0 opcode = 0x2A (42)
u1 | aload_1 opcode = 0x2B (43)
u1 | aload_2 opcode = 0x2C (44)
u1 | aload_3 opcode = 0x2D (45)
See Also

fload, iload, lload, dload

Notes

If you use astore to store a returnAddress in a local variable, you cannot then use aload_<n> to retrieve the value of that local variable. Instead, if a local variable holds a returnAddress, your only choices are to (1) use ret to return to that address, or (2) use one of the store instructions to store some other value in the local variable.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - anewarray

anewarray

allocate new array for objects

Jasmin Syntax

   anewarray <type>
<type> is either the name of a class or interface, e.g. java/lang/String, or, to create the first dimension of a multidimensional array, <type> can be an array type descriptor, e.g. [Ljava/lang/String;

Stack
Before | After
size | arrayref
... | ...
Description

anewarray allocates a new array for holding object references. It pops an int, size, off the stack and constructs a new array capable of holding size object references of the type indicated by <type>.

<type> indicates what types of object references are to be stored in the array (see aastore). It is the name of a class or an interface, or an array type descriptor. If it is java/lang/Object, for example, then any type of object reference can be stored in the array. <type> is resolved at runtime to a Java class, interface or array. See Chapter 7 for a discussion of how classes are resolved.

A reference to the new array is pushed onto the stack. Entries in the new array are initially set to null.

Example

; Allocate a 10-element array of for holding references to
; Threads. This is like the Java code:
;      Thread x[] = new Thread[10];

bipush 10
anewarray java/lang/Thread
astore_1    ; store the new array in local variable 1

; Allocate a multi-dimensional array like:
;       new String[2][5]

; using anewarray. First, allocate new 2-element array for holding
; arrays of strings and store it in local variable 1.
iconst_2
anewarray [Ljava/lang/String;      ; type descriptor for array-of-String
astore_1

; next, allocate first array of String[5] and store it in index 0
aload_1
iconst_0
bipush 5
anewarray java/lang/String
aastore

; finally, allocate second array of String[5] and store it in index 1
aload_1
iconst_1
bipush 5
anewarray java/lang/String
aastore
Exceptions

NegativeArraySizeException - size is less than zero

Bytecode

In bytecode, immediately after the anewarray opcode there is a 16-bit unsigned integer index. This is the index of an entry in the constant pool that is tagged a CONSTANT_Class entry. The name field of this entry is given by <type> parameter in Jasmin.
Type | Description
u1 | anewarray opcode = 0xBD (189)
u2 | index
See Also

newarray, multianewarray, new

Notes

It is more efficient to use multianewarray to allocate multi-dimensional arrays.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - athrow

athrow

throw an exception

Jasmin Syntax

    athrow
Stack
Before | After
objectref | n/a
... |
Description

Removes objectref (a reference to an object) from the operand stack, and 'throws' the exception represented by that object. objectref is an instance of Throwable or one of its subclasses.

To throw an exception, the system searches for a handler for objectref's class in the exception table of the currently active method.

If no handler is found, the current method's frame is discarded, its invoker's frame is reinstated, and the exception is immediately rethrown. This process is repeated until a handler is found or until there are no more procedures on the callstack (at which point, the current thread dies, typically printing out an error message).

If a handler is found, the operand stack of the active method is cleared, objectref is pushed on the operand stack of the current method, and execution continues at the first instruction of the handler.

See Chapter 10 for a full description of exceptions in the JVM.

Example

; Throw an IOException. This is equivalent to the Java code:
;
;   throw new java.io.IOException();
;
new java/io/IOException          ; 1) create and initialize an IOException instance
dup
invokespecial java/io/IOException/<init>()V
athrow                           ; 2) throw the IOException instance on the stack
Exceptions

NullPointerException - the objectref on the stack is null.

Bytecode
Type | Description
u1 | athrow opcode = 0xBF (191)

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - caload

caload

retrieve character from array

Jasmin Syntax

    caload

Stack
Before | After
index | value
arrayref | ...
... | ...
Description

Retrieves a character from an array of characters and pushes it on the operand stack. arrayref is a reference to an array of chars. index is an int. The arrayref and index are removed from the stack, and the 16-bit unsigned Unicode character at the given index in the array is retrieved, zero extended to a 32-bit int, and pushed onto the stack.

Example

; This is like the Java code:
;     char x = arr[0];
; where x is local variable 2 and arr is a
; char array in local variable 1
aload_1       ; load local variable 1 onto the stack
iconst_0      ; push the integer 0 onto the stack
caload        ; retrieve the entry
istore_2      ; store the entry in local variable 2
Exceptions

NullPointerException - arrayref is null

ArrayIndexOutOfBoundsException - index is < 0 or >= arrayref.length

Bytecode
Type | Description
u1 | caload opcode = 0x34 (52)
See Also

iaload, laload, faload, daload, aaload, baload, saload, iastore, lastore, fastore, dastore, aastore, bastore, castore, sastore

Notes

Array indices start at 0 (the first entry in the array is at index 0).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - Inhaltsverzeichnis

  • Java Virtual Machine - Online Instruction Reference
    • example
    • aaload
    • aastore
    • aconst_null
    • aload
    • aload_<n>
    • anewarray
    • areturn
    • arraylength
    • astore
    • astore_<n>
    • athrow
    • baload
    • bastore
    • bipush
    • breakpoint
    • caload
    • castore
    • checkcast
    • d2f
    • d2i
    • d2l
    • dadd
    • daload
    • dastore
    • dcmpg
    • dcmpl
    • dconst_<d>
    • ddiv
    • dload
    • dload_<n>
    • dmul
    • dneg
    • drem
    • dreturn
    • dstore
    • dstore_<n>
    • dsub
    • dup
    • dup2
    • dup2_x1
    • dup2_x2
    • dup_x1
    • dup_x2
    • f2d
    • f2i
    • f2l
    • fadd
    • faload
    • fastore
    • fcmpg
    • fcmpl
    • fconst_<f>
    • fdiv
    • fload
    • fload_<n>
    • fmul
    • fneg
    • frem
    • freturn
    • fstore
    • fstore_<n>
    • fsub
    • getfield
    • getstatic
    • goto
    • goto_w
    • i2b
    • i2c
    • i2d
    • i2f
    • i2l
    • i2s
    • iadd
    • iaload
    • iand
    • iastore
    • iconst_<n>
    • iconst_m1
    • idiv
    • if_acmpeq
    • if_acmpne
    • if_icmpeq
    • if_icmpge
    • if_icmpgt
    • if_icmple
    • if_icmplt
    • if_icmpne
    • ifeq
    • ifge
    • ifgt
    • ifle
    • iflt
    • ifne
    • ifnonnull
    • ifnull
    • iinc
    • iload
    • iload_<n>
    • impdep1
    • impdep2
    • imul
    • ineg
    • instanceof
    • invokeinterface
    • invokespecial
    • invokestatic
    • invokevirtual
    • ior
    • irem
    • ireturn
    • ishl
    • ishr
    • istore
    • istore_<n>
    • isub
    • iushr
    • ixor
    • jsr
    • jsr_w
    • l2d
    • l2f
    • l2i
    • ladd
    • laload
    • land
    • lastore
    • lcmp
    • lconst_<l>
    • ldc
    • ldc_w
    • ldc2_w
    • ldiv
    • lload
    • lload_<n>
    • lmul
    • lneg
    • lookupswitch
    • lor
    • lrem
    • lreturn
    • lshl
    • lshr
    • lstore
    • lstore_<n>
    • lsub
    • lushr
    • lxor
    • monitorenter
    • monitorexit
    • multianewarray
    • new
    • newarray
    • nop
    • pop
    • pop2
    • putfield
    • putstatic
    • ret
    • return
    • saload
    • sastore
    • sipush
    • swap
    • tableswitch
    • wide
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - dmul

dmul

multiply two doubles

Jasmin Syntax

    dmul
Stack
Before | After
value1-word1 | result-word1
value1-word2 | result-word1
value1-word1 | ...
value2-word2 |
... |
Description

Pops the top two double-precision floating point numbers off the stack, multiplies them, and pushes the double-precision result back onto the stack. Multiplication is performed using the standard IEEE rules for double precision floating point arithmetic.

Bytecode
Type | Description
u1 | dmul opcode = 0x6B (107)
See Also

imul, lmul, fmul

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - dneg

dneg

negate a double

Jasmin Syntax

    dneg
Stack
Before | After
value-word1 | result-word1
value-word2 | result-word2
... | ...
Description

Removes the top double-precision float from the operand stack, negates it (i.e. inverts its sign), and pushes the negated result back onto the stack.

Note that, in IEEE double precision floating point arithmetic, negation is not quite the same as subtracting from 0. IEEE has two zeros, +0.0 and -0.0, and dneg applied to +0.0 is -0.0, whereas (+0.0 minus +0.0) is +0.0.

Bytecode
Type | Description
u1 | dneg opcode = 0x77 (119)
See Also

ineg, fneg, lneg

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - drem

drem

remainder of two doubles

Jasmin Syntax

    drem
Stack
Before | After
value1-word1 | result-word1
value1-word2 | result-word2
value2-word1 | ...
value2-word2 |
... |
Description

Pops two double-precision numbers off the operand stack, divides by the top double, computes the remainder and pushes the double-precision result back onto the stack. This is like the C function fmod. The remainder is computed using the equation:

remainder = value2 - (intof( value2 / value1 ) * value1)

where intof () rounds towards the nearest integer, or towards the nearest even integer if the number is half way between two integers.

Bytecode
Type | Description
u1 | drem opcode = 0x73 (115)
See Also

irem, frem, lrem

Notes

1. Divide by zero will result in NaN being pushed onto the stack as the result.

2. This operation is not the same as the IEEE-defined remainder operation, which uses slightly different rules for rounding. Use the Java library routine Math.IEEEremainder if you want the IEEE behavior.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - dreturn

dreturn

return from method with double result

Jasmin Syntax

    dreturn

Stack
Before | After
return-value-word1 | n/a
return-value-word2 |
... |
Description

dreturn pops the two-word double off the stack and pushes it onto the operand stack of the invoker (i.e. the method which used invokevirtual, invokespecial, invokestatic or invokeinterface to call the currently executing method). All other items on the current method's operand stack are discarded. If the current method is marked as synchronized, then an implicit monitorexit instruction is executed. Then the current method's frame is discarded, the invoker's frame is reinstated, and control returns to the invoker. This instruction can only be used in methods whose return type is double.

Bytecode
Type | Description
u1 | dreturn opcode = 0xAF (175)
See Also

areturn, lreturn, freturn, ireturn, return, invokevirtual, invokespecial, invokestatic, invokeinterface

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - example

example

an example of an instruction entry

Jasmin Syntax

    example <param1> <param2> ...
Stack
Before | After
item1 | item2
item2 | item1
... | ...
Description

This page explains the format for instruction reference pages.

The first line on a reference page lists the name of an instruction and gives a brief synopsis of the instruction.

The 'Jasmin Syntax' section indicates the Jasmin assembler syntax for the instruction. In the example above, the instruction is shown with two parameters, one called <param1> and the other called <param2>. The 'Jasmin Syntax' also includes additional notes for Jasmin users.

The 'Stack' section describes the effect that the instruction has on the operand stack. It shows a symbolic representation of the stack state before and after the execution of the instruction. Each row in the tables represents a one-word entry on the stack. The first row represents the top of the stack. In the example above, its clear that the order of the top two words on the stack is reversed by the instruction.

The section you are reading is the 'Description' section, which gives details of how the instruction works and what its side effects are.

Example

; This section often contains examples illustrating how
; an instruction is used.

; Examples are written using the Jasmin assembler syntax.
Exceptions

This section lists any exceptions generated by the instruction at runtime, and explains what causes each exception.

Bytecode

The 'Bytecode' section gives details on how the instruction is laid out in the bytecode of a class file. It shows a table listing the opcode for the instruction, as well as any additional parameters that follow the opcode in bytecode.
Type | Description
u1 | This line usually shows the opcode for the instruction
u1 | A 'u1' field is an unsigned 1-byte integer field
u2 | A 'u2' field is an unsigned 2-byte integer field
u4 | A 'u4' field is an unsigned 4-byte integer field
s1 | A 's1' field is a signed 1-byte integer field
s2 | A 's2' field is a signed 2-byte short integer field
s4 | A 's4' field is a signed 4-byte integer field
See Also

The 'See Also' section lists related instructions that you should look at.

Notes

The 'Notes' section gives additional details that you should be aware of.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - fload_<n>

fload_<n>

retrieve float from local variable <n>

Jasmin Syntax

    fload_0
or
    fload_1
or
    fload_2
or
    fload_3
Stack
Before | After
... | float-value
 | ...
Description

fload_<n> represents the series of opcodes fload_0, fload_1, fload_2, and fload_3 that retrieve a single precision float in local variables 0, 1, 2 or 3 and push it onto the stack. <n> must be a valid local variable number in the current frame.

'fload_<n>' is functionally equivalent to 'fload <n>', although it is typically more efficient and also takes fewer bytes in the bytecode.

Example

fload_0         ;push float in local variable 0
fload_1         ;push float in local variable 1
fload_2         ;push float in local variable 2
fload_3         ;push float in local variable 3
Bytecode
Type | Description
u1 | fload_0 opcode = 0x22 (34)
u1 | fload_1 opcode = 0x23 (35)
u1 | fload_2 opcode = 0x24 (36)
u1 | fload_3 opcode = 0x25 (37)
See Also

aload, iload, lload, dload, fload

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - fmul

fmul

multiply two floats

Jasmin Syntax

    fmul
Stack
Before | After
value1 | result
value2 | ...
... |
Description

Pops two single-precision floating point numbers off of the stack, multiplies them, and pushes the single precision result back onto the stack. IEEE 754 rules for floating point arithmetic are used.

Bytecode
Type | Description
u1 | fmul opcode = 0x6A (106)
See Also

imul, lmul, dmul

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - ifgt

ifgt

jump if greater than zero

Jasmin Syntax

    ifgt <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
value | ...
... |
Description

ifgt pops the top int off the operand stack. If the int is greater than zero, execution branches to the address (pc + branchoffset), where pc is the address of the ifgt opcode in the bytecode and branchoffset is a 16-bit signed integer parameter following the ifgt opcode in the bytecode. If the int on the stack does is less than or equal to zero, execution continues at the next instruction.

If you are using Jasmin, branchoffset is computed for you from the address of <label>.

Example

    iload_1         ; push the int value in local variable 1 onto the stack
    ifgt Label      ; if the value on the stack is greater than zero, jump to Label
    return          ; return if local variable 1 is less than or equal to zero
Label:
    ; execution continues here if local variable 1 is greater than zero...
Bytecode
Type | Description
u1 | ifgt opcode = 0x9D (157)
s2 | branchoffset
See Also

ifnull, ifeq, ifle, ifne, ifnonnull, iflt, ifge

Notes

Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - ifle

ifle

jump if less than or equal to zero

Jasmin Syntax

    ifle <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
value | ...
... |
Description

ifle pops the top int off the operand stack. If the int is less than or equal to zero, execution branches to the address (pc + branchoffset), where pc is the address of the ifle opcode in the bytecode and branchoffset is a 16-bit signed integer parameter following the ifle opcode in the bytecode. If the int on the stack is greater than zero, execution continues at the next instruction.

If you are using Jasmin, branchoffset is computed for you from the address of <label>.

Example

    iload_1         ; push the int value in local variable 1 onto the stack
    ifle Label      ; if the value on the stack is <= zero, jump to Label
    return          ; return if local variable 1 is greater than zero
Label:
    ; execution continues here if local variable 1 is less than or equal to zero...
Bytecode
Type | Description
u1 | ifle opcode = 0x9E (158)
s2 | branchoffset
See Also

ifnull, ifeq, iflt, ifne, ifnonnull, ifgt, ifge

Notes

Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - iflt

iflt

jump if less than zero

Jasmin Syntax

    iflt <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
value | ...
... |
Description

iflt pops the top int off the operand stack. If the int is less than zero, execution branches to the address (pc + branchoffset), where pc is the address of the iflt opcode in the bytecode and branchoffset is a 16-bit signed integer parameter following the ifeq opcode in the bytecode. If the int on the stack is greater than or equal to zero, execution continues at the next instruction.

If you are using Jasmin, branchoffset is computed for you from the address of <label>.

Example

    iload_1         ; push the int value in local variable 1 onto the stack
    iflt Label      ; if the value on the stack is below zero, jump to Label
    return          ; return if local variable 1 is greater than or equal to zero
Label:
    ; execution continues here if local variable 1 is less than zero...
Bytecode
Type | Description
u1 | iflt opcode = 0x9B (155)
s2 | branchoffset
See Also

ifnull, ifeq, ifle, ifne, ifnonnull, ifgt, ifge

Notes

Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - ifne

ifne

jump if nonzero

Jasmin Syntax

    ifne <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
value | ...
... |
Description

ifne pops the top int off the operand stack. If the int does not equal zero, execution branches to the address (pc + branchoffset), where pc is the address of the ifne opcode in the bytecode and branchoffset is a 16-bit signed integer parameter following the ifne opcode in the bytecode. If the int on the stack equals zero, execution continues at the next instruction.

If you are using Jasmin, branchoffset is computed for you from the address of <label>.

Example

    iload_1         ; push the int value in local variable 1 onto the stack
    ifne Label      ; if the value on the stack is nonzero, jump to Label
    return          ; return if local variable 1 is zero
Label:
    ; execution continues here if local variable 1 does not equal zero...
Bytecode
Type | Description
u1 | ifne opcode = 0x9A (154)
s2 | branchoffset
See Also

ifnull, ifeq, ifle, iflt, ifnonnull, ifgt, ifge

Notes

Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - ifnonnull

ifnonnull

jump if non-null

Jasmin Syntax

    ifnonnull <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
objectref | ...
... |
Description

ifnonnull pops the top object reference off the operand stack. If the object reference is not the special null reference, execution branches to the address (pc + branchoffset), where pc is the address of the ifnonnull opcode in the bytecode and branchoffset is a 16-bit signed integer parameter following the ifnonnull opcode in the bytecode. If the object reference on the stack is null, execution continues at the next instruction.

If you are using Jasmin, branchoffset is computed for you from the address of <label>.

Example

    aload_1         ; push the object reference in local variable 1 onto the stack
    ifnonnull Label ; if local variable isn't null, jump to Label
    return          ; return if local variable 1 is null
Label:
    ; execution continues here if local variable 1 is something other than null ...
Bytecode
Type | Description
u1 | ifnonnull opcode = 0xC7 (199)
s2 | branchoffset
See Also

ifnull, ifeq, ifle, iflt, ifne, ifgt, ifge

Notes

Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - ifnull

ifnull

jump if null

Jasmin Syntax

    ifnull <label>
<label> is a label name. To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
objectref | ...
... |
Description

ifnull pops the top object reference off the operand stack. If the object reference is to the special object null, execution branches to the address (pc + branchoffset), where pc is the address of the ifnull opcode in the bytecode and branchoffset is a 16-bit signed integer parameter following the ifnull opcode in the bytecode. If the object reference on the stack is not null, execution continues at the next instruction.

If you are using Jasmin, branchoffset is computed for you from the address of <label>.

Example

    aload_1         ; push the object reference in local variable 1 onto the stack
    ifnull Label    ; if local variable 1 is null, jump to Label
    return          ; return if local variable 1 isn't null
Label:
    ; execution continues here if local variable 1 is null...
Bytecode
Type | Description
u1 | ifnull opcode = 0xC6 (198)
s2 | branch-offset
See Also

ifeq, iflt, ifle, ifne, ifnonnull, ifgt, ifge

Notes

Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - iinc

iinc

increment integer in local variable

Jasmin Syntax

    iinc <varnum> <n>
or
    wide
    iinc <varnum> <n>
In the first form, <varnum> is an unsigned integer in the range 0 to 0xFF and <n> is a signed integer in the range -128 to 127. In the second (wide) form, <varnum> is an unsigned integer in the range 0 to 0xFFFF and <n> is a signed integer in the range -32768 to <= 32767.

Stack
Before | After
... | ...
Description

iinc increments the int held in the local variable <varnum> by <n>. The iinc instruction takes two parameters: <varnum> is an unsigned integer which indicates which local variable should be used. <n> is the integer amount to increment or decrement the variable by. <varnum> must be a valid local variable number in the current method's frame.

Example

iinc 1 10       ; increment local variable 1 by 10.
iinc 1 -1       ; decrement local variable 1 by 1.
Bytecode

For local variable numbers in the range 0-255, and values of <n> in the range -128 to 127, use:
Type | Description
u1 | iinc opcode = 0x84 (132)
u1 | <varnum>
s1 | <n>
There is also a wide format for this instruction, which supports access to all local variables from 0 to 65535, and values of <n> between -32768 and 32767:
Type | Description
u1 | wide opcode = 0xC4 (196)
u1 | iinc opcode = 0x84 (132)
u2 | <varnum>
s2 | <n>
See Also

wide

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - iload

iload

retrieve integer from local variable

Jasmin Syntax

    iload <varnum>
or
    wide
    iload <varnum>
In the first form, <varnum> is an unsigned integer in the range 0 to 0xFF. In the second (wide) form, <varnum> is an unsigned integer in the range 0 to 0xFFFE.

Stack
Before | After
... | int-value
 | ...
Description

Pushes the int value held in a local variable onto the operand stack. The iload instruction takes a single parameter, <varnum>, an unsigned integer which indicates which local variable to use. The single-word int value held in that local variable is retrieved and placed on the stack. <varnum> must be a valid local variable number in the current method's frame.

Example

bipush 5        ; push 5 onto the stack
istore 1        ; pop 5 off of the stack and store in local variable 1
iload 1         ; push the int in local variable 1 (the value 5)
                ; back onto the stack
Bytecode

For local variable numbers in the range 0-255, use:
Type | Description
u1 | iload opcode = 0x15 (21)
u1 | <varnum>
There is also a wide format for this instruction, which supports access to all local variables from 0 to 65535:
Type | Description
u1 | wide opcode = 0xC4 (196)
u1 | iload opcode = 0x15 (21)
u2 | <varnum>
See Also

aload, fload, lload, dload, astore, fstore, lstore, dstore, istore

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - iload_<n>

iload_<n>

push integer from local variable <n>

Jasmin Syntax

    iload_0
or
    iload_1
ir
    iload_2
or
    iload_3
Stack
Before | After
... | int-value
 | ...
Description

iload_<n> represents the series of opcodes iload_0, iload_1, iload_2, and iload_3 that retrieve a single precision float in local variables 0, 1, 2 or 3 and push it onto the stack. <n> must be a valid local variable number in the current frame.

'iload_<n>' is functionally equivalent to 'iload <n>', although it is typically more efficient and also takes fewer bytes in the bytecode.

Example

iload_0         ;push integer in local variable 0 onto the stack
iload_1         ;push integer in local variable 1 onto the stack
iload_2         ;push integer in local variable 2 onto the stack
iload_3         ;push integer in local variable 3 onto the stack
Bytecode
Type | Description
u1 | iload_0 opcode = 0x1A (26)
u1 | iload_1 opcode = 0x1B (27)
u1 | iload_2 opcode = 0x1C (28)
u1 | iload_3 opcode = 0x1D (29)
See Also

iload, fload, lload, dload

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - impdep1

impdep1

reserved opcode

Jasmin Syntax

    n/a
Stack
Before | After
... | ...
Description

This opcode, like impdep2 and breakpoint, is reserved for internal use by Java implementations, and must not appear in any class file - methods containing this opcode will fail verification.

Bytecode
Type | Description
u1 | imped1 opcode = 0xFE (254)
See Also

impdep2, breakpoint

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - impdep2

impdep2

reserved opcode

Jasmin Syntax

    n/a
Stack
Before | After
... | ...
Description

This opcode, like impdep1 and breakpoint, is reserved for internal use by Java implementations, and must not appear in any class file - methods containing this opcode will fail verification.

Bytecode
Type | Description
u1 | imped2 opcode = 0xFF (255)
See Also

impdep1, breakpoint

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - imul

imul

multiply two integers

Jasmin Syntax

    imul
Stack
Before | After
value1 | result
value2 | ...
... |
Description

Pops the top two integers from the operand stack, multiplies them, and pushes the integer result back onto the stack. On overflow, imul produces a result whose low order bits are correct, but whose sign bit may be incorrect.

Bytecode
Type | Description
u1 | imul opcode = 0x68 (104)
See Also

lmul, fmul, dmul

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Instruction Reference

Java Virtual Machine
Online Instruction Reference

This document contains a DRAFT version of the instruction reference (Chapter 13) printed in Java Virtual Machine, by Jon Meyer and Troy Downing, published by O'Reilly Associates, ISBN 1-56592-194-1. See book details for further information on this book.

The material presented here probably has some typos and minor errors, but we felt that it would still be a useful reference source for people looking for details of the JVM. You can also see Jasmin Home Page for further information on Jasmin and the JVM.

This material is provided on an "AS IS" basis without warranty of any kind, including without limitation the warranties of merchantability, fitness for a purpose and non-infringement. The entire risk as to the quality and performance of the Software is borne by you. Should the Software prove defective, you and not Chris Hector assume the entire cost of any service and repair. SOME JURISDICTIONS DO NOT ALLOW EXCLUSIONS OF AN IMPLIED WARRANTY, SO THIS DISCLAIMER MAY NOT APPLY TO YOU AND YOU MAY HAVE OTHER LEGAL RIGHTS THATVARY BY JURISDICTION.

  • example
  • aaload
  • aastore
  • aconst_null
  • aload
  • aload_<n>
  • anewarray
  • areturn
  • arraylength
  • astore
  • astore_<n>
  • athrow
  • baload
  • bastore
  • bipush
  • breakpoint
  • caload
  • castore
  • checkcast
  • d2f
  • d2i
  • d2l
  • dadd
  • daload
  • dastore
  • dcmpg
  • dcmpl
  • dconst_<d>
  • ddiv
  • dload
  • dload_<n>
  • dmul
  • dneg
  • drem
  • dreturn
  • dstore
  • dstore_<n>
  • dsub
  • dup
  • dup2
  • dup2_x1
  • dup2_x2
  • dup_x1
  • dup_x2
  • f2d
  • f2i
  • f2l
  • fadd
  • faload
  • fastore
  • fcmpg
  • fcmpl
  • fconst_<f>
  • fdiv
  • fload
  • fload_<n>
  • fmul
  • fneg
  • frem
  • freturn
  • fstore
  • fstore_<n>
  • fsub
  • getfield
  • getstatic
  • goto
  • goto_w
  • i2b
  • i2c
  • i2d
  • i2f
  • i2l
  • i2s
  • iadd
  • iaload
  • iand
  • iastore
  • iconst_<n>
  • iconst_m1
  • idiv
  • if_acmpeq
  • if_acmpne
  • if_icmpeq
  • if_icmpge
  • if_icmpgt
  • if_icmple
  • if_icmplt
  • if_icmpne
  • ifeq
  • ifge
  • ifgt
  • ifle
  • iflt
  • ifne
  • ifnonnull
  • ifnull
  • iinc
  • iload
  • iload_<n>
  • impdep1
  • impdep2
  • imul
  • ineg
  • instanceof
  • invokeinterface
  • invokespecial
  • invokestatic
  • invokevirtual
  • ior
  • irem
  • ireturn
  • ishl
  • ishr
  • istore
  • istore_<n>
  • isub
  • iushr
  • ixor
  • jsr
  • jsr_w
  • l2d
  • l2f
  • l2i
  • ladd
  • laload
  • land
  • lastore
  • lcmp
  • lconst_<l>
  • ldc
  • ldc_w
  • ldc2_w
  • ldiv
  • lload
  • lload_<n>
  • lmul
  • lneg
  • lookupswitch
  • lor
  • lrem
  • lreturn
  • lshl
  • lshr
  • lstore
  • lstore_<n>
  • lsub
  • lushr
  • lxor
  • monitorenter
  • monitorexit
  • multianewarray
  • new
  • newarray
  • nop
  • pop
  • pop2
  • putfield
  • putstatic
  • ret
  • return
  • saload
  • sastore
  • sipush
  • swap
  • tableswitch
  • wide
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - ldc2_w

ldc2_w

push two-word constant onto stack

Jasmin Syntax

    ldc2_w <value>
<value> is a long integer or a double-precision floating point number.

Stack
Before | After
... | <value>-word1
 | <value>-word2
 | ...
Description

ldc2_w pushes a two-word constant value onto the operand stack. ldc2_w takes a single parameter, <value>, which is the two-word item to push. The following Java types can be pushed using ldc2_w:

long
double

Example

ldc2_w 10             ; push the long integer 10
ldc2_w 1.54           ; push the double precision float 1.54
Bytecode

In bytecode, the ldc2_w opcode is followed by a 16-bit unsigned integer. This integer is the index of an entry in the constant pool. The entry is tagged either as a CONSTANT_Double or a CONSTANT_Long entry, and has a data field which contains <value>.
Type | Description
u1 | ldc2_w opcode = 0x14 (20)
u2 | index
See Also

bipush, sipush, ldc, ldc_w, aconst_null, iconst_m1, iconst_<n>, lconst_<l>, fconst_<f>, dconst_<d>

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - lload

lload

retrieve long from local variable

Jasmin Syntax

    lload <varnum>
or
    wide
    lload <varnum>
In the first form, <varnum> is an unsigned integer in the range 0 to 0xFF. In the second (wide) form, <varnum> is an unsigned integer in the range 0 to 0xFFFE.

Stack
Before | After
... | result-word1
 | result-word2
 | ...
Description

lload retrieves a long integer held in a local variable and pushes it onto the operand stack.

Since long integers are 64-bits wide, and each local variable only holds up to 32 bits, Java uses two consecutive local variables, <varnum> and <varnum> + 1 to store a long. So lload <varnum> actually places the values of both <varnum> and <varnum> + 1 onto the operand stack.

Both <varnum> and <varnum> + 1 must be valid local variable numbers in the current frame, and together they must be holding a long.

Remember that attempting to treat two-word values as two independent single-word values will produce a verification error. So trying to retrieve either <varnum> or <varnum> + 1 independently (e.g. using iload <varnum>) will produce a verification error. Similarly, if you store a non-long value in <varnum>, then <varnum> + 1 becomes invalidated until a new value is stored in it.

Example

lconst_1        ; push the long integer 1 onto the stack
lstore 3        ; pop 1 off of the stack and store in local variables 3 and 4
lload 3         ; push the value from local variables 3 and 4 (the long integer 1)
                ; back onto the stack
Bytecode

For local variable numbers in the range 0-255, use:
Type | Description
u1 | lload opcode = 0x16 (22)
u1 | <varnum>
There is also a wide format for this instruction, which supports access to all local variables from 0 to 65535:
Type | Description
u1 | wide opcode = 0xC4 (196)
u1 | lload opcode = 0x16 (22)
u2 | <varnum>
See Also

fload, iload, dload

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - new

new

create an object

Jasmin Syntax

    new <class>
<class> is the name of the class to use, e.g. java/lang/String.

Stack
Before | After
... | objectref
 | ...
Description

new is used to create object instances.

new takes a single parameter, <class>, the name of the class of object you want to create. <class> is resolved into a Java class (see Chapter 7 for a discussion of how classes are resolved). Then new determines the size in bytes of instances of the given class and allocates memory for the new instance from the garbage collected heap. The fields of the instance are set to the initial value 0 (for numeric and boolean fields), or null (for reference fields). Next, a reference to the new object is pushed onto the operand stack.

Note that the new object is initialize uninitialized - before the new object can be used, one of its <init> methods must be called using invokespecial, as shown in the example below.

Example

; This example creates a new StringBuffer object. This is like the Java code:
;
;    StringBuffer x = new StringBuffer();

; 1. use new to create a new object reference
new java/lang/StringBuffer

; 2. dup the object reference and call its constructor
dup
invokespecial java/lang/StringBuffer/<init>()V

; 3. assign object reference on the stack to a local variable
astore_1
; local variable 1 now contains a StringBuffer object,
; ready for use

; the following example shows how to call a non-default
; constructor. It is like the Java code:
;
;    StringBuffer x = new StringBuffer(100);
new java/lang/StringBuffer
dup
bipush 100
invokespecial java/lang/StringBuffer/<init>(I)V
astore_1

Exceptions

OutOfMemoryError - not enough memory to allocate a new instance

InstantiationError - The class named by <type> is an abstract class or an interface

Bytecode

In bytecode, after the new opcode is a 16-bit unsigned integer index. This integer is the index of an entry in the constant pool of the current class. The entry is tagged a CONSTANT_Class entry (see Chapter 4). The name field of the entry is a string given by the <type> parameter in Jasmin.
Type | Description
u1 | new opcode = 0xBB (187)
u2 | index
See Also

anewarray, newarray, multianewarray

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - newarray

newarray

allocate new array for numbers or booleans

Jasmin Syntax

    newarray <type>
where <type> is one of: boolean, char, float, double, byte, short, int or long.

Stack
Before | After
n | arrayref
... | ...
Description

newarray is used to allocate single-dimension arrays of booleans, chars, floats, doubles, bytes, shorts, ints or longs. For example, when you write the Java code:

new int[10];
this is compiled into:

bipush 10          ; push the int 10 onto the stack
newarray int       ; make an array of 10 ints. The new array is left on the stack
newarray pops a positive int, n, off the stack, and constructs an array for holding n elements of the type given by <type>. Initially the elements in the array are set to zero. A reference to the new array object is left on the stack.

Example

; This is like the Java code:
;     short x[] = new short[2];

iconst_2           ; push 2 onto the stack
newarray short     ; call newarray to make a 2-element short array
astore_1           ; store the reference to the array in local variable 1
Exceptions

NegativeArraySizeException - n is less than zero.

OutOfMemoryError - insufficient memory to allocate the array.

Bytecode
Type | Description
u1 | newarray opcode = 0xBC (188)
u1 | array-type (see below)

In bytecode, the type of the array is specified by the array-type byte immediately following the newarray opcode, which has one of the following values:
Array Type | Value
boolean | 4
char | 5
float | 6
double | 7
byte | 8
short | 9
int | 10
long | 11
See Also

anewarray, multianewarray, new

Notes

The Java boolean false is represented in the JVM by the integer 0; true is represented by the integer 1. Boolean arrays are actually treated as byte arrays and are initialized to false (0). You should use the baload and bastore instructions to load and store values in boolean arrays.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - nop

nop

do nothing

Jasmin Syntax

    nop
Stack
Before | After
... | ...
Description

This instruction has no effect - compilers sometimes generate nop's for debugging, testing or timing purposes.

Example

nop             ; do nothing

Bytecode
Type | Description
u1 | nop opcode = 0x0 (0)

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - pop2

pop2

discard top two words on stack

Jasmin Syntax

    pop2
Stack
Before | After
item1 | ...
item2 |
... |
Description

Removes two single-word items from the stack (e.g. two integers, or an integer and an object reference) or one two-word item (i.e. a double or a long).

Example

invokemethod Myclass/foo()D    ; call double Myclass.foo();
pop2                           ; discard the double result

Bytecode
Type | Description
u1 | pop2 opcode = 0x58 (88)
See Also

pop

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - putfield

putfield

set value of object field

Jasmin Syntax

    putfield <field-spec> <descriptor>
<field-spec> is composed of two parts, a classname and a fieldname. The classname is all of the characters in the <field-spec> up to the last '/' character, and the fieldname is the rest of the characters after the last '/'. For example:

    foo/baz/AnotherClass/aVeryLongFieldName
    -- classname -------/-- fieldname -----
{{JM - can we turn this into a nicer diagram?}}
<descriptor> is the Java type descriptor for the field, for example Ljava/io/PrintStream;

In Jasmin, the .field directive is used to add a field to a class. See Chapter 16 for a description of this and other Jasmin directives.

Stack
Before | After
value | ...
objectref |
... |
or, for fields holding doubles or longs:
Before | After
value-word1 | ...
value-word2 |
objectref |
... |
Description

putfield sets the value of the field identified by <field-spec> in objectref (a reference to an object) to the single or double word value on the operand stack. For example, if you have the class:

    package xyz;
    class Point {
        public int xCoord, yCoord;
    };
Then, assuming p is an instance of the class Point, writing the Java expression:

    p.xCoord = 10;
generates JVM code like:

    aload_1                      ; push object in local varable 1 (i.e. p) onto the stack
    bipush 10                    ; push the integer 10 onto the stack
    putfield xyz/Point/xCoord I  ; set the value of the integer field p.xCoord to 10
In Jasmin, putfield takes two parameters, <field-spec> and <descriptor>. <field-spec> provides classname, the name of the class that defines the field, as well as fieldname, the name of the field. In the example above, the <field-spec> is "xyz/Point/xCoord", indicating that the classname is called "xyz/Point" and the fieldname is "xCoord". <descriptor> indicates the type of data held in the field, and is a standard Java type descriptor (see Chapter 4). In the example above, <descriptor> is "I", since the field holds an integer.

putfield first resolves classname to a Java class. Then it locates fieldname in that class, determining the size of the field (in bytes) and its offset (in bytes) from the base of the object data. The type of the field must match <descriptor>. See Chapter 7 for a full discussion of how fields are resolved

To set the value of the field, putfield pops either a 4-byte or 8-byte quantity off the stack (depending on the field descriptor), and truncates it to be width bytes long. Then it sets the bytes starting at offset and extending for width bytes in objectref's instance data to the new value.

Exceptions

NullPointerException - objectref is null

Bytecode

In bytecode, the putfield opcode is followed by a 16-bit unsigned integer index. This is the index of an entry in the constant pool of the current class. The entry is tagged a CONSTANT_Fieldref entry. The fieldref entry lists a CONSTANT_Class entry in the constant pool whose name is the classname given in <field-spec>, as well as a CONSTANT_NameAndType entry in the constant pool, whose name is the fieldname given in <field-spec>, and whose descriptor is the string given by <descriptor>.
Type | Description
u1 | putfield opcode = 0xB5 (181)
u2 | index
See Also

getfield, putstatic, getstatic

Notes

Fields cannot be overriden, although they can be 'shadowed'. For example, with the two classes:

    class A { int x; }
and
    class B extends A { int x; }
instances of B will have storage for both the field "A/x" and the field "B/x". Which field is accessed is determined by the class name given in <field-spec>.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - putstatic

putstatic

set value of static field

Jasmin Syntax

    putstatic <field-spec> <descriptor>
<field-spec> is composed of two parts, a classname and a fieldname. The classname is all of the characters in the <field-spec> up to the last '/' character, and the fieldname is the rest of the characters after the last '/'. For example:

    foo/baz/AnotherClass/aVeryLongFieldName
    -- classname -------/-- fieldname -----
{{JM - can we turn this into a nicer diagram?}}

<descriptor> is the Java type descriptor for the field, for example Ljava/io/PrintStream;
In Jasmin, the .field directive is used to add a field to a class. See Chapter 16 for a description of this and other Jasmin directives.

Stack
Before | After
value | ...
... |
or, for static fields holding longs or doubles:
Before | After
value-word1 | ...
value-word2 |
... |
Description

putstatic sets the value of the static field (also known as a class field) identified by <field-spec> to the single or double word value on the operand stack. For example, when you write the Java expression:

    java.lang.System.out = myStream;
this generates a call to getstatic like:

    aload_1    ; push object reference in local variable 1 (i.e. myStream) onto stack
               ; now use putstatic to assign it to System.out
    putstatic java/lang/System/out Ljava/io/PrintStream;
In Jasmin, putstatic takes two parameters, <field-spec> and <descriptor>. <field-spec> provides classname, the name of the class that defines the static field, as well fieldname, as the name of the field. In the example above, the <field-spec> is "java/lang/System/out", indicating that the classname is "java/lang/System" and the fieldname is "out". <descriptor> indicates the type of data held in the field, and is a standard Java type descriptor (see Chapter 4). In the example above, <descriptor> is "Ljava/io/PrintStream;", i.e. an instance of the PrintStream class.

putstatic first resolves classname into a Java class. Then it locates the fieldname in that class, determining the width of the field (in bytes) and its offset (in bytes) from the base of the class's static data. The type of the field must match <descriptor>. See Chapter 7 for more on how fields are resolved

To set the value of the field, putstatic pops either a 4-byte or 8-byte quantity off the stack (depending on the field descriptor), and truncates it to be wodth bytes long. Then it sets the bytes starting at offset and extending for width bytes in the class's static data to the new value.

Bytecode

In bytecode, the putstatic opcode is followed by a 16-bit unsigned integer index. This is the index of an entry in the constant pool of the current class. The entry is tagged a CONSTANT_Fieldref entry. The fieldref entry lists a CONSTANT_Class entry in the constant pool whose name is the classname given in <field-spec>, as well as a CONSTANT_NameAndType entry in the constant pool, whose name is the fieldname given in <field-spec>, and whose descriptor is the string given by <descriptor>.
Type | Description
u1 | putstatic opcode = 0xB3 (179)
u2 | index
See Also

putfield, getfield, getstatic

Notes

Fields cannot be overriden, although they can be 'shadowed'. For example, with the two classes:

    class A { static int X; }
and
    class B extends A { static int X; }
then the runtime system will allocate storage for both the static field "A/X" and the static field "B/X". Which field is accessed is determined by the class name given in <field-spec>.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - ret

ret

return from subroutine

Jasmin Syntax

    ret <varnum>
or
    wide
    ret <varnum>
In the first form, <varnum> is an unsigned integer in the range 0 to 0xFF. In the second (wide) form, <varnum> is an unsigned integer in the range 0 to 0xFFFF.

Stack
Before | After
... | ...
Description

ret is used to return from a subroutine that was invoked by jsr or jsr_w. It takes a single parameter, <varnum>, an unsigned integer which local variable is holding the returnAddress for this subroutine. Execution continues at the address stored in that local variable.

Return addresses are left on the stack by the jsr and jsr_w instructions. Methods are expected to immediately store the return address in a local variable, ready for use with ret.

Example

; This example method uses a PrintMe subroutine to invoke the System.out.println() method.

.method usingSubroutine()V
    ldc "Message 1"
    jsr PrintMe          ; print "Message 1"

    ldc "Message 2"
    jsr PrintMe          ; print "Message 2"

    ldc "Message 3"
    jsr PrintMe          ; print "Message 3"

    return   ; now return from usingSubroutine

; define the PrintMe subroutine ...
PrintMe:
    astore_1            ; store return-address in local variable 1
    ; call System.out.println()
    getstatic java/lang/System/out Ljava/io/PrintStream;
    invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V

    ret 1               ; return to the return-address in local variable 1
.end method
Bytecode

For local variable numbers in the range 0-255, use:
Type | Description
u1 | ret opcode = 0xA9 (169)
u1 | <varnum>
There is also a wide format for this instruction, which supports access to all local variables from 0 to 65535:
Type | Description
u1 | wide opcode = 0xC4 (196)
u1 | ret opcode = 0xA9 (169)
u2 | <varnum>
See Also

jsr, jsr_w, goto, goto_w, wide

Notes

The assymetry between jsr (which pushes a returnAddress onto the stack) and ret (which gets the returnAddress from a local variable) is intentional - the bytecode verifier relies on this structure (see Chapter 5) .

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - return

return

return from method

Jasmin Syntax

    return
Stack
Before | After
... | ...
Description

return is used to return from a method whose return type is void.

All items on the current method's operand stack are discarded. If the current method is marked as synchronized, then an implicit monitorexit instruction is executed. Then the current method's frame is discarded, the invoker's frame is reinstated, and control returns to the invoker.

Example

; the following method takes no parameters, performs no actions, and returns no results.
.method identity()V
    return  ; simply return with no result
.end method
Bytecode
Type | Description
u1 | return opcode = 0xB1 (177)
See Also

lreturn, freturn, dreturn, areturn, ireturn

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - saload

saload

retrieve short from array

Jasmin Syntax

    saload
Stack
Before | After
index | value
arrayref | ...
... |
Description

Retrieves a short from an array of shorts and places it on the stack. arrayref is a reference to an array of shorts. index is an int. The arrayref and index are removed from the stack, and the 16-bit signed short at the given index in the array is retrieved, sign-extended to an int, and pushed onto the stack.

Example

; This is like the Java code:
;      short x = arr[0];
; where x is local variable 2 and arr is
; an array in local variable 1
aload_1       ; load local variable 1 onto the stack
iconst_0      ; push the integer 0 onto the stack
saload        ; retrieve the entry
istore_2      ; store the entry in local variable 2
Exceptions

NullPointerException - arrayref is null

ArrayIndexOutOfBoundsException - index is < 0 or >= arrayref.length

Bytecode
Type | Description
u1 | saload opcode = 0x35 (53)
See Also

iaload, laload, faload, daload, aaload, baload, caload, iastore, lastore, fastore, dastore, aastore, bastore, castore, sastore

Notes

Array indices start at 0 (the first entry in the array is at index 0).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - sastore

sastore

store in short array

Jasmin Syntax

    sastore
Stack
Before | After
value | ...
index |
arrayref |
... |
Description

Takes an int from the stack, truncates it to a signed 16-bit short, and stores it in an array of shorts. arrayref is a reference to an array of 16-bit signed shorts. index is an int. value is the int to be stored in the array. arrayref, index and value are removed from the stack, and value is stored in the array at the given index.

Exceptions

ArrayIndexOutOfBoundsException - index is < 0 or >= arrayref.length

NullPointerException - arrayref is null

Bytecode
Type | Description
u1 | sastore opcode = 0x56 (86)
See Also

iastore, lastore, fastore, dastore, aastore, bastore, castore, iaload, laload, faload, daload, aaload, baload, caload, saload

Notes

Array indices start at 0 (the first entry in the array is at index 0).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - sipush

sipush

push two-byte signed integer

Jasmin Syntax

    sipush <n>
<n> is a signed integer in the range -32768 to 32767.

Stack
Before | After
... | value
 | ...
Description

sipush takes a single parameter, <n> (a 16-bit signed integer), sign extends it to a 32-bit int, and pushes the resulting int onto the operand stack.

sipush is typically more efficient than ldc. It also occupies fewer bytes in the class file.

Example

sipush    0x10    ; push the value 0x10 (16)
                  ; onto the operand stack

Bytecode

The sipush opcode is followed in the bytecode by a 16-bit signed short specifying the integer value to push.
Type | Description
u1 | sipush opcode = 0x11 (17)
s2 | <n>
See Also

bipush, ldc, ldc_w, ldc2_w, aconst_null, iconst_m1, iconst_<n>, lconst_<l>, fconst_<f>, dconst_<d>

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - swap

swap

swap top two stack words

Jasmin Syntax

    swap
Stack
Before | After
word1 | word2
word2 | word1
... | ...
Description

Swaps the top two single-word items on the stack. word1/word2 cannot belong to a long or double.

Bytecode
Type | Description
u1 | swap opcode = 0x5F (95)
Notes

There is no swap2, although you could use:

    dup2_x2
    pop2
to achieve the same effect.

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - tableswitch

tableswitch

jump according to a table

Jasmin Syntax

     tableswitch  <low> [<high>]
                  <label1>
                  <label2>
                  ...
                  <labelN>
        default : <defaultLabel>
<low> is a 32-bit signed integer. <label1>, <label2>, etc. are label names. <high> is a 32-bit signed integer which is greater than or equal to <low>. There must be <high>-<low>+1 labels given in the table. If <high> is omitted, Jasmin calculates it for you based on the number of entries in the table.

To define the location of the label, use the <label> name followed by a colon:

<label>:
<label> then becomes associated the address of the following instruction. Labels can only be assigned one location in a method. On the other hand, a single <label> can be the target of multiple branch instructions.

Stack
Before | After
val | ...
... |
Description

tableswitch is used to perform computed jump. The jump table used by tableswitch is given in the bytecode after the tableswitch opcode.

An integer, val, is popped off the top of the operand stack. If this value is less than <low>, or if it is greater than <high>, execution branches to the address (pc + default_offset), where pc is the address of the tableswitch opcode in the bytecode, and default_offset is taken from the bytecode and is the relative address of the instruction at <defaultLabel>.

If val is in the range <low> to <high>, execution branches to the i'th entry in the table, where i is (val - <low>) and the first entry in the table is index 0. i.e. pc becomes the address (pc + table[val - <low>]).

The following pseudo-code illustrates the computation performed by tableswitch:

int val = pop();                // pop an int from the stack
if (val < low || val > high) {  // if its less than <low> or greater than <high>,
    pc += default;              // branch to default
} else {                        // otherwise
    pc += table[val - low];     // branch to entry in table
}
Notice that all addresses stored in the table are relative to the address of the tableswitch opcode in the bytecode. If you are using Jasmin, these addresses are computed for you from the address of the given labels.

Example

    iload_1 ; push local variable 1 onto the stack

    ; if the variable contains 0, jump to ZeroLabel
    ; if the variable contains 1, jump to OneLabel
    ; if the variable contains 2, jump to TwoLabel
    ; otherwis jump to DefaultLabel
    tableswitch 0 2
        ZeroLabel
        OneLabel
        TwoLabel
      default: DefaultLabel

ZeroLabel:
    ; the variable contained 0 ...
    ldc 100
    ireturn   ; return the result 100

OneLabel:
    ; the variable contained 1 ...
    bipush 200
    ireturn   ; return the result 200

TwoLabel:
    ; the variable contained 2 ...
    bipush 300
    ireturn   ; return the result 300

DefaultLabel:
    ; the variable contained something else ...
    bipush 0
    ireturn   ; return the result 0

Bytecode

tableswitch is a variable length instruction. Immediately after the tableswitch opcode, between 0 to 3 bytes of padding zeros are inserted, so that the default_offset parameter starts at an offset in the bytecode which is a multiple of 4. Next, two signed 32-bit integers are given - low and high, followed by (low - high + 1) 32-bit integer offsets.
Type | Description
u1 | tableswitch opcode = 0xAA (170)
- | ...0-3 bytes of padding ...
s4 | default_offset
s4 | <low>
s4 | <low> + N - 1
s4 | offset_1
s4 | offset_2
... | ...
s4 | offset_N
See Also

lookupswitch

Notes

Addresses are measured in bytes from the start of the bytecode (i.e. address 0 is the first byte in the bytecode of the currently executing method).

prev next contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates


Java Virtual Machine - Online Reference - wide

 prev contents
wide

next instruction uses 16-bit index

Jasmin Syntax

    wide
    <instruction> <parameter> [<parameter>]
Note that the Jasmin assembler automatically widens instructions as necessary - so the wide instruction is optional in Jasmin.

Stack
Before | After
... | ...
Description

wide is placed in front of an instruction that accesses a local variable. You use it to extend the range of local variables available to the instruction from 8 bits (i.e. 0-255) to 16 bits (i.e. 0-65535). In addition, for iinc, it increases the increment range. wide is used in conjunction with one of the following opcodes: aload, dload, iload, fload, lload, astore, dstore, istore, fstore, lstore, iinc and ret. See the reference pages of those instructions for more details.

Bytecode

There are two bytecode formats. For aload, dload, iload, fload, lload, astore, dstore, istore, fstore, lstore, and ret, use:
Type | Description
u1 | wide opcode = 0xC4 (196)
u1 | <opcode>
u2 | <varnum>
or, for iinc, use:
Type | Description
u1 | wide opcode = 0xC4 (196)
u1 | <opcode>
u2 | <varnum>
u2 | <n>
See Also

aload, iload, fload, dload, lload, astore, istore, fstore, dstore, lstore, iinc, ret

Notes

The opcode that follows wide cannot be the target of a branch.

prev contents
Java Virtual Machine, by Jon Meyer and Troy Downing, O'Reilly Associates