blob: 4843061be642d855522a888f35dc2cc93b8baaa8 [file] [log] [blame]
Elliott Hugheseac76672012-05-24 21:56:51 -07001/*
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
Ian Rogersc7dd2952014-10-21 23:31:19 -070021#include <sstream>
22
Andreas Gampe57943812017-12-06 21:39:13 -080023#include <android-base/logging.h>
24#include <android-base/stringprintf.h>
Andreas Gampe46ee31b2016-12-14 10:11:49 -080025
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +010026#include "entrypoints/quick/quick_entrypoints_enum.h"
Mathew Inwood597d7f62018-03-22 11:36:47 +000027#include "hidden_api.h"
Vladimir Markoa3ad0cd2018-05-04 10:06:38 +010028#include "jni/jni_internal.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080029#include "mirror/class.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070030#include "mirror/throwable.h"
Andreas Gampe373a9b52017-10-18 09:01:57 -070031#include "nativehelper/scoped_local_ref.h"
Mathieu Chartierc4f39252016-10-05 18:32:08 -070032#include "obj_ptr-inl.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070033#include "scoped_thread_state_change-inl.h"
Andreas Gampeb486a982017-06-01 13:45:54 -070034#include "thread-current-inl.h"
Elliott Hugheseac76672012-05-24 21:56:51 -070035
36namespace art {
37
Igor Murashkin367f3dd2016-09-01 17:00:24 -070038jclass WellKnownClasses::dalvik_annotation_optimization_CriticalNative;
Igor Murashkin9d4b6da2016-07-29 09:51:58 -070039jclass WellKnownClasses::dalvik_annotation_optimization_FastNative;
Andreas Gampe46aba362016-10-28 14:33:28 -070040jclass WellKnownClasses::dalvik_system_BaseDexClassLoader;
Calin Juravle7865ac72017-06-28 11:03:12 -070041jclass WellKnownClasses::dalvik_system_DelegateLastClassLoader;
Nicolas Geoffray7d8d8ff2016-11-02 12:38:05 +000042jclass WellKnownClasses::dalvik_system_DexClassLoader;
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -070043jclass WellKnownClasses::dalvik_system_DexFile;
44jclass WellKnownClasses::dalvik_system_DexPathList;
Andreas Gampec8ccf682014-09-29 20:07:43 -070045jclass WellKnownClasses::dalvik_system_DexPathList__Element;
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +010046jclass WellKnownClasses::dalvik_system_EmulatedStackFrame;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070047jclass WellKnownClasses::dalvik_system_PathClassLoader;
Mathieu Chartierb5de3bb2015-06-05 13:21:05 -070048jclass WellKnownClasses::dalvik_system_VMRuntime;
Jeff Hao13e748b2015-08-25 20:44:19 +000049jclass WellKnownClasses::java_lang_annotation_Annotation__array;
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -070050jclass WellKnownClasses::java_lang_BootClassLoader;
Elliott Hugheseac76672012-05-24 21:56:51 -070051jclass WellKnownClasses::java_lang_ClassLoader;
52jclass WellKnownClasses::java_lang_ClassNotFoundException;
53jclass WellKnownClasses::java_lang_Daemons;
54jclass WellKnownClasses::java_lang_Error;
Orion Hodson811bd5f2016-12-07 11:35:37 +000055jclass WellKnownClasses::java_lang_invoke_MethodHandle;
Orion Hodsoneb4d19b2017-11-06 15:49:23 +000056jclass WellKnownClasses::java_lang_invoke_VarHandle;
Jeff Haoc92a7a12016-06-06 11:09:20 -070057jclass WellKnownClasses::java_lang_IllegalAccessError;
58jclass WellKnownClasses::java_lang_NoClassDefFoundError;
Ian Rogersaf6e67a2013-01-16 08:38:37 -080059jclass WellKnownClasses::java_lang_Object;
Mathieu Chartiera61894d2015-04-23 16:32:54 -070060jclass WellKnownClasses::java_lang_OutOfMemoryError;
Neil Fuller79a21e72016-09-09 14:24:51 +010061jclass WellKnownClasses::java_lang_reflect_Parameter;
62jclass WellKnownClasses::java_lang_reflect_Parameter__array;
Elliott Hugheseac76672012-05-24 21:56:51 -070063jclass WellKnownClasses::java_lang_reflect_Proxy;
Elliott Hughesa4f94742012-05-29 16:28:38 -070064jclass WellKnownClasses::java_lang_RuntimeException;
Ian Rogers120f1c72012-09-28 17:17:10 -070065jclass WellKnownClasses::java_lang_StackOverflowError;
Ian Rogersdd157d72014-05-15 14:47:50 -070066jclass WellKnownClasses::java_lang_String;
Jeff Hao848f70a2014-01-15 13:49:50 -080067jclass WellKnownClasses::java_lang_StringFactory;
Mathieu Chartier987ccff2013-07-08 11:05:21 -070068jclass WellKnownClasses::java_lang_System;
Elliott Hugheseac76672012-05-24 21:56:51 -070069jclass WellKnownClasses::java_lang_Thread;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -070070jclass WellKnownClasses::java_lang_ThreadGroup;
Elliott Hughesa4f94742012-05-29 16:28:38 -070071jclass WellKnownClasses::java_lang_Throwable;
Orion Hodson928033d2018-02-07 05:30:54 +000072jclass WellKnownClasses::java_nio_ByteBuffer;
Elliott Hughesaecb5f32013-03-28 08:27:38 -070073jclass WellKnownClasses::java_nio_DirectByteBuffer;
Sebastien Hertze49e1952014-10-13 11:27:13 +020074jclass WellKnownClasses::java_util_ArrayList;
Andreas Gampe7ea6f792014-07-14 16:21:44 -070075jclass WellKnownClasses::java_util_Collections;
Narayan Kamathf5f1f802018-04-03 15:23:46 +010076jclass WellKnownClasses::java_util_function_Consumer;
Jeff Hao13e748b2015-08-25 20:44:19 +000077jclass WellKnownClasses::libcore_reflect_AnnotationFactory;
78jclass WellKnownClasses::libcore_reflect_AnnotationMember;
Andreas Gampe7ea6f792014-07-14 16:21:44 -070079jclass WellKnownClasses::libcore_util_EmptyArray;
Elliott Hugheseac76672012-05-24 21:56:51 -070080jclass WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk;
81jclass WellKnownClasses::org_apache_harmony_dalvik_ddmc_DdmServer;
82
Andreas Gampe473191c2017-12-28 16:55:31 -080083jmethodID WellKnownClasses::dalvik_system_BaseDexClassLoader_getLdLibraryPath;
Mathieu Chartierb5de3bb2015-06-05 13:21:05 -070084jmethodID WellKnownClasses::dalvik_system_VMRuntime_runFinalization;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070085jmethodID WellKnownClasses::java_lang_Boolean_valueOf;
86jmethodID WellKnownClasses::java_lang_Byte_valueOf;
87jmethodID WellKnownClasses::java_lang_Character_valueOf;
Elliott Hughesa4f94742012-05-29 16:28:38 -070088jmethodID WellKnownClasses::java_lang_ClassLoader_loadClass;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070089jmethodID WellKnownClasses::java_lang_ClassNotFoundException_init;
Elliott Hugheseac76672012-05-24 21:56:51 -070090jmethodID WellKnownClasses::java_lang_Daemons_requestHeapTrim;
91jmethodID WellKnownClasses::java_lang_Daemons_start;
Mathieu Chartiercef50f02014-12-09 17:38:52 -080092jmethodID WellKnownClasses::java_lang_Daemons_stop;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070093jmethodID WellKnownClasses::java_lang_Double_valueOf;
94jmethodID WellKnownClasses::java_lang_Float_valueOf;
95jmethodID WellKnownClasses::java_lang_Integer_valueOf;
Orion Hodson811bd5f2016-12-07 11:35:37 +000096jmethodID WellKnownClasses::java_lang_invoke_MethodHandle_invoke;
97jmethodID WellKnownClasses::java_lang_invoke_MethodHandle_invokeExact;
Orion Hodsonf8db2c32017-07-07 20:07:12 +010098jmethodID WellKnownClasses::java_lang_invoke_MethodHandles_lookup;
99jmethodID WellKnownClasses::java_lang_invoke_MethodHandles_Lookup_findConstructor;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700100jmethodID WellKnownClasses::java_lang_Long_valueOf;
Elliott Hughesa4f94742012-05-29 16:28:38 -0700101jmethodID WellKnownClasses::java_lang_ref_FinalizerReference_add;
102jmethodID WellKnownClasses::java_lang_ref_ReferenceQueue_add;
Neil Fuller79a21e72016-09-09 14:24:51 +0100103jmethodID WellKnownClasses::java_lang_reflect_Parameter_init;
Brian Carlstromea46f952013-07-30 01:26:50 -0700104jmethodID WellKnownClasses::java_lang_reflect_Proxy_invoke;
Ian Rogersef28b142012-11-30 14:22:18 -0800105jmethodID WellKnownClasses::java_lang_Runtime_nativeLoad;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700106jmethodID WellKnownClasses::java_lang_Short_valueOf;
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000107jmethodID WellKnownClasses::java_lang_String_charAt;
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700108jmethodID WellKnownClasses::java_lang_System_runFinalization = nullptr;
Tobias Thierer5cbe65d2016-07-22 18:37:59 +0100109jmethodID WellKnownClasses::java_lang_Thread_dispatchUncaughtException;
Elliott Hugheseac76672012-05-24 21:56:51 -0700110jmethodID WellKnownClasses::java_lang_Thread_init;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700111jmethodID WellKnownClasses::java_lang_Thread_run;
Andreas Gampe56776012018-01-26 17:40:55 -0800112jmethodID WellKnownClasses::java_lang_ThreadGroup_add;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700113jmethodID WellKnownClasses::java_lang_ThreadGroup_removeThread;
Elliott Hughesaecb5f32013-03-28 08:27:38 -0700114jmethodID WellKnownClasses::java_nio_DirectByteBuffer_init;
Narayan Kamathf5f1f802018-04-03 15:23:46 +0100115jmethodID WellKnownClasses::java_util_function_Consumer_accept;
Jeff Hao13e748b2015-08-25 20:44:19 +0000116jmethodID WellKnownClasses::libcore_reflect_AnnotationFactory_createAnnotation;
117jmethodID WellKnownClasses::libcore_reflect_AnnotationMember_init;
Elliott Hugheseac76672012-05-24 21:56:51 -0700118jmethodID WellKnownClasses::org_apache_harmony_dalvik_ddmc_DdmServer_broadcast;
119jmethodID WellKnownClasses::org_apache_harmony_dalvik_ddmc_DdmServer_dispatch;
120
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -0700121jfieldID WellKnownClasses::dalvik_system_DexFile_cookie;
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800122jfieldID WellKnownClasses::dalvik_system_DexFile_fileName;
Andreas Gampe46aba362016-10-28 14:33:28 -0700123jfieldID WellKnownClasses::dalvik_system_BaseDexClassLoader_pathList;
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -0700124jfieldID WellKnownClasses::dalvik_system_DexPathList_dexElements;
Andreas Gampec8ccf682014-09-29 20:07:43 -0700125jfieldID WellKnownClasses::dalvik_system_DexPathList__Element_dexFile;
Narayan Kamathf5f1f802018-04-03 15:23:46 +0100126jfieldID WellKnownClasses::dalvik_system_VMRuntime_nonSdkApiUsageConsumer;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700127jfieldID WellKnownClasses::java_lang_Thread_daemon;
128jfieldID WellKnownClasses::java_lang_Thread_group;
129jfieldID WellKnownClasses::java_lang_Thread_lock;
130jfieldID WellKnownClasses::java_lang_Thread_name;
131jfieldID WellKnownClasses::java_lang_Thread_priority;
Anwar Ghuloum3c50a4b2013-06-21 13:05:23 -0700132jfieldID WellKnownClasses::java_lang_Thread_nativePeer;
Sebastien Hertze49e1952014-10-13 11:27:13 +0200133jfieldID WellKnownClasses::java_lang_ThreadGroup_groups;
Przemyslaw Szczepaniak464595f2015-11-24 11:59:59 +0000134jfieldID WellKnownClasses::java_lang_ThreadGroup_ngroups;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700135jfieldID WellKnownClasses::java_lang_ThreadGroup_mainThreadGroup;
136jfieldID WellKnownClasses::java_lang_ThreadGroup_name;
Sebastien Hertze49e1952014-10-13 11:27:13 +0200137jfieldID WellKnownClasses::java_lang_ThreadGroup_parent;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700138jfieldID WellKnownClasses::java_lang_ThreadGroup_systemThreadGroup;
Brian Carlstrom34375312014-09-10 23:10:47 -0700139jfieldID WellKnownClasses::java_lang_Throwable_cause;
140jfieldID WellKnownClasses::java_lang_Throwable_detailMessage;
141jfieldID WellKnownClasses::java_lang_Throwable_stackTrace;
142jfieldID WellKnownClasses::java_lang_Throwable_stackState;
143jfieldID WellKnownClasses::java_lang_Throwable_suppressedExceptions;
Elliott Hugheseac76672012-05-24 21:56:51 -0700144jfieldID WellKnownClasses::java_lang_reflect_Proxy_h;
Orion Hodson928033d2018-02-07 05:30:54 +0000145jfieldID WellKnownClasses::java_nio_ByteBuffer_address;
146jfieldID WellKnownClasses::java_nio_ByteBuffer_hb;
147jfieldID WellKnownClasses::java_nio_ByteBuffer_isReadOnly;
148jfieldID WellKnownClasses::java_nio_ByteBuffer_limit;
149jfieldID WellKnownClasses::java_nio_ByteBuffer_offset;
Elliott Hughesaecb5f32013-03-28 08:27:38 -0700150jfieldID WellKnownClasses::java_nio_DirectByteBuffer_capacity;
151jfieldID WellKnownClasses::java_nio_DirectByteBuffer_effectiveDirectAddress;
Sebastien Hertze49e1952014-10-13 11:27:13 +0200152jfieldID WellKnownClasses::java_util_ArrayList_array;
153jfieldID WellKnownClasses::java_util_ArrayList_size;
Brian Carlstrom34375312014-09-10 23:10:47 -0700154jfieldID WellKnownClasses::java_util_Collections_EMPTY_LIST;
155jfieldID WellKnownClasses::libcore_util_EmptyArray_STACK_TRACE_ELEMENT;
Elliott Hugheseac76672012-05-24 21:56:51 -0700156jfieldID WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_data;
157jfieldID WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_length;
158jfieldID WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_offset;
159jfieldID WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_type;
160
161static jclass CacheClass(JNIEnv* env, const char* jni_class_name) {
162 ScopedLocalRef<jclass> c(env, env->FindClass(jni_class_name));
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700163 if (c.get() == nullptr) {
Elliott Hugheseac76672012-05-24 21:56:51 -0700164 LOG(FATAL) << "Couldn't find class: " << jni_class_name;
165 }
166 return reinterpret_cast<jclass>(env->NewGlobalRef(c.get()));
167}
168
Brian Carlstrom3c821c62014-09-10 10:08:37 -0700169static jfieldID CacheField(JNIEnv* env, jclass c, bool is_static,
170 const char* name, const char* signature) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700171 jfieldID fid = is_static ? env->GetStaticFieldID(c, name, signature) :
172 env->GetFieldID(c, name, signature);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700173 if (fid == nullptr) {
Brian Carlstrom3c821c62014-09-10 10:08:37 -0700174 ScopedObjectAccess soa(env);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700175 if (soa.Self()->IsExceptionPending()) {
Andreas Gampe3fec9ac2016-09-13 10:47:28 -0700176 LOG(FATAL_WITHOUT_ABORT) << soa.Self()->GetException()->Dump();
Mathieu Chartiere401d142015-04-22 13:56:20 -0700177 }
Brian Carlstrom3c821c62014-09-10 10:08:37 -0700178 std::ostringstream os;
179 WellKnownClasses::ToClass(c)->DumpClass(os, mirror::Class::kDumpClassFullDetail);
180 LOG(FATAL) << "Couldn't find field \"" << name << "\" with signature \"" << signature << "\": "
181 << os.str();
Elliott Hugheseac76672012-05-24 21:56:51 -0700182 }
183 return fid;
184}
185
Orion Hodsonf8db2c32017-07-07 20:07:12 +0100186static jmethodID CacheMethod(JNIEnv* env, jclass c, bool is_static,
187 const char* name, const char* signature) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700188 jmethodID mid = is_static ? env->GetStaticMethodID(c, name, signature) :
189 env->GetMethodID(c, name, signature);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700190 if (mid == nullptr) {
Brian Carlstrom3c821c62014-09-10 10:08:37 -0700191 ScopedObjectAccess soa(env);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700192 if (soa.Self()->IsExceptionPending()) {
Andreas Gampe3fec9ac2016-09-13 10:47:28 -0700193 LOG(FATAL_WITHOUT_ABORT) << soa.Self()->GetException()->Dump();
Mathieu Chartiere401d142015-04-22 13:56:20 -0700194 }
Brian Carlstrom3c821c62014-09-10 10:08:37 -0700195 std::ostringstream os;
196 WellKnownClasses::ToClass(c)->DumpClass(os, mirror::Class::kDumpClassFullDetail);
197 LOG(FATAL) << "Couldn't find method \"" << name << "\" with signature \"" << signature << "\": "
198 << os.str();
Elliott Hugheseac76672012-05-24 21:56:51 -0700199 }
200 return mid;
201}
202
Orion Hodsonf8db2c32017-07-07 20:07:12 +0100203static jmethodID CacheMethod(JNIEnv* env, const char* klass, bool is_static,
204 const char* name, const char* signature) {
205 ScopedLocalRef<jclass> java_class(env, env->FindClass(klass));
206 return CacheMethod(env, java_class.get(), is_static, name, signature);
207}
208
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700209static jmethodID CachePrimitiveBoxingMethod(JNIEnv* env, char prim_name, const char* boxed_name) {
210 ScopedLocalRef<jclass> boxed_class(env, env->FindClass(boxed_name));
211 return CacheMethod(env, boxed_class.get(), true, "valueOf",
Andreas Gampe46ee31b2016-12-14 10:11:49 -0800212 android::base::StringPrintf("(%c)L%s;", prim_name, boxed_name).c_str());
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700213}
214
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +0100215#define STRING_INIT_LIST(V) \
216 V(java_lang_String_init, "()V", newEmptyString, "newEmptyString", "()Ljava/lang/String;", NewEmptyString) \
217 V(java_lang_String_init_B, "([B)V", newStringFromBytes_B, "newStringFromBytes", "([B)Ljava/lang/String;", NewStringFromBytes_B) \
218 V(java_lang_String_init_BI, "([BI)V", newStringFromBytes_BI, "newStringFromBytes", "([BI)Ljava/lang/String;", NewStringFromBytes_BI) \
219 V(java_lang_String_init_BII, "([BII)V", newStringFromBytes_BII, "newStringFromBytes", "([BII)Ljava/lang/String;", NewStringFromBytes_BII) \
220 V(java_lang_String_init_BIII, "([BIII)V", newStringFromBytes_BIII, "newStringFromBytes", "([BIII)Ljava/lang/String;", NewStringFromBytes_BIII) \
221 V(java_lang_String_init_BIIString, "([BIILjava/lang/String;)V", newStringFromBytes_BIIString, "newStringFromBytes", "([BIILjava/lang/String;)Ljava/lang/String;", NewStringFromBytes_BIIString) \
222 V(java_lang_String_init_BString, "([BLjava/lang/String;)V", newStringFromBytes_BString, "newStringFromBytes", "([BLjava/lang/String;)Ljava/lang/String;", NewStringFromBytes_BString) \
223 V(java_lang_String_init_BIICharset, "([BIILjava/nio/charset/Charset;)V", newStringFromBytes_BIICharset, "newStringFromBytes", "([BIILjava/nio/charset/Charset;)Ljava/lang/String;", NewStringFromBytes_BIICharset) \
224 V(java_lang_String_init_BCharset, "([BLjava/nio/charset/Charset;)V", newStringFromBytes_BCharset, "newStringFromBytes", "([BLjava/nio/charset/Charset;)Ljava/lang/String;", NewStringFromBytes_BCharset) \
225 V(java_lang_String_init_C, "([C)V", newStringFromChars_C, "newStringFromChars", "([C)Ljava/lang/String;", NewStringFromChars_C) \
226 V(java_lang_String_init_CII, "([CII)V", newStringFromChars_CII, "newStringFromChars", "([CII)Ljava/lang/String;", NewStringFromChars_CII) \
227 V(java_lang_String_init_IIC, "(II[C)V", newStringFromChars_IIC, "newStringFromChars", "(II[C)Ljava/lang/String;", NewStringFromChars_IIC) \
228 V(java_lang_String_init_String, "(Ljava/lang/String;)V", newStringFromString, "newStringFromString", "(Ljava/lang/String;)Ljava/lang/String;", NewStringFromString) \
229 V(java_lang_String_init_StringBuffer, "(Ljava/lang/StringBuffer;)V", newStringFromStringBuffer, "newStringFromStringBuffer", "(Ljava/lang/StringBuffer;)Ljava/lang/String;", NewStringFromStringBuffer) \
230 V(java_lang_String_init_III, "([III)V", newStringFromCodePoints, "newStringFromCodePoints", "([III)Ljava/lang/String;", NewStringFromCodePoints) \
231 V(java_lang_String_init_StringBuilder, "(Ljava/lang/StringBuilder;)V", newStringFromStringBuilder, "newStringFromStringBuilder", "(Ljava/lang/StringBuilder;)Ljava/lang/String;", NewStringFromStringBuilder) \
232
233#define STATIC_STRING_INIT(init_runtime_name, init_signature, new_runtime_name, ...) \
234 static ArtMethod* init_runtime_name; \
235 static ArtMethod* new_runtime_name;
236 STRING_INIT_LIST(STATIC_STRING_INIT)
237#undef STATIC_STRING_INIT
238
239void WellKnownClasses::InitStringInit(JNIEnv* env) {
240 ScopedObjectAccess soa(Thread::Current());
241 #define LOAD_STRING_INIT(init_runtime_name, init_signature, new_runtime_name, \
242 new_java_name, new_signature, ...) \
Andreas Gampe13b27842016-11-07 16:48:23 -0800243 init_runtime_name = jni::DecodeArtMethod( \
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +0100244 CacheMethod(env, java_lang_String, false, "<init>", init_signature)); \
Andreas Gampe13b27842016-11-07 16:48:23 -0800245 new_runtime_name = jni::DecodeArtMethod( \
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +0100246 CacheMethod(env, java_lang_StringFactory, true, new_java_name, new_signature));
247 STRING_INIT_LIST(LOAD_STRING_INIT)
248 #undef LOAD_STRING_INIT
249}
250
251void Thread::InitStringEntryPoints() {
252 QuickEntryPoints* qpoints = &tlsPtr_.quick_entrypoints;
253 #define SET_ENTRY_POINT(init_runtime_name, init_signature, new_runtime_name, \
254 new_java_name, new_signature, entry_point_name) \
255 qpoints->p ## entry_point_name = reinterpret_cast<void(*)()>(new_runtime_name);
256 STRING_INIT_LIST(SET_ENTRY_POINT)
257 #undef SET_ENTRY_POINT
258}
259
260ArtMethod* WellKnownClasses::StringInitToStringFactory(ArtMethod* string_init) {
261 #define TO_STRING_FACTORY(init_runtime_name, init_signature, new_runtime_name, \
262 new_java_name, new_signature, entry_point_name) \
Andreas Gampeca620d72016-11-08 08:09:33 -0800263 if (string_init == (init_runtime_name)) { \
264 return (new_runtime_name); \
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +0100265 }
266 STRING_INIT_LIST(TO_STRING_FACTORY)
267 #undef TO_STRING_FACTORY
268 LOG(FATAL) << "Could not find StringFactory method for String.<init>";
269 return nullptr;
270}
271
272uint32_t WellKnownClasses::StringInitToEntryPoint(ArtMethod* string_init) {
273 #define TO_ENTRY_POINT(init_runtime_name, init_signature, new_runtime_name, \
274 new_java_name, new_signature, entry_point_name) \
Andreas Gampeca620d72016-11-08 08:09:33 -0800275 if (string_init == (init_runtime_name)) { \
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +0100276 return kQuick ## entry_point_name; \
277 }
278 STRING_INIT_LIST(TO_ENTRY_POINT)
Victor Chang2f5bfb12017-12-18 19:04:53 +0100279 #undef TO_ENTRY_POINT
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +0100280 LOG(FATAL) << "Could not find StringFactory method for String.<init>";
281 return 0;
282}
283#undef STRING_INIT_LIST
284
Brian Carlstromea46f952013-07-30 01:26:50 -0700285void WellKnownClasses::Init(JNIEnv* env) {
David Brazdil32bde992018-05-14 15:24:34 +0100286 hiddenapi::ScopedHiddenApiEnforcementPolicySetting hiddenapi_exemption(
287 hiddenapi::EnforcementPolicy::kNoChecks);
David Brazdila5efc4c2018-02-13 10:01:31 -0800288
Igor Murashkin367f3dd2016-09-01 17:00:24 -0700289 dalvik_annotation_optimization_CriticalNative =
290 CacheClass(env, "dalvik/annotation/optimization/CriticalNative");
Igor Murashkin9d4b6da2016-07-29 09:51:58 -0700291 dalvik_annotation_optimization_FastNative = CacheClass(env, "dalvik/annotation/optimization/FastNative");
Andreas Gampe46aba362016-10-28 14:33:28 -0700292 dalvik_system_BaseDexClassLoader = CacheClass(env, "dalvik/system/BaseDexClassLoader");
Calin Juravle7865ac72017-06-28 11:03:12 -0700293 dalvik_system_DelegateLastClassLoader = CacheClass(env, "dalvik/system/DelegateLastClassLoader");
Nicolas Geoffray7d8d8ff2016-11-02 12:38:05 +0000294 dalvik_system_DexClassLoader = CacheClass(env, "dalvik/system/DexClassLoader");
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -0700295 dalvik_system_DexFile = CacheClass(env, "dalvik/system/DexFile");
296 dalvik_system_DexPathList = CacheClass(env, "dalvik/system/DexPathList");
Andreas Gampec8ccf682014-09-29 20:07:43 -0700297 dalvik_system_DexPathList__Element = CacheClass(env, "dalvik/system/DexPathList$Element");
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +0100298 dalvik_system_EmulatedStackFrame = CacheClass(env, "dalvik/system/EmulatedStackFrame");
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700299 dalvik_system_PathClassLoader = CacheClass(env, "dalvik/system/PathClassLoader");
Mathieu Chartierb5de3bb2015-06-05 13:21:05 -0700300 dalvik_system_VMRuntime = CacheClass(env, "dalvik/system/VMRuntime");
301
Jeff Hao13e748b2015-08-25 20:44:19 +0000302 java_lang_annotation_Annotation__array = CacheClass(env, "[Ljava/lang/annotation/Annotation;");
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -0700303 java_lang_BootClassLoader = CacheClass(env, "java/lang/BootClassLoader");
Elliott Hugheseac76672012-05-24 21:56:51 -0700304 java_lang_ClassLoader = CacheClass(env, "java/lang/ClassLoader");
305 java_lang_ClassNotFoundException = CacheClass(env, "java/lang/ClassNotFoundException");
306 java_lang_Daemons = CacheClass(env, "java/lang/Daemons");
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800307 java_lang_Object = CacheClass(env, "java/lang/Object");
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700308 java_lang_OutOfMemoryError = CacheClass(env, "java/lang/OutOfMemoryError");
Elliott Hugheseac76672012-05-24 21:56:51 -0700309 java_lang_Error = CacheClass(env, "java/lang/Error");
Jeff Haoc92a7a12016-06-06 11:09:20 -0700310 java_lang_IllegalAccessError = CacheClass(env, "java/lang/IllegalAccessError");
Orion Hodson811bd5f2016-12-07 11:35:37 +0000311 java_lang_invoke_MethodHandle = CacheClass(env, "java/lang/invoke/MethodHandle");
Orion Hodsoneb4d19b2017-11-06 15:49:23 +0000312 java_lang_invoke_VarHandle = CacheClass(env, "java/lang/invoke/VarHandle");
Jeff Haoc92a7a12016-06-06 11:09:20 -0700313 java_lang_NoClassDefFoundError = CacheClass(env, "java/lang/NoClassDefFoundError");
Neil Fuller79a21e72016-09-09 14:24:51 +0100314 java_lang_reflect_Parameter = CacheClass(env, "java/lang/reflect/Parameter");
315 java_lang_reflect_Parameter__array = CacheClass(env, "[Ljava/lang/reflect/Parameter;");
Elliott Hugheseac76672012-05-24 21:56:51 -0700316 java_lang_reflect_Proxy = CacheClass(env, "java/lang/reflect/Proxy");
Elliott Hughesa4f94742012-05-29 16:28:38 -0700317 java_lang_RuntimeException = CacheClass(env, "java/lang/RuntimeException");
Ian Rogers120f1c72012-09-28 17:17:10 -0700318 java_lang_StackOverflowError = CacheClass(env, "java/lang/StackOverflowError");
Ian Rogersdd157d72014-05-15 14:47:50 -0700319 java_lang_String = CacheClass(env, "java/lang/String");
Jeff Hao848f70a2014-01-15 13:49:50 -0800320 java_lang_StringFactory = CacheClass(env, "java/lang/StringFactory");
Mathieu Chartier987ccff2013-07-08 11:05:21 -0700321 java_lang_System = CacheClass(env, "java/lang/System");
Elliott Hugheseac76672012-05-24 21:56:51 -0700322 java_lang_Thread = CacheClass(env, "java/lang/Thread");
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700323 java_lang_ThreadGroup = CacheClass(env, "java/lang/ThreadGroup");
Elliott Hughesa4f94742012-05-29 16:28:38 -0700324 java_lang_Throwable = CacheClass(env, "java/lang/Throwable");
Orion Hodson928033d2018-02-07 05:30:54 +0000325 java_nio_ByteBuffer = CacheClass(env, "java/nio/ByteBuffer");
Elliott Hughesaecb5f32013-03-28 08:27:38 -0700326 java_nio_DirectByteBuffer = CacheClass(env, "java/nio/DirectByteBuffer");
Sebastien Hertze49e1952014-10-13 11:27:13 +0200327 java_util_ArrayList = CacheClass(env, "java/util/ArrayList");
Andreas Gampe7ea6f792014-07-14 16:21:44 -0700328 java_util_Collections = CacheClass(env, "java/util/Collections");
Narayan Kamathf5f1f802018-04-03 15:23:46 +0100329 java_util_function_Consumer = CacheClass(env, "java/util/function/Consumer");
Jeff Hao13e748b2015-08-25 20:44:19 +0000330 libcore_reflect_AnnotationFactory = CacheClass(env, "libcore/reflect/AnnotationFactory");
331 libcore_reflect_AnnotationMember = CacheClass(env, "libcore/reflect/AnnotationMember");
Andreas Gampe7ea6f792014-07-14 16:21:44 -0700332 libcore_util_EmptyArray = CacheClass(env, "libcore/util/EmptyArray");
Elliott Hugheseac76672012-05-24 21:56:51 -0700333 org_apache_harmony_dalvik_ddmc_Chunk = CacheClass(env, "org/apache/harmony/dalvik/ddmc/Chunk");
334 org_apache_harmony_dalvik_ddmc_DdmServer = CacheClass(env, "org/apache/harmony/dalvik/ddmc/DdmServer");
335
Andreas Gampe473191c2017-12-28 16:55:31 -0800336 dalvik_system_BaseDexClassLoader_getLdLibraryPath = CacheMethod(env, dalvik_system_BaseDexClassLoader, false, "getLdLibraryPath", "()Ljava/lang/String;");
Mathieu Chartierb5de3bb2015-06-05 13:21:05 -0700337 dalvik_system_VMRuntime_runFinalization = CacheMethod(env, dalvik_system_VMRuntime, true, "runFinalization", "(J)V");
Elliott Hugheseac76672012-05-24 21:56:51 -0700338 java_lang_ClassNotFoundException_init = CacheMethod(env, java_lang_ClassNotFoundException, false, "<init>", "(Ljava/lang/String;Ljava/lang/Throwable;)V");
Elliott Hughesa4f94742012-05-29 16:28:38 -0700339 java_lang_ClassLoader_loadClass = CacheMethod(env, java_lang_ClassLoader, false, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
Mathieu Chartier7664f5c2012-06-08 18:15:32 -0700340
Elliott Hugheseac76672012-05-24 21:56:51 -0700341 java_lang_Daemons_requestHeapTrim = CacheMethod(env, java_lang_Daemons, true, "requestHeapTrim", "()V");
342 java_lang_Daemons_start = CacheMethod(env, java_lang_Daemons, true, "start", "()V");
Mathieu Chartiercef50f02014-12-09 17:38:52 -0800343 java_lang_Daemons_stop = CacheMethod(env, java_lang_Daemons, true, "stop", "()V");
Orion Hodsonf8db2c32017-07-07 20:07:12 +0100344 java_lang_invoke_MethodHandle_invoke = CacheMethod(env, java_lang_invoke_MethodHandle, false, "invoke", "([Ljava/lang/Object;)Ljava/lang/Object;");
345 java_lang_invoke_MethodHandle_invokeExact = CacheMethod(env, java_lang_invoke_MethodHandle, false, "invokeExact", "([Ljava/lang/Object;)Ljava/lang/Object;");
346 java_lang_invoke_MethodHandles_lookup = CacheMethod(env, "java/lang/invoke/MethodHandles", true, "lookup", "()Ljava/lang/invoke/MethodHandles$Lookup;");
347 java_lang_invoke_MethodHandles_Lookup_findConstructor = CacheMethod(env, "java/lang/invoke/MethodHandles$Lookup", false, "findConstructor", "(Ljava/lang/Class;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/MethodHandle;");
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100348
Orion Hodsonf8db2c32017-07-07 20:07:12 +0100349 java_lang_ref_FinalizerReference_add = CacheMethod(env, "java/lang/ref/FinalizerReference", true, "add", "(Ljava/lang/Object;)V");
350 java_lang_ref_ReferenceQueue_add = CacheMethod(env, "java/lang/ref/ReferenceQueue", true, "add", "(Ljava/lang/ref/Reference;)V");
Elliott Hughesa4f94742012-05-29 16:28:38 -0700351
Neil Fuller79a21e72016-09-09 14:24:51 +0100352 java_lang_reflect_Parameter_init = CacheMethod(env, java_lang_reflect_Parameter, false, "<init>", "(Ljava/lang/String;ILjava/lang/reflect/Executable;I)V");
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000353 java_lang_String_charAt = CacheMethod(env, java_lang_String, false, "charAt", "(I)C");
Tobias Thierer5cbe65d2016-07-22 18:37:59 +0100354 java_lang_Thread_dispatchUncaughtException = CacheMethod(env, java_lang_Thread, false, "dispatchUncaughtException", "(Ljava/lang/Throwable;)V");
Elliott Hugheseac76672012-05-24 21:56:51 -0700355 java_lang_Thread_init = CacheMethod(env, java_lang_Thread, false, "<init>", "(Ljava/lang/ThreadGroup;Ljava/lang/String;IZ)V");
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700356 java_lang_Thread_run = CacheMethod(env, java_lang_Thread, false, "run", "()V");
Andreas Gampe56776012018-01-26 17:40:55 -0800357 java_lang_ThreadGroup_add = CacheMethod(env, java_lang_ThreadGroup, false, "add", "(Ljava/lang/Thread;)V");
Piotr Jastrzebskie6cd3b52015-05-07 09:41:00 +0100358 java_lang_ThreadGroup_removeThread = CacheMethod(env, java_lang_ThreadGroup, false, "threadTerminated", "(Ljava/lang/Thread;)V");
Elliott Hughesb5681212013-03-29 17:29:22 -0700359 java_nio_DirectByteBuffer_init = CacheMethod(env, java_nio_DirectByteBuffer, false, "<init>", "(JI)V");
Narayan Kamathf5f1f802018-04-03 15:23:46 +0100360 java_util_function_Consumer_accept = CacheMethod(env, java_util_function_Consumer, false, "accept", "(Ljava/lang/Object;)V");
Jeff Hao13e748b2015-08-25 20:44:19 +0000361 libcore_reflect_AnnotationFactory_createAnnotation = CacheMethod(env, libcore_reflect_AnnotationFactory, true, "createAnnotation", "(Ljava/lang/Class;[Llibcore/reflect/AnnotationMember;)Ljava/lang/annotation/Annotation;");
362 libcore_reflect_AnnotationMember_init = CacheMethod(env, libcore_reflect_AnnotationMember, false, "<init>", "(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/reflect/Method;)V");
Elliott Hugheseac76672012-05-24 21:56:51 -0700363 org_apache_harmony_dalvik_ddmc_DdmServer_broadcast = CacheMethod(env, org_apache_harmony_dalvik_ddmc_DdmServer, true, "broadcast", "(I)V");
364 org_apache_harmony_dalvik_ddmc_DdmServer_dispatch = CacheMethod(env, org_apache_harmony_dalvik_ddmc_DdmServer, true, "dispatch", "(I[BII)Lorg/apache/harmony/dalvik/ddmc/Chunk;");
365
Andreas Gampe46aba362016-10-28 14:33:28 -0700366 dalvik_system_BaseDexClassLoader_pathList = CacheField(env, dalvik_system_BaseDexClassLoader, false, "pathList", "Ldalvik/system/DexPathList;");
Andreas Gampe324b9bb2015-02-23 16:33:22 -0800367 dalvik_system_DexFile_cookie = CacheField(env, dalvik_system_DexFile, false, "mCookie", "Ljava/lang/Object;");
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800368 dalvik_system_DexFile_fileName = CacheField(env, dalvik_system_DexFile, false, "mFileName", "Ljava/lang/String;");
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -0700369 dalvik_system_DexPathList_dexElements = CacheField(env, dalvik_system_DexPathList, false, "dexElements", "[Ldalvik/system/DexPathList$Element;");
Andreas Gampec8ccf682014-09-29 20:07:43 -0700370 dalvik_system_DexPathList__Element_dexFile = CacheField(env, dalvik_system_DexPathList__Element, false, "dexFile", "Ldalvik/system/DexFile;");
Narayan Kamathf5f1f802018-04-03 15:23:46 +0100371 dalvik_system_VMRuntime_nonSdkApiUsageConsumer = CacheField(env, dalvik_system_VMRuntime, true, "nonSdkApiUsageConsumer", "Ljava/util/function/Consumer;");
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700372 java_lang_Thread_daemon = CacheField(env, java_lang_Thread, false, "daemon", "Z");
373 java_lang_Thread_group = CacheField(env, java_lang_Thread, false, "group", "Ljava/lang/ThreadGroup;");
Elliott Hughesc5dc2ff2013-01-09 13:44:30 -0800374 java_lang_Thread_lock = CacheField(env, java_lang_Thread, false, "lock", "Ljava/lang/Object;");
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700375 java_lang_Thread_name = CacheField(env, java_lang_Thread, false, "name", "Ljava/lang/String;");
376 java_lang_Thread_priority = CacheField(env, java_lang_Thread, false, "priority", "I");
Ian Rogersef7d42f2014-01-06 12:55:46 -0800377 java_lang_Thread_nativePeer = CacheField(env, java_lang_Thread, false, "nativePeer", "J");
Narayan Kamathd1ef4362015-11-12 11:49:06 +0000378 java_lang_ThreadGroup_groups = CacheField(env, java_lang_ThreadGroup, false, "groups", "[Ljava/lang/ThreadGroup;");
Przemyslaw Szczepaniak464595f2015-11-24 11:59:59 +0000379 java_lang_ThreadGroup_ngroups = CacheField(env, java_lang_ThreadGroup, false, "ngroups", "I");
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700380 java_lang_ThreadGroup_mainThreadGroup = CacheField(env, java_lang_ThreadGroup, true, "mainThreadGroup", "Ljava/lang/ThreadGroup;");
381 java_lang_ThreadGroup_name = CacheField(env, java_lang_ThreadGroup, false, "name", "Ljava/lang/String;");
Sebastien Hertze49e1952014-10-13 11:27:13 +0200382 java_lang_ThreadGroup_parent = CacheField(env, java_lang_ThreadGroup, false, "parent", "Ljava/lang/ThreadGroup;");
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700383 java_lang_ThreadGroup_systemThreadGroup = CacheField(env, java_lang_ThreadGroup, true, "systemThreadGroup", "Ljava/lang/ThreadGroup;");
Brian Carlstrom34375312014-09-10 23:10:47 -0700384 java_lang_Throwable_cause = CacheField(env, java_lang_Throwable, false, "cause", "Ljava/lang/Throwable;");
385 java_lang_Throwable_detailMessage = CacheField(env, java_lang_Throwable, false, "detailMessage", "Ljava/lang/String;");
386 java_lang_Throwable_stackTrace = CacheField(env, java_lang_Throwable, false, "stackTrace", "[Ljava/lang/StackTraceElement;");
Piotr Jastrzebskic16a50f2015-05-07 09:41:00 +0100387 java_lang_Throwable_stackState = CacheField(env, java_lang_Throwable, false, "backtrace", "Ljava/lang/Object;");
Brian Carlstrom34375312014-09-10 23:10:47 -0700388 java_lang_Throwable_suppressedExceptions = CacheField(env, java_lang_Throwable, false, "suppressedExceptions", "Ljava/util/List;");
Orion Hodson928033d2018-02-07 05:30:54 +0000389 java_nio_ByteBuffer_address = CacheField(env, java_nio_ByteBuffer, false, "address", "J");
390 java_nio_ByteBuffer_hb = CacheField(env, java_nio_ByteBuffer, false, "hb", "[B");
391 java_nio_ByteBuffer_isReadOnly = CacheField(env, java_nio_ByteBuffer, false, "isReadOnly", "Z");
392 java_nio_ByteBuffer_limit = CacheField(env, java_nio_ByteBuffer, false, "limit", "I");
393 java_nio_ByteBuffer_offset = CacheField(env, java_nio_ByteBuffer, false, "offset", "I");
Elliott Hughesaecb5f32013-03-28 08:27:38 -0700394 java_nio_DirectByteBuffer_capacity = CacheField(env, java_nio_DirectByteBuffer, false, "capacity", "I");
Piotr Jastrzebski8c145b92015-05-05 12:54:00 +0100395 java_nio_DirectByteBuffer_effectiveDirectAddress = CacheField(env, java_nio_DirectByteBuffer, false, "address", "J");
Narayan Kamathd1ef4362015-11-12 11:49:06 +0000396 java_util_ArrayList_array = CacheField(env, java_util_ArrayList, false, "elementData", "[Ljava/lang/Object;");
Sebastien Hertze49e1952014-10-13 11:27:13 +0200397 java_util_ArrayList_size = CacheField(env, java_util_ArrayList, false, "size", "I");
Brian Carlstrom34375312014-09-10 23:10:47 -0700398 java_util_Collections_EMPTY_LIST = CacheField(env, java_util_Collections, true, "EMPTY_LIST", "Ljava/util/List;");
399 libcore_util_EmptyArray_STACK_TRACE_ELEMENT = CacheField(env, libcore_util_EmptyArray, true, "STACK_TRACE_ELEMENT", "[Ljava/lang/StackTraceElement;");
Sebastien Hertzb30e0c62014-09-11 16:23:44 +0200400 org_apache_harmony_dalvik_ddmc_Chunk_data = CacheField(env, org_apache_harmony_dalvik_ddmc_Chunk, false, "data", "[B");
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700401 org_apache_harmony_dalvik_ddmc_Chunk_length = CacheField(env, org_apache_harmony_dalvik_ddmc_Chunk, false, "length", "I");
402 org_apache_harmony_dalvik_ddmc_Chunk_offset = CacheField(env, org_apache_harmony_dalvik_ddmc_Chunk, false, "offset", "I");
403 org_apache_harmony_dalvik_ddmc_Chunk_type = CacheField(env, org_apache_harmony_dalvik_ddmc_Chunk, false, "type", "I");
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700404
405 java_lang_Boolean_valueOf = CachePrimitiveBoxingMethod(env, 'Z', "java/lang/Boolean");
406 java_lang_Byte_valueOf = CachePrimitiveBoxingMethod(env, 'B', "java/lang/Byte");
407 java_lang_Character_valueOf = CachePrimitiveBoxingMethod(env, 'C', "java/lang/Character");
408 java_lang_Double_valueOf = CachePrimitiveBoxingMethod(env, 'D', "java/lang/Double");
409 java_lang_Float_valueOf = CachePrimitiveBoxingMethod(env, 'F', "java/lang/Float");
410 java_lang_Integer_valueOf = CachePrimitiveBoxingMethod(env, 'I', "java/lang/Integer");
411 java_lang_Long_valueOf = CachePrimitiveBoxingMethod(env, 'J', "java/lang/Long");
412 java_lang_Short_valueOf = CachePrimitiveBoxingMethod(env, 'S', "java/lang/Short");
Jeff Hao848f70a2014-01-15 13:49:50 -0800413
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +0100414 InitStringInit(env);
Jeff Hao848f70a2014-01-15 13:49:50 -0800415 Thread::Current()->InitStringEntryPoints();
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700416}
417
Ian Rogersef28b142012-11-30 14:22:18 -0800418void WellKnownClasses::LateInit(JNIEnv* env) {
419 ScopedLocalRef<jclass> java_lang_Runtime(env, env->FindClass("java/lang/Runtime"));
Przemyslaw Szczepaniakf11cd292016-08-17 17:46:38 +0100420 // CacheField and CacheMethod will initialize their classes. Classes below
421 // have clinit sections that call JNI methods. Late init is required
422 // to make sure these JNI methods are available.
Dmitriy Ivanov44409d32015-11-11 14:18:55 -0800423 java_lang_Runtime_nativeLoad =
424 CacheMethod(env, java_lang_Runtime.get(), true, "nativeLoad",
Andreas Gampe473191c2017-12-28 16:55:31 -0800425 "(Ljava/lang/String;Ljava/lang/ClassLoader;)"
Dmitriy Ivanov44409d32015-11-11 14:18:55 -0800426 "Ljava/lang/String;");
Przemyslaw Szczepaniakf11cd292016-08-17 17:46:38 +0100427 java_lang_reflect_Proxy_invoke =
428 CacheMethod(env, java_lang_reflect_Proxy, true, "invoke",
429 "(Ljava/lang/reflect/Proxy;Ljava/lang/reflect/Method;"
430 "[Ljava/lang/Object;)Ljava/lang/Object;");
431 java_lang_reflect_Proxy_h =
432 CacheField(env, java_lang_reflect_Proxy, false, "h",
433 "Ljava/lang/reflect/InvocationHandler;");
Ian Rogersef28b142012-11-30 14:22:18 -0800434}
435
Andreas Gampedb48a792017-09-08 22:18:30 -0700436void WellKnownClasses::Clear() {
437 dalvik_annotation_optimization_CriticalNative = nullptr;
438 dalvik_annotation_optimization_FastNative = nullptr;
439 dalvik_system_BaseDexClassLoader = nullptr;
440 dalvik_system_DelegateLastClassLoader = nullptr;
441 dalvik_system_DexClassLoader = nullptr;
442 dalvik_system_DexFile = nullptr;
443 dalvik_system_DexPathList = nullptr;
444 dalvik_system_DexPathList__Element = nullptr;
445 dalvik_system_EmulatedStackFrame = nullptr;
446 dalvik_system_PathClassLoader = nullptr;
447 dalvik_system_VMRuntime = nullptr;
448 java_lang_annotation_Annotation__array = nullptr;
449 java_lang_BootClassLoader = nullptr;
450 java_lang_ClassLoader = nullptr;
451 java_lang_ClassNotFoundException = nullptr;
452 java_lang_Daemons = nullptr;
453 java_lang_Error = nullptr;
454 java_lang_IllegalAccessError = nullptr;
455 java_lang_invoke_MethodHandle = nullptr;
Orion Hodsoneb4d19b2017-11-06 15:49:23 +0000456 java_lang_invoke_VarHandle = nullptr;
Andreas Gampedb48a792017-09-08 22:18:30 -0700457 java_lang_NoClassDefFoundError = nullptr;
458 java_lang_Object = nullptr;
459 java_lang_OutOfMemoryError = nullptr;
Andreas Gampedb48a792017-09-08 22:18:30 -0700460 java_lang_reflect_Parameter = nullptr;
461 java_lang_reflect_Parameter__array = nullptr;
462 java_lang_reflect_Proxy = nullptr;
463 java_lang_RuntimeException = nullptr;
464 java_lang_StackOverflowError = nullptr;
465 java_lang_String = nullptr;
466 java_lang_StringFactory = nullptr;
467 java_lang_System = nullptr;
468 java_lang_Thread = nullptr;
469 java_lang_ThreadGroup = nullptr;
470 java_lang_Throwable = nullptr;
471 java_util_ArrayList = nullptr;
472 java_util_Collections = nullptr;
Orion Hodson928033d2018-02-07 05:30:54 +0000473 java_nio_ByteBuffer = nullptr;
Andreas Gampedb48a792017-09-08 22:18:30 -0700474 java_nio_DirectByteBuffer = nullptr;
475 libcore_reflect_AnnotationFactory = nullptr;
476 libcore_reflect_AnnotationMember = nullptr;
477 libcore_util_EmptyArray = nullptr;
478 org_apache_harmony_dalvik_ddmc_Chunk = nullptr;
479 org_apache_harmony_dalvik_ddmc_DdmServer = nullptr;
480
Andreas Gampe473191c2017-12-28 16:55:31 -0800481 dalvik_system_BaseDexClassLoader_getLdLibraryPath = nullptr;
Andreas Gampedb48a792017-09-08 22:18:30 -0700482 dalvik_system_VMRuntime_runFinalization = nullptr;
483 java_lang_Boolean_valueOf = nullptr;
484 java_lang_Byte_valueOf = nullptr;
485 java_lang_Character_valueOf = nullptr;
486 java_lang_ClassLoader_loadClass = nullptr;
487 java_lang_ClassNotFoundException_init = nullptr;
488 java_lang_Daemons_requestHeapTrim = nullptr;
489 java_lang_Daemons_start = nullptr;
490 java_lang_Daemons_stop = nullptr;
491 java_lang_Double_valueOf = nullptr;
492 java_lang_Float_valueOf = nullptr;
493 java_lang_Integer_valueOf = nullptr;
494 java_lang_invoke_MethodHandle_invoke = nullptr;
495 java_lang_invoke_MethodHandle_invokeExact = nullptr;
496 java_lang_invoke_MethodHandles_lookup = nullptr;
497 java_lang_invoke_MethodHandles_Lookup_findConstructor = nullptr;
498 java_lang_Long_valueOf = nullptr;
499 java_lang_ref_FinalizerReference_add = nullptr;
500 java_lang_ref_ReferenceQueue_add = nullptr;
501 java_lang_reflect_Parameter_init = nullptr;
502 java_lang_reflect_Proxy_invoke = nullptr;
503 java_lang_Runtime_nativeLoad = nullptr;
504 java_lang_Short_valueOf = nullptr;
505 java_lang_String_charAt = nullptr;
506 java_lang_System_runFinalization = nullptr;
507 java_lang_Thread_dispatchUncaughtException = nullptr;
508 java_lang_Thread_init = nullptr;
509 java_lang_Thread_run = nullptr;
Andreas Gampe56776012018-01-26 17:40:55 -0800510 java_lang_ThreadGroup_add = nullptr;
Andreas Gampedb48a792017-09-08 22:18:30 -0700511 java_lang_ThreadGroup_removeThread = nullptr;
512 java_nio_DirectByteBuffer_init = nullptr;
513 libcore_reflect_AnnotationFactory_createAnnotation = nullptr;
514 libcore_reflect_AnnotationMember_init = nullptr;
515 org_apache_harmony_dalvik_ddmc_DdmServer_broadcast = nullptr;
516 org_apache_harmony_dalvik_ddmc_DdmServer_dispatch = nullptr;
517
518 dalvik_system_BaseDexClassLoader_pathList = nullptr;
519 dalvik_system_DexFile_cookie = nullptr;
520 dalvik_system_DexFile_fileName = nullptr;
521 dalvik_system_DexPathList_dexElements = nullptr;
522 dalvik_system_DexPathList__Element_dexFile = nullptr;
Vladimir Marko60976722018-04-06 15:29:38 +0100523 dalvik_system_VMRuntime_nonSdkApiUsageConsumer = nullptr;
Andreas Gampedb48a792017-09-08 22:18:30 -0700524 java_lang_reflect_Proxy_h = nullptr;
525 java_lang_Thread_daemon = nullptr;
526 java_lang_Thread_group = nullptr;
527 java_lang_Thread_lock = nullptr;
528 java_lang_Thread_name = nullptr;
529 java_lang_Thread_priority = nullptr;
530 java_lang_Thread_nativePeer = nullptr;
531 java_lang_ThreadGroup_groups = nullptr;
532 java_lang_ThreadGroup_ngroups = nullptr;
533 java_lang_ThreadGroup_mainThreadGroup = nullptr;
534 java_lang_ThreadGroup_name = nullptr;
535 java_lang_ThreadGroup_parent = nullptr;
536 java_lang_ThreadGroup_systemThreadGroup = nullptr;
537 java_lang_Throwable_cause = nullptr;
538 java_lang_Throwable_detailMessage = nullptr;
539 java_lang_Throwable_stackTrace = nullptr;
540 java_lang_Throwable_stackState = nullptr;
541 java_lang_Throwable_suppressedExceptions = nullptr;
Orion Hodson928033d2018-02-07 05:30:54 +0000542 java_nio_ByteBuffer_address = nullptr;
543 java_nio_ByteBuffer_hb = nullptr;
544 java_nio_ByteBuffer_isReadOnly = nullptr;
545 java_nio_ByteBuffer_limit = nullptr;
546 java_nio_ByteBuffer_offset = nullptr;
Andreas Gampedb48a792017-09-08 22:18:30 -0700547 java_nio_DirectByteBuffer_capacity = nullptr;
548 java_nio_DirectByteBuffer_effectiveDirectAddress = nullptr;
549 java_util_ArrayList_array = nullptr;
550 java_util_ArrayList_size = nullptr;
551 java_util_Collections_EMPTY_LIST = nullptr;
552 libcore_util_EmptyArray_STACK_TRACE_ELEMENT = nullptr;
553 org_apache_harmony_dalvik_ddmc_Chunk_data = nullptr;
554 org_apache_harmony_dalvik_ddmc_Chunk_length = nullptr;
555 org_apache_harmony_dalvik_ddmc_Chunk_offset = nullptr;
556 org_apache_harmony_dalvik_ddmc_Chunk_type = nullptr;
557}
558
Mathieu Chartierc4f39252016-10-05 18:32:08 -0700559ObjPtr<mirror::Class> WellKnownClasses::ToClass(jclass global_jclass) {
Alex Lightd6251582016-10-31 11:12:30 -0700560 auto ret = ObjPtr<mirror::Class>::DownCast(Thread::Current()->DecodeJObject(global_jclass));
561 DCHECK(!ret.IsNull());
562 return ret;
Elliott Hugheseac76672012-05-24 21:56:51 -0700563}
564
Elliott Hugheseac76672012-05-24 21:56:51 -0700565} // namespace art