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

Side by Side Diff: runtime/vm/object_graph.cc

Issue 1179973005: Make ObjectGraph wait for concurrent sweeper before using mark bits (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « no previous file | runtime/vm/object_graph_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/object_graph.h" 5 #include "vm/object_graph.h"
6 6
7 #include "vm/dart.h" 7 #include "vm/dart.h"
8 #include "vm/growable_array.h" 8 #include "vm/growable_array.h"
9 #include "vm/isolate.h" 9 #include "vm/isolate.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 public: 140 public:
141 explicit Unmarker(Isolate* isolate) : ObjectVisitor(isolate) { } 141 explicit Unmarker(Isolate* isolate) : ObjectVisitor(isolate) { }
142 142
143 void VisitObject(RawObject* obj) { 143 void VisitObject(RawObject* obj) {
144 if (obj->IsMarked()) { 144 if (obj->IsMarked()) {
145 obj->ClearMarkBit(); 145 obj->ClearMarkBit();
146 } 146 }
147 } 147 }
148 148
149 static void UnmarkAll(Isolate* isolate) { 149 static void UnmarkAll(Isolate* isolate) {
150 PageSpace* old_space = isolate->heap()->old_space();
151 MonitorLocker ml(old_space->tasks_lock());
152 while (old_space->tasks() > 0) {
153 ml.Wait();
154 }
155 Unmarker unmarker(isolate); 150 Unmarker unmarker(isolate);
156 isolate->heap()->VisitObjects(&unmarker); 151 isolate->heap()->VisitObjects(&unmarker);
157 } 152 }
158 153
159 private: 154 private:
160 DISALLOW_COPY_AND_ASSIGN(Unmarker); 155 DISALLOW_COPY_AND_ASSIGN(Unmarker);
161 }; 156 };
162 157
163 158
164 ObjectGraph::ObjectGraph(Isolate* isolate) 159 ObjectGraph::ObjectGraph(Isolate* isolate)
165 : StackResource(isolate) { 160 : StackResource(isolate) {
166 // The VM isolate has all its objects pre-marked, so iterating over it 161 // The VM isolate has all its objects pre-marked, so iterating over it
167 // would be a no-op. 162 // would be a no-op.
168 ASSERT(isolate != Dart::vm_isolate()); 163 ASSERT(isolate != Dart::vm_isolate());
169 isolate->heap()->WriteProtectCode(false); 164 isolate->heap()->WriteProtectCode(false);
170 } 165 }
171 166
172 167
173 ObjectGraph::~ObjectGraph() { 168 ObjectGraph::~ObjectGraph() {
174 isolate()->heap()->WriteProtectCode(true); 169 isolate()->heap()->WriteProtectCode(true);
175 } 170 }
176 171
177 172
178 void ObjectGraph::IterateObjects(ObjectGraph::Visitor* visitor) { 173 void ObjectGraph::IterateObjects(ObjectGraph::Visitor* visitor) {
179 NoSafepointScope no_safepoint_scope_; 174 NoSafepointScope no_safepoint_scope_;
175 PageSpace* old_space = isolate()->heap()->old_space();
176 MonitorLocker ml(old_space->tasks_lock());
177 while (old_space->tasks() > 0) {
178 ml.Wait();
179 }
180 Stack stack(isolate()); 180 Stack stack(isolate());
181 isolate()->VisitObjectPointers(&stack, false, false); 181 isolate()->VisitObjectPointers(&stack, false, false);
182 stack.TraverseGraph(visitor); 182 stack.TraverseGraph(visitor);
183 Unmarker::UnmarkAll(isolate()); 183 Unmarker::UnmarkAll(isolate());
184 } 184 }
185 185
186 186
187 void ObjectGraph::IterateObjectsFrom(const Object& root, 187 void ObjectGraph::IterateObjectsFrom(const Object& root,
188 ObjectGraph::Visitor* visitor) { 188 ObjectGraph::Visitor* visitor) {
189 NoSafepointScope no_safepoint_scope_; 189 NoSafepointScope no_safepoint_scope_;
190 PageSpace* old_space = isolate()->heap()->old_space();
191 MonitorLocker ml(old_space->tasks_lock());
192 while (old_space->tasks() > 0) {
193 ml.Wait();
194 }
190 Stack stack(isolate()); 195 Stack stack(isolate());
191 RawObject* root_raw = root.raw(); 196 RawObject* root_raw = root.raw();
192 stack.VisitPointer(&root_raw); 197 stack.VisitPointer(&root_raw);
193 stack.TraverseGraph(visitor); 198 stack.TraverseGraph(visitor);
194 // TODO(koda): Optimize if we only visited a small subgraph. 199 // TODO(koda): Optimize if we only visited a small subgraph.
195 Unmarker::UnmarkAll(isolate()); 200 Unmarker::UnmarkAll(isolate());
196 } 201 }
197 202
198 203
199 class SizeVisitor : public ObjectGraph::Visitor { 204 class SizeVisitor : public ObjectGraph::Visitor {
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 { 467 {
463 WritePointerVisitor ptr_writer(isolate(), stream); 468 WritePointerVisitor ptr_writer(isolate(), stream);
464 isolate()->VisitObjectPointers(&ptr_writer, false, false); 469 isolate()->VisitObjectPointers(&ptr_writer, false, false);
465 } 470 }
466 stream->WriteUnsigned(0); 471 stream->WriteUnsigned(0);
467 IterateObjects(&visitor); 472 IterateObjects(&visitor);
468 return visitor.count() + 1; // + root 473 return visitor.count() + 1; // + root
469 } 474 }
470 475
471 } // namespace dart 476 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/object_graph_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698