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 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 Error::Handle(Compiler::CompileFunction(target_function)); | 742 Error::Handle(Compiler::CompileFunction(target_function)); |
743 if (!error.IsNull()) { | 743 if (!error.IsNull()) { |
744 Exceptions::PropagateError(error); | 744 Exceptions::PropagateError(error); |
745 } | 745 } |
746 } | 746 } |
747 const Code& target_code = Code::Handle(target_function.CurrentCode()); | 747 const Code& target_code = Code::Handle(target_function.CurrentCode()); |
748 // Before patching verify that we are not repeatedly patching to the same | 748 // Before patching verify that we are not repeatedly patching to the same |
749 // target. | 749 // target. |
750 ASSERT(target_code.EntryPoint() != | 750 ASSERT(target_code.EntryPoint() != |
751 CodePatcher::GetStaticCallTargetAt(caller_frame->pc(), caller_code)); | 751 CodePatcher::GetStaticCallTargetAt(caller_frame->pc(), caller_code)); |
752 CodePatcher::PatchStaticCallAt(caller_frame->pc(), caller_code, | 752 const Instructions& instrs = |
753 target_code.EntryPoint()); | 753 Instructions::Handle(caller_code.instructions()); |
754 caller_code.SetStaticCallTargetCodeAt(caller_frame->pc(), target_code); | 754 { |
| 755 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
| 756 CodePatcher::PatchStaticCallAt(caller_frame->pc(), caller_code, |
| 757 target_code.EntryPoint()); |
| 758 caller_code.SetStaticCallTargetCodeAt(caller_frame->pc(), target_code); |
| 759 } |
755 if (FLAG_trace_patching) { | 760 if (FLAG_trace_patching) { |
756 OS::PrintErr("PatchStaticCall: patching from %#" Px " to '%s' %#" Px "\n", | 761 OS::PrintErr("PatchStaticCall: patching from %#" Px " to '%s' %#" Px "\n", |
757 caller_frame->pc(), | 762 caller_frame->pc(), |
758 target_function.ToFullyQualifiedCString(), | 763 target_function.ToFullyQualifiedCString(), |
759 target_code.EntryPoint()); | 764 target_code.EntryPoint()); |
760 } | 765 } |
761 arguments.SetReturn(target_code); | 766 arguments.SetReturn(target_code); |
762 } | 767 } |
763 | 768 |
764 | 769 |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1464 caller_code.GetStaticCallTargetFunctionAt(frame->pc())); | 1469 caller_code.GetStaticCallTargetFunctionAt(frame->pc())); |
1465 const Code& target_code = Code::Handle( | 1470 const Code& target_code = Code::Handle( |
1466 caller_code.GetStaticCallTargetCodeAt(frame->pc())); | 1471 caller_code.GetStaticCallTargetCodeAt(frame->pc())); |
1467 ASSERT(!target_code.IsNull()); | 1472 ASSERT(!target_code.IsNull()); |
1468 // Since there was a reference to the target_code in the caller_code, it is | 1473 // Since there was a reference to the target_code in the caller_code, it is |
1469 // not possible for the target_function's code to be disconnected. | 1474 // not possible for the target_function's code to be disconnected. |
1470 ASSERT(target_function.HasCode()); | 1475 ASSERT(target_function.HasCode()); |
1471 ASSERT(target_function.raw() == target_code.function()); | 1476 ASSERT(target_function.raw() == target_code.function()); |
1472 | 1477 |
1473 const Code& current_target_code = Code::Handle(target_function.CurrentCode()); | 1478 const Code& current_target_code = Code::Handle(target_function.CurrentCode()); |
1474 CodePatcher::PatchStaticCallAt(frame->pc(), caller_code, | 1479 const Instructions& instrs = Instructions::Handle(caller_code.instructions()); |
1475 current_target_code.EntryPoint()); | 1480 { |
1476 caller_code.SetStaticCallTargetCodeAt(frame->pc(), current_target_code); | 1481 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
| 1482 CodePatcher::PatchStaticCallAt(frame->pc(), caller_code, |
| 1483 current_target_code.EntryPoint()); |
| 1484 caller_code.SetStaticCallTargetCodeAt(frame->pc(), current_target_code); |
| 1485 } |
1477 if (FLAG_trace_patching) { | 1486 if (FLAG_trace_patching) { |
1478 OS::PrintErr("FixCallersTarget: patching from %#" Px " to '%s' %#" Px "\n", | 1487 OS::PrintErr("FixCallersTarget: patching from %#" Px " to '%s' %#" Px "\n", |
1479 frame->pc(), | 1488 frame->pc(), |
1480 target_function.ToFullyQualifiedCString(), | 1489 target_function.ToFullyQualifiedCString(), |
1481 current_target_code.EntryPoint()); | 1490 current_target_code.EntryPoint()); |
1482 } | 1491 } |
1483 arguments.SetReturn(current_target_code); | 1492 arguments.SetReturn(current_target_code); |
1484 } | 1493 } |
1485 | 1494 |
1486 | 1495 |
(...skipping 19 matching lines...) Expand all Loading... |
1506 const Code& unoptimized_code = Code::Handle(function.unoptimized_code()); | 1515 const Code& unoptimized_code = Code::Handle(function.unoptimized_code()); |
1507 ASSERT(!unoptimized_code.IsNull()); | 1516 ASSERT(!unoptimized_code.IsNull()); |
1508 // The switch to unoptimized code may have already occurred. | 1517 // The switch to unoptimized code may have already occurred. |
1509 if (function.HasOptimizedCode()) { | 1518 if (function.HasOptimizedCode()) { |
1510 function.SwitchToUnoptimizedCode(); | 1519 function.SwitchToUnoptimizedCode(); |
1511 } | 1520 } |
1512 // Patch call site (lazy deoptimization is quite rare, patching it twice | 1521 // Patch call site (lazy deoptimization is quite rare, patching it twice |
1513 // is not a performance issue). | 1522 // is not a performance issue). |
1514 uword lazy_deopt_jump = optimized_code.GetLazyDeoptPc(); | 1523 uword lazy_deopt_jump = optimized_code.GetLazyDeoptPc(); |
1515 ASSERT(lazy_deopt_jump != 0); | 1524 ASSERT(lazy_deopt_jump != 0); |
1516 CodePatcher::InsertCallAt(pc, lazy_deopt_jump); | 1525 const Instructions& instrs = |
| 1526 Instructions::Handle(optimized_code.instructions()); |
| 1527 { |
| 1528 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
| 1529 CodePatcher::InsertCallAt(pc, lazy_deopt_jump); |
| 1530 } |
1517 // Mark code as dead (do not GC its embedded objects). | 1531 // Mark code as dead (do not GC its embedded objects). |
1518 optimized_code.set_is_alive(false); | 1532 optimized_code.set_is_alive(false); |
1519 } | 1533 } |
1520 | 1534 |
1521 | 1535 |
1522 // Currently checks only that all optimized frames have kDeoptIndex | 1536 // Currently checks only that all optimized frames have kDeoptIndex |
1523 // and unoptimized code has the kDeoptAfter. | 1537 // and unoptimized code has the kDeoptAfter. |
1524 void DeoptimizeAll() { | 1538 void DeoptimizeAll() { |
1525 DartFrameIterator iterator; | 1539 DartFrameIterator iterator; |
1526 StackFrame* frame = iterator.NextFrame(); | 1540 StackFrame* frame = iterator.NextFrame(); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1732 // of the given value. | 1746 // of the given value. |
1733 // Arg0: Field object; | 1747 // Arg0: Field object; |
1734 // Arg1: Value that is being stored. | 1748 // Arg1: Value that is being stored. |
1735 DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) { | 1749 DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) { |
1736 const Field& field = Field::CheckedHandle(arguments.ArgAt(0)); | 1750 const Field& field = Field::CheckedHandle(arguments.ArgAt(0)); |
1737 const Object& value = Object::Handle(arguments.ArgAt(1)); | 1751 const Object& value = Object::Handle(arguments.ArgAt(1)); |
1738 field.UpdateGuardedCidAndLength(value); | 1752 field.UpdateGuardedCidAndLength(value); |
1739 } | 1753 } |
1740 | 1754 |
1741 } // namespace dart | 1755 } // namespace dart |
OLD | NEW |