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 | |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 20 | #include <deque> |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 21 | #include <string> |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 22 | #include <utility> |
| 23 | #include <vector> |
| 24 | |
Mathieu Chartier | bad0267 | 2014-08-25 13:08:22 -0700 | [diff] [blame] | 25 | #include "base/allocator.h" |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 26 | #include "base/hash_set.h" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 27 | #include "base/macros.h" |
Elliott Hughes | 76b6167 | 2012-12-12 17:47:30 -0800 | [diff] [blame] | 28 | #include "base/mutex.h" |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 29 | #include "dex_file.h" |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 30 | #include "gc_root.h" |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 31 | #include "jni.h" |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 32 | #include "oat_file.h" |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 33 | #include "object_callbacks.h" |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 34 | |
| 35 | namespace art { |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 36 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 37 | namespace gc { |
| 38 | namespace space { |
| 39 | class ImageSpace; |
| 40 | } // namespace space |
| 41 | } // namespace gc |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 42 | namespace mirror { |
Ian Rogers | 33e9566 | 2013-05-20 20:29:14 -0700 | [diff] [blame] | 43 | class ClassLoader; |
| 44 | class DexCache; |
| 45 | class DexCacheTest_Open_Test; |
| 46 | class IfTable; |
| 47 | template<class T> class ObjectArray; |
| 48 | class StackTraceElement; |
| 49 | } // namespace mirror |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 50 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 51 | template<class T> class Handle; |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 52 | class InternTable; |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 53 | template<class T> class ObjectLock; |
Andreas Gampe | 7ba6496 | 2014-10-23 11:37:40 -0700 | [diff] [blame] | 54 | class Runtime; |
Mathieu Chartier | 2b7c4d1 | 2014-05-19 10:52:16 -0700 | [diff] [blame] | 55 | class ScopedObjectAccessAlreadyRunnable; |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 56 | template<size_t kNumReferences> class PACKED(4) StackHandleScope; |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 57 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 58 | typedef bool (ClassVisitor)(mirror::Class* c, void* arg); |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 59 | |
Mathieu Chartier | 893263b | 2014-03-04 11:07:42 -0800 | [diff] [blame] | 60 | enum VisitRootFlags : uint8_t; |
| 61 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 62 | class ClassLinker { |
| 63 | public: |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 64 | // Well known mirror::Class roots accessed via GetClassRoot. |
| 65 | enum ClassRoot { |
| 66 | kJavaLangClass, |
| 67 | kJavaLangObject, |
| 68 | kClassArrayClass, |
| 69 | kObjectArrayClass, |
| 70 | kJavaLangString, |
| 71 | kJavaLangDexCache, |
| 72 | kJavaLangRefReference, |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 73 | kJavaLangReflectArtMethod, |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 74 | kJavaLangReflectConstructor, |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 75 | kJavaLangReflectField, |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 76 | kJavaLangReflectMethod, |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 77 | kJavaLangReflectProxy, |
| 78 | kJavaLangStringArrayClass, |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 79 | kJavaLangReflectArtMethodArrayClass, |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 80 | kJavaLangReflectConstructorArrayClass, |
Mathieu Chartier | daaf326 | 2015-03-24 13:30:28 -0700 | [diff] [blame] | 81 | kJavaLangReflectFieldArrayClass, |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 82 | kJavaLangReflectMethodArrayClass, |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 83 | kJavaLangClassLoader, |
| 84 | kJavaLangThrowable, |
| 85 | kJavaLangClassNotFoundException, |
| 86 | kJavaLangStackTraceElement, |
| 87 | kPrimitiveBoolean, |
| 88 | kPrimitiveByte, |
| 89 | kPrimitiveChar, |
| 90 | kPrimitiveDouble, |
| 91 | kPrimitiveFloat, |
| 92 | kPrimitiveInt, |
| 93 | kPrimitiveLong, |
| 94 | kPrimitiveShort, |
| 95 | kPrimitiveVoid, |
| 96 | kBooleanArrayClass, |
| 97 | kByteArrayClass, |
| 98 | kCharArrayClass, |
| 99 | kDoubleArrayClass, |
| 100 | kFloatArrayClass, |
| 101 | kIntArrayClass, |
| 102 | kLongArrayClass, |
| 103 | kShortArrayClass, |
| 104 | kJavaLangStackTraceElementArrayClass, |
| 105 | kClassRootsMax, |
| 106 | }; |
| 107 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 108 | explicit ClassLinker(InternTable* intern_table); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 109 | ~ClassLinker(); |
Carl Shapiro | 565f507 | 2011-07-10 13:39:43 -0700 | [diff] [blame] | 110 | |
Alex Light | 64ad14d | 2014-08-19 14:23:13 -0700 | [diff] [blame] | 111 | // Initialize class linker by bootstraping from dex files. |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 112 | void InitWithoutImage(std::vector<std::unique_ptr<const DexFile>> boot_class_path) |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 113 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 114 | |
| 115 | // Initialize class linker from one or more images. |
| 116 | void InitFromImage() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 117 | |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 118 | // Finds a class by its descriptor, loading it if necessary. |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 119 | // If class_loader is null, searches boot_class_path_. |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 120 | mirror::Class* FindClass(Thread* self, const char* descriptor, |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 121 | Handle<mirror::ClassLoader> class_loader) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 122 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 123 | |
Andreas Gampe | f865ea9 | 2015-04-13 22:14:19 -0700 | [diff] [blame] | 124 | // Finds a class in the path class loader, loading it if necessary without using JNI. Hash |
| 125 | // function is supposed to be ComputeModifiedUtf8Hash(descriptor). Returns true if the |
| 126 | // class-loader chain could be handled, false otherwise, i.e., a non-supported class-loader |
| 127 | // was encountered while walking the parent chain (currently only BootClassLoader and |
| 128 | // PathClassLoader are supported). |
| 129 | bool FindClassInPathClassLoader(ScopedObjectAccessAlreadyRunnable& soa, |
| 130 | Thread* self, const char* descriptor, size_t hash, |
| 131 | Handle<mirror::ClassLoader> class_loader, |
| 132 | mirror::Class** result) |
Mathieu Chartier | ab0ed82 | 2014-09-11 14:21:41 -0700 | [diff] [blame] | 133 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 134 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 135 | // Finds a class by its descriptor using the "system" class loader, ie by searching the |
| 136 | // boot_class_path_. |
| 137 | mirror::Class* FindSystemClass(Thread* self, const char* descriptor) |
| 138 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 139 | |
| 140 | // Finds the array class given for the element class. |
Mathieu Chartier | b74cd29 | 2014-05-29 14:31:33 -0700 | [diff] [blame] | 141 | mirror::Class* FindArrayClass(Thread* self, mirror::Class** element_class) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 142 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 143 | |
Ian Rogers | 6355745 | 2014-06-04 16:57:15 -0700 | [diff] [blame] | 144 | // Returns true if the class linker is initialized. |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 145 | bool IsInitialized() const { |
| 146 | return init_done_; |
| 147 | } |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 148 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 149 | // Define a new a class based on a ClassDef from a DexFile |
Mathieu Chartier | e7c9a8c | 2014-11-06 16:35:45 -0800 | [diff] [blame] | 150 | mirror::Class* DefineClass(Thread* self, const char* descriptor, size_t hash, |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 151 | Handle<mirror::ClassLoader> class_loader, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 152 | const DexFile& dex_file, const DexFile::ClassDef& dex_class_def) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 153 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 154 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 155 | // 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] | 156 | // by the given 'class_loader'. |
Mathieu Chartier | e7c9a8c | 2014-11-06 16:35:45 -0800 | [diff] [blame] | 157 | mirror::Class* LookupClass(Thread* self, const char* descriptor, size_t hash, |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 158 | mirror::ClassLoader* class_loader) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 159 | LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) |
| 160 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 161 | |
Elliott Hughes | 6fa602d | 2011-12-02 17:54:25 -0800 | [diff] [blame] | 162 | // Finds all the classes with the given descriptor, regardless of ClassLoader. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 163 | void LookupClasses(const char* descriptor, std::vector<mirror::Class*>& classes) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 164 | LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) |
| 165 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 6fa602d | 2011-12-02 17:54:25 -0800 | [diff] [blame] | 166 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 167 | mirror::Class* FindPrimitiveClass(char type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 168 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 169 | // General class unloading is not supported, this is used to prune |
| 170 | // unwanted classes during image writing. |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 171 | bool RemoveClass(const char* descriptor, mirror::ClassLoader* class_loader) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 172 | LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) |
| 173 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 174 | |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 175 | void DumpAllClasses(int flags) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 176 | LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) |
| 177 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 178 | |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 179 | void DumpForSigQuit(std::ostream& os) |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 180 | LOCKS_EXCLUDED(Locks::classlinker_classes_lock_); |
Elliott Hughes | cac6cc7 | 2011-11-03 20:31:21 -0700 | [diff] [blame] | 181 | |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 182 | size_t NumLoadedClasses() |
| 183 | LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) |
| 184 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 185 | |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 186 | // Resolve a String with the given index from the DexFile, storing the |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 187 | // result in the DexCache. The referrer is used to identify the |
| 188 | // target DexCache and ClassLoader to use for resolution. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 189 | mirror::String* ResolveString(uint32_t string_idx, mirror::ArtMethod* referrer) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 190 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 191 | |
| 192 | // Resolve a String with the given index from the DexFile, storing the |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 193 | // result in the DexCache. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 194 | mirror::String* ResolveString(const DexFile& dex_file, uint32_t string_idx, |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 195 | Handle<mirror::DexCache> dex_cache) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 196 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 197 | |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 198 | // Resolve a Type with the given index from the DexFile, storing the |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 199 | // result in the DexCache. The referrer is used to identity the |
| 200 | // target DexCache and ClassLoader to use for resolution. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 201 | mirror::Class* ResolveType(const DexFile& dex_file, uint16_t type_idx, mirror::Class* referrer) |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 202 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 203 | |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 204 | // Resolve a Type with the given index from the DexFile, storing the |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 205 | // result in the DexCache. The referrer is used to identify the |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 206 | // target DexCache and ClassLoader to use for resolution. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 207 | mirror::Class* ResolveType(uint16_t type_idx, mirror::ArtMethod* referrer) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 208 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 209 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 210 | mirror::Class* ResolveType(uint16_t type_idx, ArtField* referrer) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 211 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 212 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 213 | // Resolve a type with the given ID from the DexFile, storing the |
| 214 | // result in DexCache. The ClassLoader is used to search for the |
| 215 | // type, since it may be referenced from but not contained within |
| 216 | // the given DexFile. |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 217 | mirror::Class* ResolveType(const DexFile& dex_file, uint16_t type_idx, |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 218 | Handle<mirror::DexCache> dex_cache, |
| 219 | Handle<mirror::ClassLoader> class_loader) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 220 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 221 | |
| 222 | // Resolve a method with a given ID from the DexFile, storing the |
| 223 | // result in DexCache. The ClassLinker and ClassLoader are used as |
| 224 | // in ResolveType. What is unique is the method type argument which |
| 225 | // is used to determine if this method is a direct, static, or |
| 226 | // virtual method. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 227 | mirror::ArtMethod* ResolveMethod(const DexFile& dex_file, |
| 228 | uint32_t method_idx, |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 229 | Handle<mirror::DexCache> dex_cache, |
| 230 | Handle<mirror::ClassLoader> class_loader, |
| 231 | Handle<mirror::ArtMethod> referrer, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 232 | InvokeType type) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 233 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 234 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 235 | mirror::ArtMethod* GetResolvedMethod(uint32_t method_idx, mirror::ArtMethod* referrer) |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 236 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 237 | mirror::ArtMethod* ResolveMethod(Thread* self, uint32_t method_idx, mirror::ArtMethod** referrer, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 238 | InvokeType type) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 239 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 240 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 241 | ArtField* GetResolvedField(uint32_t field_idx, mirror::Class* field_declaring_class) |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 242 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 243 | ArtField* GetResolvedField(uint32_t field_idx, mirror::DexCache* dex_cache) |
| 244 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 245 | ArtField* ResolveField(uint32_t field_idx, mirror::ArtMethod* referrer, bool is_static) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 246 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | b9edb84 | 2011-08-28 16:31:06 -0700 | [diff] [blame] | 247 | |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 248 | // Resolve a field with a given ID from the DexFile, storing the |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 249 | // result in DexCache. The ClassLinker and ClassLoader are used as |
| 250 | // in ResolveType. What is unique is the is_static argument which is |
| 251 | // used to determine if we are resolving a static or non-static |
| 252 | // field. |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 253 | ArtField* ResolveField(const DexFile& dex_file, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 254 | uint32_t field_idx, |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 255 | Handle<mirror::DexCache> dex_cache, |
| 256 | Handle<mirror::ClassLoader> class_loader, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 257 | bool is_static) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 258 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 259 | |
Ian Rogers | b067ac2 | 2011-12-13 18:05:09 -0800 | [diff] [blame] | 260 | // Resolve a field with a given ID from the DexFile, storing the |
| 261 | // result in DexCache. The ClassLinker and ClassLoader are used as |
| 262 | // in ResolveType. No is_static argument is provided so that Java |
| 263 | // field resolution semantics are followed. |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 264 | ArtField* ResolveFieldJLS(const DexFile& dex_file, uint32_t field_idx, |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 265 | Handle<mirror::DexCache> dex_cache, |
| 266 | Handle<mirror::ClassLoader> class_loader) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 267 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | b067ac2 | 2011-12-13 18:05:09 -0800 | [diff] [blame] | 268 | |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 269 | // Get shorty from method index without resolution. Used to do handlerization. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 270 | const char* MethodShorty(uint32_t method_idx, mirror::ArtMethod* referrer, uint32_t* length) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 271 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 272 | |
Elliott Hughes | f4c21c9 | 2011-08-19 17:31:31 -0700 | [diff] [blame] | 273 | // Returns true on success, false if there's an exception pending. |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 274 | // can_run_clinit=false allows the compiler to attempt to init a class, |
| 275 | // given the restriction that no <clinit> execution is possible. |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 276 | bool EnsureInitialized(Thread* self, Handle<mirror::Class> c, bool can_init_fields, |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 277 | bool can_init_parents) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 278 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 279 | |
Elliott Hughes | 2a20cfd | 2011-09-23 19:30:41 -0700 | [diff] [blame] | 280 | // Initializes classes that have instances in the image but that have |
| 281 | // <clinit> methods so they could not be initialized by the compiler. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 282 | void RunRootClinits() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 2a20cfd | 2011-09-23 19:30:41 -0700 | [diff] [blame] | 283 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 284 | void RegisterDexFile(const DexFile& dex_file) |
| 285 | LOCKS_EXCLUDED(dex_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 286 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 287 | void RegisterDexFile(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 288 | LOCKS_EXCLUDED(dex_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 289 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 290 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 291 | const OatFile* RegisterOatFile(const OatFile* oat_file) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 292 | LOCKS_EXCLUDED(dex_lock_); |
Brian Carlstrom | 866c862 | 2012-01-06 16:35:13 -0800 | [diff] [blame] | 293 | |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 294 | const std::vector<const DexFile*>& GetBootClassPath() { |
| 295 | return boot_class_path_; |
| 296 | } |
| 297 | |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 298 | void VisitClasses(ClassVisitor* visitor, void* arg) |
Ian Rogers | dbf3be0 | 2014-08-29 15:40:08 -0700 | [diff] [blame] | 299 | LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 300 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | dbf3be0 | 2014-08-29 15:40:08 -0700 | [diff] [blame] | 301 | |
| 302 | // Less efficient variant of VisitClasses that copies the class_table_ into secondary storage |
| 303 | // so that it can visit individual classes without holding the doesn't hold the |
| 304 | // Locks::classlinker_classes_lock_. As the Locks::classlinker_classes_lock_ isn't held this code |
| 305 | // can race with insertion and deletion of classes while the visitor is being called. |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 306 | void VisitClassesWithoutClassesLock(ClassVisitor* visitor, void* arg) |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 307 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 308 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 309 | void VisitClassRoots(RootVisitor* visitor, VisitRootFlags flags) |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 310 | LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) |
| 311 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 312 | void VisitRoots(RootVisitor* visitor, VisitRootFlags flags) |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 313 | LOCKS_EXCLUDED(dex_lock_) |
| 314 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 315 | |
Hiroshi Yamauchi | e9e3e69 | 2014-06-24 14:31:37 -0700 | [diff] [blame] | 316 | mirror::DexCache* FindDexCache(const DexFile& dex_file) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 317 | LOCKS_EXCLUDED(dex_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 318 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | e9e3e69 | 2014-06-24 14:31:37 -0700 | [diff] [blame] | 319 | bool IsDexFileRegistered(const DexFile& dex_file) |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 320 | LOCKS_EXCLUDED(dex_lock_) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | e9e3e69 | 2014-06-24 14:31:37 -0700 | [diff] [blame] | 321 | void FixupDexCaches(mirror::ArtMethod* resolution_method) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 322 | LOCKS_EXCLUDED(dex_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 323 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 1d9f52b | 2011-10-13 10:50:45 -0700 | [diff] [blame] | 324 | |
Richard Uhler | 66d874d | 2015-01-15 09:37:19 -0800 | [diff] [blame] | 325 | // Finds or creates the oat file holding dex_location. Then loads and returns |
| 326 | // all corresponding dex files (there may be more than one dex file loaded |
| 327 | // in the case of multidex). |
| 328 | // This may return the original, unquickened dex files if the oat file could |
| 329 | // not be generated. |
| 330 | // |
| 331 | // Returns an empty vector if the dex files could not be loaded. In this |
| 332 | // case, there will be at least one error message returned describing why no |
| 333 | // dex files could not be loaded. The 'error_msgs' argument must not be |
| 334 | // null, regardless of whether there is an error or not. |
| 335 | // |
| 336 | // This method should not be called with the mutator_lock_ held, because it |
| 337 | // could end up starving GC if we need to generate or relocate any oat |
| 338 | // files. |
| 339 | std::vector<std::unique_ptr<const DexFile>> OpenDexFilesFromOat( |
| 340 | const char* dex_location, const char* oat_location, |
| 341 | std::vector<std::string>* error_msgs) |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 342 | LOCKS_EXCLUDED(dex_lock_, Locks::mutator_lock_); |
jeffhao | f6174e8 | 2012-01-31 16:14:17 -0800 | [diff] [blame] | 343 | |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 344 | // Allocate an instance of a java.lang.Object. |
| 345 | mirror::Object* AllocObject(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 346 | |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 347 | // TODO: replace this with multiple methods that allocate the correct managed type. |
Shih-wei Liao | 4417536 | 2011-08-28 16:59:17 -0700 | [diff] [blame] | 348 | template <class T> |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 349 | mirror::ObjectArray<T>* AllocObjectArray(Thread* self, size_t length) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 350 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 351 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 352 | mirror::ObjectArray<mirror::Class>* AllocClassArray(Thread* self, size_t length) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 353 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
jeffhao | 98eacac | 2011-09-14 16:11:53 -0700 | [diff] [blame] | 354 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 355 | mirror::ObjectArray<mirror::String>* AllocStringArray(Thread* self, size_t length) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 356 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 357 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 358 | mirror::ObjectArray<mirror::ArtMethod>* AllocArtMethodArray(Thread* self, size_t length) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 359 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 360 | |
| 361 | mirror::IfTable* AllocIfTable(Thread* self, size_t ifcount) |
| 362 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 363 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 364 | ArtField* AllocArtFieldArray(Thread* self, size_t length) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 365 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 366 | |
| 367 | mirror::ObjectArray<mirror::StackTraceElement>* AllocStackTraceElementArray(Thread* self, |
| 368 | size_t length) |
| 369 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 370 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 371 | void VerifyClass(Thread* self, Handle<mirror::Class> klass) |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 372 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 373 | bool VerifyClassUsingOatFile(const DexFile& dex_file, mirror::Class* klass, |
| 374 | mirror::Class::Status& oat_file_class_status) |
| 375 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 376 | void ResolveClassExceptionHandlerTypes(const DexFile& dex_file, |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 377 | Handle<mirror::Class> klass) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 378 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 379 | void ResolveMethodExceptionHandlerTypes(const DexFile& dex_file, mirror::ArtMethod* klass) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 380 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 381 | |
Mathieu Chartier | 2b7c4d1 | 2014-05-19 10:52:16 -0700 | [diff] [blame] | 382 | mirror::Class* CreateProxyClass(ScopedObjectAccessAlreadyRunnable& soa, jstring name, |
| 383 | jobjectArray interfaces, jobject loader, jobjectArray methods, |
| 384 | jobjectArray throws) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 385 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 386 | std::string GetDescriptorForProxy(mirror::Class* proxy_class) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 387 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 388 | mirror::ArtMethod* FindMethodForProxy(mirror::Class* proxy_class, |
| 389 | mirror::ArtMethod* proxy_method) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 390 | LOCKS_EXCLUDED(dex_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 391 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 392 | |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 393 | // Get the oat code for a method when its class isn't yet initialized |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 394 | const void* GetQuickOatCodeFor(mirror::ArtMethod* method) |
| 395 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 396 | |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 397 | // Get the oat code for a method from a method index. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 398 | const void* GetQuickOatCodeFor(const DexFile& dex_file, uint16_t class_def_idx, uint32_t method_idx) |
| 399 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 400 | |
Hiroshi Yamauchi | 9bdec88 | 2014-08-15 17:11:12 -0700 | [diff] [blame] | 401 | // Get compiled code for a method, return null if no code |
| 402 | // exists. This is unlike Get..OatCodeFor which will return a bridge |
| 403 | // or interpreter entrypoint. |
| 404 | const void* GetOatMethodQuickCodeFor(mirror::ArtMethod* method) |
| 405 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | 9bdec88 | 2014-08-15 17:11:12 -0700 | [diff] [blame] | 406 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 407 | pid_t GetClassesLockOwner(); // For SignalCatcher. |
| 408 | pid_t GetDexLockOwner(); // For SignalCatcher. |
Brian Carlstrom | 24a3c2e | 2011-10-17 18:07:52 -0700 | [diff] [blame] | 409 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 410 | mirror::Class* GetClassRoot(ClassRoot class_root) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Jeff Hao | 0aba0ba | 2013-06-03 14:49:28 -0700 | [diff] [blame] | 411 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 412 | static const char* GetClassRootDescriptor(ClassRoot class_root); |
Andreas Gampe | 2da8823 | 2014-02-27 12:26:20 -0800 | [diff] [blame] | 413 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 414 | // Is the given entry point quick code to run the resolution stub? |
| 415 | bool IsQuickResolutionStub(const void* entry_point) const; |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 416 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 417 | // Is the given entry point quick code to bridge into the interpreter? |
| 418 | bool IsQuickToInterpreterBridge(const void* entry_point) const; |
| 419 | |
| 420 | // Is the given entry point quick code to run the generic JNI stub? |
| 421 | bool IsQuickGenericJniStub(const void* entry_point) const; |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 422 | |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 423 | InternTable* GetInternTable() const { |
| 424 | return intern_table_; |
| 425 | } |
| 426 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 427 | // Set the entrypoints up for method to the given code. |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 428 | void SetEntryPointsToCompiledCode(mirror::ArtMethod* method, const void* method_code) const |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 429 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 430 | |
| 431 | // Set the entrypoints up for method to the enter the interpreter. |
| 432 | void SetEntryPointsToInterpreter(mirror::ArtMethod* method) const |
| 433 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 434 | |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 435 | // Attempts to insert a class into a class table. Returns null if |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 436 | // the class was inserted, otherwise returns an existing class with |
| 437 | // the same descriptor and ClassLoader. |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 438 | mirror::Class* InsertClass(const char* descriptor, mirror::Class* klass, size_t hash) |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 439 | LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) |
| 440 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 441 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 442 | // Special code to allocate an art method, use this instead of class->AllocObject. |
| 443 | mirror::ArtMethod* AllocArtMethod(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 444 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 445 | mirror::ObjectArray<mirror::Class>* GetClassRoots() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 446 | mirror::ObjectArray<mirror::Class>* class_roots = class_roots_.Read(); |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 447 | DCHECK(class_roots != nullptr); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 448 | return class_roots; |
| 449 | } |
| 450 | |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 451 | // Move all of the image classes into the class table for faster lookups. |
| 452 | void MoveImageClassesToClassTable() |
| 453 | LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) |
| 454 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 455 | // Move the class table to the pre-zygote table to reduce memory usage. This works by ensuring |
| 456 | // that no more classes are ever added to the pre zygote table which makes it that the pages |
| 457 | // always remain shared dirty instead of private dirty. |
| 458 | void MoveClassTableToPreZygote() |
| 459 | LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) |
| 460 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 461 | |
Sebastien Hertz | 6963e44 | 2014-11-26 22:11:27 +0100 | [diff] [blame] | 462 | // Returns true if the method can be called with its direct code pointer, false otherwise. |
| 463 | bool MayBeCalledWithDirectCodePointer(mirror::ArtMethod* m) |
| 464 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 465 | |
Andreas Gampe | 81c6f8d | 2015-03-25 17:19:53 -0700 | [diff] [blame] | 466 | // Creates a GlobalRef PathClassLoader that can be used to load classes from the given dex files. |
| 467 | // Note: the objects are not completely set up. Do not use this outside of tests and the compiler. |
| 468 | jobject CreatePathClassLoader(Thread* self, std::vector<const DexFile*>& dex_files) |
| 469 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 470 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 471 | private: |
Mathieu Chartier | a89d7ed | 2014-12-05 10:57:13 -0800 | [diff] [blame] | 472 | static void InitFromImageInterpretOnlyCallback(mirror::Object* obj, void* arg) |
| 473 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 474 | |
Ian Rogers | 97b52f8 | 2014-08-14 11:34:07 -0700 | [diff] [blame] | 475 | const OatFile::OatMethod FindOatMethodFor(mirror::ArtMethod* method, bool* found) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 476 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
TDYa127 | 8532191 | 2012-04-01 15:24:56 -0700 | [diff] [blame] | 477 | |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 478 | OatFile& GetImageOatFile(gc::space::ImageSpace* space) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 479 | LOCKS_EXCLUDED(dex_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 480 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 481 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 482 | void FinishInit(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 483 | |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 484 | // For early bootstrapping by Init |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 485 | mirror::Class* AllocClass(Thread* self, mirror::Class* java_lang_Class, uint32_t class_size) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 486 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 487 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 488 | // Alloc* convenience functions to avoid needing to pass in mirror::Class* |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 489 | // values that are known to the ClassLinker such as |
| 490 | // kObjectArrayClass and kJavaLangString etc. |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 491 | mirror::Class* AllocClass(Thread* self, uint32_t class_size) |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 492 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 493 | mirror::DexCache* AllocDexCache(Thread* self, const DexFile& dex_file) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 494 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 495 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 496 | mirror::Class* CreatePrimitiveClass(Thread* self, Primitive::Type type) |
| 497 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 498 | mirror::Class* InitializePrimitiveClass(mirror::Class* primitive_class, Primitive::Type type) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 499 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 500 | |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 501 | |
Mathieu Chartier | e7c9a8c | 2014-11-06 16:35:45 -0800 | [diff] [blame] | 502 | mirror::Class* CreateArrayClass(Thread* self, const char* descriptor, size_t hash, |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 503 | Handle<mirror::ClassLoader> class_loader) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 504 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 505 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 506 | void AppendToBootClassPath(Thread* self, const DexFile& dex_file) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 507 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 508 | void AppendToBootClassPath(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 509 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 510 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 511 | // Precomputes size needed for Class, in the case of a non-temporary class this size must be |
| 512 | // sufficient to hold all static fields. |
| 513 | uint32_t SizeOfClassWithoutEmbeddedTables(const DexFile& dex_file, |
| 514 | const DexFile::ClassDef& dex_class_def); |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 515 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 516 | // Setup the classloader, class def index, type idx so that we can insert this class in the class |
| 517 | // table. |
| 518 | void SetupClass(const DexFile& dex_file, const DexFile::ClassDef& dex_class_def, |
| 519 | Handle<mirror::Class> klass, mirror::ClassLoader* class_loader) |
| 520 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 521 | |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 522 | void LoadClass(Thread* self, const DexFile& dex_file, const DexFile::ClassDef& dex_class_def, |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 523 | Handle<mirror::Class> klass) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 524 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 525 | void LoadClassMembers(Thread* self, const DexFile& dex_file, const uint8_t* class_data, |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 526 | Handle<mirror::Class> klass, const OatFile::OatClass* oat_class) |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 527 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 528 | |
Mathieu Chartier | c785344 | 2015-03-27 14:35:38 -0700 | [diff] [blame] | 529 | void LoadField(const ClassDataItemIterator& it, Handle<mirror::Class> klass, |
| 530 | ArtField* dst) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 531 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 532 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 533 | mirror::ArtMethod* LoadMethod(Thread* self, const DexFile& dex_file, |
| 534 | const ClassDataItemIterator& dex_method, |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 535 | Handle<mirror::Class> klass) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 536 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 537 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 538 | void FixupStaticTrampolines(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 539 | |
Ian Rogers | 97b52f8 | 2014-08-14 11:34:07 -0700 | [diff] [blame] | 540 | // Finds the associated oat class for a dex_file and descriptor. Returns an invalid OatClass on |
| 541 | // error and sets found to false. |
| 542 | OatFile::OatClass FindOatClass(const DexFile& dex_file, uint16_t class_def_idx, bool* found) |
Ian Rogers | 33e9566 | 2013-05-20 20:29:14 -0700 | [diff] [blame] | 543 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 544 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 545 | void RegisterDexFileLocked(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 546 | EXCLUSIVE_LOCKS_REQUIRED(dex_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 547 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | e9e3e69 | 2014-06-24 14:31:37 -0700 | [diff] [blame] | 548 | bool IsDexFileRegisteredLocked(const DexFile& dex_file) |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 549 | SHARED_LOCKS_REQUIRED(dex_lock_, Locks::mutator_lock_); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 550 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 551 | bool InitializeClass(Thread* self, Handle<mirror::Class> klass, bool can_run_clinit, |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 552 | bool can_init_parents) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 553 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 554 | bool WaitForInitializeClass(Handle<mirror::Class> klass, Thread* self, |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 555 | ObjectLock<mirror::Class>& lock); |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 556 | bool ValidateSuperClassDescriptors(Handle<mirror::Class> klass) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 557 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 558 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 559 | bool IsSameDescriptorInDifferentClassContexts(Thread* self, const char* descriptor, |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 560 | Handle<mirror::ClassLoader> class_loader1, |
| 561 | Handle<mirror::ClassLoader> class_loader2) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 562 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 563 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 564 | bool IsSameMethodSignatureInDifferentClassContexts(Thread* self, mirror::ArtMethod* method, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 565 | mirror::Class* klass1, |
| 566 | mirror::Class* klass2) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 567 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 568 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 569 | bool LinkClass(Thread* self, const char* descriptor, Handle<mirror::Class> klass, |
| 570 | Handle<mirror::ObjectArray<mirror::Class>> interfaces, |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 571 | mirror::Class** new_class) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 572 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 573 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 574 | bool LinkSuperClass(Handle<mirror::Class> klass) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 575 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 576 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 577 | bool LoadSuperAndInterfaces(Handle<mirror::Class> klass, const DexFile& dex_file) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 578 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 579 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 580 | bool LinkMethods(Thread* self, Handle<mirror::Class> klass, |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 581 | Handle<mirror::ObjectArray<mirror::Class>> interfaces, |
| 582 | StackHandleScope<mirror::Class::kImtSize>* out_imt) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 583 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 584 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 585 | bool LinkVirtualMethods(Thread* self, Handle<mirror::Class> klass) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 586 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 587 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 588 | bool LinkInterfaceMethods(Thread* const self, Handle<mirror::Class> klass, |
| 589 | Handle<mirror::ObjectArray<mirror::Class>> interfaces, |
| 590 | StackHandleScope<mirror::Class::kImtSize>* out_imt) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 591 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 592 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 593 | bool LinkStaticFields(Thread* self, Handle<mirror::Class> klass, size_t* class_size) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 594 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 595 | bool LinkInstanceFields(Thread* self, Handle<mirror::Class> klass) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 596 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 597 | bool LinkFields(Thread* self, Handle<mirror::Class> klass, bool is_static, size_t* class_size) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 598 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 599 | void LinkCode(Handle<mirror::ArtMethod> method, const OatFile::OatClass* oat_class, |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 600 | uint32_t class_def_method_index) |
Dmitry Petrochenko | f0972a4 | 2014-05-16 17:43:39 +0700 | [diff] [blame] | 601 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 602 | void CreateReferenceInstanceOffsets(Handle<mirror::Class> klass) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 603 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 604 | |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 605 | // For use by ImageWriter to find DexCaches for its roots |
Hiroshi Yamauchi | e9e3e69 | 2014-06-24 14:31:37 -0700 | [diff] [blame] | 606 | ReaderWriterMutex* DexLock() |
| 607 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) LOCK_RETURNED(dex_lock_) { |
| 608 | return &dex_lock_; |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 609 | } |
Hiroshi Yamauchi | e9e3e69 | 2014-06-24 14:31:37 -0700 | [diff] [blame] | 610 | size_t GetDexCacheCount() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_, dex_lock_) { |
| 611 | return dex_caches_.size(); |
| 612 | } |
| 613 | mirror::DexCache* GetDexCache(size_t idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_, dex_lock_); |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 614 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 615 | const OatFile* FindOpenedOatFileFromOatLocation(const std::string& oat_location) |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 616 | LOCKS_EXCLUDED(dex_lock_); |
Andreas Gampe | 833a485 | 2014-05-21 18:46:59 -0700 | [diff] [blame] | 617 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 618 | mirror::ArtMethod* CreateProxyConstructor(Thread* self, Handle<mirror::Class> klass, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 619 | mirror::Class* proxy_class) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 620 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 621 | mirror::ArtMethod* CreateProxyMethod(Thread* self, Handle<mirror::Class> klass, |
| 622 | Handle<mirror::ArtMethod> prototype) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 623 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 624 | |
Andreas Gampe | 4849859 | 2014-09-10 19:48:05 -0700 | [diff] [blame] | 625 | // Ensures that methods have the kAccPreverified bit set. We use the kAccPreverfied bit on the |
| 626 | // class access flags to determine whether this has been done before. |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 627 | void EnsurePreverifiedMethods(Handle<mirror::Class> c) |
Andreas Gampe | 4849859 | 2014-09-10 19:48:05 -0700 | [diff] [blame] | 628 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 629 | |
Ian Rogers | dbf3be0 | 2014-08-29 15:40:08 -0700 | [diff] [blame] | 630 | mirror::Class* LookupClassFromTableLocked(const char* descriptor, |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 631 | mirror::ClassLoader* class_loader, |
Ian Rogers | dbf3be0 | 2014-08-29 15:40:08 -0700 | [diff] [blame] | 632 | size_t hash) |
| 633 | SHARED_LOCKS_REQUIRED(Locks::classlinker_classes_lock_, Locks::mutator_lock_); |
| 634 | |
| 635 | mirror::Class* UpdateClass(const char* descriptor, mirror::Class* klass, size_t hash) |
| 636 | LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) |
| 637 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 638 | |
Ian Rogers | dbf3be0 | 2014-08-29 15:40:08 -0700 | [diff] [blame] | 639 | mirror::Class* LookupClassFromImage(const char* descriptor) |
| 640 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 641 | |
| 642 | // EnsureResolved is called to make sure that a class in the class_table_ has been resolved |
| 643 | // before returning it to the caller. Its the responsibility of the thread that placed the class |
| 644 | // in the table to make it resolved. The thread doing resolution must notify on the class' lock |
| 645 | // when resolution has occurred. This happens in mirror::Class::SetStatus. As resolution may |
| 646 | // retire a class, the version of the class in the table is returned and this may differ from |
| 647 | // the class passed in. |
| 648 | mirror::Class* EnsureResolved(Thread* self, const char* descriptor, mirror::Class* klass) |
| 649 | WARN_UNUSED SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 650 | |
| 651 | void FixupTemporaryDeclaringClass(mirror::Class* temp_class, mirror::Class* new_class) |
| 652 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 653 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 654 | void SetClassRoot(ClassRoot class_root, mirror::Class* klass) |
| 655 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 656 | |
| 657 | // Return the quick generic JNI stub for testing. |
| 658 | const void* GetRuntimeQuickGenericJniStub() const; |
| 659 | |
Andreas Gampe | bfdcdc1 | 2015-04-22 18:10:36 -0700 | [diff] [blame] | 660 | // Throw the class initialization failure recorded when first trying to initialize the given |
| 661 | // class. |
| 662 | // Note: Currently we only store the descriptor, so we cannot throw the exact throwable, only |
| 663 | // a recreation with a custom string. |
| 664 | void ThrowEarlierClassFailure(mirror::Class* c) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 665 | |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 666 | std::vector<const DexFile*> boot_class_path_; |
Richard Uhler | fbef44d | 2014-12-23 09:48:51 -0800 | [diff] [blame] | 667 | std::vector<std::unique_ptr<const DexFile>> opened_dex_files_; |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 668 | |
Ian Rogers | 1bf8d4d | 2013-05-30 00:18:49 -0700 | [diff] [blame] | 669 | mutable ReaderWriterMutex dex_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; |
Andreas Gampe | c8ccf68 | 2014-09-29 20:07:43 -0700 | [diff] [blame] | 670 | std::vector<size_t> new_dex_cache_roots_ GUARDED_BY(dex_lock_); |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 671 | std::vector<GcRoot<mirror::DexCache>> dex_caches_ GUARDED_BY(dex_lock_); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 672 | std::vector<const OatFile*> oat_files_ GUARDED_BY(dex_lock_); |
Brian Carlstrom | 47d237a | 2011-10-18 15:08:33 -0700 | [diff] [blame] | 673 | |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 674 | class ClassDescriptorHashEquals { |
| 675 | public: |
| 676 | // Same class loader and descriptor. |
| 677 | std::size_t operator()(const GcRoot<mirror::Class>& root) const NO_THREAD_SAFETY_ANALYSIS; |
Mathieu Chartier | 47f867a | 2015-03-18 10:39:00 -0700 | [diff] [blame] | 678 | bool operator()(const GcRoot<mirror::Class>& a, const GcRoot<mirror::Class>& b) const |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 679 | NO_THREAD_SAFETY_ANALYSIS; |
| 680 | // Same class loader and descriptor. |
| 681 | std::size_t operator()(const std::pair<const char*, mirror::ClassLoader*>& element) const |
| 682 | NO_THREAD_SAFETY_ANALYSIS; |
| 683 | bool operator()(const GcRoot<mirror::Class>& a, |
Mathieu Chartier | 47f867a | 2015-03-18 10:39:00 -0700 | [diff] [blame] | 684 | const std::pair<const char*, mirror::ClassLoader*>& b) const |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 685 | NO_THREAD_SAFETY_ANALYSIS; |
| 686 | // Same descriptor. |
Mathieu Chartier | 47f867a | 2015-03-18 10:39:00 -0700 | [diff] [blame] | 687 | bool operator()(const GcRoot<mirror::Class>& a, const char* descriptor) const |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 688 | NO_THREAD_SAFETY_ANALYSIS; |
| 689 | std::size_t operator()(const char* descriptor) const NO_THREAD_SAFETY_ANALYSIS; |
| 690 | }; |
| 691 | class GcRootEmptyFn { |
| 692 | public: |
| 693 | void MakeEmpty(GcRoot<mirror::Class>& item) const { |
| 694 | item = GcRoot<mirror::Class>(); |
| 695 | } |
| 696 | bool IsEmpty(const GcRoot<mirror::Class>& item) const { |
| 697 | return item.IsNull(); |
| 698 | } |
| 699 | }; |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 700 | |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 701 | // hash set which hashes class descriptor, and compares descriptors nad class loaders. Results |
| 702 | // should be compared for a matching Class descriptor and class loader. |
| 703 | typedef HashSet<GcRoot<mirror::Class>, GcRootEmptyFn, ClassDescriptorHashEquals, |
| 704 | ClassDescriptorHashEquals, TrackingAllocator<GcRoot<mirror::Class>, kAllocatorTagClassTable>> |
| 705 | Table; |
Hiroshi Yamauchi | a91a4bc | 2014-06-13 16:44:55 -0700 | [diff] [blame] | 706 | // This contains strong roots. To enable concurrent root scanning of |
| 707 | // the class table, be careful to use a read barrier when accessing this. |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 708 | Table class_table_ GUARDED_BY(Locks::classlinker_classes_lock_); |
Mathieu Chartier | c2e2062 | 2014-11-03 11:41:47 -0800 | [diff] [blame] | 709 | Table pre_zygote_class_table_ GUARDED_BY(Locks::classlinker_classes_lock_); |
| 710 | std::vector<GcRoot<mirror::Class>> new_class_roots_; |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 711 | |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 712 | // Do we need to search dex caches to find image classes? |
| 713 | bool dex_cache_image_class_lookup_required_; |
| 714 | // Number of times we've searched dex caches for a class. After a certain number of misses we move |
| 715 | // the classes into the class_table_ to avoid dex cache based searches. |
Ian Rogers | 68b5685 | 2014-08-29 20:19:11 -0700 | [diff] [blame] | 716 | Atomic<uint32_t> failed_dex_cache_class_lookups_; |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 717 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 718 | // Well known mirror::Class roots. |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 719 | GcRoot<mirror::ObjectArray<mirror::Class>> class_roots_; |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 720 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 721 | // The interface table used by all arrays. |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 722 | GcRoot<mirror::IfTable> array_iftable_; |
Carl Shapiro | 565f507 | 2011-07-10 13:39:43 -0700 | [diff] [blame] | 723 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 724 | // A cache of the last FindArrayClass results. The cache serves to avoid creating array class |
| 725 | // descriptors for the sake of performing FindClass. |
| 726 | static constexpr size_t kFindArrayCacheSize = 16; |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 727 | GcRoot<mirror::Class> find_array_class_cache_[kFindArrayCacheSize]; |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 728 | size_t find_array_class_cache_next_victim_; |
| 729 | |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 730 | bool init_done_; |
Mathieu Chartier | 893263b | 2014-03-04 11:07:42 -0800 | [diff] [blame] | 731 | bool log_new_dex_caches_roots_ GUARDED_BY(dex_lock_); |
| 732 | bool log_new_class_table_roots_ GUARDED_BY(Locks::classlinker_classes_lock_); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 733 | |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 734 | InternTable* intern_table_; |
| 735 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 736 | // Trampolines within the image the bounce to runtime entrypoints. Done so that there is a single |
| 737 | // patch point within the image. TODO: make these proper relocations. |
Jeff Hao | 0aba0ba | 2013-06-03 14:49:28 -0700 | [diff] [blame] | 738 | const void* quick_resolution_trampoline_; |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 739 | const void* quick_imt_conflict_trampoline_; |
Andreas Gampe | 2da8823 | 2014-02-27 12:26:20 -0800 | [diff] [blame] | 740 | const void* quick_generic_jni_trampoline_; |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 741 | const void* quick_to_interpreter_bridge_trampoline_; |
Jeff Hao | 0aba0ba | 2013-06-03 14:49:28 -0700 | [diff] [blame] | 742 | |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 743 | // Image pointer size. |
| 744 | size_t image_pointer_size_; |
| 745 | |
Brian Carlstrom | 34f426c | 2011-10-04 12:58:02 -0700 | [diff] [blame] | 746 | friend class ImageWriter; // for GetClassRoots |
Alex Light | a59dd80 | 2014-07-02 16:28:08 -0700 | [diff] [blame] | 747 | friend class ImageDumper; // for FindOpenedOatFileFromOatLocation |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 748 | friend class JniCompilerTest; // for GetRuntimeQuickGenericJniStub |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 749 | ART_FRIEND_TEST(mirror::DexCacheTest, Open); // for AllocDexCache |
| 750 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 751 | DISALLOW_COPY_AND_ASSIGN(ClassLinker); |
| 752 | }; |
| 753 | |
| 754 | } // namespace art |
| 755 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 756 | #endif // ART_RUNTIME_CLASS_LINKER_H_ |