Chromium Code Reviews| 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/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/code_patcher.h" | 10 #include "vm/code_patcher.h" |
| (...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1336 if (interrupt_bits & Isolate::kVmStatusInterrupt) { | 1336 if (interrupt_bits & Isolate::kVmStatusInterrupt) { |
| 1337 Dart_IsolateInterruptCallback callback = isolate->VmStatsCallback(); | 1337 Dart_IsolateInterruptCallback callback = isolate->VmStatsCallback(); |
| 1338 if (callback) { | 1338 if (callback) { |
| 1339 (*callback)(); | 1339 (*callback)(); |
| 1340 } | 1340 } |
| 1341 } | 1341 } |
| 1342 | 1342 |
| 1343 if (FLAG_use_osr && (interrupt_bits == 0)) { | 1343 if (FLAG_use_osr && (interrupt_bits == 0)) { |
| 1344 DartFrameIterator iterator; | 1344 DartFrameIterator iterator; |
| 1345 StackFrame* frame = iterator.NextFrame(); | 1345 StackFrame* frame = iterator.NextFrame(); |
| 1346 const Function& function = Function::Handle(frame->LookupDartFunction()); | 1346 const Code& code = Code::ZoneHandle(frame->LookupDartCode()); |
|
srdjan
2013/11/19 19:18:29
Optional, as it will fail in next line: ASSERT(!co
zra
2013/11/22 17:18:54
Done.
| |
| 1347 const Function& function = Function::Handle(code.function()); | |
| 1347 ASSERT(!function.IsNull()); | 1348 ASSERT(!function.IsNull()); |
| 1348 if (!CanOptimizeFunction(function, isolate)) return; | 1349 ASSERT(function.HasCode()); |
|
srdjan
2013/11/19 19:18:29
Why does this need to be true? Is this because onc
zra
2013/11/22 17:18:54
Done.
| |
| 1350 if (!CanOptimizeFunction(function, isolate)) { | |
| 1351 return; | |
| 1352 } | |
| 1349 intptr_t osr_id = | 1353 intptr_t osr_id = |
| 1350 Code::Handle(function.unoptimized_code()).GetDeoptIdForOsr(frame->pc()); | 1354 Code::Handle(function.unoptimized_code()).GetDeoptIdForOsr(frame->pc()); |
| 1351 if (FLAG_trace_osr) { | 1355 if (FLAG_trace_osr) { |
| 1352 OS::Print("Attempting OSR for %s at id=%" Pd ", count=%" Pd "\n", | 1356 OS::Print("Attempting OSR for %s at id=%" Pd ", count=%" Pd "\n", |
| 1353 function.ToFullyQualifiedCString(), | 1357 function.ToFullyQualifiedCString(), |
| 1354 osr_id, | 1358 osr_id, |
| 1355 function.usage_counter()); | 1359 function.usage_counter()); |
| 1356 } | 1360 } |
| 1357 | 1361 |
| 1358 const Code& original_code = Code::Handle(function.CurrentCode()); | 1362 const Code& original_code = Code::Handle(function.CurrentCode()); |
| 1363 ASSERT(!original_code.IsNull()); | |
| 1359 const Error& error = | 1364 const Error& error = |
| 1360 Error::Handle(Compiler::CompileOptimizedFunction(function, osr_id)); | 1365 Error::Handle(Compiler::CompileOptimizedFunction(function, osr_id)); |
| 1361 if (!error.IsNull()) Exceptions::PropagateError(error); | 1366 if (!error.IsNull()) { |
| 1367 Exceptions::PropagateError(error); | |
| 1368 } | |
| 1362 | 1369 |
| 1363 const Code& optimized_code = Code::Handle(function.CurrentCode()); | 1370 const Code& optimized_code = Code::Handle(function.CurrentCode()); |
| 1364 // The current code will not be changed in the case that the compiler | 1371 // The current code will not be changed in the case that the compiler |
| 1365 // bailed out during OSR compilation. | 1372 // bailed out during OSR compilation. |
| 1366 if (optimized_code.raw() != original_code.raw()) { | 1373 if (optimized_code.raw() != original_code.raw()) { |
| 1367 // The OSR code does not work for calling the function, so restore the | 1374 // The OSR code does not work for calling the function, so restore the |
| 1368 // unoptimized code. Patch the stack frame to return into the OSR | 1375 // unoptimized code. Patch the stack frame to return into the OSR |
| 1369 // code. | 1376 // code. |
| 1370 uword optimized_entry = | 1377 uword optimized_entry = |
| 1371 Instructions::Handle(optimized_code.instructions()).EntryPoint(); | 1378 Instructions::Handle(optimized_code.instructions()).EntryPoint(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1427 ASSERT(frame != NULL); | 1434 ASSERT(frame != NULL); |
| 1428 if (frame->IsEntryFrame()) { | 1435 if (frame->IsEntryFrame()) { |
| 1429 // Since function's current code is always unpatched, the entry frame always | 1436 // Since function's current code is always unpatched, the entry frame always |
| 1430 // calls to unpatched code. | 1437 // calls to unpatched code. |
| 1431 UNREACHABLE(); | 1438 UNREACHABLE(); |
| 1432 } | 1439 } |
| 1433 ASSERT(frame->IsDartFrame()); | 1440 ASSERT(frame->IsDartFrame()); |
| 1434 const Code& caller_code = Code::Handle(frame->LookupDartCode()); | 1441 const Code& caller_code = Code::Handle(frame->LookupDartCode()); |
| 1435 ASSERT(caller_code.is_optimized()); | 1442 ASSERT(caller_code.is_optimized()); |
| 1436 const Function& target_function = Function::Handle( | 1443 const Function& target_function = Function::Handle( |
| 1437 caller_code.GetStaticCallTargetFunctionAt(frame->pc())); | 1444 caller_code.GetStaticCallTargetFunctionAt(frame->pc())); |
|
srdjan
2013/11/19 19:18:29
GetStaticCallTargetCodeAt ->target_code -> functio
zra
2013/11/22 17:18:54
Done.
| |
| 1438 | 1445 |
| 1439 // Check whether the code object has been detached from the target function. | 1446 ASSERT(target_function.HasCode()); |
| 1440 // If it has been detached, reattach it. | 1447 Code& target_code = Code::Handle(target_function.CurrentCode()); |
| 1441 Code& target_code = Code::Handle(); | 1448 CodePatcher::PatchStaticCallAt(frame->pc(), caller_code, |
| 1442 if (target_function.HasCode()) { | 1449 target_code.EntryPoint()); |
| 1443 target_code ^= target_function.CurrentCode(); | 1450 caller_code.SetStaticCallTargetCodeAt(frame->pc(), target_code); |
| 1444 CodePatcher::PatchStaticCallAt(frame->pc(), caller_code, | |
| 1445 target_code.EntryPoint()); | |
| 1446 caller_code.SetStaticCallTargetCodeAt(frame->pc(), target_code); | |
| 1447 } else { | |
| 1448 ASSERT(target_function.unoptimized_code() == Code::null()); | |
| 1449 target_code ^= caller_code.GetStaticCallTargetCodeAt(frame->pc()); | |
| 1450 ASSERT(!target_code.IsNull()); | |
| 1451 ASSERT(!target_code.is_optimized()); | |
| 1452 target_function.ReattachCode(target_code); | |
| 1453 } | |
| 1454 if (FLAG_trace_patching) { | 1451 if (FLAG_trace_patching) { |
| 1455 OS::PrintErr("FixCallersTarget: patching from %#" Px " to '%s' %#" Px "\n", | 1452 OS::PrintErr("FixCallersTarget: patching from %#" Px " to '%s' %#" Px "\n", |
| 1456 frame->pc(), | 1453 frame->pc(), |
| 1457 Function::Handle(target_code.function()).ToFullyQualifiedCString(), | 1454 Function::Handle(target_code.function()).ToFullyQualifiedCString(), |
| 1458 target_code.EntryPoint()); | 1455 target_code.EntryPoint()); |
| 1459 } | 1456 } |
| 1460 arguments.SetReturn(target_code); | 1457 arguments.SetReturn(target_code); |
| 1461 ASSERT(target_function.HasCode()); | 1458 ASSERT(target_function.HasCode()); |
| 1462 } | 1459 } |
| 1463 | 1460 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1476 | 1473 |
| 1477 void DeoptimizeAt(const Code& optimized_code, uword pc) { | 1474 void DeoptimizeAt(const Code& optimized_code, uword pc) { |
| 1478 ASSERT(optimized_code.is_optimized()); | 1475 ASSERT(optimized_code.is_optimized()); |
| 1479 intptr_t deopt_reason = kDeoptUnknown; | 1476 intptr_t deopt_reason = kDeoptUnknown; |
| 1480 const DeoptInfo& deopt_info = | 1477 const DeoptInfo& deopt_info = |
| 1481 DeoptInfo::Handle(optimized_code.GetDeoptInfoAtPc(pc, &deopt_reason)); | 1478 DeoptInfo::Handle(optimized_code.GetDeoptInfoAtPc(pc, &deopt_reason)); |
| 1482 ASSERT(!deopt_info.IsNull()); | 1479 ASSERT(!deopt_info.IsNull()); |
| 1483 const Function& function = Function::Handle(optimized_code.function()); | 1480 const Function& function = Function::Handle(optimized_code.function()); |
| 1484 const Code& unoptimized_code = Code::Handle(function.unoptimized_code()); | 1481 const Code& unoptimized_code = Code::Handle(function.unoptimized_code()); |
| 1485 ASSERT(!unoptimized_code.IsNull()); | 1482 ASSERT(!unoptimized_code.IsNull()); |
| 1486 // The switch to unoptimized code may have already occured. | 1483 // The switch to unoptimized code may have already occurred. |
| 1487 if (function.HasOptimizedCode()) { | 1484 if (function.HasOptimizedCode()) { |
| 1488 function.SwitchToUnoptimizedCode(); | 1485 function.SwitchToUnoptimizedCode(); |
| 1489 } | 1486 } |
| 1490 // Patch call site (lazy deoptimization is quite rare, patching it twice | 1487 // Patch call site (lazy deoptimization is quite rare, patching it twice |
| 1491 // is not a performance issue). | 1488 // is not a performance issue). |
| 1492 uword lazy_deopt_jump = optimized_code.GetLazyDeoptPc(); | 1489 uword lazy_deopt_jump = optimized_code.GetLazyDeoptPc(); |
| 1493 ASSERT(lazy_deopt_jump != 0); | 1490 ASSERT(lazy_deopt_jump != 0); |
| 1494 CodePatcher::InsertCallAt(pc, lazy_deopt_jump); | 1491 CodePatcher::InsertCallAt(pc, lazy_deopt_jump); |
| 1495 // Mark code as dead (do not GC its embedded objects). | 1492 // Mark code as dead (do not GC its embedded objects). |
| 1496 optimized_code.set_is_alive(false); | 1493 optimized_code.set_is_alive(false); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1701 // of the given value. | 1698 // of the given value. |
| 1702 // Arg0: Field object; | 1699 // Arg0: Field object; |
| 1703 // Arg1: Value that is being stored. | 1700 // Arg1: Value that is being stored. |
| 1704 DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) { | 1701 DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) { |
| 1705 const Field& field = Field::CheckedHandle(arguments.ArgAt(0)); | 1702 const Field& field = Field::CheckedHandle(arguments.ArgAt(0)); |
| 1706 const Object& value = Object::Handle(arguments.ArgAt(1)); | 1703 const Object& value = Object::Handle(arguments.ArgAt(1)); |
| 1707 field.UpdateGuardedCidAndLength(value); | 1704 field.UpdateGuardedCidAndLength(value); |
| 1708 } | 1705 } |
| 1709 | 1706 |
| 1710 } // namespace dart | 1707 } // namespace dart |
| OLD | NEW |