Contents | Prev | Next | Index | The JavaTM Virtual Machine Specification |
Operation
Convertint
tobyte
Format
i2b
Forms
i2b = 145 (0x91)
Operand Stack
..., value ..., result
Description
The value on the top of the operand stack must be of typeint
. It is popped from the operand stack, truncated to abyte
, then sign-extended to anint
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.
Operation
Convertint
tochar
Format
i2c
Forms
i2c = 146 (0x92)
Operand Stack
..., value ..., result
Description
The value on the top of the operand stack must be of typeint
. It is popped from the operand stack, truncated tochar
, then zero-extended to anint
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.
Operation
Convertint
todouble
Format
i2d
Forms
i2d = 135 (0x87)
Operand Stack
..., value ..., result
Description
The value on the top of the operand stack must be of typeint
. It is popped from the operand stack and converted to adouble
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 typeint
are exactly representable by typedouble
, the conversion is exact.
Operation
Convertint
tofloat
Format
i2f
Forms
i2f = 134 (0x86)
Operand Stack
..., value ..., result
Description
The value on the top of the operand stack must be of typeint
. It is popped from the operand stack and converted to thefloat
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.
Operation
Convertint
tolong
Format
i2l
Forms
i2l = 133 (0x85)
Operand Stack
..., value ..., result
Description
The value on the top of the operand stack must be of typeint
. It is popped from the operand stack and sign-extended to along
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 typeint
are exactly representable by typelong
, the conversion is exact.
Operation
Convert
int
toshort
Format
i2s
Forms
i2s = 147 (0x93)
Operand Stack
..., value ..., result
Description
The value on the top of the operand stack must be of typeint
. It is popped from the operand stack, truncated to ashort
, then sign-extended to anint
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.
Operation
Addint
Format
iadd
Forms
iadd = 96 (0x60)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typeint
. The values are popped from the operand stack. Theint
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.
Operation
Loadint
from array
Format
iaload
Forms
iaload = 46 (0x2e)
Operand Stack
..., arrayref, index ..., value
Description
The arrayref must be of typereference
and must refer to an array whose components are of typeint
. The index must be of typeint
. Both arrayref and index are popped from the operand stack. Theint
value in the component of the array at index is retrieved and pushed onto the operand stack.
Runtime Exceptions
If arrayref isnull
, iaload throws aNullPointerException
.
Otherwise, if index is not within the bounds of the array referenced by arrayref, the iaload instruction throws an ArrayIndexOutOfBoundsException
.
Operation
Boolean ANDint
Format
iand
Forms
iand = 126 (0x7e)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typeint
. They are popped from the operand stack. Anint
result is calculated by taking the bitwise AND (conjunction) of value1 and value2. The result is pushed onto the operand stack.
Operation
Store intoint
array
Format
iastore
Forms
iastore = 79 (0x4f)
Operand Stack
..., arrayref, index, value ...
Description
The arrayref must be of typereference
and must refer to an array whose components are of typeint
. Both index and value must be of typeint
. The arrayref, index, and value are popped from the operand stack. Theint
value is stored as the component of the array indexed by index.
Runtime Exceptions
If arrayref isnull
, iastore throws aNullPointerException
.
Otherwise, if index is not within the bounds of the array referenced by arrayref, the iastore instruction throws an ArrayIndexOutOfBoundsException
.
Operation
Pushint
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.
Operation
Divideint
Format
idiv
Forms
idiv = 108 (0x6c)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typeint
. The values are popped from the operand stack. Theint
result is the value of the Java programming language expression value1 / value2. The result is pushed onto the operand stack.
Anint
division rounds towards 0; that is, the quotient produced forint
values in n/d is anint
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 anint
division is 0, idiv throws anArithmeticException
.
Operation
Branch ifreference
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:
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.
Operation
Branch ifint
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:
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.
Operation
Branch ifint
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:
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.
Operation
Branch ifreference
notnull
Format
ifnonnull branchbyte1 branchbyte2
Forms
ifnonnull = 199 (0xc7)
Operand Stack
..., value ...
Description
The value must be of typereference
. It is popped from the operand stack. If value is notnull
, 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.
Operation
Branch ifreference
isnull
Format
ifnull branchbyte1 branchbyte2
Forms
ifnull = 198 (0xc6)
Operand Stack
..., value ...
Description
The value must of typereference
. It is popped from the operand stack. If value isnull
, 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.
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 anint
. The value const is first sign-extended to anint
, 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.
Operation
Loadint
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.
Operation
Loadint
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.
Multiplyint
Format
imul
Forms
imul = 104 (0x68)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typeint
. The values are popped from the operand stack. Theint
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.
Operation
Negateint
Format
ineg
Forms
ineg = 116 (0x74)
Operand Stack
..., value ..., result
Description
The value must be of typeint
. It is popped from the operand stack. Theint
result is the arithmetic negation of value, -value. The result is pushed onto the operand stack.
Forint
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 negativeint
results in that same maximum negative number. Despite the fact that overflow has occurred, no exception is thrown.
For allint
valuesx
, -x
equals (~x
) +1
.
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 notnull
and is an instance of the resolved class or array or implements the resolved interface, the instanceof instruction pushes anint
result of 1 as an int on the operand stack. Otherwise, it pushes anint
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:
[]
, that is, an array of components of type SC, then:
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.
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:
AbstractMethodError
is raised.
If the method is synchronized
, the monitor associated with objectref is acquired or reentered.
If the method is notnative
, 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 typelong
ordouble
, 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 machinepc
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:
native
method is synchronized
, the monitor associated with objectref is released or exited as if by execution of a monitorexit instruction.
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 isnull
, the invokeinterface instruction throws aNullPointerException
.
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 notpublic
, invokeinterface throws anIllegalAccessError
.
Otherwise, if the selected method isabstract
, invokeinterface throws anAbstractMethodError
.
Otherwise, if the selected method isnative
and the code that implements the method cannot be bound, invokeinterface throws anUnsatisfiedLinkError
.
Notes
The count operand of the invokeinterface instruction records a measure of the number of argument values, where an argument value of typelong
or typedouble
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 typeslong
anddouble
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.
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:
ACC_SUPER
flag (see Table 4.1, "Class access and property modifiers") is set for the current class.
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:
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 notnative
, 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 typelong
ordouble
, 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 machinepc
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:
native
method is synchronized
, the monitor associated with objectref is released or exited as if by execution of a monitorexit instruction.
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 anIncompatibleClassChangeError
.
Otherwise, if no method matching the resolved name and descriptor is selected, invokespecial throws an AbstractMethodError
.
Otherwise, if the selected method isabstract
, invokespecial throws anAbstractMethodError
.
Runtime Exceptions
Otherwise, if objectref isnull
, the invokespecial instruction throws aNullPointerException
.
Otherwise, if the selected method isnative
and the code that implements the method cannot be bound, invokespecial throws anUnsatisfiedLinkError
.
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 typeslong
anddouble
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.
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 bestatic
, and therefore cannot beabstract
.
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 notnative
, 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 typelong
ordouble
, 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 machinepc
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:
native
method is synchronized
, the monitor associated with the resolved class is released or exited as if by execution of a monitorexit instruction.
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 isnative
and the code that implements the method cannot be bound, invokestatic throws anUnsatisfiedLinkError
.
Notes
The nargs argument values are not one-to-one with the first nargs local variables. Argument values of typeslong
anddouble
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.
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:
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 notnative
, 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 typelong
ordouble
, 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 machinepc
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:
native
method is synchronized
, the monitor associated with objectref is released or exited as if by execution of a monitorexit instruction.
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 anIncompatibleClassChangeError
.
Runtime Exceptions
Otherwise, if objectref isnull
, the invokevirtual instruction throws aNullPointerException
.
Otherwise, if no method matching the resolved name and descriptor is selected, invokevirtual throws an AbstractMethodError
.
Otherwise, if the selected method isabstract
, invokevirtual throws anAbstractMethodError
.
Otherwise, if the selected method isnative
and the code that implements the method cannot be bound, invokevirtual throws anUnsatisfiedLinkError
.
Notes
The nargs argument values and objectref are not one-to-one with the first nargs + 1 local variables. Argument values of typeslong
anddouble
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.
Operation
Boolean ORint
Format
ior
Forms
ior = 128 (0x80)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typeint
. They are popped from the operand stack. Anint
result is calculated by taking the bitwise inclusive OR of value1 and value2. The result is pushed onto the operand stack.
Operation
Remainderint
Format
irem
Forms
irem = 112 (0x70)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typeint
. The values are popped from the operand stack. Theint
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 toa
. This identity holds even in the special case in which the dividend is the negativeint
of largest possible magnitude for its type and the divisor is -1
(the remainder is0
). 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 anint
remainder operator is 0, irem throws anArithmeticException
.
Operation
Returnint
from method
Format
ireturn
Forms
ireturn = 172 (0xac)
Operand Stack
..., value [empty]
Description
The current method must have return typeboolean
,byte
,short
,char
, orint
. The value must be of typeint
. If the current method is asynchronized
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 asynchronized
method and the current thread is not the owner of the monitor acquired or reentered on invocation of the method, ireturn throws anIllegalMonitorStateException
. This can happen, for example, if asynchronized
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
.
Operation
Shift leftint
Format
ishl
Forms
ishl = 120 (0x78)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typeint
. The values are popped from the operand stack. Anint
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.
Operation
Arithmetic shift rightint
Format
ishr
Forms
ishr = 122 (0x7a)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typeint
. The values are popped from the operand stack. Anint
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.
Operation
Storeint
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.
Operation
Storeint
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.
Operation
Subtractint
Format
isub
Forms
isub = 100 (0x64)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typeint
. The values are popped from the operand stack. Theint
result is value1 - value2. The result is pushed onto the operand stack.
Forint
subtraction,a
-b
produces the same result asa
+ (-b
). Forint
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.
Operation
Logical shift rightint
Format
iushr
Forms
iushr = 124 (0x7c)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typeint
. The values are popped from the operand stack. Anint
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.
Operation
Boolean XORint
Format
ixor
Forms
ixor = 130 (0x82)
Operand Stack
..., value1, value2 ..., result
Description
Both value1 and value2 must be of typeint
. They are popped from the operand stack. Anint
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