src/cpu/x86/vm/stubGenerator_x86_32.cpp

Print this page
rev 146 : [mq]: mixa.layout.patch


1447   }
1448 
1449   //
1450   //  Generate 'unsafe' array copy stub
1451   //  Though just as safe as the other stubs, it takes an unscaled
1452   //  size_t argument instead of an element count.
1453   //
1454   //  Input:
1455   //    4(rsp)   - source array address
1456   //    8(rsp)   - destination array address
1457   //   12(rsp)   - byte count, can be zero
1458   //
1459   //  Output:
1460   //    rax, ==  0  -  success
1461   //    rax, == -1  -  need to call System.arraycopy
1462   //
1463   // Examines the alignment of the operands and dispatches
1464   // to a long, int, short, or byte copy loop.
1465   //
1466   address generate_unsafe_copy(const char *name,

1467                                address byte_copy_entry,
1468                                address short_copy_entry,
1469                                address int_copy_entry,
1470                                address long_copy_entry) {
1471 
1472     Label L_long_aligned, L_int_aligned, L_short_aligned;
1473 
1474     __ align(CodeEntryAlignment);
1475     StubCodeMark mark(this, "StubRoutines", name);
1476     address start = __ pc();
1477 
1478     const Register from       = rax;  // source array address
1479     const Register to         = rdx;  // destination array address
1480     const Register count      = rcx;  // elements count
1481 
1482     __ enter(); // required for proper stackwalking of RuntimeStub frame
1483     __ pushl(rsi);
1484     __ pushl(rdi);
1485     Address  from_arg(rsp, 12+ 4);      // from
1486     Address    to_arg(rsp, 12+ 8);      // to
1487     Address count_arg(rsp, 12+12);      // byte count
1488 
1489     // Load up:
1490     __ movl(from ,  from_arg);
1491     __ movl(to   ,    to_arg);
1492     __ movl(count, count_arg);
1493 
1494     // bump this on entry, not on exit:
1495     inc_counter_np(SharedRuntime::_unsafe_array_copy_ctr);
1496 



1497     const Register bits = rsi;
1498     __ movl(bits, from);
1499     __ orl(bits, to);
1500     __ orl(bits, count);
1501 
1502     __ testl(bits, BytesPerLong-1);
1503     __ jccb(Assembler::zero, L_long_aligned);
1504 
1505     __ testl(bits, BytesPerInt-1);
1506     __ jccb(Assembler::zero, L_int_aligned);
1507 
1508     __ testl(bits, BytesPerShort-1);
1509     __ jump_cc(Assembler::notZero, RuntimeAddress(byte_copy_entry));
1510 
1511     __ BIND(L_short_aligned);
1512     __ shrl(count, LogBytesPerShort); // size => short_count
1513     __ movl(count_arg, count);          // update 'count'
1514     __ jump(RuntimeAddress(short_copy_entry));
1515 
1516     __ BIND(L_int_aligned);


1558   //
1559   //  Generate generic array copy stubs
1560   //
1561   //  Input:
1562   //     4(rsp)    -  src oop
1563   //     8(rsp)    -  src_pos
1564   //    12(rsp)    -  dst oop
1565   //    16(rsp)    -  dst_pos
1566   //    20(rsp)    -  element count
1567   //
1568   //  Output:
1569   //    rax, ==  0  -  success
1570   //    rax, == -1^K - failure, where K is partial transfer count
1571   //
1572   address generate_generic_copy(const char *name,
1573                                 address entry_jbyte_arraycopy,
1574                                 address entry_jshort_arraycopy,
1575                                 address entry_jint_arraycopy,
1576                                 address entry_oop_arraycopy,
1577                                 address entry_jlong_arraycopy,

1578                                 address entry_checkcast_arraycopy) {
1579     Label L_failed, L_failed_0, L_objArray;
1580 
1581     { int modulus = CodeEntryAlignment;
1582       int target  = modulus - 5; // 5 = sizeof jmp(L_failed)
1583       int advance = target - (__ offset() % modulus);
1584       if (advance < 0)  advance += modulus;
1585       if (advance > 0)  __ nop(advance);
1586     }
1587     StubCodeMark mark(this, "StubRoutines", name);
1588 
1589     // Short-hop target to L_failed.  Makes for denser prologue code.
1590     __ BIND(L_failed_0);
1591     __ jmp(L_failed);
1592     assert(__ offset() % CodeEntryAlignment == 0, "no further alignment needed");
1593 
1594     __ align(CodeEntryAlignment);
1595     address start = __ pc();
1596 
1597     __ enter(); // required for proper stackwalking of RuntimeStub frame


1659     const Register rcx_src_klass = rcx;    // array klass
1660     __ movl(rcx_src_klass, Address(src, oopDesc::klass_offset_in_bytes()));
1661 
1662 #ifdef ASSERT
1663     //  assert(src->klass() != NULL);
1664     BLOCK_COMMENT("assert klasses not null");
1665     { Label L1, L2;
1666       __ testl(rcx_src_klass, rcx_src_klass);
1667       __ jccb(Assembler::notZero, L2);   // it is broken if klass is NULL
1668       __ bind(L1);
1669       __ stop("broken null klass");
1670       __ bind(L2);
1671       __ cmpl(dst_klass_addr, 0);
1672       __ jccb(Assembler::equal, L1);      // this would be broken also
1673       BLOCK_COMMENT("assert done");
1674     }
1675 #endif //ASSERT
1676 
1677     // Load layout helper (32-bits)
1678     //
1679     //  |array_tag|     | header_size | element_type |     |log2_element_size|
1680     // 32        30    24            16              8     2                 0
1681     //
1682     //   array_tag: typeArray = 0x3, objArray = 0x2, non-array = 0x0
1683     //
1684 
1685     int lh_offset = klassOopDesc::header_size() * HeapWordSize +
1686                     Klass::layout_helper_offset_in_bytes();
1687     Address src_klass_lh_addr(rcx_src_klass, lh_offset);
1688 
1689     // Handle objArrays completely differently...
1690     jint objArray_lh = Klass::array_layout_helper(T_OBJECT);



1691     __ cmpl(src_klass_lh_addr, objArray_lh);
1692     __ jcc(Assembler::equal, L_objArray);
1693 
1694     //  if (src->klass() != dst->klass()) return -1;
1695     __ cmpl(rcx_src_klass, dst_klass_addr);
1696     __ jccb(Assembler::notEqual, L_failed_0);
1697 
1698     const Register rcx_lh = rcx;  // layout helper
1699     assert(rcx_lh == rcx_src_klass, "known alias");
1700     __ movl(rcx_lh, src_klass_lh_addr);
1701 
1702     //  if (!src->is_Array()) return -1;
1703     __ cmpl(rcx_lh, Klass::_lh_neutral_value);
1704     __ jcc(Assembler::greaterEqual, L_failed_0); // signed cmp
1705 
1706     // At this point, it is known to be a typeArray (array_tag 0x3).
1707 #ifdef ASSERT
1708     { Label L;
1709       __ cmpl(rcx_lh, (Klass::_lh_array_tag_type_value << Klass::_lh_array_tag_shift));
1710       __ jcc(Assembler::greaterEqual, L); // signed cmp
1711       __ stop("must be a primitive array");
1712       __ bind(L);
1713     }
1714 #endif
1715 
1716     assert_different_registers(src, src_pos, dst, dst_pos, rcx_lh);
1717     arraycopy_range_checks(src, src_pos, dst, dst_pos, LENGTH, L_failed);
1718 
1719     // typeArrayKlass
1720     //
1721     // src_addr = (src + array_header_in_bytes()) + (src_pos << log2elemsize);
1722     // dst_addr = (dst + array_header_in_bytes()) + (dst_pos << log2elemsize);
1723     //
1724     const Register rsi_offset = rsi; // array offset
1725     const Register src_array  = src; // src array offset
1726     const Register dst_array  = dst; // dst array offset
1727     const Register rdi_elsize = rdi; // log2 element size
1728 
1729     __ movl(rsi_offset, rcx_lh);
1730     __ shrl(rsi_offset, Klass::_lh_header_size_shift);
1731     __ andl(rsi_offset, Klass::_lh_header_size_mask);   // array_offset
1732     __ addl(src_array, rsi_offset);  // src array offset
1733     __ addl(dst_array, rsi_offset);  // dst array offset
1734     __ andl(rcx_lh, Klass::_lh_log2_element_size_mask); // log2 elsize

1735 
1736     // next registers should be set before the jump to corresponding stub
1737     const Register from       = src; // source array address
1738     const Register to         = dst; // destination array address
1739     const Register count      = rcx; // elements count
1740     // some of them should be duplicated on stack
1741 #define FROM   Address(rsp, 12+ 4)
1742 #define TO     Address(rsp, 12+ 8)   // Not used now
1743 #define COUNT  Address(rsp, 12+12)   // Only for oop arraycopy
1744 
1745     BLOCK_COMMENT("scale indexes to element size");
1746     __ movl(rsi, SRC_POS);  // src_pos
1747     __ shll(rsi); // src_pos << rcx (log2 elsize)
1748     assert(src_array == from, "");
1749     __ addl(from, rsi);     // from = src_array + SRC_POS << log2 elsize
1750     __ movl(rdi, DST_POS);  // dst_pos
1751     __ shll(rdi); // dst_pos << rcx (log2 elsize)
1752     assert(dst_array == to, "");
1753     __ addl(to,  rdi);      // to   = dst_array + DST_POS << log2 elsize
1754     __ movl(FROM, from);    // src_addr
1755     __ movl(rdi_elsize, rcx_lh); // log2 elsize
1756     __ movl(count, LENGTH); // elements count
1757 
1758     BLOCK_COMMENT("choose copy loop based on element size");
1759     __ cmpl(rdi_elsize, 0);
1760 
1761     __ jump_cc(Assembler::equal, RuntimeAddress(entry_jbyte_arraycopy));
1762     __ cmpl(rdi_elsize, LogBytesPerShort);
1763     __ jump_cc(Assembler::equal, RuntimeAddress(entry_jshort_arraycopy));
1764     __ cmpl(rdi_elsize, LogBytesPerInt);
1765     __ jump_cc(Assembler::equal, RuntimeAddress(entry_jint_arraycopy));
1766 #ifdef ASSERT
1767     __ cmpl(rdi_elsize, LogBytesPerLong);
1768     __ jccb(Assembler::notEqual, L_failed);
1769 #endif
1770     __ popl(rdi); // Do pops here since jlong_arraycopy stub does not do it.
1771     __ popl(rsi);
1772     __ jump(RuntimeAddress(entry_jlong_arraycopy));
1773 
1774   __ BIND(L_failed);
1775     __ xorl(rax, rax);
1776     __ notl(rax); // return -1
1777     __ popl(rdi);
1778     __ popl(rsi);
1779     __ leave(); // required for proper stackwalking of RuntimeStub frame
1780     __ ret(0);
1781 


1782     // objArrayKlass
1783   __ BIND(L_objArray);
1784     // live at this point:  rcx_src_klass, src[_pos], dst[_pos]
1785 
1786     Label L_plain_copy, L_checkcast_copy;
1787     //  test array classes for subtyping
1788     __ cmpl(rcx_src_klass, dst_klass_addr); // usual case is exact equality
1789     __ jccb(Assembler::notEqual, L_checkcast_copy);
1790 
1791     // Identically typed arrays can be copied without element-wise checks.
1792     assert_different_registers(src, src_pos, dst, dst_pos, rcx_src_klass);
1793     arraycopy_range_checks(src, src_pos, dst, dst_pos, LENGTH, L_failed);
1794 
1795   __ BIND(L_plain_copy);
1796     __ movl(count, LENGTH); // elements count
1797     __ movl(src_pos, SRC_POS);  // reload src_pos
1798     __ leal(from, Address(src, src_pos, Address::times_4,
1799                   arrayOopDesc::base_offset_in_bytes(T_OBJECT))); // src_addr
1800     __ movl(dst_pos, DST_POS);  // reload dst_pos
1801     __ leal(to,   Address(dst, dst_pos, Address::times_4,
1802                   arrayOopDesc::base_offset_in_bytes(T_OBJECT))); // dst_addr
1803     __ movl(FROM,  from);   // src_addr
1804     __ movl(TO,    to);     // dst_addr
1805     __ movl(COUNT, count);  // count
1806     __ jump(RuntimeAddress(entry_oop_arraycopy));
1807 
1808   __ BIND(L_checkcast_copy);
1809     // live at this point:  rcx_src_klass, dst[_pos], src[_pos]
1810     {
1811       // Handy offsets:
1812       int  ek_offset = (klassOopDesc::header_size() * HeapWordSize +
1813                         objArrayKlass::element_klass_offset_in_bytes());
1814       int sco_offset = (klassOopDesc::header_size() * HeapWordSize +
1815                         Klass::super_check_offset_offset_in_bytes());
1816 
1817       Register rsi_dst_klass = rsi;
1818       Register rdi_temp      = rdi;
1819       assert(rsi_dst_klass == src_pos, "expected alias w/ src_pos");
1820       assert(rdi_temp      == dst_pos, "expected alias w/ dst_pos");
1821       Address dst_klass_lh_addr(rsi_dst_klass, lh_offset);
1822 
1823       // Before looking at dst.length, make sure dst is also an objArray.
1824       __ movl(rsi_dst_klass, dst_klass_addr);
1825       __ cmpl(dst_klass_lh_addr, objArray_lh);
1826       __ jccb(Assembler::notEqual, L_failed);
1827 
1828       // It is safe to examine both src.length and dst.length.
1829       __ movl(src_pos, SRC_POS);        // reload rsi
1830       arraycopy_range_checks(src, src_pos, dst, dst_pos, LENGTH, L_failed);
1831       // (Now src_pos and dst_pos are killed, but not src and dst.)
1832 
1833       // We'll need this temp (don't forget to pop it after the type check).
1834       __ pushl(rbx);
1835       Register rbx_src_klass = rbx;
1836 
1837       __ movl(rbx_src_klass, rcx_src_klass); // spill away from rcx
1838       __ movl(rsi_dst_klass, dst_klass_addr);
1839       Address super_check_offset_addr(rsi_dst_klass, sco_offset);
1840       Label L_fail_array_check;
1841       generate_type_check(rbx_src_klass,
1842                           super_check_offset_addr, dst_klass_addr,
1843                           rdi_temp, NULL, &L_fail_array_check);
1844       // (On fall-through, we have passed the array type check.)
1845       __ popl(rbx);
1846       __ jmp(L_plain_copy);


1880       __ leal(from, Address(src, src_pos, Address::times_4,
1881                             arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
1882       __ movl(from_arg, from);
1883 
1884       __ leal(to, Address(dst, dst_pos, Address::times_4,
1885                           arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
1886       __ movl(to_arg, to);
1887       __ jump(RuntimeAddress(entry_checkcast_arraycopy));
1888     }
1889 
1890     return start;
1891   }
1892 
1893   void generate_arraycopy_stubs() {
1894     address entry;
1895     address entry_jbyte_arraycopy;
1896     address entry_jshort_arraycopy;
1897     address entry_jint_arraycopy;
1898     address entry_oop_arraycopy;
1899     address entry_jlong_arraycopy;

1900     address entry_checkcast_arraycopy;
1901 
1902     StubRoutines::_arrayof_jbyte_disjoint_arraycopy =
1903         generate_disjoint_copy(T_BYTE,  true, Address::times_1, &entry,
1904                                "arrayof_jbyte_disjoint_arraycopy");
1905     StubRoutines::_arrayof_jbyte_arraycopy =
1906         generate_conjoint_copy(T_BYTE,  true, Address::times_1,  entry,
1907                                NULL, "arrayof_jbyte_arraycopy");
1908     StubRoutines::_jbyte_disjoint_arraycopy =
1909         generate_disjoint_copy(T_BYTE, false, Address::times_1, &entry,
1910                                "jbyte_disjoint_arraycopy");
1911     StubRoutines::_jbyte_arraycopy =
1912         generate_conjoint_copy(T_BYTE, false, Address::times_1,  entry,
1913                                &entry_jbyte_arraycopy, "jbyte_arraycopy");
1914 
1915     StubRoutines::_arrayof_jshort_disjoint_arraycopy =
1916         generate_disjoint_copy(T_SHORT,  true, Address::times_2, &entry,
1917                                "arrayof_jshort_disjoint_arraycopy");
1918     StubRoutines::_arrayof_jshort_arraycopy =
1919         generate_conjoint_copy(T_SHORT,  true, Address::times_2,  entry,


1946         generate_conjoint_long_copy(entry, &entry_jlong_arraycopy,
1947                                     "jlong_arraycopy");
1948 
1949     StubRoutines::_arrayof_jint_disjoint_arraycopy  =
1950         StubRoutines::_jint_disjoint_arraycopy;
1951     StubRoutines::_arrayof_oop_disjoint_arraycopy   =
1952         StubRoutines::_oop_disjoint_arraycopy;
1953     StubRoutines::_arrayof_jlong_disjoint_arraycopy =
1954         StubRoutines::_jlong_disjoint_arraycopy;
1955 
1956     StubRoutines::_arrayof_jint_arraycopy  = StubRoutines::_jint_arraycopy;
1957     StubRoutines::_arrayof_oop_arraycopy   = StubRoutines::_oop_arraycopy;
1958     StubRoutines::_arrayof_jlong_arraycopy = StubRoutines::_jlong_arraycopy;
1959 
1960     StubRoutines::_checkcast_arraycopy =
1961         generate_checkcast_copy("checkcast_arraycopy",
1962                                   &entry_checkcast_arraycopy);
1963 
1964     StubRoutines::_unsafe_arraycopy =
1965         generate_unsafe_copy("unsafe_arraycopy",

1966                                entry_jbyte_arraycopy,
1967                                entry_jshort_arraycopy,
1968                                entry_jint_arraycopy,
1969                                entry_jlong_arraycopy);
1970 
1971     StubRoutines::_generic_arraycopy =
1972         generate_generic_copy("generic_arraycopy",
1973                                entry_jbyte_arraycopy,
1974                                entry_jshort_arraycopy,
1975                                entry_jint_arraycopy,
1976                                entry_oop_arraycopy,
1977                                entry_jlong_arraycopy,

1978                                entry_checkcast_arraycopy);
1979   }
1980 
1981  public:
1982   // Information about frame layout at time of blocking runtime call.
1983   // Note that we only have to preserve callee-saved registers since
1984   // the compilers are responsible for supplying a continuation point
1985   // if they expect all registers to be preserved.
1986   enum layout {
1987     thread_off,    // last_java_sp
1988     rbp_off,       // callee saved register
1989     ret_pc,
1990     framesize
1991   };
1992 
1993  private:
1994 
1995 #undef  __
1996 #define __ masm->
1997 




1447   }
1448 
1449   //
1450   //  Generate 'unsafe' array copy stub
1451   //  Though just as safe as the other stubs, it takes an unscaled
1452   //  size_t argument instead of an element count.
1453   //
1454   //  Input:
1455   //    4(rsp)   - source array address
1456   //    8(rsp)   - destination array address
1457   //   12(rsp)   - byte count, can be zero
1458   //
1459   //  Output:
1460   //    rax, ==  0  -  success
1461   //    rax, == -1  -  need to call System.arraycopy
1462   //
1463   // Examines the alignment of the operands and dispatches
1464   // to a long, int, short, or byte copy loop.
1465   //
1466   address generate_unsafe_copy(const char *name,
1467                                address* entry,
1468                                address byte_copy_entry,
1469                                address short_copy_entry,
1470                                address int_copy_entry,
1471                                address long_copy_entry) {
1472 
1473     Label L_long_aligned, L_int_aligned, L_short_aligned;
1474 
1475     __ align(CodeEntryAlignment);
1476     StubCodeMark mark(this, "StubRoutines", name);
1477     address start = __ pc();
1478 
1479     const Register from       = rax;  // source array address
1480     const Register to         = rdx;  // destination array address
1481     const Register count      = rcx;  // elements count
1482 
1483     __ enter(); // required for proper stackwalking of RuntimeStub frame
1484     __ pushl(rsi);
1485     __ pushl(rdi);
1486     Address  from_arg(rsp, 12+ 4);      // from
1487     Address    to_arg(rsp, 12+ 8);      // to
1488     Address count_arg(rsp, 12+12);      // byte count
1489 
1490     // Load up:
1491     __ movl(from ,  from_arg);
1492     __ movl(to   ,    to_arg);
1493     __ movl(count, count_arg);
1494 
1495     // bump this on entry, not on exit:
1496     inc_counter_np(SharedRuntime::_unsafe_array_copy_ctr);
1497 
1498     *entry = __ pc(); // Entry point from generic arraycopy stub.
1499     BLOCK_COMMENT("Entry:");
1500 
1501     const Register bits = rsi;
1502     __ movl(bits, from);
1503     __ orl(bits, to);
1504     __ orl(bits, count);
1505 
1506     __ testl(bits, BytesPerLong-1);
1507     __ jccb(Assembler::zero, L_long_aligned);
1508 
1509     __ testl(bits, BytesPerInt-1);
1510     __ jccb(Assembler::zero, L_int_aligned);
1511 
1512     __ testl(bits, BytesPerShort-1);
1513     __ jump_cc(Assembler::notZero, RuntimeAddress(byte_copy_entry));
1514 
1515     __ BIND(L_short_aligned);
1516     __ shrl(count, LogBytesPerShort); // size => short_count
1517     __ movl(count_arg, count);          // update 'count'
1518     __ jump(RuntimeAddress(short_copy_entry));
1519 
1520     __ BIND(L_int_aligned);


1562   //
1563   //  Generate generic array copy stubs
1564   //
1565   //  Input:
1566   //     4(rsp)    -  src oop
1567   //     8(rsp)    -  src_pos
1568   //    12(rsp)    -  dst oop
1569   //    16(rsp)    -  dst_pos
1570   //    20(rsp)    -  element count
1571   //
1572   //  Output:
1573   //    rax, ==  0  -  success
1574   //    rax, == -1^K - failure, where K is partial transfer count
1575   //
1576   address generate_generic_copy(const char *name,
1577                                 address entry_jbyte_arraycopy,
1578                                 address entry_jshort_arraycopy,
1579                                 address entry_jint_arraycopy,
1580                                 address entry_oop_arraycopy,
1581                                 address entry_jlong_arraycopy,
1582                                 address entry_unsafe_arraycopy,
1583                                 address entry_checkcast_arraycopy) {
1584     Label L_failed, L_failed_0, L_objArray;
1585 
1586     { int modulus = CodeEntryAlignment;
1587       int target  = modulus - 5; // 5 = sizeof jmp(L_failed)
1588       int advance = target - (__ offset() % modulus);
1589       if (advance < 0)  advance += modulus;
1590       if (advance > 0)  __ nop(advance);
1591     }
1592     StubCodeMark mark(this, "StubRoutines", name);
1593 
1594     // Short-hop target to L_failed.  Makes for denser prologue code.
1595     __ BIND(L_failed_0);
1596     __ jmp(L_failed);
1597     assert(__ offset() % CodeEntryAlignment == 0, "no further alignment needed");
1598 
1599     __ align(CodeEntryAlignment);
1600     address start = __ pc();
1601 
1602     __ enter(); // required for proper stackwalking of RuntimeStub frame


1664     const Register rcx_src_klass = rcx;    // array klass
1665     __ movl(rcx_src_klass, Address(src, oopDesc::klass_offset_in_bytes()));
1666 
1667 #ifdef ASSERT
1668     //  assert(src->klass() != NULL);
1669     BLOCK_COMMENT("assert klasses not null");
1670     { Label L1, L2;
1671       __ testl(rcx_src_klass, rcx_src_klass);
1672       __ jccb(Assembler::notZero, L2);   // it is broken if klass is NULL
1673       __ bind(L1);
1674       __ stop("broken null klass");
1675       __ bind(L2);
1676       __ cmpl(dst_klass_addr, 0);
1677       __ jccb(Assembler::equal, L1);      // this would be broken also
1678       BLOCK_COMMENT("assert done");
1679     }
1680 #endif //ASSERT
1681 
1682     // Load layout helper (32-bits)
1683     //
1684     //  | array_tag | element_type | log2_element_size | header_size |
1685     // 32          28             24                  16             0
1686     //
1687     //   array_tag: typeArray = 0xF, objArray = 0xD, normal instance = 0x0
1688     //
1689 
1690     int lh_offset = klassOopDesc::header_size() * HeapWordSize +
1691                     Klass::layout_helper_offset_in_bytes();
1692     Address src_klass_lh_addr(rcx_src_klass, lh_offset);
1693 
1694     // Handle objArrays completely differently...
1695     // This is necessary because they have covariant element types.
1696     // The next type check (for src.klass == dst.klass), can get a
1697     // false negative in the case of object arrays.
1698     jint objArray_lh = LayoutHelper::for_array(T_OBJECT).as_int();
1699     __ cmpl(src_klass_lh_addr, objArray_lh);
1700     __ jcc(Assembler::equal, L_objArray);
1701 
1702     //  if (src->klass() != dst->klass()) return -1;
1703     __ cmpl(rcx_src_klass, dst_klass_addr);
1704     __ jcc(Assembler::notEqual, L_failed_0);
1705 
1706     const Register rcx_lh = rcx;  // layout helper
1707     assert(rcx_lh == rcx_src_klass, "known alias");
1708     __ movl(rcx_lh, src_klass_lh_addr);
1709 
1710     //  if (!src->has_length_field()) return -1;
1711     __ cmpl(rcx_lh, LayoutHelper::_neutral_value);
1712     __ jcc(Assembler::greaterEqual, L_failed_0); // signed cmp
1713 










1714     assert_different_registers(src, src_pos, dst, dst_pos, rcx_lh);
1715     arraycopy_range_checks(src, src_pos, dst, dst_pos, LENGTH, L_failed);
1716 
1717     // typeArrayKlass
1718     //
1719     // src_addr = (src + array_header_in_bytes()) + (src_pos << log2elemsize);
1720     // dst_addr = (dst + array_header_in_bytes()) + (dst_pos << log2elemsize);
1721     //
1722     const Register rsi_offset = rsi; // array offset
1723     const Register src_array  = src; // src array offset
1724     const Register dst_array  = dst; // dst array offset
1725     const Register rdi_elsize = rdi; // log2 element size
1726 
1727     __ movl(rsi_offset, rcx_lh);
1728     assert(LayoutHelper::_header_size_shift == 0, "");
1729     __ andl(rsi_offset, LayoutHelper::_header_size_mask);   // array_offset
1730     __ addl(src_array, rsi_offset);  // src array offset
1731     __ addl(dst_array, rsi_offset);  // dst array offset
1732     __ shrl(rcx_lh, LayoutHelper::_element_size_shift);
1733     __ andl(rcx_lh, LayoutHelper::_element_size_mask); // log2 elsize
1734 
1735     // next registers should be set before the jump to corresponding stub
1736     const Register from       = src; // source array address
1737     const Register to         = dst; // destination array address
1738     const Register count      = rcx; // elements count
1739     // some of them should be duplicated on stack
1740 #define FROM   Address(rsp, 12+ 4)
1741 #define TO     Address(rsp, 12+ 8)   // Not used now
1742 #define COUNT  Address(rsp, 12+12)   // Only for oop arraycopy
1743 
1744     BLOCK_COMMENT("scale indexes to element size");
1745     __ movl(rsi, SRC_POS);  // src_pos
1746     __ shll(rsi); // src_pos << rcx (log2 elsize)
1747     assert(src_array == from, "");
1748     __ addl(from, rsi);     // from = src_array + SRC_POS << log2 elsize
1749     __ movl(rsi, DST_POS);  // dst_pos (reuse rsi for a temp)
1750     __ shll(rsi); // dst_pos << rcx (log2 elsize)
1751     assert(dst_array == to, "");
1752     __ addl(to,  rsi);      // to   = dst_array + DST_POS << log2 elsize
1753     __ movl(FROM, from);    // src_addr

1754     __ movl(count, LENGTH); // elements count
1755 
1756     BLOCK_COMMENT("choose copy loop based on element size");
1757     __ cmpl(rdi_elsize, 0);
1758 
1759     __ jump_cc(Assembler::equal, RuntimeAddress(entry_jbyte_arraycopy));
1760     __ cmpl(rdi_elsize, LogBytesPerShort);
1761     __ jump_cc(Assembler::equal, RuntimeAddress(entry_jshort_arraycopy));
1762     __ cmpl(rdi_elsize, LogBytesPerInt);
1763     __ jump_cc(Assembler::equal, RuntimeAddress(entry_jint_arraycopy));
1764 #ifdef ASSERT
1765     __ cmpl(rdi_elsize, LogBytesPerLong);
1766     __ jccb(Assembler::notEqual, L_failed);
1767 #endif
1768     __ popl(rdi); // Do pops here since jlong_arraycopy stub does not do it.
1769     __ popl(rsi);
1770     __ jump(RuntimeAddress(entry_jlong_arraycopy));
1771 
1772   __ BIND(L_failed);
1773     __ xorl(rax, rax);
1774     __ notl(rax); // return -1
1775     __ popl(rdi);
1776     __ popl(rsi);
1777     __ leave(); // required for proper stackwalking of RuntimeStub frame
1778     __ ret(0);
1779 
1780     Label L_different_objArray, L_plain_copy, L_checkcast_copy;
1781 
1782     // objArrayKlass
1783   __ BIND(L_objArray);
1784     // live at this point:  rcx_src_klass, src[_pos], dst[_pos]
1785 

1786     //  test array classes for subtyping
1787     __ cmpl(rcx_src_klass, dst_klass_addr); // usual case is exact equality
1788     __ jccb(Assembler::notEqual, L_different_objArray);
1789 
1790     // Identically typed arrays can be copied without element-wise checks.
1791     assert_different_registers(src, src_pos, dst, dst_pos, rcx_src_klass);
1792     arraycopy_range_checks(src, src_pos, dst, dst_pos, LENGTH, L_failed);
1793 
1794   __ BIND(L_plain_copy);
1795     __ movl(count, LENGTH); // elements count
1796     __ movl(src_pos, SRC_POS);  // reload src_pos
1797     __ leal(from, Address(src, src_pos, Address::times_4,
1798                   arrayOopDesc::base_offset_in_bytes(T_OBJECT))); // src_addr
1799     __ movl(dst_pos, DST_POS);  // reload dst_pos
1800     __ leal(to,   Address(dst, dst_pos, Address::times_4,
1801                   arrayOopDesc::base_offset_in_bytes(T_OBJECT))); // dst_addr
1802     __ movl(FROM,  from);   // src_addr
1803     __ movl(TO,    to);     // dst_addr
1804     __ movl(COUNT, count);  // count
1805     __ jump(RuntimeAddress(entry_oop_arraycopy));
1806 
1807   __ BIND(L_different_objArray);
1808     // live at this point:  rcx_src_klass, dst[_pos], src[_pos]
1809     {
1810       // Handy offsets:
1811       int  ek_offset = (klassOopDesc::header_size() * HeapWordSize +
1812                         objArrayKlass::element_klass_offset_in_bytes());
1813       int sco_offset = (klassOopDesc::header_size() * HeapWordSize +
1814                         Klass::super_check_offset_offset_in_bytes());
1815 
1816       Register rsi_dst_klass = rsi;
1817       Register rdi_temp      = rdi;
1818       assert(rsi_dst_klass == src_pos, "expected alias w/ src_pos");
1819       assert(rdi_temp      == dst_pos, "expected alias w/ dst_pos");
1820       Address dst_klass_lh_addr(rsi_dst_klass, lh_offset);
1821 
1822       // Before looking at dst.length, make sure dst is also an objArray.
1823       __ movl(rsi_dst_klass, dst_klass_addr);
1824       __ cmpl(dst_klass_lh_addr, objArray_lh);
1825       __ jcc(Assembler::notEqual, L_failed);
1826 
1827       // It is safe to examine both src.length and dst.length.
1828       __ movl(src_pos, SRC_POS);        // reload rsi
1829       arraycopy_range_checks(src, src_pos, dst, dst_pos, LENGTH, L_failed);
1830       // (Now src_pos and dst_pos are killed, but not src and dst.)
1831 
1832       // We'll need this temp (don't forget to pop it after the type check).
1833       __ pushl(rbx);
1834       Register rbx_src_klass = rbx;
1835 
1836       __ movl(rbx_src_klass, rcx_src_klass); // spill away from rcx
1837       __ movl(rsi_dst_klass, dst_klass_addr);
1838       Address super_check_offset_addr(rsi_dst_klass, sco_offset);
1839       Label L_fail_array_check;
1840       generate_type_check(rbx_src_klass,
1841                           super_check_offset_addr, dst_klass_addr,
1842                           rdi_temp, NULL, &L_fail_array_check);
1843       // (On fall-through, we have passed the array type check.)
1844       __ popl(rbx);
1845       __ jmp(L_plain_copy);


1879       __ leal(from, Address(src, src_pos, Address::times_4,
1880                             arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
1881       __ movl(from_arg, from);
1882 
1883       __ leal(to, Address(dst, dst_pos, Address::times_4,
1884                           arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
1885       __ movl(to_arg, to);
1886       __ jump(RuntimeAddress(entry_checkcast_arraycopy));
1887     }
1888 
1889     return start;
1890   }
1891 
1892   void generate_arraycopy_stubs() {
1893     address entry;
1894     address entry_jbyte_arraycopy;
1895     address entry_jshort_arraycopy;
1896     address entry_jint_arraycopy;
1897     address entry_oop_arraycopy;
1898     address entry_jlong_arraycopy;
1899     address entry_unsafe_arraycopy;
1900     address entry_checkcast_arraycopy;
1901 
1902     StubRoutines::_arrayof_jbyte_disjoint_arraycopy =
1903         generate_disjoint_copy(T_BYTE,  true, Address::times_1, &entry,
1904                                "arrayof_jbyte_disjoint_arraycopy");
1905     StubRoutines::_arrayof_jbyte_arraycopy =
1906         generate_conjoint_copy(T_BYTE,  true, Address::times_1,  entry,
1907                                NULL, "arrayof_jbyte_arraycopy");
1908     StubRoutines::_jbyte_disjoint_arraycopy =
1909         generate_disjoint_copy(T_BYTE, false, Address::times_1, &entry,
1910                                "jbyte_disjoint_arraycopy");
1911     StubRoutines::_jbyte_arraycopy =
1912         generate_conjoint_copy(T_BYTE, false, Address::times_1,  entry,
1913                                &entry_jbyte_arraycopy, "jbyte_arraycopy");
1914 
1915     StubRoutines::_arrayof_jshort_disjoint_arraycopy =
1916         generate_disjoint_copy(T_SHORT,  true, Address::times_2, &entry,
1917                                "arrayof_jshort_disjoint_arraycopy");
1918     StubRoutines::_arrayof_jshort_arraycopy =
1919         generate_conjoint_copy(T_SHORT,  true, Address::times_2,  entry,


1946         generate_conjoint_long_copy(entry, &entry_jlong_arraycopy,
1947                                     "jlong_arraycopy");
1948 
1949     StubRoutines::_arrayof_jint_disjoint_arraycopy  =
1950         StubRoutines::_jint_disjoint_arraycopy;
1951     StubRoutines::_arrayof_oop_disjoint_arraycopy   =
1952         StubRoutines::_oop_disjoint_arraycopy;
1953     StubRoutines::_arrayof_jlong_disjoint_arraycopy =
1954         StubRoutines::_jlong_disjoint_arraycopy;
1955 
1956     StubRoutines::_arrayof_jint_arraycopy  = StubRoutines::_jint_arraycopy;
1957     StubRoutines::_arrayof_oop_arraycopy   = StubRoutines::_oop_arraycopy;
1958     StubRoutines::_arrayof_jlong_arraycopy = StubRoutines::_jlong_arraycopy;
1959 
1960     StubRoutines::_checkcast_arraycopy =
1961         generate_checkcast_copy("checkcast_arraycopy",
1962                                   &entry_checkcast_arraycopy);
1963 
1964     StubRoutines::_unsafe_arraycopy =
1965         generate_unsafe_copy("unsafe_arraycopy",
1966                                &entry_unsafe_arraycopy,
1967                                entry_jbyte_arraycopy,
1968                                entry_jshort_arraycopy,
1969                                entry_jint_arraycopy,
1970                                entry_jlong_arraycopy);
1971 
1972     StubRoutines::_generic_arraycopy =
1973         generate_generic_copy("generic_arraycopy",
1974                                entry_jbyte_arraycopy,
1975                                entry_jshort_arraycopy,
1976                                entry_jint_arraycopy,
1977                                entry_oop_arraycopy,
1978                                entry_jlong_arraycopy,
1979                                entry_unsafe_arraycopy,
1980                                entry_checkcast_arraycopy);
1981   }
1982 
1983  public:
1984   // Information about frame layout at time of blocking runtime call.
1985   // Note that we only have to preserve callee-saved registers since
1986   // the compilers are responsible for supplying a continuation point
1987   // if they expect all registers to be preserved.
1988   enum layout {
1989     thread_off,    // last_java_sp
1990     rbp_off,       // callee saved register
1991     ret_pc,
1992     framesize
1993   };
1994 
1995  private:
1996 
1997 #undef  __
1998 #define __ masm->
1999