OLD | NEW |
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/become.h" | 10 #include "vm/become.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 #error RAW_NULL should not be defined. | 106 #error RAW_NULL should not be defined. |
107 #endif | 107 #endif |
108 #define RAW_NULL kHeapObjectTag | 108 #define RAW_NULL kHeapObjectTag |
109 Object* Object::null_object_ = NULL; | 109 Object* Object::null_object_ = NULL; |
110 Array* Object::null_array_ = NULL; | 110 Array* Object::null_array_ = NULL; |
111 String* Object::null_string_ = NULL; | 111 String* Object::null_string_ = NULL; |
112 Instance* Object::null_instance_ = NULL; | 112 Instance* Object::null_instance_ = NULL; |
113 TypeArguments* Object::null_type_arguments_ = NULL; | 113 TypeArguments* Object::null_type_arguments_ = NULL; |
114 Array* Object::empty_array_ = NULL; | 114 Array* Object::empty_array_ = NULL; |
115 Array* Object::zero_array_ = NULL; | 115 Array* Object::zero_array_ = NULL; |
| 116 Context* Object::empty_context_ = NULL; |
116 ContextScope* Object::empty_context_scope_ = NULL; | 117 ContextScope* Object::empty_context_scope_ = NULL; |
117 ObjectPool* Object::empty_object_pool_ = NULL; | 118 ObjectPool* Object::empty_object_pool_ = NULL; |
118 PcDescriptors* Object::empty_descriptors_ = NULL; | 119 PcDescriptors* Object::empty_descriptors_ = NULL; |
119 LocalVarDescriptors* Object::empty_var_descriptors_ = NULL; | 120 LocalVarDescriptors* Object::empty_var_descriptors_ = NULL; |
120 ExceptionHandlers* Object::empty_exception_handlers_ = NULL; | 121 ExceptionHandlers* Object::empty_exception_handlers_ = NULL; |
121 Array* Object::extractor_parameter_types_ = NULL; | 122 Array* Object::extractor_parameter_types_ = NULL; |
122 Array* Object::extractor_parameter_names_ = NULL; | 123 Array* Object::extractor_parameter_names_ = NULL; |
123 Instance* Object::sentinel_ = NULL; | 124 Instance* Object::sentinel_ = NULL; |
124 Instance* Object::transition_sentinel_ = NULL; | 125 Instance* Object::transition_sentinel_ = NULL; |
125 Instance* Object::unknown_constant_ = NULL; | 126 Instance* Object::unknown_constant_ = NULL; |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 Heap* heap = isolate->heap(); | 510 Heap* heap = isolate->heap(); |
510 | 511 |
511 // Allocate the read only object handles here. | 512 // Allocate the read only object handles here. |
512 null_object_ = Object::ReadOnlyHandle(); | 513 null_object_ = Object::ReadOnlyHandle(); |
513 null_array_ = Array::ReadOnlyHandle(); | 514 null_array_ = Array::ReadOnlyHandle(); |
514 null_string_ = String::ReadOnlyHandle(); | 515 null_string_ = String::ReadOnlyHandle(); |
515 null_instance_ = Instance::ReadOnlyHandle(); | 516 null_instance_ = Instance::ReadOnlyHandle(); |
516 null_type_arguments_ = TypeArguments::ReadOnlyHandle(); | 517 null_type_arguments_ = TypeArguments::ReadOnlyHandle(); |
517 empty_array_ = Array::ReadOnlyHandle(); | 518 empty_array_ = Array::ReadOnlyHandle(); |
518 zero_array_ = Array::ReadOnlyHandle(); | 519 zero_array_ = Array::ReadOnlyHandle(); |
| 520 empty_context_ = Context::ReadOnlyHandle(); |
519 empty_context_scope_ = ContextScope::ReadOnlyHandle(); | 521 empty_context_scope_ = ContextScope::ReadOnlyHandle(); |
520 empty_object_pool_ = ObjectPool::ReadOnlyHandle(); | 522 empty_object_pool_ = ObjectPool::ReadOnlyHandle(); |
521 empty_descriptors_ = PcDescriptors::ReadOnlyHandle(); | 523 empty_descriptors_ = PcDescriptors::ReadOnlyHandle(); |
522 empty_var_descriptors_ = LocalVarDescriptors::ReadOnlyHandle(); | 524 empty_var_descriptors_ = LocalVarDescriptors::ReadOnlyHandle(); |
523 empty_exception_handlers_ = ExceptionHandlers::ReadOnlyHandle(); | 525 empty_exception_handlers_ = ExceptionHandlers::ReadOnlyHandle(); |
524 extractor_parameter_types_ = Array::ReadOnlyHandle(); | 526 extractor_parameter_types_ = Array::ReadOnlyHandle(); |
525 extractor_parameter_names_ = Array::ReadOnlyHandle(); | 527 extractor_parameter_names_ = Array::ReadOnlyHandle(); |
526 sentinel_ = Instance::ReadOnlyHandle(); | 528 sentinel_ = Instance::ReadOnlyHandle(); |
527 transition_sentinel_ = Instance::ReadOnlyHandle(); | 529 transition_sentinel_ = Instance::ReadOnlyHandle(); |
528 unknown_constant_ = Instance::ReadOnlyHandle(); | 530 unknown_constant_ = Instance::ReadOnlyHandle(); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 uword address = heap->Allocate(Array::InstanceSize(1), Heap::kOld); | 772 uword address = heap->Allocate(Array::InstanceSize(1), Heap::kOld); |
771 InitializeObject(address, kImmutableArrayCid, Array::InstanceSize(1), true); | 773 InitializeObject(address, kImmutableArrayCid, Array::InstanceSize(1), true); |
772 Array::initializeHandle( | 774 Array::initializeHandle( |
773 zero_array_, reinterpret_cast<RawArray*>(address + kHeapObjectTag)); | 775 zero_array_, reinterpret_cast<RawArray*>(address + kHeapObjectTag)); |
774 zero_array_->StoreSmi(&zero_array_->raw_ptr()->length_, Smi::New(1)); | 776 zero_array_->StoreSmi(&zero_array_->raw_ptr()->length_, Smi::New(1)); |
775 smi = Smi::New(0); | 777 smi = Smi::New(0); |
776 zero_array_->SetAt(0, smi); | 778 zero_array_->SetAt(0, smi); |
777 zero_array_->SetCanonical(); | 779 zero_array_->SetCanonical(); |
778 } | 780 } |
779 | 781 |
| 782 // Allocate and initialize the empty context object. |
| 783 { |
| 784 uword address = heap->Allocate(Context::InstanceSize(0), Heap::kOld); |
| 785 InitializeObject(address, kContextCid, Context::InstanceSize(0), true); |
| 786 Context::initializeHandle(empty_context_, reinterpret_cast<RawContext*>( |
| 787 address + kHeapObjectTag)); |
| 788 empty_context_->StoreNonPointer(&empty_context_->raw_ptr()->num_variables_, |
| 789 0); |
| 790 empty_context_->SetCanonical(); |
| 791 } |
| 792 |
780 // Allocate and initialize the canonical empty context scope object. | 793 // Allocate and initialize the canonical empty context scope object. |
781 { | 794 { |
782 uword address = heap->Allocate(ContextScope::InstanceSize(0), Heap::kOld); | 795 uword address = heap->Allocate(ContextScope::InstanceSize(0), Heap::kOld); |
783 InitializeObject(address, kContextScopeCid, ContextScope::InstanceSize(0), | 796 InitializeObject(address, kContextScopeCid, ContextScope::InstanceSize(0), |
784 true); | 797 true); |
785 ContextScope::initializeHandle( | 798 ContextScope::initializeHandle( |
786 empty_context_scope_, | 799 empty_context_scope_, |
787 reinterpret_cast<RawContextScope*>(address + kHeapObjectTag)); | 800 reinterpret_cast<RawContextScope*>(address + kHeapObjectTag)); |
788 empty_context_scope_->StoreNonPointer( | 801 empty_context_scope_->StoreNonPointer( |
789 &empty_context_scope_->raw_ptr()->num_variables_, 0); | 802 &empty_context_scope_->raw_ptr()->num_variables_, 0); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 ASSERT(!null_string_->IsSmi()); | 928 ASSERT(!null_string_->IsSmi()); |
916 ASSERT(null_string_->IsString()); | 929 ASSERT(null_string_->IsString()); |
917 ASSERT(!null_instance_->IsSmi()); | 930 ASSERT(!null_instance_->IsSmi()); |
918 ASSERT(null_instance_->IsInstance()); | 931 ASSERT(null_instance_->IsInstance()); |
919 ASSERT(!null_type_arguments_->IsSmi()); | 932 ASSERT(!null_type_arguments_->IsSmi()); |
920 ASSERT(null_type_arguments_->IsTypeArguments()); | 933 ASSERT(null_type_arguments_->IsTypeArguments()); |
921 ASSERT(!empty_array_->IsSmi()); | 934 ASSERT(!empty_array_->IsSmi()); |
922 ASSERT(empty_array_->IsArray()); | 935 ASSERT(empty_array_->IsArray()); |
923 ASSERT(!zero_array_->IsSmi()); | 936 ASSERT(!zero_array_->IsSmi()); |
924 ASSERT(zero_array_->IsArray()); | 937 ASSERT(zero_array_->IsArray()); |
| 938 ASSERT(!empty_context_->IsSmi()); |
| 939 ASSERT(empty_context_->IsContext()); |
925 ASSERT(!empty_context_scope_->IsSmi()); | 940 ASSERT(!empty_context_scope_->IsSmi()); |
926 ASSERT(empty_context_scope_->IsContextScope()); | 941 ASSERT(empty_context_scope_->IsContextScope()); |
927 ASSERT(!empty_descriptors_->IsSmi()); | 942 ASSERT(!empty_descriptors_->IsSmi()); |
928 ASSERT(empty_descriptors_->IsPcDescriptors()); | 943 ASSERT(empty_descriptors_->IsPcDescriptors()); |
929 ASSERT(!empty_var_descriptors_->IsSmi()); | 944 ASSERT(!empty_var_descriptors_->IsSmi()); |
930 ASSERT(empty_var_descriptors_->IsLocalVarDescriptors()); | 945 ASSERT(empty_var_descriptors_->IsLocalVarDescriptors()); |
931 ASSERT(!empty_exception_handlers_->IsSmi()); | 946 ASSERT(!empty_exception_handlers_->IsSmi()); |
932 ASSERT(empty_exception_handlers_->IsExceptionHandlers()); | 947 ASSERT(empty_exception_handlers_->IsExceptionHandlers()); |
933 ASSERT(!sentinel_->IsSmi()); | 948 ASSERT(!sentinel_->IsSmi()); |
934 ASSERT(sentinel_->IsInstance()); | 949 ASSERT(sentinel_->IsInstance()); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 Library::InitCoreLibrary(isolate); | 1276 Library::InitCoreLibrary(isolate); |
1262 | 1277 |
1263 // Basic infrastructure has been setup, initialize the class dictionary. | 1278 // Basic infrastructure has been setup, initialize the class dictionary. |
1264 const Library& core_lib = Library::Handle(zone, Library::CoreLibrary()); | 1279 const Library& core_lib = Library::Handle(zone, Library::CoreLibrary()); |
1265 ASSERT(!core_lib.IsNull()); | 1280 ASSERT(!core_lib.IsNull()); |
1266 | 1281 |
1267 const GrowableObjectArray& pending_classes = | 1282 const GrowableObjectArray& pending_classes = |
1268 GrowableObjectArray::Handle(zone, GrowableObjectArray::New()); | 1283 GrowableObjectArray::Handle(zone, GrowableObjectArray::New()); |
1269 object_store->set_pending_classes(pending_classes); | 1284 object_store->set_pending_classes(pending_classes); |
1270 | 1285 |
1271 Context& context = Context::Handle(zone, Context::New(0, Heap::kOld)); | |
1272 object_store->set_empty_context(context); | |
1273 | |
1274 // Now that the symbol table is initialized and that the core dictionary as | 1286 // Now that the symbol table is initialized and that the core dictionary as |
1275 // well as the core implementation dictionary have been setup, preallocate | 1287 // well as the core implementation dictionary have been setup, preallocate |
1276 // remaining classes and register them by name in the dictionaries. | 1288 // remaining classes and register them by name in the dictionaries. |
1277 String& name = String::Handle(zone); | 1289 String& name = String::Handle(zone); |
1278 cls = object_store->array_class(); // Was allocated above. | 1290 cls = object_store->array_class(); // Was allocated above. |
1279 RegisterPrivateClass(cls, Symbols::_List(), core_lib); | 1291 RegisterPrivateClass(cls, Symbols::_List(), core_lib); |
1280 pending_classes.Add(cls); | 1292 pending_classes.Add(cls); |
1281 // We cannot use NewNonParameterizedType(cls), because Array is | 1293 // We cannot use NewNonParameterizedType(cls), because Array is |
1282 // parameterized. Warning: class _List has not been patched yet. Its | 1294 // parameterized. Warning: class _List has not been patched yet. Its |
1283 // declared number of type parameters is still 0. It will become 1 after | 1295 // declared number of type parameters is still 0. It will become 1 after |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1780 cls = Class::New<SendPort>(); | 1792 cls = Class::New<SendPort>(); |
1781 cls = Class::New<StackTrace>(); | 1793 cls = Class::New<StackTrace>(); |
1782 cls = Class::New<RegExp>(); | 1794 cls = Class::New<RegExp>(); |
1783 cls = Class::New<Number>(); | 1795 cls = Class::New<Number>(); |
1784 | 1796 |
1785 cls = Class::New<WeakProperty>(); | 1797 cls = Class::New<WeakProperty>(); |
1786 object_store->set_weak_property_class(cls); | 1798 object_store->set_weak_property_class(cls); |
1787 | 1799 |
1788 cls = Class::New<MirrorReference>(); | 1800 cls = Class::New<MirrorReference>(); |
1789 cls = Class::New<UserTag>(); | 1801 cls = Class::New<UserTag>(); |
1790 | |
1791 const Context& context = Context::Handle(zone, Context::New(0, Heap::kOld)); | |
1792 object_store->set_empty_context(context); | |
1793 } | 1802 } |
1794 return Error::null(); | 1803 return Error::null(); |
1795 } | 1804 } |
1796 | 1805 |
1797 | 1806 |
1798 #if defined(DEBUG) | 1807 #if defined(DEBUG) |
1799 bool Object::InVMHeap() const { | 1808 bool Object::InVMHeap() const { |
1800 if (FLAG_verify_handles && raw()->IsVMHeapObject()) { | 1809 if (FLAG_verify_handles && raw()->IsVMHeapObject()) { |
1801 Heap* vm_isolate_heap = Dart::vm_isolate()->heap(); | 1810 Heap* vm_isolate_heap = Dart::vm_isolate()->heap(); |
1802 ASSERT(vm_isolate_heap->Contains(RawObject::ToAddr(raw()))); | 1811 ASSERT(vm_isolate_heap->Contains(RawObject::ToAddr(raw()))); |
(...skipping 5120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6923 pieces->Add(Symbols::RBracket()); | 6932 pieces->Add(Symbols::RBracket()); |
6924 } else { | 6933 } else { |
6925 pieces->Add(Symbols::RBrace()); | 6934 pieces->Add(Symbols::RBrace()); |
6926 } | 6935 } |
6927 } | 6936 } |
6928 } | 6937 } |
6929 | 6938 |
6930 | 6939 |
6931 RawInstance* Function::ImplicitStaticClosure() const { | 6940 RawInstance* Function::ImplicitStaticClosure() const { |
6932 if (implicit_static_closure() == Instance::null()) { | 6941 if (implicit_static_closure() == Instance::null()) { |
6933 Thread* thread = Thread::Current(); | 6942 Zone* zone = Thread::Current()->zone(); |
6934 Isolate* isolate = thread->isolate(); | 6943 const Context& context = Object::empty_context(); |
6935 Zone* zone = thread->zone(); | |
6936 ObjectStore* object_store = isolate->object_store(); | |
6937 const Context& context = | |
6938 Context::Handle(zone, object_store->empty_context()); | |
6939 const TypeArguments& instantiator = TypeArguments::Handle(zone); | 6944 const TypeArguments& instantiator = TypeArguments::Handle(zone); |
6940 Instance& closure = Instance::Handle( | 6945 Instance& closure = Instance::Handle( |
6941 zone, Closure::New(instantiator, *this, context, Heap::kOld)); | 6946 zone, Closure::New(instantiator, *this, context, Heap::kOld)); |
6942 set_implicit_static_closure(closure); | 6947 set_implicit_static_closure(closure); |
6943 } | 6948 } |
6944 return implicit_static_closure(); | 6949 return implicit_static_closure(); |
6945 } | 6950 } |
6946 | 6951 |
6947 | 6952 |
6948 RawInstance* Function::ImplicitInstanceClosure(const Instance& receiver) const { | 6953 RawInstance* Function::ImplicitInstanceClosure(const Instance& receiver) const { |
(...skipping 16158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
23107 return UserTag::null(); | 23112 return UserTag::null(); |
23108 } | 23113 } |
23109 | 23114 |
23110 | 23115 |
23111 const char* UserTag::ToCString() const { | 23116 const char* UserTag::ToCString() const { |
23112 const String& tag_label = String::Handle(label()); | 23117 const String& tag_label = String::Handle(label()); |
23113 return tag_label.ToCString(); | 23118 return tag_label.ToCString(); |
23114 } | 23119 } |
23115 | 23120 |
23116 } // namespace dart | 23121 } // namespace dart |
OLD | NEW |