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 "vm/atomic.h" | 10 #include "vm/atomic.h" |
11 #include "vm/base_isolate.h" | 11 #include "vm/base_isolate.h" |
12 #include "vm/class_table.h" | 12 #include "vm/class_table.h" |
13 #include "vm/handles.h" | 13 #include "vm/handles.h" |
14 #include "vm/megamorphic_cache_table.h" | 14 #include "vm/megamorphic_cache_table.h" |
15 #include "vm/metrics.h" | 15 #include "vm/metrics.h" |
16 #include "vm/random.h" | 16 #include "vm/random.h" |
17 #include "vm/tags.h" | 17 #include "vm/tags.h" |
18 #include "vm/thread.h" | 18 #include "vm/thread.h" |
19 #include "vm/os_thread.h" | 19 #include "vm/os_thread.h" |
20 #include "vm/timeline.h" | 20 #include "vm/timeline.h" |
21 #include "vm/timer.h" | 21 #include "vm/timer.h" |
22 #include "vm/trace_buffer.h" | 22 #include "vm/trace_buffer.h" |
23 | 23 |
24 namespace dart { | 24 namespace dart { |
25 | 25 |
26 // Forward declarations. | 26 // Forward declarations. |
27 class AbstractType; | |
28 class ApiState; | 27 class ApiState; |
29 class Array; | |
30 class BackgroundCompiler; | 28 class BackgroundCompiler; |
31 class Capability; | 29 class Capability; |
32 class CHA; | 30 class CHA; |
33 class Class; | |
34 class Code; | |
35 class CodeIndexTable; | 31 class CodeIndexTable; |
36 class CompilerStats; | 32 class CompilerStats; |
37 class Debugger; | 33 class Debugger; |
38 class DeoptContext; | 34 class DeoptContext; |
39 class Error; | |
40 class ExceptionHandlers; | |
41 class Field; | |
42 class Function; | |
43 class GrowableObjectArray; | |
44 class HandleScope; | 35 class HandleScope; |
45 class HandleVisitor; | 36 class HandleVisitor; |
46 class Heap; | 37 class Heap; |
47 class ICData; | 38 class ICData; |
48 class Instance; | |
49 class IsolateProfilerData; | 39 class IsolateProfilerData; |
50 class IsolateSpawnState; | 40 class IsolateSpawnState; |
51 class Library; | |
52 class Log; | 41 class Log; |
53 class MessageHandler; | 42 class MessageHandler; |
54 class Mutex; | 43 class Mutex; |
55 class Object; | 44 class Object; |
56 class ObjectIdRing; | 45 class ObjectIdRing; |
57 class ObjectPointerVisitor; | 46 class ObjectPointerVisitor; |
58 class ObjectStore; | 47 class ObjectStore; |
59 class PcDescriptors; | |
60 class RawInstance; | 48 class RawInstance; |
61 class RawArray; | 49 class RawArray; |
62 class RawContext; | 50 class RawContext; |
63 class RawDouble; | 51 class RawDouble; |
64 class RawGrowableObjectArray; | 52 class RawGrowableObjectArray; |
65 class RawMint; | 53 class RawMint; |
66 class RawObject; | 54 class RawObject; |
67 class RawInteger; | 55 class RawInteger; |
68 class RawError; | 56 class RawError; |
69 class RawFloat32x4; | 57 class RawFloat32x4; |
70 class RawInt32x4; | 58 class RawInt32x4; |
71 class RawUserTag; | 59 class RawUserTag; |
72 class SampleBuffer; | 60 class SampleBuffer; |
73 class SendPort; | 61 class SendPort; |
74 class ServiceIdZone; | 62 class ServiceIdZone; |
75 class Simulator; | 63 class Simulator; |
76 class StackResource; | 64 class StackResource; |
77 class StackZone; | 65 class StackZone; |
78 class StoreBuffer; | 66 class StoreBuffer; |
79 class StubCode; | 67 class StubCode; |
80 class ThreadRegistry; | 68 class ThreadRegistry; |
81 class TypeArguments; | |
82 class TypeParameter; | |
83 class UserTag; | 69 class UserTag; |
84 | 70 |
85 | 71 |
86 class IsolateVisitor { | 72 class IsolateVisitor { |
87 public: | 73 public: |
88 IsolateVisitor() {} | 74 IsolateVisitor() {} |
89 virtual ~IsolateVisitor() {} | 75 virtual ~IsolateVisitor() {} |
90 | 76 |
91 virtual void VisitIsolate(Isolate* isolate) = 0; | 77 virtual void VisitIsolate(Isolate* isolate) = 0; |
92 | 78 |
93 private: | 79 private: |
94 DISALLOW_COPY_AND_ASSIGN(IsolateVisitor); | 80 DISALLOW_COPY_AND_ASSIGN(IsolateVisitor); |
95 }; | 81 }; |
96 | 82 |
97 #define REUSABLE_HANDLE_LIST(V) \ | |
98 V(AbstractType) \ | |
99 V(Array) \ | |
100 V(Class) \ | |
101 V(Code) \ | |
102 V(Error) \ | |
103 V(ExceptionHandlers) \ | |
104 V(Field) \ | |
105 V(Function) \ | |
106 V(GrowableObjectArray) \ | |
107 V(Instance) \ | |
108 V(Library) \ | |
109 V(Object) \ | |
110 V(PcDescriptors) \ | |
111 V(String) \ | |
112 V(TypeArguments) \ | |
113 V(TypeParameter) \ | |
114 | 83 |
115 class Isolate : public BaseIsolate { | 84 class Isolate : public BaseIsolate { |
116 public: | 85 public: |
117 // Keep both these enums in sync with isolate_patch.dart. | 86 // Keep both these enums in sync with isolate_patch.dart. |
118 // The different Isolate API message types. | 87 // The different Isolate API message types. |
119 enum LibMsgId { | 88 enum LibMsgId { |
120 kPauseMsg = 1, | 89 kPauseMsg = 1, |
121 kResumeMsg = 2, | 90 kResumeMsg = 2, |
122 kPingMsg = 3, | 91 kPingMsg = 3, |
123 kKillMsg = 4, | 92 kKillMsg = 4, |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 void AppendServiceExtensionCall(const Instance& closure, | 692 void AppendServiceExtensionCall(const Instance& closure, |
724 const String& method_name, | 693 const String& method_name, |
725 const Array& parameter_keys, | 694 const Array& parameter_keys, |
726 const Array& parameter_values, | 695 const Array& parameter_values, |
727 const Instance& reply_port, | 696 const Instance& reply_port, |
728 const Instance& id); | 697 const Instance& id); |
729 void RegisterServiceExtensionHandler(const String& name, | 698 void RegisterServiceExtensionHandler(const String& name, |
730 const Instance& closure); | 699 const Instance& closure); |
731 RawInstance* LookupServiceExtensionHandler(const String& name); | 700 RawInstance* LookupServiceExtensionHandler(const String& name); |
732 | 701 |
733 #if defined(DEBUG) | |
734 #define REUSABLE_HANDLE_SCOPE_ACCESSORS(object) \ | |
735 void set_reusable_##object##_handle_scope_active(bool value) { \ | |
736 reusable_##object##_handle_scope_active_ = value; \ | |
737 } \ | |
738 bool reusable_##object##_handle_scope_active() const { \ | |
739 return reusable_##object##_handle_scope_active_; \ | |
740 } | |
741 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_SCOPE_ACCESSORS) | |
742 #undef REUSABLE_HANDLE_SCOPE_ACCESSORS | |
743 #endif // defined(DEBUG) | |
744 | |
745 #define REUSABLE_HANDLE(object) \ | |
746 object& object##Handle() const { \ | |
747 return *object##_handle_; \ | |
748 } | |
749 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE) | |
750 #undef REUSABLE_HANDLE | |
751 | |
752 static void VisitIsolates(IsolateVisitor* visitor); | 702 static void VisitIsolates(IsolateVisitor* visitor); |
753 | 703 |
754 // Handle service messages until we are told to resume execution. | 704 // Handle service messages until we are told to resume execution. |
755 void PauseEventHandler(); | 705 void PauseEventHandler(); |
756 | 706 |
757 // DEPRECATED: Use Thread's methods instead. During migration, these default | 707 // DEPRECATED: Use Thread's methods instead. During migration, these default |
758 // to using the mutator thread (which must also be the current thread). | 708 // to using the mutator thread (which must also be the current thread). |
759 Zone* current_zone() const { | 709 Zone* current_zone() const { |
760 ASSERT(Thread::Current() == mutator_thread_); | 710 ASSERT(Thread::Current() == mutator_thread_); |
761 return mutator_thread_->zone(); | 711 return mutator_thread_->zone(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 } | 772 } |
823 void MakeCurrentThreadMutator(Thread* thread) { | 773 void MakeCurrentThreadMutator(Thread* thread) { |
824 ASSERT(thread == Thread::Current()); | 774 ASSERT(thread == Thread::Current()); |
825 DEBUG_ASSERT(IsIsolateOf(thread)); | 775 DEBUG_ASSERT(IsIsolateOf(thread)); |
826 mutator_thread_ = thread; | 776 mutator_thread_ = thread; |
827 } | 777 } |
828 #if defined(DEBUG) | 778 #if defined(DEBUG) |
829 bool IsIsolateOf(Thread* thread); | 779 bool IsIsolateOf(Thread* thread); |
830 #endif // DEBUG | 780 #endif // DEBUG |
831 | 781 |
832 template<class T> T* AllocateReusableHandle(); | |
833 | |
834 // Accessed from generated code: | 782 // Accessed from generated code: |
835 uword stack_limit_; | 783 uword stack_limit_; |
836 StoreBuffer* store_buffer_; | 784 StoreBuffer* store_buffer_; |
837 Heap* heap_; | 785 Heap* heap_; |
838 uword vm_tag_; | 786 uword vm_tag_; |
839 uword user_tag_; | 787 uword user_tag_; |
840 RawUserTag* current_tag_; | 788 RawUserTag* current_tag_; |
841 RawUserTag* default_tag_; | 789 RawUserTag* default_tag_; |
842 ClassTable class_table_; | 790 ClassTable class_table_; |
843 bool single_step_; | 791 bool single_step_; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 | 883 |
936 // TODO(23153): Move this out of Isolate/Thread. | 884 // TODO(23153): Move this out of Isolate/Thread. |
937 CHA* cha_; | 885 CHA* cha_; |
938 | 886 |
939 // Isolate list next pointer. | 887 // Isolate list next pointer. |
940 Isolate* next_; | 888 Isolate* next_; |
941 | 889 |
942 // Used to wake the isolate when it is in the pause event loop. | 890 // Used to wake the isolate when it is in the pause event loop. |
943 Monitor* pause_loop_monitor_; | 891 Monitor* pause_loop_monitor_; |
944 | 892 |
945 // Reusable handles support. | |
946 #define REUSABLE_HANDLE_FIELDS(object) \ | |
947 object* object##_handle_; | |
948 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_FIELDS) | |
949 #undef REUSABLE_HANDLE_FIELDS | |
950 | |
951 #if defined(DEBUG) | |
952 #define REUSABLE_HANDLE_SCOPE_VARIABLE(object) \ | |
953 bool reusable_##object##_handle_scope_active_; | |
954 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_SCOPE_VARIABLE); | |
955 #undef REUSABLE_HANDLE_SCOPE_VARIABLE | |
956 #endif // defined(DEBUG) | |
957 | |
958 #define ISOLATE_METRIC_VARIABLE(type, variable, name, unit) \ | 893 #define ISOLATE_METRIC_VARIABLE(type, variable, name, unit) \ |
959 type metric_##variable##_; | 894 type metric_##variable##_; |
960 ISOLATE_METRIC_LIST(ISOLATE_METRIC_VARIABLE); | 895 ISOLATE_METRIC_LIST(ISOLATE_METRIC_VARIABLE); |
961 #undef ISOLATE_METRIC_VARIABLE | 896 #undef ISOLATE_METRIC_VARIABLE |
962 | 897 |
963 #define ISOLATE_TIMELINE_STREAM_VARIABLE(name, not_used) \ | 898 #define ISOLATE_TIMELINE_STREAM_VARIABLE(name, not_used) \ |
964 TimelineStream stream_##name##_; | 899 TimelineStream stream_##name##_; |
965 ISOLATE_TIMELINE_STREAM_LIST(ISOLATE_TIMELINE_STREAM_VARIABLE) | 900 ISOLATE_TIMELINE_STREAM_LIST(ISOLATE_TIMELINE_STREAM_VARIABLE) |
966 #undef ISOLATE_TIMELINE_STREAM_VARIABLE | 901 #undef ISOLATE_TIMELINE_STREAM_VARIABLE |
967 | 902 |
968 VMHandles reusable_handles_; | |
969 | |
970 static Dart_IsolateCreateCallback create_callback_; | 903 static Dart_IsolateCreateCallback create_callback_; |
971 static Dart_IsolateInterruptCallback interrupt_callback_; | 904 static Dart_IsolateInterruptCallback interrupt_callback_; |
972 static Dart_IsolateUnhandledExceptionCallback unhandled_exception_callback_; | 905 static Dart_IsolateUnhandledExceptionCallback unhandled_exception_callback_; |
973 static Dart_IsolateShutdownCallback shutdown_callback_; | 906 static Dart_IsolateShutdownCallback shutdown_callback_; |
974 static Dart_FileOpenCallback file_open_callback_; | 907 static Dart_FileOpenCallback file_open_callback_; |
975 static Dart_FileReadCallback file_read_callback_; | 908 static Dart_FileReadCallback file_read_callback_; |
976 static Dart_FileWriteCallback file_write_callback_; | 909 static Dart_FileWriteCallback file_write_callback_; |
977 static Dart_FileCloseCallback file_close_callback_; | 910 static Dart_FileCloseCallback file_close_callback_; |
978 static Dart_EntropySource entropy_source_callback_; | 911 static Dart_EntropySource entropy_source_callback_; |
979 static Dart_IsolateInterruptCallback vmstats_callback_; | 912 static Dart_IsolateInterruptCallback vmstats_callback_; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 uint8_t* serialized_message_; | 1076 uint8_t* serialized_message_; |
1144 intptr_t serialized_message_len_; | 1077 intptr_t serialized_message_len_; |
1145 Isolate::Flags isolate_flags_; | 1078 Isolate::Flags isolate_flags_; |
1146 bool paused_; | 1079 bool paused_; |
1147 bool errors_are_fatal_; | 1080 bool errors_are_fatal_; |
1148 }; | 1081 }; |
1149 | 1082 |
1150 } // namespace dart | 1083 } // namespace dart |
1151 | 1084 |
1152 #endif // VM_ISOLATE_H_ | 1085 #endif // VM_ISOLATE_H_ |
OLD | NEW |