Search in sources :

Example 1 with EspressoReference

use of com.oracle.truffle.espresso.ref.EspressoReference in project graal by oracle.

the class VM method JVM_PhantomReferenceRefersTo.

@SuppressWarnings({ "rawtypes", "unchecked" })
@VmImpl(isJni = true)
public boolean JVM_PhantomReferenceRefersTo(@JavaType(Reference.class) StaticObject ref, @JavaType(Object.class) StaticObject object, @Inject SubstitutionProfiler profiler) {
    if (StaticObject.isNull(ref)) {
        profiler.profile(0);
        getMeta().throwNullPointerException();
    }
    EspressoReference host = (EspressoReference) getMeta().HIDDEN_HOST_REFERENCE.getHiddenObject(ref);
    assert host instanceof Reference;
    // Call host's refersTo. Not available in 8 or 11.
    return ReferenceSupport.phantomReferenceRefersTo((Reference) host, object);
}
Also used : EspressoReference(com.oracle.truffle.espresso.ref.EspressoReference) EspressoReference(com.oracle.truffle.espresso.ref.EspressoReference) Reference(java.lang.ref.Reference) Target_java_lang_ref_Reference(com.oracle.truffle.espresso.substitutions.Target_java_lang_ref_Reference)

Example 2 with EspressoReference

use of com.oracle.truffle.espresso.ref.EspressoReference in project graal by oracle.

the class EspressoReferenceDrainer method initReferenceDrain.

void initReferenceDrain() {
    TruffleLanguage.Env env = getContext().getEnv();
    Meta meta = getMeta();
    if (getContext().multiThreadingEnabled()) {
        if (getJavaVersion().java8OrEarlier()) {
            // Initialize reference queue
            this.hostToGuestReferenceDrainThread = env.createThread(new ReferenceDrain() {

                @SuppressWarnings("rawtypes")
                @Override
                protected void updateReferencePendingList(EspressoReference head, EspressoReference prev, StaticObject lock) {
                    StaticObject obj = meta.java_lang_ref_Reference_pending.getAndSetObject(meta.java_lang_ref_Reference.getStatics(), head.getGuestReference());
                    meta.java_lang_ref_Reference_discovered.set(prev.getGuestReference(), obj);
                    getVM().JVM_MonitorNotify(lock, profiler);
                }
            });
        } else if (getJavaVersion().java9OrLater()) {
            // Initialize reference queue
            this.hostToGuestReferenceDrainThread = env.createThread(new ReferenceDrain() {

                @SuppressWarnings("rawtypes")
                @Override
                protected void updateReferencePendingList(EspressoReference head, EspressoReference prev, StaticObject lock) {
                    EspressoLock pLock = getLock();
                    pLock.lock();
                    try {
                        StaticObject obj = referencePendingList;
                        referencePendingList = head.getGuestReference();
                        meta.java_lang_ref_Reference_discovered.set(prev.getGuestReference(), obj);
                        getVM().JVM_MonitorNotify(lock, profiler);
                        pLock.signalAll();
                    } finally {
                        pLock.unlock();
                    }
                }
            });
        } else {
            throw EspressoError.shouldNotReachHere();
        }
    }
    if (hostToGuestReferenceDrainThread != null) {
        hostToGuestReferenceDrainThread.setName("Reference Drain");
    }
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) EspressoReference(com.oracle.truffle.espresso.ref.EspressoReference) TruffleLanguage(com.oracle.truffle.api.TruffleLanguage) EspressoLock(com.oracle.truffle.espresso.blocking.EspressoLock)

Example 3 with EspressoReference

use of com.oracle.truffle.espresso.ref.EspressoReference in project graal by oracle.

the class VM method JVM_ReferenceRefersTo.

@SuppressWarnings({ "rawtypes", "unchecked" })
@VmImpl(isJni = true)
public boolean JVM_ReferenceRefersTo(@JavaType(Reference.class) StaticObject ref, @JavaType(Object.class) StaticObject object, @Inject SubstitutionProfiler profiler) {
    if (StaticObject.isNull(ref)) {
        profiler.profile(0);
        getMeta().throwNullPointerException();
    }
    EspressoReference host = (EspressoReference) getMeta().HIDDEN_HOST_REFERENCE.getHiddenObject(ref);
    assert host instanceof Reference;
    // Call host's refersTo. Not available in 8 or 11.
    return ReferenceSupport.referenceRefersTo((Reference) host, object);
}
Also used : EspressoReference(com.oracle.truffle.espresso.ref.EspressoReference) EspressoReference(com.oracle.truffle.espresso.ref.EspressoReference) Reference(java.lang.ref.Reference) Target_java_lang_ref_Reference(com.oracle.truffle.espresso.substitutions.Target_java_lang_ref_Reference)

Example 4 with EspressoReference

use of com.oracle.truffle.espresso.ref.EspressoReference in project graal by oracle.

the class Target_java_lang_ref_Reference method clear.

@SuppressWarnings("rawtypes")
@Substitution(hasReceiver = true)
public static void clear(@JavaType(Reference.class) StaticObject self, @Inject Meta meta) {
    if (// 
    InterpreterToVM.instanceOf(self, meta.java_lang_ref_WeakReference) || // 
    InterpreterToVM.instanceOf(self, meta.java_lang_ref_SoftReference) || // 
    InterpreterToVM.instanceOf(self, meta.java_lang_ref_PhantomReference) || InterpreterToVM.instanceOf(self, meta.java_lang_ref_FinalReference)) {
        EspressoReference ref = (EspressoReference) meta.HIDDEN_HOST_REFERENCE.getHiddenObject(self);
        if (ref != null) {
            assert ref instanceof Reference;
            ref.clear();
            // Also remove host reference.
            meta.HIDDEN_HOST_REFERENCE.setHiddenObject(self, null);
        }
    } else {
        meta.java_lang_ref_Reference_referent.set(self, StaticObject.NULL);
    }
}
Also used : EspressoReference(com.oracle.truffle.espresso.ref.EspressoReference) Reference(java.lang.ref.Reference) EspressoReference(com.oracle.truffle.espresso.ref.EspressoReference)

Example 5 with EspressoReference

use of com.oracle.truffle.espresso.ref.EspressoReference in project graal by oracle.

the class Target_java_lang_ref_Reference method init.

@Substitution(hasReceiver = true, methodName = "<init>")
public static void init(@JavaType(Reference.class) StaticObject self, @JavaType(Object.class) StaticObject referent, @JavaType(ReferenceQueue.class) StaticObject queue, @Inject EspressoContext context) {
    // Guest referent field is ignored for weak/soft/final/phantom references.
    EspressoReference ref = null;
    Meta meta = context.getMeta();
    if (InterpreterToVM.instanceOf(self, meta.java_lang_ref_WeakReference)) {
        ref = EspressoReference.createWeak(context, self, referent);
    } else if (InterpreterToVM.instanceOf(self, meta.java_lang_ref_SoftReference)) {
        ref = EspressoReference.createSoft(context, self, referent);
    } else if (InterpreterToVM.instanceOf(self, meta.java_lang_ref_FinalReference)) {
        ref = EspressoReference.createFinal(context, self, referent);
    } else if (InterpreterToVM.instanceOf(self, meta.java_lang_ref_PhantomReference)) {
        ref = EspressoReference.createPhantom(context, self, referent);
    }
    if (ref != null) {
        // Weak/Soft/Final/Phantom reference.
        meta.HIDDEN_HOST_REFERENCE.setHiddenObject(self, ref);
    } else {
        // Strong reference.
        meta.java_lang_ref_Reference_referent.set(self, referent);
    }
    if (StaticObject.isNull(queue)) {
        meta.java_lang_ref_Reference_queue.set(self, meta.java_lang_ref_ReferenceQueue_NULL.get(meta.java_lang_ref_ReferenceQueue.tryInitializeAndGetStatics()));
    } else {
        meta.java_lang_ref_Reference_queue.set(self, queue);
    }
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) EspressoReference(com.oracle.truffle.espresso.ref.EspressoReference)

Aggregations

EspressoReference (com.oracle.truffle.espresso.ref.EspressoReference)6 Reference (java.lang.ref.Reference)4 Meta (com.oracle.truffle.espresso.meta.Meta)2 Target_java_lang_ref_Reference (com.oracle.truffle.espresso.substitutions.Target_java_lang_ref_Reference)2 TruffleLanguage (com.oracle.truffle.api.TruffleLanguage)1 EspressoLock (com.oracle.truffle.espresso.blocking.EspressoLock)1 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)1