Skip to content

Commit

Permalink
Merge pull request #16220 from JasonFengJ9/threadparkdelay
Browse files Browse the repository at this point in the history
CRIU avoid unnecessary park() when a balancing unpark() occurred
  • Loading branch information
tajila committed Oct 28, 2022
2 parents a05d1f2 + 28b0db0 commit 530b026
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions runtime/vm/threadhelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ timeCompensationHelper(J9VMThread *vmThread, U_8 threadHelperType, omrthread_mon
#endif /* defined(J9VM_OPT_CRIU_SUPPORT) */

switch(threadHelperType) {
/* Following three APIs return J9THREAD_TIMED_OUT when the timeout expired.
* A timeout of 0 (0ms, 0ns) indicates wait/park indefinitely.
*/
case HELPER_TYPE_MONITOR_WAIT_INTERRUPTABLE:
rc = omrthread_monitor_wait_interruptable(monitor, millis, nanos);
break;
Expand All @@ -439,6 +442,9 @@ timeCompensationHelper(J9VMThread *vmThread, U_8 threadHelperType, omrthread_mon
rc = omrthread_park(millis, nanos);
break;
case HELPER_TYPE_THREAD_SLEEP:
/* Returns 0 when the timeout specified passed.
* A timeout of 0 (0ms, 0ns) indicates an immediate return.
*/
rc = omrthread_sleep_interruptable(millis, nanos);
break;
default:
Expand All @@ -451,11 +457,18 @@ timeCompensationHelper(J9VMThread *vmThread, U_8 threadHelperType, omrthread_mon
if ((compensationMightBeRequired && J9_IS_CRIU_RESTORED(vm))
|| isThreadHaltedAtSingleThreadedMode
) {
/* There was a C/R and a compensation is required,
/* There was a C/R and a compensation might be required,
* or this is a halted thread at single threaded mode.
*/
bool timeCompensationRequired = TRUE;
if (waitTimed) {
const I_8 timeout10ms = 10;
bool timedout = FALSE;
if (HELPER_TYPE_THREAD_SLEEP == threadHelperType) {
timedout = 0 == rc;
} else {
timedout = J9THREAD_TIMED_OUT == rc;
}
if (waitTimed && timedout) {
PORT_ACCESS_FROM_JAVAVM(vm);
const I_32 oneMillion = 1000000;
I_64 nanoTimePast = j9time_nano_time() - nanoTimeStart;
Expand All @@ -477,7 +490,7 @@ timeCompensationHelper(J9VMThread *vmThread, U_8 threadHelperType, omrthread_mon
/* timed out since millisPast > millis or millisPast == millis && nanoTimePast >= nanos */
if (isThreadHaltedAtSingleThreadedMode) {
/* This is a halted thread at single threaded mode, sleep another 10ms. */
millis = 10;
millis = timeout10ms;
nanos = 0;
} else {
/* timed out and no compensation required */
Expand All @@ -490,8 +503,11 @@ timeCompensationHelper(J9VMThread *vmThread, U_8 threadHelperType, omrthread_mon
}
} else if (isThreadHaltedAtSingleThreadedMode) {
/* This is a halted thread at single threaded mode, wait another 10ms. */
millis = 10;
millis = timeout10ms;
nanos = 0;
} else {
/* No time compensation if not waitTimed and timedout, or not paused at single threaded mode. */
timeCompensationRequired = FALSE;
}
if (timeCompensationRequired) {
Assert_VM_false((0 == millis) && (0 == nanos));
Expand Down

0 comments on commit 530b026

Please sign in to comment.