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 | |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 20 | #include <string> |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 21 | #include <utility> |
| 22 | #include <vector> |
| 23 | |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 24 | #include "base/macros.h" |
Elliott Hughes | 76b6167 | 2012-12-12 17:47:30 -0800 | [diff] [blame] | 25 | #include "base/mutex.h" |
Brian Carlstrom | 7e49dca | 2011-07-22 18:07:34 -0700 | [diff] [blame] | 26 | #include "dex_file.h" |
Elliott Hughes | e5448b5 | 2012-01-18 16:44:06 -0800 | [diff] [blame] | 27 | #include "gtest/gtest.h" |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 28 | #include "jni.h" |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 29 | #include "oat_file.h" |
Mathieu Chartier | 83c8ee0 | 2014-01-28 14:50:23 -0800 | [diff] [blame] | 30 | #include "object_callbacks.h" |
Hiroshi Yamauchi | e9e3e69 | 2014-06-24 14:31:37 -0700 | [diff] [blame^] | 31 | #include "read_barrier.h" |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 32 | |
| 33 | namespace art { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 34 | namespace gc { |
| 35 | namespace space { |
| 36 | class ImageSpace; |
| 37 | } // namespace space |
| 38 | } // namespace gc |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 39 | namespace mirror { |
Ian Rogers | 33e9566 | 2013-05-20 20:29:14 -0700 | [diff] [blame] | 40 | class ClassLoader; |
| 41 | class DexCache; |
| 42 | class DexCacheTest_Open_Test; |
| 43 | class IfTable; |
| 44 | template<class T> class ObjectArray; |
| 45 | class StackTraceElement; |
| 46 | } // namespace mirror |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 47 | |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 48 | class InternTable; |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 49 | template<class T> class ObjectLock; |
Mathieu Chartier | 2b7c4d1 | 2014-05-19 10:52:16 -0700 | [diff] [blame] | 50 | class ScopedObjectAccessAlreadyRunnable; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 51 | template<class T> class Handle; |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 52 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 53 | typedef bool (ClassVisitor)(mirror::Class* c, void* arg); |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 54 | |
Mathieu Chartier | 893263b | 2014-03-04 11:07:42 -0800 | [diff] [blame] | 55 | enum VisitRootFlags : uint8_t; |
| 56 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 57 | class ClassLinker { |
| 58 | public: |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 59 | // Interface method table size. Increasing this value reduces the chance of two interface methods |
| 60 | // colliding in the interface method table but increases the size of classes that implement |
| 61 | // (non-marker) interfaces. |
| 62 | static constexpr size_t kImtSize = 64; |
| 63 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 64 | explicit ClassLinker(InternTable* intern_table); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 65 | ~ClassLinker(); |
Carl Shapiro | 565f507 | 2011-07-10 13:39:43 -0700 | [diff] [blame] | 66 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 67 | // Initialize class linker by bootstraping from dex files |
| 68 | void InitFromCompiler(const std::vector<const DexFile*>& boot_class_path) |
| 69 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 70 | |
| 71 | // Initialize class linker from one or more images. |
| 72 | void InitFromImage() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 73 | |
Ian Rogers | be7149f | 2013-08-20 09:29:39 -0700 | [diff] [blame] | 74 | bool IsInBootClassPath(const char* descriptor); |
| 75 | |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 76 | // Finds a class by its descriptor, loading it if necessary. |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 77 | // If class_loader is null, searches boot_class_path_. |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 78 | mirror::Class* FindClass(Thread* self, const char* descriptor, |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 79 | Handle<mirror::ClassLoader> class_loader) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 80 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 81 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 82 | // Finds a class by its descriptor using the "system" class loader, ie by searching the |
| 83 | // boot_class_path_. |
| 84 | mirror::Class* FindSystemClass(Thread* self, const char* descriptor) |
| 85 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 86 | |
| 87 | // Finds the array class given for the element class. |
Mathieu Chartier | b74cd29 | 2014-05-29 14:31:33 -0700 | [diff] [blame] | 88 | mirror::Class* FindArrayClass(Thread* self, mirror::Class** element_class) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 89 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 90 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 91 | // Reutrns true if the class linker is initialized. |
| 92 | bool IsInitialized() const; |
| 93 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 94 | // Define a new a class based on a ClassDef from a DexFile |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 95 | mirror::Class* DefineClass(const char* descriptor, |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 96 | Handle<mirror::ClassLoader> class_loader, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 97 | const DexFile& dex_file, const DexFile::ClassDef& dex_class_def) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 98 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 64bf5a3 | 2011-09-20 14:43:12 -0700 | [diff] [blame] | 99 | |
| 100 | // Finds a class by its descriptor, returning NULL if it isn't wasn't loaded |
| 101 | // by the given 'class_loader'. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 102 | mirror::Class* LookupClass(const char* descriptor, const mirror::ClassLoader* class_loader) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 103 | LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) |
| 104 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 105 | |
Elliott Hughes | 6fa602d | 2011-12-02 17:54:25 -0800 | [diff] [blame] | 106 | // Finds all the classes with the given descriptor, regardless of ClassLoader. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 107 | void LookupClasses(const char* descriptor, std::vector<mirror::Class*>& classes) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 108 | LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) |
| 109 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 6fa602d | 2011-12-02 17:54:25 -0800 | [diff] [blame] | 110 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 111 | mirror::Class* FindPrimitiveClass(char type) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 112 | |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 113 | // General class unloading is not supported, this is used to prune |
| 114 | // unwanted classes during image writing. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 115 | bool RemoveClass(const char* descriptor, const mirror::ClassLoader* class_loader) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 116 | LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) |
| 117 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 118 | |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 119 | void DumpAllClasses(int flags) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 120 | LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) |
| 121 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 122 | |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 123 | void DumpForSigQuit(std::ostream& os) |
| 124 | LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) |
| 125 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | cac6cc7 | 2011-11-03 20:31:21 -0700 | [diff] [blame] | 126 | |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 127 | size_t NumLoadedClasses() |
| 128 | LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) |
| 129 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | e27955c | 2011-08-26 15:21:24 -0700 | [diff] [blame] | 130 | |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 131 | // Resolve a String with the given index from the DexFile, storing the |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 132 | // result in the DexCache. The referrer is used to identify the |
| 133 | // target DexCache and ClassLoader to use for resolution. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 134 | mirror::String* ResolveString(uint32_t string_idx, mirror::ArtMethod* referrer) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 135 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 136 | |
| 137 | // Resolve a String with the given index from the DexFile, storing the |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 138 | // result in the DexCache. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 139 | mirror::String* ResolveString(const DexFile& dex_file, uint32_t string_idx, |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 140 | Handle<mirror::DexCache> dex_cache) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 141 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 142 | |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 143 | // Resolve a Type with the given index from the DexFile, storing the |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 144 | // result in the DexCache. The referrer is used to identity the |
| 145 | // target DexCache and ClassLoader to use for resolution. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 146 | 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] | 147 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 148 | |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 149 | // Resolve a Type with the given index from the DexFile, storing the |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 150 | // result in the DexCache. The referrer is used to identify the |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 151 | // target DexCache and ClassLoader to use for resolution. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 152 | mirror::Class* ResolveType(uint16_t type_idx, mirror::ArtMethod* referrer) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 153 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 154 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 155 | mirror::Class* ResolveType(uint16_t type_idx, mirror::ArtField* referrer) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 156 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | b63ec39 | 2011-08-27 17:38:27 -0700 | [diff] [blame] | 157 | |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 158 | // Resolve a type with the given ID from the DexFile, storing the |
| 159 | // result in DexCache. The ClassLoader is used to search for the |
| 160 | // type, since it may be referenced from but not contained within |
| 161 | // the given DexFile. |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 162 | mirror::Class* ResolveType(const DexFile& dex_file, uint16_t type_idx, |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 163 | Handle<mirror::DexCache> dex_cache, |
| 164 | Handle<mirror::ClassLoader> class_loader) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 165 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 166 | |
| 167 | // Resolve a method with a given ID from the DexFile, storing the |
| 168 | // result in DexCache. The ClassLinker and ClassLoader are used as |
| 169 | // in ResolveType. What is unique is the method type argument which |
| 170 | // is used to determine if this method is a direct, static, or |
| 171 | // virtual method. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 172 | mirror::ArtMethod* ResolveMethod(const DexFile& dex_file, |
| 173 | uint32_t method_idx, |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 174 | Handle<mirror::DexCache> dex_cache, |
| 175 | Handle<mirror::ClassLoader> class_loader, |
| 176 | Handle<mirror::ArtMethod> referrer, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 177 | InvokeType type) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 178 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 179 | |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 180 | mirror::ArtMethod* GetResolvedMethod(uint32_t method_idx, mirror::ArtMethod* referrer, |
| 181 | InvokeType type) |
| 182 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 183 | mirror::ArtMethod* ResolveMethod(Thread* self, uint32_t method_idx, mirror::ArtMethod** referrer, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 184 | InvokeType type) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 185 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 186 | |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 187 | mirror::ArtField* GetResolvedField(uint32_t field_idx, mirror::Class* field_declaring_class) |
| 188 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 189 | mirror::ArtField* ResolveField(uint32_t field_idx, mirror::ArtMethod* referrer, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 190 | bool is_static) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 191 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | b9edb84 | 2011-08-28 16:31:06 -0700 | [diff] [blame] | 192 | |
Brian Carlstrom | 1619286 | 2011-09-12 17:50:06 -0700 | [diff] [blame] | 193 | // Resolve a field with a given ID from the DexFile, storing the |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 194 | // result in DexCache. The ClassLinker and ClassLoader are used as |
| 195 | // in ResolveType. What is unique is the is_static argument which is |
| 196 | // used to determine if we are resolving a static or non-static |
| 197 | // field. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 198 | mirror::ArtField* ResolveField(const DexFile& dex_file, |
| 199 | uint32_t field_idx, |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 200 | Handle<mirror::DexCache> dex_cache, |
| 201 | Handle<mirror::ClassLoader> class_loader, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 202 | bool is_static) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 203 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 9ea1cb1 | 2011-08-24 23:18:18 -0700 | [diff] [blame] | 204 | |
Ian Rogers | b067ac2 | 2011-12-13 18:05:09 -0800 | [diff] [blame] | 205 | // Resolve a field with a given ID from the DexFile, storing the |
| 206 | // result in DexCache. The ClassLinker and ClassLoader are used as |
| 207 | // in ResolveType. No is_static argument is provided so that Java |
| 208 | // field resolution semantics are followed. |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 209 | mirror::ArtField* ResolveFieldJLS(const DexFile& dex_file, uint32_t field_idx, |
| 210 | Handle<mirror::DexCache> dex_cache, |
| 211 | Handle<mirror::ClassLoader> class_loader) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 212 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | b067ac2 | 2011-12-13 18:05:09 -0800 | [diff] [blame] | 213 | |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 214 | // Get shorty from method index without resolution. Used to do handlerization. |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 215 | 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] | 216 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 217 | |
Elliott Hughes | f4c21c9 | 2011-08-19 17:31:31 -0700 | [diff] [blame] | 218 | // Returns true on success, false if there's an exception pending. |
Brian Carlstrom | 25c3325 | 2011-09-18 15:58:35 -0700 | [diff] [blame] | 219 | // can_run_clinit=false allows the compiler to attempt to init a class, |
| 220 | // given the restriction that no <clinit> execution is possible. |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 221 | bool EnsureInitialized(Handle<mirror::Class> c, bool can_init_fields, bool can_init_parents) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 222 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 223 | |
Elliott Hughes | 2a20cfd | 2011-09-23 19:30:41 -0700 | [diff] [blame] | 224 | // Initializes classes that have instances in the image but that have |
| 225 | // <clinit> methods so they could not be initialized by the compiler. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 226 | void RunRootClinits() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 2a20cfd | 2011-09-23 19:30:41 -0700 | [diff] [blame] | 227 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 228 | void RegisterDexFile(const DexFile& dex_file) |
| 229 | LOCKS_EXCLUDED(dex_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 230 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 231 | void RegisterDexFile(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 232 | LOCKS_EXCLUDED(dex_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 233 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 234 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 235 | const OatFile* RegisterOatFile(const OatFile* oat_file) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 236 | LOCKS_EXCLUDED(dex_lock_); |
Brian Carlstrom | 866c862 | 2012-01-06 16:35:13 -0800 | [diff] [blame] | 237 | |
Brian Carlstrom | 8a48741 | 2011-08-29 20:08:52 -0700 | [diff] [blame] | 238 | const std::vector<const DexFile*>& GetBootClassPath() { |
| 239 | return boot_class_path_; |
| 240 | } |
| 241 | |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 242 | void VisitClasses(ClassVisitor* visitor, void* arg) |
| 243 | LOCKS_EXCLUDED(dex_lock_) |
| 244 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 245 | // Less efficient variant of VisitClasses that doesn't hold the classlinker_classes_lock_ |
| 246 | // when calling the visitor. |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 247 | void VisitClassesWithoutClassesLock(ClassVisitor* visitor, void* arg) |
| 248 | LOCKS_EXCLUDED(dex_lock_) |
| 249 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 250 | |
Mathieu Chartier | 52e4b43 | 2014-06-10 11:22:31 -0700 | [diff] [blame] | 251 | void VisitClassRoots(RootCallback* callback, void* arg, VisitRootFlags flags) |
| 252 | LOCKS_EXCLUDED(Locks::classlinker_classes_lock_); |
Mathieu Chartier | 893263b | 2014-03-04 11:07:42 -0800 | [diff] [blame] | 253 | void VisitRoots(RootCallback* callback, void* arg, VisitRootFlags flags) |
Mathieu Chartier | 52e4b43 | 2014-06-10 11:22:31 -0700 | [diff] [blame] | 254 | LOCKS_EXCLUDED(dex_lock_); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 255 | |
Hiroshi Yamauchi | e9e3e69 | 2014-06-24 14:31:37 -0700 | [diff] [blame^] | 256 | mirror::DexCache* FindDexCache(const DexFile& dex_file) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 257 | LOCKS_EXCLUDED(dex_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 258 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | e9e3e69 | 2014-06-24 14:31:37 -0700 | [diff] [blame^] | 259 | bool IsDexFileRegistered(const DexFile& dex_file) |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 260 | LOCKS_EXCLUDED(dex_lock_) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | e9e3e69 | 2014-06-24 14:31:37 -0700 | [diff] [blame^] | 261 | void FixupDexCaches(mirror::ArtMethod* resolution_method) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 262 | LOCKS_EXCLUDED(dex_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 263 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 1d9f52b | 2011-10-13 10:50:45 -0700 | [diff] [blame] | 264 | |
jeffhao | 262bf46 | 2011-10-20 18:36:32 -0700 | [diff] [blame] | 265 | // Generate an oat file from a dex file |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 266 | bool GenerateOatFile(const char* dex_filename, |
Brian Carlstrom | d601af8 | 2012-01-06 10:15:19 -0800 | [diff] [blame] | 267 | int oat_fd, |
Vladimir Marko | 60836d5 | 2014-01-16 15:53:38 +0000 | [diff] [blame] | 268 | const char* oat_cache_filename, |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 269 | std::string* error_msg) |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 270 | LOCKS_EXCLUDED(Locks::mutator_lock_); |
jeffhao | 262bf46 | 2011-10-20 18:36:32 -0700 | [diff] [blame] | 271 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 272 | const OatFile* FindOatFileFromOatLocation(const std::string& location, |
| 273 | std::string* error_msg) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 274 | LOCKS_EXCLUDED(dex_lock_); |
| 275 | |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 276 | // Finds the oat file for a dex location, generating the oat file if |
| 277 | // it is missing or out of date. Returns the DexFile from within the |
| 278 | // created oat file. |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 279 | const DexFile* FindOrCreateOatFileForDexLocation(const char* dex_location, |
Brian Carlstrom | 756ee4e | 2013-10-03 15:46:12 -0700 | [diff] [blame] | 280 | uint32_t dex_location_checksum, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 281 | const char* oat_location, |
Andreas Gampe | 329d188 | 2014-04-08 10:32:19 -0700 | [diff] [blame] | 282 | std::vector<std::string>* error_msgs) |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 283 | LOCKS_EXCLUDED(dex_lock_, Locks::mutator_lock_); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 284 | // Find a DexFile within an OatFile given a DexFile location. Note |
| 285 | // that this returns null if the location checksum of the DexFile |
| 286 | // does not match the OatFile. |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 287 | const DexFile* FindDexFileInOatFileFromDexLocation(const char* location, |
Brian Carlstrom | 08cbf66 | 2013-12-10 16:52:57 -0800 | [diff] [blame] | 288 | const uint32_t* const location_checksum, |
Brian Carlstrom | 0e12bdc | 2014-05-14 17:44:28 -0700 | [diff] [blame] | 289 | InstructionSet isa, |
Andreas Gampe | 329d188 | 2014-04-08 10:32:19 -0700 | [diff] [blame] | 290 | std::vector<std::string>* error_msgs) |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 291 | LOCKS_EXCLUDED(dex_lock_, Locks::mutator_lock_); |
Brian Carlstrom | 5b332c8 | 2012-02-01 15:02:31 -0800 | [diff] [blame] | 292 | |
jeffhao | f6174e8 | 2012-01-31 16:14:17 -0800 | [diff] [blame] | 293 | |
Brian Carlstrom | 28db012 | 2012-10-18 16:20:41 -0700 | [diff] [blame] | 294 | // Returns true if oat file contains the dex file with the given location and checksum. |
Brian Carlstrom | afe2551 | 2012-06-27 17:02:58 -0700 | [diff] [blame] | 295 | static bool VerifyOatFileChecksums(const OatFile* oat_file, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 296 | const char* dex_location, |
| 297 | uint32_t dex_location_checksum, |
Brian Carlstrom | 2afe494 | 2014-05-19 10:25:33 -0700 | [diff] [blame] | 298 | InstructionSet instruction_set, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 299 | std::string* error_msg); |
Brian Carlstrom | afe2551 | 2012-06-27 17:02:58 -0700 | [diff] [blame] | 300 | |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 301 | // 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] | 302 | template <class T> |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 303 | mirror::ObjectArray<T>* AllocObjectArray(Thread* self, size_t length) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 304 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 305 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 306 | mirror::ObjectArray<mirror::Class>* AllocClassArray(Thread* self, size_t length) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 307 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
jeffhao | 98eacac | 2011-09-14 16:11:53 -0700 | [diff] [blame] | 308 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 309 | mirror::ObjectArray<mirror::String>* AllocStringArray(Thread* self, size_t length) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 310 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 311 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 312 | mirror::ObjectArray<mirror::ArtMethod>* AllocArtMethodArray(Thread* self, size_t length) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 313 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 314 | |
| 315 | mirror::IfTable* AllocIfTable(Thread* self, size_t ifcount) |
| 316 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 317 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 318 | mirror::ObjectArray<mirror::ArtField>* AllocArtFieldArray(Thread* self, size_t length) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 319 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 320 | |
| 321 | mirror::ObjectArray<mirror::StackTraceElement>* AllocStackTraceElementArray(Thread* self, |
| 322 | size_t length) |
| 323 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 324 | |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 325 | void VerifyClass(Handle<mirror::Class> klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 326 | bool VerifyClassUsingOatFile(const DexFile& dex_file, mirror::Class* klass, |
| 327 | mirror::Class::Status& oat_file_class_status) |
| 328 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 329 | void ResolveClassExceptionHandlerTypes(const DexFile& dex_file, |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 330 | Handle<mirror::Class> klass) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 331 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 332 | void ResolveMethodExceptionHandlerTypes(const DexFile& dex_file, mirror::ArtMethod* klass) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 333 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 334 | |
Mathieu Chartier | 2b7c4d1 | 2014-05-19 10:52:16 -0700 | [diff] [blame] | 335 | mirror::Class* CreateProxyClass(ScopedObjectAccessAlreadyRunnable& soa, jstring name, |
| 336 | jobjectArray interfaces, jobject loader, jobjectArray methods, |
| 337 | jobjectArray throws) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 338 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 339 | std::string GetDescriptorForProxy(mirror::Class* proxy_class) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 340 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 341 | mirror::ArtMethod* FindMethodForProxy(mirror::Class* proxy_class, |
| 342 | mirror::ArtMethod* proxy_method) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 343 | LOCKS_EXCLUDED(dex_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 344 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 345 | |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 346 | // 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] | 347 | const void* GetQuickOatCodeFor(mirror::ArtMethod* method) |
| 348 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 349 | const void* GetPortableOatCodeFor(mirror::ArtMethod* method, bool* have_portable_code) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 350 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 351 | |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 352 | // Get the oat code for a method from a method index. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 353 | const void* GetQuickOatCodeFor(const DexFile& dex_file, uint16_t class_def_idx, uint32_t method_idx) |
| 354 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 355 | 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] | 356 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | e35517a | 2012-10-30 18:49:55 -0700 | [diff] [blame] | 357 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 358 | pid_t GetClassesLockOwner(); // For SignalCatcher. |
| 359 | pid_t GetDexLockOwner(); // For SignalCatcher. |
Brian Carlstrom | 24a3c2e | 2011-10-17 18:07:52 -0700 | [diff] [blame] | 360 | |
Jeff Hao | 0aba0ba | 2013-06-03 14:49:28 -0700 | [diff] [blame] | 361 | const void* GetPortableResolutionTrampoline() const { |
| 362 | return portable_resolution_trampoline_; |
| 363 | } |
| 364 | |
Andreas Gampe | 2da8823 | 2014-02-27 12:26:20 -0800 | [diff] [blame] | 365 | const void* GetQuickGenericJniTrampoline() const { |
Dmitry Petrochenko | f0972a4 | 2014-05-16 17:43:39 +0700 | [diff] [blame] | 366 | return quick_generic_jni_trampoline_; |
| 367 | } |
Andreas Gampe | 2da8823 | 2014-02-27 12:26:20 -0800 | [diff] [blame] | 368 | |
Jeff Hao | 0aba0ba | 2013-06-03 14:49:28 -0700 | [diff] [blame] | 369 | const void* GetQuickResolutionTrampoline() const { |
| 370 | return quick_resolution_trampoline_; |
| 371 | } |
| 372 | |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 373 | const void* GetPortableImtConflictTrampoline() const { |
| 374 | return portable_imt_conflict_trampoline_; |
| 375 | } |
| 376 | |
| 377 | const void* GetQuickImtConflictTrampoline() const { |
| 378 | return quick_imt_conflict_trampoline_; |
| 379 | } |
| 380 | |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 381 | const void* GetQuickToInterpreterBridgeTrampoline() const { |
| 382 | return quick_to_interpreter_bridge_trampoline_; |
| 383 | } |
| 384 | |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 385 | InternTable* GetInternTable() const { |
| 386 | return intern_table_; |
| 387 | } |
| 388 | |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 389 | // Attempts to insert a class into a class table. Returns NULL if |
| 390 | // the class was inserted, otherwise returns an existing class with |
| 391 | // the same descriptor and ClassLoader. |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 392 | mirror::Class* InsertClass(const char* descriptor, mirror::Class* klass, size_t hash) |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 393 | LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) |
| 394 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 395 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 396 | // Special code to allocate an art method, use this instead of class->AllocObject. |
| 397 | mirror::ArtMethod* AllocArtMethod(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 61e019d | 2011-07-14 16:53:09 -0700 | [diff] [blame] | 398 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 399 | private: |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 400 | const OatFile::OatMethod GetOatMethodFor(mirror::ArtMethod* method) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 401 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
TDYa127 | 8532191 | 2012-04-01 15:24:56 -0700 | [diff] [blame] | 402 | |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 403 | OatFile& GetImageOatFile(gc::space::ImageSpace* space) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 404 | LOCKS_EXCLUDED(dex_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 405 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 406 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 407 | void FinishInit(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 408 | |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 409 | // For early bootstrapping by Init |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 410 | 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] | 411 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 412 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 413 | // Alloc* convenience functions to avoid needing to pass in mirror::Class* |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 414 | // values that are known to the ClassLinker such as |
| 415 | // kObjectArrayClass and kJavaLangString etc. |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 416 | mirror::Class* AllocClass(Thread* self, uint32_t class_size) |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 417 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 418 | mirror::DexCache* AllocDexCache(Thread* self, const DexFile& dex_file) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 419 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 420 | mirror::ArtField* AllocArtField(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | bdb0391 | 2011-09-14 00:55:44 -0700 | [diff] [blame] | 421 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 422 | mirror::Class* CreatePrimitiveClass(Thread* self, Primitive::Type type) |
| 423 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 424 | mirror::Class* InitializePrimitiveClass(mirror::Class* primitive_class, Primitive::Type type) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 425 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 5b8e4c8 | 2011-09-18 01:38:59 -0700 | [diff] [blame] | 426 | |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 427 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 428 | mirror::Class* CreateArrayClass(Thread* self, const char* descriptor, |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 429 | Handle<mirror::ClassLoader> class_loader) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 430 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | a331b3c | 2011-07-18 17:47:56 -0700 | [diff] [blame] | 431 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 432 | void AppendToBootClassPath(const DexFile& dex_file) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 433 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 434 | void AppendToBootClassPath(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 435 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 436 | |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 437 | void ConstructFieldMap(const DexFile& dex_file, const DexFile::ClassDef& dex_class_def, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 438 | mirror::Class* c, SafeMap<uint32_t, mirror::ArtField*>& field_map) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 439 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 5fe594f | 2011-09-08 12:33:17 -0700 | [diff] [blame] | 440 | |
Ian Rogers | 6fac447 | 2014-02-25 17:01:10 -0800 | [diff] [blame] | 441 | uint32_t SizeOfClass(const DexFile& dex_file, |
Brian Carlstrom | 4873d46 | 2011-08-21 15:23:39 -0700 | [diff] [blame] | 442 | const DexFile::ClassDef& dex_class_def); |
| 443 | |
Brian Carlstrom | f615a61 | 2011-07-23 12:50:34 -0700 | [diff] [blame] | 444 | void LoadClass(const DexFile& dex_file, |
| 445 | const DexFile::ClassDef& dex_class_def, |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 446 | Handle<mirror::Class> klass, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 447 | mirror::ClassLoader* class_loader) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 448 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 449 | void LoadClassMembers(const DexFile& dex_file, |
| 450 | const byte* class_data, |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 451 | Handle<mirror::Class> klass, |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 452 | mirror::ClassLoader* class_loader, |
| 453 | const OatFile::OatClass* oat_class) |
| 454 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 455 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 456 | void LoadField(const DexFile& dex_file, const ClassDataItemIterator& it, |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 457 | Handle<mirror::Class> klass, Handle<mirror::ArtField> dst) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 458 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 459 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 460 | mirror::ArtMethod* LoadMethod(Thread* self, const DexFile& dex_file, |
| 461 | const ClassDataItemIterator& dex_method, |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 462 | Handle<mirror::Class> klass) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 463 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 934486c | 2011-07-12 23:42:50 -0700 | [diff] [blame] | 464 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 465 | void FixupStaticTrampolines(mirror::Class* klass) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 466 | |
| 467 | // Finds the associated oat class for a dex_file and descriptor |
Vladimir Marko | d3c5beb | 2014-04-11 16:32:51 +0100 | [diff] [blame] | 468 | OatFile::OatClass GetOatClass(const DexFile& dex_file, uint16_t class_def_idx) |
Ian Rogers | 33e9566 | 2013-05-20 20:29:14 -0700 | [diff] [blame] | 469 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 1984651 | 2012-02-24 11:42:47 -0800 | [diff] [blame] | 470 | |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 471 | void RegisterDexFileLocked(const DexFile& dex_file, Handle<mirror::DexCache> dex_cache) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 472 | EXCLUSIVE_LOCKS_REQUIRED(dex_lock_) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 473 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Hiroshi Yamauchi | e9e3e69 | 2014-06-24 14:31:37 -0700 | [diff] [blame^] | 474 | bool IsDexFileRegisteredLocked(const DexFile& dex_file) |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 475 | SHARED_LOCKS_REQUIRED(dex_lock_, Locks::mutator_lock_); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 476 | |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 477 | bool InitializeClass(Handle<mirror::Class> klass, bool can_run_clinit, |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 478 | bool can_init_parents) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 479 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 480 | bool WaitForInitializeClass(Handle<mirror::Class> klass, Thread* self, |
Mathieu Chartier | c528dba | 2013-11-26 12:00:11 -0800 | [diff] [blame] | 481 | ObjectLock<mirror::Class>& lock); |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 482 | bool ValidateSuperClassDescriptors(Handle<mirror::Class> klass) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 483 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 484 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 485 | bool IsSameDescriptorInDifferentClassContexts(Thread* self, const char* descriptor, |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 486 | Handle<mirror::ClassLoader> class_loader1, |
| 487 | Handle<mirror::ClassLoader> class_loader2) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 488 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 489 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 490 | bool IsSameMethodSignatureInDifferentClassContexts(Thread* self, mirror::ArtMethod* method, |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 491 | mirror::Class* klass1, |
| 492 | mirror::Class* klass2) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 493 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 494 | |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 495 | bool LinkClass(Thread* self, Handle<mirror::Class> klass, |
| 496 | Handle<mirror::ObjectArray<mirror::Class>> interfaces) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 497 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 498 | |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 499 | bool LinkSuperClass(Handle<mirror::Class> klass) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 500 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 501 | |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 502 | bool LoadSuperAndInterfaces(Handle<mirror::Class> klass, const DexFile& dex_file) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 503 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 504 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 505 | bool LinkMethods(Thread* self, Handle<mirror::Class> klass, |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 506 | Handle<mirror::ObjectArray<mirror::Class>> interfaces) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 507 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 508 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 509 | bool LinkVirtualMethods(Thread* self, Handle<mirror::Class> klass) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 510 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 511 | |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 512 | bool LinkInterfaceMethods(Handle<mirror::Class> klass, |
| 513 | Handle<mirror::ObjectArray<mirror::Class>> interfaces) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 514 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 515 | |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 516 | bool LinkStaticFields(Handle<mirror::Class> klass) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 517 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 518 | bool LinkInstanceFields(Handle<mirror::Class> klass) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 519 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 520 | bool LinkFields(Handle<mirror::Class> klass, bool is_static) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 521 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 522 | void LinkCode(Handle<mirror::ArtMethod> method, const OatFile::OatClass* oat_class, |
Dmitry Petrochenko | f0972a4 | 2014-05-16 17:43:39 +0700 | [diff] [blame] | 523 | const DexFile& dex_file, uint32_t dex_method_index, uint32_t method_index) |
| 524 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 525 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 526 | |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 527 | void CreateReferenceInstanceOffsets(Handle<mirror::Class> klass) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 528 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 529 | void CreateReferenceStaticOffsets(Handle<mirror::Class> klass) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 530 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 531 | void CreateReferenceOffsets(Handle<mirror::Class> klass, bool is_static, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 532 | uint32_t reference_offsets) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 533 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 534 | |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 535 | // For use by ImageWriter to find DexCaches for its roots |
Hiroshi Yamauchi | e9e3e69 | 2014-06-24 14:31:37 -0700 | [diff] [blame^] | 536 | ReaderWriterMutex* DexLock() |
| 537 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) LOCK_RETURNED(dex_lock_) { |
| 538 | return &dex_lock_; |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 539 | } |
Hiroshi Yamauchi | e9e3e69 | 2014-06-24 14:31:37 -0700 | [diff] [blame^] | 540 | size_t GetDexCacheCount() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_, dex_lock_) { |
| 541 | return dex_caches_.size(); |
| 542 | } |
| 543 | 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] | 544 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 545 | const OatFile* FindOpenedOatFileForDexFile(const DexFile& dex_file) |
Ian Rogers | 33e9566 | 2013-05-20 20:29:14 -0700 | [diff] [blame] | 546 | LOCKS_EXCLUDED(dex_lock_) |
| 547 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 548 | const OatFile* FindOpenedOatFileFromDexLocation(const char* dex_location, |
Brian Carlstrom | 08cbf66 | 2013-12-10 16:52:57 -0800 | [diff] [blame] | 549 | const uint32_t* const dex_location_checksum) |
Ian Rogers | 719d1a3 | 2014-03-06 12:13:39 -0800 | [diff] [blame] | 550 | LOCKS_EXCLUDED(dex_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 551 | const OatFile* FindOpenedOatFileFromOatLocation(const std::string& oat_location) |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 552 | LOCKS_EXCLUDED(dex_lock_); |
| 553 | const DexFile* FindDexFileInOatLocation(const char* dex_location, |
Ian Rogers | e3359f7 | 2013-06-11 15:14:11 -0700 | [diff] [blame] | 554 | uint32_t dex_location_checksum, |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 555 | const char* oat_location, |
| 556 | std::string* error_msg) |
| 557 | LOCKS_EXCLUDED(dex_lock_); |
Ian Rogers | e3359f7 | 2013-06-11 15:14:11 -0700 | [diff] [blame] | 558 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 559 | const DexFile* VerifyAndOpenDexFileFromOatFile(const std::string& oat_file_location, |
| 560 | const char* dex_location, |
| 561 | std::string* error_msg, |
| 562 | bool* open_failed) |
| 563 | LOCKS_EXCLUDED(dex_lock_); |
Brian Carlstrom | fad7143 | 2011-10-16 20:25:10 -0700 | [diff] [blame] | 564 | |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 565 | mirror::ArtMethod* CreateProxyConstructor(Thread* self, Handle<mirror::Class> klass, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 566 | mirror::Class* proxy_class) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 567 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 568 | mirror::ArtMethod* CreateProxyMethod(Thread* self, Handle<mirror::Class> klass, |
| 569 | Handle<mirror::ArtMethod> prototype) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 570 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Jesse Wilson | 95caa79 | 2011-10-12 18:14:17 -0400 | [diff] [blame] | 571 | |
Brian Carlstrom | 4a96b60 | 2011-07-26 16:40:23 -0700 | [diff] [blame] | 572 | std::vector<const DexFile*> boot_class_path_; |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 573 | |
Ian Rogers | 1bf8d4d | 2013-05-30 00:18:49 -0700 | [diff] [blame] | 574 | mutable ReaderWriterMutex dex_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; |
Mathieu Chartier | 893263b | 2014-03-04 11:07:42 -0800 | [diff] [blame] | 575 | std::vector<size_t> new_dex_cache_roots_ GUARDED_BY(dex_lock_);; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 576 | std::vector<mirror::DexCache*> dex_caches_ GUARDED_BY(dex_lock_); |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 577 | std::vector<const OatFile*> oat_files_ GUARDED_BY(dex_lock_); |
Brian Carlstrom | 47d237a | 2011-10-18 15:08:33 -0700 | [diff] [blame] | 578 | |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 579 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 580 | // multimap from a string hash code of a class descriptor to |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 581 | // mirror::Class* instances. Results should be compared for a matching |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 582 | // Class::descriptor_ and Class::class_loader_. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 583 | typedef std::multimap<size_t, mirror::Class*> Table; |
Hiroshi Yamauchi | a91a4bc | 2014-06-13 16:44:55 -0700 | [diff] [blame] | 584 | // This contains strong roots. To enable concurrent root scanning of |
| 585 | // 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] | 586 | Table class_table_ GUARDED_BY(Locks::classlinker_classes_lock_); |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 587 | std::vector<std::pair<size_t, mirror::Class*>> new_class_roots_; |
Elliott Hughes | f834936 | 2012-06-18 15:00:06 -0700 | [diff] [blame] | 588 | |
Ian Rogers | 7dfb28c | 2013-08-22 08:18:36 -0700 | [diff] [blame] | 589 | // Do we need to search dex caches to find image classes? |
| 590 | bool dex_cache_image_class_lookup_required_; |
| 591 | // Number of times we've searched dex caches for a class. After a certain number of misses we move |
| 592 | // the classes into the class_table_ to avoid dex cache based searches. |
| 593 | AtomicInteger failed_dex_cache_class_lookups_; |
| 594 | |
| 595 | mirror::Class* LookupClassFromTableLocked(const char* descriptor, |
| 596 | const mirror::ClassLoader* class_loader, |
| 597 | size_t hash) |
| 598 | SHARED_LOCKS_REQUIRED(Locks::classlinker_classes_lock_, Locks::mutator_lock_); |
| 599 | |
| 600 | void MoveImageClassesToClassTable() LOCKS_EXCLUDED(Locks::classlinker_classes_lock_) |
| 601 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 602 | mirror::Class* LookupClassFromImage(const char* descriptor) |
| 603 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 604 | |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 605 | // indexes into class_roots_. |
| 606 | // needs to be kept in sync with class_roots_descriptors_. |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 607 | enum ClassRoot { |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 608 | kJavaLangClass, |
| 609 | kJavaLangObject, |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 610 | kClassArrayClass, |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 611 | kObjectArrayClass, |
| 612 | kJavaLangString, |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 613 | kJavaLangDexCache, |
Elliott Hughes | bf61ba3 | 2011-10-11 10:53:09 -0700 | [diff] [blame] | 614 | kJavaLangRefReference, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 615 | kJavaLangReflectArtField, |
| 616 | kJavaLangReflectArtMethod, |
Ian Rogers | 466bb25 | 2011-10-14 03:29:56 -0700 | [diff] [blame] | 617 | kJavaLangReflectProxy, |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 618 | kJavaLangStringArrayClass, |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 619 | kJavaLangReflectArtFieldArrayClass, |
| 620 | kJavaLangReflectArtMethodArrayClass, |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 621 | kJavaLangClassLoader, |
Ian Rogers | 5167c97 | 2012-02-03 10:41:20 -0800 | [diff] [blame] | 622 | kJavaLangThrowable, |
jeffhao | 8cd6dda | 2012-02-22 10:15:34 -0800 | [diff] [blame] | 623 | kJavaLangClassNotFoundException, |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 624 | kJavaLangStackTraceElement, |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 625 | kPrimitiveBoolean, |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 626 | kPrimitiveByte, |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 627 | kPrimitiveChar, |
| 628 | kPrimitiveDouble, |
| 629 | kPrimitiveFloat, |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 630 | kPrimitiveInt, |
| 631 | kPrimitiveLong, |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 632 | kPrimitiveShort, |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 633 | kPrimitiveVoid, |
Elliott Hughes | d8ddfd5 | 2011-08-15 14:32:53 -0700 | [diff] [blame] | 634 | kBooleanArrayClass, |
| 635 | kByteArrayClass, |
| 636 | kCharArrayClass, |
| 637 | kDoubleArrayClass, |
| 638 | kFloatArrayClass, |
| 639 | kIntArrayClass, |
| 640 | kLongArrayClass, |
| 641 | kShortArrayClass, |
Shih-wei Liao | 55df06b | 2011-08-26 14:39:27 -0700 | [diff] [blame] | 642 | kJavaLangStackTraceElementArrayClass, |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 643 | kClassRootsMax, |
| 644 | }; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 645 | mirror::ObjectArray<mirror::Class>* class_roots_; |
Brian Carlstrom | 913af1b | 2011-07-23 21:41:13 -0700 | [diff] [blame] | 646 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 647 | mirror::Class* GetClassRoot(ClassRoot class_root) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | 74eb46a | 2011-08-02 20:10:14 -0700 | [diff] [blame] | 648 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 649 | void SetClassRoot(ClassRoot class_root, mirror::Class* klass) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 650 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 651 | |
Hiroshi Yamauchi | e9e3e69 | 2014-06-24 14:31:37 -0700 | [diff] [blame^] | 652 | mirror::ObjectArray<mirror::Class>* GetClassRoots() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 653 | mirror::ObjectArray<mirror::Class>* class_roots = |
| 654 | ReadBarrier::BarrierForRoot<mirror::ObjectArray<mirror::Class>, kWithReadBarrier>( |
| 655 | &class_roots_); |
| 656 | DCHECK(class_roots != NULL); |
| 657 | return class_roots; |
Brian Carlstrom | 34f426c | 2011-10-04 12:58:02 -0700 | [diff] [blame] | 658 | } |
| 659 | |
Elliott Hughes | 418d20f | 2011-09-22 14:00:39 -0700 | [diff] [blame] | 660 | static const char* class_roots_descriptors_[]; |
Brian Carlstrom | a663ea5 | 2011-08-19 23:33:41 -0700 | [diff] [blame] | 661 | |
| 662 | const char* GetClassRootDescriptor(ClassRoot class_root) { |
| 663 | const char* descriptor = class_roots_descriptors_[class_root]; |
| 664 | CHECK(descriptor != NULL); |
| 665 | return descriptor; |
| 666 | } |
| 667 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 668 | // The interface table used by all arrays. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 669 | mirror::IfTable* array_iftable_; |
Carl Shapiro | 565f507 | 2011-07-10 13:39:43 -0700 | [diff] [blame] | 670 | |
Ian Rogers | 9837939 | 2014-02-24 16:53:16 -0800 | [diff] [blame] | 671 | // A cache of the last FindArrayClass results. The cache serves to avoid creating array class |
| 672 | // descriptors for the sake of performing FindClass. |
| 673 | static constexpr size_t kFindArrayCacheSize = 16; |
| 674 | mirror::Class* find_array_class_cache_[kFindArrayCacheSize]; |
| 675 | size_t find_array_class_cache_next_victim_; |
| 676 | |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 677 | bool init_done_; |
Mathieu Chartier | 893263b | 2014-03-04 11:07:42 -0800 | [diff] [blame] | 678 | bool log_new_dex_caches_roots_ GUARDED_BY(dex_lock_); |
| 679 | bool log_new_class_table_roots_ GUARDED_BY(Locks::classlinker_classes_lock_); |
Brian Carlstrom | 75cb3b4 | 2011-07-28 02:13:36 -0700 | [diff] [blame] | 680 | |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 681 | InternTable* intern_table_; |
| 682 | |
Jeff Hao | 0aba0ba | 2013-06-03 14:49:28 -0700 | [diff] [blame] | 683 | const void* portable_resolution_trampoline_; |
| 684 | const void* quick_resolution_trampoline_; |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 685 | const void* portable_imt_conflict_trampoline_; |
| 686 | const void* quick_imt_conflict_trampoline_; |
Andreas Gampe | 2da8823 | 2014-02-27 12:26:20 -0800 | [diff] [blame] | 687 | const void* quick_generic_jni_trampoline_; |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 688 | const void* quick_to_interpreter_bridge_trampoline_; |
Jeff Hao | 0aba0ba | 2013-06-03 14:49:28 -0700 | [diff] [blame] | 689 | |
Brian Carlstrom | 34f426c | 2011-10-04 12:58:02 -0700 | [diff] [blame] | 690 | friend class ImageWriter; // for GetClassRoots |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 691 | FRIEND_TEST(ClassLinkerTest, ClassRootDescriptors); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 692 | FRIEND_TEST(mirror::DexCacheTest, Open); |
Brian Carlstrom | ae82698 | 2011-11-09 01:33:42 -0800 | [diff] [blame] | 693 | FRIEND_TEST(ExceptionTest, FindExceptionHandler); |
| 694 | FRIEND_TEST(ObjectTest, AllocObjectArray); |
Carl Shapiro | 0e5d75d | 2011-07-06 18:28:37 -0700 | [diff] [blame] | 695 | DISALLOW_COPY_AND_ASSIGN(ClassLinker); |
| 696 | }; |
| 697 | |
| 698 | } // namespace art |
| 699 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 700 | #endif // ART_RUNTIME_CLASS_LINKER_H_ |