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

Side by Side Diff: vm/object.cc

Issue 11648006: Create read only handles for empty_array and sentinel objects (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 cpp_vtable Object::handle_vtable_ = 0; 52 cpp_vtable Object::handle_vtable_ = 0;
53 cpp_vtable Object::builtin_vtables_[kNumPredefinedCids] = { 0 }; 53 cpp_vtable Object::builtin_vtables_[kNumPredefinedCids] = { 0 };
54 cpp_vtable Smi::handle_vtable_ = 0; 54 cpp_vtable Smi::handle_vtable_ = 0;
55 55
56 // These are initialized to a value that will force a illegal memory access if 56 // These are initialized to a value that will force a illegal memory access if
57 // they are being used. 57 // they are being used.
58 #if defined(RAW_NULL) 58 #if defined(RAW_NULL)
59 #error RAW_NULL should not be defined. 59 #error RAW_NULL should not be defined.
60 #endif 60 #endif
61 #define RAW_NULL kHeapObjectTag 61 #define RAW_NULL kHeapObjectTag
62 RawObject* Object::null_ = reinterpret_cast<RawInstance*>(RAW_NULL); 62 Array* Object::empty_array_ = NULL;
63 RawArray* Object::empty_array_ = reinterpret_cast<RawArray*>(RAW_NULL); 63 Instance* Object::sentinel_ = NULL;
64 RawInstance* Object::sentinel_ = reinterpret_cast<RawInstance*>(RAW_NULL); 64 Instance* Object::transition_sentinel_ = NULL;
65 RawInstance* Object::transition_sentinel_ = 65
66 reinterpret_cast<RawInstance*>(RAW_NULL); 66 RawObject* Object::null_ = reinterpret_cast<RawObject*>(RAW_NULL);
67 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 67 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
68 RawClass* Object::null_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 68 RawClass* Object::null_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
69 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 69 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
70 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 70 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
71 RawClass* Object::unresolved_class_class_ = 71 RawClass* Object::unresolved_class_class_ =
72 reinterpret_cast<RawClass*>(RAW_NULL); 72 reinterpret_cast<RawClass*>(RAW_NULL);
73 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 73 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
74 RawClass* Object::instantiated_type_arguments_class_ = 74 RawClass* Object::instantiated_type_arguments_class_ =
75 reinterpret_cast<RawClass*>(RAW_NULL); 75 reinterpret_cast<RawClass*>(RAW_NULL);
76 RawClass* Object::patch_class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 76 RawClass* Object::patch_class_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // TODO(iposva): NoGCScope needs to be added here. 233 // TODO(iposva): NoGCScope needs to be added here.
234 ASSERT(class_class() == null_); 234 ASSERT(class_class() == null_);
235 // Initialize the static vtable values. 235 // Initialize the static vtable values.
236 { 236 {
237 Object fake_object; 237 Object fake_object;
238 Smi fake_smi; 238 Smi fake_smi;
239 Object::handle_vtable_ = fake_object.vtable(); 239 Object::handle_vtable_ = fake_object.vtable();
240 Smi::handle_vtable_ = fake_smi.vtable(); 240 Smi::handle_vtable_ = fake_smi.vtable();
241 } 241 }
242 242
243 // Allocate the read only object handles here.
244 empty_array_ = reinterpret_cast<Array*>(Dart::AllocateReadOnlyHandle());
245 sentinel_ = reinterpret_cast<Instance*>(Dart::AllocateReadOnlyHandle());
246 transition_sentinel_ =
247 reinterpret_cast<Instance*>(Dart::AllocateReadOnlyHandle());
248
243 Isolate* isolate = Isolate::Current(); 249 Isolate* isolate = Isolate::Current();
244 Heap* heap = isolate->heap(); 250 Heap* heap = isolate->heap();
245 // Allocate and initialize the null instance. 251 // Allocate and initialize the null instance.
246 // 'null_' must be the first object allocated as it is used in allocation to 252 // 'null_' must be the first object allocated as it is used in allocation to
247 // clear the object. 253 // clear the object.
248 { 254 {
249 uword address = heap->Allocate(Instance::InstanceSize(), Heap::kOld); 255 uword address = heap->Allocate(Instance::InstanceSize(), Heap::kOld);
250 null_ = reinterpret_cast<RawInstance*>(address + kHeapObjectTag); 256 null_ = reinterpret_cast<RawInstance*>(address + kHeapObjectTag);
251 // The call below is using 'null_' to initialize itself. 257 // The call below is using 'null_' to initialize itself.
252 InitializeObject(address, kNullCid, Instance::InstanceSize()); 258 InitializeObject(address, kNullCid, Instance::InstanceSize());
253 } 259 }
254 260
255 // Initialize object_store empty array to null_ in order to be able to check 261 // Initialize the empty array handle to null_ in order to be able to check
256 // if the empty array was allocated (RAW_NULL is not available). 262 // if the empty array was allocated (RAW_NULL is not available).
257 empty_array_ = Array::null(); 263 *empty_array_ = Array::null();
258 264
259 Class& cls = Class::Handle(); 265 Class& cls = Class::Handle();
260 266
261 // Allocate and initialize the class class. 267 // Allocate and initialize the class class.
262 { 268 {
263 intptr_t size = Class::InstanceSize(); 269 intptr_t size = Class::InstanceSize();
264 uword address = heap->Allocate(size, Heap::kOld); 270 uword address = heap->Allocate(size, Heap::kOld);
265 class_class_ = reinterpret_cast<RawClass*>(address + kHeapObjectTag); 271 class_class_ = reinterpret_cast<RawClass*>(address + kHeapObjectTag);
266 InitializeObject(address, Class::kClassId, size); 272 InitializeObject(address, Class::kClassId, size);
267 273
(...skipping 19 matching lines...) Expand all
287 cls = Class::New<Instance>(kNullCid); 293 cls = Class::New<Instance>(kNullCid);
288 cls.set_is_finalized(); 294 cls.set_is_finalized();
289 null_class_ = cls.raw(); 295 null_class_ = cls.raw();
290 296
291 // Allocate and initialize the free list element class. 297 // Allocate and initialize the free list element class.
292 cls = Class::New<FreeListElement::FakeInstance>(kFreeListElement); 298 cls = Class::New<FreeListElement::FakeInstance>(kFreeListElement);
293 cls.set_is_finalized(); 299 cls.set_is_finalized();
294 300
295 // Allocate and initialize the sentinel values of Null class. 301 // Allocate and initialize the sentinel values of Null class.
296 { 302 {
297 Instance& sentinel = Instance::Handle(); 303 *sentinel_ ^=
298 sentinel ^=
299 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); 304 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld);
300 sentinel_ = sentinel.raw();
301 305
302 Instance& transition_sentinel = Instance::Handle(); 306 *transition_sentinel_ ^=
303 transition_sentinel ^=
304 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); 307 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld);
305 transition_sentinel_ = transition_sentinel.raw();
306 } 308 }
307 309
308 cls = Class::New<Instance>(kDynamicCid); 310 cls = Class::New<Instance>(kDynamicCid);
309 cls.set_is_finalized(); 311 cls.set_is_finalized();
310 cls.set_is_abstract(); 312 cls.set_is_abstract();
311 dynamic_class_ = cls.raw(); 313 dynamic_class_ = cls.raw();
312 314
313 // Allocate the remaining VM internal classes. 315 // Allocate the remaining VM internal classes.
314 cls = Class::New<UnresolvedClass>(); 316 cls = Class::New<UnresolvedClass>();
315 unresolved_class_class_ = cls.raw(); 317 unresolved_class_class_ = cls.raw();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 cls = Class::New<Array>(); 415 cls = Class::New<Array>();
414 isolate->object_store()->set_array_class(cls); 416 isolate->object_store()->set_array_class(cls);
415 cls = Class::NewStringClass(kOneByteStringCid); 417 cls = Class::NewStringClass(kOneByteStringCid);
416 isolate->object_store()->set_one_byte_string_class(cls); 418 isolate->object_store()->set_one_byte_string_class(cls);
417 cls = Class::NewStringClass(kTwoByteStringCid); 419 cls = Class::NewStringClass(kTwoByteStringCid);
418 isolate->object_store()->set_two_byte_string_class(cls); 420 isolate->object_store()->set_two_byte_string_class(cls);
419 421
420 // Allocate and initialize the empty_array instance. 422 // Allocate and initialize the empty_array instance.
421 { 423 {
422 uword address = heap->Allocate(Array::InstanceSize(0), Heap::kOld); 424 uword address = heap->Allocate(Array::InstanceSize(0), Heap::kOld);
423 empty_array_ = reinterpret_cast<RawArray*>(address + kHeapObjectTag); 425 *empty_array_ = reinterpret_cast<RawArray*>(address + kHeapObjectTag);
424 InitializeObject(address, kArrayCid, Array::InstanceSize(0)); 426 InitializeObject(address, kArrayCid, Array::InstanceSize(0));
425 empty_array_->ptr()->length_ = Smi::New(0); 427 empty_array_->raw()->ptr()->length_ = Smi::New(0);
426 } 428 }
427 } 429 }
428 430
429 431
430 #define SET_CLASS_NAME(class_name, name) \ 432 #define SET_CLASS_NAME(class_name, name) \
431 cls = class_name##_class(); \ 433 cls = class_name##_class(); \
432 str = Symbols::name(); \ 434 str = Symbols::name(); \
433 cls.set_name(str); \ 435 cls.set_name(str); \
434 436
435 void Object::RegisterSingletonClassNames() { 437 void Object::RegisterSingletonClassNames() {
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 } 1250 }
1249 } 1251 }
1250 1252
1251 private: 1253 private:
1252 DISALLOW_COPY_AND_ASSIGN(StoreBufferObjectPointerVisitor); 1254 DISALLOW_COPY_AND_ASSIGN(StoreBufferObjectPointerVisitor);
1253 }; 1255 };
1254 1256
1255 1257
1256 bool Object::IsNotTemporaryScopedHandle() const { 1258 bool Object::IsNotTemporaryScopedHandle() const {
1257 return (IsZoneHandle() || 1259 return (IsZoneHandle() ||
1258 Symbols::IsPredefinedHandle(reinterpret_cast<uword>(this))); 1260 Dart::IsReadOnlyHandle(reinterpret_cast<uword>(this)));
Ivan Posva 2012/12/20 23:43:52 Could we have a IsReadOnlyHandle similar to IsZone
siva 2012/12/21 02:28:06 Added IsReadOnlyHandle method to Object. Regardin
Ivan Posva 2012/12/21 07:33:41 I find the name confusing on two fronts: - The Not
1259 } 1261 }
1260 1262
1261 1263
1262 1264
1263 RawObject* Object::Clone(const Object& src, Heap::Space space) { 1265 RawObject* Object::Clone(const Object& src, Heap::Space space) {
1264 const Class& cls = Class::Handle(src.clazz()); 1266 const Class& cls = Class::Handle(src.clazz());
1265 intptr_t size = src.raw()->Size(); 1267 intptr_t size = src.raw()->Size();
1266 RawObject* raw_obj = Object::Allocate(cls.id(), size, space); 1268 RawObject* raw_obj = Object::Allocate(cls.id(), size, space);
1267 NoGCScope no_gc; 1269 NoGCScope no_gc;
1268 memmove(raw_obj->ptr(), src.raw()->ptr(), size); 1270 memmove(raw_obj->ptr(), src.raw()->ptr(), size);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 result.raw_ptr()->num_native_fields_ = 0; 1413 result.raw_ptr()->num_native_fields_ = 0;
1412 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex; 1414 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex;
1413 result.InitEmptyFields(); 1415 result.InitEmptyFields();
1414 Isolate::Current()->class_table()->Register(result); 1416 Isolate::Current()->class_table()->Register(result);
1415 return result.raw(); 1417 return result.raw();
1416 } 1418 }
1417 1419
1418 1420
1419 // Initialize class fields of type Array with empty array. 1421 // Initialize class fields of type Array with empty array.
1420 void Class::InitEmptyFields() { 1422 void Class::InitEmptyFields() {
1421 if (Object::empty_array() == Array::null()) { 1423 if (Object::empty_array().raw() == Array::null()) {
1422 // The empty array has not been initialized yet. 1424 // The empty array has not been initialized yet.
1423 return; 1425 return;
1424 } 1426 }
1425 StorePointer(&raw_ptr()->interfaces_, Object::empty_array()); 1427 StorePointer(&raw_ptr()->interfaces_, Object::empty_array().raw());
1426 StorePointer(&raw_ptr()->constants_, Object::empty_array()); 1428 StorePointer(&raw_ptr()->constants_, Object::empty_array().raw());
1427 StorePointer(&raw_ptr()->canonical_types_, Object::empty_array()); 1429 StorePointer(&raw_ptr()->canonical_types_, Object::empty_array().raw());
1428 StorePointer(&raw_ptr()->functions_, Object::empty_array()); 1430 StorePointer(&raw_ptr()->functions_, Object::empty_array().raw());
1429 StorePointer(&raw_ptr()->fields_, Object::empty_array()); 1431 StorePointer(&raw_ptr()->fields_, Object::empty_array().raw());
1430 } 1432 }
1431 1433
1432 1434
1433 bool Class::HasInstanceFields() const { 1435 bool Class::HasInstanceFields() const {
1434 const Array& field_array = Array::Handle(fields()); 1436 const Array& field_array = Array::Handle(fields());
1435 Field& field = Field::Handle(); 1437 Field& field = Field::Handle();
1436 for (intptr_t i = 0; i < field_array.Length(); ++i) { 1438 for (intptr_t i = 0; i < field_array.Length(); ++i) {
1437 field ^= field_array.At(i); 1439 field ^= field_array.At(i);
1438 if (!field.is_static()) { 1440 if (!field.is_static()) {
1439 return true; 1441 return true;
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
1833 // way as the owner class of its non-static signature function. 1835 // way as the owner class of its non-static signature function.
1834 // It is not type parameterized if its signature function is static. 1836 // It is not type parameterized if its signature function is static.
1835 if (!signature_function.is_static() && 1837 if (!signature_function.is_static() &&
1836 (owner_class.NumTypeParameters() > 0) && 1838 (owner_class.NumTypeParameters() > 0) &&
1837 !signature_function.HasInstantiatedSignature()) { 1839 !signature_function.HasInstantiatedSignature()) {
1838 type_parameters = owner_class.type_parameters(); 1840 type_parameters = owner_class.type_parameters();
1839 } 1841 }
1840 const intptr_t token_pos = signature_function.token_pos(); 1842 const intptr_t token_pos = signature_function.token_pos();
1841 Class& result = Class::Handle(New<Instance>(name, script, token_pos)); 1843 Class& result = Class::Handle(New<Instance>(name, script, token_pos));
1842 const Type& super_type = Type::Handle(Type::ObjectType()); 1844 const Type& super_type = Type::Handle(Type::ObjectType());
1843 const Array& empty_array = Array::Handle(Object::empty_array());
1844 ASSERT(!super_type.IsNull()); 1845 ASSERT(!super_type.IsNull());
1845 result.set_instance_size(Closure::InstanceSize()); 1846 result.set_instance_size(Closure::InstanceSize());
1846 result.set_next_field_offset(Closure::InstanceSize()); 1847 result.set_next_field_offset(Closure::InstanceSize());
1847 result.set_super_type(super_type); 1848 result.set_super_type(super_type);
1848 result.set_signature_function(signature_function); 1849 result.set_signature_function(signature_function);
1849 result.set_type_parameters(type_parameters); 1850 result.set_type_parameters(type_parameters);
1850 result.SetFields(empty_array); 1851 result.SetFields(Object::empty_array());
1851 result.SetFunctions(empty_array); 1852 result.SetFunctions(Object::empty_array());
1852 result.set_type_arguments_field_offset( 1853 result.set_type_arguments_field_offset(
1853 Closure::type_arguments_offset()); 1854 Closure::type_arguments_offset());
1854 // Implements interface "Function". 1855 // Implements interface "Function".
1855 const Type& function_type = Type::Handle(Type::Function()); 1856 const Type& function_type = Type::Handle(Type::Function());
1856 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); 1857 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld));
1857 interfaces.SetAt(0, function_type); 1858 interfaces.SetAt(0, function_type);
1858 result.set_interfaces(interfaces); 1859 result.set_interfaces(interfaces);
1859 // Unless the signature function already has a signature class, create a 1860 // Unless the signature function already has a signature class, create a
1860 // canonical signature class by having the signature function point back to 1861 // canonical signature class by having the signature function point back to
1861 // the signature class. 1862 // the signature class.
(...skipping 17 matching lines...) Expand all
1879 result.set_canonical_types(new_canonical_types); 1880 result.set_canonical_types(new_canonical_types);
1880 return result.raw(); 1881 return result.raw();
1881 } 1882 }
1882 1883
1883 1884
1884 RawClass* Class::NewNativeWrapper(const Library& library, 1885 RawClass* Class::NewNativeWrapper(const Library& library,
1885 const String& name, 1886 const String& name,
1886 int field_count) { 1887 int field_count) {
1887 Class& cls = Class::Handle(library.LookupClass(name)); 1888 Class& cls = Class::Handle(library.LookupClass(name));
1888 if (cls.IsNull()) { 1889 if (cls.IsNull()) {
1889 const Array& empty_array = Array::Handle(Object::empty_array());
1890 cls = New<Instance>(name, Script::Handle(), Scanner::kDummyTokenIndex); 1890 cls = New<Instance>(name, Script::Handle(), Scanner::kDummyTokenIndex);
1891 cls.SetFields(empty_array); 1891 cls.SetFields(Object::empty_array());
1892 cls.SetFunctions(empty_array); 1892 cls.SetFunctions(Object::empty_array());
1893 // Set super class to Object. 1893 // Set super class to Object.
1894 cls.set_super_type(Type::Handle(Type::ObjectType())); 1894 cls.set_super_type(Type::Handle(Type::ObjectType()));
1895 // Compute instance size. First word contains a pointer to a properly 1895 // Compute instance size. First word contains a pointer to a properly
1896 // sized typed array once the first native field has been set. 1896 // sized typed array once the first native field has been set.
1897 intptr_t instance_size = sizeof(RawObject) + kWordSize; 1897 intptr_t instance_size = sizeof(RawObject) + kWordSize;
1898 cls.set_instance_size(RoundedAllocationSize(instance_size)); 1898 cls.set_instance_size(RoundedAllocationSize(instance_size));
1899 cls.set_next_field_offset(instance_size); 1899 cls.set_next_field_offset(instance_size);
1900 cls.set_num_native_fields(field_count); 1900 cls.set_num_native_fields(field_count);
1901 cls.set_is_finalized(); 1901 cls.set_is_finalized();
1902 library.AddClass(cls); 1902 library.AddClass(cls);
(...skipping 2029 matching lines...) Expand 10 before | Expand all | Expand 10 after
3932 RawFunction::Kind kind, 3932 RawFunction::Kind kind,
3933 bool is_static, 3933 bool is_static,
3934 bool is_const, 3934 bool is_const,
3935 bool is_abstract, 3935 bool is_abstract,
3936 bool is_external, 3936 bool is_external,
3937 const Object& owner, 3937 const Object& owner,
3938 intptr_t token_pos) { 3938 intptr_t token_pos) {
3939 ASSERT(name.IsOneByteString()); 3939 ASSERT(name.IsOneByteString());
3940 ASSERT(!owner.IsNull()); 3940 ASSERT(!owner.IsNull());
3941 const Function& result = Function::Handle(Function::New()); 3941 const Function& result = Function::Handle(Function::New());
3942 const Array& empty_array = Array::Handle(Object::empty_array()); 3942 result.set_parameter_types(Object::empty_array());
3943 result.set_parameter_types(empty_array); 3943 result.set_parameter_names(Object::empty_array());
3944 result.set_parameter_names(empty_array);
3945 result.set_name(name); 3944 result.set_name(name);
3946 result.set_kind(kind); 3945 result.set_kind(kind);
3947 result.set_is_static(is_static); 3946 result.set_is_static(is_static);
3948 result.set_is_const(is_const); 3947 result.set_is_const(is_const);
3949 result.set_is_abstract(is_abstract); 3948 result.set_is_abstract(is_abstract);
3950 result.set_is_external(is_external); 3949 result.set_is_external(is_external);
3951 result.set_intrinsic_kind(kUnknownIntrinsic); 3950 result.set_intrinsic_kind(kUnknownIntrinsic);
3952 result.set_owner(owner); 3951 result.set_owner(owner);
3953 result.set_token_pos(token_pos); 3952 result.set_token_pos(token_pos);
3954 result.set_end_token_pos(token_pos); 3953 result.set_end_token_pos(token_pos);
(...skipping 1997 matching lines...) Expand 10 before | Expand all | Expand 10 after
5952 } 5951 }
5953 intptr_t index = num_imports(); 5952 intptr_t index = num_imports();
5954 imports.SetAt(index, ns); 5953 imports.SetAt(index, ns);
5955 set_num_imports(index + 1); 5954 set_num_imports(index + 1);
5956 } 5955 }
5957 5956
5958 5957
5959 // Convenience function to determine whether the export list is 5958 // Convenience function to determine whether the export list is
5960 // non-empty. 5959 // non-empty.
5961 bool Library::HasExports() const { 5960 bool Library::HasExports() const {
5962 return exports() != Object::empty_array(); 5961 return exports() != Object::empty_array().raw();
5963 } 5962 }
5964 5963
5965 5964
5966 // We add one namespace at a time to the exports array and don't 5965 // We add one namespace at a time to the exports array and don't
5967 // pre-allocate any unused capacity. The assumption is that 5966 // pre-allocate any unused capacity. The assumption is that
5968 // re-exports are quite rare. 5967 // re-exports are quite rare.
5969 void Library::AddExport(const Namespace& ns) const { 5968 void Library::AddExport(const Namespace& ns) const {
5970 Array &exports = Array::Handle(this->exports()); 5969 Array &exports = Array::Handle(this->exports());
5971 intptr_t num_exports = exports.Length(); 5970 intptr_t num_exports = exports.Length();
5972 exports = Array::Grow(exports, num_exports + 1); 5971 exports = Array::Grow(exports, num_exports + 1);
(...skipping 30 matching lines...) Expand all
6003 return reinterpret_cast<RawLibrary*>(raw); 6002 return reinterpret_cast<RawLibrary*>(raw);
6004 } 6003 }
6005 6004
6006 6005
6007 RawLibrary* Library::NewLibraryHelper(const String& url, 6006 RawLibrary* Library::NewLibraryHelper(const String& url,
6008 bool import_core_lib) { 6007 bool import_core_lib) {
6009 const Library& result = Library::Handle(Library::New()); 6008 const Library& result = Library::Handle(Library::New());
6010 result.StorePointer(&result.raw_ptr()->name_, url.raw()); 6009 result.StorePointer(&result.raw_ptr()->name_, url.raw());
6011 result.StorePointer(&result.raw_ptr()->url_, url.raw()); 6010 result.StorePointer(&result.raw_ptr()->url_, url.raw());
6012 result.raw_ptr()->private_key_ = Scanner::AllocatePrivateKey(result); 6011 result.raw_ptr()->private_key_ = Scanner::AllocatePrivateKey(result);
6013 result.raw_ptr()->dictionary_ = Object::empty_array(); 6012 result.raw_ptr()->dictionary_ = Object::empty_array().raw();
6014 result.raw_ptr()->anonymous_classes_ = Object::empty_array(); 6013 result.raw_ptr()->anonymous_classes_ = Object::empty_array().raw();
6015 result.raw_ptr()->num_anonymous_ = 0; 6014 result.raw_ptr()->num_anonymous_ = 0;
6016 result.raw_ptr()->imports_ = Object::empty_array(); 6015 result.raw_ptr()->imports_ = Object::empty_array().raw();
6017 result.raw_ptr()->exports_ = Object::empty_array(); 6016 result.raw_ptr()->exports_ = Object::empty_array().raw();
6018 result.raw_ptr()->loaded_scripts_ = Array::null(); 6017 result.raw_ptr()->loaded_scripts_ = Array::null();
6019 result.set_native_entry_resolver(NULL); 6018 result.set_native_entry_resolver(NULL);
6020 result.raw_ptr()->corelib_imported_ = true; 6019 result.raw_ptr()->corelib_imported_ = true;
6021 result.set_debuggable(false); 6020 result.set_debuggable(false);
6022 result.raw_ptr()->load_state_ = RawLibrary::kAllocated; 6021 result.raw_ptr()->load_state_ = RawLibrary::kAllocated;
6023 result.raw_ptr()->index_ = -1; 6022 result.raw_ptr()->index_ = -1;
6024 result.InitClassDictionary(); 6023 result.InitClassDictionary();
6025 result.InitImportList(); 6024 result.InitImportList();
6026 if (import_core_lib) { 6025 if (import_core_lib) {
6027 const Library& core_lib = Library::Handle(Library::CoreLibrary()); 6026 const Library& core_lib = Library::Handle(Library::CoreLibrary());
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
7061 7060
7062 Code::Comments& Code::Comments::New(intptr_t count) { 7061 Code::Comments& Code::Comments::New(intptr_t count) {
7063 Comments* comments; 7062 Comments* comments;
7064 if (count < 0 || count > (kIntptrMax / kNumberOfEntries)) { 7063 if (count < 0 || count > (kIntptrMax / kNumberOfEntries)) {
7065 // This should be caught before we reach here. 7064 // This should be caught before we reach here.
7066 FATAL1("Fatal error in Code::Comments::New: invalid count %"Pd"\n", count); 7065 FATAL1("Fatal error in Code::Comments::New: invalid count %"Pd"\n", count);
7067 } 7066 }
7068 if (count == 0) { 7067 if (count == 0) {
7069 comments = new Comments(Object::empty_array()); 7068 comments = new Comments(Object::empty_array());
7070 } else { 7069 } else {
7071 comments = new Comments(Array::New(count * kNumberOfEntries)); 7070 comments =
7071 new Comments(Array::ZoneHandle(Array::New(count * kNumberOfEntries)));
Ivan Posva 2012/12/20 23:43:52 Should probably be a regular scoped handle.
siva 2012/12/21 02:28:06 Done.
7072 } 7072 }
7073 return *comments; 7073 return *comments;
7074 } 7074 }
7075 7075
7076 7076
7077 intptr_t Code::Comments::Length() const { 7077 intptr_t Code::Comments::Length() const {
7078 if (comments_.IsNull()) { 7078 if (comments_.IsNull()) {
7079 return 0; 7079 return 0;
7080 } 7080 }
7081 return comments_.Length() / kNumberOfEntries; 7081 return comments_.Length() / kNumberOfEntries;
(...skipping 16 matching lines...) Expand all
7098 return String::CheckedHandle( 7098 return String::CheckedHandle(
7099 comments_.At(idx * kNumberOfEntries + kCommentEntry)); 7099 comments_.At(idx * kNumberOfEntries + kCommentEntry));
7100 } 7100 }
7101 7101
7102 7102
7103 void Code::Comments::SetCommentAt(intptr_t idx, const String& comment) { 7103 void Code::Comments::SetCommentAt(intptr_t idx, const String& comment) {
7104 comments_.SetAt(idx * kNumberOfEntries + kCommentEntry, comment); 7104 comments_.SetAt(idx * kNumberOfEntries + kCommentEntry, comment);
7105 } 7105 }
7106 7106
7107 7107
7108 Code::Comments::Comments(RawArray* comments) 7108 Code::Comments::Comments(const Array& comments)
7109 : comments_(Array::Handle(comments)) { 7109 : comments_(comments) {
7110 } 7110 }
7111 7111
7112 7112
7113 void Code::set_stackmaps(const Array& maps) const { 7113 void Code::set_stackmaps(const Array& maps) const {
7114 StorePointer(&raw_ptr()->stackmaps_, maps.raw()); 7114 StorePointer(&raw_ptr()->stackmaps_, maps.raw());
7115 } 7115 }
7116 7116
7117 7117
7118 void Code::set_deopt_info_array(const Array& array) const { 7118 void Code::set_deopt_info_array(const Array& array) const {
7119 StorePointer(&raw_ptr()->deopt_info_array_, array.raw()); 7119 StorePointer(&raw_ptr()->deopt_info_array_, array.raw());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
7157 (code.function() == array.At(i + kSCallTableFunctionEntry))); 7157 (code.function() == array.At(i + kSCallTableFunctionEntry)));
7158 array.SetAt(i + kSCallTableCodeEntry, code); 7158 array.SetAt(i + kSCallTableCodeEntry, code);
7159 return; 7159 return;
7160 } 7160 }
7161 } 7161 }
7162 UNREACHABLE(); 7162 UNREACHABLE();
7163 } 7163 }
7164 7164
7165 7165
7166 const Code::Comments& Code::comments() const { 7166 const Code::Comments& Code::comments() const {
7167 Comments* comments = new Code::Comments(raw_ptr()->comments_); 7167 Comments* comments = new Code::Comments(Array::Handle(raw_ptr()->comments_));
7168 return *comments; 7168 return *comments;
7169 } 7169 }
7170 7170
7171 7171
7172 void Code::set_comments(const Code::Comments& comments) const { 7172 void Code::set_comments(const Code::Comments& comments) const {
7173 StorePointer(&raw_ptr()->comments_, comments.comments_.raw()); 7173 StorePointer(&raw_ptr()->comments_, comments.comments_.raw());
7174 } 7174 }
7175 7175
7176 7176
7177 RawCode* Code::New(intptr_t pointer_offsets_length) { 7177 RawCode* Code::New(intptr_t pointer_offsets_length) {
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after
8411 ASSERT(other.IsFinalized()); 8411 ASSERT(other.IsFinalized());
8412 ASSERT(!other.IsDynamicType()); 8412 ASSERT(!other.IsDynamicType());
8413 ASSERT(!other.IsMalformed()); 8413 ASSERT(!other.IsMalformed());
8414 const Class& cls = Class::Handle(clazz()); 8414 const Class& cls = Class::Handle(clazz());
8415 if (cls.IsNullClass()) { 8415 if (cls.IsNullClass()) {
8416 if (!IsNull()) { 8416 if (!IsNull()) {
8417 // We can only encounter Object::sentinel() or 8417 // We can only encounter Object::sentinel() or
8418 // Object::transition_sentinel() if type checks were not eliminated at 8418 // Object::transition_sentinel() if type checks were not eliminated at
8419 // compile time. Both sentinels are instances of the Null class, but they 8419 // compile time. Both sentinels are instances of the Null class, but they
8420 // are not the Object::null() instance. 8420 // are not the Object::null() instance.
8421 ASSERT((raw() == Object::transition_sentinel()) || 8421 ASSERT((raw() == Object::transition_sentinel().raw()) ||
8422 (raw() == Object::sentinel())); 8422 (raw() == Object::sentinel().raw()));
8423 ASSERT(!FLAG_eliminate_type_checks); 8423 ASSERT(!FLAG_eliminate_type_checks);
8424 return true; // We are doing an instance of test as part of a type check. 8424 return true; // We are doing an instance of test as part of a type check.
8425 } 8425 }
8426 // The null instance can be returned from a void function. 8426 // The null instance can be returned from a void function.
8427 if (other.IsVoidType()) { 8427 if (other.IsVoidType()) {
8428 return true; 8428 return true;
8429 } 8429 }
8430 // Otherwise, null is only an instance of Object and of dynamic. 8430 // Otherwise, null is only an instance of Object and of dynamic.
8431 // It is not necessary to fully instantiate the other type for this test. 8431 // It is not necessary to fully instantiate the other type for this test.
8432 Class& other_class = Class::Handle(); 8432 Class& other_class = Class::Handle();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
8565 8565
8566 bool Instance::IsValidFieldOffset(int offset) const { 8566 bool Instance::IsValidFieldOffset(int offset) const {
8567 const Class& cls = Class::Handle(clazz()); 8567 const Class& cls = Class::Handle(clazz());
8568 return (offset >= 0 && offset <= (cls.instance_size() - kWordSize)); 8568 return (offset >= 0 && offset <= (cls.instance_size() - kWordSize));
8569 } 8569 }
8570 8570
8571 8571
8572 const char* Instance::ToCString() const { 8572 const char* Instance::ToCString() const {
8573 if (IsNull()) { 8573 if (IsNull()) {
8574 return "null"; 8574 return "null";
8575 } else if (raw() == Object::sentinel()) { 8575 } else if (raw() == Object::sentinel().raw()) {
8576 return "sentinel"; 8576 return "sentinel";
8577 } else if (raw() == Object::transition_sentinel()) { 8577 } else if (raw() == Object::transition_sentinel().raw()) {
8578 return "transition_sentinel"; 8578 return "transition_sentinel";
8579 } else if (Isolate::Current()->no_gc_scope_depth() > 0) { 8579 } else if (Isolate::Current()->no_gc_scope_depth() > 0) {
8580 // Can occur when running disassembler. 8580 // Can occur when running disassembler.
8581 return "Instance"; 8581 return "Instance";
8582 } else { 8582 } else {
8583 if (IsClosure()) { 8583 if (IsClosure()) {
8584 return Closure::ToCString(*this); 8584 return Closure::ToCString(*this);
8585 } 8585 }
8586 const char* kFormat = "Instance of '%s'"; 8586 const char* kFormat = "Instance of '%s'";
8587 const Class& cls = Class::Handle(clazz()); 8587 const Class& cls = Class::Handle(clazz());
(...skipping 2878 matching lines...) Expand 10 before | Expand all | Expand 10 after
11466 } 11466 }
11467 return result.raw(); 11467 return result.raw();
11468 } 11468 }
11469 11469
11470 11470
11471 RawArray* Array::MakeArray(const GrowableObjectArray& growable_array) { 11471 RawArray* Array::MakeArray(const GrowableObjectArray& growable_array) {
11472 intptr_t used_len = growable_array.Length(); 11472 intptr_t used_len = growable_array.Length();
11473 intptr_t capacity_len = growable_array.Capacity(); 11473 intptr_t capacity_len = growable_array.Capacity();
11474 Isolate* isolate = Isolate::Current(); 11474 Isolate* isolate = Isolate::Current();
11475 const Array& array = Array::Handle(isolate, growable_array.data()); 11475 const Array& array = Array::Handle(isolate, growable_array.data());
11476 const Array& new_array = Array::Handle(isolate, Object::empty_array());
11477 intptr_t capacity_size = Array::InstanceSize(capacity_len); 11476 intptr_t capacity_size = Array::InstanceSize(capacity_len);
11478 intptr_t used_size = Array::InstanceSize(used_len); 11477 intptr_t used_size = Array::InstanceSize(used_len);
11479 NoGCScope no_gc; 11478 NoGCScope no_gc;
11480 11479
11481 // Update the size in the header field and length of the array object. 11480 // Update the size in the header field and length of the array object.
11482 uword tags = array.raw_ptr()->tags_; 11481 uword tags = array.raw_ptr()->tags_;
11483 ASSERT(kArrayCid == RawObject::ClassIdTag::decode(tags)); 11482 ASSERT(kArrayCid == RawObject::ClassIdTag::decode(tags));
11484 tags = RawObject::SizeTag::update(used_size, tags); 11483 tags = RawObject::SizeTag::update(used_size, tags);
11485 array.raw_ptr()->tags_ = tags; 11484 array.raw_ptr()->tags_ = tags;
11486 array.SetLength(used_len); 11485 array.SetLength(used_len);
11487 11486
11488 // Null the GrowableObjectArray, we are removing it's backing array. 11487 // Null the GrowableObjectArray, we are removing it's backing array.
11489 growable_array.SetLength(0); 11488 growable_array.SetLength(0);
11490 growable_array.SetData(new_array); 11489 growable_array.SetData(Object::empty_array());
11491 11490
11492 // If there is any left over space fill it with either an Array object or 11491 // If there is any left over space fill it with either an Array object or
11493 // just a plain object (depending on the amount of left over space) so 11492 // just a plain object (depending on the amount of left over space) so
11494 // that it can be traversed over successfully during garbage collection. 11493 // that it can be traversed over successfully during garbage collection.
11495 Object::MakeUnusedSpaceTraversable(array, capacity_size, used_size); 11494 Object::MakeUnusedSpaceTraversable(array, capacity_size, used_size);
11496 11495
11497 return array.raw(); 11496 return array.raw();
11498 } 11497 }
11499 11498
11500 11499
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after
12493 } 12492 }
12494 return result.raw(); 12493 return result.raw();
12495 } 12494 }
12496 12495
12497 12496
12498 const char* WeakProperty::ToCString() const { 12497 const char* WeakProperty::ToCString() const {
12499 return "_WeakProperty"; 12498 return "_WeakProperty";
12500 } 12499 }
12501 12500
12502 } // namespace dart 12501 } // namespace dart
OLDNEW
« vm/object.h ('K') | « vm/object.h ('k') | vm/object_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698