Java Reference
In-Depth Information
Exercise 6.9. In Figure 6.19, we suggest an alternative addressing scheme where a pointer
to an object actually points 12 bytes into the object, making the addressing of components
(fields, array elements, or string characters) simpler. Implement this scheme, changing both
the run-time code and the code generated for addressing components.
Exercise 6.10. Implement the JVM instructions invokevirtual and invokespecial . Test
them.
Exercise 6.11. Implement the JVM invokeinterface instruction. See [Alpern et al., 2001]
for a discussion of this.
Exercise 6.12. Implement arrays in the HIR ( iaload and iastore have been implemented
in the HIR), the LIR, and SPIM. Implement the arraylength instruction. Test these.
Exercise 6.13. Implement the instance field operations getfield and putfield in the
HIR, the LIR, and SPIM. Test these.
Exercise 6.14. Implement the remaining JVM load and store instructions and test them.
Exercise 6.15. In the current implementation, all general-purpose registers are treated as
callee-saved registers; they are saved by the method being invoked. Modify the compiler so
that it instead treats all general-purpose registers as caller-saved, generating code to save
registers before a call to another method, and restoring those same registers after the call.
The following exercises implement various optimizations, which are discussed in Section
6.3.3. The code already defines a method, optimize() , in the class NControlFlowGraph .
That is a good place to put calls to any methods that perform optimizations on the HIR.
Exercise 6.16. Implement inlining in the optimizations phase. Use an arbitrary instruction
count in deciding what methods to inline. Be careful in dealing with virtual methods.
Exercise 6.17. Implement constant folding in the optimizations phase.
Exercise 6.18. Implement common sub-expression elimination in the optimization phase.
Exercise 6.19. Implement the lifting of invariant code in the optimization phase.
Exercise 6.20. Design and implement a strategy for performing various forms of strength
reduction in the optimization phase.
Exercise 6.21. Implement redundant array bounds check elimination in the optimization
phase.
Exercise 6.22. Implement redundant null check elimination in the optimization phase.
Exercise 6.23. Implement a simple version of peephole optimizations, simplifying some of
the branches discussed in Section 6.3.7.
Exercise 6.24. (Involved 7 ) Implement the JVM instructions lookupswitch and
lookuptable in the HIR, the LIR, and SPIM. Test these. Notice that these flow-of-control
instructions introduce multiple predecessors and multiple successors to basic blocks in the
ow graph.
Exercise 6.25. (Involved) Introduce the long types of constants, variables and operations
into the HIR, the LIR, and SPIM. This assumes you have already added them to j--. Notice
that this will complicate all portions of your JVM to SPIM translation, including register
allocation, because longs require two registers and complicate their operations in SPIM.
7 Meaning not necessarily dicult but involving some work.
 
Search WWH ::




Custom Search