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