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 | |
Mathieu Chartier | db70ce5 | 2016-12-12 11:06:59 -0800 | [diff] [blame] | 81 | static uint32_t HashDescriptor(ObjPtr<mirror::Class> klass) |
| 82 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 83 | |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 84 | template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Vladimir Marko | 1fe5839 | 2019-04-10 16:14:56 +0100 | [diff] [blame] | 85 | ObjPtr<mirror::Class> Read() const REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 86 | |
| 87 | // NO_THREAD_SAFETY_ANALYSIS since the visitor may require heap bitmap lock. |
| 88 | template<typename Visitor> |
| 89 | void VisitRoot(const Visitor& visitor) const NO_THREAD_SAFETY_ANALYSIS; |
| 90 | |
| 91 | private: |
| 92 | // Extract a raw pointer from an address. |
| 93 | static ObjPtr<mirror::Class> ExtractPtr(uint32_t data) |
| 94 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 95 | |
| 96 | static uint32_t Encode(ObjPtr<mirror::Class> klass, uint32_t hash_bits) |
| 97 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 98 | |
| 99 | // Data contains the class pointer GcRoot as well as the low bits of the descriptor hash. |
| 100 | mutable Atomic<uint32_t> data_; |
| 101 | static const uint32_t kHashMask = kObjectAlignment - 1; |
| 102 | }; |
| 103 | |
| 104 | using DescriptorHashPair = std::pair<const char*, uint32_t>; |
| 105 | |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 106 | class ClassDescriptorHashEquals { |
| 107 | public: |
| 108 | // uint32_t for cross compilation. |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 109 | uint32_t operator()(const TableSlot& slot) const NO_THREAD_SAFETY_ANALYSIS; |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 110 | // Same class loader and descriptor. |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 111 | bool operator()(const TableSlot& a, const TableSlot& b) const |
Mathieu Chartier | 6beced4 | 2016-11-15 15:51:31 -0800 | [diff] [blame] | 112 | NO_THREAD_SAFETY_ANALYSIS; |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 113 | // Same descriptor. |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 114 | bool operator()(const TableSlot& a, const DescriptorHashPair& b) const |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 115 | NO_THREAD_SAFETY_ANALYSIS; |
| 116 | // uint32_t for cross compilation. |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 117 | uint32_t operator()(const DescriptorHashPair& pair) const NO_THREAD_SAFETY_ANALYSIS; |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 118 | }; |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 119 | |
| 120 | class TableSlotEmptyFn { |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 121 | public: |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 122 | void MakeEmpty(TableSlot& item) const NO_THREAD_SAFETY_ANALYSIS { |
| 123 | item = TableSlot(); |
| 124 | DCHECK(IsEmpty(item)); |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 125 | } |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 126 | bool IsEmpty(const TableSlot& item) const NO_THREAD_SAFETY_ANALYSIS { |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 127 | return item.IsNull(); |
| 128 | } |
| 129 | }; |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 130 | |
| 131 | // Hash set that hashes class descriptor, and compares descriptors and class loaders. Results |
| 132 | // should be compared for a matching class descriptor and class loader. |
| 133 | typedef HashSet<TableSlot, |
| 134 | TableSlotEmptyFn, |
| 135 | ClassDescriptorHashEquals, |
| 136 | ClassDescriptorHashEquals, |
| 137 | TrackingAllocator<TableSlot, kAllocatorTagClassTable>> ClassSet; |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 138 | |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 139 | ClassTable(); |
| 140 | |
| 141 | // Used by image writer for checking. |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 142 | bool Contains(ObjPtr<mirror::Class> klass) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 143 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 144 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 145 | |
| 146 | // Freeze the current class tables by allocating a new table and never updating or modifying the |
| 147 | // existing table. This helps prevents dirty pages after caused by inserting after zygote fork. |
| 148 | void FreezeSnapshot() |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 149 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 150 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 151 | |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 152 | // Returns the number of classes in previous snapshots defined by `defining_loader`. |
Vladimir Marko | c5798bf | 2016-12-09 10:20:54 +0000 | [diff] [blame] | 153 | size_t NumZygoteClasses(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 | |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 157 | // 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] | 158 | size_t NumNonZygoteClasses(ObjPtr<mirror::ClassLoader> defining_loader) const |
| 159 | REQUIRES(!lock_) |
| 160 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 161 | |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 162 | // Returns the number of classes in previous snapshots no matter the defining loader. |
| 163 | size_t NumReferencedZygoteClasses() const |
| 164 | REQUIRES(!lock_) |
| 165 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 166 | |
| 167 | // Returns all off the classes in the lastest snapshot no matter the defining loader. |
| 168 | size_t NumReferencedNonZygoteClasses() const |
| 169 | REQUIRES(!lock_) |
| 170 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 171 | |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 172 | // 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] | 173 | ObjPtr<mirror::Class> UpdateClass(const char* descriptor, |
| 174 | ObjPtr<mirror::Class> new_klass, |
| 175 | size_t hash) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 176 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 177 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 178 | |
Mathieu Chartier | e4275c0 | 2015-08-06 15:34:15 -0700 | [diff] [blame] | 179 | // NO_THREAD_SAFETY_ANALYSIS for object marking requiring heap bitmap lock. |
| 180 | template<class Visitor> |
| 181 | void VisitRoots(Visitor& visitor) |
Mathieu Chartier | 00310e0 | 2015-10-17 12:46:42 -0700 | [diff] [blame] | 182 | NO_THREAD_SAFETY_ANALYSIS |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 183 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 184 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 185 | |
Mathieu Chartier | e4275c0 | 2015-08-06 15:34:15 -0700 | [diff] [blame] | 186 | template<class Visitor> |
| 187 | void VisitRoots(const Visitor& visitor) |
Mathieu Chartier | 00310e0 | 2015-10-17 12:46:42 -0700 | [diff] [blame] | 188 | NO_THREAD_SAFETY_ANALYSIS |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 189 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 190 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 191 | |
Mathieu Chartier | 1aa8ec2 | 2016-02-01 10:34:47 -0800 | [diff] [blame] | 192 | // Stops visit if the visitor returns false. |
Alexey Grebenkin | be4c2bd | 2018-02-01 19:09:59 +0300 | [diff] [blame] | 193 | template <typename Visitor, ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Mathieu Chartier | 1aa8ec2 | 2016-02-01 10:34:47 -0800 | [diff] [blame] | 194 | bool Visit(Visitor& visitor) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 195 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 196 | REQUIRES_SHARED(Locks::mutator_lock_); |
Alexey Grebenkin | be4c2bd | 2018-02-01 19:09:59 +0300 | [diff] [blame] | 197 | template <typename Visitor, ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Mathieu Chartier | db70ce5 | 2016-12-12 11:06:59 -0800 | [diff] [blame] | 198 | bool Visit(const Visitor& visitor) |
| 199 | REQUIRES(!lock_) |
| 200 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 201 | |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 202 | // 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] | 203 | ObjPtr<mirror::Class> Lookup(const char* descriptor, size_t hash) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 204 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 205 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 206 | |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 207 | // Return the first class that matches the descriptor of klass. Returns null if there are none. |
Vladimir Marko | 1fe5839 | 2019-04-10 16:14:56 +0100 | [diff] [blame] | 208 | ObjPtr<mirror::Class> LookupByDescriptor(ObjPtr<mirror::Class> klass) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 209 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 210 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 211 | |
Vladimir Marko | cd556b0 | 2017-02-03 11:47:34 +0000 | [diff] [blame] | 212 | // Try to insert a class and return the inserted class if successful. If another class |
| 213 | // with the same descriptor is already in the table, return the existing entry. |
| 214 | ObjPtr<mirror::Class> TryInsert(ObjPtr<mirror::Class> klass) |
| 215 | REQUIRES(!lock_) |
| 216 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 217 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 218 | void Insert(ObjPtr<mirror::Class> klass) |
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 | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 221 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 222 | void InsertWithHash(ObjPtr<mirror::Class> klass, size_t hash) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 223 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 224 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 225 | |
| 226 | // Returns true if the class was found and removed, false otherwise. |
| 227 | bool Remove(const char* descriptor) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 228 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 229 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 00310e0 | 2015-10-17 12:46:42 -0700 | [diff] [blame] | 230 | |
Mathieu Chartier | c9dbb1d | 2016-06-03 17:47:32 -0700 | [diff] [blame] | 231 | // 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] | 232 | bool InsertStrongRoot(ObjPtr<mirror::Object> obj) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 233 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 234 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 235 | |
Vladimir Marko | 1bc4b17 | 2016-10-24 16:53:39 +0000 | [diff] [blame] | 236 | // Return true if we inserted the oat file, false if it already exists. |
| 237 | bool InsertOatFile(const OatFile* oat_file) |
| 238 | REQUIRES(!lock_) |
| 239 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 240 | |
Mathieu Chartier | 41dc8ce | 2015-12-04 15:07:48 -0800 | [diff] [blame] | 241 | // Combines all of the tables into one class set. |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 242 | size_t WriteToMemory(uint8_t* ptr) const |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 243 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 244 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 245 | |
| 246 | // 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] | 247 | size_t ReadFromMemory(uint8_t* ptr) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 248 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 249 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | 208a5cb | 2015-12-02 15:44:07 -0800 | [diff] [blame] | 250 | |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 251 | // Add a class set to the front of classes. |
| 252 | void AddClassSet(ClassSet&& set) |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 253 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 254 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 255 | |
Mathieu Chartier | c9dbb1d | 2016-06-03 17:47:32 -0700 | [diff] [blame] | 256 | // Clear strong roots (other than classes themselves). |
| 257 | void ClearStrongRoots() |
| 258 | REQUIRES(!lock_) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 259 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | c9dbb1d | 2016-06-03 17:47:32 -0700 | [diff] [blame] | 260 | |
Mathieu Chartier | 72041a0 | 2017-07-14 18:23:25 -0700 | [diff] [blame] | 261 | // Filter strong roots (other than classes themselves). |
| 262 | template <typename Filter> |
| 263 | void RemoveStrongRoots(const Filter& filter) |
| 264 | REQUIRES(!lock_) |
| 265 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 266 | |
Mathieu Chartier | 92091bd | 2016-05-10 18:13:20 -0700 | [diff] [blame] | 267 | ReaderWriterMutex& GetLock() { |
| 268 | return lock_; |
| 269 | } |
| 270 | |
Mathieu Chartier | 88027bd | 2016-03-02 16:08:31 -0800 | [diff] [blame] | 271 | private: |
Mathieu Chartier | 8c19d24 | 2017-03-06 12:35:10 -0800 | [diff] [blame] | 272 | // Only copies classes. |
Vladimir Marko | 6ad2f6d | 2017-01-18 15:22:59 +0000 | [diff] [blame] | 273 | void CopyWithoutLocks(const ClassTable& source_table) NO_THREAD_SAFETY_ANALYSIS; |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 274 | void InsertWithoutLocks(ObjPtr<mirror::Class> klass) NO_THREAD_SAFETY_ANALYSIS; |
Mathieu Chartier | 496577f | 2016-09-20 15:33:31 -0700 | [diff] [blame] | 275 | |
Vladimir Marko | c5798bf | 2016-12-09 10:20:54 +0000 | [diff] [blame] | 276 | size_t CountDefiningLoaderClasses(ObjPtr<mirror::ClassLoader> defining_loader, |
| 277 | const ClassSet& set) const |
| 278 | REQUIRES(lock_) |
| 279 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 280 | |
Vladimir Marko | 1bc4b17 | 2016-10-24 16:53:39 +0000 | [diff] [blame] | 281 | // Return true if we inserted the oat file, false if it already exists. |
| 282 | bool InsertOatFileLocked(const OatFile* oat_file) |
| 283 | REQUIRES(lock_) |
| 284 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 285 | |
Mathieu Chartier | 1609e3a | 2016-04-05 14:36:57 -0700 | [diff] [blame] | 286 | // Lock to guard inserting and removing. |
| 287 | mutable ReaderWriterMutex lock_; |
Mathieu Chartier | 90ef3db | 2015-08-04 15:19:41 -0700 | [diff] [blame] | 288 | // 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] | 289 | std::vector<ClassSet> classes_ GUARDED_BY(lock_); |
Mathieu Chartier | c9dbb1d | 2016-06-03 17:47:32 -0700 | [diff] [blame] | 290 | // Extra strong roots that can be either dex files or dex caches. Dex files used by the class |
| 291 | // loader which may not be owned by the class loader must be held strongly live. Also dex caches |
| 292 | // are held live to prevent them being unloading once they have classes in them. |
| 293 | std::vector<GcRoot<mirror::Object>> strong_roots_ GUARDED_BY(lock_); |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 294 | // Keep track of oat files with GC roots associated with dex caches in `strong_roots_`. |
| 295 | std::vector<const OatFile*> oat_files_ GUARDED_BY(lock_); |
Mathieu Chartier | 496577f | 2016-09-20 15:33:31 -0700 | [diff] [blame] | 296 | |
Vladimir Marko | 7452797 | 2016-11-29 15:57:32 +0000 | [diff] [blame] | 297 | friend class linker::ImageWriter; // for InsertWithoutLocks. |
Mathieu Chartier | cc5ebdf | 2015-07-27 11:19:43 -0700 | [diff] [blame] | 298 | }; |
| 299 | |
| 300 | } // namespace art |
| 301 | |
| 302 | #endif // ART_RUNTIME_CLASS_TABLE_H_ |