Chromium Code Reviews| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 Profiler::EndExecution(isolate); | 227 Profiler::EndExecution(isolate); |
| 209 thread->Unschedule(); | 228 thread->Unschedule(); |
| 210 // TODO(koda): Move store_buffer_block_ into State. | 229 // TODO(koda): Move store_buffer_block_ into State. |
| 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; |
|
koda
2015/10/07 21:02:54
In debug mode, please zap all the reusable handles
srdjan
2015/10/08 16:22:01
ReusableHandleScope already makes sure that nobody
| |
| 219 ASSERT(Isolate::Current() == NULL); | 238 ASSERT(Isolate::Current() == NULL); |
| 220 thread->heap_ = NULL; | 239 thread->heap_ = NULL; |
| 221 } | 240 } |
| 222 | 241 |
| 223 | 242 |
| 224 void Thread::EnterIsolateAsHelper(Isolate* isolate, bool bypass_safepoint) { | 243 void Thread::EnterIsolateAsHelper(Isolate* isolate, bool bypass_safepoint) { |
| 225 Thread* thread = Thread::Current(); | 244 Thread* thread = Thread::Current(); |
| 226 ASSERT(thread != NULL); | 245 ASSERT(thread != NULL); |
| 227 ASSERT(thread->isolate() == NULL); | 246 ASSERT(thread->isolate() == NULL); |
| 228 thread->isolate_ = isolate; | 247 thread->isolate_ = isolate; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 ASSERT(isolate_ != NULL); | 330 ASSERT(isolate_ != NULL); |
| 312 isolate_->cha_ = value; | 331 isolate_->cha_ = value; |
| 313 } | 332 } |
| 314 | 333 |
| 315 | 334 |
| 316 Log* Thread::log() const { | 335 Log* Thread::log() const { |
| 317 return log_; | 336 return log_; |
| 318 } | 337 } |
| 319 | 338 |
| 320 | 339 |
| 340 template<class C> | |
| 341 C* Thread::AllocateReusableHandle() { | |
| 342 C* handle = reinterpret_cast<C*>(reusable_handles_.AllocateScopedHandle()); | |
| 343 C::initializeHandle(handle, C::null()); | |
| 344 return handle; | |
| 345 } | |
| 346 | |
| 347 | |
| 348 void Thread::VisitObjectPointers(ObjectPointerVisitor* visitor) { | |
| 349 ASSERT(visitor != NULL); | |
| 350 | |
| 351 // Visit objects in thread specific handles area. | |
| 352 reusable_handles_.VisitObjectPointers(visitor); | |
| 353 } | |
| 354 | |
| 355 | |
| 321 void Thread::SetThreadInterrupter(ThreadInterruptCallback callback, | 356 void Thread::SetThreadInterrupter(ThreadInterruptCallback callback, |
| 322 void* data) { | 357 void* data) { |
| 323 ASSERT(Thread::Current() == this); | 358 ASSERT(Thread::Current() == this); |
| 324 thread_interrupt_callback_ = callback; | 359 thread_interrupt_callback_ = callback; |
| 325 thread_interrupt_data_ = data; | 360 thread_interrupt_data_ = data; |
| 326 } | 361 } |
| 327 | 362 |
| 328 | 363 |
| 329 bool Thread::IsThreadInterrupterEnabled(ThreadInterruptCallback* callback, | 364 bool Thread::IsThreadInterrupterEnabled(ThreadInterruptCallback* callback, |
| 330 void** data) const { | 365 void** data) const { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 return Thread::name##_entry_point_offset(); \ | 412 return Thread::name##_entry_point_offset(); \ |
| 378 } | 413 } |
| 379 LEAF_RUNTIME_ENTRY_LIST(COMPUTE_OFFSET) | 414 LEAF_RUNTIME_ENTRY_LIST(COMPUTE_OFFSET) |
| 380 #undef COMPUTE_OFFSET | 415 #undef COMPUTE_OFFSET |
| 381 | 416 |
| 382 UNREACHABLE(); | 417 UNREACHABLE(); |
| 383 return -1; | 418 return -1; |
| 384 } | 419 } |
| 385 | 420 |
| 386 } // namespace dart | 421 } // namespace dart |
| OLD | NEW |