Chromium Code Reviews| Index: base/android/jni_android.h |
| diff --git a/base/android/jni_android.h b/base/android/jni_android.h |
| index 909e3daf7a303d0d3ed52275fb96e8a63725dd31..3030f112094d6e554261736999e833969259b30f 100644 |
| --- a/base/android/jni_android.h |
| +++ b/base/android/jni_android.h |
| @@ -14,6 +14,41 @@ |
| #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_PROFILING_ENTERED_NATIVE. |
| +#define JNI_PROFILING_LEAVING_NATIVE \ |
|
Primiano Tucci (use gerrit)
2016/10/13 20:03:21
I'd just call these JNI_SAVE_FRAME_POINTER and JNI
Dmitry Skiba
2016/10/17 22:09:11
Done.
|
| + 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_PROFILING_LEAVING_NATIVE, allowing frame-based unwinding |
| +// (used by the heap profiler) to produce complete traces. |
| +#define JNI_PROFILING_ENTERED_NATIVE \ |
| + 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_PROFILING_LEAVING_NATIVE |
| +#define JNI_PROFILING_ENTERED_NATIVE |
| + |
| +#endif // HAVE_TRACE_STACK_FRAME_POINTERS |
| namespace base { |
| namespace android { |
| @@ -122,6 +157,22 @@ 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(); |
|
Primiano Tucci (use gerrit)
2016/10/13 20:03:21
s/SavedFrame/GetLastFrameSavedForCurrentThread()/
Dmitry Skiba
2016/10/17 22:09:11
This feels unnecessarily long. I think we should e
|
| + private: |
|
Primiano Tucci (use gerrit)
2016/10/13 20:03:21
micro-nit: add \n after private:
Dmitry Skiba
2016/10/17 22:09:11
Done.
|
| + void* previous_fp_; |
| + DISALLOW_COPY_AND_ASSIGN(JNIStackFrameSaver); |
|
Primiano Tucci (use gerrit)
2016/10/13 20:03:21
micro-nit: add extra \n before DISALLOW
Dmitry Skiba
2016/10/17 22:09:11
Done.
|
| +}; |
| + |
| +#endif // HAVE_TRACE_STACK_FRAME_POINTERS |
| + |
| } // namespace android |
| } // namespace base |