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

Side by Side Diff: vm/object.h

Issue 9594028: Add a first class GrowableObjectArray type in the VM and use it internally in the VM at all spots w… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 9 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
« no previous file with comments | « vm/class_finalizer_test.cc ('k') | vm/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 3281 matching lines...) Expand 10 before | Expand all | Expand 10 after
3292 // Creates and returns a new array with 'new_length'. Copies all elements from 3292 // Creates and returns a new array with 'new_length'. Copies all elements from
3293 // 'source' to the new array. 'new_length' must be greater than or equal to 3293 // 'source' to the new array. 'new_length' must be greater than or equal to
3294 // 'source.Length()'. 'source' can be null. 3294 // 'source.Length()'. 'source' can be null.
3295 static RawArray* Grow(const Array& source, 3295 static RawArray* Grow(const Array& source,
3296 int new_length, 3296 int new_length,
3297 Heap::Space space = Heap::kNew); 3297 Heap::Space space = Heap::kNew);
3298 3298
3299 // Returns the preallocated empty array, used to initialize array fields. 3299 // Returns the preallocated empty array, used to initialize array fields.
3300 static RawArray* Empty(); 3300 static RawArray* Empty();
3301 3301
3302 // Return an Array object that contains all the elements currently present
3303 // in the specified Growable Object Array. This is done by truncating the
3304 // backing array in the Growable Object Array to the currently used size.
3305 // The remaining unused part of the backing array is marked as an Array
3306 // object or a regular Object so that it can be traversed during garbage
3307 // collection. The backing array of the original Growable Object Array is
3308 // set to an empty array.
3309 static RawArray* MakeArray(const GrowableObjectArray& growable_array);
3310
3302 protected: 3311 protected:
3303 static RawArray* New(const Class& cls, 3312 static RawArray* New(const Class& cls,
3304 intptr_t len, 3313 intptr_t len,
3305 Heap::Space space = Heap::kNew); 3314 Heap::Space space = Heap::kNew);
3306 3315
3307 private: 3316 private:
3308 // Make sure that the array size cannot wrap around. 3317 // Make sure that the array size cannot wrap around.
3309 static const intptr_t kMaxArrayElements = 512 * 1024 * 1024; 3318 static const intptr_t kMaxArrayElements = 512 * 1024 * 1024;
3310 3319
3311 RawObject** ObjectAddr(intptr_t index) const { 3320 RawObject** ObjectAddr(intptr_t index) const {
(...skipping 16 matching lines...) Expand all
3328 class ImmutableArray : public Array { 3337 class ImmutableArray : public Array {
3329 public: 3338 public:
3330 static RawImmutableArray* New(intptr_t len, Heap::Space space = Heap::kNew); 3339 static RawImmutableArray* New(intptr_t len, Heap::Space space = Heap::kNew);
3331 3340
3332 private: 3341 private:
3333 HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array); 3342 HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array);
3334 friend class Class; 3343 friend class Class;
3335 }; 3344 };
3336 3345
3337 3346
3347 class GrowableObjectArray : public Instance {
3348 public:
3349 intptr_t Capacity() const {
3350 NoGCScope no_gc;
3351 ASSERT(!IsNull());
3352 return Smi::Value(DataArray()->length_);
3353 }
3354 intptr_t Length() const {
3355 ASSERT(!IsNull());
3356 return Smi::Value(raw_ptr()->length_);
3357 }
3358
3359 RawObject* At(intptr_t index) const {
3360 NoGCScope no_gc;
3361 ASSERT(!IsNull());
3362 ASSERT(index < Length());
3363 return *ObjectAddr(index);
3364 }
3365 void SetAt(intptr_t index, const Object& value) const {
3366 NoGCScope no_gc;
3367 ASSERT(!IsNull());
3368 ASSERT(index < Length());
3369 StorePointer(ObjectAddr(index), value.raw());
3370 }
3371
3372 void Add(const Object& value, Heap::Space space = Heap::kNew) const;
3373 RawObject* RemoveLast() const;
3374
3375 virtual RawAbstractTypeArguments* GetTypeArguments() const {
3376 const Array& contents = Array::Handle(data());
3377 return contents.GetTypeArguments();
3378 }
3379 virtual void SetTypeArguments(const AbstractTypeArguments& value) const {
3380 const Array& contents = Array::Handle(data());
3381 contents.SetTypeArguments(value);
3382 }
3383
3384 virtual bool Equals(const Instance& other) const;
3385
3386 static intptr_t length_offset() {
3387 return OFFSET_OF(RawGrowableObjectArray, length_);
3388 }
3389 static intptr_t data_offset() {
3390 return OFFSET_OF(RawGrowableObjectArray, data_);
3391 }
3392
3393 static intptr_t InstanceSize() {
3394 return RoundedAllocationSize(sizeof(RawGrowableObjectArray));
3395 }
3396
3397 static RawGrowableObjectArray* New(Heap::Space space = Heap::kNew) {
3398 return New(kDefaultInitialCapacity, space);
3399 }
3400 static RawGrowableObjectArray* New(intptr_t capacity,
3401 Heap::Space space = Heap::kNew);
3402
3403 private:
3404 RawArray* data() const { return raw_ptr()->data_; }
3405 void SetLength(intptr_t value) const {
3406 // This is only safe because we create a new Smi, which does not cause
3407 // heap allocation.
3408 raw_ptr()->length_ = Smi::New(value);
3409 }
3410 void SetData(const Array& value) const {
3411 StorePointer(&raw_ptr()->data_, value.raw());
3412 }
3413 RawArray* DataArray() const { return data()->ptr(); }
3414 RawObject** ObjectAddr(intptr_t index) const {
3415 ASSERT((index >= 0) && (index < Length()));
3416 return &(DataArray()->data()[index]);
3417 }
3418
3419 static const int kDefaultInitialCapacity = 4;
3420
3421 HEAP_OBJECT_IMPLEMENTATION(GrowableObjectArray, Instance);
3422 friend class Class;
3423 friend class Array;
3424 };
3425
3426
3338 class ByteArray : public Instance { 3427 class ByteArray : public Instance {
3339 public: 3428 public:
3340 virtual intptr_t Length() const; 3429 virtual intptr_t Length() const;
3341 3430
3342 static void Copy(uint8_t* dst, 3431 static void Copy(uint8_t* dst,
3343 const ByteArray& src, 3432 const ByteArray& src,
3344 intptr_t src_offset, 3433 intptr_t src_offset,
3345 intptr_t length); 3434 intptr_t length);
3346 3435
3347 static void Copy(const ByteArray& dst, 3436 static void Copy(const ByteArray& dst,
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
3806 } 3895 }
3807 3896
3808 3897
3809 void Context::SetAt(intptr_t index, const Instance& value) const { 3898 void Context::SetAt(intptr_t index, const Instance& value) const {
3810 StorePointer(InstanceAddr(index), value.raw()); 3899 StorePointer(InstanceAddr(index), value.raw());
3811 } 3900 }
3812 3901
3813 } // namespace dart 3902 } // namespace dart
3814 3903
3815 #endif // VM_OBJECT_H_ 3904 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « vm/class_finalizer_test.cc ('k') | vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698