| 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 4813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4824 return true; | 4824 return true; |
| 4825 } | 4825 } |
| 4826 } | 4826 } |
| 4827 return false; | 4827 return false; |
| 4828 } | 4828 } |
| 4829 | 4829 |
| 4830 | 4830 |
| 4831 RawTypeArguments* TypeArguments::InstantiateFrom( | 4831 RawTypeArguments* TypeArguments::InstantiateFrom( |
| 4832 const TypeArguments& instantiator_type_arguments, | 4832 const TypeArguments& instantiator_type_arguments, |
| 4833 Error* bound_error, | 4833 Error* bound_error, |
| 4834 TrailPtr trail) const { | 4834 TrailPtr trail, |
| 4835 Heap::Space space) const { |
| 4835 ASSERT(!IsInstantiated()); | 4836 ASSERT(!IsInstantiated()); |
| 4836 if (!instantiator_type_arguments.IsNull() && | 4837 if (!instantiator_type_arguments.IsNull() && |
| 4837 IsUninstantiatedIdentity() && | 4838 IsUninstantiatedIdentity() && |
| 4838 (instantiator_type_arguments.Length() == Length())) { | 4839 (instantiator_type_arguments.Length() == Length())) { |
| 4839 return instantiator_type_arguments.raw(); | 4840 return instantiator_type_arguments.raw(); |
| 4840 } | 4841 } |
| 4841 const intptr_t num_types = Length(); | 4842 const intptr_t num_types = Length(); |
| 4842 TypeArguments& instantiated_array = | 4843 TypeArguments& instantiated_array = |
| 4843 TypeArguments::Handle(TypeArguments::New(num_types, Heap::kNew)); | 4844 TypeArguments::Handle(TypeArguments::New(num_types, space)); |
| 4844 AbstractType& type = AbstractType::Handle(); | 4845 AbstractType& type = AbstractType::Handle(); |
| 4845 for (intptr_t i = 0; i < num_types; i++) { | 4846 for (intptr_t i = 0; i < num_types; i++) { |
| 4846 type = TypeAt(i); | 4847 type = TypeAt(i); |
| 4847 // If this type argument T is null, the type A containing T in its flattened | 4848 // If this type argument T is null, the type A containing T in its flattened |
| 4848 // type argument vector V is recursive and is still being finalized. | 4849 // type argument vector V is recursive and is still being finalized. |
| 4849 // T is the type argument of a super type of A. T is being instantiated | 4850 // T is the type argument of a super type of A. T is being instantiated |
| 4850 // during finalization of V, which is also the instantiator. T depends | 4851 // during finalization of V, which is also the instantiator. T depends |
| 4851 // solely on the type parameters of A and will be replaced by a non-null | 4852 // solely on the type parameters of A and will be replaced by a non-null |
| 4852 // type before A is marked as finalized. | 4853 // type before A is marked as finalized. |
| 4853 if (!type.IsNull() && !type.IsInstantiated()) { | 4854 if (!type.IsNull() && !type.IsInstantiated()) { |
| 4854 type = type.InstantiateFrom(instantiator_type_arguments, | 4855 type = type.InstantiateFrom(instantiator_type_arguments, |
| 4855 bound_error, | 4856 bound_error, |
| 4856 trail); | 4857 trail, |
| 4858 space); |
| 4857 } | 4859 } |
| 4858 instantiated_array.SetTypeAt(i, type); | 4860 instantiated_array.SetTypeAt(i, type); |
| 4859 } | 4861 } |
| 4860 return instantiated_array.raw(); | 4862 return instantiated_array.raw(); |
| 4861 } | 4863 } |
| 4862 | 4864 |
| 4863 | 4865 |
| 4864 RawTypeArguments* TypeArguments::InstantiateAndCanonicalizeFrom( | 4866 RawTypeArguments* TypeArguments::InstantiateAndCanonicalizeFrom( |
| 4865 const TypeArguments& instantiator_type_arguments, | 4867 const TypeArguments& instantiator_type_arguments, |
| 4866 Error* bound_error) const { | 4868 Error* bound_error) const { |
| (...skipping 8910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13777 | 13779 |
| 13778 RawMegamorphicCache* MegamorphicCache::New() { | 13780 RawMegamorphicCache* MegamorphicCache::New() { |
| 13779 MegamorphicCache& result = MegamorphicCache::Handle(); | 13781 MegamorphicCache& result = MegamorphicCache::Handle(); |
| 13780 { RawObject* raw = Object::Allocate(MegamorphicCache::kClassId, | 13782 { RawObject* raw = Object::Allocate(MegamorphicCache::kClassId, |
| 13781 MegamorphicCache::InstanceSize(), | 13783 MegamorphicCache::InstanceSize(), |
| 13782 Heap::kOld); | 13784 Heap::kOld); |
| 13783 NoSafepointScope no_safepoint; | 13785 NoSafepointScope no_safepoint; |
| 13784 result ^= raw; | 13786 result ^= raw; |
| 13785 } | 13787 } |
| 13786 const intptr_t capacity = kInitialCapacity; | 13788 const intptr_t capacity = kInitialCapacity; |
| 13787 const Array& buckets = Array::Handle(Array::New(kEntryLength * capacity)); | 13789 const Array& buckets = Array::Handle( |
| 13790 Array::New(kEntryLength * capacity, Heap::kOld)); |
| 13788 ASSERT(Isolate::Current()->megamorphic_cache_table()->miss_handler() != NULL); | 13791 ASSERT(Isolate::Current()->megamorphic_cache_table()->miss_handler() != NULL); |
| 13789 const Function& handler = Function::Handle( | 13792 const Function& handler = Function::Handle( |
| 13790 Isolate::Current()->megamorphic_cache_table()->miss_handler()); | 13793 Isolate::Current()->megamorphic_cache_table()->miss_handler()); |
| 13791 for (intptr_t i = 0; i < capacity; ++i) { | 13794 for (intptr_t i = 0; i < capacity; ++i) { |
| 13792 SetEntry(buckets, i, smi_illegal_cid(), handler); | 13795 SetEntry(buckets, i, smi_illegal_cid(), handler); |
| 13793 } | 13796 } |
| 13794 result.set_buckets(buckets); | 13797 result.set_buckets(buckets); |
| 13795 result.set_mask(capacity - 1); | 13798 result.set_mask(capacity - 1); |
| 13796 result.set_filled_entry_count(0); | 13799 result.set_filled_entry_count(0); |
| 13797 return result.raw(); | 13800 return result.raw(); |
| (...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14914 bool AbstractType::IsRecursive() const { | 14917 bool AbstractType::IsRecursive() const { |
| 14915 // AbstractType is an abstract class. | 14918 // AbstractType is an abstract class. |
| 14916 UNREACHABLE(); | 14919 UNREACHABLE(); |
| 14917 return false; | 14920 return false; |
| 14918 } | 14921 } |
| 14919 | 14922 |
| 14920 | 14923 |
| 14921 RawAbstractType* AbstractType::InstantiateFrom( | 14924 RawAbstractType* AbstractType::InstantiateFrom( |
| 14922 const TypeArguments& instantiator_type_arguments, | 14925 const TypeArguments& instantiator_type_arguments, |
| 14923 Error* bound_error, | 14926 Error* bound_error, |
| 14924 TrailPtr trail) const { | 14927 TrailPtr trail, |
| 14928 Heap::Space space) const { |
| 14925 // AbstractType is an abstract class. | 14929 // AbstractType is an abstract class. |
| 14926 UNREACHABLE(); | 14930 UNREACHABLE(); |
| 14927 return NULL; | 14931 return NULL; |
| 14928 } | 14932 } |
| 14929 | 14933 |
| 14930 | 14934 |
| 14931 RawAbstractType* AbstractType::CloneUnfinalized() const { | 14935 RawAbstractType* AbstractType::CloneUnfinalized() const { |
| 14932 // AbstractType is an abstract class. | 14936 // AbstractType is an abstract class. |
| 14933 UNREACHABLE(); | 14937 UNREACHABLE(); |
| 14934 return NULL; | 14938 return NULL; |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15515 num_type_args = len; | 15519 num_type_args = len; |
| 15516 len = cls.NumTypeParameters(); // Check the type parameters only. | 15520 len = cls.NumTypeParameters(); // Check the type parameters only. |
| 15517 } | 15521 } |
| 15518 return (len == 0) || args.IsSubvectorInstantiated(num_type_args - len, len); | 15522 return (len == 0) || args.IsSubvectorInstantiated(num_type_args - len, len); |
| 15519 } | 15523 } |
| 15520 | 15524 |
| 15521 | 15525 |
| 15522 RawAbstractType* Type::InstantiateFrom( | 15526 RawAbstractType* Type::InstantiateFrom( |
| 15523 const TypeArguments& instantiator_type_arguments, | 15527 const TypeArguments& instantiator_type_arguments, |
| 15524 Error* bound_error, | 15528 Error* bound_error, |
| 15525 TrailPtr trail) const { | 15529 TrailPtr trail, |
| 15530 Heap::Space space) const { |
| 15531 Zone* zone = Thread::Current()->zone(); |
| 15526 ASSERT(IsFinalized() || IsBeingFinalized()); | 15532 ASSERT(IsFinalized() || IsBeingFinalized()); |
| 15527 ASSERT(!IsInstantiated()); | 15533 ASSERT(!IsInstantiated()); |
| 15528 // Return the uninstantiated type unchanged if malformed. No copy needed. | 15534 // Return the uninstantiated type unchanged if malformed. No copy needed. |
| 15529 if (IsMalformed()) { | 15535 if (IsMalformed()) { |
| 15530 return raw(); | 15536 return raw(); |
| 15531 } | 15537 } |
| 15532 // Instantiating this type with its own type arguments as instantiator can | 15538 // Instantiating this type with its own type arguments as instantiator can |
| 15533 // occur during finalization and bounds checking. Return the type unchanged. | 15539 // occur during finalization and bounds checking. Return the type unchanged. |
| 15534 if (arguments() == instantiator_type_arguments.raw()) { | 15540 if (arguments() == instantiator_type_arguments.raw()) { |
| 15535 return raw(); | 15541 return raw(); |
| 15536 } | 15542 } |
| 15537 // If this type is recursive, we may already be instantiating it. | 15543 // If this type is recursive, we may already be instantiating it. |
| 15538 Type& instantiated_type = Type::Handle(); | 15544 Type& instantiated_type = Type::Handle(zone); |
| 15539 instantiated_type ^= OnlyBuddyInTrail(trail); | 15545 instantiated_type ^= OnlyBuddyInTrail(trail); |
| 15540 if (!instantiated_type.IsNull()) { | 15546 if (!instantiated_type.IsNull()) { |
| 15541 ASSERT(IsRecursive()); | 15547 ASSERT(IsRecursive()); |
| 15542 return instantiated_type.raw(); | 15548 return instantiated_type.raw(); |
| 15543 } | 15549 } |
| 15544 // Note that the type class has to be resolved at this time, but not | 15550 // Note that the type class has to be resolved at this time, but not |
| 15545 // necessarily finalized yet. We may be checking bounds at compile time or | 15551 // necessarily finalized yet. We may be checking bounds at compile time or |
| 15546 // finalizing the type argument vector of a recursive type. | 15552 // finalizing the type argument vector of a recursive type. |
| 15547 const Class& cls = Class::Handle(type_class()); | 15553 const Class& cls = Class::Handle(zone, type_class()); |
| 15548 | 15554 |
| 15549 // This uninstantiated type is not modified, as it can be instantiated | 15555 // This uninstantiated type is not modified, as it can be instantiated |
| 15550 // with different instantiators. Allocate a new instantiated version of it. | 15556 // with different instantiators. Allocate a new instantiated version of it. |
| 15551 instantiated_type = Type::New(cls, TypeArguments::Handle(), token_pos()); | 15557 instantiated_type = Type::New(cls, TypeArguments::Handle(zone), token_pos()); |
| 15552 TypeArguments& type_arguments = TypeArguments::Handle(arguments()); | 15558 TypeArguments& type_arguments = TypeArguments::Handle(zone, arguments()); |
| 15553 ASSERT(type_arguments.Length() == cls.NumTypeArguments()); | 15559 ASSERT(type_arguments.Length() == cls.NumTypeArguments()); |
| 15554 if (type_arguments.IsRecursive()) { | 15560 if (type_arguments.IsRecursive()) { |
| 15555 AddOnlyBuddyToTrail(&trail, instantiated_type); | 15561 AddOnlyBuddyToTrail(&trail, instantiated_type); |
| 15556 } | 15562 } |
| 15557 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, | 15563 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, |
| 15558 bound_error, | 15564 bound_error, |
| 15559 trail); | 15565 trail, |
| 15566 space); |
| 15560 instantiated_type.set_arguments(type_arguments); | 15567 instantiated_type.set_arguments(type_arguments); |
| 15561 if (IsFinalized()) { | 15568 if (IsFinalized()) { |
| 15562 instantiated_type.SetIsFinalized(); | 15569 instantiated_type.SetIsFinalized(); |
| 15563 } else { | 15570 } else { |
| 15564 instantiated_type.set_is_resolved(); | 15571 instantiated_type.set_is_resolved(); |
| 15565 } | 15572 } |
| 15566 // Canonicalization is not part of instantiation. | 15573 // Canonicalization is not part of instantiation. |
| 15567 return instantiated_type.raw(); | 15574 return instantiated_type.raw(); |
| 15568 } | 15575 } |
| 15569 | 15576 |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15956 if (TestAndAddBuddyToTrail(&trail, AbstractType::Cast(other))) { | 15963 if (TestAndAddBuddyToTrail(&trail, AbstractType::Cast(other))) { |
| 15957 return true; | 15964 return true; |
| 15958 } | 15965 } |
| 15959 return AbstractType::Handle(type()).IsEquivalent(other, trail); | 15966 return AbstractType::Handle(type()).IsEquivalent(other, trail); |
| 15960 } | 15967 } |
| 15961 | 15968 |
| 15962 | 15969 |
| 15963 RawTypeRef* TypeRef::InstantiateFrom( | 15970 RawTypeRef* TypeRef::InstantiateFrom( |
| 15964 const TypeArguments& instantiator_type_arguments, | 15971 const TypeArguments& instantiator_type_arguments, |
| 15965 Error* bound_error, | 15972 Error* bound_error, |
| 15966 TrailPtr trail) const { | 15973 TrailPtr trail, |
| 15974 Heap::Space space) const { |
| 15967 TypeRef& instantiated_type_ref = TypeRef::Handle(); | 15975 TypeRef& instantiated_type_ref = TypeRef::Handle(); |
| 15968 instantiated_type_ref ^= OnlyBuddyInTrail(trail); | 15976 instantiated_type_ref ^= OnlyBuddyInTrail(trail); |
| 15969 if (!instantiated_type_ref.IsNull()) { | 15977 if (!instantiated_type_ref.IsNull()) { |
| 15970 return instantiated_type_ref.raw(); | 15978 return instantiated_type_ref.raw(); |
| 15971 } | 15979 } |
| 15972 AbstractType& ref_type = AbstractType::Handle(type()); | 15980 AbstractType& ref_type = AbstractType::Handle(type()); |
| 15973 ASSERT(!ref_type.IsTypeRef()); | 15981 ASSERT(!ref_type.IsTypeRef()); |
| 15974 AbstractType& instantiated_ref_type = AbstractType::Handle(); | 15982 AbstractType& instantiated_ref_type = AbstractType::Handle(); |
| 15975 instantiated_ref_type = ref_type.InstantiateFrom( | 15983 instantiated_ref_type = ref_type.InstantiateFrom( |
| 15976 instantiator_type_arguments, bound_error, trail); | 15984 instantiator_type_arguments, bound_error, trail, space); |
| 15977 ASSERT(!instantiated_ref_type.IsTypeRef()); | 15985 ASSERT(!instantiated_ref_type.IsTypeRef()); |
| 15978 instantiated_type_ref = TypeRef::New(instantiated_ref_type); | 15986 instantiated_type_ref = TypeRef::New(instantiated_ref_type); |
| 15979 AddOnlyBuddyToTrail(&trail, instantiated_type_ref); | 15987 AddOnlyBuddyToTrail(&trail, instantiated_type_ref); |
| 15980 return instantiated_type_ref.raw(); | 15988 return instantiated_type_ref.raw(); |
| 15981 } | 15989 } |
| 15982 | 15990 |
| 15983 | 15991 |
| 15984 RawTypeRef* TypeRef::CloneUninstantiated(const Class& new_owner, | 15992 RawTypeRef* TypeRef::CloneUninstantiated(const Class& new_owner, |
| 15985 TrailPtr trail) const { | 15993 TrailPtr trail) const { |
| 15986 TypeRef& cloned_type_ref = TypeRef::Handle(); | 15994 TypeRef& cloned_type_ref = TypeRef::Handle(); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16170 | 16178 |
| 16171 | 16179 |
| 16172 void TypeParameter::set_bound(const AbstractType& value) const { | 16180 void TypeParameter::set_bound(const AbstractType& value) const { |
| 16173 StorePointer(&raw_ptr()->bound_, value.raw()); | 16181 StorePointer(&raw_ptr()->bound_, value.raw()); |
| 16174 } | 16182 } |
| 16175 | 16183 |
| 16176 | 16184 |
| 16177 RawAbstractType* TypeParameter::InstantiateFrom( | 16185 RawAbstractType* TypeParameter::InstantiateFrom( |
| 16178 const TypeArguments& instantiator_type_arguments, | 16186 const TypeArguments& instantiator_type_arguments, |
| 16179 Error* bound_error, | 16187 Error* bound_error, |
| 16180 TrailPtr trail) const { | 16188 TrailPtr trail, |
| 16189 Heap::Space space) const { |
| 16181 ASSERT(IsFinalized()); | 16190 ASSERT(IsFinalized()); |
| 16182 if (instantiator_type_arguments.IsNull()) { | 16191 if (instantiator_type_arguments.IsNull()) { |
| 16183 return Type::DynamicType(); | 16192 return Type::DynamicType(); |
| 16184 } | 16193 } |
| 16185 const AbstractType& type_arg = AbstractType::Handle( | 16194 const AbstractType& type_arg = AbstractType::Handle( |
| 16186 instantiator_type_arguments.TypeAt(index())); | 16195 instantiator_type_arguments.TypeAt(index())); |
| 16187 // There is no need to canonicalize the instantiated type parameter, since all | 16196 // There is no need to canonicalize the instantiated type parameter, since all |
| 16188 // type arguments are canonicalized at type finalization time. It would be too | 16197 // type arguments are canonicalized at type finalization time. It would be too |
| 16189 // early to canonicalize the returned type argument here, since instantiation | 16198 // early to canonicalize the returned type argument here, since instantiation |
| 16190 // not only happens at run time, but also during type finalization. | 16199 // not only happens at run time, but also during type finalization. |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16433 // A null type parameter is set when marking a type malformed because of a | 16442 // A null type parameter is set when marking a type malformed because of a |
| 16434 // bound error at compile time. | 16443 // bound error at compile time. |
| 16435 ASSERT(value.IsNull() || value.IsFinalized()); | 16444 ASSERT(value.IsNull() || value.IsFinalized()); |
| 16436 StorePointer(&raw_ptr()->type_parameter_, value.raw()); | 16445 StorePointer(&raw_ptr()->type_parameter_, value.raw()); |
| 16437 } | 16446 } |
| 16438 | 16447 |
| 16439 | 16448 |
| 16440 RawAbstractType* BoundedType::InstantiateFrom( | 16449 RawAbstractType* BoundedType::InstantiateFrom( |
| 16441 const TypeArguments& instantiator_type_arguments, | 16450 const TypeArguments& instantiator_type_arguments, |
| 16442 Error* bound_error, | 16451 Error* bound_error, |
| 16443 TrailPtr trail) const { | 16452 TrailPtr trail, |
| 16453 Heap::Space space) const { |
| 16444 ASSERT(IsFinalized()); | 16454 ASSERT(IsFinalized()); |
| 16445 AbstractType& bounded_type = AbstractType::Handle(type()); | 16455 AbstractType& bounded_type = AbstractType::Handle(type()); |
| 16446 ASSERT(bounded_type.IsFinalized()); | 16456 ASSERT(bounded_type.IsFinalized()); |
| 16447 if (!bounded_type.IsInstantiated()) { | 16457 if (!bounded_type.IsInstantiated()) { |
| 16448 bounded_type = bounded_type.InstantiateFrom(instantiator_type_arguments, | 16458 bounded_type = bounded_type.InstantiateFrom(instantiator_type_arguments, |
| 16449 bound_error, | 16459 bound_error, |
| 16450 trail); | 16460 trail, |
| 16461 space); |
| 16451 // In case types of instantiator_type_arguments are not finalized, then | 16462 // In case types of instantiator_type_arguments are not finalized, then |
| 16452 // the instantiated bounded_type is not finalized either. | 16463 // the instantiated bounded_type is not finalized either. |
| 16453 // Note that instantiator_type_arguments must have the final length, though. | 16464 // Note that instantiator_type_arguments must have the final length, though. |
| 16454 } | 16465 } |
| 16455 if ((Isolate::Current()->flags().type_checks()) && | 16466 if ((Isolate::Current()->flags().type_checks()) && |
| 16456 (bound_error != NULL) && bound_error->IsNull()) { | 16467 (bound_error != NULL) && bound_error->IsNull()) { |
| 16457 AbstractType& upper_bound = AbstractType::Handle(bound()); | 16468 AbstractType& upper_bound = AbstractType::Handle(bound()); |
| 16458 ASSERT(upper_bound.IsFinalized()); | 16469 ASSERT(upper_bound.IsFinalized()); |
| 16459 ASSERT(!upper_bound.IsObjectType() && !upper_bound.IsDynamicType()); | 16470 ASSERT(!upper_bound.IsObjectType() && !upper_bound.IsDynamicType()); |
| 16460 const TypeParameter& type_param = TypeParameter::Handle(type_parameter()); | 16471 const TypeParameter& type_param = TypeParameter::Handle(type_parameter()); |
| 16461 if (!upper_bound.IsInstantiated()) { | 16472 if (!upper_bound.IsInstantiated()) { |
| 16462 upper_bound = upper_bound.InstantiateFrom(instantiator_type_arguments, | 16473 upper_bound = upper_bound.InstantiateFrom(instantiator_type_arguments, |
| 16463 bound_error, | 16474 bound_error, |
| 16464 trail); | 16475 trail, |
| 16476 space); |
| 16465 // Instantiated upper_bound may not be finalized. See comment above. | 16477 // Instantiated upper_bound may not be finalized. See comment above. |
| 16466 } | 16478 } |
| 16467 if (bound_error->IsNull()) { | 16479 if (bound_error->IsNull()) { |
| 16468 if (!type_param.CheckBound(bounded_type, upper_bound, bound_error) && | 16480 if (!type_param.CheckBound(bounded_type, upper_bound, bound_error) && |
| 16469 bound_error->IsNull()) { | 16481 bound_error->IsNull()) { |
| 16470 // We cannot determine yet whether the bounded_type is below the | 16482 // We cannot determine yet whether the bounded_type is below the |
| 16471 // upper_bound, because one or both of them is still uninstantiated. | 16483 // upper_bound, because one or both of them is still uninstantiated. |
| 16472 ASSERT(!bounded_type.IsInstantiated() || !upper_bound.IsInstantiated()); | 16484 ASSERT(!bounded_type.IsInstantiated() || !upper_bound.IsInstantiated()); |
| 16473 // Postpone bound check by returning a new BoundedType with partially | 16485 // Postpone bound check by returning a new BoundedType with partially |
| 16474 // instantiated bounded_type and upper_bound, but keeping type_param. | 16486 // instantiated bounded_type and upper_bound, but keeping type_param. |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16845 if (Smi::IsValid(value)) { | 16857 if (Smi::IsValid(value)) { |
| 16846 return Smi::New(value); | 16858 return Smi::New(value); |
| 16847 } | 16859 } |
| 16848 return Mint::New(value); | 16860 return Mint::New(value); |
| 16849 } | 16861 } |
| 16850 return raw(); | 16862 return raw(); |
| 16851 } | 16863 } |
| 16852 | 16864 |
| 16853 | 16865 |
| 16854 RawInteger* Integer::ArithmeticOp(Token::Kind operation, | 16866 RawInteger* Integer::ArithmeticOp(Token::Kind operation, |
| 16855 const Integer& other) const { | 16867 const Integer& other, |
| 16868 Heap::Space space) const { |
| 16856 // In 32-bit mode, the result of any operation between two Smis will fit in a | 16869 // In 32-bit mode, the result of any operation between two Smis will fit in a |
| 16857 // 32-bit signed result, except the product of two Smis, which will be 64-bit. | 16870 // 32-bit signed result, except the product of two Smis, which will be 64-bit. |
| 16858 // In 64-bit mode, the result of any operation between two Smis will fit in a | 16871 // In 64-bit mode, the result of any operation between two Smis will fit in a |
| 16859 // 64-bit signed result, except the product of two Smis (see below). | 16872 // 64-bit signed result, except the product of two Smis (see below). |
| 16860 if (IsSmi() && other.IsSmi()) { | 16873 if (IsSmi() && other.IsSmi()) { |
| 16861 const intptr_t left_value = Smi::Value(Smi::RawCast(raw())); | 16874 const intptr_t left_value = Smi::Value(Smi::RawCast(raw())); |
| 16862 const intptr_t right_value = Smi::Value(Smi::RawCast(other.raw())); | 16875 const intptr_t right_value = Smi::Value(Smi::RawCast(other.raw())); |
| 16863 switch (operation) { | 16876 switch (operation) { |
| 16864 case Token::kADD: | 16877 case Token::kADD: |
| 16865 return Integer::New(left_value + right_value); | 16878 return Integer::New(left_value + right_value, space); |
| 16866 case Token::kSUB: | 16879 case Token::kSUB: |
| 16867 return Integer::New(left_value - right_value); | 16880 return Integer::New(left_value - right_value, space); |
| 16868 case Token::kMUL: { | 16881 case Token::kMUL: { |
| 16869 if (Smi::kBits < 32) { | 16882 if (Smi::kBits < 32) { |
| 16870 // In 32-bit mode, the product of two Smis fits in a 64-bit result. | 16883 // In 32-bit mode, the product of two Smis fits in a 64-bit result. |
| 16871 return Integer::New(static_cast<int64_t>(left_value) * | 16884 return Integer::New(static_cast<int64_t>(left_value) * |
| 16872 static_cast<int64_t>(right_value)); | 16885 static_cast<int64_t>(right_value), |
| 16886 space); |
| 16873 } else { | 16887 } else { |
| 16874 // In 64-bit mode, the product of two signed integers fits in a | 16888 // In 64-bit mode, the product of two signed integers fits in a |
| 16875 // 64-bit result if the sum of the highest bits of their absolute | 16889 // 64-bit result if the sum of the highest bits of their absolute |
| 16876 // values is smaller than 62. | 16890 // values is smaller than 62. |
| 16877 ASSERT(sizeof(intptr_t) == sizeof(int64_t)); | 16891 ASSERT(sizeof(intptr_t) == sizeof(int64_t)); |
| 16878 if ((Utils::HighestBit(left_value) + | 16892 if ((Utils::HighestBit(left_value) + |
| 16879 Utils::HighestBit(right_value)) < 62) { | 16893 Utils::HighestBit(right_value)) < 62) { |
| 16880 return Integer::New(left_value * right_value); | 16894 return Integer::New(left_value * right_value, space); |
| 16881 } | 16895 } |
| 16882 } | 16896 } |
| 16883 // Perform a Bigint multiplication below. | 16897 // Perform a Bigint multiplication below. |
| 16884 break; | 16898 break; |
| 16885 } | 16899 } |
| 16886 case Token::kTRUNCDIV: | 16900 case Token::kTRUNCDIV: |
| 16887 return Integer::New(left_value / right_value); | 16901 return Integer::New(left_value / right_value, space); |
| 16888 case Token::kMOD: { | 16902 case Token::kMOD: { |
| 16889 const intptr_t remainder = left_value % right_value; | 16903 const intptr_t remainder = left_value % right_value; |
| 16890 if (remainder < 0) { | 16904 if (remainder < 0) { |
| 16891 if (right_value < 0) { | 16905 if (right_value < 0) { |
| 16892 return Integer::New(remainder - right_value); | 16906 return Integer::New(remainder - right_value, space); |
| 16893 } else { | 16907 } else { |
| 16894 return Integer::New(remainder + right_value); | 16908 return Integer::New(remainder + right_value, space); |
| 16895 } | 16909 } |
| 16896 } | 16910 } |
| 16897 return Integer::New(remainder); | 16911 return Integer::New(remainder, space); |
| 16898 } | 16912 } |
| 16899 default: | 16913 default: |
| 16900 UNIMPLEMENTED(); | 16914 UNIMPLEMENTED(); |
| 16901 } | 16915 } |
| 16902 } | 16916 } |
| 16903 if (!IsBigint() && !other.IsBigint()) { | 16917 if (!IsBigint() && !other.IsBigint()) { |
| 16904 const int64_t left_value = AsInt64Value(); | 16918 const int64_t left_value = AsInt64Value(); |
| 16905 const int64_t right_value = other.AsInt64Value(); | 16919 const int64_t right_value = other.AsInt64Value(); |
| 16906 switch (operation) { | 16920 switch (operation) { |
| 16907 case Token::kADD: { | 16921 case Token::kADD: { |
| 16908 if (((left_value < 0) != (right_value < 0)) || | 16922 if (((left_value < 0) != (right_value < 0)) || |
| 16909 ((left_value + right_value) < 0) == (left_value < 0)) { | 16923 ((left_value + right_value) < 0) == (left_value < 0)) { |
| 16910 return Integer::New(left_value + right_value); | 16924 return Integer::New(left_value + right_value, space); |
| 16911 } | 16925 } |
| 16912 break; | 16926 break; |
| 16913 } | 16927 } |
| 16914 case Token::kSUB: { | 16928 case Token::kSUB: { |
| 16915 if (((left_value < 0) == (right_value < 0)) || | 16929 if (((left_value < 0) == (right_value < 0)) || |
| 16916 ((left_value - right_value) < 0) == (left_value < 0)) { | 16930 ((left_value - right_value) < 0) == (left_value < 0)) { |
| 16917 return Integer::New(left_value - right_value); | 16931 return Integer::New(left_value - right_value, space); |
| 16918 } | 16932 } |
| 16919 break; | 16933 break; |
| 16920 } | 16934 } |
| 16921 case Token::kMUL: { | 16935 case Token::kMUL: { |
| 16922 if ((Utils::HighestBit(left_value) + | 16936 if ((Utils::HighestBit(left_value) + |
| 16923 Utils::HighestBit(right_value)) < 62) { | 16937 Utils::HighestBit(right_value)) < 62) { |
| 16924 return Integer::New(left_value * right_value); | 16938 return Integer::New(left_value * right_value, space); |
| 16925 } | 16939 } |
| 16926 break; | 16940 break; |
| 16927 } | 16941 } |
| 16928 case Token::kTRUNCDIV: { | 16942 case Token::kTRUNCDIV: { |
| 16929 if ((left_value != Mint::kMinValue) || (right_value != -1)) { | 16943 if ((left_value != Mint::kMinValue) || (right_value != -1)) { |
| 16930 return Integer::New(left_value / right_value); | 16944 return Integer::New(left_value / right_value, space); |
| 16931 } | 16945 } |
| 16932 break; | 16946 break; |
| 16933 } | 16947 } |
| 16934 case Token::kMOD: { | 16948 case Token::kMOD: { |
| 16935 const int64_t remainder = left_value % right_value; | 16949 const int64_t remainder = left_value % right_value; |
| 16936 if (remainder < 0) { | 16950 if (remainder < 0) { |
| 16937 if (right_value < 0) { | 16951 if (right_value < 0) { |
| 16938 return Integer::New(remainder - right_value); | 16952 return Integer::New(remainder - right_value, space); |
| 16939 } else { | 16953 } else { |
| 16940 return Integer::New(remainder + right_value); | 16954 return Integer::New(remainder + right_value, space); |
| 16941 } | 16955 } |
| 16942 } | 16956 } |
| 16943 return Integer::New(remainder); | 16957 return Integer::New(remainder, space); |
| 16944 } | 16958 } |
| 16945 default: | 16959 default: |
| 16946 UNIMPLEMENTED(); | 16960 UNIMPLEMENTED(); |
| 16947 } | 16961 } |
| 16948 } | 16962 } |
| 16949 return Integer::null(); // Notify caller that a bigint operation is required. | 16963 return Integer::null(); // Notify caller that a bigint operation is required. |
| 16950 } | 16964 } |
| 16951 | 16965 |
| 16952 | 16966 |
| 16953 static bool Are64bitOperands(const Integer& op1, const Integer& op2) { | 16967 static bool Are64bitOperands(const Integer& op1, const Integer& op2) { |
| (...skipping 4536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21490 return tag_label.ToCString(); | 21504 return tag_label.ToCString(); |
| 21491 } | 21505 } |
| 21492 | 21506 |
| 21493 | 21507 |
| 21494 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 21508 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 21495 Instance::PrintJSONImpl(stream, ref); | 21509 Instance::PrintJSONImpl(stream, ref); |
| 21496 } | 21510 } |
| 21497 | 21511 |
| 21498 | 21512 |
| 21499 } // namespace dart | 21513 } // namespace dart |
| OLD | NEW |