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

Side by Side Diff: src/arm/stub-cache-arm.cc

Issue 143213003: Turn ArrayPush into a stub specialized on the elements kind and argc. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Properly bind label Created 6 years, 11 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 | « src/arm/code-stubs-arm.cc ('k') | src/code-stubs.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 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 1553 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 index.translate(holder), Representation::Tagged()); 1564 index.translate(holder), Representation::Tagged());
1565 GenerateJumpFunction(object, r1, &miss); 1565 GenerateJumpFunction(object, r1, &miss);
1566 1566
1567 HandlerFrontendFooter(&miss); 1567 HandlerFrontendFooter(&miss);
1568 1568
1569 // Return the generated code. 1569 // Return the generated code.
1570 return GetCode(Code::FAST, name); 1570 return GetCode(Code::FAST, name);
1571 } 1571 }
1572 1572
1573 1573
1574 Handle<Code> CallStubCompiler::CompileArrayPushCall(
1575 Handle<Object> object,
1576 Handle<JSObject> holder,
1577 Handle<Cell> cell,
1578 Handle<JSFunction> function,
1579 Handle<String> name,
1580 Code::StubType type) {
1581 // If object is not an array or is observed or sealed, bail out to regular
1582 // call.
1583 if (!object->IsJSArray() ||
1584 !cell.is_null() ||
1585 Handle<JSArray>::cast(object)->map()->is_observed() ||
1586 !Handle<JSArray>::cast(object)->map()->is_extensible()) {
1587 return Handle<Code>::null();
1588 }
1589
1590 Label miss;
1591
1592 HandlerFrontendHeader(object, holder, name, RECEIVER_MAP_CHECK, &miss);
1593 Register receiver = r0;
1594 Register scratch = r1;
1595
1596 const int argc = arguments().immediate();
1597 if (argc == 0) {
1598 // Nothing to do, just return the length.
1599 __ ldr(r0, FieldMemOperand(receiver, JSArray::kLengthOffset));
1600 __ Drop(argc + 1);
1601 __ Ret();
1602 } else {
1603 Label call_builtin;
1604
1605 if (argc == 1) { // Otherwise fall through to call the builtin.
1606 Label attempt_to_grow_elements, with_write_barrier, check_double;
1607
1608 Register elements = r6;
1609 Register end_elements = r5;
1610 // Get the elements array of the object.
1611 __ ldr(elements, FieldMemOperand(receiver, JSArray::kElementsOffset));
1612
1613 // Check that the elements are in fast mode and writable.
1614 __ CheckMap(elements,
1615 scratch,
1616 Heap::kFixedArrayMapRootIndex,
1617 &check_double,
1618 DONT_DO_SMI_CHECK);
1619
1620 // Get the array's length into scratch and calculate new length.
1621 __ ldr(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset));
1622 __ add(scratch, scratch, Operand(Smi::FromInt(argc)));
1623
1624 // Get the elements' length.
1625 __ ldr(r4, FieldMemOperand(elements, FixedArray::kLengthOffset));
1626
1627 // Check if we could survive without allocation.
1628 __ cmp(scratch, r4);
1629 __ b(gt, &attempt_to_grow_elements);
1630
1631 // Check if value is a smi.
1632 __ ldr(r4, MemOperand(sp, (argc - 1) * kPointerSize));
1633 __ JumpIfNotSmi(r4, &with_write_barrier);
1634
1635 // Save new length.
1636 __ str(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset));
1637
1638 // Store the value.
1639 // We may need a register containing the address end_elements below,
1640 // so write back the value in end_elements.
1641 __ add(end_elements, elements, Operand::PointerOffsetFromSmiKey(scratch));
1642 const int kEndElementsOffset =
1643 FixedArray::kHeaderSize - kHeapObjectTag - argc * kPointerSize;
1644 __ str(r4, MemOperand(end_elements, kEndElementsOffset, PreIndex));
1645
1646 // Check for a smi.
1647 __ Drop(argc + 1);
1648 __ mov(r0, scratch);
1649 __ Ret();
1650
1651 __ bind(&check_double);
1652
1653 // Check that the elements are in fast mode and writable.
1654 __ CheckMap(elements,
1655 scratch,
1656 Heap::kFixedDoubleArrayMapRootIndex,
1657 &call_builtin,
1658 DONT_DO_SMI_CHECK);
1659
1660 // Get the array's length into scratch and calculate new length.
1661 __ ldr(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset));
1662 __ add(scratch, scratch, Operand(Smi::FromInt(argc)));
1663
1664 // Get the elements' length.
1665 __ ldr(r4, FieldMemOperand(elements, FixedArray::kLengthOffset));
1666
1667 // Check if we could survive without allocation.
1668 __ cmp(scratch, r4);
1669 __ b(gt, &call_builtin);
1670
1671 __ ldr(r4, MemOperand(sp, (argc - 1) * kPointerSize));
1672 __ StoreNumberToDoubleElements(r4, scratch, elements, r5, d0,
1673 &call_builtin, argc * kDoubleSize);
1674
1675 // Save new length.
1676 __ str(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset));
1677
1678 __ Drop(argc + 1);
1679 __ mov(r0, scratch);
1680 __ Ret();
1681
1682 __ bind(&with_write_barrier);
1683
1684 __ ldr(r3, FieldMemOperand(receiver, HeapObject::kMapOffset));
1685
1686 if (FLAG_smi_only_arrays && !FLAG_trace_elements_transitions) {
1687 Label fast_object, not_fast_object;
1688 __ CheckFastObjectElements(r3, r9, &not_fast_object);
1689 __ jmp(&fast_object);
1690 // In case of fast smi-only, convert to fast object, otherwise bail out.
1691 __ bind(&not_fast_object);
1692 __ CheckFastSmiElements(r3, r9, &call_builtin);
1693
1694 __ ldr(r9, FieldMemOperand(r4, HeapObject::kMapOffset));
1695 __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
1696 __ cmp(r9, ip);
1697 __ b(eq, &call_builtin);
1698 // edx: receiver
1699 // r3: map
1700 Label try_holey_map;
1701 __ LoadTransitionedArrayMapConditional(FAST_SMI_ELEMENTS,
1702 FAST_ELEMENTS,
1703 r3,
1704 r9,
1705 &try_holey_map);
1706 __ mov(r2, receiver);
1707 ElementsTransitionGenerator::
1708 GenerateMapChangeElementsTransition(masm(),
1709 DONT_TRACK_ALLOCATION_SITE,
1710 NULL);
1711 __ jmp(&fast_object);
1712
1713 __ bind(&try_holey_map);
1714 __ LoadTransitionedArrayMapConditional(FAST_HOLEY_SMI_ELEMENTS,
1715 FAST_HOLEY_ELEMENTS,
1716 r3,
1717 r9,
1718 &call_builtin);
1719 __ mov(r2, receiver);
1720 ElementsTransitionGenerator::
1721 GenerateMapChangeElementsTransition(masm(),
1722 DONT_TRACK_ALLOCATION_SITE,
1723 NULL);
1724 __ bind(&fast_object);
1725 } else {
1726 __ CheckFastObjectElements(r3, r3, &call_builtin);
1727 }
1728
1729 // Save new length.
1730 __ str(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset));
1731
1732 // Store the value.
1733 // We may need a register containing the address end_elements below,
1734 // so write back the value in end_elements.
1735 __ add(end_elements, elements, Operand::PointerOffsetFromSmiKey(scratch));
1736 __ str(r4, MemOperand(end_elements, kEndElementsOffset, PreIndex));
1737
1738 __ RecordWrite(elements,
1739 end_elements,
1740 r4,
1741 kLRHasNotBeenSaved,
1742 kDontSaveFPRegs,
1743 EMIT_REMEMBERED_SET,
1744 OMIT_SMI_CHECK);
1745 __ Drop(argc + 1);
1746 __ mov(r0, scratch);
1747 __ Ret();
1748
1749 __ bind(&attempt_to_grow_elements);
1750 // scratch: array's length + 1.
1751
1752 if (!FLAG_inline_new) {
1753 __ b(&call_builtin);
1754 }
1755
1756 __ ldr(r2, MemOperand(sp, (argc - 1) * kPointerSize));
1757 // Growing elements that are SMI-only requires special handling in case
1758 // the new element is non-Smi. For now, delegate to the builtin.
1759 Label no_fast_elements_check;
1760 __ JumpIfSmi(r2, &no_fast_elements_check);
1761 __ ldr(r9, FieldMemOperand(receiver, HeapObject::kMapOffset));
1762 __ CheckFastObjectElements(r9, r9, &call_builtin);
1763 __ bind(&no_fast_elements_check);
1764
1765 ExternalReference new_space_allocation_top =
1766 ExternalReference::new_space_allocation_top_address(isolate());
1767 ExternalReference new_space_allocation_limit =
1768 ExternalReference::new_space_allocation_limit_address(isolate());
1769
1770 const int kAllocationDelta = 4;
1771 // Load top and check if it is the end of elements.
1772 __ add(end_elements, elements, Operand::PointerOffsetFromSmiKey(scratch));
1773 __ add(end_elements, end_elements, Operand(kEndElementsOffset));
1774 __ mov(r4, Operand(new_space_allocation_top));
1775 __ ldr(r3, MemOperand(r4));
1776 __ cmp(end_elements, r3);
1777 __ b(ne, &call_builtin);
1778
1779 __ mov(r9, Operand(new_space_allocation_limit));
1780 __ ldr(r9, MemOperand(r9));
1781 __ add(r3, r3, Operand(kAllocationDelta * kPointerSize));
1782 __ cmp(r3, r9);
1783 __ b(hi, &call_builtin);
1784
1785 // We fit and could grow elements.
1786 // Update new_space_allocation_top.
1787 __ str(r3, MemOperand(r4));
1788 // Push the argument.
1789 __ str(r2, MemOperand(end_elements));
1790 // Fill the rest with holes.
1791 __ LoadRoot(r3, Heap::kTheHoleValueRootIndex);
1792 for (int i = 1; i < kAllocationDelta; i++) {
1793 __ str(r3, MemOperand(end_elements, i * kPointerSize));
1794 }
1795
1796 // Update elements' and array's sizes.
1797 __ str(scratch, FieldMemOperand(receiver, JSArray::kLengthOffset));
1798 __ ldr(r4, FieldMemOperand(elements, FixedArray::kLengthOffset));
1799 __ add(r4, r4, Operand(Smi::FromInt(kAllocationDelta)));
1800 __ str(r4, FieldMemOperand(elements, FixedArray::kLengthOffset));
1801
1802 // Elements are in new space, so write barrier is not required.
1803 __ Drop(argc + 1);
1804 __ mov(r0, scratch);
1805 __ Ret();
1806 }
1807 __ bind(&call_builtin);
1808 __ TailCallExternalReference(
1809 ExternalReference(Builtins::c_ArrayPush, isolate()), argc + 1, 1);
1810 }
1811
1812 HandlerFrontendFooter(&miss);
1813
1814 // Return the generated code.
1815 return GetCode(type, name);
1816 }
1817
1818
1819 Handle<Code> CallStubCompiler::CompileFastApiCall( 1574 Handle<Code> CallStubCompiler::CompileFastApiCall(
1820 const CallOptimization& optimization, 1575 const CallOptimization& optimization,
1821 Handle<Object> object, 1576 Handle<Object> object,
1822 Handle<JSObject> holder, 1577 Handle<JSObject> holder,
1823 Handle<Cell> cell, 1578 Handle<Cell> cell,
1824 Handle<JSFunction> function, 1579 Handle<JSFunction> function,
1825 Handle<String> name) { 1580 Handle<String> name) {
1826 Counters* counters = isolate()->counters(); 1581 Counters* counters = isolate()->counters();
1827 1582
1828 ASSERT(optimization.is_simple_api_call()); 1583 ASSERT(optimization.is_simple_api_call());
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
2416 // ----------------------------------- 2171 // -----------------------------------
2417 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss); 2172 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss);
2418 } 2173 }
2419 2174
2420 2175
2421 #undef __ 2176 #undef __
2422 2177
2423 } } // namespace v8::internal 2178 } } // namespace v8::internal
2424 2179
2425 #endif // V8_TARGET_ARCH_ARM 2180 #endif // V8_TARGET_ARCH_ARM
OLDNEW
« no previous file with comments | « src/arm/code-stubs-arm.cc ('k') | src/code-stubs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698