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

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

Issue 165523002: Avoid repeated resolution of types by marking them as resolved. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 2011 matching lines...) Expand 10 before | Expand all | Expand 10 after
2022 const intptr_t num_type_params = NumTypeParameters(); 2022 const intptr_t num_type_params = NumTypeParameters();
2023 if (!FLAG_overlap_type_arguments || 2023 if (!FLAG_overlap_type_arguments ||
2024 (num_type_params == 0) || 2024 (num_type_params == 0) ||
2025 (super_type() == AbstractType::null()) || 2025 (super_type() == AbstractType::null()) ||
2026 (super_type() == isolate->object_store()->object_type())) { 2026 (super_type() == isolate->object_store()->object_type())) {
2027 set_num_own_type_arguments(num_type_params); 2027 set_num_own_type_arguments(num_type_params);
2028 return num_type_params; 2028 return num_type_params;
2029 } 2029 }
2030 ASSERT(!IsMixinApplication() || is_mixin_type_applied()); 2030 ASSERT(!IsMixinApplication() || is_mixin_type_applied());
2031 const AbstractType& sup_type = AbstractType::Handle(isolate, super_type()); 2031 const AbstractType& sup_type = AbstractType::Handle(isolate, super_type());
2032 ASSERT(sup_type.IsResolved());
2033 const TypeArguments& sup_type_args = 2032 const TypeArguments& sup_type_args =
2034 TypeArguments::Handle(isolate, sup_type.arguments()); 2033 TypeArguments::Handle(isolate, sup_type.arguments());
2035 if (sup_type_args.IsNull()) { 2034 if (sup_type_args.IsNull()) {
2036 // The super type is raw or the super class is non generic. 2035 // The super type is raw or the super class is non generic.
2037 // In either case, overlapping is not possible. 2036 // In either case, overlapping is not possible.
2038 set_num_own_type_arguments(num_type_params); 2037 set_num_own_type_arguments(num_type_params);
2039 return num_type_params; 2038 return num_type_params;
2040 } 2039 }
2041 const intptr_t num_sup_type_args = sup_type_args.Length(); 2040 const intptr_t num_sup_type_args = sup_type_args.Length();
2042 // At this point, the super type may or may not be finalized. In either case, 2041 // At this point, the super type may or may not be finalized. In either case,
2043 // the result of this function must remain the same. 2042 // the result of this function must remain the same.
2044 // The value of num_sup_type_args may increase when the super type is 2043 // The value of num_sup_type_args may increase when the super type is
2045 // finalized, but the last num_sup_type_args type arguments will not be 2044 // finalized, but the last num_sup_type_args type arguments will not be
2046 // modified by finalization, only shifted to higher indices in the vector. 2045 // modified by finalization, only shifted to higher indices in the vector.
2047 // They may however get wrapped in a BoundedType, which we skip. 2046 // They may however get wrapped in a BoundedType, which we skip.
2047 // The super type may not even be resolved yet. This is not necessary, since
2048 // we only check for matching type parameters, which are resolved by default.
2048 const TypeArguments& type_params = 2049 const TypeArguments& type_params =
2049 TypeArguments::Handle(isolate, type_parameters()); 2050 TypeArguments::Handle(isolate, type_parameters());
2050 // Determine the maximum overlap of a prefix of the vector consisting of the 2051 // Determine the maximum overlap of a prefix of the vector consisting of the
2051 // type parameters of this class with a suffix of the vector consisting of the 2052 // type parameters of this class with a suffix of the vector consisting of the
2052 // type arguments of the super type of this class. 2053 // type arguments of the super type of this class.
2053 // The number of own type arguments of this class is the number of its type 2054 // The number of own type arguments of this class is the number of its type
2054 // parameters minus the number of type arguments in the overlap. 2055 // parameters minus the number of type arguments in the overlap.
2055 // Attempt to overlap the whole vector of type parameters; reduce the size 2056 // Attempt to overlap the whole vector of type parameters; reduce the size
2056 // of the vector (keeping the first type parameter) until it fits or until 2057 // of the vector (keeping the first type parameter) until it fits or until
2057 // its size is zero. 2058 // its size is zero.
(...skipping 2302 matching lines...) Expand 10 before | Expand all | Expand 10 after
4360 current ^= table.At(index); 4361 current ^= table.At(index);
4361 } 4362 }
4362 return index; // Index of element if found or slot into which to add it. 4363 return index; // Index of element if found or slot into which to add it.
4363 } 4364 }
4364 4365
4365 4366
4366 RawTypeArguments* TypeArguments::CloneUnfinalized() const { 4367 RawTypeArguments* TypeArguments::CloneUnfinalized() const {
4367 if (IsNull() || IsFinalized()) { 4368 if (IsNull() || IsFinalized()) {
4368 return raw(); 4369 return raw();
4369 } 4370 }
4371 ASSERT(IsResolved());
4370 AbstractType& type = AbstractType::Handle(); 4372 AbstractType& type = AbstractType::Handle();
4371 const intptr_t num_types = Length(); 4373 const intptr_t num_types = Length();
4372 const TypeArguments& clone = TypeArguments::Handle( 4374 const TypeArguments& clone = TypeArguments::Handle(
4373 TypeArguments::New(num_types)); 4375 TypeArguments::New(num_types));
4374 for (intptr_t i = 0; i < num_types; i++) { 4376 for (intptr_t i = 0; i < num_types; i++) {
4375 type = TypeAt(i); 4377 type = TypeAt(i);
4376 type = type.CloneUnfinalized(); 4378 type = type.CloneUnfinalized();
4377 clone.SetTypeAt(i, type); 4379 clone.SetTypeAt(i, type);
4378 } 4380 }
4381 ASSERT(clone.IsResolved());
4379 return clone.raw(); 4382 return clone.raw();
4380 } 4383 }
4381 4384
4382 4385
4383 RawTypeArguments* TypeArguments::Canonicalize( 4386 RawTypeArguments* TypeArguments::Canonicalize(
4384 GrowableObjectArray* trail) const { 4387 GrowableObjectArray* trail) const {
4385 if (IsNull() || IsCanonical()) { 4388 if (IsNull() || IsCanonical()) {
4386 ASSERT(IsOld()); 4389 ASSERT(IsOld());
4387 return this->raw(); 4390 return this->raw();
4388 } 4391 }
(...skipping 8173 matching lines...) Expand 10 before | Expand all | Expand 10 after
12562 return Isolate::Current()->object_store()->function_type(); 12565 return Isolate::Current()->object_store()->function_type();
12563 } 12566 }
12564 12567
12565 12568
12566 RawType* Type::NewNonParameterizedType(const Class& type_class) { 12569 RawType* Type::NewNonParameterizedType(const Class& type_class) {
12567 ASSERT(type_class.NumTypeArguments() == 0); 12570 ASSERT(type_class.NumTypeArguments() == 0);
12568 if (type_class.raw() == Object::dynamic_class()) { 12571 if (type_class.raw() == Object::dynamic_class()) {
12569 // If the dynamic type has not been setup in the VM isolate, then we need 12572 // If the dynamic type has not been setup in the VM isolate, then we need
12570 // to allocate it here. 12573 // to allocate it here.
12571 if (Object::dynamic_type() != reinterpret_cast<RawType*>(RAW_NULL)) { 12574 if (Object::dynamic_type() != reinterpret_cast<RawType*>(RAW_NULL)) {
12575 ASSERT(Type::Handle(Object::dynamic_type()).IsFinalized());
12572 return Object::dynamic_type(); 12576 return Object::dynamic_type();
12573 } 12577 }
12574 ASSERT(Isolate::Current() == Dart::vm_isolate()); 12578 ASSERT(Isolate::Current() == Dart::vm_isolate());
12575 } 12579 }
12576 Type& type = Type::Handle(type_class.CanonicalType()); 12580 Type& type = Type::Handle(type_class.CanonicalType());
12577 if (type.IsNull()) { 12581 if (type.IsNull()) {
12578 const TypeArguments& no_type_arguments = TypeArguments::Handle(); 12582 const TypeArguments& no_type_arguments = TypeArguments::Handle();
12579 type ^= Type::New(Object::Handle(type_class.raw()), 12583 type ^= Type::New(Object::Handle(type_class.raw()),
12580 no_type_arguments, 12584 no_type_arguments,
12581 Scanner::kNoSourcePos); 12585 Scanner::kNoSourcePos);
12582 type.SetIsFinalized(); 12586 type.SetIsFinalized();
12583 type ^= type.Canonicalize(); 12587 type ^= type.Canonicalize();
12584 } 12588 }
12589 ASSERT(type.IsFinalized());
12585 return type.raw(); 12590 return type.raw();
12586 } 12591 }
12587 12592
12588 12593
12589 void Type::SetIsFinalized() const { 12594 void Type::SetIsFinalized() const {
12590 ASSERT(!IsFinalized()); 12595 ASSERT(!IsFinalized());
12591 if (IsInstantiated()) { 12596 if (IsInstantiated()) {
12592 set_type_state(RawType::kFinalizedInstantiated); 12597 set_type_state(RawType::kFinalizedInstantiated);
12593 } else { 12598 } else {
12594 set_type_state(RawType::kFinalizedUninstantiated); 12599 set_type_state(RawType::kFinalizedUninstantiated);
12595 } 12600 }
12596 } 12601 }
12597 12602
12598 12603
12599 void Type::ResetIsFinalized() const { 12604 void Type::ResetIsFinalized() const {
12600 ASSERT(IsFinalized()); 12605 ASSERT(IsFinalized());
12601 set_type_state(RawType::kBeingFinalized); 12606 set_type_state(RawType::kBeingFinalized);
12602 SetIsFinalized(); 12607 SetIsFinalized();
12603 } 12608 }
12604 12609
12605 12610
12606 void Type::set_is_being_finalized() const { 12611 void Type::set_is_being_finalized() const {
12607 ASSERT(!IsFinalized() && !IsBeingFinalized()); 12612 ASSERT(IsResolved() && !IsFinalized() && !IsBeingFinalized());
12608 set_type_state(RawType::kBeingFinalized); 12613 set_type_state(RawType::kBeingFinalized);
12609 } 12614 }
12610 12615
12611 12616
12612 bool Type::IsMalformed() const { 12617 bool Type::IsMalformed() const {
12613 if (raw_ptr()->error_ == LanguageError::null()) { 12618 if (raw_ptr()->error_ == LanguageError::null()) {
12614 return false; 12619 return false;
12615 } 12620 }
12616 const LanguageError& type_error = LanguageError::Handle(error()); 12621 const LanguageError& type_error = LanguageError::Handle(error());
12617 return type_error.kind() == LanguageError::kMalformedType; 12622 return type_error.kind() == LanguageError::kMalformedType;
(...skipping 23 matching lines...) Expand all
12641 ASSERT(type_error.kind() == LanguageError::kMalboundedType); 12646 ASSERT(type_error.kind() == LanguageError::kMalboundedType);
12642 return FLAG_enable_type_checks; 12647 return FLAG_enable_type_checks;
12643 } 12648 }
12644 12649
12645 12650
12646 void Type::set_error(const LanguageError& value) const { 12651 void Type::set_error(const LanguageError& value) const {
12647 StorePointer(&raw_ptr()->error_, value.raw()); 12652 StorePointer(&raw_ptr()->error_, value.raw());
12648 } 12653 }
12649 12654
12650 12655
12651 bool Type::IsResolved() const { 12656 void Type::set_is_resolved() const {
12652 if (IsFinalized()) { 12657 ASSERT(!IsResolved());
12653 return true; 12658 set_type_state(RawType::kResolved);
12654 }
12655 if (!HasResolvedTypeClass()) {
12656 return false;
12657 }
12658 const TypeArguments& args = TypeArguments::Handle(arguments());
12659 return args.IsNull() || args.IsResolved();
12660 } 12659 }
12661 12660
12662 12661
12663 bool Type::HasResolvedTypeClass() const { 12662 bool Type::HasResolvedTypeClass() const {
12664 const Object& type_class = Object::Handle(raw_ptr()->type_class_); 12663 const Object& type_class = Object::Handle(raw_ptr()->type_class_);
12665 return !type_class.IsNull() && type_class.IsClass(); 12664 return !type_class.IsNull() && type_class.IsClass();
12666 } 12665 }
12667 12666
12668 12667
12669 RawClass* Type::type_class() const { 12668 RawClass* Type::type_class() const {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
12804 RawAbstractType* Type::CloneUnfinalized() const { 12803 RawAbstractType* Type::CloneUnfinalized() const {
12805 ASSERT(IsResolved()); 12804 ASSERT(IsResolved());
12806 if (IsFinalized()) { 12805 if (IsFinalized()) {
12807 return raw(); 12806 return raw();
12808 } 12807 }
12809 ASSERT(!IsMalformed()); // Malformed types are finalized. 12808 ASSERT(!IsMalformed()); // Malformed types are finalized.
12810 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization. 12809 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization.
12811 TypeArguments& type_args = TypeArguments::Handle(arguments()); 12810 TypeArguments& type_args = TypeArguments::Handle(arguments());
12812 type_args = type_args.CloneUnfinalized(); 12811 type_args = type_args.CloneUnfinalized();
12813 const Class& type_cls = Class::Handle(type_class()); 12812 const Class& type_cls = Class::Handle(type_class());
12814 return Type::New(type_cls, type_args, token_pos()); 12813 const Type& type = Type::Handle(Type::New(type_cls, type_args, token_pos()));
12814 type.set_is_resolved();
12815 return type.raw();
12815 } 12816 }
12816 12817
12817 12818
12818 RawAbstractType* Type::Canonicalize(GrowableObjectArray* trail) const { 12819 RawAbstractType* Type::Canonicalize(GrowableObjectArray* trail) const {
12819 ASSERT(IsFinalized()); 12820 ASSERT(IsFinalized());
12820 if (IsCanonical() || IsMalformed()) { 12821 if (IsCanonical() || IsMalformed()) {
12821 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld()); 12822 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld());
12822 return this->raw(); 12823 return this->raw();
12823 } 12824 }
12824 Isolate* isolate = Isolate::Current(); 12825 Isolate* isolate = Isolate::Current();
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
12954 } 12955 }
12955 12956
12956 12957
12957 void Type::set_token_pos(intptr_t token_pos) const { 12958 void Type::set_token_pos(intptr_t token_pos) const {
12958 ASSERT(token_pos >= 0); 12959 ASSERT(token_pos >= 0);
12959 raw_ptr()->token_pos_ = token_pos; 12960 raw_ptr()->token_pos_ = token_pos;
12960 } 12961 }
12961 12962
12962 12963
12963 void Type::set_type_state(int8_t state) const { 12964 void Type::set_type_state(int8_t state) const {
12964 ASSERT((state == RawType::kAllocated) || 12965 ASSERT((state >= RawType::kAllocated) &&
12965 (state == RawType::kBeingFinalized) || 12966 (state <= RawType::kFinalizedUninstantiated));
12966 (state == RawType::kFinalizedInstantiated) ||
12967 (state == RawType::kFinalizedUninstantiated));
12968 raw_ptr()->type_state_ = state; 12967 raw_ptr()->type_state_ = state;
12969 } 12968 }
12970 12969
12971 12970
12972 const char* Type::ToCString() const { 12971 const char* Type::ToCString() const {
12973 if (IsResolved()) { 12972 if (IsResolved()) {
12974 const TypeArguments& type_arguments = TypeArguments::Handle(arguments()); 12973 const TypeArguments& type_arguments = TypeArguments::Handle(arguments());
12975 const char* class_name; 12974 const char* class_name;
12976 if (HasResolvedTypeClass()) { 12975 if (HasResolvedTypeClass()) {
12977 class_name = String::Handle( 12976 class_name = String::Handle(
(...skipping 4386 matching lines...) Expand 10 before | Expand all | Expand 10 after
17364 return "_MirrorReference"; 17363 return "_MirrorReference";
17365 } 17364 }
17366 17365
17367 17366
17368 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 17367 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
17369 Instance::PrintToJSONStream(stream, ref); 17368 Instance::PrintToJSONStream(stream, ref);
17370 } 17369 }
17371 17370
17372 17371
17373 } // namespace dart 17372 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698