hotspot/src/cpu/x86/vm/templateInterpreterGenerator_x86_64.cpp
changeset 34651 07b1cc0f6040
child 35214 d86005e0b4c2
equal deleted inserted replaced
34648:b7ea5d095ef5 34651:07b1cc0f6040
       
     1 /*
       
     2  * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  *
       
    23  */
       
    24 
       
    25 #include "precompiled.hpp"
       
    26 #include "asm/macroAssembler.hpp"
       
    27 #include "interpreter/interpreter.hpp"
       
    28 #include "interpreter/interpreterGenerator.hpp"
       
    29 #include "runtime/arguments.hpp"
       
    30 
       
    31 #define __ _masm->
       
    32 
       
    33 #ifndef CC_INTERP
       
    34 
       
    35 /**
       
    36  * Method entry for static native methods:
       
    37  *   int java.util.zip.CRC32.update(int crc, int b)
       
    38  */
       
    39 address InterpreterGenerator::generate_CRC32_update_entry() {
       
    40   if (UseCRC32Intrinsics) {
       
    41     address entry = __ pc();
       
    42 
       
    43     // rbx,: Method*
       
    44     // r13: senderSP must preserved for slow path, set SP to it on fast path
       
    45     // c_rarg0: scratch (rdi on non-Win64, rcx on Win64)
       
    46     // c_rarg1: scratch (rsi on non-Win64, rdx on Win64)
       
    47 
       
    48     Label slow_path;
       
    49     // If we need a safepoint check, generate full interpreter entry.
       
    50     ExternalAddress state(SafepointSynchronize::address_of_state());
       
    51     __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
       
    52              SafepointSynchronize::_not_synchronized);
       
    53     __ jcc(Assembler::notEqual, slow_path);
       
    54 
       
    55     // We don't generate local frame and don't align stack because
       
    56     // we call stub code and there is no safepoint on this path.
       
    57 
       
    58     // Load parameters
       
    59     const Register crc = rax;  // crc
       
    60     const Register val = c_rarg0;  // source java byte value
       
    61     const Register tbl = c_rarg1;  // scratch
       
    62 
       
    63     // Arguments are reversed on java expression stack
       
    64     __ movl(val, Address(rsp,   wordSize)); // byte value
       
    65     __ movl(crc, Address(rsp, 2*wordSize)); // Initial CRC
       
    66 
       
    67     __ lea(tbl, ExternalAddress(StubRoutines::crc_table_addr()));
       
    68     __ notl(crc); // ~crc
       
    69     __ update_byte_crc32(crc, val, tbl);
       
    70     __ notl(crc); // ~crc
       
    71     // result in rax
       
    72 
       
    73     // _areturn
       
    74     __ pop(rdi);                // get return address
       
    75     __ mov(rsp, r13);           // set sp to sender sp
       
    76     __ jmp(rdi);
       
    77 
       
    78     // generate a vanilla native entry as the slow path
       
    79     __ bind(slow_path);
       
    80     __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native));
       
    81     return entry;
       
    82   }
       
    83   return NULL;
       
    84 }
       
    85 
       
    86 /**
       
    87  * Method entry for static native methods:
       
    88  *   int java.util.zip.CRC32.updateBytes(int crc, byte[] b, int off, int len)
       
    89  *   int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len)
       
    90  */
       
    91 address InterpreterGenerator::generate_CRC32_updateBytes_entry(AbstractInterpreter::MethodKind kind) {
       
    92   if (UseCRC32Intrinsics) {
       
    93     address entry = __ pc();
       
    94 
       
    95     // rbx,: Method*
       
    96     // r13: senderSP must preserved for slow path, set SP to it on fast path
       
    97 
       
    98     Label slow_path;
       
    99     // If we need a safepoint check, generate full interpreter entry.
       
   100     ExternalAddress state(SafepointSynchronize::address_of_state());
       
   101     __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
       
   102              SafepointSynchronize::_not_synchronized);
       
   103     __ jcc(Assembler::notEqual, slow_path);
       
   104 
       
   105     // We don't generate local frame and don't align stack because
       
   106     // we call stub code and there is no safepoint on this path.
       
   107 
       
   108     // Load parameters
       
   109     const Register crc = c_rarg0;  // crc
       
   110     const Register buf = c_rarg1;  // source java byte array address
       
   111     const Register len = c_rarg2;  // length
       
   112     const Register off = len;      // offset (never overlaps with 'len')
       
   113 
       
   114     // Arguments are reversed on java expression stack
       
   115     // Calculate address of start element
       
   116     if (kind == Interpreter::java_util_zip_CRC32_updateByteBuffer) {
       
   117       __ movptr(buf, Address(rsp, 3*wordSize)); // long buf
       
   118       __ movl2ptr(off, Address(rsp, 2*wordSize)); // offset
       
   119       __ addq(buf, off); // + offset
       
   120       __ movl(crc,   Address(rsp, 5*wordSize)); // Initial CRC
       
   121     } else {
       
   122       __ movptr(buf, Address(rsp, 3*wordSize)); // byte[] array
       
   123       __ addptr(buf, arrayOopDesc::base_offset_in_bytes(T_BYTE)); // + header size
       
   124       __ movl2ptr(off, Address(rsp, 2*wordSize)); // offset
       
   125       __ addq(buf, off); // + offset
       
   126       __ movl(crc,   Address(rsp, 4*wordSize)); // Initial CRC
       
   127     }
       
   128     // Can now load 'len' since we're finished with 'off'
       
   129     __ movl(len, Address(rsp, wordSize)); // Length
       
   130 
       
   131     __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, StubRoutines::updateBytesCRC32()), crc, buf, len);
       
   132     // result in rax
       
   133 
       
   134     // _areturn
       
   135     __ pop(rdi);                // get return address
       
   136     __ mov(rsp, r13);           // set sp to sender sp
       
   137     __ jmp(rdi);
       
   138 
       
   139     // generate a vanilla native entry as the slow path
       
   140     __ bind(slow_path);
       
   141     __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native));
       
   142     return entry;
       
   143   }
       
   144   return NULL;
       
   145 }
       
   146 
       
   147 /**
       
   148 * Method entry for static native methods:
       
   149 *   int java.util.zip.CRC32C.updateBytes(int crc, byte[] b, int off, int end)
       
   150 *   int java.util.zip.CRC32C.updateByteBuffer(int crc, long address, int off, int end)
       
   151 */
       
   152 address InterpreterGenerator::generate_CRC32C_updateBytes_entry(AbstractInterpreter::MethodKind kind) {
       
   153   if (UseCRC32CIntrinsics) {
       
   154     address entry = __ pc();
       
   155     // Load parameters
       
   156     const Register crc = c_rarg0;  // crc
       
   157     const Register buf = c_rarg1;  // source java byte array address
       
   158     const Register len = c_rarg2;
       
   159     const Register off = c_rarg3;  // offset
       
   160     const Register end = len;
       
   161 
       
   162     // Arguments are reversed on java expression stack
       
   163     // Calculate address of start element
       
   164     if (kind == Interpreter::java_util_zip_CRC32C_updateDirectByteBuffer) {
       
   165       __ movptr(buf, Address(rsp, 3 * wordSize)); // long buf
       
   166       __ movl2ptr(off, Address(rsp, 2 * wordSize)); // offset
       
   167       __ addq(buf, off); // + offset
       
   168       __ movl(crc, Address(rsp, 5 * wordSize)); // Initial CRC
       
   169       // Note on 5 * wordSize vs. 4 * wordSize:
       
   170       // *   int java.util.zip.CRC32C.updateByteBuffer(int crc, long address, int off, int end)
       
   171       //                                                   4         2,3          1        0
       
   172       // end starts at SP + 8
       
   173       // The Java(R) Virtual Machine Specification Java SE 7 Edition
       
   174       // 4.10.2.3. Values of Types long and double
       
   175       //    "When calculating operand stack length, values of type long and double have length two."
       
   176     } else {
       
   177       __ movptr(buf, Address(rsp, 3 * wordSize)); // byte[] array
       
   178       __ addptr(buf, arrayOopDesc::base_offset_in_bytes(T_BYTE)); // + header size
       
   179       __ movl2ptr(off, Address(rsp, 2 * wordSize)); // offset
       
   180       __ addq(buf, off); // + offset
       
   181       __ movl(crc, Address(rsp, 4 * wordSize)); // Initial CRC
       
   182     }
       
   183     __ movl(end, Address(rsp, wordSize)); // end
       
   184     __ subl(end, off); // end - off
       
   185     __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, StubRoutines::updateBytesCRC32C()), crc, buf, len);
       
   186     // result in rax
       
   187     // _areturn
       
   188     __ pop(rdi);                // get return address
       
   189     __ mov(rsp, r13);           // set sp to sender sp
       
   190     __ jmp(rdi);
       
   191 
       
   192     return entry;
       
   193   }
       
   194 
       
   195   return NULL;
       
   196 }
       
   197 #endif // ! CC_INTERP