Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: vm/object.cc

Issue 10012042: Wire GrowableArray to use the internal VM object. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 8031 matching lines...) Expand 10 before | Expand all | Expand 10 after
8565 8571
8566 const char* ImmutableArray::ToCString() const { 8572 const char* ImmutableArray::ToCString() const {
8567 return "ImmutableArray"; 8573 return "ImmutableArray";
8568 } 8574 }
8569 8575
8570 8576
8571 void GrowableObjectArray::Add(const Object& value, Heap::Space space) const { 8577 void GrowableObjectArray::Add(const Object& value, Heap::Space space) const {
8572 ASSERT(!IsNull()); 8578 ASSERT(!IsNull());
8573 Array& contents = Array::Handle(data()); 8579 Array& contents = Array::Handle(data());
8574 if (Length() == Capacity()) { 8580 if (Length() == Capacity()) {
8575 intptr_t new_capacity = Capacity() * 2; 8581 // TODO(Issue 2500): Need a better growth strategy.
8582 intptr_t new_capacity = (Capacity() == 0) ? 4 : Capacity() * 2;
8576 if (new_capacity <= Capacity()) { 8583 if (new_capacity <= Capacity()) {
8577 // Use the preallocated out of memory exception to avoid calling 8584 // Use the preallocated out of memory exception to avoid calling
8578 // into dart code or allocating any code. 8585 // into dart code or allocating any code.
8579 const Instance& exception = 8586 const Instance& exception =
8580 Instance::Handle(Isolate::Current()->object_store()->out_of_memory()); 8587 Instance::Handle(Isolate::Current()->object_store()->out_of_memory());
8581 Exceptions::Throw(exception); 8588 Exceptions::Throw(exception);
8582 UNREACHABLE(); 8589 UNREACHABLE();
8583 } 8590 }
8584 StorePointer(&(raw_ptr()->data_), 8591 Grow(new_capacity, space);
8585 Array::Grow(contents, new_capacity, space));
8586 contents = data(); 8592 contents = data();
8587 } 8593 }
8588 ASSERT(Length() < Capacity()); 8594 ASSERT(Length() < Capacity());
8589 intptr_t index = Length(); 8595 intptr_t index = Length();
8590 SetLength(index + 1); 8596 SetLength(index + 1);
8591 contents.SetAt(index, value); 8597 contents.SetAt(index, value);
8592 } 8598 }
8593 8599
8594 8600
8601 void GrowableObjectArray::Grow(intptr_t new_capacity, Heap::Space space) const {
8602 ASSERT(new_capacity > Capacity());
8603 Array& contents = Array::Handle(data());
8604 StorePointer(&(raw_ptr()->data_),
8605 Array::Grow(contents, new_capacity, space));
8606 }
8607
8608
8595 RawObject* GrowableObjectArray::RemoveLast() const { 8609 RawObject* GrowableObjectArray::RemoveLast() const {
8596 ASSERT(!IsNull()); 8610 ASSERT(!IsNull());
8597 ASSERT(Length() > 0); 8611 ASSERT(Length() > 0);
8598 intptr_t index = Length() - 1; 8612 intptr_t index = Length() - 1;
8599 const Array& contents = Array::Handle(data()); 8613 const Array& contents = Array::Handle(data());
8600 const Object& obj = Object::Handle(contents.At(index)); 8614 const Object& obj = Object::Handle(contents.At(index));
8601 contents.SetAt(index, Object::Handle()); 8615 contents.SetAt(index, Object::Handle());
8602 SetLength(index); 8616 SetLength(index);
8603 return obj.raw(); 8617 return obj.raw();
8604 } 8618 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
8637 if (contents.At(i) != other_contents.At(i)) { 8651 if (contents.At(i) != other_contents.At(i)) {
8638 return false; 8652 return false;
8639 } 8653 }
8640 } 8654 }
8641 return true; 8655 return true;
8642 } 8656 }
8643 8657
8644 8658
8645 RawGrowableObjectArray* GrowableObjectArray::New(intptr_t capacity, 8659 RawGrowableObjectArray* GrowableObjectArray::New(intptr_t capacity,
8646 Heap::Space space) { 8660 Heap::Space space) {
8661 const Array& data = Array::Handle(Array::New(capacity, space));
8662 return New(data, space);
8663 }
8664
8665
8666 RawGrowableObjectArray* GrowableObjectArray::New(const Array& array,
8667 Heap::Space space) {
8647 ObjectStore* object_store = Isolate::Current()->object_store(); 8668 ObjectStore* object_store = Isolate::Current()->object_store();
8648 Class& cls = Class::Handle(object_store->growable_object_array_class()); 8669 Class& cls = Class::Handle(object_store->growable_object_array_class());
8649 const Array& data = Array::Handle(Array::New(capacity, space));
8650 GrowableObjectArray& result = GrowableObjectArray::Handle(); 8670 GrowableObjectArray& result = GrowableObjectArray::Handle();
8651 { 8671 {
8652 RawObject* raw = Object::Allocate(cls, 8672 RawObject* raw = Object::Allocate(cls,
8653 GrowableObjectArray::InstanceSize(), 8673 GrowableObjectArray::InstanceSize(),
8654 space); 8674 space);
8655 NoGCScope no_gc; 8675 NoGCScope no_gc;
8656 result ^= raw; 8676 result ^= raw;
8657 result.SetLength(0); 8677 result.SetLength(0);
8658 result.SetData(data); 8678 result.SetData(array);
8659 } 8679 }
8660 return result.raw(); 8680 return result.raw();
8661 } 8681 }
8662 8682
8663 8683
8664 const char* GrowableObjectArray::ToCString() const { 8684 const char* GrowableObjectArray::ToCString() const {
8665 return "GrowableObjectArray"; 8685 return "GrowableObjectArray";
8666 } 8686 }
8667 8687
8668 8688
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
9110 const String& str = String::Handle(pattern()); 9130 const String& str = String::Handle(pattern());
9111 const char* format = "JSRegExp: pattern=%s flags=%s"; 9131 const char* format = "JSRegExp: pattern=%s flags=%s";
9112 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 9132 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
9113 char* chars = reinterpret_cast<char*>( 9133 char* chars = reinterpret_cast<char*>(
9114 Isolate::Current()->current_zone()->Allocate(len + 1)); 9134 Isolate::Current()->current_zone()->Allocate(len + 1));
9115 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 9135 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
9116 return chars; 9136 return chars;
9117 } 9137 }
9118 9138
9119 } // namespace dart 9139 } // namespace dart
OLDNEW
« lib/growable_array.dart ('K') | « vm/object.h ('k') | vm/opt_code_generator_ia32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698