@@ -326,7 +326,7 @@ class CheckinTask : public StateMachineTask {
326326 virtual void RunInternal () {
327327 data_->WaitUntil (kStartLoop );
328328
329- uword last_sync = OS::GetCurrentTimeMillis ();
329+ uword last_sync = OS::GetCurrentMonotonicMicros ();
330330 while (!data ()->IsIn (kPleaseExit )) {
331331 OS::SleepMicros (100 ); // Make test avoid consuming 100% CPU x kTaskCount.
332332 switch (data ()->level ) {
@@ -335,22 +335,22 @@ class CheckinTask : public StateMachineTask {
335335 RuntimeCallDeoptScope no_deopt (
336336 Thread::Current (), RuntimeCallDeoptAbility::kCannotLazyDeopt );
337337 if (SafepointIfRequested (thread_, data ()->gc_only_checkins )) {
338- last_sync = OS::GetCurrentTimeMillis ();
338+ last_sync = OS::GetCurrentMonotonicMicros ();
339339 }
340340 break ;
341341 }
342342 case SafepointLevel::kGCAndDeopt : {
343343 // This thread should join only GC and Deopt safepoint operations.
344344 if (SafepointIfRequested (thread_, data ()->deopt_checkin )) {
345- last_sync = OS::GetCurrentTimeMillis ();
345+ last_sync = OS::GetCurrentMonotonicMicros ();
346346 }
347347 break ;
348348 }
349349 case SafepointLevel::kGCAndDeoptAndReload : {
350350 // This thread should join any safepoint operations.
351351 ReloadParticipationScope allow_reload (thread_);
352352 if (SafepointIfRequested (thread_, data ()->reload_checkin )) {
353- last_sync = OS::GetCurrentTimeMillis ();
353+ last_sync = OS::GetCurrentMonotonicMicros ();
354354 }
355355 break ;
356356 }
@@ -367,8 +367,8 @@ class CheckinTask : public StateMachineTask {
367367 // After being quite sure to not have joined deopt safepoint if we only
368368 // support GC safepoints, we will eventually comply here to make main
369369 // thread continue.
370- const auto now = OS::GetCurrentTimeMillis ();
371- if ((now - last_sync) > 1000 ) {
370+ const auto now = OS::GetCurrentMonotonicMicros ();
371+ if ((now - last_sync) > 1000000 ) {
372372 ReloadParticipationScope allow_reload (thread_);
373373 if (SafepointIfRequested (thread_, data ()->timeout_checkin )) {
374374 last_sync = now;
@@ -494,25 +494,27 @@ ISOLATE_UNIT_TEST_CASE(SafepointOperation_SafepointPointTest) {
494494 for (intptr_t i = 0 ; i < kTaskCount ; i++) {
495495 threads[i]->WaitUntil (CheckinTask::kExited );
496496 }
497+ // Unlucky scheduling may result in more timeout checkins than intended, but
498+ // never checkins of otherwise the wrong type.
497499 for (intptr_t i = 0 ; i < kTaskCount ; ++i) {
498500 switch (task_to_level (i)) {
499501 case SafepointLevel::kGC :
500- EXPECT_EQ ( 2 , gc_only_checkins[i]);
501- EXPECT_EQ (0 , deopt_checkins[i]);
502- EXPECT_EQ (0 , reload_checkins[i]);
503- EXPECT_EQ ( 4 , timeout_checkins[i]);
502+ EXPECT_LE ( gc_only_checkins[i], 2 );
503+ EXPECT_EQ (deopt_checkins[i], 0 );
504+ EXPECT_EQ (reload_checkins[i], 0 );
505+ EXPECT_GE ( timeout_checkins[i], 4 );
504506 break ;
505507 case SafepointLevel::kGCAndDeopt :
506- EXPECT_EQ (0 , gc_only_checkins[i]);
507- EXPECT_EQ ( 4 , deopt_checkins[i]);
508- EXPECT_EQ (0 , reload_checkins[i]);
509- EXPECT_EQ ( 2 , timeout_checkins[i]);
508+ EXPECT_EQ (gc_only_checkins[i], 0 );
509+ EXPECT_LE ( deopt_checkins[i], 4 );
510+ EXPECT_EQ (reload_checkins[i], 0 );
511+ EXPECT_GE ( timeout_checkins[i], 2 );
510512 break ;
511513 case SafepointLevel::kGCAndDeoptAndReload :
512- EXPECT_EQ (0 , gc_only_checkins[i]);
513- EXPECT_EQ (0 , deopt_checkins[i]);
514- EXPECT_EQ ( 6 , reload_checkins[i]);
515- EXPECT_EQ ( 0 , timeout_checkins[i]);
514+ EXPECT_EQ (gc_only_checkins[i], 0 );
515+ EXPECT_EQ (deopt_checkins[i], 0 );
516+ EXPECT_LE ( reload_checkins[i], 6 );
517+ EXPECT_GE ( timeout_checkins[i], 0 );
516518 break ;
517519 case SafepointLevel::kNumLevels :
518520 case SafepointLevel::kNoSafepoint :
0 commit comments