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_nio_Buffer;
92   static jclass java_nio_ByteBuffer;
93   static jclass java_nio_DirectByteBuffer;
94   static jclass java_util_Collections;
95   static jclass java_util_function_Consumer;
96   static jclass libcore_reflect_AnnotationFactory;
97   static jclass libcore_reflect_AnnotationMember;
98   static jclass libcore_util_EmptyArray;
99   static jclass org_apache_harmony_dalvik_ddmc_Chunk;
100   static jclass org_apache_harmony_dalvik_ddmc_DdmServer;
101 
102   static jmethodID dalvik_system_BaseDexClassLoader_getLdLibraryPath;
103   static jmethodID dalvik_system_VMRuntime_runFinalization;
104   static jmethodID dalvik_system_VMRuntime_hiddenApiUsed;
105   static jmethodID java_lang_Boolean_valueOf;
106   static jmethodID java_lang_Byte_valueOf;
107   static jmethodID java_lang_Character_valueOf;
108   static jmethodID java_lang_ClassLoader_loadClass;
109   static jmethodID java_lang_ClassNotFoundException_init;
110   static jmethodID java_lang_Daemons_start;
111   static jmethodID java_lang_Daemons_stop;
112   static jmethodID java_lang_Daemons_waitForDaemonStart;
113   static jmethodID java_lang_Double_valueOf;
114   static jmethodID java_lang_Float_valueOf;
115   static jmethodID java_lang_Integer_valueOf;
116   static jmethodID java_lang_invoke_MethodHandles_lookup;
117   static jmethodID java_lang_invoke_MethodHandles_Lookup_findConstructor;
118   static jmethodID java_lang_Long_valueOf;
119   static jmethodID java_lang_ref_FinalizerReference_add;
120   static jmethodID java_lang_ref_ReferenceQueue_add;
121   static jmethodID java_lang_reflect_InvocationTargetException_init;
122   static jmethodID java_lang_reflect_Parameter_init;
123   static jmethodID java_lang_reflect_Proxy_init;
124   static jmethodID java_lang_reflect_Proxy_invoke;
125   static jmethodID java_lang_Runtime_nativeLoad;
126   static jmethodID java_lang_Short_valueOf;
127   static jmethodID java_lang_String_charAt;
128   static jmethodID java_lang_Thread_dispatchUncaughtException;
129   static jmethodID java_lang_Thread_init;
130   static jmethodID java_lang_Thread_run;
131   static jmethodID java_lang_ThreadGroup_add;
132   static jmethodID java_lang_ThreadGroup_removeThread;
133   static jmethodID java_nio_Buffer_isDirect;
134   static jmethodID java_nio_DirectByteBuffer_init;
135   static jmethodID java_util_function_Consumer_accept;
136   static jmethodID libcore_reflect_AnnotationFactory_createAnnotation;
137   static jmethodID libcore_reflect_AnnotationMember_init;
138   static jmethodID org_apache_harmony_dalvik_ddmc_DdmServer_broadcast;
139   static jmethodID org_apache_harmony_dalvik_ddmc_DdmServer_dispatch;
140 
141   static jfieldID dalvik_system_BaseDexClassLoader_pathList;
142   static jfieldID dalvik_system_BaseDexClassLoader_sharedLibraryLoaders;
143   static jfieldID dalvik_system_DexFile_cookie;
144   static jfieldID dalvik_system_DexFile_fileName;
145   static jfieldID dalvik_system_DexPathList_dexElements;
146   static jfieldID dalvik_system_DexPathList__Element_dexFile;
147   static jfieldID dalvik_system_VMRuntime_nonSdkApiUsageConsumer;
148   static jfieldID java_io_FileDescriptor_descriptor;
149   static jfieldID java_lang_Thread_parkBlocker;
150   static jfieldID java_lang_Thread_daemon;
151   static jfieldID java_lang_Thread_group;
152   static jfieldID java_lang_Thread_lock;
153   static jfieldID java_lang_Thread_name;
154   static jfieldID java_lang_Thread_priority;
155   static jfieldID java_lang_Thread_nativePeer;
156   static jfieldID java_lang_Thread_systemDaemon;
157   static jfieldID java_lang_Thread_unparkedBeforeStart;
158   static jfieldID java_lang_ThreadGroup_groups;
159   static jfieldID java_lang_ThreadGroup_ngroups;
160   static jfieldID java_lang_ThreadGroup_mainThreadGroup;
161   static jfieldID java_lang_ThreadGroup_name;
162   static jfieldID java_lang_ThreadGroup_parent;
163   static jfieldID java_lang_ThreadGroup_systemThreadGroup;
164   static jfieldID java_lang_Throwable_cause;
165   static jfieldID java_lang_Throwable_detailMessage;
166   static jfieldID java_lang_Throwable_stackTrace;
167   static jfieldID java_lang_Throwable_stackState;
168   static jfieldID java_lang_Throwable_suppressedExceptions;
169   static jfieldID java_nio_Buffer_address;
170   static jfieldID java_nio_Buffer_capacity;
171   static jfieldID java_nio_Buffer_elementSizeShift;
172   static jfieldID java_nio_Buffer_limit;
173   static jfieldID java_nio_Buffer_position;
174   static jfieldID java_nio_ByteBuffer_address;
175   static jfieldID java_nio_ByteBuffer_hb;
176   static jfieldID java_nio_ByteBuffer_isReadOnly;
177   static jfieldID java_nio_ByteBuffer_limit;
178   static jfieldID java_nio_ByteBuffer_offset;
179 
180   static jfieldID java_util_Collections_EMPTY_LIST;
181   static jfieldID libcore_util_EmptyArray_STACK_TRACE_ELEMENT;
182   static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_data;
183   static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_length;
184   static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_offset;
185   static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_type;
186 };
187 
188 }  // namespace art
189 
190 #endif  // ART_RUNTIME_WELL_KNOWN_CLASSES_H_
191