• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ART_RUNTIME_NATIVE_NATIVE_UTIL_H_
18 #define ART_RUNTIME_NATIVE_NATIVE_UTIL_H_
19 
20 #include <jni.h>
21 
22 #include "android-base/logging.h"
23 #include "base/macros.h"
24 #include "nativehelper/ScopedLocalRef.h"
25 
26 namespace art {
27 
RegisterNativeMethodsInternal(JNIEnv * env,const char * jni_class_name,const JNINativeMethod * methods,jint method_count)28 ALWAYS_INLINE inline void RegisterNativeMethodsInternal(JNIEnv* env,
29                                                         const char* jni_class_name,
30                                                         const JNINativeMethod* methods,
31                                                         jint method_count) {
32   ScopedLocalRef<jclass> c(env, env->FindClass(jni_class_name));
33   if (c.get() == nullptr) {
34     LOG(FATAL) << "Couldn't find class: " << jni_class_name;
35   }
36   jint jni_result = env->RegisterNatives(c.get(), methods, method_count);
37   CHECK_EQ(JNI_OK, jni_result);
38 }
39 
40 #define REGISTER_NATIVE_METHODS(jni_class_name) \
41   RegisterNativeMethodsInternal(env, (jni_class_name), gMethods, arraysize(gMethods))
42 
43 }  // namespace art
44 
45 #endif  // ART_RUNTIME_NATIVE_NATIVE_UTIL_H_
46