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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 177 |
178 | 178 |
179 Thread::Thread(bool init_vm_constants) | 179 Thread::Thread(bool init_vm_constants) |
180 : id_(OSThread::GetCurrentThreadId()), | 180 : id_(OSThread::GetCurrentThreadId()), |
181 thread_interrupt_callback_(NULL), | 181 thread_interrupt_callback_(NULL), |
182 thread_interrupt_data_(NULL), | 182 thread_interrupt_data_(NULL), |
183 isolate_(NULL), | 183 isolate_(NULL), |
184 heap_(NULL), | 184 heap_(NULL), |
185 store_buffer_block_(NULL), | 185 store_buffer_block_(NULL), |
186 log_(new class Log()), | 186 log_(new class Log()), |
187 deopt_id_(0), | |
188 vm_tag_(0), | |
189 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_INITIALIZERS) | 187 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_INITIALIZERS) |
190 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_SCOPE_INIT) | 188 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_SCOPE_INIT) |
191 reusable_handles_(), | 189 reusable_handles_(), |
192 cha_(NULL), | 190 cha_(NULL), |
| 191 deopt_id_(0), |
| 192 vm_tag_(0), |
| 193 pending_functions_(GrowableObjectArray::null()), |
193 no_callback_scope_depth_(0), | 194 no_callback_scope_depth_(0), |
194 thread_list_next_(NULL) { | 195 thread_list_next_(NULL) { |
195 ClearState(); | 196 ClearState(); |
196 | 197 |
197 #define DEFAULT_INIT(type_name, member_name, init_expr, default_init_value) \ | 198 #define DEFAULT_INIT(type_name, member_name, init_expr, default_init_value) \ |
198 member_name = default_init_value; | 199 member_name = default_init_value; |
199 CACHED_CONSTANTS_LIST(DEFAULT_INIT) | 200 CACHED_CONSTANTS_LIST(DEFAULT_INIT) |
200 #undef DEFAULT_INIT | 201 #undef DEFAULT_INIT |
201 | 202 |
202 #define DEFAULT_INIT(name) \ | 203 #define DEFAULT_INIT(name) \ |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 #undef INIT_VALUE | 243 #undef INIT_VALUE |
243 | 244 |
244 // Setup the thread specific reusable handles. | 245 // Setup the thread specific reusable handles. |
245 #define REUSABLE_HANDLE_ALLOCATION(object) \ | 246 #define REUSABLE_HANDLE_ALLOCATION(object) \ |
246 this->object##_handle_ = this->AllocateReusableHandle<object>(); | 247 this->object##_handle_ = this->AllocateReusableHandle<object>(); |
247 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_ALLOCATION) | 248 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_ALLOCATION) |
248 #undef REUSABLE_HANDLE_ALLOCATION | 249 #undef REUSABLE_HANDLE_ALLOCATION |
249 } | 250 } |
250 | 251 |
251 | 252 |
| 253 void Thread::ClearState() { |
| 254 memset(&state_, 0, sizeof(state_)); |
| 255 pending_functions_ = GrowableObjectArray::null(); |
| 256 } |
| 257 |
| 258 |
| 259 RawGrowableObjectArray* Thread::pending_functions() { |
| 260 if (pending_functions_ == GrowableObjectArray::null()) { |
| 261 pending_functions_ = GrowableObjectArray::New(); |
| 262 } |
| 263 return pending_functions_; |
| 264 } |
| 265 |
| 266 |
252 void Thread::Schedule(Isolate* isolate, bool bypass_safepoint) { | 267 void Thread::Schedule(Isolate* isolate, bool bypass_safepoint) { |
253 State st; | 268 State st; |
254 if (isolate->thread_registry()->RestoreStateTo(this, &st, bypass_safepoint)) { | 269 if (isolate->thread_registry()->RestoreStateTo(this, &st, bypass_safepoint)) { |
255 ASSERT(isolate->thread_registry()->Contains(this)); | 270 ASSERT(isolate->thread_registry()->Contains(this)); |
256 state_ = st; | 271 state_ = st; |
257 } | 272 } |
258 } | 273 } |
259 | 274 |
260 | 275 |
261 void Thread::Unschedule(bool bypass_safepoint) { | 276 void Thread::Unschedule(bool bypass_safepoint) { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 REUSABLE_HANDLE_LIST(CLEAR_REUSABLE_HANDLE) | 436 REUSABLE_HANDLE_LIST(CLEAR_REUSABLE_HANDLE) |
422 #undef CLEAR_REUSABLE_HANDLE | 437 #undef CLEAR_REUSABLE_HANDLE |
423 } | 438 } |
424 | 439 |
425 | 440 |
426 void Thread::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 441 void Thread::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
427 ASSERT(visitor != NULL); | 442 ASSERT(visitor != NULL); |
428 | 443 |
429 // Visit objects in thread specific handles area. | 444 // Visit objects in thread specific handles area. |
430 reusable_handles_.VisitObjectPointers(visitor); | 445 reusable_handles_.VisitObjectPointers(visitor); |
| 446 |
| 447 if (pending_functions_ != GrowableObjectArray::null()) { |
| 448 visitor->VisitPointer( |
| 449 reinterpret_cast<RawObject**>(&pending_functions_)); |
| 450 } |
431 } | 451 } |
432 | 452 |
433 | 453 |
434 void Thread::SetThreadInterrupter(ThreadInterruptCallback callback, | 454 void Thread::SetThreadInterrupter(ThreadInterruptCallback callback, |
435 void* data) { | 455 void* data) { |
436 ASSERT(Thread::Current() == this); | 456 ASSERT(Thread::Current() == this); |
437 thread_interrupt_callback_ = callback; | 457 thread_interrupt_callback_ = callback; |
438 thread_interrupt_data_ = data; | 458 thread_interrupt_data_ = data; |
439 } | 459 } |
440 | 460 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 Thread* ThreadIterator::Next() { | 542 Thread* ThreadIterator::Next() { |
523 ASSERT(Thread::thread_list_lock_ != NULL); | 543 ASSERT(Thread::thread_list_lock_ != NULL); |
524 ASSERT(Thread::thread_list_lock_->IsOwnedByCurrentThread()); | 544 ASSERT(Thread::thread_list_lock_->IsOwnedByCurrentThread()); |
525 Thread* current = next_; | 545 Thread* current = next_; |
526 next_ = next_->thread_list_next_; | 546 next_ = next_->thread_list_next_; |
527 return current; | 547 return current; |
528 } | 548 } |
529 | 549 |
530 | 550 |
531 } // namespace dart | 551 } // namespace dart |
OLD | NEW |