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

Unified Diff: runtime/vm/heap.cc

Issue 2566383002: ObjectGraph: Establish a HeapIterationScope *before* making the heap writable, least the sweeper in… (Closed)
Patch Set: . Created 4 years 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 a6a4daae895edfefe0e2f89a0f888fcc0cac9bb9..78f987fdf4976bcdb1f495183fbe26d203433543 100644
--- a/runtime/vm/heap.cc
+++ b/runtime/vm/heap.cc
@@ -200,28 +200,39 @@ void Heap::VisitObjects(ObjectVisitor* visitor) const {
}
-HeapIterationScope::HeapIterationScope()
+HeapIterationScope::HeapIterationScope(bool writable)
: StackResource(Thread::Current()),
- old_space_(isolate()->heap()->old_space()) {
- // It's not yet safe to iterate over a paged space while it's concurrently
- // sweeping, so wait for any such task to complete first.
- MonitorLocker ml(old_space_->tasks_lock());
+ old_space_(isolate()->heap()->old_space()),
+ writable_(writable) {
+ {
+ // It's not yet safe to iterate over a paged space while it's concurrently
+ // sweeping, so wait for any such task to complete first.
+ MonitorLocker ml(old_space_->tasks_lock());
#if defined(DEBUG)
- // We currently don't support nesting of HeapIterationScopes.
- ASSERT(old_space_->iterating_thread_ != thread());
+ // We currently don't support nesting of HeapIterationScopes.
+ ASSERT(old_space_->iterating_thread_ != thread());
#endif
- while (old_space_->tasks() > 0) {
- ml.WaitWithSafepointCheck(thread());
- }
+ while (old_space_->tasks() > 0) {
+ ml.WaitWithSafepointCheck(thread());
+ }
#if defined(DEBUG)
- ASSERT(old_space_->iterating_thread_ == NULL);
- old_space_->iterating_thread_ = thread();
+ ASSERT(old_space_->iterating_thread_ == NULL);
+ old_space_->iterating_thread_ = thread();
#endif
- old_space_->set_tasks(1);
+ old_space_->set_tasks(1);
+ }
+
+ if (writable_) {
+ thread()->heap()->WriteProtectCode(false);
+ }
}
HeapIterationScope::~HeapIterationScope() {
+ if (writable_) {
+ thread()->heap()->WriteProtectCode(true);
+ }
+
MonitorLocker ml(old_space_->tasks_lock());
#if defined(DEBUG)
ASSERT(old_space_->iterating_thread_ == thread());
« 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