Refactor ahat's perflib api.

This change substantially refactors how ahat accesses heap dump data.
Rather than use the perflib API directly with some additional
information accessed on the side via AhatSnapshot, we introduce an
entirely new API for accessing all the information we need from a heap
dump. Perflib is used when processing the heap dump to populate the
information initially, but afterwards all views and handlers go
through the new com.android.ahat.heapdump API.

The primary motivation for this change is to facilitate adding support
for diffing two heap dumps to ahat. The new API provides flexibility
that will make it easier to form links between objects in different
snapshots and introduce place holder objects to show when there is an
object in another snapshot that has no corresponding object in this
snapshot.

A large number of test cases were added to cover missing cases
discovered in the process of refactoring ahat's perflib API.

The external user-facing UI may have minor cosmetic changes, but
otherwise is unchanged.

Test: m ahat-test, with many new tests added.
Bug: 33770653

Change-Id: I1a6b05ea469ebbbac67d99129dd9faa457b4d17e
diff --git a/tools/ahat/src/DominatedList.java b/tools/ahat/src/DominatedList.java
index 7a673f5..c884e7f 100644
--- a/tools/ahat/src/DominatedList.java
+++ b/tools/ahat/src/DominatedList.java
@@ -16,8 +16,9 @@
 
 package com.android.ahat;
 
-import com.android.tools.perflib.heap.Heap;
-import com.android.tools.perflib.heap.Instance;
+import com.android.ahat.heapdump.AhatHeap;
+import com.android.ahat.heapdump.AhatInstance;
+import com.android.ahat.heapdump.AhatSnapshot;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -39,39 +40,32 @@
    * @param instances the collection of instances to generate a list for
    */
   public static void render(final AhatSnapshot snapshot,
-      Doc doc, Query query, String id, Collection<Instance> instances) {
-    List<Instance> insts = new ArrayList<Instance>(instances);
+      Doc doc, Query query, String id, Collection<AhatInstance> instances) {
+    List<AhatInstance> insts = new ArrayList<AhatInstance>(instances);
     Collections.sort(insts, Sort.defaultInstanceCompare(snapshot));
-    HeapTable.render(doc, query, id, new TableConfig(snapshot), snapshot, insts);
+    HeapTable.render(doc, query, id, new TableConfig(), snapshot, insts);
   }
 
-  private static class TableConfig implements HeapTable.TableConfig<Instance> {
-    AhatSnapshot mSnapshot;
-
-    public TableConfig(AhatSnapshot snapshot) {
-      mSnapshot = snapshot;
-    }
-
+  private static class TableConfig implements HeapTable.TableConfig<AhatInstance> {
     @Override
     public String getHeapsDescription() {
       return "Bytes Retained by Heap";
     }
 
     @Override
-    public long getSize(Instance element, Heap heap) {
-      int index = mSnapshot.getHeapIndex(heap);
-      return element.getRetainedSize(index);
+    public long getSize(AhatInstance element, AhatHeap heap) {
+      return element.getRetainedSize(heap);
     }
 
     @Override
-    public List<HeapTable.ValueConfig<Instance>> getValueConfigs() {
-      HeapTable.ValueConfig<Instance> value = new HeapTable.ValueConfig<Instance>() {
+    public List<HeapTable.ValueConfig<AhatInstance>> getValueConfigs() {
+      HeapTable.ValueConfig<AhatInstance> value = new HeapTable.ValueConfig<AhatInstance>() {
         public String getDescription() {
           return "Object";
         }
 
-        public DocString render(Instance element) {
-          return Value.render(mSnapshot, element);
+        public DocString render(AhatInstance element) {
+          return Summarizer.summarize(element);
         }
       };
       return Collections.singletonList(value);