Search in sources :

Example 1 with EspressoLock

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);
}
Also used : EspressoLock(com.oracle.truffle.espresso.blocking.EspressoLock)

Example 2 with EspressoLock

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);
    }
}
Also used : EspressoContext(com.oracle.truffle.espresso.runtime.EspressoContext) EspressoLock(com.oracle.truffle.espresso.blocking.EspressoLock)

Example 3 with EspressoLock

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;
}
Also used : EspressoLock(com.oracle.truffle.espresso.blocking.EspressoLock) SuppressFBWarnings(com.oracle.truffle.espresso.impl.SuppressFBWarnings)

Example 4 with EspressoLock

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");
    }
}
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 5 with EspressoLock

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();
    }
}
Also used : EspressoLock(com.oracle.truffle.espresso.blocking.EspressoLock)

Aggregations

EspressoLock (com.oracle.truffle.espresso.blocking.EspressoLock)6 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 TruffleLanguage (com.oracle.truffle.api.TruffleLanguage)1 GuestInterruptedException (com.oracle.truffle.espresso.blocking.GuestInterruptedException)1 SuppressFBWarnings (com.oracle.truffle.espresso.impl.SuppressFBWarnings)1 Meta (com.oracle.truffle.espresso.meta.Meta)1 EspressoReference (com.oracle.truffle.espresso.ref.EspressoReference)1 EspressoContext (com.oracle.truffle.espresso.runtime.EspressoContext)1