Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: runtime/vm/code_generator.cc

Issue 24834002: Refactor some deoptimization code. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/deferred_objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1487 const intptr_t owner_cid = Class::Handle(Function::Handle( 1487 const intptr_t owner_cid = Class::Handle(Function::Handle(
1488 optimized_code.function()).Owner()).id(); 1488 optimized_code.function()).Owner()).id();
1489 if (ContainsCid(classes, owner_cid)) { 1489 if (ContainsCid(classes, owner_cid)) {
1490 DeoptimizeAt(optimized_code, frame->pc()); 1490 DeoptimizeAt(optimized_code, frame->pc());
1491 } 1491 }
1492 } 1492 }
1493 } 1493 }
1494 } 1494 }
1495 1495
1496 1496
1497 // Copy saved registers into the isolate buffer. 1497 static void CopySavedRegisters(uword saved_registers_address,
1498 static void CopySavedRegisters(uword saved_registers_address) { 1498 fpu_register_t** fpu_registers,
1499 intptr_t** cpu_registers) {
1499 ASSERT(sizeof(fpu_register_t) == kFpuRegisterSize); 1500 ASSERT(sizeof(fpu_register_t) == kFpuRegisterSize);
1500 fpu_register_t* fpu_registers_copy = 1501 fpu_register_t* fpu_registers_copy =
1501 new fpu_register_t[kNumberOfFpuRegisters]; 1502 new fpu_register_t[kNumberOfFpuRegisters];
1502 ASSERT(fpu_registers_copy != NULL); 1503 ASSERT(fpu_registers_copy != NULL);
1503 for (intptr_t i = 0; i < kNumberOfFpuRegisters; i++) { 1504 for (intptr_t i = 0; i < kNumberOfFpuRegisters; i++) {
1504 fpu_registers_copy[i] = 1505 fpu_registers_copy[i] =
1505 *reinterpret_cast<fpu_register_t*>(saved_registers_address); 1506 *reinterpret_cast<fpu_register_t*>(saved_registers_address);
1506 saved_registers_address += kFpuRegisterSize; 1507 saved_registers_address += kFpuRegisterSize;
1507 } 1508 }
1508 Isolate::Current()->set_deopt_fpu_registers_copy(fpu_registers_copy); 1509 *fpu_registers = fpu_registers_copy;
1509 1510
1510 ASSERT(sizeof(intptr_t) == kWordSize); 1511 ASSERT(sizeof(intptr_t) == kWordSize);
1511 intptr_t* cpu_registers_copy = new intptr_t[kNumberOfCpuRegisters]; 1512 intptr_t* cpu_registers_copy = new intptr_t[kNumberOfCpuRegisters];
1512 ASSERT(cpu_registers_copy != NULL); 1513 ASSERT(cpu_registers_copy != NULL);
1513 for (intptr_t i = 0; i < kNumberOfCpuRegisters; i++) { 1514 for (intptr_t i = 0; i < kNumberOfCpuRegisters; i++) {
1514 cpu_registers_copy[i] = 1515 cpu_registers_copy[i] =
1515 *reinterpret_cast<intptr_t*>(saved_registers_address); 1516 *reinterpret_cast<intptr_t*>(saved_registers_address);
1516 saved_registers_address += kWordSize; 1517 saved_registers_address += kWordSize;
1517 } 1518 }
1518 Isolate::Current()->set_deopt_cpu_registers_copy(cpu_registers_copy); 1519 *cpu_registers = cpu_registers_copy;
1519 } 1520 }
1520 1521
1521 1522
1522 // Copy optimized frame into the isolate buffer. 1523 // Copy optimized frame. The first incoming argument is stored at the
1523 // The first incoming argument is stored at the last entry in the 1524 // last entry in the copied frame buffer.
1524 // copied frame buffer. 1525 static void CopyFrame(DeoptContext* deopt_context,
1525 static void CopyFrame(const Code& optimized_code, const StackFrame& frame) { 1526 const Code& optimized_code,
1527 const StackFrame& frame,
1528 intptr_t** frame_start,
1529 intptr_t* frame_size) {
1526 const Function& function = Function::Handle(optimized_code.function()); 1530 const Function& function = Function::Handle(optimized_code.function());
1527 // Do not copy incoming arguments if there are optional arguments (they 1531 // Do not copy incoming arguments if there are optional arguments (they
1528 // are copied into local space at method entry). 1532 // are copied into local space at method entry).
1529 const intptr_t num_args = 1533 const intptr_t num_args =
1530 function.HasOptionalParameters() ? 0 : function.num_fixed_parameters(); 1534 function.HasOptionalParameters() ? 0 : function.num_fixed_parameters();
1531 // The fixed size section of the (fake) Dart frame called via a stub by the 1535 // The fixed size section of the (fake) Dart frame called via a stub by the
1532 // optimized function contains FP, PP (ARM and MIPS only), PC-marker and 1536 // optimized function contains FP, PP (ARM and MIPS only), PC-marker and
1533 // return-address. This section is copied as well, so that its contained 1537 // return-address. This section is copied as well, so that its contained
1534 // values can be updated before returning to the deoptimized function. 1538 // values can be updated before returning to the deoptimized function.
1535 const intptr_t frame_copy_size = 1539 const intptr_t frame_copy_size =
1536 + kDartFrameFixedSize // For saved values below sp. 1540 + kDartFrameFixedSize // For saved values below sp.
1537 + ((frame.fp() - frame.sp()) / kWordSize) // For frame size incl. sp. 1541 + ((frame.fp() - frame.sp()) / kWordSize) // For frame size incl. sp.
1538 + 1 // For fp. 1542 + 1 // For fp.
1539 + kParamEndSlotFromFp // For saved values above fp. 1543 + kParamEndSlotFromFp // For saved values above fp.
1540 + num_args; // For arguments. 1544 + num_args; // For arguments.
1541 intptr_t* frame_copy = new intptr_t[frame_copy_size]; 1545 intptr_t* frame_copy = new intptr_t[frame_copy_size];
1542 ASSERT(frame_copy != NULL); 1546 ASSERT(frame_copy != NULL);
1543 intptr_t* start = reinterpret_cast<intptr_t*>( 1547 intptr_t* start = reinterpret_cast<intptr_t*>(
1544 frame.sp() - (kDartFrameFixedSize * kWordSize)); 1548 frame.sp() - (kDartFrameFixedSize * kWordSize));
1545 for (intptr_t i = 0; i < frame_copy_size; i++) { 1549 for (intptr_t i = 0; i < frame_copy_size; i++) {
1546 frame_copy[i] = *(start + i); 1550 frame_copy[i] = *(start + i);
1547 } 1551 }
1548 Isolate::Current()->SetDeoptFrameCopy(frame_copy, frame_copy_size); 1552 *frame_start = frame_copy;
1553 *frame_size = frame_copy_size;
1549 } 1554 }
1550 1555
1551 1556
1552 // Copies saved registers and caller's frame into temporary buffers. 1557 // Copies saved registers and caller's frame into temporary buffers.
1553 // Returns the stack size of unoptimized frame. 1558 // Returns the stack size of unoptimized frame.
1554 DEFINE_LEAF_RUNTIME_ENTRY(intptr_t, DeoptimizeCopyFrame, 1559 DEFINE_LEAF_RUNTIME_ENTRY(intptr_t, DeoptimizeCopyFrame,
1555 1, uword saved_registers_address) { 1560 1, uword saved_registers_address) {
1556 Isolate* isolate = Isolate::Current(); 1561 Isolate* isolate = Isolate::Current();
1557 StackZone zone(isolate); 1562 StackZone zone(isolate);
1558 HANDLESCOPE(isolate); 1563 HANDLESCOPE(isolate);
1559 1564
1560 // All registers have been saved below last-fp as if they were locals. 1565 // All registers have been saved below last-fp as if they were locals.
1561 const uword last_fp = saved_registers_address 1566 const uword last_fp = saved_registers_address
1562 + (kNumberOfCpuRegisters * kWordSize) 1567 + (kNumberOfCpuRegisters * kWordSize)
1563 + (kNumberOfFpuRegisters * kFpuRegisterSize) 1568 + (kNumberOfFpuRegisters * kFpuRegisterSize)
1564 - ((kFirstLocalSlotFromFp + 1) * kWordSize); 1569 - ((kFirstLocalSlotFromFp + 1) * kWordSize);
1565 CopySavedRegisters(saved_registers_address); 1570 fpu_register_t* fpu_registers;
1571 intptr_t* cpu_registers;
1572 CopySavedRegisters(saved_registers_address, &fpu_registers, &cpu_registers);
1566 1573
1567 // Get optimized code and frame that need to be deoptimized. 1574 // Get optimized code and frame that need to be deoptimized.
1568 DartFrameIterator iterator(last_fp); 1575 DartFrameIterator iterator(last_fp);
1569 StackFrame* caller_frame = iterator.NextFrame(); 1576 StackFrame* caller_frame = iterator.NextFrame();
1570 ASSERT(caller_frame != NULL); 1577 ASSERT(caller_frame != NULL);
1571 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode()); 1578 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode());
1572 ASSERT(optimized_code.is_optimized()); 1579 ASSERT(optimized_code.is_optimized());
1573 1580
1574 intptr_t deopt_reason = kDeoptUnknown; 1581 intptr_t deopt_reason = kDeoptUnknown;
1575 const DeoptInfo& deopt_info = DeoptInfo::Handle( 1582 const DeoptInfo& deopt_info = DeoptInfo::Handle(
1576 optimized_code.GetDeoptInfoAtPc(caller_frame->pc(), &deopt_reason)); 1583 optimized_code.GetDeoptInfoAtPc(caller_frame->pc(), &deopt_reason));
1577 ASSERT(!deopt_info.IsNull()); 1584 ASSERT(!deopt_info.IsNull());
1578 1585
1579 CopyFrame(optimized_code, *caller_frame); 1586 // Create the DeoptContext for this deoptimization. Store in isolate.
1587 const Function& function = Function::Handle(optimized_code.function());
1588 const intptr_t num_args =
1589 function.HasOptionalParameters() ? 0 : function.num_fixed_parameters();
1590 DeoptContext* deopt_context = new DeoptContext(
1591 Array::Handle(optimized_code.object_table()),
1592 num_args,
1593 static_cast<DeoptReasonId>(deopt_reason));
1594 isolate->set_deopt_context(deopt_context);
1595
1596 // TODO(turnidge): Why can't I move CopySavedRegisters here?
Florian Schneider 2013/10/01 16:44:27 It would be good to resolve this before landing. H
turnidge 2013/10/01 16:53:06 Before I was able to get a SIGBUS by reordering th
1597 intptr_t* frame_start;
1598 intptr_t frame_size;
1599 CopyFrame(deopt_context, optimized_code, *caller_frame,
1600 &frame_start, &frame_size);
1601 deopt_context->SetSourceArgs(frame_start, frame_size,
1602 fpu_registers, cpu_registers,
1603 true); // true = source frame is a copy.
1604
1580 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) { 1605 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) {
1581 Function& function = Function::Handle(optimized_code.function());
1582 OS::PrintErr( 1606 OS::PrintErr(
1583 "Deoptimizing (reason %" Pd " '%s') at pc %#" Px " '%s' (count %d)\n", 1607 "Deoptimizing (reason %" Pd " '%s') at pc %#" Px " '%s' (count %d)\n",
1584 deopt_reason, 1608 deopt_reason,
1585 DeoptReasonToText(deopt_reason), 1609 DeoptReasonToText(deopt_reason),
1586 caller_frame->pc(), 1610 caller_frame->pc(),
1587 function.ToFullyQualifiedCString(), 1611 function.ToFullyQualifiedCString(),
1588 function.deoptimization_counter()); 1612 function.deoptimization_counter());
1589 } 1613 }
1590 1614
1591 // Compute the stack size of the unoptimized frame. For functions with 1615 // Compute the stack size of the unoptimized frame. For functions with
1592 // optional arguments the deoptimization info does not describe the 1616 // optional arguments the deoptimization info does not describe the
1593 // incoming arguments. 1617 // incoming arguments.
1594 const Function& function = Function::Handle(optimized_code.function());
1595 const intptr_t num_args =
1596 function.HasOptionalParameters() ? 0 : function.num_fixed_parameters();
1597 const intptr_t unoptimized_stack_size = 1618 const intptr_t unoptimized_stack_size =
1598 + deopt_info.FrameSize() 1619 + deopt_info.FrameSize()
1599 - kDartFrameFixedSize 1620 - kDartFrameFixedSize
1600 - num_args 1621 - num_args
1601 - kParamEndSlotFromFp 1622 - kParamEndSlotFromFp
1602 - 1; // For fp. 1623 - 1; // For fp.
1603 return unoptimized_stack_size * kWordSize; // Stack size (FP - SP) in bytes. 1624 return unoptimized_stack_size * kWordSize; // Stack size (FP - SP) in bytes.
1604 } 1625 }
1605 END_LEAF_RUNTIME_ENTRY 1626 END_LEAF_RUNTIME_ENTRY
1606 1627
1607 1628
1608 static void DeoptimizeWithDeoptInfo(const Code& code, 1629 static void DeoptimizeWithDeoptInfo(DeoptContext* deopt_context,
1630 const Code& code,
1609 const DeoptInfo& deopt_info, 1631 const DeoptInfo& deopt_info,
1610 const StackFrame& caller_frame, 1632 const StackFrame& caller_frame) {
1611 intptr_t deopt_reason) {
1612 const intptr_t len = deopt_info.TranslationLength(); 1633 const intptr_t len = deopt_info.TranslationLength();
1613 GrowableArray<DeoptInstr*> deopt_instructions(len); 1634 GrowableArray<DeoptInstr*> deopt_instructions(len);
1614 const Array& deopt_table = Array::Handle(code.deopt_info_array()); 1635 const Array& deopt_table = Array::Handle(code.deopt_info_array());
1615 ASSERT(!deopt_table.IsNull()); 1636 ASSERT(!deopt_table.IsNull());
1616 deopt_info.ToInstructions(deopt_table, &deopt_instructions); 1637 deopt_info.ToInstructions(deopt_table, &deopt_instructions);
1617 1638
1618 intptr_t* start = reinterpret_cast<intptr_t*>( 1639 intptr_t* start = reinterpret_cast<intptr_t*>(
1619 caller_frame.sp() - (kDartFrameFixedSize * kWordSize)); 1640 caller_frame.sp() - (kDartFrameFixedSize * kWordSize));
1620 const Function& function = Function::Handle(code.function()); 1641 const Function& function = Function::Handle(code.function());
1621 const intptr_t num_args = 1642 const intptr_t num_args =
1622 function.HasOptionalParameters() ? 0 : function.num_fixed_parameters(); 1643 function.HasOptionalParameters() ? 0 : function.num_fixed_parameters();
1623 const intptr_t to_frame_size = 1644 const intptr_t to_frame_size =
1624 + kDartFrameFixedSize // For saved values below sp. 1645 + kDartFrameFixedSize // For saved values below sp.
1625 + (caller_frame.fp() - caller_frame.sp()) / kWordSize 1646 + (caller_frame.fp() - caller_frame.sp()) / kWordSize
1626 + 1 // For fp. 1647 + 1 // For fp.
1627 + kParamEndSlotFromFp 1648 + kParamEndSlotFromFp
1628 + num_args; 1649 + num_args;
1629 DeoptimizationContext deopt_context(start, 1650
1630 to_frame_size, 1651 deopt_context->SetDestArgs(start, to_frame_size);
1631 Array::Handle(code.object_table()), 1652
1632 num_args,
1633 static_cast<DeoptReasonId>(deopt_reason));
1634 const intptr_t frame_size = deopt_info.FrameSize(); 1653 const intptr_t frame_size = deopt_info.FrameSize();
1635 1654
1636 // All kMaterializeObject instructions are emitted before the instructions 1655 // All kMaterializeObject instructions are emitted before the instructions
1637 // that describe stack frames. Skip them and defer materialization of 1656 // that describe stack frames. Skip them and defer materialization of
1638 // objects until the frame is fully reconstructed and it is safe to perform 1657 // objects until the frame is fully reconstructed and it is safe to perform
1639 // GC. 1658 // GC.
1640 // Arguments (class of the instance to allocate and field-value pairs) are 1659 // Arguments (class of the instance to allocate and field-value pairs) are
1641 // described as part of the expression stack for the bottom-most deoptimized 1660 // described as part of the expression stack for the bottom-most deoptimized
1642 // frame. They will be used during materialization and removed from the stack 1661 // frame. They will be used during materialization and removed from the stack
1643 // right before control switches to the unoptimized code. 1662 // right before control switches to the unoptimized code.
1644 const intptr_t num_materializations = len - frame_size; 1663 const intptr_t num_materializations = len - frame_size;
1645 Isolate::Current()->PrepareForDeferredMaterialization(num_materializations); 1664 deopt_context->PrepareForDeferredMaterialization(num_materializations);
1646 for (intptr_t from_index = 0, to_index = kDartFrameFixedSize; 1665 for (intptr_t from_index = 0, to_index = kDartFrameFixedSize;
1647 from_index < num_materializations; 1666 from_index < num_materializations;
1648 from_index++) { 1667 from_index++) {
1649 const intptr_t field_count = 1668 const intptr_t field_count =
1650 DeoptInstr::GetFieldCount(deopt_instructions[from_index]); 1669 DeoptInstr::GetFieldCount(deopt_instructions[from_index]);
1651 intptr_t* args = deopt_context.GetToFrameAddressAt(to_index); 1670 intptr_t* args = deopt_context->GetDestFrameAddressAt(to_index);
1652 DeferredObject* obj = new DeferredObject(field_count, args); 1671 DeferredObject* obj = new DeferredObject(field_count, args);
1653 Isolate::Current()->SetDeferredObjectAt(from_index, obj); 1672 deopt_context->SetDeferredObjectAt(from_index, obj);
1654 to_index += obj->ArgumentCount(); 1673 to_index += obj->ArgumentCount();
1655 } 1674 }
1656 1675
1657 // Populate stack frames. 1676 // Populate stack frames.
1658 for (intptr_t to_index = frame_size - 1, from_index = len - 1; 1677 for (intptr_t to_index = frame_size - 1, from_index = len - 1;
1659 to_index >= 0; 1678 to_index >= 0;
1660 to_index--, from_index--) { 1679 to_index--, from_index--) {
1661 intptr_t* to_addr = deopt_context.GetToFrameAddressAt(to_index); 1680 intptr_t* to_addr = deopt_context->GetDestFrameAddressAt(to_index);
1662 deopt_instructions[from_index]->Execute(&deopt_context, to_addr); 1681 deopt_instructions[from_index]->Execute(deopt_context, to_addr);
1663 } 1682 }
1664 1683
1665 if (FLAG_trace_deoptimization_verbose) { 1684 if (FLAG_trace_deoptimization_verbose) {
1666 for (intptr_t i = 0; i < frame_size; i++) { 1685 for (intptr_t i = 0; i < frame_size; i++) {
1667 OS::PrintErr("*%" Pd ". [%" Px "] %#014" Px " [%s]\n", 1686 OS::PrintErr("*%" Pd ". [%" Px "] %#014" Px " [%s]\n",
1668 i, 1687 i,
1669 reinterpret_cast<uword>(&start[i]), 1688 reinterpret_cast<uword>(&start[i]),
1670 start[i], 1689 start[i],
1671 deopt_instructions[i + (len - frame_size)]->ToCString()); 1690 deopt_instructions[i + (len - frame_size)]->ToCString());
1672 } 1691 }
(...skipping 11 matching lines...) Expand all
1684 DartFrameIterator iterator(last_fp); 1703 DartFrameIterator iterator(last_fp);
1685 StackFrame* caller_frame = iterator.NextFrame(); 1704 StackFrame* caller_frame = iterator.NextFrame();
1686 ASSERT(caller_frame != NULL); 1705 ASSERT(caller_frame != NULL);
1687 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode()); 1706 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode());
1688 const Function& function = Function::Handle(optimized_code.function()); 1707 const Function& function = Function::Handle(optimized_code.function());
1689 ASSERT(!function.IsNull()); 1708 ASSERT(!function.IsNull());
1690 const Code& unoptimized_code = Code::Handle(function.unoptimized_code()); 1709 const Code& unoptimized_code = Code::Handle(function.unoptimized_code());
1691 ASSERT(!optimized_code.IsNull() && optimized_code.is_optimized()); 1710 ASSERT(!optimized_code.IsNull() && optimized_code.is_optimized());
1692 ASSERT(!unoptimized_code.IsNull() && !unoptimized_code.is_optimized()); 1711 ASSERT(!unoptimized_code.IsNull() && !unoptimized_code.is_optimized());
1693 1712
1694 intptr_t* frame_copy = isolate->deopt_frame_copy();
1695 intptr_t* cpu_registers_copy = isolate->deopt_cpu_registers_copy();
1696 fpu_register_t* fpu_registers_copy = isolate->deopt_fpu_registers_copy();
1697
1698 intptr_t deopt_reason = kDeoptUnknown; 1713 intptr_t deopt_reason = kDeoptUnknown;
1699 const DeoptInfo& deopt_info = DeoptInfo::Handle( 1714 const DeoptInfo& deopt_info = DeoptInfo::Handle(
1700 optimized_code.GetDeoptInfoAtPc(caller_frame->pc(), &deopt_reason)); 1715 optimized_code.GetDeoptInfoAtPc(caller_frame->pc(), &deopt_reason));
1701 ASSERT(!deopt_info.IsNull()); 1716 ASSERT(!deopt_info.IsNull());
1702 1717
1703 DeoptimizeWithDeoptInfo(optimized_code, 1718 DeoptContext* deopt_context = isolate->deopt_context();
1719 DeoptimizeWithDeoptInfo(deopt_context,
1720 optimized_code,
1704 deopt_info, 1721 deopt_info,
1705 *caller_frame, 1722 *caller_frame);
1706 deopt_reason);
1707
1708 isolate->SetDeoptFrameCopy(NULL, 0);
1709 isolate->set_deopt_cpu_registers_copy(NULL);
1710 isolate->set_deopt_fpu_registers_copy(NULL);
1711 delete[] frame_copy;
1712 delete[] cpu_registers_copy;
1713 delete[] fpu_registers_copy;
1714 } 1723 }
1715 END_LEAF_RUNTIME_ENTRY 1724 END_LEAF_RUNTIME_ENTRY
1716 1725
1717 1726
1718 // This is the last step in the deoptimization, GC can occur. 1727 // This is the last step in the deoptimization, GC can occur.
1719 // Returns number of bytes to remove from the expression stack of the 1728 // Returns number of bytes to remove from the expression stack of the
1720 // bottom-most deoptimized frame. Those arguments were artificially injected 1729 // bottom-most deoptimized frame. Those arguments were artificially injected
1721 // under return address to keep them discoverable by GC that can occur during 1730 // under return address to keep them discoverable by GC that can occur during
1722 // materialization phase. 1731 // materialization phase.
1723 DEFINE_RUNTIME_ENTRY(DeoptimizeMaterialize, 0) { 1732 DEFINE_RUNTIME_ENTRY(DeoptimizeMaterialize, 0) {
1724 // First materialize all unboxed "primitive" values (doubles, mints, simd) 1733 DeoptContext* deopt_context = isolate->deopt_context();
1725 // then materialize objects. The order is important: objects might be
1726 // referencing boxes allocated on the first step. At the same time
1727 // objects can't be referencing other deferred objects because storing
1728 // an object into a field is always conservatively treated as escaping by
1729 // allocation sinking and load forwarding.
1730 isolate->MaterializeDeferredBoxes();
1731 isolate->MaterializeDeferredObjects();
1732 1734
1733 // Compute total number of artificial arguments used during deoptimization. 1735 intptr_t deopt_arg_count = deopt_context->MaterializeDeferredObjects();
1734 intptr_t deopt_arguments = 0; 1736 isolate->set_deopt_context(NULL);
1735 for (intptr_t i = 0; i < isolate->DeferredObjectsCount(); i++) { 1737 delete deopt_context;
1736 deopt_arguments += isolate->GetDeferredObject(i)->ArgumentCount();
1737 }
1738 Isolate::Current()->DeleteDeferredObjects();
1739 1738
1740 // Return value tells deoptimization stub to remove the given number of bytes 1739 // Return value tells deoptimization stub to remove the given number of bytes
1741 // from the stack. 1740 // from the stack.
1742 arguments.SetReturn(Smi::Handle(Smi::New(deopt_arguments * kWordSize))); 1741 arguments.SetReturn(Smi::Handle(Smi::New(deopt_arg_count * kWordSize)));
1743 1742
1744 // Since this is the only step where GC can occur during deoptimization, 1743 // Since this is the only step where GC can occur during deoptimization,
1745 // use it to report the source line where deoptimization occured. 1744 // use it to report the source line where deoptimization occured.
1746 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) { 1745 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) {
1747 DartFrameIterator iterator; 1746 DartFrameIterator iterator;
1748 StackFrame* top_frame = iterator.NextFrame(); 1747 StackFrame* top_frame = iterator.NextFrame();
1749 ASSERT(top_frame != NULL); 1748 ASSERT(top_frame != NULL);
1750 const Code& code = Code::Handle(top_frame->LookupDartCode()); 1749 const Code& code = Code::Handle(top_frame->LookupDartCode());
1751 const Function& top_function = Function::Handle(code.function()); 1750 const Function& top_function = Function::Handle(code.function());
1752 const Script& script = Script::Handle(top_function.script()); 1751 const Script& script = Script::Handle(top_function.script());
1753 const intptr_t token_pos = code.GetTokenIndexOfPC(top_frame->pc()); 1752 const intptr_t token_pos = code.GetTokenIndexOfPC(top_frame->pc());
1754 intptr_t line, column; 1753 intptr_t line, column;
1755 script.GetTokenLocation(token_pos, &line, &column); 1754 script.GetTokenLocation(token_pos, &line, &column);
1756 String& line_string = String::Handle(script.GetLine(line)); 1755 String& line_string = String::Handle(script.GetLine(line));
1757 OS::PrintErr(" Function: %s\n", top_function.ToFullyQualifiedCString()); 1756 OS::PrintErr(" Function: %s\n", top_function.ToFullyQualifiedCString());
1758 OS::PrintErr(" Line %" Pd ": '%s'\n", line, line_string.ToCString()); 1757 OS::PrintErr(" Line %" Pd ": '%s'\n", line, line_string.ToCString());
1759 OS::PrintErr(" Deopt args: %" Pd "\n", deopt_arguments); 1758 OS::PrintErr(" Deopt args: %" Pd "\n", deopt_arg_count);
1760 } 1759 }
1761 } 1760 }
1762 1761
1763 1762
1764 DEFINE_LEAF_RUNTIME_ENTRY(intptr_t, 1763 DEFINE_LEAF_RUNTIME_ENTRY(intptr_t,
1765 BigintCompare, 1764 BigintCompare,
1766 2, 1765 2,
1767 RawBigint* left, 1766 RawBigint* left,
1768 RawBigint* right) { 1767 RawBigint* right) {
1769 Isolate* isolate = Isolate::Current(); 1768 Isolate* isolate = Isolate::Current();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 field.UpdateCid(cid); 1827 field.UpdateCid(cid);
1829 intptr_t list_length = Field::kNoFixedLength; 1828 intptr_t list_length = Field::kNoFixedLength;
1830 if ((field.guarded_cid() != kDynamicCid) && 1829 if ((field.guarded_cid() != kDynamicCid) &&
1831 field.is_final() && RawObject::IsBuiltinListClassId(cid)) { 1830 field.is_final() && RawObject::IsBuiltinListClassId(cid)) {
1832 list_length = GetListLength(value); 1831 list_length = GetListLength(value);
1833 } 1832 }
1834 field.UpdateLength(list_length); 1833 field.UpdateLength(list_length);
1835 } 1834 }
1836 1835
1837 } // namespace dart 1836 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/deferred_objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698