Chromium Code Reviews| 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/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 629 name = Symbols::WeakProperty(); | 629 name = Symbols::WeakProperty(); |
| 630 RegisterClass(cls, name, core_impl_lib); | 630 RegisterClass(cls, name, core_impl_lib); |
| 631 pending_classes.Add(cls, Heap::kOld); | 631 pending_classes.Add(cls, Heap::kOld); |
| 632 | 632 |
| 633 // Initialize the base interfaces used by the core VM classes. | 633 // Initialize the base interfaces used by the core VM classes. |
| 634 const Script& script = Script::Handle(Bootstrap::LoadCoreScript(false)); | 634 const Script& script = Script::Handle(Bootstrap::LoadCoreScript(false)); |
| 635 | 635 |
| 636 // Allocate and initialize the Object class and type. The Object | 636 // Allocate and initialize the Object class and type. The Object |
| 637 // class and ByteArray subclasses are the only pre-allocated, | 637 // class and ByteArray subclasses are the only pre-allocated, |
| 638 // non-interface classes in the core library. | 638 // non-interface classes in the core library. |
| 639 cls = Class::New<Instance>(); | 639 cls = Class::New<Instance>(kInstanceCid); |
| 640 object_store->set_object_class(cls); | 640 object_store->set_object_class(cls); |
| 641 name = Symbols::Object(); | 641 name = Symbols::Object(); |
| 642 cls.set_name(name); | 642 cls.set_name(name); |
| 643 cls.set_script(script); | 643 cls.set_script(script); |
| 644 cls.set_is_prefinalized(); | 644 cls.set_is_prefinalized(); |
| 645 core_lib.AddClass(cls); | 645 core_lib.AddClass(cls); |
| 646 pending_classes.Add(cls, Heap::kOld); | 646 pending_classes.Add(cls, Heap::kOld); |
| 647 type = Type::NewNonParameterizedType(cls); | 647 type = Type::NewNonParameterizedType(cls); |
| 648 object_store->set_object_type(type); | 648 object_store->set_object_type(type); |
| 649 | 649 |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 912 | 912 |
| 913 void Object::InitFromSnapshot(Isolate* isolate) { | 913 void Object::InitFromSnapshot(Isolate* isolate) { |
| 914 TIMERSCOPE(time_bootstrap); | 914 TIMERSCOPE(time_bootstrap); |
| 915 ObjectStore* object_store = isolate->object_store(); | 915 ObjectStore* object_store = isolate->object_store(); |
| 916 | 916 |
| 917 Class& cls = Class::Handle(); | 917 Class& cls = Class::Handle(); |
| 918 | 918 |
| 919 // Set up empty classes in the object store, these will get | 919 // Set up empty classes in the object store, these will get |
| 920 // initialized correctly when we read from the snapshot. | 920 // initialized correctly when we read from the snapshot. |
| 921 // This is done to allow bootstrapping of reading classes from the snapshot. | 921 // This is done to allow bootstrapping of reading classes from the snapshot. |
| 922 cls = Class::New<Instance>(kInstanceCid); | |
| 923 object_store->set_object_class(cls); | |
| 924 | |
| 922 cls = Class::New<Array>(); | 925 cls = Class::New<Array>(); |
| 923 object_store->set_array_class(cls); | 926 object_store->set_array_class(cls); |
| 924 | 927 |
| 925 cls = Class::New<ImmutableArray>(); | 928 cls = Class::New<ImmutableArray>(); |
| 926 object_store->set_immutable_array_class(cls); | 929 object_store->set_immutable_array_class(cls); |
| 927 | 930 |
| 928 cls = Class::New<GrowableObjectArray>(); | 931 cls = Class::New<GrowableObjectArray>(); |
| 929 object_store->set_growable_object_array_class(cls); | 932 object_store->set_growable_object_array_class(cls); |
| 930 | 933 |
| 931 cls = Class::New<Int8Array>(); | 934 cls = Class::New<Int8Array>(); |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1243 RawObject* raw = Object::Allocate(Class::kClassId, | 1246 RawObject* raw = Object::Allocate(Class::kClassId, |
| 1244 Class::InstanceSize(), | 1247 Class::InstanceSize(), |
| 1245 Heap::kOld); | 1248 Heap::kOld); |
| 1246 NoGCScope no_gc; | 1249 NoGCScope no_gc; |
| 1247 result ^= raw; | 1250 result ^= raw; |
| 1248 } | 1251 } |
| 1249 FakeObject fake; | 1252 FakeObject fake; |
| 1250 result.set_handle_vtable(fake.vtable()); | 1253 result.set_handle_vtable(fake.vtable()); |
| 1251 result.set_instance_size(FakeObject::InstanceSize()); | 1254 result.set_instance_size(FakeObject::InstanceSize()); |
| 1252 result.set_next_field_offset(FakeObject::InstanceSize()); | 1255 result.set_next_field_offset(FakeObject::InstanceSize()); |
| 1253 result.set_id((FakeObject::kClassId != kInstanceCid && | 1256 ASSERT((FakeObject::kClassId != kInstanceCid) && |
| 1254 FakeObject::kClassId != kClosureCid) ? | 1257 (FakeObject::kClassId != kClosureCid)); |
| 1255 FakeObject::kClassId : kIllegalCid); | 1258 result.set_id(FakeObject::kClassId); |
| 1256 result.raw_ptr()->state_bits_ = 0; | 1259 result.raw_ptr()->state_bits_ = 0; |
| 1257 // VM backed classes are almost ready: run checks and resolve class | 1260 // VM backed classes are almost ready: run checks and resolve class |
| 1258 // references, but do not recompute size. | 1261 // references, but do not recompute size. |
| 1259 result.set_is_prefinalized(); | 1262 result.set_is_prefinalized(); |
| 1260 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments; | 1263 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments; |
| 1261 result.raw_ptr()->num_native_fields_ = 0; | 1264 result.raw_ptr()->num_native_fields_ = 0; |
| 1262 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex; | 1265 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex; |
| 1263 result.InitEmptyFields(); | 1266 result.InitEmptyFields(); |
| 1264 Isolate::Current()->class_table()->Register(result); | 1267 Isolate::Current()->class_table()->Register(result); |
| 1265 return result.raw(); | 1268 return result.raw(); |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1667 } | 1670 } |
| 1668 FakeInstance fake; | 1671 FakeInstance fake; |
| 1669 ASSERT(fake.IsInstance()); | 1672 ASSERT(fake.IsInstance()); |
| 1670 result.set_handle_vtable(fake.vtable()); | 1673 result.set_handle_vtable(fake.vtable()); |
| 1671 result.set_instance_size(FakeInstance::InstanceSize()); | 1674 result.set_instance_size(FakeInstance::InstanceSize()); |
| 1672 result.set_next_field_offset(FakeInstance::InstanceSize()); | 1675 result.set_next_field_offset(FakeInstance::InstanceSize()); |
| 1673 result.set_id(index); | 1676 result.set_id(index); |
| 1674 result.raw_ptr()->state_bits_ = 0; | 1677 result.raw_ptr()->state_bits_ = 0; |
| 1675 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments; | 1678 result.raw_ptr()->type_arguments_instance_field_offset_ = kNoTypeArguments; |
| 1676 result.raw_ptr()->num_native_fields_ = 0; | 1679 result.raw_ptr()->num_native_fields_ = 0; |
| 1680 result.raw_ptr()->token_pos_ = Scanner::kDummyTokenIndex; | |
| 1677 result.InitEmptyFields(); | 1681 result.InitEmptyFields(); |
| 1678 Isolate::Current()->class_table()->Register(result); | 1682 Isolate::Current()->class_table()->Register(result); |
| 1679 return result.raw(); | 1683 return result.raw(); |
| 1680 } | 1684 } |
| 1681 | 1685 |
| 1682 | 1686 |
| 1687 // Force instantiation of template version to work around ld problems. | |
|
Florian Schneider
2012/08/22 08:18:15
I think explicit instantiation can be avoided if y
siva
2012/08/22 15:17:02
The function is pretty big and would look pretty o
| |
| 1688 template RawClass* Class::New<Closure>(intptr_t index); | |
| 1689 | |
| 1690 | |
| 1683 template <class FakeInstance> | 1691 template <class FakeInstance> |
| 1684 RawClass* Class::New(const String& name, | 1692 RawClass* Class::New(const String& name, |
| 1685 const Script& script, | 1693 const Script& script, |
| 1686 intptr_t token_pos) { | 1694 intptr_t token_pos) { |
| 1687 Class& result = Class::Handle(New<FakeInstance>(kIllegalCid)); | 1695 Class& result = Class::Handle(New<FakeInstance>(kIllegalCid)); |
| 1688 result.set_name(name); | 1696 result.set_name(name); |
| 1689 result.set_script(script); | 1697 result.set_script(script); |
| 1690 result.set_token_pos(token_pos); | 1698 result.set_token_pos(token_pos); |
| 1691 return result.raw(); | 1699 return result.raw(); |
| 1692 } | 1700 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1759 // Cache the signature type as the first canonicalized type in result. | 1767 // Cache the signature type as the first canonicalized type in result. |
| 1760 const Type& signature_type = Type::Handle(result.SignatureType()); | 1768 const Type& signature_type = Type::Handle(result.SignatureType()); |
| 1761 ASSERT(!signature_type.IsFinalized()); | 1769 ASSERT(!signature_type.IsFinalized()); |
| 1762 const Array& new_canonical_types = Array::Handle(Array::New(1, Heap::kOld)); | 1770 const Array& new_canonical_types = Array::Handle(Array::New(1, Heap::kOld)); |
| 1763 new_canonical_types.SetAt(0, signature_type); | 1771 new_canonical_types.SetAt(0, signature_type); |
| 1764 result.set_canonical_types(new_canonical_types); | 1772 result.set_canonical_types(new_canonical_types); |
| 1765 return result.raw(); | 1773 return result.raw(); |
| 1766 } | 1774 } |
| 1767 | 1775 |
| 1768 | 1776 |
| 1769 RawClass* Class::GetClass(intptr_t class_id, bool is_signature_class) { | |
| 1770 if (class_id >= kIntegerCid && class_id <= kWeakPropertyCid) { | |
| 1771 return Isolate::Current()->class_table()->At(class_id); | |
| 1772 } | |
| 1773 if (class_id >= kNumPredefinedCids) { | |
| 1774 if (is_signature_class) { | |
| 1775 return Class::New<Closure>(); | |
| 1776 } | |
| 1777 return Class::New<Instance>(); | |
| 1778 } | |
| 1779 OS::Print("Class::GetClass id unknown: %d\n", class_id); | |
| 1780 UNREACHABLE(); | |
| 1781 return Class::null(); | |
| 1782 } | |
| 1783 | |
| 1784 | |
| 1785 RawClass* Class::NewNativeWrapper(const Library& library, | 1777 RawClass* Class::NewNativeWrapper(const Library& library, |
| 1786 const String& name, | 1778 const String& name, |
| 1787 int field_count) { | 1779 int field_count) { |
| 1788 Class& cls = Class::Handle(library.LookupClass(name)); | 1780 Class& cls = Class::Handle(library.LookupClass(name)); |
| 1789 if (cls.IsNull()) { | 1781 if (cls.IsNull()) { |
| 1790 const Array& empty_array = Array::Handle(Object::empty_array()); | 1782 const Array& empty_array = Array::Handle(Object::empty_array()); |
| 1791 cls = New<Instance>(name, Script::Handle(), Scanner::kDummyTokenIndex); | 1783 cls = New<Instance>(name, Script::Handle(), Scanner::kDummyTokenIndex); |
| 1792 cls.SetFields(empty_array); | 1784 cls.SetFields(empty_array); |
| 1793 cls.SetFunctions(empty_array); | 1785 cls.SetFunctions(empty_array); |
| 1794 // Set super class to Object. | 1786 // Set super class to Object. |
| (...skipping 9346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11141 } | 11133 } |
| 11142 return result.raw(); | 11134 return result.raw(); |
| 11143 } | 11135 } |
| 11144 | 11136 |
| 11145 | 11137 |
| 11146 const char* WeakProperty::ToCString() const { | 11138 const char* WeakProperty::ToCString() const { |
| 11147 return "WeakProperty"; | 11139 return "WeakProperty"; |
| 11148 } | 11140 } |
| 11149 | 11141 |
| 11150 } // namespace dart | 11142 } // namespace dart |
| OLD | NEW |