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.

55<br />

the stack challenging in some cases. As a result, the less than relationship is replaced<br />

with a greater than relationship by switching the order of the values once they are<br />

already present on the operand stack. This is accomplished using a swap bytecode.<br />

Once the order of the values has been swapped, the greater than relationship can be<br />

used in order to achieve the same result as the original less than relationship. This<br />

is illustrated in Figure 4.6 which shows the sequence of bytecodes before and after<br />

branch despecialization is performed. A similar transformation can be employed in<br />

order to express uses of the less than or equal relationship in terms of the greater<br />

than or equal relationship.<br />

4.1.6 Widening Despecializations<br />

Widening despecializations increase the number of bytes that are used to represent an<br />

integer value. For example, bipush is normally used to generate most constant values<br />

between -128 and 127. The value that is placed on the stack is dictated by a single<br />

operand byte that immediately follows the opcode. The sipush opcode makes use of<br />

two operand bytes in order to facilitate generating any constant value between -32768<br />

and 32767. As a result, replacing occurrences of bipush with sipush is classified as a<br />

widening despecialization because the number of bytes used to represent the constant<br />

has increased, or been widened, from one byte to two bytes.<br />

Despecializing occurrences of sipush by replacing them with either ldc or ldc w<br />

is also an example of a widening despecialization. In this case, the number of operand<br />

bytes that appear in the code stream is not increased. In fact, if the constant pool<br />

contains less than 256 elements, allowing an ldc bytecode to be used for despecialization,<br />

the number of operand bytes in the code stream actually decreases by one.<br />

However, the constant value in the constant pool is expressed using four bytes regardless<br />

of its magnitude. As a result, replacing sipush with either ldc or ldc w is a<br />

widening despecialization because the number of bytes used to express the constant<br />

value that is being loaded has increased from two bytes to four bytes.<br />

It is also possible to despecialize all occurrences of the ldc bytecode. The ldc w<br />

bytecode is used in its place. This is a widening despecialization because ldc uses<br />

a single operand byte in order to specify an offset into the constant pool between 1<br />

and 255 1 . The ldc w bytecode uses two operand bytes in order to specify its offset<br />

into the constant pool. As a result, it can be used to access all of the slots normally<br />

1 The Java Virtual Machine Specification requires that constant pool entry 0 remain unused with<br />

the intent that this location store a pointer to virtual machine implementation specific data. As a<br />

result, ldc will never refer to position zero in the constant pool.

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

Saved successfully!

Ooh no, something went wrong!