blob: c18473197baeb3c42525645af1954b43a8999bda [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"
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
Elliott Hugheseac76672012-05-24 21:56:51 -070032// 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
Mathieu Chartier987ccff2013-07-08 11:05:21 -070036jmethodID CacheMethod(JNIEnv* env, jclass c, bool is_static, const char* name, const char* signature);
37
Elliott Hugheseac76672012-05-24 21:56:51 -070038struct WellKnownClasses {
Brian Carlstromea46f952013-07-30 01:26:50 -070039 public:
Ian Rogersef28b142012-11-30 14:22:18 -080040 static void Init(JNIEnv* env); // Run before native methods are registered.
41 static void LateInit(JNIEnv* env); // Run after native methods are registered.
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +010042 static ArtMethod* StringInitToStringFactory(ArtMethod* method);
43 static uint32_t StringInitToEntryPoint(ArtMethod* method);
Elliott Hugheseac76672012-05-24 21:56:51 -070044
Mathieu Chartierc4f39252016-10-05 18:32:08 -070045 static ObjPtr<mirror::Class> ToClass(jclass global_jclass) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesaf8d15a2012-05-29 09:12:18 -070046
Igor Murashkin367f3dd2016-09-01 17:00:24 -070047 static jclass dalvik_annotation_optimization_CriticalNative;
Igor Murashkin9d4b6da2016-07-29 09:51:58 -070048 static jclass dalvik_annotation_optimization_FastNative;
Andreas Gampe46aba362016-10-28 14:33:28 -070049 static jclass dalvik_system_BaseDexClassLoader;
Nicolas Geoffray7d8d8ff2016-11-02 12:38:05 +000050 static jclass dalvik_system_DexClassLoader;
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -070051 static jclass dalvik_system_DexFile;
52 static jclass dalvik_system_DexPathList;
Andreas Gampec8ccf682014-09-29 20:07:43 -070053 static jclass dalvik_system_DexPathList__Element;
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +010054 static jclass dalvik_system_EmulatedStackFrame;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070055 static jclass dalvik_system_PathClassLoader;
Mathieu Chartierb5de3bb2015-06-05 13:21:05 -070056 static jclass dalvik_system_VMRuntime;
Jeff Hao13e748b2015-08-25 20:44:19 +000057 static jclass java_lang_annotation_Annotation__array;
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -070058 static jclass java_lang_BootClassLoader;
Elliott Hugheseac76672012-05-24 21:56:51 -070059 static jclass java_lang_ClassLoader;
60 static jclass java_lang_ClassNotFoundException;
61 static jclass java_lang_Daemons;
62 static jclass java_lang_Error;
Jeff Haoc92a7a12016-06-06 11:09:20 -070063 static jclass java_lang_IllegalAccessError;
Orion Hodson811bd5f2016-12-07 11:35:37 +000064 static jclass java_lang_invoke_MethodHandle;
Jeff Haoc92a7a12016-06-06 11:09:20 -070065 static jclass java_lang_NoClassDefFoundError;
Ian Rogersaf6e67a2013-01-16 08:38:37 -080066 static jclass java_lang_Object;
Mathieu Chartiera61894d2015-04-23 16:32:54 -070067 static jclass java_lang_OutOfMemoryError;
Brian Carlstromea46f952013-07-30 01:26:50 -070068 static jclass java_lang_reflect_Constructor;
Neil Fuller0e844392016-09-08 13:43:31 +010069 static jclass java_lang_reflect_Executable;
Brian Carlstromea46f952013-07-30 01:26:50 -070070 static jclass java_lang_reflect_Field;
71 static jclass java_lang_reflect_Method;
Neil Fuller79a21e72016-09-09 14:24:51 +010072 static jclass java_lang_reflect_Parameter;
73 static jclass java_lang_reflect_Parameter__array;
Elliott Hugheseac76672012-05-24 21:56:51 -070074 static jclass java_lang_reflect_Proxy;
Elliott Hughesa4f94742012-05-29 16:28:38 -070075 static jclass java_lang_RuntimeException;
Ian Rogers120f1c72012-09-28 17:17:10 -070076 static jclass java_lang_StackOverflowError;
Ian Rogersdd157d72014-05-15 14:47:50 -070077 static jclass java_lang_String;
Jeff Hao848f70a2014-01-15 13:49:50 -080078 static jclass java_lang_StringFactory;
Mathieu Chartier987ccff2013-07-08 11:05:21 -070079 static jclass java_lang_System;
Elliott Hugheseac76672012-05-24 21:56:51 -070080 static jclass java_lang_Thread;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -070081 static jclass java_lang_ThreadGroup;
Elliott Hughesa4f94742012-05-29 16:28:38 -070082 static jclass java_lang_Throwable;
Sebastien Hertze49e1952014-10-13 11:27:13 +020083 static jclass java_util_ArrayList;
Andreas Gampe7ea6f792014-07-14 16:21:44 -070084 static jclass java_util_Collections;
Elliott Hughesaecb5f32013-03-28 08:27:38 -070085 static jclass java_nio_DirectByteBuffer;
Jeff Hao13e748b2015-08-25 20:44:19 +000086 static jclass libcore_reflect_AnnotationFactory;
87 static jclass libcore_reflect_AnnotationMember;
Andreas Gampe7ea6f792014-07-14 16:21:44 -070088 static jclass libcore_util_EmptyArray;
Elliott Hugheseac76672012-05-24 21:56:51 -070089 static jclass org_apache_harmony_dalvik_ddmc_Chunk;
90 static jclass org_apache_harmony_dalvik_ddmc_DdmServer;
91
Mathieu Chartierb5de3bb2015-06-05 13:21:05 -070092 static jmethodID dalvik_system_VMRuntime_runFinalization;
Ian Rogers00f7d0e2012-07-19 15:28:27 -070093 static jmethodID java_lang_Boolean_valueOf;
94 static jmethodID java_lang_Byte_valueOf;
95 static jmethodID java_lang_Character_valueOf;
Elliott Hughesa4f94742012-05-29 16:28:38 -070096 static jmethodID java_lang_ClassLoader_loadClass;
Elliott Hugheseac76672012-05-24 21:56:51 -070097 static jmethodID java_lang_ClassNotFoundException_init;
98 static jmethodID java_lang_Daemons_requestHeapTrim;
99 static jmethodID java_lang_Daemons_start;
Mathieu Chartiercef50f02014-12-09 17:38:52 -0800100 static jmethodID java_lang_Daemons_stop;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700101 static jmethodID java_lang_Double_valueOf;
102 static jmethodID java_lang_Float_valueOf;
103 static jmethodID java_lang_Integer_valueOf;
Orion Hodson811bd5f2016-12-07 11:35:37 +0000104 static jmethodID java_lang_invoke_MethodHandle_invoke;
105 static jmethodID java_lang_invoke_MethodHandle_invokeExact;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700106 static jmethodID java_lang_Long_valueOf;
Elliott Hughesa4f94742012-05-29 16:28:38 -0700107 static jmethodID java_lang_ref_FinalizerReference_add;
108 static jmethodID java_lang_ref_ReferenceQueue_add;
Neil Fuller79a21e72016-09-09 14:24:51 +0100109 static jmethodID java_lang_reflect_Parameter_init;
Brian Carlstromea46f952013-07-30 01:26:50 -0700110 static jmethodID java_lang_reflect_Proxy_invoke;
Ian Rogersef28b142012-11-30 14:22:18 -0800111 static jmethodID java_lang_Runtime_nativeLoad;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700112 static jmethodID java_lang_Short_valueOf;
Nicolas Geoffray5d37c152017-01-12 13:25:19 +0000113 static jmethodID java_lang_String_charAt;
Mathieu Chartier987ccff2013-07-08 11:05:21 -0700114 static jmethodID java_lang_System_runFinalization;
Tobias Thierer5cbe65d2016-07-22 18:37:59 +0100115 static jmethodID java_lang_Thread_dispatchUncaughtException;
Elliott Hugheseac76672012-05-24 21:56:51 -0700116 static jmethodID java_lang_Thread_init;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700117 static jmethodID java_lang_Thread_run;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700118 static jmethodID java_lang_ThreadGroup_removeThread;
Elliott Hughesaecb5f32013-03-28 08:27:38 -0700119 static jmethodID java_nio_DirectByteBuffer_init;
Jeff Hao13e748b2015-08-25 20:44:19 +0000120 static jmethodID libcore_reflect_AnnotationFactory_createAnnotation;
121 static jmethodID libcore_reflect_AnnotationMember_init;
Elliott Hugheseac76672012-05-24 21:56:51 -0700122 static jmethodID org_apache_harmony_dalvik_ddmc_DdmServer_broadcast;
123 static jmethodID org_apache_harmony_dalvik_ddmc_DdmServer_dispatch;
124
Andreas Gampe46aba362016-10-28 14:33:28 -0700125 static jfieldID dalvik_system_BaseDexClassLoader_pathList;
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -0700126 static jfieldID dalvik_system_DexFile_cookie;
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800127 static jfieldID dalvik_system_DexFile_fileName;
Mathieu Chartier6bcae8f2014-09-04 18:33:17 -0700128 static jfieldID dalvik_system_DexPathList_dexElements;
Andreas Gampec8ccf682014-09-29 20:07:43 -0700129 static jfieldID dalvik_system_DexPathList__Element_dexFile;
Neil Fuller0e844392016-09-08 13:43:31 +0100130 static jfieldID java_lang_reflect_Executable_artMethod;
Elliott Hugheseac76672012-05-24 21:56:51 -0700131 static jfieldID java_lang_reflect_Proxy_h;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700132 static jfieldID java_lang_Thread_daemon;
133 static jfieldID java_lang_Thread_group;
134 static jfieldID java_lang_Thread_lock;
135 static jfieldID java_lang_Thread_name;
136 static jfieldID java_lang_Thread_priority;
Anwar Ghuloum3c50a4b2013-06-21 13:05:23 -0700137 static jfieldID java_lang_Thread_nativePeer;
Sebastien Hertze49e1952014-10-13 11:27:13 +0200138 static jfieldID java_lang_ThreadGroup_groups;
Przemyslaw Szczepaniak464595f2015-11-24 11:59:59 +0000139 static jfieldID java_lang_ThreadGroup_ngroups;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700140 static jfieldID java_lang_ThreadGroup_mainThreadGroup;
141 static jfieldID java_lang_ThreadGroup_name;
Sebastien Hertze49e1952014-10-13 11:27:13 +0200142 static jfieldID java_lang_ThreadGroup_parent;
Elliott Hughesaf8d15a2012-05-29 09:12:18 -0700143 static jfieldID java_lang_ThreadGroup_systemThreadGroup;
Brian Carlstrom34375312014-09-10 23:10:47 -0700144 static jfieldID java_lang_Throwable_cause;
145 static jfieldID java_lang_Throwable_detailMessage;
146 static jfieldID java_lang_Throwable_stackTrace;
147 static jfieldID java_lang_Throwable_stackState;
148 static jfieldID java_lang_Throwable_suppressedExceptions;
Elliott Hughesaecb5f32013-03-28 08:27:38 -0700149 static jfieldID java_nio_DirectByteBuffer_capacity;
150 static jfieldID java_nio_DirectByteBuffer_effectiveDirectAddress;
Sebastien Hertze49e1952014-10-13 11:27:13 +0200151 static jfieldID java_util_ArrayList_array;
152 static jfieldID java_util_ArrayList_size;
Brian Carlstrom34375312014-09-10 23:10:47 -0700153 static jfieldID java_util_Collections_EMPTY_LIST;
154 static jfieldID libcore_util_EmptyArray_STACK_TRACE_ELEMENT;
Elliott Hugheseac76672012-05-24 21:56:51 -0700155 static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_data;
156 static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_length;
157 static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_offset;
158 static jfieldID org_apache_harmony_dalvik_ddmc_Chunk_type;
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +0100159
160 private:
161 static void InitStringInit(JNIEnv* env);
Elliott Hugheseac76672012-05-24 21:56:51 -0700162};
163
164} // namespace art
165
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700166#endif // ART_RUNTIME_WELL_KNOWN_CLASSES_H_