| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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/object.h" | 5 #include "vm/object.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 "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 Object* Object::null_object_ = NULL; | 94 Object* Object::null_object_ = NULL; |
| 95 Array* Object::null_array_ = NULL; | 95 Array* Object::null_array_ = NULL; |
| 96 String* Object::null_string_ = NULL; | 96 String* Object::null_string_ = NULL; |
| 97 Instance* Object::null_instance_ = NULL; | 97 Instance* Object::null_instance_ = NULL; |
| 98 TypeArguments* Object::null_type_arguments_ = NULL; | 98 TypeArguments* Object::null_type_arguments_ = NULL; |
| 99 Array* Object::empty_array_ = NULL; | 99 Array* Object::empty_array_ = NULL; |
| 100 Array* Object::zero_array_ = NULL; | 100 Array* Object::zero_array_ = NULL; |
| 101 PcDescriptors* Object::empty_descriptors_ = NULL; | 101 PcDescriptors* Object::empty_descriptors_ = NULL; |
| 102 LocalVarDescriptors* Object::empty_var_descriptors_ = NULL; | 102 LocalVarDescriptors* Object::empty_var_descriptors_ = NULL; |
| 103 ExceptionHandlers* Object::empty_exception_handlers_ = NULL; | 103 ExceptionHandlers* Object::empty_exception_handlers_ = NULL; |
| 104 Array* Object::extractor_parameter_types_ = NULL; |
| 105 Array* Object::extractor_parameter_names_ = NULL; |
| 104 Instance* Object::sentinel_ = NULL; | 106 Instance* Object::sentinel_ = NULL; |
| 105 Instance* Object::transition_sentinel_ = NULL; | 107 Instance* Object::transition_sentinel_ = NULL; |
| 106 Instance* Object::unknown_constant_ = NULL; | 108 Instance* Object::unknown_constant_ = NULL; |
| 107 Instance* Object::non_constant_ = NULL; | 109 Instance* Object::non_constant_ = NULL; |
| 108 Bool* Object::bool_true_ = NULL; | 110 Bool* Object::bool_true_ = NULL; |
| 109 Bool* Object::bool_false_ = NULL; | 111 Bool* Object::bool_false_ = NULL; |
| 110 Smi* Object::smi_illegal_cid_ = NULL; | 112 Smi* Object::smi_illegal_cid_ = NULL; |
| 111 LanguageError* Object::snapshot_writer_error_ = NULL; | 113 LanguageError* Object::snapshot_writer_error_ = NULL; |
| 112 LanguageError* Object::branch_offset_error_ = NULL; | 114 LanguageError* Object::branch_offset_error_ = NULL; |
| 113 | 115 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 } else if (value == '\\') { | 444 } else if (value == '\\') { |
| 443 return '\\'; | 445 return '\\'; |
| 444 } else if (value == '$') { | 446 } else if (value == '$') { |
| 445 return '$'; | 447 return '$'; |
| 446 } | 448 } |
| 447 UNREACHABLE(); | 449 UNREACHABLE(); |
| 448 return '\0'; | 450 return '\0'; |
| 449 } | 451 } |
| 450 | 452 |
| 451 | 453 |
| 452 void Object::InitOnce() { | 454 void Object::InitOnce(Isolate* isolate) { |
| 455 // Should only be run by the vm isolate. |
| 456 ASSERT(isolate == Dart::vm_isolate()); |
| 457 |
| 453 // TODO(iposva): NoGCScope needs to be added here. | 458 // TODO(iposva): NoGCScope needs to be added here. |
| 454 ASSERT(class_class() == null_); | 459 ASSERT(class_class() == null_); |
| 455 // Initialize the static vtable values. | 460 // Initialize the static vtable values. |
| 456 { | 461 { |
| 457 Object fake_object; | 462 Object fake_object; |
| 458 Smi fake_smi; | 463 Smi fake_smi; |
| 459 Object::handle_vtable_ = fake_object.vtable(); | 464 Object::handle_vtable_ = fake_object.vtable(); |
| 460 Smi::handle_vtable_ = fake_smi.vtable(); | 465 Smi::handle_vtable_ = fake_smi.vtable(); |
| 461 } | 466 } |
| 462 | 467 |
| 463 Isolate* isolate = Isolate::Current(); | |
| 464 Heap* heap = isolate->heap(); | 468 Heap* heap = isolate->heap(); |
| 465 | 469 |
| 466 // Allocate the read only object handles here. | 470 // Allocate the read only object handles here. |
| 467 null_object_ = Object::ReadOnlyHandle(); | 471 null_object_ = Object::ReadOnlyHandle(); |
| 468 null_array_ = Array::ReadOnlyHandle(); | 472 null_array_ = Array::ReadOnlyHandle(); |
| 469 null_string_ = String::ReadOnlyHandle(); | 473 null_string_ = String::ReadOnlyHandle(); |
| 470 null_instance_ = Instance::ReadOnlyHandle(); | 474 null_instance_ = Instance::ReadOnlyHandle(); |
| 471 null_type_arguments_ = TypeArguments::ReadOnlyHandle(); | 475 null_type_arguments_ = TypeArguments::ReadOnlyHandle(); |
| 472 empty_array_ = Array::ReadOnlyHandle(); | 476 empty_array_ = Array::ReadOnlyHandle(); |
| 473 zero_array_ = Array::ReadOnlyHandle(); | 477 zero_array_ = Array::ReadOnlyHandle(); |
| 474 empty_descriptors_ = PcDescriptors::ReadOnlyHandle(); | 478 empty_descriptors_ = PcDescriptors::ReadOnlyHandle(); |
| 475 empty_var_descriptors_ = LocalVarDescriptors::ReadOnlyHandle(); | 479 empty_var_descriptors_ = LocalVarDescriptors::ReadOnlyHandle(); |
| 476 empty_exception_handlers_ = ExceptionHandlers::ReadOnlyHandle(); | 480 empty_exception_handlers_ = ExceptionHandlers::ReadOnlyHandle(); |
| 481 extractor_parameter_types_ = Array::ReadOnlyHandle(); |
| 482 extractor_parameter_names_ = Array::ReadOnlyHandle(); |
| 477 sentinel_ = Instance::ReadOnlyHandle(); | 483 sentinel_ = Instance::ReadOnlyHandle(); |
| 478 transition_sentinel_ = Instance::ReadOnlyHandle(); | 484 transition_sentinel_ = Instance::ReadOnlyHandle(); |
| 479 unknown_constant_ = Instance::ReadOnlyHandle(); | 485 unknown_constant_ = Instance::ReadOnlyHandle(); |
| 480 non_constant_ = Instance::ReadOnlyHandle(); | 486 non_constant_ = Instance::ReadOnlyHandle(); |
| 481 bool_true_ = Bool::ReadOnlyHandle(); | 487 bool_true_ = Bool::ReadOnlyHandle(); |
| 482 bool_false_ = Bool::ReadOnlyHandle(); | 488 bool_false_ = Bool::ReadOnlyHandle(); |
| 483 smi_illegal_cid_ = Smi::ReadOnlyHandle(); | 489 smi_illegal_cid_ = Smi::ReadOnlyHandle(); |
| 484 snapshot_writer_error_ = LanguageError::ReadOnlyHandle(); | 490 snapshot_writer_error_ = LanguageError::ReadOnlyHandle(); |
| 485 branch_offset_error_ = LanguageError::ReadOnlyHandle(); | 491 branch_offset_error_ = LanguageError::ReadOnlyHandle(); |
| 486 | 492 |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 ASSERT(!null_string_->IsSmi()); | 792 ASSERT(!null_string_->IsSmi()); |
| 787 ASSERT(null_string_->IsString()); | 793 ASSERT(null_string_->IsString()); |
| 788 ASSERT(!null_instance_->IsSmi()); | 794 ASSERT(!null_instance_->IsSmi()); |
| 789 ASSERT(null_instance_->IsInstance()); | 795 ASSERT(null_instance_->IsInstance()); |
| 790 ASSERT(!null_type_arguments_->IsSmi()); | 796 ASSERT(!null_type_arguments_->IsSmi()); |
| 791 ASSERT(null_type_arguments_->IsTypeArguments()); | 797 ASSERT(null_type_arguments_->IsTypeArguments()); |
| 792 ASSERT(!empty_array_->IsSmi()); | 798 ASSERT(!empty_array_->IsSmi()); |
| 793 ASSERT(empty_array_->IsArray()); | 799 ASSERT(empty_array_->IsArray()); |
| 794 ASSERT(!zero_array_->IsSmi()); | 800 ASSERT(!zero_array_->IsSmi()); |
| 795 ASSERT(zero_array_->IsArray()); | 801 ASSERT(zero_array_->IsArray()); |
| 802 ASSERT(!empty_descriptors_->IsSmi()); |
| 803 ASSERT(empty_descriptors_->IsPcDescriptors()); |
| 804 ASSERT(!empty_var_descriptors_->IsSmi()); |
| 805 ASSERT(empty_var_descriptors_->IsLocalVarDescriptors()); |
| 806 ASSERT(!empty_exception_handlers_->IsSmi()); |
| 807 ASSERT(empty_exception_handlers_->IsExceptionHandlers()); |
| 796 ASSERT(!sentinel_->IsSmi()); | 808 ASSERT(!sentinel_->IsSmi()); |
| 797 ASSERT(sentinel_->IsInstance()); | 809 ASSERT(sentinel_->IsInstance()); |
| 798 ASSERT(!transition_sentinel_->IsSmi()); | 810 ASSERT(!transition_sentinel_->IsSmi()); |
| 799 ASSERT(transition_sentinel_->IsInstance()); | 811 ASSERT(transition_sentinel_->IsInstance()); |
| 800 ASSERT(!unknown_constant_->IsSmi()); | 812 ASSERT(!unknown_constant_->IsSmi()); |
| 801 ASSERT(unknown_constant_->IsInstance()); | 813 ASSERT(unknown_constant_->IsInstance()); |
| 802 ASSERT(!non_constant_->IsSmi()); | 814 ASSERT(!non_constant_->IsSmi()); |
| 803 ASSERT(non_constant_->IsInstance()); | 815 ASSERT(non_constant_->IsInstance()); |
| 804 ASSERT(!bool_true_->IsSmi()); | 816 ASSERT(!bool_true_->IsSmi()); |
| 805 ASSERT(bool_true_->IsBool()); | 817 ASSERT(bool_true_->IsBool()); |
| 806 ASSERT(!bool_false_->IsSmi()); | 818 ASSERT(!bool_false_->IsSmi()); |
| 807 ASSERT(bool_false_->IsBool()); | 819 ASSERT(bool_false_->IsBool()); |
| 808 ASSERT(smi_illegal_cid_->IsSmi()); | 820 ASSERT(smi_illegal_cid_->IsSmi()); |
| 809 ASSERT(!snapshot_writer_error_->IsSmi()); | 821 ASSERT(!snapshot_writer_error_->IsSmi()); |
| 810 ASSERT(snapshot_writer_error_->IsLanguageError()); | 822 ASSERT(snapshot_writer_error_->IsLanguageError()); |
| 811 ASSERT(!branch_offset_error_->IsSmi()); | 823 ASSERT(!branch_offset_error_->IsSmi()); |
| 812 ASSERT(branch_offset_error_->IsLanguageError()); | 824 ASSERT(branch_offset_error_->IsLanguageError()); |
| 813 } | 825 } |
| 814 | 826 |
| 815 | 827 |
| 828 // An object visitor which will mark all visited objects. This is used to |
| 829 // premark all objects in the vm_isolate_ heap. |
| 830 class PremarkingVisitor : public ObjectVisitor { |
| 831 public: |
| 832 explicit PremarkingVisitor(Isolate* isolate) : ObjectVisitor(isolate) {} |
| 833 |
| 834 void VisitObject(RawObject* obj) { |
| 835 // RawInstruction objects are premarked on allocation. |
| 836 if (!obj->IsMarked()) { |
| 837 obj->SetMarkBit(); |
| 838 } |
| 839 } |
| 840 }; |
| 841 |
| 842 |
| 816 #define SET_CLASS_NAME(class_name, name) \ | 843 #define SET_CLASS_NAME(class_name, name) \ |
| 817 cls = class_name##_class(); \ | 844 cls = class_name##_class(); \ |
| 818 cls.set_name(Symbols::name()); \ | 845 cls.set_name(Symbols::name()); \ |
| 819 | 846 |
| 820 void Object::RegisterSingletonClassNames() { | 847 void Object::FinalizeVMIsolate(Isolate* isolate) { |
| 821 Class& cls = Class::Handle(); | 848 // Should only be run by the vm isolate. |
| 849 ASSERT(isolate == Dart::vm_isolate()); |
| 850 |
| 851 // Allocate the parameter arrays for method extractor types and names. |
| 852 *extractor_parameter_types_ = Array::New(1, Heap::kOld); |
| 853 extractor_parameter_types_->SetAt(0, Type::Handle(Type::DynamicType())); |
| 854 *extractor_parameter_names_ = Array::New(1, Heap::kOld); |
| 855 extractor_parameter_names_->SetAt(0, Symbols::This()); |
| 856 |
| 857 ASSERT(!extractor_parameter_types_->IsSmi()); |
| 858 ASSERT(extractor_parameter_types_->IsArray()); |
| 859 ASSERT(!extractor_parameter_names_->IsSmi()); |
| 860 ASSERT(extractor_parameter_names_->IsArray()); |
| 861 |
| 822 | 862 |
| 823 // Set up names for all VM singleton classes. | 863 // Set up names for all VM singleton classes. |
| 864 Class& cls = Class::Handle(isolate); |
| 865 |
| 824 SET_CLASS_NAME(class, Class); | 866 SET_CLASS_NAME(class, Class); |
| 825 SET_CLASS_NAME(dynamic, Dynamic); | 867 SET_CLASS_NAME(dynamic, Dynamic); |
| 826 SET_CLASS_NAME(void, Void); | 868 SET_CLASS_NAME(void, Void); |
| 827 SET_CLASS_NAME(unresolved_class, UnresolvedClass); | 869 SET_CLASS_NAME(unresolved_class, UnresolvedClass); |
| 828 SET_CLASS_NAME(type_arguments, TypeArguments); | 870 SET_CLASS_NAME(type_arguments, TypeArguments); |
| 829 SET_CLASS_NAME(patch_class, PatchClass); | 871 SET_CLASS_NAME(patch_class, PatchClass); |
| 830 SET_CLASS_NAME(function, Function); | 872 SET_CLASS_NAME(function, Function); |
| 831 SET_CLASS_NAME(closure_data, ClosureData); | 873 SET_CLASS_NAME(closure_data, ClosureData); |
| 832 SET_CLASS_NAME(redirection_data, RedirectionData); | 874 SET_CLASS_NAME(redirection_data, RedirectionData); |
| 833 SET_CLASS_NAME(field, Field); | 875 SET_CLASS_NAME(field, Field); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 848 SET_CLASS_NAME(icdata, ICData); | 890 SET_CLASS_NAME(icdata, ICData); |
| 849 SET_CLASS_NAME(megamorphic_cache, MegamorphicCache); | 891 SET_CLASS_NAME(megamorphic_cache, MegamorphicCache); |
| 850 SET_CLASS_NAME(subtypetestcache, SubtypeTestCache); | 892 SET_CLASS_NAME(subtypetestcache, SubtypeTestCache); |
| 851 SET_CLASS_NAME(api_error, ApiError); | 893 SET_CLASS_NAME(api_error, ApiError); |
| 852 SET_CLASS_NAME(language_error, LanguageError); | 894 SET_CLASS_NAME(language_error, LanguageError); |
| 853 SET_CLASS_NAME(unhandled_exception, UnhandledException); | 895 SET_CLASS_NAME(unhandled_exception, UnhandledException); |
| 854 SET_CLASS_NAME(unwind_error, UnwindError); | 896 SET_CLASS_NAME(unwind_error, UnwindError); |
| 855 | 897 |
| 856 // Set up names for object array and one byte string class which are | 898 // Set up names for object array and one byte string class which are |
| 857 // pre-allocated in the vm isolate also. | 899 // pre-allocated in the vm isolate also. |
| 858 cls = Dart::vm_isolate()->object_store()->array_class(); | 900 cls = isolate->object_store()->array_class(); |
| 859 cls.set_name(Symbols::_List()); | 901 cls.set_name(Symbols::_List()); |
| 860 cls = Dart::vm_isolate()->object_store()->one_byte_string_class(); | 902 cls = isolate->object_store()->one_byte_string_class(); |
| 861 cls.set_name(Symbols::OneByteString()); | 903 cls.set_name(Symbols::OneByteString()); |
| 904 |
| 905 // Make the VM isolate read-only after setting all objects as marked. |
| 906 PremarkingVisitor premarker(isolate); |
| 907 isolate->heap()->WriteProtect(false); |
| 908 ASSERT(isolate->heap()->UsedInWords(Heap::kNew) == 0); |
| 909 isolate->heap()->IterateOldObjects(&premarker); |
| 910 isolate->heap()->WriteProtect(true); |
| 862 } | 911 } |
| 863 | 912 |
| 864 | 913 |
| 865 // Make unused space in an object whose type has been transformed safe | 914 // Make unused space in an object whose type has been transformed safe |
| 866 // for traversing during GC. | 915 // for traversing during GC. |
| 867 // The unused part of the transformed object is marked as an TypedDataInt8Array | 916 // The unused part of the transformed object is marked as an TypedDataInt8Array |
| 868 // object. | 917 // object. |
| 869 void Object::MakeUnusedSpaceTraversable(const Object& obj, | 918 void Object::MakeUnusedSpaceTraversable(const Object& obj, |
| 870 intptr_t original_size, | 919 intptr_t original_size, |
| 871 intptr_t used_size) { | 920 intptr_t used_size) { |
| (...skipping 19395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20267 return tag_label.ToCString(); | 20316 return tag_label.ToCString(); |
| 20268 } | 20317 } |
| 20269 | 20318 |
| 20270 | 20319 |
| 20271 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20320 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 20272 Instance::PrintJSONImpl(stream, ref); | 20321 Instance::PrintJSONImpl(stream, ref); |
| 20273 } | 20322 } |
| 20274 | 20323 |
| 20275 | 20324 |
| 20276 } // namespace dart | 20325 } // namespace dart |
| OLD | NEW |