OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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.h" | 7 #include "vm/assembler.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 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1441 // This is called from function that needs to be optimized. | 1441 // This is called from function that needs to be optimized. |
1442 // The requesting function can be already optimized (reoptimization). | 1442 // The requesting function can be already optimized (reoptimization). |
1443 // Returns the Code object where to continue execution. | 1443 // Returns the Code object where to continue execution. |
1444 DEFINE_RUNTIME_ENTRY(OptimizeInvokedFunction, 1) { | 1444 DEFINE_RUNTIME_ENTRY(OptimizeInvokedFunction, 1) { |
1445 const Function& function = Function::CheckedHandle(zone, | 1445 const Function& function = Function::CheckedHandle(zone, |
1446 arguments.ArgAt(0)); | 1446 arguments.ArgAt(0)); |
1447 ASSERT(!function.IsNull()); | 1447 ASSERT(!function.IsNull()); |
1448 ASSERT(function.HasCode()); | 1448 ASSERT(function.HasCode()); |
1449 | 1449 |
1450 if (CanOptimizeFunction(function, isolate)) { | 1450 if (CanOptimizeFunction(function, isolate)) { |
1451 // Reset usage counter for reoptimization before calling optimizer to | |
1452 // prevent recursive triggering of function optimization. | |
1453 function.set_usage_counter(0); | |
1454 if (FLAG_background_compilation) { | 1451 if (FLAG_background_compilation) { |
| 1452 // Reduce the chance of triggering optimization while the function is |
| 1453 // being optimized in the background. INT_MIN should ensure that it takes |
| 1454 // long time to trigger optimization. |
| 1455 // Note that the background compilation queue rejects duplicate entries. |
| 1456 function.set_usage_counter(INT_MIN); |
1455 BackgroundCompiler::EnsureInit(thread); | 1457 BackgroundCompiler::EnsureInit(thread); |
1456 ASSERT(isolate->background_compiler() != NULL); | 1458 ASSERT(isolate->background_compiler() != NULL); |
1457 isolate->background_compiler()->CompileOptimized(function); | 1459 isolate->background_compiler()->CompileOptimized(function); |
1458 // Continue in the same code. | 1460 // Continue in the same code. |
1459 arguments.SetReturn(Code::Handle(zone, function.CurrentCode())); | 1461 arguments.SetReturn(Code::Handle(zone, function.CurrentCode())); |
1460 return; | 1462 return; |
1461 } | 1463 } |
| 1464 |
| 1465 // Reset usage counter for reoptimization before calling optimizer to |
| 1466 // prevent recursive triggering of function optimization. |
| 1467 function.set_usage_counter(0); |
1462 if (FLAG_trace_compiler) { | 1468 if (FLAG_trace_compiler) { |
1463 if (function.HasOptimizedCode()) { | 1469 if (function.HasOptimizedCode()) { |
1464 THR_Print("ReCompiling function: '%s' \n", | 1470 THR_Print("ReCompiling function: '%s' \n", |
1465 function.ToFullyQualifiedCString()); | 1471 function.ToFullyQualifiedCString()); |
1466 } | 1472 } |
1467 } | 1473 } |
1468 const Error& error = Error::Handle( | 1474 const Error& error = Error::Handle( |
1469 zone, Compiler::CompileOptimizedFunction(thread, function)); | 1475 zone, Compiler::CompileOptimizedFunction(thread, function)); |
1470 if (!error.IsNull()) { | 1476 if (!error.IsNull()) { |
1471 Exceptions::PropagateError(error); | 1477 Exceptions::PropagateError(error); |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1835 const intptr_t elm_size = old_data.ElementSizeInBytes(); | 1841 const intptr_t elm_size = old_data.ElementSizeInBytes(); |
1836 const TypedData& new_data = | 1842 const TypedData& new_data = |
1837 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); | 1843 TypedData::Handle(TypedData::New(cid, new_size, Heap::kOld)); |
1838 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); | 1844 TypedData::Copy(new_data, 0, old_data, 0, old_size * elm_size); |
1839 typed_data_cell.SetAt(0, new_data); | 1845 typed_data_cell.SetAt(0, new_data); |
1840 arguments.SetReturn(new_data); | 1846 arguments.SetReturn(new_data); |
1841 } | 1847 } |
1842 | 1848 |
1843 | 1849 |
1844 } // namespace dart | 1850 } // namespace dart |
OLD | NEW |