Make allocation tracker use less memory
The allocation tracker no longer keeps recently allocated objects live.
Instead it just keeps their class objects live as strong roots. This fixed
the gc-stress test failure for 098-ddmc.
Also fixed the issue in DisableNewSystemWeak() for allocation tracker,
by making new allocation to wait until GC's sweeping to complete. I didn't
feel any significant slowdown with this wait.
Bug: 20037135
Change-Id: I6a98188832cf7ee478007e3788e742dc6e18f7b8
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index f0ba0bd..3dafb7d 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -3716,6 +3716,35 @@
}
}
+void Heap::AllowNewAllocationRecords() const {
+ if (IsAllocTrackingEnabled()) {
+ MutexLock mu(Thread::Current(), *Locks::alloc_tracker_lock_);
+ if (IsAllocTrackingEnabled()) {
+ GetAllocationRecords()->AllowNewAllocationRecords();
+ }
+ }
+}
+
+void Heap::DisallowNewAllocationRecords() const {
+ if (IsAllocTrackingEnabled()) {
+ MutexLock mu(Thread::Current(), *Locks::alloc_tracker_lock_);
+ if (IsAllocTrackingEnabled()) {
+ GetAllocationRecords()->DisallowNewAllocationRecords();
+ }
+ }
+}
+
+void Heap::EnsureNewAllocationRecordsDisallowed() const {
+ if (IsAllocTrackingEnabled()) {
+ // Lock and unlock once to ensure that no threads are still in the
+ // middle of adding new allocation records.
+ MutexLock mu(Thread::Current(), *Locks::alloc_tracker_lock_);
+ if (IsAllocTrackingEnabled()) {
+ GetAllocationRecords()->EnsureNewAllocationRecordsDisallowed();
+ }
+ }
+}
+
// Based on debug malloc logic from libc/bionic/debug_stacktrace.cpp.
class StackCrawlState {
public: