[Table of Contents]

Remarks on Java

This section includes some remarks and quotations from the JLS that are relevant to the JVM. For example:

No error occurs even if the set of classes being linked would encounter a compile-time error.
[ 13.4.5, p. 245 in JLS]

This means that the JVM must run programs that are not acceptable to any Java compiler.

Java uses a run-time type check when storing references in arrays to ensure complete type safety.
[ 1, p. 3 in JLS]

** Working Notes **

Creating Call Frames

  1. The call instructions are defined to ``set the pc to the opcode of the first instruction in the [method body].''
    1. Of course, they mean the address of the opcode of the first instruction.
    2. Is there any provision in the class-file format to start a method other than at the instruction at address 0?
    3. Mustn't the byte at address 0 be the opcode of that instruction?
    4. Do they even define what ``the opcode of the instruction'' is when an instruction is prefaced by the wide modifier?

The opcode of the first instruction in the code array begins at index 0.
[ 4.8.1, p. 118 in JVMS]

The wide instruction is a variable-length instruction. An instruction form that appears as part of a wide instruction is not a reachable instruction.

Throwing Run-Time Exceptions

N. B., Along with the athrow instruction, any other JVM instruction can throw an exception.

One way to handle run-time exceptions is to add a new component to the state, called pending-exception. After executing each instruction, the inter preter checks whether pending -exception is non-null. If so, it should be the name of a subclass of Error or Exception and the interpreter proceeds to:

  1. Build an instance of that exception class.
  2. Throw that exception.

The value of pending-exception may have to include initialization parameters for the constructor (e.g., with a message string, or other information about cause of the exception or the context of the exception.) The interpreter might also have to record information about the context of the exception, such as the stack-trace.

It is probably best to restrict this interpreter mechanism to throwing run-time exceptions, and have athrow handle explicit throwing of conditions. Thus, the athrow instruction can throw any condition, including an explicitly constructed instance of RuntimeException, but the interpreter's built-in handling of pending-exception is restricted to constructing and throwing instanced of RuntimeException.

The interpreter can construct the instance of the exception condition by invoking the appropriate constructor. The arguments included in pending-exception are typed values, so the implied method signature can be constructed and used to identify the appropriate method.

This page is URL http://www.computationallogic.com/software/djvm/html-0.5/remarks-on-java.html