Java Reference
In-Depth Information
Top of Stack
Space for b = 10
Dynamic Link
Previous D1
Display D1
Space for b = −10
Dynamic Link
Previous D1
Space for a
Dynamic Link = Nul l
Previous D0
Display D0
Figure 12.7: An Example of Display Registers
frame's control information area contains a slot for the previous value of the
frame's display register. This value is saved when a call begins and is restored
when the call ends. The dynamic link is still needed, because previous display
values do not always point to the caller's frame.
Both static links and displays are used in real compilers, and each tech-
nique presents di
s. Displays allow direct access to all frames,
and thus make access to all visible variables very e
ff
erent tradeo
ff
cient. However, if nesting
is deep, several valuable registers may need to be reserved. Static links are
very flexible, allowing unlimited nesting of procedures. However, access to
non-local procedure variables can be slowed by the need to extract and follow
static links.
Fortunately, the code generated using the two techniques can be readily
improved. Static links are just address-valued expressions computed to ac-
cess variables (much like address calculations involving pointer variables). A
careful compiler can notice that an expression is being needlessly recomputed,
and reuse a previous computation, often directly from a register. Similarly, a
display can be allocated statically in memory. If a particular display value is
used frequently, a register allocator will place the display value in a register to
avoid repeated loads (just as it would for any other heavily used variable).
12.2.5 Block-Level Allocation
Java,C,C
, and most other programming languages, allow decla-
ration of local variables within blocks as well as within subprograms. Often
a block will contain only one or two variables, along with statements that use
them. Do we allocate an entire frame for each such block?
We could, by considering a block with local variables to be a call of an
in-line subprogram without parameters. The call causes the allocation of a
new frame. This implementation technique would require a display or static
++
,andC
 
 
Search WWH ::




Custom Search