| 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 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 Error::Handle(Compiler::CompileFunction(target_function)); | 718 Error::Handle(Compiler::CompileFunction(target_function)); |
| 719 if (!error.IsNull()) { | 719 if (!error.IsNull()) { |
| 720 Exceptions::PropagateError(error); | 720 Exceptions::PropagateError(error); |
| 721 } | 721 } |
| 722 } | 722 } |
| 723 const Code& target_code = Code::Handle(target_function.CurrentCode()); | 723 const Code& target_code = Code::Handle(target_function.CurrentCode()); |
| 724 // Before patching verify that we are not repeatedly patching to the same | 724 // Before patching verify that we are not repeatedly patching to the same |
| 725 // target. | 725 // target. |
| 726 ASSERT(target_code.EntryPoint() != | 726 ASSERT(target_code.EntryPoint() != |
| 727 CodePatcher::GetStaticCallTargetAt(caller_frame->pc(), caller_code)); | 727 CodePatcher::GetStaticCallTargetAt(caller_frame->pc(), caller_code)); |
| 728 CodePatcher::PatchStaticCallAt(caller_frame->pc(), caller_code, | 728 const Instructions& instrs = |
| 729 target_code.EntryPoint()); | 729 Instructions::Handle(caller_code.instructions()); |
| 730 caller_code.SetStaticCallTargetCodeAt(caller_frame->pc(), target_code); | 730 { |
| 731 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
| 732 CodePatcher::PatchStaticCallAt(caller_frame->pc(), caller_code, |
| 733 target_code.EntryPoint()); |
| 734 caller_code.SetStaticCallTargetCodeAt(caller_frame->pc(), target_code); |
| 735 } |
| 731 if (FLAG_trace_patching) { | 736 if (FLAG_trace_patching) { |
| 732 OS::PrintErr("PatchStaticCall: patching from %#" Px " to '%s' %#" Px "\n", | 737 OS::PrintErr("PatchStaticCall: patching from %#" Px " to '%s' %#" Px "\n", |
| 733 caller_frame->pc(), | 738 caller_frame->pc(), |
| 734 target_function.ToFullyQualifiedCString(), | 739 target_function.ToFullyQualifiedCString(), |
| 735 target_code.EntryPoint()); | 740 target_code.EntryPoint()); |
| 736 } | 741 } |
| 737 arguments.SetReturn(target_code); | 742 arguments.SetReturn(target_code); |
| 738 } | 743 } |
| 739 | 744 |
| 740 | 745 |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1447 caller_code.GetStaticCallTargetFunctionAt(frame->pc())); | 1452 caller_code.GetStaticCallTargetFunctionAt(frame->pc())); |
| 1448 const Code& target_code = Code::Handle( | 1453 const Code& target_code = Code::Handle( |
| 1449 caller_code.GetStaticCallTargetCodeAt(frame->pc())); | 1454 caller_code.GetStaticCallTargetCodeAt(frame->pc())); |
| 1450 ASSERT(!target_code.IsNull()); | 1455 ASSERT(!target_code.IsNull()); |
| 1451 // Since there was a reference to the target_code in the caller_code, it is | 1456 // Since there was a reference to the target_code in the caller_code, it is |
| 1452 // not possible for the target_function's code to be disconnected. | 1457 // not possible for the target_function's code to be disconnected. |
| 1453 ASSERT(target_function.HasCode()); | 1458 ASSERT(target_function.HasCode()); |
| 1454 ASSERT(target_function.raw() == target_code.function()); | 1459 ASSERT(target_function.raw() == target_code.function()); |
| 1455 | 1460 |
| 1456 const Code& current_target_code = Code::Handle(target_function.CurrentCode()); | 1461 const Code& current_target_code = Code::Handle(target_function.CurrentCode()); |
| 1457 CodePatcher::PatchStaticCallAt(frame->pc(), caller_code, | 1462 const Instructions& instrs = Instructions::Handle(caller_code.instructions()); |
| 1458 current_target_code.EntryPoint()); | 1463 { |
| 1459 caller_code.SetStaticCallTargetCodeAt(frame->pc(), current_target_code); | 1464 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
| 1465 CodePatcher::PatchStaticCallAt(frame->pc(), caller_code, |
| 1466 current_target_code.EntryPoint()); |
| 1467 caller_code.SetStaticCallTargetCodeAt(frame->pc(), current_target_code); |
| 1468 } |
| 1460 if (FLAG_trace_patching) { | 1469 if (FLAG_trace_patching) { |
| 1461 OS::PrintErr("FixCallersTarget: patching from %#" Px " to '%s' %#" Px "\n", | 1470 OS::PrintErr("FixCallersTarget: patching from %#" Px " to '%s' %#" Px "\n", |
| 1462 frame->pc(), | 1471 frame->pc(), |
| 1463 target_function.ToFullyQualifiedCString(), | 1472 target_function.ToFullyQualifiedCString(), |
| 1464 current_target_code.EntryPoint()); | 1473 current_target_code.EntryPoint()); |
| 1465 } | 1474 } |
| 1466 arguments.SetReturn(current_target_code); | 1475 arguments.SetReturn(current_target_code); |
| 1467 } | 1476 } |
| 1468 | 1477 |
| 1469 | 1478 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1489 const Code& unoptimized_code = Code::Handle(function.unoptimized_code()); | 1498 const Code& unoptimized_code = Code::Handle(function.unoptimized_code()); |
| 1490 ASSERT(!unoptimized_code.IsNull()); | 1499 ASSERT(!unoptimized_code.IsNull()); |
| 1491 // The switch to unoptimized code may have already occurred. | 1500 // The switch to unoptimized code may have already occurred. |
| 1492 if (function.HasOptimizedCode()) { | 1501 if (function.HasOptimizedCode()) { |
| 1493 function.SwitchToUnoptimizedCode(); | 1502 function.SwitchToUnoptimizedCode(); |
| 1494 } | 1503 } |
| 1495 // Patch call site (lazy deoptimization is quite rare, patching it twice | 1504 // Patch call site (lazy deoptimization is quite rare, patching it twice |
| 1496 // is not a performance issue). | 1505 // is not a performance issue). |
| 1497 uword lazy_deopt_jump = optimized_code.GetLazyDeoptPc(); | 1506 uword lazy_deopt_jump = optimized_code.GetLazyDeoptPc(); |
| 1498 ASSERT(lazy_deopt_jump != 0); | 1507 ASSERT(lazy_deopt_jump != 0); |
| 1499 CodePatcher::InsertCallAt(pc, lazy_deopt_jump); | 1508 const Instructions& instrs = |
| 1509 Instructions::Handle(optimized_code.instructions()); |
| 1510 { |
| 1511 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
| 1512 CodePatcher::InsertCallAt(pc, lazy_deopt_jump); |
| 1513 } |
| 1500 // Mark code as dead (do not GC its embedded objects). | 1514 // Mark code as dead (do not GC its embedded objects). |
| 1501 optimized_code.set_is_alive(false); | 1515 optimized_code.set_is_alive(false); |
| 1502 } | 1516 } |
| 1503 | 1517 |
| 1504 | 1518 |
| 1505 // Currently checks only that all optimized frames have kDeoptIndex | 1519 // Currently checks only that all optimized frames have kDeoptIndex |
| 1506 // and unoptimized code has the kDeoptAfter. | 1520 // and unoptimized code has the kDeoptAfter. |
| 1507 void DeoptimizeAll() { | 1521 void DeoptimizeAll() { |
| 1508 DartFrameIterator iterator; | 1522 DartFrameIterator iterator; |
| 1509 StackFrame* frame = iterator.NextFrame(); | 1523 StackFrame* frame = iterator.NextFrame(); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1715 // of the given value. | 1729 // of the given value. |
| 1716 // Arg0: Field object; | 1730 // Arg0: Field object; |
| 1717 // Arg1: Value that is being stored. | 1731 // Arg1: Value that is being stored. |
| 1718 DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) { | 1732 DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) { |
| 1719 const Field& field = Field::CheckedHandle(arguments.ArgAt(0)); | 1733 const Field& field = Field::CheckedHandle(arguments.ArgAt(0)); |
| 1720 const Object& value = Object::Handle(arguments.ArgAt(1)); | 1734 const Object& value = Object::Handle(arguments.ArgAt(1)); |
| 1721 field.UpdateGuardedCidAndLength(value); | 1735 field.UpdateGuardedCidAndLength(value); |
| 1722 } | 1736 } |
| 1723 | 1737 |
| 1724 } // namespace dart | 1738 } // namespace dart |
| OLD | NEW |