Search in sources :

Example 21 with Meta

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);
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 22 with Meta

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);
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) ModuleEntry(com.oracle.truffle.espresso.impl.ModuleTable.ModuleEntry) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 23 with Meta

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);
    }
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) EntryTable(com.oracle.truffle.espresso.impl.EntryTable) ModuleEntry(com.oracle.truffle.espresso.impl.ModuleTable.ModuleEntry) PackageTable(com.oracle.truffle.espresso.impl.PackageTable) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Example 24 with Meta

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;
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 25 with Meta

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;
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) EspressoException(com.oracle.truffle.espresso.runtime.EspressoException) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) EspressoExitException(com.oracle.truffle.espresso.runtime.EspressoExitException) Method(com.oracle.truffle.espresso.impl.Method) FrameInstance(com.oracle.truffle.api.frame.FrameInstance) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

Meta (com.oracle.truffle.espresso.meta.Meta)82 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)29 Method (com.oracle.truffle.espresso.impl.Method)27 ExportMessage (com.oracle.truffle.api.library.ExportMessage)24 Klass (com.oracle.truffle.espresso.impl.Klass)21 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)21 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)21 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)20 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)17 ArityException (com.oracle.truffle.api.interop.ArityException)9 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)9 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)9 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)8 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)6 NativeType (com.oracle.truffle.espresso.ffi.NativeType)4 Field (com.oracle.truffle.espresso.impl.Field)4 ArrayList (java.util.ArrayList)4 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)3 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)3 RuntimeConstantPool (com.oracle.truffle.espresso.classfile.RuntimeConstantPool)3