blob: 4a3c3ec5498ed0674e807053d6eb1fec70be3974 [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
Elliott Hughes07ed66b2012-12-12 18:34:25 -080021#include "base/logging.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080022#include "mirror/class.h"
Elliott Hugheseac76672012-05-24 21:56:51 -070023#include "ScopedLocalRef.h"
Brian Carlstrom3c821c62014-09-10 10:08:37 -070024#include "scoped_thread_state_change.h"
Brian Carlstroma3d27182013-11-05 23:22:27 -080025#include "thread-inl.h"
Elliott Hugheseac76672012-05-24 21:56:51 -070026
27namespace art {
28
29jclass WellKnownClasses::com_android_dex_Dex;
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -070030jclass WellKnownClasses::dalvik_system_DexFile;
31jclass WellKnownClasses::dalvik_system_DexPathList;
Andreas Gampec8ccf682014-09-29 20:07:43 -070032jclass WellKnownClasses::dalvik_system_DexPathList__Element;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070033jclass WellKnownClasses::dalvik_system_PathClassLoader;
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -070034jclass WellKnownClasses::java_lang_BootClassLoader;
Elliott Hugheseac76672012-05-24 21:56:51 -070035jclass WellKnownClasses::java_lang_ClassLoader;
36jclass WellKnownClasses::java_lang_ClassNotFoundException;
37jclass WellKnownClasses::java_lang_Daemons;
38jclass WellKnownClasses::java_lang_Error;
Ian Rogersaf6e67a2013-01-16 08:38:37 -080039jclass WellKnownClasses::java_lang_Object;
Mathieu Chartier66f19252012-09-18 08:57:04 -070040jclass WellKnownClasses::java_lang_reflect_AbstractMethod;
Brian Carlstromea46f952013-07-30 01:26:50 -070041jclass WellKnownClasses::java_lang_reflect_ArtMethod;
42jclass WellKnownClasses::java_lang_reflect_Constructor;
43jclass WellKnownClasses::java_lang_reflect_Field;
44jclass WellKnownClasses::java_lang_reflect_Method;
Elliott Hugheseac76672012-05-24 21:56:51 -070045jclass WellKnownClasses::java_lang_reflect_Proxy;
Elliott Hughesa4f94742012-05-29 16:28:38 -070046jclass WellKnownClasses::java_lang_RuntimeException;
Ian Rogers120f1c72012-09-28 17:17:10 -070047jclass WellKnownClasses::java_lang_StackOverflowError;
Ian Rogersdd157d72014-05-15 14:47:50 -070048jclass WellKnownClasses::java_lang_String;
Mathieu Chartier987ccff2013-07-08 11:05:21 -070049jclass WellKnownClasses::java_lang_System;
Elliott Hugheseac76672012-05-24 21:56:51 -070050jclass WellKnownClasses::java_lang_Thread;
Andreas Gampec8ccf682014-09-29 20:07:43 -070051jclass WellKnownClasses::java_lang_Thread__UncaughtExceptionHandler;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -070052jclass WellKnownClasses::java_lang_ThreadGroup;
Elliott Hughesa4f94742012-05-29 16:28:38 -070053jclass WellKnownClasses::java_lang_Throwable;
Elliott Hughesaecb5f32013-03-28 08:27:38 -070054jclass WellKnownClasses::java_nio_DirectByteBuffer;
Andreas Gampe7ea6f792014-07-14 16:21:44 -070055jclass WellKnownClasses::java_util_Collections;
56jclass WellKnownClasses::libcore_util_EmptyArray;
Elliott Hugheseac76672012-05-24 21:56:51 -070057jclass WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk;
58jclass WellKnownClasses::org_apache_harmony_dalvik_ddmc_DdmServer;
59
60jmethodID WellKnownClasses::com_android_dex_Dex_create;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070061jmethodID WellKnownClasses::java_lang_Boolean_valueOf;
62jmethodID WellKnownClasses::java_lang_Byte_valueOf;
63jmethodID WellKnownClasses::java_lang_Character_valueOf;
Elliott Hughesa4f94742012-05-29 16:28:38 -070064jmethodID WellKnownClasses::java_lang_ClassLoader_loadClass;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070065jmethodID WellKnownClasses::java_lang_ClassNotFoundException_init;
Mathieu Chartier7664f5c2012-06-08 18:15:32 -070066jmethodID WellKnownClasses::java_lang_Daemons_requestGC;
Elliott Hugheseac76672012-05-24 21:56:51 -070067jmethodID WellKnownClasses::java_lang_Daemons_requestHeapTrim;
68jmethodID WellKnownClasses::java_lang_Daemons_start;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070069jmethodID WellKnownClasses::java_lang_Double_valueOf;
70jmethodID WellKnownClasses::java_lang_Float_valueOf;
71jmethodID WellKnownClasses::java_lang_Integer_valueOf;
72jmethodID WellKnownClasses::java_lang_Long_valueOf;
Elliott Hughesa4f94742012-05-29 16:28:38 -070073jmethodID WellKnownClasses::java_lang_ref_FinalizerReference_add;
74jmethodID WellKnownClasses::java_lang_ref_ReferenceQueue_add;
Brian Carlstromea46f952013-07-30 01:26:50 -070075jmethodID WellKnownClasses::java_lang_reflect_Proxy_invoke;
Ian Rogersef28b142012-11-30 14:22:18 -080076jmethodID WellKnownClasses::java_lang_Runtime_nativeLoad;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070077jmethodID WellKnownClasses::java_lang_Short_valueOf;
Mathieu Chartier987ccff2013-07-08 11:05:21 -070078jmethodID WellKnownClasses::java_lang_System_runFinalization = NULL;
Elliott Hugheseac76672012-05-24 21:56:51 -070079jmethodID WellKnownClasses::java_lang_Thread_init;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -070080jmethodID WellKnownClasses::java_lang_Thread_run;
Andreas Gampec8ccf682014-09-29 20:07:43 -070081jmethodID WellKnownClasses::java_lang_Thread__UncaughtExceptionHandler_uncaughtException;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -070082jmethodID WellKnownClasses::java_lang_ThreadGroup_removeThread;
Elliott Hughesaecb5f32013-03-28 08:27:38 -070083jmethodID WellKnownClasses::java_nio_DirectByteBuffer_init;
Elliott Hugheseac76672012-05-24 21:56:51 -070084jmethodID WellKnownClasses::org_apache_harmony_dalvik_ddmc_DdmServer_broadcast;
85jmethodID WellKnownClasses::org_apache_harmony_dalvik_ddmc_DdmServer_dispatch;
86
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -070087jfieldID WellKnownClasses::dalvik_system_DexFile_cookie;
88jfieldID WellKnownClasses::dalvik_system_PathClassLoader_pathList;
89jfieldID WellKnownClasses::dalvik_system_DexPathList_dexElements;
Andreas Gampec8ccf682014-09-29 20:07:43 -070090jfieldID WellKnownClasses::dalvik_system_DexPathList__Element_dexFile;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -070091jfieldID WellKnownClasses::java_lang_Thread_daemon;
92jfieldID WellKnownClasses::java_lang_Thread_group;
93jfieldID WellKnownClasses::java_lang_Thread_lock;
94jfieldID WellKnownClasses::java_lang_Thread_name;
95jfieldID WellKnownClasses::java_lang_Thread_priority;
96jfieldID WellKnownClasses::java_lang_Thread_uncaughtHandler;
Anwar Ghuloum3c50a4b2013-06-21 13:05:23 -070097jfieldID WellKnownClasses::java_lang_Thread_nativePeer;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -070098jfieldID WellKnownClasses::java_lang_ThreadGroup_mainThreadGroup;
99jfieldID WellKnownClasses::java_lang_ThreadGroup_name;
100jfieldID WellKnownClasses::java_lang_ThreadGroup_systemThreadGroup;
Brian Carlstrom34375312014-09-10 23:10:47 -0700101jfieldID WellKnownClasses::java_lang_Throwable_cause;
102jfieldID WellKnownClasses::java_lang_Throwable_detailMessage;
103jfieldID WellKnownClasses::java_lang_Throwable_stackTrace;
104jfieldID WellKnownClasses::java_lang_Throwable_stackState;
105jfieldID WellKnownClasses::java_lang_Throwable_suppressedExceptions;
Brian Carlstromea46f952013-07-30 01:26:50 -0700106jfieldID WellKnownClasses::java_lang_reflect_AbstractMethod_artMethod;
107jfieldID WellKnownClasses::java_lang_reflect_Field_artField;
Elliott Hugheseac76672012-05-24 21:56:51 -0700108jfieldID WellKnownClasses::java_lang_reflect_Proxy_h;
Elliott Hughesaecb5f32013-03-28 08:27:38 -0700109jfieldID WellKnownClasses::java_nio_DirectByteBuffer_capacity;
110jfieldID WellKnownClasses::java_nio_DirectByteBuffer_effectiveDirectAddress;
Brian Carlstrom34375312014-09-10 23:10:47 -0700111jfieldID WellKnownClasses::java_util_Collections_EMPTY_LIST;
112jfieldID WellKnownClasses::libcore_util_EmptyArray_STACK_TRACE_ELEMENT;
Elliott Hugheseac76672012-05-24 21:56:51 -0700113jfieldID WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_data;
114jfieldID WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_length;
115jfieldID WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_offset;
116jfieldID WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_type;
117
118static jclass CacheClass(JNIEnv* env, const char* jni_class_name) {
119 ScopedLocalRef<jclass> c(env, env->FindClass(jni_class_name));
120 if (c.get() == NULL) {
121 LOG(FATAL) << "Couldn't find class: " << jni_class_name;
122 }
123 return reinterpret_cast<jclass>(env->NewGlobalRef(c.get()));
124}
125
Brian Carlstrom3c821c62014-09-10 10:08:37 -0700126static jfieldID CacheField(JNIEnv* env, jclass c, bool is_static,
127 const char* name, const char* signature) {
128 jfieldID fid = (is_static ?
129 env->GetStaticFieldID(c, name, signature) :
130 env->GetFieldID(c, name, signature));
Elliott Hugheseac76672012-05-24 21:56:51 -0700131 if (fid == NULL) {
Brian Carlstrom3c821c62014-09-10 10:08:37 -0700132 ScopedObjectAccess soa(env);
133 std::ostringstream os;
134 WellKnownClasses::ToClass(c)->DumpClass(os, mirror::Class::kDumpClassFullDetail);
135 LOG(FATAL) << "Couldn't find field \"" << name << "\" with signature \"" << signature << "\": "
136 << os.str();
Elliott Hugheseac76672012-05-24 21:56:51 -0700137 }
138 return fid;
139}
140
Brian Carlstrom3c821c62014-09-10 10:08:37 -0700141jmethodID CacheMethod(JNIEnv* env, jclass c, bool is_static,
142 const char* name, const char* signature) {
143 jmethodID mid = (is_static ?
144 env->GetStaticMethodID(c, name, signature) :
145 env->GetMethodID(c, name, signature));
Elliott Hugheseac76672012-05-24 21:56:51 -0700146 if (mid == NULL) {
Brian Carlstrom3c821c62014-09-10 10:08:37 -0700147 ScopedObjectAccess soa(env);
148 std::ostringstream os;
149 WellKnownClasses::ToClass(c)->DumpClass(os, mirror::Class::kDumpClassFullDetail);
150 LOG(FATAL) << "Couldn't find method \"" << name << "\" with signature \"" << signature << "\": "
151 << os.str();
Elliott Hugheseac76672012-05-24 21:56:51 -0700152 }
153 return mid;
154}
155
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700156static jmethodID CachePrimitiveBoxingMethod(JNIEnv* env, char prim_name, const char* boxed_name) {
157 ScopedLocalRef<jclass> boxed_class(env, env->FindClass(boxed_name));
158 return CacheMethod(env, boxed_class.get(), true, "valueOf",
159 StringPrintf("(%c)L%s;", prim_name, boxed_name).c_str());
160}
161
Brian Carlstromea46f952013-07-30 01:26:50 -0700162void WellKnownClasses::Init(JNIEnv* env) {
Elliott Hugheseac76672012-05-24 21:56:51 -0700163 com_android_dex_Dex = CacheClass(env, "com/android/dex/Dex");
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -0700164 dalvik_system_DexFile = CacheClass(env, "dalvik/system/DexFile");
165 dalvik_system_DexPathList = CacheClass(env, "dalvik/system/DexPathList");
Andreas Gampec8ccf682014-09-29 20:07:43 -0700166 dalvik_system_DexPathList__Element = CacheClass(env, "dalvik/system/DexPathList$Element");
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700167 dalvik_system_PathClassLoader = CacheClass(env, "dalvik/system/PathClassLoader");
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -0700168 java_lang_BootClassLoader = CacheClass(env, "java/lang/BootClassLoader");
Elliott Hugheseac76672012-05-24 21:56:51 -0700169 java_lang_ClassLoader = CacheClass(env, "java/lang/ClassLoader");
170 java_lang_ClassNotFoundException = CacheClass(env, "java/lang/ClassNotFoundException");
171 java_lang_Daemons = CacheClass(env, "java/lang/Daemons");
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800172 java_lang_Object = CacheClass(env, "java/lang/Object");
Elliott Hugheseac76672012-05-24 21:56:51 -0700173 java_lang_Error = CacheClass(env, "java/lang/Error");
Mathieu Chartier66f19252012-09-18 08:57:04 -0700174 java_lang_reflect_AbstractMethod = CacheClass(env, "java/lang/reflect/AbstractMethod");
Brian Carlstromea46f952013-07-30 01:26:50 -0700175 java_lang_reflect_ArtMethod = CacheClass(env, "java/lang/reflect/ArtMethod");
176 java_lang_reflect_Constructor = CacheClass(env, "java/lang/reflect/Constructor");
177 java_lang_reflect_Field = CacheClass(env, "java/lang/reflect/Field");
178 java_lang_reflect_Method = CacheClass(env, "java/lang/reflect/Method");
Elliott Hugheseac76672012-05-24 21:56:51 -0700179 java_lang_reflect_Proxy = CacheClass(env, "java/lang/reflect/Proxy");
Elliott Hughesa4f94742012-05-29 16:28:38 -0700180 java_lang_RuntimeException = CacheClass(env, "java/lang/RuntimeException");
Ian Rogers120f1c72012-09-28 17:17:10 -0700181 java_lang_StackOverflowError = CacheClass(env, "java/lang/StackOverflowError");
Ian Rogersdd157d72014-05-15 14:47:50 -0700182 java_lang_String = CacheClass(env, "java/lang/String");
Mathieu Chartier987ccff2013-07-08 11:05:21 -0700183 java_lang_System = CacheClass(env, "java/lang/System");
Elliott Hugheseac76672012-05-24 21:56:51 -0700184 java_lang_Thread = CacheClass(env, "java/lang/Thread");
Andreas Gampec8ccf682014-09-29 20:07:43 -0700185 java_lang_Thread__UncaughtExceptionHandler = CacheClass(env,
186 "java/lang/Thread$UncaughtExceptionHandler");
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700187 java_lang_ThreadGroup = CacheClass(env, "java/lang/ThreadGroup");
Elliott Hughesa4f94742012-05-29 16:28:38 -0700188 java_lang_Throwable = CacheClass(env, "java/lang/Throwable");
Elliott Hughesaecb5f32013-03-28 08:27:38 -0700189 java_nio_DirectByteBuffer = CacheClass(env, "java/nio/DirectByteBuffer");
Andreas Gampe7ea6f792014-07-14 16:21:44 -0700190 java_util_Collections = CacheClass(env, "java/util/Collections");
191 libcore_util_EmptyArray = CacheClass(env, "libcore/util/EmptyArray");
Elliott Hugheseac76672012-05-24 21:56:51 -0700192 org_apache_harmony_dalvik_ddmc_Chunk = CacheClass(env, "org/apache/harmony/dalvik/ddmc/Chunk");
193 org_apache_harmony_dalvik_ddmc_DdmServer = CacheClass(env, "org/apache/harmony/dalvik/ddmc/DdmServer");
194
195 com_android_dex_Dex_create = CacheMethod(env, com_android_dex_Dex, true, "create", "(Ljava/nio/ByteBuffer;)Lcom/android/dex/Dex;");
196 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 -0700197 java_lang_ClassLoader_loadClass = CacheMethod(env, java_lang_ClassLoader, false, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
Mathieu Chartier7664f5c2012-06-08 18:15:32 -0700198
199 java_lang_Daemons_requestGC = CacheMethod(env, java_lang_Daemons, true, "requestGC", "()V");
Elliott Hugheseac76672012-05-24 21:56:51 -0700200 java_lang_Daemons_requestHeapTrim = CacheMethod(env, java_lang_Daemons, true, "requestHeapTrim", "()V");
201 java_lang_Daemons_start = CacheMethod(env, java_lang_Daemons, true, "start", "()V");
Elliott Hughesa4f94742012-05-29 16:28:38 -0700202
203 ScopedLocalRef<jclass> java_lang_ref_FinalizerReference(env, env->FindClass("java/lang/ref/FinalizerReference"));
204 java_lang_ref_FinalizerReference_add = CacheMethod(env, java_lang_ref_FinalizerReference.get(), true, "add", "(Ljava/lang/Object;)V");
205 ScopedLocalRef<jclass> java_lang_ref_ReferenceQueue(env, env->FindClass("java/lang/ref/ReferenceQueue"));
206 java_lang_ref_ReferenceQueue_add = CacheMethod(env, java_lang_ref_ReferenceQueue.get(), true, "add", "(Ljava/lang/ref/Reference;)V");
207
Brian Carlstromea46f952013-07-30 01:26:50 -0700208 java_lang_reflect_Proxy_invoke = CacheMethod(env, java_lang_reflect_Proxy, true, "invoke", "(Ljava/lang/reflect/Proxy;Ljava/lang/reflect/ArtMethod;[Ljava/lang/Object;)Ljava/lang/Object;");
Elliott Hugheseac76672012-05-24 21:56:51 -0700209 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 -0700210 java_lang_Thread_run = CacheMethod(env, java_lang_Thread, false, "run", "()V");
Andreas Gampec8ccf682014-09-29 20:07:43 -0700211 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 -0700212 java_lang_ThreadGroup_removeThread = CacheMethod(env, java_lang_ThreadGroup, false, "removeThread", "(Ljava/lang/Thread;)V");
Elliott Hughesb5681212013-03-29 17:29:22 -0700213 java_nio_DirectByteBuffer_init = CacheMethod(env, java_nio_DirectByteBuffer, false, "<init>", "(JI)V");
Elliott Hugheseac76672012-05-24 21:56:51 -0700214 org_apache_harmony_dalvik_ddmc_DdmServer_broadcast = CacheMethod(env, org_apache_harmony_dalvik_ddmc_DdmServer, true, "broadcast", "(I)V");
215 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;");
216
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -0700217 dalvik_system_DexFile_cookie = CacheField(env, dalvik_system_DexFile, false, "mCookie", "J");
218 dalvik_system_PathClassLoader_pathList = CacheField(env, dalvik_system_PathClassLoader, false, "pathList", "Ldalvik/system/DexPathList;");
219 dalvik_system_DexPathList_dexElements = CacheField(env, dalvik_system_DexPathList, false, "dexElements", "[Ldalvik/system/DexPathList$Element;");
Andreas Gampec8ccf682014-09-29 20:07:43 -0700220 dalvik_system_DexPathList__Element_dexFile = CacheField(env, dalvik_system_DexPathList__Element, false, "dexFile", "Ldalvik/system/DexFile;");
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700221 java_lang_Thread_daemon = CacheField(env, java_lang_Thread, false, "daemon", "Z");
222 java_lang_Thread_group = CacheField(env, java_lang_Thread, false, "group", "Ljava/lang/ThreadGroup;");
Elliott Hughesc5dc2ff2013-01-09 13:44:30 -0800223 java_lang_Thread_lock = CacheField(env, java_lang_Thread, false, "lock", "Ljava/lang/Object;");
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700224 java_lang_Thread_name = CacheField(env, java_lang_Thread, false, "name", "Ljava/lang/String;");
225 java_lang_Thread_priority = CacheField(env, java_lang_Thread, false, "priority", "I");
226 java_lang_Thread_uncaughtHandler = CacheField(env, java_lang_Thread, false, "uncaughtHandler", "Ljava/lang/Thread$UncaughtExceptionHandler;");
Ian Rogersef7d42f2014-01-06 12:55:46 -0800227 java_lang_Thread_nativePeer = CacheField(env, java_lang_Thread, false, "nativePeer", "J");
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700228 java_lang_ThreadGroup_mainThreadGroup = CacheField(env, java_lang_ThreadGroup, true, "mainThreadGroup", "Ljava/lang/ThreadGroup;");
229 java_lang_ThreadGroup_name = CacheField(env, java_lang_ThreadGroup, false, "name", "Ljava/lang/String;");
230 java_lang_ThreadGroup_systemThreadGroup = CacheField(env, java_lang_ThreadGroup, true, "systemThreadGroup", "Ljava/lang/ThreadGroup;");
Brian Carlstrom34375312014-09-10 23:10:47 -0700231 java_lang_Throwable_cause = CacheField(env, java_lang_Throwable, false, "cause", "Ljava/lang/Throwable;");
232 java_lang_Throwable_detailMessage = CacheField(env, java_lang_Throwable, false, "detailMessage", "Ljava/lang/String;");
233 java_lang_Throwable_stackTrace = CacheField(env, java_lang_Throwable, false, "stackTrace", "[Ljava/lang/StackTraceElement;");
234 java_lang_Throwable_stackState = CacheField(env, java_lang_Throwable, false, "stackState", "Ljava/lang/Object;");
235 java_lang_Throwable_suppressedExceptions = CacheField(env, java_lang_Throwable, false, "suppressedExceptions", "Ljava/util/List;");
Brian Carlstromea46f952013-07-30 01:26:50 -0700236 java_lang_reflect_AbstractMethod_artMethod = CacheField(env, java_lang_reflect_AbstractMethod, false, "artMethod", "Ljava/lang/reflect/ArtMethod;");
237 java_lang_reflect_Field_artField = CacheField(env, java_lang_reflect_Field, false, "artField", "Ljava/lang/reflect/ArtField;");
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700238 java_lang_reflect_Proxy_h = CacheField(env, java_lang_reflect_Proxy, false, "h", "Ljava/lang/reflect/InvocationHandler;");
Elliott Hughesaecb5f32013-03-28 08:27:38 -0700239 java_nio_DirectByteBuffer_capacity = CacheField(env, java_nio_DirectByteBuffer, false, "capacity", "I");
Elliott Hughes2e8a4fc2013-03-29 16:33:52 -0700240 java_nio_DirectByteBuffer_effectiveDirectAddress = CacheField(env, java_nio_DirectByteBuffer, false, "effectiveDirectAddress", "J");
Brian Carlstrom34375312014-09-10 23:10:47 -0700241 java_util_Collections_EMPTY_LIST = CacheField(env, java_util_Collections, true, "EMPTY_LIST", "Ljava/util/List;");
242 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 +0200243 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 -0700244 org_apache_harmony_dalvik_ddmc_Chunk_length = CacheField(env, org_apache_harmony_dalvik_ddmc_Chunk, false, "length", "I");
245 org_apache_harmony_dalvik_ddmc_Chunk_offset = CacheField(env, org_apache_harmony_dalvik_ddmc_Chunk, false, "offset", "I");
246 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 -0700247
248 java_lang_Boolean_valueOf = CachePrimitiveBoxingMethod(env, 'Z', "java/lang/Boolean");
249 java_lang_Byte_valueOf = CachePrimitiveBoxingMethod(env, 'B', "java/lang/Byte");
250 java_lang_Character_valueOf = CachePrimitiveBoxingMethod(env, 'C', "java/lang/Character");
251 java_lang_Double_valueOf = CachePrimitiveBoxingMethod(env, 'D', "java/lang/Double");
252 java_lang_Float_valueOf = CachePrimitiveBoxingMethod(env, 'F', "java/lang/Float");
253 java_lang_Integer_valueOf = CachePrimitiveBoxingMethod(env, 'I', "java/lang/Integer");
254 java_lang_Long_valueOf = CachePrimitiveBoxingMethod(env, 'J', "java/lang/Long");
255 java_lang_Short_valueOf = CachePrimitiveBoxingMethod(env, 'S', "java/lang/Short");
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700256}
257
Ian Rogersef28b142012-11-30 14:22:18 -0800258void WellKnownClasses::LateInit(JNIEnv* env) {
259 ScopedLocalRef<jclass> java_lang_Runtime(env, env->FindClass("java/lang/Runtime"));
Elliott Hughesc8fece32013-01-02 11:27:23 -0800260 java_lang_Runtime_nativeLoad = CacheMethod(env, java_lang_Runtime.get(), true, "nativeLoad", "(Ljava/lang/String;Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/lang/String;");
Ian Rogersef28b142012-11-30 14:22:18 -0800261}
262
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800263mirror::Class* WellKnownClasses::ToClass(jclass global_jclass) {
264 return reinterpret_cast<mirror::Class*>(Thread::Current()->DecodeJObject(global_jclass));
Elliott Hugheseac76672012-05-24 21:56:51 -0700265}
266
267} // namespace art