| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 Array* Object::extractor_parameter_names_ = NULL; | 102 Array* Object::extractor_parameter_names_ = NULL; |
| 103 Instance* Object::sentinel_ = NULL; | 103 Instance* Object::sentinel_ = NULL; |
| 104 Instance* Object::transition_sentinel_ = NULL; | 104 Instance* Object::transition_sentinel_ = NULL; |
| 105 Instance* Object::unknown_constant_ = NULL; | 105 Instance* Object::unknown_constant_ = NULL; |
| 106 Instance* Object::non_constant_ = NULL; | 106 Instance* Object::non_constant_ = NULL; |
| 107 Bool* Object::bool_true_ = NULL; | 107 Bool* Object::bool_true_ = NULL; |
| 108 Bool* Object::bool_false_ = NULL; | 108 Bool* Object::bool_false_ = NULL; |
| 109 Smi* Object::smi_illegal_cid_ = NULL; | 109 Smi* Object::smi_illegal_cid_ = NULL; |
| 110 LanguageError* Object::snapshot_writer_error_ = NULL; | 110 LanguageError* Object::snapshot_writer_error_ = NULL; |
| 111 LanguageError* Object::branch_offset_error_ = NULL; | 111 LanguageError* Object::branch_offset_error_ = NULL; |
| 112 Array* Object::vm_isolate_snapshot_object_table_ = NULL; |
| 112 | 113 |
| 113 RawObject* Object::null_ = reinterpret_cast<RawObject*>(RAW_NULL); | 114 RawObject* Object::null_ = reinterpret_cast<RawObject*>(RAW_NULL); |
| 114 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 115 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 115 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 116 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 116 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 117 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 117 RawType* Object::dynamic_type_ = reinterpret_cast<RawType*>(RAW_NULL); | 118 RawType* Object::dynamic_type_ = reinterpret_cast<RawType*>(RAW_NULL); |
| 118 RawType* Object::void_type_ = reinterpret_cast<RawType*>(RAW_NULL); | 119 RawType* Object::void_type_ = reinterpret_cast<RawType*>(RAW_NULL); |
| 119 RawClass* Object::unresolved_class_class_ = | 120 RawClass* Object::unresolved_class_class_ = |
| 120 reinterpret_cast<RawClass*>(RAW_NULL); | 121 reinterpret_cast<RawClass*>(RAW_NULL); |
| 121 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 122 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 extractor_parameter_names_ = Array::ReadOnlyHandle(); | 410 extractor_parameter_names_ = Array::ReadOnlyHandle(); |
| 410 sentinel_ = Instance::ReadOnlyHandle(); | 411 sentinel_ = Instance::ReadOnlyHandle(); |
| 411 transition_sentinel_ = Instance::ReadOnlyHandle(); | 412 transition_sentinel_ = Instance::ReadOnlyHandle(); |
| 412 unknown_constant_ = Instance::ReadOnlyHandle(); | 413 unknown_constant_ = Instance::ReadOnlyHandle(); |
| 413 non_constant_ = Instance::ReadOnlyHandle(); | 414 non_constant_ = Instance::ReadOnlyHandle(); |
| 414 bool_true_ = Bool::ReadOnlyHandle(); | 415 bool_true_ = Bool::ReadOnlyHandle(); |
| 415 bool_false_ = Bool::ReadOnlyHandle(); | 416 bool_false_ = Bool::ReadOnlyHandle(); |
| 416 smi_illegal_cid_ = Smi::ReadOnlyHandle(); | 417 smi_illegal_cid_ = Smi::ReadOnlyHandle(); |
| 417 snapshot_writer_error_ = LanguageError::ReadOnlyHandle(); | 418 snapshot_writer_error_ = LanguageError::ReadOnlyHandle(); |
| 418 branch_offset_error_ = LanguageError::ReadOnlyHandle(); | 419 branch_offset_error_ = LanguageError::ReadOnlyHandle(); |
| 420 vm_isolate_snapshot_object_table_ = Array::ReadOnlyHandle(); |
| 419 | 421 |
| 420 | 422 |
| 421 // Allocate and initialize the null instance. | 423 // Allocate and initialize the null instance. |
| 422 // 'null_' must be the first object allocated as it is used in allocation to | 424 // 'null_' must be the first object allocated as it is used in allocation to |
| 423 // clear the object. | 425 // clear the object. |
| 424 { | 426 { |
| 425 uword address = heap->Allocate(Instance::InstanceSize(), Heap::kOld); | 427 uword address = heap->Allocate(Instance::InstanceSize(), Heap::kOld); |
| 426 null_ = reinterpret_cast<RawInstance*>(address + kHeapObjectTag); | 428 null_ = reinterpret_cast<RawInstance*>(address + kHeapObjectTag); |
| 427 // The call below is using 'null_' to initialize itself. | 429 // The call below is using 'null_' to initialize itself. |
| 428 InitializeObject(address, kNullCid, Instance::InstanceSize()); | 430 InitializeObject(address, kNullCid, Instance::InstanceSize()); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 InitializeObject(address, | 662 InitializeObject(address, |
| 661 kExceptionHandlersCid, | 663 kExceptionHandlersCid, |
| 662 ExceptionHandlers::InstanceSize(0)); | 664 ExceptionHandlers::InstanceSize(0)); |
| 663 ExceptionHandlers::initializeHandle( | 665 ExceptionHandlers::initializeHandle( |
| 664 empty_exception_handlers_, | 666 empty_exception_handlers_, |
| 665 reinterpret_cast<RawExceptionHandlers*>(address + kHeapObjectTag)); | 667 reinterpret_cast<RawExceptionHandlers*>(address + kHeapObjectTag)); |
| 666 empty_exception_handlers_->StoreNonPointer( | 668 empty_exception_handlers_->StoreNonPointer( |
| 667 &empty_exception_handlers_->raw_ptr()->num_entries_, 0); | 669 &empty_exception_handlers_->raw_ptr()->num_entries_, 0); |
| 668 } | 670 } |
| 669 | 671 |
| 672 // The VM isolate snapshot object table is initialized to an empty array |
| 673 // as we do not have any VM isolate snapshot at this time. |
| 674 *vm_isolate_snapshot_object_table_ = Object::empty_array().raw(); |
| 675 |
| 670 cls = Class::New<Instance>(kDynamicCid); | 676 cls = Class::New<Instance>(kDynamicCid); |
| 671 cls.set_is_abstract(); | 677 cls.set_is_abstract(); |
| 672 cls.set_num_type_arguments(0); | 678 cls.set_num_type_arguments(0); |
| 673 cls.set_num_own_type_arguments(0); | 679 cls.set_num_own_type_arguments(0); |
| 674 cls.set_is_type_finalized(); | 680 cls.set_is_type_finalized(); |
| 675 cls.set_is_finalized(); | 681 cls.set_is_finalized(); |
| 676 dynamic_class_ = cls.raw(); | 682 dynamic_class_ = cls.raw(); |
| 677 | 683 |
| 678 cls = Class::New<Instance>(kVoidCid); | 684 cls = Class::New<Instance>(kVoidCid); |
| 679 cls.set_num_type_arguments(0); | 685 cls.set_num_type_arguments(0); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 ASSERT(non_constant_->IsInstance()); | 745 ASSERT(non_constant_->IsInstance()); |
| 740 ASSERT(!bool_true_->IsSmi()); | 746 ASSERT(!bool_true_->IsSmi()); |
| 741 ASSERT(bool_true_->IsBool()); | 747 ASSERT(bool_true_->IsBool()); |
| 742 ASSERT(!bool_false_->IsSmi()); | 748 ASSERT(!bool_false_->IsSmi()); |
| 743 ASSERT(bool_false_->IsBool()); | 749 ASSERT(bool_false_->IsBool()); |
| 744 ASSERT(smi_illegal_cid_->IsSmi()); | 750 ASSERT(smi_illegal_cid_->IsSmi()); |
| 745 ASSERT(!snapshot_writer_error_->IsSmi()); | 751 ASSERT(!snapshot_writer_error_->IsSmi()); |
| 746 ASSERT(snapshot_writer_error_->IsLanguageError()); | 752 ASSERT(snapshot_writer_error_->IsLanguageError()); |
| 747 ASSERT(!branch_offset_error_->IsSmi()); | 753 ASSERT(!branch_offset_error_->IsSmi()); |
| 748 ASSERT(branch_offset_error_->IsLanguageError()); | 754 ASSERT(branch_offset_error_->IsLanguageError()); |
| 755 ASSERT(!vm_isolate_snapshot_object_table_->IsSmi()); |
| 756 ASSERT(vm_isolate_snapshot_object_table_->IsArray()); |
| 749 } | 757 } |
| 750 | 758 |
| 751 | 759 |
| 752 // An object visitor which will mark all visited objects. This is used to | 760 // An object visitor which will mark all visited objects. This is used to |
| 753 // premark all objects in the vm_isolate_ heap. | 761 // premark all objects in the vm_isolate_ heap. |
| 754 class PremarkingVisitor : public ObjectVisitor { | 762 class PremarkingVisitor : public ObjectVisitor { |
| 755 public: | 763 public: |
| 756 explicit PremarkingVisitor(Isolate* isolate) : ObjectVisitor(isolate) {} | 764 explicit PremarkingVisitor(Isolate* isolate) : ObjectVisitor(isolate) {} |
| 757 | 765 |
| 758 void VisitObject(RawObject* obj) { | 766 void VisitObject(RawObject* obj) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 | 836 |
| 829 // Make the VM isolate read-only after setting all objects as marked. | 837 // Make the VM isolate read-only after setting all objects as marked. |
| 830 PremarkingVisitor premarker(isolate); | 838 PremarkingVisitor premarker(isolate); |
| 831 isolate->heap()->WriteProtect(false); | 839 isolate->heap()->WriteProtect(false); |
| 832 ASSERT(isolate->heap()->UsedInWords(Heap::kNew) == 0); | 840 ASSERT(isolate->heap()->UsedInWords(Heap::kNew) == 0); |
| 833 isolate->heap()->old_space()->VisitObjects(&premarker); | 841 isolate->heap()->old_space()->VisitObjects(&premarker); |
| 834 isolate->heap()->WriteProtect(true); | 842 isolate->heap()->WriteProtect(true); |
| 835 } | 843 } |
| 836 | 844 |
| 837 | 845 |
| 846 void Object::InitVmIsolateSnapshotObjectTable(intptr_t len) { |
| 847 ASSERT(Isolate::Current() == Dart::vm_isolate()); |
| 848 *vm_isolate_snapshot_object_table_ = Array::New(len, Heap::kOld); |
| 849 } |
| 850 |
| 851 |
| 838 // Make unused space in an object whose type has been transformed safe | 852 // Make unused space in an object whose type has been transformed safe |
| 839 // for traversing during GC. | 853 // for traversing during GC. |
| 840 // The unused part of the transformed object is marked as an TypedDataInt8Array | 854 // The unused part of the transformed object is marked as an TypedDataInt8Array |
| 841 // object. | 855 // object. |
| 842 void Object::MakeUnusedSpaceTraversable(const Object& obj, | 856 void Object::MakeUnusedSpaceTraversable(const Object& obj, |
| 843 intptr_t original_size, | 857 intptr_t original_size, |
| 844 intptr_t used_size) { | 858 intptr_t used_size) { |
| 845 ASSERT(Isolate::Current()->no_safepoint_scope_depth() > 0); | 859 ASSERT(Isolate::Current()->no_safepoint_scope_depth() > 0); |
| 846 ASSERT(!obj.IsNull()); | 860 ASSERT(!obj.IsNull()); |
| 847 ASSERT(original_size >= used_size); | 861 ASSERT(original_size >= used_size); |
| (...skipping 19857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20705 return tag_label.ToCString(); | 20719 return tag_label.ToCString(); |
| 20706 } | 20720 } |
| 20707 | 20721 |
| 20708 | 20722 |
| 20709 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20723 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 20710 Instance::PrintJSONImpl(stream, ref); | 20724 Instance::PrintJSONImpl(stream, ref); |
| 20711 } | 20725 } |
| 20712 | 20726 |
| 20713 | 20727 |
| 20714 } // namespace dart | 20728 } // namespace dart |
| OLD | NEW |