• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "read_barrier_option.h"
24 
25 namespace art {
26 
27 class ArtField;
28 class ArtMethod;
29 
30 namespace mirror {
31 class Class;
32 }  // namespace mirror
33 
34 namespace detail {
35 
36 template <typename MemberType, MemberType** kMember>
37 struct ClassFromMember {
38   template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
39   static ObjPtr<mirror::Class> Get() REQUIRES_SHARED(Locks::mutator_lock_);
40 
41   mirror::Class* operator->() const REQUIRES_SHARED(Locks::mutator_lock_);
42 };
43 
44 template <typename MemberType, MemberType** kMember>
45 bool operator==(const ClassFromMember<MemberType, kMember> lhs, ObjPtr<mirror::Class> rhs)
46     REQUIRES_SHARED(Locks::mutator_lock_);
47 
48 template <typename MemberType, MemberType** kMember>
49 bool operator==(ObjPtr<mirror::Class> lhs, const ClassFromMember<MemberType, kMember> rhs)
50     REQUIRES_SHARED(Locks::mutator_lock_);
51 
52 template <typename MemberType, MemberType** kMember>
53 bool operator!=(const ClassFromMember<MemberType, kMember> lhs, ObjPtr<mirror::Class> rhs)
54     REQUIRES_SHARED(Locks::mutator_lock_);
55 
56 template <typename MemberType, MemberType** kMember>
57 bool operator!=(ObjPtr<mirror::Class> lhs, const ClassFromMember<MemberType, kMember> rhs)
58     REQUIRES_SHARED(Locks::mutator_lock_);
59 
60 }  // namespace detail
61 
62 // Various classes used in JNI. We cache them so we don't have to keep looking them up.
63 
64 struct WellKnownClasses {
65  public:
66   // Run before native methods are registered.
67   static void Init(JNIEnv* env);
68   // Run after native methods are registered.
69   static void LateInit(JNIEnv* env);
70 
71   static void Clear();
72 
73   static void HandleJniIdTypeChange(JNIEnv* env);
74 
75   static void InitStringInit(ObjPtr<mirror::Class> string_class,
76                              ObjPtr<mirror::Class> string_builder_class)
77       REQUIRES_SHARED(Locks::mutator_lock_);
78   static ArtMethod* StringInitToStringFactory(ArtMethod* method);
79   static uint32_t StringInitToEntryPoint(ArtMethod* method);
80 
81   static ObjPtr<mirror::Class> ToClass(jclass global_jclass) REQUIRES_SHARED(Locks::mutator_lock_);
82 
83  private:
84   static void InitFieldsAndMethodsOnly(JNIEnv* env);
85 
86   template <ArtMethod** kMethod>
87   using ClassFromMethod = detail::ClassFromMember<ArtMethod, kMethod>;
88 
89   template <ArtField** kField>
90   using ClassFromField = detail::ClassFromMember<ArtField, kField>;
91 
92  public:
93   static jclass dalvik_annotation_optimization_CriticalNative;
94   static jclass dalvik_annotation_optimization_FastNative;
95   static jclass dalvik_annotation_optimization_NeverCompile;
96   static jclass dalvik_annotation_optimization_NeverInline;
97   static jclass java_lang_annotation_Annotation__array;
98   static jclass java_lang_ClassValue;
99   static jclass java_lang_Record;
100   static jclass java_lang_reflect_Parameter__array;
101   static jclass java_lang_StringFactory;
102   static jclass java_lang_System;
103   static jclass java_lang_Void;
104   static jclass libcore_reflect_AnnotationMember__array;
105 
106   static ArtMethod* dalvik_system_BaseDexClassLoader_getLdLibraryPath;
107   static ArtMethod* dalvik_system_DelegateLastClassLoader_init;  // Only for the declaring class.
108   static ArtMethod* dalvik_system_DexClassLoader_init;  // Only for the declaring class.
109   static ArtMethod* dalvik_system_InMemoryDexClassLoader_init;  // Only for the declaring class.
110   static ArtMethod* dalvik_system_PathClassLoader_init;  // Only for the declaring class.
111   static ArtMethod* dalvik_system_VMRuntime_hiddenApiUsed;
112   static ArtMethod* java_lang_Boolean_valueOf;
113   static ArtMethod* java_lang_BootClassLoader_init;  // Only for the declaring class.
114   static ArtMethod* java_lang_Byte_valueOf;
115   static ArtMethod* java_lang_Character_valueOf;
116   static ArtMethod* java_lang_ClassLoader_loadClass;
117   static ArtMethod* java_lang_ClassNotFoundException_init;
118   static ArtMethod* java_lang_Daemons_start;
119   static ArtMethod* java_lang_Daemons_stop;
120   static ArtMethod* java_lang_Daemons_waitForDaemonStart;
121   static ArtMethod* java_lang_Double_doubleToRawLongBits;
122   static ArtMethod* java_lang_Double_valueOf;
123   static ArtMethod* java_lang_Error_init;  // Only for the declaring class.
124   static ArtMethod* java_lang_Float_floatToRawIntBits;
125   static ArtMethod* java_lang_Float_valueOf;
126   static ArtMethod* java_lang_IllegalAccessError_init;  // Only for the declaring class.
127   static ArtMethod* java_lang_Integer_valueOf;
128   static ArtMethod* java_lang_Long_valueOf;
129   static ArtMethod* java_lang_NoClassDefFoundError_init;  // Only for the declaring class.
130   static ArtMethod* java_lang_OutOfMemoryError_init;  // Only for the declaring class.
131   static ArtMethod* java_lang_Runtime_nativeLoad;
132   static ArtMethod* java_lang_RuntimeException_init;  // Only for the declaring class.
133   static ArtMethod* java_lang_Short_valueOf;
134   static ArtMethod* java_lang_StackOverflowError_init;  // Only for the declaring class.
135   static ArtMethod* java_lang_String_charAt;
136   static ArtMethod* java_lang_Thread_dispatchUncaughtException;
137   static ArtMethod* java_lang_Thread_init;
138   static ArtMethod* java_lang_Thread_run;
139   static ArtMethod* java_lang_ThreadGroup_add;
140   static ArtMethod* java_lang_ThreadGroup_threadTerminated;
141   static ArtMethod* java_lang_invoke_MethodHandle_asType;
142   static ArtMethod* java_lang_invoke_MethodHandle_invokeExact;
143   static ArtMethod* java_lang_invoke_MethodHandles_lookup;
144   static ArtMethod* java_lang_invoke_MethodHandles_Lookup_findConstructor;
145   static ArtMethod* java_lang_ref_FinalizerReference_add;
146   static ArtMethod* java_lang_ref_ReferenceQueue_add;
147   static ArtMethod* java_lang_reflect_InvocationTargetException_init;
148   static ArtMethod* java_lang_reflect_Parameter_init;
149   static ArtMethod* java_lang_reflect_Proxy_init;
150   static ArtMethod* java_lang_reflect_Proxy_invoke;
151   static ArtMethod* java_nio_Buffer_isDirect;
152   static ArtMethod* java_nio_DirectByteBuffer_init;
153   static ArtMethod* java_util_function_Consumer_accept;
154   static ArtMethod* jdk_internal_math_FloatingDecimal_getBinaryToASCIIConverter_D;
155   static ArtMethod* jdk_internal_math_FloatingDecimal_getBinaryToASCIIConverter_F;
156   static ArtMethod* jdk_internal_math_FloatingDecimal_BinaryToASCIIBuffer_getChars;
157   static ArtMethod* libcore_reflect_AnnotationFactory_createAnnotation;
158   static ArtMethod* libcore_reflect_AnnotationMember_init;
159   static ArtMethod* org_apache_harmony_dalvik_ddmc_DdmServer_broadcast;
160   static ArtMethod* org_apache_harmony_dalvik_ddmc_DdmServer_dispatch;
161 
162   static ArtField* dalvik_system_BaseDexClassLoader_pathList;
163   static ArtField* dalvik_system_BaseDexClassLoader_sharedLibraryLoaders;
164   static ArtField* dalvik_system_BaseDexClassLoader_sharedLibraryLoadersAfter;
165   static ArtField* dalvik_system_DexFile_cookie;
166   static ArtField* dalvik_system_DexFile_fileName;
167   static ArtField* dalvik_system_DexPathList_dexElements;
168   static ArtField* dalvik_system_DexPathList__Element_dexFile;
169   static ArtField* dalvik_system_VMRuntime_nonSdkApiUsageConsumer;
170   static ArtField* java_io_FileDescriptor_descriptor;
171   static ArtField* java_lang_ClassLoader_parent;
172   static ArtField* java_lang_Thread_parkBlocker;
173   static ArtField* java_lang_Thread_daemon;
174   static ArtField* java_lang_Thread_group;
175   static ArtField* java_lang_Thread_lock;
176   static ArtField* java_lang_Thread_name;
177   static ArtField* java_lang_Thread_priority;
178   static ArtField* java_lang_Thread_nativePeer;
179   static ArtField* java_lang_Thread_systemDaemon;
180   static ArtField* java_lang_Thread_unparkedBeforeStart;
181   static ArtField* java_lang_ThreadGroup_groups;
182   static ArtField* java_lang_ThreadGroup_ngroups;
183   static ArtField* java_lang_ThreadGroup_mainThreadGroup;
184   static ArtField* java_lang_ThreadGroup_name;
185   static ArtField* java_lang_ThreadGroup_parent;
186   static ArtField* java_lang_ThreadGroup_systemThreadGroup;
187   static ArtField* java_lang_Throwable_cause;
188   static ArtField* java_lang_Throwable_detailMessage;
189   static ArtField* java_lang_Throwable_stackTrace;
190   static ArtField* java_lang_Throwable_stackState;
191   static ArtField* java_lang_Throwable_suppressedExceptions;
192   static ArtField* java_nio_Buffer_address;
193   static ArtField* java_nio_Buffer_capacity;
194   static ArtField* java_nio_Buffer_elementSizeShift;
195   static ArtField* java_nio_Buffer_limit;
196   static ArtField* java_nio_Buffer_position;
197   static ArtField* java_nio_ByteBuffer_hb;
198   static ArtField* java_nio_ByteBuffer_isReadOnly;
199   static ArtField* java_nio_ByteBuffer_offset;
200   static ArtField* java_util_Collections_EMPTY_LIST;
201   static ArtField* jdk_internal_math_FloatingDecimal_BinaryToASCIIBuffer_buffer;
202   static ArtField* jdk_internal_math_FloatingDecimal_ExceptionalBinaryToASCIIBuffer_image;
203   static ArtField* libcore_util_EmptyArray_STACK_TRACE_ELEMENT;
204   static ArtField* org_apache_harmony_dalvik_ddmc_Chunk_data;
205   static ArtField* org_apache_harmony_dalvik_ddmc_Chunk_length;
206   static ArtField* org_apache_harmony_dalvik_ddmc_Chunk_offset;
207   static ArtField* org_apache_harmony_dalvik_ddmc_Chunk_type;
208 
209   static constexpr ClassFromField<&dalvik_system_BaseDexClassLoader_pathList>
210       dalvik_system_BaseDexClassLoader;
211   static constexpr ClassFromMethod<&dalvik_system_DelegateLastClassLoader_init>
212       dalvik_system_DelegateLastClassLoader;
213   static constexpr ClassFromMethod<&dalvik_system_DexClassLoader_init>
214       dalvik_system_DexClassLoader;
215   static constexpr ClassFromField<&dalvik_system_DexFile_cookie> dalvik_system_DexFile;
216   static constexpr ClassFromField<&dalvik_system_DexPathList_dexElements> dalvik_system_DexPathList;
217   static constexpr ClassFromField<&dalvik_system_DexPathList__Element_dexFile>
218       dalvik_system_DexPathList__Element;
219   static constexpr ClassFromMethod<&dalvik_system_InMemoryDexClassLoader_init>
220       dalvik_system_InMemoryDexClassLoader;
221   static constexpr ClassFromMethod<&dalvik_system_PathClassLoader_init>
222       dalvik_system_PathClassLoader;
223   static constexpr ClassFromMethod<&java_lang_BootClassLoader_init> java_lang_BootClassLoader;
224   static constexpr ClassFromField<&java_lang_ClassLoader_parent> java_lang_ClassLoader;
225   static constexpr ClassFromMethod<&java_lang_Daemons_start> java_lang_Daemons;
226   static constexpr ClassFromMethod<&java_lang_Error_init> java_lang_Error;
227   static constexpr ClassFromMethod<&java_lang_IllegalAccessError_init>
228       java_lang_IllegalAccessError;
229   static constexpr ClassFromMethod<&java_lang_NoClassDefFoundError_init>
230       java_lang_NoClassDefFoundError;
231   static constexpr ClassFromMethod<&java_lang_OutOfMemoryError_init> java_lang_OutOfMemoryError;
232   static constexpr ClassFromMethod<&java_lang_RuntimeException_init> java_lang_RuntimeException;
233   static constexpr ClassFromMethod<&java_lang_StackOverflowError_init>
234       java_lang_StackOverflowError;
235   static constexpr ClassFromField<&java_lang_Thread_daemon> java_lang_Thread;
236   static constexpr ClassFromField<&java_lang_ThreadGroup_groups> java_lang_ThreadGroup;
237   static constexpr ClassFromMethod<&java_lang_reflect_InvocationTargetException_init>
238       java_lang_reflect_InvocationTargetException;
239   static constexpr ClassFromMethod<&java_lang_reflect_Parameter_init>
240       java_lang_reflect_Parameter;
241   static constexpr ClassFromField<&java_nio_Buffer_address> java_nio_Buffer;
242   static constexpr ClassFromField<&java_util_Collections_EMPTY_LIST> java_util_Collections;
243   static constexpr ClassFromField<&libcore_util_EmptyArray_STACK_TRACE_ELEMENT>
244       libcore_util_EmptyArray;
245 };
246 
247 }  // namespace art
248 
249 #endif  // ART_RUNTIME_WELL_KNOWN_CLASSES_H_
250