Fix the CC monkey crashes.
Add ScopedGCCriticalSection around the monitor deflation to avoid race
conditions on the lock word.
Bug: 31773180
Bug: 31712602
Bug: 31712174
Bug: 31712601
Bug: 31712256
Bug: 31710993
Bug: 12687968
Test: test-art host/N9, N9 libartd boot, Ritz EAAC.
Change-Id: Id05c6502fb08ca2e0770af4940b737038c3412d6
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index 33f849a..01c4c62 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -47,6 +47,7 @@
#include "gc/collector/semi_space.h"
#include "gc/collector/sticky_mark_sweep.h"
#include "gc/reference_processor.h"
+#include "gc/scoped_gc_critical_section.h"
#include "gc/space/bump_pointer_space.h"
#include "gc/space/dlmalloc_space-inl.h"
#include "gc/space/image_space.h"
@@ -1423,6 +1424,8 @@
// Deflate the monitors, this can cause a pause but shouldn't matter since we don't care
// about pauses.
ScopedTrace trace("Deflating monitors");
+ // Avoid race conditions on the lock word for CC.
+ ScopedGCCriticalSection gcs(self, kGcCauseTrim, kCollectorTypeHeapTrim);
ScopedSuspendAll ssa(__FUNCTION__);
uint64_t start_time = NanoTime();
size_t count = runtime->GetMonitorList()->DeflateMonitors();