Add allocation stack traces for HPROF dump.
This feature is currently only enabled when DDMS's allocation tracking
is enabled. In the future there should be a way to enable this feature
before an application starts.
Also updates DDMS's recent allocation tracking to use a new backend
data structure that is shared with this feature.
The following system properties controls customizable parameters:
dalvik.vm.allocTrackerMax: max number of objects that have allocation
records, default 512K;
dalvik.vm.recentAllocMax: max number of records that are sent to DDMS
when clicking "Get allocation" button,
default 64K-1 (limit of the protocol);
dalvik.vm.allocStackDepth: max number of stack frames in an allocation
record, default 4.
Bug: 20037135
Change-Id: I26ed378a5613678bd3c43e846025f90470a8e059
diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h
index 81a9741..09bd370 100644
--- a/runtime/gc/heap.h
+++ b/runtime/gc/heap.h
@@ -58,6 +58,7 @@
namespace gc {
+class AllocRecordObjectMap;
class ReferenceProcessor;
class TaskProcessor;
@@ -683,6 +684,27 @@
void DumpGcCountRateHistogram(std::ostream& os) const;
void DumpBlockingGcCountRateHistogram(std::ostream& os) const;
+ // Allocation tracking support
+ // Callers to this function use double-checked locking to ensure safety on allocation_records_
+ bool IsAllocTrackingEnabled() const {
+ return alloc_tracking_enabled_.LoadRelaxed();
+ }
+
+ void SetAllocTrackingEnabled(bool enabled) EXCLUSIVE_LOCKS_REQUIRED(Locks::alloc_tracker_lock_) {
+ alloc_tracking_enabled_.StoreRelaxed(enabled);
+ }
+
+ AllocRecordObjectMap* GetAllocationRecords() const
+ EXCLUSIVE_LOCKS_REQUIRED(Locks::alloc_tracker_lock_) {
+ return allocation_records_.get();
+ }
+
+ void SetAllocationRecords(AllocRecordObjectMap* records)
+ EXCLUSIVE_LOCKS_REQUIRED(Locks::alloc_tracker_lock_);
+
+ void SweepAllocationRecords(IsMarkedCallback* visitor, void* arg) const
+ SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+
private:
class ConcurrentGCTask;
class CollectorTransitionTask;
@@ -1191,6 +1213,11 @@
// The histogram of the number of blocking GC invocations per window duration.
Histogram<uint64_t> blocking_gc_count_rate_histogram_ GUARDED_BY(gc_complete_lock_);
+ // Allocation tracking support
+ Atomic<bool> alloc_tracking_enabled_;
+ std::unique_ptr<AllocRecordObjectMap> allocation_records_
+ GUARDED_BY(Locks::alloc_tracker_lock_);
+
friend class CollectorTransitionTask;
friend class collector::GarbageCollector;
friend class collector::MarkCompact;