use of com.oracle.truffle.espresso.blocking.EspressoLock in project graal by oracle.
the class InterpreterToVM method monitorExit.
public static void monitorExit(@JavaType(Object.class) StaticObject obj, Meta meta) {
final EspressoLock lock = obj.getLock(meta.getContext());
if (!holdsLock(lock)) {
// Espresso has its own monitor handling.
throw meta.throwException(meta.java_lang_IllegalMonitorStateException);
}
monitorUnsafeExit(lock);
}
use of com.oracle.truffle.espresso.blocking.EspressoLock in project graal by oracle.
the class InterpreterToVM method monitorEnter.
// endregion
// region Monitor enter/exit
public static void monitorEnter(@JavaType(Object.class) StaticObject obj, Meta meta) {
final EspressoLock lock = obj.getLock(meta.getContext());
EspressoContext context = meta.getContext();
if (!monitorTryLock(lock)) {
contendedMonitorEnter(obj, meta, lock, context);
}
}
use of com.oracle.truffle.espresso.blocking.EspressoLock in project graal by oracle.
the class StaticObject method getLock.
/**
* Returns an {@link EspressoLock} instance for use with this {@link StaticObject} instance.
*
* <p>
* The {@link EspressoLock} instance will be unique and cached. Calling this method on
* {@link StaticObject#NULL} is an invalid operation.
*
* <p>
* The returned {@link EspressoLock} instance supports the same usages as do the {@link Object}
* monitor methods ({@link Object#wait() wait}, {@link Object#notify notify}, and
* {@link Object#notifyAll notifyAll}) when used with the built-in monitor lock.
*
* @param context
*/
@SuppressFBWarnings(value = "DC", justification = "Implementations of EspressoLock have only final and volatile fields")
public final EspressoLock getLock(EspressoContext context) {
checkNotForeign();
if (isNull(this)) {
CompilerDirectives.transferToInterpreter();
throw EspressoError.shouldNotReachHere("StaticObject.NULL.getLock()");
}
EspressoLock l = lockOrForeignMarker;
if (l == null) {
synchronized (this) {
l = lockOrForeignMarker;
if (l == null) {
lockOrForeignMarker = l = EspressoLock.create(context.getBlockingSupport());
}
}
}
return l;
}
use of com.oracle.truffle.espresso.blocking.EspressoLock 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.blocking.EspressoLock in project graal by oracle.
the class EspressoReferenceDrainer method getAndClearReferencePendingList.
StaticObject getAndClearReferencePendingList() {
// Should be under guest lock
EspressoLock pLock = getLock();
pLock.lock();
try {
StaticObject res = referencePendingList;
referencePendingList = StaticObject.NULL;
return res;
} finally {
pLock.unlock();
}
}
Aggregations