| OLD | NEW |
| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 165 |
| 166 | 166 |
| 167 RawGrowableObjectArray* Thread::pending_functions() { | 167 RawGrowableObjectArray* Thread::pending_functions() { |
| 168 if (pending_functions_ == GrowableObjectArray::null()) { | 168 if (pending_functions_ == GrowableObjectArray::null()) { |
| 169 pending_functions_ = GrowableObjectArray::New(Heap::kOld); | 169 pending_functions_ = GrowableObjectArray::New(Heap::kOld); |
| 170 } | 170 } |
| 171 return pending_functions_; | 171 return pending_functions_; |
| 172 } | 172 } |
| 173 | 173 |
| 174 | 174 |
| 175 void Thread::EnterIsolate(Isolate* isolate) { | 175 bool Thread::EnterIsolate(Isolate* isolate) { |
| 176 const bool kIsMutatorThread = true; | 176 const bool kIsMutatorThread = true; |
| 177 const bool kDontBypassSafepoints = false; | 177 const bool kDontBypassSafepoints = false; |
| 178 ThreadRegistry* tr = isolate->thread_registry(); | 178 ThreadRegistry* tr = isolate->thread_registry(); |
| 179 Thread* thread = tr->Schedule( | 179 Thread* thread = tr->Schedule( |
| 180 isolate, kIsMutatorThread, kDontBypassSafepoints); | 180 isolate, kIsMutatorThread, kDontBypassSafepoints); |
| 181 isolate->MakeCurrentThreadMutator(thread); | 181 if (thread != NULL) { |
| 182 thread->set_vm_tag(VMTag::kVMTagId); | 182 isolate->MakeCurrentThreadMutator(thread); |
| 183 ASSERT(thread->store_buffer_block_ == NULL); | 183 thread->set_vm_tag(VMTag::kVMTagId); |
| 184 thread->StoreBufferAcquire(); | 184 ASSERT(thread->store_buffer_block_ == NULL); |
| 185 thread->StoreBufferAcquire(); |
| 186 return true; |
| 187 } |
| 188 return false; |
| 185 } | 189 } |
| 186 | 190 |
| 187 | 191 |
| 188 void Thread::ExitIsolate() { | 192 void Thread::ExitIsolate() { |
| 189 Thread* thread = Thread::Current(); | 193 Thread* thread = Thread::Current(); |
| 190 ASSERT(thread != NULL); | 194 ASSERT(thread != NULL); |
| 191 ASSERT(thread->IsMutatorThread()); | 195 ASSERT(thread->IsMutatorThread()); |
| 192 #if defined(DEBUG) | 196 #if defined(DEBUG) |
| 193 ASSERT(!thread->IsAnyReusableHandleScopeActive()); | 197 ASSERT(!thread->IsAnyReusableHandleScopeActive()); |
| 194 #endif // DEBUG | 198 #endif // DEBUG |
| 195 // Clear since GC will not visit the thread once it is unscheduled. | 199 // Clear since GC will not visit the thread once it is unscheduled. |
| 196 thread->ClearReusableHandles(); | 200 thread->ClearReusableHandles(); |
| 197 thread->StoreBufferRelease(); | 201 thread->StoreBufferRelease(); |
| 198 Isolate* isolate = thread->isolate(); | 202 Isolate* isolate = thread->isolate(); |
| 199 ASSERT(isolate != NULL); | 203 ASSERT(isolate != NULL); |
| 200 if (isolate->is_runnable()) { | 204 if (isolate->is_runnable()) { |
| 201 thread->set_vm_tag(VMTag::kIdleTagId); | 205 thread->set_vm_tag(VMTag::kIdleTagId); |
| 202 } else { | 206 } else { |
| 203 thread->set_vm_tag(VMTag::kLoadWaitTagId); | 207 thread->set_vm_tag(VMTag::kLoadWaitTagId); |
| 204 } | 208 } |
| 205 const bool kIsMutatorThread = true; | 209 const bool kIsMutatorThread = true; |
| 206 const bool kDontBypassSafepoints = false; | 210 const bool kDontBypassSafepoints = false; |
| 207 ThreadRegistry* tr = isolate->thread_registry(); | 211 ThreadRegistry* tr = isolate->thread_registry(); |
| 208 tr->Unschedule(thread, kIsMutatorThread, kDontBypassSafepoints); | 212 tr->Unschedule(thread, kIsMutatorThread, kDontBypassSafepoints); |
| 209 isolate->ClearMutatorThread(); | 213 isolate->ClearMutatorThread(); |
| 210 } | 214 } |
| 211 | 215 |
| 212 | 216 |
| 213 void Thread::EnterIsolateAsHelper(Isolate* isolate, bool bypass_safepoint) { | 217 bool Thread::EnterIsolateAsHelper(Isolate* isolate, bool bypass_safepoint) { |
| 214 const bool kIsNotMutatorThread = false; | 218 const bool kIsNotMutatorThread = false; |
| 215 ThreadRegistry* tr = isolate->thread_registry(); | 219 ThreadRegistry* tr = isolate->thread_registry(); |
| 216 Thread* thread = tr->Schedule(isolate, kIsNotMutatorThread, bypass_safepoint); | 220 Thread* thread = tr->Schedule(isolate, kIsNotMutatorThread, bypass_safepoint); |
| 217 ASSERT(thread->store_buffer_block_ == NULL); | 221 if (thread != NULL) { |
| 218 // TODO(koda): Use StoreBufferAcquire once we properly flush before Scavenge. | 222 ASSERT(thread->store_buffer_block_ == NULL); |
| 219 thread->store_buffer_block_ = | 223 // TODO(koda): Use StoreBufferAcquire once we properly flush |
| 220 thread->isolate()->store_buffer()->PopEmptyBlock(); | 224 // before Scavenge. |
| 221 // This thread should not be the main mutator. | 225 thread->store_buffer_block_ = |
| 222 ASSERT(!thread->IsMutatorThread()); | 226 thread->isolate()->store_buffer()->PopEmptyBlock(); |
| 227 // This thread should not be the main mutator. |
| 228 ASSERT(!thread->IsMutatorThread()); |
| 229 return true; |
| 230 } |
| 231 return false; |
| 223 } | 232 } |
| 224 | 233 |
| 225 | 234 |
| 226 void Thread::ExitIsolateAsHelper(bool bypass_safepoint) { | 235 void Thread::ExitIsolateAsHelper(bool bypass_safepoint) { |
| 227 Thread* thread = Thread::Current(); | 236 Thread* thread = Thread::Current(); |
| 228 ASSERT(thread != NULL); | 237 ASSERT(thread != NULL); |
| 229 ASSERT(!thread->IsMutatorThread()); | 238 ASSERT(!thread->IsMutatorThread()); |
| 230 thread->StoreBufferRelease(); | 239 thread->StoreBufferRelease(); |
| 231 Isolate* isolate = thread->isolate(); | 240 Isolate* isolate = thread->isolate(); |
| 232 ASSERT(isolate != NULL); | 241 ASSERT(isolate != NULL); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 | 458 |
| 450 DisableThreadInterruptsScope::~DisableThreadInterruptsScope() { | 459 DisableThreadInterruptsScope::~DisableThreadInterruptsScope() { |
| 451 if (thread() != NULL) { | 460 if (thread() != NULL) { |
| 452 OSThread* os_thread = thread()->os_thread(); | 461 OSThread* os_thread = thread()->os_thread(); |
| 453 ASSERT(os_thread != NULL); | 462 ASSERT(os_thread != NULL); |
| 454 os_thread->EnableThreadInterrupts(); | 463 os_thread->EnableThreadInterrupts(); |
| 455 } | 464 } |
| 456 } | 465 } |
| 457 | 466 |
| 458 } // namespace dart | 467 } // namespace dart |
| OLD | NEW |