ahat: getImmediateDominator should not return the SuperRoot.

We should not be exposing the SuperRoot instance anywhere through the
public API, because the SuperRoot is not part of the public API. Change
getImmediateDominator to return null for "rooted" instances instead of
the SuperRoot instance to better match the documented behavior.

Test: atest ahat-tests, with new test added.
Change-Id: Id93a09bd714d7b00c6c50233f01d1af7b4258fae
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 281c977..e62fb40 100644
--- a/tools/ahat/src/main/com/android/ahat/heapdump/AhatInstance.java
+++ b/tools/ahat/src/main/com/android/ahat/heapdump/AhatInstance.java
@@ -264,6 +264,9 @@
    * @return the immediate dominator of this instance
    */
   public AhatInstance getImmediateDominator() {
+    if (mImmediateDominator instanceof SuperRoot) {
+      return null;
+    }
     return mImmediateDominator;
   }
 
diff --git a/tools/ahat/src/test/com/android/ahat/InstanceTest.java b/tools/ahat/src/test/com/android/ahat/InstanceTest.java
index af0a73b..376122b 100644
--- a/tools/ahat/src/test/com/android/ahat/InstanceTest.java
+++ b/tools/ahat/src/test/com/android/ahat/InstanceTest.java
@@ -412,6 +412,15 @@
   }
 
   @Test
+  public void isRoot() throws IOException {
+    // We expect the Main class to be a root.
+    TestDump dump = TestDump.getTestDump();
+    AhatInstance main = dump.findClass("Main");
+    assertTrue(main.isRoot());
+    assertNull(main.getImmediateDominator());
+  }
+
+  @Test
   public void isNotRoot() throws IOException {
     TestDump dump = TestDump.getTestDump();
     AhatInstance obj = dump.getDumpedAhatInstance("anObject");