From d4f9da0795573c14006d0795ff288aadbacd33b5 Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Tue, 6 Jul 2021 10:03:38 +0200 Subject: [PATCH] Throw BinderProxyMapSizeException when hitting limits. To make it easier to cluster these errors. Test: N/A Change-Id: Id967c1d537ca655df2363bf38a798d632bf1b160 --- core/java/android/os/BinderProxy.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core/java/android/os/BinderProxy.java b/core/java/android/os/BinderProxy.java index d44b016cb5d00..2afbe8b2c4aa1 100644 --- a/core/java/android/os/BinderProxy.java +++ b/core/java/android/os/BinderProxy.java @@ -53,6 +53,12 @@ public final class BinderProxy implements IBinder { private static volatile Binder.ProxyTransactListener sTransactListener = null; + private static class BinderProxyMapSizeException extends AssertionError { + BinderProxyMapSizeException(String s) { + super(s); + } + }; + /** * @see {@link Binder#setProxyTransactListener(listener)}. */ @@ -73,7 +79,10 @@ public final class BinderProxy implements IBinder { private static final int LOG_MAIN_INDEX_SIZE = 8; private static final int MAIN_INDEX_SIZE = 1 << LOG_MAIN_INDEX_SIZE; private static final int MAIN_INDEX_MASK = MAIN_INDEX_SIZE - 1; - // Debuggable builds will throw an AssertionError if the number of map entries exceeds: + /** + * Debuggable builds will throw an BinderProxyMapSizeException if the number of + * map entries exceeds: + */ private static final int CRASH_AT_SIZE = 20_000; /** @@ -228,7 +237,8 @@ public final class BinderProxy implements IBinder { dumpProxyInterfaceCounts(); dumpPerUidProxyCounts(); Runtime.getRuntime().gc(); - throw new AssertionError("Binder ProxyMap has too many entries: " + throw new BinderProxyMapSizeException( + "Binder ProxyMap has too many entries: " + totalSize + " (total), " + totalUnclearedSize + " (uncleared), " + unclearedSize() + " (uncleared after GC). BinderProxy leak?"); } else if (totalSize > 3 * totalUnclearedSize / 2) {