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

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: remove redudant mirror asserts, fix test 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 Bool* Object::bool_true_ = NULL; 88 Bool* Object::bool_true_ = NULL;
89 Bool* Object::bool_false_ = NULL; 89 Bool* Object::bool_false_ = NULL;
90 Smi* Object::smi_illegal_cid_ = NULL; 90 Smi* Object::smi_illegal_cid_ = NULL;
91 LanguageError* Object::snapshot_writer_error_ = NULL; 91 LanguageError* Object::snapshot_writer_error_ = NULL;
92 LanguageError* Object::branch_offset_error_ = NULL; 92 LanguageError* Object::branch_offset_error_ = NULL;
93 93
94 RawObject* Object::null_ = reinterpret_cast<RawObject*>(RAW_NULL); 94 RawObject* Object::null_ = reinterpret_cast<RawObject*>(RAW_NULL);
95 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 95 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
96 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 96 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
97 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 97 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
98 RawType* Object::dynamic_type_ = reinterpret_cast<RawType*>(RAW_NULL);
99 RawType* Object::void_type_ = reinterpret_cast<RawType*>(RAW_NULL);
98 RawClass* Object::unresolved_class_class_ = 100 RawClass* Object::unresolved_class_class_ =
99 reinterpret_cast<RawClass*>(RAW_NULL); 101 reinterpret_cast<RawClass*>(RAW_NULL);
100 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 102 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
101 RawClass* Object::instantiated_type_arguments_class_ = 103 RawClass* Object::instantiated_type_arguments_class_ =
102 reinterpret_cast<RawClass*>(RAW_NULL); 104 reinterpret_cast<RawClass*>(RAW_NULL);
103 RawClass* Object::patch_class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 105 RawClass* Object::patch_class_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
104 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 106 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
105 RawClass* Object::closure_data_class_ = reinterpret_cast<RawClass*>(RAW_NULL); 107 RawClass* Object::closure_data_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
106 RawClass* Object::redirection_data_class_ = 108 RawClass* Object::redirection_data_class_ =
107 reinterpret_cast<RawClass*>(RAW_NULL); 109 reinterpret_cast<RawClass*>(RAW_NULL);
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 } 435 }
434 436
435 // Allocate and initialize optimizing compiler constants. 437 // Allocate and initialize optimizing compiler constants.
436 { 438 {
437 *unknown_constant_ ^= 439 *unknown_constant_ ^=
438 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); 440 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld);
439 *non_constant_ ^= 441 *non_constant_ ^=
440 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); 442 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld);
441 } 443 }
442 444
443 cls = Class::New<Instance>(kDynamicCid);
444 cls.set_is_finalized();
445 cls.set_is_type_finalized();
446 cls.set_is_abstract();
447 dynamic_class_ = cls.raw();
448
449 // Allocate the remaining VM internal classes. 445 // Allocate the remaining VM internal classes.
450 cls = Class::New<UnresolvedClass>(); 446 cls = Class::New<UnresolvedClass>();
451 unresolved_class_class_ = cls.raw(); 447 unresolved_class_class_ = cls.raw();
452 448
453 cls = Class::New<Instance>(kVoidCid);
454 cls.set_is_finalized();
455 cls.set_is_type_finalized();
456 void_class_ = cls.raw();
457
458 cls = Class::New<TypeArguments>(); 449 cls = Class::New<TypeArguments>();
459 type_arguments_class_ = cls.raw(); 450 type_arguments_class_ = cls.raw();
460 451
461 cls = Class::New<InstantiatedTypeArguments>(); 452 cls = Class::New<InstantiatedTypeArguments>();
462 instantiated_type_arguments_class_ = cls.raw(); 453 instantiated_type_arguments_class_ = cls.raw();
463 454
464 cls = Class::New<PatchClass>(); 455 cls = Class::New<PatchClass>();
465 patch_class_class_ = cls.raw(); 456 patch_class_class_ = cls.raw();
466 457
467 cls = Class::New<Function>(); 458 cls = Class::New<Function>();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 // Allocate and initialize the empty_array instance. 551 // Allocate and initialize the empty_array instance.
561 { 552 {
562 uword address = heap->Allocate(Array::InstanceSize(0), Heap::kOld); 553 uword address = heap->Allocate(Array::InstanceSize(0), Heap::kOld);
563 InitializeObject(address, kArrayCid, Array::InstanceSize(0)); 554 InitializeObject(address, kArrayCid, Array::InstanceSize(0));
564 Array::initializeHandle( 555 Array::initializeHandle(
565 empty_array_, 556 empty_array_,
566 reinterpret_cast<RawArray*>(address + kHeapObjectTag)); 557 reinterpret_cast<RawArray*>(address + kHeapObjectTag));
567 empty_array_->raw()->ptr()->length_ = Smi::New(0); 558 empty_array_->raw()->ptr()->length_ = Smi::New(0);
568 } 559 }
569 560
561 cls = Class::New<Instance>(kDynamicCid);
562 cls.set_is_finalized();
563 cls.set_is_type_finalized();
564 cls.set_is_abstract();
565 dynamic_class_ = cls.raw();
566
567 cls = Class::New<Instance>(kVoidCid);
568 cls.set_is_finalized();
569 cls.set_is_type_finalized();
570 void_class_ = cls.raw();
571
572 cls = Class::New<Type>();
573 cls.set_is_finalized();
574 cls.set_is_type_finalized();
575 isolate->object_store()->set_type_class(cls);
576
577 cls = dynamic_class_;
578 dynamic_type_ = Type::NewNonParameterizedType(cls);
579
580 cls = void_class_;
581 void_type_ = Type::NewNonParameterizedType(cls);
582
570 // Allocate and initialize singleton true and false boolean objects. 583 // Allocate and initialize singleton true and false boolean objects.
571 cls = Class::New<Bool>(); 584 cls = Class::New<Bool>();
572 isolate->object_store()->set_bool_class(cls); 585 isolate->object_store()->set_bool_class(cls);
573 *bool_true_ = Bool::New(true); 586 *bool_true_ = Bool::New(true);
574 *bool_false_ = Bool::New(false); 587 *bool_false_ = Bool::New(false);
575 588
576 *smi_illegal_cid_ = Smi::New(kIllegalCid); 589 *smi_illegal_cid_ = Smi::New(kIllegalCid);
577 590
578 String& error_str = String::Handle(); 591 String& error_str = String::Handle();
579 error_str = String::New("SnapshotWriter Error"); 592 error_str = String::New("SnapshotWriter Error");
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 847
835 // Now that the symbol table is initialized and that the core dictionary as 848 // Now that the symbol table is initialized and that the core dictionary as
836 // well as the core implementation dictionary have been setup, preallocate 849 // well as the core implementation dictionary have been setup, preallocate
837 // remaining classes and register them by name in the dictionaries. 850 // remaining classes and register them by name in the dictionaries.
838 String& name = String::Handle(); 851 String& name = String::Handle();
839 cls = Class::New<Bool>(); 852 cls = Class::New<Bool>();
840 object_store->set_bool_class(cls); 853 object_store->set_bool_class(cls);
841 RegisterClass(cls, Symbols::Bool(), core_lib); 854 RegisterClass(cls, Symbols::Bool(), core_lib);
842 pending_classes.Add(cls, Heap::kOld); 855 pending_classes.Add(cls, Heap::kOld);
843 856
857 // TODO(12364): The class 'Null' is not registered in the class dictionary
858 // because it is not exported by dart:core.
844 cls = Class::New<Instance>(kNullCid); 859 cls = Class::New<Instance>(kNullCid);
845 cls.set_name(Symbols::Null()); 860 cls.set_name(Symbols::Null());
846 // We immediately mark Null as finalized because it has no corresponding 861 // We immediately mark Null as finalized because it has no corresponding
847 // source. 862 // source.
848 cls.set_is_finalized(); 863 cls.set_is_finalized();
849 cls.set_is_type_finalized(); 864 cls.set_is_type_finalized();
850 object_store->set_null_class(cls); 865 object_store->set_null_class(cls);
851 cls.set_library(core_lib); // A sort of fiction for the mirrors. 866 cls.set_library(core_lib); // A sort of fiction for the mirrors.
852 // When/if we promote Null to an ordinary class, it should be added to the 867 // When/if we promote Null to an ordinary class, it should be added to the
853 // core library, given source and added to the list of classes pending 868 // core library, given source and added to the list of classes pending
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 object_store->set_bool_type(type); 1121 object_store->set_bool_type(type);
1107 1122
1108 cls = object_store->smi_class(); 1123 cls = object_store->smi_class();
1109 type = Type::NewNonParameterizedType(cls); 1124 type = Type::NewNonParameterizedType(cls);
1110 object_store->set_smi_type(type); 1125 object_store->set_smi_type(type);
1111 1126
1112 cls = object_store->mint_class(); 1127 cls = object_store->mint_class();
1113 type = Type::NewNonParameterizedType(cls); 1128 type = Type::NewNonParameterizedType(cls);
1114 object_store->set_mint_type(type); 1129 object_store->set_mint_type(type);
1115 1130
1116 // The class 'Null' is not register in the class dictionary because it is not
1117 // The classes 'void' and 'dynamic' are phoney classes to make type checking 1131 // The classes 'void' and 'dynamic' are phoney classes to make type checking
1118 // more regular; they live in the VM isolate. The class 'void' is not 1132 // more regular; they live in the VM isolate. The class 'void' is not
1119 // registered in the class dictionary because its name is a reserved word. 1133 // registered in the class dictionary because its name is a reserved word.
1120 // The class 'dynamic' is registered in the class dictionary because its name 1134 // The class 'dynamic' is registered in the class dictionary because its name
1121 // is a built-in identifier (this is wrong). 1135 // is a built-in identifier (this is wrong).
1122 // The corresponding types are stored in the object store. 1136 // The corresponding types are stored in the object store.
1123 cls = object_store->null_class(); 1137 cls = object_store->null_class();
1124 type = Type::NewNonParameterizedType(cls); 1138 type = Type::NewNonParameterizedType(cls);
1125 object_store->set_null_type(type); 1139 object_store->set_null_type(type);
1126 1140
1127 // Consider removing when/if Null becomes an ordinary class. 1141 // Consider removing when/if Null becomes an ordinary class.
1128 type = object_store->object_type(); 1142 type = object_store->object_type();
1129 cls.set_super_type(type); 1143 cls.set_super_type(type);
1130 1144
1131 cls = void_class();
1132 type = Type::NewNonParameterizedType(cls);
1133 object_store->set_void_type(type);
1134
1135 cls = dynamic_class();
1136 type = Type::NewNonParameterizedType(cls);
1137 object_store->set_dynamic_type(type);
1138
1139 // Finish the initialization by compiling the bootstrap scripts containing the 1145 // Finish the initialization by compiling the bootstrap scripts containing the
1140 // base interfaces and the implementation of the internal classes. 1146 // base interfaces and the implementation of the internal classes.
1141 const Error& error = Error::Handle(Bootstrap::LoadandCompileScripts()); 1147 const Error& error = Error::Handle(Bootstrap::LoadandCompileScripts());
1142 if (!error.IsNull()) { 1148 if (!error.IsNull()) {
1143 return error.raw(); 1149 return error.raw();
1144 } 1150 }
1145 1151
1146 ClassFinalizer::VerifyBootstrapClasses(); 1152 ClassFinalizer::VerifyBootstrapClasses();
1147 MarkInvisibleFunctions(); 1153 MarkInvisibleFunctions();
1148 1154
(...skipping 1510 matching lines...) Expand 10 before | Expand all | Expand 10 after
2659 2665
2660 2666
2661 RawFunction* Class::LookupFunction(const String& name, intptr_t type) const { 2667 RawFunction* Class::LookupFunction(const String& name, intptr_t type) const {
2662 Isolate* isolate = Isolate::Current(); 2668 Isolate* isolate = Isolate::Current();
2663 if (EnsureIsFinalized(isolate) != Error::null()) { 2669 if (EnsureIsFinalized(isolate) != Error::null()) {
2664 return Function::null(); 2670 return Function::null();
2665 } 2671 }
2666 ReusableHandleScope reused_handles(isolate); 2672 ReusableHandleScope reused_handles(isolate);
2667 Array& funcs = reused_handles.ArrayHandle(); 2673 Array& funcs = reused_handles.ArrayHandle();
2668 funcs ^= functions(); 2674 funcs ^= functions();
2669 if (funcs.IsNull()) { 2675 ASSERT(!funcs.IsNull());
2670 // This can occur, e.g., for Null classes.
2671 return Function::null();
2672 }
2673 Function& function = reused_handles.FunctionHandle(); 2676 Function& function = reused_handles.FunctionHandle();
2674 const intptr_t len = funcs.Length(); 2677 const intptr_t len = funcs.Length();
2675 if (name.IsSymbol()) { 2678 if (name.IsSymbol()) {
2676 // Quick Symbol compare. 2679 // Quick Symbol compare.
2677 NoGCScope no_gc; 2680 NoGCScope no_gc;
2678 for (intptr_t i = 0; i < len; i++) { 2681 for (intptr_t i = 0; i < len; i++) {
2679 function ^= funcs.At(i); 2682 function ^= funcs.At(i);
2680 if (function.name() == name.raw()) { 2683 if (function.name() == name.raw()) {
2681 return CheckFunctionType(function, type); 2684 return CheckFunctionType(function, type);
2682 } 2685 }
(...skipping 15 matching lines...) Expand all
2698 2701
2699 RawFunction* Class::LookupFunctionAllowPrivate(const String& name, 2702 RawFunction* Class::LookupFunctionAllowPrivate(const String& name,
2700 intptr_t type) const { 2703 intptr_t type) const {
2701 Isolate* isolate = Isolate::Current(); 2704 Isolate* isolate = Isolate::Current();
2702 if (EnsureIsFinalized(isolate) != Error::null()) { 2705 if (EnsureIsFinalized(isolate) != Error::null()) {
2703 return Function::null(); 2706 return Function::null();
2704 } 2707 }
2705 ReusableHandleScope reused_handles(isolate); 2708 ReusableHandleScope reused_handles(isolate);
2706 Array& funcs = reused_handles.ArrayHandle(); 2709 Array& funcs = reused_handles.ArrayHandle();
2707 funcs ^= functions(); 2710 funcs ^= functions();
2708 if (funcs.IsNull()) { 2711 ASSERT(!funcs.IsNull());
2709 // This can occur, e.g., for Null classes.
2710 return Function::null();
2711 }
2712 Function& function = reused_handles.FunctionHandle(); 2712 Function& function = reused_handles.FunctionHandle();
2713 String& function_name = reused_handles.StringHandle(); 2713 String& function_name = reused_handles.StringHandle();
2714 intptr_t len = funcs.Length(); 2714 intptr_t len = funcs.Length();
2715 for (intptr_t i = 0; i < len; i++) { 2715 for (intptr_t i = 0; i < len; i++) {
2716 function ^= funcs.At(i); 2716 function ^= funcs.At(i);
2717 function_name ^= function.name(); 2717 function_name ^= function.name();
2718 if (String::EqualsIgnoringPrivateKey(function_name, name)) { 2718 if (String::EqualsIgnoringPrivateKey(function_name, name)) {
2719 return CheckFunctionType(function, type); 2719 return CheckFunctionType(function, type);
2720 } 2720 }
2721 } 2721 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2802 2802
2803 2803
2804 RawField* Class::LookupField(const String& name, intptr_t type) const { 2804 RawField* Class::LookupField(const String& name, intptr_t type) const {
2805 Isolate* isolate = Isolate::Current(); 2805 Isolate* isolate = Isolate::Current();
2806 if (EnsureIsFinalized(isolate) != Error::null()) { 2806 if (EnsureIsFinalized(isolate) != Error::null()) {
2807 return Field::null(); 2807 return Field::null();
2808 } 2808 }
2809 ReusableHandleScope reused_handles(isolate); 2809 ReusableHandleScope reused_handles(isolate);
2810 Array& flds = reused_handles.ArrayHandle(); 2810 Array& flds = reused_handles.ArrayHandle();
2811 flds ^= fields(); 2811 flds ^= fields();
2812 if (flds.IsNull()) { 2812 ASSERT(!flds.IsNull());
2813 // This can occur, e.g., for Null classes.
2814 return Field::null();
2815 }
2816 Field& field = reused_handles.FieldHandle(); 2813 Field& field = reused_handles.FieldHandle();
2817 String& field_name = reused_handles.StringHandle(); 2814 String& field_name = reused_handles.StringHandle();
2818 intptr_t len = flds.Length(); 2815 intptr_t len = flds.Length();
2819 for (intptr_t i = 0; i < len; i++) { 2816 for (intptr_t i = 0; i < len; i++) {
2820 field ^= flds.At(i); 2817 field ^= flds.At(i);
2821 field_name ^= field.name(); 2818 field_name ^= field.name();
2822 if (String::EqualsIgnoringPrivateKey(field_name, name)) { 2819 if (String::EqualsIgnoringPrivateKey(field_name, name)) {
2823 if (type == kInstance) { 2820 if (type == kInstance) {
2824 if (!field.is_static()) { 2821 if (!field.is_static()) {
2825 return field.raw(); 2822 return field.raw();
(...skipping 7645 matching lines...) Expand 10 before | Expand all | Expand 10 after
10471 RawString* AbstractType::ClassName() const { 10468 RawString* AbstractType::ClassName() const {
10472 if (HasResolvedTypeClass()) { 10469 if (HasResolvedTypeClass()) {
10473 return Class::Handle(type_class()).Name(); 10470 return Class::Handle(type_class()).Name();
10474 } else { 10471 } else {
10475 return UnresolvedClass::Handle(unresolved_class()).Name(); 10472 return UnresolvedClass::Handle(unresolved_class()).Name();
10476 } 10473 }
10477 } 10474 }
10478 10475
10479 10476
10480 bool AbstractType::IsNullType() const { 10477 bool AbstractType::IsNullType() const {
10481 return HasResolvedTypeClass() && 10478 ASSERT(Type::Handle(Type::NullType()).IsCanonical());
10482 (type_class() == Type::Handle(Type::NullType()).type_class()); 10479 return raw() == Type::NullType();
10483 } 10480 }
10484 10481
10485 10482
10486 bool AbstractType::IsBoolType() const { 10483 bool AbstractType::IsBoolType() const {
10487 return HasResolvedTypeClass() && 10484 return HasResolvedTypeClass() &&
10488 (type_class() == Type::Handle(Type::BoolType()).type_class()); 10485 (type_class() == Type::Handle(Type::BoolType()).type_class());
10489 } 10486 }
10490 10487
10491 10488
10492 bool AbstractType::IsIntType() const { 10489 bool AbstractType::IsIntType() const {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
10621 stream->CloseObject(); 10618 stream->CloseObject();
10622 } 10619 }
10623 10620
10624 10621
10625 RawType* Type::NullType() { 10622 RawType* Type::NullType() {
10626 return Isolate::Current()->object_store()->null_type(); 10623 return Isolate::Current()->object_store()->null_type();
10627 } 10624 }
10628 10625
10629 10626
10630 RawType* Type::DynamicType() { 10627 RawType* Type::DynamicType() {
10631 return Isolate::Current()->object_store()->dynamic_type(); 10628 return Object::dynamic_type();
10632 } 10629 }
10633 10630
10634 10631
10635 RawType* Type::VoidType() { 10632 RawType* Type::VoidType() {
10636 return Isolate::Current()->object_store()->void_type(); 10633 return Object::void_type();
10637 } 10634 }
10638 10635
10639 10636
10640 RawType* Type::ObjectType() { 10637 RawType* Type::ObjectType() {
10641 return Isolate::Current()->object_store()->object_type(); 10638 return Isolate::Current()->object_store()->object_type();
10642 } 10639 }
10643 10640
10644 10641
10645 RawType* Type::BoolType() { 10642 RawType* Type::BoolType() {
10646 return Isolate::Current()->object_store()->bool_type(); 10643 return Isolate::Current()->object_store()->bool_type();
(...skipping 3979 matching lines...) Expand 10 before | Expand all | Expand 10 after
14626 } 14623 }
14627 14624
14628 14625
14629 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 14626 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
14630 stream->OpenObject(); 14627 stream->OpenObject();
14631 stream->CloseObject(); 14628 stream->CloseObject();
14632 } 14629 }
14633 14630
14634 14631
14635 } // namespace dart 14632 } // 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