From 8cc0f19e6164f4d7d9a3775f84abf6400d16bdc8 Mon Sep 17 00:00:00 2001 From: Jim Chen Date: Wed, 5 Feb 2014 12:37:54 -0600 Subject: [PATCH] Bug 959214 - Use unwinder when getting ANR native stack; r=blassey --- mobile/android/base/ANRReporter.java | 6 ++++-- mozglue/android/jni-stubs.inc | 6 +++--- widget/android/AndroidJNI.cpp | 24 +++++++++++++++++++----- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/mobile/android/base/ANRReporter.java b/mobile/android/base/ANRReporter.java index 05a87eec5ca1..5fe2cabd601d 100644 --- a/mobile/android/base/ANRReporter.java +++ b/mobile/android/base/ANRReporter.java @@ -54,7 +54,7 @@ public final class ANRReporter extends BroadcastReceiver private Handler mHandler; private volatile boolean mPendingANR; - private static native boolean requestNativeStack(); + private static native boolean requestNativeStack(boolean unwind); private static native String getNativeStack(); private static native void releaseNativeStack(); @@ -460,7 +460,9 @@ public final class ANRReporter extends BroadcastReceiver private static void processTraces(Reader traces, File pingFile) { - boolean haveNativeStack = requestNativeStack(); + // Unwinding is memory intensive; only unwind if we have enough memory + boolean haveNativeStack = requestNativeStack( + /* unwind */ SysInfo.getMemSize() >= 640); try { OutputStream ping = new BufferedOutputStream( new FileOutputStream(pingFile), TRACES_BLOCK_SIZE); diff --git a/mozglue/android/jni-stubs.inc b/mozglue/android/jni-stubs.inc index d55625265b91..66565fcf4a29 100644 --- a/mozglue/android/jni-stubs.inc +++ b/mozglue/android/jni-stubs.inc @@ -533,16 +533,16 @@ Java_org_mozilla_gecko_gfx_NativePanZoomController_getOverScrollMode(JNIEnv * ar #ifdef JNI_STUBS -typedef jboolean (*Java_org_mozilla_gecko_ANRReporter_requestNativeStack_t)(JNIEnv *, jclass); +typedef jboolean (*Java_org_mozilla_gecko_ANRReporter_requestNativeStack_t)(JNIEnv *, jclass, jboolean); static Java_org_mozilla_gecko_ANRReporter_requestNativeStack_t f_Java_org_mozilla_gecko_ANRReporter_requestNativeStack; extern "C" NS_EXPORT jboolean JNICALL -Java_org_mozilla_gecko_ANRReporter_requestNativeStack(JNIEnv * arg0, jclass arg1) { +Java_org_mozilla_gecko_ANRReporter_requestNativeStack(JNIEnv * arg0, jclass arg1, jboolean arg2) { if (!f_Java_org_mozilla_gecko_ANRReporter_requestNativeStack) { arg0->ThrowNew(arg0->FindClass("java/lang/UnsupportedOperationException"), "JNI Function called before it was loaded"); return false; } - return f_Java_org_mozilla_gecko_ANRReporter_requestNativeStack(arg0, arg1); + return f_Java_org_mozilla_gecko_ANRReporter_requestNativeStack(arg0, arg1, arg2); } #endif diff --git a/widget/android/AndroidJNI.cpp b/widget/android/AndroidJNI.cpp index 077032c1d5e4..c92705785b3a 100644 --- a/widget/android/AndroidJNI.cpp +++ b/widget/android/AndroidJNI.cpp @@ -945,7 +945,7 @@ Java_org_mozilla_gecko_gfx_NativePanZoomController_getOverScrollMode(JNIEnv* env } NS_EXPORT jboolean JNICALL -Java_org_mozilla_gecko_ANRReporter_requestNativeStack(JNIEnv*, jclass) +Java_org_mozilla_gecko_ANRReporter_requestNativeStack(JNIEnv*, jclass, jboolean aUnwind) { if (profiler_is_active()) { // Don't proceed if profiler is already running @@ -955,11 +955,25 @@ Java_org_mozilla_gecko_ANRReporter_requestNativeStack(JNIEnv*, jclass) // generally unsafe to use the profiler from off the main thread. However, // the risk here is limited because for most users, the profiler is not run // elsewhere. See the discussion in Bug 863777, comment 13 - const char *NATIVE_STACK_FEATURES[] = {"leaf", "threads", "privacy"}; + const char *NATIVE_STACK_FEATURES[] = + {"leaf", "threads", "privacy"}; + const char *NATIVE_STACK_UNWIND_FEATURES[] = + {"leaf", "threads", "privacy", "stackwalk"}; + + const char **features = NATIVE_STACK_FEATURES; + size_t features_size = sizeof(NATIVE_STACK_FEATURES); + if (aUnwind) { + features = NATIVE_STACK_UNWIND_FEATURES; + features_size = sizeof(NATIVE_STACK_UNWIND_FEATURES); + // We want the new unwinder if the unwind mode has not been set yet + putenv("MOZ_PROFILER_NEW=1"); + } + + const char *NATIVE_STACK_THREADS[] = + {"GeckoMain", "Compositor"}; // Buffer one sample and let the profiler wait a long time - profiler_start(100, 10000, NATIVE_STACK_FEATURES, - sizeof(NATIVE_STACK_FEATURES) / sizeof(char*), - nullptr, 0); + profiler_start(100, 10000, features, features_size / sizeof(char*), + NATIVE_STACK_THREADS, sizeof(NATIVE_STACK_THREADS) / sizeof(char*)); return JNI_TRUE; }