| 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 "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1394 ASSERT(object_store->stacktrace_class() != Class::null()); | 1394 ASSERT(object_store->stacktrace_class() != Class::null()); |
| 1395 return object_store->stacktrace_class(); | 1395 return object_store->stacktrace_class(); |
| 1396 case kJSRegExp: | 1396 case kJSRegExp: |
| 1397 ASSERT(object_store->jsregexp_class() != Class::null()); | 1397 ASSERT(object_store->jsregexp_class() != Class::null()); |
| 1398 return object_store->jsregexp_class(); | 1398 return object_store->jsregexp_class(); |
| 1399 case kClosure: | 1399 case kClosure: |
| 1400 return Class::New<Closure>(); | 1400 return Class::New<Closure>(); |
| 1401 case kInstance: | 1401 case kInstance: |
| 1402 return Class::New<Instance>(); | 1402 return Class::New<Instance>(); |
| 1403 default: | 1403 default: |
| 1404 OS::Print("Class::GetClass kind unknown: %d\n", kind); |
| 1404 UNREACHABLE(); | 1405 UNREACHABLE(); |
| 1405 } | 1406 } |
| 1406 return Class::null(); | 1407 return Class::null(); |
| 1407 } | 1408 } |
| 1408 | 1409 |
| 1409 | 1410 |
| 1410 RawClass* Class::NewNativeWrapper(Library* library, | 1411 RawClass* Class::NewNativeWrapper(Library* library, |
| 1411 const String& name, | 1412 const String& name, |
| 1412 int field_count) { | 1413 int field_count) { |
| 1413 Class& cls = Class::Handle(library->LookupClass(name)); | 1414 Class& cls = Class::Handle(library->LookupClass(name)); |
| (...skipping 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3152 | 3153 |
| 3153 | 3154 |
| 3154 | 3155 |
| 3155 RawAbstractType** TypeArguments::TypeAddr(intptr_t index) const { | 3156 RawAbstractType** TypeArguments::TypeAddr(intptr_t index) const { |
| 3156 // TODO(iposva): Determine if we should throw an exception here. | 3157 // TODO(iposva): Determine if we should throw an exception here. |
| 3157 ASSERT((index >= 0) && (index < Length())); | 3158 ASSERT((index >= 0) && (index < Length())); |
| 3158 return &raw_ptr()->types_[index]; | 3159 return &raw_ptr()->types_[index]; |
| 3159 } | 3160 } |
| 3160 | 3161 |
| 3161 | 3162 |
| 3162 void TypeArguments::SetLength(intptr_t value) { | 3163 void TypeArguments::SetLength(intptr_t value) const { |
| 3163 ASSERT(!IsCanonical()); | 3164 ASSERT(!IsCanonical()); |
| 3164 // This is only safe because we create a new Smi, which does not cause | 3165 // This is only safe because we create a new Smi, which does not cause |
| 3165 // heap allocation. | 3166 // heap allocation. |
| 3166 raw_ptr()->length_ = Smi::New(value); | 3167 raw_ptr()->length_ = Smi::New(value); |
| 3167 } | 3168 } |
| 3168 | 3169 |
| 3169 | 3170 |
| 3170 RawAbstractTypeArguments* TypeArguments::Canonicalize() const { | 3171 RawAbstractTypeArguments* TypeArguments::Canonicalize() const { |
| 3171 if (IsNull() || IsCanonical() || !IsInstantiated()) { | 3172 if (IsNull() || IsCanonical() || !IsInstantiated()) { |
| 3172 return this->raw(); | 3173 return this->raw(); |
| (...skipping 5473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8646 | 8647 |
| 8647 RawArray* Array::Empty() { | 8648 RawArray* Array::Empty() { |
| 8648 return Isolate::Current()->object_store()->empty_array(); | 8649 return Isolate::Current()->object_store()->empty_array(); |
| 8649 } | 8650 } |
| 8650 | 8651 |
| 8651 | 8652 |
| 8652 RawArray* Array::MakeArray(const GrowableObjectArray& growable_array) { | 8653 RawArray* Array::MakeArray(const GrowableObjectArray& growable_array) { |
| 8653 intptr_t used_len = growable_array.Length(); | 8654 intptr_t used_len = growable_array.Length(); |
| 8654 intptr_t capacity_len = growable_array.Capacity(); | 8655 intptr_t capacity_len = growable_array.Capacity(); |
| 8655 Isolate* isolate = Isolate::Current(); | 8656 Isolate* isolate = Isolate::Current(); |
| 8656 Array& array = Array::Handle(isolate, growable_array.data()); | 8657 const Array& array = Array::Handle(isolate, growable_array.data()); |
| 8657 Array& new_array = Array::Handle(isolate, Array::Empty()); | 8658 const Array& new_array = Array::Handle(isolate, Array::Empty()); |
| 8658 intptr_t capacity_size = Array::InstanceSize(capacity_len); | 8659 intptr_t capacity_size = Array::InstanceSize(capacity_len); |
| 8659 intptr_t used_size = Array::InstanceSize(used_len); | 8660 intptr_t used_size = Array::InstanceSize(used_len); |
| 8660 NoGCScope no_gc; | 8661 NoGCScope no_gc; |
| 8661 | 8662 |
| 8662 // Update the size in the header field and length of the array object. | 8663 // Update the size in the header field and length of the array object. |
| 8663 uword tags = 0; | 8664 uword tags = array.raw_ptr()->tags_; |
| 8665 ASSERT(kArray == RawObject::ClassTag::decode(tags)); |
| 8664 tags = RawObject::SizeTag::update(used_size, tags); | 8666 tags = RawObject::SizeTag::update(used_size, tags); |
| 8665 array.raw_ptr()->tags_ = tags; | 8667 array.raw_ptr()->tags_ = tags; |
| 8666 array.SetLength(used_len); | 8668 array.SetLength(used_len); |
| 8667 | 8669 |
| 8668 // Null the GrowableObjectArray, we are removing it's backing array. | 8670 // Null the GrowableObjectArray, we are removing it's backing array. |
| 8669 growable_array.SetLength(0); | 8671 growable_array.SetLength(0); |
| 8670 growable_array.SetData(new_array); | 8672 growable_array.SetData(new_array); |
| 8671 | 8673 |
| 8672 // If there is any left over space fill it with either an Array object or | 8674 // If there is any left over space fill it with either an Array object or |
| 8673 // just a plain object (depending on the amount of left over space) so | 8675 // just a plain object (depending on the amount of left over space) so |
| 8674 // that it can be traversed over successfully during garbage collection. | 8676 // that it can be traversed over successfully during garbage collection. |
| 8675 if (capacity_size != used_size) { | 8677 if (capacity_size != used_size) { |
| 8676 ASSERT(capacity_len > used_len); | 8678 ASSERT(capacity_len > used_len); |
| 8677 intptr_t leftover_size = capacity_size - used_size; | 8679 intptr_t leftover_size = capacity_size - used_size; |
| 8678 | 8680 |
| 8679 uword addr = RawObject::ToAddr(array.raw()) + used_size; | 8681 uword addr = RawObject::ToAddr(array.raw()) + used_size; |
| 8680 if (leftover_size >= Array::InstanceSize(0)) { | 8682 if (leftover_size >= Array::InstanceSize(0)) { |
| 8681 // As we have enough space to use an array object, update the leftover | 8683 // As we have enough space to use an array object, update the leftover |
| 8682 // space as an Array object. | 8684 // space as an Array object. |
| 8683 RawArray* raw = reinterpret_cast<RawArray*>(RawObject::FromAddr(addr)); | 8685 RawArray* raw = reinterpret_cast<RawArray*>(RawObject::FromAddr(addr)); |
| 8684 raw->ptr()->class_ = isolate->object_store()->array_class(); | 8686 const Class& cls = Class::Handle(isolate->object_store()->array_class()); |
| 8687 raw->ptr()->class_ = cls.raw(); |
| 8685 tags = 0; | 8688 tags = 0; |
| 8686 tags = RawObject::SizeTag::update(leftover_size, tags); | 8689 tags = RawObject::SizeTag::update(leftover_size, tags); |
| 8690 tags = RawObject::ClassTag::update(cls.index(), tags); |
| 8687 raw->ptr()->tags_ = tags; | 8691 raw->ptr()->tags_ = tags; |
| 8688 intptr_t leftover_len = | 8692 intptr_t leftover_len = |
| 8689 ((leftover_size - Array::InstanceSize(0)) / kWordSize); | 8693 ((leftover_size - Array::InstanceSize(0)) / kWordSize); |
| 8690 raw->ptr()->tags_ = tags; | 8694 raw->ptr()->tags_ = tags; |
| 8691 raw->ptr()->length_ = Smi::New(leftover_len); | 8695 raw->ptr()->length_ = Smi::New(leftover_len); |
| 8692 } else { | 8696 } else { |
| 8693 // Update the leftover space as a basic object. | 8697 // Update the leftover space as a basic object. |
| 8694 ASSERT(leftover_size == Object::InstanceSize()); | 8698 ASSERT(leftover_size == Object::InstanceSize()); |
| 8695 RawObject* raw = reinterpret_cast<RawObject*>(RawObject::FromAddr(addr)); | 8699 RawObject* raw = reinterpret_cast<RawObject*>(RawObject::FromAddr(addr)); |
| 8696 raw->ptr()->class_ = isolate->object_store()->object_class(); | 8700 const Class& cls = Class::Handle(isolate->object_store()->object_class()); |
| 8701 raw->ptr()->class_ = cls.raw(); |
| 8697 tags = 0; | 8702 tags = 0; |
| 8698 tags = RawObject::SizeTag::update(leftover_size, tags); | 8703 tags = RawObject::SizeTag::update(leftover_size, tags); |
| 8704 tags = RawObject::ClassTag::update(cls.index(), tags); |
| 8699 raw->ptr()->tags_ = tags; | 8705 raw->ptr()->tags_ = tags; |
| 8700 } | 8706 } |
| 8701 } | 8707 } |
| 8702 return array.raw(); | 8708 return array.raw(); |
| 8703 } | 8709 } |
| 8704 | 8710 |
| 8705 | 8711 |
| 8706 RawImmutableArray* ImmutableArray::New(intptr_t len, | 8712 RawImmutableArray* ImmutableArray::New(intptr_t len, |
| 8707 Heap::Space space) { | 8713 Heap::Space space) { |
| 8708 ObjectStore* object_store = Isolate::Current()->object_store(); | 8714 ObjectStore* object_store = Isolate::Current()->object_store(); |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9283 const String& str = String::Handle(pattern()); | 9289 const String& str = String::Handle(pattern()); |
| 9284 const char* format = "JSRegExp: pattern=%s flags=%s"; | 9290 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 9285 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 9291 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 9286 char* chars = reinterpret_cast<char*>( | 9292 char* chars = reinterpret_cast<char*>( |
| 9287 Isolate::Current()->current_zone()->Allocate(len + 1)); | 9293 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 9288 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 9294 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 9289 return chars; | 9295 return chars; |
| 9290 } | 9296 } |
| 9291 | 9297 |
| 9292 } // namespace dart | 9298 } // namespace dart |
| OLD | NEW |