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

Side by Side Diff: vm/object.h

Issue 9139067: Use special allocation functions for object creation while deserializing from a full snapshot in ... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 8 years, 11 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 | « no previous file | 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 kUnwindErrorClass, 161 kUnwindErrorClass,
162 kMaxId, 162 kMaxId,
163 kInvalidIndex = -1, 163 kInvalidIndex = -1,
164 }; 164 };
165 165
166 virtual ~Object() { } 166 virtual ~Object() { }
167 167
168 RawObject* raw() const { return raw_; } 168 RawObject* raw() const { return raw_; }
169 void operator=(RawObject* value) { SetRaw(value); } 169 void operator=(RawObject* value) { SetRaw(value); }
170 170
171 void set_tags(intptr_t value) { 171 void set_tags(intptr_t value) const {
172 // TODO(asiva): Remove the capability of setting tags in general. The mask 172 // TODO(asiva): Remove the capability of setting tags in general. The mask
173 // here only allows for canonical and from_snapshot flags to be set. 173 // here only allows for canonical and from_snapshot flags to be set.
174 ASSERT(!IsNull()); 174 ASSERT(!IsNull());
175 uword tags = raw()->ptr()->tags_ & ~0x0000000c; 175 uword tags = raw()->ptr()->tags_ & ~0x0000000c;
176 raw()->ptr()->tags_ = tags | (value & 0x0000000c); 176 raw()->ptr()->tags_ = tags | (value & 0x0000000c);
177 } 177 }
178 void SetCreatedFromSnapshot() const { 178 void SetCreatedFromSnapshot() const {
179 ASSERT(!IsNull()); 179 ASSERT(!IsNull());
180 raw()->SetCreatedFromSnapshot(); 180 raw()->SetCreatedFromSnapshot();
181 } 181 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 340
341 static RawObject* Allocate(const Class& cls, 341 static RawObject* Allocate(const Class& cls,
342 intptr_t size, 342 intptr_t size,
343 Heap::Space space); 343 Heap::Space space);
344 344
345 static intptr_t RoundedAllocationSize(intptr_t size) { 345 static intptr_t RoundedAllocationSize(intptr_t size) {
346 return Utils::RoundUp(size, kObjectAlignment); 346 return Utils::RoundUp(size, kObjectAlignment);
347 } 347 }
348 348
349 template<typename type> void StorePointer(type* addr, type value) const { 349 template<typename type> void StorePointer(type* addr, type value) const {
350 ASSERT(Isolate::Current()->no_gc_scope_depth() == 0);
351 // TODO(iposva): Implement real store barrier here. 350 // TODO(iposva): Implement real store barrier here.
352 *addr = value; 351 *addr = value;
353 // Filter stores based on source and target. 352 // Filter stores based on source and target.
354 if (value->IsNewObject() && raw()->IsOldObject()) { 353 if (value->IsNewObject() && raw()->IsOldObject()) {
355 uword ptr = reinterpret_cast<uword>(addr); 354 uword ptr = reinterpret_cast<uword>(addr);
356 Isolate::Current()->store_buffer()->AddPointer(ptr); 355 Isolate::Current()->store_buffer()->AddPointer(ptr);
357 } 356 }
358 } 357 }
359 358
360 RawObject* raw_; // The raw object reference. 359 RawObject* raw_; // The raw object reference.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 static RawClass* var_descriptors_class_; // Class of LocalVarDescriptors. 398 static RawClass* var_descriptors_class_; // Class of LocalVarDescriptors.
400 static RawClass* exception_handlers_class_; // Class of ExceptionHandlers. 399 static RawClass* exception_handlers_class_; // Class of ExceptionHandlers.
401 static RawClass* context_class_; // Class of the Context vm object. 400 static RawClass* context_class_; // Class of the Context vm object.
402 static RawClass* context_scope_class_; // Class of ContextScope vm object. 401 static RawClass* context_scope_class_; // Class of ContextScope vm object.
403 static RawClass* api_error_class_; // Class of ApiError. 402 static RawClass* api_error_class_; // Class of ApiError.
404 static RawClass* language_error_class_; // Class of LanguageError. 403 static RawClass* language_error_class_; // Class of LanguageError.
405 static RawClass* unhandled_exception_class_; // Class of UnhandledException. 404 static RawClass* unhandled_exception_class_; // Class of UnhandledException.
406 static RawClass* unwind_error_class_; // Class of UnwindError. 405 static RawClass* unwind_error_class_; // Class of UnwindError.
407 406
408 friend void RawObject::Validate() const; 407 friend void RawObject::Validate() const;
408 friend class SnapshotReader;
409 409
410 // Disallow allocation. 410 // Disallow allocation.
411 void* operator new(size_t size); 411 void* operator new(size_t size);
412 // Disallow copy constructor. 412 // Disallow copy constructor.
413 DISALLOW_COPY_AND_ASSIGN(Object); 413 DISALLOW_COPY_AND_ASSIGN(Object);
414 }; 414 };
415 415
416 416
417 class Class : public Object { 417 class Class : public Object {
418 public: 418 public:
(...skipping 2325 matching lines...) Expand 10 before | Expand all | Expand 10 after
2744 raw_ptr()->length_ = Smi::New(value); 2744 raw_ptr()->length_ = Smi::New(value);
2745 } 2745 }
2746 2746
2747 void SetHash(intptr_t value) const { 2747 void SetHash(intptr_t value) const {
2748 // This is only safe because we create a new Smi, which does not cause 2748 // This is only safe because we create a new Smi, which does not cause
2749 // heap allocation. 2749 // heap allocation.
2750 raw_ptr()->hash_ = Smi::New(value); 2750 raw_ptr()->hash_ = Smi::New(value);
2751 } 2751 }
2752 2752
2753 template<typename HandleType, typename ElementType> 2753 template<typename HandleType, typename ElementType>
2754 static RawString* ReadFromImpl(SnapshotReader* reader, 2754 static void ReadFromImpl(SnapshotReader* reader,
2755 intptr_t object_id, 2755 HandleType* str_obj,
2756 intptr_t tags, 2756 intptr_t len,
2757 Snapshot::Kind kind); 2757 intptr_t tags);
2758 2758
2759 HEAP_OBJECT_IMPLEMENTATION(String, Instance); 2759 HEAP_OBJECT_IMPLEMENTATION(String, Instance);
2760 }; 2760 };
2761 2761
2762 2762
2763 class OneByteString : public String { 2763 class OneByteString : public String {
2764 public: 2764 public:
2765 virtual int32_t CharAt(intptr_t index) const { 2765 virtual int32_t CharAt(intptr_t index) const {
2766 return *CharAddr(index); 2766 return *CharAddr(index);
2767 } 2767 }
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
3115 static intptr_t InstanceSize(intptr_t len) { 3115 static intptr_t InstanceSize(intptr_t len) {
3116 // Ensure that variable length data is not adding to the object length. 3116 // Ensure that variable length data is not adding to the object length.
3117 ASSERT(sizeof(RawArray) == (sizeof(RawObject) + (2 * kWordSize))); 3117 ASSERT(sizeof(RawArray) == (sizeof(RawObject) + (2 * kWordSize)));
3118 return RoundedAllocationSize(sizeof(RawArray) + (len * kWordSize)); 3118 return RoundedAllocationSize(sizeof(RawArray) + (len * kWordSize));
3119 } 3119 }
3120 3120
3121 // Make the array immutable to Dart code by switching the class pointer 3121 // Make the array immutable to Dart code by switching the class pointer
3122 // to ImmutableArray. 3122 // to ImmutableArray.
3123 void MakeImmutable() const; 3123 void MakeImmutable() const;
3124 3124
3125 static RawArray* New(intptr_t len, Heap::Space space = Heap::kNew) { 3125 static RawArray* New(intptr_t len, Heap::Space space = Heap::kNew);
3126 return New(len, false, space);
3127 }
3128 3126
3129 // Creates and returns a new array with 'new_length'. Copies all elements from 3127 // Creates and returns a new array with 'new_length'. Copies all elements from
3130 // 'source' to the new array. 'new_length' must be greater than or equal to 3128 // 'source' to the new array. 'new_length' must be greater than or equal to
3131 // 'source.Length()'. 'source' can be null. 3129 // 'source.Length()'. 'source' can be null.
3132 static RawArray* Grow(const Array& source, 3130 static RawArray* Grow(const Array& source,
3133 int new_length, 3131 int new_length,
3134 Heap::Space space = Heap::kNew); 3132 Heap::Space space = Heap::kNew);
3135 3133
3136 // Returns the preallocated empty array, used to initialize array fields. 3134 // Returns the preallocated empty array, used to initialize array fields.
3137 static RawArray* Empty(); 3135 static RawArray* Empty();
3138 3136
3139 protected: 3137 protected:
3140 static RawArray* New(intptr_t len, 3138 static RawArray* New(const Class& cls,
3141 bool immutable, 3139 intptr_t len,
3142 Heap::Space space = Heap::kNew); 3140 Heap::Space space = Heap::kNew);
3143 3141
3144 private: 3142 private:
3145 // Make sure that the array size cannot wrap around. 3143 // Make sure that the array size cannot wrap around.
3146 static const intptr_t kMaxArrayElements = 512 * 1024 * 1024; 3144 static const intptr_t kMaxArrayElements = 512 * 1024 * 1024;
3147 3145
3148 RawObject** ObjectAddr(intptr_t index) const { 3146 RawObject** ObjectAddr(intptr_t index) const {
3149 // TODO(iposva): Determine if we should throw an exception here. 3147 // TODO(iposva): Determine if we should throw an exception here.
3150 ASSERT((index >= 0) && (index < Length())); 3148 ASSERT((index >= 0) && (index < Length()));
3151 return &raw_ptr()->data()[index]; 3149 return &raw_ptr()->data()[index];
3152 } 3150 }
3153 3151
3154 void SetLength(intptr_t value) { 3152 void SetLength(intptr_t value) {
3155 // This is only safe because we create a new Smi, which does not cause 3153 // This is only safe because we create a new Smi, which does not cause
3156 // heap allocation. 3154 // heap allocation.
3157 raw_ptr()->length_ = Smi::New(value); 3155 raw_ptr()->length_ = Smi::New(value);
3158 } 3156 }
3159 3157
3160 HEAP_OBJECT_IMPLEMENTATION(Array, Instance); 3158 HEAP_OBJECT_IMPLEMENTATION(Array, Instance);
3161 friend class Class; 3159 friend class Class;
3162 }; 3160 };
3163 3161
3164 3162
3165 class ImmutableArray : public Array { 3163 class ImmutableArray : public Array {
3166 public: 3164 public:
3167 static RawImmutableArray* New(intptr_t len, Heap::Space space = Heap::kNew) { 3165 static RawImmutableArray* New(intptr_t len, Heap::Space space = Heap::kNew);
3168 return reinterpret_cast<RawImmutableArray*>(Array::New(len, true, space));
3169 }
3170 3166
3171 private: 3167 private:
3172 HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array); 3168 HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array);
3173 friend class Class; 3169 friend class Class;
3174 }; 3170 };
3175 3171
3176 3172
3177 class ByteBuffer : public Instance { 3173 class ByteBuffer : public Instance {
3178 public: 3174 public:
3179 intptr_t Length() const { 3175 intptr_t Length() const {
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
3444 } 3440 }
3445 3441
3446 3442
3447 void Context::SetAt(intptr_t index, const Instance& value) const { 3443 void Context::SetAt(intptr_t index, const Instance& value) const {
3448 StorePointer(InstanceAddr(index), value.raw()); 3444 StorePointer(InstanceAddr(index), value.raw());
3449 } 3445 }
3450 3446
3451 } // namespace dart 3447 } // namespace dart
3452 3448
3453 #endif // VM_OBJECT_H_ 3449 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « no previous file | vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698