Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_RUNTIME_CLASS_TABLE_H_ |
| 18 | #define ART_RUNTIME_CLASS_TABLE_H_ |
| 19 | |
| 20 | #include <string> |
| 21 | #include <utility> |
| 22 | #include <vector> |
| 23 | |
| 24 | #include "base/allocator.h" |
| 25 | #include "base/hash_set.h" |
| 26 | #include "base/macros.h" |
| 27 | #include "base/mutex.h" |
| 28 | #include "dex_file.h" |
| 29 | #include "gc_root.h" |
Mathieu Chartier | bc5a795 | 2016-10-17 15:46:31 -0700 | [diff] [blame] | 30 | #include "obj_ptr.h" |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 31 | #include "object_callbacks.h" |
| 32 | #include "runtime.h" |
| 33 | |
| 34 | namespace art { |
| 35 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 36 | class OatFile; |
| 37 | |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 38 | namespace mirror { |
| 39 | class ClassLoader; |
| 40 | } // namespace mirror |
| 41 | |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 42 | // Each loader has a ClassTable |
| 43 | class ClassTable { |
| 44 | public: |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 45 | class TableSlot { |
| 46 | public: |
| 47 | TableSlot() : data_(0u) {} |
| 48 | |
| 49 | TableSlot(const TableSlot& copy) : data_(copy.data_.LoadRelaxed()) {} |
| 50 | |
| 51 | explicit TableSlot(ObjPtr<mirror::Class> klass); |
| 52 | |
| 53 | TableSlot(ObjPtr<mirror::Class> klass, uint32_t descriptor_hash); |
| 54 | |
| 55 | TableSlot& operator=(const TableSlot& copy) { |
| 56 | data_.StoreRelaxed(copy.data_.LoadRelaxed()); |
| 57 | return *this; |
| 58 | } |
| 59 | |
| 60 | bool IsNull() const REQUIRES_SHARED(Locks::mutator_lock_) { |
| 61 | return Read<kWithoutReadBarrier>() == nullptr; |
| 62 | } |
| 63 | |
| 64 | uint32_t Hash() const { |
| 65 | return MaskHash(data_.LoadRelaxed()); |
| 66 | } |
| 67 | |
| 68 | static uint32_t MaskHash(uint32_t hash) { |
| 69 | return hash & kHashMask; |
| 70 | } |
| 71 | |
| 72 | bool MaskedHashEquals(uint32_t other) const { |
| 73 | return MaskHash(other) == Hash(); |
| 74 | } |
| 75 | |
Mathieu Chartier | db70ce5 | 2016-12-12 11:06:59 -0800 | [diff] [blame] | 76 | static uint32_t HashDescriptor(ObjPtr<mirror::Class> klass) |
| 77 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 78 | |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 79 | template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
| 80 | mirror::Class* Read() const REQUIRES_SHARED(Locks::mutator_lock_); |
| 81 | |
| 82 | // NO_THREAD_SAFETY_ANALYSIS since the visitor may require heap bitmap lock. |
| 83 | template<typename Visitor> |
| 84 | void VisitRoot(const Visitor& visitor) const NO_THREAD_SAFETY_ANALYSIS; |
| 85 | |
| 86 | private: |
| 87 | // Extract a raw pointer from an address. |
| 88 | static ObjPtr<mirror::Class> ExtractPtr(uint32_t data) |
| 89 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 90 | |
| 91 | static uint32_t Encode(ObjPtr<mirror::Class> klass, uint32_t hash_bits) |
| 92 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 93 | |
| 94 | // Data contains the class pointer GcRoot as well as the low bits of the descriptor hash. |
| 95 | mutable Atomic<uint32_t> data_; |
| 96 | static const uint32_t kHashMask = kObjectAlignment - 1; |
| 97 | }; |
| 98 | |
| 99 | using DescriptorHashPair = std::pair<const char*, uint32_t>; |
| 100 | |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 101 | class ClassDescriptorHashEquals { |
| 102 | public: |
| 103 | // uint32_t for cross compilation. |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 104 | uint32_t operator()(const TableSlot& slot) const NO_THREAD_SAFETY_ANALYSIS; |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 105 | // Same class loader and descriptor. |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 106 | bool operator()(const TableSlot& a, const TableSlot& b) const |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 107 | NO_THREAD_SAFETY_ANALYSIS; |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 108 | // Same descriptor. |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 109 | bool operator()(const TableSlot& a, const DescriptorHashPair& b) const |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 110 | NO_THREAD_SAFETY_ANALYSIS; |
| 111 | // uint32_t for cross compilation. |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 112 | uint32_t operator()(const DescriptorHashPair& pair) const NO_THREAD_SAFETY_ANALYSIS; |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 113 | }; |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 114 | |
| 115 | class TableSlotEmptyFn { |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 116 | public: |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 117 | void MakeEmpty(TableSlot& item) const NO_THREAD_SAFETY_ANALYSIS { |
| 118 | item = TableSlot(); |
| 119 | DCHECK(IsEmpty(item)); |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 120 | } |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 121 | bool IsEmpty(const TableSlot& item) const NO_THREAD_SAFETY_ANALYSIS { |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 122 | return item.IsNull(); |
| 123 | } |
| 124 | }; |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 125 | |
| 126 | // Hash set that hashes class descriptor, and compares descriptors and class loaders. Results |
| 127 | // should be compared for a matching class descriptor and class loader. |
| 128 | typedef HashSet<TableSlot, |
| 129 | TableSlotEmptyFn, |
| 130 | ClassDescriptorHashEquals, |
| 131 | ClassDescriptorHashEquals, |
| 132 | TrackingAllocator<TableSlot, kAllocatorTagClassTable>> ClassSet; |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 133 | |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 134 | ClassTable(); |
| 135 | |
| 136 | // Used by image writer for checking. |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 137 | bool Contains(ObjPtr<mirror::Class> klass) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 138 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 139 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 140 | |
| 141 | // Freeze the current class tables by allocating a new table and never updating or modifying the |
| 142 | // existing table. This helps prevents dirty pages after caused by inserting after zygote fork. |
| 143 | void FreezeSnapshot() |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 144 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 145 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 146 | |
| 147 | // Returns the number of classes in previous snapshots. |
Vladimir Marko | c5798bf | 2016-12-09 10:20:54 +0000 | [diff] [blame] | 148 | size_t NumZygoteClasses(ObjPtr<mirror::ClassLoader> defining_loader) const |
| 149 | REQUIRES(!lock_) |
| 150 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 151 | |
| 152 | // Returns all off the classes in the lastest snapshot. |
Vladimir Marko | c5798bf | 2016-12-09 10:20:54 +0000 | [diff] [blame] | 153 | size_t NumNonZygoteClasses(ObjPtr<mirror::ClassLoader> defining_loader) const |
| 154 | REQUIRES(!lock_) |
| 155 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 156 | |
| 157 | // Update a class in the table with the new class. Returns the existing class which was replaced. |
| 158 | mirror::Class* UpdateClass(const char* descriptor, mirror::Class* new_klass, size_t hash) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 159 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 160 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 161 | |
Mathieu Chartier | e4275c0 | 2015-08-06 15:34:15 -0700 | [diff] [blame] | 162 | // NO_THREAD_SAFETY_ANALYSIS for object marking requiring heap bitmap lock. |
| 163 | template<class Visitor> |
| 164 | void VisitRoots(Visitor& visitor) |
Mathieu Chartier | 00310e0 | 2015-10-17 12:46:42 -0700 | [diff] [blame] | 165 | NO_THREAD_SAFETY_ANALYSIS |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 166 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 167 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 168 | |
Mathieu Chartier | e4275c0 | 2015-08-06 15:34:15 -0700 | [diff] [blame] | 169 | template<class Visitor> |
| 170 | void VisitRoots(const Visitor& visitor) |
Mathieu Chartier | 00310e0 | 2015-10-17 12:46:42 -0700 | [diff] [blame] | 171 | NO_THREAD_SAFETY_ANALYSIS |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 172 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 173 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 174 | |
Mathieu Chartier | 1aa8ec2 | 2016-02-01 10:34:47 -0800 | [diff] [blame] | 175 | // Stops visit if the visitor returns false. |
| 176 | template <typename Visitor> |
| 177 | bool Visit(Visitor& visitor) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 178 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 179 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | db70ce5 | 2016-12-12 11:06:59 -0800 | [diff] [blame] | 180 | template <typename Visitor> |
| 181 | bool Visit(const Visitor& visitor) |
| 182 | REQUIRES(!lock_) |
| 183 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 184 | |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 185 | // Return the first class that matches the descriptor. Returns null if there are none. |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 186 | mirror::Class* Lookup(const char* descriptor, size_t hash) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 187 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 188 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 189 | |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 190 | // Return the first class that matches the descriptor of klass. Returns null if there are none. |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 191 | mirror::Class* LookupByDescriptor(ObjPtr<mirror::Class> klass) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 192 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 193 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 194 | |
Vladimir Marko | cd556b0 | 2017-02-03 11:47:34 +0000 | [diff] [blame] | 195 | // Try to insert a class and return the inserted class if successful. If another class |
| 196 | // with the same descriptor is already in the table, return the existing entry. |
| 197 | ObjPtr<mirror::Class> TryInsert(ObjPtr<mirror::Class> klass) |
| 198 | REQUIRES(!lock_) |
| 199 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 200 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 201 | void Insert(ObjPtr<mirror::Class> klass) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 202 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 203 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 204 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 205 | void InsertWithHash(ObjPtr<mirror::Class> klass, size_t hash) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 206 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 207 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 208 | |
| 209 | // Returns true if the class was found and removed, false otherwise. |
| 210 | bool Remove(const char* descriptor) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 211 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 212 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 00310e0 | 2015-10-17 12:46:42 -0700 | [diff] [blame] | 213 | |
Mathieu Chartier | c9dbb1d | 2016-06-03 17:47:32 -0700 | [diff] [blame] | 214 | // Return true if we inserted the strong root, false if it already exists. |
Mathieu Chartier | bc5a795 | 2016-10-17 15:46:31 -0700 | [diff] [blame] | 215 | bool InsertStrongRoot(ObjPtr<mirror::Object> obj) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 216 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 217 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 218 | |
Vladimir Marko | 1bc4b17 | 2016-10-24 16:53:39 +0000 | [diff] [blame] | 219 | // Return true if we inserted the oat file, false if it already exists. |
| 220 | bool InsertOatFile(const OatFile* oat_file) |
| 221 | REQUIRES(!lock_) |
| 222 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 223 | |
Mathieu Chartier | 41dc8ce | 2015-12-04 15:07:48 -0800 | [diff] [blame] | 224 | // Combines all of the tables into one class set. |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 225 | size_t WriteToMemory(uint8_t* ptr) const |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 226 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 227 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 228 | |
| 229 | // Read a table from ptr and put it at the front of the class set. |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 230 | size_t ReadFromMemory(uint8_t* ptr) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 231 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 232 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 233 | |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 234 | // Add a class set to the front of classes. |
| 235 | void AddClassSet(ClassSet&& set) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 236 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 237 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 238 | |
Mathieu Chartier | c9dbb1d | 2016-06-03 17:47:32 -0700 | [diff] [blame] | 239 | // Clear strong roots (other than classes themselves). |
| 240 | void ClearStrongRoots() |
| 241 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 242 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | c9dbb1d | 2016-06-03 17:47:32 -0700 | [diff] [blame] | 243 | |
Mathieu Chartier | 92091bd | 2016-05-10 18:13:20 -0700 | [diff] [blame] | 244 | ReaderWriterMutex& GetLock() { |
| 245 | return lock_; |
| 246 | } |
| 247 | |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 248 | private: |
Vladimir Marko | 6ad2f6d | 2017-01-18 15:22:59 +0000 | [diff] [blame] | 249 | void CopyWithoutLocks(const ClassTable& source_table) NO_THREAD_SAFETY_ANALYSIS; |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 250 | void InsertWithoutLocks(ObjPtr<mirror::Class> klass) NO_THREAD_SAFETY_ANALYSIS; |
Mathieu Chartier | 496577f | 2016-09-20 15:33:31 -0700 | [diff] [blame] | 251 | |
Vladimir Marko | c5798bf | 2016-12-09 10:20:54 +0000 | [diff] [blame] | 252 | size_t CountDefiningLoaderClasses(ObjPtr<mirror::ClassLoader> defining_loader, |
| 253 | const ClassSet& set) const |
| 254 | REQUIRES(lock_) |
| 255 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 256 | |
Vladimir Marko | 1bc4b17 | 2016-10-24 16:53:39 +0000 | [diff] [blame] | 257 | // Return true if we inserted the oat file, false if it already exists. |
| 258 | bool InsertOatFileLocked(const OatFile* oat_file) |
| 259 | REQUIRES(lock_) |
| 260 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 261 | |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 262 | // Lock to guard inserting and removing. |
| 263 | mutable ReaderWriterMutex lock_; |
Mathieu Chartier | 90ef3db | 2015-08-04 15:19:41 -0700 | [diff] [blame] | 264 | // We have a vector to help prevent dirty pages after the zygote forks by calling FreezeSnapshot. |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 265 | std::vector<ClassSet> classes_ GUARDED_BY(lock_); |
Mathieu Chartier | c9dbb1d | 2016-06-03 17:47:32 -0700 | [diff] [blame] | 266 | // Extra strong roots that can be either dex files or dex caches. Dex files used by the class |
| 267 | // loader which may not be owned by the class loader must be held strongly live. Also dex caches |
| 268 | // are held live to prevent them being unloading once they have classes in them. |
| 269 | std::vector<GcRoot<mirror::Object>> strong_roots_ GUARDED_BY(lock_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 270 | // Keep track of oat files with GC roots associated with dex caches in `strong_roots_`. |
| 271 | std::vector<const OatFile*> oat_files_ GUARDED_BY(lock_); |
Mathieu Chartier | 496577f | 2016-09-20 15:33:31 -0700 | [diff] [blame] | 272 | |
| 273 | friend class ImageWriter; // for InsertWithoutLocks. |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 274 | }; |
| 275 | |
| 276 | } // namespace art |
| 277 | |
| 278 | #endif // ART_RUNTIME_CLASS_TABLE_H_ |