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 1431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1442 if (ContainsCid(classes, owner_cid)) { | 1442 if (ContainsCid(classes, owner_cid)) { |
1443 DeoptimizeAt(optimized_code, frame->pc()); | 1443 DeoptimizeAt(optimized_code, frame->pc()); |
1444 } | 1444 } |
1445 } | 1445 } |
1446 } | 1446 } |
1447 } | 1447 } |
1448 | 1448 |
1449 | 1449 |
1450 // Copy saved registers into the isolate buffer. | 1450 // Copy saved registers into the isolate buffer. |
1451 static void CopySavedRegisters(uword saved_registers_address) { | 1451 static void CopySavedRegisters(uword saved_registers_address) { |
1452 double* fpu_registers_copy = new double[kNumberOfFpuRegisters]; | 1452 fpu_register_t* fpu_registers_copy = |
| 1453 new fpu_register_t[kNumberOfFpuRegisters]; |
1453 ASSERT(fpu_registers_copy != NULL); | 1454 ASSERT(fpu_registers_copy != NULL); |
1454 for (intptr_t i = 0; i < kNumberOfFpuRegisters; i++) { | 1455 for (intptr_t i = 0; i < kNumberOfFpuRegisters; i++) { |
1455 fpu_registers_copy[i] = *reinterpret_cast<double*>(saved_registers_address); | 1456 fpu_registers_copy[i] = |
1456 saved_registers_address += kDoubleSize; | 1457 *reinterpret_cast<fpu_register_t*>(saved_registers_address); |
| 1458 saved_registers_address += kFpuRegisterSize; |
1457 } | 1459 } |
1458 Isolate::Current()->set_deopt_fpu_registers_copy(fpu_registers_copy); | 1460 Isolate::Current()->set_deopt_fpu_registers_copy(fpu_registers_copy); |
1459 | 1461 |
1460 intptr_t* cpu_registers_copy = new intptr_t[kNumberOfCpuRegisters]; | 1462 intptr_t* cpu_registers_copy = new intptr_t[kNumberOfCpuRegisters]; |
1461 ASSERT(cpu_registers_copy != NULL); | 1463 ASSERT(cpu_registers_copy != NULL); |
1462 for (intptr_t i = 0; i < kNumberOfCpuRegisters; i++) { | 1464 for (intptr_t i = 0; i < kNumberOfCpuRegisters; i++) { |
1463 cpu_registers_copy[i] = | 1465 cpu_registers_copy[i] = |
1464 *reinterpret_cast<intptr_t*>(saved_registers_address); | 1466 *reinterpret_cast<intptr_t*>(saved_registers_address); |
1465 saved_registers_address += kWordSize; | 1467 saved_registers_address += kWordSize; |
1466 } | 1468 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1498 // Copies saved registers and caller's frame into temporary buffers. | 1500 // Copies saved registers and caller's frame into temporary buffers. |
1499 // Returns the stack size of unoptimized frame. | 1501 // Returns the stack size of unoptimized frame. |
1500 DEFINE_LEAF_RUNTIME_ENTRY(intptr_t, DeoptimizeCopyFrame, | 1502 DEFINE_LEAF_RUNTIME_ENTRY(intptr_t, DeoptimizeCopyFrame, |
1501 uword saved_registers_address) { | 1503 uword saved_registers_address) { |
1502 Isolate* isolate = Isolate::Current(); | 1504 Isolate* isolate = Isolate::Current(); |
1503 StackZone zone(isolate); | 1505 StackZone zone(isolate); |
1504 HANDLESCOPE(isolate); | 1506 HANDLESCOPE(isolate); |
1505 | 1507 |
1506 // All registers have been saved below last-fp. | 1508 // All registers have been saved below last-fp. |
1507 const uword last_fp = saved_registers_address + | 1509 const uword last_fp = saved_registers_address + |
1508 kNumberOfCpuRegisters * kWordSize + kNumberOfFpuRegisters * kDoubleSize; | 1510 kNumberOfCpuRegisters * kWordSize + |
| 1511 kNumberOfFpuRegisters * kFpuRegisterSize; |
1509 CopySavedRegisters(saved_registers_address); | 1512 CopySavedRegisters(saved_registers_address); |
1510 | 1513 |
1511 // Get optimized code and frame that need to be deoptimized. | 1514 // Get optimized code and frame that need to be deoptimized. |
1512 DartFrameIterator iterator(last_fp); | 1515 DartFrameIterator iterator(last_fp); |
1513 StackFrame* caller_frame = iterator.NextFrame(); | 1516 StackFrame* caller_frame = iterator.NextFrame(); |
1514 ASSERT(caller_frame != NULL); | 1517 ASSERT(caller_frame != NULL); |
1515 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode()); | 1518 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode()); |
1516 ASSERT(optimized_code.is_optimized()); | 1519 ASSERT(optimized_code.is_optimized()); |
1517 | 1520 |
1518 | 1521 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1600 ASSERT(caller_frame != NULL); | 1603 ASSERT(caller_frame != NULL); |
1601 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode()); | 1604 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode()); |
1602 const Function& function = Function::Handle(optimized_code.function()); | 1605 const Function& function = Function::Handle(optimized_code.function()); |
1603 ASSERT(!function.IsNull()); | 1606 ASSERT(!function.IsNull()); |
1604 const Code& unoptimized_code = Code::Handle(function.unoptimized_code()); | 1607 const Code& unoptimized_code = Code::Handle(function.unoptimized_code()); |
1605 ASSERT(!optimized_code.IsNull() && optimized_code.is_optimized()); | 1608 ASSERT(!optimized_code.IsNull() && optimized_code.is_optimized()); |
1606 ASSERT(!unoptimized_code.IsNull() && !unoptimized_code.is_optimized()); | 1609 ASSERT(!unoptimized_code.IsNull() && !unoptimized_code.is_optimized()); |
1607 | 1610 |
1608 intptr_t* frame_copy = isolate->deopt_frame_copy(); | 1611 intptr_t* frame_copy = isolate->deopt_frame_copy(); |
1609 intptr_t* cpu_registers_copy = isolate->deopt_cpu_registers_copy(); | 1612 intptr_t* cpu_registers_copy = isolate->deopt_cpu_registers_copy(); |
1610 double* fpu_registers_copy = isolate->deopt_fpu_registers_copy(); | 1613 fpu_register_t* fpu_registers_copy = isolate->deopt_fpu_registers_copy(); |
1611 | 1614 |
1612 intptr_t deopt_reason = kDeoptUnknown; | 1615 intptr_t deopt_reason = kDeoptUnknown; |
1613 const DeoptInfo& deopt_info = DeoptInfo::Handle( | 1616 const DeoptInfo& deopt_info = DeoptInfo::Handle( |
1614 optimized_code.GetDeoptInfoAtPc(caller_frame->pc(), &deopt_reason)); | 1617 optimized_code.GetDeoptInfoAtPc(caller_frame->pc(), &deopt_reason)); |
1615 ASSERT(!deopt_info.IsNull()); | 1618 ASSERT(!deopt_info.IsNull()); |
1616 | 1619 |
1617 const intptr_t caller_fp = DeoptimizeWithDeoptInfo(optimized_code, | 1620 const intptr_t caller_fp = DeoptimizeWithDeoptInfo(optimized_code, |
1618 deopt_info, | 1621 deopt_info, |
1619 *caller_frame, | 1622 *caller_frame, |
1620 deopt_reason); | 1623 deopt_reason); |
1621 | 1624 |
1622 isolate->SetDeoptFrameCopy(NULL, 0); | 1625 isolate->SetDeoptFrameCopy(NULL, 0); |
1623 isolate->set_deopt_cpu_registers_copy(NULL); | 1626 isolate->set_deopt_cpu_registers_copy(NULL); |
1624 isolate->set_deopt_fpu_registers_copy(NULL); | 1627 isolate->set_deopt_fpu_registers_copy(NULL); |
1625 delete[] frame_copy; | 1628 delete[] frame_copy; |
1626 delete[] cpu_registers_copy; | 1629 delete[] cpu_registers_copy; |
1627 delete[] fpu_registers_copy; | 1630 delete[] fpu_registers_copy; |
1628 | 1631 |
1629 return caller_fp; | 1632 return caller_fp; |
1630 } | 1633 } |
1631 END_LEAF_RUNTIME_ENTRY | 1634 END_LEAF_RUNTIME_ENTRY |
1632 | 1635 |
1633 | 1636 |
1634 // This is the last step in the deoptimization, GC can occur. | 1637 // This is the last step in the deoptimization, GC can occur. |
1635 DEFINE_RUNTIME_ENTRY(DeoptimizeMaterializeDoubles, 0) { | 1638 DEFINE_RUNTIME_ENTRY(DeoptimizeMaterializeDoubles, 0) { |
1636 DeferredDouble* deferred_double = Isolate::Current()->DetachDeferredDoubles(); | 1639 DeferredObject* deferred_object = Isolate::Current()->DetachDeferredObjects(); |
1637 | 1640 |
1638 while (deferred_double != NULL) { | 1641 while (deferred_object != NULL) { |
1639 DeferredDouble* current = deferred_double; | 1642 DeferredObject* current = deferred_object; |
1640 deferred_double = deferred_double->next(); | 1643 deferred_object = deferred_object->next(); |
1641 | 1644 |
1642 RawDouble** slot = current->slot(); | 1645 current->materialize(); |
1643 *slot = Double::New(current->value()); | |
1644 | |
1645 if (FLAG_trace_deoptimization_verbose) { | |
1646 OS::PrintErr("materializing double at %"Px": %g\n", | |
1647 reinterpret_cast<uword>(current->slot()), | |
1648 current->value()); | |
1649 } | |
1650 | 1646 |
1651 delete current; | 1647 delete current; |
1652 } | 1648 } |
1653 | 1649 |
1654 DeferredMint* deferred_mint = Isolate::Current()->DetachDeferredMints(); | |
1655 | |
1656 while (deferred_mint != NULL) { | |
1657 DeferredMint* current = deferred_mint; | |
1658 deferred_mint = deferred_mint->next(); | |
1659 | |
1660 RawMint** slot = current->slot(); | |
1661 ASSERT(!Smi::IsValid64(current->value())); | |
1662 *slot = Mint::New(current->value()); | |
1663 | |
1664 if (FLAG_trace_deoptimization_verbose) { | |
1665 OS::PrintErr("materializing mint at %"Px": %"Pd64"\n", | |
1666 reinterpret_cast<uword>(current->slot()), | |
1667 current->value()); | |
1668 } | |
1669 | |
1670 delete current; | |
1671 } | |
1672 // Since this is the only step where GC can occur during deoptimization, | 1650 // Since this is the only step where GC can occur during deoptimization, |
1673 // use it to report the source line where deoptimization occured. | 1651 // use it to report the source line where deoptimization occured. |
1674 if (FLAG_trace_deoptimization) { | 1652 if (FLAG_trace_deoptimization) { |
1675 DartFrameIterator iterator; | 1653 DartFrameIterator iterator; |
1676 StackFrame* top_frame = iterator.NextFrame(); | 1654 StackFrame* top_frame = iterator.NextFrame(); |
1677 ASSERT(top_frame != NULL); | 1655 ASSERT(top_frame != NULL); |
1678 const Code& code = Code::Handle(top_frame->LookupDartCode()); | 1656 const Code& code = Code::Handle(top_frame->LookupDartCode()); |
1679 const Function& top_function = Function::Handle(code.function()); | 1657 const Function& top_function = Function::Handle(code.function()); |
1680 const Script& script = Script::Handle(top_function.script()); | 1658 const Script& script = Script::Handle(top_function.script()); |
1681 const intptr_t token_pos = code.GetTokenIndexOfPC(top_frame->pc()); | 1659 const intptr_t token_pos = code.GetTokenIndexOfPC(top_frame->pc()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1727 if (right < 0) { | 1705 if (right < 0) { |
1728 remainder -= right; | 1706 remainder -= right; |
1729 } else { | 1707 } else { |
1730 remainder += right; | 1708 remainder += right; |
1731 } | 1709 } |
1732 } | 1710 } |
1733 return remainder; | 1711 return remainder; |
1734 } | 1712 } |
1735 | 1713 |
1736 } // namespace dart | 1714 } // namespace dart |
OLD | NEW |