Dynamic semantics of the JVME - JVM

In the JVM exceptions are objects that can be thrown and caught. JVME extends JVMO by instructions dealing with exceptions, namely to raise an exception, to jump to and to return from subroutines.

The extension JVME of JVMO consists in adding to the execVMO a rule for each of the error handling instructions and in adding to switchVMC a new rule which describes the context switch when an exception is thrown.

trustfulVME = trustfulSchemeC (execVME; switchVME)

Environment. To implement the try/catch construct of Java, JVME provides exception tables. They list the exceptions of a method. When an exception is raised, these tables are searched for the handler.

Any quadruple (f ; u; h; t) describes the range of instructions ff ::u 1g where an exception is handled that is compatible with t.

When an exception is raised, the run-time system searches the exception table of the current method. If no handler is found, the frame of the current method is discarded and the invoker frame is re-instantiated to continue the search for an exception handler. If a handler is found, the operand stack is cleared and the reference of the exception is pushed onto the stack. The execution continues from the address of the handler (within the current method and with the current register values). This propagation of exceptions terminates since we assume that Main has a default" exception handler. It catches any exception and points to Halt. Its exception table is [(0; 2; 2; Throwable)].

State. Exception handling modi_es the frame stack. The universe Switch is extended to signal the handling of a thrown exception:

data Switch = : : : j Throw(Ref ) j ThrowInit(Ref )

When an exception occurs in a <clinit> method the switch will be set to ThrowInit and the method's class must be marked as Unusable. We extend the universe

Values. To implement Java try/_nally constructs, JVME supports embedded subroutines. The corresponding instructions push 32-bit program counters onto the stack or load them from local variables. This requires that Pc is injected in Word.

Rules. Figure below de_nes the rules of switchVME. The switchVME rules search for the handler of the thrown exception. If the current pc and exception match an exception entry of the current method, switchVME sets the program counter to the _rst matching handler and replaces the operand stack with the thrown exception. The function handler selects the appropriate error handler (if any) where the function excs returns the exception table of the given method.

If te exception escapes from the current method, the top method frame is discarded and it is checked whether the invoker frame has de_ned a handler.

If an exceptpin thrown in a <clinit> method is not compatible with Error, an ExceptionInInitializerError replaces the thrown one. If a <clinit> method frame is popped, the declared class becomes Unusable. The exception

Switch machine for JVME

Switch machine for JVME

NoClassDefFoundError is thrown, if an unusable class should be initialized.

The macro raise(c) is a short hand for the following code template:

This code can be implemented as a static method de_ned for instance in class

The execVME rules specify the e_ect of the JVME instructions on the current frame. The Athrow instruction takes the reference from the top of the stack and throws the exception represented by that reference, namely by triggering the switchVME submachine. The Jsr instruction is used to implement _nally clauses of Java. Its execution transfers the control to the

Trustful execution of JVME instructions

Trustful execution of JVME instructions

given label and pushes the address of the next instruction on the operand stack. This address is typically used by Ret to return from the subroutine.

Therefore from the top of the stack where this return address has been put by Jsr, it has to be stored in a register (using Store) to be found there by Ret, as one can see below in the compilation of _nally statements.

JVME also extends in the expected way the rules where run-time exceptions might occur. A typical representative of this extension is the de_nition for Prim. The new rule throws an ArithmeticException, if the operator is an integer or long division or remainder operator and the right operand is 0. JVME throws a NullPointerException if the target reference of a GetField, PutField, InvokeSpecial or InvokeVirtual instruction is null , or if the reference of the Athrow instruction is null . The machine throws a ClassCastException, if for a Checkcast instruction the reference on top of stack is neither null nor assignment compatible with the required type.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JVM Topics