1 /*
2  * Copyright 2018 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 LIBNATIVEHELPER_JNICONSTANTS_H_
18 #define LIBNATIVEHELPER_JNICONSTANTS_H_
19 
20 #include "jni.h"
21 
22 struct JniConstants {
23     // Global reference to java.io.FileDescriptor.
24     static jclass GetFileDescriptorClass(JNIEnv* env);
25 
26     // java.io.FileDescriptor.descriptor.
27     static jfieldID GetFileDescriptorDescriptorField(JNIEnv* env);
28 
29     // java.io.FileDescriptor.ownerId.
30     static jfieldID GetFileDescriptorOwnerIdField(JNIEnv* env);
31 
32     // void java.io.FileDescriptor.<init>().
33     static jmethodID GetFileDescriptorInitMethod(JNIEnv* env);
34 
35     // Global reference to java.nio.NIOAccess.
36     static jclass GetNioAccessClass(JNIEnv* env);
37 
38     // Object java.nio.NIOAccess.getBaseArray(Buffer);
39     static jmethodID GetNioAccessGetBaseArrayMethod(JNIEnv* env);
40 
41     // int java.nio.NIOAccess.getBaseArrayOffset(Buffer);
42     static jmethodID GetNioAccessGetBaseArrayOffsetMethod(JNIEnv* env);
43 
44     // Global reference to java.nio.Buffer.
45     static jclass GetNioBufferClass(JNIEnv* env);
46 
47     // long java.nio.Buffer.address
48     static jfieldID GetNioBufferAddressField(JNIEnv* env);
49 
50     // int java.nio.Buffer._elementSizeShift
51     static jfieldID GetNioBufferElementSizeShiftField(JNIEnv* env);
52 
53     // int java.nio.Buffer.limit;
54     static jfieldID GetNioBufferLimitField(JNIEnv* env);
55 
56     // int java.nio.Buffer.position;
57     static jfieldID GetNioBufferPositionField(JNIEnv* env);
58 
59     // Object java.nio.Buffer.array()
60     static jmethodID GetNioBufferArrayMethod(JNIEnv* env);
61 
62     // int java.nio.Buffer.arrayOffset()
63     static jmethodID GetNioBufferArrayOffsetMethod(JNIEnv* env);
64 
65     // Global reference to java.lang.ref.Reference.
66     static jclass GetReferenceClass(JNIEnv* env);
67 
68     // Object java.lang.ref.Reference.get()
69     static jmethodID GetReferenceGetMethod(JNIEnv* env);
70 
71     // Global reference to java.lang.String.
72     static jclass GetStringClass(JNIEnv* env);
73 
74     // Ensure class constants are initialized before use. Field and method
75     // constants are lazily initialized via getters.
76     static void EnsureClassReferencesInitialized(JNIEnv* env);
77 
78     // Ensure any cached heap objects from previous VM instances are
79     // invalidated. There is no notification here that a VM is destroyed so this
80     // method must be called when a new VM is created (and calls from any
81     // earlier VM's are completed). The caching of heap objects in this class is
82     // one reason why there is a limit of VM instance per process.
83     static void Uninitialize();
84 };
85 
86 #endif  // LIBNATIVEHELPER_JNICONSTANTS_H_
87