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);
}
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;
}
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;
}
}
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;
}
}
}
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);
}
}
}
Aggregations