This section includes some remarks and quotations from the JLS that are relevant to the JVM. For example:
This means that the JVM must run programs that are not acceptable to any Java compiler.No error occurs even if the set of classes being linked would encounter a compile-time error.
[ 13.4.5, p. 245 in JLS]
Java uses a run-time type check when storing references in arrays to ensure complete type safety.
[ 1, p. 3 in JLS]
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.
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:
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.