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

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

Issue 1748913002: Factor out code that looks up a canonical type and adds it to the canonical_types_ array if necessa… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix bug Created 4 years, 9 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
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | 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 3540 matching lines...) Expand 10 before | Expand all | Expand 10 after
3551 if (!IsGeneric() && !IsClosureClass()) { 3551 if (!IsGeneric() && !IsClosureClass()) {
3552 ASSERT((canonical_types() == Object::null()) || 3552 ASSERT((canonical_types() == Object::null()) ||
3553 (canonical_types() == type.raw())); // Set during own finalization. 3553 (canonical_types() == type.raw())); // Set during own finalization.
3554 set_canonical_types(type); 3554 set_canonical_types(type);
3555 } else { 3555 } else {
3556 Array& types = Array::Handle(); 3556 Array& types = Array::Handle();
3557 types ^= canonical_types(); 3557 types ^= canonical_types();
3558 ASSERT(!types.IsNull() && (types.Length() > 1)); 3558 ASSERT(!types.IsNull() && (types.Length() > 1));
3559 ASSERT((types.At(0) == Object::null()) || (types.At(0) == type.raw())); 3559 ASSERT((types.At(0) == Object::null()) || (types.At(0) == type.raw()));
3560 types.SetAt(0, type); 3560 types.SetAt(0, type);
3561 // Makes sure that 'canonical_types' has not changed.
3562 ASSERT(types.raw() == canonical_types());
3561 } 3563 }
3562 } 3564 }
3563 3565
3564 3566
3565 intptr_t Class::FindCanonicalTypeIndex(const AbstractType& needle) const { 3567 intptr_t Class::FindCanonicalTypeIndex(const AbstractType& needle) const {
3566 Thread* thread = Thread::Current(); 3568 Thread* thread = Thread::Current();
3567 if (EnsureIsFinalized(thread) != Error::null()) { 3569 if (EnsureIsFinalized(thread) != Error::null()) {
3568 return -1; 3570 return -1;
3569 } 3571 }
3570 if (needle.raw() == CanonicalType()) { 3572 if (needle.raw() == CanonicalType()) {
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
4120 Zone* zone = Thread::Current()->zone(); 4122 Zone* zone = Thread::Current()->zone();
4121 const Library& lib = Library::Handle(zone, library()); 4123 const Library& lib = Library::Handle(zone, library());
4122 const Object& obj = Object::Handle(zone, lib.LookupLocalObject(name)); 4124 const Object& obj = Object::Handle(zone, lib.LookupLocalObject(name));
4123 if (!obj.IsNull() && obj.IsLibraryPrefix()) { 4125 if (!obj.IsNull() && obj.IsLibraryPrefix()) {
4124 return LibraryPrefix::Cast(obj).raw(); 4126 return LibraryPrefix::Cast(obj).raw();
4125 } 4127 }
4126 return LibraryPrefix::null(); 4128 return LibraryPrefix::null();
4127 } 4129 }
4128 4130
4129 4131
4132 RawAbstractType* Class::LookupCanonicalType(const AbstractType& lookup_type,
regis 2016/02/29 23:40:04 Lookup and insert?
srdjan 2016/03/30 17:48:27 LookupOrAdd
4133 intptr_t start_index) const {
4134 intptr_t index = start_index;
4135 Zone* zone = Thread::Current()->zone();
4136 AbstractType& type = Type::Handle(zone);
4137 Array& canonical_types = Array::Handle(zone);
4138 canonical_types ^= this->canonical_types();
4139 if (canonical_types.IsNull()) {
4140 canonical_types = empty_array().raw();
4141 }
4142 ASSERT(canonical_types.IsArray());
4143 const intptr_t length = canonical_types.Length();
4144 while (index < length) {
4145 type ^= canonical_types.At(index);
4146 if (type.IsNull()) {
4147 break;
4148 }
4149 ASSERT(type.IsFinalized());
4150 if (lookup_type.Equals(type)) {
4151 ASSERT(type.IsCanonical());
4152 return type.raw();
4153 }
4154 index++;
4155 }
4156
4157 lookup_type.SetCanonical();
4158
4159 // The type needs to be added to the list. Grow the list if it is full.
4160 if (index >= length) {
4161 ASSERT((index == length) || ((index == 1) && (length == 0)));
4162 const intptr_t new_length = (length > 64) ?
4163 (length + 64) :
4164 ((length == 0) ? 2 : (length * 2));
4165 const Array& new_canonical_types = Array::Handle(
4166 zone, Array::Grow(canonical_types, new_length, Heap::kOld));
4167 new_canonical_types.SetAt(index, lookup_type);
4168 this->set_canonical_types(new_canonical_types);
4169 } else {
4170 canonical_types.SetAt(index, lookup_type);
4171 }
4172 return lookup_type.raw();
4173 }
4174
4175
4130 const char* Class::ToCString() const { 4176 const char* Class::ToCString() const {
4131 const Library& lib = Library::Handle(library()); 4177 const Library& lib = Library::Handle(library());
4132 const char* library_name = lib.IsNull() ? "" : lib.ToCString(); 4178 const char* library_name = lib.IsNull() ? "" : lib.ToCString();
4133 const char* patch_prefix = is_patch() ? "Patch " : ""; 4179 const char* patch_prefix = is_patch() ? "Patch " : "";
4134 const char* class_name = String::Handle(Name()).ToCString(); 4180 const char* class_name = String::Handle(Name()).ToCString();
4135 return OS::SCreate(Thread::Current()->zone(), 4181 return OS::SCreate(Thread::Current()->zone(),
4136 "%s %sClass: %s", library_name, patch_prefix, class_name); 4182 "%s %sClass: %s", library_name, patch_prefix, class_name);
4137 } 4183 }
4138 4184
4139 4185
(...skipping 11646 matching lines...) Expand 10 before | Expand all | Expand 10 after
15786 // In case the type is first canonicalized at runtime, its type argument 15832 // In case the type is first canonicalized at runtime, its type argument
15787 // vector may be longer than necessary. This is not an issue. 15833 // vector may be longer than necessary. This is not an issue.
15788 ASSERT(type_args.IsNull() || (type_args.Length() >= cls.NumTypeArguments())); 15834 ASSERT(type_args.IsNull() || (type_args.Length() >= cls.NumTypeArguments()));
15789 type_args = type_args.Canonicalize(trail); 15835 type_args = type_args.Canonicalize(trail);
15790 if (IsCanonical()) { 15836 if (IsCanonical()) {
15791 // Canonicalizing type_args canonicalized this type as a side effect. 15837 // Canonicalizing type_args canonicalized this type as a side effect.
15792 ASSERT(IsRecursive()); 15838 ASSERT(IsRecursive());
15793 return this->raw(); 15839 return this->raw();
15794 } 15840 }
15795 set_arguments(type_args); 15841 set_arguments(type_args);
15842 ASSERT(type_args.IsNull() || type_args.IsOld());
15796 15843
15797 // Canonicalizing the type arguments may have changed the index, may have 15844 return cls.LookupCanonicalType(*this, index);
15798 // grown the table, or may even have canonicalized this type.
regis 2016/02/29 23:40:04 I would still keep this comment around, because th
srdjan 2016/03/30 17:48:27 Done.
15799 canonical_types ^= cls.canonical_types();
15800 if (canonical_types.IsNull()) {
15801 canonical_types = empty_array().raw();
15802 }
15803 length = canonical_types.Length();
15804 while (index < length) {
15805 type ^= canonical_types.At(index);
15806 if (type.IsNull()) {
15807 break;
15808 }
15809 ASSERT(type.IsFinalized());
15810 if (this->Equals(type)) {
15811 ASSERT(type.IsCanonical());
15812 return type.raw();
15813 }
15814 index++;
15815 }
15816
15817 // The type needs to be added to the list. Grow the list if it is full.
15818 if (index >= length) {
15819 ASSERT((index == length) || ((index == 1) && (length == 0)));
15820 const intptr_t new_length = (length > 64) ?
15821 (length + 64) :
15822 ((length == 0) ? 2 : (length * 2));
15823 const Array& new_canonical_types = Array::Handle(
15824 zone, Array::Grow(canonical_types, new_length, Heap::kOld));
15825 cls.set_canonical_types(new_canonical_types);
15826 canonical_types = new_canonical_types.raw();
15827 }
15828 canonical_types.SetAt(index, *this);
15829 ASSERT(IsOld());
15830 ASSERT(type_args.IsNull() || type_args.IsOld());
15831 SetCanonical();
15832 return this->raw();
15833 } 15845 }
15834 15846
15835 15847
15836 RawString* Type::EnumerateURIs() const { 15848 RawString* Type::EnumerateURIs() const {
15837 if (IsDynamicType()) { 15849 if (IsDynamicType()) {
15838 return Symbols::Empty().raw(); 15850 return Symbols::Empty().raw();
15839 } 15851 }
15840 Zone* zone = Thread::Current()->zone(); 15852 Zone* zone = Thread::Current()->zone();
15841 GrowableHandlePtrArray<const String> pieces(zone, 6); 15853 GrowableHandlePtrArray<const String> pieces(zone, 6);
15842 const Class& cls = Class::Handle(zone, type_class()); 15854 const Class& cls = Class::Handle(zone, type_class());
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
16296 sig_fun.set_parameter_types(Array::Handle(Array::New(num_params, 16308 sig_fun.set_parameter_types(Array::Handle(Array::New(num_params,
16297 Heap::kOld))); 16309 Heap::kOld)));
16298 for (intptr_t i = 0; i < num_params; i++) { 16310 for (intptr_t i = 0; i < num_params; i++) {
16299 type = fun.ParameterTypeAt(i); 16311 type = fun.ParameterTypeAt(i);
16300 type = type.Canonicalize(trail); 16312 type = type.Canonicalize(trail);
16301 sig_fun.SetParameterTypeAt(i, type); 16313 sig_fun.SetParameterTypeAt(i, type);
16302 } 16314 }
16303 sig_fun.set_parameter_names(Array::Handle(zone, fun.parameter_names())); 16315 sig_fun.set_parameter_names(Array::Handle(zone, fun.parameter_names()));
16304 set_signature(sig_fun); 16316 set_signature(sig_fun);
16305 } 16317 }
16318 ASSERT(type_args.IsNull() || type_args.IsOld());
16306 16319
16307 // Canonicalizing the type arguments and the signature may have changed the 16320 return scope_cls.LookupCanonicalType(*this, index);
16308 // index, may have grown the table, or may even have canonicalized this type.
regis 2016/02/29 23:40:04 ditto
16309 canonical_types ^= scope_cls.canonical_types();
16310 if (canonical_types.IsNull()) {
16311 canonical_types = empty_array().raw();
16312 }
16313 length = canonical_types.Length();
16314 while (index < length) {
16315 type ^= canonical_types.At(index);
16316 if (type.IsNull()) {
16317 break;
16318 }
16319 ASSERT(type.IsFinalized());
16320 if (this->Equals(type)) {
16321 ASSERT(type.IsCanonical());
16322 return type.raw();
16323 }
16324 index++;
16325 }
16326
16327 // The type needs to be added to the list. Grow the list if it is full.
16328 if (index >= length) {
16329 ASSERT((index == length) || ((index == 1) && (length == 0)));
16330 const intptr_t new_length = (length > 64) ?
16331 (length + 64) :
16332 ((length == 0) ? 2 : (length * 2));
16333 const Array& new_canonical_types = Array::Handle(
16334 zone, Array::Grow(canonical_types, new_length, Heap::kOld));
16335 scope_cls.set_canonical_types(new_canonical_types);
16336 canonical_types = new_canonical_types.raw();
16337 }
16338 canonical_types.SetAt(index, *this);
16339 ASSERT(IsOld());
16340 ASSERT(type_args.IsNull() || type_args.IsOld());
16341 SetCanonical();
16342 return this->raw();
16343 } 16321 }
16344 16322
16345 16323
16346 RawString* FunctionType::EnumerateURIs() const { 16324 RawString* FunctionType::EnumerateURIs() const {
16347 Zone* zone = Thread::Current()->zone(); 16325 Zone* zone = Thread::Current()->zone();
16348 // The scope class and type arguments do not appear explicitly in the user 16326 // The scope class and type arguments do not appear explicitly in the user
16349 // visible name. The type arguments were used to instantiate the function type 16327 // visible name. The type arguments were used to instantiate the function type
16350 // prior to this call. 16328 // prior to this call.
16351 const Function& sig_fun = Function::Handle(zone, signature()); 16329 const Function& sig_fun = Function::Handle(zone, signature());
16352 AbstractType& type = AbstractType::Handle(zone); 16330 AbstractType& type = AbstractType::Handle(zone);
(...skipping 5327 matching lines...) Expand 10 before | Expand all | Expand 10 after
21680 return UserTag::null(); 21658 return UserTag::null();
21681 } 21659 }
21682 21660
21683 21661
21684 const char* UserTag::ToCString() const { 21662 const char* UserTag::ToCString() const {
21685 const String& tag_label = String::Handle(label()); 21663 const String& tag_label = String::Handle(label());
21686 return tag_label.ToCString(); 21664 return tag_label.ToCString();
21687 } 21665 }
21688 21666
21689 } // namespace dart 21667 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698