Java Reference
In-Depth Information
Exercises
1. Show as many instruction sequences as you can that occupy fewer than
10 bytes and have the e
ect of pushing 0 on the runtime stack. Your
instructions can temporarily modify any storage you wish, but at the
end of the sequence, the only noticeable change should be the new top-
of-stack cell containing 0.
ff
2. Investigate the layout of the JVM constant pool and design an algorithm
to discover the type and value of the i
th entry.
3. As described in Section 10.2.2, a constant-pool entry is referenced by its
ordinal location in the pool. Why was the JVM's constant pool designed
in this fashion when it would surely be faster for programs to specify the
byte-o
ff
set of a constant-pool entry directly?
4. Why are there two instructions (ldc and ldc w) for pushing a constant
value on top of the runtime stack?
5. The form of the getstatic instruction is described in Section 10.2.3 as
having both a name and a type . While the name is certainly necessary to
access the desired static field, is the type information really necessary?
Recall that the accessed field has a declared type in the class defining the
field.
6. The getstatic instruction described in Section 10.2.3 requires that the
static field's name be specifiedas an immediate operand of the instruction.
Suppose the JVM instead had a getarbitrary instruction that could load
a value fromsome arbitrary location. Instead of specifying the field by its
name in an immediate operand, the location's address would be found
at TOS.
What are the implications of such an instruction on the performance and
security of the JVM?
7. The JVMhas two instructions for unconditional jumps: goto and goto w.
Determine the appropriate conditions for using each instruction.
 
 
Search WWH ::




Custom Search