blob: 28438062dfdda953360a45887c028abd87da10a8 [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
Elliott Hughes07ed66b2012-12-12 18:34:25 -080023#include "base/logging.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024#include "mirror/class.h"
Elliott Hugheseac76672012-05-24 21:56:51 -070025#include "ScopedLocalRef.h"
Brian Carlstrom3c821c62014-09-10 10:08:37 -070026#include "scoped_thread_state_change.h"
Brian Carlstroma3d27182013-11-05 23:22:27 -080027#include "thread-inl.h"
Elliott Hugheseac76672012-05-24 21:56:51 -070028
29namespace art {
30
31jclass WellKnownClasses::com_android_dex_Dex;
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -070032jclass WellKnownClasses::dalvik_system_DexFile;
33jclass WellKnownClasses::dalvik_system_DexPathList;
Andreas Gampec8ccf682014-09-29 20:07:43 -070034jclass WellKnownClasses::dalvik_system_DexPathList__Element;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070035jclass WellKnownClasses::dalvik_system_PathClassLoader;
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -070036jclass WellKnownClasses::java_lang_BootClassLoader;
Elliott Hugheseac76672012-05-24 21:56:51 -070037jclass WellKnownClasses::java_lang_ClassLoader;
38jclass WellKnownClasses::java_lang_ClassNotFoundException;
39jclass WellKnownClasses::java_lang_Daemons;
40jclass WellKnownClasses::java_lang_Error;
Ian Rogersaf6e67a2013-01-16 08:38:37 -080041jclass WellKnownClasses::java_lang_Object;
Mathieu Chartiera61894d2015-04-23 16:32:54 -070042jclass WellKnownClasses::java_lang_OutOfMemoryError;
Mathieu Chartier66f19252012-09-18 08:57:04 -070043jclass WellKnownClasses::java_lang_reflect_AbstractMethod;
Brian Carlstromea46f952013-07-30 01:26:50 -070044jclass WellKnownClasses::java_lang_reflect_ArtMethod;
45jclass WellKnownClasses::java_lang_reflect_Constructor;
46jclass WellKnownClasses::java_lang_reflect_Field;
47jclass WellKnownClasses::java_lang_reflect_Method;
Elliott Hugheseac76672012-05-24 21:56:51 -070048jclass WellKnownClasses::java_lang_reflect_Proxy;
Elliott Hughesa4f94742012-05-29 16:28:38 -070049jclass WellKnownClasses::java_lang_RuntimeException;
Ian Rogers120f1c72012-09-28 17:17:10 -070050jclass WellKnownClasses::java_lang_StackOverflowError;
Ian Rogersdd157d72014-05-15 14:47:50 -070051jclass WellKnownClasses::java_lang_String;
Jeff Hao848f70a2014-01-15 13:49:50 -080052jclass WellKnownClasses::java_lang_StringFactory;
Mathieu Chartier987ccff2013-07-08 11:05:21 -070053jclass WellKnownClasses::java_lang_System;
Elliott Hugheseac76672012-05-24 21:56:51 -070054jclass WellKnownClasses::java_lang_Thread;
Andreas Gampec8ccf682014-09-29 20:07:43 -070055jclass WellKnownClasses::java_lang_Thread__UncaughtExceptionHandler;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -070056jclass WellKnownClasses::java_lang_ThreadGroup;
Elliott Hughesa4f94742012-05-29 16:28:38 -070057jclass WellKnownClasses::java_lang_Throwable;
Elliott Hughesaecb5f32013-03-28 08:27:38 -070058jclass WellKnownClasses::java_nio_DirectByteBuffer;
Sebastien Hertze49e1952014-10-13 11:27:13 +020059jclass WellKnownClasses::java_util_ArrayList;
Andreas Gampe7ea6f792014-07-14 16:21:44 -070060jclass WellKnownClasses::java_util_Collections;
61jclass WellKnownClasses::libcore_util_EmptyArray;
Elliott Hugheseac76672012-05-24 21:56:51 -070062jclass WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk;
63jclass WellKnownClasses::org_apache_harmony_dalvik_ddmc_DdmServer;
64
65jmethodID WellKnownClasses::com_android_dex_Dex_create;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070066jmethodID WellKnownClasses::java_lang_Boolean_valueOf;
67jmethodID WellKnownClasses::java_lang_Byte_valueOf;
68jmethodID WellKnownClasses::java_lang_Character_valueOf;
Elliott Hughesa4f94742012-05-29 16:28:38 -070069jmethodID WellKnownClasses::java_lang_ClassLoader_loadClass;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070070jmethodID WellKnownClasses::java_lang_ClassNotFoundException_init;
Elliott Hugheseac76672012-05-24 21:56:51 -070071jmethodID WellKnownClasses::java_lang_Daemons_requestHeapTrim;
72jmethodID WellKnownClasses::java_lang_Daemons_start;
Mathieu Chartiercef50f02014-12-09 17:38:52 -080073jmethodID WellKnownClasses::java_lang_Daemons_stop;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070074jmethodID WellKnownClasses::java_lang_Double_valueOf;
75jmethodID WellKnownClasses::java_lang_Float_valueOf;
76jmethodID WellKnownClasses::java_lang_Integer_valueOf;
77jmethodID WellKnownClasses::java_lang_Long_valueOf;
Elliott Hughesa4f94742012-05-29 16:28:38 -070078jmethodID WellKnownClasses::java_lang_ref_FinalizerReference_add;
79jmethodID WellKnownClasses::java_lang_ref_ReferenceQueue_add;
Brian Carlstromea46f952013-07-30 01:26:50 -070080jmethodID WellKnownClasses::java_lang_reflect_Proxy_invoke;
Ian Rogersef28b142012-11-30 14:22:18 -080081jmethodID WellKnownClasses::java_lang_Runtime_nativeLoad;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070082jmethodID WellKnownClasses::java_lang_Short_valueOf;
Jeff Hao848f70a2014-01-15 13:49:50 -080083jmethodID WellKnownClasses::java_lang_String_init;
84jmethodID WellKnownClasses::java_lang_String_init_B;
85jmethodID WellKnownClasses::java_lang_String_init_BI;
86jmethodID WellKnownClasses::java_lang_String_init_BII;
87jmethodID WellKnownClasses::java_lang_String_init_BIII;
88jmethodID WellKnownClasses::java_lang_String_init_BIIString;
89jmethodID WellKnownClasses::java_lang_String_init_BString;
90jmethodID WellKnownClasses::java_lang_String_init_BIICharset;
91jmethodID WellKnownClasses::java_lang_String_init_BCharset;
92jmethodID WellKnownClasses::java_lang_String_init_C;
93jmethodID WellKnownClasses::java_lang_String_init_CII;
94jmethodID WellKnownClasses::java_lang_String_init_IIC;
95jmethodID WellKnownClasses::java_lang_String_init_String;
96jmethodID WellKnownClasses::java_lang_String_init_StringBuffer;
97jmethodID WellKnownClasses::java_lang_String_init_III;
98jmethodID WellKnownClasses::java_lang_String_init_StringBuilder;
99jmethodID WellKnownClasses::java_lang_StringFactory_newEmptyString;
100jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromBytes_B;
101jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BI;
102jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BII;
103jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BIII;
104jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BIIString;
105jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BString;
106jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BIICharset;
107jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromBytes_BCharset;
108jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromChars_C;
109jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromChars_CII;
110jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromChars_IIC;
111jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromString;
112jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromStringBuffer;
113jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromCodePoints;
114jmethodID WellKnownClasses::java_lang_StringFactory_newStringFromStringBuilder;
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700115jmethodID WellKnownClasses::java_lang_System_runFinalization = nullptr;
Elliott Hugheseac76672012-05-24 21:56:51 -0700116jmethodID WellKnownClasses::java_lang_Thread_init;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700117jmethodID WellKnownClasses::java_lang_Thread_run;
Andreas Gampec8ccf682014-09-29 20:07:43 -0700118jmethodID WellKnownClasses::java_lang_Thread__UncaughtExceptionHandler_uncaughtException;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700119jmethodID WellKnownClasses::java_lang_ThreadGroup_removeThread;
Elliott Hughesaecb5f32013-03-28 08:27:38 -0700120jmethodID WellKnownClasses::java_nio_DirectByteBuffer_init;
Elliott Hugheseac76672012-05-24 21:56:51 -0700121jmethodID WellKnownClasses::org_apache_harmony_dalvik_ddmc_DdmServer_broadcast;
122jmethodID WellKnownClasses::org_apache_harmony_dalvik_ddmc_DdmServer_dispatch;
123
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -0700124jfieldID WellKnownClasses::dalvik_system_DexFile_cookie;
125jfieldID WellKnownClasses::dalvik_system_PathClassLoader_pathList;
126jfieldID WellKnownClasses::dalvik_system_DexPathList_dexElements;
Andreas Gampec8ccf682014-09-29 20:07:43 -0700127jfieldID WellKnownClasses::dalvik_system_DexPathList__Element_dexFile;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700128jfieldID WellKnownClasses::java_lang_Thread_daemon;
129jfieldID WellKnownClasses::java_lang_Thread_group;
130jfieldID WellKnownClasses::java_lang_Thread_lock;
131jfieldID WellKnownClasses::java_lang_Thread_name;
132jfieldID WellKnownClasses::java_lang_Thread_priority;
133jfieldID WellKnownClasses::java_lang_Thread_uncaughtHandler;
Anwar Ghuloum3c50a4b2013-06-21 13:05:23 -0700134jfieldID WellKnownClasses::java_lang_Thread_nativePeer;
Sebastien Hertze49e1952014-10-13 11:27:13 +0200135jfieldID WellKnownClasses::java_lang_ThreadGroup_groups;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700136jfieldID WellKnownClasses::java_lang_ThreadGroup_mainThreadGroup;
137jfieldID WellKnownClasses::java_lang_ThreadGroup_name;
Sebastien Hertze49e1952014-10-13 11:27:13 +0200138jfieldID WellKnownClasses::java_lang_ThreadGroup_parent;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700139jfieldID WellKnownClasses::java_lang_ThreadGroup_systemThreadGroup;
Brian Carlstrom34375312014-09-10 23:10:47 -0700140jfieldID WellKnownClasses::java_lang_Throwable_cause;
141jfieldID WellKnownClasses::java_lang_Throwable_detailMessage;
142jfieldID WellKnownClasses::java_lang_Throwable_stackTrace;
143jfieldID WellKnownClasses::java_lang_Throwable_stackState;
144jfieldID WellKnownClasses::java_lang_Throwable_suppressedExceptions;
Brian Carlstromea46f952013-07-30 01:26:50 -0700145jfieldID WellKnownClasses::java_lang_reflect_AbstractMethod_artMethod;
Elliott Hugheseac76672012-05-24 21:56:51 -0700146jfieldID WellKnownClasses::java_lang_reflect_Proxy_h;
Elliott Hughesaecb5f32013-03-28 08:27:38 -0700147jfieldID WellKnownClasses::java_nio_DirectByteBuffer_capacity;
148jfieldID WellKnownClasses::java_nio_DirectByteBuffer_effectiveDirectAddress;
Sebastien Hertze49e1952014-10-13 11:27:13 +0200149jfieldID WellKnownClasses::java_util_ArrayList_array;
150jfieldID WellKnownClasses::java_util_ArrayList_size;
Brian Carlstrom34375312014-09-10 23:10:47 -0700151jfieldID WellKnownClasses::java_util_Collections_EMPTY_LIST;
152jfieldID WellKnownClasses::libcore_util_EmptyArray_STACK_TRACE_ELEMENT;
Elliott Hugheseac76672012-05-24 21:56:51 -0700153jfieldID WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_data;
154jfieldID WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_length;
155jfieldID WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_offset;
156jfieldID WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_type;
157
158static jclass CacheClass(JNIEnv* env, const char* jni_class_name) {
159 ScopedLocalRef<jclass> c(env, env->FindClass(jni_class_name));
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700160 if (c.get() == nullptr) {
Elliott Hugheseac76672012-05-24 21:56:51 -0700161 LOG(FATAL) << "Couldn't find class: " << jni_class_name;
162 }
163 return reinterpret_cast<jclass>(env->NewGlobalRef(c.get()));
164}
165
Brian Carlstrom3c821c62014-09-10 10:08:37 -0700166static jfieldID CacheField(JNIEnv* env, jclass c, bool is_static,
167 const char* name, const char* signature) {
168 jfieldID fid = (is_static ?
169 env->GetStaticFieldID(c, name, signature) :
170 env->GetFieldID(c, name, signature));
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700171 if (fid == nullptr) {
Brian Carlstrom3c821c62014-09-10 10:08:37 -0700172 ScopedObjectAccess soa(env);
173 std::ostringstream os;
174 WellKnownClasses::ToClass(c)->DumpClass(os, mirror::Class::kDumpClassFullDetail);
175 LOG(FATAL) << "Couldn't find field \"" << name << "\" with signature \"" << signature << "\": "
176 << os.str();
Elliott Hugheseac76672012-05-24 21:56:51 -0700177 }
178 return fid;
179}
180
Brian Carlstrom3c821c62014-09-10 10:08:37 -0700181jmethodID CacheMethod(JNIEnv* env, jclass c, bool is_static,
182 const char* name, const char* signature) {
183 jmethodID mid = (is_static ?
184 env->GetStaticMethodID(c, name, signature) :
185 env->GetMethodID(c, name, signature));
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700186 if (mid == nullptr) {
Brian Carlstrom3c821c62014-09-10 10:08:37 -0700187 ScopedObjectAccess soa(env);
188 std::ostringstream os;
189 WellKnownClasses::ToClass(c)->DumpClass(os, mirror::Class::kDumpClassFullDetail);
190 LOG(FATAL) << "Couldn't find method \"" << name << "\" with signature \"" << signature << "\": "
191 << os.str();
Elliott Hugheseac76672012-05-24 21:56:51 -0700192 }
193 return mid;
194}
195
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700196static jmethodID CachePrimitiveBoxingMethod(JNIEnv* env, char prim_name, const char* boxed_name) {
197 ScopedLocalRef<jclass> boxed_class(env, env->FindClass(boxed_name));
198 return CacheMethod(env, boxed_class.get(), true, "valueOf",
199 StringPrintf("(%c)L%s;", prim_name, boxed_name).c_str());
200}
201
Brian Carlstromea46f952013-07-30 01:26:50 -0700202void WellKnownClasses::Init(JNIEnv* env) {
Elliott Hugheseac76672012-05-24 21:56:51 -0700203 com_android_dex_Dex = CacheClass(env, "com/android/dex/Dex");
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -0700204 dalvik_system_DexFile = CacheClass(env, "dalvik/system/DexFile");
205 dalvik_system_DexPathList = CacheClass(env, "dalvik/system/DexPathList");
Andreas Gampec8ccf682014-09-29 20:07:43 -0700206 dalvik_system_DexPathList__Element = CacheClass(env, "dalvik/system/DexPathList$Element");
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700207 dalvik_system_PathClassLoader = CacheClass(env, "dalvik/system/PathClassLoader");
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -0700208 java_lang_BootClassLoader = CacheClass(env, "java/lang/BootClassLoader");
Elliott Hugheseac76672012-05-24 21:56:51 -0700209 java_lang_ClassLoader = CacheClass(env, "java/lang/ClassLoader");
210 java_lang_ClassNotFoundException = CacheClass(env, "java/lang/ClassNotFoundException");
211 java_lang_Daemons = CacheClass(env, "java/lang/Daemons");
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800212 java_lang_Object = CacheClass(env, "java/lang/Object");
Mathieu Chartiera61894d2015-04-23 16:32:54 -0700213 java_lang_OutOfMemoryError = CacheClass(env, "java/lang/OutOfMemoryError");
Elliott Hugheseac76672012-05-24 21:56:51 -0700214 java_lang_Error = CacheClass(env, "java/lang/Error");
Mathieu Chartier66f19252012-09-18 08:57:04 -0700215 java_lang_reflect_AbstractMethod = CacheClass(env, "java/lang/reflect/AbstractMethod");
Brian Carlstromea46f952013-07-30 01:26:50 -0700216 java_lang_reflect_ArtMethod = CacheClass(env, "java/lang/reflect/ArtMethod");
217 java_lang_reflect_Constructor = CacheClass(env, "java/lang/reflect/Constructor");
218 java_lang_reflect_Field = CacheClass(env, "java/lang/reflect/Field");
219 java_lang_reflect_Method = CacheClass(env, "java/lang/reflect/Method");
Elliott Hugheseac76672012-05-24 21:56:51 -0700220 java_lang_reflect_Proxy = CacheClass(env, "java/lang/reflect/Proxy");
Elliott Hughesa4f94742012-05-29 16:28:38 -0700221 java_lang_RuntimeException = CacheClass(env, "java/lang/RuntimeException");
Ian Rogers120f1c72012-09-28 17:17:10 -0700222 java_lang_StackOverflowError = CacheClass(env, "java/lang/StackOverflowError");
Ian Rogersdd157d72014-05-15 14:47:50 -0700223 java_lang_String = CacheClass(env, "java/lang/String");
Jeff Hao848f70a2014-01-15 13:49:50 -0800224 java_lang_StringFactory = CacheClass(env, "java/lang/StringFactory");
Mathieu Chartier987ccff2013-07-08 11:05:21 -0700225 java_lang_System = CacheClass(env, "java/lang/System");
Elliott Hugheseac76672012-05-24 21:56:51 -0700226 java_lang_Thread = CacheClass(env, "java/lang/Thread");
Andreas Gampec8ccf682014-09-29 20:07:43 -0700227 java_lang_Thread__UncaughtExceptionHandler = CacheClass(env,
228 "java/lang/Thread$UncaughtExceptionHandler");
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700229 java_lang_ThreadGroup = CacheClass(env, "java/lang/ThreadGroup");
Elliott Hughesa4f94742012-05-29 16:28:38 -0700230 java_lang_Throwable = CacheClass(env, "java/lang/Throwable");
Elliott Hughesaecb5f32013-03-28 08:27:38 -0700231 java_nio_DirectByteBuffer = CacheClass(env, "java/nio/DirectByteBuffer");
Sebastien Hertze49e1952014-10-13 11:27:13 +0200232 java_util_ArrayList = CacheClass(env, "java/util/ArrayList");
Andreas Gampe7ea6f792014-07-14 16:21:44 -0700233 java_util_Collections = CacheClass(env, "java/util/Collections");
234 libcore_util_EmptyArray = CacheClass(env, "libcore/util/EmptyArray");
Elliott Hugheseac76672012-05-24 21:56:51 -0700235 org_apache_harmony_dalvik_ddmc_Chunk = CacheClass(env, "org/apache/harmony/dalvik/ddmc/Chunk");
236 org_apache_harmony_dalvik_ddmc_DdmServer = CacheClass(env, "org/apache/harmony/dalvik/ddmc/DdmServer");
237
238 com_android_dex_Dex_create = CacheMethod(env, com_android_dex_Dex, true, "create", "(Ljava/nio/ByteBuffer;)Lcom/android/dex/Dex;");
239 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 -0700240 java_lang_ClassLoader_loadClass = CacheMethod(env, java_lang_ClassLoader, false, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
Mathieu Chartier7664f5c2012-06-08 18:15:32 -0700241
Elliott Hugheseac76672012-05-24 21:56:51 -0700242 java_lang_Daemons_requestHeapTrim = CacheMethod(env, java_lang_Daemons, true, "requestHeapTrim", "()V");
243 java_lang_Daemons_start = CacheMethod(env, java_lang_Daemons, true, "start", "()V");
Mathieu Chartiercef50f02014-12-09 17:38:52 -0800244 java_lang_Daemons_stop = CacheMethod(env, java_lang_Daemons, true, "stop", "()V");
Elliott Hughesa4f94742012-05-29 16:28:38 -0700245
246 ScopedLocalRef<jclass> java_lang_ref_FinalizerReference(env, env->FindClass("java/lang/ref/FinalizerReference"));
247 java_lang_ref_FinalizerReference_add = CacheMethod(env, java_lang_ref_FinalizerReference.get(), true, "add", "(Ljava/lang/Object;)V");
248 ScopedLocalRef<jclass> java_lang_ref_ReferenceQueue(env, env->FindClass("java/lang/ref/ReferenceQueue"));
249 java_lang_ref_ReferenceQueue_add = CacheMethod(env, java_lang_ref_ReferenceQueue.get(), true, "add", "(Ljava/lang/ref/Reference;)V");
250
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700251 java_lang_reflect_Proxy_invoke = CacheMethod(env, java_lang_reflect_Proxy, true, "invoke", "(Ljava/lang/reflect/Proxy;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;");
Elliott Hugheseac76672012-05-24 21:56:51 -0700252 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 -0700253 java_lang_Thread_run = CacheMethod(env, java_lang_Thread, false, "run", "()V");
Andreas Gampec8ccf682014-09-29 20:07:43 -0700254 java_lang_Thread__UncaughtExceptionHandler_uncaughtException = CacheMethod(env, java_lang_Thread__UncaughtExceptionHandler, false, "uncaughtException", "(Ljava/lang/Thread;Ljava/lang/Throwable;)V");
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700255 java_lang_ThreadGroup_removeThread = CacheMethod(env, java_lang_ThreadGroup, false, "removeThread", "(Ljava/lang/Thread;)V");
Elliott Hughesb5681212013-03-29 17:29:22 -0700256 java_nio_DirectByteBuffer_init = CacheMethod(env, java_nio_DirectByteBuffer, false, "<init>", "(JI)V");
Elliott Hugheseac76672012-05-24 21:56:51 -0700257 org_apache_harmony_dalvik_ddmc_DdmServer_broadcast = CacheMethod(env, org_apache_harmony_dalvik_ddmc_DdmServer, true, "broadcast", "(I)V");
258 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;");
259
Jeff Hao848f70a2014-01-15 13:49:50 -0800260 java_lang_String_init = CacheMethod(env, java_lang_String, false, "<init>", "()V");
261 java_lang_String_init_B = CacheMethod(env, java_lang_String, false, "<init>", "([B)V");
262 java_lang_String_init_BI = CacheMethod(env, java_lang_String, false, "<init>", "([BI)V");
263 java_lang_String_init_BII = CacheMethod(env, java_lang_String, false, "<init>", "([BII)V");
264 java_lang_String_init_BIII = CacheMethod(env, java_lang_String, false, "<init>", "([BIII)V");
265 java_lang_String_init_BIIString = CacheMethod(env, java_lang_String, false, "<init>",
266 "([BIILjava/lang/String;)V");
267 java_lang_String_init_BString = CacheMethod(env, java_lang_String, false, "<init>",
268 "([BLjava/lang/String;)V");
269 java_lang_String_init_BIICharset = CacheMethod(env, java_lang_String, false, "<init>",
270 "([BIILjava/nio/charset/Charset;)V");
271 java_lang_String_init_BCharset = CacheMethod(env, java_lang_String, false, "<init>",
272 "([BLjava/nio/charset/Charset;)V");
273 java_lang_String_init_C = CacheMethod(env, java_lang_String, false, "<init>", "([C)V");
274 java_lang_String_init_CII = CacheMethod(env, java_lang_String, false, "<init>", "([CII)V");
275 java_lang_String_init_IIC = CacheMethod(env, java_lang_String, false, "<init>", "(II[C)V");
276 java_lang_String_init_String = CacheMethod(env, java_lang_String, false, "<init>",
277 "(Ljava/lang/String;)V");
278 java_lang_String_init_StringBuffer = CacheMethod(env, java_lang_String, false, "<init>",
279 "(Ljava/lang/StringBuffer;)V");
280 java_lang_String_init_III = CacheMethod(env, java_lang_String, false, "<init>", "([III)V");
281 java_lang_String_init_StringBuilder = CacheMethod(env, java_lang_String, false, "<init>",
282 "(Ljava/lang/StringBuilder;)V");
283 java_lang_StringFactory_newEmptyString = CacheMethod(env, java_lang_StringFactory, true,
284 "newEmptyString", "()Ljava/lang/String;");
285 java_lang_StringFactory_newStringFromBytes_B = CacheMethod(env, java_lang_StringFactory, true,
286 "newStringFromBytes", "([B)Ljava/lang/String;");
287 java_lang_StringFactory_newStringFromBytes_BI = CacheMethod(env, java_lang_StringFactory, true,
288 "newStringFromBytes", "([BI)Ljava/lang/String;");
289 java_lang_StringFactory_newStringFromBytes_BII = CacheMethod(env, java_lang_StringFactory, true,
290 "newStringFromBytes", "([BII)Ljava/lang/String;");
291 java_lang_StringFactory_newStringFromBytes_BIII = CacheMethod(env, java_lang_StringFactory, true,
292 "newStringFromBytes", "([BIII)Ljava/lang/String;");
293 java_lang_StringFactory_newStringFromBytes_BIIString = CacheMethod(env, java_lang_StringFactory,
294 true, "newStringFromBytes", "([BIILjava/lang/String;)Ljava/lang/String;");
295 java_lang_StringFactory_newStringFromBytes_BString = CacheMethod(env, java_lang_StringFactory,
296 true, "newStringFromBytes", "([BLjava/lang/String;)Ljava/lang/String;");
297 java_lang_StringFactory_newStringFromBytes_BIICharset = CacheMethod(env, java_lang_StringFactory,
298 true, "newStringFromBytes", "([BIILjava/nio/charset/Charset;)Ljava/lang/String;");
299 java_lang_StringFactory_newStringFromBytes_BCharset = CacheMethod(env, java_lang_StringFactory,
300 true, "newStringFromBytes", "([BLjava/nio/charset/Charset;)Ljava/lang/String;");
301 java_lang_StringFactory_newStringFromChars_C = CacheMethod(env, java_lang_StringFactory, true,
302 "newStringFromChars", "([C)Ljava/lang/String;");
303 java_lang_StringFactory_newStringFromChars_CII = CacheMethod(env, java_lang_StringFactory, true,
304 "newStringFromChars", "([CII)Ljava/lang/String;");
305 java_lang_StringFactory_newStringFromChars_IIC = CacheMethod(env, java_lang_StringFactory, true,
306 "newStringFromChars", "(II[C)Ljava/lang/String;");
307 java_lang_StringFactory_newStringFromString = CacheMethod(env, java_lang_StringFactory, true,
308 "newStringFromString", "(Ljava/lang/String;)Ljava/lang/String;");
309 java_lang_StringFactory_newStringFromStringBuffer = CacheMethod(env, java_lang_StringFactory,
310 true, "newStringFromStringBuffer", "(Ljava/lang/StringBuffer;)Ljava/lang/String;");
311 java_lang_StringFactory_newStringFromCodePoints = CacheMethod(env, java_lang_StringFactory,
312 true, "newStringFromCodePoints", "([III)Ljava/lang/String;");
313 java_lang_StringFactory_newStringFromStringBuilder = CacheMethod(env, java_lang_StringFactory,
314 true, "newStringFromStringBuilder", "(Ljava/lang/StringBuilder;)Ljava/lang/String;");
315
Andreas Gampe324b9bb2015-02-23 16:33:22 -0800316 dalvik_system_DexFile_cookie = CacheField(env, dalvik_system_DexFile, false, "mCookie", "Ljava/lang/Object;");
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -0700317 dalvik_system_PathClassLoader_pathList = CacheField(env, dalvik_system_PathClassLoader, false, "pathList", "Ldalvik/system/DexPathList;");
318 dalvik_system_DexPathList_dexElements = CacheField(env, dalvik_system_DexPathList, false, "dexElements", "[Ldalvik/system/DexPathList$Element;");
Andreas Gampec8ccf682014-09-29 20:07:43 -0700319 dalvik_system_DexPathList__Element_dexFile = CacheField(env, dalvik_system_DexPathList__Element, false, "dexFile", "Ldalvik/system/DexFile;");
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700320 java_lang_Thread_daemon = CacheField(env, java_lang_Thread, false, "daemon", "Z");
321 java_lang_Thread_group = CacheField(env, java_lang_Thread, false, "group", "Ljava/lang/ThreadGroup;");
Elliott Hughesc5dc2ff2013-01-09 13:44:30 -0800322 java_lang_Thread_lock = CacheField(env, java_lang_Thread, false, "lock", "Ljava/lang/Object;");
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700323 java_lang_Thread_name = CacheField(env, java_lang_Thread, false, "name", "Ljava/lang/String;");
324 java_lang_Thread_priority = CacheField(env, java_lang_Thread, false, "priority", "I");
325 java_lang_Thread_uncaughtHandler = CacheField(env, java_lang_Thread, false, "uncaughtHandler", "Ljava/lang/Thread$UncaughtExceptionHandler;");
Ian Rogersef7d42f2014-01-06 12:55:46 -0800326 java_lang_Thread_nativePeer = CacheField(env, java_lang_Thread, false, "nativePeer", "J");
Sebastien Hertze49e1952014-10-13 11:27:13 +0200327 java_lang_ThreadGroup_groups = CacheField(env, java_lang_ThreadGroup, false, "groups", "Ljava/util/List;");
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700328 java_lang_ThreadGroup_mainThreadGroup = CacheField(env, java_lang_ThreadGroup, true, "mainThreadGroup", "Ljava/lang/ThreadGroup;");
329 java_lang_ThreadGroup_name = CacheField(env, java_lang_ThreadGroup, false, "name", "Ljava/lang/String;");
Sebastien Hertze49e1952014-10-13 11:27:13 +0200330 java_lang_ThreadGroup_parent = CacheField(env, java_lang_ThreadGroup, false, "parent", "Ljava/lang/ThreadGroup;");
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700331 java_lang_ThreadGroup_systemThreadGroup = CacheField(env, java_lang_ThreadGroup, true, "systemThreadGroup", "Ljava/lang/ThreadGroup;");
Brian Carlstrom34375312014-09-10 23:10:47 -0700332 java_lang_Throwable_cause = CacheField(env, java_lang_Throwable, false, "cause", "Ljava/lang/Throwable;");
333 java_lang_Throwable_detailMessage = CacheField(env, java_lang_Throwable, false, "detailMessage", "Ljava/lang/String;");
334 java_lang_Throwable_stackTrace = CacheField(env, java_lang_Throwable, false, "stackTrace", "[Ljava/lang/StackTraceElement;");
335 java_lang_Throwable_stackState = CacheField(env, java_lang_Throwable, false, "stackState", "Ljava/lang/Object;");
336 java_lang_Throwable_suppressedExceptions = CacheField(env, java_lang_Throwable, false, "suppressedExceptions", "Ljava/util/List;");
Brian Carlstromea46f952013-07-30 01:26:50 -0700337 java_lang_reflect_AbstractMethod_artMethod = CacheField(env, java_lang_reflect_AbstractMethod, false, "artMethod", "Ljava/lang/reflect/ArtMethod;");
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700338 java_lang_reflect_Proxy_h = CacheField(env, java_lang_reflect_Proxy, false, "h", "Ljava/lang/reflect/InvocationHandler;");
Elliott Hughesaecb5f32013-03-28 08:27:38 -0700339 java_nio_DirectByteBuffer_capacity = CacheField(env, java_nio_DirectByteBuffer, false, "capacity", "I");
Elliott Hughes2e8a4fc2013-03-29 16:33:52 -0700340 java_nio_DirectByteBuffer_effectiveDirectAddress = CacheField(env, java_nio_DirectByteBuffer, false, "effectiveDirectAddress", "J");
Sebastien Hertze49e1952014-10-13 11:27:13 +0200341 java_util_ArrayList_array = CacheField(env, java_util_ArrayList, false, "array", "[Ljava/lang/Object;");
342 java_util_ArrayList_size = CacheField(env, java_util_ArrayList, false, "size", "I");
Brian Carlstrom34375312014-09-10 23:10:47 -0700343 java_util_Collections_EMPTY_LIST = CacheField(env, java_util_Collections, true, "EMPTY_LIST", "Ljava/util/List;");
344 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 +0200345 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 -0700346 org_apache_harmony_dalvik_ddmc_Chunk_length = CacheField(env, org_apache_harmony_dalvik_ddmc_Chunk, false, "length", "I");
347 org_apache_harmony_dalvik_ddmc_Chunk_offset = CacheField(env, org_apache_harmony_dalvik_ddmc_Chunk, false, "offset", "I");
348 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 -0700349
350 java_lang_Boolean_valueOf = CachePrimitiveBoxingMethod(env, 'Z', "java/lang/Boolean");
351 java_lang_Byte_valueOf = CachePrimitiveBoxingMethod(env, 'B', "java/lang/Byte");
352 java_lang_Character_valueOf = CachePrimitiveBoxingMethod(env, 'C', "java/lang/Character");
353 java_lang_Double_valueOf = CachePrimitiveBoxingMethod(env, 'D', "java/lang/Double");
354 java_lang_Float_valueOf = CachePrimitiveBoxingMethod(env, 'F', "java/lang/Float");
355 java_lang_Integer_valueOf = CachePrimitiveBoxingMethod(env, 'I', "java/lang/Integer");
356 java_lang_Long_valueOf = CachePrimitiveBoxingMethod(env, 'J', "java/lang/Long");
357 java_lang_Short_valueOf = CachePrimitiveBoxingMethod(env, 'S', "java/lang/Short");
Jeff Hao848f70a2014-01-15 13:49:50 -0800358
359 Thread::Current()->InitStringEntryPoints();
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700360}
361
Ian Rogersef28b142012-11-30 14:22:18 -0800362void WellKnownClasses::LateInit(JNIEnv* env) {
363 ScopedLocalRef<jclass> java_lang_Runtime(env, env->FindClass("java/lang/Runtime"));
Dmitriy Ivanov785049f2014-07-18 10:08:57 -0700364 java_lang_Runtime_nativeLoad = CacheMethod(env, java_lang_Runtime.get(), true, "nativeLoad", "(Ljava/lang/String;Ljava/lang/ClassLoader;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;");
Ian Rogersef28b142012-11-30 14:22:18 -0800365}
366
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800367mirror::Class* WellKnownClasses::ToClass(jclass global_jclass) {
368 return reinterpret_cast<mirror::Class*>(Thread::Current()->DecodeJObject(global_jclass));
Elliott Hugheseac76672012-05-24 21:56:51 -0700369}
370
Jeff Hao848f70a2014-01-15 13:49:50 -0800371jmethodID WellKnownClasses::StringInitToStringFactoryMethodID(jmethodID string_init) {
372 // TODO: Prioritize ordering.
373 if (string_init == java_lang_String_init) {
374 return java_lang_StringFactory_newEmptyString;
375 } else if (string_init == java_lang_String_init_B) {
376 return java_lang_StringFactory_newStringFromBytes_B;
377 } else if (string_init == java_lang_String_init_BI) {
378 return java_lang_StringFactory_newStringFromBytes_BI;
379 } else if (string_init == java_lang_String_init_BII) {
380 return java_lang_StringFactory_newStringFromBytes_BII;
381 } else if (string_init == java_lang_String_init_BIII) {
382 return java_lang_StringFactory_newStringFromBytes_BIII;
383 } else if (string_init == java_lang_String_init_BIIString) {
384 return java_lang_StringFactory_newStringFromBytes_BIIString;
385 } else if (string_init == java_lang_String_init_BString) {
386 return java_lang_StringFactory_newStringFromBytes_BString;
387 } else if (string_init == java_lang_String_init_BIICharset) {
388 return java_lang_StringFactory_newStringFromBytes_BIICharset;
389 } else if (string_init == java_lang_String_init_BCharset) {
390 return java_lang_StringFactory_newStringFromBytes_BCharset;
391 } else if (string_init == java_lang_String_init_C) {
392 return java_lang_StringFactory_newStringFromChars_C;
393 } else if (string_init == java_lang_String_init_CII) {
394 return java_lang_StringFactory_newStringFromChars_CII;
395 } else if (string_init == java_lang_String_init_IIC) {
396 return java_lang_StringFactory_newStringFromChars_IIC;
397 } else if (string_init == java_lang_String_init_String) {
398 return java_lang_StringFactory_newStringFromString;
399 } else if (string_init == java_lang_String_init_StringBuffer) {
400 return java_lang_StringFactory_newStringFromStringBuffer;
401 } else if (string_init == java_lang_String_init_III) {
402 return java_lang_StringFactory_newStringFromCodePoints;
403 } else if (string_init == java_lang_String_init_StringBuilder) {
404 return java_lang_StringFactory_newStringFromStringBuilder;
405 }
406 LOG(FATAL) << "Could not find StringFactory method for String.<init>";
407 return nullptr;
408}
409
Elliott Hugheseac76672012-05-24 21:56:51 -0700410} // namespace art