| 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 #ifndef VM_THREAD_H_ | 5 #ifndef VM_THREAD_H_ |
| 6 #define VM_THREAD_H_ | 6 #define VM_THREAD_H_ |
| 7 | 7 |
| 8 #include "vm/globals.h" | 8 #include "vm/globals.h" |
| 9 #include "vm/handles.h" |
| 9 #include "vm/os_thread.h" | 10 #include "vm/os_thread.h" |
| 10 #include "vm/store_buffer.h" | 11 #include "vm/store_buffer.h" |
| 11 #include "vm/runtime_entry_list.h" | 12 #include "vm/runtime_entry_list.h" |
| 12 | 13 |
| 13 namespace dart { | 14 namespace dart { |
| 14 | 15 |
| 16 class AbstractType; |
| 17 class Array; |
| 15 class CHA; | 18 class CHA; |
| 19 class Class; |
| 20 class Code; |
| 21 class Error; |
| 22 class ExceptionHandlers; |
| 23 class Field; |
| 24 class Function; |
| 25 class GrowableObjectArray; |
| 16 class HandleScope; | 26 class HandleScope; |
| 17 class Heap; | 27 class Heap; |
| 28 class Instance; |
| 18 class Isolate; | 29 class Isolate; |
| 30 class Library; |
| 19 class Log; | 31 class Log; |
| 20 class LongJumpScope; | 32 class LongJumpScope; |
| 21 class Object; | 33 class Object; |
| 34 class PcDescriptors; |
| 22 class RawBool; | 35 class RawBool; |
| 23 class RawObject; | 36 class RawObject; |
| 24 class RawCode; | 37 class RawCode; |
| 25 class RawString; | 38 class RawString; |
| 26 class RuntimeEntry; | 39 class RuntimeEntry; |
| 27 class StackResource; | 40 class StackResource; |
| 41 class String; |
| 28 class TimelineEventBlock; | 42 class TimelineEventBlock; |
| 43 class TypeArguments; |
| 44 class TypeParameter; |
| 29 class Zone; | 45 class Zone; |
| 30 | 46 |
| 47 #define REUSABLE_HANDLE_LIST(V) \ |
| 48 V(AbstractType) \ |
| 49 V(Array) \ |
| 50 V(Class) \ |
| 51 V(Code) \ |
| 52 V(Error) \ |
| 53 V(ExceptionHandlers) \ |
| 54 V(Field) \ |
| 55 V(Function) \ |
| 56 V(GrowableObjectArray) \ |
| 57 V(Instance) \ |
| 58 V(Library) \ |
| 59 V(Object) \ |
| 60 V(PcDescriptors) \ |
| 61 V(String) \ |
| 62 V(TypeArguments) \ |
| 63 V(TypeParameter) \ |
| 64 |
| 65 |
| 31 // List of VM-global objects/addresses cached in each Thread object. | 66 // List of VM-global objects/addresses cached in each Thread object. |
| 32 #define CACHED_VM_OBJECTS_LIST(V) \ | 67 #define CACHED_VM_OBJECTS_LIST(V) \ |
| 33 V(RawObject*, object_null_, Object::null(), NULL) \ | 68 V(RawObject*, object_null_, Object::null(), NULL) \ |
| 34 V(RawBool*, bool_true_, Object::bool_true().raw(), NULL) \ | 69 V(RawBool*, bool_true_, Object::bool_true().raw(), NULL) \ |
| 35 V(RawBool*, bool_false_, Object::bool_false().raw(), NULL) \ | 70 V(RawBool*, bool_false_, Object::bool_false().raw(), NULL) \ |
| 36 V(RawCode*, update_store_buffer_code_, \ | 71 V(RawCode*, update_store_buffer_code_, \ |
| 37 StubCode::UpdateStoreBuffer_entry()->code(), NULL) \ | 72 StubCode::UpdateStoreBuffer_entry()->code(), NULL) \ |
| 38 V(RawCode*, fix_callers_target_code_, \ | 73 V(RawCode*, fix_callers_target_code_, \ |
| 39 StubCode::FixCallersTarget_entry()->code(), NULL) \ | 74 StubCode::FixCallersTarget_entry()->code(), NULL) \ |
| 40 V(RawCode*, fix_allocation_stub_code_, \ | 75 V(RawCode*, fix_allocation_stub_code_, \ |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 ThreadId id() const { | 330 ThreadId id() const { |
| 296 ASSERT(id_ != OSThread::kInvalidThreadId); | 331 ASSERT(id_ != OSThread::kInvalidThreadId); |
| 297 return id_; | 332 return id_; |
| 298 } | 333 } |
| 299 | 334 |
| 300 void SetThreadInterrupter(ThreadInterruptCallback callback, void* data); | 335 void SetThreadInterrupter(ThreadInterruptCallback callback, void* data); |
| 301 | 336 |
| 302 bool IsThreadInterrupterEnabled(ThreadInterruptCallback* callback, | 337 bool IsThreadInterrupterEnabled(ThreadInterruptCallback* callback, |
| 303 void** data) const; | 338 void** data) const; |
| 304 | 339 |
| 340 #if defined(DEBUG) |
| 341 #define REUSABLE_HANDLE_SCOPE_ACCESSORS(object) \ |
| 342 void set_reusable_##object##_handle_scope_active(bool value) { \ |
| 343 reusable_##object##_handle_scope_active_ = value; \ |
| 344 } \ |
| 345 bool reusable_##object##_handle_scope_active() const { \ |
| 346 return reusable_##object##_handle_scope_active_; \ |
| 347 } |
| 348 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_SCOPE_ACCESSORS) |
| 349 #undef REUSABLE_HANDLE_SCOPE_ACCESSORS |
| 350 |
| 351 bool IsAnyReusableHandleScopeActive() const { |
| 352 #define IS_REUSABLE_HANDLE_SCOPE_ACTIVE(object) \ |
| 353 if (reusable_##object##_handle_scope_active_) return true; |
| 354 REUSABLE_HANDLE_LIST(IS_REUSABLE_HANDLE_SCOPE_ACTIVE) |
| 355 return false; |
| 356 #undef IS_REUSABLE_HANDLE_SCOPE_ACTIVE |
| 357 } |
| 358 #endif // defined(DEBUG) |
| 359 |
| 360 #define REUSABLE_HANDLE(object) \ |
| 361 object& object##Handle() const { \ |
| 362 return *object##_handle_; \ |
| 363 } |
| 364 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE) |
| 365 #undef REUSABLE_HANDLE |
| 366 |
| 367 void VisitObjectPointers(ObjectPointerVisitor* visitor); |
| 368 |
| 305 private: | 369 private: |
| 370 template<class T> T* AllocateReusableHandle(); |
| 371 |
| 306 static ThreadLocalKey thread_key_; | 372 static ThreadLocalKey thread_key_; |
| 307 | 373 |
| 308 const ThreadId id_; | 374 const ThreadId id_; |
| 309 ThreadInterruptCallback thread_interrupt_callback_; | 375 ThreadInterruptCallback thread_interrupt_callback_; |
| 310 void* thread_interrupt_data_; | 376 void* thread_interrupt_data_; |
| 311 Isolate* isolate_; | 377 Isolate* isolate_; |
| 312 Heap* heap_; | 378 Heap* heap_; |
| 313 State state_; | 379 State state_; |
| 314 Mutex timeline_block_lock_; | 380 Mutex timeline_block_lock_; |
| 315 StoreBufferBlock* store_buffer_block_; | 381 StoreBufferBlock* store_buffer_block_; |
| 316 class Log* log_; | 382 class Log* log_; |
| 317 uword vm_tag_; | 383 uword vm_tag_; |
| 318 #define DECLARE_MEMBERS(type_name, member_name, expr, default_init_value) \ | 384 #define DECLARE_MEMBERS(type_name, member_name, expr, default_init_value) \ |
| 319 type_name member_name; | 385 type_name member_name; |
| 320 CACHED_CONSTANTS_LIST(DECLARE_MEMBERS) | 386 CACHED_CONSTANTS_LIST(DECLARE_MEMBERS) |
| 321 #undef DECLARE_MEMBERS | 387 #undef DECLARE_MEMBERS |
| 322 | 388 |
| 323 #define DECLARE_MEMBERS(name) \ | 389 #define DECLARE_MEMBERS(name) \ |
| 324 uword name##_entry_point_; | 390 uword name##_entry_point_; |
| 325 RUNTIME_ENTRY_LIST(DECLARE_MEMBERS) | 391 RUNTIME_ENTRY_LIST(DECLARE_MEMBERS) |
| 326 #undef DECLARE_MEMBERS | 392 #undef DECLARE_MEMBERS |
| 327 | 393 |
| 328 #define DECLARE_MEMBERS(returntype, name, ...) \ | 394 #define DECLARE_MEMBERS(returntype, name, ...) \ |
| 329 uword name##_entry_point_; | 395 uword name##_entry_point_; |
| 330 LEAF_RUNTIME_ENTRY_LIST(DECLARE_MEMBERS) | 396 LEAF_RUNTIME_ENTRY_LIST(DECLARE_MEMBERS) |
| 331 #undef DECLARE_MEMBERS | 397 #undef DECLARE_MEMBERS |
| 332 | 398 |
| 399 // Reusable handles support. |
| 400 #define REUSABLE_HANDLE_FIELDS(object) \ |
| 401 object* object##_handle_; |
| 402 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_FIELDS) |
| 403 #undef REUSABLE_HANDLE_FIELDS |
| 404 |
| 405 #if defined(DEBUG) |
| 406 #define REUSABLE_HANDLE_SCOPE_VARIABLE(object) \ |
| 407 bool reusable_##object##_handle_scope_active_; |
| 408 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_SCOPE_VARIABLE); |
| 409 #undef REUSABLE_HANDLE_SCOPE_VARIABLE |
| 410 #endif // defined(DEBUG) |
| 411 |
| 412 VMHandles reusable_handles_; |
| 413 |
| 333 explicit Thread(bool init_vm_constants = true); | 414 explicit Thread(bool init_vm_constants = true); |
| 334 | 415 |
| 335 void InitVMConstants(); | 416 void InitVMConstants(); |
| 336 | 417 |
| 337 void ClearState() { | 418 void ClearState() { |
| 338 memset(&state_, 0, sizeof(state_)); | 419 memset(&state_, 0, sizeof(state_)); |
| 339 } | 420 } |
| 340 | 421 |
| 341 void StoreBufferRelease( | 422 void StoreBufferRelease( |
| 342 StoreBuffer::ThresholdPolicy policy = StoreBuffer::kCheckThreshold); | 423 StoreBuffer::ThresholdPolicy policy = StoreBuffer::kCheckThreshold); |
| 343 void StoreBufferAcquire(); | 424 void StoreBufferAcquire(); |
| 344 | 425 |
| 345 void set_zone(Zone* zone) { | 426 void set_zone(Zone* zone) { |
| 346 state_.zone = zone; | 427 state_.zone = zone; |
| 347 } | 428 } |
| 348 | 429 |
| 349 void set_top_exit_frame_info(uword top_exit_frame_info) { | 430 void set_top_exit_frame_info(uword top_exit_frame_info) { |
| 350 state_.top_exit_frame_info = top_exit_frame_info; | 431 state_.top_exit_frame_info = top_exit_frame_info; |
| 351 } | 432 } |
| 352 | 433 |
| 353 static void SetCurrent(Thread* current); | 434 static void SetCurrent(Thread* current); |
| 354 | 435 |
| 355 void Schedule(Isolate* isolate, bool bypass_safepoint = false); | 436 void Schedule(Isolate* isolate, bool bypass_safepoint = false); |
| 356 void Unschedule(bool bypass_safepoint = false); | 437 void Unschedule(bool bypass_safepoint = false); |
| 357 | 438 |
| 439 #define REUSABLE_FRIEND_DECLARATION(name) \ |
| 440 friend class Reusable##name##HandleScope; |
| 441 REUSABLE_HANDLE_LIST(REUSABLE_FRIEND_DECLARATION) |
| 442 #undef REUSABLE_FRIEND_DECLARATION |
| 443 |
| 358 friend class ApiZone; | 444 friend class ApiZone; |
| 359 friend class Isolate; | 445 friend class Isolate; |
| 360 friend class StackZone; | 446 friend class StackZone; |
| 361 friend class ThreadRegistry; | 447 friend class ThreadRegistry; |
| 362 DISALLOW_COPY_AND_ASSIGN(Thread); | 448 DISALLOW_COPY_AND_ASSIGN(Thread); |
| 363 }; | 449 }; |
| 364 | 450 |
| 365 } // namespace dart | 451 } // namespace dart |
| 366 | 452 |
| 367 #endif // VM_THREAD_H_ | 453 #endif // VM_THREAD_H_ |
| OLD | NEW |