summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Richard Uhler <ruhler@google.com> 2025-01-02 13:16:03 -0800
committer Richard Uhler <ruhler@google.com> 2025-01-02 15:57:51 -0800
commit44022f13f1932dbcf948da823375c17dfc724a1c (patch)
treec657bac4b5dbc1d8ce03495878ea1eee77e170ae
parent3f87b5be94fb5340a38157e718dcc232e70e3029 (diff)
Remove ahat's dependency on guava.
Reduces the size of ahat.jar from 3.1M down to 188k. The 16x blowup in code size from guava is not worth the few lines of code saved. Test: m ahat-tests ; java -jar out/host/linux-x86/framework/ahat-tests.jar Test: Manual inspection of heap dump containing duplicate bitmaps. Change-Id: Ic3b09f92ffcca6a2a3c9aec1961251bb45aad2a3
-rw-r--r--tools/ahat/Android.bp3
-rw-r--r--tools/ahat/src/main/com/android/ahat/heapdump/AhatBitmapInstance.java31
2 files changed, 16 insertions, 18 deletions
diff --git a/tools/ahat/Android.bp b/tools/ahat/Android.bp
index e1c7314605..6db914b277 100644
--- a/tools/ahat/Android.bp
+++ b/tools/ahat/Android.bp
@@ -34,9 +34,6 @@ java_binary_host {
// Use a relaxed version to allow distribution against older runtimes.
java_version: "11",
javacflags: ["-Xdoclint:all/protected"],
- static_libs: [
- "guava",
- ],
}
// --- ahat-test-dump.jar --------------
diff --git a/tools/ahat/src/main/com/android/ahat/heapdump/AhatBitmapInstance.java b/tools/ahat/src/main/com/android/ahat/heapdump/AhatBitmapInstance.java
index 30631784ab..c8a48dd08a 100644
--- a/tools/ahat/src/main/com/android/ahat/heapdump/AhatBitmapInstance.java
+++ b/tools/ahat/src/main/com/android/ahat/heapdump/AhatBitmapInstance.java
@@ -17,16 +17,15 @@
package com.android.ahat.heapdump;
import java.awt.image.BufferedImage;
-import java.util.Arrays;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
-import java.util.stream.Collectors;
-import com.google.common.collect.TreeMultimap;
+import java.util.TreeMap;
/**
* A java object that has `android.graphics.Bitmap` as its base class.
@@ -66,14 +65,14 @@ public class AhatBitmapInstance extends AhatClassInstance implements Comparable<
private int format;
private Map<Long, byte[]> buffers;
private Set<Long> referenced;
- private TreeMultimap<BitmapInfo, AhatBitmapInstance> instances;
+ private Map<BitmapInfo, List<AhatBitmapInstance>> instances;
BitmapDumpData(int count, int format) {
this.count = count;
this.format = format;
this.buffers = new HashMap<Long, byte[]>(count);
this.referenced = new HashSet<Long>(count);
- this.instances = TreeMultimap.create();
+ this.instances = new TreeMap<>();
}
};
@@ -124,16 +123,15 @@ public class AhatBitmapInstance extends AhatClassInstance implements Comparable<
AhatBitmapInstance bmp = obj.asBitmapInstance();
if (bmp != null) {
BitmapInfo info = bmp.getBitmapInfo(result);
- if (info != null) {
- result.instances.put(info, bmp);
+
+ // Avoid adding instances referenced from BitmapDumpData. These
+ // instances shall *not* be counted.
+ if (info != null && !result.referenced.contains(bmp.getId())) {
+ result.instances.computeIfAbsent(info, k -> new ArrayList<>()).add(bmp);
}
}
}
- /* remove all instances referenced from BitmapDumpData,
- * these instances shall *not* be counted
- */
- instances.removeIf(i -> { return result.referenced.contains(i.getId()); });
return result;
}
@@ -182,10 +180,13 @@ public class AhatBitmapInstance extends AhatClassInstance implements Comparable<
*/
public static List<List<AhatBitmapInstance>> findDuplicates(BitmapDumpData bitmapDumpData) {
if (bitmapDumpData != null) {
- return bitmapDumpData.instances.keySet().stream()
- .filter(k -> bitmapDumpData.instances.get(k).size() > 1)
- .map(k -> new ArrayList<>(bitmapDumpData.instances.get(k)))
- .collect(Collectors.toList());
+ List<List<AhatBitmapInstance>> duplicates = new ArrayList<>();
+ for (List<AhatBitmapInstance> values : bitmapDumpData.instances.values()) {
+ if (values.size() > 1) {
+ duplicates.add(new ArrayList<>(values));
+ }
+ }
+ return duplicates;
}
return null;
}