OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_ISOLATE_H_ | 5 #ifndef VM_ISOLATE_H_ |
6 #define VM_ISOLATE_H_ | 6 #define VM_ISOLATE_H_ |
7 | 7 |
8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/thread.h" | 10 #include "platform/thread.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 class Simulator; | 57 class Simulator; |
58 class StackResource; | 58 class StackResource; |
59 class StackZone; | 59 class StackZone; |
60 class StubCode; | 60 class StubCode; |
61 class TypeArguments; | 61 class TypeArguments; |
62 class TypeParameter; | 62 class TypeParameter; |
63 class ObjectHistogram; | 63 class ObjectHistogram; |
64 class ObjectIdRing; | 64 class ObjectIdRing; |
65 | 65 |
66 | 66 |
67 #define REUSABLE_HANDLE_LIST(V) \ | |
68 V(Object) \ | |
69 V(Array) \ | |
70 V(String) \ | |
71 V(Instance) \ | |
72 V(Function) \ | |
73 V(Field) \ | |
74 V(Class) \ | |
75 V(TypeParameter) \ | |
76 V(TypeArguments) \ | |
77 | |
78 | |
79 class IsolateVisitor { | 67 class IsolateVisitor { |
80 public: | 68 public: |
81 IsolateVisitor() {} | 69 IsolateVisitor() {} |
82 virtual ~IsolateVisitor() {} | 70 virtual ~IsolateVisitor() {} |
83 | 71 |
84 virtual void VisitIsolate(Isolate* isolate) = 0; | 72 virtual void VisitIsolate(Isolate* isolate) = 0; |
85 | 73 |
86 private: | 74 private: |
87 DISALLOW_COPY_AND_ASSIGN(IsolateVisitor); | 75 DISALLOW_COPY_AND_ASSIGN(IsolateVisitor); |
88 }; | 76 }; |
89 | 77 |
| 78 #define REUSABLE_HANDLE_LIST(V) \ |
| 79 V(Object) \ |
| 80 V(Array) \ |
| 81 V(String) \ |
| 82 V(Instance) \ |
| 83 V(Function) \ |
| 84 V(Field) \ |
| 85 V(Class) \ |
| 86 V(TypeParameter) \ |
| 87 V(TypeArguments) \ |
90 | 88 |
91 class Isolate : public BaseIsolate { | 89 class Isolate : public BaseIsolate { |
92 public: | 90 public: |
93 ~Isolate(); | 91 ~Isolate(); |
94 | 92 |
95 static inline Isolate* Current() { | 93 static inline Isolate* Current() { |
96 return reinterpret_cast<Isolate*>(Thread::GetThreadLocal(isolate_key)); | 94 return reinterpret_cast<Isolate*>(Thread::GetThreadLocal(isolate_key)); |
97 } | 95 } |
98 | 96 |
99 static void SetCurrent(Isolate* isolate); | 97 static void SetCurrent(Isolate* isolate); |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 | 430 |
433 void set_thread_state(InterruptableThreadState* state) { | 431 void set_thread_state(InterruptableThreadState* state) { |
434 ASSERT((thread_state_ == NULL) || (state == NULL)); | 432 ASSERT((thread_state_ == NULL) || (state == NULL)); |
435 thread_state_ = state; | 433 thread_state_ = state; |
436 } | 434 } |
437 | 435 |
438 InterruptableThreadState* thread_state() const { | 436 InterruptableThreadState* thread_state() const { |
439 return thread_state_; | 437 return thread_state_; |
440 } | 438 } |
441 | 439 |
| 440 #if defined(DEBUG) |
| 441 #define REUSABLE_HANDLE_SCOPE_ACCESSORS(object) \ |
| 442 void set_reusable_##object##_handle_scope_active(bool value) { \ |
| 443 reusable_##object##_handle_scope_active_ = value; \ |
| 444 } \ |
| 445 bool reusable_##object##_handle_scope_active() const { \ |
| 446 return reusable_##object##_handle_scope_active_; \ |
| 447 } |
| 448 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_SCOPE_ACCESSORS) |
| 449 #undef REUSABLE_HANDLE_SCOPE_ACCESSORS |
| 450 #endif // defined(DEBUG) |
| 451 |
| 452 #define REUSABLE_HANDLE(object) \ |
| 453 object& object##Handle() const { \ |
| 454 return *object##_handle_; \ |
| 455 } |
| 456 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE) |
| 457 #undef REUSABLE_HANDLE |
| 458 |
442 static void VisitIsolates(IsolateVisitor* visitor); | 459 static void VisitIsolates(IsolateVisitor* visitor); |
443 | 460 |
444 private: | 461 private: |
445 Isolate(); | 462 Isolate(); |
446 | 463 |
447 void BuildName(const char* name_prefix); | 464 void BuildName(const char* name_prefix); |
448 void PrintInvokedFunctions(); | 465 void PrintInvokedFunctions(); |
449 | 466 |
450 template<class T> T* AllocateReusableHandle(); | 467 template<class T> T* AllocateReusableHandle(); |
451 | 468 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 | 515 |
499 IsolateProfilerData* profiler_data_; | 516 IsolateProfilerData* profiler_data_; |
500 Mutex profiler_data_mutex_; | 517 Mutex profiler_data_mutex_; |
501 InterruptableThreadState* thread_state_; | 518 InterruptableThreadState* thread_state_; |
502 | 519 |
503 // Isolate list next pointer. | 520 // Isolate list next pointer. |
504 Isolate* next_; | 521 Isolate* next_; |
505 | 522 |
506 // Reusable handles support. | 523 // Reusable handles support. |
507 #define REUSABLE_HANDLE_FIELDS(object) \ | 524 #define REUSABLE_HANDLE_FIELDS(object) \ |
508 object* object##_handle_; \ | 525 object* object##_handle_; |
509 | |
510 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_FIELDS) | 526 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_FIELDS) |
511 #undef REUSABLE_HANDLE_FIELDS | 527 #undef REUSABLE_HANDLE_FIELDS |
| 528 |
| 529 #if defined(DEBUG) |
| 530 #define REUSABLE_HANDLE_SCOPE_VARIABLE(object) \ |
| 531 bool reusable_##object##_handle_scope_active_; |
| 532 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_SCOPE_VARIABLE); |
| 533 #undef REUSABLE_HANDLE_SCOPE_VARIABLE |
| 534 #endif // defined(DEBUG) |
| 535 |
512 VMHandles reusable_handles_; | 536 VMHandles reusable_handles_; |
513 | 537 |
514 static Dart_IsolateCreateCallback create_callback_; | 538 static Dart_IsolateCreateCallback create_callback_; |
515 static Dart_IsolateInterruptCallback interrupt_callback_; | 539 static Dart_IsolateInterruptCallback interrupt_callback_; |
516 static Dart_IsolateUnhandledExceptionCallback unhandled_exception_callback_; | 540 static Dart_IsolateUnhandledExceptionCallback unhandled_exception_callback_; |
517 static Dart_IsolateShutdownCallback shutdown_callback_; | 541 static Dart_IsolateShutdownCallback shutdown_callback_; |
518 static Dart_FileOpenCallback file_open_callback_; | 542 static Dart_FileOpenCallback file_open_callback_; |
519 static Dart_FileReadCallback file_read_callback_; | 543 static Dart_FileReadCallback file_read_callback_; |
520 static Dart_FileWriteCallback file_write_callback_; | 544 static Dart_FileWriteCallback file_write_callback_; |
521 static Dart_FileCloseCallback file_close_callback_; | 545 static Dart_FileCloseCallback file_close_callback_; |
522 static Dart_EntropySource entropy_source_callback_; | 546 static Dart_EntropySource entropy_source_callback_; |
523 static Dart_IsolateInterruptCallback vmstats_callback_; | 547 static Dart_IsolateInterruptCallback vmstats_callback_; |
524 static Dart_ServiceIsolateCreateCalback service_create_callback_; | 548 static Dart_ServiceIsolateCreateCalback service_create_callback_; |
525 | 549 |
526 // Manage list of existing isolates. | 550 // Manage list of existing isolates. |
527 static void AddIsolateTolist(Isolate* isolate); | 551 static void AddIsolateTolist(Isolate* isolate); |
528 static void RemoveIsolateFromList(Isolate* isolate); | 552 static void RemoveIsolateFromList(Isolate* isolate); |
529 static void CheckForDuplicateThreadState(InterruptableThreadState* state); | 553 static void CheckForDuplicateThreadState(InterruptableThreadState* state); |
530 static Monitor* isolates_list_monitor_; | 554 static Monitor* isolates_list_monitor_; |
531 static Isolate* isolates_list_head_; | 555 static Isolate* isolates_list_head_; |
532 | 556 |
533 friend class ReusableHandleScope; | 557 #define REUSABLE_FRIEND_DECLARATION(name) \ |
534 friend class ReusableObjectHandleScope; | 558 friend class Reusable##name##HandleScope; |
| 559 REUSABLE_HANDLE_LIST(REUSABLE_FRIEND_DECLARATION) |
| 560 #undef REUSABLE_FRIEND_DECLARATION |
535 | 561 |
536 DISALLOW_COPY_AND_ASSIGN(Isolate); | 562 DISALLOW_COPY_AND_ASSIGN(Isolate); |
537 }; | 563 }; |
538 | 564 |
539 | 565 |
540 // When we need to execute code in an isolate, we use the | 566 // When we need to execute code in an isolate, we use the |
541 // StartIsolateScope. | 567 // StartIsolateScope. |
542 class StartIsolateScope { | 568 class StartIsolateScope { |
543 public: | 569 public: |
544 explicit StartIsolateScope(Isolate* new_isolate) | 570 explicit StartIsolateScope(Isolate* new_isolate) |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 char* script_url_; | 651 char* script_url_; |
626 char* library_url_; | 652 char* library_url_; |
627 char* class_name_; | 653 char* class_name_; |
628 char* function_name_; | 654 char* function_name_; |
629 char* exception_callback_name_; | 655 char* exception_callback_name_; |
630 }; | 656 }; |
631 | 657 |
632 } // namespace dart | 658 } // namespace dart |
633 | 659 |
634 #endif // VM_ISOLATE_H_ | 660 #endif // VM_ISOLATE_H_ |
OLD | NEW |