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

Unified Diff: runtime/vm/heap.cc

Issue 2995543004: [vm, gc] Require a safepoint for heap iteration. (Closed)
Patch Set: explicit-thread Created 3 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/heap.h ('k') | runtime/vm/isolate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/heap.cc
diff --git a/runtime/vm/heap.cc b/runtime/vm/heap.cc
index ad1f24deadd339df802c63bc1e38e44f711af771..7cdbf210ae2a50e27149b688ce83e2ad31dbf145 100644
--- a/runtime/vm/heap.cc
+++ b/runtime/vm/heap.cc
@@ -14,6 +14,7 @@
#include "vm/os.h"
#include "vm/pages.h"
#include "vm/raw_object.h"
+#include "vm/safepoint.h"
#include "vm/scavenger.h"
#include "vm/service.h"
#include "vm/service_event.h"
@@ -190,9 +191,10 @@ void Heap::VisitObjectsImagePages(ObjectVisitor* visitor) const {
old_space_.VisitObjectsImagePages(visitor);
}
-HeapIterationScope::HeapIterationScope(bool writable)
- : StackResource(Thread::Current()),
- old_space_(isolate()->heap()->old_space()),
+HeapIterationScope::HeapIterationScope(Thread* thread, bool writable)
+ : StackResource(thread),
+ heap_(isolate()->heap()),
+ old_space_(heap_->old_space()),
writable_(writable) {
{
// It's not yet safe to iterate over a paged space while it's concurrently
@@ -200,28 +202,32 @@ HeapIterationScope::HeapIterationScope(bool writable)
MonitorLocker ml(old_space_->tasks_lock());
#if defined(DEBUG)
// We currently don't support nesting of HeapIterationScopes.
- ASSERT(old_space_->iterating_thread_ != thread());
+ ASSERT(old_space_->iterating_thread_ != thread);
#endif
while (old_space_->tasks() > 0) {
- ml.WaitWithSafepointCheck(thread());
+ ml.WaitWithSafepointCheck(thread);
}
#if defined(DEBUG)
ASSERT(old_space_->iterating_thread_ == NULL);
- old_space_->iterating_thread_ = thread();
+ old_space_->iterating_thread_ = thread;
#endif
old_space_->set_tasks(1);
}
+ isolate()->safepoint_handler()->SafepointThreads(thread);
+
if (writable_) {
- thread()->heap()->WriteProtectCode(false);
+ heap_->WriteProtectCode(false);
}
}
HeapIterationScope::~HeapIterationScope() {
if (writable_) {
- thread()->heap()->WriteProtectCode(true);
+ heap_->WriteProtectCode(true);
}
+ isolate()->safepoint_handler()->ResumeThreads(thread());
+
MonitorLocker ml(old_space_->tasks_lock());
#if defined(DEBUG)
ASSERT(old_space_->iterating_thread_ == thread());
@@ -232,21 +238,37 @@ HeapIterationScope::~HeapIterationScope() {
ml.NotifyAll();
}
-void Heap::IterateObjects(ObjectVisitor* visitor) const {
- // The visitor must not allocate from the heap.
- NoSafepointScope no_safepoint_scope_;
- new_space_.VisitObjects(visitor);
- IterateOldObjects(visitor);
+void HeapIterationScope::IterateObjects(ObjectVisitor* visitor) const {
+ heap_->VisitObjects(visitor);
}
-void Heap::IterateOldObjects(ObjectVisitor* visitor) const {
- HeapIterationScope heap_iteration_scope;
- old_space_.VisitObjects(visitor);
+void HeapIterationScope::IterateObjectsNoImagePages(
+ ObjectVisitor* visitor) const {
+ heap_->new_space()->VisitObjects(visitor);
+ heap_->old_space()->VisitObjectsNoImagePages(visitor);
}
-void Heap::IterateOldObjectsNoImagePages(ObjectVisitor* visitor) const {
- HeapIterationScope heap_iteration_scope;
- old_space_.VisitObjectsNoImagePages(visitor);
+void HeapIterationScope::IterateOldObjects(ObjectVisitor* visitor) const {
+ old_space_->VisitObjects(visitor);
+}
+
+void HeapIterationScope::IterateOldObjectsNoImagePages(
+ ObjectVisitor* visitor) const {
+ old_space_->VisitObjectsNoImagePages(visitor);
+}
+
+void HeapIterationScope::IterateVMIsolateObjects(ObjectVisitor* visitor) const {
+ Dart::vm_isolate()->heap()->VisitObjects(visitor);
+}
+
+void HeapIterationScope::IterateObjectPointers(ObjectPointerVisitor* visitor,
+ bool validate_frames) {
+ isolate()->VisitObjectPointers(visitor, validate_frames);
+}
+
+void HeapIterationScope::IterateStackPointers(ObjectPointerVisitor* visitor,
+ bool validate_frames) {
+ isolate()->VisitStackPointers(visitor, validate_frames);
}
void Heap::VisitObjectPointers(ObjectPointerVisitor* visitor) const {
@@ -263,7 +285,6 @@ RawInstructions* Heap::FindObjectInCodeSpace(FindObjectVisitor* visitor) const {
}
RawObject* Heap::FindOldObject(FindObjectVisitor* visitor) const {
- HeapIterationScope heap_iteration_scope;
return old_space_.FindObject(visitor, HeapPage::kData);
}
@@ -547,7 +568,7 @@ ObjectSet* Heap::CreateAllocatedObjectSet(
}
bool Heap::Verify(MarkExpectation mark_expectation) const {
- HeapIterationScope heap_iteration_scope;
+ HeapIterationScope heap_iteration_scope(Thread::Current());
return VerifyGC(mark_expectation);
}
« no previous file with comments | « runtime/vm/heap.h ('k') | runtime/vm/isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698