summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Hans Boehm <hboehm@google.com> 2017-11-03 15:56:59 -0700
committer Hans Boehm <hboehm@google.com> 2017-11-30 15:29:11 -0800
commitc79595fefa09166b5df5f66f5c6889721b05972c (patch)
tree96d27c114ad6195e88bfcc38c283c5dcc232cf26
parent8f380ab29c8606bca861ba21eee52cedfbc99f46 (diff)
Ensure that debug builds crash again if there is a BinderProxy leak.
This fails when trying to run the AOSP mailer with CRASH_AT_SIZE = 500, when the check interval is reduced sufficiently so that the test is actually executed. System server has been observed to use more than 1000 BinderProxies. Thus 5000 seems like roughly the lowest safe limit. Note that the test is executed somewhat rarely, so we may exceed this number by quite a few before we actually crash. Bug: 65760710 Test: Builds, AOSP boots & works for a few tasks. Fails as expected with reduced limit. Change-Id: I1c999b85e1ba1bd1d166a9ffba4f0b3992ffee45
-rw-r--r--core/java/android/os/Binder.java9
1 files changed, 8 insertions, 1 deletions
diff --git a/core/java/android/os/Binder.java b/core/java/android/os/Binder.java
index 3c1d83c44cde..86e58291edc6 100644
--- a/core/java/android/os/Binder.java
+++ b/core/java/android/os/Binder.java
@@ -767,6 +767,8 @@ 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:
+ private static final int CRASH_AT_SIZE = 5_000;
/**
* We next warn when we exceed this bucket size.
@@ -888,9 +890,14 @@ final class BinderProxy implements IBinder {
keyArray[size] = key;
}
if (size >= mWarnBucketSize) {
+ final int total_size = size();
Log.v(Binder.TAG, "BinderProxy map growth! bucket size = " + size
- + " total = " + size());
+ + " total = " + total_size);
mWarnBucketSize += WARN_INCREMENT;
+ if (Build.IS_DEBUGGABLE && total_size > CRASH_AT_SIZE) {
+ throw new AssertionError("Binder ProxyMap has too many entries. "
+ + "BinderProxy leak?");
+ }
}
}