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

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(const Code& optimized_code,
1525 static void CopyFrame(const Code& optimized_code, const StackFrame& frame) { 1526 const StackFrame& frame,
1527 intptr_t** frame_start,
1528 intptr_t* frame_size) {
1526 const Function& function = Function::Handle(optimized_code.function()); 1529 const Function& function = Function::Handle(optimized_code.function());
1527 // Do not copy incoming arguments if there are optional arguments (they 1530 // Do not copy incoming arguments if there are optional arguments (they
1528 // are copied into local space at method entry). 1531 // are copied into local space at method entry).
1529 const intptr_t num_args = 1532 const intptr_t num_args =
1530 function.HasOptionalParameters() ? 0 : function.num_fixed_parameters(); 1533 function.HasOptionalParameters() ? 0 : function.num_fixed_parameters();
1531 // The fixed size section of the (fake) Dart frame called via a stub by the 1534 // 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 1535 // 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 1536 // return-address. This section is copied as well, so that its contained
1534 // values can be updated before returning to the deoptimized function. 1537 // values can be updated before returning to the deoptimized function.
1535 const intptr_t frame_copy_size = 1538 const intptr_t frame_copy_size =
1536 + kDartFrameFixedSize // For saved values below sp. 1539 + kDartFrameFixedSize // For saved values below sp.
1537 + ((frame.fp() - frame.sp()) / kWordSize) // For frame size incl. sp. 1540 + ((frame.fp() - frame.sp()) / kWordSize) // For frame size incl. sp.
1538 + 1 // For fp. 1541 + 1 // For fp.
1539 + kParamEndSlotFromFp // For saved values above fp. 1542 + kParamEndSlotFromFp // For saved values above fp.
1540 + num_args; // For arguments. 1543 + num_args; // For arguments.
1541 intptr_t* frame_copy = new intptr_t[frame_copy_size]; 1544 intptr_t* frame_copy = new intptr_t[frame_copy_size];
1542 ASSERT(frame_copy != NULL); 1545 ASSERT(frame_copy != NULL);
1543 intptr_t* start = reinterpret_cast<intptr_t*>( 1546 intptr_t* start = reinterpret_cast<intptr_t*>(
1544 frame.sp() - (kDartFrameFixedSize * kWordSize)); 1547 frame.sp() - (kDartFrameFixedSize * kWordSize));
1545 for (intptr_t i = 0; i < frame_copy_size; i++) { 1548 for (intptr_t i = 0; i < frame_copy_size; i++) {
1546 frame_copy[i] = *(start + i); 1549 frame_copy[i] = *(start + i);
1547 } 1550 }
1548 Isolate::Current()->SetDeoptFrameCopy(frame_copy, frame_copy_size); 1551 *frame_start = frame_copy;
1552 *frame_size = frame_copy_size;
1549 } 1553 }
1550 1554
1551 1555
1552 // Copies saved registers and caller's frame into temporary buffers. 1556 // Copies saved registers and caller's frame into temporary buffers.
1553 // Returns the stack size of unoptimized frame. 1557 // Returns the stack size of unoptimized frame.
1554 DEFINE_LEAF_RUNTIME_ENTRY(intptr_t, DeoptimizeCopyFrame, 1558 DEFINE_LEAF_RUNTIME_ENTRY(intptr_t, DeoptimizeCopyFrame,
1555 1, uword saved_registers_address) { 1559 1, uword saved_registers_address) {
1556 Isolate* isolate = Isolate::Current(); 1560 Isolate* isolate = Isolate::Current();
1557 StackZone zone(isolate); 1561 StackZone zone(isolate);
1558 HANDLESCOPE(isolate); 1562 HANDLESCOPE(isolate);
1559 1563
1560 // All registers have been saved below last-fp as if they were locals. 1564 // All registers have been saved below last-fp as if they were locals.
1561 const uword last_fp = saved_registers_address 1565 const uword last_fp = saved_registers_address
1562 + (kNumberOfCpuRegisters * kWordSize) 1566 + (kNumberOfCpuRegisters * kWordSize)
1563 + (kNumberOfFpuRegisters * kFpuRegisterSize) 1567 + (kNumberOfFpuRegisters * kFpuRegisterSize)
1564 - ((kFirstLocalSlotFromFp + 1) * kWordSize); 1568 - ((kFirstLocalSlotFromFp + 1) * kWordSize);
1565 CopySavedRegisters(saved_registers_address);
1566 1569
1567 // Get optimized code and frame that need to be deoptimized. 1570 // Get optimized code and frame that need to be deoptimized.
1568 DartFrameIterator iterator(last_fp); 1571 DartFrameIterator iterator(last_fp);
1569 StackFrame* caller_frame = iterator.NextFrame(); 1572 StackFrame* caller_frame = iterator.NextFrame();
1570 ASSERT(caller_frame != NULL); 1573 ASSERT(caller_frame != NULL);
1571 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode()); 1574 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode());
1572 ASSERT(optimized_code.is_optimized()); 1575 ASSERT(optimized_code.is_optimized());
1573 1576
1574 intptr_t deopt_reason = kDeoptUnknown; 1577 intptr_t deopt_reason = kDeoptUnknown;
1575 const DeoptInfo& deopt_info = DeoptInfo::Handle( 1578 const DeoptInfo& deopt_info = DeoptInfo::Handle(
1576 optimized_code.GetDeoptInfoAtPc(caller_frame->pc(), &deopt_reason)); 1579 optimized_code.GetDeoptInfoAtPc(caller_frame->pc(), &deopt_reason));
1577 ASSERT(!deopt_info.IsNull()); 1580 ASSERT(!deopt_info.IsNull());
1578 1581
1579 CopyFrame(optimized_code, *caller_frame); 1582 // Create the DeoptContext for this deoptimization. Store in isolate.
1583 const Function& function = Function::Handle(optimized_code.function());
1584 const intptr_t num_args =
1585 function.HasOptionalParameters() ? 0 : function.num_fixed_parameters();
1586 DeoptContext* deopt_context = new DeoptContext(
1587 Array::Handle(optimized_code.object_table()),
1588 num_args,
1589 static_cast<DeoptReasonId>(deopt_reason));
1590 isolate->set_deopt_context(deopt_context);
1591
1592 // Copy the saved registers and the source frame.
1593 fpu_register_t* fpu_registers;
1594 intptr_t* cpu_registers;
1595 intptr_t* frame_start;
1596 intptr_t frame_size;
1597 CopySavedRegisters(saved_registers_address, &fpu_registers, &cpu_registers);
1598 CopyFrame(optimized_code, *caller_frame, &frame_start, &frame_size);
1599 deopt_context->SetSourceArgs(frame_start, frame_size,
1600 fpu_registers, cpu_registers,
1601 true); // true = source frame is a copy.
1602
1580 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) { 1603 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) {
1581 Function& function = Function::Handle(optimized_code.function());
1582 OS::PrintErr( 1604 OS::PrintErr(
1583 "Deoptimizing (reason %" Pd " '%s') at pc %#" Px " '%s' (count %d)\n", 1605 "Deoptimizing (reason %" Pd " '%s') at pc %#" Px " '%s' (count %d)\n",
1584 deopt_reason, 1606 deopt_reason,
1585 DeoptReasonToText(deopt_reason), 1607 DeoptReasonToText(deopt_reason),
1586 caller_frame->pc(), 1608 caller_frame->pc(),
1587 function.ToFullyQualifiedCString(), 1609 function.ToFullyQualifiedCString(),
1588 function.deoptimization_counter()); 1610 function.deoptimization_counter());
1589 } 1611 }
1590 1612
1591 // Compute the stack size of the unoptimized frame. For functions with 1613 // Compute the stack size of the unoptimized frame. For functions with
1592 // optional arguments the deoptimization info does not describe the 1614 // optional arguments the deoptimization info does not describe the
1593 // incoming arguments. 1615 // 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 = 1616 const intptr_t unoptimized_stack_size =
1598 + deopt_info.FrameSize() 1617 + deopt_info.FrameSize()
1599 - kDartFrameFixedSize 1618 - kDartFrameFixedSize
1600 - num_args 1619 - num_args
1601 - kParamEndSlotFromFp 1620 - kParamEndSlotFromFp
1602 - 1; // For fp. 1621 - 1; // For fp.
1603 return unoptimized_stack_size * kWordSize; // Stack size (FP - SP) in bytes. 1622 return unoptimized_stack_size * kWordSize; // Stack size (FP - SP) in bytes.
1604 } 1623 }
1605 END_LEAF_RUNTIME_ENTRY 1624 END_LEAF_RUNTIME_ENTRY
1606 1625
1607 1626
1608 static void DeoptimizeWithDeoptInfo(const Code& code, 1627 static void DeoptimizeWithDeoptInfo(DeoptContext* deopt_context,
1628 const Code& code,
1609 const DeoptInfo& deopt_info, 1629 const DeoptInfo& deopt_info,
1610 const StackFrame& caller_frame, 1630 const StackFrame& caller_frame) {
1611 intptr_t deopt_reason) {
1612 const intptr_t len = deopt_info.TranslationLength(); 1631 const intptr_t len = deopt_info.TranslationLength();
1613 GrowableArray<DeoptInstr*> deopt_instructions(len); 1632 GrowableArray<DeoptInstr*> deopt_instructions(len);
1614 const Array& deopt_table = Array::Handle(code.deopt_info_array()); 1633 const Array& deopt_table = Array::Handle(code.deopt_info_array());
1615 ASSERT(!deopt_table.IsNull()); 1634 ASSERT(!deopt_table.IsNull());
1616 deopt_info.ToInstructions(deopt_table, &deopt_instructions); 1635 deopt_info.ToInstructions(deopt_table, &deopt_instructions);
1617 1636
1618 intptr_t* start = reinterpret_cast<intptr_t*>( 1637 intptr_t* start = reinterpret_cast<intptr_t*>(
1619 caller_frame.sp() - (kDartFrameFixedSize * kWordSize)); 1638 caller_frame.sp() - (kDartFrameFixedSize * kWordSize));
1620 const Function& function = Function::Handle(code.function()); 1639 const Function& function = Function::Handle(code.function());
1621 const intptr_t num_args = 1640 const intptr_t num_args =
1622 function.HasOptionalParameters() ? 0 : function.num_fixed_parameters(); 1641 function.HasOptionalParameters() ? 0 : function.num_fixed_parameters();
1623 const intptr_t to_frame_size = 1642 const intptr_t to_frame_size =
1624 + kDartFrameFixedSize // For saved values below sp. 1643 + kDartFrameFixedSize // For saved values below sp.
1625 + (caller_frame.fp() - caller_frame.sp()) / kWordSize 1644 + (caller_frame.fp() - caller_frame.sp()) / kWordSize
1626 + 1 // For fp. 1645 + 1 // For fp.
1627 + kParamEndSlotFromFp 1646 + kParamEndSlotFromFp
1628 + num_args; 1647 + num_args;
1629 DeoptimizationContext deopt_context(start, 1648
1630 to_frame_size, 1649 deopt_context->SetDestArgs(start, to_frame_size);
1631 Array::Handle(code.object_table()), 1650
1632 num_args,
1633 static_cast<DeoptReasonId>(deopt_reason));
1634 const intptr_t frame_size = deopt_info.FrameSize(); 1651 const intptr_t frame_size = deopt_info.FrameSize();
1635 1652
1636 // All kMaterializeObject instructions are emitted before the instructions 1653 // All kMaterializeObject instructions are emitted before the instructions
1637 // that describe stack frames. Skip them and defer materialization of 1654 // that describe stack frames. Skip them and defer materialization of
1638 // objects until the frame is fully reconstructed and it is safe to perform 1655 // objects until the frame is fully reconstructed and it is safe to perform
1639 // GC. 1656 // GC.
1640 // Arguments (class of the instance to allocate and field-value pairs) are 1657 // 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 1658 // 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 1659 // frame. They will be used during materialization and removed from the stack
1643 // right before control switches to the unoptimized code. 1660 // right before control switches to the unoptimized code.
1644 const intptr_t num_materializations = len - frame_size; 1661 const intptr_t num_materializations = len - frame_size;
1645 Isolate::Current()->PrepareForDeferredMaterialization(num_materializations); 1662 deopt_context->PrepareForDeferredMaterialization(num_materializations);
1646 for (intptr_t from_index = 0, to_index = kDartFrameFixedSize; 1663 for (intptr_t from_index = 0, to_index = kDartFrameFixedSize;
1647 from_index < num_materializations; 1664 from_index < num_materializations;
1648 from_index++) { 1665 from_index++) {
1649 const intptr_t field_count = 1666 const intptr_t field_count =
1650 DeoptInstr::GetFieldCount(deopt_instructions[from_index]); 1667 DeoptInstr::GetFieldCount(deopt_instructions[from_index]);
1651 intptr_t* args = deopt_context.GetToFrameAddressAt(to_index); 1668 intptr_t* args = deopt_context->GetDestFrameAddressAt(to_index);
1652 DeferredObject* obj = new DeferredObject(field_count, args); 1669 DeferredObject* obj = new DeferredObject(field_count, args);
1653 Isolate::Current()->SetDeferredObjectAt(from_index, obj); 1670 deopt_context->SetDeferredObjectAt(from_index, obj);
1654 to_index += obj->ArgumentCount(); 1671 to_index += obj->ArgumentCount();
1655 } 1672 }
1656 1673
1657 // Populate stack frames. 1674 // Populate stack frames.
1658 for (intptr_t to_index = frame_size - 1, from_index = len - 1; 1675 for (intptr_t to_index = frame_size - 1, from_index = len - 1;
1659 to_index >= 0; 1676 to_index >= 0;
1660 to_index--, from_index--) { 1677 to_index--, from_index--) {
1661 intptr_t* to_addr = deopt_context.GetToFrameAddressAt(to_index); 1678 intptr_t* to_addr = deopt_context->GetDestFrameAddressAt(to_index);
1662 deopt_instructions[from_index]->Execute(&deopt_context, to_addr); 1679 deopt_instructions[from_index]->Execute(deopt_context, to_addr);
1663 } 1680 }
1664 1681
1665 if (FLAG_trace_deoptimization_verbose) { 1682 if (FLAG_trace_deoptimization_verbose) {
1666 for (intptr_t i = 0; i < frame_size; i++) { 1683 for (intptr_t i = 0; i < frame_size; i++) {
1667 OS::PrintErr("*%" Pd ". [%" Px "] %#014" Px " [%s]\n", 1684 OS::PrintErr("*%" Pd ". [%" Px "] %#014" Px " [%s]\n",
1668 i, 1685 i,
1669 reinterpret_cast<uword>(&start[i]), 1686 reinterpret_cast<uword>(&start[i]),
1670 start[i], 1687 start[i],
1671 deopt_instructions[i + (len - frame_size)]->ToCString()); 1688 deopt_instructions[i + (len - frame_size)]->ToCString());
1672 } 1689 }
(...skipping 11 matching lines...) Expand all
1684 DartFrameIterator iterator(last_fp); 1701 DartFrameIterator iterator(last_fp);
1685 StackFrame* caller_frame = iterator.NextFrame(); 1702 StackFrame* caller_frame = iterator.NextFrame();
1686 ASSERT(caller_frame != NULL); 1703 ASSERT(caller_frame != NULL);
1687 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode()); 1704 const Code& optimized_code = Code::Handle(caller_frame->LookupDartCode());
1688 const Function& function = Function::Handle(optimized_code.function()); 1705 const Function& function = Function::Handle(optimized_code.function());
1689 ASSERT(!function.IsNull()); 1706 ASSERT(!function.IsNull());
1690 const Code& unoptimized_code = Code::Handle(function.unoptimized_code()); 1707 const Code& unoptimized_code = Code::Handle(function.unoptimized_code());
1691 ASSERT(!optimized_code.IsNull() && optimized_code.is_optimized()); 1708 ASSERT(!optimized_code.IsNull() && optimized_code.is_optimized());
1692 ASSERT(!unoptimized_code.IsNull() && !unoptimized_code.is_optimized()); 1709 ASSERT(!unoptimized_code.IsNull() && !unoptimized_code.is_optimized());
1693 1710
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; 1711 intptr_t deopt_reason = kDeoptUnknown;
1699 const DeoptInfo& deopt_info = DeoptInfo::Handle( 1712 const DeoptInfo& deopt_info = DeoptInfo::Handle(
1700 optimized_code.GetDeoptInfoAtPc(caller_frame->pc(), &deopt_reason)); 1713 optimized_code.GetDeoptInfoAtPc(caller_frame->pc(), &deopt_reason));
1701 ASSERT(!deopt_info.IsNull()); 1714 ASSERT(!deopt_info.IsNull());
1702 1715
1703 DeoptimizeWithDeoptInfo(optimized_code, 1716 DeoptContext* deopt_context = isolate->deopt_context();
1717 DeoptimizeWithDeoptInfo(deopt_context,
1718 optimized_code,
1704 deopt_info, 1719 deopt_info,
1705 *caller_frame, 1720 *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 } 1721 }
1715 END_LEAF_RUNTIME_ENTRY 1722 END_LEAF_RUNTIME_ENTRY
1716 1723
1717 1724
1718 // This is the last step in the deoptimization, GC can occur. 1725 // This is the last step in the deoptimization, GC can occur.
1719 // Returns number of bytes to remove from the expression stack of the 1726 // Returns number of bytes to remove from the expression stack of the
1720 // bottom-most deoptimized frame. Those arguments were artificially injected 1727 // bottom-most deoptimized frame. Those arguments were artificially injected
1721 // under return address to keep them discoverable by GC that can occur during 1728 // under return address to keep them discoverable by GC that can occur during
1722 // materialization phase. 1729 // materialization phase.
1723 DEFINE_RUNTIME_ENTRY(DeoptimizeMaterialize, 0) { 1730 DEFINE_RUNTIME_ENTRY(DeoptimizeMaterialize, 0) {
1724 // First materialize all unboxed "primitive" values (doubles, mints, simd) 1731 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 1732
1733 // Compute total number of artificial arguments used during deoptimization. 1733 intptr_t deopt_arg_count = deopt_context->MaterializeDeferredObjects();
1734 intptr_t deopt_arguments = 0; 1734 isolate->set_deopt_context(NULL);
1735 for (intptr_t i = 0; i < isolate->DeferredObjectsCount(); i++) { 1735 delete deopt_context;
1736 deopt_arguments += isolate->GetDeferredObject(i)->ArgumentCount();
1737 }
1738 Isolate::Current()->DeleteDeferredObjects();
1739 1736
1740 // Return value tells deoptimization stub to remove the given number of bytes 1737 // Return value tells deoptimization stub to remove the given number of bytes
1741 // from the stack. 1738 // from the stack.
1742 arguments.SetReturn(Smi::Handle(Smi::New(deopt_arguments * kWordSize))); 1739 arguments.SetReturn(Smi::Handle(Smi::New(deopt_arg_count * kWordSize)));
1743 1740
1744 // Since this is the only step where GC can occur during deoptimization, 1741 // Since this is the only step where GC can occur during deoptimization,
1745 // use it to report the source line where deoptimization occured. 1742 // use it to report the source line where deoptimization occured.
1746 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) { 1743 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) {
1747 DartFrameIterator iterator; 1744 DartFrameIterator iterator;
1748 StackFrame* top_frame = iterator.NextFrame(); 1745 StackFrame* top_frame = iterator.NextFrame();
1749 ASSERT(top_frame != NULL); 1746 ASSERT(top_frame != NULL);
1750 const Code& code = Code::Handle(top_frame->LookupDartCode()); 1747 const Code& code = Code::Handle(top_frame->LookupDartCode());
1751 const Function& top_function = Function::Handle(code.function()); 1748 const Function& top_function = Function::Handle(code.function());
1752 const Script& script = Script::Handle(top_function.script()); 1749 const Script& script = Script::Handle(top_function.script());
1753 const intptr_t token_pos = code.GetTokenIndexOfPC(top_frame->pc()); 1750 const intptr_t token_pos = code.GetTokenIndexOfPC(top_frame->pc());
1754 intptr_t line, column; 1751 intptr_t line, column;
1755 script.GetTokenLocation(token_pos, &line, &column); 1752 script.GetTokenLocation(token_pos, &line, &column);
1756 String& line_string = String::Handle(script.GetLine(line)); 1753 String& line_string = String::Handle(script.GetLine(line));
1757 OS::PrintErr(" Function: %s\n", top_function.ToFullyQualifiedCString()); 1754 OS::PrintErr(" Function: %s\n", top_function.ToFullyQualifiedCString());
1758 OS::PrintErr(" Line %" Pd ": '%s'\n", line, line_string.ToCString()); 1755 OS::PrintErr(" Line %" Pd ": '%s'\n", line, line_string.ToCString());
1759 OS::PrintErr(" Deopt args: %" Pd "\n", deopt_arguments); 1756 OS::PrintErr(" Deopt args: %" Pd "\n", deopt_arg_count);
1760 } 1757 }
1761 } 1758 }
1762 1759
1763 1760
1764 DEFINE_LEAF_RUNTIME_ENTRY(intptr_t, 1761 DEFINE_LEAF_RUNTIME_ENTRY(intptr_t,
1765 BigintCompare, 1762 BigintCompare,
1766 2, 1763 2,
1767 RawBigint* left, 1764 RawBigint* left,
1768 RawBigint* right) { 1765 RawBigint* right) {
1769 Isolate* isolate = Isolate::Current(); 1766 Isolate* isolate = Isolate::Current();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 field.UpdateCid(cid); 1825 field.UpdateCid(cid);
1829 intptr_t list_length = Field::kNoFixedLength; 1826 intptr_t list_length = Field::kNoFixedLength;
1830 if ((field.guarded_cid() != kDynamicCid) && 1827 if ((field.guarded_cid() != kDynamicCid) &&
1831 field.is_final() && RawObject::IsBuiltinListClassId(cid)) { 1828 field.is_final() && RawObject::IsBuiltinListClassId(cid)) {
1832 list_length = GetListLength(value); 1829 list_length = GetListLength(value);
1833 } 1830 }
1834 field.UpdateLength(list_length); 1831 field.UpdateLength(list_length);
1835 } 1832 }
1836 1833
1837 } // namespace dart 1834 } // 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