Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: tools/clang/blink_gc_plugin/Edge.h

Issue 207913002: Global cycle detection analysis. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 virtual void AtCollection(Collection*); 65 virtual void AtCollection(Collection*);
66 66
67 private: 67 private:
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 enum LivenessKind { kWeak, kStrong, kRoot };
75 76
76 virtual ~Edge() { } 77 virtual ~Edge() { }
78 virtual LivenessKind Kind() = 0;
77 virtual void Accept(EdgeVisitor*) = 0; 79 virtual void Accept(EdgeVisitor*) = 0;
78 virtual bool NeedsFinalization() = 0; 80 virtual bool NeedsFinalization() = 0;
79 virtual TracingStatus NeedsTracing(NeedsTracingOption) { 81 virtual TracingStatus NeedsTracing(NeedsTracingOption) {
80 return TracingStatus::Unknown(); 82 return TracingStatus::Unknown();
81 } 83 }
82 84
83 virtual bool IsValue() { return false; } 85 virtual bool IsValue() { return false; }
84 virtual bool IsRawPtr() { return false; } 86 virtual bool IsRawPtr() { return false; }
85 virtual bool IsRefPtr() { return false; } 87 virtual bool IsRefPtr() { return false; }
86 virtual bool IsOwnPtr() { return false; } 88 virtual bool IsOwnPtr() { return false; }
87 virtual bool IsMember() { return false; } 89 virtual bool IsMember() { return false; }
88 virtual bool IsWeakMember() { return false; } 90 virtual bool IsWeakMember() { return false; }
89 virtual bool IsPersistent() { return false; } 91 virtual bool IsPersistent() { return false; }
90 virtual bool IsCollection() { return false; } 92 virtual bool IsCollection() { return false; }
91 }; 93 };
92 94
93 // A value edge is a direct edge to some type, eg, part-object edges. 95 // A value edge is a direct edge to some type, eg, part-object edges.
94 class Value : public Edge { 96 class Value : public Edge {
95 public: 97 public:
96 explicit Value(RecordInfo* value) : value_(value) {}; 98 explicit Value(RecordInfo* value) : value_(value) {};
97 bool IsValue() { return true; } 99 bool IsValue() { return true; }
100 LivenessKind Kind() { return kStrong; }
98 bool NeedsFinalization(); 101 bool NeedsFinalization();
99 TracingStatus NeedsTracing(NeedsTracingOption); 102 TracingStatus NeedsTracing(NeedsTracingOption);
100 void Accept(EdgeVisitor* visitor) { visitor->VisitValue(this); } 103 void Accept(EdgeVisitor* visitor) { visitor->VisitValue(this); }
101 RecordInfo* value() { return value_; } 104 RecordInfo* value() { return value_; }
102 private: 105 private:
103 RecordInfo* value_; 106 RecordInfo* value_;
104 }; 107 };
105 108
106 // Shared base for smart-pointer edges. 109 // Shared base for smart-pointer edges.
107 class PtrEdge : public Edge { 110 class PtrEdge : public Edge {
108 public: 111 public:
109 ~PtrEdge() { delete ptr_; } 112 ~PtrEdge() { delete ptr_; }
110 Edge* ptr() { return ptr_; } 113 Edge* ptr() { return ptr_; }
111 protected: 114 protected:
112 PtrEdge(Edge* ptr) : ptr_(ptr) { 115 PtrEdge(Edge* ptr) : ptr_(ptr) {
113 assert(ptr && "EdgePtr pointer must be non-null"); 116 assert(ptr && "EdgePtr pointer must be non-null");
114 } 117 }
115 private: 118 private:
116 Edge* ptr_; 119 Edge* ptr_;
117 }; 120 };
118 121
119 class RawPtr : public PtrEdge { 122 class RawPtr : public PtrEdge {
120 public: 123 public:
121 explicit RawPtr(Edge* ptr) : PtrEdge(ptr) { } 124 explicit RawPtr(Edge* ptr) : PtrEdge(ptr) { }
122 bool IsRawPtr() { return true; } 125 bool IsRawPtr() { return true; }
126 LivenessKind Kind() { return kWeak; }
123 bool NeedsFinalization() { return false; } 127 bool NeedsFinalization() { return false; }
124 TracingStatus NeedsTracing(NeedsTracingOption) { 128 TracingStatus NeedsTracing(NeedsTracingOption) {
125 return TracingStatus::Unneeded(); 129 return TracingStatus::Unneeded();
126 } 130 }
127 void Accept(EdgeVisitor* visitor) { visitor->VisitRawPtr(this); } 131 void Accept(EdgeVisitor* visitor) { visitor->VisitRawPtr(this); }
128 }; 132 };
129 133
130 class RefPtr : public PtrEdge { 134 class RefPtr : public PtrEdge {
131 public: 135 public:
132 explicit RefPtr(Edge* ptr) : PtrEdge(ptr) { } 136 explicit RefPtr(Edge* ptr) : PtrEdge(ptr) { }
133 bool IsRefPtr() { return true; } 137 bool IsRefPtr() { return true; }
138 LivenessKind Kind() { return kStrong; }
134 bool NeedsFinalization() { return true; } 139 bool NeedsFinalization() { return true; }
135 TracingStatus NeedsTracing(NeedsTracingOption) { 140 TracingStatus NeedsTracing(NeedsTracingOption) {
136 return TracingStatus::Unneeded(); 141 return TracingStatus::Unneeded();
137 } 142 }
138 void Accept(EdgeVisitor* visitor) { visitor->VisitRefPtr(this); } 143 void Accept(EdgeVisitor* visitor) { visitor->VisitRefPtr(this); }
139 }; 144 };
140 145
141 class OwnPtr : public PtrEdge { 146 class OwnPtr : public PtrEdge {
142 public: 147 public:
143 explicit OwnPtr(Edge* ptr) : PtrEdge(ptr) { } 148 explicit OwnPtr(Edge* ptr) : PtrEdge(ptr) { }
144 bool IsOwnPtr() { return true; } 149 bool IsOwnPtr() { return true; }
150 LivenessKind Kind() { return kStrong; }
145 bool NeedsFinalization() { return true; } 151 bool NeedsFinalization() { return true; }
146 TracingStatus NeedsTracing(NeedsTracingOption) { 152 TracingStatus NeedsTracing(NeedsTracingOption) {
147 return TracingStatus::Unneeded(); 153 return TracingStatus::Unneeded();
148 } 154 }
149 void Accept(EdgeVisitor* visitor) { visitor->VisitOwnPtr(this); } 155 void Accept(EdgeVisitor* visitor) { visitor->VisitOwnPtr(this); }
150 }; 156 };
151 157
152 class Member : public PtrEdge { 158 class Member : public PtrEdge {
153 public: 159 public:
154 explicit Member(Edge* ptr) : PtrEdge(ptr) { } 160 explicit Member(Edge* ptr) : PtrEdge(ptr) { }
155 bool IsMember() { return true; } 161 bool IsMember() { return true; }
162 LivenessKind Kind() { return kStrong; }
156 bool NeedsFinalization() { return false; } 163 bool NeedsFinalization() { return false; }
157 TracingStatus NeedsTracing(NeedsTracingOption) { 164 TracingStatus NeedsTracing(NeedsTracingOption) {
158 return TracingStatus::Needed(); 165 return TracingStatus::Needed();
159 } 166 }
160 void Accept(EdgeVisitor* visitor) { visitor->VisitMember(this); } 167 void Accept(EdgeVisitor* visitor) { visitor->VisitMember(this); }
161 }; 168 };
162 169
163 class WeakMember : public PtrEdge { 170 class WeakMember : public PtrEdge {
164 public: 171 public:
165 explicit WeakMember(Edge* ptr) : PtrEdge(ptr) { } 172 explicit WeakMember(Edge* ptr) : PtrEdge(ptr) { }
166 bool IsWeakMember() { return true; } 173 bool IsWeakMember() { return true; }
174 LivenessKind Kind() { return kWeak; }
167 bool NeedsFinalization() { return false; } 175 bool NeedsFinalization() { return false; }
168 TracingStatus NeedsTracing(NeedsTracingOption) { 176 TracingStatus NeedsTracing(NeedsTracingOption) {
169 return TracingStatus::Needed(); 177 return TracingStatus::Needed();
170 } 178 }
171 void Accept(EdgeVisitor* visitor) { visitor->VisitWeakMember(this); } 179 void Accept(EdgeVisitor* visitor) { visitor->VisitWeakMember(this); }
172 }; 180 };
173 181
174 class Persistent : public PtrEdge { 182 class Persistent : public PtrEdge {
175 public: 183 public:
176 explicit Persistent(Edge* ptr) : PtrEdge(ptr) { } 184 explicit Persistent(Edge* ptr) : PtrEdge(ptr) { }
177 bool IsPersistent() { return true; } 185 bool IsPersistent() { return true; }
186 LivenessKind Kind() { return kRoot; }
178 bool NeedsFinalization() { return true; } 187 bool NeedsFinalization() { return true; }
179 TracingStatus NeedsTracing(NeedsTracingOption) { 188 TracingStatus NeedsTracing(NeedsTracingOption) {
180 return TracingStatus::Unneeded(); 189 return TracingStatus::Unneeded();
181 } 190 }
182 void Accept(EdgeVisitor* visitor) { visitor->VisitPersistent(this); } 191 void Accept(EdgeVisitor* visitor) { visitor->VisitPersistent(this); }
183 }; 192 };
184 193
185 class Collection : public Edge { 194 class Collection : public Edge {
186 public: 195 public:
187 typedef std::vector<Edge*> Members; 196 typedef std::vector<Edge*> Members;
188 Collection(RecordInfo* info, bool on_heap, bool is_root) 197 Collection(RecordInfo* info, bool on_heap, bool is_root)
189 : info_(info), 198 : info_(info),
190 on_heap_(on_heap), 199 on_heap_(on_heap),
191 is_root_(is_root) {} 200 is_root_(is_root) {}
192 ~Collection() { 201 ~Collection() {
193 for (Members::iterator it = members_.begin(); it != members_.end(); ++it) { 202 for (Members::iterator it = members_.begin(); it != members_.end(); ++it) {
194 assert(*it && "Collection-edge members must be non-null"); 203 assert(*it && "Collection-edge members must be non-null");
195 delete *it; 204 delete *it;
196 } 205 }
197 } 206 }
198 bool IsCollection() { return true; } 207 bool IsCollection() { return true; }
208 LivenessKind Kind() { return is_root_ ? kRoot : kStrong; }
199 bool on_heap() { return on_heap_; } 209 bool on_heap() { return on_heap_; }
200 bool is_root() { return is_root_; } 210 bool is_root() { return is_root_; }
201 Members& members() { return members_; } 211 Members& members() { return members_; }
202 void Accept(EdgeVisitor* visitor) { visitor->VisitCollection(this); } 212 void Accept(EdgeVisitor* visitor) { visitor->VisitCollection(this); }
203 void AcceptMembers(EdgeVisitor* visitor) { 213 void AcceptMembers(EdgeVisitor* visitor) {
204 for (Members::iterator it = members_.begin(); it != members_.end(); ++it) 214 for (Members::iterator it = members_.begin(); it != members_.end(); ++it)
205 (*it)->Accept(visitor); 215 (*it)->Accept(visitor);
206 } 216 }
207 bool NeedsFinalization(); 217 bool NeedsFinalization();
208 TracingStatus NeedsTracing(NeedsTracingOption) { 218 TracingStatus NeedsTracing(NeedsTracingOption) {
(...skipping 10 matching lines...) Expand all
219 return status; 229 return status;
220 } 230 }
221 private: 231 private:
222 RecordInfo* info_; 232 RecordInfo* info_;
223 Members members_; 233 Members members_;
224 bool on_heap_; 234 bool on_heap_;
225 bool is_root_; 235 bool is_root_;
226 }; 236 };
227 237
228 #endif // TOOLS_BLINK_GC_PLUGIN_EDGE_H_ 238 #endif // TOOLS_BLINK_GC_PLUGIN_EDGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698