use of com.oracle.truffle.espresso.threads.State 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);
}
}
}
use of com.oracle.truffle.espresso.threads.State in project graal by oracle.
the class Target_sun_misc_Unsafe method park.
/**
* Block current thread, returning when a balancing <tt>unpark</tt> occurs, or a balancing
* <tt>unpark</tt> has already occurred, or the thread is interrupted, or, if not absolute and
* time is not zero, the given time nanoseconds have elapsed, or if absolute, the given deadline
* in milliseconds since Epoch has passed, or spuriously (i.e., returning for no "reason").
* Note: This operation is in the Unsafe class only because <tt>unpark</tt> is, so it would be
* strange to place it elsewhere.
*/
@TruffleBoundary
@Substitution(hasReceiver = true)
@SuppressWarnings("try")
public static void park(@JavaType(Unsafe.class) StaticObject self, boolean isAbsolute, long time, @Inject Meta meta) {
if (time < 0 || (isAbsolute && time == 0)) {
// don't wait at all
return;
}
EspressoContext context = meta.getContext();
StaticObject thread = context.getCurrentThread();
if (meta.getThreadAccess().isInterrupted(thread, false)) {
return;
}
Unsafe unsafe = UnsafeAccess.getIfAllowed(meta);
Thread hostThread = Thread.currentThread();
Object blocker = LockSupport.getBlocker(hostThread);
State state = time > 0 ? State.TIMED_WAITING : State.WAITING;
try (Transition transition = Transition.transition(context, state)) {
Field parkBlocker = meta.java_lang_Thread.lookupDeclaredField(Symbol.Name.parkBlocker, Type.java_lang_Object);
StaticObject guestBlocker = parkBlocker.getObject(thread);
// LockSupport.park(/* guest blocker */);
if (!StaticObject.isNull(guestBlocker)) {
unsafe.putObject(hostThread, PARK_BLOCKER_OFFSET, guestBlocker);
}
parkBoundary(self, isAbsolute, time, meta);
}
unsafe.putObject(hostThread, PARK_BLOCKER_OFFSET, blocker);
}
Aggregations