13.10.2014 Views

OPTIMIZING THE JAVA VIRTUAL MACHINE INSTRUCTION SET BY ...

OPTIMIZING THE JAVA VIRTUAL MACHINE INSTRUCTION SET BY ...

OPTIMIZING THE JAVA VIRTUAL MACHINE INSTRUCTION SET BY ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

15<br />

...<br />

aload 3 iconst 2<br />

faload<br />

...<br />

i − 1<br />

i i + 1 i + 2<br />

i + 3<br />

Figure 2.3: A Code Stream Showing An Array Element Access<br />

dup dup x1 dup x2<br />

dup2 dup2 x1 dup2 x2<br />

pop pop2 swap<br />

Table 2.5: Stack Manipulation Bytecodes<br />

copy a pointer to the array onto the operand stack. The second bytecode utilized will<br />

be iconst 2. It will put the constant integer 2 onto the operand stack, specifying<br />

what index will be accessed. Finally, a faload bytecode will be used in order to pop<br />

the array pointer and index from the operand stack and replace them with a copy of<br />

the value stored at index 2 of the array.<br />

2.3.4 Stack Manipulation<br />

Most Java bytecodes are only permitted to access elements that are at the top of<br />

the operand stack. Occasionally, this restriction presents difficulties. Consequently,<br />

there are several bytecodes that are able to reorder stack values or duplicate values<br />

“trapped” under other operands on the stack. One such bytecode is swap, which<br />

reverses the order of the top two elements on the operand stack. Other bytecodes are<br />

capable of duplicating one or two elements that are located somewhere on the stack.<br />

The dup bytecode is the simplest of these, replicating the top element on the stack.<br />

Other variants of dup replicate elements from deeper within the stack. Each of the 9<br />

stack manipulation bytecodes are listed in Table 2.5.<br />

2.3.5 Arithmetic Operations<br />

Of the 201 bytecodes defined by the Java Virtual Machine Specification, 36 are devoted<br />

to arithmetic operations. These bytecodes are listed in Table 2.6. All bytecodes<br />

that perform arithmetic operations are typed. Their names begin with one of the<br />

characters listed in Table 2.2, which indicates the type of data that the operation<br />

is performed on. The values used as input to these arithmetic operations are read

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!