blob: baa21286a850d1d28bfd969b2b5aa69ae495f4f2 [file] [log] [blame]
Vladimir Markob4eb1b12018-05-24 11:09:38 +01001/*
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 Marko5868ada2020-05-12 11:50:34 +010020#include <stdint.h>
21
22#include "base/locks.h"
23#include "read_barrier_option.h"
Vladimir Markob4eb1b12018-05-24 11:09:38 +010024
25namespace art {
26
Vladimir Marko5868ada2020-05-12 11:50:34 +010027class ClassLinker;
28template<class MirrorType> class ObjPtr;
29
Vladimir Markob4eb1b12018-05-24 11:09:38 +010030namespace mirror {
31class ArrayElementVarHandle;
32class ByteArrayViewVarHandle;
33class ByteBufferViewVarHandle;
34class CallSite;
Vladimir Marko5868ada2020-05-12 11:50:34 +010035class Class;
Vladimir Markob4eb1b12018-05-24 11:09:38 +010036class ClassExt;
37class ClassLoader;
38class Constructor;
39class DexCache;
40class EmulatedStackFrame;
41class Field;
42class FieldVarHandle;
43class Method;
44class MethodHandleImpl;
45class MethodHandlesLookup;
46class MethodType;
47class Object;
Vladimir Marko5868ada2020-05-12 11:50:34 +010048template<class T> class ObjectArray;
Vladimir Markob4eb1b12018-05-24 11:09:38 +010049class Proxy;
50template<typename T> class PrimitiveArray;
51class Reference;
52class StackTraceElement;
Orion Hodsondd411962021-06-25 08:55:22 +010053class StaticFieldVarHandle;
Vladimir Markob4eb1b12018-05-24 11:09:38 +010054class String;
55class Throwable;
56class VarHandle;
57} // namespace mirror
58
Alex Lightc1ad13a2020-03-24 11:37:45 -070059#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 Hodsondd411962021-06-25 08:55:22 +010082 M(kJavaLangInvokeStaticFieldVarHandle, "Ljava/lang/invoke/StaticFieldVarHandle;", mirror::StaticFieldVarHandle) \
Alex Lightc1ad13a2020-03-24 11:37:45 -070083 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 Markob4eb1b12018-05-24 11:09:38 +0100103 M(kJavaLangClassNotFoundException, "Ljava/lang/ClassNotFoundException;", detail::NoMirrorType<detail::ClassNotFoundExceptionTag>) \
Vladimir Markob4eb1b12018-05-24 11:09:38 +0100104 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 Lightc1ad13a2020-03-24 11:37:45 -0700112 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 Markob4eb1b12018-05-24 11:09:38 +0100117
118// Well known mirror::Class roots accessed via ClassLinker::GetClassRoots().
119enum 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
126const char* GetClassRootDescriptor(ClassRoot class_root);
127
128template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Vladimir Marko5868ada2020-05-12 11:50:34 +0100129ObjPtr<mirror::Class> GetClassRoot(ClassRoot class_root,
130 ObjPtr<mirror::ObjectArray<mirror::Class>> class_roots)
131 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Markob4eb1b12018-05-24 11:09:38 +0100132
133template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Vladimir Marko5868ada2020-05-12 11:50:34 +0100134ObjPtr<mirror::Class> GetClassRoot(ClassRoot class_root, ClassLinker* linker)
135 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Markob4eb1b12018-05-24 11:09:38 +0100136
137template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Vladimir Marko5868ada2020-05-12 11:50:34 +0100138ObjPtr<mirror::Class> GetClassRoot(ClassRoot class_root) REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Markob4eb1b12018-05-24 11:09:38 +0100139
140template <class MirrorType, ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Vladimir Marko5868ada2020-05-12 11:50:34 +0100141ObjPtr<mirror::Class> GetClassRoot(ObjPtr<mirror::ObjectArray<mirror::Class>> class_roots)
142 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Markob4eb1b12018-05-24 11:09:38 +0100143
144template <class MirrorType, ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Vladimir Marko5868ada2020-05-12 11:50:34 +0100145ObjPtr<mirror::Class> GetClassRoot(ClassLinker* linker) REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Markob4eb1b12018-05-24 11:09:38 +0100146
147template <class MirrorType, ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Vladimir Marko5868ada2020-05-12 11:50:34 +0100148ObjPtr<mirror::Class> GetClassRoot() REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Markob4eb1b12018-05-24 11:09:38 +0100149
150} // namespace art
151
152#endif // ART_RUNTIME_CLASS_ROOT_H_