Vladimir Marko | b4eb1b1 | 2018-05-24 11:09:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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_CLASS_ROOT_H_ |
| 18 | #define ART_RUNTIME_CLASS_ROOT_H_ |
| 19 | |
Vladimir Marko | 5868ada | 2020-05-12 11:50:34 +0100 | [diff] [blame] | 20 | #include <stdint.h> |
| 21 | |
| 22 | #include "base/locks.h" |
| 23 | #include "read_barrier_option.h" |
Vladimir Marko | b4eb1b1 | 2018-05-24 11:09:38 +0100 | [diff] [blame] | 24 | |
| 25 | namespace art { |
| 26 | |
Vladimir Marko | 5868ada | 2020-05-12 11:50:34 +0100 | [diff] [blame] | 27 | class ClassLinker; |
| 28 | template<class MirrorType> class ObjPtr; |
| 29 | |
Vladimir Marko | b4eb1b1 | 2018-05-24 11:09:38 +0100 | [diff] [blame] | 30 | namespace mirror { |
| 31 | class ArrayElementVarHandle; |
| 32 | class ByteArrayViewVarHandle; |
| 33 | class ByteBufferViewVarHandle; |
| 34 | class CallSite; |
Vladimir Marko | 5868ada | 2020-05-12 11:50:34 +0100 | [diff] [blame] | 35 | class Class; |
Vladimir Marko | b4eb1b1 | 2018-05-24 11:09:38 +0100 | [diff] [blame] | 36 | class ClassExt; |
| 37 | class ClassLoader; |
| 38 | class Constructor; |
| 39 | class DexCache; |
| 40 | class EmulatedStackFrame; |
| 41 | class Field; |
| 42 | class FieldVarHandle; |
| 43 | class Method; |
| 44 | class MethodHandleImpl; |
| 45 | class MethodHandlesLookup; |
| 46 | class MethodType; |
| 47 | class Object; |
Vladimir Marko | 5868ada | 2020-05-12 11:50:34 +0100 | [diff] [blame] | 48 | template<class T> class ObjectArray; |
Vladimir Marko | b4eb1b1 | 2018-05-24 11:09:38 +0100 | [diff] [blame] | 49 | class Proxy; |
| 50 | template<typename T> class PrimitiveArray; |
| 51 | class Reference; |
| 52 | class StackTraceElement; |
Orion Hodson | dd41196 | 2021-06-25 08:55:22 +0100 | [diff] [blame] | 53 | class StaticFieldVarHandle; |
Vladimir Marko | b4eb1b1 | 2018-05-24 11:09:38 +0100 | [diff] [blame] | 54 | class String; |
| 55 | class Throwable; |
| 56 | class VarHandle; |
| 57 | } // namespace mirror |
| 58 | |
Alex Light | c1ad13a | 2020-03-24 11:37:45 -0700 | [diff] [blame] | 59 | #define CLASS_MIRROR_ROOT_LIST(M) \ |
| 60 | M(kJavaLangClass, "Ljava/lang/Class;", mirror::Class) \ |
| 61 | M(kJavaLangObject, "Ljava/lang/Object;", mirror::Object) \ |
| 62 | M(kClassArrayClass, "[Ljava/lang/Class;", mirror::ObjectArray<mirror::Class>) \ |
| 63 | M(kObjectArrayClass, "[Ljava/lang/Object;", mirror::ObjectArray<mirror::Object>) \ |
| 64 | M(kJavaLangString, "Ljava/lang/String;", mirror::String) \ |
| 65 | M(kJavaLangDexCache, "Ljava/lang/DexCache;", mirror::DexCache) \ |
| 66 | M(kJavaLangRefReference, "Ljava/lang/ref/Reference;", mirror::Reference) \ |
| 67 | M(kJavaLangReflectConstructor, "Ljava/lang/reflect/Constructor;", mirror::Constructor) \ |
| 68 | M(kJavaLangReflectField, "Ljava/lang/reflect/Field;", mirror::Field) \ |
| 69 | M(kJavaLangReflectMethod, "Ljava/lang/reflect/Method;", mirror::Method) \ |
| 70 | M(kJavaLangReflectProxy, "Ljava/lang/reflect/Proxy;", mirror::Proxy) \ |
| 71 | M(kJavaLangStringArrayClass, "[Ljava/lang/String;", mirror::ObjectArray<mirror::String>) \ |
| 72 | M(kJavaLangReflectConstructorArrayClass, "[Ljava/lang/reflect/Constructor;", mirror::ObjectArray<mirror::Constructor>) \ |
| 73 | M(kJavaLangReflectFieldArrayClass, "[Ljava/lang/reflect/Field;", mirror::ObjectArray<mirror::Field>) \ |
| 74 | M(kJavaLangReflectMethodArrayClass, "[Ljava/lang/reflect/Method;", mirror::ObjectArray<mirror::Method>) \ |
| 75 | M(kJavaLangInvokeCallSite, "Ljava/lang/invoke/CallSite;", mirror::CallSite) \ |
| 76 | M(kJavaLangInvokeMethodHandle, "Ljava/lang/invoke/MethodHandle;", mirror::MethodHandle) \ |
| 77 | M(kJavaLangInvokeMethodHandleImpl, "Ljava/lang/invoke/MethodHandleImpl;", mirror::MethodHandleImpl) \ |
| 78 | M(kJavaLangInvokeMethodHandlesLookup, "Ljava/lang/invoke/MethodHandles$Lookup;", mirror::MethodHandlesLookup) \ |
| 79 | M(kJavaLangInvokeMethodType, "Ljava/lang/invoke/MethodType;", mirror::MethodType) \ |
| 80 | M(kJavaLangInvokeVarHandle, "Ljava/lang/invoke/VarHandle;", mirror::VarHandle) \ |
| 81 | M(kJavaLangInvokeFieldVarHandle, "Ljava/lang/invoke/FieldVarHandle;", mirror::FieldVarHandle) \ |
Orion Hodson | dd41196 | 2021-06-25 08:55:22 +0100 | [diff] [blame] | 82 | M(kJavaLangInvokeStaticFieldVarHandle, "Ljava/lang/invoke/StaticFieldVarHandle;", mirror::StaticFieldVarHandle) \ |
Alex Light | c1ad13a | 2020-03-24 11:37:45 -0700 | [diff] [blame] | 83 | M(kJavaLangInvokeArrayElementVarHandle, "Ljava/lang/invoke/ArrayElementVarHandle;", mirror::ArrayElementVarHandle) \ |
| 84 | M(kJavaLangInvokeByteArrayViewVarHandle, "Ljava/lang/invoke/ByteArrayViewVarHandle;", mirror::ByteArrayViewVarHandle) \ |
| 85 | M(kJavaLangInvokeByteBufferViewVarHandle, "Ljava/lang/invoke/ByteBufferViewVarHandle;", mirror::ByteBufferViewVarHandle) \ |
| 86 | M(kJavaLangClassLoader, "Ljava/lang/ClassLoader;", mirror::ClassLoader) \ |
| 87 | M(kJavaLangThrowable, "Ljava/lang/Throwable;", mirror::Throwable) \ |
| 88 | M(kJavaLangStackTraceElement, "Ljava/lang/StackTraceElement;", mirror::StackTraceElement) \ |
| 89 | M(kDalvikSystemEmulatedStackFrame, "Ldalvik/system/EmulatedStackFrame;", mirror::EmulatedStackFrame) \ |
| 90 | M(kBooleanArrayClass, "[Z", mirror::PrimitiveArray<uint8_t>) \ |
| 91 | M(kByteArrayClass, "[B", mirror::PrimitiveArray<int8_t>) \ |
| 92 | M(kCharArrayClass, "[C", mirror::PrimitiveArray<uint16_t>) \ |
| 93 | M(kDoubleArrayClass, "[D", mirror::PrimitiveArray<double>) \ |
| 94 | M(kFloatArrayClass, "[F", mirror::PrimitiveArray<float>) \ |
| 95 | M(kIntArrayClass, "[I", mirror::PrimitiveArray<int32_t>) \ |
| 96 | M(kLongArrayClass, "[J", mirror::PrimitiveArray<int64_t>) \ |
| 97 | M(kShortArrayClass, "[S", mirror::PrimitiveArray<int16_t>) \ |
| 98 | M(kJavaLangStackTraceElementArrayClass, "[Ljava/lang/StackTraceElement;", mirror::ObjectArray<mirror::StackTraceElement>) \ |
| 99 | M(kJavaLangClassLoaderArrayClass, "[Ljava/lang/ClassLoader;", mirror::ObjectArray<mirror::ClassLoader>) \ |
| 100 | M(kDalvikSystemClassExt, "Ldalvik/system/ClassExt;", mirror::ClassExt) |
| 101 | |
| 102 | #define CLASS_NO_MIRROR_ROOT_LIST(M) \ |
Vladimir Marko | b4eb1b1 | 2018-05-24 11:09:38 +0100 | [diff] [blame] | 103 | M(kJavaLangClassNotFoundException, "Ljava/lang/ClassNotFoundException;", detail::NoMirrorType<detail::ClassNotFoundExceptionTag>) \ |
Vladimir Marko | b4eb1b1 | 2018-05-24 11:09:38 +0100 | [diff] [blame] | 104 | M(kPrimitiveBoolean, "Z", detail::NoMirrorType<uint8_t>) \ |
| 105 | M(kPrimitiveByte, "B", detail::NoMirrorType<int8_t>) \ |
| 106 | M(kPrimitiveChar, "C", detail::NoMirrorType<uint16_t>) \ |
| 107 | M(kPrimitiveDouble, "D", detail::NoMirrorType<double>) \ |
| 108 | M(kPrimitiveFloat, "F", detail::NoMirrorType<float>) \ |
| 109 | M(kPrimitiveInt, "I", detail::NoMirrorType<int32_t>) \ |
| 110 | M(kPrimitiveLong, "J", detail::NoMirrorType<int64_t>) \ |
| 111 | M(kPrimitiveShort, "S", detail::NoMirrorType<int16_t>) \ |
Alex Light | c1ad13a | 2020-03-24 11:37:45 -0700 | [diff] [blame] | 112 | M(kPrimitiveVoid, "V", detail::NoMirrorType<void>) |
| 113 | |
| 114 | #define CLASS_ROOT_LIST(M) \ |
| 115 | CLASS_MIRROR_ROOT_LIST(M) \ |
| 116 | CLASS_NO_MIRROR_ROOT_LIST(M) |
Vladimir Marko | b4eb1b1 | 2018-05-24 11:09:38 +0100 | [diff] [blame] | 117 | |
| 118 | // Well known mirror::Class roots accessed via ClassLinker::GetClassRoots(). |
| 119 | enum class ClassRoot : uint32_t { |
| 120 | #define CLASS_ROOT_ENUMERATOR(name, descriptor, mirror_type) name, |
| 121 | CLASS_ROOT_LIST(CLASS_ROOT_ENUMERATOR) |
| 122 | #undef CLASS_ROOT_ENUMERATOR |
| 123 | kMax, |
| 124 | }; |
| 125 | |
| 126 | const char* GetClassRootDescriptor(ClassRoot class_root); |
| 127 | |
| 128 | template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Vladimir Marko | 5868ada | 2020-05-12 11:50:34 +0100 | [diff] [blame] | 129 | ObjPtr<mirror::Class> GetClassRoot(ClassRoot class_root, |
| 130 | ObjPtr<mirror::ObjectArray<mirror::Class>> class_roots) |
| 131 | REQUIRES_SHARED(Locks::mutator_lock_); |
Vladimir Marko | b4eb1b1 | 2018-05-24 11:09:38 +0100 | [diff] [blame] | 132 | |
| 133 | template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Vladimir Marko | 5868ada | 2020-05-12 11:50:34 +0100 | [diff] [blame] | 134 | ObjPtr<mirror::Class> GetClassRoot(ClassRoot class_root, ClassLinker* linker) |
| 135 | REQUIRES_SHARED(Locks::mutator_lock_); |
Vladimir Marko | b4eb1b1 | 2018-05-24 11:09:38 +0100 | [diff] [blame] | 136 | |
| 137 | template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Vladimir Marko | 5868ada | 2020-05-12 11:50:34 +0100 | [diff] [blame] | 138 | ObjPtr<mirror::Class> GetClassRoot(ClassRoot class_root) REQUIRES_SHARED(Locks::mutator_lock_); |
Vladimir Marko | b4eb1b1 | 2018-05-24 11:09:38 +0100 | [diff] [blame] | 139 | |
| 140 | template <class MirrorType, ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Vladimir Marko | 5868ada | 2020-05-12 11:50:34 +0100 | [diff] [blame] | 141 | ObjPtr<mirror::Class> GetClassRoot(ObjPtr<mirror::ObjectArray<mirror::Class>> class_roots) |
| 142 | REQUIRES_SHARED(Locks::mutator_lock_); |
Vladimir Marko | b4eb1b1 | 2018-05-24 11:09:38 +0100 | [diff] [blame] | 143 | |
| 144 | template <class MirrorType, ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Vladimir Marko | 5868ada | 2020-05-12 11:50:34 +0100 | [diff] [blame] | 145 | ObjPtr<mirror::Class> GetClassRoot(ClassLinker* linker) REQUIRES_SHARED(Locks::mutator_lock_); |
Vladimir Marko | b4eb1b1 | 2018-05-24 11:09:38 +0100 | [diff] [blame] | 146 | |
| 147 | template <class MirrorType, ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Vladimir Marko | 5868ada | 2020-05-12 11:50:34 +0100 | [diff] [blame] | 148 | ObjPtr<mirror::Class> GetClassRoot() REQUIRES_SHARED(Locks::mutator_lock_); |
Vladimir Marko | b4eb1b1 | 2018-05-24 11:09:38 +0100 | [diff] [blame] | 149 | |
| 150 | } // namespace art |
| 151 | |
| 152 | #endif // ART_RUNTIME_CLASS_ROOT_H_ |