blob: c334f5d4162c352634258dc8ce2d0ca7fbb876da [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
Andreas Gampe7fbc4a52018-11-28 08:26:47 -080020#include "base/locks.h"
Elliott Hugheseac76672012-05-24 21:56:51 -070021#include "jni.h"
Mathieu Chartierc4f39252016-10-05 18:32:08 -070022#include "obj_ptr.h"
Elliott Hugheseac76672012-05-24 21:56:51 -070023
24namespace art {
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +010025
26class ArtMethod;
27
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080028namespace mirror {
Elliott Hughesaf8d15a2012-05-29 09:12:18 -070029class Class;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030} // namespace mirror
Elliott Hughesaf8d15a2012-05-29 09:12:18 -070031
Orion Hodson814b9282020-02-19 16:37:11 +000032// Various classes used in JNI. We cache them so we don't have to keep looking them up.
Elliott Hugheseac76672012-05-24 21:56:51 -070033
34struct WellKnownClasses {
Brian Carlstromea46f952013-07-30 01:26:50 -070035 public:
Alex Lightf3677472019-06-26 16:31:53 -070036 // Run before native methods are registered.
37 static void Init(JNIEnv* env);
38 // Run after native methods are registered.
39 static void LateInit(JNIEnv* env);
Andreas Gampedb48a792017-09-08 22:18:30 -070040
41 static void Clear();
42
Alex Lightf3677472019-06-26 16:31:53 -070043 static void HandleJniIdTypeChange(JNIEnv* env);
44
Andreas Gampe9abc31e2018-05-17 11:47:09 -070045 static void InitStringInit(ObjPtr<mirror::Class> string_class,
46 ObjPtr<mirror::Class> string_builder_class)
47 REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +010048 static ArtMethod* StringInitToStringFactory(ArtMethod* method);
49 static uint32_t StringInitToEntryPoint(ArtMethod* method);
Elliott Hugheseac76672012-05-24 21:56:51 -070050
Mathieu Chartierc4f39252016-10-05 18:32:08 -070051 static ObjPtr<mirror::Class> ToClass(jclass global_jclass) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesaf8d15a2012-05-29 09:12:18 -070052
Alex Lightf3677472019-06-26 16:31:53 -070053 private:
54 static void InitFieldsAndMethodsOnly(JNIEnv* env);
55
56 public:
Igor Murashkin367f3dd2016-09-01 17:00:24 -070057 static jclass dalvik_annotation_optimization_CriticalNative;
Igor Murashkin9d4b6da2016-07-29 09:51:58 -070058 static jclass dalvik_annotation_optimization_FastNative;
Kevin Jeon55737562021-11-19 20:39:30 +000059 static jclass dalvik_annotation_optimization_NeverCompile;
Andreas Gampe46aba362016-10-28 14:33:28 -070060 static jclass dalvik_system_BaseDexClassLoader;
Calin Juravle7865ac72017-06-28 11:03:12 -070061 static jclass dalvik_system_DelegateLastClassLoader;
Nicolas Geoffray7d8d8ff2016-11-02 12:38:05 +000062 static jclass dalvik_system_DexClassLoader;
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -070063 static jclass dalvik_system_DexFile;
64 static jclass dalvik_system_DexPathList;
Andreas Gampec8ccf682014-09-29 20:07:43 -070065 static jclass dalvik_system_DexPathList__Element;
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +010066 static jclass dalvik_system_EmulatedStackFrame;
David Brazdil05909d82018-12-06 16:25:16 +000067 static jclass dalvik_system_InMemoryDexClassLoader;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070068 static jclass dalvik_system_PathClassLoader;
Mathieu Chartierb5de3bb2015-06-05 13:21:05 -070069 static jclass dalvik_system_VMRuntime;
Jeff Hao13e748b2015-08-25 20:44:19 +000070 static jclass java_lang_annotation_Annotation__array;
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -070071 static jclass java_lang_BootClassLoader;
Elliott Hugheseac76672012-05-24 21:56:51 -070072 static jclass java_lang_ClassLoader;
73 static jclass java_lang_ClassNotFoundException;
74 static jclass java_lang_Daemons;
75 static jclass java_lang_Error;
Jeff Haoc92a7a12016-06-06 11:09:20 -070076 static jclass java_lang_IllegalAccessError;
77 static jclass java_lang_NoClassDefFoundError;
Ian Rogersaf6e67a2013-01-16 08:38:37 -080078 static jclass java_lang_Object;
Mathieu Chartiera61894d2015-04-23 16:32:54 -070079 static jclass java_lang_OutOfMemoryError;
Alex Lightf284a2d2019-06-24 13:30:42 -070080 static jclass java_lang_reflect_InvocationTargetException;
Neil Fuller79a21e72016-09-09 14:24:51 +010081 static jclass java_lang_reflect_Parameter;
82 static jclass java_lang_reflect_Parameter__array;
Elliott Hugheseac76672012-05-24 21:56:51 -070083 static jclass java_lang_reflect_Proxy;
Elliott Hughesa4f94742012-05-29 16:28:38 -070084 static jclass java_lang_RuntimeException;
Ian Rogers120f1c72012-09-28 17:17:10 -070085 static jclass java_lang_StackOverflowError;
Ian Rogersdd157d72014-05-15 14:47:50 -070086 static jclass java_lang_String;
Jeff Hao848f70a2014-01-15 13:49:50 -080087 static jclass java_lang_StringFactory;
Mathieu Chartier987ccff2013-07-08 11:05:21 -070088 static jclass java_lang_System;
Elliott Hugheseac76672012-05-24 21:56:51 -070089 static jclass java_lang_Thread;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -070090 static jclass java_lang_ThreadGroup;
Elliott Hughesa4f94742012-05-29 16:28:38 -070091 static jclass java_lang_Throwable;
Orion Hodson2ff0cb12020-08-27 09:04:57 +010092 static jclass java_lang_Void;
Orion Hodsonbda163d2020-04-01 17:36:26 +010093 static jclass java_nio_Buffer;
Orion Hodson928033d2018-02-07 05:30:54 +000094 static jclass java_nio_ByteBuffer;
Elliott Hughesaecb5f32013-03-28 08:27:38 -070095 static jclass java_nio_DirectByteBuffer;
Orion Hodson814b9282020-02-19 16:37:11 +000096 static jclass java_util_Collections;
97 static jclass java_util_function_Consumer;
Jeff Hao13e748b2015-08-25 20:44:19 +000098 static jclass libcore_reflect_AnnotationFactory;
99 static jclass libcore_reflect_AnnotationMember;
Neil Fullerc0f02d42018-06-11 09:49:01 +0000100 static jclass libcore_util_EmptyArray;
Elliott Hugheseac76672012-05-24 21:56:51 -0700101 static jclass org_apache_harmony_dalvik_ddmc_Chunk;
102 static jclass org_apache_harmony_dalvik_ddmc_DdmServer;
103
Andreas Gampe473191c2017-12-28 16:55:31 -0800104 static jmethodID dalvik_system_BaseDexClassLoader_getLdLibraryPath;
Mathieu Chartierb5de3bb2015-06-05 13:21:05 -0700105 static jmethodID dalvik_system_VMRuntime_runFinalization;
Andrei Oneaa2d2bc22019-01-25 16:18:53 +0000106 static jmethodID dalvik_system_VMRuntime_hiddenApiUsed;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700107 static jmethodID java_lang_Boolean_valueOf;
108 static jmethodID java_lang_Byte_valueOf;
109 static jmethodID java_lang_Character_valueOf;
Elliott Hughesa4f94742012-05-29 16:28:38 -0700110 static jmethodID java_lang_ClassLoader_loadClass;
Elliott Hugheseac76672012-05-24 21:56:51 -0700111 static jmethodID java_lang_ClassNotFoundException_init;
Elliott Hugheseac76672012-05-24 21:56:51 -0700112 static jmethodID java_lang_Daemons_start;
Mathieu Chartiercef50f02014-12-09 17:38:52 -0800113 static jmethodID java_lang_Daemons_stop;
Alex Lighte0b2ce42019-02-21 19:23:42 +0000114 static jmethodID java_lang_Daemons_waitForDaemonStart;
Vladimir Markod3e9c622020-08-05 12:20:28 +0100115 static jmethodID java_lang_Double_doubleToRawLongBits;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700116 static jmethodID java_lang_Double_valueOf;
Vladimir Markod3e9c622020-08-05 12:20:28 +0100117 static jmethodID java_lang_Float_floatToRawIntBits;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700118 static jmethodID java_lang_Float_valueOf;
119 static jmethodID java_lang_Integer_valueOf;
Orion Hodsonb08e1152022-01-05 14:29:05 +0000120 static jmethodID java_lang_invoke_MethodHandle_asType;
Orion Hodson8671f582022-03-09 06:53:48 +0000121 static jmethodID java_lang_invoke_MethodHandle_invokeExact;
Orion Hodsonf8db2c32017-07-07 20:07:12 +0100122 static jmethodID java_lang_invoke_MethodHandles_lookup;
123 static jmethodID java_lang_invoke_MethodHandles_Lookup_findConstructor;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700124 static jmethodID java_lang_Long_valueOf;
Elliott Hughesa4f94742012-05-29 16:28:38 -0700125 static jmethodID java_lang_ref_FinalizerReference_add;
126 static jmethodID java_lang_ref_ReferenceQueue_add;
Alex Lightf284a2d2019-06-24 13:30:42 -0700127 static jmethodID java_lang_reflect_InvocationTargetException_init;
Neil Fuller79a21e72016-09-09 14:24:51 +0100128 static jmethodID java_lang_reflect_Parameter_init;
Alex Light6cae5ea2018-06-07 17:07:02 -0700129 static jmethodID java_lang_reflect_Proxy_init;
Brian Carlstromea46f952013-07-30 01:26:50 -0700130 static jmethodID java_lang_reflect_Proxy_invoke;
Ian Rogersef28b142012-11-30 14:22:18 -0800131 static jmethodID java_lang_Runtime_nativeLoad;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700132 static jmethodID java_lang_Short_valueOf;
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000133 static jmethodID java_lang_String_charAt;
Tobias Thierer5cbe65d2016-07-22 18:37:59 +0100134 static jmethodID java_lang_Thread_dispatchUncaughtException;
Elliott Hugheseac76672012-05-24 21:56:51 -0700135 static jmethodID java_lang_Thread_init;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700136 static jmethodID java_lang_Thread_run;
Andreas Gampe56776012018-01-26 17:40:55 -0800137 static jmethodID java_lang_ThreadGroup_add;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700138 static jmethodID java_lang_ThreadGroup_removeThread;
Orion Hodson7285a4b2020-07-10 13:31:35 +0100139 static jmethodID java_nio_Buffer_isDirect;
Elliott Hughesaecb5f32013-03-28 08:27:38 -0700140 static jmethodID java_nio_DirectByteBuffer_init;
Narayan Kamathf5f1f802018-04-03 15:23:46 +0100141 static jmethodID java_util_function_Consumer_accept;
Jeff Hao13e748b2015-08-25 20:44:19 +0000142 static jmethodID libcore_reflect_AnnotationFactory_createAnnotation;
143 static jmethodID libcore_reflect_AnnotationMember_init;
Elliott Hugheseac76672012-05-24 21:56:51 -0700144 static jmethodID org_apache_harmony_dalvik_ddmc_DdmServer_broadcast;
145 static jmethodID org_apache_harmony_dalvik_ddmc_DdmServer_dispatch;
146
Andreas Gampe46aba362016-10-28 14:33:28 -0700147 static jfieldID dalvik_system_BaseDexClassLoader_pathList;
Nicolas Geoffray80a560c2018-10-26 13:48:51 +0100148 static jfieldID dalvik_system_BaseDexClassLoader_sharedLibraryLoaders;
Brad Stenning9c924e82021-10-11 19:09:00 -0700149 static jfieldID dalvik_system_BaseDexClassLoader_sharedLibraryLoadersAfter;
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -0700150 static jfieldID dalvik_system_DexFile_cookie;
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800151 static jfieldID dalvik_system_DexFile_fileName;
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -0700152 static jfieldID dalvik_system_DexPathList_dexElements;
Andreas Gampec8ccf682014-09-29 20:07:43 -0700153 static jfieldID dalvik_system_DexPathList__Element_dexFile;
Narayan Kamathf5f1f802018-04-03 15:23:46 +0100154 static jfieldID dalvik_system_VMRuntime_nonSdkApiUsageConsumer;
Orion Hodsoneb070f02020-03-10 14:00:18 +0000155 static jfieldID java_io_FileDescriptor_descriptor;
Vladimir Markoe300c4e2021-06-08 16:00:05 +0100156 static jfieldID java_lang_ClassLoader_parent;
Charles Munger5cc0e752018-11-09 12:30:46 -0800157 static jfieldID java_lang_Thread_parkBlocker;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700158 static jfieldID java_lang_Thread_daemon;
159 static jfieldID java_lang_Thread_group;
160 static jfieldID java_lang_Thread_lock;
161 static jfieldID java_lang_Thread_name;
162 static jfieldID java_lang_Thread_priority;
Anwar Ghuloum3c50a4b2013-06-21 13:05:23 -0700163 static jfieldID java_lang_Thread_nativePeer;
Alex Lighte0b2ce42019-02-21 19:23:42 +0000164 static jfieldID java_lang_Thread_systemDaemon;
Charles Mungeraa31f492018-11-01 18:57:38 +0000165 static jfieldID java_lang_Thread_unparkedBeforeStart;
Sebastien Hertze49e1952014-10-13 11:27:13 +0200166 static jfieldID java_lang_ThreadGroup_groups;
Przemyslaw Szczepaniak464595f2015-11-24 11:59:59 +0000167 static jfieldID java_lang_ThreadGroup_ngroups;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700168 static jfieldID java_lang_ThreadGroup_mainThreadGroup;
169 static jfieldID java_lang_ThreadGroup_name;
Sebastien Hertze49e1952014-10-13 11:27:13 +0200170 static jfieldID java_lang_ThreadGroup_parent;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700171 static jfieldID java_lang_ThreadGroup_systemThreadGroup;
Brian Carlstrom34375312014-09-10 23:10:47 -0700172 static jfieldID java_lang_Throwable_cause;
173 static jfieldID java_lang_Throwable_detailMessage;
174 static jfieldID java_lang_Throwable_stackTrace;
175 static jfieldID java_lang_Throwable_stackState;
176 static jfieldID java_lang_Throwable_suppressedExceptions;
Orion Hodson814b9282020-02-19 16:37:11 +0000177 static jfieldID java_nio_Buffer_address;
Orion Hodsonbda163d2020-04-01 17:36:26 +0100178 static jfieldID java_nio_Buffer_capacity;
Orion Hodson814b9282020-02-19 16:37:11 +0000179 static jfieldID java_nio_Buffer_elementSizeShift;
180 static jfieldID java_nio_Buffer_limit;
181 static jfieldID java_nio_Buffer_position;
Orion Hodson928033d2018-02-07 05:30:54 +0000182 static jfieldID java_nio_ByteBuffer_address;
183 static jfieldID java_nio_ByteBuffer_hb;
184 static jfieldID java_nio_ByteBuffer_isReadOnly;
185 static jfieldID java_nio_ByteBuffer_limit;
186 static jfieldID java_nio_ByteBuffer_offset;
Orion Hodson928033d2018-02-07 05:30:54 +0000187
Brian Carlstrom34375312014-09-10 23:10:47 -0700188 static jfieldID java_util_Collections_EMPTY_LIST;
Neil Fullerc0f02d42018-06-11 09:49:01 +0000189 static jfieldID libcore_util_EmptyArray_STACK_TRACE_ELEMENT;
Elliott Hugheseac76672012-05-24 21:56:51 -0700190 static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_data;
191 static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_length;
192 static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_offset;
193 static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_type;
194};
195
196} // namespace art
197
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700198#endif // ART_RUNTIME_WELL_KNOWN_CLASSES_H_