Home | History | Annotate | Download | only in runtime
      1 /*
      2  * Copyright (C) 2011 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_JNI_INTERNAL_H_
     18 #define ART_RUNTIME_JNI_INTERNAL_H_
     19 
     20 #include <jni.h>
     21 #include <iosfwd>
     22 #include "nativehelper/jni_macros.h"
     23 
     24 #include "base/macros.h"
     25 
     26 #define REGISTER_NATIVE_METHODS(jni_class_name) \
     27   RegisterNativeMethods(env, jni_class_name, gMethods, arraysize(gMethods))
     28 
     29 namespace art {
     30 
     31 class ArtField;
     32 class ArtMethod;
     33 
     34 const JNINativeInterface* GetJniNativeInterface();
     35 const JNINativeInterface* GetRuntimeShutdownNativeInterface();
     36 
     37 // Similar to RegisterNatives except its passed a descriptor for a class name and failures are
     38 // fatal.
     39 void RegisterNativeMethods(JNIEnv* env, const char* jni_class_name, const JNINativeMethod* methods,
     40                            jint method_count);
     41 
     42 int ThrowNewException(JNIEnv* env, jclass exception_class, const char* msg, jobject cause);
     43 
     44 namespace jni {
     45 
     46 ALWAYS_INLINE
     47 static inline ArtField* DecodeArtField(jfieldID fid) {
     48   return reinterpret_cast<ArtField*>(fid);
     49 }
     50 
     51 ALWAYS_INLINE
     52 static inline jfieldID EncodeArtField(ArtField* field) {
     53   return reinterpret_cast<jfieldID>(field);
     54 }
     55 
     56 ALWAYS_INLINE
     57 static inline jmethodID EncodeArtMethod(ArtMethod* art_method) {
     58   return reinterpret_cast<jmethodID>(art_method);
     59 }
     60 
     61 ALWAYS_INLINE
     62 static inline ArtMethod* DecodeArtMethod(jmethodID method_id) {
     63   return reinterpret_cast<ArtMethod*>(method_id);
     64 }
     65 
     66 }  // namespace jni
     67 }  // namespace art
     68 
     69 std::ostream& operator<<(std::ostream& os, const jobjectRefType& rhs);
     70 
     71 #endif  // ART_RUNTIME_JNI_INTERNAL_H_
     72