Java Reference
In-Depth Information
dup_x1
This instruction duplicates the TOS element, but it sit-
uates the duplicated cell as shown in the example, two
cells below the TOS.
One application of this seemingly bizarre instruction
is the duplication of a value that participates in an
embedded assignment .Con id r
431
431
( this . x y ),
where y happens to have the value 431. The example
starts with y 's value already loaded on the stack. The
example ends with the stack prepared for the putfield
instruction followed by the method call to
foo
431
foo
.
Before
After
The dup_x1 instruction duplicates the 431 and places it below the this reference
(shown as
·
). Recall that the field assigned by a putfield is an immediate
operand of the instruction. Thus, when the putfield for x completes, the top
two elements will be removed from the stack, leaving the duplicated 431 as the
parameter value for
. This instruction nicely demonstrates that the JVM
instruction set was designed not to be simple but to allow for compact code
sequences. Exercise 11 explores this in greater detail.
foo
10.3 Static Single Assignment Form
The static single assignment (SSA) Form [CFR + 91] intermediate representa-
tion has properties that are beneficial for program analysis and optimization
(Chapter 14). The form is named after a property enjoyed by purely functional
languages: single assignment means that a name in a program is assigned
only once. This property makes the assignment
a b +
1amathematical
truth: after a b +
1fortherestof
the program's execution. Neither a nor b could change value due to the single-
assignment rule.
1 completes, a mathematically equals b +
In summary, the program assignment a b +
1translates
into the predicate a = b +
1, which persists indefinitely. This allows algebraic
substitution throughout the program of b +
1for a .
Such transparency makes programs arguably easier to analyze and op-
timize. Some would argue further that functional programs are easier to
understand and maintain.
Now consider the assignment x x +
1. We assume all names are prop-
erly initialized before they are used. For x x +
1tomakesense, x must
already have been assigned some value. In that case, x x +
1 violates the
single-assignment rule. Moreover, the program fragment x x +
1 does not
translate well mathematically, since its corresponding mathematical predicate
x = x +
1 is always false.
 
 
Search WWH ::




Custom Search