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

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

Issue 1541073002: Implement safepointing of threads (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: self-review-comments Created 4 years, 11 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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/gc_sweeper.h" 5 #include "vm/gc_sweeper.h"
6 6
7 #include "vm/freelist.h" 7 #include "vm/freelist.h"
8 #include "vm/globals.h" 8 #include "vm/globals.h"
9 #include "vm/heap.h" 9 #include "vm/heap.h"
10 #include "vm/lockers.h" 10 #include "vm/lockers.h"
11 #include "vm/pages.h" 11 #include "vm/pages.h"
12 #include "vm/safepoint.h"
12 #include "vm/thread_pool.h" 13 #include "vm/thread_pool.h"
13 #include "vm/thread_registry.h"
14 14
15 namespace dart { 15 namespace dart {
16 16
17 bool GCSweeper::SweepPage(HeapPage* page, FreeList* freelist, bool locked) { 17 bool GCSweeper::SweepPage(HeapPage* page, FreeList* freelist, bool locked) {
18 // Keep track whether this page is still in use. 18 // Keep track whether this page is still in use.
19 bool in_use = false; 19 bool in_use = false;
20 20
21 bool is_executable = (page->type() == HeapPage::kExecutable); 21 bool is_executable = (page->type() == HeapPage::kExecutable);
22 uword start = page->object_start(); 22 uword start = page->object_start();
23 uword end = page->object_end(); 23 uword end = page->object_end();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 ASSERT(last_ != NULL); 109 ASSERT(last_ != NULL);
110 ASSERT(freelist_ != NULL); 110 ASSERT(freelist_ != NULL);
111 MonitorLocker ml(old_space_->tasks_lock()); 111 MonitorLocker ml(old_space_->tasks_lock());
112 old_space_->set_tasks(old_space_->tasks() + 1); 112 old_space_->set_tasks(old_space_->tasks() + 1);
113 ml.Notify(); 113 ml.Notify();
114 } 114 }
115 115
116 virtual void Run() { 116 virtual void Run() {
117 bool result = Thread::EnterIsolateAsHelper(task_isolate_); 117 bool result = Thread::EnterIsolateAsHelper(task_isolate_);
118 ASSERT(result); 118 ASSERT(result);
119 Thread* thread = Thread::Current();
119 GCSweeper sweeper; 120 GCSweeper sweeper;
120 121
121 HeapPage* page = first_; 122 HeapPage* page = first_;
122 HeapPage* prev_page = NULL; 123 HeapPage* prev_page = NULL;
123 124
124 while (page != NULL) { 125 while (page != NULL) {
125 task_isolate_->thread_registry()->CheckSafepoint();
126 HeapPage* next_page = page->next(); 126 HeapPage* next_page = page->next();
127 ASSERT(page->type() == HeapPage::kData); 127 ASSERT(page->type() == HeapPage::kData);
128 bool page_in_use = sweeper.SweepPage(page, freelist_, false); 128 bool page_in_use = sweeper.SweepPage(page, freelist_, false);
129 if (page_in_use) { 129 if (page_in_use) {
130 prev_page = page; 130 prev_page = page;
131 } else { 131 } else {
132 old_space_->FreePage(page, prev_page); 132 old_space_->FreePage(page, prev_page);
133 } 133 }
134 { 134 {
135 // Notify the mutator thread that we have added elements to the free 135 // Notify the mutator thread that we have added elements to the free
136 // list or that more capacity is available. 136 // list or that more capacity is available.
137 TransitionVMToBlocked transition(thread);
zra 2016/01/08 23:32:07 I think I'm a little confused by the meaning of th
siva 2016/01/12 21:26:22 True this was a hack I did initially to get things
137 MonitorLocker ml(old_space_->tasks_lock()); 138 MonitorLocker ml(old_space_->tasks_lock());
138 ml.Notify(); 139 ml.Notify();
139 } 140 }
140 if (page == last_) break; 141 if (page == last_) break;
141 page = next_page; 142 page = next_page;
142 } 143 }
143 // Exit isolate cleanly *before* notifying it, to avoid shutdown race. 144 // Exit isolate cleanly *before* notifying it, to avoid shutdown race.
144 Thread::ExitIsolateAsHelper(); 145 Thread::ExitIsolateAsHelper();
145 // This sweeper task is done. Notify the original isolate. 146 // This sweeper task is done. Notify the original isolate.
146 { 147 {
(...skipping 19 matching lines...) Expand all
166 SweeperTask* task = 167 SweeperTask* task =
167 new SweeperTask(isolate, 168 new SweeperTask(isolate,
168 isolate->heap()->old_space(), 169 isolate->heap()->old_space(),
169 first, last, 170 first, last,
170 freelist); 171 freelist);
171 ThreadPool* pool = Dart::thread_pool(); 172 ThreadPool* pool = Dart::thread_pool();
172 pool->Run(task); 173 pool->Run(task);
173 } 174 }
174 175
175 } // namespace dart 176 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698