Java Reference
In-Depth Information
Exercises
1. Consider the following Java method:
public static int fact(int n){
if (n == 0)
return 1;
else return n*fact(n-1); }
Using your favorite Java compiler, show the JVM bytecodes that would
be generated for this method. Explain what each of the generated byte-
codes contributes to the execution of the methods.
If the “public static” prefix is removed, the Java method becomes a
validC or C
function. Compile it using your favorite compiler on your
favorite processor using no optimization . List the machine instructions
generated and show which machine instructions correspond to each
generated JVM bytecode.
++
2. On many processors, certain designated registers must be used to hold
a parameter to a subprogram or a return value from a function. Suggest
how the techniques of Section 13.1 could be extended so that when
bytecodes are translated, parameters and return values are computed
directly into the designated register (without any unnecessary register-
to-register moves).
3. Recall that a key to generating e
cient target-machine code from byte-
codes is to avoid explicit stack manipulations for bytecode operands.
Rather, machine registers are used to hold “stacked” values.
Assume we use the techniques of Section 13.3.1 to allocate registers on-
the-fly. Explain how we could tag each bytecode, prior to code gener-
ation, with the machine registers the bytecode will use for its operands
and result value. (These tags would then be used to “fill in” register
names when bytecodes are expanded to machine code.)
 
 
Search WWH ::




Custom Search