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 #endif // defined(DEBUG) | |
351 | |
352 #define REUSABLE_HANDLE(object) \ | |
353 object& object##Handle() const { \ | |
354 return *object##_handle_; \ | |
355 } | |
356 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE) | |
357 #undef REUSABLE_HANDLE | |
358 | |
359 void VisitObjectPointers(ObjectPointerVisitor* visitor); | |
360 | |
305 private: | 361 private: |
362 template<class T> T* AllocateReusableHandle(); | |
363 | |
306 static ThreadLocalKey thread_key_; | 364 static ThreadLocalKey thread_key_; |
307 | 365 |
308 const ThreadId id_; | 366 const ThreadId id_; |
309 ThreadInterruptCallback thread_interrupt_callback_; | 367 ThreadInterruptCallback thread_interrupt_callback_; |
310 void* thread_interrupt_data_; | 368 void* thread_interrupt_data_; |
311 Isolate* isolate_; | 369 Isolate* isolate_; |
312 Heap* heap_; | 370 Heap* heap_; |
313 State state_; | 371 State state_; |
314 Mutex timeline_block_lock_; | 372 Mutex timeline_block_lock_; |
315 StoreBufferBlock* store_buffer_block_; | 373 StoreBufferBlock* store_buffer_block_; |
316 class Log* log_; | 374 class Log* log_; |
317 uword vm_tag_; | 375 uword vm_tag_; |
318 #define DECLARE_MEMBERS(type_name, member_name, expr, default_init_value) \ | 376 #define DECLARE_MEMBERS(type_name, member_name, expr, default_init_value) \ |
319 type_name member_name; | 377 type_name member_name; |
320 CACHED_CONSTANTS_LIST(DECLARE_MEMBERS) | 378 CACHED_CONSTANTS_LIST(DECLARE_MEMBERS) |
321 #undef DECLARE_MEMBERS | 379 #undef DECLARE_MEMBERS |
322 | 380 |
323 #define DECLARE_MEMBERS(name) \ | 381 #define DECLARE_MEMBERS(name) \ |
324 uword name##_entry_point_; | 382 uword name##_entry_point_; |
325 RUNTIME_ENTRY_LIST(DECLARE_MEMBERS) | 383 RUNTIME_ENTRY_LIST(DECLARE_MEMBERS) |
326 #undef DECLARE_MEMBERS | 384 #undef DECLARE_MEMBERS |
327 | 385 |
328 #define DECLARE_MEMBERS(returntype, name, ...) \ | 386 #define DECLARE_MEMBERS(returntype, name, ...) \ |
329 uword name##_entry_point_; | 387 uword name##_entry_point_; |
330 LEAF_RUNTIME_ENTRY_LIST(DECLARE_MEMBERS) | 388 LEAF_RUNTIME_ENTRY_LIST(DECLARE_MEMBERS) |
331 #undef DECLARE_MEMBERS | 389 #undef DECLARE_MEMBERS |
332 | 390 |
391 // Reusable handles support. | |
392 #define REUSABLE_HANDLE_FIELDS(object) \ | |
393 object* object##_handle_; | |
394 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_FIELDS) | |
395 #undef REUSABLE_HANDLE_FIELDS | |
396 | |
397 #if defined(DEBUG) | |
398 #define REUSABLE_HANDLE_SCOPE_VARIABLE(object) \ | |
399 bool reusable_##object##_handle_scope_active_; | |
400 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_SCOPE_VARIABLE); | |
401 #undef REUSABLE_HANDLE_SCOPE_VARIABLE | |
402 #endif // defined(DEBUG) | |
403 | |
404 | |
koda
2015/10/07 21:02:54
Excessive blank lines.
srdjan
2015/10/08 16:22:01
Done.
| |
405 | |
406 VMHandles reusable_handles_; | |
407 | |
333 explicit Thread(bool init_vm_constants = true); | 408 explicit Thread(bool init_vm_constants = true); |
334 | 409 |
335 void InitVMConstants(); | 410 void InitVMConstants(); |
336 | 411 |
337 void ClearState() { | 412 void ClearState() { |
338 memset(&state_, 0, sizeof(state_)); | 413 memset(&state_, 0, sizeof(state_)); |
339 } | 414 } |
340 | 415 |
341 void StoreBufferRelease( | 416 void StoreBufferRelease( |
342 StoreBuffer::ThresholdPolicy policy = StoreBuffer::kCheckThreshold); | 417 StoreBuffer::ThresholdPolicy policy = StoreBuffer::kCheckThreshold); |
343 void StoreBufferAcquire(); | 418 void StoreBufferAcquire(); |
344 | 419 |
345 void set_zone(Zone* zone) { | 420 void set_zone(Zone* zone) { |
346 state_.zone = zone; | 421 state_.zone = zone; |
347 } | 422 } |
348 | 423 |
349 void set_top_exit_frame_info(uword top_exit_frame_info) { | 424 void set_top_exit_frame_info(uword top_exit_frame_info) { |
350 state_.top_exit_frame_info = top_exit_frame_info; | 425 state_.top_exit_frame_info = top_exit_frame_info; |
351 } | 426 } |
352 | 427 |
353 static void SetCurrent(Thread* current); | 428 static void SetCurrent(Thread* current); |
354 | 429 |
355 void Schedule(Isolate* isolate, bool bypass_safepoint = false); | 430 void Schedule(Isolate* isolate, bool bypass_safepoint = false); |
356 void Unschedule(bool bypass_safepoint = false); | 431 void Unschedule(bool bypass_safepoint = false); |
357 | 432 |
433 #define REUSABLE_FRIEND_DECLARATION(name) \ | |
434 friend class Reusable##name##HandleScope; | |
435 REUSABLE_HANDLE_LIST(REUSABLE_FRIEND_DECLARATION) | |
436 #undef REUSABLE_FRIEND_DECLARATION | |
437 | |
358 friend class ApiZone; | 438 friend class ApiZone; |
359 friend class Isolate; | 439 friend class Isolate; |
360 friend class StackZone; | 440 friend class StackZone; |
361 friend class ThreadRegistry; | 441 friend class ThreadRegistry; |
362 DISALLOW_COPY_AND_ASSIGN(Thread); | 442 DISALLOW_COPY_AND_ASSIGN(Thread); |
363 }; | 443 }; |
364 | 444 |
365 } // namespace dart | 445 } // namespace dart |
366 | 446 |
367 #endif // VM_THREAD_H_ | 447 #endif // VM_THREAD_H_ |
OLD | NEW |