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 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 static Dart_IsolateInterruptCallback interrupt_callback_; | 700 static Dart_IsolateInterruptCallback interrupt_callback_; |
701 static Dart_IsolateUnhandledExceptionCallback unhandled_exception_callback_; | 701 static Dart_IsolateUnhandledExceptionCallback unhandled_exception_callback_; |
702 static Dart_IsolateShutdownCallback shutdown_callback_; | 702 static Dart_IsolateShutdownCallback shutdown_callback_; |
703 static Dart_FileOpenCallback file_open_callback_; | 703 static Dart_FileOpenCallback file_open_callback_; |
704 static Dart_FileReadCallback file_read_callback_; | 704 static Dart_FileReadCallback file_read_callback_; |
705 static Dart_FileWriteCallback file_write_callback_; | 705 static Dart_FileWriteCallback file_write_callback_; |
706 static Dart_FileCloseCallback file_close_callback_; | 706 static Dart_FileCloseCallback file_close_callback_; |
707 static Dart_IsolateInterruptCallback vmstats_callback_; | 707 static Dart_IsolateInterruptCallback vmstats_callback_; |
708 | 708 |
709 friend class ReusableHandleScope; | 709 friend class ReusableHandleScope; |
| 710 friend class ReusableObjectHandleScope; |
710 DISALLOW_COPY_AND_ASSIGN(Isolate); | 711 DISALLOW_COPY_AND_ASSIGN(Isolate); |
711 }; | 712 }; |
712 | 713 |
713 // The class ReusableHandleScope is used in regions of the | |
714 // virtual machine where isolate specific reusable handles are used. | |
715 // This class asserts that we do not add code that will result in recursive | |
716 // uses of reusable handles. | |
717 // It is used as follows: | |
718 // { | |
719 // ReusableHandleScope reused_handles(isolate); | |
720 // .... | |
721 // ..... | |
722 // code that uses isolate specific reusable handles. | |
723 // Array& funcs = reused_handles.ArrayHandle(); | |
724 // .... | |
725 // } | |
726 #if defined(DEBUG) | |
727 class ReusableHandleScope : public StackResource { | |
728 public: | |
729 explicit ReusableHandleScope(Isolate* isolate) | |
730 : StackResource(isolate), isolate_(isolate) { | |
731 ASSERT(!isolate->reusable_handle_scope_active()); | |
732 isolate->set_reusable_handle_scope_active(true); | |
733 } | |
734 ReusableHandleScope() | |
735 : StackResource(Isolate::Current()), isolate_(Isolate::Current()) { | |
736 ASSERT(!isolate()->reusable_handle_scope_active()); | |
737 isolate()->set_reusable_handle_scope_active(true); | |
738 } | |
739 ~ReusableHandleScope() { | |
740 ASSERT(isolate()->reusable_handle_scope_active()); | |
741 isolate()->set_reusable_handle_scope_active(false); | |
742 ResetHandles(); | |
743 } | |
744 | |
745 #define REUSABLE_HANDLE_ACCESSORS(object) \ | |
746 object& object##Handle() { \ | |
747 ASSERT(isolate_->object##_handle_ != NULL); \ | |
748 return *isolate_->object##_handle_; \ | |
749 } \ | |
750 | |
751 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_ACCESSORS) | |
752 #undef REUSABLE_HANDLE_ACCESSORS | |
753 | |
754 private: | |
755 void ResetHandles(); | |
756 Isolate* isolate_; | |
757 DISALLOW_COPY_AND_ASSIGN(ReusableHandleScope); | |
758 }; | |
759 #else | |
760 class ReusableHandleScope : public ValueObject { | |
761 public: | |
762 explicit ReusableHandleScope(Isolate* isolate) : isolate_(isolate) { | |
763 } | |
764 ReusableHandleScope() : isolate_(Isolate::Current()) { | |
765 } | |
766 ~ReusableHandleScope() { | |
767 ResetHandles(); | |
768 } | |
769 | |
770 #define REUSABLE_HANDLE_ACCESSORS(object) \ | |
771 object& object##Handle() { \ | |
772 ASSERT(isolate_->object##_handle_ != NULL); \ | |
773 return *isolate_->object##_handle_; \ | |
774 } \ | |
775 | |
776 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_ACCESSORS) | |
777 #undef REUSABLE_HANDLE_ACCESSORS | |
778 | |
779 private: | |
780 void ResetHandles(); | |
781 Isolate* isolate_; | |
782 DISALLOW_COPY_AND_ASSIGN(ReusableHandleScope); | |
783 }; | |
784 #endif // defined(DEBUG) | |
785 | |
786 | |
787 | 714 |
788 // When we need to execute code in an isolate, we use the | 715 // When we need to execute code in an isolate, we use the |
789 // StartIsolateScope. | 716 // StartIsolateScope. |
790 class StartIsolateScope { | 717 class StartIsolateScope { |
791 public: | 718 public: |
792 explicit StartIsolateScope(Isolate* new_isolate) | 719 explicit StartIsolateScope(Isolate* new_isolate) |
793 : new_isolate_(new_isolate), saved_isolate_(Isolate::Current()) { | 720 : new_isolate_(new_isolate), saved_isolate_(Isolate::Current()) { |
794 ASSERT(new_isolate_ != NULL); | 721 ASSERT(new_isolate_ != NULL); |
795 if (saved_isolate_ != new_isolate_) { | 722 if (saved_isolate_ != new_isolate_) { |
796 ASSERT(Isolate::Current() == NULL); | 723 ASSERT(Isolate::Current() == NULL); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 Isolate* isolate_; | 797 Isolate* isolate_; |
871 char* script_url_; | 798 char* script_url_; |
872 char* library_url_; | 799 char* library_url_; |
873 char* function_name_; | 800 char* function_name_; |
874 char* exception_callback_name_; | 801 char* exception_callback_name_; |
875 }; | 802 }; |
876 | 803 |
877 } // namespace dart | 804 } // namespace dart |
878 | 805 |
879 #endif // VM_ISOLATE_H_ | 806 #endif // VM_ISOLATE_H_ |
OLD | NEW |