1 /*
2  * Copyright (C) 2012 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_WELL_KNOWN_CLASSES_H_
18 #define ART_RUNTIME_WELL_KNOWN_CLASSES_H_
19 
20 #include "base/locks.h"
21 #include "jni.h"
22 #include "obj_ptr.h"
23 
24 namespace art {
25 
26 class ArtMethod;
27 
28 namespace mirror {
29 class Class;
30 }  // namespace mirror
31 
32 // Various classes used in JNI. We cache them so we don't have to keep looking them up.
33 
34 struct WellKnownClasses {
35  public:
36   // Run before native methods are registered.
37   static void Init(JNIEnv* env);
38   // Run after native methods are registered.
39   static void LateInit(JNIEnv* env);
40 
41   static void Clear();
42 
43   static void HandleJniIdTypeChange(JNIEnv* env);
44 
45   static void InitStringInit(ObjPtr<mirror::Class> string_class,
46                              ObjPtr<mirror::Class> string_builder_class)
47       REQUIRES_SHARED(Locks::mutator_lock_);
48   static ArtMethod* StringInitToStringFactory(ArtMethod* method);
49   static uint32_t StringInitToEntryPoint(ArtMethod* method);
50 
51   static ObjPtr<mirror::Class> ToClass(jclass global_jclass) REQUIRES_SHARED(Locks::mutator_lock_);
52 
53  private:
54   static void InitFieldsAndMethodsOnly(JNIEnv* env);
55 
56  public:
57   static jclass dalvik_annotation_optimization_CriticalNative;
58   static jclass dalvik_annotation_optimization_FastNative;
59   static jclass dalvik_system_BaseDexClassLoader;
60   static jclass dalvik_system_DelegateLastClassLoader;
61   static jclass dalvik_system_DexClassLoader;
62   static jclass dalvik_system_DexFile;
63   static jclass dalvik_system_DexPathList;
64   static jclass dalvik_system_DexPathList__Element;
65   static jclass dalvik_system_EmulatedStackFrame;
66   static jclass dalvik_system_InMemoryDexClassLoader;
67   static jclass dalvik_system_PathClassLoader;
68   static jclass dalvik_system_VMRuntime;
69   static jclass java_lang_annotation_Annotation__array;
70   static jclass java_lang_BootClassLoader;
71   static jclass java_lang_ClassLoader;
72   static jclass java_lang_ClassNotFoundException;
73   static jclass java_lang_Daemons;
74   static jclass java_lang_Error;
75   static jclass java_lang_IllegalAccessError;
76   static jclass java_lang_NoClassDefFoundError;
77   static jclass java_lang_Object;
78   static jclass java_lang_OutOfMemoryError;
79   static jclass java_lang_reflect_InvocationTargetException;
80   static jclass java_lang_reflect_Parameter;
81   static jclass java_lang_reflect_Parameter__array;
82   static jclass java_lang_reflect_Proxy;
83   static jclass java_lang_RuntimeException;
84   static jclass java_lang_StackOverflowError;
85   static jclass java_lang_String;
86   static jclass java_lang_StringFactory;
87   static jclass java_lang_System;
88   static jclass java_lang_Thread;
89   static jclass java_lang_ThreadGroup;
90   static jclass java_lang_Throwable;
91   static jclass java_lang_Void;
92   static jclass java_nio_Buffer;
93   static jclass java_nio_ByteBuffer;
94   static jclass java_nio_DirectByteBuffer;
95   static jclass java_util_Collections;
96   static jclass java_util_function_Consumer;
97   static jclass libcore_reflect_AnnotationFactory;
98   static jclass libcore_reflect_AnnotationMember;
99   static jclass libcore_util_EmptyArray;
100   static jclass org_apache_harmony_dalvik_ddmc_Chunk;
101   static jclass org_apache_harmony_dalvik_ddmc_DdmServer;
102 
103   static jmethodID dalvik_system_BaseDexClassLoader_getLdLibraryPath;
104   static jmethodID dalvik_system_VMRuntime_runFinalization;
105   static jmethodID dalvik_system_VMRuntime_hiddenApiUsed;
106   static jmethodID java_lang_Boolean_valueOf;
107   static jmethodID java_lang_Byte_valueOf;
108   static jmethodID java_lang_Character_valueOf;
109   static jmethodID java_lang_ClassLoader_loadClass;
110   static jmethodID java_lang_ClassNotFoundException_init;
111   static jmethodID java_lang_Daemons_start;
112   static jmethodID java_lang_Daemons_stop;
113   static jmethodID java_lang_Daemons_waitForDaemonStart;
114   static jmethodID java_lang_Double_doubleToRawLongBits;
115   static jmethodID java_lang_Double_valueOf;
116   static jmethodID java_lang_Float_floatToRawIntBits;
117   static jmethodID java_lang_Float_valueOf;
118   static jmethodID java_lang_Integer_valueOf;
119   static jmethodID java_lang_invoke_MethodHandles_lookup;
120   static jmethodID java_lang_invoke_MethodHandles_Lookup_findConstructor;
121   static jmethodID java_lang_Long_valueOf;
122   static jmethodID java_lang_ref_FinalizerReference_add;
123   static jmethodID java_lang_ref_ReferenceQueue_add;
124   static jmethodID java_lang_reflect_InvocationTargetException_init;
125   static jmethodID java_lang_reflect_Parameter_init;
126   static jmethodID java_lang_reflect_Proxy_init;
127   static jmethodID java_lang_reflect_Proxy_invoke;
128   static jmethodID java_lang_Runtime_nativeLoad;
129   static jmethodID java_lang_Short_valueOf;
130   static jmethodID java_lang_String_charAt;
131   static jmethodID java_lang_Thread_dispatchUncaughtException;
132   static jmethodID java_lang_Thread_init;
133   static jmethodID java_lang_Thread_run;
134   static jmethodID java_lang_ThreadGroup_add;
135   static jmethodID java_lang_ThreadGroup_removeThread;
136   static jmethodID java_nio_Buffer_isDirect;
137   static jmethodID java_nio_DirectByteBuffer_init;
138   static jmethodID java_util_function_Consumer_accept;
139   static jmethodID libcore_reflect_AnnotationFactory_createAnnotation;
140   static jmethodID libcore_reflect_AnnotationMember_init;
141   static jmethodID org_apache_harmony_dalvik_ddmc_DdmServer_broadcast;
142   static jmethodID org_apache_harmony_dalvik_ddmc_DdmServer_dispatch;
143 
144   static jfieldID dalvik_system_BaseDexClassLoader_pathList;
145   static jfieldID dalvik_system_BaseDexClassLoader_sharedLibraryLoaders;
146   static jfieldID dalvik_system_DexFile_cookie;
147   static jfieldID dalvik_system_DexFile_fileName;
148   static jfieldID dalvik_system_DexPathList_dexElements;
149   static jfieldID dalvik_system_DexPathList__Element_dexFile;
150   static jfieldID dalvik_system_VMRuntime_nonSdkApiUsageConsumer;
151   static jfieldID java_io_FileDescriptor_descriptor;
152   static jfieldID java_lang_Thread_parkBlocker;
153   static jfieldID java_lang_Thread_daemon;
154   static jfieldID java_lang_Thread_group;
155   static jfieldID java_lang_Thread_lock;
156   static jfieldID java_lang_Thread_name;
157   static jfieldID java_lang_Thread_priority;
158   static jfieldID java_lang_Thread_nativePeer;
159   static jfieldID java_lang_Thread_systemDaemon;
160   static jfieldID java_lang_Thread_unparkedBeforeStart;
161   static jfieldID java_lang_ThreadGroup_groups;
162   static jfieldID java_lang_ThreadGroup_ngroups;
163   static jfieldID java_lang_ThreadGroup_mainThreadGroup;
164   static jfieldID java_lang_ThreadGroup_name;
165   static jfieldID java_lang_ThreadGroup_parent;
166   static jfieldID java_lang_ThreadGroup_systemThreadGroup;
167   static jfieldID java_lang_Throwable_cause;
168   static jfieldID java_lang_Throwable_detailMessage;
169   static jfieldID java_lang_Throwable_stackTrace;
170   static jfieldID java_lang_Throwable_stackState;
171   static jfieldID java_lang_Throwable_suppressedExceptions;
172   static jfieldID java_nio_Buffer_address;
173   static jfieldID java_nio_Buffer_capacity;
174   static jfieldID java_nio_Buffer_elementSizeShift;
175   static jfieldID java_nio_Buffer_limit;
176   static jfieldID java_nio_Buffer_position;
177   static jfieldID java_nio_ByteBuffer_address;
178   static jfieldID java_nio_ByteBuffer_hb;
179   static jfieldID java_nio_ByteBuffer_isReadOnly;
180   static jfieldID java_nio_ByteBuffer_limit;
181   static jfieldID java_nio_ByteBuffer_offset;
182 
183   static jfieldID java_util_Collections_EMPTY_LIST;
184   static jfieldID libcore_util_EmptyArray_STACK_TRACE_ELEMENT;
185   static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_data;
186   static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_length;
187   static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_offset;
188   static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_type;
189 };
190 
191 }  // namespace art
192 
193 #endif  // ART_RUNTIME_WELL_KNOWN_CLASSES_H_
194