Add instances to sites after removing duplicate ids.
Wait until we've had a chance to remove instances with duplicate ids
before adding instances to their corresponding allocation site.
Reuses the existing iteration over instances that was previously used
for updating registered native sizes and moves that after the
reachability computation in preparation for some anticipated future
changes.
Bug: 110447634
Test: m ahat-test
Test: run ahat on the heap dump from the bug and confirm no duplicate
instances show up in the list of byte[] instances.
Change-Id: Ie8651d26724148501a7534c9600885002627cd19
diff --git a/tools/ahat/src/main/com/android/ahat/heapdump/AhatInstance.java b/tools/ahat/src/main/com/android/ahat/heapdump/AhatInstance.java
index 20f368f..a321ec0 100644
--- a/tools/ahat/src/main/com/android/ahat/heapdump/AhatInstance.java
+++ b/tools/ahat/src/main/com/android/ahat/heapdump/AhatInstance.java
@@ -82,7 +82,6 @@
void initialize(AhatHeap heap, Site site, AhatClassObj classObj) {
mHeap = heap;
mSite = site;
- site.addInstance(this);
mClassObj = classObj;
}
diff --git a/tools/ahat/src/main/com/android/ahat/heapdump/AhatSnapshot.java b/tools/ahat/src/main/com/android/ahat/heapdump/AhatSnapshot.java
index d9c7a19..12d3755 100644
--- a/tools/ahat/src/main/com/android/ahat/heapdump/AhatSnapshot.java
+++ b/tools/ahat/src/main/com/android/ahat/heapdump/AhatSnapshot.java
@@ -47,15 +47,19 @@
mHeaps = heaps;
mRootSite = rootSite;
- // Update registered native allocation size.
- for (AhatInstance cleaner : mInstances) {
- AhatInstance.RegisteredNativeAllocation nra = cleaner.asRegisteredNativeAllocation();
+ AhatInstance.computeReachability(mSuperRoot, progress, mInstances.size());
+
+ for (AhatInstance inst : mInstances) {
+ // Add this instance to its site.
+ inst.getSite().addInstance(inst);
+
+ // Update registered native allocation size.
+ AhatInstance.RegisteredNativeAllocation nra = inst.asRegisteredNativeAllocation();
if (nra != null) {
nra.referent.addRegisteredNativeSize(nra.size);
}
}
- AhatInstance.computeReachability(mSuperRoot, progress, mInstances.size());
DominatorsComputation.computeDominators(mSuperRoot, progress, mInstances.size());
AhatInstance.computeRetainedSize(mSuperRoot, mHeaps.size());