OSDN Git Service

Go to suspended before waiting for GC to complete.
authorMathieu Chartier <mathieuc@google.com>
Fri, 19 May 2017 20:05:06 +0000 (13:05 -0700)
committerandroid-build-team Robot <android-build-team-robot@google.com>
Mon, 22 May 2017 23:38:23 +0000 (23:38 +0000)
We are not allowed to wait on the GC complete lock while holding the
mutator lock.

Bug: 38449715
Bug: 38350590

Test: test-art-host

(cherry picked from commit b93d5b1f39fb0651dfe2f165ad1431c962f5a78e)

Change-Id: Ib5b6d99b82f0c4a999bfcbbb1f5271da41a51040
(cherry picked from commit 5dc8a08723afa5373abf6ccfc7c0fd57eb7a2936)

runtime/gc/heap.cc

index bd4f99b..e1cb5b4 100644 (file)
@@ -1407,6 +1407,9 @@ void Heap::TrimIndirectReferenceTables(Thread* self) {
 }
 
 void Heap::StartGC(Thread* self, GcCause cause, CollectorType collector_type) {
+  // Need to do this before acquiring the locks since we don't want to get suspended while
+  // holding any locks.
+  ScopedThreadStateChange tsc(self, kWaitingForGcToComplete);
   MutexLock mu(self, *gc_complete_lock_);
   // Ensure there is only one GC at a time.
   WaitForGcToCompleteLocked(cause, self);
@@ -1415,14 +1418,9 @@ void Heap::StartGC(Thread* self, GcCause cause, CollectorType collector_type) {
 }
 
 void Heap::TrimSpaces(Thread* self) {
-  {
-    // Need to do this before acquiring the locks since we don't want to get suspended while
-    // holding any locks.
-    ScopedThreadStateChange tsc(self, kWaitingForGcToComplete);
-    // Pretend we are doing a GC to prevent background compaction from deleting the space we are
-    // trimming.
-    StartGC(self, kGcCauseTrim, kCollectorTypeHeapTrim);
-  }
+  // Pretend we are doing a GC to prevent background compaction from deleting the space we are
+  // trimming.
+  StartGC(self, kGcCauseTrim, kCollectorTypeHeapTrim);
   ScopedTrace trace(__PRETTY_FUNCTION__);
   const uint64_t start_ns = NanoTime();
   // Trim the managed spaces.