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);
}
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");
}
}
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);
}
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);
}
}
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);
}
}
Aggregations