Home | History | Annotate | Download | only in jni_generator
      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/scoped_java_ref.h"
     12 #include "base/logging.h"
     13 #include "build/build_config.h"
     14 
     15 // Project-specific macros used by the header files generated by
     16 // jni_generator.py. Different projects can then specify their own
     17 // implementation for this file.
     18 #define CHECK_NATIVE_PTR(env, jcaller, native_ptr, method_name, ...) \
     19   DCHECK(native_ptr) << method_name;
     20 
     21 #define CHECK_CLAZZ(env, jcaller, clazz, ...) DCHECK(clazz);
     22 
     23 #if defined(ARCH_CPU_X86)
     24 // Dalvik JIT generated code doesn't guarantee 16-byte stack alignment on
     25 // x86 - use force_align_arg_pointer to realign the stack at the JNI
     26 // boundary. crbug.com/655248
     27 #define JNI_GENERATOR_EXPORT \
     28   extern "C" __attribute__((visibility("default"), force_align_arg_pointer))
     29 #else
     30 #define JNI_GENERATOR_EXPORT extern "C" __attribute__((visibility("default")))
     31 #endif
     32 
     33 namespace jni_generator {
     34 
     35 inline void HandleRegistrationError(JNIEnv* env,
     36                                     jclass clazz,
     37                                     const char* filename) {
     38   LOG(ERROR) << "RegisterNatives failed in " << filename;
     39 }
     40 
     41 inline void CheckException(JNIEnv* env) {
     42   base::android::CheckException(env);
     43 }
     44 
     45 inline bool ShouldSkipJniRegistration(bool is_maindex_class) {
     46   switch (base::android::GetJniRegistrationType()) {
     47     case base::android::ALL_JNI_REGISTRATION:
     48       return false;
     49     case base::android::NO_JNI_REGISTRATION:
     50       // TODO(estevenson): Change this to a DCHECK.
     51       return true;
     52     case base::android::SELECTIVE_JNI_REGISTRATION:
     53       return !is_maindex_class;
     54     default:
     55       NOTREACHED();
     56       return false;
     57   }
     58 }
     59 
     60 }  // namespace jni_generator
     61 
     62 #endif  // BASE_ANDROID_JNI_GENERATOR_JNI_GENERATOR_HELPER_H_
     63