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" |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 28 | #include "gc_root.h" |
Mathieu Chartier | bc5a795 | 2016-10-17 15:46:31 -0700 | [diff] [blame] | 29 | #include "obj_ptr.h" |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 30 | |
| 31 | namespace art { |
| 32 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 33 | class OatFile; |
| 34 | |
Vladimir Marko | 7452797 | 2016-11-29 15:57:32 +0000 | [diff] [blame] | 35 | namespace linker { |
| 36 | class ImageWriter; |
| 37 | } // namespace linker |
| 38 | |
| 39 | namespace linker { |
| 40 | class OatWriter; |
| 41 | } // namespace linker |
| 42 | |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 43 | namespace mirror { |
Igor Murashkin | 2ffb703 | 2017-11-08 13:35:21 -0800 | [diff] [blame] | 44 | class Class; |
| 45 | class ClassLoader; |
| 46 | class Object; |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 47 | } // namespace mirror |
| 48 | |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 49 | // Each loader has a ClassTable |
| 50 | class ClassTable { |
| 51 | public: |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 52 | class TableSlot { |
| 53 | public: |
| 54 | TableSlot() : data_(0u) {} |
| 55 | |
Orion Hodson | 88591fe | 2018-03-06 13:35:43 +0000 | [diff] [blame] | 56 | TableSlot(const TableSlot& copy) : data_(copy.data_.load(std::memory_order_relaxed)) {} |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 57 | |
| 58 | explicit TableSlot(ObjPtr<mirror::Class> klass); |
| 59 | |
| 60 | TableSlot(ObjPtr<mirror::Class> klass, uint32_t descriptor_hash); |
| 61 | |
| 62 | TableSlot& operator=(const TableSlot& copy) { |
Orion Hodson | 88591fe | 2018-03-06 13:35:43 +0000 | [diff] [blame] | 63 | data_.store(copy.data_.load(std::memory_order_relaxed), std::memory_order_relaxed); |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 64 | return *this; |
| 65 | } |
| 66 | |
Vladimir Marko | c6934e3 | 2019-04-10 11:40:01 +0100 | [diff] [blame] | 67 | bool IsNull() const REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 68 | |
| 69 | uint32_t Hash() const { |
Orion Hodson | 88591fe | 2018-03-06 13:35:43 +0000 | [diff] [blame] | 70 | return MaskHash(data_.load(std::memory_order_relaxed)); |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static uint32_t MaskHash(uint32_t hash) { |
| 74 | return hash & kHashMask; |
| 75 | } |
| 76 | |
| 77 | bool MaskedHashEquals(uint32_t other) const { |
| 78 | return MaskHash(other) == Hash(); |
| 79 | } |
| 80 | |
| 81 | template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Vladimir Marko | 1fe5839 | 2019-04-10 16:14:56 +0100 | [diff] [blame] | 82 | ObjPtr<mirror::Class> Read() const REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 83 | |
| 84 | // NO_THREAD_SAFETY_ANALYSIS since the visitor may require heap bitmap lock. |
| 85 | template<typename Visitor> |
| 86 | void VisitRoot(const Visitor& visitor) const NO_THREAD_SAFETY_ANALYSIS; |
| 87 | |
| 88 | private: |
| 89 | // Extract a raw pointer from an address. |
| 90 | static ObjPtr<mirror::Class> ExtractPtr(uint32_t data) |
| 91 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 92 | |
| 93 | static uint32_t Encode(ObjPtr<mirror::Class> klass, uint32_t hash_bits) |
| 94 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 95 | |
| 96 | // Data contains the class pointer GcRoot as well as the low bits of the descriptor hash. |
| 97 | mutable Atomic<uint32_t> data_; |
Stelios Ioannou | d9696b7 | 2021-06-14 15:49:26 +0100 | [diff] [blame] | 98 | static constexpr uint32_t kHashMask = kObjectAlignment - 1; |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | using DescriptorHashPair = std::pair<const char*, uint32_t>; |
| 102 | |
Vladimir Marko | eae6a71 | 2021-02-05 13:33:28 +0000 | [diff] [blame] | 103 | class ClassDescriptorHash { |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 104 | public: |
| 105 | // uint32_t for cross compilation. |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 106 | uint32_t operator()(const TableSlot& slot) const NO_THREAD_SAFETY_ANALYSIS; |
Vladimir Marko | eae6a71 | 2021-02-05 13:33:28 +0000 | [diff] [blame] | 107 | // uint32_t for cross compilation. |
| 108 | uint32_t operator()(const DescriptorHashPair& pair) const NO_THREAD_SAFETY_ANALYSIS; |
| 109 | }; |
| 110 | |
| 111 | class ClassDescriptorEquals { |
| 112 | public: |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 113 | // Same class loader and descriptor. |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 114 | bool operator()(const TableSlot& a, const TableSlot& b) const |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 115 | NO_THREAD_SAFETY_ANALYSIS; |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 116 | // Same descriptor. |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 117 | bool operator()(const TableSlot& a, const DescriptorHashPair& b) const |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 118 | NO_THREAD_SAFETY_ANALYSIS; |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 119 | }; |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 120 | |
| 121 | class TableSlotEmptyFn { |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 122 | public: |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 123 | void MakeEmpty(TableSlot& item) const NO_THREAD_SAFETY_ANALYSIS { |
| 124 | item = TableSlot(); |
| 125 | DCHECK(IsEmpty(item)); |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 126 | } |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 127 | bool IsEmpty(const TableSlot& item) const NO_THREAD_SAFETY_ANALYSIS { |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 128 | return item.IsNull(); |
| 129 | } |
| 130 | }; |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 131 | |
| 132 | // Hash set that hashes class descriptor, and compares descriptors and class loaders. Results |
| 133 | // should be compared for a matching class descriptor and class loader. |
Vladimir Marko | 4f99071 | 2021-07-14 12:45:13 +0100 | [diff] [blame] | 134 | using ClassSet = HashSet<TableSlot, |
| 135 | TableSlotEmptyFn, |
| 136 | ClassDescriptorHash, |
| 137 | ClassDescriptorEquals, |
| 138 | TrackingAllocator<TableSlot, kAllocatorTagClassTable>>; |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 139 | |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 140 | ClassTable(); |
| 141 | |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 142 | // Freeze the current class tables by allocating a new table and never updating or modifying the |
| 143 | // existing table. This helps prevents dirty pages after caused by inserting after zygote fork. |
| 144 | void FreezeSnapshot() |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 145 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 146 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 147 | |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 148 | // Returns the number of classes in previous snapshots defined by `defining_loader`. |
Vladimir Marko | c5798bf | 2016-12-09 10:20:54 +0000 | [diff] [blame] | 149 | size_t NumZygoteClasses(ObjPtr<mirror::ClassLoader> defining_loader) const |
| 150 | REQUIRES(!lock_) |
| 151 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 152 | |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 153 | // Returns all off the classes in the lastest snapshot defined by `defining_loader`. |
Vladimir Marko | c5798bf | 2016-12-09 10:20:54 +0000 | [diff] [blame] | 154 | size_t NumNonZygoteClasses(ObjPtr<mirror::ClassLoader> defining_loader) const |
| 155 | REQUIRES(!lock_) |
| 156 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 157 | |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 158 | // Returns the number of classes in previous snapshots no matter the defining loader. |
| 159 | size_t NumReferencedZygoteClasses() const |
| 160 | REQUIRES(!lock_) |
| 161 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 162 | |
| 163 | // Returns all off the classes in the lastest snapshot no matter the defining loader. |
| 164 | size_t NumReferencedNonZygoteClasses() const |
| 165 | REQUIRES(!lock_) |
| 166 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 167 | |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 168 | // Update a class in the table with the new class. Returns the existing class which was replaced. |
Vladimir Marko | 1fe5839 | 2019-04-10 16:14:56 +0100 | [diff] [blame] | 169 | ObjPtr<mirror::Class> UpdateClass(const char* descriptor, |
| 170 | ObjPtr<mirror::Class> new_klass, |
| 171 | size_t hash) |
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 | e4275c0 | 2015-08-06 15:34:15 -0700 | [diff] [blame] | 175 | // NO_THREAD_SAFETY_ANALYSIS for object marking requiring heap bitmap lock. |
| 176 | template<class Visitor> |
| 177 | void VisitRoots(Visitor& visitor) |
Mathieu Chartier | 00310e0 | 2015-10-17 12:46:42 -0700 | [diff] [blame] | 178 | NO_THREAD_SAFETY_ANALYSIS |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 179 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 180 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 181 | |
Mathieu Chartier | e4275c0 | 2015-08-06 15:34:15 -0700 | [diff] [blame] | 182 | template<class Visitor> |
| 183 | void VisitRoots(const Visitor& visitor) |
Mathieu Chartier | 00310e0 | 2015-10-17 12:46:42 -0700 | [diff] [blame] | 184 | NO_THREAD_SAFETY_ANALYSIS |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 185 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 186 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 187 | |
Mathieu Chartier | 1aa8ec2 | 2016-02-01 10:34:47 -0800 | [diff] [blame] | 188 | // Stops visit if the visitor returns false. |
Vladimir Marko | 5f958f6 | 2022-02-08 12:01:07 +0000 | [diff] [blame] | 189 | template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier, typename Visitor> |
Mathieu Chartier | 1aa8ec2 | 2016-02-01 10:34:47 -0800 | [diff] [blame] | 190 | bool Visit(Visitor& visitor) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 191 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 192 | REQUIRES_SHARED(Locks::mutator_lock_); |
Vladimir Marko | 5f958f6 | 2022-02-08 12:01:07 +0000 | [diff] [blame] | 193 | template <ReadBarrierOption kReadBarrierOption = kWithReadBarrier, typename Visitor> |
Mathieu Chartier | db70ce5 | 2016-12-12 11:06:59 -0800 | [diff] [blame] | 194 | bool Visit(const Visitor& visitor) |
| 195 | REQUIRES(!lock_) |
| 196 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 197 | |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 198 | // Return the first class that matches the descriptor. Returns null if there are none. |
Vladimir Marko | 1fe5839 | 2019-04-10 16:14:56 +0100 | [diff] [blame] | 199 | ObjPtr<mirror::Class> Lookup(const char* descriptor, size_t hash) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 200 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 201 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 202 | |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 203 | // Return the first class that matches the descriptor of klass. Returns null if there are none. |
Vladimir Marko | 1dab575 | 2021-02-25 15:41:33 +0000 | [diff] [blame] | 204 | // Used for tests and debug-build checks. |
Vladimir Marko | 1fe5839 | 2019-04-10 16:14:56 +0100 | [diff] [blame] | 205 | ObjPtr<mirror::Class> LookupByDescriptor(ObjPtr<mirror::Class> klass) |
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 | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 208 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 209 | void Insert(ObjPtr<mirror::Class> klass) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 210 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 211 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 212 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 213 | void InsertWithHash(ObjPtr<mirror::Class> klass, size_t hash) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 214 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 215 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 216 | |
Mathieu Chartier | c9dbb1d | 2016-06-03 17:47:32 -0700 | [diff] [blame] | 217 | // 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] | 218 | bool InsertStrongRoot(ObjPtr<mirror::Object> obj) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 219 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 220 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 221 | |
Vladimir Marko | 1bc4b17 | 2016-10-24 16:53:39 +0000 | [diff] [blame] | 222 | // Return true if we inserted the oat file, false if it already exists. |
| 223 | bool InsertOatFile(const OatFile* oat_file) |
| 224 | REQUIRES(!lock_) |
| 225 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 226 | |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 227 | // 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] | 228 | size_t ReadFromMemory(uint8_t* ptr) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 229 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 230 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 231 | |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 232 | // Add a class set to the front of classes. |
| 233 | void AddClassSet(ClassSet&& set) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 234 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 235 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 236 | |
Mathieu Chartier | c9dbb1d | 2016-06-03 17:47:32 -0700 | [diff] [blame] | 237 | // Clear strong roots (other than classes themselves). |
| 238 | void ClearStrongRoots() |
| 239 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 240 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | c9dbb1d | 2016-06-03 17:47:32 -0700 | [diff] [blame] | 241 | |
Mathieu Chartier | 72041a0 | 2017-07-14 18:23:25 -0700 | [diff] [blame] | 242 | // Filter strong roots (other than classes themselves). |
| 243 | template <typename Filter> |
| 244 | void RemoveStrongRoots(const Filter& filter) |
| 245 | REQUIRES(!lock_) |
| 246 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 247 | |
Mathieu Chartier | 92091bd | 2016-05-10 18:13:20 -0700 | [diff] [blame] | 248 | ReaderWriterMutex& GetLock() { |
| 249 | return lock_; |
| 250 | } |
| 251 | |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 252 | private: |
Vladimir Marko | c5798bf | 2016-12-09 10:20:54 +0000 | [diff] [blame] | 253 | size_t CountDefiningLoaderClasses(ObjPtr<mirror::ClassLoader> defining_loader, |
| 254 | const ClassSet& set) const |
| 255 | REQUIRES(lock_) |
| 256 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 257 | |
Vladimir Marko | 1bc4b17 | 2016-10-24 16:53:39 +0000 | [diff] [blame] | 258 | // Return true if we inserted the oat file, false if it already exists. |
| 259 | bool InsertOatFileLocked(const OatFile* oat_file) |
| 260 | REQUIRES(lock_) |
| 261 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 262 | |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 263 | // Lock to guard inserting and removing. |
| 264 | mutable ReaderWriterMutex lock_; |
Mathieu Chartier | 90ef3db | 2015-08-04 15:19:41 -0700 | [diff] [blame] | 265 | // 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] | 266 | std::vector<ClassSet> classes_ GUARDED_BY(lock_); |
Mathieu Chartier | c9dbb1d | 2016-06-03 17:47:32 -0700 | [diff] [blame] | 267 | // Extra strong roots that can be either dex files or dex caches. Dex files used by the class |
| 268 | // loader which may not be owned by the class loader must be held strongly live. Also dex caches |
| 269 | // are held live to prevent them being unloading once they have classes in them. |
| 270 | std::vector<GcRoot<mirror::Object>> strong_roots_ GUARDED_BY(lock_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 271 | // Keep track of oat files with GC roots associated with dex caches in `strong_roots_`. |
| 272 | std::vector<const OatFile*> oat_files_ GUARDED_BY(lock_); |
Mathieu Chartier | 496577f | 2016-09-20 15:33:31 -0700 | [diff] [blame] | 273 | |
Vladimir Marko | 7452797 | 2016-11-29 15:57:32 +0000 | [diff] [blame] | 274 | friend class linker::ImageWriter; // for InsertWithoutLocks. |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 275 | }; |
| 276 | |
| 277 | } // namespace art |
| 278 | |
| 279 | #endif // ART_RUNTIME_CLASS_TABLE_H_ |