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" |
11 #include "vm/class_table.h" | 11 #include "vm/class_table.h" |
12 #include "vm/counters.h" | 12 #include "vm/counters.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/store_buffer.h" | 17 #include "vm/store_buffer.h" |
18 #include "vm/tags.h" | 18 #include "vm/tags.h" |
19 #include "vm/thread.h" | 19 #include "vm/thread.h" |
20 #include "vm/os_thread.h" | 20 #include "vm/os_thread.h" |
21 #include "vm/trace_buffer.h" | 21 #include "vm/trace_buffer.h" |
22 #include "vm/timer.h" | 22 #include "vm/timer.h" |
23 | 23 |
24 namespace dart { | 24 namespace dart { |
25 | 25 |
26 DECLARE_FLAG(bool, enable_type_checks); | |
27 DECLARE_FLAG(bool, enable_asserts); | |
28 DECLARE_FLAG(bool, error_on_bad_type); | |
29 DECLARE_FLAG(bool, error_on_bad_override); | |
30 | |
31 // Forward declarations. | 26 // Forward declarations. |
32 class AbstractType; | 27 class AbstractType; |
33 class ApiState; | 28 class ApiState; |
34 class Array; | 29 class Array; |
35 class Capability; | 30 class Capability; |
36 class CHA; | 31 class CHA; |
37 class Class; | 32 class Class; |
38 class Code; | 33 class Code; |
39 class CodeIndexTable; | 34 class CodeIndexTable; |
40 class CompilerStats; | 35 class CompilerStats; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 class Isolate : public BaseIsolate { | 114 class Isolate : public BaseIsolate { |
120 public: | 115 public: |
121 ~Isolate(); | 116 ~Isolate(); |
122 | 117 |
123 static inline Isolate* Current() { | 118 static inline Isolate* Current() { |
124 Thread* thread = Thread::Current(); | 119 Thread* thread = Thread::Current(); |
125 return thread == NULL ? NULL : thread->isolate(); | 120 return thread == NULL ? NULL : thread->isolate(); |
126 } | 121 } |
127 | 122 |
128 static void InitOnce(); | 123 static void InitOnce(); |
129 static Isolate* Init(const char* name_prefix, bool is_vm_isolate = false); | 124 static Isolate* Init(const char* name_prefix, |
125 const Dart_IsolateFlags& api_flags, | |
126 bool is_vm_isolate = false); | |
130 void Shutdown(); | 127 void Shutdown(); |
131 | 128 |
132 // Register a newly introduced class. | 129 // Register a newly introduced class. |
133 void RegisterClass(const Class& cls); | 130 void RegisterClass(const Class& cls); |
134 void RegisterClassAt(intptr_t index, const Class& cls); | 131 void RegisterClassAt(intptr_t index, const Class& cls); |
135 void ValidateClassTable(); | 132 void ValidateClassTable(); |
136 | 133 |
137 // Visit all object pointers. | 134 // Visit all object pointers. |
138 void VisitObjectPointers(ObjectPointerVisitor* visitor, | 135 void VisitObjectPointers(ObjectPointerVisitor* visitor, |
139 bool visit_prologue_weak_persistent_handles, | 136 bool visit_prologue_weak_persistent_handles, |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 | 373 |
377 void set_single_step(bool value) { single_step_ = value; } | 374 void set_single_step(bool value) { single_step_ = value; } |
378 bool single_step() const { return single_step_; } | 375 bool single_step() const { return single_step_; } |
379 static intptr_t single_step_offset() { | 376 static intptr_t single_step_offset() { |
380 return OFFSET_OF(Isolate, single_step_); | 377 return OFFSET_OF(Isolate, single_step_); |
381 } | 378 } |
382 | 379 |
383 void set_has_compiled(bool value) { has_compiled_ = value; } | 380 void set_has_compiled(bool value) { has_compiled_ = value; } |
384 bool has_compiled() const { return has_compiled_; } | 381 bool has_compiled() const { return has_compiled_; } |
385 | 382 |
386 void set_strict_compilation(bool value) { strict_compilation_ = value; } | 383 // TODO(iposva): Evaluate whether two different isolate flag structures are |
387 bool strict_compilation() const { return strict_compilation_; } | 384 // needed. Currently it serves as a separation between publicly visible flags |
388 bool TypeChecksEnabled() { | 385 // and VM internal flags. |
389 return FLAG_enable_type_checks || strict_compilation_; | 386 class Flags : public ValueObject { |
390 } | 387 public: |
391 bool AssertsEnabled() { | 388 // Construct default flags as specified by the options. |
392 return FLAG_enable_asserts || strict_compilation_; | 389 Flags(); |
393 } | 390 |
394 bool ErrorOnBadTypeEnabled() { | 391 bool type_checks() const { return type_checks_; } |
395 return FLAG_error_on_bad_type || strict_compilation_; | 392 bool asserts() const { return asserts_; } |
396 } | 393 bool error_on_bad_type() const { return error_on_bad_type_; } |
397 bool ErrorOnBadOverrideEnabled() { | 394 bool error_on_bad_override() const { return error_on_bad_override_; } |
398 return FLAG_error_on_bad_override || strict_compilation_; | 395 |
396 void set_checked(bool val) { | |
397 type_checks_ = val; | |
398 asserts_ = val; | |
399 } | |
400 | |
401 void CopyFrom(const Flags& orig); | |
Florian Schneider
2015/06/08 11:25:49
Are these used outside constructors? Otherwise, ju
| |
402 void CopyFrom(const Dart_IsolateFlags& api_flags); | |
403 void CopyTo(Dart_IsolateFlags* api_flags) const; | |
404 | |
405 private: | |
406 bool type_checks_; | |
407 bool asserts_; | |
408 bool error_on_bad_type_; | |
409 bool error_on_bad_override_; | |
410 | |
411 friend class Isolate; | |
412 | |
413 DISALLOW_ALLOCATION(); | |
414 DISALLOW_COPY_AND_ASSIGN(Flags); | |
415 }; | |
416 | |
417 const Flags& flags() const { return flags_; } | |
418 | |
419 // Set the checks in the compiler to the highest level. Statically and when | |
420 // executing generated code. Needs to be called before any code has been | |
421 // compiled. | |
422 void set_strict_compilation() { | |
423 ASSERT(!has_compiled()); | |
424 flags_.type_checks_ = true; | |
425 flags_.asserts_ = true; | |
426 flags_.error_on_bad_type_ = true; | |
427 flags_.error_on_bad_override_ = true; | |
399 } | 428 } |
400 | 429 |
401 // Requests that the debugger resume execution. | 430 // Requests that the debugger resume execution. |
402 void Resume() { | 431 void Resume() { |
403 resume_request_ = true; | 432 resume_request_ = true; |
404 } | 433 } |
405 | 434 |
406 // Returns whether the vm service has requested that the debugger | 435 // Returns whether the vm service has requested that the debugger |
407 // resume execution. | 436 // resume execution. |
408 bool GetAndClearResumeRequest() { | 437 bool GetAndClearResumeRequest() { |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
670 #undef REUSABLE_HANDLE | 699 #undef REUSABLE_HANDLE |
671 | 700 |
672 static void VisitIsolates(IsolateVisitor* visitor); | 701 static void VisitIsolates(IsolateVisitor* visitor); |
673 | 702 |
674 Counters* counters() { return &counters_; } | 703 Counters* counters() { return &counters_; } |
675 | 704 |
676 // Handle service messages until we are told to resume execution. | 705 // Handle service messages until we are told to resume execution. |
677 void PauseEventHandler(); | 706 void PauseEventHandler(); |
678 | 707 |
679 private: | 708 private: |
680 Isolate(); | 709 explicit Isolate(const Dart_IsolateFlags& api_flags); |
681 | 710 |
682 void BuildName(const char* name_prefix); | 711 void BuildName(const char* name_prefix); |
683 void PrintInvokedFunctions(); | 712 void PrintInvokedFunctions(); |
684 | 713 |
685 void ProfileIdle(); | 714 void ProfileIdle(); |
686 | 715 |
687 void set_user_tag(uword tag) { | 716 void set_user_tag(uword tag) { |
688 user_tag_ = tag; | 717 user_tag_ = tag; |
689 } | 718 } |
690 | 719 |
(...skipping 22 matching lines...) Expand all Loading... | |
713 uword top_exit_frame_info_; | 742 uword top_exit_frame_info_; |
714 void* init_callback_data_; | 743 void* init_callback_data_; |
715 Dart_EnvironmentCallback environment_callback_; | 744 Dart_EnvironmentCallback environment_callback_; |
716 Dart_LibraryTagHandler library_tag_handler_; | 745 Dart_LibraryTagHandler library_tag_handler_; |
717 ApiState* api_state_; | 746 ApiState* api_state_; |
718 StubCode* stub_code_; | 747 StubCode* stub_code_; |
719 Debugger* debugger_; | 748 Debugger* debugger_; |
720 bool single_step_; | 749 bool single_step_; |
721 bool resume_request_; | 750 bool resume_request_; |
722 bool has_compiled_; | 751 bool has_compiled_; |
723 bool strict_compilation_; | 752 Flags flags_; |
724 Random random_; | 753 Random random_; |
725 Simulator* simulator_; | 754 Simulator* simulator_; |
726 LongJumpScope* long_jump_base_; | 755 LongJumpScope* long_jump_base_; |
727 TimerList timer_list_; | 756 TimerList timer_list_; |
728 intptr_t deopt_id_; | 757 intptr_t deopt_id_; |
729 Mutex* mutex_; // protects stack_limit_ and saved_stack_limit_. | 758 Mutex* mutex_; // protects stack_limit_ and saved_stack_limit_. |
730 uword stack_limit_; | 759 uword stack_limit_; |
731 uword saved_stack_limit_; | 760 uword saved_stack_limit_; |
732 uword stack_base_; | 761 uword stack_base_; |
733 uword stack_overflow_flags_; | 762 uword stack_overflow_flags_; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
919 | 948 |
920 DISALLOW_COPY_AND_ASSIGN(SwitchIsolateScope); | 949 DISALLOW_COPY_AND_ASSIGN(SwitchIsolateScope); |
921 }; | 950 }; |
922 | 951 |
923 | 952 |
924 class IsolateSpawnState { | 953 class IsolateSpawnState { |
925 public: | 954 public: |
926 IsolateSpawnState(Dart_Port parent_port, | 955 IsolateSpawnState(Dart_Port parent_port, |
927 const Function& func, | 956 const Function& func, |
928 const Instance& message, | 957 const Instance& message, |
929 bool paused, | 958 bool paused); |
930 bool checked); | |
931 IsolateSpawnState(Dart_Port parent_port, | 959 IsolateSpawnState(Dart_Port parent_port, |
932 const char* script_url, | 960 const char* script_url, |
933 const char* package_root, | 961 const char* package_root, |
934 const Instance& args, | 962 const Instance& args, |
935 const Instance& message, | 963 const Instance& message, |
936 bool paused, | 964 bool paused); |
937 bool checked); | |
938 ~IsolateSpawnState(); | 965 ~IsolateSpawnState(); |
939 | 966 |
940 Isolate* isolate() const { return isolate_; } | 967 Isolate* isolate() const { return isolate_; } |
941 void set_isolate(Isolate* value) { isolate_ = value; } | 968 void set_isolate(Isolate* value) { isolate_ = value; } |
942 | 969 |
943 Dart_Port parent_port() const { return parent_port_; } | 970 Dart_Port parent_port() const { return parent_port_; } |
944 char* script_url() const { return script_url_; } | 971 char* script_url() const { return script_url_; } |
945 char* package_root() const { return package_root_; } | 972 char* package_root() const { return package_root_; } |
946 char* library_url() const { return library_url_; } | 973 char* library_url() const { return library_url_; } |
947 char* class_name() const { return class_name_; } | 974 char* class_name() const { return class_name_; } |
948 char* function_name() const { return function_name_; } | 975 char* function_name() const { return function_name_; } |
949 bool is_spawn_uri() const { return library_url_ == NULL; } | 976 bool is_spawn_uri() const { return library_url_ == NULL; } |
950 bool paused() const { return paused_; } | 977 bool paused() const { return paused_; } |
951 bool checked_mode() const { return checked_; } | 978 Isolate::Flags* isolate_flags() { return &isolate_flags_; } |
952 | 979 |
953 RawObject* ResolveFunction(); | 980 RawObject* ResolveFunction(); |
954 RawInstance* BuildArgs(Zone* zone); | 981 RawInstance* BuildArgs(Zone* zone); |
955 RawInstance* BuildMessage(Zone* zone); | 982 RawInstance* BuildMessage(Zone* zone); |
956 void Cleanup(); | 983 void Cleanup(); |
957 | 984 |
958 private: | 985 private: |
959 Isolate* isolate_; | 986 Isolate* isolate_; |
960 Dart_Port parent_port_; | 987 Dart_Port parent_port_; |
961 char* script_url_; | 988 char* script_url_; |
962 char* package_root_; | 989 char* package_root_; |
963 char* library_url_; | 990 char* library_url_; |
964 char* class_name_; | 991 char* class_name_; |
965 char* function_name_; | 992 char* function_name_; |
966 uint8_t* serialized_args_; | 993 uint8_t* serialized_args_; |
967 intptr_t serialized_args_len_; | 994 intptr_t serialized_args_len_; |
968 uint8_t* serialized_message_; | 995 uint8_t* serialized_message_; |
969 intptr_t serialized_message_len_; | 996 intptr_t serialized_message_len_; |
997 Isolate::Flags isolate_flags_; | |
970 bool paused_; | 998 bool paused_; |
971 bool checked_; | |
972 }; | 999 }; |
973 | 1000 |
974 } // namespace dart | 1001 } // namespace dart |
975 | 1002 |
976 #endif // VM_ISOLATE_H_ | 1003 #endif // VM_ISOLATE_H_ |
OLD | NEW |