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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

169<br />

a larger portion of the instruction cache is required to hold the entire loop. Consequently,<br />

there is a greater possibility that portions of the main loop will be removed<br />

from the cache, resulting in more cache misses. In the worst case, the size of the interpreter<br />

loop will grow beyond the size of the instruction cache, causing instruction<br />

cache misses to occur with great frequency unless the application being executed uses<br />

only a small number of distinct bytecodes. These cache misses are expensive because<br />

the interpreter’s execution cannot proceed until the needed instructions are loaded<br />

from main memory.<br />

There is also a software engineering cost associated with introducing new multicodes.<br />

Because multicodes increase the number of cases within the interpreter’s main<br />

loop, they increase the amount of code that must be maintained and debugged. However,<br />

since the codelet that implements each multicode is generated automatically,<br />

and the total amount of new code that is added is small in comparison to the size<br />

of the virtual machine, the increased amount of code is not a large concern from a<br />

software engineering perspective.<br />

7.7 Multicode Optimization<br />

When the codelet that implements a multicode is formed, new optimization opportunities<br />

become available. The opportunities could not be utilized before the substitution<br />

was performed because of the intervening transfers of control present between<br />

each bytecode.<br />

A large number of optimizations can be performed. These optimizations can be<br />

divided into two categories:<br />

• Traditional optimizations such as constant folding, dead code elimination and<br />

common subexpression elimination.<br />

• Specialized optimization that exploit the stack semantics used by the virtual<br />

machine’s operand stack.<br />

Many of the traditional optimizations are performed automatically by the compiler<br />

when the virtual machine is compiled. However, the compiler is unable to perform<br />

the specialized optimizations that exploit the stack semantics used by the operand<br />

stack because it does not know that the array used to implement the operand stack<br />

behaves like a stack.<br />

An example will be used in order to demonstrate some of the optimizations that<br />

can be performed. Consider the bytecode sequence:

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

Saved successfully!

Ooh no, something went wrong!