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_JNI_INTERNAL_H_
18 #define ART_RUNTIME_JNI_JNI_INTERNAL_H_
19 
20 #include <jni.h>
21 #include <iosfwd>
22 
23 #include "base/macros.h"
24 
25 namespace art {
26 
27 class ArtField;
28 class ArtMethod;
29 
30 const JNINativeInterface* GetJniNativeInterface();
31 const JNINativeInterface* GetRuntimeShutdownNativeInterface();
32 
33 int ThrowNewException(JNIEnv* env, jclass exception_class, const char* msg, jobject cause);
34 
35 // Enables native stack checking for field and method resolutions via JNI. This should be called
36 // during runtime initialization after libjavacore and libopenjdk have been dlopen()'ed.
37 void JniInitializeNativeCallerCheck();
38 
39 // Removes native stack checking state.
40 void JniShutdownNativeCallerCheck();
41 
42 namespace jni {
43 
44 ALWAYS_INLINE
DecodeArtField(jfieldID fid)45 static inline ArtField* DecodeArtField(jfieldID fid) {
46   return reinterpret_cast<ArtField*>(fid);
47 }
48 
49 ALWAYS_INLINE
EncodeArtField(ArtField * field)50 static inline jfieldID EncodeArtField(ArtField* field) {
51   return reinterpret_cast<jfieldID>(field);
52 }
53 
54 ALWAYS_INLINE
EncodeArtMethod(ArtMethod * art_method)55 static inline jmethodID EncodeArtMethod(ArtMethod* art_method) {
56   return reinterpret_cast<jmethodID>(art_method);
57 }
58 
59 ALWAYS_INLINE
DecodeArtMethod(jmethodID method_id)60 static inline ArtMethod* DecodeArtMethod(jmethodID method_id) {
61   return reinterpret_cast<ArtMethod*>(method_id);
62 }
63 
64 }  // namespace jni
65 }  // namespace art
66 
67 std::ostream& operator<<(std::ostream& os, const jobjectRefType& rhs);
68 
69 #endif  // ART_RUNTIME_JNI_JNI_INTERNAL_H_
70