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