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" |
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/gc_callbacks.h" | 13 #include "vm/gc_callbacks.h" |
14 #include "vm/handles.h" | |
14 #include "vm/megamorphic_cache_table.h" | 15 #include "vm/megamorphic_cache_table.h" |
15 #include "vm/store_buffer.h" | 16 #include "vm/store_buffer.h" |
16 #include "vm/timer.h" | 17 #include "vm/timer.h" |
17 | 18 |
18 namespace dart { | 19 namespace dart { |
19 | 20 |
20 // Forward declarations. | 21 // Forward declarations. |
22 class AbstractType; | |
21 class ApiState; | 23 class ApiState; |
24 class Array; | |
25 class Class; | |
22 class CodeIndexTable; | 26 class CodeIndexTable; |
23 class Debugger; | 27 class Debugger; |
28 class Field; | |
24 class Function; | 29 class Function; |
25 class HandleScope; | 30 class HandleScope; |
26 class HandleVisitor; | 31 class HandleVisitor; |
27 class Heap; | 32 class Heap; |
28 class ICData; | 33 class ICData; |
29 class Instance; | 34 class Instance; |
30 class LongJump; | 35 class LongJump; |
31 class MessageHandler; | 36 class MessageHandler; |
32 class Mutex; | 37 class Mutex; |
38 class Object; | |
33 class ObjectPointerVisitor; | 39 class ObjectPointerVisitor; |
34 class ObjectStore; | 40 class ObjectStore; |
35 class RawInstance; | 41 class RawInstance; |
36 class RawArray; | 42 class RawArray; |
37 class RawContext; | 43 class RawContext; |
38 class RawDouble; | 44 class RawDouble; |
39 class RawMint; | 45 class RawMint; |
40 class RawObject; | 46 class RawObject; |
41 class RawInteger; | 47 class RawInteger; |
42 class RawError; | 48 class RawError; |
49 class RawFloat32x4; | |
50 class RawUint32x4; | |
43 class Simulator; | 51 class Simulator; |
44 class StackResource; | 52 class StackResource; |
45 class StackZone; | 53 class StackZone; |
46 class StubCode; | 54 class StubCode; |
47 class RawFloat32x4; | 55 class TypeArguments; |
48 class RawUint32x4; | 56 class TypeParameter; |
49 class ObjectHistogram; | 57 class ObjectHistogram; |
50 | 58 |
51 | 59 |
52 // Used by the deoptimization infrastructure to defer allocation of unboxed | 60 // Used by the deoptimization infrastructure to defer allocation of unboxed |
53 // objects until frame is fully rewritten and GC is safe. | 61 // objects until frame is fully rewritten and GC is safe. |
54 // Describes a stack slot that should be populated with a reference to the | 62 // Describes a stack slot that should be populated with a reference to the |
55 // materialized object. | 63 // materialized object. |
56 class DeferredSlot { | 64 class DeferredSlot { |
57 public: | 65 public: |
58 DeferredSlot(RawInstance** slot, DeferredSlot* next) | 66 DeferredSlot(RawInstance** slot, DeferredSlot* next) |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 // The first argument is Class of the instance to materialize followed by | 218 // The first argument is Class of the instance to materialize followed by |
211 // Field, value pairs. | 219 // Field, value pairs. |
212 RawObject** args_; | 220 RawObject** args_; |
213 | 221 |
214 // Object materialized from this description. | 222 // Object materialized from this description. |
215 const Instance* object_; | 223 const Instance* object_; |
216 | 224 |
217 DISALLOW_COPY_AND_ASSIGN(DeferredObject); | 225 DISALLOW_COPY_AND_ASSIGN(DeferredObject); |
218 }; | 226 }; |
219 | 227 |
228 #define REUSABLE_HANDLE_LIST(V) \ | |
229 V(Object) \ | |
230 V(Array) \ | |
231 V(String) \ | |
232 V(Instance) \ | |
233 V(Function) \ | |
234 V(Field) \ | |
235 V(Class) \ | |
236 V(AbstractType) \ | |
237 V(TypeParameter) \ | |
238 V(TypeArguments) \ | |
220 | 239 |
221 class Isolate : public BaseIsolate { | 240 class Isolate : public BaseIsolate { |
222 public: | 241 public: |
223 ~Isolate(); | 242 ~Isolate(); |
224 | 243 |
225 static inline Isolate* Current() { | 244 static inline Isolate* Current() { |
226 return reinterpret_cast<Isolate*>(Thread::GetThreadLocal(isolate_key)); | 245 return reinterpret_cast<Isolate*>(Thread::GetThreadLocal(isolate_key)); |
227 } | 246 } |
228 | 247 |
229 static void SetCurrent(Isolate* isolate); | 248 static void SetCurrent(Isolate* isolate); |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
588 | 607 |
589 void BuildName(const char* name_prefix); | 608 void BuildName(const char* name_prefix); |
590 void PrintInvokedFunctions(); | 609 void PrintInvokedFunctions(); |
591 | 610 |
592 static bool FetchStacktrace(); | 611 static bool FetchStacktrace(); |
593 static bool FetchStackFrameDetails(); | 612 static bool FetchStackFrameDetails(); |
594 char* GetStatusDetails(); | 613 char* GetStatusDetails(); |
595 char* GetStatusStacktrace(); | 614 char* GetStatusStacktrace(); |
596 char* GetStatusStackFrame(intptr_t index); | 615 char* GetStatusStackFrame(intptr_t index); |
597 char* DoStacktraceInterrupt(Dart_IsolateInterruptCallback cb); | 616 char* DoStacktraceInterrupt(Dart_IsolateInterruptCallback cb); |
617 template<class T> T* AllocateReusableHandle(); | |
598 | 618 |
599 static ThreadLocalKey isolate_key; | 619 static ThreadLocalKey isolate_key; |
600 StoreBuffer store_buffer_; | 620 StoreBuffer store_buffer_; |
601 ClassTable class_table_; | 621 ClassTable class_table_; |
602 MegamorphicCacheTable megamorphic_cache_table_; | 622 MegamorphicCacheTable megamorphic_cache_table_; |
603 Dart_MessageNotifyCallback message_notify_callback_; | 623 Dart_MessageNotifyCallback message_notify_callback_; |
604 char* name_; | 624 char* name_; |
605 int64_t start_time_; | 625 int64_t start_time_; |
606 Dart_Port main_port_; | 626 Dart_Port main_port_; |
607 Heap* heap_; | 627 Heap* heap_; |
(...skipping 28 matching lines...) Expand all Loading... | |
636 DeferredSlot* deferred_object_refs_; | 656 DeferredSlot* deferred_object_refs_; |
637 | 657 |
638 intptr_t deferred_objects_count_; | 658 intptr_t deferred_objects_count_; |
639 DeferredObject** deferred_objects_; | 659 DeferredObject** deferred_objects_; |
640 | 660 |
641 // Status support. | 661 // Status support. |
642 char* stacktrace_; | 662 char* stacktrace_; |
643 intptr_t stack_frame_index_; | 663 intptr_t stack_frame_index_; |
644 ObjectHistogram* object_histogram_; | 664 ObjectHistogram* object_histogram_; |
645 | 665 |
666 // Reusable handles support. | |
667 #define REUSABLE_HANDLE_FIELDS(object) \ | |
668 object* object##_handle_; \ | |
669 | |
670 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_FIELDS) | |
671 #undef REUSABLE_HANDLE_FIELDS | |
672 VMHandles handles_; | |
Ivan Posva
2013/06/22 01:01:36
reusable_handles_?
siva
2013/07/18 20:39:23
Done.
| |
673 | |
646 static Dart_IsolateCreateCallback create_callback_; | 674 static Dart_IsolateCreateCallback create_callback_; |
647 static Dart_IsolateInterruptCallback interrupt_callback_; | 675 static Dart_IsolateInterruptCallback interrupt_callback_; |
648 static Dart_IsolateUnhandledExceptionCallback unhandled_exception_callback_; | 676 static Dart_IsolateUnhandledExceptionCallback unhandled_exception_callback_; |
649 static Dart_IsolateShutdownCallback shutdown_callback_; | 677 static Dart_IsolateShutdownCallback shutdown_callback_; |
650 static Dart_FileOpenCallback file_open_callback_; | 678 static Dart_FileOpenCallback file_open_callback_; |
651 static Dart_FileReadCallback file_read_callback_; | 679 static Dart_FileReadCallback file_read_callback_; |
652 static Dart_FileWriteCallback file_write_callback_; | 680 static Dart_FileWriteCallback file_write_callback_; |
653 static Dart_FileCloseCallback file_close_callback_; | 681 static Dart_FileCloseCallback file_close_callback_; |
654 static Dart_IsolateInterruptCallback vmstats_callback_; | 682 static Dart_IsolateInterruptCallback vmstats_callback_; |
655 | 683 |
684 friend class ReusableHandleScope; | |
656 DISALLOW_COPY_AND_ASSIGN(Isolate); | 685 DISALLOW_COPY_AND_ASSIGN(Isolate); |
657 }; | 686 }; |
658 | 687 |
688 // The class ReusableHandleScope is used in regions of the | |
689 // virtual machine where isolate specific reusable handles are used. | |
690 // This class asserts that we do not add code that will result in recursive | |
691 // uses of reusable handles. | |
692 // It is used as follows: | |
693 // { | |
694 // ReusableHandleScope reused_handles(isolate); | |
695 // .... | |
696 // ..... | |
697 // code that uses isolate specific reusable handles. | |
698 // Array& funcs = reused_handles.ArrayHandle(); | |
699 // .... | |
700 // } | |
701 #if defined(DEBUG) | |
702 class ReusableHandleScope : public StackResource { | |
703 #else | |
704 class ReusableHandleScope : public ValueObject { | |
705 #endif | |
706 | |
707 public: | |
708 explicit ReusableHandleScope(Isolate* isolate) : isolate_(isolate) { | |
709 #if defined(DEBUG) | |
710 ASSERT(!isolate->reusable_handle_scope_active()); | |
711 isolate->set_reusable_handle_scope_active(true); | |
712 #endif // defined(DEBUG) | |
713 } | |
714 ReusableHandleScope() : isolate_(Isolate::Current()) { | |
715 #if defined(DEBUG) | |
716 ASSERT(!isolate_->reusable_handle_scope_active()); | |
717 isolate_->set_reusable_handle_scope_active(true); | |
718 #endif // defined(DEBUG) | |
719 } | |
720 ~ReusableHandleScope() { | |
721 #if defined(DEBUG) | |
722 ASSERT(isolate_->reusable_handle_scope_active()); | |
723 isolate_->set_reusable_handle_scope_active(false); | |
724 #endif // defined(DEBUG) | |
Ivan Posva
2013/06/22 01:01:36
To not keep objects alive longer than needed we sh
siva
2013/07/18 20:39:23
Done.
| |
725 } | |
726 | |
727 #define REUSABLE_HANDLE_ACCESSORS(object) \ | |
728 object& object##Handle() { \ | |
729 ASSERT(isolate_->object##_handle_ != NULL); \ | |
730 return *isolate_->object##_handle_; \ | |
731 } \ | |
732 | |
733 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_ACCESSORS) | |
734 #undef REUSABLE_HANDLE_ACCESSORS | |
735 | |
736 private: | |
737 Isolate* isolate_; | |
738 DISALLOW_COPY_AND_ASSIGN(ReusableHandleScope); | |
739 }; | |
740 | |
659 // When we need to execute code in an isolate, we use the | 741 // When we need to execute code in an isolate, we use the |
660 // StartIsolateScope. | 742 // StartIsolateScope. |
661 class StartIsolateScope { | 743 class StartIsolateScope { |
662 public: | 744 public: |
663 explicit StartIsolateScope(Isolate* new_isolate) | 745 explicit StartIsolateScope(Isolate* new_isolate) |
664 : new_isolate_(new_isolate), saved_isolate_(Isolate::Current()) { | 746 : new_isolate_(new_isolate), saved_isolate_(Isolate::Current()) { |
665 ASSERT(new_isolate_ != NULL); | 747 ASSERT(new_isolate_ != NULL); |
666 if (saved_isolate_ != new_isolate_) { | 748 if (saved_isolate_ != new_isolate_) { |
667 ASSERT(Isolate::Current() == NULL); | 749 ASSERT(Isolate::Current() == NULL); |
668 Isolate::SetCurrent(new_isolate_); | 750 Isolate::SetCurrent(new_isolate_); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
764 | 846 |
765 private: | 847 private: |
766 Isolate::IsolateRunState saved_state_; | 848 Isolate::IsolateRunState saved_state_; |
767 | 849 |
768 DISALLOW_COPY_AND_ASSIGN(IsolateRunStateManager); | 850 DISALLOW_COPY_AND_ASSIGN(IsolateRunStateManager); |
769 }; | 851 }; |
770 | 852 |
771 } // namespace dart | 853 } // namespace dart |
772 | 854 |
773 #endif // VM_ISOLATE_H_ | 855 #endif // VM_ISOLATE_H_ |
OLD | NEW |