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