| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef TOOLS_BLINK_GC_PLUGIN_EDGE_H_ | 5 #ifndef TOOLS_BLINK_GC_PLUGIN_EDGE_H_ |
| 6 #define TOOLS_BLINK_GC_PLUGIN_EDGE_H_ | 6 #define TOOLS_BLINK_GC_PLUGIN_EDGE_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "TracingStatus.h" | 10 #include "TracingStatus.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 Context context_; | 68 Context context_; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 // Base class for all edges. | 71 // Base class for all edges. |
| 72 class Edge { | 72 class Edge { |
| 73 public: | 73 public: |
| 74 enum NeedsTracingOption { kRecursive, kNonRecursive }; | 74 enum NeedsTracingOption { kRecursive, kNonRecursive }; |
| 75 | 75 |
| 76 virtual ~Edge() { } | 76 virtual ~Edge() { } |
| 77 virtual void Accept(EdgeVisitor*) = 0; | 77 virtual void Accept(EdgeVisitor*) = 0; |
| 78 virtual bool NeedsFinalization() = 0; |
| 78 virtual TracingStatus NeedsTracing(NeedsTracingOption) { | 79 virtual TracingStatus NeedsTracing(NeedsTracingOption) { |
| 79 return TracingStatus::Unknown(); | 80 return TracingStatus::Unknown(); |
| 80 } | 81 } |
| 81 | 82 |
| 82 virtual bool IsValue() { return false; } | 83 virtual bool IsValue() { return false; } |
| 83 virtual bool IsRawPtr() { return false; } | 84 virtual bool IsRawPtr() { return false; } |
| 84 virtual bool IsRefPtr() { return false; } | 85 virtual bool IsRefPtr() { return false; } |
| 85 virtual bool IsOwnPtr() { return false; } | 86 virtual bool IsOwnPtr() { return false; } |
| 86 virtual bool IsMember() { return false; } | 87 virtual bool IsMember() { return false; } |
| 87 virtual bool IsWeakMember() { return false; } | 88 virtual bool IsWeakMember() { return false; } |
| 88 virtual bool IsPersistent() { return false; } | 89 virtual bool IsPersistent() { return false; } |
| 89 virtual bool IsCollection() { return false; } | 90 virtual bool IsCollection() { return false; } |
| 90 }; | 91 }; |
| 91 | 92 |
| 92 // A value edge is a direct edge to some type, eg, part-object edges. | 93 // A value edge is a direct edge to some type, eg, part-object edges. |
| 93 class Value : public Edge { | 94 class Value : public Edge { |
| 94 public: | 95 public: |
| 95 explicit Value(RecordInfo* value) : value_(value) {}; | 96 explicit Value(RecordInfo* value) : value_(value) {}; |
| 96 bool IsValue() { return true; } | 97 bool IsValue() { return true; } |
| 98 bool NeedsFinalization(); |
| 97 TracingStatus NeedsTracing(NeedsTracingOption); | 99 TracingStatus NeedsTracing(NeedsTracingOption); |
| 98 void Accept(EdgeVisitor* visitor) { visitor->VisitValue(this); } | 100 void Accept(EdgeVisitor* visitor) { visitor->VisitValue(this); } |
| 99 RecordInfo* value() { return value_; } | 101 RecordInfo* value() { return value_; } |
| 100 private: | 102 private: |
| 101 RecordInfo* value_; | 103 RecordInfo* value_; |
| 102 }; | 104 }; |
| 103 | 105 |
| 104 // Shared base for smart-pointer edges. | 106 // Shared base for smart-pointer edges. |
| 105 class PtrEdge : public Edge { | 107 class PtrEdge : public Edge { |
| 106 public: | 108 public: |
| 107 ~PtrEdge() { delete ptr_; } | 109 ~PtrEdge() { delete ptr_; } |
| 108 Edge* ptr() { return ptr_; } | 110 Edge* ptr() { return ptr_; } |
| 109 protected: | 111 protected: |
| 110 PtrEdge(Edge* ptr) : ptr_(ptr) { | 112 PtrEdge(Edge* ptr) : ptr_(ptr) { |
| 111 assert(ptr && "EdgePtr pointer must be non-null"); | 113 assert(ptr && "EdgePtr pointer must be non-null"); |
| 112 } | 114 } |
| 113 private: | 115 private: |
| 114 Edge* ptr_; | 116 Edge* ptr_; |
| 115 }; | 117 }; |
| 116 | 118 |
| 117 class RawPtr : public PtrEdge { | 119 class RawPtr : public PtrEdge { |
| 118 public: | 120 public: |
| 119 explicit RawPtr(Edge* ptr) : PtrEdge(ptr) { } | 121 explicit RawPtr(Edge* ptr) : PtrEdge(ptr) { } |
| 120 bool IsRawPtr() { return true; } | 122 bool IsRawPtr() { return true; } |
| 123 bool NeedsFinalization() { return false; } |
| 121 TracingStatus NeedsTracing(NeedsTracingOption) { | 124 TracingStatus NeedsTracing(NeedsTracingOption) { |
| 122 return TracingStatus::Unneeded(); | 125 return TracingStatus::Unneeded(); |
| 123 } | 126 } |
| 124 void Accept(EdgeVisitor* visitor) { visitor->VisitRawPtr(this); } | 127 void Accept(EdgeVisitor* visitor) { visitor->VisitRawPtr(this); } |
| 125 }; | 128 }; |
| 126 | 129 |
| 127 class RefPtr : public PtrEdge { | 130 class RefPtr : public PtrEdge { |
| 128 public: | 131 public: |
| 129 explicit RefPtr(Edge* ptr) : PtrEdge(ptr) { } | 132 explicit RefPtr(Edge* ptr) : PtrEdge(ptr) { } |
| 130 bool IsRefPtr() { return true; } | 133 bool IsRefPtr() { return true; } |
| 134 bool NeedsFinalization() { return true; } |
| 131 TracingStatus NeedsTracing(NeedsTracingOption) { | 135 TracingStatus NeedsTracing(NeedsTracingOption) { |
| 132 return TracingStatus::Unneeded(); | 136 return TracingStatus::Unneeded(); |
| 133 } | 137 } |
| 134 void Accept(EdgeVisitor* visitor) { visitor->VisitRefPtr(this); } | 138 void Accept(EdgeVisitor* visitor) { visitor->VisitRefPtr(this); } |
| 135 }; | 139 }; |
| 136 | 140 |
| 137 class OwnPtr : public PtrEdge { | 141 class OwnPtr : public PtrEdge { |
| 138 public: | 142 public: |
| 139 explicit OwnPtr(Edge* ptr) : PtrEdge(ptr) { } | 143 explicit OwnPtr(Edge* ptr) : PtrEdge(ptr) { } |
| 140 bool IsOwnPtr() { return true; } | 144 bool IsOwnPtr() { return true; } |
| 145 bool NeedsFinalization() { return true; } |
| 141 TracingStatus NeedsTracing(NeedsTracingOption) { | 146 TracingStatus NeedsTracing(NeedsTracingOption) { |
| 142 return TracingStatus::Unneeded(); | 147 return TracingStatus::Unneeded(); |
| 143 } | 148 } |
| 144 void Accept(EdgeVisitor* visitor) { visitor->VisitOwnPtr(this); } | 149 void Accept(EdgeVisitor* visitor) { visitor->VisitOwnPtr(this); } |
| 145 }; | 150 }; |
| 146 | 151 |
| 147 class Member : public PtrEdge { | 152 class Member : public PtrEdge { |
| 148 public: | 153 public: |
| 149 explicit Member(Edge* ptr) : PtrEdge(ptr) { } | 154 explicit Member(Edge* ptr) : PtrEdge(ptr) { } |
| 150 bool IsMember() { return true; } | 155 bool IsMember() { return true; } |
| 156 bool NeedsFinalization() { return false; } |
| 151 TracingStatus NeedsTracing(NeedsTracingOption) { | 157 TracingStatus NeedsTracing(NeedsTracingOption) { |
| 152 return TracingStatus::Needed(); | 158 return TracingStatus::Needed(); |
| 153 } | 159 } |
| 154 void Accept(EdgeVisitor* visitor) { visitor->VisitMember(this); } | 160 void Accept(EdgeVisitor* visitor) { visitor->VisitMember(this); } |
| 155 }; | 161 }; |
| 156 | 162 |
| 157 class WeakMember : public PtrEdge { | 163 class WeakMember : public PtrEdge { |
| 158 public: | 164 public: |
| 159 explicit WeakMember(Edge* ptr) : PtrEdge(ptr) { } | 165 explicit WeakMember(Edge* ptr) : PtrEdge(ptr) { } |
| 160 bool IsWeakMember() { return true; } | 166 bool IsWeakMember() { return true; } |
| 167 bool NeedsFinalization() { return false; } |
| 161 TracingStatus NeedsTracing(NeedsTracingOption) { | 168 TracingStatus NeedsTracing(NeedsTracingOption) { |
| 162 return TracingStatus::Needed(); | 169 return TracingStatus::Needed(); |
| 163 } | 170 } |
| 164 void Accept(EdgeVisitor* visitor) { visitor->VisitWeakMember(this); } | 171 void Accept(EdgeVisitor* visitor) { visitor->VisitWeakMember(this); } |
| 165 }; | 172 }; |
| 166 | 173 |
| 167 class Persistent : public PtrEdge { | 174 class Persistent : public PtrEdge { |
| 168 public: | 175 public: |
| 169 explicit Persistent(Edge* ptr) : PtrEdge(ptr) { } | 176 explicit Persistent(Edge* ptr) : PtrEdge(ptr) { } |
| 170 bool IsPersistent() { return true; } | 177 bool IsPersistent() { return true; } |
| 178 bool NeedsFinalization() { return true; } |
| 171 TracingStatus NeedsTracing(NeedsTracingOption) { | 179 TracingStatus NeedsTracing(NeedsTracingOption) { |
| 172 return TracingStatus::Unneeded(); | 180 return TracingStatus::Unneeded(); |
| 173 } | 181 } |
| 174 void Accept(EdgeVisitor* visitor) { visitor->VisitPersistent(this); } | 182 void Accept(EdgeVisitor* visitor) { visitor->VisitPersistent(this); } |
| 175 }; | 183 }; |
| 176 | 184 |
| 177 class Collection : public Edge { | 185 class Collection : public Edge { |
| 178 public: | 186 public: |
| 179 typedef std::vector<Edge*> Members; | 187 typedef std::vector<Edge*> Members; |
| 180 Collection(bool on_heap, bool is_root) | 188 Collection(RecordInfo* info, bool on_heap, bool is_root) |
| 181 : on_heap_(on_heap), is_root_(is_root) {} | 189 : info_(info), |
| 190 on_heap_(on_heap), |
| 191 is_root_(is_root) {} |
| 182 ~Collection() { | 192 ~Collection() { |
| 183 for (Members::iterator it = members_.begin(); it != members_.end(); ++it) { | 193 for (Members::iterator it = members_.begin(); it != members_.end(); ++it) { |
| 184 assert(*it && "Collection-edge members must be non-null"); | 194 assert(*it && "Collection-edge members must be non-null"); |
| 185 delete *it; | 195 delete *it; |
| 186 } | 196 } |
| 187 } | 197 } |
| 188 bool IsCollection() { return true; } | 198 bool IsCollection() { return true; } |
| 189 bool on_heap() { return on_heap_; } | 199 bool on_heap() { return on_heap_; } |
| 190 bool is_root() { return is_root_; } | 200 bool is_root() { return is_root_; } |
| 191 Members& members() { return members_; } | 201 Members& members() { return members_; } |
| 192 void Accept(EdgeVisitor* visitor) { visitor->VisitCollection(this); } | 202 void Accept(EdgeVisitor* visitor) { visitor->VisitCollection(this); } |
| 193 void AcceptMembers(EdgeVisitor* visitor) { | 203 void AcceptMembers(EdgeVisitor* visitor) { |
| 194 for (Members::iterator it = members_.begin(); it != members_.end(); ++it) | 204 for (Members::iterator it = members_.begin(); it != members_.end(); ++it) |
| 195 (*it)->Accept(visitor); | 205 (*it)->Accept(visitor); |
| 196 } | 206 } |
| 207 bool NeedsFinalization(); |
| 197 TracingStatus NeedsTracing(NeedsTracingOption) { | 208 TracingStatus NeedsTracing(NeedsTracingOption) { |
| 198 if (is_root_) | 209 if (is_root_) |
| 199 return TracingStatus::Unneeded(); | 210 return TracingStatus::Unneeded(); |
| 200 if (on_heap_) | 211 if (on_heap_) |
| 201 return TracingStatus::Needed(); | 212 return TracingStatus::Needed(); |
| 202 // For off-heap collections, determine tracing status of members. | 213 // For off-heap collections, determine tracing status of members. |
| 203 TracingStatus status = TracingStatus::Unneeded(); | 214 TracingStatus status = TracingStatus::Unneeded(); |
| 204 for (Members::iterator it = members_.begin(); it != members_.end(); ++it) { | 215 for (Members::iterator it = members_.begin(); it != members_.end(); ++it) { |
| 205 // Do a non-recursive test here since members could equal the holder. | 216 // Do a non-recursive test here since members could equal the holder. |
| 206 status = status.LUB((*it)->NeedsTracing(kNonRecursive)); | 217 status = status.LUB((*it)->NeedsTracing(kNonRecursive)); |
| 207 } | 218 } |
| 208 return status; | 219 return status; |
| 209 } | 220 } |
| 210 private: | 221 private: |
| 222 RecordInfo* info_; |
| 211 Members members_; | 223 Members members_; |
| 212 bool on_heap_; | 224 bool on_heap_; |
| 213 bool is_root_; | 225 bool is_root_; |
| 214 }; | 226 }; |
| 215 | 227 |
| 216 #endif // TOOLS_BLINK_GC_PLUGIN_EDGE_H_ | 228 #endif // TOOLS_BLINK_GC_PLUGIN_EDGE_H_ |
| OLD | NEW |