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

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

Issue 1814243002: Add Thread TaskKind (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/thread.h ('k') | runtime/vm/thread_test.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) 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 Thread::Thread(Isolate* isolate) 57 Thread::Thread(Isolate* isolate)
58 : BaseThread(false), 58 : BaseThread(false),
59 stack_limit_(0), 59 stack_limit_(0),
60 stack_overflow_flags_(0), 60 stack_overflow_flags_(0),
61 isolate_(NULL), 61 isolate_(NULL),
62 heap_(NULL), 62 heap_(NULL),
63 top_exit_frame_info_(0), 63 top_exit_frame_info_(0),
64 store_buffer_block_(NULL), 64 store_buffer_block_(NULL),
65 vm_tag_(0), 65 vm_tag_(0),
66 task_kind_(kUnknownTask),
66 os_thread_(NULL), 67 os_thread_(NULL),
67 thread_lock_(new Monitor()), 68 thread_lock_(new Monitor()),
68 zone_(NULL), 69 zone_(NULL),
69 api_reusable_scope_(NULL), 70 api_reusable_scope_(NULL),
70 api_top_scope_(NULL), 71 api_top_scope_(NULL),
71 top_resource_(NULL), 72 top_resource_(NULL),
72 long_jump_base_(NULL), 73 long_jump_base_(NULL),
73 no_callback_scope_depth_(0), 74 no_callback_scope_depth_(0),
74 #if defined(DEBUG) 75 #if defined(DEBUG)
75 top_handle_scope_(NULL), 76 top_handle_scope_(NULL),
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 void Thread::clear_sticky_error() { 218 void Thread::clear_sticky_error() {
218 sticky_error_ = Error::null(); 219 sticky_error_ = Error::null();
219 } 220 }
220 221
221 222
222 bool Thread::EnterIsolate(Isolate* isolate) { 223 bool Thread::EnterIsolate(Isolate* isolate) {
223 const bool kIsMutatorThread = true; 224 const bool kIsMutatorThread = true;
224 Thread* thread = isolate->ScheduleThread(kIsMutatorThread); 225 Thread* thread = isolate->ScheduleThread(kIsMutatorThread);
225 if (thread != NULL) { 226 if (thread != NULL) {
226 ASSERT(thread->store_buffer_block_ == NULL); 227 ASSERT(thread->store_buffer_block_ == NULL);
228 thread->task_kind_ = kMutatorTask;
227 thread->StoreBufferAcquire(); 229 thread->StoreBufferAcquire();
228 return true; 230 return true;
229 } 231 }
230 return false; 232 return false;
231 } 233 }
232 234
233 235
234 void Thread::ExitIsolate() { 236 void Thread::ExitIsolate() {
235 Thread* thread = Thread::Current(); 237 Thread* thread = Thread::Current();
236 ASSERT(thread != NULL && thread->IsMutatorThread()); 238 ASSERT(thread != NULL && thread->IsMutatorThread());
237 DEBUG_ASSERT(!thread->IsAnyReusableHandleScopeActive()); 239 DEBUG_ASSERT(!thread->IsAnyReusableHandleScopeActive());
238 240 thread->task_kind_ = kUnknownTask;
239 Isolate* isolate = thread->isolate(); 241 Isolate* isolate = thread->isolate();
240 ASSERT(isolate != NULL); 242 ASSERT(isolate != NULL);
241 ASSERT(thread->execution_state() == Thread::kThreadInVM); 243 ASSERT(thread->execution_state() == Thread::kThreadInVM);
242 // Clear since GC will not visit the thread once it is unscheduled. 244 // Clear since GC will not visit the thread once it is unscheduled.
243 thread->ClearReusableHandles(); 245 thread->ClearReusableHandles();
244 thread->StoreBufferRelease(); 246 thread->StoreBufferRelease();
245 if (isolate->is_runnable()) { 247 if (isolate->is_runnable()) {
246 thread->set_vm_tag(VMTag::kIdleTagId); 248 thread->set_vm_tag(VMTag::kIdleTagId);
247 } else { 249 } else {
248 thread->set_vm_tag(VMTag::kLoadWaitTagId); 250 thread->set_vm_tag(VMTag::kLoadWaitTagId);
249 } 251 }
250 const bool kIsMutatorThread = true; 252 const bool kIsMutatorThread = true;
251 isolate->UnscheduleThread(thread, kIsMutatorThread); 253 isolate->UnscheduleThread(thread, kIsMutatorThread);
252 } 254 }
253 255
254 256
255 bool Thread::EnterIsolateAsHelper(Isolate* isolate, bool bypass_safepoint) { 257 bool Thread::EnterIsolateAsHelper(Isolate* isolate,
258 TaskKind kind,
259 bool bypass_safepoint) {
260 ASSERT(kind != kMutatorTask);
256 const bool kIsNotMutatorThread = false; 261 const bool kIsNotMutatorThread = false;
257 Thread* thread = isolate->ScheduleThread(kIsNotMutatorThread, 262 Thread* thread = isolate->ScheduleThread(kIsNotMutatorThread,
258 bypass_safepoint); 263 bypass_safepoint);
259 if (thread != NULL) { 264 if (thread != NULL) {
260 ASSERT(thread->store_buffer_block_ == NULL); 265 ASSERT(thread->store_buffer_block_ == NULL);
261 // TODO(koda): Use StoreBufferAcquire once we properly flush 266 // TODO(koda): Use StoreBufferAcquire once we properly flush
262 // before Scavenge. 267 // before Scavenge.
263 thread->store_buffer_block_ = 268 thread->store_buffer_block_ =
264 thread->isolate()->store_buffer()->PopEmptyBlock(); 269 thread->isolate()->store_buffer()->PopEmptyBlock();
265 // This thread should not be the main mutator. 270 // This thread should not be the main mutator.
271 thread->task_kind_ = kind;
266 ASSERT(!thread->IsMutatorThread()); 272 ASSERT(!thread->IsMutatorThread());
267 return true; 273 return true;
268 } 274 }
269 return false; 275 return false;
270 } 276 }
271 277
272 278
273 void Thread::ExitIsolateAsHelper(bool bypass_safepoint) { 279 void Thread::ExitIsolateAsHelper(bool bypass_safepoint) {
274 Thread* thread = Thread::Current(); 280 Thread* thread = Thread::Current();
275 ASSERT(thread != NULL); 281 ASSERT(thread != NULL);
276 ASSERT(!thread->IsMutatorThread()); 282 ASSERT(!thread->IsMutatorThread());
277 ASSERT(thread->execution_state() == Thread::kThreadInVM); 283 ASSERT(thread->execution_state() == Thread::kThreadInVM);
284 thread->task_kind_ = kUnknownTask;
278 // Clear since GC will not visit the thread once it is unscheduled. 285 // Clear since GC will not visit the thread once it is unscheduled.
279 thread->ClearReusableHandles(); 286 thread->ClearReusableHandles();
280 thread->StoreBufferRelease(); 287 thread->StoreBufferRelease();
281 Isolate* isolate = thread->isolate(); 288 Isolate* isolate = thread->isolate();
282 ASSERT(isolate != NULL); 289 ASSERT(isolate != NULL);
283 const bool kIsNotMutatorThread = false; 290 const bool kIsNotMutatorThread = false;
284 isolate->UnscheduleThread(thread, kIsNotMutatorThread, bypass_safepoint); 291 isolate->UnscheduleThread(thread, kIsNotMutatorThread, bypass_safepoint);
285 } 292 }
286 293
287 294
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 711
705 DisableThreadInterruptsScope::~DisableThreadInterruptsScope() { 712 DisableThreadInterruptsScope::~DisableThreadInterruptsScope() {
706 if (thread() != NULL) { 713 if (thread() != NULL) {
707 OSThread* os_thread = thread()->os_thread(); 714 OSThread* os_thread = thread()->os_thread();
708 ASSERT(os_thread != NULL); 715 ASSERT(os_thread != NULL);
709 os_thread->EnableThreadInterrupts(); 716 os_thread->EnableThreadInterrupts();
710 } 717 }
711 } 718 }
712 719
713 } // namespace dart 720 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/thread.h ('k') | runtime/vm/thread_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698