Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 1 | /* |
| 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 Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_WELL_KNOWN_CLASSES_H_ |
| 18 | #define ART_RUNTIME_WELL_KNOWN_CLASSES_H_ |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 19 | |
Elliott Hughes | 76b6167 | 2012-12-12 17:47:30 -0800 | [diff] [blame] | 20 | #include "base/mutex.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 21 | #include "jni.h" |
Mathieu Chartier | c4f3925 | 2016-10-05 18:32:08 -0700 | [diff] [blame] | 22 | #include "obj_ptr.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 23 | |
| 24 | namespace art { |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 25 | |
| 26 | class ArtMethod; |
| 27 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 28 | namespace mirror { |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 29 | class Class; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 30 | } // namespace mirror |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 31 | |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 32 | // Various classes used in JNI. We cache them so we don't have to keep looking |
| 33 | // them up. Similar to libcore's JniConstants (except there's no overlap, so |
| 34 | // we keep them separate). |
| 35 | |
| 36 | struct WellKnownClasses { |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 37 | public: |
Ian Rogers | ef28b14 | 2012-11-30 14:22:18 -0800 | [diff] [blame] | 38 | static void Init(JNIEnv* env); // Run before native methods are registered. |
| 39 | static void LateInit(JNIEnv* env); // Run after native methods are registered. |
Andreas Gampe | db48a79 | 2017-09-08 22:18:30 -0700 | [diff] [blame] | 40 | |
| 41 | static void Clear(); |
| 42 | |
Andreas Gampe | 9abc31e | 2018-05-17 11:47:09 -0700 | [diff] [blame] | 43 | static void InitStringInit(ObjPtr<mirror::Class> string_class, |
| 44 | ObjPtr<mirror::Class> string_builder_class) |
| 45 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 46 | static ArtMethod* StringInitToStringFactory(ArtMethod* method); |
| 47 | static uint32_t StringInitToEntryPoint(ArtMethod* method); |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 48 | |
Mathieu Chartier | c4f3925 | 2016-10-05 18:32:08 -0700 | [diff] [blame] | 49 | static ObjPtr<mirror::Class> ToClass(jclass global_jclass) REQUIRES_SHARED(Locks::mutator_lock_); |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 50 | |
Igor Murashkin | 367f3dd | 2016-09-01 17:00:24 -0700 | [diff] [blame] | 51 | static jclass dalvik_annotation_optimization_CriticalNative; |
Igor Murashkin | 9d4b6da | 2016-07-29 09:51:58 -0700 | [diff] [blame] | 52 | static jclass dalvik_annotation_optimization_FastNative; |
Andreas Gampe | 46aba36 | 2016-10-28 14:33:28 -0700 | [diff] [blame] | 53 | static jclass dalvik_system_BaseDexClassLoader; |
Calin Juravle | 7865ac7 | 2017-06-28 11:03:12 -0700 | [diff] [blame] | 54 | static jclass dalvik_system_DelegateLastClassLoader; |
Nicolas Geoffray | 7d8d8ff | 2016-11-02 12:38:05 +0000 | [diff] [blame] | 55 | static jclass dalvik_system_DexClassLoader; |
Mathieu Chartier | 6bcae8f | 2014-09-04 18:33:17 -0700 | [diff] [blame] | 56 | static jclass dalvik_system_DexFile; |
| 57 | static jclass dalvik_system_DexPathList; |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 58 | static jclass dalvik_system_DexPathList__Element; |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 59 | static jclass dalvik_system_EmulatedStackFrame; |
David Brazdil | 05909d8 | 2018-12-06 16:25:16 +0000 | [diff] [blame^] | 60 | static jclass dalvik_system_InMemoryDexClassLoader; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 61 | static jclass dalvik_system_PathClassLoader; |
Mathieu Chartier | b5de3bb | 2015-06-05 13:21:05 -0700 | [diff] [blame] | 62 | static jclass dalvik_system_VMRuntime; |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 63 | static jclass java_lang_annotation_Annotation__array; |
Mathieu Chartier | 6bcae8f | 2014-09-04 18:33:17 -0700 | [diff] [blame] | 64 | static jclass java_lang_BootClassLoader; |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 65 | static jclass java_lang_ClassLoader; |
| 66 | static jclass java_lang_ClassNotFoundException; |
| 67 | static jclass java_lang_Daemons; |
| 68 | static jclass java_lang_Error; |
Jeff Hao | c92a7a1 | 2016-06-06 11:09:20 -0700 | [diff] [blame] | 69 | static jclass java_lang_IllegalAccessError; |
| 70 | static jclass java_lang_NoClassDefFoundError; |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 71 | static jclass java_lang_Object; |
Mathieu Chartier | a61894d | 2015-04-23 16:32:54 -0700 | [diff] [blame] | 72 | static jclass java_lang_OutOfMemoryError; |
Neil Fuller | 79a21e7 | 2016-09-09 14:24:51 +0100 | [diff] [blame] | 73 | static jclass java_lang_reflect_Parameter; |
| 74 | static jclass java_lang_reflect_Parameter__array; |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 75 | static jclass java_lang_reflect_Proxy; |
Elliott Hughes | a4f9474 | 2012-05-29 16:28:38 -0700 | [diff] [blame] | 76 | static jclass java_lang_RuntimeException; |
Ian Rogers | 120f1c7 | 2012-09-28 17:17:10 -0700 | [diff] [blame] | 77 | static jclass java_lang_StackOverflowError; |
Ian Rogers | dd157d7 | 2014-05-15 14:47:50 -0700 | [diff] [blame] | 78 | static jclass java_lang_String; |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 79 | static jclass java_lang_StringFactory; |
Mathieu Chartier | 987ccff | 2013-07-08 11:05:21 -0700 | [diff] [blame] | 80 | static jclass java_lang_System; |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 81 | static jclass java_lang_Thread; |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 82 | static jclass java_lang_ThreadGroup; |
Elliott Hughes | a4f9474 | 2012-05-29 16:28:38 -0700 | [diff] [blame] | 83 | static jclass java_lang_Throwable; |
Andreas Gampe | 7ea6f79 | 2014-07-14 16:21:44 -0700 | [diff] [blame] | 84 | static jclass java_util_Collections; |
Narayan Kamath | f5f1f80 | 2018-04-03 15:23:46 +0100 | [diff] [blame] | 85 | static jclass java_util_function_Consumer; |
Orion Hodson | 928033d | 2018-02-07 05:30:54 +0000 | [diff] [blame] | 86 | static jclass java_nio_ByteBuffer; |
Elliott Hughes | aecb5f3 | 2013-03-28 08:27:38 -0700 | [diff] [blame] | 87 | static jclass java_nio_DirectByteBuffer; |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 88 | static jclass libcore_reflect_AnnotationFactory; |
| 89 | static jclass libcore_reflect_AnnotationMember; |
Neil Fuller | c0f02d4 | 2018-06-11 09:49:01 +0000 | [diff] [blame] | 90 | static jclass libcore_util_EmptyArray; |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 91 | static jclass org_apache_harmony_dalvik_ddmc_Chunk; |
| 92 | static jclass org_apache_harmony_dalvik_ddmc_DdmServer; |
| 93 | |
Andreas Gampe | 473191c | 2017-12-28 16:55:31 -0800 | [diff] [blame] | 94 | static jmethodID dalvik_system_BaseDexClassLoader_getLdLibraryPath; |
Mathieu Chartier | b5de3bb | 2015-06-05 13:21:05 -0700 | [diff] [blame] | 95 | static jmethodID dalvik_system_VMRuntime_runFinalization; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 96 | static jmethodID java_lang_Boolean_valueOf; |
| 97 | static jmethodID java_lang_Byte_valueOf; |
| 98 | static jmethodID java_lang_Character_valueOf; |
Elliott Hughes | a4f9474 | 2012-05-29 16:28:38 -0700 | [diff] [blame] | 99 | static jmethodID java_lang_ClassLoader_loadClass; |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 100 | static jmethodID java_lang_ClassNotFoundException_init; |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 101 | static jmethodID java_lang_Daemons_start; |
Mathieu Chartier | cef50f0 | 2014-12-09 17:38:52 -0800 | [diff] [blame] | 102 | static jmethodID java_lang_Daemons_stop; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 103 | static jmethodID java_lang_Double_valueOf; |
| 104 | static jmethodID java_lang_Float_valueOf; |
| 105 | static jmethodID java_lang_Integer_valueOf; |
Orion Hodson | f8db2c3 | 2017-07-07 20:07:12 +0100 | [diff] [blame] | 106 | static jmethodID java_lang_invoke_MethodHandles_lookup; |
| 107 | static jmethodID java_lang_invoke_MethodHandles_Lookup_findConstructor; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 108 | static jmethodID java_lang_Long_valueOf; |
Elliott Hughes | a4f9474 | 2012-05-29 16:28:38 -0700 | [diff] [blame] | 109 | static jmethodID java_lang_ref_FinalizerReference_add; |
| 110 | static jmethodID java_lang_ref_ReferenceQueue_add; |
Neil Fuller | 79a21e7 | 2016-09-09 14:24:51 +0100 | [diff] [blame] | 111 | static jmethodID java_lang_reflect_Parameter_init; |
Alex Light | 6cae5ea | 2018-06-07 17:07:02 -0700 | [diff] [blame] | 112 | static jmethodID java_lang_reflect_Proxy_init; |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 113 | static jmethodID java_lang_reflect_Proxy_invoke; |
Ian Rogers | ef28b14 | 2012-11-30 14:22:18 -0800 | [diff] [blame] | 114 | static jmethodID java_lang_Runtime_nativeLoad; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 115 | static jmethodID java_lang_Short_valueOf; |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 116 | static jmethodID java_lang_String_charAt; |
Tobias Thierer | 5cbe65d | 2016-07-22 18:37:59 +0100 | [diff] [blame] | 117 | static jmethodID java_lang_Thread_dispatchUncaughtException; |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 118 | static jmethodID java_lang_Thread_init; |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 119 | static jmethodID java_lang_Thread_run; |
Andreas Gampe | 5677601 | 2018-01-26 17:40:55 -0800 | [diff] [blame] | 120 | static jmethodID java_lang_ThreadGroup_add; |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 121 | static jmethodID java_lang_ThreadGroup_removeThread; |
Elliott Hughes | aecb5f3 | 2013-03-28 08:27:38 -0700 | [diff] [blame] | 122 | static jmethodID java_nio_DirectByteBuffer_init; |
Narayan Kamath | f5f1f80 | 2018-04-03 15:23:46 +0100 | [diff] [blame] | 123 | static jmethodID java_util_function_Consumer_accept; |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 124 | static jmethodID libcore_reflect_AnnotationFactory_createAnnotation; |
| 125 | static jmethodID libcore_reflect_AnnotationMember_init; |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 126 | static jmethodID org_apache_harmony_dalvik_ddmc_DdmServer_broadcast; |
| 127 | static jmethodID org_apache_harmony_dalvik_ddmc_DdmServer_dispatch; |
| 128 | |
Andreas Gampe | 46aba36 | 2016-10-28 14:33:28 -0700 | [diff] [blame] | 129 | static jfieldID dalvik_system_BaseDexClassLoader_pathList; |
Nicolas Geoffray | 80a560c | 2018-10-26 13:48:51 +0100 | [diff] [blame] | 130 | static jfieldID dalvik_system_BaseDexClassLoader_sharedLibraryLoaders; |
Mathieu Chartier | 6bcae8f | 2014-09-04 18:33:17 -0700 | [diff] [blame] | 131 | static jfieldID dalvik_system_DexFile_cookie; |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 132 | static jfieldID dalvik_system_DexFile_fileName; |
Mathieu Chartier | 6bcae8f | 2014-09-04 18:33:17 -0700 | [diff] [blame] | 133 | static jfieldID dalvik_system_DexPathList_dexElements; |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 134 | static jfieldID dalvik_system_DexPathList__Element_dexFile; |
Narayan Kamath | f5f1f80 | 2018-04-03 15:23:46 +0100 | [diff] [blame] | 135 | static jfieldID dalvik_system_VMRuntime_nonSdkApiUsageConsumer; |
Charles Munger | 5cc0e75 | 2018-11-09 12:30:46 -0800 | [diff] [blame] | 136 | static jfieldID java_lang_Thread_parkBlocker; |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 137 | static jfieldID java_lang_Thread_daemon; |
| 138 | static jfieldID java_lang_Thread_group; |
| 139 | static jfieldID java_lang_Thread_lock; |
| 140 | static jfieldID java_lang_Thread_name; |
| 141 | static jfieldID java_lang_Thread_priority; |
Anwar Ghuloum | 3c50a4b | 2013-06-21 13:05:23 -0700 | [diff] [blame] | 142 | static jfieldID java_lang_Thread_nativePeer; |
Charles Munger | aa31f49 | 2018-11-01 18:57:38 +0000 | [diff] [blame] | 143 | static jfieldID java_lang_Thread_unparkedBeforeStart; |
Sebastien Hertz | e49e195 | 2014-10-13 11:27:13 +0200 | [diff] [blame] | 144 | static jfieldID java_lang_ThreadGroup_groups; |
Przemyslaw Szczepaniak | 464595f | 2015-11-24 11:59:59 +0000 | [diff] [blame] | 145 | static jfieldID java_lang_ThreadGroup_ngroups; |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 146 | static jfieldID java_lang_ThreadGroup_mainThreadGroup; |
| 147 | static jfieldID java_lang_ThreadGroup_name; |
Sebastien Hertz | e49e195 | 2014-10-13 11:27:13 +0200 | [diff] [blame] | 148 | static jfieldID java_lang_ThreadGroup_parent; |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 149 | static jfieldID java_lang_ThreadGroup_systemThreadGroup; |
Brian Carlstrom | 3437531 | 2014-09-10 23:10:47 -0700 | [diff] [blame] | 150 | static jfieldID java_lang_Throwable_cause; |
| 151 | static jfieldID java_lang_Throwable_detailMessage; |
| 152 | static jfieldID java_lang_Throwable_stackTrace; |
| 153 | static jfieldID java_lang_Throwable_stackState; |
| 154 | static jfieldID java_lang_Throwable_suppressedExceptions; |
Orion Hodson | 928033d | 2018-02-07 05:30:54 +0000 | [diff] [blame] | 155 | static jfieldID java_nio_ByteBuffer_address; |
| 156 | static jfieldID java_nio_ByteBuffer_hb; |
| 157 | static jfieldID java_nio_ByteBuffer_isReadOnly; |
| 158 | static jfieldID java_nio_ByteBuffer_limit; |
| 159 | static jfieldID java_nio_ByteBuffer_offset; |
Elliott Hughes | aecb5f3 | 2013-03-28 08:27:38 -0700 | [diff] [blame] | 160 | static jfieldID java_nio_DirectByteBuffer_capacity; |
| 161 | static jfieldID java_nio_DirectByteBuffer_effectiveDirectAddress; |
Orion Hodson | 928033d | 2018-02-07 05:30:54 +0000 | [diff] [blame] | 162 | |
Brian Carlstrom | 3437531 | 2014-09-10 23:10:47 -0700 | [diff] [blame] | 163 | static jfieldID java_util_Collections_EMPTY_LIST; |
Neil Fuller | c0f02d4 | 2018-06-11 09:49:01 +0000 | [diff] [blame] | 164 | static jfieldID libcore_util_EmptyArray_STACK_TRACE_ELEMENT; |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 165 | static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_data; |
| 166 | static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_length; |
| 167 | static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_offset; |
| 168 | static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_type; |
| 169 | }; |
| 170 | |
| 171 | } // namespace art |
| 172 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 173 | #endif // ART_RUNTIME_WELL_KNOWN_CLASSES_H_ |