Search in sources :

Example 6 with ExceptionHandler

use of com.oracle.truffle.espresso.meta.ExceptionHandler in project graal by oracle.

the class MethodVerifier method verifyExceptionHandlers.

/**
 * Verifies actually reachable exception handlers, and the handlers they encounter if they were
 * not already verified.
 * <p>
 * This method reaches a fixed point. After execution, all handler will either have been
 * verified, or are completely unreachable.
 */
private void verifyExceptionHandlers() {
    boolean redo;
    boolean updated;
    do {
        redo = false;
        updated = false;
        for (int i = 0; i < exceptionHandlers.length; i++) {
            ExceptionHandler handler = exceptionHandlers[i];
            if (isStatus(handlerStatus[i], NONVERIFIED)) {
                updated = redo;
                boolean constructorStatus = calledConstructor;
                if (isCalledConstructor(handlerStatus[i])) {
                    calledConstructor = true;
                }
                verifyHandler(handler);
                calledConstructor = constructorStatus;
                handlerStatus[i] = setStatus(handlerStatus[i], VERIFIED);
            } else if (isStatus(handlerStatus[i], UNENCOUNTERED)) {
                redo = true;
            }
        }
    } while (redo && updated);
}
Also used : ExceptionHandler(com.oracle.truffle.espresso.meta.ExceptionHandler)

Example 7 with ExceptionHandler

use of com.oracle.truffle.espresso.meta.ExceptionHandler in project graal by oracle.

the class BytecodeNode method resolveExceptionHandlers.

@ExplodeLoop
@SuppressWarnings("unused")
private ExceptionHandler resolveExceptionHandlers(int bci, StaticObject ex) {
    CompilerAsserts.partialEvaluationConstant(bci);
    ExceptionHandler[] handlers = getMethodVersion().getExceptionHandlers();
    ExceptionHandler resolved = null;
    for (ExceptionHandler toCheck : handlers) {
        if (bci >= toCheck.getStartBCI() && bci < toCheck.getEndBCI()) {
            Klass catchType = null;
            if (!toCheck.isCatchAll()) {
                // exception handlers are similar to instanceof bytecodes, so we pass instanceof
                catchType = resolveType(Bytecodes.INSTANCEOF, (char) toCheck.catchTypeCPI());
            }
            if (catchType == null || InterpreterToVM.instanceOf(ex, catchType)) {
                // the first found exception handler is our exception handler
                resolved = toCheck;
                break;
            }
        }
    }
    return resolved;
}
Also used : ExceptionHandler(com.oracle.truffle.espresso.meta.ExceptionHandler) Klass(com.oracle.truffle.espresso.impl.Klass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) ExplodeLoop(com.oracle.truffle.api.nodes.ExplodeLoop)

Example 8 with ExceptionHandler

use of com.oracle.truffle.espresso.meta.ExceptionHandler in project graal by oracle.

the class Method method getCatchLocation.

public int getCatchLocation(int bci, StaticObject ex) {
    ExceptionHandler[] handlers = getExceptionHandlers();
    ExceptionHandler resolved = null;
    for (ExceptionHandler toCheck : handlers) {
        if (bci >= toCheck.getStartBCI() && bci < toCheck.getEndBCI()) {
            Klass catchType = null;
            if (!toCheck.isCatchAll()) {
                catchType = getRuntimeConstantPool().resolvedKlassAt(getDeclaringKlass(), toCheck.catchTypeCPI());
            }
            if (catchType == null || InterpreterToVM.instanceOf(ex, catchType)) {
                // the first found exception handler is our exception handler
                resolved = toCheck;
                break;
            }
        }
    }
    if (resolved != null) {
        return resolved.getHandlerBCI();
    } else {
        return -1;
    }
}
Also used : ExceptionHandler(com.oracle.truffle.espresso.meta.ExceptionHandler)

Example 9 with ExceptionHandler

use of com.oracle.truffle.espresso.meta.ExceptionHandler in project graal by oracle.

the class MethodVerifier method checkExceptionHandlers.

/**
 * Checks that an instruction can merge into all its handlers.
 */
private void checkExceptionHandlers(int nextBCI, Locals locals) {
    for (int i = 0; i < exceptionHandlers.length; i++) {
        ExceptionHandler handler = exceptionHandlers[i];
        if (nextBCI >= handler.getStartBCI() && nextBCI < handler.getEndBCI()) {
            OperandStack stack = new OperandStack(1);
            Symbol<Type> catchType = handler.getCatchType();
            stack.push(catchType == null ? jlThrowable : new ReferenceOperand(catchType, thisKlass));
            StackFrame oldFrame = stackFrames[handler.getHandlerBCI()];
            StackFrame newFrame = mergeFrames(stack, locals, oldFrame);
            if (isStatus(handlerStatus[i], UNENCOUNTERED) || oldFrame != newFrame) {
                handlerStatus[i] = setStatus(handlerStatus[i], NONVERIFIED);
            }
            if (calledConstructor) {
                handlerStatus[i] = setConstructorStatus(handlerStatus[i], CALLEDCONSTRUCTOR);
            } else {
                handlerStatus[i] = setConstructorStatus(handlerStatus[i], NOCONSTRUCTORCALLED);
            }
            stackFrames[handler.getHandlerBCI()] = newFrame;
        }
    }
}
Also used : ExceptionHandler(com.oracle.truffle.espresso.meta.ExceptionHandler) Type(com.oracle.truffle.espresso.descriptors.Symbol.Type)

Example 10 with ExceptionHandler

use of com.oracle.truffle.espresso.meta.ExceptionHandler in project graal by oracle.

the class MethodVerifier method validateExceptionHandlers.

private void validateExceptionHandlers() {
    verifyGuarantee(exceptionHandlers.length == 0 || maxStack >= 1, "Method with exception handlers has a zero max stack value.");
    for (ExceptionHandler handler : exceptionHandlers) {
        validateFormatBCI(handler.getHandlerBCI());
        int startBCI = handler.getStartBCI();
        validateFormatBCI(startBCI);
        int endBCI = handler.getEndBCI();
        formatGuarantee(endBCI > startBCI, "End BCI of handler is before start BCI");
        formatGuarantee(endBCI >= 0, "negative branch target: " + endBCI);
        // handler end BCI can be equal to code end.
        formatGuarantee(endBCI <= code.endBCI(), "Control flow falls through code end");
        if (handler.catchTypeCPI() != 0) {
            Klass catchType = pool.resolvedKlassAt(thisKlass, handler.catchTypeCPI());
            verifyGuarantee(getMeta().java_lang_Throwable.isAssignableFrom(catchType), "Illegal exception handler catch type: " + catchType);
        }
        if (endBCI != code.endBCI()) {
            formatGuarantee(bciStates[endBCI] != UNREACHABLE, "Jump to the middle of an instruction: " + endBCI);
        }
    }
}
Also used : ExceptionHandler(com.oracle.truffle.espresso.meta.ExceptionHandler) Klass(com.oracle.truffle.espresso.impl.Klass)

Aggregations

ExceptionHandler (com.oracle.truffle.espresso.meta.ExceptionHandler)12 Klass (com.oracle.truffle.espresso.impl.Klass)3 ExplodeLoop (com.oracle.truffle.api.nodes.ExplodeLoop)2 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)2 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)2 TruffleSafepoint (com.oracle.truffle.api.TruffleSafepoint)1 AbstractTruffleException (com.oracle.truffle.api.exception.AbstractTruffleException)1 BytecodeLookupSwitch (com.oracle.truffle.espresso.bytecode.BytecodeLookupSwitch)1 BytecodeTableSwitch (com.oracle.truffle.espresso.bytecode.BytecodeTableSwitch)1 BootstrapMethodsAttribute (com.oracle.truffle.espresso.classfile.attributes.BootstrapMethodsAttribute)1 CodeAttribute (com.oracle.truffle.espresso.classfile.attributes.CodeAttribute)1 ConstantValueAttribute (com.oracle.truffle.espresso.classfile.attributes.ConstantValueAttribute)1 EnclosingMethodAttribute (com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute)1 ExceptionsAttribute (com.oracle.truffle.espresso.classfile.attributes.ExceptionsAttribute)1 InnerClassesAttribute (com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute)1 LineNumberTableAttribute (com.oracle.truffle.espresso.classfile.attributes.LineNumberTableAttribute)1 MethodParametersAttribute (com.oracle.truffle.espresso.classfile.attributes.MethodParametersAttribute)1 NestHostAttribute (com.oracle.truffle.espresso.classfile.attributes.NestHostAttribute)1 NestMembersAttribute (com.oracle.truffle.espresso.classfile.attributes.NestMembersAttribute)1 PermittedSubclassesAttribute (com.oracle.truffle.espresso.classfile.attributes.PermittedSubclassesAttribute)1