Java Reference
In-Depth Information
(or compute) its address. For the JVM, an object reference will be pushed onto
the stack. Code generators for other architectures will load an array address
into a register.
Next, at Marker 43 , the array index is computed. The JVM will push its
value onto the stack; other architectures will load or compute the index into a
register. Finally, at Marker 44 , an array element is loaded. On the JVM this
is simple ā€” special array load instructions use the array reference and index
values at the TOS to compute an array value and push it onto the stack. For
other architectures, several instructions may need to be generated. Using the
formulas detailed in Section 12.3.1 on page 460, the address of an array element
is computed using the address of the array, the value of the index, and the size
of individual array elements. The selected value is then loaded into a register.
If array bounds checking is activated, the index value is also compared against
the array's lower and upper bounds. In Java, bounds checking is automatically
included as part of the index operation.
AST
JVM Instructions
;
AST and code for fetching the
;
array element:
ArrayReferencing
;
;
ar[i]
;
;
Code generated for the array, ar
aload 3
;
Code generated for the index, i
aload 4
LocalReferencing
LocalReferencing
ar
i
;
Get the array element value
iaload
In the above example, assume array ar is local variable 3 and that index i is
local 4. These two values are pushed onto the stack. The instruction iaload
pops the array and index values and replaces them with the value of ar[i].
A variety of array load instructions exist, depending of the type of the array
element. The ā€iā€ prefex indicates that an integer is to be loaded.
 
Search WWH ::




Custom Search