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 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 Error::Handle(Compiler::CompileFunction(target_function)); | 747 Error::Handle(Compiler::CompileFunction(target_function)); |
748 if (!error.IsNull()) { | 748 if (!error.IsNull()) { |
749 Exceptions::PropagateError(error); | 749 Exceptions::PropagateError(error); |
750 } | 750 } |
751 } | 751 } |
752 const Code& target_code = Code::Handle(target_function.CurrentCode()); | 752 const Code& target_code = Code::Handle(target_function.CurrentCode()); |
753 // Before patching verify that we are not repeatedly patching to the same | 753 // Before patching verify that we are not repeatedly patching to the same |
754 // target. | 754 // target. |
755 ASSERT(target_code.EntryPoint() != | 755 ASSERT(target_code.EntryPoint() != |
756 CodePatcher::GetStaticCallTargetAt(caller_frame->pc(), caller_code)); | 756 CodePatcher::GetStaticCallTargetAt(caller_frame->pc(), caller_code)); |
757 CodePatcher::PatchStaticCallAt(caller_frame->pc(), caller_code, | 757 const Instructions& instrs = |
758 target_code.EntryPoint()); | 758 Instructions::Handle(caller_code.instructions()); |
759 caller_code.SetStaticCallTargetCodeAt(caller_frame->pc(), target_code); | 759 { |
| 760 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
| 761 CodePatcher::PatchStaticCallAt(caller_frame->pc(), caller_code, |
| 762 target_code.EntryPoint()); |
| 763 caller_code.SetStaticCallTargetCodeAt(caller_frame->pc(), target_code); |
| 764 } |
760 if (FLAG_trace_patching) { | 765 if (FLAG_trace_patching) { |
761 OS::PrintErr("PatchStaticCall: patching from %#" Px " to '%s' %#" Px "\n", | 766 OS::PrintErr("PatchStaticCall: patching from %#" Px " to '%s' %#" Px "\n", |
762 caller_frame->pc(), | 767 caller_frame->pc(), |
763 target_function.ToFullyQualifiedCString(), | 768 target_function.ToFullyQualifiedCString(), |
764 target_code.EntryPoint()); | 769 target_code.EntryPoint()); |
765 } | 770 } |
766 arguments.SetReturn(target_code); | 771 arguments.SetReturn(target_code); |
767 } | 772 } |
768 | 773 |
769 | 774 |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1436 caller_code.GetStaticCallTargetFunctionAt(frame->pc())); | 1441 caller_code.GetStaticCallTargetFunctionAt(frame->pc())); |
1437 const Code& target_code = Code::Handle( | 1442 const Code& target_code = Code::Handle( |
1438 caller_code.GetStaticCallTargetCodeAt(frame->pc())); | 1443 caller_code.GetStaticCallTargetCodeAt(frame->pc())); |
1439 ASSERT(!target_code.IsNull()); | 1444 ASSERT(!target_code.IsNull()); |
1440 // Since there was a reference to the target_code in the caller_code, it is | 1445 // Since there was a reference to the target_code in the caller_code, it is |
1441 // not possible for the target_function's code to be disconnected. | 1446 // not possible for the target_function's code to be disconnected. |
1442 ASSERT(target_function.HasCode()); | 1447 ASSERT(target_function.HasCode()); |
1443 ASSERT(target_function.raw() == target_code.function()); | 1448 ASSERT(target_function.raw() == target_code.function()); |
1444 | 1449 |
1445 const Code& current_target_code = Code::Handle(target_function.CurrentCode()); | 1450 const Code& current_target_code = Code::Handle(target_function.CurrentCode()); |
1446 CodePatcher::PatchStaticCallAt(frame->pc(), caller_code, | 1451 const Instructions& instrs = Instructions::Handle(caller_code.instructions()); |
1447 current_target_code.EntryPoint()); | 1452 { |
1448 caller_code.SetStaticCallTargetCodeAt(frame->pc(), current_target_code); | 1453 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
| 1454 CodePatcher::PatchStaticCallAt(frame->pc(), caller_code, |
| 1455 current_target_code.EntryPoint()); |
| 1456 caller_code.SetStaticCallTargetCodeAt(frame->pc(), current_target_code); |
| 1457 } |
1449 if (FLAG_trace_patching) { | 1458 if (FLAG_trace_patching) { |
1450 OS::PrintErr("FixCallersTarget: patching from %#" Px " to '%s' %#" Px "\n", | 1459 OS::PrintErr("FixCallersTarget: patching from %#" Px " to '%s' %#" Px "\n", |
1451 frame->pc(), | 1460 frame->pc(), |
1452 target_function.ToFullyQualifiedCString(), | 1461 target_function.ToFullyQualifiedCString(), |
1453 current_target_code.EntryPoint()); | 1462 current_target_code.EntryPoint()); |
1454 } | 1463 } |
1455 arguments.SetReturn(current_target_code); | 1464 arguments.SetReturn(current_target_code); |
1456 } | 1465 } |
1457 | 1466 |
1458 | 1467 |
(...skipping 19 matching lines...) Expand all Loading... |
1478 const Code& unoptimized_code = Code::Handle(function.unoptimized_code()); | 1487 const Code& unoptimized_code = Code::Handle(function.unoptimized_code()); |
1479 ASSERT(!unoptimized_code.IsNull()); | 1488 ASSERT(!unoptimized_code.IsNull()); |
1480 // The switch to unoptimized code may have already occurred. | 1489 // The switch to unoptimized code may have already occurred. |
1481 if (function.HasOptimizedCode()) { | 1490 if (function.HasOptimizedCode()) { |
1482 function.SwitchToUnoptimizedCode(); | 1491 function.SwitchToUnoptimizedCode(); |
1483 } | 1492 } |
1484 // Patch call site (lazy deoptimization is quite rare, patching it twice | 1493 // Patch call site (lazy deoptimization is quite rare, patching it twice |
1485 // is not a performance issue). | 1494 // is not a performance issue). |
1486 uword lazy_deopt_jump = optimized_code.GetLazyDeoptPc(); | 1495 uword lazy_deopt_jump = optimized_code.GetLazyDeoptPc(); |
1487 ASSERT(lazy_deopt_jump != 0); | 1496 ASSERT(lazy_deopt_jump != 0); |
1488 CodePatcher::InsertCallAt(pc, lazy_deopt_jump); | 1497 const Instructions& instrs = |
| 1498 Instructions::Handle(optimized_code.instructions()); |
| 1499 { |
| 1500 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
| 1501 CodePatcher::InsertCallAt(pc, lazy_deopt_jump); |
| 1502 } |
1489 // Mark code as dead (do not GC its embedded objects). | 1503 // Mark code as dead (do not GC its embedded objects). |
1490 optimized_code.set_is_alive(false); | 1504 optimized_code.set_is_alive(false); |
1491 } | 1505 } |
1492 | 1506 |
1493 | 1507 |
1494 // Currently checks only that all optimized frames have kDeoptIndex | 1508 // Currently checks only that all optimized frames have kDeoptIndex |
1495 // and unoptimized code has the kDeoptAfter. | 1509 // and unoptimized code has the kDeoptAfter. |
1496 void DeoptimizeAll() { | 1510 void DeoptimizeAll() { |
1497 DartFrameIterator iterator; | 1511 DartFrameIterator iterator; |
1498 StackFrame* frame = iterator.NextFrame(); | 1512 StackFrame* frame = iterator.NextFrame(); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1704 // of the given value. | 1718 // of the given value. |
1705 // Arg0: Field object; | 1719 // Arg0: Field object; |
1706 // Arg1: Value that is being stored. | 1720 // Arg1: Value that is being stored. |
1707 DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) { | 1721 DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) { |
1708 const Field& field = Field::CheckedHandle(arguments.ArgAt(0)); | 1722 const Field& field = Field::CheckedHandle(arguments.ArgAt(0)); |
1709 const Object& value = Object::Handle(arguments.ArgAt(1)); | 1723 const Object& value = Object::Handle(arguments.ArgAt(1)); |
1710 field.UpdateGuardedCidAndLength(value); | 1724 field.UpdateGuardedCidAndLength(value); |
1711 } | 1725 } |
1712 | 1726 |
1713 } // namespace dart | 1727 } // namespace dart |
OLD | NEW |