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

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

Issue 1041523002: Refactor Thread lifecycle interface, add Thread::Enter/ExitIsolate. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 8 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
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/isolate.h » ('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) 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"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 ASSERT(first_ != NULL); 106 ASSERT(first_ != NULL);
107 ASSERT(old_space_ != NULL); 107 ASSERT(old_space_ != NULL);
108 ASSERT(last_ != NULL); 108 ASSERT(last_ != NULL);
109 ASSERT(freelist_ != NULL); 109 ASSERT(freelist_ != NULL);
110 MonitorLocker ml(old_space_->tasks_lock()); 110 MonitorLocker ml(old_space_->tasks_lock());
111 old_space_->set_tasks(old_space_->tasks() + 1); 111 old_space_->set_tasks(old_space_->tasks() + 1);
112 ml.Notify(); 112 ml.Notify();
113 } 113 }
114 114
115 virtual void Run() { 115 virtual void Run() {
116 Isolate::SetCurrent(task_isolate_); 116 Thread::EnterIsolate(task_isolate_);
117 GCSweeper sweeper; 117 GCSweeper sweeper;
118 118
119 HeapPage* page = first_; 119 HeapPage* page = first_;
120 HeapPage* prev_page = NULL; 120 HeapPage* prev_page = NULL;
121 121
122 while (page != NULL) { 122 while (page != NULL) {
123 HeapPage* next_page = page->next(); 123 HeapPage* next_page = page->next();
124 ASSERT(page->type() == HeapPage::kData); 124 ASSERT(page->type() == HeapPage::kData);
125 bool page_in_use = sweeper.SweepPage(page, freelist_, false); 125 bool page_in_use = sweeper.SweepPage(page, freelist_, false);
126 if (page_in_use) { 126 if (page_in_use) {
127 prev_page = page; 127 prev_page = page;
128 } else { 128 } else {
129 old_space_->FreePage(page, prev_page); 129 old_space_->FreePage(page, prev_page);
130 } 130 }
131 { 131 {
132 // Notify the mutator thread that we have added elements to the free 132 // Notify the mutator thread that we have added elements to the free
133 // list or that more capacity is available. 133 // list or that more capacity is available.
134 MonitorLocker ml(old_space_->tasks_lock()); 134 MonitorLocker ml(old_space_->tasks_lock());
135 ml.Notify(); 135 ml.Notify();
136 } 136 }
137 if (page == last_) break; 137 if (page == last_) break;
138 page = next_page; 138 page = next_page;
139 } 139 }
140 // This sweeper task is done. Notify the original isolate. 140 // This sweeper task is done. Notify the original isolate.
141 { 141 {
142 MonitorLocker ml(old_space_->tasks_lock()); 142 MonitorLocker ml(old_space_->tasks_lock());
143 old_space_->set_tasks(old_space_->tasks() - 1); 143 old_space_->set_tasks(old_space_->tasks() - 1);
144 ml.Notify(); 144 ml.Notify();
145 } 145 }
146 Isolate::SetCurrent(NULL); 146 Thread::ExitIsolate();
147 delete task_isolate_; 147 delete task_isolate_;
148 } 148 }
149 149
150 private: 150 private:
151 Isolate* task_isolate_; 151 Isolate* task_isolate_;
152 PageSpace* old_space_; 152 PageSpace* old_space_;
153 HeapPage* first_; 153 HeapPage* first_;
154 HeapPage* last_; 154 HeapPage* last_;
155 FreeList* freelist_; 155 FreeList* freelist_;
156 }; 156 };
157 157
158 158
159 void GCSweeper::SweepConcurrent(Isolate* isolate, 159 void GCSweeper::SweepConcurrent(Isolate* isolate,
160 HeapPage* first, 160 HeapPage* first,
161 HeapPage* last, 161 HeapPage* last,
162 FreeList* freelist) { 162 FreeList* freelist) {
163 SweeperTask* task = 163 SweeperTask* task =
164 new SweeperTask(isolate->ShallowCopy(), 164 new SweeperTask(isolate->ShallowCopy(),
165 isolate->heap()->old_space(), 165 isolate->heap()->old_space(),
166 first, last, 166 first, last,
167 freelist); 167 freelist);
168 ThreadPool* pool = Dart::thread_pool(); 168 ThreadPool* pool = Dart::thread_pool();
169 pool->Run(task); 169 pool->Run(task);
170 } 170 }
171 171
172 } // namespace dart 172 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698