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

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

Powered by Google App Engine
This is Rietveld 408576698