Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(558)

Side by Side Diff: base/android/jni_android.h

Issue 2361353002: Link stack frames of JNI stubs to JNI callbacks. (Closed)
Patch Set: git cl format Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/android/jni_android.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_ANDROID_JNI_ANDROID_H_ 5 #ifndef BASE_ANDROID_JNI_ANDROID_H_
6 #define BASE_ANDROID_JNI_ANDROID_H_ 6 #define BASE_ANDROID_JNI_ANDROID_H_
7 7
8 #include <jni.h> 8 #include <jni.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 10
11 #include <string> 11 #include <string>
12 12
13 #include "base/android/scoped_java_ref.h" 13 #include "base/android/scoped_java_ref.h"
14 #include "base/atomicops.h" 14 #include "base/atomicops.h"
15 #include "base/base_export.h" 15 #include "base/base_export.h"
16 #include "base/compiler_specific.h" 16 #include "base/compiler_specific.h"
17 #include "base/debug/stack_trace.h"
18 #include "base/macros.h"
19
20 #if HAVE_TRACE_STACK_FRAME_POINTERS
21
22 // When profiling is enabled (enable_profiling=true) this macro is added to
23 // all generated JNI stubs so that it becomes the last thing that runs before
24 // control goes into Java.
25 //
26 // This macro saves stack frame pointer of the current function. Saved value
27 // used later by JNI_LINK_SAVED_FRAME_POINTER.
28 #define JNI_SAVE_FRAME_POINTER \
29 base::android::JNIStackFrameSaver jni_frame_saver(__builtin_frame_address(0))
30
31 // When profiling is enabled (enable_profiling=true) this macro is added to
32 // all generated JNI callbacks so that it becomes the first thing that runs
33 // after control returns from Java.
34 //
35 // This macro links stack frame of the current function to the stack frame
36 // saved by JNI_SAVE_FRAME_POINTER, allowing frame-based unwinding
37 // (used by the heap profiler) to produce complete traces.
38 #define JNI_LINK_SAVED_FRAME_POINTER \
39 base::debug::ScopedStackFrameLinker jni_frame_linker( \
40 __builtin_frame_address(0), \
41 base::android::JNIStackFrameSaver::SavedFrame())
42
43 #else
44
45 // Frame-based stack unwinding is not supported, do nothing.
46 #define JNI_SAVE_FRAME_POINTER
47 #define JNI_LINK_SAVED_FRAME_POINTER
48
49 #endif // HAVE_TRACE_STACK_FRAME_POINTERS
17 50
18 namespace base { 51 namespace base {
19 namespace android { 52 namespace android {
20 53
21 // Used to mark symbols to be exported in a shared library's symbol table. 54 // Used to mark symbols to be exported in a shared library's symbol table.
22 #define JNI_EXPORT __attribute__ ((visibility("default"))) 55 #define JNI_EXPORT __attribute__ ((visibility("default")))
23 56
24 // Used to disable manual JNI registration in binaries that prefer to use native 57 // Used to disable manual JNI registration in binaries that prefer to use native
25 // JNI exports for startup performance. This is not compatible with the crazy 58 // JNI exports for startup performance. This is not compatible with the crazy
26 // linker and so defaults to off. Call DisableManualJniRegistration at the very 59 // linker and so defaults to off. Call DisableManualJniRegistration at the very
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // and returns true. 148 // and returns true.
116 BASE_EXPORT bool ClearException(JNIEnv* env); 149 BASE_EXPORT bool ClearException(JNIEnv* env);
117 150
118 // This function will call CHECK() macro if there's any pending exception. 151 // This function will call CHECK() macro if there's any pending exception.
119 BASE_EXPORT void CheckException(JNIEnv* env); 152 BASE_EXPORT void CheckException(JNIEnv* env);
120 153
121 // This returns a string representation of the java stack trace. 154 // This returns a string representation of the java stack trace.
122 BASE_EXPORT std::string GetJavaExceptionInfo(JNIEnv* env, 155 BASE_EXPORT std::string GetJavaExceptionInfo(JNIEnv* env,
123 jthrowable java_throwable); 156 jthrowable java_throwable);
124 157
158 #if HAVE_TRACE_STACK_FRAME_POINTERS
159
160 // Saves caller's PC and stack frame in a thread-local variable.
161 // Implemented only when profiling is enabled (enable_profiling=true).
162 class BASE_EXPORT JNIStackFrameSaver {
163 public:
164 JNIStackFrameSaver(void* current_fp);
165 ~JNIStackFrameSaver();
166 static void* SavedFrame();
167
168 private:
169 void* previous_fp_;
170
171 DISALLOW_COPY_AND_ASSIGN(JNIStackFrameSaver);
172 };
173
174 #endif // HAVE_TRACE_STACK_FRAME_POINTERS
175
125 } // namespace android 176 } // namespace android
126 } // namespace base 177 } // namespace base
127 178
128 #endif // BASE_ANDROID_JNI_ANDROID_H_ 179 #endif // BASE_ANDROID_JNI_ANDROID_H_
OLDNEW
« no previous file with comments | « no previous file | base/android/jni_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698