Skip to content

Commit 3940c33

Browse files
committedNov 28, 2023
use BLOCKING instead of PARKING
1 parent 3cd1de4 commit 3940c33

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed
 

‎src/hotspot/share/classfile/javaClasses.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,7 @@ bool java_lang_Thread::is_in_VTMS_transition(oop java_thread) {
16201620
}
16211621

16221622
void java_lang_Thread::set_is_in_VTMS_transition(oop java_thread, bool val) {
1623+
assert(is_in_VTMS_transition(java_thread) != val, "already %s transition", val ? "inside" : "outside");
16231624
java_thread->bool_field_put_volatile(_jvmti_is_in_VTMS_transition_offset, val);
16241625
}
16251626

‎src/hotspot/share/runtime/javaThread.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,7 @@ void JavaThread::send_async_exception(JavaThread* target, oop java_throwable) {
11381138

11391139
#if INCLUDE_JVMTI
11401140
void JavaThread::set_is_in_VTMS_transition(bool val) {
1141+
assert(is_in_VTMS_transition() != val, "already %s transition", val ? "inside" : "outside");
11411142
_is_in_VTMS_transition = val;
11421143
}
11431144

‎src/hotspot/share/runtime/objectMonitor.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ bool ObjectMonitor::enter(JavaThread* current) {
407407
add_to_contentions(-1);
408408
DEBUG_ONLY(int state = java_lang_VirtualThread::state(current->vthread()));
409409
assert((owner() == current && current->is_preemption_cancelled() && state == java_lang_VirtualThread::RUNNING) ||
410-
(owner() != current && !current->is_preemption_cancelled() && (state == java_lang_VirtualThread::PARKING || state == java_lang_VirtualThread::YIELDING)), "invariant");
410+
(owner() != current && !current->is_preemption_cancelled() && (state == java_lang_VirtualThread::BLOCKING || state == java_lang_VirtualThread::YIELDING)), "invariant");
411411
return true;
412412
}
413413
}
@@ -992,7 +992,7 @@ bool ObjectMonitor::HandlePreemptedVThread(JavaThread* current, ContinuationEntr
992992

993993
oop vthread = current->vthread();
994994
assert(java_lang_VirtualThread::state(vthread) == java_lang_VirtualThread::RUNNING, "wrong state for vthread");
995-
java_lang_VirtualThread::set_state(vthread, java_lang_VirtualThread::PARKING);
995+
java_lang_VirtualThread::set_state(vthread, java_lang_VirtualThread::BLOCKING);
996996

997997
ObjectWaiter* node = new ObjectWaiter(vthread);
998998
node->_prev = (ObjectWaiter*) 0xBAD;
@@ -1036,7 +1036,7 @@ bool ObjectMonitor::HandlePreemptedVThread(JavaThread* current, ContinuationEntr
10361036
// having that check happening before we added the node to _cxq and the release
10371037
// of the monitor happening after the last TryLock attempt we need to do something
10381038
// to avoid stranding. We set the _Responsible field which platform threads results
1039-
// in a timed-wait. For vthreads we will set the state to YIELDING instead of PARKING
1039+
// in a timed-wait. For vthreads we will set the state to YIELDING instead of BLOCKING
10401040
// so that the vthread is just added again into the scheduler queue.
10411041
Atomic::replace_if_null(&_Responsible, (JavaThread*)java_lang_Thread::thread_id(vthread));
10421042
java_lang_VirtualThread::set_state(vthread, java_lang_VirtualThread::YIELDING);
@@ -1153,7 +1153,7 @@ void ObjectMonitor::redo_enter(JavaThread* current) {
11531153

11541154
assert(java_lang_VirtualThread::state(vthread) == java_lang_VirtualThread::RUNNING, "wrong state for vthread");
11551155
bool should_yield = _Responsible == (JavaThread*)java_lang_Thread::thread_id(vthread);
1156-
java_lang_VirtualThread::set_state(vthread, should_yield ? java_lang_VirtualThread::YIELDING : java_lang_VirtualThread::PARKING);
1156+
java_lang_VirtualThread::set_state(vthread, should_yield ? java_lang_VirtualThread::YIELDING : java_lang_VirtualThread::BLOCKING);
11571157
}
11581158

11591159
void ObjectMonitor::VThreadEpilog(JavaThread* current) {

‎src/java.base/share/classes/java/lang/VirtualThread.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ private void afterYield() {
529529
// blocking on monitorenter
530530
if (s == BLOCKING) {
531531
setState(BLOCKED);
532+
532533
if (unblocked && compareAndSetState(BLOCKED, RUNNABLE)) {
533534
unblocked = false;
534535
submitRunContinuation();
@@ -1361,7 +1362,7 @@ private static void processPendingList() {
13611362
while (currentWaitingVThread != null) {
13621363
nextWaitingVThread = currentWaitingVThread.next();
13631364
currentWaitingVThread.removeFromWaitingList();
1364-
currentWaitingVThread.unpark();
1365+
currentWaitingVThread.unblock();
13651366
currentWaitingVThread = nextWaitingVThread;
13661367
}
13671368
}

0 commit comments

Comments
 (0)
Please sign in to comment.