Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: runtime/vm/isolate.cc

Issue 1162033005: Fix http://dartbug.com/23578: (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Update to ToT. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "vm/isolate.h" 5 #include "vm/isolate.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "platform/json.h" 9 #include "platform/json.h"
10 #include "vm/code_observers.h" 10 #include "vm/code_observers.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 "Pause isolates before starting."); 47 "Pause isolates before starting.");
48 DEFINE_FLAG(bool, pause_isolates_on_exit, false, 48 DEFINE_FLAG(bool, pause_isolates_on_exit, false,
49 "Pause isolates exiting."); 49 "Pause isolates exiting.");
50 DEFINE_FLAG(bool, break_at_isolate_spawn, false, 50 DEFINE_FLAG(bool, break_at_isolate_spawn, false,
51 "Insert a one-time breakpoint at the entrypoint for all spawned " 51 "Insert a one-time breakpoint at the entrypoint for all spawned "
52 "isolates"); 52 "isolates");
53 DEFINE_FLAG(charp, isolate_log_filter, NULL, 53 DEFINE_FLAG(charp, isolate_log_filter, NULL,
54 "Log isolates whose name include the filter. " 54 "Log isolates whose name include the filter. "
55 "Default: service isolate log messages are suppressed."); 55 "Default: service isolate log messages are suppressed.");
56 56
57 // TODO(iposva): Make these isolate specific flags inaccessible using the
58 // regular FLAG_xyz pattern.
59 // These flags are per-isolate and only influence the defaults.
60 DEFINE_FLAG(bool, enable_asserts, false, "Enable assert statements.");
61 DEFINE_FLAG(bool, enable_type_checks, false, "Enable type checks.");
62 DEFINE_FLAG(bool, error_on_bad_override, false,
63 "Report error for bad overrides.");
64 DEFINE_FLAG(bool, error_on_bad_type, false,
65 "Report error for malformed types.");
66
67 static void CheckedModeHandler(bool value) {
68 FLAG_enable_asserts = value;
69 FLAG_enable_type_checks = value;
70 }
71
72 // --enable-checked-mode and --checked both enable checked mode which is
73 // equivalent to setting --enable-asserts and --enable-type-checks.
74 DEFINE_FLAG_HANDLER(CheckedModeHandler,
75 enable_checked_mode,
76 "Enable checked mode.");
77
78 DEFINE_FLAG_HANDLER(CheckedModeHandler,
79 checked,
80 "Enable checked mode.");
81
82
57 // Quick access to the locally defined isolate() method. 83 // Quick access to the locally defined isolate() method.
58 #define I (isolate()) 84 #define I (isolate())
59 85
60 #if defined(DEBUG) 86 #if defined(DEBUG)
61 // Helper class to ensure that a live origin_id is never reused 87 // Helper class to ensure that a live origin_id is never reused
62 // and assigned to an isolate. 88 // and assigned to an isolate.
63 class VerifyOriginId : public IsolateVisitor { 89 class VerifyOriginId : public IsolateVisitor {
64 public: 90 public:
65 explicit VerifyOriginId(Dart_Port id) : id_(id) {} 91 explicit VerifyOriginId(Dart_Port id) : id_(id) {}
66 92
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 I->NotifyErrorListeners(exc_str, stacktrace_str); 555 I->NotifyErrorListeners(exc_str, stacktrace_str);
530 556
531 if (I->ErrorsFatal()) { 557 if (I->ErrorsFatal()) {
532 I->object_store()->set_sticky_error(result); 558 I->object_store()->set_sticky_error(result);
533 return false; 559 return false;
534 } 560 }
535 return true; 561 return true;
536 } 562 }
537 563
538 564
565 Isolate::Flags::Flags()
566 : type_checks_(FLAG_enable_type_checks),
567 asserts_(FLAG_enable_asserts),
568 error_on_bad_type_(FLAG_error_on_bad_type),
569 error_on_bad_override_(FLAG_error_on_bad_override) {}
570
571
572 void Isolate::Flags::CopyFrom(const Flags& orig) {
573 type_checks_ = orig.type_checks();
574 asserts_ = orig.asserts();
575 error_on_bad_type_ = orig.error_on_bad_type();
576 error_on_bad_override_ = orig.error_on_bad_override();
577 }
578
579
580 void Isolate::Flags::CopyFrom(const Dart_IsolateFlags& api_flags) {
581 type_checks_ = api_flags.enable_type_checks;
582 asserts_ = api_flags.enable_asserts;
583 // Leave others at defaults.
584 }
585
586
587 void Isolate::Flags::CopyTo(Dart_IsolateFlags* api_flags) const {
588 api_flags->version = DART_FLAGS_CURRENT_VERSION;
589 api_flags->enable_type_checks = type_checks();
590 api_flags->enable_asserts = asserts();
591 }
592
593
539 #if defined(DEBUG) 594 #if defined(DEBUG)
540 // static 595 // static
541 void BaseIsolate::AssertCurrent(BaseIsolate* isolate) { 596 void BaseIsolate::AssertCurrent(BaseIsolate* isolate) {
542 ASSERT(isolate == Isolate::Current()); 597 ASSERT(isolate == Isolate::Current());
543 } 598 }
544 #endif // defined(DEBUG) 599 #endif // defined(DEBUG)
545 600
546 #if defined(DEBUG) 601 #if defined(DEBUG)
547 #define REUSABLE_HANDLE_SCOPE_INIT(object) \ 602 #define REUSABLE_HANDLE_SCOPE_INIT(object) \
548 reusable_##object##_handle_scope_active_(false), 603 reusable_##object##_handle_scope_active_(false),
549 #else 604 #else
550 #define REUSABLE_HANDLE_SCOPE_INIT(object) 605 #define REUSABLE_HANDLE_SCOPE_INIT(object)
551 #endif // defined(DEBUG) 606 #endif // defined(DEBUG)
552 607
553 #define REUSABLE_HANDLE_INITIALIZERS(object) \ 608 #define REUSABLE_HANDLE_INITIALIZERS(object) \
554 object##_handle_(NULL), 609 object##_handle_(NULL),
555 610
556 Isolate::Isolate() 611 Isolate::Isolate(const Dart_IsolateFlags& api_flags)
557 : mutator_thread_(NULL), 612 : mutator_thread_(NULL),
558 vm_tag_(0), 613 vm_tag_(0),
559 store_buffer_(), 614 store_buffer_(),
560 message_notify_callback_(NULL), 615 message_notify_callback_(NULL),
561 name_(NULL), 616 name_(NULL),
562 debugger_name_(NULL), 617 debugger_name_(NULL),
563 start_time_(OS::GetCurrentTimeMicros()), 618 start_time_(OS::GetCurrentTimeMicros()),
564 main_port_(0), 619 main_port_(0),
565 origin_id_(0), 620 origin_id_(0),
566 pause_capability_(0), 621 pause_capability_(0),
567 terminate_capability_(0), 622 terminate_capability_(0),
568 errors_fatal_(true), 623 errors_fatal_(true),
569 heap_(NULL), 624 heap_(NULL),
570 object_store_(NULL), 625 object_store_(NULL),
571 top_exit_frame_info_(0), 626 top_exit_frame_info_(0),
572 init_callback_data_(NULL), 627 init_callback_data_(NULL),
573 environment_callback_(NULL), 628 environment_callback_(NULL),
574 library_tag_handler_(NULL), 629 library_tag_handler_(NULL),
575 api_state_(NULL), 630 api_state_(NULL),
576 stub_code_(NULL), 631 stub_code_(NULL),
577 debugger_(NULL), 632 debugger_(NULL),
578 single_step_(false), 633 single_step_(false),
579 resume_request_(false), 634 resume_request_(false),
580 has_compiled_(false), 635 has_compiled_(false),
581 strict_compilation_(false), 636 flags_(),
Florian Schneider 2015/06/08 11:25:49 flags_(api_flags) and remove .CopyFrom below
582 random_(), 637 random_(),
583 simulator_(NULL), 638 simulator_(NULL),
584 long_jump_base_(NULL), 639 long_jump_base_(NULL),
585 timer_list_(), 640 timer_list_(),
586 deopt_id_(0), 641 deopt_id_(0),
587 mutex_(new Mutex()), 642 mutex_(new Mutex()),
588 stack_limit_(0), 643 stack_limit_(0),
589 saved_stack_limit_(0), 644 saved_stack_limit_(0),
590 stack_base_(0), 645 stack_base_(0),
591 stack_overflow_flags_(0), 646 stack_overflow_flags_(0),
(...skipping 21 matching lines...) Expand all
613 current_tag_(UserTag::null()), 668 current_tag_(UserTag::null()),
614 default_tag_(UserTag::null()), 669 default_tag_(UserTag::null()),
615 deoptimized_code_array_(GrowableObjectArray::null()), 670 deoptimized_code_array_(GrowableObjectArray::null()),
616 metrics_list_head_(NULL), 671 metrics_list_head_(NULL),
617 cha_(NULL), 672 cha_(NULL),
618 next_(NULL), 673 next_(NULL),
619 pause_loop_monitor_(NULL), 674 pause_loop_monitor_(NULL),
620 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_INITIALIZERS) 675 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_INITIALIZERS)
621 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_SCOPE_INIT) 676 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_SCOPE_INIT)
622 reusable_handles_() { 677 reusable_handles_() {
678 flags_.CopyFrom(api_flags);
623 set_vm_tag(VMTag::kEmbedderTagId); 679 set_vm_tag(VMTag::kEmbedderTagId);
624 set_user_tag(UserTags::kDefaultUserTag); 680 set_user_tag(UserTags::kDefaultUserTag);
625 } 681 }
626 682
627 #undef REUSABLE_HANDLE_SCOPE_INIT 683 #undef REUSABLE_HANDLE_SCOPE_INIT
628 #undef REUSABLE_HANDLE_INITIALIZERS 684 #undef REUSABLE_HANDLE_INITIALIZERS
629 685
630 Isolate::~Isolate() { 686 Isolate::~Isolate() {
631 free(name_); 687 free(name_);
632 free(debugger_name_); 688 free(debugger_name_);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 #endif // DEBUG 720 #endif // DEBUG
665 721
666 722
667 void Isolate::InitOnce() { 723 void Isolate::InitOnce() {
668 create_callback_ = NULL; 724 create_callback_ = NULL;
669 isolates_list_monitor_ = new Monitor(); 725 isolates_list_monitor_ = new Monitor();
670 ASSERT(isolates_list_monitor_ != NULL); 726 ASSERT(isolates_list_monitor_ != NULL);
671 } 727 }
672 728
673 729
674 Isolate* Isolate::Init(const char* name_prefix, bool is_vm_isolate) { 730 Isolate* Isolate::Init(const char* name_prefix,
675 Isolate* result = new Isolate(); 731 const Dart_IsolateFlags& api_flags,
732 bool is_vm_isolate) {
733 Isolate* result = new Isolate(api_flags);
676 ASSERT(result != NULL); 734 ASSERT(result != NULL);
677 735
678 // Initialize metrics. 736 // Initialize metrics.
679 #define ISOLATE_METRIC_INIT(type, variable, name, unit) \ 737 #define ISOLATE_METRIC_INIT(type, variable, name, unit) \
680 result->metric_##variable##_.Init(result, name, NULL, Metric::unit); 738 result->metric_##variable##_.Init(result, name, NULL, Metric::unit);
681 ISOLATE_METRIC_LIST(ISOLATE_METRIC_INIT); 739 ISOLATE_METRIC_LIST(ISOLATE_METRIC_INIT);
682 #undef ISOLATE_METRIC_INIT 740 #undef ISOLATE_METRIC_INIT
683 741
684 // TODO(5411455): For now just set the recently created isolate as 742 // TODO(5411455): For now just set the recently created isolate as
685 // the current isolate. 743 // the current isolate.
(...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1796 ASSERT(!obj.IsError()); 1854 ASSERT(!obj.IsError());
1797 Instance& instance = Instance::Handle(isolate); 1855 Instance& instance = Instance::Handle(isolate);
1798 instance ^= obj.raw(); // Can't use Instance::Cast because may be null. 1856 instance ^= obj.raw(); // Can't use Instance::Cast because may be null.
1799 return instance.raw(); 1857 return instance.raw();
1800 } 1858 }
1801 1859
1802 1860
1803 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port, 1861 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port,
1804 const Function& func, 1862 const Function& func,
1805 const Instance& message, 1863 const Instance& message,
1806 bool paused, 1864 bool paused)
1807 bool checkedFlag)
1808 : isolate_(NULL), 1865 : isolate_(NULL),
1809 parent_port_(parent_port), 1866 parent_port_(parent_port),
1810 script_url_(NULL), 1867 script_url_(NULL),
1811 package_root_(NULL), 1868 package_root_(NULL),
1812 library_url_(NULL), 1869 library_url_(NULL),
1813 class_name_(NULL), 1870 class_name_(NULL),
1814 function_name_(NULL), 1871 function_name_(NULL),
1815 serialized_args_(NULL), 1872 serialized_args_(NULL),
1816 serialized_args_len_(0), 1873 serialized_args_len_(0),
1817 serialized_message_(NULL), 1874 serialized_message_(NULL),
1818 serialized_message_len_(0), 1875 serialized_message_len_(0),
1819 paused_(paused), 1876 isolate_flags_(),
Florian Schneider 2015/06/08 11:25:49 isolate(Isolate::Current()->flags()) and remove ->
1820 checked_(checkedFlag) { 1877 paused_(paused) {
1821 script_url_ = NULL; 1878 script_url_ = NULL;
1822 const Class& cls = Class::Handle(func.Owner()); 1879 const Class& cls = Class::Handle(func.Owner());
1823 const Library& lib = Library::Handle(cls.library()); 1880 const Library& lib = Library::Handle(cls.library());
1824 const String& lib_url = String::Handle(lib.url()); 1881 const String& lib_url = String::Handle(lib.url());
1825 library_url_ = strdup(lib_url.ToCString()); 1882 library_url_ = strdup(lib_url.ToCString());
1826 1883
1827 const String& func_name = String::Handle(func.name()); 1884 const String& func_name = String::Handle(func.name());
1828 function_name_ = strdup(func_name.ToCString()); 1885 function_name_ = strdup(func_name.ToCString());
1829 if (!cls.IsTopLevel()) { 1886 if (!cls.IsTopLevel()) {
1830 const String& class_name = String::Handle(cls.Name()); 1887 const String& class_name = String::Handle(cls.Name());
1831 class_name_ = strdup(class_name.ToCString()); 1888 class_name_ = strdup(class_name.ToCString());
1832 } 1889 }
1833 bool can_send_any_object = true; 1890 bool can_send_any_object = true;
1834 SerializeObject(message, 1891 SerializeObject(message,
1835 &serialized_message_, 1892 &serialized_message_,
1836 &serialized_message_len_, 1893 &serialized_message_len_,
1837 can_send_any_object); 1894 can_send_any_object);
1895 // Inherit flags from spawning isolate.
1896 isolate_flags()->CopyFrom(Isolate::Current()->flags());
1838 } 1897 }
1839 1898
1840 1899
1841 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port, 1900 IsolateSpawnState::IsolateSpawnState(Dart_Port parent_port,
1842 const char* script_url, 1901 const char* script_url,
1843 const char* package_root, 1902 const char* package_root,
1844 const Instance& args, 1903 const Instance& args,
1845 const Instance& message, 1904 const Instance& message,
1846 bool paused, 1905 bool paused)
1847 bool checkedFlag)
1848 : isolate_(NULL), 1906 : isolate_(NULL),
1849 parent_port_(parent_port), 1907 parent_port_(parent_port),
1850 package_root_(NULL), 1908 package_root_(NULL),
1851 library_url_(NULL), 1909 library_url_(NULL),
1852 class_name_(NULL), 1910 class_name_(NULL),
1853 function_name_(NULL), 1911 function_name_(NULL),
1854 serialized_args_(NULL), 1912 serialized_args_(NULL),
1855 serialized_args_len_(0), 1913 serialized_args_len_(0),
1856 serialized_message_(NULL), 1914 serialized_message_(NULL),
1857 serialized_message_len_(0), 1915 serialized_message_len_(0),
1858 paused_(paused), 1916 isolate_flags_(),
Florian Schneider 2015/06/08 11:25:49 isolate_flags_(Isolate::Current()->flags()) and r
1859 checked_(checkedFlag) { 1917 paused_(paused) {
1860 script_url_ = strdup(script_url); 1918 script_url_ = strdup(script_url);
1861 if (package_root != NULL) { 1919 if (package_root != NULL) {
1862 package_root_ = strdup(package_root); 1920 package_root_ = strdup(package_root);
1863 } 1921 }
1864 library_url_ = NULL; 1922 library_url_ = NULL;
1865 function_name_ = strdup("main"); 1923 function_name_ = strdup("main");
1866 bool can_send_any_object = false; 1924 bool can_send_any_object = false;
1867 SerializeObject(args, 1925 SerializeObject(args,
1868 &serialized_args_, 1926 &serialized_args_,
1869 &serialized_args_len_, 1927 &serialized_args_len_,
1870 can_send_any_object); 1928 can_send_any_object);
1871 SerializeObject(message, 1929 SerializeObject(message,
1872 &serialized_message_, 1930 &serialized_message_,
1873 &serialized_message_len_, 1931 &serialized_message_len_,
1874 can_send_any_object); 1932 can_send_any_object);
1933 // By default inherit flags from spawning isolate. These can be overridden
1934 // from the calling code.
1935 isolate_flags()->CopyFrom(Isolate::Current()->flags());
1875 } 1936 }
1876 1937
1877 1938
1878 IsolateSpawnState::~IsolateSpawnState() { 1939 IsolateSpawnState::~IsolateSpawnState() {
1879 free(script_url_); 1940 free(script_url_);
1880 free(package_root_); 1941 free(package_root_);
1881 free(library_url_); 1942 free(library_url_);
1882 free(function_name_); 1943 free(function_name_);
1883 free(class_name_); 1944 free(class_name_);
1884 free(serialized_args_); 1945 free(serialized_args_);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1965 serialized_message_, serialized_message_len_); 2026 serialized_message_, serialized_message_len_);
1966 } 2027 }
1967 2028
1968 2029
1969 void IsolateSpawnState::Cleanup() { 2030 void IsolateSpawnState::Cleanup() {
1970 SwitchIsolateScope switch_scope(I); 2031 SwitchIsolateScope switch_scope(I);
1971 Dart::ShutdownIsolate(); 2032 Dart::ShutdownIsolate();
1972 } 2033 }
1973 2034
1974 } // namespace dart 2035 } // namespace dart
OLDNEW
« runtime/vm/isolate.h ('K') | « runtime/vm/isolate.h ('k') | runtime/vm/isolate_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698