24
24
#include " j9protos.h"
25
25
#include " j9vmnls.h"
26
26
#include " objhelp.h"
27
- #if JAVA_SPEC_VERSION >= 24
28
- #include " thrtypes.h"
29
- #endif /* JAVA_SPEC_VERSION >= 24 */
30
27
#include " ut_j9vm.h"
31
28
#include " vm_api.h"
32
29
#include " AtomicSupport.hpp"
@@ -1191,7 +1188,7 @@ waitForSignal(J9VMThread *currentThread)
1191
1188
*/
1192
1189
omrthread_monitor_enter (vm->blockedVirtualThreadsMutex );
1193
1190
if (!vm->pendingBlockedVirtualThreadsNotify ) {
1194
- omrthread_monitor_wait_interruptable (vm->blockedVirtualThreadsMutex , 0 , 0 );
1191
+ omrthread_monitor_wait_interruptable (vm->blockedVirtualThreadsMutex , vm-> unblockerWaitTime , 0 );
1195
1192
}
1196
1193
vm->pendingBlockedVirtualThreadsNotify = FALSE ;
1197
1194
omrthread_monitor_exit (vm->blockedVirtualThreadsMutex );
@@ -1245,18 +1242,18 @@ takeVirtualThreadListToUnblock(J9VMThread *currentThread)
1245
1242
switch (state) {
1246
1243
case JAVA_LANG_VIRTUALTHREAD_BLOCKING:
1247
1244
{
1248
- omrthread_monitor_t monitor = syncObjectMonitor->monitor ;
1249
- /* For BLOCKING and BLOCKED states, VirtualThread.blockPermit will allow
1245
+ /* For BLOCKING state, VirtualThread.blockPermit will allow
1250
1246
* VirtualThread.afterYield() to reschedule the thread.
1251
1247
*
1252
1248
* Set blockPermit only if the monitor's blocker object is available.
1253
1249
*
1254
- * All blocking/waiting monitors have to be inflated. If the monitor has not been inflated,
1250
+ * All blocking monitors have to be inflated. If the monitor has not been inflated,
1255
1251
* then the owner has not yet released the flat lock.
1252
+ *
1253
+ * There is a special case where the FLC bit maybe overwritten by fast exit code,
1254
+ * so also unblock thread if the blocking object has a unowned flatlock.
1256
1255
*/
1257
- if (J9_ARE_ANY_BITS_SET (((J9ThreadMonitor *)monitor)->flags , J9THREAD_MONITOR_INFLATED)
1258
- && (0 == monitor->count )
1259
- ) {
1256
+ if (VM_ContinuationHelpers::isBlockingMonitorUnowned (currentThread, current->vthread )) {
1260
1257
J9VMJAVALANGVIRTUALTHREAD_SET_BLOCKPERMIT (currentThread, current->vthread , JNI_TRUE);
1261
1258
}
1262
1259
previous = current;
@@ -1284,9 +1281,9 @@ takeVirtualThreadListToUnblock(J9VMThread *currentThread)
1284
1281
) {
1285
1282
Assert_VM_true (syncObjectMonitor->virtualThreadWaitCount > 0 );
1286
1283
omrthread_monitor_t monitor = syncObjectMonitor->monitor ;
1287
- /* All blocking/ waiting monitors have to be inflated. If the monitor has not been inflated,
1288
- * then the owner has not yet released the flat lock .
1289
- */
1284
+ /* All waiting monitors have to be inflated. If the monitor has not been inflated,
1285
+ * then wait call have not been done correctly .
1286
+ */
1290
1287
if (J9_ARE_ANY_BITS_SET (((J9ThreadMonitor *)monitor)->flags , J9THREAD_MONITOR_INFLATED)
1291
1288
&& (0 == monitor->count )
1292
1289
) {
@@ -1299,18 +1296,16 @@ takeVirtualThreadListToUnblock(J9VMThread *currentThread)
1299
1296
case JAVA_LANG_VIRTUALTHREAD_BLOCKED:
1300
1297
{
1301
1298
Assert_VM_true (syncObjectMonitor->virtualThreadWaitCount > 0 );
1302
- omrthread_monitor_t monitor = syncObjectMonitor->monitor ;
1303
- /* For BLOCKING and BLOCKED states, VirtualThread.blockPermit will allow
1304
- * VirtualThread.afterYield() to reschedule the thread.
1299
+ /* For BLOCKED state, set VirtualThread.onWaitingList and
1300
+ * add vthread to the unblock list so unblocker can reschedule.
1305
1301
*
1306
- * Set blockPermit only if the monitor's blocker object is available.
1307
- *
1308
- * All blocking/waiting monitors have to be inflated. If the monitor has not been inflated,
1302
+ * All blocked monitors have to be inflated. If the monitor has not been inflated,
1309
1303
* then the owner has not yet released the flat lock.
1304
+ *
1305
+ * There is a special case where the FLC bit maybe overwritten by fast exit code,
1306
+ * so also unblock thread if the blocking object has a unowned flatlock.
1310
1307
*/
1311
- if (J9_ARE_ANY_BITS_SET (((J9ThreadMonitor *)monitor)->flags , J9THREAD_MONITOR_INFLATED)
1312
- && (0 == monitor->count )
1313
- ) {
1308
+ if (VM_ContinuationHelpers::isBlockingMonitorUnowned (currentThread, current->vthread )) {
1314
1309
unblocked = true ;
1315
1310
syncObjectMonitor->virtualThreadWaitCount -= 1 ;
1316
1311
J9VMJAVALANGVIRTUALTHREAD_SET_ONWAITINGLIST (currentThread, current->vthread , JNI_TRUE);
0 commit comments