1 /*
2 * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2015, 2016 SAP SE. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
1878 const Register argP = R15_esp;
1879 const Register crc = R3_ARG1; // crc value
1880 const Register data = R4_ARG2; // address of java byte value (kernel_crc32 needs address)
1881 const Register dataLen = R5_ARG3; // source data len (1 byte). Not used because calling the single-byte emitter.
1882 const Register table = R6_ARG4; // address of crc32 table
1883 const Register tmp = dataLen; // Reuse unused len register to show we don't actually need a separate tmp here.
1884
1885 BLOCK_COMMENT("CRC32_update {");
1886
1887 // Arguments are reversed on java expression stack
1888 #ifdef VM_LITTLE_ENDIAN
1889 __ addi(data, argP, 0+1*wordSize); // (stack) address of byte value. Emitter expects address, not value.
1890 // Being passed as an int, the single byte is at offset +0.
1891 #else
1892 __ addi(data, argP, 3+1*wordSize); // (stack) address of byte value. Emitter expects address, not value.
1893 // Being passed from java as an int, the single byte is at offset +3.
1894 #endif
1895 __ lwz(crc, 2*wordSize, argP); // Current crc state, zero extend to 64 bit to have a clean register.
1896
1897 StubRoutines::ppc64::generate_load_crc_table_addr(_masm, table);
1898 __ kernel_crc32_singleByte(crc, data, dataLen, table, tmp);
1899
1900 // Restore caller sp for c2i case and return.
1901 __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
1902 __ blr();
1903
1904 // Generate a vanilla native entry as the slow path.
1905 BLOCK_COMMENT("} CRC32_update");
1906 BIND(slow_path);
1907 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native), R11_scratch1);
1908 return start;
1909 }
1910
1911 return NULL;
1912 }
1913
1914 // CRC32 Intrinsics.
1915 /**
1916 * Method entry for static native methods:
1917 * int java.util.zip.CRC32.updateBytes( int crc, byte[] b, int off, int len)
1918 * int java.util.zip.CRC32.updateByteBuffer(int crc, long* buf, int off, int len)
1919 */
1920 address TemplateInterpreterGenerator::generate_CRC32_updateBytes_entry(AbstractInterpreter::MethodKind kind) {
1921 if (UseCRC32Intrinsics) {
1922 address start = __ pc(); // Remember stub start address (is rtn value).
1923 Label slow_path;
1924
1925 // Safepoint check
1926 const Register sync_state = R11_scratch1;
1927 int sync_state_offs = __ load_const_optimized(sync_state, SafepointSynchronize::address_of_state(), /*temp*/R0, true);
1928 __ lwz(sync_state, sync_state_offs, sync_state);
1929 __ cmpwi(CCR0, sync_state, SafepointSynchronize::_not_synchronized);
1930 __ bne(CCR0, slow_path);
1931
1932 // We don't generate local frame and don't align stack because
1933 // we not even call stub code (we generate the code inline)
1970 } else { // Used for "updateBytes update".
1971 BLOCK_COMMENT("CRC32_updateBytes {");
1972 // crc @ (SP + 4W) (32bit)
1973 // buf @ (SP + 3W) (64bit ptr to byte array)
1974 // off @ (SP + 2W) (32bit)
1975 // dataLen @ (SP + 1W) (32bit)
1976 // data = buf + off + base_offset
1977 __ ld( data, 3*wordSize, argP); // start of byte buffer
1978 __ lwa( tmp, 2*wordSize, argP); // byte buffer offset
1979 __ lwa( dataLen, 1*wordSize, argP); // #bytes to process
1980 __ add( data, data, tmp); // add byte buffer offset
1981 __ lwz( crc, 4*wordSize, argP); // current crc state
1982 __ addi(data, data, arrayOopDesc::base_offset_in_bytes(T_BYTE));
1983 }
1984
1985 StubRoutines::ppc64::generate_load_crc_table_addr(_masm, table);
1986
1987 // Performance measurements show the 1word and 2word variants to be almost equivalent,
1988 // with very light advantages for the 1word variant. We chose the 1word variant for
1989 // code compactness.
1990 __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3, tc0, tc1, tc2, tc3);
1991
1992 // Restore caller sp for c2i case and return.
1993 __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
1994 __ blr();
1995
1996 // Generate a vanilla native entry as the slow path.
1997 BLOCK_COMMENT("} CRC32_updateBytes(Buffer)");
1998 BIND(slow_path);
1999 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native), R11_scratch1);
2000 return start;
2001 }
2002
2003 return NULL;
2004 }
2005
2006 // Not supported
2007 address TemplateInterpreterGenerator::generate_CRC32C_updateBytes_entry(AbstractInterpreter::MethodKind kind) {
2008 return NULL;
2009 }
2010
2011 // =============================================================================
2012 // Exceptions
2013
2014 void TemplateInterpreterGenerator::generate_throw_exception() {
2015 Register Rexception = R17_tos,
2016 Rcontinuation = R3_RET;
2017
2018 // --------------------------------------------------------------------------
2019 // Entry point if an method returns with a pending exception (rethrow).
2020 Interpreter::_rethrow_exception_entry = __ pc();
2021 {
2022 __ restore_interpreter_state(R11_scratch1); // Sets R11_scratch1 = fp.
2023 __ ld(R12_scratch2, _ijava_state_neg(top_frame_sp), R11_scratch1);
2024 __ resize_frame_absolute(R12_scratch2, R11_scratch1, R0);
2025
2026 // Compiled code destroys templateTableBase, reload.
2027 __ load_const_optimized(R25_templateTableBase, (address)Interpreter::dispatch_table((TosState)0), R11_scratch1);
|
1 /*
2 * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2015, 2017, SAP SE. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
1878 const Register argP = R15_esp;
1879 const Register crc = R3_ARG1; // crc value
1880 const Register data = R4_ARG2; // address of java byte value (kernel_crc32 needs address)
1881 const Register dataLen = R5_ARG3; // source data len (1 byte). Not used because calling the single-byte emitter.
1882 const Register table = R6_ARG4; // address of crc32 table
1883 const Register tmp = dataLen; // Reuse unused len register to show we don't actually need a separate tmp here.
1884
1885 BLOCK_COMMENT("CRC32_update {");
1886
1887 // Arguments are reversed on java expression stack
1888 #ifdef VM_LITTLE_ENDIAN
1889 __ addi(data, argP, 0+1*wordSize); // (stack) address of byte value. Emitter expects address, not value.
1890 // Being passed as an int, the single byte is at offset +0.
1891 #else
1892 __ addi(data, argP, 3+1*wordSize); // (stack) address of byte value. Emitter expects address, not value.
1893 // Being passed from java as an int, the single byte is at offset +3.
1894 #endif
1895 __ lwz(crc, 2*wordSize, argP); // Current crc state, zero extend to 64 bit to have a clean register.
1896
1897 StubRoutines::ppc64::generate_load_crc_table_addr(_masm, table);
1898 __ kernel_crc32_singleByte(crc, data, dataLen, table, tmp, true);
1899
1900 // Restore caller sp for c2i case and return.
1901 __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
1902 __ blr();
1903
1904 // Generate a vanilla native entry as the slow path.
1905 BLOCK_COMMENT("} CRC32_update");
1906 BIND(slow_path);
1907 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native), R11_scratch1);
1908 return start;
1909 }
1910
1911 return NULL;
1912 }
1913
1914 // TODO: generate_CRC32_updateBytes_entry and generate_CRC32C_updateBytes_entry are identical
1915 // except for using different crc tables and some block comment strings.
1916 // We should provide a common implementation.
1917
1918 // CRC32 Intrinsics.
1919 /**
1920 * Method entry for static native methods:
1921 * int java.util.zip.CRC32.updateBytes( int crc, byte[] b, int off, int len)
1922 * int java.util.zip.CRC32.updateByteBuffer(int crc, long* buf, int off, int len)
1923 */
1924 address TemplateInterpreterGenerator::generate_CRC32_updateBytes_entry(AbstractInterpreter::MethodKind kind) {
1925 if (UseCRC32Intrinsics) {
1926 address start = __ pc(); // Remember stub start address (is rtn value).
1927 Label slow_path;
1928
1929 // Safepoint check
1930 const Register sync_state = R11_scratch1;
1931 int sync_state_offs = __ load_const_optimized(sync_state, SafepointSynchronize::address_of_state(), /*temp*/R0, true);
1932 __ lwz(sync_state, sync_state_offs, sync_state);
1933 __ cmpwi(CCR0, sync_state, SafepointSynchronize::_not_synchronized);
1934 __ bne(CCR0, slow_path);
1935
1936 // We don't generate local frame and don't align stack because
1937 // we not even call stub code (we generate the code inline)
1974 } else { // Used for "updateBytes update".
1975 BLOCK_COMMENT("CRC32_updateBytes {");
1976 // crc @ (SP + 4W) (32bit)
1977 // buf @ (SP + 3W) (64bit ptr to byte array)
1978 // off @ (SP + 2W) (32bit)
1979 // dataLen @ (SP + 1W) (32bit)
1980 // data = buf + off + base_offset
1981 __ ld( data, 3*wordSize, argP); // start of byte buffer
1982 __ lwa( tmp, 2*wordSize, argP); // byte buffer offset
1983 __ lwa( dataLen, 1*wordSize, argP); // #bytes to process
1984 __ add( data, data, tmp); // add byte buffer offset
1985 __ lwz( crc, 4*wordSize, argP); // current crc state
1986 __ addi(data, data, arrayOopDesc::base_offset_in_bytes(T_BYTE));
1987 }
1988
1989 StubRoutines::ppc64::generate_load_crc_table_addr(_masm, table);
1990
1991 // Performance measurements show the 1word and 2word variants to be almost equivalent,
1992 // with very light advantages for the 1word variant. We chose the 1word variant for
1993 // code compactness.
1994 __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3, tc0, tc1, tc2, tc3, true);
1995
1996 // Restore caller sp for c2i case and return.
1997 __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
1998 __ blr();
1999
2000 // Generate a vanilla native entry as the slow path.
2001 BLOCK_COMMENT("} CRC32_updateBytes(Buffer)");
2002 BIND(slow_path);
2003 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native), R11_scratch1);
2004 return start;
2005 }
2006
2007 return NULL;
2008 }
2009
2010 // CRC32C Intrinsics.
2011 /**
2012 * Method entry for static native methods:
2013 * int java.util.zip.CRC32C.updateBytes( int crc, byte[] b, int off, int len)
2014 * int java.util.zip.CRC32C.updateDirectByteBuffer(int crc, long* buf, int off, int len)
2015 **/
2016 address TemplateInterpreterGenerator::generate_CRC32C_updateBytes_entry(AbstractInterpreter::MethodKind kind) {
2017 if (UseCRC32CIntrinsics) {
2018 address start = __ pc(); // Remember stub start address (is rtn value).
2019
2020 // We don't generate local frame and don't align stack because
2021 // we not even call stub code (we generate the code inline)
2022 // and there is no safepoint on this path.
2023
2024 // Load parameters.
2025 // Z_esp is callers operand stack pointer, i.e. it points to the parameters.
2026 const Register argP = R15_esp;
2027 const Register crc = R3_ARG1; // crc value
2028 const Register data = R4_ARG2; // address of java byte array
2029 const Register dataLen = R5_ARG3; // source data len
2030 const Register table = R6_ARG4; // address of crc32c table
2031
2032 const Register t0 = R9; // scratch registers for crc calculation
2033 const Register t1 = R10;
2034 const Register t2 = R11;
2035 const Register t3 = R12;
2036
2037 const Register tc0 = R2; // registers to hold pre-calculated column addresses
2038 const Register tc1 = R7;
2039 const Register tc2 = R8;
2040 const Register tc3 = table; // table address is reconstructed at the end of kernel_crc32_* emitters
2041
2042 const Register tmp = t0; // Only used very locally to calculate byte buffer address.
2043
2044 // Arguments are reversed on java expression stack.
2045 // Calculate address of start element.
2046 if (kind == Interpreter::java_util_zip_CRC32C_updateDirectByteBuffer) { // Used for "updateDirectByteBuffer".
2047 BLOCK_COMMENT("CRC32C_updateDirectByteBuffer {");
2048 // crc @ (SP + 5W) (32bit)
2049 // buf @ (SP + 3W) (64bit ptr to long array)
2050 // off @ (SP + 2W) (32bit)
2051 // dataLen @ (SP + 1W) (32bit)
2052 // data = buf + off
2053 __ ld( data, 3*wordSize, argP); // start of byte buffer
2054 __ lwa( tmp, 2*wordSize, argP); // byte buffer offset
2055 __ lwa( dataLen, 1*wordSize, argP); // #bytes to process
2056 __ lwz( crc, 5*wordSize, argP); // current crc state
2057 __ add( data, data, tmp); // Add byte buffer offset.
2058 } else { // Used for "updateBytes update".
2059 BLOCK_COMMENT("CRC32C_updateBytes {");
2060 // crc @ (SP + 4W) (32bit)
2061 // buf @ (SP + 3W) (64bit ptr to byte array)
2062 // off @ (SP + 2W) (32bit)
2063 // dataLen @ (SP + 1W) (32bit)
2064 // data = buf + off + base_offset
2065 __ ld( data, 3*wordSize, argP); // start of byte buffer
2066 __ lwa( tmp, 2*wordSize, argP); // byte buffer offset
2067 __ lwa( dataLen, 1*wordSize, argP); // #bytes to process
2068 __ add( data, data, tmp); // add byte buffer offset
2069 __ lwz( crc, 4*wordSize, argP); // current crc state
2070 __ addi(data, data, arrayOopDesc::base_offset_in_bytes(T_BYTE));
2071 }
2072
2073 StubRoutines::ppc64::generate_load_crc32c_table_addr(_masm, table);
2074
2075 // Performance measurements show the 1word and 2word variants to be almost equivalent,
2076 // with very light advantages for the 1word variant. We chose the 1word variant for
2077 // code compactness.
2078 __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3, tc0, tc1, tc2, tc3, false);
2079
2080 // Restore caller sp for c2i case and return.
2081 __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
2082 __ blr();
2083
2084 BLOCK_COMMENT("} CRC32C_update{Bytes|DirectByteBuffer}");
2085 return start;
2086 }
2087
2088 return NULL;
2089 }
2090
2091 // =============================================================================
2092 // Exceptions
2093
2094 void TemplateInterpreterGenerator::generate_throw_exception() {
2095 Register Rexception = R17_tos,
2096 Rcontinuation = R3_RET;
2097
2098 // --------------------------------------------------------------------------
2099 // Entry point if an method returns with a pending exception (rethrow).
2100 Interpreter::_rethrow_exception_entry = __ pc();
2101 {
2102 __ restore_interpreter_state(R11_scratch1); // Sets R11_scratch1 = fp.
2103 __ ld(R12_scratch2, _ijava_state_neg(top_frame_sp), R11_scratch1);
2104 __ resize_frame_absolute(R12_scratch2, R11_scratch1, R0);
2105
2106 // Compiled code destroys templateTableBase, reload.
2107 __ load_const_optimized(R25_templateTableBase, (address)Interpreter::dispatch_table((TosState)0), R11_scratch1);
|