VM Spec

Contents | Prev | Next | Index | The JavaTM Virtual Machine Specification

A B C D F G I J L M N P R S T W

## i2b

Operation

> Convert `int` to `byte`

Format

> i2b

Forms

> i2b = 145 (0x91)

Operand Stack

> ..., value ..., result

Description

> The value on the top of the operand stack must be of type `int`. It is popped from the operand stack, truncated to a `byte`, then sign-extended to an `int` result. That result is pushed onto the operand stack.

Notes

> The i2b instruction performs a narrowing primitive conversion (§2.6.3). It may lose information about the overall magnitude of value. The result may also not have the same sign as value.

## i2c

Operation

> Convert `int` to `char`

Format

> i2c

Forms

> i2c = 146 (0x92)

Operand Stack

> ..., value ..., result

Description

> The value on the top of the operand stack must be of type `int`. It is popped from the operand stack, truncated to `char`, then zero-extended to an `int` result. That result is pushed onto the operand stack.

Notes

> The i2c instruction performs a narrowing primitive conversion (§2.6.3). It may lose information about the overall magnitude of value. The result (which is always positive) may also not have the same sign as value.

## i2d

Operation

> Convert `int` to `double`

Format

> i2d

Forms

> i2d = 135 (0x87)

Operand Stack

> ..., value ..., result

Description

> The value on the top of the operand stack must be of type `int`. It is popped from the operand stack and converted to a `double` result. The result is pushed onto the operand stack.

Notes

> The i2d instruction performs a widening primitive conversion (§2.6.2). Because all values of type `int` are exactly representable by type `double`, the conversion is exact.

## i2f

Operation

> Convert `int` to `float`

Format

> i2f

Forms

> i2f = 134 (0x86)

Operand Stack

> ..., value ..., result

Description

> The value on the top of the operand stack must be of type `int`. It is popped from the operand stack and converted to the `float` result using IEEE 754 round to nearest mode. The result is pushed onto the operand stack.

Notes

> The i2f instruction performs a widening primitive conversion (§2.6.2), but may result in a loss of precision because values of type `float` have only 24 significand bits.

## i2l

Operation

> Convert `int` to `long`

Format

> i2l

Forms

> i2l = 133 (0x85)

Operand Stack

> ..., value ..., result

Description

> The value on the top of the operand stack must be of type `int`. It is popped from the operand stack and sign-extended to a `long` result. That result is pushed onto the operand stack.

Notes

> The i2l instruction performs a widening primitive conversion (§2.6.2). Because all values of type `int` are exactly representable by type `long`, the conversion is exact.

## i2s

Operation

> Convert `int` to `short`

Format

> i2s

Forms

> i2s = 147 (0x93)

Operand Stack

> ..., value ..., result

Description

> The value on the top of the operand stack must be of type `int`. It is popped from the operand stack, truncated to a `short`, then sign-extended to an `int` result. That result is pushed onto the operand stack.

Notes

> The i2s instruction performs a narrowing primitive conversion (§2.6.3). It may lose information about the overall magnitude of value. The result may also not have the same sign as value.

## iadd

Operation

> Add `int`

Format

> iadd

Forms

> iadd = 96 (0x60)

Operand Stack

> ..., value1, value2 ..., result

Description

> Both value1 and value2 must be of type `int`. The values are popped from the operand stack. The `int` result is value1 + value2. The result is pushed onto the operand stack.

> The result is the 32 low-order bits of the true mathematical result in a sufficiently wide two's-complement format, represented as a value of type `int`. If overflow occurs, then the sign of the result may not be the same as the sign of the mathematical sum of the two values.

> Despite the fact that overflow may occur, execution of an iadd instruction never throws a runtime exception.

## iaload

Operation

> Load `int` from array

Format

> iaload

Forms

> iaload = 46 (0x2e)

Operand Stack

> ..., arrayref, index ..., value

Description

> The arrayref must be of type `reference` and must refer to an array whose components are of type `int`. The index must be of type `int`. Both arrayref and index are popped from the operand stack. The `int` value in the component of the array at index is retrieved and pushed onto the operand stack.

Runtime Exceptions

> If arrayref is `null`, iaload throws a `NullPointerException`.

> Otherwise, if index is not within the bounds of the array referenced by arrayref, the iaload instruction throws an `ArrayIndexOutOfBoundsException`.

## iand

Operation

> Boolean AND `int`

Format

> iand

Forms

> iand = 126 (0x7e)

Operand Stack

> ..., value1, value2 ..., result

Description

> Both value1 and value2 must be of type `int`. They are popped from the operand stack. An `int` result is calculated by taking the bitwise AND (conjunction) of value1 and value2. The result is pushed onto the operand stack.

## iastore

Operation

> Store into `int` array

Format

> iastore

Forms

> iastore = 79 (0x4f)

Operand Stack

> ..., arrayref, index, value ...

Description

> The arrayref must be of type `reference` and must refer to an array whose components are of type `int`. Both index and value must be of type `int`. The arrayref, index, and value are popped from the operand stack. The `int` value is stored as the component of the array indexed by index.

Runtime Exceptions

> If arrayref is `null`, iastore throws a `NullPointerException`.

> Otherwise, if index is not within the bounds of the array referenced by arrayref, the iastore instruction throws an `ArrayIndexOutOfBoundsException`.

## iconst_<i>

Operation

> Push `int` constant

Format

> iconst_<i>

Forms

> iconst_m1 = 2 (0x2) iconst_0 = 3 (0x3) iconst_1 = 4 (0x4) iconst_2 = 5 (0x5) iconst_3 = 6 (0x6) iconst_4 = 7 (0x7) iconst_5 = 8 (0x8)

Operand Stack

> ... ..., <i>

Description

> Push the `int` constant <i> (-1, 0, 1, 2, 3, 4 or 5) onto the operand stack.

Notes

> Each of this family of instructions is equivalent to bipush <i> for the respective value of <i>, except that the operand <i> is implicit.

## idiv

Operation

> Divide `int`

Format

> idiv

Forms

> idiv = 108 (0x6c)

Operand Stack

> ..., value1, value2 ..., result

Description

> Both value1 and value2 must be of type `int`. The values are popped from the operand stack. The `int` result is the value of the Java programming language expression value1 / value2. The result is pushed onto the operand stack.

> An `int` division rounds towards 0; that is, the quotient produced for `int` values in n/d is an `int` value q whose magnitude is as large as possible while satisfying . Moreover, q is positive when and n and d have the same sign, but q is negative when and n and d have opposite signs.

> There is one special case that does not satisfy this rule: if the dividend is the negative integer of largest possible magnitude for the `int` type, and the divisor is -1, then overflow occurs, and the result is equal to the dividend. Despite the overflow, no exception is thrown in this case.

Runtime Exception

> If the value of the divisor in an `int` division is 0, idiv throws an `ArithmeticException`.

## if_acmp<cond>

Operation

> Branch if `reference` comparison succeeds

Format

> if_acmp<cond>
> branchbyte1
> branchbyte2

Forms

> if_acmpeq = 165 (0xa5) if_acmpne = 166 (0xa6)

Operand Stack

> ..., value1, value2 ...

Description

> Both value1 and value2 must be of type `reference`. They are both popped from the operand stack and compared. The results of the comparison are as follows:

- eq succeeds if and only if value1 = value2
- ne succeeds if and only if value1 value2

> If the comparison succeeds, the unsigned branchbyte1 and branchbyte2 are used to construct a signed 16-bit offset, where the offset is calculated to be (branchbyte1 << 8) | branchbyte2. Execution then proceeds at that offset from the address of the opcode of this if_acmp<cond> instruction. The target address must be that of an opcode of an instruction within the method that contains this if_acmp<cond> instruction.

> Otherwise, if the comparison fails, execution proceeds at the address of the instruction following this if_acmp<cond> instruction.

## if_icmp<cond>

Operation

> Branch if `int` comparison succeeds

Format

> if_icmp<cond>
> branchbyte1
> branchbyte2

Forms

> if_icmpeq = 159 (0x9f) if_icmpne = 160 (0xa0) if_icmplt = 161 (0xa1) if_icmpge = 162 (0xa2) if_icmpgt = 163 (0xa3) if_icmple = 164 (0xa4)

Operand Stack

> ..., value1, value2 ...

Description

> Both value1 and value2 must be of type `int`. They are both popped from the operand stack and compared. All comparisons are signed. The results of the comparison are as follows:

- eq succeeds if and only if value1 = value2
- ne succeeds if and only if value1 value2
- lt succeeds if and only if value1 < value2
- le succeeds if and only if value1 value2
- gt succeeds if and only if value1 > value2
- ge succeeds if and only if value1 value2

> If the comparison succeeds, the unsigned branchbyte1 and branchbyte2 are used to construct a signed 16-bit offset, where the offset is calculated to be (branchbyte1 << 8) | branchbyte2. Execution then proceeds at that offset from the address of the opcode of this if_icmp<cond> instruction. The target address must be that of an opcode of an instruction within the method that contains this if_icmp<cond> instruction.

> Otherwise, execution proceeds at the address of the instruction following this if_icmp<cond> instruction.

## if<cond>

Operation

> Branch if `int` comparison with zero succeeds

Format

> if<cond>
> branchbyte1
> branchbyte2

Forms

> ifeq = 153 (0x99) ifne = 154 (0x9a) iflt = 155 (0x9b) ifge = 156 (0x9c) ifgt = 157 (0x9d) ifle = 158 (0x9e)

Operand Stack

> ..., value ...

Description

> The value must be of type `int`. It is popped from the operand stack and compared against zero. All comparisons are signed. The results of the comparisons are as follows:

- eq succeeds if and only if value = 0
- ne succeeds if and only if value 0
- lt succeeds if and only if value < 0
- le succeeds if and only if value 0
- gt succeeds if and only if value > 0
- ge succeeds if and only if value 0

> If the comparison succeeds, the unsigned branchbyte1 and branchbyte2 are used to construct a signed 16-bit offset, where the offset is calculated to be (branchbyte1 << 8) | branchbyte2. Execution then proceeds at that offset from the address of the opcode of this if<cond> instruction. The target address must be that of an opcode of an instruction within the method that contains this if<cond> instruction.

> Otherwise, execution proceeds at the address of the instruction following this if<cond> instruction.

## ifnonnull

Operation

> Branch if `reference` not `null`

Format

> ifnonnull
> branchbyte1
> branchbyte2

Forms

> ifnonnull = 199 (0xc7)

Operand Stack

> ..., value ...

Description

> The value must be of type `reference`. It is popped from the operand stack. If value is not `null`, the unsigned branchbyte1 and branchbyte2 are used to construct a signed 16-bit offset, where the offset is calculated to be (branchbyte1 << 8) | branchbyte2. Execution then proceeds at that offset from the address of the opcode of this ifnonnull instruction. The target address must be that of an opcode of an instruction within the method that contains this ifnonnull instruction.

> Otherwise, execution proceeds at the address of the instruction following this ifnonnull instruction.

## ifnull

Operation

> Branch if `reference` is `null`

Format

> ifnull
> branchbyte1
> branchbyte2

Forms

> ifnull = 198 (0xc6)

Operand Stack

> ..., value ...

Description

> The value must of type `reference`. It is popped from the operand stack. If value is `null`, the unsigned branchbyte1 and branchbyte2 are used to construct a signed 16-bit offset, where the offset is calculated to be (branchbyte1 << 8) | branchbyte2. Execution then proceeds at that offset from the address of the opcode of this ifnull instruction. The target address must be that of an opcode of an instruction within the method that contains this ifnull instruction.

> Otherwise, execution proceeds at the address of the instruction following this ifnull instruction.

## iinc

Operation

> Increment local variable by constant

Format

> iinc
> index
> const

Forms

> iinc = 132 (0x84)

Operand Stack

> No change

Description

> The index is an unsigned byte that must be an index into the local variable array of the current frame (§3.6). The const is an immediate signed byte. The local variable at index must contain an `int`. The value const is first sign-extended to an `int`, and then the local variable at index is incremented by that amount.

Notes

> The iinc opcode can be used in conjunction with the wide instruction to access a local variable using a two-byte unsigned index and to increment it by a two-byte immediate value.

## iload

Operation

> Load `int` from local variable

Format

> iload
> index

Forms

> iload = 21 (0x15)

Operand Stack

> ... ..., value

Description

> The index is an unsigned byte that must be an index into the local variable array of the current frame (§3.6). The local variable at index must contain an `int`. The value of the local variable at index is pushed onto the operand stack.

Notes

> The iload opcode can be used in conjunction with the wide instruction to access a local variable using a two-byte unsigned index.

## iload_<n>

Operation

> Load `int` from local variable

Format

> iload_<n>

Forms

> iload_0 = 26 (0x1a) iload_1 = 27 (0x1b) iload_2 = 28 (0x1c) iload_3 = 29 (0x1d)

Operand Stack

> ... ..., value

Description

> The <n> must be an index into the local variable array of the current frame (§3.6). The local variable at <n> must contain an `int`. The value of the local variable at <n> is pushed onto the operand stack.

Notes

> Each of the iload_<n> instructions is the same as iload with an index of <n>, except that the operand <n> is implicit.

## imul

Operation

> Multiply `int`

Format

> imul

Forms

> imul = 104 (0x68)

Operand Stack

> ..., value1, value2 ..., result

Description

> Both value1 and value2 must be of type `int`. The values are popped from the operand stack. The `int` result is value1 * value2. The result is pushed onto the operand stack.

> The result is the 32 low-order bits of the true mathematical result in a sufficiently wide two's-complement format, represented as a value of type `int`. If overflow occurs, then the sign of the result may not be the same as the sign of the mathematical sum of the two values.

> Despite the fact that overflow may occur, execution of an imul instruction never throws a runtime exception.

## ineg

Operation

> Negate `int`

Format

> ineg

Forms

> ineg = 116 (0x74)

Operand Stack

> ..., value ..., result

Description

> The value must be of type `int`. It is popped from the operand stack. The `int` result is the arithmetic negation of value, -value. The result is pushed onto the operand stack.

> For `int` values, negation is the same as subtraction from zero. Because the Java virtual machine uses two's-complement representation for integers and the range of two's-complement values is not symmetric, the negation of the maximum negative `int` results in that same maximum negative number. Despite the fact that overflow has occurred, no exception is thrown.

> For all `int` values `x`, -`x` equals (~`x`) + `1`.

## instanceof

Operation

> Determine if object is of given type

Format

> instanceof
> indexbyte1
> indexbyte2

Forms

> instanceof = 193 (0xc1)

Operand Stack

> ..., objectref ..., result

Description

> The objectref, which must be of type `reference`, is popped from the operand stack. The unsigned indexbyte1 and indexbyte2 are used to construct an index into the runtime constant pool of the current class (§3.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The runtime constant pool item at the index must be a symbolic reference to a class, array, or interface type. The named class, array, or interface type is resolved (§5.4.3.1).

> If objectref is not `null` and is an instance of the resolved class or array or implements the resolved interface, the instanceof instruction pushes an `int` result of 1 as an int on the operand stack. Otherwise, it pushes an `int` result of 0.

> The following rules are used to determine whether an objectref that is not `null` is an instance of the resolved type: If S is the class of the object referred to by objectref and T is the resolved class, array, or interface type, instanceof determines whether objectref is an instance of T as follows:

- If S is an ordinary (nonarray) class, then:

  - If T is a class type, then S must be the same class (§2.8.1) as T or a subclass of T.

  - If T is an interface type, then S must implement (§2.13) interface T.

- If S is an interface type, then:

  - If T is a class type, then T must be `Object` (§2.4.7).

  - If T is an interface type, then T must be the same interface as S, or a superinterface of S (§2.13.2).

- If S is a class representing the array type SC`[]`, that is, an array of components of type SC, then:

  - If T is a class type, then T must be `Object` (§2.4.7).

  - If T is an array type TC`[]`, that is, an array of components of type TC, then one of the following must be true:

    - TC and SC are the same primitive type (§2.4.1).

    - TC and SC are reference types (§2.4.6), and type SC can be cast to TC by these runtime rules.

  - If T is an interface type, T must be one of the interfaces implemented by arrays (§2.15).

Linking Exceptions

> During resolution of symbolic reference to the class, array, or interface type, any of the exceptions documented in Section 5.4.3.1 can be thrown.

Notes

> The instanceof instruction is very similar to the checkcast instruction. It differs in its treatment of `null`, its behavior when its test fails (checkcast throws an exception, instanceof pushes a result code), and its effect on the operand stack.

## invokeinterface

Operation

> Invoke interface method

Format

> invokeinterface
> indexbyte1
> indexbyte2
> count
> 0

Forms

> invokeinterface = 185 (0xb9)

Operand Stack

> ..., objectref, [arg1, [arg2 ...]] ...

Description

> The unsigned indexbyte1 and indexbyte2 are used to construct an index into the runtime constant pool of the current class (§3.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The runtime constant pool item at that index must be a symbolic reference to an interface method (§5.1), which gives the name and descriptor (§4.3.3) of the interface method as well as a symbolic reference to the interface in which the interface method is to be found. The named interface method is resolved (§5.4.3.4). The interface method must not be an instance initialization method (§3.9) or the class or interface initialization method (§3.9).

> The count operand is an unsigned byte that must not be zero. The objectref must be of type `reference` and must be followed on the operand stack by nargs argument values, where the number, type, and order of the values must be consistent with the descriptor of the resolved interface method. The value of the fourth operand byte must always be zero.

> Let C be the class of objectref. The actual method to be invoked is selected by the following lookup procedure:

- If C contains a declaration for an instance method with the same name and descriptor as the resolved method, then this is the method to be invoked, and the lookup procedure terminates.

- Otherwise, if C has a superclass, this same lookup procedure is performed recursively using the direct superclass of C; the method to be invoked is the result of the recursive invocation of this lookup procedure.

- Otherwise, an `AbstractMethodError` is raised.

> If the method is `synchronized`, the monitor associated with objectref is acquired or reentered.

> If the method is not `native`, the nargs argument values and objectref are popped from the operand stack. A new frame is created on the Java virtual machine stack for the method being invoked. The objectref and the argument values are consecutively made the values of local variables of the new frame, with objectref in local variable 0, arg1 in local variable 1 (or, if arg1 is of type `long` or `double`, in local variables 1 and 2), and so on. Any argument value that is of a floating-point type undergoes value set conversion (§3.8.3) prior to being stored in a local variable. The new frame is then made current, and the Java virtual machine `pc` is set to the opcode of the first instruction of the method to be invoked. Execution continues with the first instruction of the method.

> If the method is `native` and the platform-dependent code that implements it has not yet been bound (§5.6) into the Java virtual machine, that is done. The nargs argument values and objectref are popped from the operand stack and are passed as parameters to the code that implements the method. Any argument value that is of a floating-point type undergoes value set conversion (§3.8.3) prior to being passed as a parameter. The parameters are passed and the code is invoked in an implementation-dependent manner. When the platform-dependent code returns:

- If the `native` method is `synchronized`, the monitor associated with objectref is released or exited as if by execution of a monitorexit instruction.

- If the `native` method returns a value, the return value of the platform-dependent code is converted in an implementation-dependent way to the return type of the `native` method and pushed onto the operand stack.

Linking Exceptions

> During resolution of the symbolic reference to the interface method, any of the exceptions documented in §5.4.3.4 can be thrown.

Runtime Exceptions

> Otherwise, if objectref is `null`, the invokeinterface instruction throws a `NullPointerException`.

> Otherwise, if the class of objectref does not implement the resolved interface, invokeinterface throws an `IncompatibleClassChangeError`.

> Otherwise, if no method matching the resolved name and descriptor is selected, invokeinterface throws an `AbstractMethodError`.

> Otherwise, if the selected method is not `public`, invokeinterface throws an `IllegalAccessError`.

> Otherwise, if the selected method is `abstract`, invokeinterface throws an `AbstractMethodError`.

> Otherwise, if the selected method is `native` and the code that implements the method cannot be bound, invokeinterface throws an `UnsatisfiedLinkError`.

Notes

> The count operand of the invokeinterface instruction records a measure of the number of argument values, where an argument value of type `long` or type `double` contributes two units to the count value and an argument of any other type contributes one unit. This information can also be derived from the descriptor of the selected method. The redundancy is historical.

> The fourth operand byte exists to reserve space for an additional operand used in certain of Sun's implementations, which replace the invokeinterface instruction by a specialized pseudo-instruction at run time. It must be retained for backwards compatibility.

> The nargs argument values and objectref are not one-to-one with the first nargs + 1 local variables. Argument values of types `long` and `double` must be stored in two consecutive local variables, thus more than nargs local variables may be required to pass nargs argument values to the invoked method.

## invokespecial

Operation

> Invoke instance method; special handling for superclass, private, and instance initialization method invocations

Format

> invokespecial
> indexbyte1
> indexbyte2

Forms

> invokespecial = 183 (0xb7)

Operand Stack

> ..., objectref, [arg1, [arg2 ...]] ...

Description

> The unsigned indexbyte1 and indexbyte2 are used to construct an index into the runtime constant pool of the current class (§3.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The runtime constant pool item at that index must be a symbolic reference to a method (§5.1), which gives the name and descriptor (§4.3.3) of the method as well as a symbolic reference to the class in which the method is to be found. The named method is resolved (§5.4.3.3). Finally, if the resolved method is `protected` (§4.6), and it is either a member of the current class or a member of a superclass of the current class, then the class of objectref must be either the current class or a subclass of the current class.

> Next, the resolved method is selected for invocation unless all of the following conditions are true:

- The `ACC_SUPER` flag (see Table 4.1, "Class access and property modifiers") is set for the current class.

- The class of the resolved method is a superclass of the current class.

- The resolved method is not an instance initialization method (§3.9).

> If the above conditions are true, the actual method to be invoked is selected by the following lookup procedure. Let C be the direct superclass of the current class:

- If C contains a declaration for an instance method with the same name and descriptor as the resolved method, then this method will be invoked. The lookup procedure terminates.

- Otherwise, if C has a superclass, this same lookup procedure is performed recursively using the direct superclass of C. The method to be invoked is the result of the recursive invocation of this lookup procedure.

- Otherwise, an `AbstractMethodError` is raised.

> The objectref must be of type `reference` and must be followed on the operand stack by nargs argument values, where the number, type, and order of the values must be consistent with the descriptor of the selected instance method.

> If the method is `synchronized`, the monitor associated with objectref is acquired or reentered.

> If the method is not `native`, the nargs argument values and objectref are popped from the operand stack. A new frame is created on the Java virtual machine stack for the method being invoked. The objectref and the argument values are consecutively made the values of local variables of the new frame, with objectref in local variable 0, arg1 in local variable 1 (or, if arg1 is of type `long` or `double`, in local variables 1 and 2), and so on. Any argument value that is of a floating-point type undergoes value set conversion (§3.8.3) prior to being stored in a local variable. The new frame is then made current, and the Java virtual machine `pc` is set to the opcode of the first instruction of the method to be invoked. Execution continues with the first instruction of the method.

> If the method is `native` and the platform-dependent code that implements it has not yet been bound (§5.6) into the Java virtual machine, that is done. The nargs argument values and objectref are popped from the operand stack and are passed as parameters to the code that implements the method. Any argument value that is of a floating-point type undergoes value set conversion (§3.8.3) prior to being passed as a parameter. The parameters are passed and the code is invoked in an implementation-dependent manner. When the platform-dependent code returns, the following take place:

- If the `native` method is `synchronized`, the monitor associated with objectref is released or exited as if by execution of a monitorexit instruction.

- If the `native` method returns a value, the return value of the platform-dependent code is converted in an implementation-dependent way to the return type of the `native` method and pushed onto the operand stack.

Linking Exceptions

> During resolution of the symbolic reference to the method, any of the exceptions pertaining to method resolution documented in Section 5.4.3.3 can be thrown.

> Otherwise, if the resolved method is an instance initialization method, and the class in which it is declared is not the class symbolically referenced by the instruction, a `NoSuchMethodError` is thrown.

> Otherwise, if the resolved method is a class (`static`) method, the invokespecial instruction throws an `IncompatibleClassChangeError`.

> Otherwise, if no method matching the resolved name and descriptor is selected, invokespecial throws an `AbstractMethodError`.

> Otherwise, if the selected method is `abstract`, invokespecial throws an `AbstractMethodError`.

Runtime Exceptions

> Otherwise, if objectref is `null`, the invokespecial instruction throws a `NullPointerException`.

> Otherwise, if the selected method is `native` and the code that implements the method cannot be bound, invokespecial throws an `UnsatisfiedLinkError`.

Notes

> The difference between the invokespecial and the invokevirtual instructions is that invokevirtual invokes a method based on the class of the object. The invokespecial instruction is used to invoke instance initialization methods (§3.9) as well as `private` methods and methods of a superclass of the current class.

> The invokespecial instruction was named invokenonvirtual prior to Sun's JDK release 1.0.2.

> The nargs argument values and objectref are not one-to-one with the first nargs + 1 local variables. Argument values of types `long` and `double` must be stored in two consecutive local variables, thus more than nargs local variables may be required to pass nargs argument values to the invoked method.

## invokestatic

Operation

> Invoke a class (`static`) method

Format

> invokestatic
> indexbyte1
> indexbyte2

Forms

> invokestatic = 184 (0xb8)

Operand Stack

> ..., [arg1, [arg2 ...]] ...

Description

> The unsigned indexbyte1 and indexbyte2 are used to construct an index into the runtime constant pool of the current class (§3.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The runtime constant pool item at that index must be a symbolic reference to a method (§5.1), which gives the name and descriptor (§4.3.3) of the method as well as a symbolic reference to the class in which the method is to be found. The named method is resolved (§5.4.3.3). The method must not be the class or interface initialization method (§3.9). It must be `static`, and therefore cannot be `abstract`.

> On successful resolution of the method, the class that declared the resolved field is initialized (§5.5) if that class has not already been initialized.

> The operand stack must contain nargs argument values, where the number, type, and order of the values must be consistent with the descriptor of the resolved method.

> If the method is `synchronized`, the monitor associated with the resolved class is acquired or reentered.

> If the method is not `native`, the nargs argument values are popped from the operand stack. A new frame is created on the Java virtual machine stack for the method being invoked. The nargs argument values are consecutively made the values of local variables of the new frame, with arg1 in local variable 0 (or, if arg1 is of type `long` or `double`, in local variables 0 and 1) and so on. Any argument value that is of a floating-point type undergoes value set conversion (§3.8.3) prior to being stored in a local variable. The new frame is then made current, and the Java virtual machine `pc` is set to the opcode of the first instruction of the method to be invoked. Execution continues with the first instruction of the method.

> If the method is `native` and the platform-dependent code that implements it has not yet been bound (§5.6) into the Java virtual machine, that is done. The nargs argument values are popped from the operand stack and are passed as parameters to the code that implements the method. Any argument value that is of a floating-point type undergoes value set conversion (§3.8.3) prior to being passed as a parameter. The parameters are passed and the code is invoked in an implementation-dependent manner. When the platform-dependent code returns, the following take place:

- If the `native` method is `synchronized`, the monitor associated with the resolved class is released or exited as if by execution of a monitorexit instruction.

- If the `native` method returns a value, the return value of the platform-dependent code is converted in an implementation-dependent way to the return type of the `native` method and pushed onto the operand stack.

Linking Exceptions

> During resolution of the symbolic reference to the method, any of the exceptions pertaining to method resolution documented in Section 5.4.3.3 can be thrown.

> Otherwise, if the resolved method is an instance method, the invokestatic instruction throws an `IncompatibleClassChangeError`.

Runtime Exceptions

> Otherwise, if execution of this invokestatic instruction causes initialization of the referenced class, invokestatic may throw an `Error` as detailed in Section 2.17.5.

> Otherwise, if the resolved method is `native` and the code that implements the method cannot be bound, invokestatic throws an `UnsatisfiedLinkError`.

Notes

> The nargs argument values are not one-to-one with the first nargs local variables. Argument values of types `long` and `double` must be stored in two consecutive local variables, thus more than nargs local variables may be required to pass nargs argument values to the invoked method.

## invokevirtual

Operation

> Invoke instance method; dispatch based on class

Format

> invokevirtual
> indexbyte1
> indexbyte2

Forms

> invokevirtual = 182 (0xb6)

Operand Stack

> ..., objectref, [arg1, [arg2 ...]] ...

Description

> The unsigned indexbyte1 and indexbyte2 are used to construct an index into the runtime constant pool of the current class (§3.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The runtime constant pool item at that index must be a symbolic reference to a method (§5.1), which gives the name and descriptor (§4.3.3) of the method as well as a symbolic reference to the class in which the method is to be found. The named method is resolved (§5.4.3.3). The method must not be an instance initialization method (§3.9) or the class or interface initialization method (§3.9). Finally, if the resolved method is `protected` (§4.6), and it is either a member of the current class or a member of a superclass of the current class, then the class of objectref must be either the current class or a subclass of the current class.

> Let C be the class of objectref. The actual method to be invoked is selected by the following lookup procedure:

- If C contains a declaration for an instance method with the same name and descriptor as the resolved method, and the resolved method is accessible from C, then this is the method to be invoked, and the lookup procedure terminates.

- Otherwise, if C has a superclass, this same lookup procedure is performed recursively using the direct superclass of C ; the method to be invoked is the result of the recursive invocation of this lookup procedure.

- Otherwise, an `AbstractMethodError` is raised.

> The objectref must be followed on the operand stack by nargs argument values, where the number, type, and order of the values must be consistent with the descriptor of the selected instance method.

> If the method is `synchronized`, the monitor associated with objectref is acquired or reentered.

> If the method is not `native`, the nargs argument values and objectref are popped from the operand stack. A new frame is created on the Java virtual machine stack for the method being invoked. The objectref and the argument values are consecutively made the values of local variables of the new frame, with objectref in local variable 0, arg1 in local variable 1 (or, if arg1 is of type `long` or `double`, in local variables 1 and 2), and so on. Any argument value that is of a floating-point type undergoes value set conversion (§3.8.3) prior to being stored in a local variable. The new frame is then made current, and the Java virtual machine `pc` is set to the opcode of the first instruction of the method to be invoked. Execution continues with the first instruction of the method.

> If the method is `native` and the platform-dependent code that implements it has not yet been bound (§5.6) into the Java virtual machine, that is done. The nargs argument values and objectref are popped from the operand stack and are passed as parameters to the code that implements the method. Any argument value that is of a floating-point type undergoes value set conversion (§3.8.3) prior to being passed as a parameter. The parameters are passed and the code is invoked in an implementation-dependent manner. When the platform-dependent code returns, the following take place:

- If the `native` method is `synchronized`, the monitor associated with objectref is released or exited as if by execution of a monitorexit instruction.

- If the `native` method returns a value, the return value of the platform-dependent code is converted in an implementation-dependent way to the return type of the `native` method and pushed onto the operand stack.

Linking Exceptions

> During resolution of the symbolic reference to the method, any of the exceptions pertaining to method resolution documented in Section 5.4.3.3 can be thrown.

> Otherwise, if the resolved method is a class (`static`) method, the invokevirtual instruction throws an `IncompatibleClassChangeError`.

Runtime Exceptions

> Otherwise, if objectref is `null`, the invokevirtual instruction throws a `NullPointerException`.

> Otherwise, if no method matching the resolved name and descriptor is selected, invokevirtual throws an `AbstractMethodError`.

> Otherwise, if the selected method is `abstract`, invokevirtual throws an `AbstractMethodError`.

> Otherwise, if the selected method is `native` and the code that implements the method cannot be bound, invokevirtual throws an `UnsatisfiedLinkError`.

Notes

> The nargs argument values and objectref are not one-to-one with the first nargs + 1 local variables. Argument values of types `long` and `double` must be stored in two consecutive local variables, thus more than nargs local variables may be required to pass nargs argument values to the invoked method.

## ior

Operation

> Boolean OR `int`

Format

> ior

Forms

> ior = 128 (0x80)

Operand Stack

> ..., value1, value2 ..., result

Description

> Both value1 and value2 must be of type `int`. They are popped from the operand stack. An `int` result is calculated by taking the bitwise inclusive OR of value1 and value2. The result is pushed onto the operand stack.

## irem

Operation

> Remainder `int`

Format

> irem

Forms

> irem = 112 (0x70)

Operand Stack

> ..., value1, value2 ..., result

Description

> Both value1 and value2 must be of type `int`. The values are popped from the operand stack. The `int` result is value1 - (value1 / value2) * value2. The result is pushed onto the operand stack.

> The result of the irem instruction is such that `(a`/`b)*b` + `(a%b)` is equal to `a`. This identity holds even in the special case in which the dividend is the negative `int` of largest possible magnitude for its type and the divisor is -`1` (the remainder is `0`). It follows from this rule that the result of the remainder operation can be negative only if the dividend is negative and can be positive only if the dividend is positive. Moreover, the magnitude of the result is always less than the magnitude of the divisor.

Runtime Exception

> If the value of the divisor for an `int` remainder operator is 0, irem throws an `ArithmeticException`.

## ireturn

Operation

> Return `int` from method

Format

> ireturn

Forms

> ireturn = 172 (0xac)

Operand Stack

> ..., value [empty]

Description

> The current method must have return type `boolean`, `byte`, `short`, `char`, or `int`. The value must be of type `int`. If the current method is a `synchronized` method, the monitor acquired or reentered on invocation of the method is released or exited (respectively) as if by execution of a monitorexit instruction. If no exception is thrown, value is popped from the operand stack of the current frame (§3.6) and pushed onto the operand stack of the frame of the invoker. Any other values on the operand stack of the current method are discarded.

> The interpreter then returns control to the invoker of the method, reinstating the frame of the invoker.

Runtime Exceptions

> If the current method is a `synchronized` method and the current thread is not the owner of the monitor acquired or reentered on invocation of the method, ireturn throws an `IllegalMonitorStateException`. This can happen, for example, if a `synchronized` method contains a monitorexit instruction, but no monitorenter instruction, on the object on which the method is synchronized.

> Otherwise, if the virtual machine implementation enforces the rules on structured use of locks described in Section 8.13 and if the first of those rules is violated during invocation of the current method, then ireturn throws an `IllegalMonitorStateException`.

## ishl

Operation

> Shift left `int`

Format

> ishl

Forms

> ishl = 120 (0x78)

Operand Stack

> ..., value1, value2 ..., result

Description

> Both value1 and value2 must be of type `int`. The values are popped from the operand stack. An `int` result is calculated by shifting value1 left by s bit positions, where s is the value of the low 5 bits of value2. The result is pushed onto the operand stack.

Notes

> This is equivalent (even if overflow occurs) to multiplication by 2 to the power s. The shift distance actually used is always in the range 0 to 31, inclusive, as if value2 were subjected to a bitwise logical AND with the mask value 0x1f.

## ishr

Operation

> Arithmetic shift right `int`

Format

> ishr

Forms

> ishr = 122 (0x7a)

Operand Stack

> ..., value1, value2 ..., result

Description

> Both value1 and value2 must be of type `int`. The values are popped from the operand stack. An `int` result is calculated by shifting value1 right by s bit positions, with sign extension, where s is the value of the low 5 bits of value2. The result is pushed onto the operand stack.

Notes

> The resulting value is , where s is value2 & 0x1f. For nonnegative value1, this is equivalent to truncating `int` division by 2 to the power s. The shift distance actually used is always in the range 0 to 31, inclusive, as if value2 were subjected to a bitwise logical AND with the mask value 0x1f.

## istore

Operation

> Store `int` into local variable

Format

> istore
> index

Forms

> istore = 54 (0x36)

Operand Stack

> ..., value ...

Description

> The index is an unsigned byte that must be an index into the local variable array of the current frame (§3.6). The value on the top of the operand stack must be of type `int`. It is popped from the operand stack, and the value of the local variable at index is set to value.

Notes

> The istore opcode can be used in conjunction with the wide instruction to access a local variable using a two-byte unsigned index.

## istore_<n>

Operation

> Store `int` into local variable

Format

> istore_<n>

Forms

> istore_0 = 59 (0x3b) istore_1 = 60 (0x3c) istore_2 = 61 (0x3d) istore_3 = 62 (0x3e)

Operand Stack

> ..., value ...

Description

> The <n> must be an index into the local variable array of the current frame (§3.6). The value on the top of the operand stack must be of type `int`. It is popped from the operand stack, and the value of the local variable at <n> is set to value.

Notes

> Each of the istore_<n> instructions is the same as istore with an index of <n>, except that the operand <n> is implicit.

## isub

Operation

> Subtract `int`

Format

> isub

Forms

> isub = 100 (0x64)

Operand Stack

> ..., value1, value2 ..., result

Description

> Both value1 and value2 must be of type `int`. The values are popped from the operand stack. The `int` result is value1 - value2. The result is pushed onto the operand stack.

> For `int` subtraction, `a` - `b` produces the same result as `a` + (-`b`). For `int` values, subtraction from zero is the same as negation.

> The result is the 32 low-order bits of the true mathematical result in a sufficiently wide two's-complement format, represented as a value of type `int`. If overflow occurs, then the sign of the result may not be the same as the sign of the mathematical sum of the two values.

> Despite the fact that overflow may occur, execution of an isub instruction never throws a runtime exception.

## iushr

Operation

> Logical shift right `int`

Format

> iushr

Forms

> iushr = 124 (0x7c)

Operand Stack

> ..., value1, value2 ..., result

Description

> Both value1 and value2 must be of type `int`. The values are popped from the operand stack. An `int` result is calculated by shifting value1 right by s bit positions, with zero extension, where s is the value of the low 5 bits of value2. The result is pushed onto the operand stack.

Notes

> If value1 is positive and s is value2 & 0x1f, the result is the same as that of value1 >> s; if value1 is negative, the result is equal to the value of the expression (value1 >> s) + (2 << ~s). The addition of the (2 << ~s) term cancels out the propagated sign bit. The shift distance actually used is always in the range 0 to 31, inclusive.

## ixor

Operation

> Boolean XOR `int`

Format

> ixor

Forms

> ixor = 130 (0x82)

Operand Stack

> ..., value1, value2 ..., result

Description

> Both value1 and value2 must be of type `int`. They are popped from the operand stack. An `int` result is calculated by taking the bitwise exclusive OR of value1 and value2. The result is pushed onto the operand stack.

Contents | Prev | Next | Index

The JavaTM Virtual Machine Specification
Copyright © 1999 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to jvm@java.sun.com