OLD | NEW |
---|---|
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_PROFILING_ENTERED_NATIVE. | |
28 #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.
| |
29 base::android::JNIStackFrameSaver jni_frame_saver( \ | |
30 __builtin_frame_address(0)) | |
31 | |
32 // When profiling is enabled (enable_profiling=true) this macro is added to | |
33 // all generated JNI callbacks so that it becomes the first thing that runs | |
34 // after control returns from Java. | |
35 // | |
36 // This macro links stack frame of the current function to the stack frame | |
37 // saved by JNI_PROFILING_LEAVING_NATIVE, allowing frame-based unwinding | |
38 // (used by the heap profiler) to produce complete traces. | |
39 #define JNI_PROFILING_ENTERED_NATIVE \ | |
40 base::debug::ScopedStackFrameLinker jni_frame_linker( \ | |
41 __builtin_frame_address(0), \ | |
42 base::android::JNIStackFrameSaver::SavedFrame()) | |
43 | |
44 | |
45 #else | |
46 | |
47 // Frame-based stack unwinding is not supported, do nothing. | |
48 #define JNI_PROFILING_LEAVING_NATIVE | |
49 #define JNI_PROFILING_ENTERED_NATIVE | |
50 | |
51 #endif // HAVE_TRACE_STACK_FRAME_POINTERS | |
17 | 52 |
18 namespace base { | 53 namespace base { |
19 namespace android { | 54 namespace android { |
20 | 55 |
21 // Used to mark symbols to be exported in a shared library's symbol table. | 56 // Used to mark symbols to be exported in a shared library's symbol table. |
22 #define JNI_EXPORT __attribute__ ((visibility("default"))) | 57 #define JNI_EXPORT __attribute__ ((visibility("default"))) |
23 | 58 |
24 // Used to disable manual JNI registration in binaries that prefer to use native | 59 // 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 | 60 // JNI exports for startup performance. This is not compatible with the crazy |
26 // linker and so defaults to off. Call DisableManualJniRegistration at the very | 61 // linker and so defaults to off. Call DisableManualJniRegistration at the very |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 // and returns true. | 150 // and returns true. |
116 BASE_EXPORT bool ClearException(JNIEnv* env); | 151 BASE_EXPORT bool ClearException(JNIEnv* env); |
117 | 152 |
118 // This function will call CHECK() macro if there's any pending exception. | 153 // This function will call CHECK() macro if there's any pending exception. |
119 BASE_EXPORT void CheckException(JNIEnv* env); | 154 BASE_EXPORT void CheckException(JNIEnv* env); |
120 | 155 |
121 // This returns a string representation of the java stack trace. | 156 // This returns a string representation of the java stack trace. |
122 BASE_EXPORT std::string GetJavaExceptionInfo(JNIEnv* env, | 157 BASE_EXPORT std::string GetJavaExceptionInfo(JNIEnv* env, |
123 jthrowable java_throwable); | 158 jthrowable java_throwable); |
124 | 159 |
160 #if HAVE_TRACE_STACK_FRAME_POINTERS | |
161 | |
162 // Saves caller's PC and stack frame in a thread-local variable. | |
163 // Implemented only when profiling is enabled (enable_profiling=true). | |
164 class BASE_EXPORT JNIStackFrameSaver { | |
165 public: | |
166 JNIStackFrameSaver(void* current_fp); | |
167 ~JNIStackFrameSaver(); | |
168 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
| |
169 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.
| |
170 void* previous_fp_; | |
171 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.
| |
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_ |
OLD | NEW |