Go to suspended before waiting for GC to complete.
We are not allowed to wait on the GC complete lock while holding the
mutator lock.
Bug: 38449715
Bug: 38350590
Test: test-art-host
Change-Id: I4e2dfe9496a56cd7fbe8de76a1bc8951e929ddb1
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 668fb4b..3f60968 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -1413,6 +1413,9 @@
}
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);
@@ -1421,14 +1424,9 @@
}
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.