use of com.oracle.truffle.espresso.runtime.EspressoException in project graal by oracle.
the class MethodTypeConstant method signatureToMethodType.
static StaticObject signatureToMethodType(Symbol<Symbol.Type>[] signature, Klass accessingKlass, boolean failWithBME, Meta meta) {
Symbol<Symbol.Type> rt = Signatures.returnType(signature);
int pcount = Signatures.parameterCount(signature, false);
StaticObject[] ptypes = new StaticObject[pcount];
StaticObject rtype;
try {
for (int i = 0; i < pcount; i++) {
Symbol<Symbol.Type> paramType = Signatures.parameterType(signature, i);
ptypes[i] = meta.resolveSymbolAndAccessCheck(paramType, accessingKlass).mirror();
}
} catch (EspressoException e) {
if (meta.java_lang_ClassNotFoundException.isAssignableFrom(e.getGuestException().getKlass())) {
throw meta.throwExceptionWithMessage(meta.java_lang_NoClassDefFoundError, e.getGuestMessage());
}
throw e;
}
try {
rtype = meta.resolveSymbolAndAccessCheck(rt, accessingKlass).mirror();
} catch (EspressoException e) {
EspressoException rethrow = e;
if (meta.java_lang_ClassNotFoundException.isAssignableFrom(e.getGuestException().getKlass())) {
rethrow = EspressoException.wrap(Meta.initExceptionWithMessage(meta.java_lang_NoClassDefFoundError, e.getGuestMessage()), meta);
}
if (failWithBME) {
rethrow = EspressoException.wrap(Meta.initExceptionWithCause(meta.java_lang_BootstrapMethodError, rethrow.getGuestException()), meta);
}
throw rethrow;
}
return (StaticObject) meta.java_lang_invoke_MethodHandleNatives_findMethodHandleType.invokeDirect(null, rtype, StaticObject.createArray(meta.java_lang_Class_array, ptypes));
}
use of com.oracle.truffle.espresso.runtime.EspressoException in project graal by oracle.
the class VM method JVM_DoPrivileged.
@VmImpl(isJni = true)
@SuppressWarnings("unused")
@JavaType(Object.class)
public StaticObject JVM_DoPrivileged(@JavaType(Class.class) StaticObject cls, /* PrivilegedAction or PrivilegedActionException */
@JavaType(Object.class) StaticObject action, @JavaType(AccessControlContext.class) StaticObject context, boolean wrapException, @Inject Meta meta, @Inject SubstitutionProfiler profiler) {
if (StaticObject.isNull(action)) {
profiler.profile(0);
throw meta.throwNullPointerException();
}
FrameInstance callerFrame = getCallerFrame(1, false, meta);
assert callerFrame != null : "No caller ?";
Klass caller = getMethodFromFrame(callerFrame).getDeclaringKlass();
StaticObject acc = context;
if (!StaticObject.isNull(context)) {
if (!isAuthorized(context, caller)) {
acc = createDummyACC();
}
}
Method run = action.getKlass().lookupMethod(Name.run, Signature.Object);
if (run == null || !run.isPublic() || run.isStatic()) {
profiler.profile(1);
throw meta.throwException(meta.java_lang_InternalError);
}
// Prepare the privileged stack
PrivilegedStack stack = getPrivilegedStack();
stack.push(callerFrame, acc, caller);
// Execute the action.
StaticObject result;
try {
result = (StaticObject) run.invokeDirect(action);
} catch (EspressoException e) {
profiler.profile(2);
if (meta.java_lang_Exception.isAssignableFrom(e.getGuestException().getKlass()) && !meta.java_lang_RuntimeException.isAssignableFrom(e.getGuestException().getKlass())) {
profiler.profile(3);
StaticObject wrapper = meta.java_security_PrivilegedActionException.allocateInstance();
getMeta().java_security_PrivilegedActionException_init_Exception.invokeDirect(wrapper, e.getGuestException());
throw meta.throwException(wrapper);
}
profiler.profile(4);
throw e;
} finally {
stack.pop();
}
return result;
}
use of com.oracle.truffle.espresso.runtime.EspressoException in project graal by oracle.
the class VM method DetachCurrentThread.
@VmImpl
@TruffleBoundary
public int DetachCurrentThread(@Inject EspressoContext context) {
StaticObject currentThread = context.getCurrentThread();
if (currentThread == null) {
return JNI_OK;
}
getLogger().fine(() -> {
String guestName = getThreadAccess().getThreadName(currentThread);
return "DetachCurrentThread: " + guestName;
});
// HotSpot will wait forever if the current VM this thread was attached to has exited
// Should we reproduce this behaviour?
Method lastJavaMethod = Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<Method>() {
@Override
public Method visitFrame(FrameInstance frameInstance) {
Method method = getMethodFromFrame(frameInstance);
if (method != null && method.getContext() == context) {
return method;
}
return null;
}
});
if (lastJavaMethod != null) {
// this thread is executing
getLogger().warning(() -> {
String guestName = getThreadAccess().getThreadName(currentThread);
return "DetachCurrentThread called while thread is still executing Java code (" + guestName + ")";
});
return JNI_ERR;
}
StaticObject pendingException = jniEnv.getPendingException();
jniEnv.clearPendingException();
Meta meta = context.getMeta();
try {
if (pendingException != null) {
meta.java_lang_Thread_dispatchUncaughtException.invokeDirect(currentThread, pendingException);
}
getThreadAccess().terminate(currentThread);
} catch (EspressoException e) {
try {
StaticObject ex = e.getGuestException();
String exception = ex.getKlass().getExternalName();
String threadName = getThreadAccess().getThreadName(currentThread);
context.getLogger().warning(String.format("Exception: %s thrown while terminating thread \"%s\"", exception, threadName));
Method printStackTrace = ex.getKlass().lookupMethod(Name.printStackTrace, Signature._void);
printStackTrace.invokeDirect(ex);
} catch (EspressoException ee) {
String exception = ee.getGuestException().getKlass().getExternalName();
context.getLogger().warning(String.format("Exception: %s thrown while trying to print stack trace", exception));
} catch (EspressoExitException ee) {
// ignore
}
} catch (EspressoExitException e) {
// ignore
} catch (Throwable t) {
context.getLogger().severe("Host exception thrown while trying to terminate thread");
t.printStackTrace();
}
return JNI_OK;
}
use of com.oracle.truffle.espresso.runtime.EspressoException in project graal by oracle.
the class ClassRedefinition method redefineClass.
public int redefineClass(ChangePacket packet, List<ObjectKlass> invalidatedClasses, List<ObjectKlass> redefinedClasses) {
try {
switch(packet.classChange) {
case METHOD_BODY_CHANGE:
case CONSTANT_POOL_CHANGE:
case CLASS_NAME_CHANGED:
case ADD_METHOD:
case REMOVE_METHOD:
case SCHEMA_CHANGE:
doRedefineClass(packet, invalidatedClasses, redefinedClasses);
return 0;
case CLASS_HIERARCHY_CHANGED:
context.markChangedHierarchy();
doRedefineClass(packet, invalidatedClasses, redefinedClasses);
return 0;
case NEW_CLASS:
ClassInfo classInfo = packet.info;
// if there is a currently loaded class under that name
// we have to replace that in the class loader registry etc.
// otherwise, don't eagerly define the new class
Symbol<Symbol.Type> type = context.getTypes().fromName(classInfo.getName());
ClassRegistry classRegistry = context.getRegistries().getClassRegistry(classInfo.getClassLoader());
Klass loadedKlass = classRegistry.findLoadedKlass(type);
if (loadedKlass != null) {
// OK, we have to define the new klass instance and
// inject it under the existing JDWP ID
classRegistry.onInnerClassRemoved(type);
ObjectKlass newKlass = classRegistry.defineKlass(type, classInfo.getBytes());
packet.info.setKlass(newKlass);
}
return 0;
default:
return 0;
}
} catch (EspressoException ex) {
// we get from parsing the class file
return ErrorCodes.INVALID_CLASS_FORMAT;
}
}
use of com.oracle.truffle.espresso.runtime.EspressoException in project graal by oracle.
the class InterpreterToVM method fillInStackTrace.
/**
* Preemptively added method to benefit from truffle lazy stack traces when they will be
* reworked.
*/
@SuppressWarnings("unused")
public static StaticObject fillInStackTrace(@JavaType(Throwable.class) StaticObject throwable, Meta meta) {
// Inlined calls to help StackOverflows.
VM.StackTrace frames = (VM.StackTrace) meta.HIDDEN_FRAMES.getHiddenObject(throwable);
if (frames != null) {
return throwable;
}
EspressoException e = EspressoException.wrap(throwable, meta);
List<TruffleStackTraceElement> trace = TruffleStackTrace.getStackTrace(e);
if (trace == null) {
meta.HIDDEN_FRAMES.setHiddenObject(throwable, VM.StackTrace.EMPTY_STACK_TRACE);
meta.java_lang_Throwable_backtrace.setObject(throwable, throwable);
return throwable;
}
int bci = -1;
Method m = null;
frames = new VM.StackTrace();
FrameCounter c = new FrameCounter();
for (TruffleStackTraceElement element : trace) {
Node location = element.getLocation();
while (location != null) {
if (location instanceof QuickNode) {
bci = ((QuickNode) location).getBci(element.getFrame());
break;
}
location = location.getParent();
}
RootCallTarget target = element.getTarget();
if (target != null) {
RootNode rootNode = target.getRootNode();
if (rootNode instanceof EspressoRootNode) {
m = ((EspressoRootNode) rootNode).getMethod();
if (c.checkFillIn(m) || c.checkThrowableInit(m)) {
bci = UNKNOWN_BCI;
continue;
}
if (m.isNative()) {
bci = NATIVE_BCI;
}
frames.add(new VM.StackElement(m, bci));
bci = UNKNOWN_BCI;
}
}
}
meta.HIDDEN_FRAMES.setHiddenObject(throwable, frames);
meta.java_lang_Throwable_backtrace.setObject(throwable, throwable);
return throwable;
}
Aggregations