| Index: base/android/jni_android.h
|
| diff --git a/base/android/jni_android.h b/base/android/jni_android.h
|
| index 909e3daf7a303d0d3ed52275fb96e8a63725dd31..96746539b28c24322abdfb0bb7170dcfadaadf2c 100644
|
| --- a/base/android/jni_android.h
|
| +++ b/base/android/jni_android.h
|
| @@ -14,6 +14,39 @@
|
| #include "base/atomicops.h"
|
| #include "base/base_export.h"
|
| #include "base/compiler_specific.h"
|
| +#include "base/debug/stack_trace.h"
|
| +#include "base/macros.h"
|
| +
|
| +#if HAVE_TRACE_STACK_FRAME_POINTERS
|
| +
|
| +// When profiling is enabled (enable_profiling=true) this macro is added to
|
| +// all generated JNI stubs so that it becomes the last thing that runs before
|
| +// control goes into Java.
|
| +//
|
| +// This macro saves stack frame pointer of the current function. Saved value
|
| +// used later by JNI_LINK_SAVED_FRAME_POINTER.
|
| +#define JNI_SAVE_FRAME_POINTER \
|
| + base::android::JNIStackFrameSaver jni_frame_saver(__builtin_frame_address(0))
|
| +
|
| +// When profiling is enabled (enable_profiling=true) this macro is added to
|
| +// all generated JNI callbacks so that it becomes the first thing that runs
|
| +// after control returns from Java.
|
| +//
|
| +// This macro links stack frame of the current function to the stack frame
|
| +// saved by JNI_SAVE_FRAME_POINTER, allowing frame-based unwinding
|
| +// (used by the heap profiler) to produce complete traces.
|
| +#define JNI_LINK_SAVED_FRAME_POINTER \
|
| + base::debug::ScopedStackFrameLinker jni_frame_linker( \
|
| + __builtin_frame_address(0), \
|
| + base::android::JNIStackFrameSaver::SavedFrame())
|
| +
|
| +#else
|
| +
|
| +// Frame-based stack unwinding is not supported, do nothing.
|
| +#define JNI_SAVE_FRAME_POINTER
|
| +#define JNI_LINK_SAVED_FRAME_POINTER
|
| +
|
| +#endif // HAVE_TRACE_STACK_FRAME_POINTERS
|
|
|
| namespace base {
|
| namespace android {
|
| @@ -122,6 +155,24 @@ BASE_EXPORT void CheckException(JNIEnv* env);
|
| BASE_EXPORT std::string GetJavaExceptionInfo(JNIEnv* env,
|
| jthrowable java_throwable);
|
|
|
| +#if HAVE_TRACE_STACK_FRAME_POINTERS
|
| +
|
| +// Saves caller's PC and stack frame in a thread-local variable.
|
| +// Implemented only when profiling is enabled (enable_profiling=true).
|
| +class BASE_EXPORT JNIStackFrameSaver {
|
| + public:
|
| + JNIStackFrameSaver(void* current_fp);
|
| + ~JNIStackFrameSaver();
|
| + static void* SavedFrame();
|
| +
|
| + private:
|
| + void* previous_fp_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(JNIStackFrameSaver);
|
| +};
|
| +
|
| +#endif // HAVE_TRACE_STACK_FRAME_POINTERS
|
| +
|
| } // namespace android
|
| } // namespace base
|
|
|
|
|