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

Side by Side Diff: vm/object.h

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 #ifndef VM_OBJECT_H_ 5 #ifndef VM_OBJECT_H_
6 #define VM_OBJECT_H_ 6 #define VM_OBJECT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 3483 matching lines...) Expand 10 before | Expand all | Expand 10 after
3494 public: 3494 public:
3495 intptr_t Capacity() const { 3495 intptr_t Capacity() const {
3496 NoGCScope no_gc; 3496 NoGCScope no_gc;
3497 ASSERT(!IsNull()); 3497 ASSERT(!IsNull());
3498 return Smi::Value(DataArray()->length_); 3498 return Smi::Value(DataArray()->length_);
3499 } 3499 }
3500 intptr_t Length() const { 3500 intptr_t Length() const {
3501 ASSERT(!IsNull()); 3501 ASSERT(!IsNull());
3502 return Smi::Value(raw_ptr()->length_); 3502 return Smi::Value(raw_ptr()->length_);
3503 } 3503 }
3504 void SetLength(intptr_t value) const {
3505 // This is only safe because we create a new Smi, which does not cause
3506 // heap allocation.
3507 raw_ptr()->length_ = Smi::New(value);
3508 }
3509
3510 RawArray* data() const { return raw_ptr()->data_; }
3511 void SetData(const Array& value) const {
3512 StorePointer(&raw_ptr()->data_, value.raw());
3513 }
3504 3514
3505 RawObject* At(intptr_t index) const { 3515 RawObject* At(intptr_t index) const {
3506 NoGCScope no_gc; 3516 NoGCScope no_gc;
3507 ASSERT(!IsNull()); 3517 ASSERT(!IsNull());
3508 ASSERT(index < Length()); 3518 ASSERT(index < Length());
3509 return *ObjectAddr(index); 3519 return *ObjectAddr(index);
3510 } 3520 }
3511 void SetAt(intptr_t index, const Object& value) const { 3521 void SetAt(intptr_t index, const Object& value) const {
3512 NoGCScope no_gc; 3522 NoGCScope no_gc;
3513 ASSERT(!IsNull()); 3523 ASSERT(!IsNull());
3514 ASSERT(index < Length()); 3524 ASSERT(index < Length());
3515 StorePointer(ObjectAddr(index), value.raw()); 3525 StorePointer(ObjectAddr(index), value.raw());
3516 } 3526 }
3517 3527
3518 void Add(const Object& value, Heap::Space space = Heap::kNew) const; 3528 void Add(const Object& value, Heap::Space space = Heap::kNew) const;
3529 void Grow(intptr_t new_capacity, Heap::Space space = Heap::kNew) const;
3519 RawObject* RemoveLast() const; 3530 RawObject* RemoveLast() const;
3520 3531
3521 virtual RawAbstractTypeArguments* GetTypeArguments() const { 3532 virtual RawAbstractTypeArguments* GetTypeArguments() const {
3522 const Array& contents = Array::Handle(data()); 3533 const Array& contents = Array::Handle(data());
3523 return contents.GetTypeArguments(); 3534 return contents.GetTypeArguments();
3524 } 3535 }
3525 virtual void SetTypeArguments(const AbstractTypeArguments& value) const { 3536 virtual void SetTypeArguments(const AbstractTypeArguments& value) const {
3526 const Array& contents = Array::Handle(data()); 3537 const Array& contents = Array::Handle(data());
3527 contents.SetTypeArguments(value); 3538 contents.SetTypeArguments(value);
3539 raw_ptr()->type_arguments_ = value.Canonicalize();
3528 } 3540 }
3529 3541
3530 virtual bool Equals(const Instance& other) const; 3542 virtual bool Equals(const Instance& other) const;
3531 3543
3544 static intptr_t type_arguments_offset() {
3545 return OFFSET_OF(RawGrowableObjectArray, type_arguments_);
3546 }
3547
3532 static intptr_t length_offset() { 3548 static intptr_t length_offset() {
3533 return OFFSET_OF(RawGrowableObjectArray, length_); 3549 return OFFSET_OF(RawGrowableObjectArray, length_);
3534 } 3550 }
3535 static intptr_t data_offset() { 3551 static intptr_t data_offset() {
3536 return OFFSET_OF(RawGrowableObjectArray, data_); 3552 return OFFSET_OF(RawGrowableObjectArray, data_);
3537 } 3553 }
3538 3554
3539 static intptr_t InstanceSize() { 3555 static intptr_t InstanceSize() {
3540 return RoundedAllocationSize(sizeof(RawGrowableObjectArray)); 3556 return RoundedAllocationSize(sizeof(RawGrowableObjectArray));
3541 } 3557 }
3542 3558
3543 static RawGrowableObjectArray* New(Heap::Space space = Heap::kNew) { 3559 static RawGrowableObjectArray* New(Heap::Space space = Heap::kNew) {
3544 return New(kDefaultInitialCapacity, space); 3560 return New(kDefaultInitialCapacity, space);
3545 } 3561 }
3546 static RawGrowableObjectArray* New(intptr_t capacity, 3562 static RawGrowableObjectArray* New(intptr_t capacity,
3547 Heap::Space space = Heap::kNew); 3563 Heap::Space space = Heap::kNew);
3564 static RawGrowableObjectArray* New(const Array& array,
3565 Heap::Space space = Heap::kNew);
3548 3566
3549 private: 3567 private:
3550 RawArray* data() const { return raw_ptr()->data_; }
3551 void SetLength(intptr_t value) const {
3552 // This is only safe because we create a new Smi, which does not cause
3553 // heap allocation.
3554 raw_ptr()->length_ = Smi::New(value);
3555 }
3556 void SetData(const Array& value) const {
3557 StorePointer(&raw_ptr()->data_, value.raw());
3558 }
3559 RawArray* DataArray() const { return data()->ptr(); } 3568 RawArray* DataArray() const { return data()->ptr(); }
3560 RawObject** ObjectAddr(intptr_t index) const { 3569 RawObject** ObjectAddr(intptr_t index) const {
3561 ASSERT((index >= 0) && (index < Length())); 3570 ASSERT((index >= 0) && (index < Length()));
3562 return &(DataArray()->data()[index]); 3571 return &(DataArray()->data()[index]);
3563 } 3572 }
3564 3573
3565 static const int kDefaultInitialCapacity = 4; 3574 static const int kDefaultInitialCapacity = 4;
3566 3575
3567 HEAP_OBJECT_IMPLEMENTATION(GrowableObjectArray, Instance); 3576 HEAP_OBJECT_IMPLEMENTATION(GrowableObjectArray, Instance);
3568 friend class Class; 3577 friend class Class;
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
3974 } 3983 }
3975 3984
3976 3985
3977 intptr_t Stackmap::SizeInBits() const { 3986 intptr_t Stackmap::SizeInBits() const {
3978 return (Smi::Value(raw_ptr()->bitmap_size_in_bytes_) * kBitsPerByte); 3987 return (Smi::Value(raw_ptr()->bitmap_size_in_bytes_) * kBitsPerByte);
3979 } 3988 }
3980 3989
3981 } // namespace dart 3990 } // namespace dart
3982 3991
3983 #endif // VM_OBJECT_H_ 3992 #endif // VM_OBJECT_H_
OLDNEW
« lib/growable_array.dart ('K') | « vm/intrinsifier_ia32.cc ('k') | vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698