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 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 cls = Class::New<UnwindError>(); | 523 cls = Class::New<UnwindError>(); |
524 unwind_error_class_ = cls.raw(); | 524 unwind_error_class_ = cls.raw(); |
525 | 525 |
526 ASSERT(class_class() != null_); | 526 ASSERT(class_class() != null_); |
527 | 527 |
528 // Pre-allocate classes in the vm isolate so that we can for example create a | 528 // Pre-allocate classes in the vm isolate so that we can for example create a |
529 // symbol table and populate it with some frequently used strings as symbols. | 529 // symbol table and populate it with some frequently used strings as symbols. |
530 cls = Class::New<Array>(); | 530 cls = Class::New<Array>(); |
531 isolate->object_store()->set_array_class(cls); | 531 isolate->object_store()->set_array_class(cls); |
532 cls.set_type_arguments_field_offset(Array::type_arguments_offset()); | 532 cls.set_type_arguments_field_offset(Array::type_arguments_offset()); |
533 cls = Class::New<ImmutableArray>(); | 533 cls = Class::New<Array>(kImmutableArrayCid); |
534 isolate->object_store()->set_immutable_array_class(cls); | 534 isolate->object_store()->set_immutable_array_class(cls); |
535 cls.set_type_arguments_field_offset(Array::type_arguments_offset()); | 535 cls.set_type_arguments_field_offset(Array::type_arguments_offset()); |
536 cls = Class::NewStringClass(kOneByteStringCid); | 536 cls = Class::NewStringClass(kOneByteStringCid); |
537 isolate->object_store()->set_one_byte_string_class(cls); | 537 isolate->object_store()->set_one_byte_string_class(cls); |
538 cls = Class::NewStringClass(kTwoByteStringCid); | 538 cls = Class::NewStringClass(kTwoByteStringCid); |
539 isolate->object_store()->set_two_byte_string_class(cls); | 539 isolate->object_store()->set_two_byte_string_class(cls); |
540 | 540 |
541 // Allocate and initialize the empty_array instance. | 541 // Allocate and initialize the empty_array instance. |
542 { | 542 { |
543 uword address = heap->Allocate(Array::InstanceSize(0), Heap::kOld); | 543 uword address = heap->Allocate(Array::InstanceSize(0), Heap::kOld); |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 TypeArguments::Handle(), | 825 TypeArguments::Handle(), |
826 Scanner::kDummyTokenIndex); | 826 Scanner::kDummyTokenIndex); |
827 type.SetIsFinalized(); | 827 type.SetIsFinalized(); |
828 type ^= type.Canonicalize(); | 828 type ^= type.Canonicalize(); |
829 object_store->set_array_type(type); | 829 object_store->set_array_type(type); |
830 | 830 |
831 cls = object_store->growable_object_array_class(); // Was allocated above. | 831 cls = object_store->growable_object_array_class(); // Was allocated above. |
832 RegisterPrivateClass(cls, Symbols::GrowableObjectArray(), core_lib); | 832 RegisterPrivateClass(cls, Symbols::GrowableObjectArray(), core_lib); |
833 pending_classes.Add(cls, Heap::kOld); | 833 pending_classes.Add(cls, Heap::kOld); |
834 | 834 |
835 cls = Class::New<ImmutableArray>(); | 835 cls = Class::New<Array>(kImmutableArrayCid); |
836 object_store->set_immutable_array_class(cls); | 836 object_store->set_immutable_array_class(cls); |
837 cls.set_type_arguments_field_offset(Array::type_arguments_offset()); | 837 cls.set_type_arguments_field_offset(Array::type_arguments_offset()); |
838 ASSERT(object_store->immutable_array_class() != object_store->array_class()); | 838 ASSERT(object_store->immutable_array_class() != object_store->array_class()); |
| 839 cls.set_is_prefinalized(); |
839 RegisterPrivateClass(cls, Symbols::ImmutableArray(), core_lib); | 840 RegisterPrivateClass(cls, Symbols::ImmutableArray(), core_lib); |
840 pending_classes.Add(cls, Heap::kOld); | 841 pending_classes.Add(cls, Heap::kOld); |
841 | 842 |
842 cls = object_store->one_byte_string_class(); // Was allocated above. | 843 cls = object_store->one_byte_string_class(); // Was allocated above. |
843 RegisterPrivateClass(cls, Symbols::OneByteString(), core_lib); | 844 RegisterPrivateClass(cls, Symbols::OneByteString(), core_lib); |
844 pending_classes.Add(cls, Heap::kOld); | 845 pending_classes.Add(cls, Heap::kOld); |
845 | 846 |
846 cls = object_store->two_byte_string_class(); // Was allocated above. | 847 cls = object_store->two_byte_string_class(); // Was allocated above. |
847 RegisterPrivateClass(cls, Symbols::TwoByteString(), core_lib); | 848 RegisterPrivateClass(cls, Symbols::TwoByteString(), core_lib); |
848 pending_classes.Add(cls, Heap::kOld); | 849 pending_classes.Add(cls, Heap::kOld); |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 | 1114 |
1114 cls = Class::New<BoundedType>(); | 1115 cls = Class::New<BoundedType>(); |
1115 object_store->set_bounded_type_class(cls); | 1116 object_store->set_bounded_type_class(cls); |
1116 | 1117 |
1117 cls = Class::New<MixinAppType>(); | 1118 cls = Class::New<MixinAppType>(); |
1118 object_store->set_mixin_app_type_class(cls); | 1119 object_store->set_mixin_app_type_class(cls); |
1119 | 1120 |
1120 cls = Class::New<Array>(); | 1121 cls = Class::New<Array>(); |
1121 object_store->set_array_class(cls); | 1122 object_store->set_array_class(cls); |
1122 | 1123 |
1123 cls = Class::New<ImmutableArray>(); | 1124 cls = Class::New<Array>(kImmutableArrayCid); |
1124 object_store->set_immutable_array_class(cls); | 1125 object_store->set_immutable_array_class(cls); |
1125 | 1126 |
1126 cls = Class::New<GrowableObjectArray>(); | 1127 cls = Class::New<GrowableObjectArray>(); |
1127 object_store->set_growable_object_array_class(cls); | 1128 object_store->set_growable_object_array_class(cls); |
1128 | 1129 |
1129 cls = Class::New<Float32x4>(); | 1130 cls = Class::New<Float32x4>(); |
1130 object_store->set_float32x4_class(cls); | 1131 object_store->set_float32x4_class(cls); |
1131 | 1132 |
1132 cls = Class::New<Uint32x4>(); | 1133 cls = Class::New<Uint32x4>(); |
1133 object_store->set_uint32x4_class(cls); | 1134 object_store->set_uint32x4_class(cls); |
(...skipping 11401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12535 void Array::MakeImmutable() const { | 12536 void Array::MakeImmutable() const { |
12536 NoGCScope no_gc; | 12537 NoGCScope no_gc; |
12537 uword tags = raw_ptr()->tags_; | 12538 uword tags = raw_ptr()->tags_; |
12538 tags = RawObject::ClassIdTag::update(kImmutableArrayCid, tags); | 12539 tags = RawObject::ClassIdTag::update(kImmutableArrayCid, tags); |
12539 raw_ptr()->tags_ = tags; | 12540 raw_ptr()->tags_ = tags; |
12540 } | 12541 } |
12541 | 12542 |
12542 | 12543 |
12543 const char* Array::ToCString() const { | 12544 const char* Array::ToCString() const { |
12544 if (IsNull()) { | 12545 if (IsNull()) { |
12545 return "Array NULL"; | 12546 return IsImmutable() ? "ImmutableArray NULL" : "Array NULL"; |
12546 } | 12547 } |
12547 const char* format = "Array len:%"Pd""; | 12548 const char* format = !IsImmutable() ? "Array len:%"Pd"" : |
| 12549 "Immutable Array len:%"Pd""; |
12548 intptr_t len = OS::SNPrint(NULL, 0, format, Length()) + 1; | 12550 intptr_t len = OS::SNPrint(NULL, 0, format, Length()) + 1; |
12549 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 12551 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
12550 OS::SNPrint(chars, len, format, Length()); | 12552 OS::SNPrint(chars, len, format, Length()); |
12551 return chars; | 12553 return chars; |
12552 } | 12554 } |
12553 | 12555 |
12554 | 12556 |
12555 RawArray* Array::Grow(const Array& source, int new_length, Heap::Space space) { | 12557 RawArray* Array::Grow(const Array& source, int new_length, Heap::Space space) { |
12556 const Array& result = Array::Handle(Array::New(new_length, space)); | 12558 const Array& result = Array::Handle(Array::New(new_length, space)); |
12557 intptr_t len = 0; | 12559 intptr_t len = 0; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12605 | 12607 |
12606 | 12608 |
12607 RawImmutableArray* ImmutableArray::New(intptr_t len, | 12609 RawImmutableArray* ImmutableArray::New(intptr_t len, |
12608 Heap::Space space) { | 12610 Heap::Space space) { |
12609 ASSERT(Isolate::Current()->object_store()->immutable_array_class() != | 12611 ASSERT(Isolate::Current()->object_store()->immutable_array_class() != |
12610 Class::null()); | 12612 Class::null()); |
12611 return reinterpret_cast<RawImmutableArray*>(Array::New(kClassId, len, space)); | 12613 return reinterpret_cast<RawImmutableArray*>(Array::New(kClassId, len, space)); |
12612 } | 12614 } |
12613 | 12615 |
12614 | 12616 |
12615 const char* ImmutableArray::ToCString() const { | |
12616 if (IsNull()) { | |
12617 return "ImmutableArray NULL"; | |
12618 } | |
12619 const char* format = "ImmutableArray len:%"Pd""; | |
12620 intptr_t len = OS::SNPrint(NULL, 0, format, Length()) + 1; | |
12621 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | |
12622 OS::SNPrint(chars, len, format, Length()); | |
12623 return chars; | |
12624 } | |
12625 | |
12626 | |
12627 void GrowableObjectArray::Add(const Object& value, Heap::Space space) const { | 12617 void GrowableObjectArray::Add(const Object& value, Heap::Space space) const { |
12628 ASSERT(!IsNull()); | 12618 ASSERT(!IsNull()); |
12629 if (Length() == Capacity()) { | 12619 if (Length() == Capacity()) { |
12630 // TODO(Issue 2500): Need a better growth strategy. | 12620 // TODO(Issue 2500): Need a better growth strategy. |
12631 intptr_t new_capacity = (Capacity() == 0) ? 4 : Capacity() * 2; | 12621 intptr_t new_capacity = (Capacity() == 0) ? 4 : Capacity() * 2; |
12632 if (new_capacity <= Capacity()) { | 12622 if (new_capacity <= Capacity()) { |
12633 // Use the preallocated out of memory exception to avoid calling | 12623 // Use the preallocated out of memory exception to avoid calling |
12634 // into dart code or allocating any code. | 12624 // into dart code or allocating any code. |
12635 Isolate* isolate = Isolate::Current(); | 12625 Isolate* isolate = Isolate::Current(); |
12636 const Instance& exception = | 12626 const Instance& exception = |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13397 space); | 13387 space); |
13398 return reinterpret_cast<RawWeakProperty*>(raw); | 13388 return reinterpret_cast<RawWeakProperty*>(raw); |
13399 } | 13389 } |
13400 | 13390 |
13401 | 13391 |
13402 const char* WeakProperty::ToCString() const { | 13392 const char* WeakProperty::ToCString() const { |
13403 return "_WeakProperty"; | 13393 return "_WeakProperty"; |
13404 } | 13394 } |
13405 | 13395 |
13406 } // namespace dart | 13396 } // namespace dart |
OLD | NEW |