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: runtime/vm/object.cc

Issue 11312183: - Do not mix scalar values and object fields in RawInstance to (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/bigint_operations.h" 10 #include "vm/bigint_operations.h"
(...skipping 1849 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 const String& name, 1860 const String& name,
1861 int field_count) { 1861 int field_count) {
1862 Class& cls = Class::Handle(library.LookupClass(name)); 1862 Class& cls = Class::Handle(library.LookupClass(name));
1863 if (cls.IsNull()) { 1863 if (cls.IsNull()) {
1864 const Array& empty_array = Array::Handle(Object::empty_array()); 1864 const Array& empty_array = Array::Handle(Object::empty_array());
1865 cls = New<Instance>(name, Script::Handle(), Scanner::kDummyTokenIndex); 1865 cls = New<Instance>(name, Script::Handle(), Scanner::kDummyTokenIndex);
1866 cls.SetFields(empty_array); 1866 cls.SetFields(empty_array);
1867 cls.SetFunctions(empty_array); 1867 cls.SetFunctions(empty_array);
1868 // Set super class to Object. 1868 // Set super class to Object.
1869 cls.set_super_type(Type::Handle(Type::ObjectType())); 1869 cls.set_super_type(Type::Handle(Type::ObjectType()));
1870 // Compute instance size. 1870 // Compute instance size. First word contains a pointer to a properly
1871 intptr_t instance_size = (field_count * kWordSize) + sizeof(RawObject); 1871 // sized typed array once the first native field has been set.
1872 intptr_t instance_size = sizeof(RawObject) + kWordSize;
1872 cls.set_instance_size(RoundedAllocationSize(instance_size)); 1873 cls.set_instance_size(RoundedAllocationSize(instance_size));
1873 cls.set_next_field_offset(instance_size); 1874 cls.set_next_field_offset(instance_size);
1874 cls.set_num_native_fields(field_count); 1875 cls.set_num_native_fields(field_count);
1875 cls.set_is_finalized(); 1876 cls.set_is_finalized();
1876 library.AddClass(cls); 1877 library.AddClass(cls);
1877 return cls.raw(); 1878 return cls.raw();
1878 } else { 1879 } else {
1879 return Class::null(); 1880 return Class::null();
1880 } 1881 }
1881 } 1882 }
(...skipping 6305 matching lines...) Expand 10 before | Expand all | Expand 10 after
8187 !other_type_arguments.IsInstantiated()) { 8188 !other_type_arguments.IsInstantiated()) {
8188 other_type_arguments = 8189 other_type_arguments =
8189 other_type_arguments.InstantiateFrom(other_instantiator); 8190 other_type_arguments.InstantiateFrom(other_instantiator);
8190 } 8191 }
8191 } 8192 }
8192 return cls.IsSubtypeOf(type_arguments, other_class, other_type_arguments, 8193 return cls.IsSubtypeOf(type_arguments, other_class, other_type_arguments,
8193 malformed_error); 8194 malformed_error);
8194 } 8195 }
8195 8196
8196 8197
8198 void Instance::SetNativeField(int index, intptr_t value) const {
8199 ASSERT(IsValidNativeIndex(index));
8200 Object& native_fields = Object::Handle(*NativeFieldsAddr());
8201 if (native_fields.IsNull()) {
8202 // Allocate backing storage for the native fields.
8203 const Class& cls = Class::Handle(clazz());
8204 int num_native_fields = cls.num_native_fields();
8205 native_fields = IntPtrArray::New(num_native_fields);
8206 StorePointer(NativeFieldsAddr(), native_fields.raw());
8207 }
8208 IntPtrArray::Cast(native_fields).SetAt(index, value);
8209 }
8210
8211
8197 bool Instance::IsClosure() const { 8212 bool Instance::IsClosure() const {
8198 const Class& cls = Class::Handle(clazz()); 8213 const Class& cls = Class::Handle(clazz());
8199 return cls.IsSignatureClass(); 8214 return cls.IsSignatureClass();
8200 } 8215 }
8201 8216
8202 8217
8203 RawInstance* Instance::New(const Class& cls, Heap::Space space) { 8218 RawInstance* Instance::New(const Class& cls, Heap::Space space) {
8204 Instance& result = Instance::Handle(); 8219 Instance& result = Instance::Handle();
8205 { 8220 {
8206 intptr_t instance_size = cls.instance_size(); 8221 intptr_t instance_size = cls.instance_size();
8207 ASSERT(instance_size > 0); 8222 ASSERT(instance_size > 0);
8208 RawObject* raw = Object::Allocate(cls.id(), instance_size, space); 8223 RawObject* raw = Object::Allocate(cls.id(), instance_size, space);
8209 NoGCScope no_gc; 8224 NoGCScope no_gc;
8210 result ^= raw; 8225 result ^= raw;
8211 uword addr = reinterpret_cast<uword>(result.raw_ptr());
8212 // Initialize fields.
8213 intptr_t offset = sizeof(RawObject);
8214 // Initialize all native fields to NULL.
8215 for (intptr_t i = 0; i < cls.num_native_fields(); i++) {
8216 *reinterpret_cast<uword*>(addr + offset) = 0;
8217 offset += kWordSize;
8218 }
8219 } 8226 }
8220 return result.raw(); 8227 return result.raw();
8221 } 8228 }
8222 8229
8223 8230
8224 bool Instance::IsValidFieldOffset(int offset) const { 8231 bool Instance::IsValidFieldOffset(int offset) const {
8225 const Class& cls = Class::Handle(clazz()); 8232 const Class& cls = Class::Handle(clazz());
8226 return (offset >= 0 && offset <= (cls.instance_size() - kWordSize)); 8233 return (offset >= 0 && offset <= (cls.instance_size() - kWordSize));
8227 } 8234 }
8228 8235
(...skipping 3754 matching lines...) Expand 10 before | Expand all | Expand 10 after
11983 } 11990 }
11984 return result.raw(); 11991 return result.raw();
11985 } 11992 }
11986 11993
11987 11994
11988 const char* WeakProperty::ToCString() const { 11995 const char* WeakProperty::ToCString() const {
11989 return "_WeakProperty"; 11996 return "_WeakProperty";
11990 } 11997 }
11991 11998
11992 } // namespace dart 11999 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698