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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
===================================================================
--- runtime/vm/object.cc (revision 14777)
+++ runtime/vm/object.cc (working copy)
@@ -1867,8 +1867,9 @@
cls.SetFunctions(empty_array);
// Set super class to Object.
cls.set_super_type(Type::Handle(Type::ObjectType()));
- // Compute instance size.
- intptr_t instance_size = (field_count * kWordSize) + sizeof(RawObject);
+ // Compute instance size. First word contains a pointer to a properly
+ // sized typed array once the first native field has been set.
+ intptr_t instance_size = sizeof(RawObject) + kWordSize;
cls.set_instance_size(RoundedAllocationSize(instance_size));
cls.set_next_field_offset(instance_size);
cls.set_num_native_fields(field_count);
@@ -8194,6 +8195,20 @@
}
+void Instance::SetNativeField(int index, intptr_t value) const {
+ ASSERT(IsValidNativeIndex(index));
+ Object& native_fields = Object::Handle(*NativeFieldsAddr());
+ if (native_fields.IsNull()) {
+ // Allocate backing storage for the native fields.
+ const Class& cls = Class::Handle(clazz());
+ int num_native_fields = cls.num_native_fields();
+ native_fields = IntPtrArray::New(num_native_fields);
+ StorePointer(NativeFieldsAddr(), native_fields.raw());
+ }
+ IntPtrArray::Cast(native_fields).SetAt(index, value);
+}
+
+
bool Instance::IsClosure() const {
const Class& cls = Class::Handle(clazz());
return cls.IsSignatureClass();
@@ -8208,14 +8223,6 @@
RawObject* raw = Object::Allocate(cls.id(), instance_size, space);
NoGCScope no_gc;
result ^= raw;
- uword addr = reinterpret_cast<uword>(result.raw_ptr());
- // Initialize fields.
- intptr_t offset = sizeof(RawObject);
- // Initialize all native fields to NULL.
- for (intptr_t i = 0; i < cls.num_native_fields(); i++) {
- *reinterpret_cast<uword*>(addr + offset) = 0;
- offset += kWordSize;
- }
}
return result.raw();
}
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698