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 #ifndef ART_RUNTIME_WELL_KNOWN_CLASSES_H_ 18 #define ART_RUNTIME_WELL_KNOWN_CLASSES_H_ 19 20 #include "base/mutex.h" 21 #include "jni.h" 22 #include "obj_ptr.h" 23 24 namespace art { 25 26 class ArtMethod; 27 28 namespace mirror { 29 class Class; 30 } // namespace mirror 31 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 { 37 public: 38 static void Init(JNIEnv* env); // Run before native methods are registered. 39 static void LateInit(JNIEnv* env); // Run after native methods are registered. 40 41 static void Clear(); 42 43 static ArtMethod* StringInitToStringFactory(ArtMethod* method); 44 static uint32_t StringInitToEntryPoint(ArtMethod* method); 45 46 static ObjPtr<mirror::Class> ToClass(jclass global_jclass) REQUIRES_SHARED(Locks::mutator_lock_); 47 48 static jclass dalvik_annotation_optimization_CriticalNative; 49 static jclass dalvik_annotation_optimization_FastNative; 50 static jclass dalvik_system_BaseDexClassLoader; 51 static jclass dalvik_system_DelegateLastClassLoader; 52 static jclass dalvik_system_DexClassLoader; 53 static jclass dalvik_system_DexFile; 54 static jclass dalvik_system_DexPathList; 55 static jclass dalvik_system_DexPathList__Element; 56 static jclass dalvik_system_EmulatedStackFrame; 57 static jclass dalvik_system_PathClassLoader; 58 static jclass dalvik_system_VMRuntime; 59 static jclass java_lang_annotation_Annotation__array; 60 static jclass java_lang_BootClassLoader; 61 static jclass java_lang_ClassLoader; 62 static jclass java_lang_ClassNotFoundException; 63 static jclass java_lang_Daemons; 64 static jclass java_lang_Error; 65 static jclass java_lang_IllegalAccessError; 66 static jclass java_lang_invoke_MethodHandle; 67 static jclass java_lang_invoke_VarHandle; 68 static jclass java_lang_NoClassDefFoundError; 69 static jclass java_lang_Object; 70 static jclass java_lang_OutOfMemoryError; 71 static jclass java_lang_reflect_Constructor; 72 static jclass java_lang_reflect_Executable; 73 static jclass java_lang_reflect_Field; 74 static jclass java_lang_reflect_Method; 75 static jclass java_lang_reflect_Parameter; 76 static jclass java_lang_reflect_Parameter__array; 77 static jclass java_lang_reflect_Proxy; 78 static jclass java_lang_RuntimeException; 79 static jclass java_lang_StackOverflowError; 80 static jclass java_lang_String; 81 static jclass java_lang_StringFactory; 82 static jclass java_lang_System; 83 static jclass java_lang_Thread; 84 static jclass java_lang_ThreadGroup; 85 static jclass java_lang_Throwable; 86 static jclass java_util_ArrayList; 87 static jclass java_util_Collections; 88 static jclass java_util_function_Consumer; 89 static jclass java_nio_ByteBuffer; 90 static jclass java_nio_DirectByteBuffer; 91 static jclass libcore_reflect_AnnotationFactory; 92 static jclass libcore_reflect_AnnotationMember; 93 static jclass libcore_util_EmptyArray; 94 static jclass org_apache_harmony_dalvik_ddmc_Chunk; 95 static jclass org_apache_harmony_dalvik_ddmc_DdmServer; 96 97 static jmethodID dalvik_system_BaseDexClassLoader_getLdLibraryPath; 98 static jmethodID dalvik_system_VMRuntime_runFinalization; 99 static jmethodID java_lang_Boolean_valueOf; 100 static jmethodID java_lang_Byte_valueOf; 101 static jmethodID java_lang_Character_valueOf; 102 static jmethodID java_lang_ClassLoader_loadClass; 103 static jmethodID java_lang_ClassNotFoundException_init; 104 static jmethodID java_lang_Daemons_requestHeapTrim; 105 static jmethodID java_lang_Daemons_start; 106 static jmethodID java_lang_Daemons_stop; 107 static jmethodID java_lang_Double_valueOf; 108 static jmethodID java_lang_Float_valueOf; 109 static jmethodID java_lang_Integer_valueOf; 110 static jmethodID java_lang_invoke_MethodHandle_invoke; 111 static jmethodID java_lang_invoke_MethodHandle_invokeExact; 112 static jmethodID java_lang_invoke_MethodHandles_lookup; 113 static jmethodID java_lang_invoke_MethodHandles_Lookup_findConstructor; 114 static jmethodID java_lang_Long_valueOf; 115 static jmethodID java_lang_ref_FinalizerReference_add; 116 static jmethodID java_lang_ref_ReferenceQueue_add; 117 static jmethodID java_lang_reflect_Parameter_init; 118 static jmethodID java_lang_reflect_Proxy_invoke; 119 static jmethodID java_lang_Runtime_nativeLoad; 120 static jmethodID java_lang_Short_valueOf; 121 static jmethodID java_lang_String_charAt; 122 static jmethodID java_lang_System_runFinalization; 123 static jmethodID java_lang_Thread_dispatchUncaughtException; 124 static jmethodID java_lang_Thread_init; 125 static jmethodID java_lang_Thread_run; 126 static jmethodID java_lang_ThreadGroup_add; 127 static jmethodID java_lang_ThreadGroup_removeThread; 128 static jmethodID java_nio_DirectByteBuffer_init; 129 static jmethodID java_util_function_Consumer_accept; 130 static jmethodID libcore_reflect_AnnotationFactory_createAnnotation; 131 static jmethodID libcore_reflect_AnnotationMember_init; 132 static jmethodID org_apache_harmony_dalvik_ddmc_DdmServer_broadcast; 133 static jmethodID org_apache_harmony_dalvik_ddmc_DdmServer_dispatch; 134 135 static jfieldID dalvik_system_BaseDexClassLoader_pathList; 136 static jfieldID dalvik_system_DexFile_cookie; 137 static jfieldID dalvik_system_DexFile_fileName; 138 static jfieldID dalvik_system_DexPathList_dexElements; 139 static jfieldID dalvik_system_DexPathList__Element_dexFile; 140 static jfieldID dalvik_system_VMRuntime_nonSdkApiUsageConsumer; 141 static jfieldID java_lang_reflect_Executable_artMethod; 142 static jfieldID java_lang_reflect_Proxy_h; 143 static jfieldID java_lang_Thread_daemon; 144 static jfieldID java_lang_Thread_group; 145 static jfieldID java_lang_Thread_lock; 146 static jfieldID java_lang_Thread_name; 147 static jfieldID java_lang_Thread_priority; 148 static jfieldID java_lang_Thread_nativePeer; 149 static jfieldID java_lang_ThreadGroup_groups; 150 static jfieldID java_lang_ThreadGroup_ngroups; 151 static jfieldID java_lang_ThreadGroup_mainThreadGroup; 152 static jfieldID java_lang_ThreadGroup_name; 153 static jfieldID java_lang_ThreadGroup_parent; 154 static jfieldID java_lang_ThreadGroup_systemThreadGroup; 155 static jfieldID java_lang_Throwable_cause; 156 static jfieldID java_lang_Throwable_detailMessage; 157 static jfieldID java_lang_Throwable_stackTrace; 158 static jfieldID java_lang_Throwable_stackState; 159 static jfieldID java_lang_Throwable_suppressedExceptions; 160 static jfieldID java_nio_ByteBuffer_address; 161 static jfieldID java_nio_ByteBuffer_hb; 162 static jfieldID java_nio_ByteBuffer_isReadOnly; 163 static jfieldID java_nio_ByteBuffer_limit; 164 static jfieldID java_nio_ByteBuffer_offset; 165 static jfieldID java_nio_DirectByteBuffer_capacity; 166 static jfieldID java_nio_DirectByteBuffer_effectiveDirectAddress; 167 168 static jfieldID java_util_ArrayList_array; 169 static jfieldID java_util_ArrayList_size; 170 static jfieldID java_util_Collections_EMPTY_LIST; 171 static jfieldID libcore_util_EmptyArray_STACK_TRACE_ELEMENT; 172 static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_data; 173 static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_length; 174 static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_offset; 175 static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_type; 176 177 private: 178 static void InitStringInit(JNIEnv* env); 179 }; 180 181 } // namespace art 182 183 #endif // ART_RUNTIME_WELL_KNOWN_CLASSES_H_ 184