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

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
« no previous file with comments | « vm/object.h ('k') | vm/object_store.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 isolate()->store_buffer()->AddPointer(ptr); 1248 isolate()->store_buffer()->AddPointer(ptr);
1247 } 1249 }
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::IsReadOnlyHandle() const {
1257 return (IsZoneHandle() || 1259 return Dart::IsReadOnlyHandle(reinterpret_cast<uword>(this));
1258 Symbols::IsPredefinedHandle(reinterpret_cast<uword>(this)));
1259 } 1260 }
1260 1261
1261 1262
1263 bool Object::IsNotTemporaryScopedHandle() const {
1264 return (IsZoneHandle() || IsReadOnlyHandle());
1265 }
1266
1267
1262 1268
1263 RawObject* Object::Clone(const Object& src, Heap::Space space) { 1269 RawObject* Object::Clone(const Object& src, Heap::Space space) {
1264 const Class& cls = Class::Handle(src.clazz()); 1270 const Class& cls = Class::Handle(src.clazz());
1265 intptr_t size = src.raw()->Size(); 1271 intptr_t size = src.raw()->Size();
1266 RawObject* raw_obj = Object::Allocate(cls.id(), size, space); 1272 RawObject* raw_obj = Object::Allocate(cls.id(), size, space);
1267 NoGCScope no_gc; 1273 NoGCScope no_gc;
1268 memmove(raw_obj->ptr(), src.raw()->ptr(), size); 1274 memmove(raw_obj->ptr(), src.raw()->ptr(), size);
1269 if (space == Heap::kOld) { 1275 if (space == Heap::kOld) {
1270 StoreBufferObjectPointerVisitor visitor(Isolate::Current()); 1276 StoreBufferObjectPointerVisitor visitor(Isolate::Current());
1271 raw_obj->VisitPointers(&visitor); 1277 raw_obj->VisitPointers(&visitor);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 result.raw_ptr()->num_native_fields_ = 0; 1417 result.raw_ptr()->num_native_fields_ = 0;
1412 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex; 1418 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex;
1413 result.InitEmptyFields(); 1419 result.InitEmptyFields();
1414 Isolate::Current()->class_table()->Register(result); 1420 Isolate::Current()->class_table()->Register(result);
1415 return result.raw(); 1421 return result.raw();
1416 } 1422 }
1417 1423
1418 1424
1419 // Initialize class fields of type Array with empty array. 1425 // Initialize class fields of type Array with empty array.
1420 void Class::InitEmptyFields() { 1426 void Class::InitEmptyFields() {
1421 if (Object::empty_array() == Array::null()) { 1427 if (Object::empty_array().raw() == Array::null()) {
1422 // The empty array has not been initialized yet. 1428 // The empty array has not been initialized yet.
1423 return; 1429 return;
1424 } 1430 }
1425 StorePointer(&raw_ptr()->interfaces_, Object::empty_array()); 1431 StorePointer(&raw_ptr()->interfaces_, Object::empty_array().raw());
1426 StorePointer(&raw_ptr()->constants_, Object::empty_array()); 1432 StorePointer(&raw_ptr()->constants_, Object::empty_array().raw());
1427 StorePointer(&raw_ptr()->canonical_types_, Object::empty_array()); 1433 StorePointer(&raw_ptr()->canonical_types_, Object::empty_array().raw());
1428 StorePointer(&raw_ptr()->functions_, Object::empty_array()); 1434 StorePointer(&raw_ptr()->functions_, Object::empty_array().raw());
1429 StorePointer(&raw_ptr()->fields_, Object::empty_array()); 1435 StorePointer(&raw_ptr()->fields_, Object::empty_array().raw());
1430 } 1436 }
1431 1437
1432 1438
1433 bool Class::HasInstanceFields() const { 1439 bool Class::HasInstanceFields() const {
1434 const Array& field_array = Array::Handle(fields()); 1440 const Array& field_array = Array::Handle(fields());
1435 Field& field = Field::Handle(); 1441 Field& field = Field::Handle();
1436 for (intptr_t i = 0; i < field_array.Length(); ++i) { 1442 for (intptr_t i = 0; i < field_array.Length(); ++i) {
1437 field ^= field_array.At(i); 1443 field ^= field_array.At(i);
1438 if (!field.is_static()) { 1444 if (!field.is_static()) {
1439 return true; 1445 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. 1839 // way as the owner class of its non-static signature function.
1834 // It is not type parameterized if its signature function is static. 1840 // It is not type parameterized if its signature function is static.
1835 if (!signature_function.is_static() && 1841 if (!signature_function.is_static() &&
1836 (owner_class.NumTypeParameters() > 0) && 1842 (owner_class.NumTypeParameters() > 0) &&
1837 !signature_function.HasInstantiatedSignature()) { 1843 !signature_function.HasInstantiatedSignature()) {
1838 type_parameters = owner_class.type_parameters(); 1844 type_parameters = owner_class.type_parameters();
1839 } 1845 }
1840 const intptr_t token_pos = signature_function.token_pos(); 1846 const intptr_t token_pos = signature_function.token_pos();
1841 Class& result = Class::Handle(New<Instance>(name, script, token_pos)); 1847 Class& result = Class::Handle(New<Instance>(name, script, token_pos));
1842 const Type& super_type = Type::Handle(Type::ObjectType()); 1848 const Type& super_type = Type::Handle(Type::ObjectType());
1843 const Array& empty_array = Array::Handle(Object::empty_array());
1844 ASSERT(!super_type.IsNull()); 1849 ASSERT(!super_type.IsNull());
1845 result.set_instance_size(Closure::InstanceSize()); 1850 result.set_instance_size(Closure::InstanceSize());
1846 result.set_next_field_offset(Closure::InstanceSize()); 1851 result.set_next_field_offset(Closure::InstanceSize());
1847 result.set_super_type(super_type); 1852 result.set_super_type(super_type);
1848 result.set_signature_function(signature_function); 1853 result.set_signature_function(signature_function);
1849 result.set_type_parameters(type_parameters); 1854 result.set_type_parameters(type_parameters);
1850 result.SetFields(empty_array); 1855 result.SetFields(Object::empty_array());
1851 result.SetFunctions(empty_array); 1856 result.SetFunctions(Object::empty_array());
1852 result.set_type_arguments_field_offset( 1857 result.set_type_arguments_field_offset(
1853 Closure::type_arguments_offset()); 1858 Closure::type_arguments_offset());
1854 // Implements interface "Function". 1859 // Implements interface "Function".
1855 const Type& function_type = Type::Handle(Type::Function()); 1860 const Type& function_type = Type::Handle(Type::Function());
1856 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); 1861 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld));
1857 interfaces.SetAt(0, function_type); 1862 interfaces.SetAt(0, function_type);
1858 result.set_interfaces(interfaces); 1863 result.set_interfaces(interfaces);
1859 // Unless the signature function already has a signature class, create a 1864 // Unless the signature function already has a signature class, create a
1860 // canonical signature class by having the signature function point back to 1865 // canonical signature class by having the signature function point back to
1861 // the signature class. 1866 // the signature class.
(...skipping 17 matching lines...) Expand all
1879 result.set_canonical_types(new_canonical_types); 1884 result.set_canonical_types(new_canonical_types);
1880 return result.raw(); 1885 return result.raw();
1881 } 1886 }
1882 1887
1883 1888
1884 RawClass* Class::NewNativeWrapper(const Library& library, 1889 RawClass* Class::NewNativeWrapper(const Library& library,
1885 const String& name, 1890 const String& name,
1886 int field_count) { 1891 int field_count) {
1887 Class& cls = Class::Handle(library.LookupClass(name)); 1892 Class& cls = Class::Handle(library.LookupClass(name));
1888 if (cls.IsNull()) { 1893 if (cls.IsNull()) {
1889 const Array& empty_array = Array::Handle(Object::empty_array());
1890 cls = New<Instance>(name, Script::Handle(), Scanner::kDummyTokenIndex); 1894 cls = New<Instance>(name, Script::Handle(), Scanner::kDummyTokenIndex);
1891 cls.SetFields(empty_array); 1895 cls.SetFields(Object::empty_array());
1892 cls.SetFunctions(empty_array); 1896 cls.SetFunctions(Object::empty_array());
1893 // Set super class to Object. 1897 // Set super class to Object.
1894 cls.set_super_type(Type::Handle(Type::ObjectType())); 1898 cls.set_super_type(Type::Handle(Type::ObjectType()));
1895 // Compute instance size. First word contains a pointer to a properly 1899 // Compute instance size. First word contains a pointer to a properly
1896 // sized typed array once the first native field has been set. 1900 // sized typed array once the first native field has been set.
1897 intptr_t instance_size = sizeof(RawObject) + kWordSize; 1901 intptr_t instance_size = sizeof(RawObject) + kWordSize;
1898 cls.set_instance_size(RoundedAllocationSize(instance_size)); 1902 cls.set_instance_size(RoundedAllocationSize(instance_size));
1899 cls.set_next_field_offset(instance_size); 1903 cls.set_next_field_offset(instance_size);
1900 cls.set_num_native_fields(field_count); 1904 cls.set_num_native_fields(field_count);
1901 cls.set_is_finalized(); 1905 cls.set_is_finalized();
1902 library.AddClass(cls); 1906 library.AddClass(cls);
(...skipping 2029 matching lines...) Expand 10 before | Expand all | Expand 10 after
3932 RawFunction::Kind kind, 3936 RawFunction::Kind kind,
3933 bool is_static, 3937 bool is_static,
3934 bool is_const, 3938 bool is_const,
3935 bool is_abstract, 3939 bool is_abstract,
3936 bool is_external, 3940 bool is_external,
3937 const Object& owner, 3941 const Object& owner,
3938 intptr_t token_pos) { 3942 intptr_t token_pos) {
3939 ASSERT(name.IsOneByteString()); 3943 ASSERT(name.IsOneByteString());
3940 ASSERT(!owner.IsNull()); 3944 ASSERT(!owner.IsNull());
3941 const Function& result = Function::Handle(Function::New()); 3945 const Function& result = Function::Handle(Function::New());
3942 const Array& empty_array = Array::Handle(Object::empty_array()); 3946 result.set_parameter_types(Object::empty_array());
3943 result.set_parameter_types(empty_array); 3947 result.set_parameter_names(Object::empty_array());
3944 result.set_parameter_names(empty_array);
3945 result.set_name(name); 3948 result.set_name(name);
3946 result.set_kind(kind); 3949 result.set_kind(kind);
3947 result.set_is_static(is_static); 3950 result.set_is_static(is_static);
3948 result.set_is_const(is_const); 3951 result.set_is_const(is_const);
3949 result.set_is_abstract(is_abstract); 3952 result.set_is_abstract(is_abstract);
3950 result.set_is_external(is_external); 3953 result.set_is_external(is_external);
3951 result.set_intrinsic_kind(kUnknownIntrinsic); 3954 result.set_intrinsic_kind(kUnknownIntrinsic);
3952 result.set_owner(owner); 3955 result.set_owner(owner);
3953 result.set_token_pos(token_pos); 3956 result.set_token_pos(token_pos);
3954 result.set_end_token_pos(token_pos); 3957 result.set_end_token_pos(token_pos);
(...skipping 1997 matching lines...) Expand 10 before | Expand all | Expand 10 after
5952 } 5955 }
5953 intptr_t index = num_imports(); 5956 intptr_t index = num_imports();
5954 imports.SetAt(index, ns); 5957 imports.SetAt(index, ns);
5955 set_num_imports(index + 1); 5958 set_num_imports(index + 1);
5956 } 5959 }
5957 5960
5958 5961
5959 // Convenience function to determine whether the export list is 5962 // Convenience function to determine whether the export list is
5960 // non-empty. 5963 // non-empty.
5961 bool Library::HasExports() const { 5964 bool Library::HasExports() const {
5962 return exports() != Object::empty_array(); 5965 return exports() != Object::empty_array().raw();
5963 } 5966 }
5964 5967
5965 5968
5966 // We add one namespace at a time to the exports array and don't 5969 // We add one namespace at a time to the exports array and don't
5967 // pre-allocate any unused capacity. The assumption is that 5970 // pre-allocate any unused capacity. The assumption is that
5968 // re-exports are quite rare. 5971 // re-exports are quite rare.
5969 void Library::AddExport(const Namespace& ns) const { 5972 void Library::AddExport(const Namespace& ns) const {
5970 Array &exports = Array::Handle(this->exports()); 5973 Array &exports = Array::Handle(this->exports());
5971 intptr_t num_exports = exports.Length(); 5974 intptr_t num_exports = exports.Length();
5972 exports = Array::Grow(exports, num_exports + 1); 5975 exports = Array::Grow(exports, num_exports + 1);
(...skipping 30 matching lines...) Expand all
6003 return reinterpret_cast<RawLibrary*>(raw); 6006 return reinterpret_cast<RawLibrary*>(raw);
6004 } 6007 }
6005 6008
6006 6009
6007 RawLibrary* Library::NewLibraryHelper(const String& url, 6010 RawLibrary* Library::NewLibraryHelper(const String& url,
6008 bool import_core_lib) { 6011 bool import_core_lib) {
6009 const Library& result = Library::Handle(Library::New()); 6012 const Library& result = Library::Handle(Library::New());
6010 result.StorePointer(&result.raw_ptr()->name_, url.raw()); 6013 result.StorePointer(&result.raw_ptr()->name_, url.raw());
6011 result.StorePointer(&result.raw_ptr()->url_, url.raw()); 6014 result.StorePointer(&result.raw_ptr()->url_, url.raw());
6012 result.raw_ptr()->private_key_ = Scanner::AllocatePrivateKey(result); 6015 result.raw_ptr()->private_key_ = Scanner::AllocatePrivateKey(result);
6013 result.raw_ptr()->dictionary_ = Object::empty_array(); 6016 result.raw_ptr()->dictionary_ = Object::empty_array().raw();
6014 result.raw_ptr()->anonymous_classes_ = Object::empty_array(); 6017 result.raw_ptr()->anonymous_classes_ = Object::empty_array().raw();
6015 result.raw_ptr()->num_anonymous_ = 0; 6018 result.raw_ptr()->num_anonymous_ = 0;
6016 result.raw_ptr()->imports_ = Object::empty_array(); 6019 result.raw_ptr()->imports_ = Object::empty_array().raw();
6017 result.raw_ptr()->exports_ = Object::empty_array(); 6020 result.raw_ptr()->exports_ = Object::empty_array().raw();
6018 result.raw_ptr()->loaded_scripts_ = Array::null(); 6021 result.raw_ptr()->loaded_scripts_ = Array::null();
6019 result.set_native_entry_resolver(NULL); 6022 result.set_native_entry_resolver(NULL);
6020 result.raw_ptr()->corelib_imported_ = true; 6023 result.raw_ptr()->corelib_imported_ = true;
6021 result.set_debuggable(false); 6024 result.set_debuggable(false);
6022 result.raw_ptr()->load_state_ = RawLibrary::kAllocated; 6025 result.raw_ptr()->load_state_ = RawLibrary::kAllocated;
6023 result.raw_ptr()->index_ = -1; 6026 result.raw_ptr()->index_ = -1;
6024 result.InitClassDictionary(); 6027 result.InitClassDictionary();
6025 result.InitImportList(); 6028 result.InitImportList();
6026 if (import_core_lib) { 6029 if (import_core_lib) {
6027 const Library& core_lib = Library::Handle(Library::CoreLibrary()); 6030 const Library& core_lib = Library::Handle(Library::CoreLibrary());
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
7061 7064
7062 Code::Comments& Code::Comments::New(intptr_t count) { 7065 Code::Comments& Code::Comments::New(intptr_t count) {
7063 Comments* comments; 7066 Comments* comments;
7064 if (count < 0 || count > (kIntptrMax / kNumberOfEntries)) { 7067 if (count < 0 || count > (kIntptrMax / kNumberOfEntries)) {
7065 // This should be caught before we reach here. 7068 // This should be caught before we reach here.
7066 FATAL1("Fatal error in Code::Comments::New: invalid count %"Pd"\n", count); 7069 FATAL1("Fatal error in Code::Comments::New: invalid count %"Pd"\n", count);
7067 } 7070 }
7068 if (count == 0) { 7071 if (count == 0) {
7069 comments = new Comments(Object::empty_array()); 7072 comments = new Comments(Object::empty_array());
7070 } else { 7073 } else {
7071 comments = new Comments(Array::New(count * kNumberOfEntries)); 7074 const Array& data = Array::Handle(Array::New(count * kNumberOfEntries));
7075 comments = new Comments(data);
7072 } 7076 }
7073 return *comments; 7077 return *comments;
7074 } 7078 }
7075 7079
7076 7080
7077 intptr_t Code::Comments::Length() const { 7081 intptr_t Code::Comments::Length() const {
7078 if (comments_.IsNull()) { 7082 if (comments_.IsNull()) {
7079 return 0; 7083 return 0;
7080 } 7084 }
7081 return comments_.Length() / kNumberOfEntries; 7085 return comments_.Length() / kNumberOfEntries;
(...skipping 16 matching lines...) Expand all
7098 return String::CheckedHandle( 7102 return String::CheckedHandle(
7099 comments_.At(idx * kNumberOfEntries + kCommentEntry)); 7103 comments_.At(idx * kNumberOfEntries + kCommentEntry));
7100 } 7104 }
7101 7105
7102 7106
7103 void Code::Comments::SetCommentAt(intptr_t idx, const String& comment) { 7107 void Code::Comments::SetCommentAt(intptr_t idx, const String& comment) {
7104 comments_.SetAt(idx * kNumberOfEntries + kCommentEntry, comment); 7108 comments_.SetAt(idx * kNumberOfEntries + kCommentEntry, comment);
7105 } 7109 }
7106 7110
7107 7111
7108 Code::Comments::Comments(RawArray* comments) 7112 Code::Comments::Comments(const Array& comments)
7109 : comments_(Array::Handle(comments)) { 7113 : comments_(comments) {
7110 } 7114 }
7111 7115
7112 7116
7113 void Code::set_stackmaps(const Array& maps) const { 7117 void Code::set_stackmaps(const Array& maps) const {
7114 StorePointer(&raw_ptr()->stackmaps_, maps.raw()); 7118 StorePointer(&raw_ptr()->stackmaps_, maps.raw());
7115 } 7119 }
7116 7120
7117 7121
7118 void Code::set_deopt_info_array(const Array& array) const { 7122 void Code::set_deopt_info_array(const Array& array) const {
7119 StorePointer(&raw_ptr()->deopt_info_array_, array.raw()); 7123 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))); 7161 (code.function() == array.At(i + kSCallTableFunctionEntry)));
7158 array.SetAt(i + kSCallTableCodeEntry, code); 7162 array.SetAt(i + kSCallTableCodeEntry, code);
7159 return; 7163 return;
7160 } 7164 }
7161 } 7165 }
7162 UNREACHABLE(); 7166 UNREACHABLE();
7163 } 7167 }
7164 7168
7165 7169
7166 const Code::Comments& Code::comments() const { 7170 const Code::Comments& Code::comments() const {
7167 Comments* comments = new Code::Comments(raw_ptr()->comments_); 7171 Comments* comments = new Code::Comments(Array::Handle(raw_ptr()->comments_));
7168 return *comments; 7172 return *comments;
7169 } 7173 }
7170 7174
7171 7175
7172 void Code::set_comments(const Code::Comments& comments) const { 7176 void Code::set_comments(const Code::Comments& comments) const {
7173 StorePointer(&raw_ptr()->comments_, comments.comments_.raw()); 7177 StorePointer(&raw_ptr()->comments_, comments.comments_.raw());
7174 } 7178 }
7175 7179
7176 7180
7177 RawCode* Code::New(intptr_t pointer_offsets_length) { 7181 RawCode* Code::New(intptr_t pointer_offsets_length) {
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after
8411 ASSERT(other.IsFinalized()); 8415 ASSERT(other.IsFinalized());
8412 ASSERT(!other.IsDynamicType()); 8416 ASSERT(!other.IsDynamicType());
8413 ASSERT(!other.IsMalformed()); 8417 ASSERT(!other.IsMalformed());
8414 const Class& cls = Class::Handle(clazz()); 8418 const Class& cls = Class::Handle(clazz());
8415 if (cls.IsNullClass()) { 8419 if (cls.IsNullClass()) {
8416 if (!IsNull()) { 8420 if (!IsNull()) {
8417 // We can only encounter Object::sentinel() or 8421 // We can only encounter Object::sentinel() or
8418 // Object::transition_sentinel() if type checks were not eliminated at 8422 // Object::transition_sentinel() if type checks were not eliminated at
8419 // compile time. Both sentinels are instances of the Null class, but they 8423 // compile time. Both sentinels are instances of the Null class, but they
8420 // are not the Object::null() instance. 8424 // are not the Object::null() instance.
8421 ASSERT((raw() == Object::transition_sentinel()) || 8425 ASSERT((raw() == Object::transition_sentinel().raw()) ||
8422 (raw() == Object::sentinel())); 8426 (raw() == Object::sentinel().raw()));
8423 ASSERT(!FLAG_eliminate_type_checks); 8427 ASSERT(!FLAG_eliminate_type_checks);
8424 return true; // We are doing an instance of test as part of a type check. 8428 return true; // We are doing an instance of test as part of a type check.
8425 } 8429 }
8426 // The null instance can be returned from a void function. 8430 // The null instance can be returned from a void function.
8427 if (other.IsVoidType()) { 8431 if (other.IsVoidType()) {
8428 return true; 8432 return true;
8429 } 8433 }
8430 // Otherwise, null is only an instance of Object and of dynamic. 8434 // 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. 8435 // It is not necessary to fully instantiate the other type for this test.
8432 Class& other_class = Class::Handle(); 8436 Class& other_class = Class::Handle();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
8565 8569
8566 bool Instance::IsValidFieldOffset(int offset) const { 8570 bool Instance::IsValidFieldOffset(int offset) const {
8567 const Class& cls = Class::Handle(clazz()); 8571 const Class& cls = Class::Handle(clazz());
8568 return (offset >= 0 && offset <= (cls.instance_size() - kWordSize)); 8572 return (offset >= 0 && offset <= (cls.instance_size() - kWordSize));
8569 } 8573 }
8570 8574
8571 8575
8572 const char* Instance::ToCString() const { 8576 const char* Instance::ToCString() const {
8573 if (IsNull()) { 8577 if (IsNull()) {
8574 return "null"; 8578 return "null";
8575 } else if (raw() == Object::sentinel()) { 8579 } else if (raw() == Object::sentinel().raw()) {
8576 return "sentinel"; 8580 return "sentinel";
8577 } else if (raw() == Object::transition_sentinel()) { 8581 } else if (raw() == Object::transition_sentinel().raw()) {
8578 return "transition_sentinel"; 8582 return "transition_sentinel";
8579 } else if (Isolate::Current()->no_gc_scope_depth() > 0) { 8583 } else if (Isolate::Current()->no_gc_scope_depth() > 0) {
8580 // Can occur when running disassembler. 8584 // Can occur when running disassembler.
8581 return "Instance"; 8585 return "Instance";
8582 } else { 8586 } else {
8583 if (IsClosure()) { 8587 if (IsClosure()) {
8584 return Closure::ToCString(*this); 8588 return Closure::ToCString(*this);
8585 } 8589 }
8586 const char* kFormat = "Instance of '%s'"; 8590 const char* kFormat = "Instance of '%s'";
8587 const Class& cls = Class::Handle(clazz()); 8591 const Class& cls = Class::Handle(clazz());
(...skipping 2878 matching lines...) Expand 10 before | Expand all | Expand 10 after
11466 } 11470 }
11467 return result.raw(); 11471 return result.raw();
11468 } 11472 }
11469 11473
11470 11474
11471 RawArray* Array::MakeArray(const GrowableObjectArray& growable_array) { 11475 RawArray* Array::MakeArray(const GrowableObjectArray& growable_array) {
11472 intptr_t used_len = growable_array.Length(); 11476 intptr_t used_len = growable_array.Length();
11473 intptr_t capacity_len = growable_array.Capacity(); 11477 intptr_t capacity_len = growable_array.Capacity();
11474 Isolate* isolate = Isolate::Current(); 11478 Isolate* isolate = Isolate::Current();
11475 const Array& array = Array::Handle(isolate, growable_array.data()); 11479 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); 11480 intptr_t capacity_size = Array::InstanceSize(capacity_len);
11478 intptr_t used_size = Array::InstanceSize(used_len); 11481 intptr_t used_size = Array::InstanceSize(used_len);
11479 NoGCScope no_gc; 11482 NoGCScope no_gc;
11480 11483
11481 // Update the size in the header field and length of the array object. 11484 // Update the size in the header field and length of the array object.
11482 uword tags = array.raw_ptr()->tags_; 11485 uword tags = array.raw_ptr()->tags_;
11483 ASSERT(kArrayCid == RawObject::ClassIdTag::decode(tags)); 11486 ASSERT(kArrayCid == RawObject::ClassIdTag::decode(tags));
11484 tags = RawObject::SizeTag::update(used_size, tags); 11487 tags = RawObject::SizeTag::update(used_size, tags);
11485 array.raw_ptr()->tags_ = tags; 11488 array.raw_ptr()->tags_ = tags;
11486 array.SetLength(used_len); 11489 array.SetLength(used_len);
11487 11490
11488 // Null the GrowableObjectArray, we are removing it's backing array. 11491 // Null the GrowableObjectArray, we are removing it's backing array.
11489 growable_array.SetLength(0); 11492 growable_array.SetLength(0);
11490 growable_array.SetData(new_array); 11493 growable_array.SetData(Object::empty_array());
11491 11494
11492 // If there is any left over space fill it with either an Array object or 11495 // 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 11496 // just a plain object (depending on the amount of left over space) so
11494 // that it can be traversed over successfully during garbage collection. 11497 // that it can be traversed over successfully during garbage collection.
11495 Object::MakeUnusedSpaceTraversable(array, capacity_size, used_size); 11498 Object::MakeUnusedSpaceTraversable(array, capacity_size, used_size);
11496 11499
11497 return array.raw(); 11500 return array.raw();
11498 } 11501 }
11499 11502
11500 11503
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after
12493 } 12496 }
12494 return result.raw(); 12497 return result.raw();
12495 } 12498 }
12496 12499
12497 12500
12498 const char* WeakProperty::ToCString() const { 12501 const char* WeakProperty::ToCString() const {
12499 return "_WeakProperty"; 12502 return "_WeakProperty";
12500 } 12503 }
12501 12504
12502 } // namespace dart 12505 } // namespace dart
OLDNEW
« no previous file with comments | « vm/object.h ('k') | vm/object_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698