Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | */ |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_CLASS_LINKER_H_ |
| 18 | #define ART_RUNTIME_CLASS_LINKER_H_ |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 19 | |
Mathieu Chartier | c5dd319 | 2015-12-09 16:38:30 -0800 | [diff] [blame] | 20 | #include <set> |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 21 | #include <string> |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 22 | #include <unordered_map> |
Mathieu Chartier | c5dd319 | 2015-12-09 16:38:30 -0800 | [diff] [blame] | 23 | #include <unordered_set> |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 24 | #include <utility> |
| 25 | #include <vector> |
| 26 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 27 | #include "base/enums.h" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 28 | #include "base/macros.h" |
Elliott Hughes | 76b6167 | 2012-12-12 17:47:30 -0800 | [diff] [blame] | 29 | #include "base/mutex.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 30 | #include "dex/dex_file.h" |
| 31 | #include "dex/dex_file_types.h" |
Mathieu Chartier | c5dd319 | 2015-12-09 16:38:30 -0800 | [diff] [blame] | 32 | #include "dex_cache_resolved_classes.h" |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 33 | #include "gc_root.h" |
Andreas Gampe | 0f01b58 | 2017-01-18 15:22:37 -0800 | [diff] [blame] | 34 | #include "handle.h" |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 35 | #include "jni.h" |
Vladimir Marko | 97d7e1c | 2016-10-04 14:44:28 +0100 | [diff] [blame] | 36 | #include "mirror/class.h" |
Andreas Gampe | 6d7abbd | 2017-04-24 13:19:09 -0700 | [diff] [blame] | 37 | #include "verifier/verifier_enums.h" |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 38 | |
| 39 | namespace art { |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 40 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 41 | namespace gc { |
| 42 | namespace space { |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 43 | class ImageSpace; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 44 | } // namespace space |
| 45 | } // namespace gc |
Vladimir Marko | 7452797 | 2016-11-29 15:57:32 +0000 | [diff] [blame] | 46 | |
| 47 | namespace linker { |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 48 | struct CompilationHelper; |
| 49 | class ImageWriter; |
| 50 | class OatWriter; |
Vladimir Marko | 7452797 | 2016-11-29 15:57:32 +0000 | [diff] [blame] | 51 | } // namespace linker |
| 52 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 53 | namespace mirror { |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 54 | class ClassLoader; |
| 55 | class DexCache; |
| 56 | class DexCachePointerArray; |
| 57 | class DexCacheMethodHandlesTest_Open_Test; |
| 58 | class DexCacheTest_Open_Test; |
| 59 | class IfTable; |
| 60 | class MethodHandle; |
| 61 | class MethodHandlesLookup; |
| 62 | class MethodType; |
| 63 | template<class T> class ObjectArray; |
| 64 | class StackTraceElement; |
| 65 | template <typename T> struct NativeDexCachePair; |
| 66 | using MethodDexCachePair = NativeDexCachePair<ArtMethod>; |
| 67 | using MethodDexCacheType = std::atomic<MethodDexCachePair>; |
Ian Rogers | 33e9566 | 2013-05-20 20:29:14 -0700 | [diff] [blame] | 68 | } // namespace mirror |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 69 | |
Andreas Gampe | c1ac9ee | 2017-07-24 22:35:49 -0700 | [diff] [blame] | 70 | class ClassHierarchyAnalysis; |
Andreas Gampe | 2af9902 | 2017-04-25 08:32:59 -0700 | [diff] [blame] | 71 | class ClassTable; |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 72 | template<class T> class Handle; |
Vladimir Marko | 97d7e1c | 2016-10-04 14:44:28 +0100 | [diff] [blame] | 73 | class ImtConflictTable; |
| 74 | template<typename T> class LengthPrefixedArray; |
Hiroshi Yamauchi | 679b1cf | 2015-05-21 12:05:27 -0700 | [diff] [blame] | 75 | template<class T> class MutableHandle; |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 76 | class InternTable; |
Andreas Gampe | d482e73 | 2017-04-24 17:59:09 -0700 | [diff] [blame] | 77 | class LinearAlloc; |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 78 | class OatFile; |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 79 | template<class T> class ObjectLock; |
Andreas Gampe | 7ba6496 | 2014-10-23 11:37:40 -0700 | [diff] [blame] | 80 | class Runtime; |
Mathieu Chartier | 2b7c4d1 | 2014-05-19 10:52:16 -0700 | [diff] [blame] | 81 | class ScopedObjectAccessAlreadyRunnable; |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 82 | template<size_t kNumReferences> class PACKED(4) StackHandleScope; |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 83 | |
Mathieu Chartier | 893263b | 2014-03-04 11:07:42 -0800 | [diff] [blame] | 84 | enum VisitRootFlags : uint8_t; |
| 85 | |
Mathieu Chartier | 1aa8ec2 | 2016-02-01 10:34:47 -0800 | [diff] [blame] | 86 | class ClassVisitor { |
| 87 | public: |
| 88 | virtual ~ClassVisitor() {} |
| 89 | // Return true to continue visiting. |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 90 | virtual bool operator()(ObjPtr<mirror::Class> klass) = 0; |
Mathieu Chartier | 1aa8ec2 | 2016-02-01 10:34:47 -0800 | [diff] [blame] | 91 | }; |
| 92 | |
Mathieu Chartier | 9b1c71e | 2015-09-02 18:51:54 -0700 | [diff] [blame] | 93 | class ClassLoaderVisitor { |
| 94 | public: |
| 95 | virtual ~ClassLoaderVisitor() {} |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 96 | virtual void Visit(ObjPtr<mirror::ClassLoader> class_loader) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 97 | REQUIRES_SHARED(Locks::classlinker_classes_lock_, Locks::mutator_lock_) = 0; |
Mathieu Chartier | 9b1c71e | 2015-09-02 18:51:54 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 100 | class ClassLinker { |
| 101 | public: |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 102 | // Well known mirror::Class roots accessed via GetClassRoot. |
| 103 | enum ClassRoot { |
| 104 | kJavaLangClass, |
| 105 | kJavaLangObject, |
| 106 | kClassArrayClass, |
| 107 | kObjectArrayClass, |
| 108 | kJavaLangString, |
| 109 | kJavaLangDexCache, |
| 110 | kJavaLangRefReference, |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 111 | kJavaLangReflectConstructor, |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 112 | kJavaLangReflectField, |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 113 | kJavaLangReflectMethod, |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 114 | kJavaLangReflectProxy, |
| 115 | kJavaLangStringArrayClass, |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 116 | kJavaLangReflectConstructorArrayClass, |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 117 | kJavaLangReflectFieldArrayClass, |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 118 | kJavaLangReflectMethodArrayClass, |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 119 | kJavaLangInvokeCallSite, |
Narayan Kamath | afa4827 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 120 | kJavaLangInvokeMethodHandleImpl, |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 121 | kJavaLangInvokeMethodHandlesLookup, |
Narayan Kamath | afa4827 | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 122 | kJavaLangInvokeMethodType, |
Orion Hodson | 005ac51 | 2017-10-24 15:43:43 +0100 | [diff] [blame] | 123 | kJavaLangInvokeVarHandle, |
| 124 | kJavaLangInvokeFieldVarHandle, |
| 125 | kJavaLangInvokeArrayElementVarHandle, |
| 126 | kJavaLangInvokeByteArrayViewVarHandle, |
| 127 | kJavaLangInvokeByteBufferViewVarHandle, |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 128 | kJavaLangClassLoader, |
| 129 | kJavaLangThrowable, |
| 130 | kJavaLangClassNotFoundException, |
| 131 | kJavaLangStackTraceElement, |
Narayan Kamath | 000e188 | 2016-10-24 17:14:25 +0100 | [diff] [blame] | 132 | kDalvikSystemEmulatedStackFrame, |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 133 | kPrimitiveBoolean, |
| 134 | kPrimitiveByte, |
| 135 | kPrimitiveChar, |
| 136 | kPrimitiveDouble, |
| 137 | kPrimitiveFloat, |
| 138 | kPrimitiveInt, |
| 139 | kPrimitiveLong, |
| 140 | kPrimitiveShort, |
| 141 | kPrimitiveVoid, |
| 142 | kBooleanArrayClass, |
| 143 | kByteArrayClass, |
| 144 | kCharArrayClass, |
| 145 | kDoubleArrayClass, |
| 146 | kFloatArrayClass, |
| 147 | kIntArrayClass, |
| 148 | kLongArrayClass, |
| 149 | kShortArrayClass, |
| 150 | kJavaLangStackTraceElementArrayClass, |
Alex Light | d625158 | 2016-10-31 11:12:30 -0700 | [diff] [blame] | 151 | kDalvikSystemClassExt, |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 152 | kClassRootsMax, |
| 153 | }; |
| 154 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 155 | explicit ClassLinker(InternTable* intern_table); |
Chang Xing | 605fe24 | 2017-07-20 15:57:21 -0700 | [diff] [blame] | 156 | virtual ~ClassLinker(); |
Carl Shapiro | 565f507 | 2011-07-10 13:39:43 -0700 | [diff] [blame] | 157 | |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 158 | // Initialize class linker by bootstraping from dex files. |
Andreas Gampe | 3db9c5d | 2015-11-17 11:52:46 -0800 | [diff] [blame] | 159 | bool InitWithoutImage(std::vector<std::unique_ptr<const DexFile>> boot_class_path, |
| 160 | std::string* error_msg) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 161 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 162 | REQUIRES(!Locks::dex_lock_); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 163 | |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 164 | // Initialize class linker from one or more boot images. |
| 165 | bool InitFromBootImage(std::string* error_msg) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 166 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 167 | REQUIRES(!Locks::dex_lock_); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 168 | |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 169 | // Add an image space to the class linker, may fix up classloader fields and dex cache fields. |
| 170 | // The dex files that were newly opened for the space are placed in the out argument |
| 171 | // out_dex_files. Returns true if the operation succeeded. |
| 172 | // The space must be already added to the heap before calling AddImageSpace since we need to |
| 173 | // properly handle read barriers and object marking. |
| 174 | bool AddImageSpace(gc::space::ImageSpace* space, |
| 175 | Handle<mirror::ClassLoader> class_loader, |
| 176 | jobjectArray dex_elements, |
| 177 | const char* dex_location, |
| 178 | std::vector<std::unique_ptr<const DexFile>>* out_dex_files, |
| 179 | std::string* error_msg) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 180 | REQUIRES(!Locks::dex_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 181 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 182 | |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 183 | bool OpenImageDexFiles(gc::space::ImageSpace* space, |
| 184 | std::vector<std::unique_ptr<const DexFile>>* out_dex_files, |
| 185 | std::string* error_msg) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 186 | REQUIRES(!Locks::dex_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 187 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 188 | |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 189 | // Finds a class by its descriptor, loading it if necessary. |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 190 | // If class_loader is null, searches boot_class_path_. |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 191 | mirror::Class* FindClass(Thread* self, |
| 192 | const char* descriptor, |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 193 | Handle<mirror::ClassLoader> class_loader) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 194 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 195 | REQUIRES(!Locks::dex_lock_); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 196 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 197 | // Finds a class by its descriptor using the "system" class loader, ie by searching the |
| 198 | // boot_class_path_. |
| 199 | mirror::Class* FindSystemClass(Thread* self, const char* descriptor) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 200 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | c6ea7d0 | 2017-02-01 16:46:28 -0800 | [diff] [blame] | 201 | REQUIRES(!Locks::dex_lock_) { |
| 202 | return FindClass(self, descriptor, ScopedNullHandle<mirror::ClassLoader>()); |
| 203 | } |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 204 | |
| 205 | // Finds the array class given for the element class. |
Mathieu Chartier | bc5a795 | 2016-10-17 15:46:31 -0700 | [diff] [blame] | 206 | mirror::Class* FindArrayClass(Thread* self, ObjPtr<mirror::Class>* element_class) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 207 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 208 | REQUIRES(!Locks::dex_lock_); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 209 | |
Ian Rogers | 6355745 | 2014-06-04 16:57:15 -0700 | [diff] [blame] | 210 | // Returns true if the class linker is initialized. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 211 | bool IsInitialized() const { |
| 212 | return init_done_; |
| 213 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 214 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 215 | // Define a new a class based on a ClassDef from a DexFile |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 216 | mirror::Class* DefineClass(Thread* self, |
| 217 | const char* descriptor, |
| 218 | size_t hash, |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 219 | Handle<mirror::ClassLoader> class_loader, |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 220 | const DexFile& dex_file, |
| 221 | const DexFile::ClassDef& dex_class_def) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 222 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 223 | REQUIRES(!Locks::dex_lock_); |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 224 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 225 | // Finds a class by its descriptor, returning null if it isn't wasn't loaded |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 226 | // by the given 'class_loader'. |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 227 | mirror::Class* LookupClass(Thread* self, |
| 228 | const char* descriptor, |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 229 | ObjPtr<mirror::ClassLoader> class_loader) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 230 | REQUIRES(!Locks::classlinker_classes_lock_) |
Andreas Gampe | 2ff3b97 | 2017-06-05 18:14:53 -0700 | [diff] [blame] | 231 | REQUIRES_SHARED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 232 | |
Elliott Hughes | 6fa602d | 2011-12-02 17:54:25 -0800 | [diff] [blame] | 233 | // Finds all the classes with the given descriptor, regardless of ClassLoader. |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 234 | void LookupClasses(const char* descriptor, std::vector<ObjPtr<mirror::Class>>& classes) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 235 | REQUIRES(!Locks::classlinker_classes_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 236 | REQUIRES_SHARED(Locks::mutator_lock_); |
Elliott Hughes | 6fa602d | 2011-12-02 17:54:25 -0800 | [diff] [blame] | 237 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 238 | mirror::Class* FindPrimitiveClass(char type) REQUIRES_SHARED(Locks::mutator_lock_); |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 239 | |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 240 | void DumpForSigQuit(std::ostream& os) REQUIRES(!Locks::classlinker_classes_lock_); |
Elliott Hughes | cac6cc7 | 2011-11-03 20:31:21 -0700 | [diff] [blame] | 241 | |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 242 | size_t NumLoadedClasses() |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 243 | REQUIRES(!Locks::classlinker_classes_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 244 | REQUIRES_SHARED(Locks::mutator_lock_); |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 245 | |
Vladimir Marko | a64b52d | 2017-12-08 16:27:49 +0000 | [diff] [blame] | 246 | // Resolve a String with the given index from the DexFile associated with the given DexCache, |
| 247 | // storing the result in the DexCache. |
| 248 | ObjPtr<mirror::String> ResolveString(dex::StringIndex string_idx, |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 249 | Handle<mirror::DexCache> dex_cache) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 250 | REQUIRES_SHARED(Locks::mutator_lock_); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 251 | |
Vladimir Marko | a64b52d | 2017-12-08 16:27:49 +0000 | [diff] [blame] | 252 | // Find a String with the given index from the DexFile associated with the given DexCache, |
| 253 | // storing the result in the DexCache if found. Return null if not found. |
| 254 | ObjPtr<mirror::String> LookupString(dex::StringIndex string_idx, |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 255 | ObjPtr<mirror::DexCache> dex_cache) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 256 | REQUIRES_SHARED(Locks::mutator_lock_); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 257 | |
Vladimir Marko | 666ee3d | 2017-12-11 18:37:36 +0000 | [diff] [blame] | 258 | // Resolve a Type with the given index from the DexFile associated with the given `referrer`, |
| 259 | // storing the result in the DexCache. The `referrer` is used to identify the target DexCache |
| 260 | // and ClassLoader to use for resolution. |
| 261 | ObjPtr<mirror::Class> ResolveType(dex::TypeIndex type_idx, ObjPtr<mirror::Class> referrer) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 262 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 263 | REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 264 | |
Vladimir Marko | 666ee3d | 2017-12-11 18:37:36 +0000 | [diff] [blame] | 265 | // Resolve a type with the given index from the DexFile associated with the given `referrer`, |
| 266 | // storing the result in the DexCache. The `referrer` is used to identify the target DexCache |
| 267 | // and ClassLoader to use for resolution. |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 268 | ObjPtr<mirror::Class> ResolveType(dex::TypeIndex type_idx, ArtMethod* referrer) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 269 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 270 | REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 271 | |
Vladimir Marko | 666ee3d | 2017-12-11 18:37:36 +0000 | [diff] [blame] | 272 | // Resolve a type with the given index from the DexFile associated with the given DexCache |
| 273 | // and ClassLoader, storing the result in DexCache. The ClassLoader is used to search for |
| 274 | // the type, since it may be referenced from but not contained within the DexFile. |
| 275 | ObjPtr<mirror::Class> ResolveType(dex::TypeIndex type_idx, |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 276 | Handle<mirror::DexCache> dex_cache, |
| 277 | Handle<mirror::ClassLoader> class_loader) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 278 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 279 | REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 280 | |
Vladimir Marko | 666ee3d | 2017-12-11 18:37:36 +0000 | [diff] [blame] | 281 | // Look up a resolved type with the given index from the DexFile associated with the given |
| 282 | // `referrer`, storing the result in the DexCache. The `referrer` is used to identify the |
| 283 | // target DexCache and ClassLoader to use for lookup. |
| 284 | ObjPtr<mirror::Class> LookupResolvedType(dex::TypeIndex type_idx, |
| 285 | ObjPtr<mirror::Class> referrer) |
| 286 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 287 | |
| 288 | // Look up a resolved type with the given index from the DexFile associated with the given |
| 289 | // `referrer`, storing the result in the DexCache. The `referrer` is used to identify the |
| 290 | // target DexCache and ClassLoader to use for lookup. |
| 291 | ObjPtr<mirror::Class> LookupResolvedType(dex::TypeIndex type_idx, ArtMethod* referrer) |
| 292 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 293 | |
| 294 | // Look up a resolved type with the given index from the DexFile associated with the given |
| 295 | // DexCache and ClassLoader. The ClassLoader is used to search for the type, since it may |
| 296 | // be referenced from but not contained within the DexFile. |
| 297 | ObjPtr<mirror::Class> LookupResolvedType(dex::TypeIndex type_idx, |
| 298 | ObjPtr<mirror::DexCache> dex_cache, |
| 299 | ObjPtr<mirror::ClassLoader> class_loader) |
| 300 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 301 | |
Andreas Gampe | 42ef8ab | 2015-12-03 17:27:32 -0800 | [diff] [blame] | 302 | // Determine whether a dex cache result should be trusted, or an IncompatibleClassChangeError |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 303 | // check and IllegalAccessError check should be performed even after a hit. |
| 304 | enum class ResolveMode { // private. |
| 305 | kNoChecks, |
| 306 | kCheckICCEAndIAE |
Andreas Gampe | 42ef8ab | 2015-12-03 17:27:32 -0800 | [diff] [blame] | 307 | }; |
| 308 | |
Vladimir Marko | 07bfbac | 2017-07-06 14:55:02 +0100 | [diff] [blame] | 309 | // Look up a previously resolved method with the given index. |
| 310 | ArtMethod* LookupResolvedMethod(uint32_t method_idx, |
| 311 | ObjPtr<mirror::DexCache> dex_cache, |
| 312 | ObjPtr<mirror::ClassLoader> class_loader) |
| 313 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 314 | |
Vladimir Marko | 8901119 | 2017-12-11 13:45:05 +0000 | [diff] [blame] | 315 | // Resolve a method with a given ID from the DexFile associated with the given DexCache |
| 316 | // and ClassLoader, storing the result in DexCache. The ClassLinker and ClassLoader are |
| 317 | // used as in ResolveType. What is unique is the method type argument which is used to |
| 318 | // determine if this method is a direct, static, or virtual method. |
Andreas Gampe | 42ef8ab | 2015-12-03 17:27:32 -0800 | [diff] [blame] | 319 | template <ResolveMode kResolveMode> |
Vladimir Marko | 8901119 | 2017-12-11 13:45:05 +0000 | [diff] [blame] | 320 | ArtMethod* ResolveMethod(uint32_t method_idx, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 321 | Handle<mirror::DexCache> dex_cache, |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 322 | Handle<mirror::ClassLoader> class_loader, |
| 323 | ArtMethod* referrer, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 324 | InvokeType type) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 325 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 326 | REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 327 | |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 328 | template <InvokeType type, ResolveMode kResolveMode> |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 329 | ArtMethod* GetResolvedMethod(uint32_t method_idx, ArtMethod* referrer) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 330 | REQUIRES_SHARED(Locks::mutator_lock_); |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 331 | |
Andreas Gampe | 42ef8ab | 2015-12-03 17:27:32 -0800 | [diff] [blame] | 332 | template <ResolveMode kResolveMode> |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 333 | ArtMethod* ResolveMethod(Thread* self, uint32_t method_idx, ArtMethod* referrer, InvokeType type) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 334 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 335 | REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); |
Vladimir Marko | 8901119 | 2017-12-11 13:45:05 +0000 | [diff] [blame] | 336 | ArtMethod* ResolveMethodWithoutInvokeType(uint32_t method_idx, |
Jeff Hao | 0042c6d | 2015-07-29 20:14:10 -0700 | [diff] [blame] | 337 | Handle<mirror::DexCache> dex_cache, |
| 338 | Handle<mirror::ClassLoader> class_loader) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 339 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 340 | REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 341 | |
Vladimir Marko | f44d36c | 2017-03-14 14:18:46 +0000 | [diff] [blame] | 342 | ArtField* LookupResolvedField(uint32_t field_idx, ArtMethod* referrer, bool is_static) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 343 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 344 | ArtField* ResolveField(uint32_t field_idx, ArtMethod* referrer, bool is_static) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 345 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 346 | REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); |
Brian Carlstrom | b9edb84 | 2011-08-28 16:31:06 -0700 | [diff] [blame] | 347 | |
Vladimir Marko | e11dd50 | 2017-12-08 14:09:45 +0000 | [diff] [blame] | 348 | // Resolve a field with a given ID from the DexFile associated with the given DexCache |
| 349 | // and ClassLoader, storing the result in DexCache. The ClassLinker and ClassLoader |
| 350 | // are used as in ResolveType. What is unique is the is_static argument which is used |
| 351 | // to determine if we are resolving a static or non-static field. |
| 352 | ArtField* ResolveField(uint32_t field_idx, |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 353 | Handle<mirror::DexCache> dex_cache, |
Vladimir Marko | e11dd50 | 2017-12-08 14:09:45 +0000 | [diff] [blame] | 354 | Handle<mirror::ClassLoader> class_loader, |
| 355 | bool is_static) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 356 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 357 | REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 358 | |
Vladimir Marko | e11dd50 | 2017-12-08 14:09:45 +0000 | [diff] [blame] | 359 | // Resolve a field with a given ID from the DexFile associated with the given DexCache |
| 360 | // and ClassLoader, storing the result in DexCache. The ClassLinker and ClassLoader |
| 361 | // are used as in ResolveType. No is_static argument is provided so that Java |
Ian Rogers | b067ac2 | 2011-12-13 18:05:09 -0800 | [diff] [blame] | 362 | // field resolution semantics are followed. |
Vladimir Marko | e11dd50 | 2017-12-08 14:09:45 +0000 | [diff] [blame] | 363 | ArtField* ResolveFieldJLS(uint32_t field_idx, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 364 | Handle<mirror::DexCache> dex_cache, |
| 365 | Handle<mirror::ClassLoader> class_loader) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 366 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 367 | REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); |
Ian Rogers | b067ac2 | 2011-12-13 18:05:09 -0800 | [diff] [blame] | 368 | |
Vladimir Marko | af94020 | 2017-12-08 15:01:18 +0000 | [diff] [blame] | 369 | // Resolve a method type with a given ID from the DexFile associated with a given DexCache |
| 370 | // and ClassLoader, storing the result in the DexCache. |
| 371 | ObjPtr<mirror::MethodType> ResolveMethodType(Thread* self, |
| 372 | uint32_t proto_idx, |
| 373 | Handle<mirror::DexCache> dex_cache, |
| 374 | Handle<mirror::ClassLoader> class_loader) |
Narayan Kamath | 25352fc | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 375 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 376 | REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 377 | |
Vladimir Marko | af94020 | 2017-12-08 15:01:18 +0000 | [diff] [blame] | 378 | ObjPtr<mirror::MethodType> ResolveMethodType(Thread* self, |
| 379 | uint32_t proto_idx, |
| 380 | ArtMethod* referrer) |
Orion Hodson | 2e59994 | 2017-09-22 16:17:41 +0100 | [diff] [blame] | 381 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 382 | |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 383 | // Resolve a method handle with a given ID from the DexFile. The |
| 384 | // result is not cached in the DexCache as the instance will only be |
| 385 | // used once in most circumstances. |
Vladimir Marko | af94020 | 2017-12-08 15:01:18 +0000 | [diff] [blame] | 386 | ObjPtr<mirror::MethodHandle> ResolveMethodHandle(Thread* self, |
| 387 | uint32_t method_handle_idx, |
| 388 | ArtMethod* referrer) |
Orion Hodson | c069a30 | 2017-01-18 09:23:12 +0000 | [diff] [blame] | 389 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 390 | |
Elliott Hughes | f4c21c9 | 2011-08-19 17:31:31 -0700 | [diff] [blame] | 391 | // Returns true on success, false if there's an exception pending. |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 392 | // can_run_clinit=false allows the compiler to attempt to init a class, |
| 393 | // given the restriction that no <clinit> execution is possible. |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 394 | bool EnsureInitialized(Thread* self, |
| 395 | Handle<mirror::Class> c, |
| 396 | bool can_init_fields, |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 397 | bool can_init_parents) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 398 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 399 | REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 400 | |
Elliott Hughes | 2a20cfd | 2011-09-23 19:30:41 -0700 | [diff] [blame] | 401 | // Initializes classes that have instances in the image but that have |
| 402 | // <clinit> methods so they could not be initialized by the compiler. |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 403 | void RunRootClinits() |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 404 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 405 | REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); |
Elliott Hughes | 2a20cfd | 2011-09-23 19:30:41 -0700 | [diff] [blame] | 406 | |
Alex Light | 07f0621 | 2017-06-01 14:01:43 -0700 | [diff] [blame] | 407 | // Directly register an already existing dex cache. RegisterDexFile should be preferred since that |
| 408 | // reduplicates DexCaches when possible. The DexCache given to this function must already be fully |
| 409 | // initialized and not already registered. |
| 410 | void RegisterExistingDexCache(ObjPtr<mirror::DexCache> cache, |
| 411 | ObjPtr<mirror::ClassLoader> class_loader) |
| 412 | REQUIRES(!Locks::dex_lock_) |
| 413 | REQUIRES_SHARED(Locks::mutator_lock_); |
Vladimir Marko | cd556b0 | 2017-02-03 11:47:34 +0000 | [diff] [blame] | 414 | ObjPtr<mirror::DexCache> RegisterDexFile(const DexFile& dex_file, |
| 415 | ObjPtr<mirror::ClassLoader> class_loader) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 416 | REQUIRES(!Locks::dex_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 417 | REQUIRES_SHARED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 418 | |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 419 | const std::vector<const DexFile*>& GetBootClassPath() { |
| 420 | return boot_class_path_; |
| 421 | } |
| 422 | |
Mathieu Chartier | e0671ce | 2015-07-28 17:23:28 -0700 | [diff] [blame] | 423 | void VisitClasses(ClassVisitor* visitor) |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 424 | REQUIRES(!Locks::classlinker_classes_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 425 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | dbf3be0 | 2014-08-29 15:40:08 -0700 | [diff] [blame] | 426 | |
| 427 | // Less efficient variant of VisitClasses that copies the class_table_ into secondary storage |
| 428 | // so that it can visit individual classes without holding the doesn't hold the |
| 429 | // Locks::classlinker_classes_lock_. As the Locks::classlinker_classes_lock_ isn't held this code |
| 430 | // can race with insertion and deletion of classes while the visitor is being called. |
Mathieu Chartier | e0671ce | 2015-07-28 17:23:28 -0700 | [diff] [blame] | 431 | void VisitClassesWithoutClassesLock(ClassVisitor* visitor) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 432 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 433 | REQUIRES(!Locks::dex_lock_); |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 434 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 435 | void VisitClassRoots(RootVisitor* visitor, VisitRootFlags flags) |
Andreas Gampe | d98b4ed | 2016-11-04 20:27:24 -0700 | [diff] [blame] | 436 | REQUIRES(!Locks::classlinker_classes_lock_, !Locks::trace_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 437 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 438 | void VisitRoots(RootVisitor* visitor, VisitRootFlags flags) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 439 | REQUIRES(!Locks::dex_lock_, !Locks::classlinker_classes_lock_, !Locks::trace_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 440 | REQUIRES_SHARED(Locks::mutator_lock_); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 441 | |
Vladimir Marko | cd556b0 | 2017-02-03 11:47:34 +0000 | [diff] [blame] | 442 | bool IsDexFileRegistered(Thread* self, const DexFile& dex_file) |
| 443 | REQUIRES(!Locks::dex_lock_) |
| 444 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 445 | ObjPtr<mirror::DexCache> FindDexCache(Thread* self, const DexFile& dex_file) |
| 446 | REQUIRES(!Locks::dex_lock_) |
| 447 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 448 | ClassTable* FindClassTable(Thread* self, ObjPtr<mirror::DexCache> dex_cache) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 449 | REQUIRES(!Locks::dex_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 450 | REQUIRES_SHARED(Locks::mutator_lock_); |
Brian Carlstrom | 1d9f52b | 2011-10-13 10:50:45 -0700 | [diff] [blame] | 451 | |
Mathieu Chartier | 951ec2c | 2015-09-22 08:50:05 -0700 | [diff] [blame] | 452 | LengthPrefixedArray<ArtField>* AllocArtFieldArray(Thread* self, |
| 453 | LinearAlloc* allocator, |
| 454 | size_t length); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 455 | |
Mathieu Chartier | 951ec2c | 2015-09-22 08:50:05 -0700 | [diff] [blame] | 456 | LengthPrefixedArray<ArtMethod>* AllocArtMethodArray(Thread* self, |
| 457 | LinearAlloc* allocator, |
| 458 | size_t length); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 459 | |
| 460 | mirror::PointerArray* AllocPointerArray(Thread* self, size_t length) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 461 | REQUIRES_SHARED(Locks::mutator_lock_) |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 462 | REQUIRES(!Roles::uninterruptible_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 463 | |
| 464 | mirror::IfTable* AllocIfTable(Thread* self, size_t ifcount) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 465 | REQUIRES_SHARED(Locks::mutator_lock_) |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 466 | REQUIRES(!Roles::uninterruptible_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 467 | |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 468 | mirror::ObjectArray<mirror::StackTraceElement>* AllocStackTraceElementArray(Thread* self, |
| 469 | size_t length) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 470 | REQUIRES_SHARED(Locks::mutator_lock_) |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 471 | REQUIRES(!Roles::uninterruptible_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 472 | |
Andreas Gampe | 6d7abbd | 2017-04-24 13:19:09 -0700 | [diff] [blame] | 473 | verifier::FailureKind VerifyClass( |
Nicolas Geoffray | 0802518 | 2016-10-25 17:20:18 +0100 | [diff] [blame] | 474 | Thread* self, |
| 475 | Handle<mirror::Class> klass, |
| 476 | verifier::HardFailLogMode log_level = verifier::HardFailLogMode::kLogNone) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 477 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 478 | REQUIRES(!Locks::dex_lock_); |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 479 | bool VerifyClassUsingOatFile(const DexFile& dex_file, |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 480 | ObjPtr<mirror::Class> klass, |
Vladimir Marko | 2c64a83 | 2018-01-04 11:31:56 +0000 | [diff] [blame] | 481 | ClassStatus& oat_file_class_status) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 482 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 483 | REQUIRES(!Locks::dex_lock_); |
Alex Light | 5a55986 | 2016-01-29 12:24:48 -0800 | [diff] [blame] | 484 | void ResolveClassExceptionHandlerTypes(Handle<mirror::Class> klass) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 485 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 486 | REQUIRES(!Locks::dex_lock_); |
Alex Light | 5a55986 | 2016-01-29 12:24:48 -0800 | [diff] [blame] | 487 | void ResolveMethodExceptionHandlerTypes(ArtMethod* klass) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 488 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 489 | REQUIRES(!Locks::dex_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 490 | |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 491 | mirror::Class* CreateProxyClass(ScopedObjectAccessAlreadyRunnable& soa, |
| 492 | jstring name, |
| 493 | jobjectArray interfaces, |
| 494 | jobject loader, |
| 495 | jobjectArray methods, |
Mathieu Chartier | 2b7c4d1 | 2014-05-19 10:52:16 -0700 | [diff] [blame] | 496 | jobjectArray throws) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 497 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 498 | std::string GetDescriptorForProxy(ObjPtr<mirror::Class> proxy_class) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 499 | REQUIRES_SHARED(Locks::mutator_lock_); |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 500 | |
Mathieu Chartier | c971f6e | 2018-01-14 00:22:04 +0000 | [diff] [blame] | 501 | // Get the oat code for a method when its class isn't yet initialized. |
| 502 | const void* GetQuickOatCodeFor(ArtMethod* method) |
| 503 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 504 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 505 | pid_t GetClassesLockOwner(); // For SignalCatcher. |
| 506 | pid_t GetDexLockOwner(); // For SignalCatcher. |
Brian Carlstrom | 24a3c2e | 2011-10-17 18:07:52 -0700 | [diff] [blame] | 507 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 508 | mirror::Class* GetClassRoot(ClassRoot class_root) REQUIRES_SHARED(Locks::mutator_lock_); |
Jeff Hao | 0aba0ba | 2013-06-03 14:49:28 -0700 | [diff] [blame] | 509 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 510 | static const char* GetClassRootDescriptor(ClassRoot class_root); |
Andreas Gampe | 2da8823 | 2014-02-27 12:26:20 -0800 | [diff] [blame] | 511 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 512 | // Is the given entry point quick code to run the resolution stub? |
| 513 | bool IsQuickResolutionStub(const void* entry_point) const; |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 514 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 515 | // Is the given entry point quick code to bridge into the interpreter? |
| 516 | bool IsQuickToInterpreterBridge(const void* entry_point) const; |
| 517 | |
| 518 | // Is the given entry point quick code to run the generic JNI stub? |
| 519 | bool IsQuickGenericJniStub(const void* entry_point) const; |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 520 | |
David Sehr | a49e053 | 2017-08-25 08:05:29 -0700 | [diff] [blame] | 521 | // Is the given entry point the JNI dlsym lookup stub? |
| 522 | bool IsJniDlsymLookupStub(const void* entry_point) const; |
| 523 | |
Vladimir Marko | 97d7e1c | 2016-10-04 14:44:28 +0100 | [diff] [blame] | 524 | const void* GetQuickToInterpreterBridgeTrampoline() const { |
| 525 | return quick_to_interpreter_bridge_trampoline_; |
| 526 | } |
| 527 | |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 528 | InternTable* GetInternTable() const { |
| 529 | return intern_table_; |
| 530 | } |
| 531 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 532 | // Set the entrypoints up for method to the enter the interpreter. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 533 | void SetEntryPointsToInterpreter(ArtMethod* method) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 534 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 535 | |
Alex Light | db01a09 | 2017-04-03 15:39:55 -0700 | [diff] [blame] | 536 | // Set the entrypoints up for an obsolete method. |
| 537 | void SetEntryPointsForObsoleteMethod(ArtMethod* method) const |
| 538 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 539 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 540 | // Attempts to insert a class into a class table. Returns null if |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 541 | // the class was inserted, otherwise returns an existing class with |
| 542 | // the same descriptor and ClassLoader. |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 543 | mirror::Class* InsertClass(const char* descriptor, ObjPtr<mirror::Class> klass, size_t hash) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 544 | REQUIRES(!Locks::classlinker_classes_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 545 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 546 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 547 | // Add an oat file with .bss GC roots to be visited again at the end of GC |
| 548 | // for collector types that need it. |
| 549 | void WriteBarrierForBootOatFileBssRoots(const OatFile* oat_file) |
| 550 | REQUIRES(!Locks::classlinker_classes_lock_) |
| 551 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 552 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 553 | mirror::ObjectArray<mirror::Class>* GetClassRoots() REQUIRES_SHARED(Locks::mutator_lock_) { |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 554 | mirror::ObjectArray<mirror::Class>* class_roots = class_roots_.Read(); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 555 | DCHECK(class_roots != nullptr); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 556 | return class_roots; |
| 557 | } |
| 558 | |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 559 | // Move the class table to the pre-zygote table to reduce memory usage. This works by ensuring |
| 560 | // that no more classes are ever added to the pre zygote table which makes it that the pages |
| 561 | // always remain shared dirty instead of private dirty. |
| 562 | void MoveClassTableToPreZygote() |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 563 | REQUIRES(!Locks::classlinker_classes_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 564 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 565 | |
Calin Juravle | 7865ac7 | 2017-06-28 11:03:12 -0700 | [diff] [blame] | 566 | // Creates a GlobalRef PathClassLoader or DelegateLastClassLoader (specified by loader_class) |
| 567 | // that can be used to load classes from the given dex files. The parent of the class loader |
| 568 | // will be set to `parent_loader`. If `parent_loader` is null the parent will be |
| 569 | // the boot class loader. |
| 570 | // If class_loader points to a different class than PathClassLoader or DelegateLastClassLoader |
| 571 | // this method will abort. |
Andreas Gampe | 81c6f8d | 2015-03-25 17:19:53 -0700 | [diff] [blame] | 572 | // Note: the objects are not completely set up. Do not use this outside of tests and the compiler. |
Calin Juravle | 7865ac7 | 2017-06-28 11:03:12 -0700 | [diff] [blame] | 573 | jobject CreateWellKnownClassLoader(Thread* self, |
| 574 | const std::vector<const DexFile*>& dex_files, |
| 575 | jclass loader_class, |
| 576 | jobject parent_loader) |
| 577 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 578 | REQUIRES(!Locks::dex_lock_); |
| 579 | |
| 580 | // Calls CreateWellKnownClassLoader(self, |
| 581 | // dex_files, |
| 582 | // WellKnownClasses::dalvik_system_PathClassLoader, |
| 583 | // nullptr) |
Jeff Hao | f0192c8 | 2016-03-28 20:39:50 -0700 | [diff] [blame] | 584 | jobject CreatePathClassLoader(Thread* self, const std::vector<const DexFile*>& dex_files) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 585 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 586 | REQUIRES(!Locks::dex_lock_); |
Andreas Gampe | 81c6f8d | 2015-03-25 17:19:53 -0700 | [diff] [blame] | 587 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 588 | PointerSize GetImagePointerSize() const { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 589 | return image_pointer_size_; |
| 590 | } |
| 591 | |
| 592 | // Used by image writer for checking. |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 593 | bool ClassInClassTable(ObjPtr<mirror::Class> klass) |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 594 | REQUIRES(Locks::classlinker_classes_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 595 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | a89d7ed | 2014-12-05 10:57:13 -0800 | [diff] [blame] | 596 | |
Andreas Gampe | 8ac7595 | 2015-06-02 21:01:45 -0700 | [diff] [blame] | 597 | // Clear the ArrayClass cache. This is necessary when cleaning up for the image, as the cache |
| 598 | // entries are roots, but potentially not image classes. |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 599 | void DropFindArrayClassCache() REQUIRES_SHARED(Locks::mutator_lock_); |
Andreas Gampe | 8ac7595 | 2015-06-02 21:01:45 -0700 | [diff] [blame] | 600 | |
Mathieu Chartier | 951ec2c | 2015-09-22 08:50:05 -0700 | [diff] [blame] | 601 | // Clean up class loaders, this needs to happen after JNI weak globals are cleared. |
| 602 | void CleanupClassLoaders() |
Mathieu Chartier | 00310e0 | 2015-10-17 12:46:42 -0700 | [diff] [blame] | 603 | REQUIRES(!Locks::classlinker_classes_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 604 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 951ec2c | 2015-09-22 08:50:05 -0700 | [diff] [blame] | 605 | |
Mathieu Chartier | 32cc9ee | 2015-10-15 09:19:15 -0700 | [diff] [blame] | 606 | // Unlike GetOrCreateAllocatorForClassLoader, GetAllocatorForClassLoader asserts that the |
| 607 | // allocator for this class loader is already created. |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 608 | LinearAlloc* GetAllocatorForClassLoader(ObjPtr<mirror::ClassLoader> class_loader) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 609 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 951ec2c | 2015-09-22 08:50:05 -0700 | [diff] [blame] | 610 | |
Mathieu Chartier | d57d454 | 2015-10-14 10:55:30 -0700 | [diff] [blame] | 611 | // Return the linear alloc for a class loader if it is already allocated, otherwise allocate and |
| 612 | // set it. TODO: Consider using a lock other than classlinker_classes_lock_. |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 613 | LinearAlloc* GetOrCreateAllocatorForClassLoader(ObjPtr<mirror::ClassLoader> class_loader) |
Mathieu Chartier | 00310e0 | 2015-10-17 12:46:42 -0700 | [diff] [blame] | 614 | REQUIRES(!Locks::classlinker_classes_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 615 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 00310e0 | 2015-10-17 12:46:42 -0700 | [diff] [blame] | 616 | |
Mathieu Chartier | 6d25cf6 | 2016-04-12 16:54:48 -0700 | [diff] [blame] | 617 | // May be called with null class_loader due to legacy code. b/27954959 |
Mathieu Chartier | bc5a795 | 2016-10-17 15:46:31 -0700 | [diff] [blame] | 618 | void InsertDexFileInToClassLoader(ObjPtr<mirror::Object> dex_file, |
| 619 | ObjPtr<mirror::ClassLoader> class_loader) |
Mathieu Chartier | 00310e0 | 2015-10-17 12:46:42 -0700 | [diff] [blame] | 620 | REQUIRES(!Locks::classlinker_classes_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 621 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | d57d454 | 2015-10-14 10:55:30 -0700 | [diff] [blame] | 622 | |
Tamas Berghammer | dd5e5e9 | 2016-02-12 16:29:00 +0000 | [diff] [blame] | 623 | static bool ShouldUseInterpreterEntrypoint(ArtMethod* method, const void* quick_code) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 624 | REQUIRES_SHARED(Locks::mutator_lock_); |
Tamas Berghammer | dd5e5e9 | 2016-02-12 16:29:00 +0000 | [diff] [blame] | 625 | |
Mathieu Chartier | c5dd319 | 2015-12-09 16:38:30 -0800 | [diff] [blame] | 626 | std::set<DexCacheResolvedClasses> GetResolvedClasses(bool ignore_boot_classes) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 627 | REQUIRES(!Locks::dex_lock_); |
Mathieu Chartier | c5dd319 | 2015-12-09 16:38:30 -0800 | [diff] [blame] | 628 | |
Jeff Hao | f0192c8 | 2016-03-28 20:39:50 -0700 | [diff] [blame] | 629 | static bool IsBootClassLoader(ScopedObjectAccessAlreadyRunnable& soa, |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 630 | ObjPtr<mirror::ClassLoader> class_loader) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 631 | REQUIRES_SHARED(Locks::mutator_lock_); |
Jeff Hao | f0192c8 | 2016-03-28 20:39:50 -0700 | [diff] [blame] | 632 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 633 | ArtMethod* AddMethodToConflictTable(ObjPtr<mirror::Class> klass, |
Mathieu Chartier | 7f98c9a | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 634 | ArtMethod* conflict_method, |
| 635 | ArtMethod* interface_method, |
| 636 | ArtMethod* method, |
| 637 | bool force_new_conflict_method) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 638 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 7f98c9a | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 639 | |
Mathieu Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 640 | // Create a conflict table with a specified capacity. |
| 641 | ImtConflictTable* CreateImtConflictTable(size_t count, LinearAlloc* linear_alloc); |
| 642 | |
| 643 | // Static version for when the class linker is not yet created. |
| 644 | static ImtConflictTable* CreateImtConflictTable(size_t count, |
| 645 | LinearAlloc* linear_alloc, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 646 | PointerSize pointer_size); |
Mathieu Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 647 | |
| 648 | |
| 649 | // Create the IMT and conflict tables for a class. |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 650 | void FillIMTAndConflictTables(ObjPtr<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 651 | |
Mathieu Chartier | 72041a0 | 2017-07-14 18:23:25 -0700 | [diff] [blame] | 652 | // Visit all of the class tables. This is used by dex2oat to allow pruning dex caches. |
| 653 | template <class Visitor> |
| 654 | void VisitClassTables(const Visitor& visitor) |
Mathieu Chartier | 696632e | 2016-06-03 17:47:32 -0700 | [diff] [blame] | 655 | REQUIRES(!Locks::classlinker_classes_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 656 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 657 | |
Jeff Hao | c92a7a1 | 2016-06-06 11:09:20 -0700 | [diff] [blame] | 658 | // Throw the class initialization failure recorded when first trying to initialize the given |
| 659 | // class. |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 660 | void ThrowEarlierClassFailure(ObjPtr<mirror::Class> c, bool wrap_in_no_class_def = false) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 661 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 662 | REQUIRES(!Locks::dex_lock_); |
Jeff Hao | c92a7a1 | 2016-06-06 11:09:20 -0700 | [diff] [blame] | 663 | |
Mathieu Chartier | 6597577 | 2016-08-05 10:46:36 -0700 | [diff] [blame] | 664 | // Get the actual holding class for a copied method. Pretty slow, don't call often. |
| 665 | mirror::Class* GetHoldingClassOfCopiedMethod(ArtMethod* method) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 666 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 6597577 | 2016-08-05 10:46:36 -0700 | [diff] [blame] | 667 | |
Andreas Gampe | 70f1639 | 2017-01-16 14:20:10 -0800 | [diff] [blame] | 668 | // Returns null if not found. |
Andreas Gampe | 2af9902 | 2017-04-25 08:32:59 -0700 | [diff] [blame] | 669 | // This returns a pointer to the class-table, without requiring any locking - including the |
| 670 | // boot class-table. It is the caller's responsibility to access this under lock, if required. |
Andreas Gampe | 70f1639 | 2017-01-16 14:20:10 -0800 | [diff] [blame] | 671 | ClassTable* ClassTableForClassLoader(ObjPtr<mirror::ClassLoader> class_loader) |
Andreas Gampe | 2af9902 | 2017-04-25 08:32:59 -0700 | [diff] [blame] | 672 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 673 | NO_THREAD_SAFETY_ANALYSIS; |
Andreas Gampe | 70f1639 | 2017-01-16 14:20:10 -0800 | [diff] [blame] | 674 | |
Andreas Gampe | ce7732b | 2017-01-17 15:50:26 -0800 | [diff] [blame] | 675 | void AppendToBootClassPath(Thread* self, const DexFile& dex_file) |
| 676 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 677 | REQUIRES(!Locks::dex_lock_); |
| 678 | |
Mathieu Chartier | 06bed30 | 2017-07-13 13:23:18 -0700 | [diff] [blame] | 679 | // Visit all of the class loaders in the class linker. |
| 680 | void VisitClassLoaders(ClassLoaderVisitor* visitor) const |
| 681 | REQUIRES_SHARED(Locks::classlinker_classes_lock_, Locks::mutator_lock_); |
| 682 | |
Jeff Hao | 0cb1728 | 2017-07-12 14:51:49 -0700 | [diff] [blame] | 683 | // Checks that a class and its superclass from another class loader have the same virtual methods. |
| 684 | bool ValidateSuperClassDescriptors(Handle<mirror::Class> klass) |
| 685 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 686 | |
Andreas Gampe | c1ac9ee | 2017-07-24 22:35:49 -0700 | [diff] [blame] | 687 | ClassHierarchyAnalysis* GetClassHierarchyAnalysis() { |
| 688 | return cha_.get(); |
| 689 | } |
| 690 | |
Hiroshi Yamauchi | 04302db | 2015-11-11 23:45:34 -0800 | [diff] [blame] | 691 | struct DexCacheData { |
Vladimir Marko | cd556b0 | 2017-02-03 11:47:34 +0000 | [diff] [blame] | 692 | // Construct an invalid data object. |
| 693 | DexCacheData() |
| 694 | : weak_root(nullptr), |
| 695 | dex_file(nullptr), |
Vladimir Marko | cd556b0 | 2017-02-03 11:47:34 +0000 | [diff] [blame] | 696 | class_table(nullptr) { } |
| 697 | |
| 698 | // Check if the data is valid. |
| 699 | bool IsValid() const { |
| 700 | return dex_file != nullptr; |
| 701 | } |
| 702 | |
Hiroshi Yamauchi | 04302db | 2015-11-11 23:45:34 -0800 | [diff] [blame] | 703 | // Weak root to the DexCache. Note: Do not decode this unnecessarily or else class unloading may |
| 704 | // not work properly. |
| 705 | jweak weak_root; |
Vladimir Marko | d1ee20f | 2017-08-17 09:21:16 +0000 | [diff] [blame] | 706 | // The following field caches the DexCache's field here to avoid unnecessary jweak decode that |
| 707 | // triggers read barriers (and marks them alive unnecessarily and messes with class unloading.) |
Hiroshi Yamauchi | 04302db | 2015-11-11 23:45:34 -0800 | [diff] [blame] | 708 | const DexFile* dex_file; |
Vladimir Marko | cd556b0 | 2017-02-03 11:47:34 +0000 | [diff] [blame] | 709 | // Identify the associated class loader's class table. This is used to make sure that |
| 710 | // the Java call to native DexCache.setResolvedType() inserts the resolved type in that |
| 711 | // class table. It is also used to make sure we don't register the same dex cache with |
| 712 | // multiple class loaders. |
| 713 | ClassTable* class_table; |
Hiroshi Yamauchi | 04302db | 2015-11-11 23:45:34 -0800 | [diff] [blame] | 714 | }; |
| 715 | |
Chang Xing | 605fe24 | 2017-07-20 15:57:21 -0700 | [diff] [blame] | 716 | protected: |
| 717 | virtual bool InitializeClass(Thread* self, |
| 718 | Handle<mirror::Class> klass, |
| 719 | bool can_run_clinit, |
| 720 | bool can_init_parents) |
| 721 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 722 | REQUIRES(!Locks::dex_lock_); |
| 723 | |
Mathieu Chartier | 9e050df | 2017-08-09 10:05:47 -0700 | [diff] [blame] | 724 | virtual verifier::FailureKind PerformClassVerification(Thread* self, |
| 725 | Handle<mirror::Class> klass, |
| 726 | verifier::HardFailLogMode log_level, |
| 727 | std::string* error_msg) |
| 728 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 729 | |
Mathieu Chartier | 951ec2c | 2015-09-22 08:50:05 -0700 | [diff] [blame] | 730 | private: |
Vladimir Marko | 921094a | 2017-01-12 18:37:06 +0000 | [diff] [blame] | 731 | class LinkInterfaceMethodsHelper; |
| 732 | |
Mathieu Chartier | 951ec2c | 2015-09-22 08:50:05 -0700 | [diff] [blame] | 733 | struct ClassLoaderData { |
Mathieu Chartier | c3fcd41 | 2015-09-25 16:54:59 -0700 | [diff] [blame] | 734 | jweak weak_root; // Weak root to enable class unloading. |
Mathieu Chartier | 951ec2c | 2015-09-22 08:50:05 -0700 | [diff] [blame] | 735 | ClassTable* class_table; |
| 736 | LinearAlloc* allocator; |
| 737 | }; |
| 738 | |
Alex Light | f1f1049 | 2015-10-07 16:08:36 -0700 | [diff] [blame] | 739 | // Ensures that the supertype of 'klass' ('supertype') is verified. Returns false and throws |
| 740 | // appropriate exceptions if verification failed hard. Returns true for successful verification or |
| 741 | // soft-failures. |
| 742 | bool AttemptSupertypeVerification(Thread* self, |
| 743 | Handle<mirror::Class> klass, |
| 744 | Handle<mirror::Class> supertype) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 745 | REQUIRES(!Locks::dex_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 746 | REQUIRES_SHARED(Locks::mutator_lock_); |
Alex Light | f1f1049 | 2015-10-07 16:08:36 -0700 | [diff] [blame] | 747 | |
Andreas Gampe | c1ac9ee | 2017-07-24 22:35:49 -0700 | [diff] [blame] | 748 | void DeleteClassLoader(Thread* self, const ClassLoaderData& data) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 749 | REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 1dad3f6 | 2015-10-23 14:59:54 +0100 | [diff] [blame] | 750 | |
Mathieu Chartier | e0671ce | 2015-07-28 17:23:28 -0700 | [diff] [blame] | 751 | void VisitClassesInternal(ClassVisitor* visitor) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 752 | REQUIRES_SHARED(Locks::classlinker_classes_lock_, Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 753 | |
| 754 | // Returns the number of zygote and image classes. |
Mathieu Chartier | 6b06953 | 2015-08-05 15:08:12 -0700 | [diff] [blame] | 755 | size_t NumZygoteClasses() const |
| 756 | REQUIRES(Locks::classlinker_classes_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 757 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 758 | |
| 759 | // Returns the number of non zygote nor image classes. |
Mathieu Chartier | 6b06953 | 2015-08-05 15:08:12 -0700 | [diff] [blame] | 760 | size_t NumNonZygoteClasses() const |
| 761 | REQUIRES(Locks::classlinker_classes_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 762 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 763 | |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 764 | void FinishInit(Thread* self) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 765 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 766 | REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 767 | |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 768 | // For early bootstrapping by Init |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 769 | mirror::Class* AllocClass(Thread* self, |
| 770 | ObjPtr<mirror::Class> java_lang_Class, |
| 771 | uint32_t class_size) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 772 | REQUIRES_SHARED(Locks::mutator_lock_) |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 773 | REQUIRES(!Roles::uninterruptible_); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 774 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 775 | // Alloc* convenience functions to avoid needing to pass in mirror::Class* |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 776 | // values that are known to the ClassLinker such as |
| 777 | // kObjectArrayClass and kJavaLangString etc. |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 778 | mirror::Class* AllocClass(Thread* self, uint32_t class_size) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 779 | REQUIRES_SHARED(Locks::mutator_lock_) |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 780 | REQUIRES(!Roles::uninterruptible_); |
Mathieu Chartier | 6c60d84 | 2016-09-15 10:24:43 -0700 | [diff] [blame] | 781 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 782 | mirror::DexCache* AllocDexCache(ObjPtr<mirror::String>* out_location, |
Mathieu Chartier | 6c60d84 | 2016-09-15 10:24:43 -0700 | [diff] [blame] | 783 | Thread* self, |
| 784 | const DexFile& dex_file) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 785 | REQUIRES_SHARED(Locks::mutator_lock_) |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 786 | REQUIRES(!Roles::uninterruptible_); |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 787 | |
Mathieu Chartier | 6c60d84 | 2016-09-15 10:24:43 -0700 | [diff] [blame] | 788 | // Used for tests and AppendToBootClassPath. |
| 789 | mirror::DexCache* AllocAndInitializeDexCache(Thread* self, |
| 790 | const DexFile& dex_file, |
| 791 | LinearAlloc* linear_alloc) |
| 792 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 793 | REQUIRES(!Locks::dex_lock_) |
Mathieu Chartier | 6c60d84 | 2016-09-15 10:24:43 -0700 | [diff] [blame] | 794 | REQUIRES(!Roles::uninterruptible_); |
| 795 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 796 | mirror::Class* CreatePrimitiveClass(Thread* self, Primitive::Type type) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 797 | REQUIRES_SHARED(Locks::mutator_lock_) |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 798 | REQUIRES(!Roles::uninterruptible_); |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 799 | mirror::Class* InitializePrimitiveClass(ObjPtr<mirror::Class> primitive_class, |
| 800 | Primitive::Type type) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 801 | REQUIRES_SHARED(Locks::mutator_lock_) |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 802 | REQUIRES(!Roles::uninterruptible_); |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 803 | |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 804 | mirror::Class* CreateArrayClass(Thread* self, |
| 805 | const char* descriptor, |
| 806 | size_t hash, |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 807 | Handle<mirror::ClassLoader> class_loader) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 808 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 809 | REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 810 | |
Vladimir Marko | cd556b0 | 2017-02-03 11:47:34 +0000 | [diff] [blame] | 811 | void AppendToBootClassPath(const DexFile& dex_file, ObjPtr<mirror::DexCache> dex_cache) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 812 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 813 | REQUIRES(!Locks::dex_lock_); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 814 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 815 | // Precomputes size needed for Class, in the case of a non-temporary class this size must be |
| 816 | // sufficient to hold all static fields. |
| 817 | uint32_t SizeOfClassWithoutEmbeddedTables(const DexFile& dex_file, |
| 818 | const DexFile::ClassDef& dex_class_def); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 819 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 820 | // Setup the classloader, class def index, type idx so that we can insert this class in the class |
| 821 | // table. |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 822 | void SetupClass(const DexFile& dex_file, |
| 823 | const DexFile::ClassDef& dex_class_def, |
| 824 | Handle<mirror::Class> klass, |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 825 | ObjPtr<mirror::ClassLoader> class_loader) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 826 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 827 | |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 828 | void LoadClass(Thread* self, |
| 829 | const DexFile& dex_file, |
| 830 | const DexFile::ClassDef& dex_class_def, |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 831 | Handle<mirror::Class> klass) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 832 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 833 | void LoadClassMembers(Thread* self, |
| 834 | const DexFile& dex_file, |
| 835 | const uint8_t* class_data, |
Vladimir Marko | 97d7e1c | 2016-10-04 14:44:28 +0100 | [diff] [blame] | 836 | Handle<mirror::Class> klass) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 837 | REQUIRES_SHARED(Locks::mutator_lock_); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 838 | |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 839 | void LoadField(const ClassDataItemIterator& it, Handle<mirror::Class> klass, ArtField* dst) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 840 | REQUIRES_SHARED(Locks::mutator_lock_); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 841 | |
Mathieu Chartier | 268764d | 2016-09-13 12:09:38 -0700 | [diff] [blame] | 842 | void LoadMethod(const DexFile& dex_file, |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 843 | const ClassDataItemIterator& it, |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 844 | Handle<mirror::Class> klass, ArtMethod* dst) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 845 | REQUIRES_SHARED(Locks::mutator_lock_); |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 846 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 847 | void FixupStaticTrampolines(ObjPtr<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 848 | |
Nicolas Geoffray | 7d8d8ff | 2016-11-02 12:38:05 +0000 | [diff] [blame] | 849 | // Finds a class in a Path- or DexClassLoader, loading it if necessary without using JNI. Hash |
Andreas Gampe | 34ee684 | 2014-12-02 15:43:52 -0800 | [diff] [blame] | 850 | // function is supposed to be ComputeModifiedUtf8Hash(descriptor). Returns true if the |
| 851 | // class-loader chain could be handled, false otherwise, i.e., a non-supported class-loader |
| 852 | // was encountered while walking the parent chain (currently only BootClassLoader and |
| 853 | // PathClassLoader are supported). |
Nicolas Geoffray | 7d8d8ff | 2016-11-02 12:38:05 +0000 | [diff] [blame] | 854 | bool FindClassInBaseDexClassLoader(ScopedObjectAccessAlreadyRunnable& soa, |
| 855 | Thread* self, |
| 856 | const char* descriptor, |
| 857 | size_t hash, |
| 858 | Handle<mirror::ClassLoader> class_loader, |
| 859 | ObjPtr<mirror::Class>* result) |
Andreas Gampe | 34ee684 | 2014-12-02 15:43:52 -0800 | [diff] [blame] | 860 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 861 | REQUIRES(!Locks::dex_lock_); |
Andreas Gampe | 34ee684 | 2014-12-02 15:43:52 -0800 | [diff] [blame] | 862 | |
Calin Juravle | 415dc3d | 2017-06-28 11:03:12 -0700 | [diff] [blame] | 863 | // Finds the class in the classpath of the given class loader. It only searches the class loader |
| 864 | // dex files and does not recurse into its parent. |
| 865 | // The method checks that the provided class loader is either a PathClassLoader or a |
| 866 | // DexClassLoader. |
| 867 | // If the class is found the method returns the resolved class. Otherwise it returns null. |
| 868 | ObjPtr<mirror::Class> FindClassInBaseDexClassLoaderClassPath( |
| 869 | ScopedObjectAccessAlreadyRunnable& soa, |
| 870 | const char* descriptor, |
| 871 | size_t hash, |
| 872 | Handle<mirror::ClassLoader> class_loader) |
| 873 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 874 | REQUIRES(!Locks::dex_lock_); |
| 875 | |
| 876 | // Finds the class in the boot class loader. |
| 877 | // If the class is found the method returns the resolved class. Otherwise it returns null. |
| 878 | ObjPtr<mirror::Class> FindClassInBootClassLoaderClassPath(Thread* self, |
| 879 | const char* descriptor, |
| 880 | size_t hash) |
| 881 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 882 | REQUIRES(!Locks::dex_lock_); |
| 883 | |
Vladimir Marko | 666ee3d | 2017-12-11 18:37:36 +0000 | [diff] [blame] | 884 | // Implementation of LookupResolvedType() called when the type was not found in the dex cache. |
| 885 | ObjPtr<mirror::Class> DoLookupResolvedType(dex::TypeIndex type_idx, |
| 886 | ObjPtr<mirror::DexCache> dex_cache, |
| 887 | ObjPtr<mirror::ClassLoader> class_loader) |
| 888 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 889 | |
| 890 | // Implementation of ResolveType() called when the type was not found in the dex cache. |
| 891 | ObjPtr<mirror::Class> DoResolveType(dex::TypeIndex type_idx, |
| 892 | Handle<mirror::DexCache> dex_cache, |
| 893 | Handle<mirror::ClassLoader> class_loader) |
| 894 | REQUIRES_SHARED(Locks::mutator_lock_) |
| 895 | REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); |
| 896 | |
Andreas Gampe | 34ee684 | 2014-12-02 15:43:52 -0800 | [diff] [blame] | 897 | // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded |
| 898 | // by the given 'class_loader'. Uses the provided hash for the descriptor. |
| 899 | mirror::Class* LookupClass(Thread* self, |
| 900 | const char* descriptor, |
| 901 | size_t hash, |
| 902 | ObjPtr<mirror::ClassLoader> class_loader) |
| 903 | REQUIRES(!Locks::classlinker_classes_lock_) |
| 904 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 905 | |
Vladimir Marko | f44d36c | 2017-03-14 14:18:46 +0000 | [diff] [blame] | 906 | // Find a field by its field index. |
| 907 | ArtField* LookupResolvedField(uint32_t field_idx, |
| 908 | ObjPtr<mirror::DexCache> dex_cache, |
| 909 | ObjPtr<mirror::ClassLoader> class_loader, |
| 910 | bool is_static) |
| 911 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 912 | |
Vladimir Marko | cd556b0 | 2017-02-03 11:47:34 +0000 | [diff] [blame] | 913 | void RegisterDexFileLocked(const DexFile& dex_file, |
| 914 | ObjPtr<mirror::DexCache> dex_cache, |
| 915 | ObjPtr<mirror::ClassLoader> class_loader) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 916 | REQUIRES(Locks::dex_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 917 | REQUIRES_SHARED(Locks::mutator_lock_); |
Vladimir Marko | cd556b0 | 2017-02-03 11:47:34 +0000 | [diff] [blame] | 918 | DexCacheData FindDexCacheDataLocked(const DexFile& dex_file) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 919 | REQUIRES(Locks::dex_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 920 | REQUIRES_SHARED(Locks::mutator_lock_); |
Vladimir Marko | cd556b0 | 2017-02-03 11:47:34 +0000 | [diff] [blame] | 921 | static ObjPtr<mirror::DexCache> DecodeDexCache(Thread* self, const DexCacheData& data) |
| 922 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 923 | // Called to ensure that the dex cache has been registered with the same class loader. |
| 924 | // If yes, returns the dex cache, otherwise throws InternalError and returns null. |
| 925 | ObjPtr<mirror::DexCache> EnsureSameClassLoader(Thread* self, |
| 926 | ObjPtr<mirror::DexCache> dex_cache, |
| 927 | const DexCacheData& data, |
| 928 | ObjPtr<mirror::ClassLoader> class_loader) |
| 929 | REQUIRES(!Locks::dex_lock_) |
| 930 | REQUIRES_SHARED(Locks::mutator_lock_); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 931 | |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 932 | bool InitializeDefaultInterfaceRecursive(Thread* self, |
| 933 | Handle<mirror::Class> klass, |
| 934 | bool can_run_clinit, |
| 935 | bool can_init_parents) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 936 | REQUIRES(!Locks::dex_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 937 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 938 | bool WaitForInitializeClass(Handle<mirror::Class> klass, |
| 939 | Thread* self, |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 940 | ObjectLock<mirror::Class>& lock); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 941 | |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 942 | bool IsSameDescriptorInDifferentClassContexts(Thread* self, |
| 943 | const char* descriptor, |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 944 | Handle<mirror::ClassLoader> class_loader1, |
| 945 | Handle<mirror::ClassLoader> class_loader2) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 946 | REQUIRES_SHARED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 947 | |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 948 | bool IsSameMethodSignatureInDifferentClassContexts(Thread* self, |
| 949 | ArtMethod* method, |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 950 | ObjPtr<mirror::Class> klass1, |
| 951 | ObjPtr<mirror::Class> klass2) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 952 | REQUIRES_SHARED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 953 | |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 954 | bool LinkClass(Thread* self, |
| 955 | const char* descriptor, |
| 956 | Handle<mirror::Class> klass, |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 957 | Handle<mirror::ObjectArray<mirror::Class>> interfaces, |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 958 | MutableHandle<mirror::Class>* h_new_class_out) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 959 | REQUIRES_SHARED(Locks::mutator_lock_) |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 960 | REQUIRES(!Locks::classlinker_classes_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 961 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 962 | bool LinkSuperClass(Handle<mirror::Class> klass) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 963 | REQUIRES_SHARED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 964 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 965 | bool LoadSuperAndInterfaces(Handle<mirror::Class> klass, const DexFile& dex_file) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 966 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 967 | REQUIRES(!Locks::dex_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 968 | |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 969 | bool LinkMethods(Thread* self, |
| 970 | Handle<mirror::Class> klass, |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 971 | Handle<mirror::ObjectArray<mirror::Class>> interfaces, |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 972 | bool* out_new_conflict, |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 973 | ArtMethod** out_imt) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 974 | REQUIRES_SHARED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 975 | |
Orion Hodson | f8db2c3 | 2017-07-07 20:07:12 +0100 | [diff] [blame] | 976 | mirror::MethodHandle* ResolveMethodHandleForField(Thread* self, |
| 977 | const DexFile::MethodHandleItem& method_handle, |
| 978 | ArtMethod* referrer) |
| 979 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 980 | |
| 981 | mirror::MethodHandle* ResolveMethodHandleForMethod(Thread* self, |
| 982 | const DexFile* const dex_file, |
| 983 | const DexFile::MethodHandleItem& method_handle, |
| 984 | ArtMethod* referrer) |
| 985 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 986 | |
Alex Light | 9139e00 | 2015-10-09 15:59:48 -0700 | [diff] [blame] | 987 | // A wrapper class representing the result of a method translation used for linking methods and |
| 988 | // updating superclass default methods. For each method in a classes vtable there are 4 states it |
| 989 | // could be in: |
| 990 | // 1) No translation is necessary. In this case there is no MethodTranslation object for it. This |
| 991 | // is the standard case and is true when the method is not overridable by a default method, |
| 992 | // the class defines a concrete implementation of the method, the default method implementation |
| 993 | // remains the same, or an abstract method stayed abstract. |
| 994 | // 2) The method must be translated to a different default method. We note this with |
| 995 | // CreateTranslatedMethod. |
| 996 | // 3) The method must be replaced with a conflict method. This happens when a superclass |
| 997 | // implements an interface with a default method and this class implements an unrelated |
| 998 | // interface that also defines that default method. We note this with CreateConflictingMethod. |
| 999 | // 4) The method must be replaced with an abstract miranda method. This happens when a superclass |
| 1000 | // implements an interface with a default method and this class implements a subinterface of |
| 1001 | // the superclass's interface which declares the default method abstract. We note this with |
| 1002 | // CreateAbstractMethod. |
| 1003 | // |
| 1004 | // When a method translation is unnecessary (case #1), we don't put it into the |
| 1005 | // default_translation maps. So an instance of MethodTranslation must be in one of #2-#4. |
| 1006 | class MethodTranslation { |
| 1007 | public: |
| 1008 | // This slot must become a default conflict method. |
| 1009 | static MethodTranslation CreateConflictingMethod() { |
| 1010 | return MethodTranslation(Type::kConflict, /*translation*/nullptr); |
| 1011 | } |
| 1012 | |
| 1013 | // This slot must become an abstract method. |
| 1014 | static MethodTranslation CreateAbstractMethod() { |
| 1015 | return MethodTranslation(Type::kAbstract, /*translation*/nullptr); |
| 1016 | } |
| 1017 | |
| 1018 | // Use the given method as the current value for this vtable slot during translation. |
| 1019 | static MethodTranslation CreateTranslatedMethod(ArtMethod* new_method) { |
| 1020 | return MethodTranslation(Type::kTranslation, new_method); |
| 1021 | } |
| 1022 | |
| 1023 | // Returns true if this is a method that must become a conflict method. |
| 1024 | bool IsInConflict() const { |
| 1025 | return type_ == Type::kConflict; |
| 1026 | } |
| 1027 | |
| 1028 | // Returns true if this is a method that must become an abstract method. |
| 1029 | bool IsAbstract() const { |
| 1030 | return type_ == Type::kAbstract; |
| 1031 | } |
| 1032 | |
| 1033 | // Returns true if this is a method that must become a different method. |
| 1034 | bool IsTranslation() const { |
| 1035 | return type_ == Type::kTranslation; |
| 1036 | } |
| 1037 | |
| 1038 | // Get the translated version of this method. |
| 1039 | ArtMethod* GetTranslation() const { |
| 1040 | DCHECK(IsTranslation()); |
| 1041 | DCHECK(translation_ != nullptr); |
| 1042 | return translation_; |
| 1043 | } |
| 1044 | |
| 1045 | private: |
| 1046 | enum class Type { |
| 1047 | kTranslation, |
| 1048 | kConflict, |
| 1049 | kAbstract, |
| 1050 | }; |
| 1051 | |
| 1052 | MethodTranslation(Type type, ArtMethod* translation) |
| 1053 | : translation_(translation), type_(type) {} |
| 1054 | |
| 1055 | ArtMethod* const translation_; |
| 1056 | const Type type_; |
| 1057 | }; |
| 1058 | |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 1059 | // Links the virtual methods for the given class and records any default methods that will need to |
| 1060 | // be updated later. |
| 1061 | // |
| 1062 | // Arguments: |
| 1063 | // * self - The current thread. |
| 1064 | // * klass - class, whose vtable will be filled in. |
| 1065 | // * default_translations - Vtable index to new method map. |
| 1066 | // Any vtable entries that need to be updated with new default methods |
| 1067 | // are stored into the default_translations map. The default_translations |
| 1068 | // map is keyed on the vtable index that needs to be updated. We use this |
| 1069 | // map because if we override a default method with another default |
| 1070 | // method we need to update the vtable to point to the new method. |
| 1071 | // Unfortunately since we copy the ArtMethod* we cannot just do a simple |
| 1072 | // scan, we therefore store the vtable index's that might need to be |
| 1073 | // updated with the method they will turn into. |
| 1074 | // TODO This whole default_translations thing is very dirty. There should be a better way. |
Alex Light | 9139e00 | 2015-10-09 15:59:48 -0700 | [diff] [blame] | 1075 | bool LinkVirtualMethods( |
| 1076 | Thread* self, |
| 1077 | Handle<mirror::Class> klass, |
| 1078 | /*out*/std::unordered_map<size_t, MethodTranslation>* default_translations) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1079 | REQUIRES_SHARED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1080 | |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 1081 | // Sets up the interface lookup table (IFTable) in the correct order to allow searching for |
| 1082 | // default methods. |
| 1083 | bool SetupInterfaceLookupTable(Thread* self, |
| 1084 | Handle<mirror::Class> klass, |
| 1085 | Handle<mirror::ObjectArray<mirror::Class>> interfaces) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1086 | REQUIRES_SHARED(Locks::mutator_lock_); |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 1087 | |
Alex Light | 9139e00 | 2015-10-09 15:59:48 -0700 | [diff] [blame] | 1088 | |
| 1089 | enum class DefaultMethodSearchResult { |
| 1090 | kDefaultFound, |
| 1091 | kAbstractFound, |
| 1092 | kDefaultConflict |
| 1093 | }; |
| 1094 | |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 1095 | // Find the default method implementation for 'interface_method' in 'klass', if one exists. |
| 1096 | // |
| 1097 | // Arguments: |
| 1098 | // * self - The current thread. |
| 1099 | // * target_method - The method we are trying to find a default implementation for. |
| 1100 | // * klass - The class we are searching for a definition of target_method. |
| 1101 | // * out_default_method - The pointer we will store the found default method to on success. |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 1102 | // |
| 1103 | // Return value: |
Alex Light | 9139e00 | 2015-10-09 15:59:48 -0700 | [diff] [blame] | 1104 | // * kDefaultFound - There were no conflicting method implementations found in the class while |
| 1105 | // searching for target_method. The default method implementation is stored into |
| 1106 | // out_default_method. |
| 1107 | // * kAbstractFound - There were no conflicting method implementations found in the class while |
| 1108 | // searching for target_method but no default implementation was found either. |
| 1109 | // out_default_method is set to null and the method should be considered not |
| 1110 | // implemented. |
| 1111 | // * kDefaultConflict - Conflicting method implementations were found when searching for |
| 1112 | // target_method. The value of *out_default_method is null. |
| 1113 | DefaultMethodSearchResult FindDefaultMethodImplementation( |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 1114 | Thread* self, |
| 1115 | ArtMethod* target_method, |
| 1116 | Handle<mirror::Class> klass, |
| 1117 | /*out*/ArtMethod** out_default_method) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1118 | REQUIRES_SHARED(Locks::mutator_lock_); |
Alex Light | eb7c144 | 2015-08-31 13:17:42 -0700 | [diff] [blame] | 1119 | |
| 1120 | // Sets the imt entries and fixes up the vtable for the given class by linking all the interface |
| 1121 | // methods. See LinkVirtualMethods for an explanation of what default_translations is. |
Alex Light | 9139e00 | 2015-10-09 15:59:48 -0700 | [diff] [blame] | 1122 | bool LinkInterfaceMethods( |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 1123 | Thread* self, |
| 1124 | Handle<mirror::Class> klass, |
| 1125 | const std::unordered_map<size_t, MethodTranslation>& default_translations, |
| 1126 | bool* out_new_conflict, |
| 1127 | ArtMethod** out_imt) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1128 | REQUIRES_SHARED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1129 | |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 1130 | bool LinkStaticFields(Thread* self, Handle<mirror::Class> klass, size_t* class_size) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1131 | REQUIRES_SHARED(Locks::mutator_lock_); |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 1132 | bool LinkInstanceFields(Thread* self, Handle<mirror::Class> klass) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1133 | REQUIRES_SHARED(Locks::mutator_lock_); |
Igor Murashkin | b1d8c31 | 2015-08-04 11:18:43 -0700 | [diff] [blame] | 1134 | bool LinkFields(Thread* self, Handle<mirror::Class> klass, bool is_static, size_t* class_size) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1135 | REQUIRES_SHARED(Locks::mutator_lock_); |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 1136 | void CreateReferenceInstanceOffsets(Handle<mirror::Class> klass) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1137 | REQUIRES_SHARED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1138 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1139 | void CheckProxyConstructor(ArtMethod* constructor) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1140 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1141 | void CheckProxyMethod(ArtMethod* method, ArtMethod* prototype) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1142 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1143 | |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 1144 | size_t GetDexCacheCount() REQUIRES_SHARED(Locks::mutator_lock_, Locks::dex_lock_) { |
Hiroshi Yamauchi | e9e3e69 | 2014-06-24 14:31:37 -0700 | [diff] [blame] | 1145 | return dex_caches_.size(); |
| 1146 | } |
Hiroshi Yamauchi | 04302db | 2015-11-11 23:45:34 -0800 | [diff] [blame] | 1147 | const std::list<DexCacheData>& GetDexCachesData() |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 1148 | REQUIRES_SHARED(Locks::mutator_lock_, Locks::dex_lock_) { |
Mathieu Chartier | 673ed3d | 2015-08-28 14:56:43 -0700 | [diff] [blame] | 1149 | return dex_caches_; |
| 1150 | } |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 1151 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1152 | void CreateProxyConstructor(Handle<mirror::Class> klass, ArtMethod* out) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1153 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1154 | void CreateProxyMethod(Handle<mirror::Class> klass, ArtMethod* prototype, ArtMethod* out) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1155 | REQUIRES_SHARED(Locks::mutator_lock_); |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 1156 | |
Mathieu Chartier | 5b83050 | 2016-03-02 10:30:23 -0800 | [diff] [blame] | 1157 | // Register a class loader and create its class table and allocator. Should not be called if |
| 1158 | // these are already created. |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 1159 | void RegisterClassLoader(ObjPtr<mirror::ClassLoader> class_loader) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1160 | REQUIRES_SHARED(Locks::mutator_lock_) |
Mathieu Chartier | 5b83050 | 2016-03-02 10:30:23 -0800 | [diff] [blame] | 1161 | REQUIRES(Locks::classlinker_classes_lock_); |
| 1162 | |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 1163 | // Insert a new class table if not found. |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 1164 | ClassTable* InsertClassTableForClassLoader(ObjPtr<mirror::ClassLoader> class_loader) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1165 | REQUIRES_SHARED(Locks::mutator_lock_) |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 1166 | REQUIRES(Locks::classlinker_classes_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 1167 | |
Ian Rogers | dbf3be0 | 2014-08-29 15:40:08 -0700 | [diff] [blame] | 1168 | // EnsureResolved is called to make sure that a class in the class_table_ has been resolved |
| 1169 | // before returning it to the caller. Its the responsibility of the thread that placed the class |
| 1170 | // in the table to make it resolved. The thread doing resolution must notify on the class' lock |
| 1171 | // when resolution has occurred. This happens in mirror::Class::SetStatus. As resolution may |
| 1172 | // retire a class, the version of the class in the table is returned and this may differ from |
| 1173 | // the class passed in. |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 1174 | mirror::Class* EnsureResolved(Thread* self, const char* descriptor, ObjPtr<mirror::Class> klass) |
Mathieu Chartier | c77f3ab | 2015-09-03 19:41:50 -0700 | [diff] [blame] | 1175 | WARN_UNUSED |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1176 | REQUIRES_SHARED(Locks::mutator_lock_) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 1177 | REQUIRES(!Locks::dex_lock_); |
Ian Rogers | dbf3be0 | 2014-08-29 15:40:08 -0700 | [diff] [blame] | 1178 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 1179 | void FixupTemporaryDeclaringClass(ObjPtr<mirror::Class> temp_class, |
| 1180 | ObjPtr<mirror::Class> new_class) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1181 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | dbf3be0 | 2014-08-29 15:40:08 -0700 | [diff] [blame] | 1182 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 1183 | void SetClassRoot(ClassRoot class_root, ObjPtr<mirror::Class> klass) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1184 | REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 1185 | |
| 1186 | // Return the quick generic JNI stub for testing. |
| 1187 | const void* GetRuntimeQuickGenericJniStub() const; |
| 1188 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 1189 | bool CanWeInitializeClass(ObjPtr<mirror::Class> klass, |
| 1190 | bool can_init_statics, |
| 1191 | bool can_init_parents) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1192 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1193 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 1194 | void UpdateClassMethods(ObjPtr<mirror::Class> klass, |
Alex Light | e64300b | 2015-12-15 15:02:47 -0800 | [diff] [blame] | 1195 | LengthPrefixedArray<ArtMethod>* new_methods) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1196 | REQUIRES_SHARED(Locks::mutator_lock_) |
Mathieu Chartier | 54d220e | 2015-07-30 16:20:06 -0700 | [diff] [blame] | 1197 | REQUIRES(!Locks::classlinker_classes_lock_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1198 | |
Andreas Gampe | 7ba5a67 | 2016-02-04 21:45:01 -0800 | [diff] [blame] | 1199 | // Check that c1 == FindSystemClass(self, descriptor). Abort with class dumps otherwise. |
| 1200 | void CheckSystemClass(Thread* self, Handle<mirror::Class> c1, const char* descriptor) |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 1201 | REQUIRES(!Locks::dex_lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1202 | REQUIRES_SHARED(Locks::mutator_lock_); |
Andreas Gampe | 7ba5a67 | 2016-02-04 21:45:01 -0800 | [diff] [blame] | 1203 | |
Vladimir Marko | 921094a | 2017-01-12 18:37:06 +0000 | [diff] [blame] | 1204 | // Allocate method arrays for interfaces. |
| 1205 | bool AllocateIfTableMethodArrays(Thread* self, |
| 1206 | Handle<mirror::Class> klass, |
| 1207 | Handle<mirror::IfTable> iftable) |
| 1208 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 1209 | |
Mathieu Chartier | 7f98c9a | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 1210 | // Sets imt_ref appropriately for LinkInterfaceMethods. |
| 1211 | // If there is no method in the imt location of imt_ref it will store the given method there. |
| 1212 | // Otherwise it will set the conflict method which will figure out which method to use during |
| 1213 | // runtime. |
| 1214 | void SetIMTRef(ArtMethod* unimplemented_method, |
| 1215 | ArtMethod* imt_conflict_method, |
| 1216 | ArtMethod* current_method, |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 1217 | /*out*/bool* new_conflict, |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1218 | /*out*/ArtMethod** imt_ref) REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 7f98c9a | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 1219 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 1220 | void FillIMTFromIfTable(ObjPtr<mirror::IfTable> if_table, |
Mathieu Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 1221 | ArtMethod* unimplemented_method, |
| 1222 | ArtMethod* imt_conflict_method, |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 1223 | ObjPtr<mirror::Class> klass, |
Mathieu Chartier | e42888f | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 1224 | bool create_conflict_tables, |
| 1225 | bool ignore_copied_methods, |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 1226 | /*out*/bool* new_conflict, |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1227 | /*out*/ArtMethod** imt) REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 7f98c9a | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 1228 | |
| 1229 | void FillImtFromSuperClass(Handle<mirror::Class> klass, |
| 1230 | ArtMethod* unimplemented_method, |
| 1231 | ArtMethod* imt_conflict_method, |
Artem Udovichenko | a62cb9b | 2016-06-30 09:18:25 +0000 | [diff] [blame] | 1232 | bool* new_conflict, |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1233 | ArtMethod** imt) REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 7f98c9a | 2016-04-14 10:49:19 -0700 | [diff] [blame] | 1234 | |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1235 | // Check invoke type against the referenced class. Throws IncompatibleClassChangeError |
| 1236 | // (if `kThrowOnError`) and returns true on mismatch (kInterface on a non-interface class, |
| 1237 | // kVirtual on interface, kDefault on interface for dex files not supporting default methods), |
| 1238 | // otherwise returns false. |
| 1239 | template <bool kThrowOnError, typename ClassGetter> |
| 1240 | static bool CheckInvokeClassMismatch(ObjPtr<mirror::DexCache> dex_cache, |
| 1241 | InvokeType type, |
| 1242 | ClassGetter class_getter) |
| 1243 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 1244 | // Helper that feeds the above function with `ClassGetter` doing `LookupResolvedType()`. |
| 1245 | template <bool kThrow> |
| 1246 | bool CheckInvokeClassMismatch(ObjPtr<mirror::DexCache> dex_cache, |
| 1247 | InvokeType type, |
| 1248 | uint32_t method_idx, |
| 1249 | ObjPtr<mirror::ClassLoader> class_loader) |
| 1250 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 1251 | |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 1252 | std::vector<const DexFile*> boot_class_path_; |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 1253 | std::vector<std::unique_ptr<const DexFile>> boot_dex_files_; |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 1254 | |
Hiroshi Yamauchi | 04302db | 2015-11-11 23:45:34 -0800 | [diff] [blame] | 1255 | // JNI weak globals and side data to allow dex caches to get unloaded. We lazily delete weak |
| 1256 | // globals when we register new dex files. |
Andreas Gampe | cc1b535 | 2016-12-01 16:58:38 -0800 | [diff] [blame] | 1257 | std::list<DexCacheData> dex_caches_ GUARDED_BY(Locks::dex_lock_); |
Brian Carlstrom | 47d237a | 2011-10-18 15:08:33 -0700 | [diff] [blame] | 1258 | |
Mathieu Chartier | 9b1c71e | 2015-09-02 18:51:54 -0700 | [diff] [blame] | 1259 | // This contains the class loaders which have class tables. It is populated by |
Mathieu Chartier | 951ec2c | 2015-09-22 08:50:05 -0700 | [diff] [blame] | 1260 | // InsertClassTableForClassLoader. |
| 1261 | std::list<ClassLoaderData> class_loaders_ |
Mathieu Chartier | 6b06953 | 2015-08-05 15:08:12 -0700 | [diff] [blame] | 1262 | GUARDED_BY(Locks::classlinker_classes_lock_); |
| 1263 | |
| 1264 | // Boot class path table. Since the class loader for this is null. |
Andreas Gampe | 2af9902 | 2017-04-25 08:32:59 -0700 | [diff] [blame] | 1265 | std::unique_ptr<ClassTable> boot_class_table_ GUARDED_BY(Locks::classlinker_classes_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1266 | |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 1267 | // New class roots, only used by CMS since the GC needs to mark these in the pause. |
| 1268 | std::vector<GcRoot<mirror::Class>> new_class_roots_ GUARDED_BY(Locks::classlinker_classes_lock_); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 1269 | |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1270 | // Boot image oat files with new .bss GC roots to be visited in the pause by CMS. |
| 1271 | std::vector<const OatFile*> new_bss_roots_boot_oat_files_ |
| 1272 | GUARDED_BY(Locks::classlinker_classes_lock_); |
| 1273 | |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 1274 | // Number of times we've searched dex caches for a class. After a certain number of misses we move |
| 1275 | // the classes into the class_table_ to avoid dex cache based searches. |
Ian Rogers | 68b5685 | 2014-08-29 20:19:11 -0700 | [diff] [blame] | 1276 | Atomic<uint32_t> failed_dex_cache_class_lookups_; |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 1277 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 1278 | // Well known mirror::Class roots. |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 1279 | GcRoot<mirror::ObjectArray<mirror::Class>> class_roots_; |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 1280 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 1281 | // The interface table used by all arrays. |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 1282 | GcRoot<mirror::IfTable> array_iftable_; |
Carl Shapiro | 565f507 | 2011-07-10 13:39:43 -0700 | [diff] [blame] | 1283 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 1284 | // A cache of the last FindArrayClass results. The cache serves to avoid creating array class |
| 1285 | // descriptors for the sake of performing FindClass. |
| 1286 | static constexpr size_t kFindArrayCacheSize = 16; |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 1287 | GcRoot<mirror::Class> find_array_class_cache_[kFindArrayCacheSize]; |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 1288 | size_t find_array_class_cache_next_victim_; |
| 1289 | |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 1290 | bool init_done_; |
Vladimir Marko | 1998cd0 | 2017-01-13 13:02:58 +0000 | [diff] [blame] | 1291 | bool log_new_roots_ GUARDED_BY(Locks::classlinker_classes_lock_); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 1292 | |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 1293 | InternTable* intern_table_; |
| 1294 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 1295 | // Trampolines within the image the bounce to runtime entrypoints. Done so that there is a single |
| 1296 | // patch point within the image. TODO: make these proper relocations. |
Jeff Hao | 0aba0ba | 2013-06-03 14:49:28 -0700 | [diff] [blame] | 1297 | const void* quick_resolution_trampoline_; |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 1298 | const void* quick_imt_conflict_trampoline_; |
Andreas Gampe | 2da8823 | 2014-02-27 12:26:20 -0800 | [diff] [blame] | 1299 | const void* quick_generic_jni_trampoline_; |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 1300 | const void* quick_to_interpreter_bridge_trampoline_; |
Jeff Hao | 0aba0ba | 2013-06-03 14:49:28 -0700 | [diff] [blame] | 1301 | |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 1302 | // Image pointer size. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1303 | PointerSize image_pointer_size_; |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 1304 | |
Andreas Gampe | c1ac9ee | 2017-07-24 22:35:49 -0700 | [diff] [blame] | 1305 | std::unique_ptr<ClassHierarchyAnalysis> cha_; |
| 1306 | |
Mathieu Chartier | 6597577 | 2016-08-05 10:46:36 -0700 | [diff] [blame] | 1307 | class FindVirtualMethodHolderVisitor; |
Andreas Gampe | 2af9902 | 2017-04-25 08:32:59 -0700 | [diff] [blame] | 1308 | |
| 1309 | friend class AppImageClassLoadersAndDexCachesHelper; |
Mathieu Chartier | f9c6fc6 | 2015-10-07 11:44:05 -0700 | [diff] [blame] | 1310 | friend class ImageDumper; // for DexLock |
Vladimir Marko | 7452797 | 2016-11-29 15:57:32 +0000 | [diff] [blame] | 1311 | friend struct linker::CompilationHelper; // For Compile in ImageTest. |
| 1312 | friend class linker::ImageWriter; // for GetClassRoots |
| 1313 | friend class linker::OatWriter; // for boot image string/class table slot address lookup. |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 1314 | friend class JniCompilerTest; // for GetRuntimeQuickGenericJniStub |
Andreas Gampe | 5f4a09a | 2015-09-28 13:16:33 -0700 | [diff] [blame] | 1315 | friend class JniInternalTest; // for GetRuntimeQuickGenericJniStub |
Andreas Gampe | 2af9902 | 2017-04-25 08:32:59 -0700 | [diff] [blame] | 1316 | friend class VMClassLoader; // for LookupClass and FindClassInBaseDexClassLoader. |
Mathieu Chartier | 7617216 | 2016-01-26 14:54:06 -0800 | [diff] [blame] | 1317 | ART_FRIEND_TEST(ClassLinkerTest, RegisterDexFileName); // for DexLock, and RegisterDexFileLocked |
Narayan Kamath | 25352fc | 2016-08-03 12:46:58 +0100 | [diff] [blame] | 1318 | ART_FRIEND_TEST(mirror::DexCacheMethodHandlesTest, Open); // for AllocDexCache |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 1319 | ART_FRIEND_TEST(mirror::DexCacheTest, Open); // for AllocDexCache |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1320 | DISALLOW_COPY_AND_ASSIGN(ClassLinker); |
| 1321 | }; |
| 1322 | |
Andreas Gampe | 0f01b58 | 2017-01-18 15:22:37 -0800 | [diff] [blame] | 1323 | class ClassLoadCallback { |
| 1324 | public: |
| 1325 | virtual ~ClassLoadCallback() {} |
| 1326 | |
Alex Light | b0f1192 | 2017-01-23 14:25:17 -0800 | [diff] [blame] | 1327 | // If set we will replace initial_class_def & initial_dex_file with the final versions. The |
| 1328 | // callback author is responsible for ensuring these are allocated in such a way they can be |
| 1329 | // cleaned up if another transformation occurs. Note that both must be set or null/unchanged on |
| 1330 | // return. |
| 1331 | // Note: the class may be temporary, in which case a following ClassPrepare event will be a |
| 1332 | // different object. It is the listener's responsibility to handle this. |
| 1333 | // Note: This callback is rarely useful so a default implementation has been given that does |
| 1334 | // nothing. |
| 1335 | virtual void ClassPreDefine(const char* descriptor ATTRIBUTE_UNUSED, |
| 1336 | Handle<mirror::Class> klass ATTRIBUTE_UNUSED, |
| 1337 | Handle<mirror::ClassLoader> class_loader ATTRIBUTE_UNUSED, |
| 1338 | const DexFile& initial_dex_file ATTRIBUTE_UNUSED, |
| 1339 | const DexFile::ClassDef& initial_class_def ATTRIBUTE_UNUSED, |
| 1340 | /*out*/DexFile const** final_dex_file ATTRIBUTE_UNUSED, |
Alex Light | 4b0cedf | 2017-01-24 11:15:20 -0800 | [diff] [blame] | 1341 | /*out*/DexFile::ClassDef const** final_class_def ATTRIBUTE_UNUSED) |
Alex Light | b0f1192 | 2017-01-23 14:25:17 -0800 | [diff] [blame] | 1342 | REQUIRES_SHARED(Locks::mutator_lock_) {} |
| 1343 | |
Andreas Gampe | 0f01b58 | 2017-01-18 15:22:37 -0800 | [diff] [blame] | 1344 | // A class has been loaded. |
| 1345 | // Note: the class may be temporary, in which case a following ClassPrepare event will be a |
| 1346 | // different object. It is the listener's responsibility to handle this. |
| 1347 | virtual void ClassLoad(Handle<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_) = 0; |
| 1348 | |
| 1349 | // A class has been prepared, i.e., resolved. As the ClassLoad event might have been for a |
| 1350 | // temporary class, provide both the former and the current class. |
| 1351 | virtual void ClassPrepare(Handle<mirror::Class> temp_klass, |
| 1352 | Handle<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_) = 0; |
| 1353 | }; |
| 1354 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 1355 | } // namespace art |
| 1356 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 1357 | #endif // ART_RUNTIME_CLASS_LINKER_H_ |