Contents | Prev | Next | Index | The JavaTM Virtual Machine Specification |
Operation
Loadreference
from array
Format
aaload
Forms
aaload = 50 (0x32)
Operand Stack
..., arrayref, index ..., value
Description
The arrayref must be of typereference
and must refer to an array whose components are of typereference
. The index must be of typeint
. Both arrayref and index are popped from the operand stack. Thereference
value in the component of the array at index is retrieved and pushed onto the operand stack.
Runtime Exceptions
If arrayref isnull
, aaload throws aNullPointerException
.
Otherwise, if index is not within the bounds of the array referenced by arrayref, the aaload instruction throws anArrayIndex
OutOfBoundsException
.
Operation
Store intoreference
array
Format
aastore
Forms
aastore = 83 (0x53)
Operand Stack
..., arrayref, index, value ...
Description
The arrayref must be of typereference
and must refer to an array whose components are of typereference
. The index must be of typeint
and value must be of typereference
. The arrayref, index, and value are popped from the operand stack. Thereference
value is stored as the component of the array at index.
The type of value must be assignment compatible (§2.6.7) with the type of the components of the array referenced by arrayref. Assignment of a value of reference type S (source) to a variable of reference type T (target) is allowed only when the type S supports all the operations defined on type T. The detailed rules follow:
[]
, that is, an array of components of type SC, then:
Runtime Exceptions
If arrayref isnull
, aastore throws aNullPointerException
.
Otherwise, if index is not within the bounds of the array referenced by arrayref, the aastore instruction throws an ArrayIndexOutOfBoundsException
.
Otherwise, if arrayref is notnull
and the actual type of value is not assignment compatible (§2.6.7) with the actual type of the components of the array, aastore throws anArrayStoreException
.
Operation
Pushnull
Format
aconst_null
Forms
aconst_null = 1 (0x1)
Operand Stack
... ..., null
Description
Push thenull
objectreference
onto the operand stack.
Notes
The Java virtual machine does not mandate a concrete value for null
.
Operation
Loadreference
from local variable
Format
aload index
Forms
aload = 25 (0x19)
Operand Stack
... ..., objectref
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 a reference
. The objectref in the local variable at index is pushed onto the operand stack.
Notes
The aload instruction cannot be used to load a value of type returnAddress
from a local variable onto the operand stack. This asymmetry with the astore instruction is intentional.
The aload opcode can be used in conjunction with the wide instruction to access a local variable using a two-byte unsigned index.
Operation
Loadreference
from local variable
Format
aload_<n>
Forms
aload_0 = 42 (0x2a) aload_1 = 43 (0x2b) aload_2 = 44 (0x2c) aload_3 = 45 (0x2d)
Operand Stack
... ..., objectref
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 a reference
. The objectref in the local variable at index is pushed onto the operand stack.
Notes
An aload_<n> instruction cannot be used to load a value of type returnAddress
from a local variable onto the operand stack. This asymmetry with the corresponding astore_<n> instruction is intentional. Each of the aload_<n> instructions is the same as aload with an index of <n>, except that the operand <n> is implicit.
Operation
Create new array ofreference
Format
anewarray indexbyte1 indexbyte2
Forms
anewarray = 189 (0xbd)
Operand Stack
..., count ..., arrayref
Description
The count must be of typeint
. It is popped off the operand stack. The count represents the number of components of the array to be created. 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 class, array, or interface type. The named class, array, or interface type is resolved (§5.4.3.1). A new array with components of that type, of length count, is allocated from the garbage-collected heap, and areference
arrayref to this new array object is pushed onto the operand stack. All components of the new array are initialized tonull
, the default value forreference
types (§2.5.1).
Linking Exceptions
During resolution of the symbolic reference to the class, array, or interface type, any of the exceptions documented in §5.4.3.1 can be thrown.
Runtime Exception
Otherwise, if count is less than zero, the anewarray instruction throws a NegativeArraySizeException
.
Notes
The anewarray instruction is used to create a single dimension of an array of object references or part of a multidimensional array.
Operation
Returnreference
from method
Format
areturn
Forms
areturn = 176 (0xb0)
Operand Stack
..., objectref [empty]
Description
The objectref must be of typereference
and must refer to an object of a type that is assignment compatible (§2.6.7) with the type represented by the return descriptor (§4.3.3) of the current method. 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, objectref 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 reinstates the frame of the invoker and returns control to 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, areturn 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 §8.13 and if the first of those rules is violated during invocation of the current method, then areturn throws an IllegalMonitorStateException
.
Operation
Get length of array
Format
arraylength
Forms
arraylength = 190 (0xbe)
Operand Stack
..., arrayref ..., length
Description
The arrayref must be of typereference
and must refer to an array. It is popped from the operand stack. The length of the array it references is determined. That length is pushed onto the operand stack as anint
.
Runtime Exception
If the arrayref isnull
, the arraylength instruction throws aNullPointerException
.
Operation
Storereference
into local variable
Format
astore index
Forms
astore = 58 (0x3a)
Operand Stack
..., objectref ...
Description
The index is an unsigned byte that must be an index into the local variable array of the current frame (§3.6). The objectref on the top of the operand stack must be of typereturnAddress
or of typereference
. It is popped from the operand stack, and the value of the local variable at index is set to objectref.
Notes
The astore instruction is used with an objectref of typereturn
Address
when implementing thefinally
clauses of the Java programming language (see Section 7.13, "Compilingfinally
"). The aload instruction cannot be used to load a value of typereturnAddress
from a local variable onto the operand stack. This asymmetry with the astore instruction is intentional.
The astore opcode can be used in conjunction with the wide instruction to access a local variable using a two-byte unsigned index.
Operation
Storereference
into local variable
Format
astore_<n>
Forms
astore_0 = 75 (0x4b) astore_1 = 76 (0x4c) astore_2 = 77 (0x4d) astore_3 = 78 (0x4e)
Operand Stack
..., objectref ...
Description
The <n> must be an index into the local variable array of the current frame (§3.6). The objectref on the top of the operand stack must be of typereturnAddress
or of typereference
. It is popped from the operand stack, and the value of the local variable at <n> is set to objectref.
Notes
An astore_<n> instruction is used with an objectref of typereturnAddress
when implementing thefinally
clauses of the Java programming language (see Section 7.13, "Compilingfinally
"). An aload_<n> instruction cannot be used to load a value of typereturnAddress
from a local variable onto the operand stack. This asymmetry with the corresponding astore_<n> instruction is intentional.
Each of the astore_<n> instructions is the same as astore with an index of <n>, except that the operand <n> is implicit.
Operation
Throw exception or error
Format
athrow
Forms
athrow = 191 (0xbf)
Operand Stack
..., objectref objectref
Description
The objectref must be of typereference
and must refer to an object that is an instance of classThrowable
or of a subclass ofThrowable
. It is popped from the operand stack. The objectref is then thrown by searching the current method (§3.6) for the first exception handler that matches the class of objectref, as given by the algorithm in §3.10.
If an exception handler that matches objectref is found, it contains the location of the code intended to handle this exception. The pc
register is reset to that location, the operand stack of the current frame is cleared, objectref is pushed back onto the operand stack, and execution continues.
If no matching exception handler is found in the current frame, that frame is popped. If the current frame represents an invocation of 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. Finally, the frame of its invoker is reinstated, if such a frame exists, and the objectref is rethrown. If no such frame exists, the current thread exits.
Runtime Exceptions
If objectref isnull
, athrow throws aNullPointerException
instead of objectref.
Otherwise, if the method of the current frame is asynchronized
method and the current thread is not the owner of the monitor acquired or reentered on invocation of the method, athrow throws anIllegalMonitorStateException
instead of the object previously being thrown. This can happen, for example, if an abruptly completingsynchronized
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 §8.13 and if the first of those rules is violated during invocation of the current method, then athrow throws an IllegalMonitorStateException
instead of the object previously being thrown.
Notes
The operand stack diagram for the athrow instruction may be misleading: If a handler for this exception is matched in the current method, the athrow instruction discards all the values on the operand stack, then pushes the thrown object onto the operand stack. However, if no handler is matched in the current method and the exception is thrown farther up the method invocation chain, then the operand stack of the method (if any) that handles the exception is cleared and objectref is pushed onto that empty operand stack. All intervening frames from the method that threw the exception up to, but not including, the method that handles the exception are discarded.
Contents | Prev | Next | Index
The JavaTM Virtual Machine Specification
Copyright © 1999 Sun Microsystems, Inc.
All rights reserved
Please send any comments or corrections to [email protected]