Java Reference
In-Depth Information
Exercises
1. Inmost object-oriented languages, objects can reference themselves using
a reserved keyword such as self or this.
(a) Assuming that an object's self-reference is in local 0, write a visit
method for MethodBodyVisitor,
(ThisReferencing), that gener-
ates code to compute the value of the self-reference.
(b) Write the corresponding
visit
visit
(ThisReferencing)methodforthe
LHSVisitor.
2. As described in Section 11.3.3, a static reference has the following two
components in the JVM:
The type of the reference;
The fully qualified name of the reference, including its host class.
Froma security perspective for the JVM, investigatewhy static references
are as described above.
(a) Why is the type of the reference included with each getstatic
instruction?
(b) Itmightbemoree
cient to use the relative o
ff
set of a static field
within a class in lieu of its name. Why are o
ff
sets not used in the
JVM getstatic instruction?
3. Design an AST node that implements the CondTesting interface to ac-
commodate an if statement with no else clause.
(a) How do you satisfy the CondTestinginterface while indicating that
the if statement has no else clause?
(b) How is the code-generation strategy presented in Section 11.3.9
a
ff
ected by your design?
4. Consider the code-generation strategy presented in Section 11.3.9. A
conditional jump to f alseLabel is taken, when the predicate is false,to
skip over code that should execute only when the predicate is true.
Rewrite the code-generation strategy so that the conditional jump is
taken when the predicate is true, to skip over code that should execute
only when the predicate is false.
 
 
Search WWH ::




Custom Search