summaryrefslogtreecommitdiff
path: root/base/android/jni_generator/jni_generator_helper.h
blob: 3062806a85fd7f08732e88ff4b7e85c6fd6f0609 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_ANDROID_JNI_GENERATOR_JNI_GENERATOR_HELPER_H_
#define BASE_ANDROID_JNI_GENERATOR_JNI_GENERATOR_HELPER_H_

#include <jni.h>

#include "base/android/jni_android.h"
#include "base/android/scoped_java_ref.h"
#include "base/logging.h"
#include "build/build_config.h"

// Project-specific macros used by the header files generated by
// jni_generator.py. Different projects can then specify their own
// implementation for this file.
#define CHECK_NATIVE_PTR(env, jcaller, native_ptr, method_name, ...) \
  DCHECK(native_ptr) << method_name;

#define CHECK_CLAZZ(env, jcaller, clazz, ...) DCHECK(clazz);

#if defined(ARCH_CPU_X86)
// Dalvik JIT generated code doesn't guarantee 16-byte stack alignment on
// x86 - use force_align_arg_pointer to realign the stack at the JNI
// boundary. crbug.com/655248
#define JNI_GENERATOR_EXPORT \
  extern "C" __attribute__((visibility("default"), force_align_arg_pointer))
#else
#define JNI_GENERATOR_EXPORT extern "C" __attribute__((visibility("default")))
#endif

namespace jni_generator {

inline void HandleRegistrationError(JNIEnv* env,
                                    jclass clazz,
                                    const char* filename) {
  LOG(ERROR) << "RegisterNatives failed in " << filename;
}

inline void CheckException(JNIEnv* env) {
  base::android::CheckException(env);
}

inline bool ShouldSkipJniRegistration(bool is_maindex_class) {
  switch (base::android::GetJniRegistrationType()) {
    case base::android::ALL_JNI_REGISTRATION:
      return false;
    case base::android::NO_JNI_REGISTRATION:
      // TODO(estevenson): Change this to a DCHECK.
      return true;
    case base::android::SELECTIVE_JNI_REGISTRATION:
      return !is_maindex_class;
    default:
      NOTREACHED();
      return false;
  }
}

}  // namespace jni_generator

#endif  // BASE_ANDROID_JNI_GENERATOR_JNI_GENERATOR_HELPER_H_