Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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_GC_ROOT_H_ |
| 18 | #define ART_RUNTIME_GC_ROOT_H_ |
| 19 | |
Andreas Gampe | 7fbc4a5 | 2018-11-28 08:26:47 -0800 | [diff] [blame] | 20 | #include "base/locks.h" // For Locks::mutator_lock_. |
Mathieu Chartier | bad0267 | 2014-08-25 13:08:22 -0700 | [diff] [blame] | 21 | #include "base/macros.h" |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 22 | #include "mirror/object_reference.h" |
Andreas Gampe | 217488a | 2017-09-18 08:34:42 -0700 | [diff] [blame] | 23 | #include "read_barrier_option.h" |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 24 | |
| 25 | namespace art { |
Hiroshi Yamauchi | 3f64f25 | 2015-06-12 18:35:06 -0700 | [diff] [blame] | 26 | class ArtField; |
| 27 | class ArtMethod; |
Andreas Gampe | c73cb64 | 2017-02-22 10:11:30 -0800 | [diff] [blame] | 28 | template<class MirrorType> class ObjPtr; |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 29 | |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 30 | namespace mirror { |
| 31 | class Object; |
| 32 | } // namespace mirror |
| 33 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 34 | template <size_t kBufferSize> |
| 35 | class BufferedRootVisitor; |
| 36 | |
Mathieu Chartier | 4809d0a | 2015-04-07 10:39:04 -0700 | [diff] [blame] | 37 | // Dependent on pointer size so that we don't have frames that are too big on 64 bit. |
| 38 | static const size_t kDefaultBufferedRootCount = 1024 / sizeof(void*); |
| 39 | |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 40 | enum RootType { |
| 41 | kRootUnknown = 0, |
| 42 | kRootJNIGlobal, |
| 43 | kRootJNILocal, |
| 44 | kRootJavaFrame, |
| 45 | kRootNativeStack, |
| 46 | kRootStickyClass, |
| 47 | kRootThreadBlock, |
| 48 | kRootMonitorUsed, |
| 49 | kRootThreadObject, |
| 50 | kRootInternedString, |
Man Cao | 1ed11b9 | 2015-06-11 22:47:35 -0700 | [diff] [blame] | 51 | kRootFinalizing, // used for HPROF's conversion to HprofHeapTag |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 52 | kRootDebugger, |
Man Cao | 1ed11b9 | 2015-06-11 22:47:35 -0700 | [diff] [blame] | 53 | kRootReferenceCleanup, // used for HPROF's conversion to HprofHeapTag |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 54 | kRootVMInternal, |
| 55 | kRootJNIMonitor, |
| 56 | }; |
Vladimir Marko | 9974e3c | 2020-06-10 16:27:06 +0100 | [diff] [blame] | 57 | std::ostream& operator<<(std::ostream& os, RootType root_type); |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 58 | |
Mathieu Chartier | d3ed9a3 | 2015-04-10 14:23:35 -0700 | [diff] [blame] | 59 | // Only used by hprof. thread_id_ and type_ are only used by hprof. |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 60 | class RootInfo { |
| 61 | public: |
| 62 | // Thread id 0 is for non thread roots. |
| 63 | explicit RootInfo(RootType type, uint32_t thread_id = 0) |
| 64 | : type_(type), thread_id_(thread_id) { |
| 65 | } |
Andreas Gampe | 758a801 | 2015-04-03 21:28:42 -0700 | [diff] [blame] | 66 | RootInfo(const RootInfo&) = default; |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 67 | virtual ~RootInfo() { |
| 68 | } |
| 69 | RootType GetType() const { |
| 70 | return type_; |
| 71 | } |
| 72 | uint32_t GetThreadId() const { |
| 73 | return thread_id_; |
| 74 | } |
| 75 | virtual void Describe(std::ostream& os) const { |
| 76 | os << "Type=" << type_ << " thread_id=" << thread_id_; |
| 77 | } |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 78 | std::string ToString() const; |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 79 | |
| 80 | private: |
| 81 | const RootType type_; |
| 82 | const uint32_t thread_id_; |
| 83 | }; |
| 84 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 85 | inline std::ostream& operator<<(std::ostream& os, const RootInfo& root_info) { |
| 86 | root_info.Describe(os); |
| 87 | return os; |
| 88 | } |
| 89 | |
Andreas Gampe | 585da95 | 2016-12-02 14:52:29 -0800 | [diff] [blame] | 90 | // Not all combinations of flags are valid. You may not visit all roots as well as the new roots |
| 91 | // (no logical reason to do this). You also may not start logging new roots and stop logging new |
| 92 | // roots (also no logical reason to do this). |
| 93 | // |
| 94 | // The precise flag ensures that more metadata is supplied. An example is vreg data for compiled |
| 95 | // method frames. |
| 96 | enum VisitRootFlags : uint8_t { |
Florian Mayer | e828ea0 | 2019-10-10 18:20:21 +0100 | [diff] [blame] | 97 | kVisitRootFlagAllRoots = (1 << 0), |
| 98 | kVisitRootFlagNewRoots = (1 << 1), |
| 99 | kVisitRootFlagStartLoggingNewRoots = (1 << 2), |
| 100 | kVisitRootFlagStopLoggingNewRoots = (1 << 3), |
| 101 | kVisitRootFlagClearRootLog = (1 << 4), |
| 102 | kVisitRootFlagClassLoader = (1 << 5), |
| 103 | // There is no (1 << 6). |
| 104 | kVisitRootFlagPrecise = (1 << 7), |
Andreas Gampe | 585da95 | 2016-12-02 14:52:29 -0800 | [diff] [blame] | 105 | }; |
| 106 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 107 | class RootVisitor { |
| 108 | public: |
| 109 | virtual ~RootVisitor() { } |
| 110 | |
Mathieu Chartier | d3ed9a3 | 2015-04-10 14:23:35 -0700 | [diff] [blame] | 111 | // Single root version, not overridable. |
Mathieu Chartier | 9b1c71e | 2015-09-02 18:51:54 -0700 | [diff] [blame] | 112 | ALWAYS_INLINE void VisitRoot(mirror::Object** root, const RootInfo& info) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 113 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | 9b1c71e | 2015-09-02 18:51:54 -0700 | [diff] [blame] | 114 | VisitRoots(&root, 1, info); |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Mathieu Chartier | d3ed9a3 | 2015-04-10 14:23:35 -0700 | [diff] [blame] | 117 | // Single root version, not overridable. |
Mathieu Chartier | 9b1c71e | 2015-09-02 18:51:54 -0700 | [diff] [blame] | 118 | ALWAYS_INLINE void VisitRootIfNonNull(mirror::Object** root, const RootInfo& info) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 119 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | 9b1c71e | 2015-09-02 18:51:54 -0700 | [diff] [blame] | 120 | if (*root != nullptr) { |
| 121 | VisitRoot(root, info); |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
| 125 | virtual void VisitRoots(mirror::Object*** roots, size_t count, const RootInfo& info) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 126 | REQUIRES_SHARED(Locks::mutator_lock_) = 0; |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 127 | |
| 128 | virtual void VisitRoots(mirror::CompressedReference<mirror::Object>** roots, size_t count, |
| 129 | const RootInfo& info) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 130 | REQUIRES_SHARED(Locks::mutator_lock_) = 0; |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | // Only visits roots one at a time, doesn't handle updating roots. Used when performance isn't |
| 134 | // critical. |
| 135 | class SingleRootVisitor : public RootVisitor { |
| 136 | private: |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 137 | void VisitRoots(mirror::Object*** roots, size_t count, const RootInfo& info) override |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 138 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 139 | for (size_t i = 0; i < count; ++i) { |
| 140 | VisitRoot(*roots[i], info); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | void VisitRoots(mirror::CompressedReference<mirror::Object>** roots, size_t count, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 145 | const RootInfo& info) override |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 146 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 147 | for (size_t i = 0; i < count; ++i) { |
| 148 | VisitRoot(roots[i]->AsMirrorPtr(), info); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | virtual void VisitRoot(mirror::Object* root, const RootInfo& info) = 0; |
| 153 | }; |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 154 | |
Hiroshi Yamauchi | 3f64f25 | 2015-06-12 18:35:06 -0700 | [diff] [blame] | 155 | class GcRootSource { |
| 156 | public: |
| 157 | GcRootSource() |
| 158 | : field_(nullptr), method_(nullptr) { |
| 159 | } |
| 160 | explicit GcRootSource(ArtField* field) |
| 161 | : field_(field), method_(nullptr) { |
| 162 | } |
| 163 | explicit GcRootSource(ArtMethod* method) |
| 164 | : field_(nullptr), method_(method) { |
| 165 | } |
| 166 | ArtField* GetArtField() const { |
| 167 | return field_; |
| 168 | } |
| 169 | ArtMethod* GetArtMethod() const { |
| 170 | return method_; |
| 171 | } |
| 172 | bool HasArtField() const { |
| 173 | return field_ != nullptr; |
| 174 | } |
| 175 | bool HasArtMethod() const { |
| 176 | return method_ != nullptr; |
| 177 | } |
| 178 | |
| 179 | private: |
| 180 | ArtField* const field_; |
| 181 | ArtMethod* const method_; |
| 182 | |
| 183 | DISALLOW_COPY_AND_ASSIGN(GcRootSource); |
| 184 | }; |
| 185 | |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 186 | template<class MirrorType> |
Hiroshi Yamauchi | 9e47bfa | 2015-02-23 11:14:40 -0800 | [diff] [blame] | 187 | class GcRoot { |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 188 | public: |
| 189 | template<ReadBarrierOption kReadBarrierOption = kWithReadBarrier> |
Hiroshi Yamauchi | 3f64f25 | 2015-06-12 18:35:06 -0700 | [diff] [blame] | 190 | ALWAYS_INLINE MirrorType* Read(GcRootSource* gc_root_source = nullptr) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 191 | REQUIRES_SHARED(Locks::mutator_lock_); |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 192 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 193 | void VisitRoot(RootVisitor* visitor, const RootInfo& info) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 194 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 195 | DCHECK(!IsNull()); |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 196 | mirror::CompressedReference<mirror::Object>* roots[1] = { &root_ }; |
| 197 | visitor->VisitRoots(roots, 1u, info); |
Mathieu Chartier | eb175f7 | 2014-10-31 11:49:27 -0700 | [diff] [blame] | 198 | DCHECK(!IsNull()); |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 201 | void VisitRootIfNonNull(RootVisitor* visitor, const RootInfo& info) const |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 202 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 203 | if (!IsNull()) { |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 204 | VisitRoot(visitor, info); |
Mathieu Chartier | e34fa1d | 2015-01-14 14:55:47 -0800 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 208 | ALWAYS_INLINE mirror::CompressedReference<mirror::Object>* AddressWithoutBarrier() { |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 209 | return &root_; |
| 210 | } |
| 211 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 212 | ALWAYS_INLINE bool IsNull() const { |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 213 | // It's safe to null-check it without a read barrier. |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 214 | return root_.IsNull(); |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Mathieu Chartier | 6597577 | 2016-08-05 10:46:36 -0700 | [diff] [blame] | 217 | ALWAYS_INLINE GcRoot() {} |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 218 | explicit ALWAYS_INLINE GcRoot(MirrorType* ref) |
| 219 | REQUIRES_SHARED(Locks::mutator_lock_); |
Andreas Gampe | c73cb64 | 2017-02-22 10:11:30 -0800 | [diff] [blame] | 220 | explicit ALWAYS_INLINE GcRoot(ObjPtr<MirrorType> ref) |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 221 | REQUIRES_SHARED(Locks::mutator_lock_); |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 222 | |
| 223 | private: |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 224 | // Root visitors take pointers to root_ and place them in CompressedReference** arrays. We use a |
Mathieu Chartier | 9086b65 | 2015-04-14 09:35:18 -0700 | [diff] [blame] | 225 | // CompressedReference<mirror::Object> here since it violates strict aliasing requirements to |
| 226 | // cast CompressedReference<MirrorType>* to CompressedReference<mirror::Object>*. |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 227 | mutable mirror::CompressedReference<mirror::Object> root_; |
| 228 | |
| 229 | template <size_t kBufferSize> friend class BufferedRootVisitor; |
| 230 | }; |
| 231 | |
| 232 | // Simple data structure for buffered root visiting to avoid virtual dispatch overhead. Currently |
| 233 | // only for CompressedReferences since these are more common than the Object** roots which are only |
| 234 | // for thread local roots. |
| 235 | template <size_t kBufferSize> |
| 236 | class BufferedRootVisitor { |
| 237 | public: |
| 238 | BufferedRootVisitor(RootVisitor* visitor, const RootInfo& root_info) |
| 239 | : visitor_(visitor), root_info_(root_info), buffer_pos_(0) { |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 242 | ~BufferedRootVisitor() { |
| 243 | Flush(); |
| 244 | } |
| 245 | |
| 246 | template <class MirrorType> |
| 247 | ALWAYS_INLINE void VisitRootIfNonNull(GcRoot<MirrorType>& root) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 248 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 249 | if (!root.IsNull()) { |
| 250 | VisitRoot(root); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | template <class MirrorType> |
| 255 | ALWAYS_INLINE void VisitRootIfNonNull(mirror::CompressedReference<MirrorType>* root) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 256 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 257 | if (!root->IsNull()) { |
| 258 | VisitRoot(root); |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | template <class MirrorType> |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 263 | void VisitRoot(GcRoot<MirrorType>& root) REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 264 | VisitRoot(root.AddressWithoutBarrier()); |
| 265 | } |
| 266 | |
| 267 | template <class MirrorType> |
| 268 | void VisitRoot(mirror::CompressedReference<MirrorType>* root) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 269 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 270 | if (UNLIKELY(buffer_pos_ >= kBufferSize)) { |
| 271 | Flush(); |
| 272 | } |
| 273 | roots_[buffer_pos_++] = root; |
| 274 | } |
| 275 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 276 | void Flush() REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 277 | visitor_->VisitRoots(roots_, buffer_pos_, root_info_); |
| 278 | buffer_pos_ = 0; |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | private: |
Mathieu Chartier | bb87e0f | 2015-04-03 11:21:55 -0700 | [diff] [blame] | 282 | RootVisitor* const visitor_; |
| 283 | RootInfo root_info_; |
| 284 | mirror::CompressedReference<mirror::Object>* roots_[kBufferSize]; |
| 285 | size_t buffer_pos_; |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 286 | }; |
| 287 | |
Mathieu Chartier | 58c3f6a | 2016-12-01 14:21:11 -0800 | [diff] [blame] | 288 | class UnbufferedRootVisitor { |
| 289 | public: |
| 290 | UnbufferedRootVisitor(RootVisitor* visitor, const RootInfo& root_info) |
| 291 | : visitor_(visitor), root_info_(root_info) {} |
| 292 | |
| 293 | template <class MirrorType> |
| 294 | ALWAYS_INLINE void VisitRootIfNonNull(GcRoot<MirrorType>& root) const |
| 295 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 296 | if (!root.IsNull()) { |
| 297 | VisitRoot(root); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | template <class MirrorType> |
| 302 | ALWAYS_INLINE void VisitRootIfNonNull(mirror::CompressedReference<MirrorType>* root) const |
| 303 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 304 | if (!root->IsNull()) { |
| 305 | VisitRoot(root); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | template <class MirrorType> |
| 310 | void VisitRoot(GcRoot<MirrorType>& root) const REQUIRES_SHARED(Locks::mutator_lock_) { |
| 311 | VisitRoot(root.AddressWithoutBarrier()); |
| 312 | } |
| 313 | |
| 314 | template <class MirrorType> |
| 315 | void VisitRoot(mirror::CompressedReference<MirrorType>* root) const |
| 316 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 317 | visitor_->VisitRoots(&root, 1, root_info_); |
| 318 | } |
| 319 | |
| 320 | private: |
| 321 | RootVisitor* const visitor_; |
| 322 | RootInfo root_info_; |
| 323 | }; |
| 324 | |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 325 | } // namespace art |
| 326 | |
| 327 | #endif // ART_RUNTIME_GC_ROOT_H_ |