| 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/debugging_flags.h" |
| 17 #include "base/debug/stack_trace.h" | 18 #include "base/debug/stack_trace.h" |
| 18 #include "base/macros.h" | 19 #include "base/macros.h" |
| 19 | 20 |
| 20 #if HAVE_TRACE_STACK_FRAME_POINTERS | 21 #if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS) |
| 21 | 22 |
| 22 // When profiling is enabled (enable_profiling=true) this macro is added to | 23 // 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 // all generated JNI stubs so that it becomes the last thing that runs before |
| 24 // control goes into Java. | 25 // control goes into Java. |
| 25 // | 26 // |
| 26 // This macro saves stack frame pointer of the current function. Saved value | 27 // This macro saves stack frame pointer of the current function. Saved value |
| 27 // used later by JNI_LINK_SAVED_FRAME_POINTER. | 28 // used later by JNI_LINK_SAVED_FRAME_POINTER. |
| 28 #define JNI_SAVE_FRAME_POINTER \ | 29 #define JNI_SAVE_FRAME_POINTER \ |
| 29 base::android::JNIStackFrameSaver jni_frame_saver(__builtin_frame_address(0)) | 30 base::android::JNIStackFrameSaver jni_frame_saver(__builtin_frame_address(0)) |
| 30 | 31 |
| 31 // When profiling is enabled (enable_profiling=true) this macro is added to | 32 // 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 // all generated JNI callbacks so that it becomes the first thing that runs |
| 33 // after control returns from Java. | 34 // after control returns from Java. |
| 34 // | 35 // |
| 35 // This macro links stack frame of the current function to the stack frame | 36 // 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 // saved by JNI_SAVE_FRAME_POINTER, allowing frame-based unwinding |
| 37 // (used by the heap profiler) to produce complete traces. | 38 // (used by the heap profiler) to produce complete traces. |
| 38 #define JNI_LINK_SAVED_FRAME_POINTER \ | 39 #define JNI_LINK_SAVED_FRAME_POINTER \ |
| 39 base::debug::ScopedStackFrameLinker jni_frame_linker( \ | 40 base::debug::ScopedStackFrameLinker jni_frame_linker( \ |
| 40 __builtin_frame_address(0), \ | 41 __builtin_frame_address(0), \ |
| 41 base::android::JNIStackFrameSaver::SavedFrame()) | 42 base::android::JNIStackFrameSaver::SavedFrame()) |
| 42 | 43 |
| 43 #else | 44 #else |
| 44 | 45 |
| 45 // Frame-based stack unwinding is not supported, do nothing. | 46 // Frame-based stack unwinding is not supported, do nothing. |
| 46 #define JNI_SAVE_FRAME_POINTER | 47 #define JNI_SAVE_FRAME_POINTER |
| 47 #define JNI_LINK_SAVED_FRAME_POINTER | 48 #define JNI_LINK_SAVED_FRAME_POINTER |
| 48 | 49 |
| 49 #endif // HAVE_TRACE_STACK_FRAME_POINTERS | 50 #endif // BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS) |
| 50 | 51 |
| 51 namespace base { | 52 namespace base { |
| 52 namespace android { | 53 namespace android { |
| 53 | 54 |
| 54 // Used to mark symbols to be exported in a shared library's symbol table. | 55 // Used to mark symbols to be exported in a shared library's symbol table. |
| 55 #define JNI_EXPORT __attribute__ ((visibility("default"))) | 56 #define JNI_EXPORT __attribute__ ((visibility("default"))) |
| 56 | 57 |
| 57 // The level of JNI registration required for the current process. | 58 // The level of JNI registration required for the current process. |
| 58 enum JniRegistrationType { | 59 enum JniRegistrationType { |
| 59 // Register all native methods. | 60 // Register all native methods. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // and returns true. | 160 // and returns true. |
| 160 BASE_EXPORT bool ClearException(JNIEnv* env); | 161 BASE_EXPORT bool ClearException(JNIEnv* env); |
| 161 | 162 |
| 162 // This function will call CHECK() macro if there's any pending exception. | 163 // This function will call CHECK() macro if there's any pending exception. |
| 163 BASE_EXPORT void CheckException(JNIEnv* env); | 164 BASE_EXPORT void CheckException(JNIEnv* env); |
| 164 | 165 |
| 165 // This returns a string representation of the java stack trace. | 166 // This returns a string representation of the java stack trace. |
| 166 BASE_EXPORT std::string GetJavaExceptionInfo(JNIEnv* env, | 167 BASE_EXPORT std::string GetJavaExceptionInfo(JNIEnv* env, |
| 167 jthrowable java_throwable); | 168 jthrowable java_throwable); |
| 168 | 169 |
| 169 #if HAVE_TRACE_STACK_FRAME_POINTERS | 170 #if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS) |
| 170 | 171 |
| 171 // Saves caller's PC and stack frame in a thread-local variable. | 172 // Saves caller's PC and stack frame in a thread-local variable. |
| 172 // Implemented only when profiling is enabled (enable_profiling=true). | 173 // Implemented only when profiling is enabled (enable_profiling=true). |
| 173 class BASE_EXPORT JNIStackFrameSaver { | 174 class BASE_EXPORT JNIStackFrameSaver { |
| 174 public: | 175 public: |
| 175 JNIStackFrameSaver(void* current_fp); | 176 JNIStackFrameSaver(void* current_fp); |
| 176 ~JNIStackFrameSaver(); | 177 ~JNIStackFrameSaver(); |
| 177 static void* SavedFrame(); | 178 static void* SavedFrame(); |
| 178 | 179 |
| 179 private: | 180 private: |
| 180 void* previous_fp_; | 181 void* previous_fp_; |
| 181 | 182 |
| 182 DISALLOW_COPY_AND_ASSIGN(JNIStackFrameSaver); | 183 DISALLOW_COPY_AND_ASSIGN(JNIStackFrameSaver); |
| 183 }; | 184 }; |
| 184 | 185 |
| 185 #endif // HAVE_TRACE_STACK_FRAME_POINTERS | 186 #endif // BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS) |
| 186 | 187 |
| 187 } // namespace android | 188 } // namespace android |
| 188 } // namespace base | 189 } // namespace base |
| 189 | 190 |
| 190 #endif // BASE_ANDROID_JNI_ANDROID_H_ | 191 #endif // BASE_ANDROID_JNI_ANDROID_H_ |
| OLD | NEW |