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