• 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 #include "well_known_classes.h"
18 
19 #include <stdlib.h>
20 
21 #include <sstream>
22 
23 #include <android-base/logging.h>
24 #include <android-base/stringprintf.h>
25 
26 #include "art_method-inl.h"
27 #include "base/casts.h"
28 #include "base/enums.h"
29 #include "class_linker.h"
30 #include "class_root-inl.h"
31 #include "entrypoints/quick/quick_entrypoints_enum.h"
32 #include "handle_scope-inl.h"
33 #include "hidden_api.h"
34 #include "jni/java_vm_ext.h"
35 #include "jni/jni_internal.h"
36 #include "jni_id_type.h"
37 #include "mirror/class.h"
38 #include "mirror/throwable.h"
39 #include "nativehelper/scoped_local_ref.h"
40 #include "obj_ptr-inl.h"
41 #include "runtime.h"
42 #include "scoped_thread_state_change-inl.h"
43 #include "scoped_thread_state_change.h"
44 #include "thread-current-inl.h"
45 
46 namespace art {
47 
48 jclass WellKnownClasses::dalvik_annotation_optimization_CriticalNative;
49 jclass WellKnownClasses::dalvik_annotation_optimization_FastNative;
50 jclass WellKnownClasses::dalvik_annotation_optimization_NeverCompile;
51 jclass WellKnownClasses::dalvik_annotation_optimization_NeverInline;
52 jclass WellKnownClasses::java_lang_annotation_Annotation__array;
53 jclass WellKnownClasses::java_lang_ClassValue;
54 jclass WellKnownClasses::java_lang_Record;
55 jclass WellKnownClasses::java_lang_reflect_Parameter__array;
56 jclass WellKnownClasses::java_lang_StringFactory;
57 jclass WellKnownClasses::java_lang_System;
58 jclass WellKnownClasses::java_lang_Void;
59 jclass WellKnownClasses::libcore_reflect_AnnotationMember__array;
60 
61 ArtMethod* WellKnownClasses::dalvik_system_BaseDexClassLoader_getLdLibraryPath;
62 ArtMethod* WellKnownClasses::dalvik_system_DelegateLastClassLoader_init;
63 ArtMethod* WellKnownClasses::dalvik_system_DexClassLoader_init;
64 ArtMethod* WellKnownClasses::dalvik_system_InMemoryDexClassLoader_init;
65 ArtMethod* WellKnownClasses::dalvik_system_PathClassLoader_init;
66 ArtMethod* WellKnownClasses::dalvik_system_VMRuntime_hiddenApiUsed;
67 ArtMethod* WellKnownClasses::java_lang_Boolean_valueOf;
68 ArtMethod* WellKnownClasses::java_lang_BootClassLoader_init;
69 ArtMethod* WellKnownClasses::java_lang_Byte_valueOf;
70 ArtMethod* WellKnownClasses::java_lang_Character_valueOf;
71 ArtMethod* WellKnownClasses::java_lang_ClassLoader_loadClass;
72 ArtMethod* WellKnownClasses::java_lang_ClassNotFoundException_init;
73 ArtMethod* WellKnownClasses::java_lang_Daemons_start;
74 ArtMethod* WellKnownClasses::java_lang_Daemons_stop;
75 ArtMethod* WellKnownClasses::java_lang_Daemons_waitForDaemonStart;
76 ArtMethod* WellKnownClasses::java_lang_Double_doubleToRawLongBits;
77 ArtMethod* WellKnownClasses::java_lang_Double_valueOf;
78 ArtMethod* WellKnownClasses::java_lang_Error_init;
79 ArtMethod* WellKnownClasses::java_lang_Float_floatToRawIntBits;
80 ArtMethod* WellKnownClasses::java_lang_Float_valueOf;
81 ArtMethod* WellKnownClasses::java_lang_IllegalAccessError_init;
82 ArtMethod* WellKnownClasses::java_lang_Integer_valueOf;
83 ArtMethod* WellKnownClasses::java_lang_Long_valueOf;
84 ArtMethod* WellKnownClasses::java_lang_NoClassDefFoundError_init;
85 ArtMethod* WellKnownClasses::java_lang_OutOfMemoryError_init;
86 ArtMethod* WellKnownClasses::java_lang_Runtime_nativeLoad;
87 ArtMethod* WellKnownClasses::java_lang_RuntimeException_init;
88 ArtMethod* WellKnownClasses::java_lang_Short_valueOf;
89 ArtMethod* WellKnownClasses::java_lang_StackOverflowError_init;
90 ArtMethod* WellKnownClasses::java_lang_String_charAt;
91 ArtMethod* WellKnownClasses::java_lang_Thread_dispatchUncaughtException;
92 ArtMethod* WellKnownClasses::java_lang_Thread_init;
93 ArtMethod* WellKnownClasses::java_lang_Thread_run;
94 ArtMethod* WellKnownClasses::java_lang_ThreadGroup_add;
95 ArtMethod* WellKnownClasses::java_lang_ThreadGroup_threadTerminated;
96 ArtMethod* WellKnownClasses::java_lang_invoke_MethodHandle_asType;
97 ArtMethod* WellKnownClasses::java_lang_invoke_MethodHandle_invokeExact;
98 ArtMethod* WellKnownClasses::java_lang_invoke_MethodHandles_lookup;
99 ArtMethod* WellKnownClasses::java_lang_invoke_MethodHandles_Lookup_findConstructor;
100 ArtMethod* WellKnownClasses::java_lang_ref_FinalizerReference_add;
101 ArtMethod* WellKnownClasses::java_lang_ref_ReferenceQueue_add;
102 ArtMethod* WellKnownClasses::java_lang_reflect_InvocationTargetException_init;
103 ArtMethod* WellKnownClasses::java_lang_reflect_Parameter_init;
104 ArtMethod* WellKnownClasses::java_lang_reflect_Proxy_init;
105 ArtMethod* WellKnownClasses::java_lang_reflect_Proxy_invoke;
106 ArtMethod* WellKnownClasses::java_nio_Buffer_isDirect;
107 ArtMethod* WellKnownClasses::java_nio_DirectByteBuffer_init;
108 ArtMethod* WellKnownClasses::java_util_function_Consumer_accept;
109 ArtMethod* WellKnownClasses::jdk_internal_math_FloatingDecimal_getBinaryToASCIIConverter_D;
110 ArtMethod* WellKnownClasses::jdk_internal_math_FloatingDecimal_getBinaryToASCIIConverter_F;
111 ArtMethod* WellKnownClasses::jdk_internal_math_FloatingDecimal_BinaryToASCIIBuffer_getChars;
112 ArtMethod* WellKnownClasses::libcore_reflect_AnnotationFactory_createAnnotation;
113 ArtMethod* WellKnownClasses::libcore_reflect_AnnotationMember_init;
114 ArtMethod* WellKnownClasses::org_apache_harmony_dalvik_ddmc_DdmServer_broadcast;
115 ArtMethod* WellKnownClasses::org_apache_harmony_dalvik_ddmc_DdmServer_dispatch;
116 
117 ArtField* WellKnownClasses::dalvik_system_BaseDexClassLoader_pathList;
118 ArtField* WellKnownClasses::dalvik_system_BaseDexClassLoader_sharedLibraryLoaders;
119 ArtField* WellKnownClasses::dalvik_system_BaseDexClassLoader_sharedLibraryLoadersAfter;
120 ArtField* WellKnownClasses::dalvik_system_DexFile_cookie;
121 ArtField* WellKnownClasses::dalvik_system_DexFile_fileName;
122 ArtField* WellKnownClasses::dalvik_system_DexPathList_dexElements;
123 ArtField* WellKnownClasses::dalvik_system_DexPathList__Element_dexFile;
124 ArtField* WellKnownClasses::dalvik_system_VMRuntime_nonSdkApiUsageConsumer;
125 ArtField* WellKnownClasses::java_io_FileDescriptor_descriptor;
126 ArtField* WellKnownClasses::java_lang_ClassLoader_parent;
127 ArtField* WellKnownClasses::java_lang_Thread_parkBlocker;
128 ArtField* WellKnownClasses::java_lang_Thread_daemon;
129 ArtField* WellKnownClasses::java_lang_Thread_group;
130 ArtField* WellKnownClasses::java_lang_Thread_lock;
131 ArtField* WellKnownClasses::java_lang_Thread_name;
132 ArtField* WellKnownClasses::java_lang_Thread_priority;
133 ArtField* WellKnownClasses::java_lang_Thread_nativePeer;
134 ArtField* WellKnownClasses::java_lang_Thread_systemDaemon;
135 ArtField* WellKnownClasses::java_lang_Thread_unparkedBeforeStart;
136 ArtField* WellKnownClasses::java_lang_ThreadGroup_groups;
137 ArtField* WellKnownClasses::java_lang_ThreadGroup_ngroups;
138 ArtField* WellKnownClasses::java_lang_ThreadGroup_mainThreadGroup;
139 ArtField* WellKnownClasses::java_lang_ThreadGroup_name;
140 ArtField* WellKnownClasses::java_lang_ThreadGroup_parent;
141 ArtField* WellKnownClasses::java_lang_ThreadGroup_systemThreadGroup;
142 ArtField* WellKnownClasses::java_lang_Throwable_cause;
143 ArtField* WellKnownClasses::java_lang_Throwable_detailMessage;
144 ArtField* WellKnownClasses::java_lang_Throwable_stackTrace;
145 ArtField* WellKnownClasses::java_lang_Throwable_stackState;
146 ArtField* WellKnownClasses::java_lang_Throwable_suppressedExceptions;
147 ArtField* WellKnownClasses::java_nio_Buffer_address;
148 ArtField* WellKnownClasses::java_nio_Buffer_capacity;
149 ArtField* WellKnownClasses::java_nio_Buffer_elementSizeShift;
150 ArtField* WellKnownClasses::java_nio_Buffer_limit;
151 ArtField* WellKnownClasses::java_nio_Buffer_position;
152 ArtField* WellKnownClasses::java_nio_ByteBuffer_hb;
153 ArtField* WellKnownClasses::java_nio_ByteBuffer_isReadOnly;
154 ArtField* WellKnownClasses::java_nio_ByteBuffer_offset;
155 ArtField* WellKnownClasses::java_util_Collections_EMPTY_LIST;
156 ArtField* WellKnownClasses::jdk_internal_math_FloatingDecimal_BinaryToASCIIBuffer_buffer;
157 ArtField* WellKnownClasses::jdk_internal_math_FloatingDecimal_ExceptionalBinaryToASCIIBuffer_image;
158 ArtField* WellKnownClasses::libcore_util_EmptyArray_STACK_TRACE_ELEMENT;
159 ArtField* WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_data;
160 ArtField* WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_length;
161 ArtField* WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_offset;
162 ArtField* WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_type;
163 
FindSystemClass(ClassLinker * class_linker,Thread * self,const char * descriptor)164 static ObjPtr<mirror::Class> FindSystemClass(ClassLinker* class_linker,
165                                              Thread* self,
166                                              const char* descriptor)
167     REQUIRES_SHARED(Locks::mutator_lock_) {
168   ObjPtr<mirror::Class> klass = class_linker->FindSystemClass(self, descriptor);
169   CHECK(klass != nullptr) << "Couldn't find system class: " << descriptor;
170   return klass;
171 }
172 
CacheClass(JNIEnv * env,const char * jni_class_name)173 static jclass CacheClass(JNIEnv* env, const char* jni_class_name) {
174   ScopedLocalRef<jclass> c(env, env->FindClass(jni_class_name));
175   if (c.get() == nullptr) {
176     LOG(FATAL) << "Couldn't find class: " << jni_class_name;
177   }
178   return reinterpret_cast<jclass>(env->NewGlobalRef(c.get()));
179 }
180 
CacheField(ObjPtr<mirror::Class> klass,bool is_static,const char * name,const char * signature)181 static ArtField* CacheField(ObjPtr<mirror::Class> klass,
182                             bool is_static,
183                             const char* name,
184                             const char* signature) REQUIRES_SHARED(Locks::mutator_lock_) {
185   ArtField* field = is_static
186       ? klass->FindDeclaredStaticField(name, signature)
187       : klass->FindDeclaredInstanceField(name, signature);
188   if (UNLIKELY(field == nullptr)) {
189     std::ostringstream os;
190     klass->DumpClass(os, mirror::Class::kDumpClassFullDetail);
191     LOG(FATAL) << "Couldn't find " << (is_static ? "static" : "instance") << " field \""
192                << name << "\" with signature \"" << signature << "\": " << os.str();
193     UNREACHABLE();
194   }
195   return field;
196 }
197 
CacheMethod(ObjPtr<mirror::Class> klass,bool is_static,const char * name,const char * signature,PointerSize pointer_size)198 static ArtMethod* CacheMethod(ObjPtr<mirror::Class> klass,
199                               bool is_static,
200                               const char* name,
201                               const char* signature,
202                               PointerSize pointer_size) REQUIRES_SHARED(Locks::mutator_lock_) {
203   ArtMethod* method = klass->IsInterface()
204       ? klass->FindInterfaceMethod(name, signature, pointer_size)
205       : klass->FindClassMethod(name, signature, pointer_size);
206   if (UNLIKELY(method == nullptr) || UNLIKELY(is_static != method->IsStatic())) {
207     std::ostringstream os;
208     klass->DumpClass(os, mirror::Class::kDumpClassFullDetail);
209     LOG(FATAL) << "Couldn't find " << (is_static ? "static" : "instance") << " method \""
210                << name << "\" with signature \"" << signature << "\": " << os.str();
211     UNREACHABLE();
212   }
213   DCHECK(method->GetDeclaringClass() == klass);
214   return method;
215 }
216 
CachePrimitiveBoxingMethod(ClassLinker * class_linker,Thread * self,char prim_name,const char * boxed_name)217 static ArtMethod* CachePrimitiveBoxingMethod(ClassLinker* class_linker,
218                                              Thread* self,
219                                              char prim_name,
220                                              const char* boxed_name)
221     REQUIRES_SHARED(Locks::mutator_lock_) {
222   ObjPtr<mirror::Class> boxed_class = FindSystemClass(class_linker, self, boxed_name);
223   PointerSize pointer_size = class_linker->GetImagePointerSize();
224   std::string signature = android::base::StringPrintf("(%c)%s", prim_name, boxed_name);
225   return CacheMethod(boxed_class, /*is_static=*/ true, "valueOf", signature.c_str(), pointer_size);
226 }
227 
228 #define STRING_INIT_LIST(V) \
229   V(java_lang_String_init, "()V", newEmptyString, "newEmptyString", "()Ljava/lang/String;", NewEmptyString) \
230   V(java_lang_String_init_B, "([B)V", newStringFromBytes_B, "newStringFromBytes", "([B)Ljava/lang/String;", NewStringFromBytes_B) \
231   V(java_lang_String_init_BB, "([BB)V", newStringFromBytes_BB, "newStringFromBytes", "([BB)Ljava/lang/String;", NewStringFromBytes_BB) \
232   V(java_lang_String_init_BI, "([BI)V", newStringFromBytes_BI, "newStringFromBytes", "([BI)Ljava/lang/String;", NewStringFromBytes_BI) \
233   V(java_lang_String_init_BII, "([BII)V", newStringFromBytes_BII, "newStringFromBytes", "([BII)Ljava/lang/String;", NewStringFromBytes_BII) \
234   V(java_lang_String_init_BIII, "([BIII)V", newStringFromBytes_BIII, "newStringFromBytes", "([BIII)Ljava/lang/String;", NewStringFromBytes_BIII) \
235   V(java_lang_String_init_BIIString, "([BIILjava/lang/String;)V", newStringFromBytes_BIIString, "newStringFromBytes", "([BIILjava/lang/String;)Ljava/lang/String;", NewStringFromBytes_BIIString) \
236   V(java_lang_String_init_BString, "([BLjava/lang/String;)V", newStringFromBytes_BString, "newStringFromBytes", "([BLjava/lang/String;)Ljava/lang/String;", NewStringFromBytes_BString) \
237   V(java_lang_String_init_BIICharset, "([BIILjava/nio/charset/Charset;)V", newStringFromBytes_BIICharset, "newStringFromBytes", "([BIILjava/nio/charset/Charset;)Ljava/lang/String;", NewStringFromBytes_BIICharset) \
238   V(java_lang_String_init_BCharset, "([BLjava/nio/charset/Charset;)V", newStringFromBytes_BCharset, "newStringFromBytes", "([BLjava/nio/charset/Charset;)Ljava/lang/String;", NewStringFromBytes_BCharset) \
239   V(java_lang_String_init_C, "([C)V", newStringFromChars_C, "newStringFromChars", "([C)Ljava/lang/String;", NewStringFromChars_C) \
240   V(java_lang_String_init_CII, "([CII)V", newStringFromChars_CII, "newStringFromChars", "([CII)Ljava/lang/String;", NewStringFromChars_CII) \
241   V(java_lang_String_init_IIC, "(II[C)V", newStringFromChars_IIC, "newStringFromChars", "(II[C)Ljava/lang/String;", NewStringFromChars_IIC) \
242   V(java_lang_String_init_String, "(Ljava/lang/String;)V", newStringFromString, "newStringFromString", "(Ljava/lang/String;)Ljava/lang/String;", NewStringFromString) \
243   V(java_lang_String_init_StringBuffer, "(Ljava/lang/StringBuffer;)V", newStringFromStringBuffer, "newStringFromStringBuffer", "(Ljava/lang/StringBuffer;)Ljava/lang/String;", NewStringFromStringBuffer) \
244   V(java_lang_String_init_III, "([III)V", newStringFromCodePoints, "newStringFromCodePoints", "([III)Ljava/lang/String;", NewStringFromCodePoints) \
245   V(java_lang_String_init_StringBuilder, "(Ljava/lang/StringBuilder;)V", newStringFromStringBuilder, "newStringFromStringBuilder", "(Ljava/lang/StringBuilder;)Ljava/lang/String;", NewStringFromStringBuilder) \
246 
247 #define STATIC_STRING_INIT(init_runtime_name, init_signature, new_runtime_name, ...) \
248     static ArtMethod* init_runtime_name = nullptr; \
249     static ArtMethod* new_runtime_name = nullptr;
STRING_INIT_LIST(STATIC_STRING_INIT)250     STRING_INIT_LIST(STATIC_STRING_INIT)
251 #undef STATIC_STRING_INIT
252 
253 void WellKnownClasses::InitStringInit(ObjPtr<mirror::Class> string_class,
254                                       ObjPtr<mirror::Class> string_builder_class) {
255   PointerSize p_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
256   auto find_method = [p_size](ObjPtr<mirror::Class> klass,
257                               const char* name,
258                               const char* sig,
259                               bool expext_static) REQUIRES_SHARED(Locks::mutator_lock_) {
260     ArtMethod* ret = klass->FindClassMethod(name, sig, p_size);
261     CHECK(ret != nullptr);
262     CHECK_EQ(expext_static, ret->IsStatic());
263     return ret;
264   };
265 
266   #define LOAD_STRING_INIT(init_runtime_name, init_signature, new_runtime_name,                  \
267                            new_java_name, new_signature, ...)                                    \
268       init_runtime_name = find_method(string_class, "<init>", init_signature, false);            \
269       new_runtime_name = find_method(string_builder_class, new_java_name, new_signature, true);
270       STRING_INIT_LIST(LOAD_STRING_INIT)
271   #undef LOAD_STRING_INIT
272 }
273 
InitStringEntryPoints()274 void Thread::InitStringEntryPoints() {
275   QuickEntryPoints* qpoints = &tlsPtr_.quick_entrypoints;
276 #define SET_ENTRY_POINT(init_runtime_name,                                        \
277                         init_signature,                                           \
278                         new_runtime_name,                                         \
279                         new_java_name,                                            \
280                         new_signature,                                            \
281                         entry_point_name)                                         \
282   DCHECK_IMPLIES(Runtime::Current()->IsStarted(), (new_runtime_name) != nullptr); \
283   qpoints->p##entry_point_name = reinterpret_cast<void*>(new_runtime_name);
284   STRING_INIT_LIST(SET_ENTRY_POINT)
285 #undef SET_ENTRY_POINT
286 }
287 
StringInitToStringFactory(ArtMethod * string_init)288 ArtMethod* WellKnownClasses::StringInitToStringFactory(ArtMethod* string_init) {
289   #define TO_STRING_FACTORY(init_runtime_name, init_signature, new_runtime_name,            \
290                             new_java_name, new_signature, entry_point_name)                 \
291       DCHECK((init_runtime_name) != nullptr);                                               \
292       if (string_init == (init_runtime_name)) {                                             \
293         DCHECK((new_runtime_name) != nullptr);                                              \
294         return (new_runtime_name);                                                          \
295       }
296       STRING_INIT_LIST(TO_STRING_FACTORY)
297   #undef TO_STRING_FACTORY
298   LOG(FATAL) << "Could not find StringFactory method for String.<init>";
299   UNREACHABLE();
300 }
301 
StringInitToEntryPoint(ArtMethod * string_init)302 uint32_t WellKnownClasses::StringInitToEntryPoint(ArtMethod* string_init) {
303   #define TO_ENTRY_POINT(init_runtime_name, init_signature, new_runtime_name,               \
304                          new_java_name, new_signature, entry_point_name)                    \
305       if (string_init == (init_runtime_name)) {                                             \
306         return kQuick ## entry_point_name;                                                  \
307       }
308       STRING_INIT_LIST(TO_ENTRY_POINT)
309   #undef TO_ENTRY_POINT
310   LOG(FATAL) << "Could not find StringFactory method for String.<init>";
311   UNREACHABLE();
312 }
313 #undef STRING_INIT_LIST
314 
Init(JNIEnv * env)315 void WellKnownClasses::Init(JNIEnv* env) {
316   hiddenapi::ScopedHiddenApiEnforcementPolicySetting hiddenapi_exemption(
317       hiddenapi::EnforcementPolicy::kDisabled);
318 
319   dalvik_annotation_optimization_CriticalNative =
320       CacheClass(env, "dalvik/annotation/optimization/CriticalNative");
321   dalvik_annotation_optimization_FastNative = CacheClass(env, "dalvik/annotation/optimization/FastNative");
322   dalvik_annotation_optimization_NeverCompile =
323       CacheClass(env, "dalvik/annotation/optimization/NeverCompile");
324   dalvik_annotation_optimization_NeverInline =
325       CacheClass(env, "dalvik/annotation/optimization/NeverInline");
326 
327   java_lang_annotation_Annotation__array = CacheClass(env, "[Ljava/lang/annotation/Annotation;");
328   java_lang_ClassValue = CacheClass(env, "java/lang/ClassValue");
329   java_lang_Record = CacheClass(env, "java/lang/Record");
330   java_lang_reflect_Parameter__array = CacheClass(env, "[Ljava/lang/reflect/Parameter;");
331   java_lang_StringFactory = CacheClass(env, "java/lang/StringFactory");
332   java_lang_System = CacheClass(env, "java/lang/System");
333   java_lang_Void = CacheClass(env, "java/lang/Void");
334   libcore_reflect_AnnotationMember__array = CacheClass(env, "[Llibcore/reflect/AnnotationMember;");
335 
336   InitFieldsAndMethodsOnly(env);
337 }
338 
InitFieldsAndMethodsOnly(JNIEnv * env)339 void WellKnownClasses::InitFieldsAndMethodsOnly(JNIEnv* env) {
340   hiddenapi::ScopedHiddenApiEnforcementPolicySetting hiddenapi_exemption(
341       hiddenapi::EnforcementPolicy::kDisabled);
342 
343   Thread* self = Thread::ForEnv(env);
344   ScopedObjectAccess soa(self);
345   ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
346 
347   java_lang_Boolean_valueOf =
348       CachePrimitiveBoxingMethod(class_linker, self, 'Z', "Ljava/lang/Boolean;");
349   java_lang_Byte_valueOf =
350       CachePrimitiveBoxingMethod(class_linker, self, 'B', "Ljava/lang/Byte;");
351   java_lang_Character_valueOf =
352       CachePrimitiveBoxingMethod(class_linker, self, 'C', "Ljava/lang/Character;");
353   java_lang_Double_valueOf =
354       CachePrimitiveBoxingMethod(class_linker, self, 'D', "Ljava/lang/Double;");
355   java_lang_Float_valueOf =
356       CachePrimitiveBoxingMethod(class_linker, self, 'F', "Ljava/lang/Float;");
357   java_lang_Integer_valueOf =
358       CachePrimitiveBoxingMethod(class_linker, self, 'I', "Ljava/lang/Integer;");
359   java_lang_Long_valueOf =
360       CachePrimitiveBoxingMethod(class_linker, self, 'J', "Ljava/lang/Long;");
361   java_lang_Short_valueOf =
362       CachePrimitiveBoxingMethod(class_linker, self, 'S', "Ljava/lang/Short;");
363 
364   StackHandleScope<42u> hs(self);
365   Handle<mirror::Class> d_s_bdcl =
366       hs.NewHandle(FindSystemClass(class_linker, self, "Ldalvik/system/BaseDexClassLoader;"));
367   Handle<mirror::Class> d_s_dlcl =
368       hs.NewHandle(FindSystemClass(class_linker, self, "Ldalvik/system/DelegateLastClassLoader;"));
369   Handle<mirror::Class> d_s_dcl =
370       hs.NewHandle(FindSystemClass(class_linker, self, "Ldalvik/system/DexClassLoader;"));
371   Handle<mirror::Class> d_s_df =
372       hs.NewHandle(FindSystemClass(class_linker, self, "Ldalvik/system/DexFile;"));
373   Handle<mirror::Class> d_s_dpl =
374       hs.NewHandle(FindSystemClass(class_linker, self, "Ldalvik/system/DexPathList;"));
375   Handle<mirror::Class> d_s_dpl_e =
376       hs.NewHandle(FindSystemClass(class_linker, self, "Ldalvik/system/DexPathList$Element;"));
377   Handle<mirror::Class> d_s_imdcl =
378       hs.NewHandle(FindSystemClass(class_linker, self, "Ldalvik/system/InMemoryDexClassLoader;"));
379   Handle<mirror::Class> d_s_pcl =
380       hs.NewHandle(FindSystemClass(class_linker, self, "Ldalvik/system/PathClassLoader;"));
381   Handle<mirror::Class> d_s_vmr =
382       hs.NewHandle(FindSystemClass(class_linker, self, "Ldalvik/system/VMRuntime;"));
383   Handle<mirror::Class> j_i_fd =
384       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/io/FileDescriptor;"));
385   Handle<mirror::Class> j_l_bcl =
386       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/lang/BootClassLoader;"));
387   Handle<mirror::Class> j_l_cl =
388       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/lang/ClassLoader;"));
389   Handle<mirror::Class> j_l_cnfe =
390       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/lang/ClassNotFoundException;"));
391   Handle<mirror::Class> j_l_Daemons =
392       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/lang/Daemons;"));
393   Handle<mirror::Class> j_l_Error =
394       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/lang/Error;"));
395   Handle<mirror::Class> j_l_IllegalAccessError =
396       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/lang/IllegalAccessError;"));
397   Handle<mirror::Class> j_l_NoClassDefFoundError =
398       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/lang/NoClassDefFoundError;"));
399   Handle<mirror::Class> j_l_OutOfMemoryError =
400       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/lang/OutOfMemoryError;"));
401   Handle<mirror::Class> j_l_RuntimeException =
402       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/lang/RuntimeException;"));
403   Handle<mirror::Class> j_l_StackOverflowError =
404       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/lang/StackOverflowError;"));
405   Handle<mirror::Class> j_l_Thread =
406       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/lang/Thread;"));
407   Handle<mirror::Class> j_l_tg =
408       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/lang/ThreadGroup;"));
409   Handle<mirror::Class> j_l_i_MethodHandle =
410       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/lang/invoke/MethodHandle;"));
411   Handle<mirror::Class> j_l_i_MethodHandles =
412       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/lang/invoke/MethodHandles;"));
413   Handle<mirror::Class> j_l_i_MethodHandles_Lookup =
414       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/lang/invoke/MethodHandles$Lookup;"));
415   Handle<mirror::Class> j_l_r_fr =
416       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/lang/ref/FinalizerReference;"));
417   Handle<mirror::Class> j_l_r_rq =
418       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/lang/ref/ReferenceQueue;"));
419   Handle<mirror::Class> j_l_rl_ite = hs.NewHandle(
420       FindSystemClass(class_linker, self, "Ljava/lang/reflect/InvocationTargetException;"));
421   Handle<mirror::Class> j_l_rl_Parameter =
422       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/lang/reflect/Parameter;"));
423   Handle<mirror::Class> j_n_b =
424       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/nio/Buffer;"));
425   Handle<mirror::Class> j_n_bb =
426       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/nio/ByteBuffer;"));
427   Handle<mirror::Class> j_n_dbb =
428       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/nio/DirectByteBuffer;"));
429   Handle<mirror::Class> j_u_c =
430       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/util/Collections;"));
431   Handle<mirror::Class> j_u_f_c =
432       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/util/function/Consumer;"));
433   Handle<mirror::Class> j_i_m_fd =
434       hs.NewHandle(FindSystemClass(class_linker, self, "Ljdk/internal/math/FloatingDecimal;"));
435   Handle<mirror::Class> j_i_m_fd_btab = hs.NewHandle(FindSystemClass(
436       class_linker, self, "Ljdk/internal/math/FloatingDecimal$BinaryToASCIIBuffer;"));
437   Handle<mirror::Class> j_i_m_fd_ebtab = hs.NewHandle(FindSystemClass(
438       class_linker, self, "Ljdk/internal/math/FloatingDecimal$ExceptionalBinaryToASCIIBuffer;"));
439   Handle<mirror::Class> l_r_af =
440       hs.NewHandle(FindSystemClass(class_linker, self, "Llibcore/reflect/AnnotationFactory;"));
441   Handle<mirror::Class> l_r_am =
442       hs.NewHandle(FindSystemClass(class_linker, self, "Llibcore/reflect/AnnotationMember;"));
443   Handle<mirror::Class> l_u_ea =
444       hs.NewHandle(FindSystemClass(class_linker, self, "Llibcore/util/EmptyArray;"));
445   Handle<mirror::Class> o_a_h_d_c =
446       hs.NewHandle(FindSystemClass(class_linker, self, "Lorg/apache/harmony/dalvik/ddmc/Chunk;"));
447   Handle<mirror::Class> o_a_h_d_d_ds =
448       hs.NewHandle(FindSystemClass(class_linker, self, "Lorg/apache/harmony/dalvik/ddmc/DdmServer;"));
449 
450   ScopedAssertNoThreadSuspension sants(__FUNCTION__);
451   PointerSize pointer_size = class_linker->GetImagePointerSize();
452 
453   dalvik_system_BaseDexClassLoader_getLdLibraryPath = CacheMethod(
454       d_s_bdcl.Get(),
455       /*is_static=*/ false,
456       "getLdLibraryPath",
457       "()Ljava/lang/String;",
458       pointer_size);
459   dalvik_system_DelegateLastClassLoader_init = CacheMethod(
460       d_s_dlcl.Get(),
461       /*is_static=*/ false,
462       "<init>",
463       "(Ljava/lang/String;Ljava/lang/ClassLoader;)V",
464       pointer_size);
465   dalvik_system_DexClassLoader_init = CacheMethod(
466       d_s_dcl.Get(),
467       /*is_static=*/ false,
468       "<init>",
469       "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/ClassLoader;)V",
470       pointer_size);
471   dalvik_system_InMemoryDexClassLoader_init = CacheMethod(
472       d_s_imdcl.Get(),
473       /*is_static=*/ false,
474       "<init>",
475       "(Ljava/nio/ByteBuffer;Ljava/lang/ClassLoader;)V",
476       pointer_size);
477   dalvik_system_PathClassLoader_init = CacheMethod(
478       d_s_pcl.Get(),
479       /*is_static=*/ false,
480       "<init>",
481       "(Ljava/lang/String;Ljava/lang/ClassLoader;)V",
482       pointer_size);
483 
484   dalvik_system_VMRuntime_hiddenApiUsed = CacheMethod(
485       d_s_vmr.Get(),
486       /*is_static=*/ true,
487       "hiddenApiUsed",
488       "(ILjava/lang/String;Ljava/lang/String;IZ)V",
489       pointer_size);
490 
491   java_lang_BootClassLoader_init =
492       CacheMethod(j_l_bcl.Get(), /*is_static=*/ false, "<init>", "()V", pointer_size);
493   java_lang_ClassLoader_loadClass = CacheMethod(
494       j_l_cl.Get(),
495       /*is_static=*/ false,
496       "loadClass",
497       "(Ljava/lang/String;)Ljava/lang/Class;",
498       pointer_size);
499 
500   java_lang_ClassNotFoundException_init = CacheMethod(
501       j_l_cnfe.Get(),
502       /*is_static=*/ false,
503       "<init>",
504       "(Ljava/lang/String;Ljava/lang/Throwable;)V",
505       pointer_size);
506 
507   ObjPtr<mirror::Class> j_l_Double = java_lang_Double_valueOf->GetDeclaringClass();
508   java_lang_Double_doubleToRawLongBits =
509       CacheMethod(j_l_Double, /*is_static=*/ true, "doubleToRawLongBits", "(D)J", pointer_size);
510   ObjPtr<mirror::Class> j_l_Float = java_lang_Float_valueOf->GetDeclaringClass();
511   java_lang_Float_floatToRawIntBits =
512       CacheMethod(j_l_Float, /*is_static=*/ true, "floatToRawIntBits", "(F)I", pointer_size);
513 
514   java_lang_Daemons_start = CacheMethod(
515       j_l_Daemons.Get(), /*is_static=*/ true, "start", "()V", pointer_size);
516   java_lang_Daemons_stop = CacheMethod(
517       j_l_Daemons.Get(), /*is_static=*/ true, "stop", "()V", pointer_size);
518   java_lang_Daemons_waitForDaemonStart = CacheMethod(
519       j_l_Daemons.Get(), /*is_static=*/ true, "waitForDaemonStart", "()V", pointer_size);
520 
521   java_lang_Error_init = CacheMethod(
522       j_l_Error.Get(), /*is_static=*/ false, "<init>", "()V", pointer_size);
523   java_lang_IllegalAccessError_init = CacheMethod(
524       j_l_IllegalAccessError.Get(), /*is_static=*/ false, "<init>", "()V", pointer_size);
525   java_lang_NoClassDefFoundError_init = CacheMethod(
526       j_l_NoClassDefFoundError.Get(), /*is_static=*/ false, "<init>", "()V", pointer_size);
527   java_lang_OutOfMemoryError_init = CacheMethod(
528       j_l_OutOfMemoryError.Get(), /*is_static=*/ false, "<init>", "()V", pointer_size);
529   java_lang_RuntimeException_init = CacheMethod(
530       j_l_RuntimeException.Get(), /*is_static=*/ false, "<init>", "()V", pointer_size);
531   java_lang_StackOverflowError_init = CacheMethod(
532       j_l_StackOverflowError.Get(), /*is_static=*/ false, "<init>", "()V", pointer_size);
533 
534   ObjPtr<mirror::Class> j_l_String = GetClassRoot<mirror::String>(class_linker);
535   java_lang_String_charAt = CacheMethod(
536       j_l_String, /*is_static=*/ false, "charAt", "(I)C", pointer_size);
537 
538   java_lang_Thread_dispatchUncaughtException = CacheMethod(
539       j_l_Thread.Get(),
540       /*is_static=*/ false,
541       "dispatchUncaughtException",
542       "(Ljava/lang/Throwable;)V",
543       pointer_size);
544   java_lang_Thread_init = CacheMethod(
545       j_l_Thread.Get(),
546       /*is_static=*/ false,
547       "<init>",
548       "(Ljava/lang/ThreadGroup;Ljava/lang/String;IZ)V",
549       pointer_size);
550   java_lang_Thread_run = CacheMethod(
551       j_l_Thread.Get(), /*is_static=*/ false, "run", "()V", pointer_size);
552   java_lang_ThreadGroup_add = CacheMethod(
553       j_l_tg.Get(), /*is_static=*/ false, "add", "(Ljava/lang/Thread;)V", pointer_size);
554   java_lang_ThreadGroup_threadTerminated = CacheMethod(
555       j_l_tg.Get(),
556       /*is_static=*/ false,
557       "threadTerminated",
558       "(Ljava/lang/Thread;)V",
559       pointer_size);
560 
561   java_lang_invoke_MethodHandle_asType = CacheMethod(
562       j_l_i_MethodHandle.Get(),
563       /*is_static=*/ false,
564       "asType",
565       "(Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/MethodHandle;",
566       pointer_size);
567   java_lang_invoke_MethodHandle_invokeExact = CacheMethod(
568       j_l_i_MethodHandle.Get(),
569       /*is_static=*/ false,
570       "invokeExact",
571       "([Ljava/lang/Object;)Ljava/lang/Object;",
572       pointer_size);
573   java_lang_invoke_MethodHandles_lookup = CacheMethod(
574       j_l_i_MethodHandles.Get(),
575       /*is_static=*/ true,
576       "lookup",
577       "()Ljava/lang/invoke/MethodHandles$Lookup;",
578       pointer_size);
579   java_lang_invoke_MethodHandles_Lookup_findConstructor = CacheMethod(
580       j_l_i_MethodHandles_Lookup.Get(),
581       /*is_static=*/ false,
582       "findConstructor",
583       "(Ljava/lang/Class;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/MethodHandle;",
584       pointer_size);
585 
586   java_lang_ref_FinalizerReference_add = CacheMethod(
587       j_l_r_fr.Get(), /*is_static=*/ true, "add", "(Ljava/lang/Object;)V", pointer_size);
588   java_lang_ref_ReferenceQueue_add = CacheMethod(
589       j_l_r_rq.Get(), /*is_static=*/ true, "add", "(Ljava/lang/ref/Reference;)V", pointer_size);
590 
591   java_lang_reflect_InvocationTargetException_init = CacheMethod(
592       j_l_rl_ite.Get(), /*is_static=*/ false, "<init>", "(Ljava/lang/Throwable;)V", pointer_size);
593   java_lang_reflect_Parameter_init = CacheMethod(
594       j_l_rl_Parameter.Get(),
595       /*is_static=*/ false,
596       "<init>",
597       "(Ljava/lang/String;ILjava/lang/reflect/Executable;I)V",
598       pointer_size);
599 
600   ObjPtr<mirror::Class> j_l_rl_Proxy = GetClassRoot<mirror::Proxy>(class_linker);
601   java_lang_reflect_Proxy_init = CacheMethod(
602       j_l_rl_Proxy,
603       /*is_static=*/ false,
604       "<init>",
605       "(Ljava/lang/reflect/InvocationHandler;)V",
606       pointer_size);
607   java_lang_reflect_Proxy_invoke = CacheMethod(
608       j_l_rl_Proxy,
609       /*is_static=*/ true,
610       "invoke",
611       "(Ljava/lang/reflect/Proxy;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;",
612       pointer_size);
613 
614   java_nio_Buffer_isDirect =
615       CacheMethod(j_n_b.Get(), /*is_static=*/ false, "isDirect", "()Z", pointer_size);
616   java_nio_DirectByteBuffer_init =
617       CacheMethod(j_n_dbb.Get(), /*is_static=*/ false, "<init>", "(JI)V", pointer_size);
618 
619   java_util_function_Consumer_accept = CacheMethod(
620       j_u_f_c.Get(), /*is_static=*/ false, "accept", "(Ljava/lang/Object;)V", pointer_size);
621 
622   jdk_internal_math_FloatingDecimal_getBinaryToASCIIConverter_D = CacheMethod(
623       j_i_m_fd.Get(),
624       /*is_static=*/ true,
625       "getBinaryToASCIIConverter",
626       "(D)Ljdk/internal/math/FloatingDecimal$BinaryToASCIIConverter;",
627       pointer_size);
628   jdk_internal_math_FloatingDecimal_getBinaryToASCIIConverter_F = CacheMethod(
629       j_i_m_fd.Get(),
630       /*is_static=*/ true,
631       "getBinaryToASCIIConverter",
632       "(F)Ljdk/internal/math/FloatingDecimal$BinaryToASCIIConverter;",
633       pointer_size);
634   jdk_internal_math_FloatingDecimal_BinaryToASCIIBuffer_getChars =
635       CacheMethod(j_i_m_fd_btab.Get(), /*is_static=*/ false, "getChars", "([C)I", pointer_size);
636 
637   libcore_reflect_AnnotationFactory_createAnnotation = CacheMethod(
638       l_r_af.Get(),
639       /*is_static=*/ true,
640       "createAnnotation",
641       "(Ljava/lang/Class;[Llibcore/reflect/AnnotationMember;)Ljava/lang/annotation/Annotation;",
642       pointer_size);
643   libcore_reflect_AnnotationMember_init = CacheMethod(
644       l_r_am.Get(),
645       /*is_static=*/ false,
646       "<init>",
647       "(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/reflect/Method;)V",
648       pointer_size);
649 
650   org_apache_harmony_dalvik_ddmc_DdmServer_broadcast =
651       CacheMethod(o_a_h_d_d_ds.Get(), /*is_static=*/ true, "broadcast", "(I)V", pointer_size);
652   org_apache_harmony_dalvik_ddmc_DdmServer_dispatch = CacheMethod(
653       o_a_h_d_d_ds.Get(),
654       /*is_static=*/ true,
655       "dispatch",
656       "(I[BII)Lorg/apache/harmony/dalvik/ddmc/Chunk;",
657       pointer_size);
658 
659   dalvik_system_BaseDexClassLoader_pathList = CacheField(
660       d_s_bdcl.Get(), /*is_static=*/ false, "pathList", "Ldalvik/system/DexPathList;");
661   dalvik_system_BaseDexClassLoader_sharedLibraryLoaders = CacheField(
662       d_s_bdcl.Get(), /*is_static=*/ false, "sharedLibraryLoaders", "[Ljava/lang/ClassLoader;");
663   dalvik_system_BaseDexClassLoader_sharedLibraryLoadersAfter = CacheField(
664       d_s_bdcl.Get(),
665       /*is_static=*/ false,
666       "sharedLibraryLoadersAfter",
667       "[Ljava/lang/ClassLoader;");
668   dalvik_system_DexFile_cookie = CacheField(
669       d_s_df.Get(), /*is_static=*/ false, "mCookie", "Ljava/lang/Object;");
670   dalvik_system_DexFile_fileName = CacheField(
671       d_s_df.Get(), /*is_static=*/ false, "mFileName", "Ljava/lang/String;");
672   dalvik_system_DexPathList_dexElements = CacheField(
673       d_s_dpl.Get(), /*is_static=*/ false, "dexElements", "[Ldalvik/system/DexPathList$Element;");
674   dalvik_system_DexPathList__Element_dexFile = CacheField(
675       d_s_dpl_e.Get(), /*is_static=*/ false, "dexFile", "Ldalvik/system/DexFile;");
676 
677   dalvik_system_VMRuntime_nonSdkApiUsageConsumer = CacheField(
678       d_s_vmr.Get(),
679       /*is_static=*/ true,
680       "nonSdkApiUsageConsumer",
681       "Ljava/util/function/Consumer;");
682 
683   java_io_FileDescriptor_descriptor = CacheField(
684       j_i_fd.Get(), /*is_static=*/ false, "descriptor", "I");
685 
686   java_lang_ClassLoader_parent = CacheField(
687       j_l_cl.Get(), /*is_static=*/ false, "parent", "Ljava/lang/ClassLoader;");
688 
689   java_lang_Thread_parkBlocker =
690       CacheField(j_l_Thread.Get(), /*is_static=*/ false, "parkBlocker", "Ljava/lang/Object;");
691   java_lang_Thread_daemon = CacheField(j_l_Thread.Get(), /*is_static=*/ false, "daemon", "Z");
692   java_lang_Thread_group =
693       CacheField(j_l_Thread.Get(), /*is_static=*/ false, "group", "Ljava/lang/ThreadGroup;");
694   java_lang_Thread_lock =
695       CacheField(j_l_Thread.Get(), /*is_static=*/ false, "lock", "Ljava/lang/Object;");
696   java_lang_Thread_name =
697       CacheField(j_l_Thread.Get(), /*is_static=*/ false, "name", "Ljava/lang/String;");
698   java_lang_Thread_priority = CacheField(j_l_Thread.Get(), /*is_static=*/ false, "priority", "I");
699   java_lang_Thread_nativePeer =
700       CacheField(j_l_Thread.Get(), /*is_static=*/ false, "nativePeer", "J");
701   java_lang_Thread_systemDaemon =
702       CacheField(j_l_Thread.Get(), /*is_static=*/ false, "systemDaemon", "Z");
703   java_lang_Thread_unparkedBeforeStart =
704       CacheField(j_l_Thread.Get(), /*is_static=*/ false, "unparkedBeforeStart", "Z");
705 
706   java_lang_ThreadGroup_groups =
707       CacheField(j_l_tg.Get(), /*is_static=*/ false, "groups", "[Ljava/lang/ThreadGroup;");
708   java_lang_ThreadGroup_ngroups = CacheField(j_l_tg.Get(), /*is_static=*/ false, "ngroups", "I");
709   java_lang_ThreadGroup_mainThreadGroup =
710       CacheField(j_l_tg.Get(), /*is_static=*/ true, "mainThreadGroup", "Ljava/lang/ThreadGroup;");
711   java_lang_ThreadGroup_name =
712       CacheField(j_l_tg.Get(), /*is_static=*/ false, "name", "Ljava/lang/String;");
713   java_lang_ThreadGroup_parent =
714       CacheField(j_l_tg.Get(), /*is_static=*/ false, "parent", "Ljava/lang/ThreadGroup;");
715   java_lang_ThreadGroup_systemThreadGroup =
716       CacheField(j_l_tg.Get(), /*is_static=*/ true, "systemThreadGroup", "Ljava/lang/ThreadGroup;");
717 
718   ObjPtr<mirror::Class> j_l_Throwable = GetClassRoot<mirror::Throwable>(class_linker);
719   java_lang_Throwable_cause = CacheField(
720       j_l_Throwable, /*is_static=*/ false, "cause", "Ljava/lang/Throwable;");
721   java_lang_Throwable_detailMessage = CacheField(
722       j_l_Throwable, /*is_static=*/ false, "detailMessage", "Ljava/lang/String;");
723   java_lang_Throwable_stackTrace = CacheField(
724       j_l_Throwable, /*is_static=*/ false, "stackTrace", "[Ljava/lang/StackTraceElement;");
725   java_lang_Throwable_stackState = CacheField(
726       j_l_Throwable, /*is_static=*/ false, "backtrace", "Ljava/lang/Object;");
727   java_lang_Throwable_suppressedExceptions = CacheField(
728       j_l_Throwable, /*is_static=*/ false, "suppressedExceptions", "Ljava/util/List;");
729 
730   java_nio_Buffer_address = CacheField(j_n_b.Get(), /*is_static=*/ false, "address", "J");
731   java_nio_Buffer_capacity = CacheField(j_n_b.Get(), /*is_static=*/ false, "capacity", "I");
732   java_nio_Buffer_elementSizeShift =
733       CacheField(j_n_b.Get(), /*is_static=*/ false, "_elementSizeShift", "I");
734   java_nio_Buffer_limit = CacheField(j_n_b.Get(), /*is_static=*/ false, "limit", "I");
735   java_nio_Buffer_position = CacheField(j_n_b.Get(), /*is_static=*/ false, "position", "I");
736 
737   java_nio_ByteBuffer_hb = CacheField(j_n_bb.Get(), /*is_static=*/ false, "hb", "[B");
738   java_nio_ByteBuffer_isReadOnly =
739       CacheField(j_n_bb.Get(), /*is_static=*/ false, "isReadOnly", "Z");
740   java_nio_ByteBuffer_offset = CacheField(j_n_bb.Get(), /*is_static=*/ false, "offset", "I");
741 
742   java_util_Collections_EMPTY_LIST =
743       CacheField(j_u_c.Get(), /*is_static=*/ true, "EMPTY_LIST", "Ljava/util/List;");
744 
745   jdk_internal_math_FloatingDecimal_BinaryToASCIIBuffer_buffer =
746       CacheField(j_i_m_fd_btab.Get(), /*is_static=*/ false, "buffer", "[C");
747   jdk_internal_math_FloatingDecimal_ExceptionalBinaryToASCIIBuffer_image = CacheField(
748       j_i_m_fd_ebtab.Get(), /*is_static=*/ false, "image", "Ljava/lang/String;");
749 
750   libcore_util_EmptyArray_STACK_TRACE_ELEMENT = CacheField(
751       l_u_ea.Get(), /*is_static=*/ true, "STACK_TRACE_ELEMENT", "[Ljava/lang/StackTraceElement;");
752 
753   org_apache_harmony_dalvik_ddmc_Chunk_data =
754       CacheField(o_a_h_d_c.Get(), /*is_static=*/ false, "data", "[B");
755   org_apache_harmony_dalvik_ddmc_Chunk_length =
756       CacheField(o_a_h_d_c.Get(), /*is_static=*/ false, "length", "I");
757   org_apache_harmony_dalvik_ddmc_Chunk_offset =
758       CacheField(o_a_h_d_c.Get(), /*is_static=*/ false, "offset", "I");
759   org_apache_harmony_dalvik_ddmc_Chunk_type =
760       CacheField(o_a_h_d_c.Get(), /*is_static=*/ false, "type", "I");
761 }
762 
LateInit(JNIEnv * env)763 void WellKnownClasses::LateInit(JNIEnv* env) {
764   // Initialize the `Runtime` class that was previously initialized
765   // by `CacheMethod()` calling `FindMethodJNI()`.
766   // TODO: Move this initialization to `ClassLinker`.
767   ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
768   Thread* self = Thread::ForEnv(env);
769   ScopedObjectAccess soa(self);
770   StackHandleScope<1u> hs(self);
771   Handle<mirror::Class> j_l_Runtime =
772       hs.NewHandle(FindSystemClass(class_linker, self, "Ljava/lang/Runtime;"));
773   bool success = class_linker->EnsureInitialized(
774       self, j_l_Runtime, /*can_init_fields=*/ true, /*can_init_parents=*/ true);
775   CHECK(success) << "Failed to initialize " << j_l_Runtime->PrettyDescriptor();
776 
777   // The function `GetClassLoader()` in `jni_internal.cc` is checking if the caller
778   // is `java_lang_Runtime_nativeLoad` and, if so, returns the class loader override.
779   // However, this function is used several times between `WellKnownClasses::Init()`
780   // and setting up the override by the `Runtime` and requires that we take the other
781   // path, rather than returning the uninitialized override. Therefore we cannot
782   // initialize this well-known method early and require the `LateInit()`.
783   // TODO: Clean up the initialization steps.
784   java_lang_Runtime_nativeLoad = CacheMethod(
785       j_l_Runtime.Get(),
786       /*is_static=*/ true,
787       "nativeLoad",
788       "(Ljava/lang/String;Ljava/lang/ClassLoader;Ljava/lang/Class;)Ljava/lang/String;",
789       class_linker->GetImagePointerSize());
790 }
791 
HandleJniIdTypeChange(JNIEnv * env)792 void WellKnownClasses::HandleJniIdTypeChange(JNIEnv* env) {
793   WellKnownClasses::InitFieldsAndMethodsOnly(env);
794   WellKnownClasses::LateInit(env);
795 }
796 
Clear()797 void WellKnownClasses::Clear() {
798   dalvik_annotation_optimization_CriticalNative = nullptr;
799   dalvik_annotation_optimization_FastNative = nullptr;
800   dalvik_annotation_optimization_NeverCompile = nullptr;
801   dalvik_annotation_optimization_NeverInline = nullptr;
802   java_lang_annotation_Annotation__array = nullptr;
803   java_lang_ClassValue = nullptr;
804   java_lang_Record = nullptr;
805   java_lang_reflect_Parameter__array = nullptr;
806   java_lang_StringFactory = nullptr;
807   java_lang_System = nullptr;
808   java_lang_Void = nullptr;
809   libcore_reflect_AnnotationMember__array = nullptr;
810 
811   dalvik_system_BaseDexClassLoader_getLdLibraryPath = nullptr;
812   WellKnownClasses::dalvik_system_DelegateLastClassLoader_init = nullptr;
813   WellKnownClasses::dalvik_system_DexClassLoader_init = nullptr;
814   WellKnownClasses::dalvik_system_InMemoryDexClassLoader_init = nullptr;
815   WellKnownClasses::dalvik_system_PathClassLoader_init = nullptr;
816   dalvik_system_VMRuntime_hiddenApiUsed = nullptr;
817   java_io_FileDescriptor_descriptor = nullptr;
818   java_lang_Boolean_valueOf = nullptr;
819   java_lang_Byte_valueOf = nullptr;
820   java_lang_Character_valueOf = nullptr;
821   java_lang_BootClassLoader_init = nullptr;
822   java_lang_ClassLoader_loadClass = nullptr;
823   java_lang_ClassNotFoundException_init = nullptr;
824   java_lang_Daemons_start = nullptr;
825   java_lang_Daemons_stop = nullptr;
826   java_lang_Daemons_waitForDaemonStart = nullptr;
827   java_lang_Double_doubleToRawLongBits = nullptr;
828   java_lang_Double_valueOf = nullptr;
829   java_lang_Error_init = nullptr;
830   java_lang_Float_floatToRawIntBits = nullptr;
831   java_lang_Float_valueOf = nullptr;
832   java_lang_IllegalAccessError_init = nullptr;
833   java_lang_Integer_valueOf = nullptr;
834   java_lang_Long_valueOf = nullptr;
835   java_lang_NoClassDefFoundError_init = nullptr;
836   java_lang_OutOfMemoryError_init = nullptr;
837   java_lang_Runtime_nativeLoad = nullptr;
838   java_lang_RuntimeException_init = nullptr;
839   java_lang_Short_valueOf = nullptr;
840   java_lang_StackOverflowError_init = nullptr;
841   java_lang_String_charAt = nullptr;
842   java_lang_Thread_dispatchUncaughtException = nullptr;
843   java_lang_Thread_init = nullptr;
844   java_lang_Thread_run = nullptr;
845   java_lang_ThreadGroup_add = nullptr;
846   java_lang_ThreadGroup_threadTerminated = nullptr;
847   java_lang_invoke_MethodHandle_asType = nullptr;
848   java_lang_invoke_MethodHandle_invokeExact = nullptr;
849   java_lang_invoke_MethodHandles_lookup = nullptr;
850   java_lang_invoke_MethodHandles_Lookup_findConstructor = nullptr;
851   java_lang_ref_FinalizerReference_add = nullptr;
852   java_lang_ref_ReferenceQueue_add = nullptr;
853   java_lang_reflect_InvocationTargetException_init = nullptr;
854   java_lang_reflect_Parameter_init = nullptr;
855   java_lang_reflect_Proxy_init = nullptr;
856   java_lang_reflect_Proxy_invoke = nullptr;
857   java_nio_Buffer_isDirect = nullptr;
858   java_nio_DirectByteBuffer_init = nullptr;
859   jdk_internal_math_FloatingDecimal_getBinaryToASCIIConverter_D = nullptr;
860   jdk_internal_math_FloatingDecimal_getBinaryToASCIIConverter_F = nullptr;
861   jdk_internal_math_FloatingDecimal_BinaryToASCIIBuffer_getChars = nullptr;
862   libcore_reflect_AnnotationFactory_createAnnotation = nullptr;
863   libcore_reflect_AnnotationMember_init = nullptr;
864   org_apache_harmony_dalvik_ddmc_DdmServer_broadcast = nullptr;
865   org_apache_harmony_dalvik_ddmc_DdmServer_dispatch = nullptr;
866 
867   dalvik_system_BaseDexClassLoader_pathList = nullptr;
868   dalvik_system_DexFile_cookie = nullptr;
869   dalvik_system_DexFile_fileName = nullptr;
870   dalvik_system_DexPathList_dexElements = nullptr;
871   dalvik_system_DexPathList__Element_dexFile = nullptr;
872   dalvik_system_VMRuntime_nonSdkApiUsageConsumer = nullptr;
873   java_lang_ClassLoader_parent = nullptr;
874   java_lang_Thread_parkBlocker = nullptr;
875   java_lang_Thread_daemon = nullptr;
876   java_lang_Thread_group = nullptr;
877   java_lang_Thread_lock = nullptr;
878   java_lang_Thread_name = nullptr;
879   java_lang_Thread_priority = nullptr;
880   java_lang_Thread_nativePeer = nullptr;
881   java_lang_ThreadGroup_groups = nullptr;
882   java_lang_ThreadGroup_ngroups = nullptr;
883   java_lang_ThreadGroup_mainThreadGroup = nullptr;
884   java_lang_ThreadGroup_name = nullptr;
885   java_lang_ThreadGroup_parent = nullptr;
886   java_lang_ThreadGroup_systemThreadGroup = nullptr;
887   java_lang_Throwable_cause = nullptr;
888   java_lang_Throwable_detailMessage = nullptr;
889   java_lang_Throwable_stackTrace = nullptr;
890   java_lang_Throwable_stackState = nullptr;
891   java_lang_Throwable_suppressedExceptions = nullptr;
892   java_nio_Buffer_address = nullptr;
893   java_nio_Buffer_elementSizeShift = nullptr;
894   java_nio_Buffer_limit = nullptr;
895   java_nio_Buffer_position = nullptr;
896   java_nio_ByteBuffer_hb = nullptr;
897   java_nio_ByteBuffer_isReadOnly = nullptr;
898   java_nio_ByteBuffer_offset = nullptr;
899   java_util_Collections_EMPTY_LIST = nullptr;
900   jdk_internal_math_FloatingDecimal_BinaryToASCIIBuffer_buffer = nullptr;
901   jdk_internal_math_FloatingDecimal_ExceptionalBinaryToASCIIBuffer_image = nullptr;
902   libcore_util_EmptyArray_STACK_TRACE_ELEMENT = nullptr;
903   org_apache_harmony_dalvik_ddmc_Chunk_data = nullptr;
904   org_apache_harmony_dalvik_ddmc_Chunk_length = nullptr;
905   org_apache_harmony_dalvik_ddmc_Chunk_offset = nullptr;
906   org_apache_harmony_dalvik_ddmc_Chunk_type = nullptr;
907 }
908 
ToClass(jclass global_jclass)909 ObjPtr<mirror::Class> WellKnownClasses::ToClass(jclass global_jclass) {
910   JavaVMExt* vm = Runtime::Current()->GetJavaVM();
911   auto ret = ObjPtr<mirror::Class>::DownCast(vm->DecodeGlobal(global_jclass));
912   DCHECK(!ret.IsNull());
913   return ret;
914 }
915 
916 }  // namespace art
917