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

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

Issue 1533023002: - Make sure to prepare all threads for GC. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address review comments. Created 5 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 unified diff | Download patch
« no previous file with comments | « runtime/vm/thread.h ('k') | runtime/vm/thread_registry.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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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/thread.h" 5 #include "vm/thread.h"
6 6
7 #include "vm/dart_api_state.h" 7 #include "vm/dart_api_state.h"
8 #include "vm/growable_array.h" 8 #include "vm/growable_array.h"
9 #include "vm/isolate.h" 9 #include "vm/isolate.h"
10 #include "vm/lockers.h" 10 #include "vm/lockers.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 ASSERT(!thread->IsMutatorThread()); 229 ASSERT(!thread->IsMutatorThread());
230 thread->StoreBufferRelease(); 230 thread->StoreBufferRelease();
231 Isolate* isolate = thread->isolate(); 231 Isolate* isolate = thread->isolate();
232 ASSERT(isolate != NULL); 232 ASSERT(isolate != NULL);
233 const bool kIsNotMutatorThread = false; 233 const bool kIsNotMutatorThread = false;
234 ThreadRegistry* tr = isolate->thread_registry(); 234 ThreadRegistry* tr = isolate->thread_registry();
235 tr->Unschedule(thread, kIsNotMutatorThread, bypass_safepoint); 235 tr->Unschedule(thread, kIsNotMutatorThread, bypass_safepoint);
236 } 236 }
237 237
238 238
239 // TODO(koda): Make non-static and invoke in SafepointThreads.
240 void Thread::PrepareForGC() { 239 void Thread::PrepareForGC() {
241 Thread* thread = Thread::Current(); 240 ASSERT(isolate()->thread_registry()->AtSafepoint());
242 // Prevent scheduling another GC. 241 // Prevent scheduling another GC by ignoring the threshold.
243 thread->StoreBufferRelease(StoreBuffer::kIgnoreThreshold); 242 StoreBufferRelease(StoreBuffer::kIgnoreThreshold);
244 // Make sure to get an *empty* block; the isolate needs all entries 243 // Make sure to get an *empty* block; the isolate needs all entries
245 // at GC time. 244 // at GC time.
246 // TODO(koda): Replace with an epilogue (PrepareAfterGC) that acquires. 245 // TODO(koda): Replace with an epilogue (PrepareAfterGC) that acquires.
247 thread->store_buffer_block_ = 246 store_buffer_block_ = isolate()->store_buffer()->PopEmptyBlock();
248 thread->isolate()->store_buffer()->PopEmptyBlock();
249 } 247 }
250 248
251 249
252 void Thread::StoreBufferBlockProcess(StoreBuffer::ThresholdPolicy policy) { 250 void Thread::StoreBufferBlockProcess(StoreBuffer::ThresholdPolicy policy) {
253 StoreBufferRelease(policy); 251 StoreBufferRelease(policy);
254 StoreBufferAcquire(); 252 StoreBufferAcquire();
255 } 253 }
256 254
257 255
258 void Thread::StoreBufferAddObject(RawObject* obj) { 256 void Thread::StoreBufferAddObject(RawObject* obj) {
259 store_buffer_block_->Push(obj); 257 store_buffer_block_->Push(obj);
260 if (store_buffer_block_->IsFull()) { 258 if (store_buffer_block_->IsFull()) {
261 StoreBufferBlockProcess(StoreBuffer::kCheckThreshold); 259 StoreBufferBlockProcess(StoreBuffer::kCheckThreshold);
262 } 260 }
263 } 261 }
264 262
265 263
266 void Thread::StoreBufferAddObjectGC(RawObject* obj) { 264 void Thread::StoreBufferAddObjectGC(RawObject* obj) {
267 store_buffer_block_->Push(obj); 265 store_buffer_block_->Push(obj);
268 if (store_buffer_block_->IsFull()) { 266 if (store_buffer_block_->IsFull()) {
269 StoreBufferBlockProcess(StoreBuffer::kIgnoreThreshold); 267 StoreBufferBlockProcess(StoreBuffer::kIgnoreThreshold);
270 } 268 }
271 } 269 }
272 270
273 271
274 void Thread::StoreBufferRelease(StoreBuffer::ThresholdPolicy policy) { 272 void Thread::StoreBufferRelease(StoreBuffer::ThresholdPolicy policy) {
275 StoreBufferBlock* block = store_buffer_block_; 273 StoreBufferBlock* block = store_buffer_block_;
276 store_buffer_block_ = NULL; 274 store_buffer_block_ = NULL;
277 isolate_->store_buffer()->PushBlock(block, policy); 275 isolate()->store_buffer()->PushBlock(block, policy);
278 } 276 }
279 277
280 278
281 void Thread::StoreBufferAcquire() { 279 void Thread::StoreBufferAcquire() {
282 store_buffer_block_ = isolate()->store_buffer()->PopNonFullBlock(); 280 store_buffer_block_ = isolate()->store_buffer()->PopNonFullBlock();
283 } 281 }
284 282
285 283
286 bool Thread::IsMutatorThread() const { 284 bool Thread::IsMutatorThread() const {
287 return ((isolate_ != NULL) && (isolate_->mutator_thread() == this)); 285 return ((isolate_ != NULL) && (isolate_->mutator_thread() == this));
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 447
450 DisableThreadInterruptsScope::~DisableThreadInterruptsScope() { 448 DisableThreadInterruptsScope::~DisableThreadInterruptsScope() {
451 if (thread() != NULL) { 449 if (thread() != NULL) {
452 OSThread* os_thread = thread()->os_thread(); 450 OSThread* os_thread = thread()->os_thread();
453 ASSERT(os_thread != NULL); 451 ASSERT(os_thread != NULL);
454 os_thread->EnableThreadInterrupts(); 452 os_thread->EnableThreadInterrupts();
455 } 453 }
456 } 454 }
457 455
458 } // namespace dart 456 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/thread.h ('k') | runtime/vm/thread_registry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698