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/code_patcher.h" | 8 #include "vm/code_patcher.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
| (...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1309 } | 1309 } |
| 1310 } | 1310 } |
| 1311 } | 1311 } |
| 1312 } | 1312 } |
| 1313 | 1313 |
| 1314 | 1314 |
| 1315 // Only unoptimized code has invocation counter threshold checking. | 1315 // Only unoptimized code has invocation counter threshold checking. |
| 1316 // Once the invocation counter threshold is reached any entry into the | 1316 // Once the invocation counter threshold is reached any entry into the |
| 1317 // unoptimized code is redirected to this function. | 1317 // unoptimized code is redirected to this function. |
| 1318 DEFINE_RUNTIME_ENTRY(OptimizeInvokedFunction, 1) { | 1318 DEFINE_RUNTIME_ENTRY(OptimizeInvokedFunction, 1) { |
| 1319 const intptr_t kLowInvocationCount = -100000000; | |
|
siva
2012/05/24 23:44:22
Why this value and not kIntptrMin....
srdjan
2012/05/24 23:57:22
It must be a Smi, could have been MinSmi but this
| |
| 1319 ASSERT(arguments.Count() == | 1320 ASSERT(arguments.Count() == |
| 1320 kOptimizeInvokedFunctionRuntimeEntry.argument_count()); | 1321 kOptimizeInvokedFunctionRuntimeEntry.argument_count()); |
| 1321 const Function& function = Function::CheckedHandle(arguments.At(0)); | 1322 const Function& function = Function::CheckedHandle(arguments.At(0)); |
| 1322 if (isolate->debugger()->IsActive()) { | 1323 if (isolate->debugger()->IsActive()) { |
| 1323 // We cannot set breakpoints in optimized code, so do not optimize | 1324 // We cannot set breakpoints in optimized code, so do not optimize |
| 1324 // the function. | 1325 // the function. |
| 1325 function.set_usage_counter(0); | 1326 function.set_usage_counter(0); |
| 1326 return; | 1327 return; |
| 1327 } | 1328 } |
| 1328 if (function.deoptimization_counter() >= | 1329 if (function.deoptimization_counter() >= |
| 1329 FLAG_deoptimization_counter_threshold) { | 1330 FLAG_deoptimization_counter_threshold) { |
| 1330 // TODO(srdjan): Investigate excessive deoptimization. | 1331 // TODO(srdjan): Investigate excessive deoptimization. |
| 1331 function.set_usage_counter(0); | 1332 function.set_usage_counter(kLowInvocationCount); |
| 1332 return; | 1333 return; |
| 1333 } | 1334 } |
| 1334 if (function.HasOptimizedCode()) { | 1335 if (function.HasOptimizedCode()) { |
| 1335 // The caller has been already optimized. | 1336 // The caller has been already optimized. |
| 1336 // TODO(srdjan): This is a significant slowdown, the caller is probably in | 1337 // TODO(srdjan): This is a significant slowdown, the caller is probably in |
| 1337 // a loop. Maybe test if the code has been optimized before calling. | 1338 // a loop. Maybe test if the code has been optimized before calling. |
| 1338 // If this happens from optimized code, then it means that the optimized | 1339 // If this happens from optimized code, then it means that the optimized |
| 1339 // code needs to be reoptimized. | 1340 // code needs to be reoptimized. |
| 1340 function.set_usage_counter(0); | 1341 function.set_usage_counter(kLowInvocationCount); |
| 1341 return; | 1342 return; |
| 1342 } | 1343 } |
| 1343 if (function.is_optimizable()) { | 1344 if (function.is_optimizable()) { |
| 1344 ASSERT(!function.HasOptimizedCode()); | 1345 ASSERT(!function.HasOptimizedCode()); |
| 1345 const Code& unoptimized_code = Code::Handle(function.unoptimized_code()); | 1346 const Code& unoptimized_code = Code::Handle(function.unoptimized_code()); |
| 1346 // Compilation patches the entry of unoptimized code. | 1347 // Compilation patches the entry of unoptimized code. |
| 1347 const Error& error = | 1348 const Error& error = |
| 1348 Error::Handle(Compiler::CompileOptimizedFunction(function)); | 1349 Error::Handle(Compiler::CompileOptimizedFunction(function)); |
| 1349 if (!error.IsNull()) { | 1350 if (!error.IsNull()) { |
| 1350 Exceptions::PropagateError(error); | 1351 Exceptions::PropagateError(error); |
| 1351 } | 1352 } |
| 1352 const Code& optimized_code = Code::Handle(function.CurrentCode()); | 1353 const Code& optimized_code = Code::Handle(function.CurrentCode()); |
| 1353 ASSERT(!optimized_code.IsNull()); | 1354 ASSERT(!optimized_code.IsNull()); |
| 1354 ASSERT(!unoptimized_code.IsNull()); | 1355 ASSERT(!unoptimized_code.IsNull()); |
| 1355 } else { | 1356 } else { |
| 1356 // TODO(5442338): Abort as this should not happen. | 1357 // TODO(5442338): Abort as this should not happen. |
| 1357 function.set_usage_counter(0); | 1358 function.set_usage_counter(kLowInvocationCount); |
| 1358 } | 1359 } |
| 1359 } | 1360 } |
| 1360 | 1361 |
| 1361 | 1362 |
| 1362 // The caller must be a static call in a Dart frame, or an entry frame. | 1363 // The caller must be a static call in a Dart frame, or an entry frame. |
| 1363 // Patch static call to point to 'new_entry_point'. | 1364 // Patch static call to point to 'new_entry_point'. |
| 1364 DEFINE_RUNTIME_ENTRY(FixCallersTarget, 1) { | 1365 DEFINE_RUNTIME_ENTRY(FixCallersTarget, 1) { |
| 1365 ASSERT(arguments.Count() == kFixCallersTargetRuntimeEntry.argument_count()); | 1366 ASSERT(arguments.Count() == kFixCallersTargetRuntimeEntry.argument_count()); |
| 1366 const Function& function = Function::CheckedHandle(arguments.At(0)); | 1367 const Function& function = Function::CheckedHandle(arguments.At(0)); |
| 1367 ASSERT(!function.IsNull()); | 1368 ASSERT(!function.IsNull()); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1554 } | 1555 } |
| 1555 } | 1556 } |
| 1556 } | 1557 } |
| 1557 // The cache is null terminated, therefore the loop above should never | 1558 // The cache is null terminated, therefore the loop above should never |
| 1558 // terminate by itself. | 1559 // terminate by itself. |
| 1559 UNREACHABLE(); | 1560 UNREACHABLE(); |
| 1560 return Code::null(); | 1561 return Code::null(); |
| 1561 } | 1562 } |
| 1562 | 1563 |
| 1563 } // namespace dart | 1564 } // namespace dart |
| OLD | NEW |