Chromium Code Reviews| 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 4245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 == 1) ? 3 : ((length - 1) * 2 + 1); |
|
Ivan Posva
2014/02/21 22:26:56
How about not allowing unbounded exponential growt
regis
2014/02/21 23:08:47
Done.
| |
| 4267 prior_instantiations = | 4267 prior_instantiations = |
| 4268 Array::Grow(prior_instantiations, length, Heap::kOld); | 4268 Array::Grow(prior_instantiations, length, Heap::kOld); |
| 4269 set_instantiations(prior_instantiations); | 4269 set_instantiations(prior_instantiations); |
| 4270 ASSERT((index + 2) < length); | 4270 ASSERT((index + 2) < length); |
| 4271 } | 4271 } |
| 4272 prior_instantiations.SetAt(index, instantiator_type_arguments); | 4272 prior_instantiations.SetAt(index, instantiator_type_arguments); |
| 4273 prior_instantiations.SetAt(index + 1, result); | 4273 prior_instantiations.SetAt(index + 1, result); |
| 4274 prior_instantiations.SetAt(index + 2, | 4274 prior_instantiations.SetAt(index + 2, |
| 4275 Smi::Handle(Smi::New(StubCode::kNoInstantiator))); | 4275 Smi::Handle(Smi::New(StubCode::kNoInstantiator))); |
| 4276 return result.raw(); | 4276 return result.raw(); |
| (...skipping 8608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12885 } | 12885 } |
| 12886 ASSERT(this->Equals(type)); | 12886 ASSERT(this->Equals(type)); |
| 12887 return type.raw(); | 12887 return type.raw(); |
| 12888 } | 12888 } |
| 12889 | 12889 |
| 12890 Array& canonical_types = Array::Handle(isolate); | 12890 Array& canonical_types = Array::Handle(isolate); |
| 12891 canonical_types ^= cls.canonical_types(); | 12891 canonical_types ^= cls.canonical_types(); |
| 12892 if (canonical_types.IsNull()) { | 12892 if (canonical_types.IsNull()) { |
| 12893 canonical_types = empty_array().raw(); | 12893 canonical_types = empty_array().raw(); |
| 12894 } | 12894 } |
| 12895 const intptr_t canonical_types_len = canonical_types.Length(); | 12895 const intptr_t length = canonical_types.Length(); |
| 12896 // Linear search to see whether this type is already present in the | 12896 // Linear search to see whether this type is already present in the |
| 12897 // list of canonicalized types. | 12897 // list of canonicalized types. |
| 12898 // TODO(asiva): Try to re-factor this lookup code to make sharing | 12898 // TODO(asiva): Try to re-factor this lookup code to make sharing |
| 12899 // easy between the 4 versions of this loop. | 12899 // easy between the 4 versions of this loop. |
| 12900 intptr_t index = 0; | 12900 intptr_t index = 0; |
| 12901 while (index < canonical_types_len) { | 12901 while (index < length) { |
| 12902 type ^= canonical_types.At(index); | 12902 type ^= canonical_types.At(index); |
| 12903 if (type.IsNull()) { | 12903 if (type.IsNull()) { |
| 12904 break; | 12904 break; |
| 12905 } | 12905 } |
| 12906 ASSERT(type.IsFinalized()); | 12906 ASSERT(type.IsFinalized()); |
| 12907 if (this->Equals(type)) { | 12907 if (this->Equals(type)) { |
| 12908 return type.raw(); | 12908 return type.raw(); |
| 12909 } | 12909 } |
| 12910 index++; | 12910 index++; |
| 12911 } | 12911 } |
| 12912 // Canonicalize the type arguments. | 12912 // Canonicalize the type arguments. |
| 12913 TypeArguments& type_args = TypeArguments::Handle(isolate, arguments()); | 12913 TypeArguments& type_args = TypeArguments::Handle(isolate, arguments()); |
| 12914 // In case the type is first canonicalized at runtime, its type argument | 12914 // In case the type is first canonicalized at runtime, its type argument |
| 12915 // vector may be longer than necessary. This is not an issue. | 12915 // vector may be longer than necessary. This is not an issue. |
| 12916 ASSERT(type_args.IsNull() || (type_args.Length() >= cls.NumTypeArguments())); | 12916 ASSERT(type_args.IsNull() || (type_args.Length() >= cls.NumTypeArguments())); |
| 12917 type_args = type_args.Canonicalize(trail); | 12917 type_args = type_args.Canonicalize(trail); |
| 12918 set_arguments(type_args); | 12918 set_arguments(type_args); |
| 12919 // The type needs to be added to the list. Grow the list if it is full. | 12919 // The type needs to be added to the list. Grow the list if it is full. |
| 12920 if (index == canonical_types_len) { | 12920 if (index == length) { |
| 12921 const intptr_t kLengthIncrement = 2; // Raw and parameterized. | 12921 const intptr_t new_length = (length == 0) ? 1 : (length * 2); |
|
Ivan Posva
2014/02/21 22:26:56
ditto
regis
2014/02/21 23:08:47
Done.
| |
| 12922 const intptr_t new_length = canonical_types.Length() + kLengthIncrement; | |
| 12923 const Array& new_canonical_types = Array::Handle( | 12922 const Array& new_canonical_types = Array::Handle( |
| 12924 isolate, Array::Grow(canonical_types, new_length, Heap::kOld)); | 12923 isolate, Array::Grow(canonical_types, new_length, Heap::kOld)); |
| 12925 cls.set_canonical_types(new_canonical_types); | 12924 cls.set_canonical_types(new_canonical_types); |
| 12926 new_canonical_types.SetAt(index, *this); | 12925 new_canonical_types.SetAt(index, *this); |
| 12927 } else { | 12926 } else { |
| 12928 canonical_types.SetAt(index, *this); | 12927 canonical_types.SetAt(index, *this); |
| 12929 } | 12928 } |
| 12930 #ifdef DEBUG | 12929 #ifdef DEBUG |
| 12931 if ((index == 0) && cls.IsCanonicalSignatureClass()) { | 12930 if ((index == 0) && cls.IsCanonicalSignatureClass()) { |
| 12932 // Verify that the first canonical type is the signature type by checking | 12931 // Verify that the first canonical type is the signature type by checking |
| (...skipping 4520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 17453 return "_MirrorReference"; | 17452 return "_MirrorReference"; |
| 17454 } | 17453 } |
| 17455 | 17454 |
| 17456 | 17455 |
| 17457 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 17456 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 17458 Instance::PrintToJSONStream(stream, ref); | 17457 Instance::PrintToJSONStream(stream, ref); |
| 17459 } | 17458 } |
| 17460 | 17459 |
| 17461 | 17460 |
| 17462 } // namespace dart | 17461 } // namespace dart |
| OLD | NEW |