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

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

Issue 1814813003: Collect samples for background threads. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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 | « runtime/vm/gc_marker.cc ('k') | runtime/vm/precompiler.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) 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/safepoint.h"
13 #include "vm/thread_pool.h" 13 #include "vm/thread_pool.h"
14 #include "vm/timeline.h"
14 15
15 namespace dart { 16 namespace dart {
16 17
17 bool GCSweeper::SweepPage(HeapPage* page, FreeList* freelist, bool locked) { 18 bool GCSweeper::SweepPage(HeapPage* page, FreeList* freelist, bool locked) {
18 // Keep track whether this page is still in use. 19 // Keep track whether this page is still in use.
19 bool in_use = false; 20 bool in_use = false;
20 21
21 bool is_executable = (page->type() == HeapPage::kExecutable); 22 bool is_executable = (page->type() == HeapPage::kExecutable);
22 uword start = page->object_start(); 23 uword start = page->object_start();
23 uword end = page->object_end(); 24 uword end = page->object_end();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 ASSERT(last_ != NULL); 110 ASSERT(last_ != NULL);
110 ASSERT(freelist_ != NULL); 111 ASSERT(freelist_ != NULL);
111 MonitorLocker ml(old_space_->tasks_lock()); 112 MonitorLocker ml(old_space_->tasks_lock());
112 old_space_->set_tasks(old_space_->tasks() + 1); 113 old_space_->set_tasks(old_space_->tasks() + 1);
113 ml.Notify(); 114 ml.Notify();
114 } 115 }
115 116
116 virtual void Run() { 117 virtual void Run() {
117 bool result = Thread::EnterIsolateAsHelper(task_isolate_); 118 bool result = Thread::EnterIsolateAsHelper(task_isolate_);
118 ASSERT(result); 119 ASSERT(result);
119 Thread* thread = Thread::Current(); 120 {
120 GCSweeper sweeper; 121 Thread* thread = Thread::Current();
122 TimelineDurationScope tds(thread, Timeline::GetGCStream(), "SweeperTask");
123 GCSweeper sweeper;
121 124
122 HeapPage* page = first_; 125 HeapPage* page = first_;
123 HeapPage* prev_page = NULL; 126 HeapPage* prev_page = NULL;
124 127
125 while (page != NULL) { 128 while (page != NULL) {
126 thread->CheckForSafepoint(); 129 thread->CheckForSafepoint();
127 HeapPage* next_page = page->next(); 130 HeapPage* next_page = page->next();
128 ASSERT(page->type() == HeapPage::kData); 131 ASSERT(page->type() == HeapPage::kData);
129 bool page_in_use = sweeper.SweepPage(page, freelist_, false); 132 bool page_in_use = sweeper.SweepPage(page, freelist_, false);
130 if (page_in_use) { 133 if (page_in_use) {
131 prev_page = page; 134 prev_page = page;
132 } else { 135 } else {
133 old_space_->FreePage(page, prev_page); 136 old_space_->FreePage(page, prev_page);
137 }
138 {
139 // Notify the mutator thread that we have added elements to the free
140 // list or that more capacity is available.
141 MonitorLocker ml(old_space_->tasks_lock());
142 ml.Notify();
143 }
144 if (page == last_) break;
145 page = next_page;
134 } 146 }
135 {
136 // Notify the mutator thread that we have added elements to the free
137 // list or that more capacity is available.
138 MonitorLocker ml(old_space_->tasks_lock());
139 ml.Notify();
140 }
141 if (page == last_) break;
142 page = next_page;
143 } 147 }
144 // Exit isolate cleanly *before* notifying it, to avoid shutdown race. 148 // Exit isolate cleanly *before* notifying it, to avoid shutdown race.
145 Thread::ExitIsolateAsHelper(); 149 Thread::ExitIsolateAsHelper();
146 // This sweeper task is done. Notify the original isolate. 150 // This sweeper task is done. Notify the original isolate.
147 { 151 {
148 MonitorLocker ml(old_space_->tasks_lock()); 152 MonitorLocker ml(old_space_->tasks_lock());
149 old_space_->set_tasks(old_space_->tasks() - 1); 153 old_space_->set_tasks(old_space_->tasks() - 1);
150 ml.Notify(); 154 ml.Notify();
151 } 155 }
152 } 156 }
(...skipping 14 matching lines...) Expand all
167 SweeperTask* task = 171 SweeperTask* task =
168 new SweeperTask(isolate, 172 new SweeperTask(isolate,
169 isolate->heap()->old_space(), 173 isolate->heap()->old_space(),
170 first, last, 174 first, last,
171 freelist); 175 freelist);
172 ThreadPool* pool = Dart::thread_pool(); 176 ThreadPool* pool = Dart::thread_pool();
173 pool->Run(task); 177 pool->Run(task);
174 } 178 }
175 179
176 } // namespace dart 180 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/gc_marker.cc ('k') | runtime/vm/precompiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698