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/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 Instance* Object::unknown_constant_ = NULL; | 85 Instance* Object::unknown_constant_ = NULL; |
| 86 Instance* Object::non_constant_ = NULL; | 86 Instance* Object::non_constant_ = NULL; |
| 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::null_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | |
| 96 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 95 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 97 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 96 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 98 RawClass* Object::unresolved_class_class_ = | 97 RawClass* Object::unresolved_class_class_ = |
| 99 reinterpret_cast<RawClass*>(RAW_NULL); | 98 reinterpret_cast<RawClass*>(RAW_NULL); |
| 100 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 99 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 101 RawClass* Object::instantiated_type_arguments_class_ = | 100 RawClass* Object::instantiated_type_arguments_class_ = |
| 102 reinterpret_cast<RawClass*>(RAW_NULL); | 101 reinterpret_cast<RawClass*>(RAW_NULL); |
| 103 RawClass* Object::patch_class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 102 RawClass* Object::patch_class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 104 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 103 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 105 RawClass* Object::closure_data_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 104 RawClass* Object::closure_data_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 Class::kNoTypeArguments; | 408 Class::kNoTypeArguments; |
| 410 cls.raw_ptr()->num_native_fields_ = 0; | 409 cls.raw_ptr()->num_native_fields_ = 0; |
| 411 cls.InitEmptyFields(); | 410 cls.InitEmptyFields(); |
| 412 isolate->RegisterClass(cls); | 411 isolate->RegisterClass(cls); |
| 413 } | 412 } |
| 414 | 413 |
| 415 // Allocate and initialize the null class. | 414 // Allocate and initialize the null class. |
| 416 cls = Class::New<Instance>(kNullCid); | 415 cls = Class::New<Instance>(kNullCid); |
| 417 cls.set_is_finalized(); | 416 cls.set_is_finalized(); |
| 418 cls.set_is_type_finalized(); | 417 cls.set_is_type_finalized(); |
| 419 null_class_ = cls.raw(); | 418 isolate->object_store()->set_null_class(cls); |
| 420 | 419 |
| 421 // Allocate and initialize the free list element class. | 420 // Allocate and initialize the free list element class. |
| 422 cls = Class::New<FreeListElement::FakeInstance>(kFreeListElement); | 421 cls = Class::New<FreeListElement::FakeInstance>(kFreeListElement); |
| 423 cls.set_is_finalized(); | 422 cls.set_is_finalized(); |
| 424 cls.set_is_type_finalized(); | 423 cls.set_is_type_finalized(); |
| 425 | 424 |
| 426 // Allocate and initialize the sentinel values of Null class. | 425 // Allocate and initialize the sentinel values of Null class. |
| 427 { | 426 { |
| 428 *sentinel_ ^= | 427 *sentinel_ ^= |
| 429 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); | 428 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 614 | 613 |
| 615 #define SET_CLASS_NAME(class_name, name) \ | 614 #define SET_CLASS_NAME(class_name, name) \ |
| 616 cls = class_name##_class(); \ | 615 cls = class_name##_class(); \ |
| 617 cls.set_name(Symbols::name()); \ | 616 cls.set_name(Symbols::name()); \ |
| 618 | 617 |
| 619 void Object::RegisterSingletonClassNames() { | 618 void Object::RegisterSingletonClassNames() { |
| 620 Class& cls = Class::Handle(); | 619 Class& cls = Class::Handle(); |
| 621 | 620 |
| 622 // Set up names for all VM singleton classes. | 621 // Set up names for all VM singleton classes. |
| 623 SET_CLASS_NAME(class, Class); | 622 SET_CLASS_NAME(class, Class); |
| 624 SET_CLASS_NAME(null, Null); | |
| 625 SET_CLASS_NAME(dynamic, Dynamic); | 623 SET_CLASS_NAME(dynamic, Dynamic); |
| 626 SET_CLASS_NAME(void, Void); | 624 SET_CLASS_NAME(void, Void); |
| 627 SET_CLASS_NAME(unresolved_class, UnresolvedClass); | 625 SET_CLASS_NAME(unresolved_class, UnresolvedClass); |
| 628 SET_CLASS_NAME(type_arguments, TypeArguments); | 626 SET_CLASS_NAME(type_arguments, TypeArguments); |
| 629 SET_CLASS_NAME(instantiated_type_arguments, InstantiatedTypeArguments); | 627 SET_CLASS_NAME(instantiated_type_arguments, InstantiatedTypeArguments); |
| 630 SET_CLASS_NAME(patch_class, PatchClass); | 628 SET_CLASS_NAME(patch_class, PatchClass); |
| 631 SET_CLASS_NAME(function, Function); | 629 SET_CLASS_NAME(function, Function); |
| 632 SET_CLASS_NAME(closure_data, ClosureData); | 630 SET_CLASS_NAME(closure_data, ClosureData); |
| 633 SET_CLASS_NAME(redirection_data, RedirectionData); | 631 SET_CLASS_NAME(redirection_data, RedirectionData); |
| 634 SET_CLASS_NAME(field, Field); | 632 SET_CLASS_NAME(field, Field); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 835 | 833 |
| 836 // Now that the symbol table is initialized and that the core dictionary as | 834 // Now that the symbol table is initialized and that the core dictionary as |
| 837 // well as the core implementation dictionary have been setup, preallocate | 835 // well as the core implementation dictionary have been setup, preallocate |
| 838 // remaining classes and register them by name in the dictionaries. | 836 // remaining classes and register them by name in the dictionaries. |
| 839 String& name = String::Handle(); | 837 String& name = String::Handle(); |
| 840 cls = Class::New<Bool>(); | 838 cls = Class::New<Bool>(); |
| 841 object_store->set_bool_class(cls); | 839 object_store->set_bool_class(cls); |
| 842 RegisterClass(cls, Symbols::Bool(), core_lib); | 840 RegisterClass(cls, Symbols::Bool(), core_lib); |
| 843 pending_classes.Add(cls, Heap::kOld); | 841 pending_classes.Add(cls, Heap::kOld); |
| 844 | 842 |
| 843 cls = Class::New<Instance>(kNullCid); | |
| 844 cls.set_name(Symbols::Null()); | |
| 845 // We immediately mark Null as finalized because it has no corresponding | |
| 846 // source. | |
| 847 cls.set_is_finalized(); | |
| 848 cls.set_is_type_finalized(); | |
| 849 object_store->set_null_class(cls); | |
| 850 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 | |
| 852 // core library, given source and added to the list of classes pending | |
| 853 // finalization. | |
| 854 // RegisterClass(cls, Symbols::Null(), core_lib); | |
| 855 // pending_classes.Add(cls, Heap::kOld); | |
| 856 | |
| 845 cls = object_store->array_class(); // Was allocated above. | 857 cls = object_store->array_class(); // Was allocated above. |
| 846 RegisterPrivateClass(cls, Symbols::ObjectArray(), core_lib); | 858 RegisterPrivateClass(cls, Symbols::ObjectArray(), core_lib); |
| 847 pending_classes.Add(cls, Heap::kOld); | 859 pending_classes.Add(cls, Heap::kOld); |
| 848 // We cannot use NewNonParameterizedType(cls), because Array is parameterized. | 860 // We cannot use NewNonParameterizedType(cls), because Array is parameterized. |
| 849 type ^= Type::New(Object::Handle(cls.raw()), | 861 type ^= Type::New(Object::Handle(cls.raw()), |
| 850 TypeArguments::Handle(), | 862 TypeArguments::Handle(), |
| 851 Scanner::kDummyTokenIndex); | 863 Scanner::kDummyTokenIndex); |
| 852 type.SetIsFinalized(); | 864 type.SetIsFinalized(); |
| 853 type ^= type.Canonicalize(); | 865 type ^= type.Canonicalize(); |
| 854 object_store->set_array_type(type); | 866 object_store->set_array_type(type); |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1093 object_store->set_bool_type(type); | 1105 object_store->set_bool_type(type); |
| 1094 | 1106 |
| 1095 cls = object_store->smi_class(); | 1107 cls = object_store->smi_class(); |
| 1096 type = Type::NewNonParameterizedType(cls); | 1108 type = Type::NewNonParameterizedType(cls); |
| 1097 object_store->set_smi_type(type); | 1109 object_store->set_smi_type(type); |
| 1098 | 1110 |
| 1099 cls = object_store->mint_class(); | 1111 cls = object_store->mint_class(); |
| 1100 type = Type::NewNonParameterizedType(cls); | 1112 type = Type::NewNonParameterizedType(cls); |
| 1101 object_store->set_mint_type(type); | 1113 object_store->set_mint_type(type); |
| 1102 | 1114 |
| 1103 // The classes 'Null' and 'void' are not registered in the class dictionary, | 1115 // The class 'Null' is not register in the class dictionary because it is not |
|
siva
2013/08/10 00:43:34
registered, the comment also doesn't seem correct.
| |
| 1104 // because their names are reserved keywords. Their names are not heap | 1116 // The classes 'void' and 'dynamic' are phoney classes to make type checking |
| 1105 // allocated, because the classes reside in the VM isolate. | 1117 // 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. | |
| 1119 // The class 'dynamic' is registered in the class dictionary because its name | |
| 1120 // is a built-in identifier (this is wrong). | |
|
siva
2013/08/10 00:43:34
Maybe you should add an issue to track this and ad
| |
| 1106 // The corresponding types are stored in the object store. | 1121 // The corresponding types are stored in the object store. |
| 1107 cls = null_class(); | 1122 cls = object_store->null_class(); |
| 1108 type = Type::NewNonParameterizedType(cls); | 1123 type = Type::NewNonParameterizedType(cls); |
| 1109 object_store->set_null_type(type); | 1124 object_store->set_null_type(type); |
| 1110 | 1125 |
| 1126 // Consider removing when/if Null becomes an ordinary class. | |
|
siva
2013/08/10 00:43:34
I think this should also have an issue and a TODO
| |
| 1127 type = object_store->object_type(); | |
| 1128 cls.set_super_type(type); | |
| 1129 | |
| 1111 cls = void_class(); | 1130 cls = void_class(); |
| 1112 type = Type::NewNonParameterizedType(cls); | 1131 type = Type::NewNonParameterizedType(cls); |
| 1113 object_store->set_void_type(type); | 1132 object_store->set_void_type(type); |
| 1114 | 1133 |
| 1115 // The class 'dynamic' is registered in the class dictionary because its name | |
| 1116 // is a built-in identifier, rather than a reserved keyword. Its name is not | |
| 1117 // heap allocated, because the class resides in the VM isolate. | |
| 1118 // The corresponding type, the "unknown type", is stored in the object store. | |
| 1119 cls = dynamic_class(); | 1134 cls = dynamic_class(); |
| 1120 type = Type::NewNonParameterizedType(cls); | 1135 type = Type::NewNonParameterizedType(cls); |
| 1121 object_store->set_dynamic_type(type); | 1136 object_store->set_dynamic_type(type); |
| 1122 | 1137 |
| 1123 // Finish the initialization by compiling the bootstrap scripts containing the | 1138 // Finish the initialization by compiling the bootstrap scripts containing the |
| 1124 // base interfaces and the implementation of the internal classes. | 1139 // base interfaces and the implementation of the internal classes. |
| 1125 const Error& error = Error::Handle(Bootstrap::LoadandCompileScripts()); | 1140 const Error& error = Error::Handle(Bootstrap::LoadandCompileScripts()); |
| 1126 if (!error.IsNull()) { | 1141 if (!error.IsNull()) { |
| 1127 return error.raw(); | 1142 return error.raw(); |
| 1128 } | 1143 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1213 | 1228 |
| 1214 cls = Class::NewStringClass(kExternalOneByteStringCid); | 1229 cls = Class::NewStringClass(kExternalOneByteStringCid); |
| 1215 object_store->set_external_one_byte_string_class(cls); | 1230 object_store->set_external_one_byte_string_class(cls); |
| 1216 | 1231 |
| 1217 cls = Class::NewStringClass(kExternalTwoByteStringCid); | 1232 cls = Class::NewStringClass(kExternalTwoByteStringCid); |
| 1218 object_store->set_external_two_byte_string_class(cls); | 1233 object_store->set_external_two_byte_string_class(cls); |
| 1219 | 1234 |
| 1220 cls = Class::New<Bool>(); | 1235 cls = Class::New<Bool>(); |
| 1221 object_store->set_bool_class(cls); | 1236 object_store->set_bool_class(cls); |
| 1222 | 1237 |
| 1238 cls = Class::New<Instance>(kNullCid); | |
| 1239 object_store->set_null_class(cls); | |
| 1240 | |
| 1223 cls = Class::New<Stacktrace>(); | 1241 cls = Class::New<Stacktrace>(); |
| 1224 object_store->set_stacktrace_class(cls); | 1242 object_store->set_stacktrace_class(cls); |
| 1225 | 1243 |
| 1226 cls = Class::New<JSRegExp>(); | 1244 cls = Class::New<JSRegExp>(); |
| 1227 object_store->set_jsregexp_class(cls); | 1245 object_store->set_jsregexp_class(cls); |
| 1228 | 1246 |
| 1229 // Some classes are not stored in the object store. Yet we still need to | 1247 // Some classes are not stored in the object store. Yet we still need to |
| 1230 // create their Class object so that they get put into the class_table | 1248 // create their Class object so that they get put into the class_table |
| 1231 // (as a side effect of Class::New()). | 1249 // (as a side effect of Class::New()). |
| 1232 cls = Class::New<DartFunction>(); | 1250 cls = Class::New<DartFunction>(); |
| (...skipping 9203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10436 | 10454 |
| 10437 RawString* AbstractType::ClassName() const { | 10455 RawString* AbstractType::ClassName() const { |
| 10438 if (HasResolvedTypeClass()) { | 10456 if (HasResolvedTypeClass()) { |
| 10439 return Class::Handle(type_class()).Name(); | 10457 return Class::Handle(type_class()).Name(); |
| 10440 } else { | 10458 } else { |
| 10441 return UnresolvedClass::Handle(unresolved_class()).Name(); | 10459 return UnresolvedClass::Handle(unresolved_class()).Name(); |
| 10442 } | 10460 } |
| 10443 } | 10461 } |
| 10444 | 10462 |
| 10445 | 10463 |
| 10464 bool AbstractType::IsNullType() const { | |
| 10465 return HasResolvedTypeClass() && | |
| 10466 (type_class() == Type::Handle(Type::NullType()).type_class()); | |
|
siva
2013/08/10 00:43:34
This has become an expensive operation now with th
| |
| 10467 } | |
| 10468 | |
| 10469 | |
| 10446 bool AbstractType::IsBoolType() const { | 10470 bool AbstractType::IsBoolType() const { |
| 10447 return HasResolvedTypeClass() && | 10471 return HasResolvedTypeClass() && |
| 10448 (type_class() == Type::Handle(Type::BoolType()).type_class()); | 10472 (type_class() == Type::Handle(Type::BoolType()).type_class()); |
| 10449 } | 10473 } |
| 10450 | 10474 |
| 10451 | 10475 |
| 10452 bool AbstractType::IsIntType() const { | 10476 bool AbstractType::IsIntType() const { |
| 10453 return HasResolvedTypeClass() && | 10477 return HasResolvedTypeClass() && |
| 10454 (type_class() == Type::Handle(Type::IntType()).type_class()); | 10478 (type_class() == Type::Handle(Type::IntType()).type_class()); |
| 10455 } | 10479 } |
| (...skipping 4130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14586 } | 14610 } |
| 14587 | 14611 |
| 14588 | 14612 |
| 14589 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 14613 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 14590 stream->OpenObject(); | 14614 stream->OpenObject(); |
| 14591 stream->CloseObject(); | 14615 stream->CloseObject(); |
| 14592 } | 14616 } |
| 14593 | 14617 |
| 14594 | 14618 |
| 14595 } // namespace dart | 14619 } // namespace dart |
| OLD | NEW |