1 /*
2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 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 *
1938 BLOCK_COMMENT("CRC32_update {");
1939
1940 // We don't generate local frame and don't align stack because
1941 // we not even call stub code (we generate the code inline)
1942 // and there is no safepoint on this path.
1943
1944 // Load java parameters.
1945 // Z_esp is callers operand stack pointer, i.e. it points to the parameters.
1946 const Register argP = Z_esp;
1947 const Register crc = Z_ARG1; // crc value
1948 const Register data = Z_ARG2; // address of java byte value (kernel_crc32 needs address)
1949 const Register dataLen = Z_ARG3; // source data len (1 byte). Not used because calling the single-byte emitter.
1950 const Register table = Z_ARG4; // address of crc32 table
1951
1952 // Arguments are reversed on java expression stack.
1953 __ z_la(data, 3+1*wordSize, argP); // byte value (stack address).
1954 // Being passed as an int, the single byte is at offset +3.
1955 __ z_llgf(crc, 2 * wordSize, argP); // Current crc state, zero extend to 64 bit to have a clean register.
1956
1957 StubRoutines::zarch::generate_load_crc_table_addr(_masm, table);
1958 __ kernel_crc32_singleByte(crc, data, dataLen, table, Z_R1);
1959
1960 // Restore caller sp for c2i case.
1961 __ resize_frame_absolute(Z_R10, Z_R0, true); // Cut the stack back to where the caller started.
1962
1963 __ z_br(Z_R14);
1964
1965 BLOCK_COMMENT("} CRC32_update");
1966
1967 // Use a previously generated vanilla native entry as the slow path.
1968 BIND(slow_path);
1969 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native), Z_R1);
1970 return __ addr_at(entry_off);
1971 }
1972
1973 return NULL;
1974 }
1975
1976
1977 // Method entry for static native methods:
1978 // int java.util.zip.CRC32.updateBytes(int crc, byte[] b, int off, int len)
2015 __ z_agf(data, 2*wordSize, argP); // Add byte buffer offset.
2016 __ z_lgf(dataLen, 1*wordSize, argP); // #bytes to process
2017 } else { // Used for "updateBytes update".
2018 // crc @ (SP + 4W) (32bit)
2019 // buf @ (SP + 3W) (64bit ptr to byte array)
2020 // off @ (SP + 2W) (32bit)
2021 // dataLen @ (SP + 1W) (32bit)
2022 // data = buf + off + base_offset
2023 BLOCK_COMMENT("CRC32_updateBytes {");
2024 __ z_llgf(crc, 4*wordSize, argP); // current crc state
2025 __ z_lg(data, 3*wordSize, argP); // start of byte buffer
2026 __ z_agf(data, 2*wordSize, argP); // Add byte buffer offset.
2027 __ z_lgf(dataLen, 1*wordSize, argP); // #bytes to process
2028 __ z_aghi(data, arrayOopDesc::base_offset_in_bytes(T_BYTE));
2029 }
2030
2031 StubRoutines::zarch::generate_load_crc_table_addr(_masm, table);
2032
2033 __ resize_frame(-(6*8), Z_R0, true); // Resize frame to provide add'l space to spill 5 registers.
2034 __ z_stmg(t0, t3, 1*8, Z_SP); // Spill regs 10..13 to make them available as work registers.
2035 __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3);
2036 __ z_lmg(t0, t3, 1*8, Z_SP); // Spill regs 10..13 back from stack.
2037
2038 // Restore caller sp for c2i case.
2039 __ resize_frame_absolute(Z_R10, Z_R0, true); // Cut the stack back to where the caller started.
2040
2041 __ z_br(Z_R14);
2042
2043 BLOCK_COMMENT("} CRC32_update{Bytes|ByteBuffer}");
2044
2045 // Use a previously generated vanilla native entry as the slow path.
2046 BIND(slow_path);
2047 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native), Z_R1);
2048 return __ addr_at(entry_off);
2049 }
2050
2051 return NULL;
2052 }
2053
2054 // Not supported
2055 address TemplateInterpreterGenerator::generate_CRC32C_updateBytes_entry(AbstractInterpreter::MethodKind kind) {
2056 return NULL;
2057 }
2058
2059 void TemplateInterpreterGenerator::bang_stack_shadow_pages(bool native_call) {
2060 // Quick & dirty stack overflow checking: bang the stack & handle trap.
2061 // Note that we do the banging after the frame is setup, since the exception
2062 // handling code expects to find a valid interpreter frame on the stack.
2063 // Doing the banging earlier fails if the caller frame is not an interpreter
2064 // frame.
2065 // (Also, the exception throwing code expects to unlock any synchronized
2066 // method receiver, so do the banging after locking the receiver.)
2067
2068 // Bang each page in the shadow zone. We can't assume it's been done for
2069 // an interpreter frame with greater than a page of locals, so each page
2070 // needs to be checked. Only true for non-native. For native, we only bang the last page.
2071 if (UseStackBanging) {
2072 const int page_size = os::vm_page_size();
2073 const int n_shadow_pages = (int)(JavaThread::stack_shadow_zone_size()/page_size);
2074 const int start_page_num = native_call ? n_shadow_pages : 1;
2075 for (int pages = start_page_num; pages <= n_shadow_pages; pages++) {
|
1 /*
2 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2016, 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 *
1938 BLOCK_COMMENT("CRC32_update {");
1939
1940 // We don't generate local frame and don't align stack because
1941 // we not even call stub code (we generate the code inline)
1942 // and there is no safepoint on this path.
1943
1944 // Load java parameters.
1945 // Z_esp is callers operand stack pointer, i.e. it points to the parameters.
1946 const Register argP = Z_esp;
1947 const Register crc = Z_ARG1; // crc value
1948 const Register data = Z_ARG2; // address of java byte value (kernel_crc32 needs address)
1949 const Register dataLen = Z_ARG3; // source data len (1 byte). Not used because calling the single-byte emitter.
1950 const Register table = Z_ARG4; // address of crc32 table
1951
1952 // Arguments are reversed on java expression stack.
1953 __ z_la(data, 3+1*wordSize, argP); // byte value (stack address).
1954 // Being passed as an int, the single byte is at offset +3.
1955 __ z_llgf(crc, 2 * wordSize, argP); // Current crc state, zero extend to 64 bit to have a clean register.
1956
1957 StubRoutines::zarch::generate_load_crc_table_addr(_masm, table);
1958 __ kernel_crc32_singleByte(crc, data, dataLen, table, Z_R1, true);
1959
1960 // Restore caller sp for c2i case.
1961 __ resize_frame_absolute(Z_R10, Z_R0, true); // Cut the stack back to where the caller started.
1962
1963 __ z_br(Z_R14);
1964
1965 BLOCK_COMMENT("} CRC32_update");
1966
1967 // Use a previously generated vanilla native entry as the slow path.
1968 BIND(slow_path);
1969 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native), Z_R1);
1970 return __ addr_at(entry_off);
1971 }
1972
1973 return NULL;
1974 }
1975
1976
1977 // Method entry for static native methods:
1978 // int java.util.zip.CRC32.updateBytes(int crc, byte[] b, int off, int len)
2015 __ z_agf(data, 2*wordSize, argP); // Add byte buffer offset.
2016 __ z_lgf(dataLen, 1*wordSize, argP); // #bytes to process
2017 } else { // Used for "updateBytes update".
2018 // crc @ (SP + 4W) (32bit)
2019 // buf @ (SP + 3W) (64bit ptr to byte array)
2020 // off @ (SP + 2W) (32bit)
2021 // dataLen @ (SP + 1W) (32bit)
2022 // data = buf + off + base_offset
2023 BLOCK_COMMENT("CRC32_updateBytes {");
2024 __ z_llgf(crc, 4*wordSize, argP); // current crc state
2025 __ z_lg(data, 3*wordSize, argP); // start of byte buffer
2026 __ z_agf(data, 2*wordSize, argP); // Add byte buffer offset.
2027 __ z_lgf(dataLen, 1*wordSize, argP); // #bytes to process
2028 __ z_aghi(data, arrayOopDesc::base_offset_in_bytes(T_BYTE));
2029 }
2030
2031 StubRoutines::zarch::generate_load_crc_table_addr(_masm, table);
2032
2033 __ resize_frame(-(6*8), Z_R0, true); // Resize frame to provide add'l space to spill 5 registers.
2034 __ z_stmg(t0, t3, 1*8, Z_SP); // Spill regs 10..13 to make them available as work registers.
2035 __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3, true);
2036 __ z_lmg(t0, t3, 1*8, Z_SP); // Spill regs 10..13 back from stack.
2037
2038 // Restore caller sp for c2i case.
2039 __ resize_frame_absolute(Z_R10, Z_R0, true); // Cut the stack back to where the caller started.
2040
2041 __ z_br(Z_R14);
2042
2043 BLOCK_COMMENT("} CRC32_update{Bytes|ByteBuffer}");
2044
2045 // Use a previously generated vanilla native entry as the slow path.
2046 BIND(slow_path);
2047 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native), Z_R1);
2048 return __ addr_at(entry_off);
2049 }
2050
2051 return NULL;
2052 }
2053
2054
2055 // Method entry for static native methods:
2056 // int java.util.zip.CRC32C.updateBytes(int crc, byte[] b, int off, int len)
2057 // int java.util.zip.CRC32C.updateDirectByteBuffer(int crc, long buf, int off, int len)
2058 address TemplateInterpreterGenerator::generate_CRC32C_updateBytes_entry(AbstractInterpreter::MethodKind kind) {
2059
2060 if (UseCRC32CIntrinsics) {
2061 uint64_t entry_off = __ offset();
2062
2063 // We don't generate local frame and don't align stack because
2064 // we call stub code and there is no safepoint on this path.
2065
2066 // Load parameters.
2067 // Z_esp is callers operand stack pointer, i.e. it points to the parameters.
2068 const Register argP = Z_esp;
2069 const Register crc = Z_ARG1; // crc value
2070 const Register data = Z_ARG2; // address of java byte array
2071 const Register dataLen = Z_ARG3; // source data len
2072 const Register table = Z_ARG4; // address of crc32 table
2073 const Register t0 = Z_R10; // work reg for kernel* emitters
2074 const Register t1 = Z_R11; // work reg for kernel* emitters
2075 const Register t2 = Z_R12; // work reg for kernel* emitters
2076 const Register t3 = Z_R13; // work reg for kernel* emitters
2077
2078 // Arguments are reversed on java expression stack.
2079 // Calculate address of start element.
2080 if (kind == Interpreter::java_util_zip_CRC32C_updateDirectByteBuffer) { // Used for "updateByteBuffer direct".
2081 // crc @ (SP + 5W) (32bit)
2082 // buf @ (SP + 3W) (64bit ptr to long array)
2083 // off @ (SP + 2W) (32bit)
2084 // dataLen @ (SP + 1W) (32bit)
2085 // data = buf + off
2086 BLOCK_COMMENT("CRC32C_updateDirectByteBuffer {");
2087 __ z_llgf(crc, 5*wordSize, argP); // current crc state
2088 __ z_lg(data, 3*wordSize, argP); // start of byte buffer
2089 __ z_agf(data, 2*wordSize, argP); // Add byte buffer offset.
2090 __ z_lgf(dataLen, 1*wordSize, argP); // #bytes to process
2091 } else { // Used for "updateBytes update".
2092 // crc @ (SP + 4W) (32bit)
2093 // buf @ (SP + 3W) (64bit ptr to byte array)
2094 // off @ (SP + 2W) (32bit)
2095 // dataLen @ (SP + 1W) (32bit)
2096 // data = buf + off + base_offset
2097 BLOCK_COMMENT("CRC32C_updateBytes {");
2098 __ z_llgf(crc, 4*wordSize, argP); // current crc state
2099 __ z_lg(data, 3*wordSize, argP); // start of byte buffer
2100 __ z_agf(data, 2*wordSize, argP); // Add byte buffer offset.
2101 __ z_lgf(dataLen, 1*wordSize, argP); // #bytes to process
2102 __ z_aghi(data, arrayOopDesc::base_offset_in_bytes(T_BYTE));
2103 }
2104
2105 StubRoutines::zarch::generate_load_crc32c_table_addr(_masm, table);
2106
2107 __ resize_frame(-(6*8), Z_R0, true); // Resize frame to provide add'l space to spill 5 registers.
2108 __ z_stmg(t0, t3, 1*8, Z_SP); // Spill regs 10..13 to make them available as work registers.
2109 __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3, false);
2110 __ z_lmg(t0, t3, 1*8, Z_SP); // Spill regs 10..13 back from stack.
2111
2112 // Restore caller sp for c2i case.
2113 __ resize_frame_absolute(Z_R10, Z_R0, true); // Cut the stack back to where the caller started.
2114
2115 __ z_br(Z_R14);
2116
2117 BLOCK_COMMENT("} CRC32C_update{Bytes|DirectByteBuffer}");
2118 return __ addr_at(entry_off);
2119 }
2120
2121 return NULL;
2122 }
2123
2124 void TemplateInterpreterGenerator::bang_stack_shadow_pages(bool native_call) {
2125 // Quick & dirty stack overflow checking: bang the stack & handle trap.
2126 // Note that we do the banging after the frame is setup, since the exception
2127 // handling code expects to find a valid interpreter frame on the stack.
2128 // Doing the banging earlier fails if the caller frame is not an interpreter
2129 // frame.
2130 // (Also, the exception throwing code expects to unlock any synchronized
2131 // method receiver, so do the banging after locking the receiver.)
2132
2133 // Bang each page in the shadow zone. We can't assume it's been done for
2134 // an interpreter frame with greater than a page of locals, so each page
2135 // needs to be checked. Only true for non-native. For native, we only bang the last page.
2136 if (UseStackBanging) {
2137 const int page_size = os::vm_page_size();
2138 const int n_shadow_pages = (int)(JavaThread::stack_shadow_zone_size()/page_size);
2139 const int start_page_num = native_call ? n_shadow_pages : 1;
2140 for (int pages = start_page_num; pages <= n_shadow_pages; pages++) {
|