Chromium Code Reviews| 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 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 object_store->set_empty_array(empty_array); | 450 object_store->set_empty_array(empty_array); |
| 451 | 451 |
| 452 // Re-initialize fields of the array class now that the empty array | 452 // Re-initialize fields of the array class now that the empty array |
| 453 // has been created. | 453 // has been created. |
| 454 cls.InitEmptyFields(); | 454 cls.InitEmptyFields(); |
| 455 | 455 |
| 456 // Set up the growable object array class (Has to be done after the array | 456 // Set up the growable object array class (Has to be done after the array |
| 457 // class is setup as one of its field is an array object). | 457 // class is setup as one of its field is an array object). |
| 458 cls = Class::New<GrowableObjectArray>(); | 458 cls = Class::New<GrowableObjectArray>(); |
| 459 object_store->set_growable_object_array_class(cls); | 459 object_store->set_growable_object_array_class(cls); |
| 460 cls.set_type_arguments_instance_field_offset( | |
| 461 GrowableObjectArray::type_arguments_offset()); | |
| 460 | 462 |
| 461 // Setup the symbol table used within the String class. | 463 // Setup the symbol table used within the String class. |
| 462 const int kInitialSymbolTableSize = 16; | 464 const int kInitialSymbolTableSize = 16; |
| 463 array = Array::New(kInitialSymbolTableSize + 1); | 465 array = Array::New(kInitialSymbolTableSize + 1); |
| 464 // Last element contains the count of used slots. | 466 // Last element contains the count of used slots. |
| 465 array.SetAt(kInitialSymbolTableSize, Smi::Handle(Smi::New(0))); | 467 array.SetAt(kInitialSymbolTableSize, Smi::Handle(Smi::New(0))); |
| 466 object_store->set_symbol_table(array); | 468 object_store->set_symbol_table(array); |
| 467 | 469 |
| 468 // canonical_type_arguments_ are NULL terminated. | 470 // canonical_type_arguments_ are NULL terminated. |
| 469 array = Array::New(4); | 471 array = Array::New(4); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 | 516 |
| 515 cls = Class::New<Bool>(); | 517 cls = Class::New<Bool>(); |
| 516 object_store->set_bool_class(cls); | 518 object_store->set_bool_class(cls); |
| 517 RegisterClass(cls, "Bool", impl_script, core_impl_lib); | 519 RegisterClass(cls, "Bool", impl_script, core_impl_lib); |
| 518 pending_classes.Add(cls, Heap::kOld); | 520 pending_classes.Add(cls, Heap::kOld); |
| 519 | 521 |
| 520 cls = object_store->array_class(); // Was allocated above. | 522 cls = object_store->array_class(); // Was allocated above. |
| 521 RegisterClass(cls, "ObjectArray", impl_script, core_impl_lib); | 523 RegisterClass(cls, "ObjectArray", impl_script, core_impl_lib); |
| 522 pending_classes.Add(cls, Heap::kOld); | 524 pending_classes.Add(cls, Heap::kOld); |
| 523 | 525 |
| 526 cls = object_store->growable_object_array_class(); // Was allocated above. | |
| 527 RegisterClass(cls, "GrowableObjectArray", impl_script, core_impl_lib); | |
| 528 pending_classes.Add(cls, Heap::kOld); | |
| 529 | |
| 524 cls = Class::New<ImmutableArray>(); | 530 cls = Class::New<ImmutableArray>(); |
| 525 object_store->set_immutable_array_class(cls); | 531 object_store->set_immutable_array_class(cls); |
| 526 cls.set_type_arguments_instance_field_offset(Array::type_arguments_offset()); | 532 cls.set_type_arguments_instance_field_offset(Array::type_arguments_offset()); |
| 527 ASSERT(object_store->immutable_array_class() != object_store->array_class()); | 533 ASSERT(object_store->immutable_array_class() != object_store->array_class()); |
| 528 RegisterClass(cls, "ImmutableArray", impl_script, core_impl_lib); | 534 RegisterClass(cls, "ImmutableArray", impl_script, core_impl_lib); |
| 529 pending_classes.Add(cls, Heap::kOld); | 535 pending_classes.Add(cls, Heap::kOld); |
| 530 | 536 |
| 531 cls = object_store->one_byte_string_class(); // Was allocated above. | 537 cls = object_store->one_byte_string_class(); // Was allocated above. |
| 532 RegisterClass(cls, "OneByteString", impl_script, core_impl_lib); | 538 RegisterClass(cls, "OneByteString", impl_script, core_impl_lib); |
| 533 pending_classes.Add(cls, Heap::kOld); | 539 pending_classes.Add(cls, Heap::kOld); |
| (...skipping 8027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8561 | 8567 |
| 8562 const char* ImmutableArray::ToCString() const { | 8568 const char* ImmutableArray::ToCString() const { |
| 8563 return "ImmutableArray"; | 8569 return "ImmutableArray"; |
| 8564 } | 8570 } |
| 8565 | 8571 |
| 8566 | 8572 |
| 8567 void GrowableObjectArray::Add(const Object& value, Heap::Space space) const { | 8573 void GrowableObjectArray::Add(const Object& value, Heap::Space space) const { |
| 8568 ASSERT(!IsNull()); | 8574 ASSERT(!IsNull()); |
| 8569 Array& contents = Array::Handle(data()); | 8575 Array& contents = Array::Handle(data()); |
| 8570 if (Length() == Capacity()) { | 8576 if (Length() == Capacity()) { |
| 8571 intptr_t new_capacity = Capacity() * 2; | 8577 intptr_t new_capacity = (Capacity() == 0) ? 4 : Capacity() * 2; |
|
srdjan
2012/04/06 21:19:51
Capacity * 2 may be to-harsh. Adding one element t
siva
2012/04/09 20:57:24
I have opened a Bug to track this and figure out h
| |
| 8572 if (new_capacity <= Capacity()) { | 8578 if (new_capacity <= Capacity()) { |
| 8573 // Use the preallocated out of memory exception to avoid calling | 8579 // Use the preallocated out of memory exception to avoid calling |
| 8574 // into dart code or allocating any code. | 8580 // into dart code or allocating any code. |
| 8575 const Instance& exception = | 8581 const Instance& exception = |
| 8576 Instance::Handle(Isolate::Current()->object_store()->out_of_memory()); | 8582 Instance::Handle(Isolate::Current()->object_store()->out_of_memory()); |
| 8577 Exceptions::Throw(exception); | 8583 Exceptions::Throw(exception); |
| 8578 UNREACHABLE(); | 8584 UNREACHABLE(); |
| 8579 } | 8585 } |
| 8580 StorePointer(&(raw_ptr()->data_), | 8586 Grow(new_capacity, space); |
| 8581 Array::Grow(contents, new_capacity, space)); | |
| 8582 contents = data(); | 8587 contents = data(); |
| 8583 } | 8588 } |
| 8584 ASSERT(Length() < Capacity()); | 8589 ASSERT(Length() < Capacity()); |
| 8585 intptr_t index = Length(); | 8590 intptr_t index = Length(); |
| 8586 SetLength(index + 1); | 8591 SetLength(index + 1); |
| 8587 contents.SetAt(index, value); | 8592 contents.SetAt(index, value); |
| 8588 } | 8593 } |
| 8589 | 8594 |
| 8590 | 8595 |
| 8596 void GrowableObjectArray::Grow(intptr_t new_capacity, Heap::Space space) const { | |
| 8597 ASSERT(new_capacity > Capacity()); | |
| 8598 Array& contents = Array::Handle(data()); | |
| 8599 StorePointer(&(raw_ptr()->data_), | |
| 8600 Array::Grow(contents, new_capacity, space)); | |
| 8601 } | |
| 8602 | |
| 8603 | |
| 8591 RawObject* GrowableObjectArray::RemoveLast() const { | 8604 RawObject* GrowableObjectArray::RemoveLast() const { |
| 8592 ASSERT(!IsNull()); | 8605 ASSERT(!IsNull()); |
| 8593 ASSERT(Length() > 0); | 8606 ASSERT(Length() > 0); |
| 8594 intptr_t index = Length() - 1; | 8607 intptr_t index = Length() - 1; |
| 8595 const Array& contents = Array::Handle(data()); | 8608 const Array& contents = Array::Handle(data()); |
| 8596 const Object& obj = Object::Handle(contents.At(index)); | 8609 const Object& obj = Object::Handle(contents.At(index)); |
| 8597 contents.SetAt(index, Object::Handle()); | 8610 contents.SetAt(index, Object::Handle()); |
| 8598 SetLength(index); | 8611 SetLength(index); |
| 8599 return obj.raw(); | 8612 return obj.raw(); |
| 8600 } | 8613 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8633 if (contents.At(i) != other_contents.At(i)) { | 8646 if (contents.At(i) != other_contents.At(i)) { |
| 8634 return false; | 8647 return false; |
| 8635 } | 8648 } |
| 8636 } | 8649 } |
| 8637 return true; | 8650 return true; |
| 8638 } | 8651 } |
| 8639 | 8652 |
| 8640 | 8653 |
| 8641 RawGrowableObjectArray* GrowableObjectArray::New(intptr_t capacity, | 8654 RawGrowableObjectArray* GrowableObjectArray::New(intptr_t capacity, |
| 8642 Heap::Space space) { | 8655 Heap::Space space) { |
| 8656 const Array& data = Array::Handle(Array::New(capacity, space)); | |
| 8657 return New(data, space); | |
| 8658 } | |
| 8659 | |
| 8660 | |
| 8661 RawGrowableObjectArray* GrowableObjectArray::New(const Array& array, | |
| 8662 Heap::Space space) { | |
| 8643 ObjectStore* object_store = Isolate::Current()->object_store(); | 8663 ObjectStore* object_store = Isolate::Current()->object_store(); |
| 8644 Class& cls = Class::Handle(object_store->growable_object_array_class()); | 8664 Class& cls = Class::Handle(object_store->growable_object_array_class()); |
| 8645 const Array& data = Array::Handle(Array::New(capacity, space)); | |
| 8646 GrowableObjectArray& result = GrowableObjectArray::Handle(); | 8665 GrowableObjectArray& result = GrowableObjectArray::Handle(); |
| 8647 { | 8666 { |
| 8648 RawObject* raw = Object::Allocate(cls, | 8667 RawObject* raw = Object::Allocate(cls, |
| 8649 GrowableObjectArray::InstanceSize(), | 8668 GrowableObjectArray::InstanceSize(), |
| 8650 space); | 8669 space); |
| 8651 NoGCScope no_gc; | 8670 NoGCScope no_gc; |
| 8652 result ^= raw; | 8671 result ^= raw; |
| 8653 result.SetLength(0); | 8672 result.SetLength(0); |
| 8654 result.SetData(data); | 8673 result.SetData(array); |
| 8655 } | 8674 } |
| 8656 return result.raw(); | 8675 return result.raw(); |
| 8657 } | 8676 } |
| 8658 | 8677 |
| 8659 | 8678 |
| 8660 const char* GrowableObjectArray::ToCString() const { | 8679 const char* GrowableObjectArray::ToCString() const { |
| 8661 return "GrowableObjectArray"; | 8680 return "GrowableObjectArray"; |
| 8662 } | 8681 } |
| 8663 | 8682 |
| 8664 | 8683 |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9107 const String& str = String::Handle(pattern()); | 9126 const String& str = String::Handle(pattern()); |
| 9108 const char* format = "JSRegExp: pattern=%s flags=%s"; | 9127 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 9109 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 9128 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 9110 char* chars = reinterpret_cast<char*>( | 9129 char* chars = reinterpret_cast<char*>( |
| 9111 Isolate::Current()->current_zone()->Allocate(len + 1)); | 9130 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 9112 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 9131 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 9113 return chars; | 9132 return chars; |
| 9114 } | 9133 } |
| 9115 | 9134 |
| 9116 } // namespace dart | 9135 } // namespace dart |
| OLD | NEW |