OSDN Git Service

Fix profile saver initial wait
authorMathieu Chartier <mathieuc@google.com>
Thu, 19 May 2016 02:51:23 +0000 (19:51 -0700)
committerMathieu Chartier <mathieuc@google.com>
Thu, 19 May 2016 02:55:42 +0000 (19:55 -0700)
Was using TimedWait for the initial wait, but this can return
early if the process receives any interrupt (due to futex). The
solution is to use a wait loop. If the wait returned early, not
enough classes were including in the profile. This negatively
affected application launch times in some scenarios.

Sample wait times before the change:
Waited 2.002s
Waited 97.808ms
Waited 182.676ms
Waited 2.000s
Waited 1.678s

Bug: 27688727

Change-Id: Ia84878e1278d70b4cc239374a2107d0f111dbdc5

runtime/jit/profile_saver.cc

index 8358ce3..6085783 100644 (file)
@@ -97,7 +97,15 @@ void ProfileSaver::Run() {
   // classes save (unless they started before the initial saving was done).
   {
     MutexLock mu(self, wait_lock_);
-    period_condition_.TimedWait(self, kSaveResolvedClassesDelayMs, 0);
+    constexpr uint64_t kSleepTime = kSaveResolvedClassesDelayMs;
+    const uint64_t end_time = NanoTime() + MsToNs(kSleepTime);
+    while (true) {
+      const uint64_t current_time = NanoTime();
+      if (current_time >= end_time) {
+        break;
+      }
+      period_condition_.TimedWait(self, NsToMs(end_time - current_time), 0);
+    }
     total_ms_of_sleep_ += kSaveResolvedClassesDelayMs;
   }
   FetchAndCacheResolvedClasses();