Java Reference
In-Depth Information
4. A common subprogram optimization is inlining . At the point of call,
the body of the called method is substituted for the call, with actual
parameter values used to initialize local variables that represent formal
parameters.
Assume we have the bytecodes that represent the body of subprogram
P that is marked private or final (and hence cannot be redefined in a
subclass). Assume further that P takes n parameters and uses m local
variables. Explain how we could substitute the bytecodes representing
P's body for a call to P, prior to machine code generation. What changes
in the body must be made to guarantee that the substituted bytecodes
do not “clash” with other bytecodes in the context of call?
5. Array bounds checks are mandatory in Java and C
.Theyarevery
useful in catching errors, but are also fairly expensive, especially in
loops. It is often the case that conditional branches provide information
useful in optimizing or even eliminating unnecessary bounds checks.
For example, in
while (i < 10) {
print(a[i++]);
}
we know i must be less than 10 whenever array a is indexed. Moreover,
since i is never decreased in the loop, a single check that i is non-negative
at loop entrance su
ces.
Suggest ways in which information provided by conditional branches
(in conditionals and loops) can be exploited when code to index arrays
is generated.
6. Show the expression tree, with
register
N
eeds
labeling, that corresponds
to the expression a+(b+(c+((d+e)*(f/g)))).
Show the code that would be generated using the
tree
CG code generator.
7. Recall from Section 13.2 that
gives the minimum number
of registers needed to evaluate an expression without spilling registers
to memory. Show that expressions of unbounded sizeexistthatrequire
only 2 registers for evaluation. Show that for any value of m , expressions
exist that always require at least m registers.
register
N
eeds
 
Search WWH ::




Custom Search