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

Side by Side Diff: runtime/vm/object.cc

Issue 10521004: Eliminate RawObject::class_ field entirely. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 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
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 "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 Isolate::Current()->object_store()->set_empty_array(Array::Handle()); 265 Isolate::Current()->object_store()->set_empty_array(Array::Handle());
266 266
267 Class& cls = Class::Handle(); 267 Class& cls = Class::Handle();
268 268
269 // Allocate and initialize the class class. 269 // Allocate and initialize the class class.
270 { 270 {
271 intptr_t size = Class::InstanceSize(); 271 intptr_t size = Class::InstanceSize();
272 uword address = heap->Allocate(size, Heap::kOld); 272 uword address = heap->Allocate(size, Heap::kOld);
273 class_class_ = reinterpret_cast<RawClass*>(address + kHeapObjectTag); 273 class_class_ = reinterpret_cast<RawClass*>(address + kHeapObjectTag);
274 InitializeObject(address, Class::kInstanceKind, size); 274 InitializeObject(address, Class::kInstanceKind, size);
275 // Make the class_ field point to itself.
276 class_class_->ptr()->class_ = class_class_;
277 275
278 Class fake; 276 Class fake;
279 // Initialization from Class::New<Class>. 277 // Initialization from Class::New<Class>.
280 // Directly set raw_ to break a circular dependency: SetRaw will attempt 278 // Directly set raw_ to break a circular dependency: SetRaw will attempt
281 // to lookup class class in the class table where it is not registered yet. 279 // to lookup class class in the class table where it is not registered yet.
282 cls.raw_ = class_class_; 280 cls.raw_ = class_class_;
283 cls.set_handle_vtable(fake.vtable()); 281 cls.set_handle_vtable(fake.vtable());
284 cls.set_instance_size(Class::InstanceSize()); 282 cls.set_instance_size(Class::InstanceSize());
285 cls.set_next_field_offset(Class::InstanceSize()); 283 cls.set_next_field_offset(Class::InstanceSize());
286 cls.set_instance_kind(Class::kInstanceKind); 284 cls.set_instance_kind(Class::kInstanceKind);
287 cls.set_id(Class::kInstanceKind); 285 cls.set_id(Class::kInstanceKind);
288 cls.raw_ptr()->is_const_ = false; 286 cls.raw_ptr()->is_const_ = false;
289 cls.raw_ptr()->is_interface_ = false; 287 cls.raw_ptr()->is_interface_ = false;
290 cls.set_is_finalized(); 288 cls.set_is_finalized();
291 cls.raw_ptr()->type_arguments_instance_field_offset_ = 289 cls.raw_ptr()->type_arguments_instance_field_offset_ =
292 Class::kNoTypeArguments; 290 Class::kNoTypeArguments;
293 cls.raw_ptr()->num_native_fields_ = 0; 291 cls.raw_ptr()->num_native_fields_ = 0;
294 cls.InitEmptyFields(); 292 cls.InitEmptyFields();
295 Isolate::Current()->class_table()->Register(cls); 293 Isolate::Current()->class_table()->Register(cls);
296 } 294 }
297 295
298 // Allocate and initialize the null class. 296 // Allocate and initialize the null class.
299 cls = Class::New<Instance>(kNullClassId); 297 cls = Class::New<Instance>(kNullClassId);
300 cls.set_is_finalized(); 298 cls.set_is_finalized();
301 null_class_ = cls.raw(); 299 null_class_ = cls.raw();
302 300
303 // Complete initialization of null_ instance, i.e. initialize its class_
304 // field.
305 null_->ptr()->class_ = null_class_;
306
307 // Allocate and initialize the sentinel values of Null class. 301 // Allocate and initialize the sentinel values of Null class.
308 { 302 {
309 cls = null_class_; 303 cls = null_class_;
310 Instance& sentinel = Instance::Handle(); 304 Instance& sentinel = Instance::Handle();
311 sentinel ^= Object::Allocate(cls, Instance::InstanceSize(), Heap::kOld); 305 sentinel ^= Object::Allocate(cls, Instance::InstanceSize(), Heap::kOld);
312 sentinel_ = sentinel.raw(); 306 sentinel_ = sentinel.raw();
313 307
314 Instance& transition_sentinel = Instance::Handle(); 308 Instance& transition_sentinel = Instance::Handle();
315 transition_sentinel ^= 309 transition_sentinel ^=
316 Object::Allocate(cls, Instance::InstanceSize(), Heap::kOld); 310 Object::Allocate(cls, Instance::InstanceSize(), Heap::kOld);
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 // Use the preallocated out of memory exception to avoid calling 982 // Use the preallocated out of memory exception to avoid calling
989 // into dart code or allocating any code. 983 // into dart code or allocating any code.
990 const Instance& exception = 984 const Instance& exception =
991 Instance::Handle(isolate->object_store()->out_of_memory()); 985 Instance::Handle(isolate->object_store()->out_of_memory());
992 Exceptions::Throw(exception); 986 Exceptions::Throw(exception);
993 UNREACHABLE(); 987 UNREACHABLE();
994 } 988 }
995 NoGCScope no_gc; 989 NoGCScope no_gc;
996 InitializeObject(address, cls.id(), size); 990 InitializeObject(address, cls.id(), size);
997 RawObject* raw_obj = reinterpret_cast<RawObject*>(address + kHeapObjectTag); 991 RawObject* raw_obj = reinterpret_cast<RawObject*>(address + kHeapObjectTag);
998 raw_obj->ptr()->class_ = cls.raw();
999 ASSERT(cls.id() == RawObject::ClassIdTag::decode(raw_obj->ptr()->tags_)); 992 ASSERT(cls.id() == RawObject::ClassIdTag::decode(raw_obj->ptr()->tags_));
1000 return raw_obj; 993 return raw_obj;
1001 } 994 }
1002 995
1003 996
1004 RawString* Class::Name() const { 997 RawString* Class::Name() const {
1005 if (raw_ptr()->name_ != String::null()) { 998 if (raw_ptr()->name_ != String::null()) {
1006 return raw_ptr()->name_; 999 return raw_ptr()->name_;
1007 } 1000 }
1008 ASSERT(class_class() != Class::null()); // class_class_ should be set up. 1001 ASSERT(class_class() != Class::null()); // class_class_ should be set up.
(...skipping 8017 matching lines...) Expand 10 before | Expand all | Expand 10 after
9026 return result.raw(); 9019 return result.raw();
9027 } 9020 }
9028 9021
9029 9022
9030 void Array::MakeImmutable() const { 9023 void Array::MakeImmutable() const {
9031 Isolate* isolate = Isolate::Current(); 9024 Isolate* isolate = Isolate::Current();
9032 const Class& cls = Class::Handle( 9025 const Class& cls = Class::Handle(
9033 isolate, isolate->object_store()->immutable_array_class()); 9026 isolate, isolate->object_store()->immutable_array_class());
9034 { 9027 {
9035 NoGCScope no_gc; 9028 NoGCScope no_gc;
9036 raw_ptr()->class_ = cls.raw();
9037 uword tags = raw_ptr()->tags_; 9029 uword tags = raw_ptr()->tags_;
9038 tags = RawObject::ClassIdTag::update(cls.id(), tags); 9030 tags = RawObject::ClassIdTag::update(cls.id(), tags);
9039 raw_ptr()->tags_ = tags; 9031 raw_ptr()->tags_ = tags;
9040 } 9032 }
9041 } 9033 }
9042 9034
9043 9035
9044 const char* Array::ToCString() const { 9036 const char* Array::ToCString() const {
9045 return "Array"; 9037 return "Array";
9046 } 9038 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
9097 if (capacity_size != used_size) { 9089 if (capacity_size != used_size) {
9098 ASSERT(capacity_len > used_len); 9090 ASSERT(capacity_len > used_len);
9099 intptr_t leftover_size = capacity_size - used_size; 9091 intptr_t leftover_size = capacity_size - used_size;
9100 9092
9101 uword addr = RawObject::ToAddr(array.raw()) + used_size; 9093 uword addr = RawObject::ToAddr(array.raw()) + used_size;
9102 if (leftover_size >= Array::InstanceSize(0)) { 9094 if (leftover_size >= Array::InstanceSize(0)) {
9103 // As we have enough space to use an array object, update the leftover 9095 // As we have enough space to use an array object, update the leftover
9104 // space as an Array object. 9096 // space as an Array object.
9105 RawArray* raw = reinterpret_cast<RawArray*>(RawObject::FromAddr(addr)); 9097 RawArray* raw = reinterpret_cast<RawArray*>(RawObject::FromAddr(addr));
9106 const Class& cls = Class::Handle(isolate->object_store()->array_class()); 9098 const Class& cls = Class::Handle(isolate->object_store()->array_class());
9107 raw->ptr()->class_ = cls.raw();
9108 tags = 0; 9099 tags = 0;
9109 tags = RawObject::SizeTag::update(leftover_size, tags); 9100 tags = RawObject::SizeTag::update(leftover_size, tags);
9110 tags = RawObject::ClassIdTag::update(cls.id(), tags); 9101 tags = RawObject::ClassIdTag::update(cls.id(), tags);
9111 raw->ptr()->tags_ = tags; 9102 raw->ptr()->tags_ = tags;
9112 intptr_t leftover_len = 9103 intptr_t leftover_len =
9113 ((leftover_size - Array::InstanceSize(0)) / kWordSize); 9104 ((leftover_size - Array::InstanceSize(0)) / kWordSize);
9114 raw->ptr()->tags_ = tags; 9105 raw->ptr()->tags_ = tags;
9115 raw->ptr()->length_ = Smi::New(leftover_len); 9106 raw->ptr()->length_ = Smi::New(leftover_len);
9116 } else { 9107 } else {
9117 // Update the leftover space as a basic object. 9108 // Update the leftover space as a basic object.
9118 ASSERT(leftover_size == Object::InstanceSize()); 9109 ASSERT(leftover_size == Object::InstanceSize());
9119 RawObject* raw = reinterpret_cast<RawObject*>(RawObject::FromAddr(addr)); 9110 RawObject* raw = reinterpret_cast<RawObject*>(RawObject::FromAddr(addr));
9120 const Class& cls = Class::Handle(isolate->object_store()->object_class()); 9111 const Class& cls = Class::Handle(isolate->object_store()->object_class());
9121 raw->ptr()->class_ = cls.raw();
9122 tags = 0; 9112 tags = 0;
9123 tags = RawObject::SizeTag::update(leftover_size, tags); 9113 tags = RawObject::SizeTag::update(leftover_size, tags);
9124 tags = RawObject::ClassIdTag::update(cls.id(), tags); 9114 tags = RawObject::ClassIdTag::update(cls.id(), tags);
9125 raw->ptr()->tags_ = tags; 9115 raw->ptr()->tags_ = tags;
9126 } 9116 }
9127 } 9117 }
9128 return array.raw(); 9118 return array.raw();
9129 } 9119 }
9130 9120
9131 9121
(...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after
10110 const String& str = String::Handle(pattern()); 10100 const String& str = String::Handle(pattern());
10111 const char* format = "JSRegExp: pattern=%s flags=%s"; 10101 const char* format = "JSRegExp: pattern=%s flags=%s";
10112 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); 10102 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags());
10113 char* chars = reinterpret_cast<char*>( 10103 char* chars = reinterpret_cast<char*>(
10114 Isolate::Current()->current_zone()->Allocate(len + 1)); 10104 Isolate::Current()->current_zone()->Allocate(len + 1));
10115 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); 10105 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags());
10116 return chars; 10106 return chars;
10117 } 10107 }
10118 10108
10119 } // namespace dart 10109 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698