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

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

Issue 175403004: Modify growth policy for table of canonical types in each class. (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
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 4245 matching lines...) Expand 10 before | Expand all | Expand 10 after
4256 if ((bound_error != NULL) && !bound_error->IsNull()) { 4256 if ((bound_error != NULL) && !bound_error->IsNull()) {
4257 return result.raw(); 4257 return result.raw();
4258 } 4258 }
4259 // Instantiation did not result in bound error. Canonicalize type arguments. 4259 // Instantiation did not result in bound error. Canonicalize type arguments.
4260 result = result.Canonicalize(); 4260 result = result.Canonicalize();
4261 // Add instantiator and result to instantiations array. 4261 // Add instantiator and result to instantiations array.
4262 intptr_t length = prior_instantiations.Length(); 4262 intptr_t length = prior_instantiations.Length();
4263 if ((index + 2) >= length) { 4263 if ((index + 2) >= length) {
4264 // Grow the instantiations array. 4264 // Grow the instantiations array.
4265 // The initial array is Object::zero_array() of length 1. 4265 // The initial array is Object::zero_array() of length 1.
4266 length = (length == 1) ? 3 : length + 4; 4266 length = (length > 64) ?
4267 (length + 64) :
4268 ((length == 1) ? 3 : ((length - 1) * 2 + 1));
4267 prior_instantiations = 4269 prior_instantiations =
4268 Array::Grow(prior_instantiations, length, Heap::kOld); 4270 Array::Grow(prior_instantiations, length, Heap::kOld);
4269 set_instantiations(prior_instantiations); 4271 set_instantiations(prior_instantiations);
4270 ASSERT((index + 2) < length); 4272 ASSERT((index + 2) < length);
4271 } 4273 }
4272 prior_instantiations.SetAt(index, instantiator_type_arguments); 4274 prior_instantiations.SetAt(index, instantiator_type_arguments);
4273 prior_instantiations.SetAt(index + 1, result); 4275 prior_instantiations.SetAt(index + 1, result);
4274 prior_instantiations.SetAt(index + 2, 4276 prior_instantiations.SetAt(index + 2,
4275 Smi::Handle(Smi::New(StubCode::kNoInstantiator))); 4277 Smi::Handle(Smi::New(StubCode::kNoInstantiator)));
4276 return result.raw(); 4278 return result.raw();
(...skipping 8609 matching lines...) Expand 10 before | Expand all | Expand 10 after
12886 } 12888 }
12887 ASSERT(this->Equals(type)); 12889 ASSERT(this->Equals(type));
12888 return type.raw(); 12890 return type.raw();
12889 } 12891 }
12890 12892
12891 Array& canonical_types = Array::Handle(isolate); 12893 Array& canonical_types = Array::Handle(isolate);
12892 canonical_types ^= cls.canonical_types(); 12894 canonical_types ^= cls.canonical_types();
12893 if (canonical_types.IsNull()) { 12895 if (canonical_types.IsNull()) {
12894 canonical_types = empty_array().raw(); 12896 canonical_types = empty_array().raw();
12895 } 12897 }
12896 const intptr_t canonical_types_len = canonical_types.Length(); 12898 const intptr_t length = canonical_types.Length();
12897 // Linear search to see whether this type is already present in the 12899 // Linear search to see whether this type is already present in the
12898 // list of canonicalized types. 12900 // list of canonicalized types.
12899 // TODO(asiva): Try to re-factor this lookup code to make sharing 12901 // TODO(asiva): Try to re-factor this lookup code to make sharing
12900 // easy between the 4 versions of this loop. 12902 // easy between the 4 versions of this loop.
12901 intptr_t index = 0; 12903 intptr_t index = 0;
12902 while (index < canonical_types_len) { 12904 while (index < length) {
12903 type ^= canonical_types.At(index); 12905 type ^= canonical_types.At(index);
12904 if (type.IsNull()) { 12906 if (type.IsNull()) {
12905 break; 12907 break;
12906 } 12908 }
12907 ASSERT(type.IsFinalized()); 12909 ASSERT(type.IsFinalized());
12908 if (this->Equals(type)) { 12910 if (this->Equals(type)) {
12909 return type.raw(); 12911 return type.raw();
12910 } 12912 }
12911 index++; 12913 index++;
12912 } 12914 }
12913 // Canonicalize the type arguments. 12915 // Canonicalize the type arguments.
12914 TypeArguments& type_args = TypeArguments::Handle(isolate, arguments()); 12916 TypeArguments& type_args = TypeArguments::Handle(isolate, arguments());
12915 // In case the type is first canonicalized at runtime, its type argument 12917 // In case the type is first canonicalized at runtime, its type argument
12916 // vector may be longer than necessary. This is not an issue. 12918 // vector may be longer than necessary. This is not an issue.
12917 ASSERT(type_args.IsNull() || (type_args.Length() >= cls.NumTypeArguments())); 12919 ASSERT(type_args.IsNull() || (type_args.Length() >= cls.NumTypeArguments()));
12918 type_args = type_args.Canonicalize(trail); 12920 type_args = type_args.Canonicalize(trail);
12919 set_arguments(type_args); 12921 set_arguments(type_args);
12920 // The type needs to be added to the list. Grow the list if it is full. 12922 // The type needs to be added to the list. Grow the list if it is full.
12921 if (index == canonical_types_len) { 12923 if (index == length) {
12922 const intptr_t kLengthIncrement = 2; // Raw and parameterized. 12924 const intptr_t new_length = (length > 64) ?
12923 const intptr_t new_length = canonical_types.Length() + kLengthIncrement; 12925 (length + 64) :
12926 ((length == 0) ? 1 : (length * 2));
12924 const Array& new_canonical_types = Array::Handle( 12927 const Array& new_canonical_types = Array::Handle(
12925 isolate, Array::Grow(canonical_types, new_length, Heap::kOld)); 12928 isolate, Array::Grow(canonical_types, new_length, Heap::kOld));
12926 cls.set_canonical_types(new_canonical_types); 12929 cls.set_canonical_types(new_canonical_types);
12927 new_canonical_types.SetAt(index, *this); 12930 new_canonical_types.SetAt(index, *this);
12928 } else { 12931 } else {
12929 canonical_types.SetAt(index, *this); 12932 canonical_types.SetAt(index, *this);
12930 } 12933 }
12931 #ifdef DEBUG 12934 #ifdef DEBUG
12932 if ((index == 0) && cls.IsCanonicalSignatureClass()) { 12935 if ((index == 0) && cls.IsCanonicalSignatureClass()) {
12933 // Verify that the first canonical type is the signature type by checking 12936 // Verify that the first canonical type is the signature type by checking
(...skipping 4520 matching lines...) Expand 10 before | Expand all | Expand 10 after
17454 return "_MirrorReference"; 17457 return "_MirrorReference";
17455 } 17458 }
17456 17459
17457 17460
17458 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 17461 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
17459 Instance::PrintToJSONStream(stream, ref); 17462 Instance::PrintToJSONStream(stream, ref);
17460 } 17463 }
17461 17464
17462 17465
17463 } // namespace dart 17466 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698