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

Side by Side Diff: vm/object.cc

Issue 10861023: Currently we use a generated number as the class id for object class, this change tries to pin it t… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | vm/raw_object_snapshot.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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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
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
1683 template <class FakeInstance> 1687 template <class FakeInstance>
1684 RawClass* Class::New(const String& name, 1688 RawClass* Class::New(const String& name,
1685 const Script& script, 1689 const Script& script,
1686 intptr_t token_pos) { 1690 intptr_t token_pos) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 // Cache the signature type as the first canonicalized type in result. 1763 // Cache the signature type as the first canonicalized type in result.
1760 const Type& signature_type = Type::Handle(result.SignatureType()); 1764 const Type& signature_type = Type::Handle(result.SignatureType());
1761 ASSERT(!signature_type.IsFinalized()); 1765 ASSERT(!signature_type.IsFinalized());
1762 const Array& new_canonical_types = Array::Handle(Array::New(1, Heap::kOld)); 1766 const Array& new_canonical_types = Array::Handle(Array::New(1, Heap::kOld));
1763 new_canonical_types.SetAt(0, signature_type); 1767 new_canonical_types.SetAt(0, signature_type);
1764 result.set_canonical_types(new_canonical_types); 1768 result.set_canonical_types(new_canonical_types);
1765 return result.raw(); 1769 return result.raw();
1766 } 1770 }
1767 1771
1768 1772
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(Library* library, 1773 RawClass* Class::NewNativeWrapper(Library* library,
1786 const String& name, 1774 const String& name,
1787 int field_count) { 1775 int field_count) {
1788 Class& cls = Class::Handle(library->LookupClass(name)); 1776 Class& cls = Class::Handle(library->LookupClass(name));
1789 if (cls.IsNull()) { 1777 if (cls.IsNull()) {
1790 const Array& empty_array = Array::Handle(Object::empty_array()); 1778 const Array& empty_array = Array::Handle(Object::empty_array());
1791 cls = New<Instance>(name, Script::Handle(), Scanner::kDummyTokenIndex); 1779 cls = New<Instance>(name, Script::Handle(), Scanner::kDummyTokenIndex);
1792 cls.SetFields(empty_array); 1780 cls.SetFields(empty_array);
1793 cls.SetFunctions(empty_array); 1781 cls.SetFunctions(empty_array);
1794 // Set super class to Object. 1782 // Set super class to Object.
(...skipping 9354 matching lines...) Expand 10 before | Expand all | Expand 10 after
11149 } 11137 }
11150 return result.raw(); 11138 return result.raw();
11151 } 11139 }
11152 11140
11153 11141
11154 const char* WeakProperty::ToCString() const { 11142 const char* WeakProperty::ToCString() const {
11155 return "WeakProperty"; 11143 return "WeakProperty";
11156 } 11144 }
11157 11145
11158 } // namespace dart 11146 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | vm/raw_object_snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698