| 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/base_isolate.h" | 10 #include "vm/base_isolate.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 V(TypeParameter) \ | 115 V(TypeParameter) \ |
| 116 | 116 |
| 117 class Isolate : public BaseIsolate { | 117 class Isolate : public BaseIsolate { |
| 118 public: | 118 public: |
| 119 ~Isolate(); | 119 ~Isolate(); |
| 120 | 120 |
| 121 static inline Isolate* Current() { | 121 static inline Isolate* Current() { |
| 122 Thread* thread = Thread::Current(); | 122 Thread* thread = Thread::Current(); |
| 123 return thread == NULL ? NULL : thread->isolate(); | 123 return thread == NULL ? NULL : thread->isolate(); |
| 124 } | 124 } |
| 125 static void SetCurrent(Isolate* isolate); | |
| 126 | 125 |
| 127 static void InitOnce(); | 126 static void InitOnce(); |
| 128 static Isolate* Init(const char* name_prefix, bool is_vm_isolate = false); | 127 static Isolate* Init(const char* name_prefix, bool is_vm_isolate = false); |
| 129 void Shutdown(); | 128 void Shutdown(); |
| 130 | 129 |
| 131 Isolate* ShallowCopy(); | 130 Isolate* ShallowCopy(); |
| 132 | 131 |
| 133 // Register a newly introduced class. | 132 // Register a newly introduced class. |
| 134 void RegisterClass(const Class& cls); | 133 void RegisterClass(const Class& cls); |
| 135 void RegisterClassAt(intptr_t index, const Class& cls); | 134 void RegisterClassAt(intptr_t index, const Class& cls); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 163 return message_notify_callback_; | 162 return message_notify_callback_; |
| 164 } | 163 } |
| 165 void set_message_notify_callback(Dart_MessageNotifyCallback value) { | 164 void set_message_notify_callback(Dart_MessageNotifyCallback value) { |
| 166 message_notify_callback_ = value; | 165 message_notify_callback_ = value; |
| 167 } | 166 } |
| 168 | 167 |
| 169 // A thread that operates on this isolate and may execute Dart code. | 168 // A thread that operates on this isolate and may execute Dart code. |
| 170 // No other threads operating on this isolate may execute Dart code. | 169 // No other threads operating on this isolate may execute Dart code. |
| 171 // TODO(koda): Remove after caching current thread in generated code. | 170 // TODO(koda): Remove after caching current thread in generated code. |
| 172 Thread* mutator_thread() { | 171 Thread* mutator_thread() { |
| 173 DEBUG_ASSERT(IsIsolateOf(mutator_thread_)); | 172 DEBUG_ASSERT(mutator_thread_ == NULL || IsIsolateOf(mutator_thread_)); |
| 174 return mutator_thread_; | 173 return mutator_thread_; |
| 175 } | 174 } |
| 176 #if defined(DEBUG) | 175 #if defined(DEBUG) |
| 177 bool IsIsolateOf(Thread* thread); | 176 bool IsIsolateOf(Thread* thread); |
| 178 #endif // DEBUG | 177 #endif // DEBUG |
| 179 | 178 |
| 180 const char* name() const { return name_; } | 179 const char* name() const { return name_; } |
| 181 const char* debugger_name() const { return debugger_name_; } | 180 const char* debugger_name() const { return debugger_name_; } |
| 182 void set_debugger_name(const char* name); | 181 void set_debugger_name(const char* name); |
| 183 | 182 |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 | 675 |
| 677 void BuildName(const char* name_prefix); | 676 void BuildName(const char* name_prefix); |
| 678 void PrintInvokedFunctions(); | 677 void PrintInvokedFunctions(); |
| 679 | 678 |
| 680 void ProfileIdle(); | 679 void ProfileIdle(); |
| 681 | 680 |
| 682 void set_user_tag(uword tag) { | 681 void set_user_tag(uword tag) { |
| 683 user_tag_ = tag; | 682 user_tag_ = tag; |
| 684 } | 683 } |
| 685 | 684 |
| 685 void set_mutator_thread(Thread* thread) { |
| 686 mutator_thread_ = thread; |
| 687 } |
| 688 |
| 686 template<class T> T* AllocateReusableHandle(); | 689 template<class T> T* AllocateReusableHandle(); |
| 687 | 690 |
| 688 Thread* mutator_thread_; | 691 Thread* mutator_thread_; |
| 689 uword vm_tag_; | 692 uword vm_tag_; |
| 690 StoreBuffer store_buffer_; | 693 StoreBuffer store_buffer_; |
| 691 ClassTable class_table_; | 694 ClassTable class_table_; |
| 692 MegamorphicCacheTable megamorphic_cache_table_; | 695 MegamorphicCacheTable megamorphic_cache_table_; |
| 693 Dart_MessageNotifyCallback message_notify_callback_; | 696 Dart_MessageNotifyCallback message_notify_callback_; |
| 694 char* name_; | 697 char* name_; |
| 695 char* debugger_name_; | 698 char* debugger_name_; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 DISALLOW_COPY_AND_ASSIGN(Isolate); | 821 DISALLOW_COPY_AND_ASSIGN(Isolate); |
| 819 }; | 822 }; |
| 820 | 823 |
| 821 | 824 |
| 822 // When we need to execute code in an isolate, we use the | 825 // When we need to execute code in an isolate, we use the |
| 823 // StartIsolateScope. | 826 // StartIsolateScope. |
| 824 class StartIsolateScope { | 827 class StartIsolateScope { |
| 825 public: | 828 public: |
| 826 explicit StartIsolateScope(Isolate* new_isolate) | 829 explicit StartIsolateScope(Isolate* new_isolate) |
| 827 : new_isolate_(new_isolate), saved_isolate_(Isolate::Current()) { | 830 : new_isolate_(new_isolate), saved_isolate_(Isolate::Current()) { |
| 831 // TODO(koda): Audit users; passing NULL goes against naming of this class. |
| 828 if (new_isolate_ == NULL) { | 832 if (new_isolate_ == NULL) { |
| 829 // Do nothing. | 833 // Do nothing. |
| 830 return; | 834 return; |
| 831 } | 835 } |
| 832 if (saved_isolate_ != new_isolate_) { | 836 if (saved_isolate_ != new_isolate_) { |
| 833 ASSERT(Isolate::Current() == NULL); | 837 ASSERT(Isolate::Current() == NULL); |
| 834 Isolate::SetCurrent(new_isolate_); | 838 Thread::EnterIsolate(new_isolate_); |
| 835 new_isolate_->SetStackLimitFromStackBase( | 839 new_isolate_->SetStackLimitFromStackBase( |
| 836 Isolate::GetCurrentStackPointer()); | 840 Isolate::GetCurrentStackPointer()); |
| 837 } | 841 } |
| 838 } | 842 } |
| 839 | 843 |
| 840 ~StartIsolateScope() { | 844 ~StartIsolateScope() { |
| 841 if (new_isolate_ == NULL) { | 845 if (new_isolate_ == NULL) { |
| 842 // Do nothing. | 846 // Do nothing. |
| 843 return; | 847 return; |
| 844 } | 848 } |
| 845 if (saved_isolate_ != new_isolate_) { | 849 if (saved_isolate_ != new_isolate_) { |
| 846 new_isolate_->ClearStackLimit(); | 850 new_isolate_->ClearStackLimit(); |
| 847 Isolate::SetCurrent(saved_isolate_); | 851 Thread::ExitIsolate(); |
| 852 if (saved_isolate_ != NULL) { |
| 853 Thread::EnterIsolate(saved_isolate_); |
| 854 } |
| 848 } | 855 } |
| 849 } | 856 } |
| 850 | 857 |
| 851 private: | 858 private: |
| 852 Isolate* new_isolate_; | 859 Isolate* new_isolate_; |
| 853 Isolate* saved_isolate_; | 860 Isolate* saved_isolate_; |
| 854 | 861 |
| 855 DISALLOW_COPY_AND_ASSIGN(StartIsolateScope); | 862 DISALLOW_COPY_AND_ASSIGN(StartIsolateScope); |
| 856 }; | 863 }; |
| 857 | 864 |
| 858 // When we need to temporarily become another isolate, we use the | 865 // When we need to temporarily become another isolate, we use the |
| 859 // SwitchIsolateScope. It is not permitted to run dart code while in | 866 // SwitchIsolateScope. It is not permitted to run dart code while in |
| 860 // a SwitchIsolateScope. | 867 // a SwitchIsolateScope. |
| 861 class SwitchIsolateScope { | 868 class SwitchIsolateScope { |
| 862 public: | 869 public: |
| 863 explicit SwitchIsolateScope(Isolate* new_isolate) | 870 explicit SwitchIsolateScope(Isolate* new_isolate) |
| 864 : new_isolate_(new_isolate), | 871 : new_isolate_(new_isolate), |
| 865 saved_isolate_(Isolate::Current()), | 872 saved_isolate_(Isolate::Current()), |
| 866 saved_stack_limit_(saved_isolate_ | 873 saved_stack_limit_(saved_isolate_ |
| 867 ? saved_isolate_->saved_stack_limit() : 0) { | 874 ? saved_isolate_->saved_stack_limit() : 0) { |
| 875 // TODO(koda): Audit users; why would these two ever be equal? |
| 868 if (saved_isolate_ != new_isolate_) { | 876 if (saved_isolate_ != new_isolate_) { |
| 869 Isolate::SetCurrent(new_isolate_); | 877 if (new_isolate_ == NULL) { |
| 870 if (new_isolate_ != NULL) { | 878 Thread::ExitIsolate(); |
| 879 } else { |
| 880 Thread::EnterIsolate(new_isolate_); |
| 871 // Don't allow dart code to execute. | 881 // Don't allow dart code to execute. |
| 872 new_isolate_->SetStackLimit(~static_cast<uword>(0)); | 882 new_isolate_->SetStackLimit(~static_cast<uword>(0)); |
| 873 } | 883 } |
| 874 } | 884 } |
| 875 } | 885 } |
| 876 | 886 |
| 877 ~SwitchIsolateScope() { | 887 ~SwitchIsolateScope() { |
| 878 if (saved_isolate_ != new_isolate_) { | 888 if (saved_isolate_ != new_isolate_) { |
| 879 Isolate::SetCurrent(saved_isolate_); | 889 if (new_isolate_ != NULL) { |
| 890 Thread::ExitIsolate(); |
| 891 } |
| 880 if (saved_isolate_ != NULL) { | 892 if (saved_isolate_ != NULL) { |
| 893 Thread::EnterIsolate(saved_isolate_); |
| 881 saved_isolate_->SetStackLimit(saved_stack_limit_); | 894 saved_isolate_->SetStackLimit(saved_stack_limit_); |
| 882 } | 895 } |
| 883 } | 896 } |
| 884 } | 897 } |
| 885 | 898 |
| 886 private: | 899 private: |
| 887 Isolate* new_isolate_; | 900 Isolate* new_isolate_; |
| 888 Isolate* saved_isolate_; | 901 Isolate* saved_isolate_; |
| 889 uword saved_stack_limit_; | 902 uword saved_stack_limit_; |
| 890 | 903 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 uint8_t* serialized_args_; | 947 uint8_t* serialized_args_; |
| 935 intptr_t serialized_args_len_; | 948 intptr_t serialized_args_len_; |
| 936 uint8_t* serialized_message_; | 949 uint8_t* serialized_message_; |
| 937 intptr_t serialized_message_len_; | 950 intptr_t serialized_message_len_; |
| 938 bool paused_; | 951 bool paused_; |
| 939 }; | 952 }; |
| 940 | 953 |
| 941 } // namespace dart | 954 } // namespace dart |
| 942 | 955 |
| 943 #endif // VM_ISOLATE_H_ | 956 #endif // VM_ISOLATE_H_ |
| OLD | NEW |