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

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

Issue 25569002: Do not share type arguments of mixin types, but clone them to avoid finalization (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 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') | tests/language/language_dart2js.status » ('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 1691 matching lines...) Expand 10 before | Expand all | Expand 10 after
1702 const TypeArguments& type_params = TypeArguments::Handle(type_parameters()); 1702 const TypeArguments& type_params = TypeArguments::Handle(type_parameters());
1703 return type_params.Length(); 1703 return type_params.Length();
1704 } 1704 }
1705 1705
1706 1706
1707 intptr_t Class::NumTypeArguments() const { 1707 intptr_t Class::NumTypeArguments() const {
1708 // To work properly, this call requires the super class of this class to be 1708 // To work properly, this call requires the super class of this class to be
1709 // resolved, which is checked by the type_class() call on the super type. 1709 // resolved, which is checked by the type_class() call on the super type.
1710 // Note that calling type_class() on a MixinAppType fails. 1710 // Note that calling type_class() on a MixinAppType fails.
1711 Isolate* isolate = Isolate::Current(); 1711 Isolate* isolate = Isolate::Current();
1712 ReusableHandleScope reused_handles(isolate); 1712 Class& cls = Class::Handle(isolate);
Ivan Posva 2013/10/01 18:50:04 Why was this changed?
regis 2013/10/01 19:11:58 We were just lucky before. NumTypeArguments() is r
1713 Class& cls = reused_handles.ClassHandle(); 1713 TypeArguments& type_params = TypeArguments::Handle(isolate);
1714 TypeArguments& type_params = reused_handles.TypeArgumentsHandle(); 1714 AbstractType& sup_type = AbstractType::Handle(isolate);
1715 AbstractType& sup_type = reused_handles.AbstractTypeHandle();
1716 cls ^= raw(); 1715 cls ^= raw();
1717 intptr_t num_type_args = 0; 1716 intptr_t num_type_args = 0;
1718 1717
1719 do { 1718 do {
1720 if (cls.IsSignatureClass()) { 1719 if (cls.IsSignatureClass()) {
1721 Function& signature_fun = reused_handles.FunctionHandle(); 1720 Function& signature_fun = Function::Handle(isolate);
1722 signature_fun ^= cls.signature_function(); 1721 signature_fun ^= cls.signature_function();
1723 if (!signature_fun.is_static() && 1722 if (!signature_fun.is_static() &&
1724 !signature_fun.HasInstantiatedSignature()) { 1723 !signature_fun.HasInstantiatedSignature()) {
1725 cls = signature_fun.Owner(); 1724 cls = signature_fun.Owner();
1726 } 1725 }
1727 } 1726 }
1728 // Calling NumTypeParameters() on a mixin application class will setup the 1727 // Calling NumTypeParameters() on a mixin application class will setup the
1729 // type parameters if not already done. 1728 // type parameters if not already done.
1730 if (cls.NumTypeParameters() > 0) { 1729 if (cls.NumTypeParameters() > 0) {
1731 type_params ^= cls.type_parameters(); 1730 type_params ^= cls.type_parameters();
(...skipping 1690 matching lines...) Expand 10 before | Expand all | Expand 10 after
3422 type_arg = TypeAt(i); 3421 type_arg = TypeAt(i);
3423 super_type_arg = super_type_args.TypeAt(i); 3422 super_type_arg = super_type_args.TypeAt(i);
3424 if (!type_arg.Equals(super_type_arg)) { 3423 if (!type_arg.Equals(super_type_arg)) {
3425 return false; 3424 return false;
3426 } 3425 }
3427 } 3426 }
3428 return true; 3427 return true;
3429 } 3428 }
3430 3429
3431 3430
3431 bool TypeArguments::IsFinalized() const {
3432 ASSERT(!IsNull());
3433 AbstractType& type = AbstractType::Handle();
3434 const intptr_t num_types = Length();
3435 for (intptr_t i = 0; i < num_types; i++) {
3436 type = TypeAt(i);
3437 if (!type.IsFinalized()) {
3438 return false;
3439 }
3440 }
3441 return true;
3442 }
3443
3444
3432 bool TypeArguments::IsBounded() const { 3445 bool TypeArguments::IsBounded() const {
3433 AbstractType& type = AbstractType::Handle(); 3446 AbstractType& type = AbstractType::Handle();
3434 const intptr_t num_types = Length(); 3447 const intptr_t num_types = Length();
3435 for (intptr_t i = 0; i < num_types; i++) { 3448 for (intptr_t i = 0; i < num_types; i++) {
3436 type = TypeAt(i); 3449 type = TypeAt(i);
3437 if (type.IsBoundedType()) { 3450 if (type.IsBoundedType()) {
3438 return true; 3451 return true;
3439 } 3452 }
3440 if (type.IsTypeParameter()) { 3453 if (type.IsTypeParameter()) {
3441 const AbstractType& bound = AbstractType::Handle( 3454 const AbstractType& bound = AbstractType::Handle(
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
3578 TypeArguments& current = TypeArguments::Handle(isolate); 3591 TypeArguments& current = TypeArguments::Handle(isolate);
3579 current ^= table.At(index); 3592 current ^= table.At(index);
3580 while (!current.IsNull() && !current.Equals(arguments)) { 3593 while (!current.IsNull() && !current.Equals(arguments)) {
3581 index = (index + 1) & (table_size - 1); // Move to next element. 3594 index = (index + 1) & (table_size - 1); // Move to next element.
3582 current ^= table.At(index); 3595 current ^= table.At(index);
3583 } 3596 }
3584 return index; // Index of element if found or slot into which to add it. 3597 return index; // Index of element if found or slot into which to add it.
3585 } 3598 }
3586 3599
3587 3600
3601 RawAbstractTypeArguments* TypeArguments::CloneUnfinalized() const {
3602 if (IsFinalized()) {
3603 return raw();
3604 }
3605 AbstractType& type = AbstractType::Handle();
3606 const intptr_t num_types = Length();
3607 const TypeArguments& clone = TypeArguments::Handle(
3608 TypeArguments::New(num_types));
3609 for (intptr_t i = 0; i < num_types; i++) {
3610 type = TypeAt(i);
3611 type = type.CloneUnfinalized();
3612 clone.SetTypeAt(i, type);
3613 }
3614 return clone.raw();
3615 }
3616
3617
3588 RawAbstractTypeArguments* TypeArguments::Canonicalize() const { 3618 RawAbstractTypeArguments* TypeArguments::Canonicalize() const {
3589 if (IsNull() || IsCanonical()) { 3619 if (IsNull() || IsCanonical()) {
3590 ASSERT(IsOld()); 3620 ASSERT(IsOld());
3591 return this->raw(); 3621 return this->raw();
3592 } 3622 }
3593 Isolate* isolate = Isolate::Current(); 3623 Isolate* isolate = Isolate::Current();
3594 ObjectStore* object_store = isolate->object_store(); 3624 ObjectStore* object_store = isolate->object_store();
3595 const Array& table = Array::Handle(isolate, 3625 const Array& table = Array::Handle(isolate,
3596 object_store->canonical_type_arguments()); 3626 object_store->canonical_type_arguments());
3597 ASSERT(table.Length() > 0); 3627 ASSERT(table.Length() > 0);
(...skipping 7227 matching lines...) Expand 10 before | Expand all | Expand 10 after
10825 10855
10826 RawAbstractType* AbstractType::InstantiateFrom( 10856 RawAbstractType* AbstractType::InstantiateFrom(
10827 const AbstractTypeArguments& instantiator_type_arguments, 10857 const AbstractTypeArguments& instantiator_type_arguments,
10828 Error* bound_error) const { 10858 Error* bound_error) const {
10829 // AbstractType is an abstract class. 10859 // AbstractType is an abstract class.
10830 UNREACHABLE(); 10860 UNREACHABLE();
10831 return NULL; 10861 return NULL;
10832 } 10862 }
10833 10863
10834 10864
10865 RawAbstractType* AbstractType::CloneUnfinalized() const {
10866 // AbstractType is an abstract class.
10867 UNREACHABLE();
10868 return NULL;
10869 }
10870
10871
10835 RawAbstractType* AbstractType::Canonicalize() const { 10872 RawAbstractType* AbstractType::Canonicalize() const {
10836 // AbstractType is an abstract class. 10873 // AbstractType is an abstract class.
10837 UNREACHABLE(); 10874 UNREACHABLE();
10838 return NULL; 10875 return NULL;
10839 } 10876 }
10840 10877
10841 10878
10842 RawString* AbstractType::BuildName(NameVisibility name_visibility) const { 10879 RawString* AbstractType::BuildName(NameVisibility name_visibility) const {
10843 if (IsBoundedType()) { 10880 if (IsBoundedType()) {
10844 // TODO(regis): Should the bound be visible in the name for debug purposes 10881 // TODO(regis): Should the bound be visible in the name for debug purposes
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
11354 } 11391 }
11355 if (!IsFinalized() || !other_type.IsFinalized()) { 11392 if (!IsFinalized() || !other_type.IsFinalized()) {
11356 return false; 11393 return false;
11357 } 11394 }
11358 return AbstractTypeArguments::AreEqual( 11395 return AbstractTypeArguments::AreEqual(
11359 AbstractTypeArguments::Handle(arguments()), 11396 AbstractTypeArguments::Handle(arguments()),
11360 AbstractTypeArguments::Handle(other_type.arguments())); 11397 AbstractTypeArguments::Handle(other_type.arguments()));
11361 } 11398 }
11362 11399
11363 11400
11401 RawAbstractType* Type::CloneUnfinalized() const {
11402 ASSERT(IsResolved());
11403 if (IsFinalized()) {
11404 return raw();
11405 }
11406 ASSERT(!IsMalformed()); // Malformed types are finalized.
11407 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization.
11408 AbstractTypeArguments& type_args = AbstractTypeArguments::Handle(arguments());
11409 type_args = type_args.CloneUnfinalized();
11410 const Class& type_cls = Class::Handle(type_class());
11411 return Type::New(type_cls, type_args, token_pos());
11412 }
11413
11414
11364 RawAbstractType* Type::Canonicalize() const { 11415 RawAbstractType* Type::Canonicalize() const {
11365 ASSERT(IsFinalized()); 11416 ASSERT(IsFinalized());
11366 if (IsCanonical() || IsMalformed()) { 11417 if (IsCanonical() || IsMalformed()) {
11367 ASSERT(IsMalformed() || AbstractTypeArguments::Handle(arguments()).IsOld()); 11418 ASSERT(IsMalformed() || AbstractTypeArguments::Handle(arguments()).IsOld());
11368 return this->raw(); 11419 return this->raw();
11369 } 11420 }
11370 const Class& cls = Class::Handle(type_class()); 11421 const Class& cls = Class::Handle(type_class());
11371 Array& canonical_types = Array::Handle(cls.canonical_types()); 11422 Array& canonical_types = Array::Handle(cls.canonical_types());
11372 if (canonical_types.IsNull()) { 11423 if (canonical_types.IsNull()) {
11373 // Types defined in the VM isolate are canonicalized via the object store. 11424 // Types defined in the VM isolate are canonicalized via the object store.
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
11643 type_param_name.ToCString(), 11694 type_param_name.ToCString(),
11644 class_name.ToCString(), 11695 class_name.ToCString(),
11645 declared_bound_name.ToCString(), 11696 declared_bound_name.ToCString(),
11646 bounded_type_name.ToCString(), 11697 bounded_type_name.ToCString(),
11647 upper_bound_name.ToCString()); 11698 upper_bound_name.ToCString());
11648 } 11699 }
11649 return false; 11700 return false;
11650 } 11701 }
11651 11702
11652 11703
11704 RawAbstractType* TypeParameter::CloneUnfinalized() const {
11705 if (IsFinalized()) {
11706 return raw();
11707 }
11708 // No need to clone bound, as it is not part of the finalization state.
11709 return TypeParameter::New(Class::Handle(parameterized_class()),
11710 index(),
11711 String::Handle(name()),
11712 AbstractType::Handle(bound()),
11713 token_pos());
11714 }
11715
11716
11653 intptr_t TypeParameter::Hash() const { 11717 intptr_t TypeParameter::Hash() const {
11654 ASSERT(IsFinalized()); 11718 ASSERT(IsFinalized());
11655 uword result = 0; 11719 uword result = 0;
11656 result += Class::Handle(parameterized_class()).id(); 11720 result += Class::Handle(parameterized_class()).id();
11657 // Do not include the hash of the bound, which could lead to cycles. 11721 // Do not include the hash of the bound, which could lead to cycles.
11658 result <<= index(); 11722 result <<= index();
11659 return FinalizeHash(result); 11723 return FinalizeHash(result);
11660 } 11724 }
11661 11725
11662 11726
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
11822 } 11886 }
11823 if (bound_error->IsNull()) { 11887 if (bound_error->IsNull()) {
11824 type_param.CheckBound(bounded_type, upper_bound, bound_error); 11888 type_param.CheckBound(bounded_type, upper_bound, bound_error);
11825 } 11889 }
11826 set_is_being_checked(false); 11890 set_is_being_checked(false);
11827 } 11891 }
11828 return bounded_type.raw(); 11892 return bounded_type.raw();
11829 } 11893 }
11830 11894
11831 11895
11896 RawAbstractType* BoundedType::CloneUnfinalized() const {
11897 if (IsFinalized()) {
11898 return raw();
11899 }
11900 AbstractType& bounded_type = AbstractType::Handle(type());
11901
11902 bounded_type = bounded_type.CloneUnfinalized();
11903 // No need to clone bound or type parameter, as they are not part of the
11904 // finalization state of this bounded type.
11905 return BoundedType::New(bounded_type,
11906 AbstractType::Handle(bound()),
11907 TypeParameter::Handle(type_parameter()));
11908 }
11909
11910
11832 intptr_t BoundedType::Hash() const { 11911 intptr_t BoundedType::Hash() const {
11833 uword result = 0; 11912 uword result = 0;
11834 result += AbstractType::Handle(type()).Hash(); 11913 result += AbstractType::Handle(type()).Hash();
11835 // Do not include the hash of the bound, which could lead to cycles. 11914 // Do not include the hash of the bound, which could lead to cycles.
11836 TypeParameter& type_param = TypeParameter::Handle(type_parameter()); 11915 TypeParameter& type_param = TypeParameter::Handle(type_parameter());
11837 if (!type_param.IsNull()) { 11916 if (!type_param.IsNull()) {
11838 result += type_param.Hash(); 11917 result += type_param.Hash();
11839 } 11918 }
11840 return FinalizeHash(result); 11919 return FinalizeHash(result);
11841 } 11920 }
(...skipping 3395 matching lines...) Expand 10 before | Expand all | Expand 10 after
15237 return "_MirrorReference"; 15316 return "_MirrorReference";
15238 } 15317 }
15239 15318
15240 15319
15241 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 15320 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
15242 JSONObject jsobj(stream); 15321 JSONObject jsobj(stream);
15243 } 15322 }
15244 15323
15245 15324
15246 } // namespace dart 15325 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | tests/language/language_dart2js.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698