• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_ANDROID_JNI_GENERATOR_JNI_GENERATOR_HELPER_H_
6 #define BASE_ANDROID_JNI_GENERATOR_JNI_GENERATOR_HELPER_H_
7 
8 #include <jni.h>
9 
10 #include "base/android/jni_android.h"
11 #include "base/android/jni_int_wrapper.h"
12 #include "base/android/scoped_java_ref.h"
13 #include "base/logging.h"
14 #include "base/trace_event/trace_event.h"
15 #include "build/build_config.h"
16 
17 // Project-specific macros used by the header files generated by
18 // jni_generator.py. Different projects can then specify their own
19 // implementation for this file.
20 #define CHECK_NATIVE_PTR(env, jcaller, native_ptr, method_name, ...) \
21   DCHECK(native_ptr) << method_name;
22 
23 #define CHECK_CLAZZ(env, jcaller, clazz, ...) DCHECK(clazz);
24 
25 #if defined(ARCH_CPU_X86)
26 // Dalvik JIT generated code doesn't guarantee 16-byte stack alignment on
27 // x86 - use force_align_arg_pointer to realign the stack at the JNI
28 // boundary. crbug.com/655248
29 #define JNI_GENERATOR_EXPORT \
30   extern "C" __attribute__((visibility("default"), force_align_arg_pointer))
31 #else
32 #define JNI_GENERATOR_EXPORT extern "C" __attribute__((visibility("default")))
33 #endif
34 
35 // Used to export JNI registration functions.
36 #if defined(COMPONENT_BUILD)
37 #define JNI_REGISTRATION_EXPORT __attribute__((visibility("default")))
38 #else
39 #define JNI_REGISTRATION_EXPORT
40 #endif
41 
42 namespace jni_generator {
43 
HandleRegistrationError(JNIEnv * env,jclass clazz,const char * filename)44 inline void HandleRegistrationError(JNIEnv* env,
45                                     jclass clazz,
46                                     const char* filename) {
47   LOG(ERROR) << "RegisterNatives failed in " << filename;
48 }
49 
CheckException(JNIEnv * env)50 inline void CheckException(JNIEnv* env) {
51   base::android::CheckException(env);
52 }
53 
54 }  // namespace jni_generator
55 
56 #endif  // BASE_ANDROID_JNI_GENERATOR_JNI_GENERATOR_HELPER_H_
57