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 #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 "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/text_buffer.h" | 10 #include "platform/text_buffer.h" |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 } | 684 } |
685 } | 685 } |
686 #endif // !defined(PRODUCT) | 686 #endif // !defined(PRODUCT) |
687 return kError; | 687 return kError; |
688 } | 688 } |
689 } | 689 } |
690 return kOK; | 690 return kOK; |
691 } | 691 } |
692 | 692 |
693 void Isolate::FlagsInitialize(Dart_IsolateFlags* api_flags) { | 693 void Isolate::FlagsInitialize(Dart_IsolateFlags* api_flags) { |
| 694 const bool false_by_default = false; |
| 695 const bool true_by_default = true; |
| 696 USE(true_by_default); |
| 697 USE(false_by_default); |
| 698 |
694 api_flags->version = DART_FLAGS_CURRENT_VERSION; | 699 api_flags->version = DART_FLAGS_CURRENT_VERSION; |
695 #define INIT_FROM_FLAG(name, bitname, isolate_flag, flag) \ | 700 #define INIT_FROM_FLAG(when, name, bitname, isolate_flag, flag) \ |
696 api_flags->isolate_flag = flag; | 701 api_flags->isolate_flag = flag; |
697 ISOLATE_FLAG_LIST(INIT_FROM_FLAG) | 702 ISOLATE_FLAG_LIST(INIT_FROM_FLAG) |
698 #undef INIT_FROM_FLAG | 703 #undef INIT_FROM_FLAG |
699 api_flags->use_dart_frontend = false; | 704 api_flags->use_dart_frontend = false; |
| 705 api_flags->entry_points = NULL; |
700 } | 706 } |
701 | 707 |
702 void Isolate::FlagsCopyTo(Dart_IsolateFlags* api_flags) const { | 708 void Isolate::FlagsCopyTo(Dart_IsolateFlags* api_flags) const { |
703 api_flags->version = DART_FLAGS_CURRENT_VERSION; | 709 api_flags->version = DART_FLAGS_CURRENT_VERSION; |
704 #define INIT_FROM_FIELD(name, bitname, isolate_flag, flag) \ | 710 #define INIT_FROM_FIELD(when, name, bitname, isolate_flag, flag) \ |
705 api_flags->isolate_flag = name(); | 711 api_flags->isolate_flag = name(); |
706 ISOLATE_FLAG_LIST(INIT_FROM_FIELD) | 712 ISOLATE_FLAG_LIST(INIT_FROM_FIELD) |
707 #undef INIT_FROM_FIELD | 713 #undef INIT_FROM_FIELD |
708 api_flags->use_dart_frontend = use_dart_frontend(); | 714 api_flags->use_dart_frontend = use_dart_frontend(); |
| 715 api_flags->entry_points = NULL; |
709 } | 716 } |
710 | 717 |
711 void Isolate::FlagsCopyFrom(const Dart_IsolateFlags& api_flags) { | 718 void Isolate::FlagsCopyFrom(const Dart_IsolateFlags& api_flags) { |
| 719 #if defined(DART_PRECOMPILER) |
| 720 #define FLAG_FOR_PRECOMPILER(action) action |
| 721 #else |
| 722 #define FLAG_FOR_PRECOMPILER(action) |
| 723 #endif |
| 724 |
712 #if !defined(PRODUCT) | 725 #if !defined(PRODUCT) |
713 #define SET_FROM_FLAG(name, bitname, isolate_flag, flag) \ | 726 #define FLAG_FOR_NONPRODUCT(action) action |
714 isolate_flags_ = bitname##Bit::update(api_flags.isolate_flag, isolate_flags_); | 727 #else |
| 728 #define FLAG_FOR_NONPRODUCT(action) |
| 729 #endif |
| 730 |
| 731 #define SET_FROM_FLAG(when, name, bitname, isolate_flag, flag) \ |
| 732 FLAG_FOR_##when(isolate_flags_ = bitname##Bit::update( \ |
| 733 api_flags.isolate_flag, isolate_flags_)); |
| 734 |
715 ISOLATE_FLAG_LIST(SET_FROM_FLAG) | 735 ISOLATE_FLAG_LIST(SET_FROM_FLAG) |
| 736 |
| 737 #undef FLAG_FOR_NONPRODUCT |
| 738 #undef FLAG_FOR_PRECOMPILER |
716 #undef SET_FROM_FLAG | 739 #undef SET_FROM_FLAG |
717 #endif // !defined(PRODUCT) | 740 |
718 set_use_dart_frontend(api_flags.use_dart_frontend); | 741 set_use_dart_frontend(api_flags.use_dart_frontend); |
| 742 |
| 743 // Copy entry points list. |
| 744 ASSERT(embedder_entry_points_ == NULL); |
| 745 if (api_flags.entry_points != NULL) { |
| 746 intptr_t count = 0; |
| 747 while (api_flags.entry_points[count].function_name != NULL) |
| 748 count++; |
| 749 embedder_entry_points_ = new Dart_QualifiedFunctionName[count + 1]; |
| 750 for (intptr_t i = 0; i < count; i++) { |
| 751 embedder_entry_points_[i].library_uri = |
| 752 strdup(api_flags.entry_points[i].library_uri); |
| 753 embedder_entry_points_[i].class_name = |
| 754 strdup(api_flags.entry_points[i].class_name); |
| 755 embedder_entry_points_[i].function_name = |
| 756 strdup(api_flags.entry_points[i].function_name); |
| 757 } |
| 758 memset(&embedder_entry_points_[count], 0, |
| 759 sizeof(Dart_QualifiedFunctionName)); |
| 760 } |
| 761 |
719 // Leave others at defaults. | 762 // Leave others at defaults. |
720 } | 763 } |
721 | 764 |
722 #if defined(DEBUG) | 765 #if defined(DEBUG) |
723 // static | 766 // static |
724 void BaseIsolate::AssertCurrent(BaseIsolate* isolate) { | 767 void BaseIsolate::AssertCurrent(BaseIsolate* isolate) { |
725 ASSERT(isolate == Isolate::Current()); | 768 ASSERT(isolate == Isolate::Current()); |
726 } | 769 } |
727 | 770 |
728 void BaseIsolate::AssertCurrentThreadIsMutator() const { | 771 void BaseIsolate::AssertCurrentThreadIsMutator() const { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 deoptimized_code_array_(GrowableObjectArray::null()), | 851 deoptimized_code_array_(GrowableObjectArray::null()), |
809 sticky_error_(Error::null()), | 852 sticky_error_(Error::null()), |
810 next_(NULL), | 853 next_(NULL), |
811 loading_invalidation_gen_(kInvalidGen), | 854 loading_invalidation_gen_(kInvalidGen), |
812 top_level_parsing_count_(0), | 855 top_level_parsing_count_(0), |
813 field_list_mutex_(new Mutex()), | 856 field_list_mutex_(new Mutex()), |
814 boxed_field_list_(GrowableObjectArray::null()), | 857 boxed_field_list_(GrowableObjectArray::null()), |
815 spawn_count_monitor_(new Monitor()), | 858 spawn_count_monitor_(new Monitor()), |
816 spawn_count_(0), | 859 spawn_count_(0), |
817 handler_info_cache_(), | 860 handler_info_cache_(), |
818 catch_entry_state_cache_() { | 861 catch_entry_state_cache_(), |
| 862 embedder_entry_points_(NULL), |
| 863 obfuscation_map_(NULL) { |
819 FlagsCopyFrom(api_flags); | 864 FlagsCopyFrom(api_flags); |
820 SetErrorsFatal(true); | 865 SetErrorsFatal(true); |
821 set_compilation_allowed(true); | 866 set_compilation_allowed(true); |
822 // TODO(asiva): A Thread is not available here, need to figure out | 867 // TODO(asiva): A Thread is not available here, need to figure out |
823 // how the vm_tag (kEmbedderTagId) can be set, these tags need to | 868 // how the vm_tag (kEmbedderTagId) can be set, these tags need to |
824 // move to the OSThread structure. | 869 // move to the OSThread structure. |
825 set_user_tag(UserTags::kDefaultUserTag); | 870 set_user_tag(UserTags::kDefaultUserTag); |
| 871 |
| 872 if (obfuscate()) { |
| 873 OS::PrintErr( |
| 874 "Warning: This VM has been configured to obfuscate symbol information " |
| 875 "which violates the Dart standard.\n" |
| 876 " See dartbug.com/30524 for more information.\n"); |
| 877 } |
826 } | 878 } |
827 | 879 |
828 #undef REUSABLE_HANDLE_SCOPE_INIT | 880 #undef REUSABLE_HANDLE_SCOPE_INIT |
829 #undef REUSABLE_HANDLE_INITIALIZERS | 881 #undef REUSABLE_HANDLE_INITIALIZERS |
830 | 882 |
831 Isolate::~Isolate() { | 883 Isolate::~Isolate() { |
832 #if !defined(PRODUCT) | 884 #if !defined(PRODUCT) |
833 free(debugger_name_); | 885 free(debugger_name_); |
834 delete debugger_; | 886 delete debugger_; |
835 if (FLAG_support_service) { | 887 if (FLAG_support_service) { |
(...skipping 27 matching lines...) Expand all Loading... |
863 delete message_handler_; | 915 delete message_handler_; |
864 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate. | 916 message_handler_ = NULL; // Fail fast if we send messages to a dead isolate. |
865 ASSERT(deopt_context_ == NULL); // No deopt in progress when isolate deleted. | 917 ASSERT(deopt_context_ == NULL); // No deopt in progress when isolate deleted. |
866 delete spawn_state_; | 918 delete spawn_state_; |
867 delete field_list_mutex_; | 919 delete field_list_mutex_; |
868 field_list_mutex_ = NULL; | 920 field_list_mutex_ = NULL; |
869 ASSERT(spawn_count_ == 0); | 921 ASSERT(spawn_count_ == 0); |
870 delete spawn_count_monitor_; | 922 delete spawn_count_monitor_; |
871 delete safepoint_handler_; | 923 delete safepoint_handler_; |
872 delete thread_registry_; | 924 delete thread_registry_; |
| 925 |
| 926 if (obfuscation_map_ != NULL) { |
| 927 for (intptr_t i = 0; obfuscation_map_[i] != NULL; i++) { |
| 928 delete[] obfuscation_map_[i]; |
| 929 } |
| 930 delete[] obfuscation_map_; |
| 931 } |
| 932 |
| 933 if (embedder_entry_points_ != NULL) { |
| 934 for (intptr_t i = 0; embedder_entry_points_[i].function_name != NULL; i++) { |
| 935 free(const_cast<char*>(embedder_entry_points_[i].library_uri)); |
| 936 free(const_cast<char*>(embedder_entry_points_[i].class_name)); |
| 937 free(const_cast<char*>(embedder_entry_points_[i].function_name)); |
| 938 } |
| 939 delete[] embedder_entry_points_; |
| 940 } |
873 } | 941 } |
874 | 942 |
875 void Isolate::InitOnce() { | 943 void Isolate::InitOnce() { |
876 create_callback_ = NULL; | 944 create_callback_ = NULL; |
877 isolates_list_monitor_ = new Monitor(); | 945 isolates_list_monitor_ = new Monitor(); |
878 ASSERT(isolates_list_monitor_ != NULL); | 946 ASSERT(isolates_list_monitor_ != NULL); |
879 EnableIsolateCreation(); | 947 EnableIsolateCreation(); |
880 } | 948 } |
881 | 949 |
882 Isolate* Isolate::Init(const char* name_prefix, | 950 Isolate* Isolate::Init(const char* name_prefix, |
(...skipping 1949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2832 void IsolateSpawnState::DecrementSpawnCount() { | 2900 void IsolateSpawnState::DecrementSpawnCount() { |
2833 ASSERT(spawn_count_monitor_ != NULL); | 2901 ASSERT(spawn_count_monitor_ != NULL); |
2834 ASSERT(spawn_count_ != NULL); | 2902 ASSERT(spawn_count_ != NULL); |
2835 MonitorLocker ml(spawn_count_monitor_); | 2903 MonitorLocker ml(spawn_count_monitor_); |
2836 ASSERT(*spawn_count_ > 0); | 2904 ASSERT(*spawn_count_ > 0); |
2837 *spawn_count_ = *spawn_count_ - 1; | 2905 *spawn_count_ = *spawn_count_ - 1; |
2838 ml.Notify(); | 2906 ml.Notify(); |
2839 } | 2907 } |
2840 | 2908 |
2841 } // namespace dart | 2909 } // namespace dart |
OLD | NEW |