blob: 482ff0a8f4604341ff01d112c84e3e40970a0adc [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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_WELL_KNOWN_CLASSES_H_
18#define ART_RUNTIME_WELL_KNOWN_CLASSES_H_
Elliott Hugheseac76672012-05-24 21:56:51 -070019
Elliott Hughes76b61672012-12-12 17:47:30 -080020#include "base/mutex.h"
Elliott Hugheseac76672012-05-24 21:56:51 -070021#include "jni.h"
22
23namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024namespace mirror {
Elliott Hughesaf8d15a2012-05-29 09:12:18 -070025class Class;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080026} // namespace mirror
Elliott Hughesaf8d15a2012-05-29 09:12:18 -070027
Elliott Hugheseac76672012-05-24 21:56:51 -070028// Various classes used in JNI. We cache them so we don't have to keep looking
29// them up. Similar to libcore's JniConstants (except there's no overlap, so
30// we keep them separate).
31
Mathieu Chartier987ccff2013-07-08 11:05:21 -070032jmethodID CacheMethod(JNIEnv* env, jclass c, bool is_static, const char* name, const char* signature);
33
Elliott Hugheseac76672012-05-24 21:56:51 -070034struct WellKnownClasses {
Brian Carlstromea46f952013-07-30 01:26:50 -070035 public:
Ian Rogersef28b142012-11-30 14:22:18 -080036 static void Init(JNIEnv* env); // Run before native methods are registered.
37 static void LateInit(JNIEnv* env); // Run after native methods are registered.
Jeff Hao848f70a2014-01-15 13:49:50 -080038 static jmethodID StringInitToStringFactoryMethodID(jmethodID string_init);
Elliott Hugheseac76672012-05-24 21:56:51 -070039
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080040 static mirror::Class* ToClass(jclass global_jclass)
Mathieu Chartier90443472015-07-16 20:32:27 -070041 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughesaf8d15a2012-05-29 09:12:18 -070042
Elliott Hugheseac76672012-05-24 21:56:51 -070043 static jclass com_android_dex_Dex;
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -070044 static jclass dalvik_system_DexFile;
45 static jclass dalvik_system_DexPathList;
Andreas Gampec8ccf682014-09-29 20:07:43 -070046 static jclass dalvik_system_DexPathList__Element;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070047 static jclass dalvik_system_PathClassLoader;
Mathieu Chartierb5de3bb2015-06-05 13:21:05 -070048 static jclass dalvik_system_VMRuntime;
Jeff Hao13e748b2015-08-25 20:44:19 +000049 static jclass java_lang_annotation_Annotation__array;
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -070050 static jclass java_lang_BootClassLoader;
Elliott Hugheseac76672012-05-24 21:56:51 -070051 static jclass java_lang_ClassLoader;
52 static jclass java_lang_ClassNotFoundException;
53 static jclass java_lang_Daemons;
54 static jclass java_lang_Error;
Ian Rogersaf6e67a2013-01-16 08:38:37 -080055 static jclass java_lang_Object;
Mathieu Chartiera61894d2015-04-23 16:32:54 -070056 static jclass java_lang_OutOfMemoryError;
Mathieu Chartier66f19252012-09-18 08:57:04 -070057 static jclass java_lang_reflect_AbstractMethod;
Brian Carlstromea46f952013-07-30 01:26:50 -070058 static jclass java_lang_reflect_Constructor;
59 static jclass java_lang_reflect_Field;
60 static jclass java_lang_reflect_Method;
Elliott Hugheseac76672012-05-24 21:56:51 -070061 static jclass java_lang_reflect_Proxy;
Elliott Hughesa4f94742012-05-29 16:28:38 -070062 static jclass java_lang_RuntimeException;
Ian Rogers120f1c72012-09-28 17:17:10 -070063 static jclass java_lang_StackOverflowError;
Ian Rogersdd157d72014-05-15 14:47:50 -070064 static jclass java_lang_String;
Jeff Hao848f70a2014-01-15 13:49:50 -080065 static jclass java_lang_StringFactory;
Mathieu Chartier987ccff2013-07-08 11:05:21 -070066 static jclass java_lang_System;
Elliott Hugheseac76672012-05-24 21:56:51 -070067 static jclass java_lang_Thread;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -070068 static jclass java_lang_ThreadGroup;
Andreas Gampec8ccf682014-09-29 20:07:43 -070069 static jclass java_lang_Thread__UncaughtExceptionHandler;
Elliott Hughesa4f94742012-05-29 16:28:38 -070070 static jclass java_lang_Throwable;
Sebastien Hertze49e1952014-10-13 11:27:13 +020071 static jclass java_util_ArrayList;
Andreas Gampe7ea6f792014-07-14 16:21:44 -070072 static jclass java_util_Collections;
Elliott Hughesaecb5f32013-03-28 08:27:38 -070073 static jclass java_nio_DirectByteBuffer;
Jeff Hao13e748b2015-08-25 20:44:19 +000074 static jclass libcore_reflect_AnnotationFactory;
75 static jclass libcore_reflect_AnnotationMember;
Andreas Gampe7ea6f792014-07-14 16:21:44 -070076 static jclass libcore_util_EmptyArray;
Elliott Hugheseac76672012-05-24 21:56:51 -070077 static jclass org_apache_harmony_dalvik_ddmc_Chunk;
78 static jclass org_apache_harmony_dalvik_ddmc_DdmServer;
79
80 static jmethodID com_android_dex_Dex_create;
Mathieu Chartierb5de3bb2015-06-05 13:21:05 -070081 static jmethodID dalvik_system_VMRuntime_runFinalization;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070082 static jmethodID java_lang_Boolean_valueOf;
83 static jmethodID java_lang_Byte_valueOf;
84 static jmethodID java_lang_Character_valueOf;
Elliott Hughesa4f94742012-05-29 16:28:38 -070085 static jmethodID java_lang_ClassLoader_loadClass;
Elliott Hugheseac76672012-05-24 21:56:51 -070086 static jmethodID java_lang_ClassNotFoundException_init;
87 static jmethodID java_lang_Daemons_requestHeapTrim;
88 static jmethodID java_lang_Daemons_start;
Mathieu Chartiercef50f02014-12-09 17:38:52 -080089 static jmethodID java_lang_Daemons_stop;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070090 static jmethodID java_lang_Double_valueOf;
91 static jmethodID java_lang_Float_valueOf;
92 static jmethodID java_lang_Integer_valueOf;
93 static jmethodID java_lang_Long_valueOf;
Elliott Hughesa4f94742012-05-29 16:28:38 -070094 static jmethodID java_lang_ref_FinalizerReference_add;
95 static jmethodID java_lang_ref_ReferenceQueue_add;
Brian Carlstromea46f952013-07-30 01:26:50 -070096 static jmethodID java_lang_reflect_Proxy_invoke;
Ian Rogersef28b142012-11-30 14:22:18 -080097 static jmethodID java_lang_Runtime_nativeLoad;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070098 static jmethodID java_lang_Short_valueOf;
Jeff Hao848f70a2014-01-15 13:49:50 -080099 static jmethodID java_lang_String_init;
100 static jmethodID java_lang_String_init_B;
101 static jmethodID java_lang_String_init_BI;
102 static jmethodID java_lang_String_init_BII;
103 static jmethodID java_lang_String_init_BIII;
104 static jmethodID java_lang_String_init_BIIString;
105 static jmethodID java_lang_String_init_BString;
106 static jmethodID java_lang_String_init_BIICharset;
107 static jmethodID java_lang_String_init_BCharset;
108 static jmethodID java_lang_String_init_C;
109 static jmethodID java_lang_String_init_CII;
110 static jmethodID java_lang_String_init_IIC;
111 static jmethodID java_lang_String_init_String;
112 static jmethodID java_lang_String_init_StringBuffer;
113 static jmethodID java_lang_String_init_III;
114 static jmethodID java_lang_String_init_StringBuilder;
115 static jmethodID java_lang_StringFactory_newEmptyString;
116 static jmethodID java_lang_StringFactory_newStringFromBytes_B;
117 static jmethodID java_lang_StringFactory_newStringFromBytes_BI;
118 static jmethodID java_lang_StringFactory_newStringFromBytes_BII;
119 static jmethodID java_lang_StringFactory_newStringFromBytes_BIII;
120 static jmethodID java_lang_StringFactory_newStringFromBytes_BIIString;
121 static jmethodID java_lang_StringFactory_newStringFromBytes_BString;
122 static jmethodID java_lang_StringFactory_newStringFromBytes_BIICharset;
123 static jmethodID java_lang_StringFactory_newStringFromBytes_BCharset;
124 static jmethodID java_lang_StringFactory_newStringFromChars_C;
125 static jmethodID java_lang_StringFactory_newStringFromChars_CII;
126 static jmethodID java_lang_StringFactory_newStringFromChars_IIC;
127 static jmethodID java_lang_StringFactory_newStringFromString;
128 static jmethodID java_lang_StringFactory_newStringFromStringBuffer;
129 static jmethodID java_lang_StringFactory_newStringFromCodePoints;
130 static jmethodID java_lang_StringFactory_newStringFromStringBuilder;
Mathieu Chartier987ccff2013-07-08 11:05:21 -0700131 static jmethodID java_lang_System_runFinalization;
Elliott Hugheseac76672012-05-24 21:56:51 -0700132 static jmethodID java_lang_Thread_init;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700133 static jmethodID java_lang_Thread_run;
Andreas Gampec8ccf682014-09-29 20:07:43 -0700134 static jmethodID java_lang_Thread__UncaughtExceptionHandler_uncaughtException;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700135 static jmethodID java_lang_ThreadGroup_removeThread;
Elliott Hughesaecb5f32013-03-28 08:27:38 -0700136 static jmethodID java_nio_DirectByteBuffer_init;
Jeff Hao13e748b2015-08-25 20:44:19 +0000137 static jmethodID libcore_reflect_AnnotationFactory_createAnnotation;
138 static jmethodID libcore_reflect_AnnotationMember_init;
Elliott Hugheseac76672012-05-24 21:56:51 -0700139 static jmethodID org_apache_harmony_dalvik_ddmc_DdmServer_broadcast;
140 static jmethodID org_apache_harmony_dalvik_ddmc_DdmServer_dispatch;
141
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -0700142 static jfieldID dalvik_system_DexFile_cookie;
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800143 static jfieldID dalvik_system_DexFile_fileName;
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -0700144 static jfieldID dalvik_system_DexPathList_dexElements;
Andreas Gampec8ccf682014-09-29 20:07:43 -0700145 static jfieldID dalvik_system_DexPathList__Element_dexFile;
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -0700146 static jfieldID dalvik_system_PathClassLoader_pathList;
Brian Carlstromea46f952013-07-30 01:26:50 -0700147 static jfieldID java_lang_reflect_AbstractMethod_artMethod;
Elliott Hugheseac76672012-05-24 21:56:51 -0700148 static jfieldID java_lang_reflect_Proxy_h;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700149 static jfieldID java_lang_Thread_daemon;
150 static jfieldID java_lang_Thread_group;
151 static jfieldID java_lang_Thread_lock;
152 static jfieldID java_lang_Thread_name;
153 static jfieldID java_lang_Thread_priority;
154 static jfieldID java_lang_Thread_uncaughtHandler;
Anwar Ghuloum3c50a4b2013-06-21 13:05:23 -0700155 static jfieldID java_lang_Thread_nativePeer;
Sebastien Hertze49e1952014-10-13 11:27:13 +0200156 static jfieldID java_lang_ThreadGroup_groups;
Przemyslaw Szczepaniak464595f2015-11-24 11:59:59 +0000157 static jfieldID java_lang_ThreadGroup_ngroups;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700158 static jfieldID java_lang_ThreadGroup_mainThreadGroup;
159 static jfieldID java_lang_ThreadGroup_name;
Sebastien Hertze49e1952014-10-13 11:27:13 +0200160 static jfieldID java_lang_ThreadGroup_parent;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700161 static jfieldID java_lang_ThreadGroup_systemThreadGroup;
Brian Carlstrom34375312014-09-10 23:10:47 -0700162 static jfieldID java_lang_Throwable_cause;
163 static jfieldID java_lang_Throwable_detailMessage;
164 static jfieldID java_lang_Throwable_stackTrace;
165 static jfieldID java_lang_Throwable_stackState;
166 static jfieldID java_lang_Throwable_suppressedExceptions;
Elliott Hughesaecb5f32013-03-28 08:27:38 -0700167 static jfieldID java_nio_DirectByteBuffer_capacity;
168 static jfieldID java_nio_DirectByteBuffer_effectiveDirectAddress;
Sebastien Hertze49e1952014-10-13 11:27:13 +0200169 static jfieldID java_util_ArrayList_array;
170 static jfieldID java_util_ArrayList_size;
Brian Carlstrom34375312014-09-10 23:10:47 -0700171 static jfieldID java_util_Collections_EMPTY_LIST;
172 static jfieldID libcore_util_EmptyArray_STACK_TRACE_ELEMENT;
Elliott Hugheseac76672012-05-24 21:56:51 -0700173 static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_data;
174 static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_length;
175 static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_offset;
176 static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_type;
177};
178
179} // namespace art
180
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700181#endif // ART_RUNTIME_WELL_KNOWN_CLASSES_H_