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 | |
| 17 | #include "well_known_classes.h" |
| 18 | |
| 19 | #include <stdlib.h> |
| 20 | |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 21 | #include <sstream> |
| 22 | |
Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame] | 23 | #include "android-base/stringprintf.h" |
| 24 | |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 25 | #include "base/logging.h" |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 26 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Andreas Gampe | 13b2784 | 2016-11-07 16:48:23 -0800 | [diff] [blame] | 27 | #include "jni_internal.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 28 | #include "mirror/class.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 29 | #include "mirror/throwable.h" |
Andreas Gampe | 373a9b5 | 2017-10-18 09:01:57 -0700 | [diff] [blame^] | 30 | #include "nativehelper/scoped_local_ref.h" |
Mathieu Chartier | c4f3925 | 2016-10-05 18:32:08 -0700 | [diff] [blame] | 31 | #include "obj_ptr-inl.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 32 | #include "scoped_thread_state_change-inl.h" |
Andreas Gampe | b486a98 | 2017-06-01 13:45:54 -0700 | [diff] [blame] | 33 | #include "thread-current-inl.h" |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 34 | |
| 35 | namespace art { |
| 36 | |
Igor Murashkin | 367f3dd | 2016-09-01 17:00:24 -0700 | [diff] [blame] | 37 | jclass WellKnownClasses::dalvik_annotation_optimization_CriticalNative; |
Igor Murashkin | 9d4b6da | 2016-07-29 09:51:58 -0700 | [diff] [blame] | 38 | jclass WellKnownClasses::dalvik_annotation_optimization_FastNative; |
Andreas Gampe | 46aba36 | 2016-10-28 14:33:28 -0700 | [diff] [blame] | 39 | jclass WellKnownClasses::dalvik_system_BaseDexClassLoader; |
Calin Juravle | 7865ac7 | 2017-06-28 11:03:12 -0700 | [diff] [blame] | 40 | jclass WellKnownClasses::dalvik_system_DelegateLastClassLoader; |
Nicolas Geoffray | 7d8d8ff | 2016-11-02 12:38:05 +0000 | [diff] [blame] | 41 | jclass WellKnownClasses::dalvik_system_DexClassLoader; |
Mathieu Chartier | 6bcae8f | 2014-09-04 18:33:17 -0700 | [diff] [blame] | 42 | jclass WellKnownClasses::dalvik_system_DexFile; |
| 43 | jclass WellKnownClasses::dalvik_system_DexPathList; |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 44 | jclass WellKnownClasses::dalvik_system_DexPathList__Element; |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 45 | jclass WellKnownClasses::dalvik_system_EmulatedStackFrame; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 46 | jclass WellKnownClasses::dalvik_system_PathClassLoader; |
Mathieu Chartier | b5de3bb | 2015-06-05 13:21:05 -0700 | [diff] [blame] | 47 | jclass WellKnownClasses::dalvik_system_VMRuntime; |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 48 | jclass WellKnownClasses::java_lang_annotation_Annotation__array; |
Mathieu Chartier | 6bcae8f | 2014-09-04 18:33:17 -0700 | [diff] [blame] | 49 | jclass WellKnownClasses::java_lang_BootClassLoader; |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 50 | jclass WellKnownClasses::java_lang_ClassLoader; |
| 51 | jclass WellKnownClasses::java_lang_ClassNotFoundException; |
| 52 | jclass WellKnownClasses::java_lang_Daemons; |
| 53 | jclass WellKnownClasses::java_lang_Error; |
Orion Hodson | 811bd5f | 2016-12-07 11:35:37 +0000 | [diff] [blame] | 54 | jclass WellKnownClasses::java_lang_invoke_MethodHandle; |
Jeff Hao | c92a7a1 | 2016-06-06 11:09:20 -0700 | [diff] [blame] | 55 | jclass WellKnownClasses::java_lang_IllegalAccessError; |
| 56 | jclass WellKnownClasses::java_lang_NoClassDefFoundError; |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 57 | jclass WellKnownClasses::java_lang_Object; |
Mathieu Chartier | a61894d | 2015-04-23 16:32:54 -0700 | [diff] [blame] | 58 | jclass WellKnownClasses::java_lang_OutOfMemoryError; |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 59 | jclass WellKnownClasses::java_lang_reflect_Constructor; |
Neil Fuller | 0e84439 | 2016-09-08 13:43:31 +0100 | [diff] [blame] | 60 | jclass WellKnownClasses::java_lang_reflect_Executable; |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 61 | jclass WellKnownClasses::java_lang_reflect_Field; |
| 62 | jclass WellKnownClasses::java_lang_reflect_Method; |
Neil Fuller | 79a21e7 | 2016-09-09 14:24:51 +0100 | [diff] [blame] | 63 | jclass WellKnownClasses::java_lang_reflect_Parameter; |
| 64 | jclass WellKnownClasses::java_lang_reflect_Parameter__array; |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 65 | jclass WellKnownClasses::java_lang_reflect_Proxy; |
Elliott Hughes | a4f9474 | 2012-05-29 16:28:38 -0700 | [diff] [blame] | 66 | jclass WellKnownClasses::java_lang_RuntimeException; |
Ian Rogers | 120f1c7 | 2012-09-28 17:17:10 -0700 | [diff] [blame] | 67 | jclass WellKnownClasses::java_lang_StackOverflowError; |
Ian Rogers | dd157d7 | 2014-05-15 14:47:50 -0700 | [diff] [blame] | 68 | jclass WellKnownClasses::java_lang_String; |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 69 | jclass WellKnownClasses::java_lang_StringFactory; |
Mathieu Chartier | 987ccff | 2013-07-08 11:05:21 -0700 | [diff] [blame] | 70 | jclass WellKnownClasses::java_lang_System; |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 71 | jclass WellKnownClasses::java_lang_Thread; |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 72 | jclass WellKnownClasses::java_lang_ThreadGroup; |
Elliott Hughes | a4f9474 | 2012-05-29 16:28:38 -0700 | [diff] [blame] | 73 | jclass WellKnownClasses::java_lang_Throwable; |
Elliott Hughes | aecb5f3 | 2013-03-28 08:27:38 -0700 | [diff] [blame] | 74 | jclass WellKnownClasses::java_nio_DirectByteBuffer; |
Sebastien Hertz | e49e195 | 2014-10-13 11:27:13 +0200 | [diff] [blame] | 75 | jclass WellKnownClasses::java_util_ArrayList; |
Andreas Gampe | 7ea6f79 | 2014-07-14 16:21:44 -0700 | [diff] [blame] | 76 | jclass WellKnownClasses::java_util_Collections; |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 77 | jclass WellKnownClasses::libcore_reflect_AnnotationFactory; |
| 78 | jclass WellKnownClasses::libcore_reflect_AnnotationMember; |
Andreas Gampe | 7ea6f79 | 2014-07-14 16:21:44 -0700 | [diff] [blame] | 79 | jclass WellKnownClasses::libcore_util_EmptyArray; |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 80 | jclass WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk; |
| 81 | jclass WellKnownClasses::org_apache_harmony_dalvik_ddmc_DdmServer; |
| 82 | |
Mathieu Chartier | b5de3bb | 2015-06-05 13:21:05 -0700 | [diff] [blame] | 83 | jmethodID WellKnownClasses::dalvik_system_VMRuntime_runFinalization; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 84 | jmethodID WellKnownClasses::java_lang_Boolean_valueOf; |
| 85 | jmethodID WellKnownClasses::java_lang_Byte_valueOf; |
| 86 | jmethodID WellKnownClasses::java_lang_Character_valueOf; |
Elliott Hughes | a4f9474 | 2012-05-29 16:28:38 -0700 | [diff] [blame] | 87 | jmethodID WellKnownClasses::java_lang_ClassLoader_loadClass; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 88 | jmethodID WellKnownClasses::java_lang_ClassNotFoundException_init; |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 89 | jmethodID WellKnownClasses::java_lang_Daemons_requestHeapTrim; |
| 90 | jmethodID WellKnownClasses::java_lang_Daemons_start; |
Mathieu Chartier | cef50f0 | 2014-12-09 17:38:52 -0800 | [diff] [blame] | 91 | jmethodID WellKnownClasses::java_lang_Daemons_stop; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 92 | jmethodID WellKnownClasses::java_lang_Double_valueOf; |
| 93 | jmethodID WellKnownClasses::java_lang_Float_valueOf; |
| 94 | jmethodID WellKnownClasses::java_lang_Integer_valueOf; |
Orion Hodson | 811bd5f | 2016-12-07 11:35:37 +0000 | [diff] [blame] | 95 | jmethodID WellKnownClasses::java_lang_invoke_MethodHandle_invoke; |
| 96 | jmethodID WellKnownClasses::java_lang_invoke_MethodHandle_invokeExact; |
Orion Hodson | f8db2c3 | 2017-07-07 20:07:12 +0100 | [diff] [blame] | 97 | jmethodID WellKnownClasses::java_lang_invoke_MethodHandles_lookup; |
| 98 | jmethodID WellKnownClasses::java_lang_invoke_MethodHandles_Lookup_findConstructor; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 99 | jmethodID WellKnownClasses::java_lang_Long_valueOf; |
Elliott Hughes | a4f9474 | 2012-05-29 16:28:38 -0700 | [diff] [blame] | 100 | jmethodID WellKnownClasses::java_lang_ref_FinalizerReference_add; |
| 101 | jmethodID WellKnownClasses::java_lang_ref_ReferenceQueue_add; |
Neil Fuller | 79a21e7 | 2016-09-09 14:24:51 +0100 | [diff] [blame] | 102 | jmethodID WellKnownClasses::java_lang_reflect_Parameter_init; |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 103 | jmethodID WellKnownClasses::java_lang_reflect_Proxy_invoke; |
Ian Rogers | ef28b14 | 2012-11-30 14:22:18 -0800 | [diff] [blame] | 104 | jmethodID WellKnownClasses::java_lang_Runtime_nativeLoad; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 105 | jmethodID WellKnownClasses::java_lang_Short_valueOf; |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 106 | jmethodID WellKnownClasses::java_lang_String_charAt; |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 107 | jmethodID WellKnownClasses::java_lang_System_runFinalization = nullptr; |
Tobias Thierer | 5cbe65d | 2016-07-22 18:37:59 +0100 | [diff] [blame] | 108 | jmethodID WellKnownClasses::java_lang_Thread_dispatchUncaughtException; |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 109 | jmethodID WellKnownClasses::java_lang_Thread_init; |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 110 | jmethodID WellKnownClasses::java_lang_Thread_run; |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 111 | jmethodID WellKnownClasses::java_lang_ThreadGroup_removeThread; |
Elliott Hughes | aecb5f3 | 2013-03-28 08:27:38 -0700 | [diff] [blame] | 112 | jmethodID WellKnownClasses::java_nio_DirectByteBuffer_init; |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 113 | jmethodID WellKnownClasses::libcore_reflect_AnnotationFactory_createAnnotation; |
| 114 | jmethodID WellKnownClasses::libcore_reflect_AnnotationMember_init; |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 115 | jmethodID WellKnownClasses::org_apache_harmony_dalvik_ddmc_DdmServer_broadcast; |
| 116 | jmethodID WellKnownClasses::org_apache_harmony_dalvik_ddmc_DdmServer_dispatch; |
| 117 | |
Mathieu Chartier | 6bcae8f | 2014-09-04 18:33:17 -0700 | [diff] [blame] | 118 | jfieldID WellKnownClasses::dalvik_system_DexFile_cookie; |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 119 | jfieldID WellKnownClasses::dalvik_system_DexFile_fileName; |
Andreas Gampe | 46aba36 | 2016-10-28 14:33:28 -0700 | [diff] [blame] | 120 | jfieldID WellKnownClasses::dalvik_system_BaseDexClassLoader_pathList; |
Mathieu Chartier | 6bcae8f | 2014-09-04 18:33:17 -0700 | [diff] [blame] | 121 | jfieldID WellKnownClasses::dalvik_system_DexPathList_dexElements; |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 122 | jfieldID WellKnownClasses::dalvik_system_DexPathList__Element_dexFile; |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 123 | jfieldID WellKnownClasses::java_lang_Thread_daemon; |
| 124 | jfieldID WellKnownClasses::java_lang_Thread_group; |
| 125 | jfieldID WellKnownClasses::java_lang_Thread_lock; |
| 126 | jfieldID WellKnownClasses::java_lang_Thread_name; |
| 127 | jfieldID WellKnownClasses::java_lang_Thread_priority; |
Anwar Ghuloum | 3c50a4b | 2013-06-21 13:05:23 -0700 | [diff] [blame] | 128 | jfieldID WellKnownClasses::java_lang_Thread_nativePeer; |
Sebastien Hertz | e49e195 | 2014-10-13 11:27:13 +0200 | [diff] [blame] | 129 | jfieldID WellKnownClasses::java_lang_ThreadGroup_groups; |
Przemyslaw Szczepaniak | 464595f | 2015-11-24 11:59:59 +0000 | [diff] [blame] | 130 | jfieldID WellKnownClasses::java_lang_ThreadGroup_ngroups; |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 131 | jfieldID WellKnownClasses::java_lang_ThreadGroup_mainThreadGroup; |
| 132 | jfieldID WellKnownClasses::java_lang_ThreadGroup_name; |
Sebastien Hertz | e49e195 | 2014-10-13 11:27:13 +0200 | [diff] [blame] | 133 | jfieldID WellKnownClasses::java_lang_ThreadGroup_parent; |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 134 | jfieldID WellKnownClasses::java_lang_ThreadGroup_systemThreadGroup; |
Brian Carlstrom | 3437531 | 2014-09-10 23:10:47 -0700 | [diff] [blame] | 135 | jfieldID WellKnownClasses::java_lang_Throwable_cause; |
| 136 | jfieldID WellKnownClasses::java_lang_Throwable_detailMessage; |
| 137 | jfieldID WellKnownClasses::java_lang_Throwable_stackTrace; |
| 138 | jfieldID WellKnownClasses::java_lang_Throwable_stackState; |
| 139 | jfieldID WellKnownClasses::java_lang_Throwable_suppressedExceptions; |
Neil Fuller | 0e84439 | 2016-09-08 13:43:31 +0100 | [diff] [blame] | 140 | jfieldID WellKnownClasses::java_lang_reflect_Executable_artMethod; |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 141 | jfieldID WellKnownClasses::java_lang_reflect_Proxy_h; |
Elliott Hughes | aecb5f3 | 2013-03-28 08:27:38 -0700 | [diff] [blame] | 142 | jfieldID WellKnownClasses::java_nio_DirectByteBuffer_capacity; |
| 143 | jfieldID WellKnownClasses::java_nio_DirectByteBuffer_effectiveDirectAddress; |
Sebastien Hertz | e49e195 | 2014-10-13 11:27:13 +0200 | [diff] [blame] | 144 | jfieldID WellKnownClasses::java_util_ArrayList_array; |
| 145 | jfieldID WellKnownClasses::java_util_ArrayList_size; |
Brian Carlstrom | 3437531 | 2014-09-10 23:10:47 -0700 | [diff] [blame] | 146 | jfieldID WellKnownClasses::java_util_Collections_EMPTY_LIST; |
| 147 | jfieldID WellKnownClasses::libcore_util_EmptyArray_STACK_TRACE_ELEMENT; |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 148 | jfieldID WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_data; |
| 149 | jfieldID WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_length; |
| 150 | jfieldID WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_offset; |
| 151 | jfieldID WellKnownClasses::org_apache_harmony_dalvik_ddmc_Chunk_type; |
| 152 | |
| 153 | static jclass CacheClass(JNIEnv* env, const char* jni_class_name) { |
| 154 | ScopedLocalRef<jclass> c(env, env->FindClass(jni_class_name)); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 155 | if (c.get() == nullptr) { |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 156 | LOG(FATAL) << "Couldn't find class: " << jni_class_name; |
| 157 | } |
| 158 | return reinterpret_cast<jclass>(env->NewGlobalRef(c.get())); |
| 159 | } |
| 160 | |
Brian Carlstrom | 3c821c6 | 2014-09-10 10:08:37 -0700 | [diff] [blame] | 161 | static jfieldID CacheField(JNIEnv* env, jclass c, bool is_static, |
| 162 | const char* name, const char* signature) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 163 | jfieldID fid = is_static ? env->GetStaticFieldID(c, name, signature) : |
| 164 | env->GetFieldID(c, name, signature); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 165 | if (fid == nullptr) { |
Brian Carlstrom | 3c821c6 | 2014-09-10 10:08:37 -0700 | [diff] [blame] | 166 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 167 | if (soa.Self()->IsExceptionPending()) { |
Andreas Gampe | 3fec9ac | 2016-09-13 10:47:28 -0700 | [diff] [blame] | 168 | LOG(FATAL_WITHOUT_ABORT) << soa.Self()->GetException()->Dump(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 169 | } |
Brian Carlstrom | 3c821c6 | 2014-09-10 10:08:37 -0700 | [diff] [blame] | 170 | std::ostringstream os; |
| 171 | WellKnownClasses::ToClass(c)->DumpClass(os, mirror::Class::kDumpClassFullDetail); |
| 172 | LOG(FATAL) << "Couldn't find field \"" << name << "\" with signature \"" << signature << "\": " |
| 173 | << os.str(); |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 174 | } |
| 175 | return fid; |
| 176 | } |
| 177 | |
Orion Hodson | f8db2c3 | 2017-07-07 20:07:12 +0100 | [diff] [blame] | 178 | static jmethodID CacheMethod(JNIEnv* env, jclass c, bool is_static, |
| 179 | const char* name, const char* signature) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 180 | jmethodID mid = is_static ? env->GetStaticMethodID(c, name, signature) : |
| 181 | env->GetMethodID(c, name, signature); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 182 | if (mid == nullptr) { |
Brian Carlstrom | 3c821c6 | 2014-09-10 10:08:37 -0700 | [diff] [blame] | 183 | ScopedObjectAccess soa(env); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 184 | if (soa.Self()->IsExceptionPending()) { |
Andreas Gampe | 3fec9ac | 2016-09-13 10:47:28 -0700 | [diff] [blame] | 185 | LOG(FATAL_WITHOUT_ABORT) << soa.Self()->GetException()->Dump(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 186 | } |
Brian Carlstrom | 3c821c6 | 2014-09-10 10:08:37 -0700 | [diff] [blame] | 187 | std::ostringstream os; |
| 188 | WellKnownClasses::ToClass(c)->DumpClass(os, mirror::Class::kDumpClassFullDetail); |
| 189 | LOG(FATAL) << "Couldn't find method \"" << name << "\" with signature \"" << signature << "\": " |
| 190 | << os.str(); |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 191 | } |
| 192 | return mid; |
| 193 | } |
| 194 | |
Orion Hodson | f8db2c3 | 2017-07-07 20:07:12 +0100 | [diff] [blame] | 195 | static jmethodID CacheMethod(JNIEnv* env, const char* klass, bool is_static, |
| 196 | const char* name, const char* signature) { |
| 197 | ScopedLocalRef<jclass> java_class(env, env->FindClass(klass)); |
| 198 | return CacheMethod(env, java_class.get(), is_static, name, signature); |
| 199 | } |
| 200 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 201 | static jmethodID CachePrimitiveBoxingMethod(JNIEnv* env, char prim_name, const char* boxed_name) { |
| 202 | ScopedLocalRef<jclass> boxed_class(env, env->FindClass(boxed_name)); |
| 203 | return CacheMethod(env, boxed_class.get(), true, "valueOf", |
Andreas Gampe | 46ee31b | 2016-12-14 10:11:49 -0800 | [diff] [blame] | 204 | android::base::StringPrintf("(%c)L%s;", prim_name, boxed_name).c_str()); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 207 | #define STRING_INIT_LIST(V) \ |
| 208 | V(java_lang_String_init, "()V", newEmptyString, "newEmptyString", "()Ljava/lang/String;", NewEmptyString) \ |
| 209 | V(java_lang_String_init_B, "([B)V", newStringFromBytes_B, "newStringFromBytes", "([B)Ljava/lang/String;", NewStringFromBytes_B) \ |
| 210 | V(java_lang_String_init_BI, "([BI)V", newStringFromBytes_BI, "newStringFromBytes", "([BI)Ljava/lang/String;", NewStringFromBytes_BI) \ |
| 211 | V(java_lang_String_init_BII, "([BII)V", newStringFromBytes_BII, "newStringFromBytes", "([BII)Ljava/lang/String;", NewStringFromBytes_BII) \ |
| 212 | V(java_lang_String_init_BIII, "([BIII)V", newStringFromBytes_BIII, "newStringFromBytes", "([BIII)Ljava/lang/String;", NewStringFromBytes_BIII) \ |
| 213 | V(java_lang_String_init_BIIString, "([BIILjava/lang/String;)V", newStringFromBytes_BIIString, "newStringFromBytes", "([BIILjava/lang/String;)Ljava/lang/String;", NewStringFromBytes_BIIString) \ |
| 214 | V(java_lang_String_init_BString, "([BLjava/lang/String;)V", newStringFromBytes_BString, "newStringFromBytes", "([BLjava/lang/String;)Ljava/lang/String;", NewStringFromBytes_BString) \ |
| 215 | V(java_lang_String_init_BIICharset, "([BIILjava/nio/charset/Charset;)V", newStringFromBytes_BIICharset, "newStringFromBytes", "([BIILjava/nio/charset/Charset;)Ljava/lang/String;", NewStringFromBytes_BIICharset) \ |
| 216 | V(java_lang_String_init_BCharset, "([BLjava/nio/charset/Charset;)V", newStringFromBytes_BCharset, "newStringFromBytes", "([BLjava/nio/charset/Charset;)Ljava/lang/String;", NewStringFromBytes_BCharset) \ |
| 217 | V(java_lang_String_init_C, "([C)V", newStringFromChars_C, "newStringFromChars", "([C)Ljava/lang/String;", NewStringFromChars_C) \ |
| 218 | V(java_lang_String_init_CII, "([CII)V", newStringFromChars_CII, "newStringFromChars", "([CII)Ljava/lang/String;", NewStringFromChars_CII) \ |
| 219 | V(java_lang_String_init_IIC, "(II[C)V", newStringFromChars_IIC, "newStringFromChars", "(II[C)Ljava/lang/String;", NewStringFromChars_IIC) \ |
| 220 | V(java_lang_String_init_String, "(Ljava/lang/String;)V", newStringFromString, "newStringFromString", "(Ljava/lang/String;)Ljava/lang/String;", NewStringFromString) \ |
| 221 | V(java_lang_String_init_StringBuffer, "(Ljava/lang/StringBuffer;)V", newStringFromStringBuffer, "newStringFromStringBuffer", "(Ljava/lang/StringBuffer;)Ljava/lang/String;", NewStringFromStringBuffer) \ |
| 222 | V(java_lang_String_init_III, "([III)V", newStringFromCodePoints, "newStringFromCodePoints", "([III)Ljava/lang/String;", NewStringFromCodePoints) \ |
| 223 | V(java_lang_String_init_StringBuilder, "(Ljava/lang/StringBuilder;)V", newStringFromStringBuilder, "newStringFromStringBuilder", "(Ljava/lang/StringBuilder;)Ljava/lang/String;", NewStringFromStringBuilder) \ |
| 224 | |
| 225 | #define STATIC_STRING_INIT(init_runtime_name, init_signature, new_runtime_name, ...) \ |
| 226 | static ArtMethod* init_runtime_name; \ |
| 227 | static ArtMethod* new_runtime_name; |
| 228 | STRING_INIT_LIST(STATIC_STRING_INIT) |
| 229 | #undef STATIC_STRING_INIT |
| 230 | |
| 231 | void WellKnownClasses::InitStringInit(JNIEnv* env) { |
| 232 | ScopedObjectAccess soa(Thread::Current()); |
| 233 | #define LOAD_STRING_INIT(init_runtime_name, init_signature, new_runtime_name, \ |
| 234 | new_java_name, new_signature, ...) \ |
Andreas Gampe | 13b2784 | 2016-11-07 16:48:23 -0800 | [diff] [blame] | 235 | init_runtime_name = jni::DecodeArtMethod( \ |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 236 | CacheMethod(env, java_lang_String, false, "<init>", init_signature)); \ |
Andreas Gampe | 13b2784 | 2016-11-07 16:48:23 -0800 | [diff] [blame] | 237 | new_runtime_name = jni::DecodeArtMethod( \ |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 238 | CacheMethod(env, java_lang_StringFactory, true, new_java_name, new_signature)); |
| 239 | STRING_INIT_LIST(LOAD_STRING_INIT) |
| 240 | #undef LOAD_STRING_INIT |
| 241 | } |
| 242 | |
| 243 | void Thread::InitStringEntryPoints() { |
| 244 | QuickEntryPoints* qpoints = &tlsPtr_.quick_entrypoints; |
| 245 | #define SET_ENTRY_POINT(init_runtime_name, init_signature, new_runtime_name, \ |
| 246 | new_java_name, new_signature, entry_point_name) \ |
| 247 | qpoints->p ## entry_point_name = reinterpret_cast<void(*)()>(new_runtime_name); |
| 248 | STRING_INIT_LIST(SET_ENTRY_POINT) |
| 249 | #undef SET_ENTRY_POINT |
| 250 | } |
| 251 | |
| 252 | ArtMethod* WellKnownClasses::StringInitToStringFactory(ArtMethod* string_init) { |
| 253 | #define TO_STRING_FACTORY(init_runtime_name, init_signature, new_runtime_name, \ |
| 254 | new_java_name, new_signature, entry_point_name) \ |
Andreas Gampe | ca620d7 | 2016-11-08 08:09:33 -0800 | [diff] [blame] | 255 | if (string_init == (init_runtime_name)) { \ |
| 256 | return (new_runtime_name); \ |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 257 | } |
| 258 | STRING_INIT_LIST(TO_STRING_FACTORY) |
| 259 | #undef TO_STRING_FACTORY |
| 260 | LOG(FATAL) << "Could not find StringFactory method for String.<init>"; |
| 261 | return nullptr; |
| 262 | } |
| 263 | |
| 264 | uint32_t WellKnownClasses::StringInitToEntryPoint(ArtMethod* string_init) { |
| 265 | #define TO_ENTRY_POINT(init_runtime_name, init_signature, new_runtime_name, \ |
| 266 | new_java_name, new_signature, entry_point_name) \ |
Andreas Gampe | ca620d7 | 2016-11-08 08:09:33 -0800 | [diff] [blame] | 267 | if (string_init == (init_runtime_name)) { \ |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 268 | return kQuick ## entry_point_name; \ |
| 269 | } |
| 270 | STRING_INIT_LIST(TO_ENTRY_POINT) |
| 271 | #undef TO_STRING_FACTORY |
| 272 | LOG(FATAL) << "Could not find StringFactory method for String.<init>"; |
| 273 | return 0; |
| 274 | } |
| 275 | #undef STRING_INIT_LIST |
| 276 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 277 | void WellKnownClasses::Init(JNIEnv* env) { |
Igor Murashkin | 367f3dd | 2016-09-01 17:00:24 -0700 | [diff] [blame] | 278 | dalvik_annotation_optimization_CriticalNative = |
| 279 | CacheClass(env, "dalvik/annotation/optimization/CriticalNative"); |
Igor Murashkin | 9d4b6da | 2016-07-29 09:51:58 -0700 | [diff] [blame] | 280 | dalvik_annotation_optimization_FastNative = CacheClass(env, "dalvik/annotation/optimization/FastNative"); |
Andreas Gampe | 46aba36 | 2016-10-28 14:33:28 -0700 | [diff] [blame] | 281 | dalvik_system_BaseDexClassLoader = CacheClass(env, "dalvik/system/BaseDexClassLoader"); |
Calin Juravle | 7865ac7 | 2017-06-28 11:03:12 -0700 | [diff] [blame] | 282 | dalvik_system_DelegateLastClassLoader = CacheClass(env, "dalvik/system/DelegateLastClassLoader"); |
Nicolas Geoffray | 7d8d8ff | 2016-11-02 12:38:05 +0000 | [diff] [blame] | 283 | dalvik_system_DexClassLoader = CacheClass(env, "dalvik/system/DexClassLoader"); |
Mathieu Chartier | 6bcae8f | 2014-09-04 18:33:17 -0700 | [diff] [blame] | 284 | dalvik_system_DexFile = CacheClass(env, "dalvik/system/DexFile"); |
| 285 | dalvik_system_DexPathList = CacheClass(env, "dalvik/system/DexPathList"); |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 286 | dalvik_system_DexPathList__Element = CacheClass(env, "dalvik/system/DexPathList$Element"); |
Narayan Kamath | c3b7f1a | 2016-10-19 11:05:04 +0100 | [diff] [blame] | 287 | dalvik_system_EmulatedStackFrame = CacheClass(env, "dalvik/system/EmulatedStackFrame"); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 288 | dalvik_system_PathClassLoader = CacheClass(env, "dalvik/system/PathClassLoader"); |
Mathieu Chartier | b5de3bb | 2015-06-05 13:21:05 -0700 | [diff] [blame] | 289 | dalvik_system_VMRuntime = CacheClass(env, "dalvik/system/VMRuntime"); |
| 290 | |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 291 | java_lang_annotation_Annotation__array = CacheClass(env, "[Ljava/lang/annotation/Annotation;"); |
Mathieu Chartier | 6bcae8f | 2014-09-04 18:33:17 -0700 | [diff] [blame] | 292 | java_lang_BootClassLoader = CacheClass(env, "java/lang/BootClassLoader"); |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 293 | java_lang_ClassLoader = CacheClass(env, "java/lang/ClassLoader"); |
| 294 | java_lang_ClassNotFoundException = CacheClass(env, "java/lang/ClassNotFoundException"); |
| 295 | java_lang_Daemons = CacheClass(env, "java/lang/Daemons"); |
Ian Rogers | af6e67a | 2013-01-16 08:38:37 -0800 | [diff] [blame] | 296 | java_lang_Object = CacheClass(env, "java/lang/Object"); |
Mathieu Chartier | a61894d | 2015-04-23 16:32:54 -0700 | [diff] [blame] | 297 | java_lang_OutOfMemoryError = CacheClass(env, "java/lang/OutOfMemoryError"); |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 298 | java_lang_Error = CacheClass(env, "java/lang/Error"); |
Jeff Hao | c92a7a1 | 2016-06-06 11:09:20 -0700 | [diff] [blame] | 299 | java_lang_IllegalAccessError = CacheClass(env, "java/lang/IllegalAccessError"); |
Orion Hodson | 811bd5f | 2016-12-07 11:35:37 +0000 | [diff] [blame] | 300 | java_lang_invoke_MethodHandle = CacheClass(env, "java/lang/invoke/MethodHandle"); |
Jeff Hao | c92a7a1 | 2016-06-06 11:09:20 -0700 | [diff] [blame] | 301 | java_lang_NoClassDefFoundError = CacheClass(env, "java/lang/NoClassDefFoundError"); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 302 | java_lang_reflect_Constructor = CacheClass(env, "java/lang/reflect/Constructor"); |
Neil Fuller | 0e84439 | 2016-09-08 13:43:31 +0100 | [diff] [blame] | 303 | java_lang_reflect_Executable = CacheClass(env, "java/lang/reflect/Executable"); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 304 | java_lang_reflect_Field = CacheClass(env, "java/lang/reflect/Field"); |
| 305 | java_lang_reflect_Method = CacheClass(env, "java/lang/reflect/Method"); |
Neil Fuller | 79a21e7 | 2016-09-09 14:24:51 +0100 | [diff] [blame] | 306 | java_lang_reflect_Parameter = CacheClass(env, "java/lang/reflect/Parameter"); |
| 307 | java_lang_reflect_Parameter__array = CacheClass(env, "[Ljava/lang/reflect/Parameter;"); |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 308 | java_lang_reflect_Proxy = CacheClass(env, "java/lang/reflect/Proxy"); |
Elliott Hughes | a4f9474 | 2012-05-29 16:28:38 -0700 | [diff] [blame] | 309 | java_lang_RuntimeException = CacheClass(env, "java/lang/RuntimeException"); |
Ian Rogers | 120f1c7 | 2012-09-28 17:17:10 -0700 | [diff] [blame] | 310 | java_lang_StackOverflowError = CacheClass(env, "java/lang/StackOverflowError"); |
Ian Rogers | dd157d7 | 2014-05-15 14:47:50 -0700 | [diff] [blame] | 311 | java_lang_String = CacheClass(env, "java/lang/String"); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 312 | java_lang_StringFactory = CacheClass(env, "java/lang/StringFactory"); |
Mathieu Chartier | 987ccff | 2013-07-08 11:05:21 -0700 | [diff] [blame] | 313 | java_lang_System = CacheClass(env, "java/lang/System"); |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 314 | java_lang_Thread = CacheClass(env, "java/lang/Thread"); |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 315 | java_lang_ThreadGroup = CacheClass(env, "java/lang/ThreadGroup"); |
Elliott Hughes | a4f9474 | 2012-05-29 16:28:38 -0700 | [diff] [blame] | 316 | java_lang_Throwable = CacheClass(env, "java/lang/Throwable"); |
Elliott Hughes | aecb5f3 | 2013-03-28 08:27:38 -0700 | [diff] [blame] | 317 | java_nio_DirectByteBuffer = CacheClass(env, "java/nio/DirectByteBuffer"); |
Sebastien Hertz | e49e195 | 2014-10-13 11:27:13 +0200 | [diff] [blame] | 318 | java_util_ArrayList = CacheClass(env, "java/util/ArrayList"); |
Andreas Gampe | 7ea6f79 | 2014-07-14 16:21:44 -0700 | [diff] [blame] | 319 | java_util_Collections = CacheClass(env, "java/util/Collections"); |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 320 | libcore_reflect_AnnotationFactory = CacheClass(env, "libcore/reflect/AnnotationFactory"); |
| 321 | libcore_reflect_AnnotationMember = CacheClass(env, "libcore/reflect/AnnotationMember"); |
Andreas Gampe | 7ea6f79 | 2014-07-14 16:21:44 -0700 | [diff] [blame] | 322 | libcore_util_EmptyArray = CacheClass(env, "libcore/util/EmptyArray"); |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 323 | org_apache_harmony_dalvik_ddmc_Chunk = CacheClass(env, "org/apache/harmony/dalvik/ddmc/Chunk"); |
| 324 | org_apache_harmony_dalvik_ddmc_DdmServer = CacheClass(env, "org/apache/harmony/dalvik/ddmc/DdmServer"); |
| 325 | |
Mathieu Chartier | b5de3bb | 2015-06-05 13:21:05 -0700 | [diff] [blame] | 326 | dalvik_system_VMRuntime_runFinalization = CacheMethod(env, dalvik_system_VMRuntime, true, "runFinalization", "(J)V"); |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 327 | java_lang_ClassNotFoundException_init = CacheMethod(env, java_lang_ClassNotFoundException, false, "<init>", "(Ljava/lang/String;Ljava/lang/Throwable;)V"); |
Elliott Hughes | a4f9474 | 2012-05-29 16:28:38 -0700 | [diff] [blame] | 328 | java_lang_ClassLoader_loadClass = CacheMethod(env, java_lang_ClassLoader, false, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"); |
Mathieu Chartier | 7664f5c | 2012-06-08 18:15:32 -0700 | [diff] [blame] | 329 | |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 330 | java_lang_Daemons_requestHeapTrim = CacheMethod(env, java_lang_Daemons, true, "requestHeapTrim", "()V"); |
| 331 | java_lang_Daemons_start = CacheMethod(env, java_lang_Daemons, true, "start", "()V"); |
Mathieu Chartier | cef50f0 | 2014-12-09 17:38:52 -0800 | [diff] [blame] | 332 | java_lang_Daemons_stop = CacheMethod(env, java_lang_Daemons, true, "stop", "()V"); |
Orion Hodson | f8db2c3 | 2017-07-07 20:07:12 +0100 | [diff] [blame] | 333 | java_lang_invoke_MethodHandle_invoke = CacheMethod(env, java_lang_invoke_MethodHandle, false, "invoke", "([Ljava/lang/Object;)Ljava/lang/Object;"); |
| 334 | java_lang_invoke_MethodHandle_invokeExact = CacheMethod(env, java_lang_invoke_MethodHandle, false, "invokeExact", "([Ljava/lang/Object;)Ljava/lang/Object;"); |
| 335 | java_lang_invoke_MethodHandles_lookup = CacheMethod(env, "java/lang/invoke/MethodHandles", true, "lookup", "()Ljava/lang/invoke/MethodHandles$Lookup;"); |
| 336 | java_lang_invoke_MethodHandles_Lookup_findConstructor = CacheMethod(env, "java/lang/invoke/MethodHandles$Lookup", false, "findConstructor", "(Ljava/lang/Class;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/MethodHandle;"); |
| 337 | java_lang_ref_FinalizerReference_add = CacheMethod(env, "java/lang/ref/FinalizerReference", true, "add", "(Ljava/lang/Object;)V"); |
| 338 | java_lang_ref_ReferenceQueue_add = CacheMethod(env, "java/lang/ref/ReferenceQueue", true, "add", "(Ljava/lang/ref/Reference;)V"); |
Elliott Hughes | a4f9474 | 2012-05-29 16:28:38 -0700 | [diff] [blame] | 339 | |
Neil Fuller | 79a21e7 | 2016-09-09 14:24:51 +0100 | [diff] [blame] | 340 | java_lang_reflect_Parameter_init = CacheMethod(env, java_lang_reflect_Parameter, false, "<init>", "(Ljava/lang/String;ILjava/lang/reflect/Executable;I)V"); |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 341 | java_lang_String_charAt = CacheMethod(env, java_lang_String, false, "charAt", "(I)C"); |
Tobias Thierer | 5cbe65d | 2016-07-22 18:37:59 +0100 | [diff] [blame] | 342 | java_lang_Thread_dispatchUncaughtException = CacheMethod(env, java_lang_Thread, false, "dispatchUncaughtException", "(Ljava/lang/Throwable;)V"); |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 343 | java_lang_Thread_init = CacheMethod(env, java_lang_Thread, false, "<init>", "(Ljava/lang/ThreadGroup;Ljava/lang/String;IZ)V"); |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 344 | java_lang_Thread_run = CacheMethod(env, java_lang_Thread, false, "run", "()V"); |
Piotr Jastrzebski | e6cd3b5 | 2015-05-07 09:41:00 +0100 | [diff] [blame] | 345 | java_lang_ThreadGroup_removeThread = CacheMethod(env, java_lang_ThreadGroup, false, "threadTerminated", "(Ljava/lang/Thread;)V"); |
Elliott Hughes | b568121 | 2013-03-29 17:29:22 -0700 | [diff] [blame] | 346 | java_nio_DirectByteBuffer_init = CacheMethod(env, java_nio_DirectByteBuffer, false, "<init>", "(JI)V"); |
Jeff Hao | 13e748b | 2015-08-25 20:44:19 +0000 | [diff] [blame] | 347 | libcore_reflect_AnnotationFactory_createAnnotation = CacheMethod(env, libcore_reflect_AnnotationFactory, true, "createAnnotation", "(Ljava/lang/Class;[Llibcore/reflect/AnnotationMember;)Ljava/lang/annotation/Annotation;"); |
| 348 | libcore_reflect_AnnotationMember_init = CacheMethod(env, libcore_reflect_AnnotationMember, false, "<init>", "(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/reflect/Method;)V"); |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 349 | org_apache_harmony_dalvik_ddmc_DdmServer_broadcast = CacheMethod(env, org_apache_harmony_dalvik_ddmc_DdmServer, true, "broadcast", "(I)V"); |
| 350 | 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;"); |
| 351 | |
Andreas Gampe | 46aba36 | 2016-10-28 14:33:28 -0700 | [diff] [blame] | 352 | dalvik_system_BaseDexClassLoader_pathList = CacheField(env, dalvik_system_BaseDexClassLoader, false, "pathList", "Ldalvik/system/DexPathList;"); |
Andreas Gampe | 324b9bb | 2015-02-23 16:33:22 -0800 | [diff] [blame] | 353 | dalvik_system_DexFile_cookie = CacheField(env, dalvik_system_DexFile, false, "mCookie", "Ljava/lang/Object;"); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 354 | dalvik_system_DexFile_fileName = CacheField(env, dalvik_system_DexFile, false, "mFileName", "Ljava/lang/String;"); |
Mathieu Chartier | 6bcae8f | 2014-09-04 18:33:17 -0700 | [diff] [blame] | 355 | dalvik_system_DexPathList_dexElements = CacheField(env, dalvik_system_DexPathList, false, "dexElements", "[Ldalvik/system/DexPathList$Element;"); |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 356 | dalvik_system_DexPathList__Element_dexFile = CacheField(env, dalvik_system_DexPathList__Element, false, "dexFile", "Ldalvik/system/DexFile;"); |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 357 | java_lang_Thread_daemon = CacheField(env, java_lang_Thread, false, "daemon", "Z"); |
| 358 | java_lang_Thread_group = CacheField(env, java_lang_Thread, false, "group", "Ljava/lang/ThreadGroup;"); |
Elliott Hughes | c5dc2ff | 2013-01-09 13:44:30 -0800 | [diff] [blame] | 359 | java_lang_Thread_lock = CacheField(env, java_lang_Thread, false, "lock", "Ljava/lang/Object;"); |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 360 | java_lang_Thread_name = CacheField(env, java_lang_Thread, false, "name", "Ljava/lang/String;"); |
| 361 | java_lang_Thread_priority = CacheField(env, java_lang_Thread, false, "priority", "I"); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 362 | java_lang_Thread_nativePeer = CacheField(env, java_lang_Thread, false, "nativePeer", "J"); |
Narayan Kamath | d1ef436 | 2015-11-12 11:49:06 +0000 | [diff] [blame] | 363 | java_lang_ThreadGroup_groups = CacheField(env, java_lang_ThreadGroup, false, "groups", "[Ljava/lang/ThreadGroup;"); |
Przemyslaw Szczepaniak | 464595f | 2015-11-24 11:59:59 +0000 | [diff] [blame] | 364 | java_lang_ThreadGroup_ngroups = CacheField(env, java_lang_ThreadGroup, false, "ngroups", "I"); |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 365 | java_lang_ThreadGroup_mainThreadGroup = CacheField(env, java_lang_ThreadGroup, true, "mainThreadGroup", "Ljava/lang/ThreadGroup;"); |
| 366 | java_lang_ThreadGroup_name = CacheField(env, java_lang_ThreadGroup, false, "name", "Ljava/lang/String;"); |
Sebastien Hertz | e49e195 | 2014-10-13 11:27:13 +0200 | [diff] [blame] | 367 | java_lang_ThreadGroup_parent = CacheField(env, java_lang_ThreadGroup, false, "parent", "Ljava/lang/ThreadGroup;"); |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 368 | java_lang_ThreadGroup_systemThreadGroup = CacheField(env, java_lang_ThreadGroup, true, "systemThreadGroup", "Ljava/lang/ThreadGroup;"); |
Brian Carlstrom | 3437531 | 2014-09-10 23:10:47 -0700 | [diff] [blame] | 369 | java_lang_Throwable_cause = CacheField(env, java_lang_Throwable, false, "cause", "Ljava/lang/Throwable;"); |
| 370 | java_lang_Throwable_detailMessage = CacheField(env, java_lang_Throwable, false, "detailMessage", "Ljava/lang/String;"); |
| 371 | java_lang_Throwable_stackTrace = CacheField(env, java_lang_Throwable, false, "stackTrace", "[Ljava/lang/StackTraceElement;"); |
Piotr Jastrzebski | c16a50f | 2015-05-07 09:41:00 +0100 | [diff] [blame] | 372 | java_lang_Throwable_stackState = CacheField(env, java_lang_Throwable, false, "backtrace", "Ljava/lang/Object;"); |
Brian Carlstrom | 3437531 | 2014-09-10 23:10:47 -0700 | [diff] [blame] | 373 | java_lang_Throwable_suppressedExceptions = CacheField(env, java_lang_Throwable, false, "suppressedExceptions", "Ljava/util/List;"); |
Neil Fuller | 0e84439 | 2016-09-08 13:43:31 +0100 | [diff] [blame] | 374 | java_lang_reflect_Executable_artMethod = CacheField(env, java_lang_reflect_Executable, false, "artMethod", "J"); |
Elliott Hughes | aecb5f3 | 2013-03-28 08:27:38 -0700 | [diff] [blame] | 375 | java_nio_DirectByteBuffer_capacity = CacheField(env, java_nio_DirectByteBuffer, false, "capacity", "I"); |
Piotr Jastrzebski | 8c145b9 | 2015-05-05 12:54:00 +0100 | [diff] [blame] | 376 | java_nio_DirectByteBuffer_effectiveDirectAddress = CacheField(env, java_nio_DirectByteBuffer, false, "address", "J"); |
Narayan Kamath | d1ef436 | 2015-11-12 11:49:06 +0000 | [diff] [blame] | 377 | java_util_ArrayList_array = CacheField(env, java_util_ArrayList, false, "elementData", "[Ljava/lang/Object;"); |
Sebastien Hertz | e49e195 | 2014-10-13 11:27:13 +0200 | [diff] [blame] | 378 | java_util_ArrayList_size = CacheField(env, java_util_ArrayList, false, "size", "I"); |
Brian Carlstrom | 3437531 | 2014-09-10 23:10:47 -0700 | [diff] [blame] | 379 | java_util_Collections_EMPTY_LIST = CacheField(env, java_util_Collections, true, "EMPTY_LIST", "Ljava/util/List;"); |
| 380 | libcore_util_EmptyArray_STACK_TRACE_ELEMENT = CacheField(env, libcore_util_EmptyArray, true, "STACK_TRACE_ELEMENT", "[Ljava/lang/StackTraceElement;"); |
Sebastien Hertz | b30e0c6 | 2014-09-11 16:23:44 +0200 | [diff] [blame] | 381 | org_apache_harmony_dalvik_ddmc_Chunk_data = CacheField(env, org_apache_harmony_dalvik_ddmc_Chunk, false, "data", "[B"); |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 382 | org_apache_harmony_dalvik_ddmc_Chunk_length = CacheField(env, org_apache_harmony_dalvik_ddmc_Chunk, false, "length", "I"); |
| 383 | org_apache_harmony_dalvik_ddmc_Chunk_offset = CacheField(env, org_apache_harmony_dalvik_ddmc_Chunk, false, "offset", "I"); |
| 384 | org_apache_harmony_dalvik_ddmc_Chunk_type = CacheField(env, org_apache_harmony_dalvik_ddmc_Chunk, false, "type", "I"); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 385 | |
| 386 | java_lang_Boolean_valueOf = CachePrimitiveBoxingMethod(env, 'Z', "java/lang/Boolean"); |
| 387 | java_lang_Byte_valueOf = CachePrimitiveBoxingMethod(env, 'B', "java/lang/Byte"); |
| 388 | java_lang_Character_valueOf = CachePrimitiveBoxingMethod(env, 'C', "java/lang/Character"); |
| 389 | java_lang_Double_valueOf = CachePrimitiveBoxingMethod(env, 'D', "java/lang/Double"); |
| 390 | java_lang_Float_valueOf = CachePrimitiveBoxingMethod(env, 'F', "java/lang/Float"); |
| 391 | java_lang_Integer_valueOf = CachePrimitiveBoxingMethod(env, 'I', "java/lang/Integer"); |
| 392 | java_lang_Long_valueOf = CachePrimitiveBoxingMethod(env, 'J', "java/lang/Long"); |
| 393 | java_lang_Short_valueOf = CachePrimitiveBoxingMethod(env, 'S', "java/lang/Short"); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 394 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 395 | InitStringInit(env); |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 396 | Thread::Current()->InitStringEntryPoints(); |
Elliott Hughes | af8d15a | 2012-05-29 09:12:18 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Ian Rogers | ef28b14 | 2012-11-30 14:22:18 -0800 | [diff] [blame] | 399 | void WellKnownClasses::LateInit(JNIEnv* env) { |
| 400 | ScopedLocalRef<jclass> java_lang_Runtime(env, env->FindClass("java/lang/Runtime")); |
Przemyslaw Szczepaniak | f11cd29 | 2016-08-17 17:46:38 +0100 | [diff] [blame] | 401 | // CacheField and CacheMethod will initialize their classes. Classes below |
| 402 | // have clinit sections that call JNI methods. Late init is required |
| 403 | // to make sure these JNI methods are available. |
Dmitriy Ivanov | 44409d3 | 2015-11-11 14:18:55 -0800 | [diff] [blame] | 404 | java_lang_Runtime_nativeLoad = |
| 405 | CacheMethod(env, java_lang_Runtime.get(), true, "nativeLoad", |
Dimitry Ivanov | 942dc298 | 2016-02-24 13:33:33 -0800 | [diff] [blame] | 406 | "(Ljava/lang/String;Ljava/lang/ClassLoader;Ljava/lang/String;)" |
Dmitriy Ivanov | 44409d3 | 2015-11-11 14:18:55 -0800 | [diff] [blame] | 407 | "Ljava/lang/String;"); |
Przemyslaw Szczepaniak | f11cd29 | 2016-08-17 17:46:38 +0100 | [diff] [blame] | 408 | java_lang_reflect_Proxy_invoke = |
| 409 | CacheMethod(env, java_lang_reflect_Proxy, true, "invoke", |
| 410 | "(Ljava/lang/reflect/Proxy;Ljava/lang/reflect/Method;" |
| 411 | "[Ljava/lang/Object;)Ljava/lang/Object;"); |
| 412 | java_lang_reflect_Proxy_h = |
| 413 | CacheField(env, java_lang_reflect_Proxy, false, "h", |
| 414 | "Ljava/lang/reflect/InvocationHandler;"); |
Ian Rogers | ef28b14 | 2012-11-30 14:22:18 -0800 | [diff] [blame] | 415 | } |
| 416 | |
Andreas Gampe | db48a79 | 2017-09-08 22:18:30 -0700 | [diff] [blame] | 417 | void WellKnownClasses::Clear() { |
| 418 | dalvik_annotation_optimization_CriticalNative = nullptr; |
| 419 | dalvik_annotation_optimization_FastNative = nullptr; |
| 420 | dalvik_system_BaseDexClassLoader = nullptr; |
| 421 | dalvik_system_DelegateLastClassLoader = nullptr; |
| 422 | dalvik_system_DexClassLoader = nullptr; |
| 423 | dalvik_system_DexFile = nullptr; |
| 424 | dalvik_system_DexPathList = nullptr; |
| 425 | dalvik_system_DexPathList__Element = nullptr; |
| 426 | dalvik_system_EmulatedStackFrame = nullptr; |
| 427 | dalvik_system_PathClassLoader = nullptr; |
| 428 | dalvik_system_VMRuntime = nullptr; |
| 429 | java_lang_annotation_Annotation__array = nullptr; |
| 430 | java_lang_BootClassLoader = nullptr; |
| 431 | java_lang_ClassLoader = nullptr; |
| 432 | java_lang_ClassNotFoundException = nullptr; |
| 433 | java_lang_Daemons = nullptr; |
| 434 | java_lang_Error = nullptr; |
| 435 | java_lang_IllegalAccessError = nullptr; |
| 436 | java_lang_invoke_MethodHandle = nullptr; |
| 437 | java_lang_NoClassDefFoundError = nullptr; |
| 438 | java_lang_Object = nullptr; |
| 439 | java_lang_OutOfMemoryError = nullptr; |
| 440 | java_lang_reflect_Constructor = nullptr; |
| 441 | java_lang_reflect_Executable = nullptr; |
| 442 | java_lang_reflect_Field = nullptr; |
| 443 | java_lang_reflect_Method = nullptr; |
| 444 | java_lang_reflect_Parameter = nullptr; |
| 445 | java_lang_reflect_Parameter__array = nullptr; |
| 446 | java_lang_reflect_Proxy = nullptr; |
| 447 | java_lang_RuntimeException = nullptr; |
| 448 | java_lang_StackOverflowError = nullptr; |
| 449 | java_lang_String = nullptr; |
| 450 | java_lang_StringFactory = nullptr; |
| 451 | java_lang_System = nullptr; |
| 452 | java_lang_Thread = nullptr; |
| 453 | java_lang_ThreadGroup = nullptr; |
| 454 | java_lang_Throwable = nullptr; |
| 455 | java_util_ArrayList = nullptr; |
| 456 | java_util_Collections = nullptr; |
| 457 | java_nio_DirectByteBuffer = nullptr; |
| 458 | libcore_reflect_AnnotationFactory = nullptr; |
| 459 | libcore_reflect_AnnotationMember = nullptr; |
| 460 | libcore_util_EmptyArray = nullptr; |
| 461 | org_apache_harmony_dalvik_ddmc_Chunk = nullptr; |
| 462 | org_apache_harmony_dalvik_ddmc_DdmServer = nullptr; |
| 463 | |
| 464 | dalvik_system_VMRuntime_runFinalization = nullptr; |
| 465 | java_lang_Boolean_valueOf = nullptr; |
| 466 | java_lang_Byte_valueOf = nullptr; |
| 467 | java_lang_Character_valueOf = nullptr; |
| 468 | java_lang_ClassLoader_loadClass = nullptr; |
| 469 | java_lang_ClassNotFoundException_init = nullptr; |
| 470 | java_lang_Daemons_requestHeapTrim = nullptr; |
| 471 | java_lang_Daemons_start = nullptr; |
| 472 | java_lang_Daemons_stop = nullptr; |
| 473 | java_lang_Double_valueOf = nullptr; |
| 474 | java_lang_Float_valueOf = nullptr; |
| 475 | java_lang_Integer_valueOf = nullptr; |
| 476 | java_lang_invoke_MethodHandle_invoke = nullptr; |
| 477 | java_lang_invoke_MethodHandle_invokeExact = nullptr; |
| 478 | java_lang_invoke_MethodHandles_lookup = nullptr; |
| 479 | java_lang_invoke_MethodHandles_Lookup_findConstructor = nullptr; |
| 480 | java_lang_Long_valueOf = nullptr; |
| 481 | java_lang_ref_FinalizerReference_add = nullptr; |
| 482 | java_lang_ref_ReferenceQueue_add = nullptr; |
| 483 | java_lang_reflect_Parameter_init = nullptr; |
| 484 | java_lang_reflect_Proxy_invoke = nullptr; |
| 485 | java_lang_Runtime_nativeLoad = nullptr; |
| 486 | java_lang_Short_valueOf = nullptr; |
| 487 | java_lang_String_charAt = nullptr; |
| 488 | java_lang_System_runFinalization = nullptr; |
| 489 | java_lang_Thread_dispatchUncaughtException = nullptr; |
| 490 | java_lang_Thread_init = nullptr; |
| 491 | java_lang_Thread_run = nullptr; |
| 492 | java_lang_ThreadGroup_removeThread = nullptr; |
| 493 | java_nio_DirectByteBuffer_init = nullptr; |
| 494 | libcore_reflect_AnnotationFactory_createAnnotation = nullptr; |
| 495 | libcore_reflect_AnnotationMember_init = nullptr; |
| 496 | org_apache_harmony_dalvik_ddmc_DdmServer_broadcast = nullptr; |
| 497 | org_apache_harmony_dalvik_ddmc_DdmServer_dispatch = nullptr; |
| 498 | |
| 499 | dalvik_system_BaseDexClassLoader_pathList = nullptr; |
| 500 | dalvik_system_DexFile_cookie = nullptr; |
| 501 | dalvik_system_DexFile_fileName = nullptr; |
| 502 | dalvik_system_DexPathList_dexElements = nullptr; |
| 503 | dalvik_system_DexPathList__Element_dexFile = nullptr; |
| 504 | java_lang_reflect_Executable_artMethod = nullptr; |
| 505 | java_lang_reflect_Proxy_h = nullptr; |
| 506 | java_lang_Thread_daemon = nullptr; |
| 507 | java_lang_Thread_group = nullptr; |
| 508 | java_lang_Thread_lock = nullptr; |
| 509 | java_lang_Thread_name = nullptr; |
| 510 | java_lang_Thread_priority = nullptr; |
| 511 | java_lang_Thread_nativePeer = nullptr; |
| 512 | java_lang_ThreadGroup_groups = nullptr; |
| 513 | java_lang_ThreadGroup_ngroups = nullptr; |
| 514 | java_lang_ThreadGroup_mainThreadGroup = nullptr; |
| 515 | java_lang_ThreadGroup_name = nullptr; |
| 516 | java_lang_ThreadGroup_parent = nullptr; |
| 517 | java_lang_ThreadGroup_systemThreadGroup = nullptr; |
| 518 | java_lang_Throwable_cause = nullptr; |
| 519 | java_lang_Throwable_detailMessage = nullptr; |
| 520 | java_lang_Throwable_stackTrace = nullptr; |
| 521 | java_lang_Throwable_stackState = nullptr; |
| 522 | java_lang_Throwable_suppressedExceptions = nullptr; |
| 523 | java_nio_DirectByteBuffer_capacity = nullptr; |
| 524 | java_nio_DirectByteBuffer_effectiveDirectAddress = nullptr; |
| 525 | java_util_ArrayList_array = nullptr; |
| 526 | java_util_ArrayList_size = nullptr; |
| 527 | java_util_Collections_EMPTY_LIST = nullptr; |
| 528 | libcore_util_EmptyArray_STACK_TRACE_ELEMENT = nullptr; |
| 529 | org_apache_harmony_dalvik_ddmc_Chunk_data = nullptr; |
| 530 | org_apache_harmony_dalvik_ddmc_Chunk_length = nullptr; |
| 531 | org_apache_harmony_dalvik_ddmc_Chunk_offset = nullptr; |
| 532 | org_apache_harmony_dalvik_ddmc_Chunk_type = nullptr; |
| 533 | } |
| 534 | |
Mathieu Chartier | c4f3925 | 2016-10-05 18:32:08 -0700 | [diff] [blame] | 535 | ObjPtr<mirror::Class> WellKnownClasses::ToClass(jclass global_jclass) { |
Alex Light | d625158 | 2016-10-31 11:12:30 -0700 | [diff] [blame] | 536 | auto ret = ObjPtr<mirror::Class>::DownCast(Thread::Current()->DecodeJObject(global_jclass)); |
| 537 | DCHECK(!ret.IsNull()); |
| 538 | return ret; |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Elliott Hughes | eac7667 | 2012-05-24 21:56:51 -0700 | [diff] [blame] | 541 | } // namespace art |