Serialize calls into BinderProxy.

The BinderProxy class is not thread-safe, hence all calls into it
must be serialized. This was achieved by holding the gProxyLock in
JNI code. However, a recent change added calls into BinderProxy
from ActivityManagerService without holding that lock, causing
ConcurrentModificationExceptions.

Instead of dumping debug info from AMS, make the call directly
from JNI, so we can make sure gProxyLock is held correctly.

Also, only dump on debug builds.

Bug: 71353150
Bug: 109701487
Test: sailfish builds, boots, info gets dumped with lowered limits.
Change-Id: I446a71ce4115b9936a01a170401ef98ba3818c0b
This commit is contained in:
Martijn Coenen
2018-06-05 11:02:23 +02:00
parent dea740bdce
commit dfa390e080
3 changed files with 36 additions and 14 deletions

View File

@@ -137,15 +137,6 @@ public class Binder implements IBinder {
sTracingEnabled = false;
}
/**
* Dump proxy debug information.
*
* @hide
*/
public static void dumpProxyDebugInfo() {
BinderProxy.dumpProxyDebugInfo();
}
/**
* Check if binder transaction tracing is enabled.
*
@@ -950,7 +941,8 @@ final class BinderProxy implements IBinder {
// about to crash.
final int totalUnclearedSize = unclearedSize();
if (totalUnclearedSize >= CRASH_AT_SIZE) {
dumpProxyDebugInfo();
dumpProxyInterfaceCounts();
dumpPerUidProxyCounts();
Runtime.getRuntime().gc();
throw new AssertionError("Binder ProxyMap has too many entries: "
+ totalSize + " (total), " + totalUnclearedSize + " (uncleared), "
@@ -1035,11 +1027,21 @@ final class BinderProxy implements IBinder {
private static ProxyMap sProxyMap = new ProxyMap();
/**
* Dump proxy debug information.
*
* Note: this method is not thread-safe; callers must serialize with other
* accesses to sProxyMap, in particular {@link #getInstance(long, long)}.
*
* @hide
*/
public static void dumpProxyDebugInfo() {
sProxyMap.dumpProxyInterfaceCounts();
sProxyMap.dumpPerUidProxyCounts();
private static void dumpProxyDebugInfo() {
if (Build.IS_DEBUGGABLE) {
sProxyMap.dumpProxyInterfaceCounts();
// Note that we don't call dumpPerUidProxyCounts(); this is because this
// method may be called as part of the uid limit being hit, and calling
// back into the UID tracking code would cause us to try to acquire a mutex
// that is held during that callback.
}
}
/**