| 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/growable_array.h" | 7 #include "vm/growable_array.h" |
| 8 #include "vm/isolate.h" | 8 #include "vm/isolate.h" |
| 9 #include "vm/lockers.h" | 9 #include "vm/lockers.h" |
| 10 #include "vm/log.h" | 10 #include "vm/log.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 #if defined(TARGET_OS_WINDOWS) | 98 #if defined(TARGET_OS_WINDOWS) |
| 99 void Thread::CleanUp() { | 99 void Thread::CleanUp() { |
| 100 Thread* current = Current(); | 100 Thread* current = Current(); |
| 101 if (current != NULL) { | 101 if (current != NULL) { |
| 102 SetCurrent(NULL); | 102 SetCurrent(NULL); |
| 103 delete current; | 103 delete current; |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 #endif | 106 #endif |
| 107 | 107 |
| 108 #if defined(DEBUG) |
| 109 #define REUSABLE_HANDLE_SCOPE_INIT(object) \ |
| 110 reusable_##object##_handle_scope_active_(false), |
| 111 #else |
| 112 #define REUSABLE_HANDLE_SCOPE_INIT(object) |
| 113 #endif // defined(DEBUG) |
| 114 |
| 115 #define REUSABLE_HANDLE_INITIALIZERS(object) \ |
| 116 object##_handle_(NULL), |
| 117 |
| 108 | 118 |
| 109 Thread::Thread(bool init_vm_constants) | 119 Thread::Thread(bool init_vm_constants) |
| 110 : id_(OSThread::GetCurrentThreadId()), | 120 : id_(OSThread::GetCurrentThreadId()), |
| 111 thread_interrupt_callback_(NULL), | 121 thread_interrupt_callback_(NULL), |
| 112 thread_interrupt_data_(NULL), | 122 thread_interrupt_data_(NULL), |
| 113 isolate_(NULL), | 123 isolate_(NULL), |
| 114 heap_(NULL), | 124 heap_(NULL), |
| 115 store_buffer_block_(NULL), | 125 store_buffer_block_(NULL), |
| 116 log_(new class Log()), | 126 log_(new class Log()), |
| 117 vm_tag_(0) { | 127 vm_tag_(0), |
| 128 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_INITIALIZERS) |
| 129 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_SCOPE_INIT) |
| 130 reusable_handles_() { |
| 118 ClearState(); | 131 ClearState(); |
| 119 | 132 |
| 120 #define DEFAULT_INIT(type_name, member_name, init_expr, default_init_value) \ | 133 #define DEFAULT_INIT(type_name, member_name, init_expr, default_init_value) \ |
| 121 member_name = default_init_value; | 134 member_name = default_init_value; |
| 122 CACHED_CONSTANTS_LIST(DEFAULT_INIT) | 135 CACHED_CONSTANTS_LIST(DEFAULT_INIT) |
| 123 #undef DEFAULT_INIT | 136 #undef DEFAULT_INIT |
| 124 | 137 |
| 125 #define DEFAULT_INIT(name) \ | 138 #define DEFAULT_INIT(name) \ |
| 126 name##_entry_point_ = 0; | 139 name##_entry_point_ = 0; |
| 127 RUNTIME_ENTRY_LIST(DEFAULT_INIT) | 140 RUNTIME_ENTRY_LIST(DEFAULT_INIT) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 155 ASSERT(name##_entry_point_ == 0); \ | 168 ASSERT(name##_entry_point_ == 0); \ |
| 156 name##_entry_point_ = k##name##RuntimeEntry.GetEntryPoint(); | 169 name##_entry_point_ = k##name##RuntimeEntry.GetEntryPoint(); |
| 157 RUNTIME_ENTRY_LIST(INIT_VALUE) | 170 RUNTIME_ENTRY_LIST(INIT_VALUE) |
| 158 #undef INIT_VALUE | 171 #undef INIT_VALUE |
| 159 | 172 |
| 160 #define INIT_VALUE(returntype, name, ...) \ | 173 #define INIT_VALUE(returntype, name, ...) \ |
| 161 ASSERT(name##_entry_point_ == 0); \ | 174 ASSERT(name##_entry_point_ == 0); \ |
| 162 name##_entry_point_ = k##name##RuntimeEntry.GetEntryPoint(); | 175 name##_entry_point_ = k##name##RuntimeEntry.GetEntryPoint(); |
| 163 LEAF_RUNTIME_ENTRY_LIST(INIT_VALUE) | 176 LEAF_RUNTIME_ENTRY_LIST(INIT_VALUE) |
| 164 #undef INIT_VALUE | 177 #undef INIT_VALUE |
| 178 |
| 179 // Setup the thread specific reusable handles. |
| 180 #define REUSABLE_HANDLE_ALLOCATION(object) \ |
| 181 this->object##_handle_ = this->AllocateReusableHandle<object>(); |
| 182 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_ALLOCATION) |
| 183 #undef REUSABLE_HANDLE_ALLOCATION |
| 165 } | 184 } |
| 166 | 185 |
| 167 | 186 |
| 168 void Thread::Schedule(Isolate* isolate, bool bypass_safepoint) { | 187 void Thread::Schedule(Isolate* isolate, bool bypass_safepoint) { |
| 169 State st; | 188 State st; |
| 170 if (isolate->thread_registry()->RestoreStateTo(this, &st, bypass_safepoint)) { | 189 if (isolate->thread_registry()->RestoreStateTo(this, &st, bypass_safepoint)) { |
| 171 ASSERT(isolate->thread_registry()->Contains(this)); | 190 ASSERT(isolate->thread_registry()->Contains(this)); |
| 172 state_ = st; | 191 state_ = st; |
| 173 } | 192 } |
| 174 } | 193 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 thread->StoreBufferRelease(); | 230 thread->StoreBufferRelease(); |
| 212 if (isolate->is_runnable()) { | 231 if (isolate->is_runnable()) { |
| 213 thread->set_vm_tag(VMTag::kIdleTagId); | 232 thread->set_vm_tag(VMTag::kIdleTagId); |
| 214 } else { | 233 } else { |
| 215 thread->set_vm_tag(VMTag::kLoadWaitTagId); | 234 thread->set_vm_tag(VMTag::kLoadWaitTagId); |
| 216 } | 235 } |
| 217 isolate->ClearMutatorThread(); | 236 isolate->ClearMutatorThread(); |
| 218 thread->isolate_ = NULL; | 237 thread->isolate_ = NULL; |
| 219 ASSERT(Isolate::Current() == NULL); | 238 ASSERT(Isolate::Current() == NULL); |
| 220 thread->heap_ = NULL; | 239 thread->heap_ = NULL; |
| 240 #if defined(DEBUG) |
| 241 ASSERT(!thread->IsAnyReusableHandleScopeActive()); |
| 242 #endif // DEBUG |
| 221 } | 243 } |
| 222 | 244 |
| 223 | 245 |
| 224 void Thread::EnterIsolateAsHelper(Isolate* isolate, bool bypass_safepoint) { | 246 void Thread::EnterIsolateAsHelper(Isolate* isolate, bool bypass_safepoint) { |
| 225 Thread* thread = Thread::Current(); | 247 Thread* thread = Thread::Current(); |
| 226 ASSERT(thread != NULL); | 248 ASSERT(thread != NULL); |
| 227 ASSERT(thread->isolate() == NULL); | 249 ASSERT(thread->isolate() == NULL); |
| 228 thread->isolate_ = isolate; | 250 thread->isolate_ = isolate; |
| 229 ASSERT(thread->store_buffer_block_ == NULL); | 251 ASSERT(thread->store_buffer_block_ == NULL); |
| 230 // TODO(koda): Use StoreBufferAcquire once we properly flush before Scavenge. | 252 // TODO(koda): Use StoreBufferAcquire once we properly flush before Scavenge. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 ASSERT(isolate_ != NULL); | 333 ASSERT(isolate_ != NULL); |
| 312 isolate_->cha_ = value; | 334 isolate_->cha_ = value; |
| 313 } | 335 } |
| 314 | 336 |
| 315 | 337 |
| 316 Log* Thread::log() const { | 338 Log* Thread::log() const { |
| 317 return log_; | 339 return log_; |
| 318 } | 340 } |
| 319 | 341 |
| 320 | 342 |
| 343 template<class C> |
| 344 C* Thread::AllocateReusableHandle() { |
| 345 C* handle = reinterpret_cast<C*>(reusable_handles_.AllocateScopedHandle()); |
| 346 C::initializeHandle(handle, C::null()); |
| 347 return handle; |
| 348 } |
| 349 |
| 350 |
| 351 void Thread::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
| 352 ASSERT(visitor != NULL); |
| 353 |
| 354 // Visit objects in thread specific handles area. |
| 355 reusable_handles_.VisitObjectPointers(visitor); |
| 356 } |
| 357 |
| 358 |
| 321 void Thread::SetThreadInterrupter(ThreadInterruptCallback callback, | 359 void Thread::SetThreadInterrupter(ThreadInterruptCallback callback, |
| 322 void* data) { | 360 void* data) { |
| 323 ASSERT(Thread::Current() == this); | 361 ASSERT(Thread::Current() == this); |
| 324 thread_interrupt_callback_ = callback; | 362 thread_interrupt_callback_ = callback; |
| 325 thread_interrupt_data_ = data; | 363 thread_interrupt_data_ = data; |
| 326 } | 364 } |
| 327 | 365 |
| 328 | 366 |
| 329 bool Thread::IsThreadInterrupterEnabled(ThreadInterruptCallback* callback, | 367 bool Thread::IsThreadInterrupterEnabled(ThreadInterruptCallback* callback, |
| 330 void** data) const { | 368 void** data) const { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 return Thread::name##_entry_point_offset(); \ | 415 return Thread::name##_entry_point_offset(); \ |
| 378 } | 416 } |
| 379 LEAF_RUNTIME_ENTRY_LIST(COMPUTE_OFFSET) | 417 LEAF_RUNTIME_ENTRY_LIST(COMPUTE_OFFSET) |
| 380 #undef COMPUTE_OFFSET | 418 #undef COMPUTE_OFFSET |
| 381 | 419 |
| 382 UNREACHABLE(); | 420 UNREACHABLE(); |
| 383 return -1; | 421 return -1; |
| 384 } | 422 } |
| 385 | 423 |
| 386 } // namespace dart | 424 } // namespace dart |
| OLD | NEW |