From ae07ecf3766c38af1c12822458b98036b28bd4c0 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 6 Jul 2011 17:33:27 -0700 Subject: [PATCH] Add the "debug.jni.logging" property so third-party developers can debug their JNI problems. This turns on the super-verbose but indispensible logging of all native method calls and all calls to JNI functions (for third-party code only). In particular, if you have a local reference bug, you can search for the reference given in the crash and see exactly where it came from. In every case I've seen so far, that's pinpointed the bug exactly. Change-Id: Ifb7ba02ae637bdd53cd8500febdcb9d4d7799bda --- core/java/android/os/Process.java | 3 +++ core/java/com/android/internal/os/ZygoteConnection.java | 6 ++++-- .../java/com/android/server/am/ActivityManagerService.java | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java index 05e39ac55a89a..673b187a9d367 100644 --- a/core/java/android/os/Process.java +++ b/core/java/android/os/Process.java @@ -522,6 +522,9 @@ public class Process { argsForZygote.add("--runtime-init"); argsForZygote.add("--setuid=" + uid); argsForZygote.add("--setgid=" + gid); + if ((debugFlags & Zygote.DEBUG_ENABLE_JNI_LOGGING) != 0) { + argsForZygote.add("--enable-jni-logging"); + } if ((debugFlags & Zygote.DEBUG_ENABLE_SAFEMODE) != 0) { argsForZygote.add("--enable-safemode"); } diff --git a/core/java/com/android/internal/os/ZygoteConnection.java b/core/java/com/android/internal/os/ZygoteConnection.java index b872e22c35878..7cb002c08b6ad 100644 --- a/core/java/com/android/internal/os/ZygoteConnection.java +++ b/core/java/com/android/internal/os/ZygoteConnection.java @@ -328,8 +328,8 @@ class ZygoteConnection { boolean peerWait; /** - * From --enable-debugger, --enable-checkjni, --enable-assert, and - * --enable-safemode + * From --enable-debugger, --enable-checkjni, --enable-assert, + * --enable-safemode, and --enable-jni-logging. */ int debugFlags; @@ -408,6 +408,8 @@ class ZygoteConnection { debugFlags |= Zygote.DEBUG_ENABLE_SAFEMODE; } else if (arg.equals("--enable-checkjni")) { debugFlags |= Zygote.DEBUG_ENABLE_CHECKJNI; + } else if (arg.equals("--enable-jni-logging")) { + debugFlags |= Zygote.DEBUG_ENABLE_JNI_LOGGING; } else if (arg.equals("--enable-assert")) { debugFlags |= Zygote.DEBUG_ENABLE_ASSERT; } else if (arg.equals("--peer-wait")) { diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java index 48b0b667c2f81..29cccb6b61351 100644 --- a/services/java/com/android/server/am/ActivityManagerService.java +++ b/services/java/com/android/server/am/ActivityManagerService.java @@ -1953,6 +1953,9 @@ public final class ActivityManagerService extends ActivityManagerNative if ("1".equals(SystemProperties.get("debug.checkjni"))) { debugFlags |= Zygote.DEBUG_ENABLE_CHECKJNI; } + if ("1".equals(SystemProperties.get("debug.jni.logging"))) { + debugFlags |= Zygote.DEBUG_ENABLE_JNI_LOGGING; + } if ("1".equals(SystemProperties.get("debug.assert"))) { debugFlags |= Zygote.DEBUG_ENABLE_ASSERT; }