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

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 3475 matching lines...) Expand 10 before | Expand all | Expand 10 after
3486 public: 3486 public:
3487 intptr_t Capacity() const { 3487 intptr_t Capacity() const {
3488 NoGCScope no_gc; 3488 NoGCScope no_gc;
3489 ASSERT(!IsNull()); 3489 ASSERT(!IsNull());
3490 return Smi::Value(DataArray()->length_); 3490 return Smi::Value(DataArray()->length_);
3491 } 3491 }
3492 intptr_t Length() const { 3492 intptr_t Length() const {
3493 ASSERT(!IsNull()); 3493 ASSERT(!IsNull());
3494 return Smi::Value(raw_ptr()->length_); 3494 return Smi::Value(raw_ptr()->length_);
3495 } 3495 }
3496 void SetLength(intptr_t value) const {
3497 // This is only safe because we create a new Smi, which does not cause
3498 // heap allocation.
3499 raw_ptr()->length_ = Smi::New(value);
3500 }
3501
3502 RawArray* data() const { return raw_ptr()->data_; }
3503 void SetData(const Array& value) const {
3504 StorePointer(&raw_ptr()->data_, value.raw());
3505 }
3496 3506
3497 RawObject* At(intptr_t index) const { 3507 RawObject* At(intptr_t index) const {
3498 NoGCScope no_gc; 3508 NoGCScope no_gc;
3499 ASSERT(!IsNull()); 3509 ASSERT(!IsNull());
3500 ASSERT(index < Length()); 3510 ASSERT(index < Length());
3501 return *ObjectAddr(index); 3511 return *ObjectAddr(index);
3502 } 3512 }
3503 void SetAt(intptr_t index, const Object& value) const { 3513 void SetAt(intptr_t index, const Object& value) const {
3504 NoGCScope no_gc; 3514 NoGCScope no_gc;
3505 ASSERT(!IsNull()); 3515 ASSERT(!IsNull());
3506 ASSERT(index < Length()); 3516 ASSERT(index < Length());
3507 StorePointer(ObjectAddr(index), value.raw()); 3517 StorePointer(ObjectAddr(index), value.raw());
3508 } 3518 }
3509 3519
3510 void Add(const Object& value, Heap::Space space = Heap::kNew) const; 3520 void Add(const Object& value, Heap::Space space = Heap::kNew) const;
3521 void Grow(intptr_t new_capacity, Heap::Space space = Heap::kNew) const;
3511 RawObject* RemoveLast() const; 3522 RawObject* RemoveLast() const;
3512 3523
3513 virtual RawAbstractTypeArguments* GetTypeArguments() const { 3524 virtual RawAbstractTypeArguments* GetTypeArguments() const {
3514 const Array& contents = Array::Handle(data()); 3525 const Array& contents = Array::Handle(data());
3515 return contents.GetTypeArguments(); 3526 return contents.GetTypeArguments();
3516 } 3527 }
3517 virtual void SetTypeArguments(const AbstractTypeArguments& value) const { 3528 virtual void SetTypeArguments(const AbstractTypeArguments& value) const {
3518 const Array& contents = Array::Handle(data()); 3529 const Array& contents = Array::Handle(data());
3519 contents.SetTypeArguments(value); 3530 contents.SetTypeArguments(value);
3531 raw_ptr()->type_arguments_ = value.Canonicalize();
3520 } 3532 }
3521 3533
3522 virtual bool Equals(const Instance& other) const; 3534 virtual bool Equals(const Instance& other) const;
3523 3535
3536 static intptr_t type_arguments_offset() {
3537 return OFFSET_OF(RawGrowableObjectArray, type_arguments_);
3538 }
3539
3524 static intptr_t length_offset() { 3540 static intptr_t length_offset() {
3525 return OFFSET_OF(RawGrowableObjectArray, length_); 3541 return OFFSET_OF(RawGrowableObjectArray, length_);
3526 } 3542 }
3527 static intptr_t data_offset() { 3543 static intptr_t data_offset() {
3528 return OFFSET_OF(RawGrowableObjectArray, data_); 3544 return OFFSET_OF(RawGrowableObjectArray, data_);
3529 } 3545 }
3530 3546
3531 static intptr_t InstanceSize() { 3547 static intptr_t InstanceSize() {
3532 return RoundedAllocationSize(sizeof(RawGrowableObjectArray)); 3548 return RoundedAllocationSize(sizeof(RawGrowableObjectArray));
3533 } 3549 }
3534 3550
3535 static RawGrowableObjectArray* New(Heap::Space space = Heap::kNew) { 3551 static RawGrowableObjectArray* New(Heap::Space space = Heap::kNew) {
3536 return New(kDefaultInitialCapacity, space); 3552 return New(kDefaultInitialCapacity, space);
3537 } 3553 }
3538 static RawGrowableObjectArray* New(intptr_t capacity, 3554 static RawGrowableObjectArray* New(intptr_t capacity,
3539 Heap::Space space = Heap::kNew); 3555 Heap::Space space = Heap::kNew);
3556 static RawGrowableObjectArray* New(const Array& array,
3557 Heap::Space space = Heap::kNew);
3540 3558
3541 private: 3559 private:
3542 RawArray* data() const { return raw_ptr()->data_; }
3543 void SetLength(intptr_t value) const {
3544 // This is only safe because we create a new Smi, which does not cause
3545 // heap allocation.
3546 raw_ptr()->length_ = Smi::New(value);
3547 }
3548 void SetData(const Array& value) const {
3549 StorePointer(&raw_ptr()->data_, value.raw());
3550 }
3551 RawArray* DataArray() const { return data()->ptr(); } 3560 RawArray* DataArray() const { return data()->ptr(); }
3552 RawObject** ObjectAddr(intptr_t index) const { 3561 RawObject** ObjectAddr(intptr_t index) const {
3553 ASSERT((index >= 0) && (index < Length())); 3562 ASSERT((index >= 0) && (index < Length()));
3554 return &(DataArray()->data()[index]); 3563 return &(DataArray()->data()[index]);
3555 } 3564 }
3556 3565
3557 static const int kDefaultInitialCapacity = 4; 3566 static const int kDefaultInitialCapacity = 4;
3558 3567
3559 HEAP_OBJECT_IMPLEMENTATION(GrowableObjectArray, Instance); 3568 HEAP_OBJECT_IMPLEMENTATION(GrowableObjectArray, Instance);
3560 friend class Class; 3569 friend class Class;
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
3966 } 3975 }
3967 3976
3968 3977
3969 intptr_t Stackmap::SizeInBits() const { 3978 intptr_t Stackmap::SizeInBits() const {
3970 return (Smi::Value(raw_ptr()->bitmap_size_in_bytes_) * kBitsPerByte); 3979 return (Smi::Value(raw_ptr()->bitmap_size_in_bytes_) * kBitsPerByte);
3971 } 3980 }
3972 3981
3973 } // namespace dart 3982 } // namespace dart
3974 3983
3975 #endif // VM_OBJECT_H_ 3984 #endif // VM_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698