summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Richard Uhler <ruhler@google.com> 2017-10-09 10:08:35 +0100
committer Richard Uhler <ruhler@google.com> 2017-10-09 10:08:35 +0100
commit82eeacee022429698a4b3516a1c114f51d6ef1a6 (patch)
tree82ca9b51c869d62ab0712d134ab43d9b38419702
parent25ae37970757ab06bb75b63a933926a4db4bb38d (diff)
Distinguish between weakly reachable and unreachable instances.
Annotate weakly reachable instances with "weak" instead of unreachable. Don't show a sample path from GC root for unreachable instances. Bug: 64785007 Test: m ahat-test Test: Manually inspect strong, weak, and unreachable instances. Change-Id: I1cb73d47198be847eaccd5855f6f14acf828a75a
-rw-r--r--tools/ahat/src/ObjectHandler.java5
-rw-r--r--tools/ahat/src/Summarizer.java4
-rw-r--r--tools/ahat/src/heapdump/AhatInstance.java23
-rw-r--r--tools/ahat/src/heapdump/Site.java2
-rw-r--r--tools/ahat/test/InstanceTest.java4
5 files changed, 32 insertions, 6 deletions
diff --git a/tools/ahat/src/ObjectHandler.java b/tools/ahat/src/ObjectHandler.java
index 79f8b76c92..c24f22bbf0 100644
--- a/tools/ahat/src/ObjectHandler.java
+++ b/tools/ahat/src/ObjectHandler.java
@@ -66,7 +66,10 @@ class ObjectHandler implements AhatHandler {
doc.big(Summarizer.summarize(inst));
printAllocationSite(doc, query, inst);
- printGcRootPath(doc, query, inst);
+
+ if (!inst.isUnreachable()) {
+ printGcRootPath(doc, query, inst);
+ }
doc.section("Object Info");
AhatClassObj cls = inst.getClassObj();
diff --git a/tools/ahat/src/Summarizer.java b/tools/ahat/src/Summarizer.java
index 50b2e4b3b3..901d5b2329 100644
--- a/tools/ahat/src/Summarizer.java
+++ b/tools/ahat/src/Summarizer.java
@@ -51,7 +51,9 @@ class Summarizer {
}
// Annotate unreachable objects as such.
- if (!inst.isReachable()) {
+ if (inst.isWeaklyReachable()) {
+ formatted.append("weak ");
+ } else if (inst.isUnreachable()) {
formatted.append("unreachable ");
}
diff --git a/tools/ahat/src/heapdump/AhatInstance.java b/tools/ahat/src/heapdump/AhatInstance.java
index c04448728f..cb2d738f23 100644
--- a/tools/ahat/src/heapdump/AhatInstance.java
+++ b/tools/ahat/src/heapdump/AhatInstance.java
@@ -136,13 +136,28 @@ public abstract class AhatInstance implements Diffable<AhatInstance>,
}
/**
- * Returns whether this object is strongly-reachable.
+ * Returns true if this object is strongly-reachable.
*/
- public boolean isReachable() {
+ public boolean isStronglyReachable() {
return mImmediateDominator != null;
}
/**
+ * Returns true if this object is reachable only through a
+ * soft/weak/phantom/finalizer reference.
+ */
+ public boolean isWeaklyReachable() {
+ return !isStronglyReachable() && mNextInstanceToGcRoot != null;
+ }
+
+ /**
+ * Returns true if this object is completely unreachable.
+ */
+ public boolean isUnreachable() {
+ return !isStronglyReachable() && !isWeaklyReachable();
+ }
+
+ /**
* Returns the heap that this instance is allocated on.
*/
public AhatHeap getHeap() {
@@ -499,6 +514,10 @@ public abstract class AhatInstance implements Diffable<AhatInstance>,
} else {
if (ref.ref.mSoftReverseReferences == null) {
ref.ref.mSoftReverseReferences = new ArrayList<AhatInstance>();
+ if (ref.ref.mNextInstanceToGcRoot == null) {
+ ref.ref.mNextInstanceToGcRoot = ref.src;
+ ref.ref.mNextInstanceToGcRootField = ref.field;
+ }
}
ref.ref.mSoftReverseReferences.add(ref.src);
}
diff --git a/tools/ahat/src/heapdump/Site.java b/tools/ahat/src/heapdump/Site.java
index 821493f1be..523550ad2c 100644
--- a/tools/ahat/src/heapdump/Site.java
+++ b/tools/ahat/src/heapdump/Site.java
@@ -186,7 +186,7 @@ public class Site implements Diffable<Site> {
// Add all reachable objects allocated at this site.
for (AhatInstance inst : mObjects) {
- if (inst.isReachable()) {
+ if (inst.isStronglyReachable()) {
AhatHeap heap = inst.getHeap();
Size size = inst.getSize();
ObjectsInfo info = getObjectsInfo(heap, inst.getClassObj());
diff --git a/tools/ahat/test/InstanceTest.java b/tools/ahat/test/InstanceTest.java
index 49a21e2d70..a4908fd0ab 100644
--- a/tools/ahat/test/InstanceTest.java
+++ b/tools/ahat/test/InstanceTest.java
@@ -214,7 +214,9 @@ public class InstanceTest {
// reference as having a non-null referent.
TestDump dump = TestDump.getTestDump();
AhatInstance ref = dump.getDumpedAhatInstance("aSoftReference");
- assertNotNull(ref.getReferent());
+ AhatInstance referent = ref.getReferent();
+ assertNotNull(referent);
+ assertTrue(referent.isWeaklyReachable());
}
@Test