use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.
the class ConstantPool method verifyError.
@JavaType(VerifyError.class)
static EspressoException verifyError(String message) {
CompilerDirectives.transferToInterpreter();
Meta meta = EspressoContext.get(null).getMeta();
throw meta.throwExceptionWithMessage(meta.java_lang_VerifyError, message);
}
use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.
the class VM method JVM_SetBootLoaderUnnamedModule.
@VmImpl(isJni = true)
@TruffleBoundary
public void JVM_SetBootLoaderUnnamedModule(@JavaType(internalName = "Ljava/lang/Module;") StaticObject module) {
Meta meta = getMeta();
if (StaticObject.isNull(module)) {
throw meta.throwNullPointerException();
}
if (!meta.java_lang_Module.isAssignableFrom(module.getKlass())) {
throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, "module is not an instance of java.lang.module");
}
if (!StaticObject.isNull(meta.java_lang_Module_name.getObject(module))) {
throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, "boot loader unnamed module has a name");
}
if (!StaticObject.isNull(meta.java_lang_Module_loader.getObject(module))) {
throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, "Class loader must be the boot class loader");
}
ModuleEntry bootUnnamed = getRegistries().getBootClassRegistry().getUnnamedModule();
bootUnnamed.setModule(module);
meta.HIDDEN_MODULE_ENTRY.setHiddenObject(module, bootUnnamed);
}
use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.
the class VM method defineJavaBaseModule.
@SuppressWarnings("try")
public void defineJavaBaseModule(StaticObject module, String[] packages, SubstitutionProfiler profiler) {
Meta meta = getMeta();
StaticObject loader = meta.java_lang_Module_loader.getObject(module);
if (!StaticObject.isNull(loader)) {
profiler.profile(10);
throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, "Class loader must be the bootclass loader");
}
PackageTable pkgTable = getRegistries().getBootClassRegistry().packages();
ModuleEntry javaBaseEntry = getRegistries().getJavaBaseModule();
try (EntryTable.BlockLock block = pkgTable.write()) {
if (getRegistries().javaBaseDefined()) {
profiler.profile(9);
throw meta.throwException(meta.java_lang_InternalError);
}
for (String pkg : packages) {
Symbol<Name> pkgName = getNames().getOrCreate(pkg);
if (pkgTable.lookup(pkgName) == null) {
pkgTable.createAndAddEntry(pkgName, javaBaseEntry);
}
}
javaBaseEntry.setModule(module);
meta.HIDDEN_MODULE_ENTRY.setHiddenObject(module, javaBaseEntry);
getRegistries().processFixupList(module);
}
}
use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.
the class VM method JVM_AssertionStatusDirectives.
// endregion array
// region assertion
/**
* Espresso only supports basic -ea and -esa options. Complex per-class/package filters are
* unsupported.
*/
@VmImpl(isJni = true)
@TruffleBoundary
@JavaType(internalName = "Ljava/lang/AssertionStatusDirectives;")
public StaticObject JVM_AssertionStatusDirectives(@SuppressWarnings("unused") @JavaType(Class.class) StaticObject unused) {
Meta meta = getMeta();
StaticObject instance = meta.java_lang_AssertionStatusDirectives.allocateInstance();
meta.java_lang_AssertionStatusDirectives.lookupMethod(Name._init_, Signature._void).invokeDirect(instance);
meta.java_lang_AssertionStatusDirectives_classes.set(instance, meta.java_lang_String.allocateReferenceArray(0));
meta.java_lang_AssertionStatusDirectives_classEnabled.set(instance, meta._boolean.allocatePrimitiveArray(0));
meta.java_lang_AssertionStatusDirectives_packages.set(instance, meta.java_lang_String.allocateReferenceArray(0));
meta.java_lang_AssertionStatusDirectives_packageEnabled.set(instance, meta._boolean.allocatePrimitiveArray(0));
boolean ea = getContext().getEnv().getOptions().get(EspressoOptions.EnableAssertions);
meta.java_lang_AssertionStatusDirectives_deflt.set(instance, ea);
return instance;
}
use of com.oracle.truffle.espresso.meta.Meta 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;
}
Aggregations