OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1549 index.translate(holder), Representation::Tagged()); | 1549 index.translate(holder), Representation::Tagged()); |
1550 GenerateJumpFunction(object, a1, &miss); | 1550 GenerateJumpFunction(object, a1, &miss); |
1551 | 1551 |
1552 HandlerFrontendFooter(&miss); | 1552 HandlerFrontendFooter(&miss); |
1553 | 1553 |
1554 // Return the generated code. | 1554 // Return the generated code. |
1555 return GetCode(Code::FAST, name); | 1555 return GetCode(Code::FAST, name); |
1556 } | 1556 } |
1557 | 1557 |
1558 | 1558 |
1559 Handle<Code> CallStubCompiler::CompileArrayPushCall( | |
1560 Handle<Object> object, | |
1561 Handle<JSObject> holder, | |
1562 Handle<Cell> cell, | |
1563 Handle<JSFunction> function, | |
1564 Handle<String> name, | |
1565 Code::StubType type) { | |
1566 // If object is not an array or is observed or sealed, bail out to regular | |
1567 // call. | |
1568 if (!object->IsJSArray() || | |
1569 !cell.is_null() || | |
1570 Handle<JSArray>::cast(object)->map()->is_observed() || | |
1571 !Handle<JSArray>::cast(object)->map()->is_extensible()) { | |
1572 return Handle<Code>::null(); | |
1573 } | |
1574 | |
1575 Label miss; | |
1576 HandlerFrontendHeader(object, holder, name, RECEIVER_MAP_CHECK, &miss); | |
1577 Register receiver = a0; | |
1578 Register scratch = a1; | |
1579 | |
1580 const int argc = arguments().immediate(); | |
1581 | |
1582 if (argc == 0) { | |
1583 // Nothing to do, just return the length. | |
1584 __ lw(v0, FieldMemOperand(receiver, JSArray::kLengthOffset)); | |
1585 __ DropAndRet(argc + 1); | |
1586 } else { | |
1587 Label call_builtin; | |
1588 if (argc == 1) { // Otherwise fall through to call the builtin. | |
1589 Label attempt_to_grow_elements, with_write_barrier, check_double; | |
1590 | |
1591 Register elements = t2; | |
1592 Register end_elements = t1; | |
1593 // Get the elements array of the object. | |
1594 __ lw(elements, FieldMemOperand(receiver, JSArray::kElementsOffset)); | |
1595 | |
1596 // Check that the elements are in fast mode and writable. | |
1597 __ CheckMap(elements, | |
1598 scratch, | |
1599 Heap::kFixedArrayMapRootIndex, | |
1600 &check_double, | |
1601 DONT_DO_SMI_CHECK); | |
1602 | |
1603 // Get the array's length into scratch and calculate new length. | |
1604 __ lw(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset)); | |
1605 STATIC_ASSERT(kSmiTagSize == 1); | |
1606 STATIC_ASSERT(kSmiTag == 0); | |
1607 __ Addu(scratch, scratch, Operand(Smi::FromInt(argc))); | |
1608 | |
1609 // Get the elements' length. | |
1610 __ lw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset)); | |
1611 | |
1612 // Check if we could survive without allocation. | |
1613 __ Branch(&attempt_to_grow_elements, gt, scratch, Operand(t0)); | |
1614 | |
1615 // Check if value is a smi. | |
1616 __ lw(t0, MemOperand(sp, (argc - 1) * kPointerSize)); | |
1617 __ JumpIfNotSmi(t0, &with_write_barrier); | |
1618 | |
1619 // Save new length. | |
1620 __ sw(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset)); | |
1621 | |
1622 // Store the value. | |
1623 // We may need a register containing the address end_elements below, | |
1624 // so write back the value in end_elements. | |
1625 __ sll(end_elements, scratch, kPointerSizeLog2 - kSmiTagSize); | |
1626 __ Addu(end_elements, elements, end_elements); | |
1627 const int kEndElementsOffset = | |
1628 FixedArray::kHeaderSize - kHeapObjectTag - argc * kPointerSize; | |
1629 __ Addu(end_elements, end_elements, kEndElementsOffset); | |
1630 __ sw(t0, MemOperand(end_elements)); | |
1631 | |
1632 // Check for a smi. | |
1633 __ mov(v0, scratch); | |
1634 __ DropAndRet(argc + 1); | |
1635 | |
1636 __ bind(&check_double); | |
1637 | |
1638 // Check that the elements are in fast mode and writable. | |
1639 __ CheckMap(elements, | |
1640 scratch, | |
1641 Heap::kFixedDoubleArrayMapRootIndex, | |
1642 &call_builtin, | |
1643 DONT_DO_SMI_CHECK); | |
1644 | |
1645 // Get the array's length into scratch and calculate new length. | |
1646 __ lw(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset)); | |
1647 STATIC_ASSERT(kSmiTagSize == 1); | |
1648 STATIC_ASSERT(kSmiTag == 0); | |
1649 __ Addu(scratch, scratch, Operand(Smi::FromInt(argc))); | |
1650 | |
1651 // Get the elements' length. | |
1652 __ lw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset)); | |
1653 | |
1654 // Check if we could survive without allocation. | |
1655 __ Branch(&call_builtin, gt, scratch, Operand(t0)); | |
1656 | |
1657 __ lw(t0, MemOperand(sp, (argc - 1) * kPointerSize)); | |
1658 __ StoreNumberToDoubleElements( | |
1659 t0, scratch, elements, a3, t1, a2, | |
1660 &call_builtin, argc * kDoubleSize); | |
1661 | |
1662 // Save new length. | |
1663 __ sw(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset)); | |
1664 | |
1665 __ mov(v0, scratch); | |
1666 __ DropAndRet(argc + 1); | |
1667 | |
1668 __ bind(&with_write_barrier); | |
1669 | |
1670 __ lw(a3, FieldMemOperand(receiver, HeapObject::kMapOffset)); | |
1671 | |
1672 if (FLAG_smi_only_arrays && !FLAG_trace_elements_transitions) { | |
1673 Label fast_object, not_fast_object; | |
1674 __ CheckFastObjectElements(a3, t3, ¬_fast_object); | |
1675 __ jmp(&fast_object); | |
1676 // In case of fast smi-only, convert to fast object, otherwise bail out. | |
1677 __ bind(¬_fast_object); | |
1678 __ CheckFastSmiElements(a3, t3, &call_builtin); | |
1679 | |
1680 __ lw(t3, FieldMemOperand(t0, HeapObject::kMapOffset)); | |
1681 __ LoadRoot(at, Heap::kHeapNumberMapRootIndex); | |
1682 __ Branch(&call_builtin, eq, t3, Operand(at)); | |
1683 // edx: receiver | |
1684 // a3: map | |
1685 Label try_holey_map; | |
1686 __ LoadTransitionedArrayMapConditional(FAST_SMI_ELEMENTS, | |
1687 FAST_ELEMENTS, | |
1688 a3, | |
1689 t3, | |
1690 &try_holey_map); | |
1691 __ mov(a2, receiver); | |
1692 ElementsTransitionGenerator:: | |
1693 GenerateMapChangeElementsTransition(masm(), | |
1694 DONT_TRACK_ALLOCATION_SITE, | |
1695 NULL); | |
1696 __ jmp(&fast_object); | |
1697 | |
1698 __ bind(&try_holey_map); | |
1699 __ LoadTransitionedArrayMapConditional(FAST_HOLEY_SMI_ELEMENTS, | |
1700 FAST_HOLEY_ELEMENTS, | |
1701 a3, | |
1702 t3, | |
1703 &call_builtin); | |
1704 __ mov(a2, receiver); | |
1705 ElementsTransitionGenerator:: | |
1706 GenerateMapChangeElementsTransition(masm(), | |
1707 DONT_TRACK_ALLOCATION_SITE, | |
1708 NULL); | |
1709 __ bind(&fast_object); | |
1710 } else { | |
1711 __ CheckFastObjectElements(a3, a3, &call_builtin); | |
1712 } | |
1713 | |
1714 // Save new length. | |
1715 __ sw(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset)); | |
1716 | |
1717 // Store the value. | |
1718 // We may need a register containing the address end_elements below, | |
1719 // so write back the value in end_elements. | |
1720 __ sll(end_elements, scratch, kPointerSizeLog2 - kSmiTagSize); | |
1721 __ Addu(end_elements, elements, end_elements); | |
1722 __ Addu(end_elements, end_elements, kEndElementsOffset); | |
1723 __ sw(t0, MemOperand(end_elements)); | |
1724 | |
1725 __ RecordWrite(elements, | |
1726 end_elements, | |
1727 t0, | |
1728 kRAHasNotBeenSaved, | |
1729 kDontSaveFPRegs, | |
1730 EMIT_REMEMBERED_SET, | |
1731 OMIT_SMI_CHECK); | |
1732 __ mov(v0, scratch); | |
1733 __ DropAndRet(argc + 1); | |
1734 | |
1735 __ bind(&attempt_to_grow_elements); | |
1736 // scratch: array's length + 1. | |
1737 // t0: elements' length. | |
1738 | |
1739 if (!FLAG_inline_new) { | |
1740 __ Branch(&call_builtin); | |
1741 } | |
1742 | |
1743 __ lw(a2, MemOperand(sp, (argc - 1) * kPointerSize)); | |
1744 // Growing elements that are SMI-only requires special handling in case | |
1745 // the new element is non-Smi. For now, delegate to the builtin. | |
1746 Label no_fast_elements_check; | |
1747 __ JumpIfSmi(a2, &no_fast_elements_check); | |
1748 __ lw(t3, FieldMemOperand(receiver, HeapObject::kMapOffset)); | |
1749 __ CheckFastObjectElements(t3, t3, &call_builtin); | |
1750 __ bind(&no_fast_elements_check); | |
1751 | |
1752 ExternalReference new_space_allocation_top = | |
1753 ExternalReference::new_space_allocation_top_address(isolate()); | |
1754 ExternalReference new_space_allocation_limit = | |
1755 ExternalReference::new_space_allocation_limit_address(isolate()); | |
1756 | |
1757 const int kAllocationDelta = 4; | |
1758 // Load top and check if it is the end of elements. | |
1759 __ sll(end_elements, scratch, kPointerSizeLog2 - kSmiTagSize); | |
1760 __ Addu(end_elements, elements, end_elements); | |
1761 __ Addu(end_elements, end_elements, Operand(kEndElementsOffset)); | |
1762 __ li(t3, Operand(new_space_allocation_top)); | |
1763 __ lw(a3, MemOperand(t3)); | |
1764 __ Branch(&call_builtin, ne, end_elements, Operand(a3)); | |
1765 | |
1766 __ li(t5, Operand(new_space_allocation_limit)); | |
1767 __ lw(t5, MemOperand(t5)); | |
1768 __ Addu(a3, a3, Operand(kAllocationDelta * kPointerSize)); | |
1769 __ Branch(&call_builtin, hi, a3, Operand(t5)); | |
1770 | |
1771 // We fit and could grow elements. | |
1772 // Update new_space_allocation_top. | |
1773 __ sw(a3, MemOperand(t3)); | |
1774 // Push the argument. | |
1775 __ sw(a2, MemOperand(end_elements)); | |
1776 // Fill the rest with holes. | |
1777 __ LoadRoot(a3, Heap::kTheHoleValueRootIndex); | |
1778 for (int i = 1; i < kAllocationDelta; i++) { | |
1779 __ sw(a3, MemOperand(end_elements, i * kPointerSize)); | |
1780 } | |
1781 | |
1782 // Update elements' and array's sizes. | |
1783 __ sw(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset)); | |
1784 __ Addu(t0, t0, Operand(Smi::FromInt(kAllocationDelta))); | |
1785 __ sw(t0, FieldMemOperand(elements, FixedArray::kLengthOffset)); | |
1786 | |
1787 // Elements are in new space, so write barrier is not required. | |
1788 __ mov(v0, scratch); | |
1789 __ DropAndRet(argc + 1); | |
1790 } | |
1791 __ bind(&call_builtin); | |
1792 __ TailCallExternalReference( | |
1793 ExternalReference(Builtins::c_ArrayPush, isolate()), argc + 1, 1); | |
1794 } | |
1795 | |
1796 HandlerFrontendFooter(&miss); | |
1797 | |
1798 // Return the generated code. | |
1799 return GetCode(type, name); | |
1800 } | |
1801 | |
1802 | |
1803 Handle<Code> CallStubCompiler::CompileArrayPopCall( | 1559 Handle<Code> CallStubCompiler::CompileArrayPopCall( |
1804 Handle<Object> object, | 1560 Handle<Object> object, |
1805 Handle<JSObject> holder, | 1561 Handle<JSObject> holder, |
1806 Handle<Cell> cell, | 1562 Handle<Cell> cell, |
1807 Handle<JSFunction> function, | 1563 Handle<JSFunction> function, |
1808 Handle<String> name, | 1564 Handle<String> name, |
1809 Code::StubType type) { | 1565 Code::StubType type) { |
1810 // If object is not an array or is observed or sealed, bail out to regular | 1566 // If object is not an array or is observed or sealed, bail out to regular |
1811 // call. | 1567 // call. |
1812 if (!object->IsJSArray() || | 1568 if (!object->IsJSArray() || |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2471 // ----------------------------------- | 2227 // ----------------------------------- |
2472 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss); | 2228 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss); |
2473 } | 2229 } |
2474 | 2230 |
2475 | 2231 |
2476 #undef __ | 2232 #undef __ |
2477 | 2233 |
2478 } } // namespace v8::internal | 2234 } } // namespace v8::internal |
2479 | 2235 |
2480 #endif // V8_TARGET_ARCH_MIPS | 2236 #endif // V8_TARGET_ARCH_MIPS |
OLD | NEW |