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 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 Error::Handle(Compiler::CompileFunction(target_function)); | 659 Error::Handle(Compiler::CompileFunction(target_function)); |
660 if (!error.IsNull()) { | 660 if (!error.IsNull()) { |
661 Exceptions::PropagateError(error); | 661 Exceptions::PropagateError(error); |
662 } | 662 } |
663 } | 663 } |
664 const Code& target_code = Code::Handle(target_function.CurrentCode()); | 664 const Code& target_code = Code::Handle(target_function.CurrentCode()); |
665 // Before patching verify that we are not repeatedly patching to the same | 665 // Before patching verify that we are not repeatedly patching to the same |
666 // target. | 666 // target. |
667 ASSERT(target_code.EntryPoint() != | 667 ASSERT(target_code.EntryPoint() != |
668 CodePatcher::GetStaticCallTargetAt(caller_frame->pc(), caller_code)); | 668 CodePatcher::GetStaticCallTargetAt(caller_frame->pc(), caller_code)); |
669 CodePatcher::PatchStaticCallAt(caller_frame->pc(), caller_code, | 669 const Instructions& instrs = |
670 target_code.EntryPoint()); | 670 Instructions::Handle(caller_code.instructions()); |
671 caller_code.SetStaticCallTargetCodeAt(caller_frame->pc(), target_code); | 671 { |
| 672 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
| 673 CodePatcher::PatchStaticCallAt(caller_frame->pc(), caller_code, |
| 674 target_code.EntryPoint()); |
| 675 caller_code.SetStaticCallTargetCodeAt(caller_frame->pc(), target_code); |
| 676 } |
672 if (FLAG_trace_patching) { | 677 if (FLAG_trace_patching) { |
673 OS::PrintErr("PatchStaticCall: patching from %#" Px " to '%s' %#" Px "\n", | 678 OS::PrintErr("PatchStaticCall: patching from %#" Px " to '%s' %#" Px "\n", |
674 caller_frame->pc(), | 679 caller_frame->pc(), |
675 target_function.ToFullyQualifiedCString(), | 680 target_function.ToFullyQualifiedCString(), |
676 target_code.EntryPoint()); | 681 target_code.EntryPoint()); |
677 } | 682 } |
678 arguments.SetReturn(target_code); | 683 arguments.SetReturn(target_code); |
679 } | 684 } |
680 | 685 |
681 | 686 |
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 const Error& error = | 1361 const Error& error = |
1357 Error::Handle(Compiler::CompileFunction(target_function)); | 1362 Error::Handle(Compiler::CompileFunction(target_function)); |
1358 if (!error.IsNull()) { | 1363 if (!error.IsNull()) { |
1359 Exceptions::PropagateError(error); | 1364 Exceptions::PropagateError(error); |
1360 } | 1365 } |
1361 } | 1366 } |
1362 ASSERT(target_function.HasCode()); | 1367 ASSERT(target_function.HasCode()); |
1363 ASSERT(target_function.raw() == target_code.function()); | 1368 ASSERT(target_function.raw() == target_code.function()); |
1364 | 1369 |
1365 const Code& current_target_code = Code::Handle(target_function.CurrentCode()); | 1370 const Code& current_target_code = Code::Handle(target_function.CurrentCode()); |
1366 CodePatcher::PatchStaticCallAt(frame->pc(), caller_code, | 1371 const Instructions& instrs = Instructions::Handle(caller_code.instructions()); |
1367 current_target_code.EntryPoint()); | 1372 { |
1368 caller_code.SetStaticCallTargetCodeAt(frame->pc(), current_target_code); | 1373 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
| 1374 CodePatcher::PatchStaticCallAt(frame->pc(), caller_code, |
| 1375 current_target_code.EntryPoint()); |
| 1376 caller_code.SetStaticCallTargetCodeAt(frame->pc(), current_target_code); |
| 1377 } |
1369 if (FLAG_trace_patching) { | 1378 if (FLAG_trace_patching) { |
1370 OS::PrintErr("FixCallersTarget: patching from %#" Px " to '%s' %#" Px "\n", | 1379 OS::PrintErr("FixCallersTarget: patching from %#" Px " to '%s' %#" Px "\n", |
1371 frame->pc(), | 1380 frame->pc(), |
1372 target_function.ToFullyQualifiedCString(), | 1381 target_function.ToFullyQualifiedCString(), |
1373 current_target_code.EntryPoint()); | 1382 current_target_code.EntryPoint()); |
1374 } | 1383 } |
1375 arguments.SetReturn(current_target_code); | 1384 arguments.SetReturn(current_target_code); |
1376 } | 1385 } |
1377 | 1386 |
1378 | 1387 |
(...skipping 19 matching lines...) Expand all Loading... |
1398 const Code& unoptimized_code = Code::Handle(function.unoptimized_code()); | 1407 const Code& unoptimized_code = Code::Handle(function.unoptimized_code()); |
1399 ASSERT(!unoptimized_code.IsNull()); | 1408 ASSERT(!unoptimized_code.IsNull()); |
1400 // The switch to unoptimized code may have already occurred. | 1409 // The switch to unoptimized code may have already occurred. |
1401 if (function.HasOptimizedCode()) { | 1410 if (function.HasOptimizedCode()) { |
1402 function.SwitchToUnoptimizedCode(); | 1411 function.SwitchToUnoptimizedCode(); |
1403 } | 1412 } |
1404 // Patch call site (lazy deoptimization is quite rare, patching it twice | 1413 // Patch call site (lazy deoptimization is quite rare, patching it twice |
1405 // is not a performance issue). | 1414 // is not a performance issue). |
1406 uword lazy_deopt_jump = optimized_code.GetLazyDeoptPc(); | 1415 uword lazy_deopt_jump = optimized_code.GetLazyDeoptPc(); |
1407 ASSERT(lazy_deopt_jump != 0); | 1416 ASSERT(lazy_deopt_jump != 0); |
1408 CodePatcher::InsertCallAt(pc, lazy_deopt_jump); | 1417 const Instructions& instrs = |
| 1418 Instructions::Handle(optimized_code.instructions()); |
| 1419 { |
| 1420 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
| 1421 CodePatcher::InsertCallAt(pc, lazy_deopt_jump); |
| 1422 } |
1409 if (FLAG_trace_patching) { | 1423 if (FLAG_trace_patching) { |
1410 const String& name = String::Handle(function.name()); | 1424 const String& name = String::Handle(function.name()); |
1411 OS::PrintErr("InsertCallAt: %" Px " to %" Px " for %s\n", pc, | 1425 OS::PrintErr("InsertCallAt: %" Px " to %" Px " for %s\n", pc, |
1412 lazy_deopt_jump, name.ToCString()); | 1426 lazy_deopt_jump, name.ToCString()); |
1413 } | 1427 } |
1414 // Mark code as dead (do not GC its embedded objects). | 1428 // Mark code as dead (do not GC its embedded objects). |
1415 optimized_code.set_is_alive(false); | 1429 optimized_code.set_is_alive(false); |
1416 } | 1430 } |
1417 | 1431 |
1418 | 1432 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1599 // of the given value. | 1613 // of the given value. |
1600 // Arg0: Field object; | 1614 // Arg0: Field object; |
1601 // Arg1: Value that is being stored. | 1615 // Arg1: Value that is being stored. |
1602 DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) { | 1616 DEFINE_RUNTIME_ENTRY(UpdateFieldCid, 2) { |
1603 const Field& field = Field::CheckedHandle(arguments.ArgAt(0)); | 1617 const Field& field = Field::CheckedHandle(arguments.ArgAt(0)); |
1604 const Object& value = Object::Handle(arguments.ArgAt(1)); | 1618 const Object& value = Object::Handle(arguments.ArgAt(1)); |
1605 field.UpdateGuardedCidAndLength(value); | 1619 field.UpdateGuardedCidAndLength(value); |
1606 } | 1620 } |
1607 | 1621 |
1608 } // namespace dart | 1622 } // namespace dart |
OLD | NEW |