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

Side by Side Diff: runtime/vm/object.cc

Issue 22902002: Ensure the classes void and dynamic have empty arrays for fields, functions, etc. Move their Types … (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | « runtime/vm/object.h ('k') | runtime/vm/object_store.h » ('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/cpu.h" 10 #include "vm/cpu.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 Bool* Object::bool_true_ = NULL; 87 Bool* Object::bool_true_ = NULL;
88 Bool* Object::bool_false_ = NULL; 88 Bool* Object::bool_false_ = NULL;
89 Smi* Object::smi_illegal_cid_ = NULL; 89 Smi* Object::smi_illegal_cid_ = NULL;
90 LanguageError* Object::snapshot_writer_error_ = NULL; 90 LanguageError* Object::snapshot_writer_error_ = NULL;
91 LanguageError* Object::branch_offset_error_ = NULL; 91 LanguageError* Object::branch_offset_error_ = NULL;
92 92
93 RawObject* Object::null_ = reinterpret_cast<RawObject*>(RAW_NULL); 93 RawObject* Object::null_ = reinterpret_cast<RawObject*>(RAW_NULL);
94 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 94 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
95 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 95 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
96 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 96 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
97 RawType* Object::dynamic_type_ = reinterpret_cast<RawType*>(RAW_NULL);
98 RawType* Object::void_type_ = reinterpret_cast<RawType*>(RAW_NULL);
97 RawClass* Object::unresolved_class_class_ = 99 RawClass* Object::unresolved_class_class_ =
98 reinterpret_cast<RawClass*>(RAW_NULL); 100 reinterpret_cast<RawClass*>(RAW_NULL);
99 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 101 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
100 RawClass* Object::instantiated_type_arguments_class_ = 102 RawClass* Object::instantiated_type_arguments_class_ =
101 reinterpret_cast<RawClass*>(RAW_NULL); 103 reinterpret_cast<RawClass*>(RAW_NULL);
102 RawClass* Object::patch_class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 104 RawClass* Object::patch_class_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
103 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 105 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
104 RawClass* Object::closure_data_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 106 RawClass* Object::closure_data_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
105 RawClass* Object::redirection_data_class_ = 107 RawClass* Object::redirection_data_class_ =
106 reinterpret_cast<RawClass*>(RAW_NULL); 108 reinterpret_cast<RawClass*>(RAW_NULL);
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 } 434 }
433 435
434 // Allocate and initialize optimizing compiler constants. 436 // Allocate and initialize optimizing compiler constants.
435 { 437 {
436 *unknown_constant_ ^= 438 *unknown_constant_ ^=
437 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); 439 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld);
438 *non_constant_ ^= 440 *non_constant_ ^=
439 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); 441 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld);
440 } 442 }
441 443
442 cls = Class::New<Instance>(kDynamicCid);
443 cls.set_is_finalized();
444 cls.set_is_type_finalized();
445 cls.set_is_abstract();
446 dynamic_class_ = cls.raw();
447
448 // Allocate the remaining VM internal classes. 444 // Allocate the remaining VM internal classes.
449 cls = Class::New<UnresolvedClass>(); 445 cls = Class::New<UnresolvedClass>();
450 unresolved_class_class_ = cls.raw(); 446 unresolved_class_class_ = cls.raw();
451 447
452 cls = Class::New<Instance>(kVoidCid);
453 cls.set_is_finalized();
454 cls.set_is_type_finalized();
455 void_class_ = cls.raw();
456
457 cls = Class::New<TypeArguments>(); 448 cls = Class::New<TypeArguments>();
458 type_arguments_class_ = cls.raw(); 449 type_arguments_class_ = cls.raw();
459 450
460 cls = Class::New<InstantiatedTypeArguments>(); 451 cls = Class::New<InstantiatedTypeArguments>();
461 instantiated_type_arguments_class_ = cls.raw(); 452 instantiated_type_arguments_class_ = cls.raw();
462 453
463 cls = Class::New<PatchClass>(); 454 cls = Class::New<PatchClass>();
464 patch_class_class_ = cls.raw(); 455 patch_class_class_ = cls.raw();
465 456
466 cls = Class::New<Function>(); 457 cls = Class::New<Function>();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 // Allocate and initialize the empty_array instance. 550 // Allocate and initialize the empty_array instance.
560 { 551 {
561 uword address = heap->Allocate(Array::InstanceSize(0), Heap::kOld); 552 uword address = heap->Allocate(Array::InstanceSize(0), Heap::kOld);
562 InitializeObject(address, kArrayCid, Array::InstanceSize(0)); 553 InitializeObject(address, kArrayCid, Array::InstanceSize(0));
563 Array::initializeHandle( 554 Array::initializeHandle(
564 empty_array_, 555 empty_array_,
565 reinterpret_cast<RawArray*>(address + kHeapObjectTag)); 556 reinterpret_cast<RawArray*>(address + kHeapObjectTag));
566 empty_array_->raw()->ptr()->length_ = Smi::New(0); 557 empty_array_->raw()->ptr()->length_ = Smi::New(0);
567 } 558 }
568 559
560 cls = Class::New<Instance>(kDynamicCid);
561 cls.set_is_finalized();
562 cls.set_is_type_finalized();
563 cls.set_is_abstract();
564 dynamic_class_ = cls.raw();
565
566 cls = Class::New<Instance>(kVoidCid);
567 cls.set_is_finalized();
568 cls.set_is_type_finalized();
569 void_class_ = cls.raw();
570
571 cls = Class::New<Type>();
572 cls.set_is_finalized();
573 cls.set_is_type_finalized();
574 isolate->object_store()->set_type_class(cls);
575
576 Type& type = Type::Handle();
577 cls = dynamic_class_;
578 type = Type::NewNonParameterizedType(cls);
579 dynamic_type_ = type.raw();
regis 2013/08/12 21:16:22 Do you need the type handle? How about: dynamic_ty
rmacnak 2013/08/12 22:14:53 Fixed.
580
581 cls = void_class_;
582 type = Type::NewNonParameterizedType(cls);
583 void_type_ = type.raw();
regis 2013/08/12 21:16:22 void_type_ = Type::NewNonParameterizedType(cls);
584
569 // Allocate and initialize singleton true and false boolean objects. 585 // Allocate and initialize singleton true and false boolean objects.
570 cls = Class::New<Bool>(); 586 cls = Class::New<Bool>();
571 isolate->object_store()->set_bool_class(cls); 587 isolate->object_store()->set_bool_class(cls);
572 *bool_true_ = Bool::New(true); 588 *bool_true_ = Bool::New(true);
573 *bool_false_ = Bool::New(false); 589 *bool_false_ = Bool::New(false);
574 590
575 *smi_illegal_cid_ = Smi::New(kIllegalCid); 591 *smi_illegal_cid_ = Smi::New(kIllegalCid);
576 592
577 String& error_str = String::Handle(); 593 String& error_str = String::Handle();
578 error_str = String::New("SnapshotWriter Error"); 594 error_str = String::New("SnapshotWriter Error");
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 849
834 // Now that the symbol table is initialized and that the core dictionary as 850 // Now that the symbol table is initialized and that the core dictionary as
835 // well as the core implementation dictionary have been setup, preallocate 851 // well as the core implementation dictionary have been setup, preallocate
836 // remaining classes and register them by name in the dictionaries. 852 // remaining classes and register them by name in the dictionaries.
837 String& name = String::Handle(); 853 String& name = String::Handle();
838 cls = Class::New<Bool>(); 854 cls = Class::New<Bool>();
839 object_store->set_bool_class(cls); 855 object_store->set_bool_class(cls);
840 RegisterClass(cls, Symbols::Bool(), core_lib); 856 RegisterClass(cls, Symbols::Bool(), core_lib);
841 pending_classes.Add(cls, Heap::kOld); 857 pending_classes.Add(cls, Heap::kOld);
842 858
859 // TODO(12364): The class 'Null' is not registered in the class dictionary
860 // because it is not exported by dart:core.
843 cls = Class::New<Instance>(kNullCid); 861 cls = Class::New<Instance>(kNullCid);
844 cls.set_name(Symbols::Null()); 862 cls.set_name(Symbols::Null());
845 // We immediately mark Null as finalized because it has no corresponding 863 // We immediately mark Null as finalized because it has no corresponding
846 // source. 864 // source.
847 cls.set_is_finalized(); 865 cls.set_is_finalized();
848 cls.set_is_type_finalized(); 866 cls.set_is_type_finalized();
849 object_store->set_null_class(cls); 867 object_store->set_null_class(cls);
850 cls.set_library(core_lib); // A sort of fiction for the mirrors. 868 cls.set_library(core_lib); // A sort of fiction for the mirrors.
851 // When/if we promote Null to an ordinary class, it should be added to the 869 // When/if we promote Null to an ordinary class, it should be added to the
852 // core library, given source and added to the list of classes pending 870 // core library, given source and added to the list of classes pending
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 object_store->set_bool_type(type); 1123 object_store->set_bool_type(type);
1106 1124
1107 cls = object_store->smi_class(); 1125 cls = object_store->smi_class();
1108 type = Type::NewNonParameterizedType(cls); 1126 type = Type::NewNonParameterizedType(cls);
1109 object_store->set_smi_type(type); 1127 object_store->set_smi_type(type);
1110 1128
1111 cls = object_store->mint_class(); 1129 cls = object_store->mint_class();
1112 type = Type::NewNonParameterizedType(cls); 1130 type = Type::NewNonParameterizedType(cls);
1113 object_store->set_mint_type(type); 1131 object_store->set_mint_type(type);
1114 1132
1115 // The class 'Null' is not register in the class dictionary because it is not
1116 // The classes 'void' and 'dynamic' are phoney classes to make type checking 1133 // The classes 'void' and 'dynamic' are phoney classes to make type checking
1117 // more regular; they live in the VM isolate. The class 'void' is not 1134 // more regular; they live in the VM isolate. The class 'void' is not
1118 // registered in the class dictionary because its name is a reserved word. 1135 // registered in the class dictionary because its name is a reserved word.
1119 // The class 'dynamic' is registered in the class dictionary because its name 1136 // The class 'dynamic' is registered in the class dictionary because its name
1120 // is a built-in identifier (this is wrong). 1137 // is a built-in identifier (this is wrong).
1121 // The corresponding types are stored in the object store. 1138 // The corresponding types are stored in the object store.
1122 cls = object_store->null_class(); 1139 cls = object_store->null_class();
1123 type = Type::NewNonParameterizedType(cls); 1140 type = Type::NewNonParameterizedType(cls);
1124 object_store->set_null_type(type); 1141 object_store->set_null_type(type);
1125 1142
1126 // Consider removing when/if Null becomes an ordinary class. 1143 // Consider removing when/if Null becomes an ordinary class.
1127 type = object_store->object_type(); 1144 type = object_store->object_type();
1128 cls.set_super_type(type); 1145 cls.set_super_type(type);
1129 1146
1130 cls = void_class();
1131 type = Type::NewNonParameterizedType(cls);
1132 object_store->set_void_type(type);
1133
1134 cls = dynamic_class();
1135 type = Type::NewNonParameterizedType(cls);
1136 object_store->set_dynamic_type(type);
1137
1138 // Finish the initialization by compiling the bootstrap scripts containing the 1147 // Finish the initialization by compiling the bootstrap scripts containing the
1139 // base interfaces and the implementation of the internal classes. 1148 // base interfaces and the implementation of the internal classes.
1140 const Error& error = Error::Handle(Bootstrap::LoadandCompileScripts()); 1149 const Error& error = Error::Handle(Bootstrap::LoadandCompileScripts());
1141 if (!error.IsNull()) { 1150 if (!error.IsNull()) {
1142 return error.raw(); 1151 return error.raw();
1143 } 1152 }
1144 1153
1145 ClassFinalizer::VerifyBootstrapClasses(); 1154 ClassFinalizer::VerifyBootstrapClasses();
1146 MarkInvisibleFunctions(); 1155 MarkInvisibleFunctions();
1147 1156
(...skipping 1497 matching lines...) Expand 10 before | Expand all | Expand 10 after
2645 2654
2646 2655
2647 RawFunction* Class::LookupFunction(const String& name, intptr_t type) const { 2656 RawFunction* Class::LookupFunction(const String& name, intptr_t type) const {
2648 Isolate* isolate = Isolate::Current(); 2657 Isolate* isolate = Isolate::Current();
2649 if (EnsureIsFinalized(isolate) != Error::null()) { 2658 if (EnsureIsFinalized(isolate) != Error::null()) {
2650 return Function::null(); 2659 return Function::null();
2651 } 2660 }
2652 ReusableHandleScope reused_handles(isolate); 2661 ReusableHandleScope reused_handles(isolate);
2653 Array& funcs = reused_handles.ArrayHandle(); 2662 Array& funcs = reused_handles.ArrayHandle();
2654 funcs ^= functions(); 2663 funcs ^= functions();
2655 if (funcs.IsNull()) { 2664 ASSERT(!funcs.IsNull());
2656 // This can occur, e.g., for Null classes.
2657 return Function::null();
2658 }
2659 Function& function = reused_handles.FunctionHandle(); 2665 Function& function = reused_handles.FunctionHandle();
2660 const intptr_t len = funcs.Length(); 2666 const intptr_t len = funcs.Length();
2661 if (name.IsSymbol()) { 2667 if (name.IsSymbol()) {
2662 // Quick Symbol compare. 2668 // Quick Symbol compare.
2663 NoGCScope no_gc; 2669 NoGCScope no_gc;
2664 for (intptr_t i = 0; i < len; i++) { 2670 for (intptr_t i = 0; i < len; i++) {
2665 function ^= funcs.At(i); 2671 function ^= funcs.At(i);
2666 if (function.name() == name.raw()) { 2672 if (function.name() == name.raw()) {
2667 return CheckFunctionType(function, type); 2673 return CheckFunctionType(function, type);
2668 } 2674 }
(...skipping 15 matching lines...) Expand all
2684 2690
2685 RawFunction* Class::LookupFunctionAllowPrivate(const String& name, 2691 RawFunction* Class::LookupFunctionAllowPrivate(const String& name,
2686 intptr_t type) const { 2692 intptr_t type) const {
2687 Isolate* isolate = Isolate::Current(); 2693 Isolate* isolate = Isolate::Current();
2688 if (EnsureIsFinalized(isolate) != Error::null()) { 2694 if (EnsureIsFinalized(isolate) != Error::null()) {
2689 return Function::null(); 2695 return Function::null();
2690 } 2696 }
2691 ReusableHandleScope reused_handles(isolate); 2697 ReusableHandleScope reused_handles(isolate);
2692 Array& funcs = reused_handles.ArrayHandle(); 2698 Array& funcs = reused_handles.ArrayHandle();
2693 funcs ^= functions(); 2699 funcs ^= functions();
2694 if (funcs.IsNull()) { 2700 ASSERT(!funcs.IsNull());
2695 // This can occur, e.g., for Null classes.
2696 return Function::null();
2697 }
2698 Function& function = reused_handles.FunctionHandle(); 2701 Function& function = reused_handles.FunctionHandle();
2699 String& function_name = reused_handles.StringHandle(); 2702 String& function_name = reused_handles.StringHandle();
2700 intptr_t len = funcs.Length(); 2703 intptr_t len = funcs.Length();
2701 for (intptr_t i = 0; i < len; i++) { 2704 for (intptr_t i = 0; i < len; i++) {
2702 function ^= funcs.At(i); 2705 function ^= funcs.At(i);
2703 function_name ^= function.name(); 2706 function_name ^= function.name();
2704 if (String::EqualsIgnoringPrivateKey(function_name, name)) { 2707 if (String::EqualsIgnoringPrivateKey(function_name, name)) {
2705 return CheckFunctionType(function, type); 2708 return CheckFunctionType(function, type);
2706 } 2709 }
2707 } 2710 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2788 2791
2789 2792
2790 RawField* Class::LookupField(const String& name, intptr_t type) const { 2793 RawField* Class::LookupField(const String& name, intptr_t type) const {
2791 Isolate* isolate = Isolate::Current(); 2794 Isolate* isolate = Isolate::Current();
2792 if (EnsureIsFinalized(isolate) != Error::null()) { 2795 if (EnsureIsFinalized(isolate) != Error::null()) {
2793 return Field::null(); 2796 return Field::null();
2794 } 2797 }
2795 ReusableHandleScope reused_handles(isolate); 2798 ReusableHandleScope reused_handles(isolate);
2796 Array& flds = reused_handles.ArrayHandle(); 2799 Array& flds = reused_handles.ArrayHandle();
2797 flds ^= fields(); 2800 flds ^= fields();
2798 if (flds.IsNull()) { 2801 ASSERT(!flds.IsNull());
2799 // This can occur, e.g., for Null classes.
2800 return Field::null();
2801 }
2802 Field& field = reused_handles.FieldHandle(); 2802 Field& field = reused_handles.FieldHandle();
2803 String& field_name = reused_handles.StringHandle(); 2803 String& field_name = reused_handles.StringHandle();
2804 intptr_t len = flds.Length(); 2804 intptr_t len = flds.Length();
2805 for (intptr_t i = 0; i < len; i++) { 2805 for (intptr_t i = 0; i < len; i++) {
2806 field ^= flds.At(i); 2806 field ^= flds.At(i);
2807 field_name ^= field.name(); 2807 field_name ^= field.name();
2808 if (String::EqualsIgnoringPrivateKey(field_name, name)) { 2808 if (String::EqualsIgnoringPrivateKey(field_name, name)) {
2809 if (type == kInstance) { 2809 if (type == kInstance) {
2810 if (!field.is_static()) { 2810 if (!field.is_static()) {
2811 return field.raw(); 2811 return field.raw();
(...skipping 7643 matching lines...) Expand 10 before | Expand all | Expand 10 after
10455 RawString* AbstractType::ClassName() const { 10455 RawString* AbstractType::ClassName() const {
10456 if (HasResolvedTypeClass()) { 10456 if (HasResolvedTypeClass()) {
10457 return Class::Handle(type_class()).Name(); 10457 return Class::Handle(type_class()).Name();
10458 } else { 10458 } else {
10459 return UnresolvedClass::Handle(unresolved_class()).Name(); 10459 return UnresolvedClass::Handle(unresolved_class()).Name();
10460 } 10460 }
10461 } 10461 }
10462 10462
10463 10463
10464 bool AbstractType::IsNullType() const { 10464 bool AbstractType::IsNullType() const {
10465 return HasResolvedTypeClass() && 10465 ASSERT(Type::Handle(Type::NullType()).IsCanonical());
10466 (type_class() == Type::Handle(Type::NullType()).type_class()); 10466 return raw() == Type::NullType();
10467 } 10467 }
10468 10468
10469 10469
10470 bool AbstractType::IsBoolType() const { 10470 bool AbstractType::IsBoolType() const {
10471 return HasResolvedTypeClass() && 10471 return HasResolvedTypeClass() &&
10472 (type_class() == Type::Handle(Type::BoolType()).type_class()); 10472 (type_class() == Type::Handle(Type::BoolType()).type_class());
10473 } 10473 }
10474 10474
10475 10475
10476 bool AbstractType::IsIntType() const { 10476 bool AbstractType::IsIntType() const {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
10605 stream->CloseObject(); 10605 stream->CloseObject();
10606 } 10606 }
10607 10607
10608 10608
10609 RawType* Type::NullType() { 10609 RawType* Type::NullType() {
10610 return Isolate::Current()->object_store()->null_type(); 10610 return Isolate::Current()->object_store()->null_type();
10611 } 10611 }
10612 10612
10613 10613
10614 RawType* Type::DynamicType() { 10614 RawType* Type::DynamicType() {
10615 return Isolate::Current()->object_store()->dynamic_type(); 10615 return Object::dynamic_type();
10616 } 10616 }
10617 10617
10618 10618
10619 RawType* Type::VoidType() { 10619 RawType* Type::VoidType() {
10620 return Isolate::Current()->object_store()->void_type(); 10620 return Object::void_type();
10621 } 10621 }
10622 10622
10623 10623
10624 RawType* Type::ObjectType() { 10624 RawType* Type::ObjectType() {
10625 return Isolate::Current()->object_store()->object_type(); 10625 return Isolate::Current()->object_store()->object_type();
10626 } 10626 }
10627 10627
10628 10628
10629 RawType* Type::BoolType() { 10629 RawType* Type::BoolType() {
10630 return Isolate::Current()->object_store()->bool_type(); 10630 return Isolate::Current()->object_store()->bool_type();
(...skipping 3979 matching lines...) Expand 10 before | Expand all | Expand 10 after
14610 } 14610 }
14611 14611
14612 14612
14613 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 14613 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
14614 stream->OpenObject(); 14614 stream->OpenObject();
14615 stream->CloseObject(); 14615 stream->CloseObject();
14616 } 14616 }
14617 14617
14618 14618
14619 } // namespace dart 14619 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698