Search in sources :

Example 56 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.

the class VM method getGuestReflectiveConstructorRoot.

@JavaType(java.lang.reflect.Constructor.class)
private static StaticObject getGuestReflectiveConstructorRoot(@JavaType(java.lang.reflect.Constructor.class) StaticObject seed, Meta meta) {
    assert InterpreterToVM.instanceOf(seed, meta.java_lang_reflect_Constructor);
    StaticObject curConstructor = seed;
    Method target = null;
    while (target == null) {
        target = (Method) meta.HIDDEN_CONSTRUCTOR_KEY.getHiddenObject(curConstructor);
        if (target == null) {
            curConstructor = meta.java_lang_reflect_Constructor_root.getObject(curConstructor);
        }
    }
    return curConstructor;
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Method(com.oracle.truffle.espresso.impl.Method) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 57 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.

the class VM method fillInElement.

private void fillInElement(@JavaType(StackTraceElement.class) StaticObject ste, VM.StackElement element, Method classGetName) {
    Method m = element.getMethod();
    Klass k = m.getDeclaringKlass();
    StaticObject guestClass = k.mirror();
    StaticObject loader = k.getDefiningClassLoader();
    ModuleEntry module = k.module();
    // Fill in class name
    getMeta().java_lang_StackTraceElement_declaringClass.setObject(ste, classGetName.invokeDirect(guestClass));
    getMeta().java_lang_StackTraceElement_declaringClassObject.setObject(ste, guestClass);
    // Fill in loader name
    if (!StaticObject.isNull(loader)) {
        StaticObject loaderName = getMeta().java_lang_ClassLoader_name.getObject(loader);
        if (!StaticObject.isNull(loader)) {
            getMeta().java_lang_StackTraceElement_classLoaderName.setObject(ste, loaderName);
        }
    }
    // Fill in method name
    Symbol<Name> mname = m.getName();
    getMeta().java_lang_StackTraceElement_methodName.setObject(ste, getMeta().toGuestString(mname));
    // Fill in module
    if (module.isNamed()) {
        getMeta().java_lang_StackTraceElement_moduleName.setObject(ste, getMeta().toGuestString(module.getName()));
    // TODO: module version
    }
    // Fill in source information
    getMeta().java_lang_StackTraceElement_fileName.setObject(ste, getMeta().toGuestString(m.getSourceFile()));
    getMeta().java_lang_StackTraceElement_lineNumber.setInt(ste, m.bciToLineNumber(element.getBCI()));
}
Also used : Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) ModuleEntry(com.oracle.truffle.espresso.impl.ModuleTable.ModuleEntry) Method(com.oracle.truffle.espresso.impl.Method) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Example 58 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.

the class VM method JVM_GetClassDeclaredMethods.

// TODO(tg): inject constructor calltarget.
@VmImpl(isJni = true)
@JavaType(java.lang.reflect.Method[].class)
public StaticObject JVM_GetClassDeclaredMethods(@JavaType(Class.class) StaticObject self, boolean publicOnly) {
    Meta meta = getMeta();
    ArrayList<Method> collectedMethods = new ArrayList<>();
    Klass klass = self.getMirrorKlass();
    klass.ensureLinked();
    for (Method m : klass.getDeclaredMethods()) {
        if ((!publicOnly || m.isPublic()) && // Filter out <init> and <clinit> from reflection.
        !Name._init_.equals(m.getName()) && !Name._clinit_.equals(m.getName())) {
            collectedMethods.add(m);
        }
    }
    final Method[] methods = collectedMethods.toArray(Method.EMPTY_ARRAY);
    return meta.java_lang_reflect_Method.allocateReferenceArray(methods.length, new IntFunction<StaticObject>() {

        @Override
        public StaticObject apply(int i) {
            return methods[i].makeMirror();
        }
    });
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) ArrayList(java.util.ArrayList) Method(com.oracle.truffle.espresso.impl.Method) NoSafepoint(com.oracle.truffle.espresso.jni.NoSafepoint) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 59 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.

the class Target_sun_reflect_NativeConstructorAccessorImpl method newInstance0.

@Substitution
@JavaType(Object.class)
public static StaticObject newInstance0(@JavaType(Constructor.class) StaticObject constructor, @JavaType(Object[].class) StaticObject args0, @Inject Meta meta) {
    Klass klass = meta.java_lang_reflect_Constructor_clazz.getObject(constructor).getMirrorKlass();
    klass.safeInitialize();
    if (klass.isArray() || klass.isPrimitive() || klass.isInterface() || klass.isAbstract()) {
        throw meta.throwException(meta.java_lang_InstantiationException);
    }
    Method reflectedMethod = Method.getHostReflectiveConstructorRoot(constructor, meta);
    StaticObject instance = klass.allocateInstance();
    StaticObject parameterTypes = meta.java_lang_reflect_Constructor_parameterTypes.getObject(constructor);
    Target_sun_reflect_NativeMethodAccessorImpl.callMethodReflectively(meta, instance, args0, reflectedMethod, klass, parameterTypes);
    return instance;
}
Also used : Klass(com.oracle.truffle.espresso.impl.Klass) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Method(com.oracle.truffle.espresso.impl.Method)

Example 60 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.

the class EspressoThreadRegistry method unregisterThread.

/**
 * Once a thread terminates, remove it from the active set, and notify any thread waiting for VM
 * teardown that it should check again for all non-daemon thread completion.
 */
@SuppressFBWarnings(value = "NN", justification = "Removing a thread from the active set is the state change we need.")
public void unregisterThread(StaticObject thread) {
    logger.fine(() -> {
        String guestName = getThreadAccess().getThreadName(thread);
        long guestId = getThreadAccess().getThreadId(thread);
        return String.format("unregisterThread([GUEST:%s, %d])", guestName, guestId);
    });
    activeThreads.remove(thread);
    Thread hostThread = getThreadAccess().getHost(thread);
    int id = Math.toIntExact(hostThread.getId());
    synchronized (activeThreadLock) {
        if (id == mainThreadId) {
            mainThreadId = -1;
            guestMainThread = null;
        } else if (id == finalizerThreadId) {
            guestFinalizerThread = null;
            finalizerThreadId = -1;
        } else if (id == referenceHandlerThreadId) {
            guestReferenceHandlerThread = null;
            referenceHandlerThreadId = -1;
        } else {
            Object[] threads = guestThreads;
            int threadIndex = getThreadIndex(id, threads);
            if (getThreadAccess().isAlive(thread)) {
                assert threads[threadIndex] == thread;
                threads[threadIndex] = null;
            } else {
                /*
                     * Non-alive threads may have been removed from guestThreads by
                     * refactorGuestThreads => threadIndex may be invalid/outdated and the slot
                     * could be populated by another thread.
                     */
                if (0 <= threadIndex && threadIndex < threads.length) {
                    if (threads[threadIndex] == thread) {
                        threads[threadIndex] = null;
                    }
                }
            }
        }
    }
    Object sync = context.getShutdownSynchronizer();
    synchronized (sync) {
        sync.notifyAll();
    }
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) SuppressFBWarnings(com.oracle.truffle.espresso.impl.SuppressFBWarnings)

Aggregations

StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)199 Method (com.oracle.truffle.espresso.impl.Method)57 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)44 Klass (com.oracle.truffle.espresso.impl.Klass)32 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)32 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)30 Meta (com.oracle.truffle.espresso.meta.Meta)29 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)26 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)23 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)17 ArrayList (java.util.ArrayList)13 EspressoException (com.oracle.truffle.espresso.runtime.EspressoException)9 Symbol (com.oracle.truffle.espresso.descriptors.Symbol)8 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)7 ExportMessage (com.oracle.truffle.api.library.ExportMessage)7 BytecodeNode (com.oracle.truffle.espresso.nodes.BytecodeNode)7 TruffleSafepoint (com.oracle.truffle.api.TruffleSafepoint)6 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)6 EspressoContext (com.oracle.truffle.espresso.runtime.EspressoContext)6 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)5