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.

171<br />

// iload_1:<br />

stack[sp+1] = local_vars[1];<br />

// iconst_1:<br />

stack[sp+2] = 1;<br />

// iadd:<br />

stack[sp+1] = stack[sp+1] + stack[sp+2];<br />

// istore_2:<br />

local_vars[2] = stack[sp+1];<br />

In theory, an optimizing compiler should be able to remove all of these stack<br />

adjustments. In practice, it was found that this was not the case. Testing was performed<br />

on the actual codelets used by the Kaffe virtual machine. They differ slightly<br />

from the codelets presented here because Kaffe uses a pointer based representation<br />

for the stack instead of an integer index. When those codelets were evaluated, it was<br />

observed that the assembly language code generated by g++ using optimization level<br />

4 is different for each of these code segments. The assembly language code for the<br />

case when the stack adjustments were removed by hand is 3 lines shorter than the<br />

assembly language code generated for the original code. The longer code is the result<br />

of two places where the stack pointer is still explicitly adjusted. The third is present<br />

because the final assignment from stack[sp+1] to local vars[2] is performed as<br />

written when the stack adjustments are present. When the stack adjustments are<br />

removed, this assignment is performed by making use of the fact that the value of<br />

stack[sp+1] was already present in a register.<br />

Further optimizations can be performed which are impossible for any optimizing<br />

compiler to perform. While the programmer has assigned stack semantics to the stack<br />

array, there is no way for the compiler to know this. Consequently, any optimizations<br />

that can be derived from the properties of a stack are not available to a general<br />

purpose compiler. Since sp points to the slot which represents the top of the stack at<br />

any given point in time, it is known that any location beyond stack[sp] represents<br />

a location that is beyond the top of the stack. A stack can only grow to encompass<br />

such memory locations again by performing push operations. Therefore, it is known<br />

conclusively that, outside of the codelet for the multicode being optimized, these<br />

memory locations will be written to before they are read again. As a result, any<br />

writes to such memory locations are unnecessary provided that they are not read<br />

subsequently within the same codelet.

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

Saved successfully!

Ooh no, something went wrong!