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/code_generator.h" | 5 #include "vm/code_generator.h" |
| 6 | 6 |
| 7 #include "vm/assembler_macros.h" | 7 #include "vm/assembler_macros.h" |
| 8 #include "vm/ast.h" | 8 #include "vm/ast.h" |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/code_patcher.h" | 10 #include "vm/code_patcher.h" |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 } | 395 } |
| 396 const Function& function = Function::Handle( | 396 const Function& function = Function::Handle( |
| 397 caller_frame->LookupDartFunction()); | 397 caller_frame->LookupDartFunction()); |
| 398 OS::Print(" -> Function %s\n", function.ToFullyQualifiedCString()); | 398 OS::Print(" -> Function %s\n", function.ToFullyQualifiedCString()); |
| 399 } | 399 } |
| 400 | 400 |
| 401 | 401 |
| 402 // Converts InstantiatedTypeArguments to TypeArguments and stores it | 402 // Converts InstantiatedTypeArguments to TypeArguments and stores it |
| 403 // into the instance. The assembly code can handle only type arguments of | 403 // into the instance. The assembly code can handle only type arguments of |
| 404 // class TypeArguments. Because of the overhead, do it only when needed. | 404 // class TypeArguments. Because of the overhead, do it only when needed. |
| 405 // Return false if the optimization was aborted. | 405 // Return true if type arguments have been replaced, false otherwise. |
| 406 // Set type_arguments_replaced to true if they have changed. | 406 static bool OptimizeTypeArguments(const Instance& instance) { |
| 407 static bool OptimizeTypeArguments(const Instance& instance, | 407 bool replaced = false; |
| 408 bool* type_arguments_replaced) { | |
| 409 *type_arguments_replaced = false; | |
| 410 const Class& type_class = Class::ZoneHandle(instance.clazz()); | 408 const Class& type_class = Class::ZoneHandle(instance.clazz()); |
| 411 if (!type_class.HasTypeArguments()) { | 409 if (!type_class.HasTypeArguments()) { |
| 412 return true; | 410 return replaced; |
|
Vyacheslav Egorov (Google)
2012/11/29 12:57:05
return false;
| |
| 413 } | 411 } |
| 414 AbstractTypeArguments& type_arguments = | 412 AbstractTypeArguments& type_arguments = |
| 415 AbstractTypeArguments::Handle(instance.GetTypeArguments()); | 413 AbstractTypeArguments::Handle(instance.GetTypeArguments()); |
| 416 if (type_arguments.IsNull()) { | 414 if (type_arguments.IsNull()) { |
| 417 return true; | 415 return replaced; |
|
Vyacheslav Egorov (Google)
2012/11/29 12:57:05
return false;
| |
| 418 } | 416 } |
| 419 if (type_arguments.IsInstantiatedTypeArguments()) { | 417 if (type_arguments.IsInstantiatedTypeArguments()) { |
|
Vyacheslav Egorov (Google)
2012/11/29 12:57:05
move variable here.
| |
| 420 do { | 418 do { |
| 421 const InstantiatedTypeArguments& instantiated_type_arguments = | 419 const InstantiatedTypeArguments& instantiated_type_arguments = |
| 422 InstantiatedTypeArguments::Cast(type_arguments); | 420 InstantiatedTypeArguments::Cast(type_arguments); |
| 423 const AbstractTypeArguments& uninstantiated = | 421 const AbstractTypeArguments& uninstantiated = |
| 424 AbstractTypeArguments::Handle( | 422 AbstractTypeArguments::Handle( |
| 425 instantiated_type_arguments.uninstantiated_type_arguments()); | 423 instantiated_type_arguments.uninstantiated_type_arguments()); |
| 426 const AbstractTypeArguments& instantiator = | 424 const AbstractTypeArguments& instantiator = |
| 427 AbstractTypeArguments::Handle( | 425 AbstractTypeArguments::Handle( |
| 428 instantiated_type_arguments.instantiator_type_arguments()); | 426 instantiated_type_arguments.instantiator_type_arguments()); |
| 429 type_arguments = uninstantiated.InstantiateFrom(instantiator); | 427 type_arguments = uninstantiated.InstantiateFrom(instantiator); |
| 430 } while (type_arguments.IsInstantiatedTypeArguments()); | 428 } while (type_arguments.IsInstantiatedTypeArguments()); |
| 431 AbstractTypeArguments& new_type_arguments = AbstractTypeArguments::Handle(); | 429 AbstractTypeArguments& new_type_arguments = AbstractTypeArguments::Handle(); |
| 432 new_type_arguments = type_arguments.Canonicalize(); | 430 new_type_arguments = type_arguments.Canonicalize(); |
| 433 instance.SetTypeArguments(new_type_arguments); | 431 instance.SetTypeArguments(new_type_arguments); |
| 434 *type_arguments_replaced = true; | 432 replaced = true; |
| 435 } else if (!type_arguments.IsCanonical()) { | 433 } else if (!type_arguments.IsCanonical()) { |
| 436 AbstractTypeArguments& new_type_arguments = AbstractTypeArguments::Handle(); | 434 AbstractTypeArguments& new_type_arguments = AbstractTypeArguments::Handle(); |
| 437 new_type_arguments = type_arguments.Canonicalize(); | 435 new_type_arguments = type_arguments.Canonicalize(); |
| 438 instance.SetTypeArguments(new_type_arguments); | 436 instance.SetTypeArguments(new_type_arguments); |
| 439 *type_arguments_replaced = true; | 437 replaced = true; |
| 440 } | 438 } |
|
srdjan
2012/11/29 21:12:20
Add } else { return false; } here and remove varia
| |
| 441 ASSERT(AbstractTypeArguments::Handle( | 439 ASSERT(AbstractTypeArguments::Handle( |
| 442 instance.GetTypeArguments()).IsTypeArguments()); | 440 instance.GetTypeArguments()).IsTypeArguments()); |
| 443 return true; | 441 return replaced; |
| 444 } | 442 } |
| 445 | 443 |
| 446 | 444 |
| 447 // This updates the type test cache, an array containing 4-value elements | 445 // This updates the type test cache, an array containing 4-value elements |
| 448 // (instance class, instance type arguments, instantiator type arguments and | 446 // (instance class, instance type arguments, instantiator type arguments and |
| 449 // test_result). It can be applied to classes with type arguments in which | 447 // test_result). It can be applied to classes with type arguments in which |
| 450 // case it contains just the result of the class subtype test, not including | 448 // case it contains just the result of the class subtype test, not including |
| 451 // the evaluation of type arguments. | 449 // the evaluation of type arguments. |
| 452 // This operation is currently very slow (lookup of code is not efficient yet). | 450 // This operation is currently very slow (lookup of code is not efficient yet). |
| 453 // 'instantiator' can be null, in which case inst_targ | 451 // 'instantiator' can be null, in which case inst_targ |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 466 AbstractTypeArguments& instantiator_type_arguments = | 464 AbstractTypeArguments& instantiator_type_arguments = |
| 467 AbstractTypeArguments::Handle(incoming_instantiator_type_arguments.raw()); | 465 AbstractTypeArguments::Handle(incoming_instantiator_type_arguments.raw()); |
| 468 AbstractTypeArguments& instance_type_arguments = | 466 AbstractTypeArguments& instance_type_arguments = |
| 469 AbstractTypeArguments::Handle(); | 467 AbstractTypeArguments::Handle(); |
| 470 const Class& instance_class = Class::Handle(instance.clazz()); | 468 const Class& instance_class = Class::Handle(instance.clazz()); |
| 471 | 469 |
| 472 // Canonicalize type arguments. | 470 // Canonicalize type arguments. |
| 473 bool type_arguments_replaced = false; | 471 bool type_arguments_replaced = false; |
| 474 if (instance_class.HasTypeArguments()) { | 472 if (instance_class.HasTypeArguments()) { |
| 475 // Canonicalize type arguments. | 473 // Canonicalize type arguments. |
| 476 if (!OptimizeTypeArguments(instance, &type_arguments_replaced)) { | 474 type_arguments_replaced = OptimizeTypeArguments(instance); |
| 477 if (FLAG_trace_type_checks) { | |
| 478 PrintTypeCheck("WARNING: Cannot canonicalize instance type arguments", | |
| 479 instance, type, instantiator_type_arguments, result); | |
| 480 } | |
| 481 return; | |
| 482 } | |
| 483 instance_type_arguments = instance.GetTypeArguments(); | 475 instance_type_arguments = instance.GetTypeArguments(); |
| 484 } | 476 } |
| 485 if (!instantiator.IsNull()) { | 477 if (!instantiator.IsNull()) { |
| 486 bool replaced = false; | 478 if (OptimizeTypeArguments(instantiator)) { |
| 487 if (!OptimizeTypeArguments(instantiator, &replaced)) { | |
| 488 if (FLAG_trace_type_checks) { | |
| 489 PrintTypeCheck("WARNING: Cannot canonicalize instantiator " | |
| 490 "type arguments", | |
| 491 instance, type, instantiator_type_arguments, result); | |
| 492 } | |
| 493 return; | |
| 494 } | |
| 495 if (replaced) { | |
| 496 type_arguments_replaced = true; | 479 type_arguments_replaced = true; |
| 497 } | 480 } |
| 498 instantiator_type_arguments = instantiator.GetTypeArguments(); | 481 instantiator_type_arguments = instantiator.GetTypeArguments(); |
| 499 } | 482 } |
| 500 | 483 |
| 501 intptr_t last_instance_class_id = -1; | 484 intptr_t last_instance_class_id = -1; |
| 502 AbstractTypeArguments& last_instance_type_arguments = | 485 AbstractTypeArguments& last_instance_type_arguments = |
| 503 AbstractTypeArguments::Handle(); | 486 AbstractTypeArguments::Handle(); |
| 504 AbstractTypeArguments& last_instantiator_type_arguments = | 487 AbstractTypeArguments& last_instantiator_type_arguments = |
| 505 AbstractTypeArguments::Handle(); | 488 AbstractTypeArguments::Handle(); |
| (...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1896 Isolate* isolate = Isolate::Current(); | 1879 Isolate* isolate = Isolate::Current(); |
| 1897 StackZone zone(isolate); | 1880 StackZone zone(isolate); |
| 1898 HANDLESCOPE(isolate); | 1881 HANDLESCOPE(isolate); |
| 1899 const Bigint& big_left = Bigint::Handle(left); | 1882 const Bigint& big_left = Bigint::Handle(left); |
| 1900 const Bigint& big_right = Bigint::Handle(right); | 1883 const Bigint& big_right = Bigint::Handle(right); |
| 1901 return BigintOperations::Compare(big_left, big_right); | 1884 return BigintOperations::Compare(big_left, big_right); |
| 1902 } | 1885 } |
| 1903 END_LEAF_RUNTIME_ENTRY | 1886 END_LEAF_RUNTIME_ENTRY |
| 1904 | 1887 |
| 1905 } // namespace dart | 1888 } // namespace dart |
| OLD | NEW |