| 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/code_patcher.h" | 9 #include "vm/code_patcher.h" |
| 10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 DEFINE_FLAG(bool, trace_runtime_calls, false, "Trace runtime calls"); | 40 DEFINE_FLAG(bool, trace_runtime_calls, false, "Trace runtime calls"); |
| 41 DEFINE_FLAG(int, optimization_counter_threshold, 2000, | 41 DEFINE_FLAG(int, optimization_counter_threshold, 2000, |
| 42 "Function's usage-counter value before it is optimized, -1 means never"); | 42 "Function's usage-counter value before it is optimized, -1 means never"); |
| 43 DECLARE_FLAG(bool, enable_type_checks); | 43 DECLARE_FLAG(bool, enable_type_checks); |
| 44 DECLARE_FLAG(bool, trace_type_checks); | 44 DECLARE_FLAG(bool, trace_type_checks); |
| 45 DECLARE_FLAG(bool, report_usage_count); | 45 DECLARE_FLAG(bool, report_usage_count); |
| 46 DECLARE_FLAG(int, deoptimization_counter_threshold); | 46 DECLARE_FLAG(int, deoptimization_counter_threshold); |
| 47 DEFINE_FLAG(charp, optimization_filter, NULL, "Optimize only named function"); | 47 DEFINE_FLAG(charp, optimization_filter, NULL, "Optimize only named function"); |
| 48 DEFINE_FLAG(bool, trace_failed_optimization_attempts, false, | 48 DEFINE_FLAG(bool, trace_failed_optimization_attempts, false, |
| 49 "Traces all failed optimization attempts"); | 49 "Traces all failed optimization attempts"); |
| 50 DEFINE_FLAG(int, max_subtype_cache_entries, 100, |
| 51 "Maximum number of subtype cache entries (number of checks cached)."); |
| 50 | 52 |
| 51 | 53 |
| 52 DEFINE_RUNTIME_ENTRY(TraceFunctionEntry, 1) { | 54 DEFINE_RUNTIME_ENTRY(TraceFunctionEntry, 1) { |
| 53 ASSERT(arguments.Count() == kTraceFunctionEntryRuntimeEntry.argument_count()); | 55 ASSERT(arguments.Count() == kTraceFunctionEntryRuntimeEntry.argument_count()); |
| 54 const Function& function = Function::CheckedHandle(arguments.At(0)); | 56 const Function& function = Function::CheckedHandle(arguments.At(0)); |
| 55 const String& function_name = String::Handle(function.name()); | 57 const String& function_name = String::Handle(function.name()); |
| 56 const String& class_name = | 58 const String& class_name = |
| 57 String::Handle(Class::Handle(function.Owner()).Name()); | 59 String::Handle(Class::Handle(function.Owner()).Name()); |
| 58 OS::Print("> Entering '%s.%s'\n", | 60 OS::Print("> Entering '%s.%s'\n", |
| 59 class_name.ToCString(), function_name.ToCString()); | 61 class_name.ToCString(), function_name.ToCString()); |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 } | 490 } |
| 489 instantiator_type_arguments = instantiator.GetTypeArguments(); | 491 instantiator_type_arguments = instantiator.GetTypeArguments(); |
| 490 } | 492 } |
| 491 | 493 |
| 492 intptr_t last_instance_class_id = -1; | 494 intptr_t last_instance_class_id = -1; |
| 493 AbstractTypeArguments& last_instance_type_arguments = | 495 AbstractTypeArguments& last_instance_type_arguments = |
| 494 AbstractTypeArguments::Handle(); | 496 AbstractTypeArguments::Handle(); |
| 495 AbstractTypeArguments& last_instantiator_type_arguments = | 497 AbstractTypeArguments& last_instantiator_type_arguments = |
| 496 AbstractTypeArguments::Handle(); | 498 AbstractTypeArguments::Handle(); |
| 497 Bool& last_result = Bool::Handle(); | 499 Bool& last_result = Bool::Handle(); |
| 498 intptr_t len = new_cache.NumberOfChecks(); | 500 const intptr_t len = new_cache.NumberOfChecks(); |
| 501 if (len >= FLAG_max_subtype_cache_entries) { |
| 502 return; |
| 503 } |
| 499 for (intptr_t i = 0; i < len; ++i) { | 504 for (intptr_t i = 0; i < len; ++i) { |
| 500 new_cache.GetCheck( | 505 new_cache.GetCheck( |
| 501 i, | 506 i, |
| 502 &last_instance_class_id, | 507 &last_instance_class_id, |
| 503 &last_instance_type_arguments, | 508 &last_instance_type_arguments, |
| 504 &last_instantiator_type_arguments, | 509 &last_instantiator_type_arguments, |
| 505 &last_result); | 510 &last_result); |
| 506 if ((last_instance_class_id == instance_class.id()) && | 511 if ((last_instance_class_id == instance_class.id()) && |
| 507 (last_instance_type_arguments.raw() == instance_type_arguments.raw()) && | 512 (last_instance_type_arguments.raw() == instance_type_arguments.raw()) && |
| 508 (last_instantiator_type_arguments.raw() == | 513 (last_instantiator_type_arguments.raw() == |
| 509 instantiator_type_arguments.raw())) { | 514 instantiator_type_arguments.raw())) { |
| 510 if (FLAG_trace_type_checks) { | 515 if (FLAG_trace_type_checks) { |
| 511 OS::Print("%"Pd" ", i); | 516 OS::Print("%"Pd" ", i); |
| 512 if (type_arguments_replaced) { | 517 if (type_arguments_replaced) { |
| 513 PrintTypeCheck("Duplicate cache entry (canonical.)", instance, type, | 518 PrintTypeCheck("Duplicate cache entry (canonical.)", instance, type, |
| 514 instantiator_type_arguments, result); | 519 instantiator_type_arguments, result); |
| 515 } else { | 520 } else { |
| 516 PrintTypeCheck("WARNING Duplicate cache entry", instance, type, | 521 PrintTypeCheck("WARNING Duplicate cache entry", instance, type, |
| 517 instantiator_type_arguments, result); | 522 instantiator_type_arguments, result); |
| 518 } | 523 } |
| 519 } | 524 } |
| 520 // Can occur if we have canonicalized arguments. | 525 // Can occur if we have canonicalized arguments. |
| 521 // TODO(srdjan): Investigate why this assert can fail. | 526 // TODO(srdjan): Investigate why this assert can fail. |
| 522 // ASSERT(type_arguments_replaced); | 527 // ASSERT(type_arguments_replaced); |
| 523 return; | 528 return; |
| 524 } | 529 } |
| 525 } | 530 } |
| 526 new_cache.AddCheck(instance_class.id(), | 531 if (!instantiator_type_arguments.IsInstantiatedTypeArguments()) { |
| 527 instance_type_arguments, | 532 new_cache.AddCheck(instance_class.id(), |
| 528 instantiator_type_arguments, | 533 instance_type_arguments, |
| 529 result); | 534 instantiator_type_arguments, |
| 535 result); |
| 536 } |
| 530 if (FLAG_trace_type_checks) { | 537 if (FLAG_trace_type_checks) { |
| 531 AbstractType& test_type = AbstractType::Handle(type.raw()); | 538 AbstractType& test_type = AbstractType::Handle(type.raw()); |
| 532 if (!test_type.IsInstantiated()) { | 539 if (!test_type.IsInstantiated()) { |
| 533 test_type = type.InstantiateFrom(instantiator_type_arguments); | 540 test_type = type.InstantiateFrom(instantiator_type_arguments); |
| 534 } | 541 } |
| 535 OS::Print(" Updated test cache %p ix:%"Pd":\n" | 542 OS::Print(" Updated test cache %p ix: %"Pd" with (%"Pd", %p, %p, %s)\n" |
| 536 " [%p %s %"Pd", %p %s]\n" | 543 " [%p %s %"Pd", %p %s]\n" |
| 537 " [%p %s %"Pd", %p %s] %s\n", | 544 " [%p %s %"Pd", %p %s] %s\n", |
| 538 new_cache.raw(), | 545 new_cache.raw(), |
| 539 len, | 546 len, |
| 547 instance_class.id(), |
| 548 |
| 549 instance_type_arguments.raw(), |
| 550 instantiator_type_arguments.raw(), |
| 551 result.ToCString(), |
| 552 |
| 540 instance_class.raw(), | 553 instance_class.raw(), |
| 541 instance_class.ToCString(), | 554 instance_class.ToCString(), |
| 542 instance_class.id(), | 555 instance_class.id(), |
| 543 instance_type_arguments.raw(), | 556 instance_type_arguments.raw(), |
| 544 instance_type_arguments.ToCString(), | 557 instance_type_arguments.ToCString(), |
| 558 |
| 545 test_type.type_class(), | 559 test_type.type_class(), |
| 546 Class::Handle(test_type.type_class()).ToCString(), | 560 Class::Handle(test_type.type_class()).ToCString(), |
| 547 Class::Handle(test_type.type_class()).id(), | 561 Class::Handle(test_type.type_class()).id(), |
| 548 instantiator_type_arguments.raw(), | 562 instantiator_type_arguments.raw(), |
| 549 instantiator_type_arguments.ToCString(), | 563 instantiator_type_arguments.ToCString(), |
| 550 result.ToCString()); | 564 result.ToCString()); |
| 551 } | 565 } |
| 552 } | 566 } |
| 553 | 567 |
| 554 | 568 |
| (...skipping 1330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1885 intptr_t line, column; | 1899 intptr_t line, column; |
| 1886 script.GetTokenLocation(token_pos, &line, &column); | 1900 script.GetTokenLocation(token_pos, &line, &column); |
| 1887 String& line_string = String::Handle(script.GetLine(line)); | 1901 String& line_string = String::Handle(script.GetLine(line)); |
| 1888 OS::Print(" Function: %s\n", top_function.ToFullyQualifiedCString()); | 1902 OS::Print(" Function: %s\n", top_function.ToFullyQualifiedCString()); |
| 1889 OS::Print(" Line %"Pd": '%s'\n", line, line_string.ToCString()); | 1903 OS::Print(" Line %"Pd": '%s'\n", line, line_string.ToCString()); |
| 1890 } | 1904 } |
| 1891 } | 1905 } |
| 1892 | 1906 |
| 1893 | 1907 |
| 1894 } // namespace dart | 1908 } // namespace dart |
| OLD | NEW |