Search in sources :

Example 1 with GuestInterruptedException

use of com.oracle.truffle.espresso.blocking.GuestInterruptedException in project graal by oracle.

the class VM method JVM_MonitorWait.

@VmImpl(isJni = true)
@TruffleBoundary
@SuppressFBWarnings(value = { "IMSE" }, justification = "Not dubious, .wait is just forwarded from the guest.")
@SuppressWarnings("try")
public void JVM_MonitorWait(@JavaType(Object.class) StaticObject self, long timeout, @Inject Meta meta, @Inject SubstitutionProfiler profiler) {
    EspressoContext context = getContext();
    StaticObject currentThread = context.getCurrentThread();
    State state = timeout > 0 ? State.TIMED_WAITING : State.WAITING;
    try (Transition transition = Transition.transition(context, state)) {
        if (context.EnableManagement) {
            // Locks bookkeeping.
            meta.HIDDEN_THREAD_BLOCKED_OBJECT.setHiddenObject(currentThread, self);
            Target_java_lang_Thread.incrementThreadCounter(currentThread, meta.HIDDEN_THREAD_WAITED_COUNT);
        }
        final boolean report = context.shouldReportVMEvents();
        if (report) {
            context.reportMonitorWait(self, timeout);
        }
        boolean timedOut = !InterpreterToVM.monitorWait(self.getLock(getContext()), timeout);
        if (report) {
            context.reportMonitorWaited(self, timedOut);
        }
    } catch (GuestInterruptedException e) {
        profiler.profile(0);
        if (getThreadAccess().isInterrupted(currentThread, true)) {
            throw meta.throwExceptionWithMessage(meta.java_lang_InterruptedException, e.getMessage());
        }
        getThreadAccess().fullSafePoint(currentThread);
    } catch (IllegalMonitorStateException e) {
        profiler.profile(1);
        throw meta.throwExceptionWithMessage(meta.java_lang_IllegalMonitorStateException, e.getMessage());
    } catch (IllegalArgumentException e) {
        profiler.profile(2);
        throw meta.throwExceptionWithMessage(meta.java_lang_IllegalArgumentException, e.getMessage());
    } finally {
        if (context.EnableManagement) {
            meta.HIDDEN_THREAD_BLOCKED_OBJECT.setHiddenObject(currentThread, null);
        }
    }
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) GuestInterruptedException(com.oracle.truffle.espresso.blocking.GuestInterruptedException) State(com.oracle.truffle.espresso.threads.State) Transition(com.oracle.truffle.espresso.threads.Transition) EspressoContext(com.oracle.truffle.espresso.runtime.EspressoContext) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary) SuppressFBWarnings(com.oracle.truffle.espresso.impl.SuppressFBWarnings)

Example 2 with GuestInterruptedException

use of com.oracle.truffle.espresso.blocking.GuestInterruptedException in project graal by oracle.

the class EspressoReferenceDrainer method doWaitForReferencePendingList.

@TruffleBoundary
private void doWaitForReferencePendingList() {
    try {
        EspressoLock pLock = getLock();
        pLock.lock();
        try {
            // Wait until the reference drain updates the list.
            while (!hasReferencePendingList()) {
                pLock.await(0L);
            }
        } finally {
            pLock.unlock();
        }
    } catch (GuestInterruptedException e) {
    /*
             * The guest handler thread will attempt emptying the reference list by re-obtaining it.
             * If the list is not null, then everything will proceed as normal. In the case it is
             * empty, the guest handler will simply loop back into waiting. This looping back into
             * waiting done in guest code gives us a chance to reach an espresso safe point (a back
             * edge), thus giving us the possibility to stop this thread when tearing down the VM.
             */
    }
}
Also used : GuestInterruptedException(com.oracle.truffle.espresso.blocking.GuestInterruptedException) EspressoLock(com.oracle.truffle.espresso.blocking.EspressoLock) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 GuestInterruptedException (com.oracle.truffle.espresso.blocking.GuestInterruptedException)2 EspressoLock (com.oracle.truffle.espresso.blocking.EspressoLock)1 SuppressFBWarnings (com.oracle.truffle.espresso.impl.SuppressFBWarnings)1 EspressoContext (com.oracle.truffle.espresso.runtime.EspressoContext)1 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)1 State (com.oracle.truffle.espresso.threads.State)1 Transition (com.oracle.truffle.espresso.threads.Transition)1