aoqi@0: /* aoqi@0: * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "asm/macroAssembler.hpp" aoqi@0: #include "asm/macroAssembler.inline.hpp" aoqi@0: #include "interpreter/interpreter.hpp" aoqi@0: #include "nativeInst_x86.hpp" aoqi@0: #include "oops/instanceOop.hpp" aoqi@0: #include "oops/method.hpp" aoqi@0: #include "oops/objArrayKlass.hpp" aoqi@0: #include "oops/oop.inline.hpp" aoqi@0: #include "prims/methodHandles.hpp" aoqi@0: #include "runtime/frame.inline.hpp" aoqi@0: #include "runtime/handles.inline.hpp" aoqi@0: #include "runtime/sharedRuntime.hpp" aoqi@0: #include "runtime/stubCodeGenerator.hpp" aoqi@0: #include "runtime/stubRoutines.hpp" aoqi@0: #include "runtime/thread.inline.hpp" aoqi@0: #include "utilities/top.hpp" aoqi@0: #ifdef COMPILER2 aoqi@0: #include "opto/runtime.hpp" aoqi@0: #endif aoqi@0: aoqi@0: // Declaration and definition of StubGenerator (no .hpp file). aoqi@0: // For a more detailed description of the stub routine structure aoqi@0: // see the comment in stubRoutines.hpp aoqi@0: aoqi@0: #define __ _masm-> aoqi@0: #define TIMES_OOP (UseCompressedOops ? Address::times_4 : Address::times_8) aoqi@0: #define a__ ((Assembler*)_masm)-> aoqi@0: aoqi@0: #ifdef PRODUCT aoqi@0: #define BLOCK_COMMENT(str) /* nothing */ aoqi@0: #else aoqi@0: #define BLOCK_COMMENT(str) __ block_comment(str) aoqi@0: #endif aoqi@0: aoqi@0: #define BIND(label) bind(label); BLOCK_COMMENT(#label ":") aoqi@0: const int MXCSR_MASK = 0xFFC0; // Mask out any pending exceptions aoqi@0: aoqi@0: // Stub Code definitions aoqi@0: aoqi@0: static address handle_unsafe_access() { aoqi@0: JavaThread* thread = JavaThread::current(); aoqi@0: address pc = thread->saved_exception_pc(); aoqi@0: // pc is the instruction which we must emulate aoqi@0: // doing a no-op is fine: return garbage from the load aoqi@0: // therefore, compute npc aoqi@0: address npc = Assembler::locate_next_instruction(pc); aoqi@0: aoqi@0: // request an async exception aoqi@0: thread->set_pending_unsafe_access_error(); aoqi@0: aoqi@0: // return address of next instruction to execute aoqi@0: return npc; aoqi@0: } aoqi@0: aoqi@0: class StubGenerator: public StubCodeGenerator { aoqi@0: private: aoqi@0: aoqi@0: #ifdef PRODUCT aoqi@0: #define inc_counter_np(counter) ((void)0) aoqi@0: #else aoqi@0: void inc_counter_np_(int& counter) { aoqi@0: // This can destroy rscratch1 if counter is far from the code cache aoqi@0: __ incrementl(ExternalAddress((address)&counter)); aoqi@0: } aoqi@0: #define inc_counter_np(counter) \ aoqi@0: BLOCK_COMMENT("inc_counter " #counter); \ aoqi@0: inc_counter_np_(counter); aoqi@0: #endif aoqi@0: aoqi@0: // Call stubs are used to call Java from C aoqi@0: // aoqi@0: // Linux Arguments: aoqi@0: // c_rarg0: call wrapper address address aoqi@0: // c_rarg1: result address aoqi@0: // c_rarg2: result type BasicType aoqi@0: // c_rarg3: method Method* aoqi@0: // c_rarg4: (interpreter) entry point address aoqi@0: // c_rarg5: parameters intptr_t* aoqi@0: // 16(rbp): parameter size (in words) int aoqi@0: // 24(rbp): thread Thread* aoqi@0: // aoqi@0: // [ return_from_Java ] <--- rsp aoqi@0: // [ argument word n ] aoqi@0: // ... aoqi@0: // -12 [ argument word 1 ] aoqi@0: // -11 [ saved r15 ] <--- rsp_after_call aoqi@0: // -10 [ saved r14 ] aoqi@0: // -9 [ saved r13 ] aoqi@0: // -8 [ saved r12 ] aoqi@0: // -7 [ saved rbx ] aoqi@0: // -6 [ call wrapper ] aoqi@0: // -5 [ result ] aoqi@0: // -4 [ result type ] aoqi@0: // -3 [ method ] aoqi@0: // -2 [ entry point ] aoqi@0: // -1 [ parameters ] aoqi@0: // 0 [ saved rbp ] <--- rbp aoqi@0: // 1 [ return address ] aoqi@0: // 2 [ parameter size ] aoqi@0: // 3 [ thread ] aoqi@0: // aoqi@0: // Windows Arguments: aoqi@0: // c_rarg0: call wrapper address address aoqi@0: // c_rarg1: result address aoqi@0: // c_rarg2: result type BasicType aoqi@0: // c_rarg3: method Method* aoqi@0: // 48(rbp): (interpreter) entry point address aoqi@0: // 56(rbp): parameters intptr_t* aoqi@0: // 64(rbp): parameter size (in words) int aoqi@0: // 72(rbp): thread Thread* aoqi@0: // aoqi@0: // [ return_from_Java ] <--- rsp aoqi@0: // [ argument word n ] aoqi@0: // ... aoqi@0: // -28 [ argument word 1 ] aoqi@0: // -27 [ saved xmm15 ] <--- rsp_after_call aoqi@0: // [ saved xmm7-xmm14 ] aoqi@0: // -9 [ saved xmm6 ] (each xmm register takes 2 slots) aoqi@0: // -7 [ saved r15 ] aoqi@0: // -6 [ saved r14 ] aoqi@0: // -5 [ saved r13 ] aoqi@0: // -4 [ saved r12 ] aoqi@0: // -3 [ saved rdi ] aoqi@0: // -2 [ saved rsi ] aoqi@0: // -1 [ saved rbx ] aoqi@0: // 0 [ saved rbp ] <--- rbp aoqi@0: // 1 [ return address ] aoqi@0: // 2 [ call wrapper ] aoqi@0: // 3 [ result ] aoqi@0: // 4 [ result type ] aoqi@0: // 5 [ method ] aoqi@0: // 6 [ entry point ] aoqi@0: // 7 [ parameters ] aoqi@0: // 8 [ parameter size ] aoqi@0: // 9 [ thread ] aoqi@0: // aoqi@0: // Windows reserves the callers stack space for arguments 1-4. aoqi@0: // We spill c_rarg0-c_rarg3 to this space. aoqi@0: aoqi@0: // Call stub stack layout word offsets from rbp aoqi@0: enum call_stub_layout { aoqi@0: #ifdef _WIN64 aoqi@0: xmm_save_first = 6, // save from xmm6 aoqi@0: xmm_save_last = 15, // to xmm15 aoqi@0: xmm_save_base = -9, aoqi@0: rsp_after_call_off = xmm_save_base - 2 * (xmm_save_last - xmm_save_first), // -27 aoqi@0: r15_off = -7, aoqi@0: r14_off = -6, aoqi@0: r13_off = -5, aoqi@0: r12_off = -4, aoqi@0: rdi_off = -3, aoqi@0: rsi_off = -2, aoqi@0: rbx_off = -1, aoqi@0: rbp_off = 0, aoqi@0: retaddr_off = 1, aoqi@0: call_wrapper_off = 2, aoqi@0: result_off = 3, aoqi@0: result_type_off = 4, aoqi@0: method_off = 5, aoqi@0: entry_point_off = 6, aoqi@0: parameters_off = 7, aoqi@0: parameter_size_off = 8, aoqi@0: thread_off = 9 aoqi@0: #else aoqi@0: rsp_after_call_off = -12, aoqi@0: mxcsr_off = rsp_after_call_off, aoqi@0: r15_off = -11, aoqi@0: r14_off = -10, aoqi@0: r13_off = -9, aoqi@0: r12_off = -8, aoqi@0: rbx_off = -7, aoqi@0: call_wrapper_off = -6, aoqi@0: result_off = -5, aoqi@0: result_type_off = -4, aoqi@0: method_off = -3, aoqi@0: entry_point_off = -2, aoqi@0: parameters_off = -1, aoqi@0: rbp_off = 0, aoqi@0: retaddr_off = 1, aoqi@0: parameter_size_off = 2, aoqi@0: thread_off = 3 aoqi@0: #endif aoqi@0: }; aoqi@0: aoqi@0: #ifdef _WIN64 aoqi@0: Address xmm_save(int reg) { aoqi@0: assert(reg >= xmm_save_first && reg <= xmm_save_last, "XMM register number out of range"); aoqi@0: return Address(rbp, (xmm_save_base - (reg - xmm_save_first) * 2) * wordSize); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: address generate_call_stub(address& return_address) { aoqi@0: assert((int)frame::entry_frame_after_call_words == -(int)rsp_after_call_off + 1 && aoqi@0: (int)frame::entry_frame_call_wrapper_offset == (int)call_wrapper_off, aoqi@0: "adjust this code"); aoqi@0: StubCodeMark mark(this, "StubRoutines", "call_stub"); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: // same as in generate_catch_exception()! aoqi@0: const Address rsp_after_call(rbp, rsp_after_call_off * wordSize); aoqi@0: aoqi@0: const Address call_wrapper (rbp, call_wrapper_off * wordSize); aoqi@0: const Address result (rbp, result_off * wordSize); aoqi@0: const Address result_type (rbp, result_type_off * wordSize); aoqi@0: const Address method (rbp, method_off * wordSize); aoqi@0: const Address entry_point (rbp, entry_point_off * wordSize); aoqi@0: const Address parameters (rbp, parameters_off * wordSize); aoqi@0: const Address parameter_size(rbp, parameter_size_off * wordSize); aoqi@0: aoqi@0: // same as in generate_catch_exception()! aoqi@0: const Address thread (rbp, thread_off * wordSize); aoqi@0: aoqi@0: const Address r15_save(rbp, r15_off * wordSize); aoqi@0: const Address r14_save(rbp, r14_off * wordSize); aoqi@0: const Address r13_save(rbp, r13_off * wordSize); aoqi@0: const Address r12_save(rbp, r12_off * wordSize); aoqi@0: const Address rbx_save(rbp, rbx_off * wordSize); aoqi@0: aoqi@0: // stub code aoqi@0: __ enter(); aoqi@0: __ subptr(rsp, -rsp_after_call_off * wordSize); aoqi@0: aoqi@0: // save register parameters aoqi@0: #ifndef _WIN64 aoqi@0: __ movptr(parameters, c_rarg5); // parameters aoqi@0: __ movptr(entry_point, c_rarg4); // entry_point aoqi@0: #endif aoqi@0: aoqi@0: __ movptr(method, c_rarg3); // method aoqi@0: __ movl(result_type, c_rarg2); // result type aoqi@0: __ movptr(result, c_rarg1); // result aoqi@0: __ movptr(call_wrapper, c_rarg0); // call wrapper aoqi@0: aoqi@0: // save regs belonging to calling function aoqi@0: __ movptr(rbx_save, rbx); aoqi@0: __ movptr(r12_save, r12); aoqi@0: __ movptr(r13_save, r13); aoqi@0: __ movptr(r14_save, r14); aoqi@0: __ movptr(r15_save, r15); aoqi@0: #ifdef _WIN64 aoqi@0: for (int i = 6; i <= 15; i++) { aoqi@0: __ movdqu(xmm_save(i), as_XMMRegister(i)); aoqi@0: } aoqi@0: aoqi@0: const Address rdi_save(rbp, rdi_off * wordSize); aoqi@0: const Address rsi_save(rbp, rsi_off * wordSize); aoqi@0: aoqi@0: __ movptr(rsi_save, rsi); aoqi@0: __ movptr(rdi_save, rdi); aoqi@0: #else aoqi@0: const Address mxcsr_save(rbp, mxcsr_off * wordSize); aoqi@0: { aoqi@0: Label skip_ldmx; aoqi@0: __ stmxcsr(mxcsr_save); aoqi@0: __ movl(rax, mxcsr_save); aoqi@0: __ andl(rax, MXCSR_MASK); // Only check control and mask bits aoqi@0: ExternalAddress mxcsr_std(StubRoutines::addr_mxcsr_std()); aoqi@0: __ cmp32(rax, mxcsr_std); aoqi@0: __ jcc(Assembler::equal, skip_ldmx); aoqi@0: __ ldmxcsr(mxcsr_std); aoqi@0: __ bind(skip_ldmx); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // Load up thread register aoqi@0: __ movptr(r15_thread, thread); aoqi@0: __ reinit_heapbase(); aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: // make sure we have no pending exceptions aoqi@0: { aoqi@0: Label L; aoqi@0: __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD); aoqi@0: __ jcc(Assembler::equal, L); aoqi@0: __ stop("StubRoutines::call_stub: entered with pending exception"); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // pass parameters if any aoqi@0: BLOCK_COMMENT("pass parameters if any"); aoqi@0: Label parameters_done; aoqi@0: __ movl(c_rarg3, parameter_size); aoqi@0: __ testl(c_rarg3, c_rarg3); aoqi@0: __ jcc(Assembler::zero, parameters_done); aoqi@0: aoqi@0: Label loop; aoqi@0: __ movptr(c_rarg2, parameters); // parameter pointer aoqi@0: __ movl(c_rarg1, c_rarg3); // parameter counter is in c_rarg1 aoqi@0: __ BIND(loop); aoqi@0: __ movptr(rax, Address(c_rarg2, 0));// get parameter aoqi@0: __ addptr(c_rarg2, wordSize); // advance to next parameter aoqi@0: __ decrementl(c_rarg1); // decrement counter aoqi@0: __ push(rax); // pass parameter aoqi@0: __ jcc(Assembler::notZero, loop); aoqi@0: aoqi@0: // call Java function aoqi@0: __ BIND(parameters_done); aoqi@0: __ movptr(rbx, method); // get Method* aoqi@0: __ movptr(c_rarg1, entry_point); // get entry_point aoqi@0: __ mov(r13, rsp); // set sender sp aoqi@0: BLOCK_COMMENT("call Java function"); aoqi@0: __ call(c_rarg1); aoqi@0: aoqi@0: BLOCK_COMMENT("call_stub_return_address:"); aoqi@0: return_address = __ pc(); aoqi@0: aoqi@0: // store result depending on type (everything that is not aoqi@0: // T_OBJECT, T_LONG, T_FLOAT or T_DOUBLE is treated as T_INT) aoqi@0: __ movptr(c_rarg0, result); aoqi@0: Label is_long, is_float, is_double, exit; aoqi@0: __ movl(c_rarg1, result_type); aoqi@0: __ cmpl(c_rarg1, T_OBJECT); aoqi@0: __ jcc(Assembler::equal, is_long); aoqi@0: __ cmpl(c_rarg1, T_LONG); aoqi@0: __ jcc(Assembler::equal, is_long); aoqi@0: __ cmpl(c_rarg1, T_FLOAT); aoqi@0: __ jcc(Assembler::equal, is_float); aoqi@0: __ cmpl(c_rarg1, T_DOUBLE); aoqi@0: __ jcc(Assembler::equal, is_double); aoqi@0: aoqi@0: // handle T_INT case aoqi@0: __ movl(Address(c_rarg0, 0), rax); aoqi@0: aoqi@0: __ BIND(exit); aoqi@0: aoqi@0: // pop parameters aoqi@0: __ lea(rsp, rsp_after_call); aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: // verify that threads correspond aoqi@0: { aoqi@0: Label L, S; aoqi@0: __ cmpptr(r15_thread, thread); aoqi@0: __ jcc(Assembler::notEqual, S); aoqi@0: __ get_thread(rbx); aoqi@0: __ cmpptr(r15_thread, rbx); aoqi@0: __ jcc(Assembler::equal, L); aoqi@0: __ bind(S); aoqi@0: __ jcc(Assembler::equal, L); aoqi@0: __ stop("StubRoutines::call_stub: threads must correspond"); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // restore regs belonging to calling function aoqi@0: #ifdef _WIN64 aoqi@0: for (int i = 15; i >= 6; i--) { aoqi@0: __ movdqu(as_XMMRegister(i), xmm_save(i)); aoqi@0: } aoqi@0: #endif aoqi@0: __ movptr(r15, r15_save); aoqi@0: __ movptr(r14, r14_save); aoqi@0: __ movptr(r13, r13_save); aoqi@0: __ movptr(r12, r12_save); aoqi@0: __ movptr(rbx, rbx_save); aoqi@0: aoqi@0: #ifdef _WIN64 aoqi@0: __ movptr(rdi, rdi_save); aoqi@0: __ movptr(rsi, rsi_save); aoqi@0: #else aoqi@0: __ ldmxcsr(mxcsr_save); aoqi@0: #endif aoqi@0: aoqi@0: // restore rsp aoqi@0: __ addptr(rsp, -rsp_after_call_off * wordSize); aoqi@0: aoqi@0: // return aoqi@0: __ pop(rbp); aoqi@0: __ ret(0); aoqi@0: aoqi@0: // handle return types different from T_INT aoqi@0: __ BIND(is_long); aoqi@0: __ movq(Address(c_rarg0, 0), rax); aoqi@0: __ jmp(exit); aoqi@0: aoqi@0: __ BIND(is_float); aoqi@0: __ movflt(Address(c_rarg0, 0), xmm0); aoqi@0: __ jmp(exit); aoqi@0: aoqi@0: __ BIND(is_double); aoqi@0: __ movdbl(Address(c_rarg0, 0), xmm0); aoqi@0: __ jmp(exit); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Return point for a Java call if there's an exception thrown in aoqi@0: // Java code. The exception is caught and transformed into a aoqi@0: // pending exception stored in JavaThread that can be tested from aoqi@0: // within the VM. aoqi@0: // aoqi@0: // Note: Usually the parameters are removed by the callee. In case aoqi@0: // of an exception crossing an activation frame boundary, that is aoqi@0: // not the case if the callee is compiled code => need to setup the aoqi@0: // rsp. aoqi@0: // aoqi@0: // rax: exception oop aoqi@0: aoqi@0: address generate_catch_exception() { aoqi@0: StubCodeMark mark(this, "StubRoutines", "catch_exception"); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: // same as in generate_call_stub(): aoqi@0: const Address rsp_after_call(rbp, rsp_after_call_off * wordSize); aoqi@0: const Address thread (rbp, thread_off * wordSize); aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: // verify that threads correspond aoqi@0: { aoqi@0: Label L, S; aoqi@0: __ cmpptr(r15_thread, thread); aoqi@0: __ jcc(Assembler::notEqual, S); aoqi@0: __ get_thread(rbx); aoqi@0: __ cmpptr(r15_thread, rbx); aoqi@0: __ jcc(Assembler::equal, L); aoqi@0: __ bind(S); aoqi@0: __ stop("StubRoutines::catch_exception: threads must correspond"); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // set pending exception aoqi@0: __ verify_oop(rax); aoqi@0: aoqi@0: __ movptr(Address(r15_thread, Thread::pending_exception_offset()), rax); aoqi@0: __ lea(rscratch1, ExternalAddress((address)__FILE__)); aoqi@0: __ movptr(Address(r15_thread, Thread::exception_file_offset()), rscratch1); aoqi@0: __ movl(Address(r15_thread, Thread::exception_line_offset()), (int) __LINE__); aoqi@0: aoqi@0: // complete return to VM aoqi@0: assert(StubRoutines::_call_stub_return_address != NULL, aoqi@0: "_call_stub_return_address must have been generated before"); aoqi@0: __ jump(RuntimeAddress(StubRoutines::_call_stub_return_address)); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Continuation point for runtime calls returning with a pending aoqi@0: // exception. The pending exception check happened in the runtime aoqi@0: // or native call stub. The pending exception in Thread is aoqi@0: // converted into a Java-level exception. aoqi@0: // aoqi@0: // Contract with Java-level exception handlers: aoqi@0: // rax: exception aoqi@0: // rdx: throwing pc aoqi@0: // aoqi@0: // NOTE: At entry of this stub, exception-pc must be on stack !! aoqi@0: aoqi@0: address generate_forward_exception() { aoqi@0: StubCodeMark mark(this, "StubRoutines", "forward exception"); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: // Upon entry, the sp points to the return address returning into aoqi@0: // Java (interpreted or compiled) code; i.e., the return address aoqi@0: // becomes the throwing pc. aoqi@0: // aoqi@0: // Arguments pushed before the runtime call are still on the stack aoqi@0: // but the exception handler will reset the stack pointer -> aoqi@0: // ignore them. A potential result in registers can be ignored as aoqi@0: // well. aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: // make sure this code is only executed if there is a pending exception aoqi@0: { aoqi@0: Label L; aoqi@0: __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t) NULL); aoqi@0: __ jcc(Assembler::notEqual, L); aoqi@0: __ stop("StubRoutines::forward exception: no pending exception (1)"); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // compute exception handler into rbx aoqi@0: __ movptr(c_rarg0, Address(rsp, 0)); aoqi@0: BLOCK_COMMENT("call exception_handler_for_return_address"); aoqi@0: __ call_VM_leaf(CAST_FROM_FN_PTR(address, aoqi@0: SharedRuntime::exception_handler_for_return_address), aoqi@0: r15_thread, c_rarg0); aoqi@0: __ mov(rbx, rax); aoqi@0: aoqi@0: // setup rax & rdx, remove return address & clear pending exception aoqi@0: __ pop(rdx); aoqi@0: __ movptr(rax, Address(r15_thread, Thread::pending_exception_offset())); aoqi@0: __ movptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD); aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: // make sure exception is set aoqi@0: { aoqi@0: Label L; aoqi@0: __ testptr(rax, rax); aoqi@0: __ jcc(Assembler::notEqual, L); aoqi@0: __ stop("StubRoutines::forward exception: no pending exception (2)"); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // continue at exception handler (return address removed) aoqi@0: // rax: exception aoqi@0: // rbx: exception handler aoqi@0: // rdx: throwing pc aoqi@0: __ verify_oop(rax); aoqi@0: __ jmp(rbx); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Support for jint atomic::xchg(jint exchange_value, volatile jint* dest) aoqi@0: // aoqi@0: // Arguments : aoqi@0: // c_rarg0: exchange_value aoqi@0: // c_rarg0: dest aoqi@0: // aoqi@0: // Result: aoqi@0: // *dest <- ex, return (orig *dest) aoqi@0: address generate_atomic_xchg() { aoqi@0: StubCodeMark mark(this, "StubRoutines", "atomic_xchg"); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: __ movl(rax, c_rarg0); // Copy to eax we need a return value anyhow aoqi@0: __ xchgl(rax, Address(c_rarg1, 0)); // automatic LOCK aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Support for intptr_t atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) aoqi@0: // aoqi@0: // Arguments : aoqi@0: // c_rarg0: exchange_value aoqi@0: // c_rarg1: dest aoqi@0: // aoqi@0: // Result: aoqi@0: // *dest <- ex, return (orig *dest) aoqi@0: address generate_atomic_xchg_ptr() { aoqi@0: StubCodeMark mark(this, "StubRoutines", "atomic_xchg_ptr"); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: __ movptr(rax, c_rarg0); // Copy to eax we need a return value anyhow aoqi@0: __ xchgptr(rax, Address(c_rarg1, 0)); // automatic LOCK aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Support for jint atomic::atomic_cmpxchg(jint exchange_value, volatile jint* dest, aoqi@0: // jint compare_value) aoqi@0: // aoqi@0: // Arguments : aoqi@0: // c_rarg0: exchange_value aoqi@0: // c_rarg1: dest aoqi@0: // c_rarg2: compare_value aoqi@0: // aoqi@0: // Result: aoqi@0: // if ( compare_value == *dest ) { aoqi@0: // *dest = exchange_value aoqi@0: // return compare_value; aoqi@0: // else aoqi@0: // return *dest; aoqi@0: address generate_atomic_cmpxchg() { aoqi@0: StubCodeMark mark(this, "StubRoutines", "atomic_cmpxchg"); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: __ movl(rax, c_rarg2); aoqi@0: if ( os::is_MP() ) __ lock(); aoqi@0: __ cmpxchgl(c_rarg0, Address(c_rarg1, 0)); aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Support for jint atomic::atomic_cmpxchg_long(jlong exchange_value, aoqi@0: // volatile jlong* dest, aoqi@0: // jlong compare_value) aoqi@0: // Arguments : aoqi@0: // c_rarg0: exchange_value aoqi@0: // c_rarg1: dest aoqi@0: // c_rarg2: compare_value aoqi@0: // aoqi@0: // Result: aoqi@0: // if ( compare_value == *dest ) { aoqi@0: // *dest = exchange_value aoqi@0: // return compare_value; aoqi@0: // else aoqi@0: // return *dest; aoqi@0: address generate_atomic_cmpxchg_long() { aoqi@0: StubCodeMark mark(this, "StubRoutines", "atomic_cmpxchg_long"); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: __ movq(rax, c_rarg2); aoqi@0: if ( os::is_MP() ) __ lock(); aoqi@0: __ cmpxchgq(c_rarg0, Address(c_rarg1, 0)); aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Support for jint atomic::add(jint add_value, volatile jint* dest) aoqi@0: // aoqi@0: // Arguments : aoqi@0: // c_rarg0: add_value aoqi@0: // c_rarg1: dest aoqi@0: // aoqi@0: // Result: aoqi@0: // *dest += add_value aoqi@0: // return *dest; aoqi@0: address generate_atomic_add() { aoqi@0: StubCodeMark mark(this, "StubRoutines", "atomic_add"); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: __ movl(rax, c_rarg0); aoqi@0: if ( os::is_MP() ) __ lock(); aoqi@0: __ xaddl(Address(c_rarg1, 0), c_rarg0); aoqi@0: __ addl(rax, c_rarg0); aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Support for intptr_t atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) aoqi@0: // aoqi@0: // Arguments : aoqi@0: // c_rarg0: add_value aoqi@0: // c_rarg1: dest aoqi@0: // aoqi@0: // Result: aoqi@0: // *dest += add_value aoqi@0: // return *dest; aoqi@0: address generate_atomic_add_ptr() { aoqi@0: StubCodeMark mark(this, "StubRoutines", "atomic_add_ptr"); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: __ movptr(rax, c_rarg0); // Copy to eax we need a return value anyhow aoqi@0: if ( os::is_MP() ) __ lock(); aoqi@0: __ xaddptr(Address(c_rarg1, 0), c_rarg0); aoqi@0: __ addptr(rax, c_rarg0); aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Support for intptr_t OrderAccess::fence() aoqi@0: // aoqi@0: // Arguments : aoqi@0: // aoqi@0: // Result: aoqi@0: address generate_orderaccess_fence() { aoqi@0: StubCodeMark mark(this, "StubRoutines", "orderaccess_fence"); aoqi@0: address start = __ pc(); aoqi@0: __ membar(Assembler::StoreLoad); aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Support for intptr_t get_previous_fp() aoqi@0: // aoqi@0: // This routine is used to find the previous frame pointer for the aoqi@0: // caller (current_frame_guess). This is used as part of debugging aoqi@0: // ps() is seemingly lost trying to find frames. aoqi@0: // This code assumes that caller current_frame_guess) has a frame. aoqi@0: address generate_get_previous_fp() { aoqi@0: StubCodeMark mark(this, "StubRoutines", "get_previous_fp"); aoqi@0: const Address old_fp(rbp, 0); aoqi@0: const Address older_fp(rax, 0); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: __ enter(); aoqi@0: __ movptr(rax, old_fp); // callers fp aoqi@0: __ movptr(rax, older_fp); // the frame for ps() aoqi@0: __ pop(rbp); aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Support for intptr_t get_previous_sp() aoqi@0: // aoqi@0: // This routine is used to find the previous stack pointer for the aoqi@0: // caller. aoqi@0: address generate_get_previous_sp() { aoqi@0: StubCodeMark mark(this, "StubRoutines", "get_previous_sp"); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: __ movptr(rax, rsp); aoqi@0: __ addptr(rax, 8); // return address is at the top of the stack. aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: //---------------------------------------------------------------------------------------------------- aoqi@0: // Support for void verify_mxcsr() aoqi@0: // aoqi@0: // This routine is used with -Xcheck:jni to verify that native aoqi@0: // JNI code does not return to Java code without restoring the aoqi@0: // MXCSR register to our expected state. aoqi@0: aoqi@0: address generate_verify_mxcsr() { aoqi@0: StubCodeMark mark(this, "StubRoutines", "verify_mxcsr"); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: const Address mxcsr_save(rsp, 0); aoqi@0: aoqi@0: if (CheckJNICalls) { aoqi@0: Label ok_ret; aoqi@0: ExternalAddress mxcsr_std(StubRoutines::addr_mxcsr_std()); aoqi@0: __ push(rax); aoqi@0: __ subptr(rsp, wordSize); // allocate a temp location aoqi@0: __ stmxcsr(mxcsr_save); aoqi@0: __ movl(rax, mxcsr_save); aoqi@0: __ andl(rax, MXCSR_MASK); // Only check control and mask bits aoqi@0: __ cmp32(rax, mxcsr_std); aoqi@0: __ jcc(Assembler::equal, ok_ret); aoqi@0: aoqi@0: __ warn("MXCSR changed by native JNI code, use -XX:+RestoreMXCSROnJNICall"); aoqi@0: aoqi@0: __ ldmxcsr(mxcsr_std); aoqi@0: aoqi@0: __ bind(ok_ret); aoqi@0: __ addptr(rsp, wordSize); aoqi@0: __ pop(rax); aoqi@0: } aoqi@0: aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: address generate_f2i_fixup() { aoqi@0: StubCodeMark mark(this, "StubRoutines", "f2i_fixup"); aoqi@0: Address inout(rsp, 5 * wordSize); // return address + 4 saves aoqi@0: aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: Label L; aoqi@0: aoqi@0: __ push(rax); aoqi@0: __ push(c_rarg3); aoqi@0: __ push(c_rarg2); aoqi@0: __ push(c_rarg1); aoqi@0: aoqi@0: __ movl(rax, 0x7f800000); aoqi@0: __ xorl(c_rarg3, c_rarg3); aoqi@0: __ movl(c_rarg2, inout); aoqi@0: __ movl(c_rarg1, c_rarg2); aoqi@0: __ andl(c_rarg1, 0x7fffffff); aoqi@0: __ cmpl(rax, c_rarg1); // NaN? -> 0 aoqi@0: __ jcc(Assembler::negative, L); aoqi@0: __ testl(c_rarg2, c_rarg2); // signed ? min_jint : max_jint aoqi@0: __ movl(c_rarg3, 0x80000000); aoqi@0: __ movl(rax, 0x7fffffff); aoqi@0: __ cmovl(Assembler::positive, c_rarg3, rax); aoqi@0: aoqi@0: __ bind(L); aoqi@0: __ movptr(inout, c_rarg3); aoqi@0: aoqi@0: __ pop(c_rarg1); aoqi@0: __ pop(c_rarg2); aoqi@0: __ pop(c_rarg3); aoqi@0: __ pop(rax); aoqi@0: aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: address generate_f2l_fixup() { aoqi@0: StubCodeMark mark(this, "StubRoutines", "f2l_fixup"); aoqi@0: Address inout(rsp, 5 * wordSize); // return address + 4 saves aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: Label L; aoqi@0: aoqi@0: __ push(rax); aoqi@0: __ push(c_rarg3); aoqi@0: __ push(c_rarg2); aoqi@0: __ push(c_rarg1); aoqi@0: aoqi@0: __ movl(rax, 0x7f800000); aoqi@0: __ xorl(c_rarg3, c_rarg3); aoqi@0: __ movl(c_rarg2, inout); aoqi@0: __ movl(c_rarg1, c_rarg2); aoqi@0: __ andl(c_rarg1, 0x7fffffff); aoqi@0: __ cmpl(rax, c_rarg1); // NaN? -> 0 aoqi@0: __ jcc(Assembler::negative, L); aoqi@0: __ testl(c_rarg2, c_rarg2); // signed ? min_jlong : max_jlong aoqi@0: __ mov64(c_rarg3, 0x8000000000000000); aoqi@0: __ mov64(rax, 0x7fffffffffffffff); aoqi@0: __ cmov(Assembler::positive, c_rarg3, rax); aoqi@0: aoqi@0: __ bind(L); aoqi@0: __ movptr(inout, c_rarg3); aoqi@0: aoqi@0: __ pop(c_rarg1); aoqi@0: __ pop(c_rarg2); aoqi@0: __ pop(c_rarg3); aoqi@0: __ pop(rax); aoqi@0: aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: address generate_d2i_fixup() { aoqi@0: StubCodeMark mark(this, "StubRoutines", "d2i_fixup"); aoqi@0: Address inout(rsp, 6 * wordSize); // return address + 5 saves aoqi@0: aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: Label L; aoqi@0: aoqi@0: __ push(rax); aoqi@0: __ push(c_rarg3); aoqi@0: __ push(c_rarg2); aoqi@0: __ push(c_rarg1); aoqi@0: __ push(c_rarg0); aoqi@0: aoqi@0: __ movl(rax, 0x7ff00000); aoqi@0: __ movq(c_rarg2, inout); aoqi@0: __ movl(c_rarg3, c_rarg2); aoqi@0: __ mov(c_rarg1, c_rarg2); aoqi@0: __ mov(c_rarg0, c_rarg2); aoqi@0: __ negl(c_rarg3); aoqi@0: __ shrptr(c_rarg1, 0x20); aoqi@0: __ orl(c_rarg3, c_rarg2); aoqi@0: __ andl(c_rarg1, 0x7fffffff); aoqi@0: __ xorl(c_rarg2, c_rarg2); aoqi@0: __ shrl(c_rarg3, 0x1f); aoqi@0: __ orl(c_rarg1, c_rarg3); aoqi@0: __ cmpl(rax, c_rarg1); aoqi@0: __ jcc(Assembler::negative, L); // NaN -> 0 aoqi@0: __ testptr(c_rarg0, c_rarg0); // signed ? min_jint : max_jint aoqi@0: __ movl(c_rarg2, 0x80000000); aoqi@0: __ movl(rax, 0x7fffffff); aoqi@0: __ cmov(Assembler::positive, c_rarg2, rax); aoqi@0: aoqi@0: __ bind(L); aoqi@0: __ movptr(inout, c_rarg2); aoqi@0: aoqi@0: __ pop(c_rarg0); aoqi@0: __ pop(c_rarg1); aoqi@0: __ pop(c_rarg2); aoqi@0: __ pop(c_rarg3); aoqi@0: __ pop(rax); aoqi@0: aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: address generate_d2l_fixup() { aoqi@0: StubCodeMark mark(this, "StubRoutines", "d2l_fixup"); aoqi@0: Address inout(rsp, 6 * wordSize); // return address + 5 saves aoqi@0: aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: Label L; aoqi@0: aoqi@0: __ push(rax); aoqi@0: __ push(c_rarg3); aoqi@0: __ push(c_rarg2); aoqi@0: __ push(c_rarg1); aoqi@0: __ push(c_rarg0); aoqi@0: aoqi@0: __ movl(rax, 0x7ff00000); aoqi@0: __ movq(c_rarg2, inout); aoqi@0: __ movl(c_rarg3, c_rarg2); aoqi@0: __ mov(c_rarg1, c_rarg2); aoqi@0: __ mov(c_rarg0, c_rarg2); aoqi@0: __ negl(c_rarg3); aoqi@0: __ shrptr(c_rarg1, 0x20); aoqi@0: __ orl(c_rarg3, c_rarg2); aoqi@0: __ andl(c_rarg1, 0x7fffffff); aoqi@0: __ xorl(c_rarg2, c_rarg2); aoqi@0: __ shrl(c_rarg3, 0x1f); aoqi@0: __ orl(c_rarg1, c_rarg3); aoqi@0: __ cmpl(rax, c_rarg1); aoqi@0: __ jcc(Assembler::negative, L); // NaN -> 0 aoqi@0: __ testq(c_rarg0, c_rarg0); // signed ? min_jlong : max_jlong aoqi@0: __ mov64(c_rarg2, 0x8000000000000000); aoqi@0: __ mov64(rax, 0x7fffffffffffffff); aoqi@0: __ cmovq(Assembler::positive, c_rarg2, rax); aoqi@0: aoqi@0: __ bind(L); aoqi@0: __ movq(inout, c_rarg2); aoqi@0: aoqi@0: __ pop(c_rarg0); aoqi@0: __ pop(c_rarg1); aoqi@0: __ pop(c_rarg2); aoqi@0: __ pop(c_rarg3); aoqi@0: __ pop(rax); aoqi@0: aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: address generate_fp_mask(const char *stub_name, int64_t mask) { aoqi@0: __ align(CodeEntryAlignment); aoqi@0: StubCodeMark mark(this, "StubRoutines", stub_name); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: __ emit_data64( mask, relocInfo::none ); aoqi@0: __ emit_data64( mask, relocInfo::none ); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // The following routine generates a subroutine to throw an aoqi@0: // asynchronous UnknownError when an unsafe access gets a fault that aoqi@0: // could not be reasonably prevented by the programmer. (Example: aoqi@0: // SIGBUS/OBJERR.) aoqi@0: address generate_handler_for_unsafe_access() { aoqi@0: StubCodeMark mark(this, "StubRoutines", "handler_for_unsafe_access"); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: __ push(0); // hole for return address-to-be aoqi@0: __ pusha(); // push registers aoqi@0: Address next_pc(rsp, RegisterImpl::number_of_registers * BytesPerWord); aoqi@0: aoqi@0: // FIXME: this probably needs alignment logic aoqi@0: aoqi@0: __ subptr(rsp, frame::arg_reg_save_area_bytes); aoqi@0: BLOCK_COMMENT("call handle_unsafe_access"); aoqi@0: __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, handle_unsafe_access))); aoqi@0: __ addptr(rsp, frame::arg_reg_save_area_bytes); aoqi@0: aoqi@0: __ movptr(next_pc, rax); // stuff next address aoqi@0: __ popa(); aoqi@0: __ ret(0); // jump to next address aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Non-destructive plausibility checks for oops aoqi@0: // aoqi@0: // Arguments: aoqi@0: // all args on stack! aoqi@0: // aoqi@0: // Stack after saving c_rarg3: aoqi@0: // [tos + 0]: saved c_rarg3 aoqi@0: // [tos + 1]: saved c_rarg2 aoqi@0: // [tos + 2]: saved r12 (several TemplateTable methods use it) aoqi@0: // [tos + 3]: saved flags aoqi@0: // [tos + 4]: return address aoqi@0: // * [tos + 5]: error message (char*) aoqi@0: // * [tos + 6]: object to verify (oop) aoqi@0: // * [tos + 7]: saved rax - saved by caller and bashed aoqi@0: // * [tos + 8]: saved r10 (rscratch1) - saved by caller aoqi@0: // * = popped on exit aoqi@0: address generate_verify_oop() { aoqi@0: StubCodeMark mark(this, "StubRoutines", "verify_oop"); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: Label exit, error; aoqi@0: aoqi@0: __ pushf(); aoqi@0: __ incrementl(ExternalAddress((address) StubRoutines::verify_oop_count_addr())); aoqi@0: aoqi@0: __ push(r12); aoqi@0: aoqi@0: // save c_rarg2 and c_rarg3 aoqi@0: __ push(c_rarg2); aoqi@0: __ push(c_rarg3); aoqi@0: aoqi@0: enum { aoqi@0: // After previous pushes. aoqi@0: oop_to_verify = 6 * wordSize, aoqi@0: saved_rax = 7 * wordSize, aoqi@0: saved_r10 = 8 * wordSize, aoqi@0: aoqi@0: // Before the call to MacroAssembler::debug(), see below. aoqi@0: return_addr = 16 * wordSize, aoqi@0: error_msg = 17 * wordSize aoqi@0: }; aoqi@0: aoqi@0: // get object aoqi@0: __ movptr(rax, Address(rsp, oop_to_verify)); aoqi@0: aoqi@0: // make sure object is 'reasonable' aoqi@0: __ testptr(rax, rax); aoqi@0: __ jcc(Assembler::zero, exit); // if obj is NULL it is OK aoqi@0: // Check if the oop is in the right area of memory aoqi@0: __ movptr(c_rarg2, rax); aoqi@0: __ movptr(c_rarg3, (intptr_t) Universe::verify_oop_mask()); aoqi@0: __ andptr(c_rarg2, c_rarg3); aoqi@0: __ movptr(c_rarg3, (intptr_t) Universe::verify_oop_bits()); aoqi@0: __ cmpptr(c_rarg2, c_rarg3); aoqi@0: __ jcc(Assembler::notZero, error); aoqi@0: aoqi@0: // set r12 to heapbase for load_klass() aoqi@0: __ reinit_heapbase(); aoqi@0: aoqi@0: // make sure klass is 'reasonable', which is not zero. aoqi@0: __ load_klass(rax, rax); // get klass aoqi@0: __ testptr(rax, rax); aoqi@0: __ jcc(Assembler::zero, error); // if klass is NULL it is broken aoqi@0: aoqi@0: // return if everything seems ok aoqi@0: __ bind(exit); aoqi@0: __ movptr(rax, Address(rsp, saved_rax)); // get saved rax back aoqi@0: __ movptr(rscratch1, Address(rsp, saved_r10)); // get saved r10 back aoqi@0: __ pop(c_rarg3); // restore c_rarg3 aoqi@0: __ pop(c_rarg2); // restore c_rarg2 aoqi@0: __ pop(r12); // restore r12 aoqi@0: __ popf(); // restore flags aoqi@0: __ ret(4 * wordSize); // pop caller saved stuff aoqi@0: aoqi@0: // handle errors aoqi@0: __ bind(error); aoqi@0: __ movptr(rax, Address(rsp, saved_rax)); // get saved rax back aoqi@0: __ movptr(rscratch1, Address(rsp, saved_r10)); // get saved r10 back aoqi@0: __ pop(c_rarg3); // get saved c_rarg3 back aoqi@0: __ pop(c_rarg2); // get saved c_rarg2 back aoqi@0: __ pop(r12); // get saved r12 back aoqi@0: __ popf(); // get saved flags off stack -- aoqi@0: // will be ignored aoqi@0: aoqi@0: __ pusha(); // push registers aoqi@0: // (rip is already aoqi@0: // already pushed) aoqi@0: // debug(char* msg, int64_t pc, int64_t regs[]) aoqi@0: // We've popped the registers we'd saved (c_rarg3, c_rarg2 and flags), and aoqi@0: // pushed all the registers, so now the stack looks like: aoqi@0: // [tos + 0] 16 saved registers aoqi@0: // [tos + 16] return address aoqi@0: // * [tos + 17] error message (char*) aoqi@0: // * [tos + 18] object to verify (oop) aoqi@0: // * [tos + 19] saved rax - saved by caller and bashed aoqi@0: // * [tos + 20] saved r10 (rscratch1) - saved by caller aoqi@0: // * = popped on exit aoqi@0: aoqi@0: __ movptr(c_rarg0, Address(rsp, error_msg)); // pass address of error message aoqi@0: __ movptr(c_rarg1, Address(rsp, return_addr)); // pass return address aoqi@0: __ movq(c_rarg2, rsp); // pass address of regs on stack aoqi@0: __ mov(r12, rsp); // remember rsp aoqi@0: __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows aoqi@0: __ andptr(rsp, -16); // align stack as required by ABI aoqi@0: BLOCK_COMMENT("call MacroAssembler::debug"); aoqi@0: __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, MacroAssembler::debug64))); aoqi@0: __ mov(rsp, r12); // restore rsp aoqi@0: __ popa(); // pop registers (includes r12) aoqi@0: __ ret(4 * wordSize); // pop caller saved stuff aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // aoqi@0: // Verify that a register contains clean 32-bits positive value aoqi@0: // (high 32-bits are 0) so it could be used in 64-bits shifts. aoqi@0: // aoqi@0: // Input: aoqi@0: // Rint - 32-bits value aoqi@0: // Rtmp - scratch aoqi@0: // aoqi@0: void assert_clean_int(Register Rint, Register Rtmp) { aoqi@0: #ifdef ASSERT aoqi@0: Label L; aoqi@0: assert_different_registers(Rtmp, Rint); aoqi@0: __ movslq(Rtmp, Rint); aoqi@0: __ cmpq(Rtmp, Rint); aoqi@0: __ jcc(Assembler::equal, L); aoqi@0: __ stop("high 32-bits of int value are not 0"); aoqi@0: __ bind(L); aoqi@0: #endif aoqi@0: } aoqi@0: aoqi@0: // Generate overlap test for array copy stubs aoqi@0: // aoqi@0: // Input: aoqi@0: // c_rarg0 - from aoqi@0: // c_rarg1 - to aoqi@0: // c_rarg2 - element count aoqi@0: // aoqi@0: // Output: aoqi@0: // rax - &from[element count - 1] aoqi@0: // aoqi@0: void array_overlap_test(address no_overlap_target, Address::ScaleFactor sf) { aoqi@0: assert(no_overlap_target != NULL, "must be generated"); aoqi@0: array_overlap_test(no_overlap_target, NULL, sf); aoqi@0: } aoqi@0: void array_overlap_test(Label& L_no_overlap, Address::ScaleFactor sf) { aoqi@0: array_overlap_test(NULL, &L_no_overlap, sf); aoqi@0: } aoqi@0: void array_overlap_test(address no_overlap_target, Label* NOLp, Address::ScaleFactor sf) { aoqi@0: const Register from = c_rarg0; aoqi@0: const Register to = c_rarg1; aoqi@0: const Register count = c_rarg2; aoqi@0: const Register end_from = rax; aoqi@0: aoqi@0: __ cmpptr(to, from); aoqi@0: __ lea(end_from, Address(from, count, sf, 0)); aoqi@0: if (NOLp == NULL) { aoqi@0: ExternalAddress no_overlap(no_overlap_target); aoqi@0: __ jump_cc(Assembler::belowEqual, no_overlap); aoqi@0: __ cmpptr(to, end_from); aoqi@0: __ jump_cc(Assembler::aboveEqual, no_overlap); aoqi@0: } else { aoqi@0: __ jcc(Assembler::belowEqual, (*NOLp)); aoqi@0: __ cmpptr(to, end_from); aoqi@0: __ jcc(Assembler::aboveEqual, (*NOLp)); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Shuffle first three arg regs on Windows into Linux/Solaris locations. aoqi@0: // aoqi@0: // Outputs: aoqi@0: // rdi - rcx aoqi@0: // rsi - rdx aoqi@0: // rdx - r8 aoqi@0: // rcx - r9 aoqi@0: // aoqi@0: // Registers r9 and r10 are used to save rdi and rsi on Windows, which latter aoqi@0: // are non-volatile. r9 and r10 should not be used by the caller. aoqi@0: // aoqi@0: void setup_arg_regs(int nargs = 3) { aoqi@0: const Register saved_rdi = r9; aoqi@0: const Register saved_rsi = r10; aoqi@0: assert(nargs == 3 || nargs == 4, "else fix"); aoqi@0: #ifdef _WIN64 aoqi@0: assert(c_rarg0 == rcx && c_rarg1 == rdx && c_rarg2 == r8 && c_rarg3 == r9, aoqi@0: "unexpected argument registers"); aoqi@0: if (nargs >= 4) aoqi@0: __ mov(rax, r9); // r9 is also saved_rdi aoqi@0: __ movptr(saved_rdi, rdi); aoqi@0: __ movptr(saved_rsi, rsi); aoqi@0: __ mov(rdi, rcx); // c_rarg0 aoqi@0: __ mov(rsi, rdx); // c_rarg1 aoqi@0: __ mov(rdx, r8); // c_rarg2 aoqi@0: if (nargs >= 4) aoqi@0: __ mov(rcx, rax); // c_rarg3 (via rax) aoqi@0: #else aoqi@0: assert(c_rarg0 == rdi && c_rarg1 == rsi && c_rarg2 == rdx && c_rarg3 == rcx, aoqi@0: "unexpected argument registers"); aoqi@0: #endif aoqi@0: } aoqi@0: aoqi@0: void restore_arg_regs() { aoqi@0: const Register saved_rdi = r9; aoqi@0: const Register saved_rsi = r10; aoqi@0: #ifdef _WIN64 aoqi@0: __ movptr(rdi, saved_rdi); aoqi@0: __ movptr(rsi, saved_rsi); aoqi@0: #endif aoqi@0: } aoqi@0: aoqi@0: // Generate code for an array write pre barrier aoqi@0: // aoqi@0: // addr - starting address aoqi@0: // count - element count aoqi@0: // tmp - scratch register aoqi@0: // aoqi@0: // Destroy no registers! aoqi@0: // aoqi@0: void gen_write_ref_array_pre_barrier(Register addr, Register count, bool dest_uninitialized) { aoqi@0: BarrierSet* bs = Universe::heap()->barrier_set(); aoqi@0: switch (bs->kind()) { aoqi@0: case BarrierSet::G1SATBCT: aoqi@0: case BarrierSet::G1SATBCTLogging: aoqi@0: // With G1, don't generate the call if we statically know that the target in uninitialized aoqi@0: if (!dest_uninitialized) { aoqi@0: __ pusha(); // push registers aoqi@0: if (count == c_rarg0) { aoqi@0: if (addr == c_rarg1) { aoqi@0: // exactly backwards!! aoqi@0: __ xchgptr(c_rarg1, c_rarg0); aoqi@0: } else { aoqi@0: __ movptr(c_rarg1, count); aoqi@0: __ movptr(c_rarg0, addr); aoqi@0: } aoqi@0: } else { aoqi@0: __ movptr(c_rarg0, addr); aoqi@0: __ movptr(c_rarg1, count); aoqi@0: } aoqi@0: __ call_VM_leaf(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_pre), 2); aoqi@0: __ popa(); aoqi@0: } aoqi@0: break; aoqi@0: case BarrierSet::CardTableModRef: aoqi@0: case BarrierSet::CardTableExtension: aoqi@0: case BarrierSet::ModRef: aoqi@0: break; aoqi@0: default: aoqi@0: ShouldNotReachHere(); aoqi@0: aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // aoqi@0: // Generate code for an array write post barrier aoqi@0: // aoqi@0: // Input: aoqi@0: // start - register containing starting address of destination array aoqi@0: // count - elements count aoqi@0: // scratch - scratch register aoqi@0: // aoqi@0: // The input registers are overwritten. aoqi@0: // aoqi@0: void gen_write_ref_array_post_barrier(Register start, Register count, Register scratch) { aoqi@0: assert_different_registers(start, count, scratch); aoqi@0: BarrierSet* bs = Universe::heap()->barrier_set(); aoqi@0: switch (bs->kind()) { aoqi@0: case BarrierSet::G1SATBCT: aoqi@0: case BarrierSet::G1SATBCTLogging: aoqi@0: { aoqi@0: __ pusha(); // push registers (overkill) aoqi@0: if (c_rarg0 == count) { // On win64 c_rarg0 == rcx aoqi@0: assert_different_registers(c_rarg1, start); aoqi@0: __ mov(c_rarg1, count); aoqi@0: __ mov(c_rarg0, start); aoqi@0: } else { aoqi@0: assert_different_registers(c_rarg0, count); aoqi@0: __ mov(c_rarg0, start); aoqi@0: __ mov(c_rarg1, count); aoqi@0: } aoqi@0: __ call_VM_leaf(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_post), 2); aoqi@0: __ popa(); aoqi@0: } aoqi@0: break; aoqi@0: case BarrierSet::CardTableModRef: aoqi@0: case BarrierSet::CardTableExtension: aoqi@0: { aoqi@0: CardTableModRefBS* ct = (CardTableModRefBS*)bs; aoqi@0: assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code"); aoqi@0: aoqi@0: Label L_loop; aoqi@0: const Register end = count; aoqi@0: aoqi@0: __ leaq(end, Address(start, count, TIMES_OOP, 0)); // end == start+count*oop_size aoqi@0: __ subptr(end, BytesPerHeapOop); // end - 1 to make inclusive aoqi@0: __ shrptr(start, CardTableModRefBS::card_shift); aoqi@0: __ shrptr(end, CardTableModRefBS::card_shift); aoqi@0: __ subptr(end, start); // end --> cards count aoqi@0: aoqi@0: int64_t disp = (int64_t) ct->byte_map_base; aoqi@0: __ mov64(scratch, disp); aoqi@0: __ addptr(start, scratch); aoqi@0: __ BIND(L_loop); aoqi@0: __ movb(Address(start, count, Address::times_1), 0); aoqi@0: __ decrement(count); aoqi@0: __ jcc(Assembler::greaterEqual, L_loop); aoqi@0: } aoqi@0: break; aoqi@0: default: aoqi@0: ShouldNotReachHere(); aoqi@0: aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Copy big chunks forward aoqi@0: // aoqi@0: // Inputs: aoqi@0: // end_from - source arrays end address aoqi@0: // end_to - destination array end address aoqi@0: // qword_count - 64-bits element count, negative aoqi@0: // to - scratch aoqi@0: // L_copy_bytes - entry label aoqi@0: // L_copy_8_bytes - exit label aoqi@0: // aoqi@0: void copy_bytes_forward(Register end_from, Register end_to, aoqi@0: Register qword_count, Register to, aoqi@0: Label& L_copy_bytes, Label& L_copy_8_bytes) { aoqi@0: DEBUG_ONLY(__ stop("enter at entry label, not here")); aoqi@0: Label L_loop; aoqi@0: __ align(OptoLoopAlignment); aoqi@0: if (UseUnalignedLoadStores) { aoqi@0: Label L_end; aoqi@0: // Copy 64-bytes per iteration aoqi@0: __ BIND(L_loop); aoqi@0: if (UseAVX >= 2) { aoqi@0: __ vmovdqu(xmm0, Address(end_from, qword_count, Address::times_8, -56)); aoqi@0: __ vmovdqu(Address(end_to, qword_count, Address::times_8, -56), xmm0); aoqi@0: __ vmovdqu(xmm1, Address(end_from, qword_count, Address::times_8, -24)); aoqi@0: __ vmovdqu(Address(end_to, qword_count, Address::times_8, -24), xmm1); aoqi@0: } else { aoqi@0: __ movdqu(xmm0, Address(end_from, qword_count, Address::times_8, -56)); aoqi@0: __ movdqu(Address(end_to, qword_count, Address::times_8, -56), xmm0); aoqi@0: __ movdqu(xmm1, Address(end_from, qword_count, Address::times_8, -40)); aoqi@0: __ movdqu(Address(end_to, qword_count, Address::times_8, -40), xmm1); aoqi@0: __ movdqu(xmm2, Address(end_from, qword_count, Address::times_8, -24)); aoqi@0: __ movdqu(Address(end_to, qword_count, Address::times_8, -24), xmm2); aoqi@0: __ movdqu(xmm3, Address(end_from, qword_count, Address::times_8, - 8)); aoqi@0: __ movdqu(Address(end_to, qword_count, Address::times_8, - 8), xmm3); aoqi@0: } aoqi@0: __ BIND(L_copy_bytes); aoqi@0: __ addptr(qword_count, 8); aoqi@0: __ jcc(Assembler::lessEqual, L_loop); aoqi@0: __ subptr(qword_count, 4); // sub(8) and add(4) aoqi@0: __ jccb(Assembler::greater, L_end); aoqi@0: // Copy trailing 32 bytes aoqi@0: if (UseAVX >= 2) { aoqi@0: __ vmovdqu(xmm0, Address(end_from, qword_count, Address::times_8, -24)); aoqi@0: __ vmovdqu(Address(end_to, qword_count, Address::times_8, -24), xmm0); aoqi@0: } else { aoqi@0: __ movdqu(xmm0, Address(end_from, qword_count, Address::times_8, -24)); aoqi@0: __ movdqu(Address(end_to, qword_count, Address::times_8, -24), xmm0); aoqi@0: __ movdqu(xmm1, Address(end_from, qword_count, Address::times_8, - 8)); aoqi@0: __ movdqu(Address(end_to, qword_count, Address::times_8, - 8), xmm1); aoqi@0: } aoqi@0: __ addptr(qword_count, 4); aoqi@0: __ BIND(L_end); aoqi@0: if (UseAVX >= 2) { aoqi@0: // clean upper bits of YMM registers aoqi@0: __ vzeroupper(); aoqi@0: } aoqi@0: } else { aoqi@0: // Copy 32-bytes per iteration aoqi@0: __ BIND(L_loop); aoqi@0: __ movq(to, Address(end_from, qword_count, Address::times_8, -24)); aoqi@0: __ movq(Address(end_to, qword_count, Address::times_8, -24), to); aoqi@0: __ movq(to, Address(end_from, qword_count, Address::times_8, -16)); aoqi@0: __ movq(Address(end_to, qword_count, Address::times_8, -16), to); aoqi@0: __ movq(to, Address(end_from, qword_count, Address::times_8, - 8)); aoqi@0: __ movq(Address(end_to, qword_count, Address::times_8, - 8), to); aoqi@0: __ movq(to, Address(end_from, qword_count, Address::times_8, - 0)); aoqi@0: __ movq(Address(end_to, qword_count, Address::times_8, - 0), to); aoqi@0: aoqi@0: __ BIND(L_copy_bytes); aoqi@0: __ addptr(qword_count, 4); aoqi@0: __ jcc(Assembler::lessEqual, L_loop); aoqi@0: } aoqi@0: __ subptr(qword_count, 4); aoqi@0: __ jcc(Assembler::less, L_copy_8_bytes); // Copy trailing qwords aoqi@0: } aoqi@0: aoqi@0: // Copy big chunks backward aoqi@0: // aoqi@0: // Inputs: aoqi@0: // from - source arrays address aoqi@0: // dest - destination array address aoqi@0: // qword_count - 64-bits element count aoqi@0: // to - scratch aoqi@0: // L_copy_bytes - entry label aoqi@0: // L_copy_8_bytes - exit label aoqi@0: // aoqi@0: void copy_bytes_backward(Register from, Register dest, aoqi@0: Register qword_count, Register to, aoqi@0: Label& L_copy_bytes, Label& L_copy_8_bytes) { aoqi@0: DEBUG_ONLY(__ stop("enter at entry label, not here")); aoqi@0: Label L_loop; aoqi@0: __ align(OptoLoopAlignment); aoqi@0: if (UseUnalignedLoadStores) { aoqi@0: Label L_end; aoqi@0: // Copy 64-bytes per iteration aoqi@0: __ BIND(L_loop); aoqi@0: if (UseAVX >= 2) { aoqi@0: __ vmovdqu(xmm0, Address(from, qword_count, Address::times_8, 32)); aoqi@0: __ vmovdqu(Address(dest, qword_count, Address::times_8, 32), xmm0); aoqi@0: __ vmovdqu(xmm1, Address(from, qword_count, Address::times_8, 0)); aoqi@0: __ vmovdqu(Address(dest, qword_count, Address::times_8, 0), xmm1); aoqi@0: } else { aoqi@0: __ movdqu(xmm0, Address(from, qword_count, Address::times_8, 48)); aoqi@0: __ movdqu(Address(dest, qword_count, Address::times_8, 48), xmm0); aoqi@0: __ movdqu(xmm1, Address(from, qword_count, Address::times_8, 32)); aoqi@0: __ movdqu(Address(dest, qword_count, Address::times_8, 32), xmm1); aoqi@0: __ movdqu(xmm2, Address(from, qword_count, Address::times_8, 16)); aoqi@0: __ movdqu(Address(dest, qword_count, Address::times_8, 16), xmm2); aoqi@0: __ movdqu(xmm3, Address(from, qword_count, Address::times_8, 0)); aoqi@0: __ movdqu(Address(dest, qword_count, Address::times_8, 0), xmm3); aoqi@0: } aoqi@0: __ BIND(L_copy_bytes); aoqi@0: __ subptr(qword_count, 8); aoqi@0: __ jcc(Assembler::greaterEqual, L_loop); aoqi@0: aoqi@0: __ addptr(qword_count, 4); // add(8) and sub(4) aoqi@0: __ jccb(Assembler::less, L_end); aoqi@0: // Copy trailing 32 bytes aoqi@0: if (UseAVX >= 2) { aoqi@0: __ vmovdqu(xmm0, Address(from, qword_count, Address::times_8, 0)); aoqi@0: __ vmovdqu(Address(dest, qword_count, Address::times_8, 0), xmm0); aoqi@0: } else { aoqi@0: __ movdqu(xmm0, Address(from, qword_count, Address::times_8, 16)); aoqi@0: __ movdqu(Address(dest, qword_count, Address::times_8, 16), xmm0); aoqi@0: __ movdqu(xmm1, Address(from, qword_count, Address::times_8, 0)); aoqi@0: __ movdqu(Address(dest, qword_count, Address::times_8, 0), xmm1); aoqi@0: } aoqi@0: __ subptr(qword_count, 4); aoqi@0: __ BIND(L_end); aoqi@0: if (UseAVX >= 2) { aoqi@0: // clean upper bits of YMM registers aoqi@0: __ vzeroupper(); aoqi@0: } aoqi@0: } else { aoqi@0: // Copy 32-bytes per iteration aoqi@0: __ BIND(L_loop); aoqi@0: __ movq(to, Address(from, qword_count, Address::times_8, 24)); aoqi@0: __ movq(Address(dest, qword_count, Address::times_8, 24), to); aoqi@0: __ movq(to, Address(from, qword_count, Address::times_8, 16)); aoqi@0: __ movq(Address(dest, qword_count, Address::times_8, 16), to); aoqi@0: __ movq(to, Address(from, qword_count, Address::times_8, 8)); aoqi@0: __ movq(Address(dest, qword_count, Address::times_8, 8), to); aoqi@0: __ movq(to, Address(from, qword_count, Address::times_8, 0)); aoqi@0: __ movq(Address(dest, qword_count, Address::times_8, 0), to); aoqi@0: aoqi@0: __ BIND(L_copy_bytes); aoqi@0: __ subptr(qword_count, 4); aoqi@0: __ jcc(Assembler::greaterEqual, L_loop); aoqi@0: } aoqi@0: __ addptr(qword_count, 4); aoqi@0: __ jcc(Assembler::greater, L_copy_8_bytes); // Copy trailing qwords aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Arguments: aoqi@0: // aligned - true => Input and output aligned on a HeapWord == 8-byte boundary aoqi@0: // ignored aoqi@0: // name - stub name string aoqi@0: // aoqi@0: // Inputs: aoqi@0: // c_rarg0 - source array address aoqi@0: // c_rarg1 - destination array address aoqi@0: // c_rarg2 - element count, treated as ssize_t, can be zero aoqi@0: // aoqi@0: // If 'from' and/or 'to' are aligned on 4-, 2-, or 1-byte boundaries, aoqi@0: // we let the hardware handle it. The one to eight bytes within words, aoqi@0: // dwords or qwords that span cache line boundaries will still be loaded aoqi@0: // and stored atomically. aoqi@0: // aoqi@0: // Side Effects: aoqi@0: // disjoint_byte_copy_entry is set to the no-overlap entry point aoqi@0: // used by generate_conjoint_byte_copy(). aoqi@0: // aoqi@0: address generate_disjoint_byte_copy(bool aligned, address* entry, const char *name) { aoqi@0: __ align(CodeEntryAlignment); aoqi@0: StubCodeMark mark(this, "StubRoutines", name); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: Label L_copy_bytes, L_copy_8_bytes, L_copy_4_bytes, L_copy_2_bytes; aoqi@0: Label L_copy_byte, L_exit; aoqi@0: const Register from = rdi; // source array address aoqi@0: const Register to = rsi; // destination array address aoqi@0: const Register count = rdx; // elements count aoqi@0: const Register byte_count = rcx; aoqi@0: const Register qword_count = count; aoqi@0: const Register end_from = from; // source array end address aoqi@0: const Register end_to = to; // destination array end address aoqi@0: // End pointers are inclusive, and if count is not zero they point aoqi@0: // to the last unit copied: end_to[0] := end_from[0] aoqi@0: aoqi@0: __ enter(); // required for proper stackwalking of RuntimeStub frame aoqi@0: assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. aoqi@0: aoqi@0: if (entry != NULL) { aoqi@0: *entry = __ pc(); aoqi@0: // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) aoqi@0: BLOCK_COMMENT("Entry:"); aoqi@0: } aoqi@0: aoqi@0: setup_arg_regs(); // from => rdi, to => rsi, count => rdx aoqi@0: // r9 and r10 may be used to save non-volatile registers aoqi@0: aoqi@0: // 'from', 'to' and 'count' are now valid aoqi@0: __ movptr(byte_count, count); aoqi@0: __ shrptr(count, 3); // count => qword_count aoqi@0: aoqi@0: // Copy from low to high addresses. Use 'to' as scratch. aoqi@0: __ lea(end_from, Address(from, qword_count, Address::times_8, -8)); aoqi@0: __ lea(end_to, Address(to, qword_count, Address::times_8, -8)); aoqi@0: __ negptr(qword_count); // make the count negative aoqi@0: __ jmp(L_copy_bytes); aoqi@0: aoqi@0: // Copy trailing qwords aoqi@0: __ BIND(L_copy_8_bytes); aoqi@0: __ movq(rax, Address(end_from, qword_count, Address::times_8, 8)); aoqi@0: __ movq(Address(end_to, qword_count, Address::times_8, 8), rax); aoqi@0: __ increment(qword_count); aoqi@0: __ jcc(Assembler::notZero, L_copy_8_bytes); aoqi@0: aoqi@0: // Check for and copy trailing dword aoqi@0: __ BIND(L_copy_4_bytes); aoqi@0: __ testl(byte_count, 4); aoqi@0: __ jccb(Assembler::zero, L_copy_2_bytes); aoqi@0: __ movl(rax, Address(end_from, 8)); aoqi@0: __ movl(Address(end_to, 8), rax); aoqi@0: aoqi@0: __ addptr(end_from, 4); aoqi@0: __ addptr(end_to, 4); aoqi@0: aoqi@0: // Check for and copy trailing word aoqi@0: __ BIND(L_copy_2_bytes); aoqi@0: __ testl(byte_count, 2); aoqi@0: __ jccb(Assembler::zero, L_copy_byte); aoqi@0: __ movw(rax, Address(end_from, 8)); aoqi@0: __ movw(Address(end_to, 8), rax); aoqi@0: aoqi@0: __ addptr(end_from, 2); aoqi@0: __ addptr(end_to, 2); aoqi@0: aoqi@0: // Check for and copy trailing byte aoqi@0: __ BIND(L_copy_byte); aoqi@0: __ testl(byte_count, 1); aoqi@0: __ jccb(Assembler::zero, L_exit); aoqi@0: __ movb(rax, Address(end_from, 8)); aoqi@0: __ movb(Address(end_to, 8), rax); aoqi@0: aoqi@0: __ BIND(L_exit); aoqi@0: restore_arg_regs(); aoqi@0: inc_counter_np(SharedRuntime::_jbyte_array_copy_ctr); // Update counter after rscratch1 is free aoqi@0: __ xorptr(rax, rax); // return 0 aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: aoqi@0: // Copy in multi-bytes chunks aoqi@0: copy_bytes_forward(end_from, end_to, qword_count, rax, L_copy_bytes, L_copy_8_bytes); aoqi@0: __ jmp(L_copy_4_bytes); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Arguments: aoqi@0: // aligned - true => Input and output aligned on a HeapWord == 8-byte boundary aoqi@0: // ignored aoqi@0: // name - stub name string aoqi@0: // aoqi@0: // Inputs: aoqi@0: // c_rarg0 - source array address aoqi@0: // c_rarg1 - destination array address aoqi@0: // c_rarg2 - element count, treated as ssize_t, can be zero aoqi@0: // aoqi@0: // If 'from' and/or 'to' are aligned on 4-, 2-, or 1-byte boundaries, aoqi@0: // we let the hardware handle it. The one to eight bytes within words, aoqi@0: // dwords or qwords that span cache line boundaries will still be loaded aoqi@0: // and stored atomically. aoqi@0: // aoqi@0: address generate_conjoint_byte_copy(bool aligned, address nooverlap_target, aoqi@0: address* entry, const char *name) { aoqi@0: __ align(CodeEntryAlignment); aoqi@0: StubCodeMark mark(this, "StubRoutines", name); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: Label L_copy_bytes, L_copy_8_bytes, L_copy_4_bytes, L_copy_2_bytes; aoqi@0: const Register from = rdi; // source array address aoqi@0: const Register to = rsi; // destination array address aoqi@0: const Register count = rdx; // elements count aoqi@0: const Register byte_count = rcx; aoqi@0: const Register qword_count = count; aoqi@0: aoqi@0: __ enter(); // required for proper stackwalking of RuntimeStub frame aoqi@0: assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. aoqi@0: aoqi@0: if (entry != NULL) { aoqi@0: *entry = __ pc(); aoqi@0: // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) aoqi@0: BLOCK_COMMENT("Entry:"); aoqi@0: } aoqi@0: aoqi@0: array_overlap_test(nooverlap_target, Address::times_1); aoqi@0: setup_arg_regs(); // from => rdi, to => rsi, count => rdx aoqi@0: // r9 and r10 may be used to save non-volatile registers aoqi@0: aoqi@0: // 'from', 'to' and 'count' are now valid aoqi@0: __ movptr(byte_count, count); aoqi@0: __ shrptr(count, 3); // count => qword_count aoqi@0: aoqi@0: // Copy from high to low addresses. aoqi@0: aoqi@0: // Check for and copy trailing byte aoqi@0: __ testl(byte_count, 1); aoqi@0: __ jcc(Assembler::zero, L_copy_2_bytes); aoqi@0: __ movb(rax, Address(from, byte_count, Address::times_1, -1)); aoqi@0: __ movb(Address(to, byte_count, Address::times_1, -1), rax); aoqi@0: __ decrement(byte_count); // Adjust for possible trailing word aoqi@0: aoqi@0: // Check for and copy trailing word aoqi@0: __ BIND(L_copy_2_bytes); aoqi@0: __ testl(byte_count, 2); aoqi@0: __ jcc(Assembler::zero, L_copy_4_bytes); aoqi@0: __ movw(rax, Address(from, byte_count, Address::times_1, -2)); aoqi@0: __ movw(Address(to, byte_count, Address::times_1, -2), rax); aoqi@0: aoqi@0: // Check for and copy trailing dword aoqi@0: __ BIND(L_copy_4_bytes); aoqi@0: __ testl(byte_count, 4); aoqi@0: __ jcc(Assembler::zero, L_copy_bytes); aoqi@0: __ movl(rax, Address(from, qword_count, Address::times_8)); aoqi@0: __ movl(Address(to, qword_count, Address::times_8), rax); aoqi@0: __ jmp(L_copy_bytes); aoqi@0: aoqi@0: // Copy trailing qwords aoqi@0: __ BIND(L_copy_8_bytes); aoqi@0: __ movq(rax, Address(from, qword_count, Address::times_8, -8)); aoqi@0: __ movq(Address(to, qword_count, Address::times_8, -8), rax); aoqi@0: __ decrement(qword_count); aoqi@0: __ jcc(Assembler::notZero, L_copy_8_bytes); aoqi@0: aoqi@0: restore_arg_regs(); aoqi@0: inc_counter_np(SharedRuntime::_jbyte_array_copy_ctr); // Update counter after rscratch1 is free aoqi@0: __ xorptr(rax, rax); // return 0 aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: aoqi@0: // Copy in multi-bytes chunks aoqi@0: copy_bytes_backward(from, to, qword_count, rax, L_copy_bytes, L_copy_8_bytes); aoqi@0: aoqi@0: restore_arg_regs(); aoqi@0: inc_counter_np(SharedRuntime::_jbyte_array_copy_ctr); // Update counter after rscratch1 is free aoqi@0: __ xorptr(rax, rax); // return 0 aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Arguments: aoqi@0: // aligned - true => Input and output aligned on a HeapWord == 8-byte boundary aoqi@0: // ignored aoqi@0: // name - stub name string aoqi@0: // aoqi@0: // Inputs: aoqi@0: // c_rarg0 - source array address aoqi@0: // c_rarg1 - destination array address aoqi@0: // c_rarg2 - element count, treated as ssize_t, can be zero aoqi@0: // aoqi@0: // If 'from' and/or 'to' are aligned on 4- or 2-byte boundaries, we aoqi@0: // let the hardware handle it. The two or four words within dwords aoqi@0: // or qwords that span cache line boundaries will still be loaded aoqi@0: // and stored atomically. aoqi@0: // aoqi@0: // Side Effects: aoqi@0: // disjoint_short_copy_entry is set to the no-overlap entry point aoqi@0: // used by generate_conjoint_short_copy(). aoqi@0: // aoqi@0: address generate_disjoint_short_copy(bool aligned, address *entry, const char *name) { aoqi@0: __ align(CodeEntryAlignment); aoqi@0: StubCodeMark mark(this, "StubRoutines", name); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: Label L_copy_bytes, L_copy_8_bytes, L_copy_4_bytes,L_copy_2_bytes,L_exit; aoqi@0: const Register from = rdi; // source array address aoqi@0: const Register to = rsi; // destination array address aoqi@0: const Register count = rdx; // elements count aoqi@0: const Register word_count = rcx; aoqi@0: const Register qword_count = count; aoqi@0: const Register end_from = from; // source array end address aoqi@0: const Register end_to = to; // destination array end address aoqi@0: // End pointers are inclusive, and if count is not zero they point aoqi@0: // to the last unit copied: end_to[0] := end_from[0] aoqi@0: aoqi@0: __ enter(); // required for proper stackwalking of RuntimeStub frame aoqi@0: assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. aoqi@0: aoqi@0: if (entry != NULL) { aoqi@0: *entry = __ pc(); aoqi@0: // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) aoqi@0: BLOCK_COMMENT("Entry:"); aoqi@0: } aoqi@0: aoqi@0: setup_arg_regs(); // from => rdi, to => rsi, count => rdx aoqi@0: // r9 and r10 may be used to save non-volatile registers aoqi@0: aoqi@0: // 'from', 'to' and 'count' are now valid aoqi@0: __ movptr(word_count, count); aoqi@0: __ shrptr(count, 2); // count => qword_count aoqi@0: aoqi@0: // Copy from low to high addresses. Use 'to' as scratch. aoqi@0: __ lea(end_from, Address(from, qword_count, Address::times_8, -8)); aoqi@0: __ lea(end_to, Address(to, qword_count, Address::times_8, -8)); aoqi@0: __ negptr(qword_count); aoqi@0: __ jmp(L_copy_bytes); aoqi@0: aoqi@0: // Copy trailing qwords aoqi@0: __ BIND(L_copy_8_bytes); aoqi@0: __ movq(rax, Address(end_from, qword_count, Address::times_8, 8)); aoqi@0: __ movq(Address(end_to, qword_count, Address::times_8, 8), rax); aoqi@0: __ increment(qword_count); aoqi@0: __ jcc(Assembler::notZero, L_copy_8_bytes); aoqi@0: aoqi@0: // Original 'dest' is trashed, so we can't use it as a aoqi@0: // base register for a possible trailing word copy aoqi@0: aoqi@0: // Check for and copy trailing dword aoqi@0: __ BIND(L_copy_4_bytes); aoqi@0: __ testl(word_count, 2); aoqi@0: __ jccb(Assembler::zero, L_copy_2_bytes); aoqi@0: __ movl(rax, Address(end_from, 8)); aoqi@0: __ movl(Address(end_to, 8), rax); aoqi@0: aoqi@0: __ addptr(end_from, 4); aoqi@0: __ addptr(end_to, 4); aoqi@0: aoqi@0: // Check for and copy trailing word aoqi@0: __ BIND(L_copy_2_bytes); aoqi@0: __ testl(word_count, 1); aoqi@0: __ jccb(Assembler::zero, L_exit); aoqi@0: __ movw(rax, Address(end_from, 8)); aoqi@0: __ movw(Address(end_to, 8), rax); aoqi@0: aoqi@0: __ BIND(L_exit); aoqi@0: restore_arg_regs(); aoqi@0: inc_counter_np(SharedRuntime::_jshort_array_copy_ctr); // Update counter after rscratch1 is free aoqi@0: __ xorptr(rax, rax); // return 0 aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: aoqi@0: // Copy in multi-bytes chunks aoqi@0: copy_bytes_forward(end_from, end_to, qword_count, rax, L_copy_bytes, L_copy_8_bytes); aoqi@0: __ jmp(L_copy_4_bytes); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: address generate_fill(BasicType t, bool aligned, const char *name) { aoqi@0: __ align(CodeEntryAlignment); aoqi@0: StubCodeMark mark(this, "StubRoutines", name); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: BLOCK_COMMENT("Entry:"); aoqi@0: aoqi@0: const Register to = c_rarg0; // source array address aoqi@0: const Register value = c_rarg1; // value aoqi@0: const Register count = c_rarg2; // elements count aoqi@0: aoqi@0: __ enter(); // required for proper stackwalking of RuntimeStub frame aoqi@0: aoqi@0: __ generate_fill(t, aligned, to, value, count, rax, xmm0); aoqi@0: aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Arguments: aoqi@0: // aligned - true => Input and output aligned on a HeapWord == 8-byte boundary aoqi@0: // ignored aoqi@0: // name - stub name string aoqi@0: // aoqi@0: // Inputs: aoqi@0: // c_rarg0 - source array address aoqi@0: // c_rarg1 - destination array address aoqi@0: // c_rarg2 - element count, treated as ssize_t, can be zero aoqi@0: // aoqi@0: // If 'from' and/or 'to' are aligned on 4- or 2-byte boundaries, we aoqi@0: // let the hardware handle it. The two or four words within dwords aoqi@0: // or qwords that span cache line boundaries will still be loaded aoqi@0: // and stored atomically. aoqi@0: // aoqi@0: address generate_conjoint_short_copy(bool aligned, address nooverlap_target, aoqi@0: address *entry, const char *name) { aoqi@0: __ align(CodeEntryAlignment); aoqi@0: StubCodeMark mark(this, "StubRoutines", name); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: Label L_copy_bytes, L_copy_8_bytes, L_copy_4_bytes; aoqi@0: const Register from = rdi; // source array address aoqi@0: const Register to = rsi; // destination array address aoqi@0: const Register count = rdx; // elements count aoqi@0: const Register word_count = rcx; aoqi@0: const Register qword_count = count; aoqi@0: aoqi@0: __ enter(); // required for proper stackwalking of RuntimeStub frame aoqi@0: assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. aoqi@0: aoqi@0: if (entry != NULL) { aoqi@0: *entry = __ pc(); aoqi@0: // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) aoqi@0: BLOCK_COMMENT("Entry:"); aoqi@0: } aoqi@0: aoqi@0: array_overlap_test(nooverlap_target, Address::times_2); aoqi@0: setup_arg_regs(); // from => rdi, to => rsi, count => rdx aoqi@0: // r9 and r10 may be used to save non-volatile registers aoqi@0: aoqi@0: // 'from', 'to' and 'count' are now valid aoqi@0: __ movptr(word_count, count); aoqi@0: __ shrptr(count, 2); // count => qword_count aoqi@0: aoqi@0: // Copy from high to low addresses. Use 'to' as scratch. aoqi@0: aoqi@0: // Check for and copy trailing word aoqi@0: __ testl(word_count, 1); aoqi@0: __ jccb(Assembler::zero, L_copy_4_bytes); aoqi@0: __ movw(rax, Address(from, word_count, Address::times_2, -2)); aoqi@0: __ movw(Address(to, word_count, Address::times_2, -2), rax); aoqi@0: aoqi@0: // Check for and copy trailing dword aoqi@0: __ BIND(L_copy_4_bytes); aoqi@0: __ testl(word_count, 2); aoqi@0: __ jcc(Assembler::zero, L_copy_bytes); aoqi@0: __ movl(rax, Address(from, qword_count, Address::times_8)); aoqi@0: __ movl(Address(to, qword_count, Address::times_8), rax); aoqi@0: __ jmp(L_copy_bytes); aoqi@0: aoqi@0: // Copy trailing qwords aoqi@0: __ BIND(L_copy_8_bytes); aoqi@0: __ movq(rax, Address(from, qword_count, Address::times_8, -8)); aoqi@0: __ movq(Address(to, qword_count, Address::times_8, -8), rax); aoqi@0: __ decrement(qword_count); aoqi@0: __ jcc(Assembler::notZero, L_copy_8_bytes); aoqi@0: aoqi@0: restore_arg_regs(); aoqi@0: inc_counter_np(SharedRuntime::_jshort_array_copy_ctr); // Update counter after rscratch1 is free aoqi@0: __ xorptr(rax, rax); // return 0 aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: aoqi@0: // Copy in multi-bytes chunks aoqi@0: copy_bytes_backward(from, to, qword_count, rax, L_copy_bytes, L_copy_8_bytes); aoqi@0: aoqi@0: restore_arg_regs(); aoqi@0: inc_counter_np(SharedRuntime::_jshort_array_copy_ctr); // Update counter after rscratch1 is free aoqi@0: __ xorptr(rax, rax); // return 0 aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Arguments: aoqi@0: // aligned - true => Input and output aligned on a HeapWord == 8-byte boundary aoqi@0: // ignored aoqi@0: // is_oop - true => oop array, so generate store check code aoqi@0: // name - stub name string aoqi@0: // aoqi@0: // Inputs: aoqi@0: // c_rarg0 - source array address aoqi@0: // c_rarg1 - destination array address aoqi@0: // c_rarg2 - element count, treated as ssize_t, can be zero aoqi@0: // aoqi@0: // If 'from' and/or 'to' are aligned on 4-byte boundaries, we let aoqi@0: // the hardware handle it. The two dwords within qwords that span aoqi@0: // cache line boundaries will still be loaded and stored atomicly. aoqi@0: // aoqi@0: // Side Effects: aoqi@0: // disjoint_int_copy_entry is set to the no-overlap entry point aoqi@0: // used by generate_conjoint_int_oop_copy(). aoqi@0: // aoqi@0: address generate_disjoint_int_oop_copy(bool aligned, bool is_oop, address* entry, aoqi@0: const char *name, bool dest_uninitialized = false) { aoqi@0: __ align(CodeEntryAlignment); aoqi@0: StubCodeMark mark(this, "StubRoutines", name); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: Label L_copy_bytes, L_copy_8_bytes, L_copy_4_bytes, L_exit; aoqi@0: const Register from = rdi; // source array address aoqi@0: const Register to = rsi; // destination array address aoqi@0: const Register count = rdx; // elements count aoqi@0: const Register dword_count = rcx; aoqi@0: const Register qword_count = count; aoqi@0: const Register end_from = from; // source array end address aoqi@0: const Register end_to = to; // destination array end address aoqi@0: const Register saved_to = r11; // saved destination array address aoqi@0: // End pointers are inclusive, and if count is not zero they point aoqi@0: // to the last unit copied: end_to[0] := end_from[0] aoqi@0: aoqi@0: __ enter(); // required for proper stackwalking of RuntimeStub frame aoqi@0: assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. aoqi@0: aoqi@0: if (entry != NULL) { aoqi@0: *entry = __ pc(); aoqi@0: // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) aoqi@0: BLOCK_COMMENT("Entry:"); aoqi@0: } aoqi@0: aoqi@0: setup_arg_regs(); // from => rdi, to => rsi, count => rdx aoqi@0: // r9 and r10 may be used to save non-volatile registers aoqi@0: if (is_oop) { aoqi@0: __ movq(saved_to, to); aoqi@0: gen_write_ref_array_pre_barrier(to, count, dest_uninitialized); aoqi@0: } aoqi@0: aoqi@0: // 'from', 'to' and 'count' are now valid aoqi@0: __ movptr(dword_count, count); aoqi@0: __ shrptr(count, 1); // count => qword_count aoqi@0: aoqi@0: // Copy from low to high addresses. Use 'to' as scratch. aoqi@0: __ lea(end_from, Address(from, qword_count, Address::times_8, -8)); aoqi@0: __ lea(end_to, Address(to, qword_count, Address::times_8, -8)); aoqi@0: __ negptr(qword_count); aoqi@0: __ jmp(L_copy_bytes); aoqi@0: aoqi@0: // Copy trailing qwords aoqi@0: __ BIND(L_copy_8_bytes); aoqi@0: __ movq(rax, Address(end_from, qword_count, Address::times_8, 8)); aoqi@0: __ movq(Address(end_to, qword_count, Address::times_8, 8), rax); aoqi@0: __ increment(qword_count); aoqi@0: __ jcc(Assembler::notZero, L_copy_8_bytes); aoqi@0: aoqi@0: // Check for and copy trailing dword aoqi@0: __ BIND(L_copy_4_bytes); aoqi@0: __ testl(dword_count, 1); // Only byte test since the value is 0 or 1 aoqi@0: __ jccb(Assembler::zero, L_exit); aoqi@0: __ movl(rax, Address(end_from, 8)); aoqi@0: __ movl(Address(end_to, 8), rax); aoqi@0: aoqi@0: __ BIND(L_exit); aoqi@0: if (is_oop) { aoqi@0: gen_write_ref_array_post_barrier(saved_to, dword_count, rax); aoqi@0: } aoqi@0: restore_arg_regs(); aoqi@0: inc_counter_np(SharedRuntime::_jint_array_copy_ctr); // Update counter after rscratch1 is free aoqi@0: __ xorptr(rax, rax); // return 0 aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: aoqi@0: // Copy in multi-bytes chunks aoqi@0: copy_bytes_forward(end_from, end_to, qword_count, rax, L_copy_bytes, L_copy_8_bytes); aoqi@0: __ jmp(L_copy_4_bytes); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Arguments: aoqi@0: // aligned - true => Input and output aligned on a HeapWord == 8-byte boundary aoqi@0: // ignored aoqi@0: // is_oop - true => oop array, so generate store check code aoqi@0: // name - stub name string aoqi@0: // aoqi@0: // Inputs: aoqi@0: // c_rarg0 - source array address aoqi@0: // c_rarg1 - destination array address aoqi@0: // c_rarg2 - element count, treated as ssize_t, can be zero aoqi@0: // aoqi@0: // If 'from' and/or 'to' are aligned on 4-byte boundaries, we let aoqi@0: // the hardware handle it. The two dwords within qwords that span aoqi@0: // cache line boundaries will still be loaded and stored atomicly. aoqi@0: // aoqi@0: address generate_conjoint_int_oop_copy(bool aligned, bool is_oop, address nooverlap_target, aoqi@0: address *entry, const char *name, aoqi@0: bool dest_uninitialized = false) { aoqi@0: __ align(CodeEntryAlignment); aoqi@0: StubCodeMark mark(this, "StubRoutines", name); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: Label L_copy_bytes, L_copy_8_bytes, L_copy_2_bytes, L_exit; aoqi@0: const Register from = rdi; // source array address aoqi@0: const Register to = rsi; // destination array address aoqi@0: const Register count = rdx; // elements count aoqi@0: const Register dword_count = rcx; aoqi@0: const Register qword_count = count; aoqi@0: aoqi@0: __ enter(); // required for proper stackwalking of RuntimeStub frame aoqi@0: assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. aoqi@0: aoqi@0: if (entry != NULL) { aoqi@0: *entry = __ pc(); aoqi@0: // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) aoqi@0: BLOCK_COMMENT("Entry:"); aoqi@0: } aoqi@0: aoqi@0: array_overlap_test(nooverlap_target, Address::times_4); aoqi@0: setup_arg_regs(); // from => rdi, to => rsi, count => rdx aoqi@0: // r9 and r10 may be used to save non-volatile registers aoqi@0: aoqi@0: if (is_oop) { aoqi@0: // no registers are destroyed by this call aoqi@0: gen_write_ref_array_pre_barrier(to, count, dest_uninitialized); aoqi@0: } aoqi@0: aoqi@0: assert_clean_int(count, rax); // Make sure 'count' is clean int. aoqi@0: // 'from', 'to' and 'count' are now valid aoqi@0: __ movptr(dword_count, count); aoqi@0: __ shrptr(count, 1); // count => qword_count aoqi@0: aoqi@0: // Copy from high to low addresses. Use 'to' as scratch. aoqi@0: aoqi@0: // Check for and copy trailing dword aoqi@0: __ testl(dword_count, 1); aoqi@0: __ jcc(Assembler::zero, L_copy_bytes); aoqi@0: __ movl(rax, Address(from, dword_count, Address::times_4, -4)); aoqi@0: __ movl(Address(to, dword_count, Address::times_4, -4), rax); aoqi@0: __ jmp(L_copy_bytes); aoqi@0: aoqi@0: // Copy trailing qwords aoqi@0: __ BIND(L_copy_8_bytes); aoqi@0: __ movq(rax, Address(from, qword_count, Address::times_8, -8)); aoqi@0: __ movq(Address(to, qword_count, Address::times_8, -8), rax); aoqi@0: __ decrement(qword_count); aoqi@0: __ jcc(Assembler::notZero, L_copy_8_bytes); aoqi@0: aoqi@0: if (is_oop) { aoqi@0: __ jmp(L_exit); aoqi@0: } aoqi@0: restore_arg_regs(); aoqi@0: inc_counter_np(SharedRuntime::_jint_array_copy_ctr); // Update counter after rscratch1 is free aoqi@0: __ xorptr(rax, rax); // return 0 aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: aoqi@0: // Copy in multi-bytes chunks aoqi@0: copy_bytes_backward(from, to, qword_count, rax, L_copy_bytes, L_copy_8_bytes); aoqi@0: aoqi@0: __ BIND(L_exit); aoqi@0: if (is_oop) { aoqi@0: gen_write_ref_array_post_barrier(to, dword_count, rax); aoqi@0: } aoqi@0: restore_arg_regs(); aoqi@0: inc_counter_np(SharedRuntime::_jint_array_copy_ctr); // Update counter after rscratch1 is free aoqi@0: __ xorptr(rax, rax); // return 0 aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Arguments: aoqi@0: // aligned - true => Input and output aligned on a HeapWord boundary == 8 bytes aoqi@0: // ignored aoqi@0: // is_oop - true => oop array, so generate store check code aoqi@0: // name - stub name string aoqi@0: // aoqi@0: // Inputs: aoqi@0: // c_rarg0 - source array address aoqi@0: // c_rarg1 - destination array address aoqi@0: // c_rarg2 - element count, treated as ssize_t, can be zero aoqi@0: // aoqi@0: // Side Effects: aoqi@0: // disjoint_oop_copy_entry or disjoint_long_copy_entry is set to the aoqi@0: // no-overlap entry point used by generate_conjoint_long_oop_copy(). aoqi@0: // aoqi@0: address generate_disjoint_long_oop_copy(bool aligned, bool is_oop, address *entry, aoqi@0: const char *name, bool dest_uninitialized = false) { aoqi@0: __ align(CodeEntryAlignment); aoqi@0: StubCodeMark mark(this, "StubRoutines", name); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: Label L_copy_bytes, L_copy_8_bytes, L_exit; aoqi@0: const Register from = rdi; // source array address aoqi@0: const Register to = rsi; // destination array address aoqi@0: const Register qword_count = rdx; // elements count aoqi@0: const Register end_from = from; // source array end address aoqi@0: const Register end_to = rcx; // destination array end address aoqi@0: const Register saved_to = to; aoqi@0: const Register saved_count = r11; aoqi@0: // End pointers are inclusive, and if count is not zero they point aoqi@0: // to the last unit copied: end_to[0] := end_from[0] aoqi@0: aoqi@0: __ enter(); // required for proper stackwalking of RuntimeStub frame aoqi@0: // Save no-overlap entry point for generate_conjoint_long_oop_copy() aoqi@0: assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. aoqi@0: aoqi@0: if (entry != NULL) { aoqi@0: *entry = __ pc(); aoqi@0: // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) aoqi@0: BLOCK_COMMENT("Entry:"); aoqi@0: } aoqi@0: aoqi@0: setup_arg_regs(); // from => rdi, to => rsi, count => rdx aoqi@0: // r9 and r10 may be used to save non-volatile registers aoqi@0: // 'from', 'to' and 'qword_count' are now valid aoqi@0: if (is_oop) { aoqi@0: // Save to and count for store barrier aoqi@0: __ movptr(saved_count, qword_count); aoqi@0: // no registers are destroyed by this call aoqi@0: gen_write_ref_array_pre_barrier(to, qword_count, dest_uninitialized); aoqi@0: } aoqi@0: aoqi@0: // Copy from low to high addresses. Use 'to' as scratch. aoqi@0: __ lea(end_from, Address(from, qword_count, Address::times_8, -8)); aoqi@0: __ lea(end_to, Address(to, qword_count, Address::times_8, -8)); aoqi@0: __ negptr(qword_count); aoqi@0: __ jmp(L_copy_bytes); aoqi@0: aoqi@0: // Copy trailing qwords aoqi@0: __ BIND(L_copy_8_bytes); aoqi@0: __ movq(rax, Address(end_from, qword_count, Address::times_8, 8)); aoqi@0: __ movq(Address(end_to, qword_count, Address::times_8, 8), rax); aoqi@0: __ increment(qword_count); aoqi@0: __ jcc(Assembler::notZero, L_copy_8_bytes); aoqi@0: aoqi@0: if (is_oop) { aoqi@0: __ jmp(L_exit); aoqi@0: } else { aoqi@0: restore_arg_regs(); aoqi@0: inc_counter_np(SharedRuntime::_jlong_array_copy_ctr); // Update counter after rscratch1 is free aoqi@0: __ xorptr(rax, rax); // return 0 aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: } aoqi@0: aoqi@0: // Copy in multi-bytes chunks aoqi@0: copy_bytes_forward(end_from, end_to, qword_count, rax, L_copy_bytes, L_copy_8_bytes); aoqi@0: aoqi@0: if (is_oop) { aoqi@0: __ BIND(L_exit); aoqi@0: gen_write_ref_array_post_barrier(saved_to, saved_count, rax); aoqi@0: } aoqi@0: restore_arg_regs(); aoqi@0: if (is_oop) { aoqi@0: inc_counter_np(SharedRuntime::_oop_array_copy_ctr); // Update counter after rscratch1 is free aoqi@0: } else { aoqi@0: inc_counter_np(SharedRuntime::_jlong_array_copy_ctr); // Update counter after rscratch1 is free aoqi@0: } aoqi@0: __ xorptr(rax, rax); // return 0 aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Arguments: aoqi@0: // aligned - true => Input and output aligned on a HeapWord boundary == 8 bytes aoqi@0: // ignored aoqi@0: // is_oop - true => oop array, so generate store check code aoqi@0: // name - stub name string aoqi@0: // aoqi@0: // Inputs: aoqi@0: // c_rarg0 - source array address aoqi@0: // c_rarg1 - destination array address aoqi@0: // c_rarg2 - element count, treated as ssize_t, can be zero aoqi@0: // aoqi@0: address generate_conjoint_long_oop_copy(bool aligned, bool is_oop, aoqi@0: address nooverlap_target, address *entry, aoqi@0: const char *name, bool dest_uninitialized = false) { aoqi@0: __ align(CodeEntryAlignment); aoqi@0: StubCodeMark mark(this, "StubRoutines", name); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: Label L_copy_bytes, L_copy_8_bytes, L_exit; aoqi@0: const Register from = rdi; // source array address aoqi@0: const Register to = rsi; // destination array address aoqi@0: const Register qword_count = rdx; // elements count aoqi@0: const Register saved_count = rcx; aoqi@0: aoqi@0: __ enter(); // required for proper stackwalking of RuntimeStub frame aoqi@0: assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. aoqi@0: aoqi@0: if (entry != NULL) { aoqi@0: *entry = __ pc(); aoqi@0: // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) aoqi@0: BLOCK_COMMENT("Entry:"); aoqi@0: } aoqi@0: aoqi@0: array_overlap_test(nooverlap_target, Address::times_8); aoqi@0: setup_arg_regs(); // from => rdi, to => rsi, count => rdx aoqi@0: // r9 and r10 may be used to save non-volatile registers aoqi@0: // 'from', 'to' and 'qword_count' are now valid aoqi@0: if (is_oop) { aoqi@0: // Save to and count for store barrier aoqi@0: __ movptr(saved_count, qword_count); aoqi@0: // No registers are destroyed by this call aoqi@0: gen_write_ref_array_pre_barrier(to, saved_count, dest_uninitialized); aoqi@0: } aoqi@0: aoqi@0: __ jmp(L_copy_bytes); aoqi@0: aoqi@0: // Copy trailing qwords aoqi@0: __ BIND(L_copy_8_bytes); aoqi@0: __ movq(rax, Address(from, qword_count, Address::times_8, -8)); aoqi@0: __ movq(Address(to, qword_count, Address::times_8, -8), rax); aoqi@0: __ decrement(qword_count); aoqi@0: __ jcc(Assembler::notZero, L_copy_8_bytes); aoqi@0: aoqi@0: if (is_oop) { aoqi@0: __ jmp(L_exit); aoqi@0: } else { aoqi@0: restore_arg_regs(); aoqi@0: inc_counter_np(SharedRuntime::_jlong_array_copy_ctr); // Update counter after rscratch1 is free aoqi@0: __ xorptr(rax, rax); // return 0 aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: } aoqi@0: aoqi@0: // Copy in multi-bytes chunks aoqi@0: copy_bytes_backward(from, to, qword_count, rax, L_copy_bytes, L_copy_8_bytes); aoqi@0: aoqi@0: if (is_oop) { aoqi@0: __ BIND(L_exit); aoqi@0: gen_write_ref_array_post_barrier(to, saved_count, rax); aoqi@0: } aoqi@0: restore_arg_regs(); aoqi@0: if (is_oop) { aoqi@0: inc_counter_np(SharedRuntime::_oop_array_copy_ctr); // Update counter after rscratch1 is free aoqi@0: } else { aoqi@0: inc_counter_np(SharedRuntime::_jlong_array_copy_ctr); // Update counter after rscratch1 is free aoqi@0: } aoqi@0: __ xorptr(rax, rax); // return 0 aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Helper for generating a dynamic type check. aoqi@0: // Smashes no registers. aoqi@0: void generate_type_check(Register sub_klass, aoqi@0: Register super_check_offset, aoqi@0: Register super_klass, aoqi@0: Label& L_success) { aoqi@0: assert_different_registers(sub_klass, super_check_offset, super_klass); aoqi@0: aoqi@0: BLOCK_COMMENT("type_check:"); aoqi@0: aoqi@0: Label L_miss; aoqi@0: aoqi@0: __ check_klass_subtype_fast_path(sub_klass, super_klass, noreg, &L_success, &L_miss, NULL, aoqi@0: super_check_offset); aoqi@0: __ check_klass_subtype_slow_path(sub_klass, super_klass, noreg, noreg, &L_success, NULL); aoqi@0: aoqi@0: // Fall through on failure! aoqi@0: __ BIND(L_miss); aoqi@0: } aoqi@0: aoqi@0: // aoqi@0: // Generate checkcasting array copy stub aoqi@0: // aoqi@0: // Input: aoqi@0: // c_rarg0 - source array address aoqi@0: // c_rarg1 - destination array address aoqi@0: // c_rarg2 - element count, treated as ssize_t, can be zero aoqi@0: // c_rarg3 - size_t ckoff (super_check_offset) aoqi@0: // not Win64 aoqi@0: // c_rarg4 - oop ckval (super_klass) aoqi@0: // Win64 aoqi@0: // rsp+40 - oop ckval (super_klass) aoqi@0: // aoqi@0: // Output: aoqi@0: // rax == 0 - success aoqi@0: // rax == -1^K - failure, where K is partial transfer count aoqi@0: // aoqi@0: address generate_checkcast_copy(const char *name, address *entry, aoqi@0: bool dest_uninitialized = false) { aoqi@0: aoqi@0: Label L_load_element, L_store_element, L_do_card_marks, L_done; aoqi@0: aoqi@0: // Input registers (after setup_arg_regs) aoqi@0: const Register from = rdi; // source array address aoqi@0: const Register to = rsi; // destination array address aoqi@0: const Register length = rdx; // elements count aoqi@0: const Register ckoff = rcx; // super_check_offset aoqi@0: const Register ckval = r8; // super_klass aoqi@0: aoqi@0: // Registers used as temps (r13, r14 are save-on-entry) aoqi@0: const Register end_from = from; // source array end address aoqi@0: const Register end_to = r13; // destination array end address aoqi@0: const Register count = rdx; // -(count_remaining) aoqi@0: const Register r14_length = r14; // saved copy of length aoqi@0: // End pointers are inclusive, and if length is not zero they point aoqi@0: // to the last unit copied: end_to[0] := end_from[0] aoqi@0: aoqi@0: const Register rax_oop = rax; // actual oop copied aoqi@0: const Register r11_klass = r11; // oop._klass aoqi@0: aoqi@0: //--------------------------------------------------------------- aoqi@0: // Assembler stub will be used for this call to arraycopy aoqi@0: // if the two arrays are subtypes of Object[] but the aoqi@0: // destination array type is not equal to or a supertype aoqi@0: // of the source type. Each element must be separately aoqi@0: // checked. aoqi@0: aoqi@0: __ align(CodeEntryAlignment); aoqi@0: StubCodeMark mark(this, "StubRoutines", name); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: __ enter(); // required for proper stackwalking of RuntimeStub frame aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: // caller guarantees that the arrays really are different aoqi@0: // otherwise, we would have to make conjoint checks aoqi@0: { Label L; aoqi@0: array_overlap_test(L, TIMES_OOP); aoqi@0: __ stop("checkcast_copy within a single array"); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: #endif //ASSERT aoqi@0: aoqi@0: setup_arg_regs(4); // from => rdi, to => rsi, length => rdx aoqi@0: // ckoff => rcx, ckval => r8 aoqi@0: // r9 and r10 may be used to save non-volatile registers aoqi@0: #ifdef _WIN64 aoqi@0: // last argument (#4) is on stack on Win64 aoqi@0: __ movptr(ckval, Address(rsp, 6 * wordSize)); aoqi@0: #endif aoqi@0: aoqi@0: // Caller of this entry point must set up the argument registers. aoqi@0: if (entry != NULL) { aoqi@0: *entry = __ pc(); aoqi@0: BLOCK_COMMENT("Entry:"); aoqi@0: } aoqi@0: aoqi@0: // allocate spill slots for r13, r14 aoqi@0: enum { aoqi@0: saved_r13_offset, aoqi@0: saved_r14_offset, aoqi@0: saved_rbp_offset aoqi@0: }; aoqi@0: __ subptr(rsp, saved_rbp_offset * wordSize); aoqi@0: __ movptr(Address(rsp, saved_r13_offset * wordSize), r13); aoqi@0: __ movptr(Address(rsp, saved_r14_offset * wordSize), r14); aoqi@0: aoqi@0: // check that int operands are properly extended to size_t aoqi@0: assert_clean_int(length, rax); aoqi@0: assert_clean_int(ckoff, rax); aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: BLOCK_COMMENT("assert consistent ckoff/ckval"); aoqi@0: // The ckoff and ckval must be mutually consistent, aoqi@0: // even though caller generates both. aoqi@0: { Label L; aoqi@0: int sco_offset = in_bytes(Klass::super_check_offset_offset()); aoqi@0: __ cmpl(ckoff, Address(ckval, sco_offset)); aoqi@0: __ jcc(Assembler::equal, L); aoqi@0: __ stop("super_check_offset inconsistent"); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: #endif //ASSERT aoqi@0: aoqi@0: // Loop-invariant addresses. They are exclusive end pointers. aoqi@0: Address end_from_addr(from, length, TIMES_OOP, 0); aoqi@0: Address end_to_addr(to, length, TIMES_OOP, 0); aoqi@0: // Loop-variant addresses. They assume post-incremented count < 0. aoqi@0: Address from_element_addr(end_from, count, TIMES_OOP, 0); aoqi@0: Address to_element_addr(end_to, count, TIMES_OOP, 0); aoqi@0: aoqi@0: gen_write_ref_array_pre_barrier(to, count, dest_uninitialized); aoqi@0: aoqi@0: // Copy from low to high addresses, indexed from the end of each array. aoqi@0: __ lea(end_from, end_from_addr); aoqi@0: __ lea(end_to, end_to_addr); aoqi@0: __ movptr(r14_length, length); // save a copy of the length aoqi@0: assert(length == count, ""); // else fix next line: aoqi@0: __ negptr(count); // negate and test the length aoqi@0: __ jcc(Assembler::notZero, L_load_element); aoqi@0: aoqi@0: // Empty array: Nothing to do. aoqi@0: __ xorptr(rax, rax); // return 0 on (trivial) success aoqi@0: __ jmp(L_done); aoqi@0: aoqi@0: // ======== begin loop ======== aoqi@0: // (Loop is rotated; its entry is L_load_element.) aoqi@0: // Loop control: aoqi@0: // for (count = -count; count != 0; count++) aoqi@0: // Base pointers src, dst are biased by 8*(count-1),to last element. aoqi@0: __ align(OptoLoopAlignment); aoqi@0: aoqi@0: __ BIND(L_store_element); aoqi@0: __ store_heap_oop(to_element_addr, rax_oop); // store the oop aoqi@0: __ increment(count); // increment the count toward zero aoqi@0: __ jcc(Assembler::zero, L_do_card_marks); aoqi@0: aoqi@0: // ======== loop entry is here ======== aoqi@0: __ BIND(L_load_element); aoqi@0: __ load_heap_oop(rax_oop, from_element_addr); // load the oop aoqi@0: __ testptr(rax_oop, rax_oop); aoqi@0: __ jcc(Assembler::zero, L_store_element); aoqi@0: aoqi@0: __ load_klass(r11_klass, rax_oop);// query the object klass aoqi@0: generate_type_check(r11_klass, ckoff, ckval, L_store_element); aoqi@0: // ======== end loop ======== aoqi@0: aoqi@0: // It was a real error; we must depend on the caller to finish the job. aoqi@0: // Register rdx = -1 * number of *remaining* oops, r14 = *total* oops. aoqi@0: // Emit GC store barriers for the oops we have copied (r14 + rdx), aoqi@0: // and report their number to the caller. aoqi@0: assert_different_registers(rax, r14_length, count, to, end_to, rcx, rscratch1); aoqi@0: Label L_post_barrier; aoqi@0: __ addptr(r14_length, count); // K = (original - remaining) oops aoqi@0: __ movptr(rax, r14_length); // save the value aoqi@0: __ notptr(rax); // report (-1^K) to caller (does not affect flags) aoqi@0: __ jccb(Assembler::notZero, L_post_barrier); aoqi@0: __ jmp(L_done); // K == 0, nothing was copied, skip post barrier aoqi@0: aoqi@0: // Come here on success only. aoqi@0: __ BIND(L_do_card_marks); aoqi@0: __ xorptr(rax, rax); // return 0 on success aoqi@0: aoqi@0: __ BIND(L_post_barrier); aoqi@0: gen_write_ref_array_post_barrier(to, r14_length, rscratch1); aoqi@0: aoqi@0: // Common exit point (success or failure). aoqi@0: __ BIND(L_done); aoqi@0: __ movptr(r13, Address(rsp, saved_r13_offset * wordSize)); aoqi@0: __ movptr(r14, Address(rsp, saved_r14_offset * wordSize)); aoqi@0: restore_arg_regs(); aoqi@0: inc_counter_np(SharedRuntime::_checkcast_array_copy_ctr); // Update counter after rscratch1 is free aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // aoqi@0: // Generate 'unsafe' array copy stub aoqi@0: // Though just as safe as the other stubs, it takes an unscaled aoqi@0: // size_t argument instead of an element count. aoqi@0: // aoqi@0: // Input: aoqi@0: // c_rarg0 - source array address aoqi@0: // c_rarg1 - destination array address aoqi@0: // c_rarg2 - byte count, treated as ssize_t, can be zero aoqi@0: // aoqi@0: // Examines the alignment of the operands and dispatches aoqi@0: // to a long, int, short, or byte copy loop. aoqi@0: // aoqi@0: address generate_unsafe_copy(const char *name, aoqi@0: address byte_copy_entry, address short_copy_entry, aoqi@0: address int_copy_entry, address long_copy_entry) { aoqi@0: aoqi@0: Label L_long_aligned, L_int_aligned, L_short_aligned; aoqi@0: aoqi@0: // Input registers (before setup_arg_regs) aoqi@0: const Register from = c_rarg0; // source array address aoqi@0: const Register to = c_rarg1; // destination array address aoqi@0: const Register size = c_rarg2; // byte count (size_t) aoqi@0: aoqi@0: // Register used as a temp aoqi@0: const Register bits = rax; // test copy of low bits aoqi@0: aoqi@0: __ align(CodeEntryAlignment); aoqi@0: StubCodeMark mark(this, "StubRoutines", name); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: __ enter(); // required for proper stackwalking of RuntimeStub frame aoqi@0: aoqi@0: // bump this on entry, not on exit: aoqi@0: inc_counter_np(SharedRuntime::_unsafe_array_copy_ctr); aoqi@0: aoqi@0: __ mov(bits, from); aoqi@0: __ orptr(bits, to); aoqi@0: __ orptr(bits, size); aoqi@0: aoqi@0: __ testb(bits, BytesPerLong-1); aoqi@0: __ jccb(Assembler::zero, L_long_aligned); aoqi@0: aoqi@0: __ testb(bits, BytesPerInt-1); aoqi@0: __ jccb(Assembler::zero, L_int_aligned); aoqi@0: aoqi@0: __ testb(bits, BytesPerShort-1); aoqi@0: __ jump_cc(Assembler::notZero, RuntimeAddress(byte_copy_entry)); aoqi@0: aoqi@0: __ BIND(L_short_aligned); aoqi@0: __ shrptr(size, LogBytesPerShort); // size => short_count aoqi@0: __ jump(RuntimeAddress(short_copy_entry)); aoqi@0: aoqi@0: __ BIND(L_int_aligned); aoqi@0: __ shrptr(size, LogBytesPerInt); // size => int_count aoqi@0: __ jump(RuntimeAddress(int_copy_entry)); aoqi@0: aoqi@0: __ BIND(L_long_aligned); aoqi@0: __ shrptr(size, LogBytesPerLong); // size => qword_count aoqi@0: __ jump(RuntimeAddress(long_copy_entry)); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Perform range checks on the proposed arraycopy. aoqi@0: // Kills temp, but nothing else. aoqi@0: // Also, clean the sign bits of src_pos and dst_pos. aoqi@0: void arraycopy_range_checks(Register src, // source array oop (c_rarg0) aoqi@0: Register src_pos, // source position (c_rarg1) aoqi@0: Register dst, // destination array oo (c_rarg2) aoqi@0: Register dst_pos, // destination position (c_rarg3) aoqi@0: Register length, aoqi@0: Register temp, aoqi@0: Label& L_failed) { aoqi@0: BLOCK_COMMENT("arraycopy_range_checks:"); aoqi@0: aoqi@0: // if (src_pos + length > arrayOop(src)->length()) FAIL; aoqi@0: __ movl(temp, length); aoqi@0: __ addl(temp, src_pos); // src_pos + length aoqi@0: __ cmpl(temp, Address(src, arrayOopDesc::length_offset_in_bytes())); aoqi@0: __ jcc(Assembler::above, L_failed); aoqi@0: aoqi@0: // if (dst_pos + length > arrayOop(dst)->length()) FAIL; aoqi@0: __ movl(temp, length); aoqi@0: __ addl(temp, dst_pos); // dst_pos + length aoqi@0: __ cmpl(temp, Address(dst, arrayOopDesc::length_offset_in_bytes())); aoqi@0: __ jcc(Assembler::above, L_failed); aoqi@0: aoqi@0: // Have to clean up high 32-bits of 'src_pos' and 'dst_pos'. aoqi@0: // Move with sign extension can be used since they are positive. aoqi@0: __ movslq(src_pos, src_pos); aoqi@0: __ movslq(dst_pos, dst_pos); aoqi@0: aoqi@0: BLOCK_COMMENT("arraycopy_range_checks done"); aoqi@0: } aoqi@0: aoqi@0: // aoqi@0: // Generate generic array copy stubs aoqi@0: // aoqi@0: // Input: aoqi@0: // c_rarg0 - src oop aoqi@0: // c_rarg1 - src_pos (32-bits) aoqi@0: // c_rarg2 - dst oop aoqi@0: // c_rarg3 - dst_pos (32-bits) aoqi@0: // not Win64 aoqi@0: // c_rarg4 - element count (32-bits) aoqi@0: // Win64 aoqi@0: // rsp+40 - element count (32-bits) aoqi@0: // aoqi@0: // Output: aoqi@0: // rax == 0 - success aoqi@0: // rax == -1^K - failure, where K is partial transfer count aoqi@0: // aoqi@0: address generate_generic_copy(const char *name, aoqi@0: address byte_copy_entry, address short_copy_entry, aoqi@0: address int_copy_entry, address oop_copy_entry, aoqi@0: address long_copy_entry, address checkcast_copy_entry) { aoqi@0: aoqi@0: Label L_failed, L_failed_0, L_objArray; aoqi@0: Label L_copy_bytes, L_copy_shorts, L_copy_ints, L_copy_longs; aoqi@0: aoqi@0: // Input registers aoqi@0: const Register src = c_rarg0; // source array oop aoqi@0: const Register src_pos = c_rarg1; // source position aoqi@0: const Register dst = c_rarg2; // destination array oop aoqi@0: const Register dst_pos = c_rarg3; // destination position aoqi@0: #ifndef _WIN64 aoqi@0: const Register length = c_rarg4; aoqi@0: #else aoqi@0: const Address length(rsp, 6 * wordSize); // elements count is on stack on Win64 aoqi@0: #endif aoqi@0: aoqi@0: { int modulus = CodeEntryAlignment; aoqi@0: int target = modulus - 5; // 5 = sizeof jmp(L_failed) aoqi@0: int advance = target - (__ offset() % modulus); aoqi@0: if (advance < 0) advance += modulus; aoqi@0: if (advance > 0) __ nop(advance); aoqi@0: } aoqi@0: StubCodeMark mark(this, "StubRoutines", name); aoqi@0: aoqi@0: // Short-hop target to L_failed. Makes for denser prologue code. aoqi@0: __ BIND(L_failed_0); aoqi@0: __ jmp(L_failed); aoqi@0: assert(__ offset() % CodeEntryAlignment == 0, "no further alignment needed"); aoqi@0: aoqi@0: __ align(CodeEntryAlignment); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: __ enter(); // required for proper stackwalking of RuntimeStub frame aoqi@0: aoqi@0: // bump this on entry, not on exit: aoqi@0: inc_counter_np(SharedRuntime::_generic_array_copy_ctr); aoqi@0: aoqi@0: //----------------------------------------------------------------------- aoqi@0: // Assembler stub will be used for this call to arraycopy aoqi@0: // if the following conditions are met: aoqi@0: // aoqi@0: // (1) src and dst must not be null. aoqi@0: // (2) src_pos must not be negative. aoqi@0: // (3) dst_pos must not be negative. aoqi@0: // (4) length must not be negative. aoqi@0: // (5) src klass and dst klass should be the same and not NULL. aoqi@0: // (6) src and dst should be arrays. aoqi@0: // (7) src_pos + length must not exceed length of src. aoqi@0: // (8) dst_pos + length must not exceed length of dst. aoqi@0: // aoqi@0: aoqi@0: // if (src == NULL) return -1; aoqi@0: __ testptr(src, src); // src oop aoqi@0: size_t j1off = __ offset(); aoqi@0: __ jccb(Assembler::zero, L_failed_0); aoqi@0: aoqi@0: // if (src_pos < 0) return -1; aoqi@0: __ testl(src_pos, src_pos); // src_pos (32-bits) aoqi@0: __ jccb(Assembler::negative, L_failed_0); aoqi@0: aoqi@0: // if (dst == NULL) return -1; aoqi@0: __ testptr(dst, dst); // dst oop aoqi@0: __ jccb(Assembler::zero, L_failed_0); aoqi@0: aoqi@0: // if (dst_pos < 0) return -1; aoqi@0: __ testl(dst_pos, dst_pos); // dst_pos (32-bits) aoqi@0: size_t j4off = __ offset(); aoqi@0: __ jccb(Assembler::negative, L_failed_0); aoqi@0: aoqi@0: // The first four tests are very dense code, aoqi@0: // but not quite dense enough to put four aoqi@0: // jumps in a 16-byte instruction fetch buffer. aoqi@0: // That's good, because some branch predicters aoqi@0: // do not like jumps so close together. aoqi@0: // Make sure of this. aoqi@0: guarantee(((j1off ^ j4off) & ~15) != 0, "I$ line of 1st & 4th jumps"); aoqi@0: aoqi@0: // registers used as temp aoqi@0: const Register r11_length = r11; // elements count to copy aoqi@0: const Register r10_src_klass = r10; // array klass aoqi@0: aoqi@0: // if (length < 0) return -1; aoqi@0: __ movl(r11_length, length); // length (elements count, 32-bits value) aoqi@0: __ testl(r11_length, r11_length); aoqi@0: __ jccb(Assembler::negative, L_failed_0); aoqi@0: aoqi@0: __ load_klass(r10_src_klass, src); aoqi@0: #ifdef ASSERT aoqi@0: // assert(src->klass() != NULL); aoqi@0: { aoqi@0: BLOCK_COMMENT("assert klasses not null {"); aoqi@0: Label L1, L2; aoqi@0: __ testptr(r10_src_klass, r10_src_klass); aoqi@0: __ jcc(Assembler::notZero, L2); // it is broken if klass is NULL aoqi@0: __ bind(L1); aoqi@0: __ stop("broken null klass"); aoqi@0: __ bind(L2); aoqi@0: __ load_klass(rax, dst); aoqi@0: __ cmpq(rax, 0); aoqi@0: __ jcc(Assembler::equal, L1); // this would be broken also aoqi@0: BLOCK_COMMENT("} assert klasses not null done"); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // Load layout helper (32-bits) aoqi@0: // aoqi@0: // |array_tag| | header_size | element_type | |log2_element_size| aoqi@0: // 32 30 24 16 8 2 0 aoqi@0: // aoqi@0: // array_tag: typeArray = 0x3, objArray = 0x2, non-array = 0x0 aoqi@0: // aoqi@0: aoqi@0: const int lh_offset = in_bytes(Klass::layout_helper_offset()); aoqi@0: aoqi@0: // Handle objArrays completely differently... aoqi@0: const jint objArray_lh = Klass::array_layout_helper(T_OBJECT); aoqi@0: __ cmpl(Address(r10_src_klass, lh_offset), objArray_lh); aoqi@0: __ jcc(Assembler::equal, L_objArray); aoqi@0: aoqi@0: // if (src->klass() != dst->klass()) return -1; aoqi@0: __ load_klass(rax, dst); aoqi@0: __ cmpq(r10_src_klass, rax); aoqi@0: __ jcc(Assembler::notEqual, L_failed); aoqi@0: aoqi@0: const Register rax_lh = rax; // layout helper aoqi@0: __ movl(rax_lh, Address(r10_src_klass, lh_offset)); aoqi@0: aoqi@0: // if (!src->is_Array()) return -1; aoqi@0: __ cmpl(rax_lh, Klass::_lh_neutral_value); aoqi@0: __ jcc(Assembler::greaterEqual, L_failed); aoqi@0: aoqi@0: // At this point, it is known to be a typeArray (array_tag 0x3). aoqi@0: #ifdef ASSERT aoqi@0: { aoqi@0: BLOCK_COMMENT("assert primitive array {"); aoqi@0: Label L; aoqi@0: __ cmpl(rax_lh, (Klass::_lh_array_tag_type_value << Klass::_lh_array_tag_shift)); aoqi@0: __ jcc(Assembler::greaterEqual, L); aoqi@0: __ stop("must be a primitive array"); aoqi@0: __ bind(L); aoqi@0: BLOCK_COMMENT("} assert primitive array done"); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: arraycopy_range_checks(src, src_pos, dst, dst_pos, r11_length, aoqi@0: r10, L_failed); aoqi@0: aoqi@0: // TypeArrayKlass aoqi@0: // aoqi@0: // src_addr = (src + array_header_in_bytes()) + (src_pos << log2elemsize); aoqi@0: // dst_addr = (dst + array_header_in_bytes()) + (dst_pos << log2elemsize); aoqi@0: // aoqi@0: aoqi@0: const Register r10_offset = r10; // array offset aoqi@0: const Register rax_elsize = rax_lh; // element size aoqi@0: aoqi@0: __ movl(r10_offset, rax_lh); aoqi@0: __ shrl(r10_offset, Klass::_lh_header_size_shift); aoqi@0: __ andptr(r10_offset, Klass::_lh_header_size_mask); // array_offset aoqi@0: __ addptr(src, r10_offset); // src array offset aoqi@0: __ addptr(dst, r10_offset); // dst array offset aoqi@0: BLOCK_COMMENT("choose copy loop based on element size"); aoqi@0: __ andl(rax_lh, Klass::_lh_log2_element_size_mask); // rax_lh -> rax_elsize aoqi@0: aoqi@0: // next registers should be set before the jump to corresponding stub aoqi@0: const Register from = c_rarg0; // source array address aoqi@0: const Register to = c_rarg1; // destination array address aoqi@0: const Register count = c_rarg2; // elements count aoqi@0: aoqi@0: // 'from', 'to', 'count' registers should be set in such order aoqi@0: // since they are the same as 'src', 'src_pos', 'dst'. aoqi@0: aoqi@0: __ BIND(L_copy_bytes); aoqi@0: __ cmpl(rax_elsize, 0); aoqi@0: __ jccb(Assembler::notEqual, L_copy_shorts); aoqi@0: __ lea(from, Address(src, src_pos, Address::times_1, 0));// src_addr aoqi@0: __ lea(to, Address(dst, dst_pos, Address::times_1, 0));// dst_addr aoqi@0: __ movl2ptr(count, r11_length); // length aoqi@0: __ jump(RuntimeAddress(byte_copy_entry)); aoqi@0: aoqi@0: __ BIND(L_copy_shorts); aoqi@0: __ cmpl(rax_elsize, LogBytesPerShort); aoqi@0: __ jccb(Assembler::notEqual, L_copy_ints); aoqi@0: __ lea(from, Address(src, src_pos, Address::times_2, 0));// src_addr aoqi@0: __ lea(to, Address(dst, dst_pos, Address::times_2, 0));// dst_addr aoqi@0: __ movl2ptr(count, r11_length); // length aoqi@0: __ jump(RuntimeAddress(short_copy_entry)); aoqi@0: aoqi@0: __ BIND(L_copy_ints); aoqi@0: __ cmpl(rax_elsize, LogBytesPerInt); aoqi@0: __ jccb(Assembler::notEqual, L_copy_longs); aoqi@0: __ lea(from, Address(src, src_pos, Address::times_4, 0));// src_addr aoqi@0: __ lea(to, Address(dst, dst_pos, Address::times_4, 0));// dst_addr aoqi@0: __ movl2ptr(count, r11_length); // length aoqi@0: __ jump(RuntimeAddress(int_copy_entry)); aoqi@0: aoqi@0: __ BIND(L_copy_longs); aoqi@0: #ifdef ASSERT aoqi@0: { aoqi@0: BLOCK_COMMENT("assert long copy {"); aoqi@0: Label L; aoqi@0: __ cmpl(rax_elsize, LogBytesPerLong); aoqi@0: __ jcc(Assembler::equal, L); aoqi@0: __ stop("must be long copy, but elsize is wrong"); aoqi@0: __ bind(L); aoqi@0: BLOCK_COMMENT("} assert long copy done"); aoqi@0: } aoqi@0: #endif aoqi@0: __ lea(from, Address(src, src_pos, Address::times_8, 0));// src_addr aoqi@0: __ lea(to, Address(dst, dst_pos, Address::times_8, 0));// dst_addr aoqi@0: __ movl2ptr(count, r11_length); // length aoqi@0: __ jump(RuntimeAddress(long_copy_entry)); aoqi@0: aoqi@0: // ObjArrayKlass aoqi@0: __ BIND(L_objArray); aoqi@0: // live at this point: r10_src_klass, r11_length, src[_pos], dst[_pos] aoqi@0: aoqi@0: Label L_plain_copy, L_checkcast_copy; aoqi@0: // test array classes for subtyping aoqi@0: __ load_klass(rax, dst); aoqi@0: __ cmpq(r10_src_klass, rax); // usual case is exact equality aoqi@0: __ jcc(Assembler::notEqual, L_checkcast_copy); aoqi@0: aoqi@0: // Identically typed arrays can be copied without element-wise checks. aoqi@0: arraycopy_range_checks(src, src_pos, dst, dst_pos, r11_length, aoqi@0: r10, L_failed); aoqi@0: aoqi@0: __ lea(from, Address(src, src_pos, TIMES_OOP, aoqi@0: arrayOopDesc::base_offset_in_bytes(T_OBJECT))); // src_addr aoqi@0: __ lea(to, Address(dst, dst_pos, TIMES_OOP, aoqi@0: arrayOopDesc::base_offset_in_bytes(T_OBJECT))); // dst_addr aoqi@0: __ movl2ptr(count, r11_length); // length aoqi@0: __ BIND(L_plain_copy); aoqi@0: __ jump(RuntimeAddress(oop_copy_entry)); aoqi@0: aoqi@0: __ BIND(L_checkcast_copy); aoqi@0: // live at this point: r10_src_klass, r11_length, rax (dst_klass) aoqi@0: { aoqi@0: // Before looking at dst.length, make sure dst is also an objArray. aoqi@0: __ cmpl(Address(rax, lh_offset), objArray_lh); aoqi@0: __ jcc(Assembler::notEqual, L_failed); aoqi@0: aoqi@0: // It is safe to examine both src.length and dst.length. aoqi@0: arraycopy_range_checks(src, src_pos, dst, dst_pos, r11_length, aoqi@0: rax, L_failed); aoqi@0: aoqi@0: const Register r11_dst_klass = r11; aoqi@0: __ load_klass(r11_dst_klass, dst); // reload aoqi@0: aoqi@0: // Marshal the base address arguments now, freeing registers. aoqi@0: __ lea(from, Address(src, src_pos, TIMES_OOP, aoqi@0: arrayOopDesc::base_offset_in_bytes(T_OBJECT))); aoqi@0: __ lea(to, Address(dst, dst_pos, TIMES_OOP, aoqi@0: arrayOopDesc::base_offset_in_bytes(T_OBJECT))); aoqi@0: __ movl(count, length); // length (reloaded) aoqi@0: Register sco_temp = c_rarg3; // this register is free now aoqi@0: assert_different_registers(from, to, count, sco_temp, aoqi@0: r11_dst_klass, r10_src_klass); aoqi@0: assert_clean_int(count, sco_temp); aoqi@0: aoqi@0: // Generate the type check. aoqi@0: const int sco_offset = in_bytes(Klass::super_check_offset_offset()); aoqi@0: __ movl(sco_temp, Address(r11_dst_klass, sco_offset)); aoqi@0: assert_clean_int(sco_temp, rax); aoqi@0: generate_type_check(r10_src_klass, sco_temp, r11_dst_klass, L_plain_copy); aoqi@0: aoqi@0: // Fetch destination element klass from the ObjArrayKlass header. aoqi@0: int ek_offset = in_bytes(ObjArrayKlass::element_klass_offset()); aoqi@0: __ movptr(r11_dst_klass, Address(r11_dst_klass, ek_offset)); aoqi@0: __ movl( sco_temp, Address(r11_dst_klass, sco_offset)); aoqi@0: assert_clean_int(sco_temp, rax); aoqi@0: aoqi@0: // the checkcast_copy loop needs two extra arguments: aoqi@0: assert(c_rarg3 == sco_temp, "#3 already in place"); aoqi@0: // Set up arguments for checkcast_copy_entry. aoqi@0: setup_arg_regs(4); aoqi@0: __ movptr(r8, r11_dst_klass); // dst.klass.element_klass, r8 is c_rarg4 on Linux/Solaris aoqi@0: __ jump(RuntimeAddress(checkcast_copy_entry)); aoqi@0: } aoqi@0: aoqi@0: __ BIND(L_failed); aoqi@0: __ xorptr(rax, rax); aoqi@0: __ notptr(rax); // return -1 aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: void generate_arraycopy_stubs() { aoqi@0: address entry; aoqi@0: address entry_jbyte_arraycopy; aoqi@0: address entry_jshort_arraycopy; aoqi@0: address entry_jint_arraycopy; aoqi@0: address entry_oop_arraycopy; aoqi@0: address entry_jlong_arraycopy; aoqi@0: address entry_checkcast_arraycopy; aoqi@0: aoqi@0: StubRoutines::_jbyte_disjoint_arraycopy = generate_disjoint_byte_copy(false, &entry, aoqi@0: "jbyte_disjoint_arraycopy"); aoqi@0: StubRoutines::_jbyte_arraycopy = generate_conjoint_byte_copy(false, entry, &entry_jbyte_arraycopy, aoqi@0: "jbyte_arraycopy"); aoqi@0: aoqi@0: StubRoutines::_jshort_disjoint_arraycopy = generate_disjoint_short_copy(false, &entry, aoqi@0: "jshort_disjoint_arraycopy"); aoqi@0: StubRoutines::_jshort_arraycopy = generate_conjoint_short_copy(false, entry, &entry_jshort_arraycopy, aoqi@0: "jshort_arraycopy"); aoqi@0: aoqi@0: StubRoutines::_jint_disjoint_arraycopy = generate_disjoint_int_oop_copy(false, false, &entry, aoqi@0: "jint_disjoint_arraycopy"); aoqi@0: StubRoutines::_jint_arraycopy = generate_conjoint_int_oop_copy(false, false, entry, aoqi@0: &entry_jint_arraycopy, "jint_arraycopy"); aoqi@0: aoqi@0: StubRoutines::_jlong_disjoint_arraycopy = generate_disjoint_long_oop_copy(false, false, &entry, aoqi@0: "jlong_disjoint_arraycopy"); aoqi@0: StubRoutines::_jlong_arraycopy = generate_conjoint_long_oop_copy(false, false, entry, aoqi@0: &entry_jlong_arraycopy, "jlong_arraycopy"); aoqi@0: aoqi@0: aoqi@0: if (UseCompressedOops) { aoqi@0: StubRoutines::_oop_disjoint_arraycopy = generate_disjoint_int_oop_copy(false, true, &entry, aoqi@0: "oop_disjoint_arraycopy"); aoqi@0: StubRoutines::_oop_arraycopy = generate_conjoint_int_oop_copy(false, true, entry, aoqi@0: &entry_oop_arraycopy, "oop_arraycopy"); aoqi@0: StubRoutines::_oop_disjoint_arraycopy_uninit = generate_disjoint_int_oop_copy(false, true, &entry, aoqi@0: "oop_disjoint_arraycopy_uninit", aoqi@0: /*dest_uninitialized*/true); aoqi@0: StubRoutines::_oop_arraycopy_uninit = generate_conjoint_int_oop_copy(false, true, entry, aoqi@0: NULL, "oop_arraycopy_uninit", aoqi@0: /*dest_uninitialized*/true); aoqi@0: } else { aoqi@0: StubRoutines::_oop_disjoint_arraycopy = generate_disjoint_long_oop_copy(false, true, &entry, aoqi@0: "oop_disjoint_arraycopy"); aoqi@0: StubRoutines::_oop_arraycopy = generate_conjoint_long_oop_copy(false, true, entry, aoqi@0: &entry_oop_arraycopy, "oop_arraycopy"); aoqi@0: StubRoutines::_oop_disjoint_arraycopy_uninit = generate_disjoint_long_oop_copy(false, true, &entry, aoqi@0: "oop_disjoint_arraycopy_uninit", aoqi@0: /*dest_uninitialized*/true); aoqi@0: StubRoutines::_oop_arraycopy_uninit = generate_conjoint_long_oop_copy(false, true, entry, aoqi@0: NULL, "oop_arraycopy_uninit", aoqi@0: /*dest_uninitialized*/true); aoqi@0: } aoqi@0: aoqi@0: StubRoutines::_checkcast_arraycopy = generate_checkcast_copy("checkcast_arraycopy", &entry_checkcast_arraycopy); aoqi@0: StubRoutines::_checkcast_arraycopy_uninit = generate_checkcast_copy("checkcast_arraycopy_uninit", NULL, aoqi@0: /*dest_uninitialized*/true); aoqi@0: aoqi@0: StubRoutines::_unsafe_arraycopy = generate_unsafe_copy("unsafe_arraycopy", aoqi@0: entry_jbyte_arraycopy, aoqi@0: entry_jshort_arraycopy, aoqi@0: entry_jint_arraycopy, aoqi@0: entry_jlong_arraycopy); aoqi@0: StubRoutines::_generic_arraycopy = generate_generic_copy("generic_arraycopy", aoqi@0: entry_jbyte_arraycopy, aoqi@0: entry_jshort_arraycopy, aoqi@0: entry_jint_arraycopy, aoqi@0: entry_oop_arraycopy, aoqi@0: entry_jlong_arraycopy, aoqi@0: entry_checkcast_arraycopy); aoqi@0: aoqi@0: StubRoutines::_jbyte_fill = generate_fill(T_BYTE, false, "jbyte_fill"); aoqi@0: StubRoutines::_jshort_fill = generate_fill(T_SHORT, false, "jshort_fill"); aoqi@0: StubRoutines::_jint_fill = generate_fill(T_INT, false, "jint_fill"); aoqi@0: StubRoutines::_arrayof_jbyte_fill = generate_fill(T_BYTE, true, "arrayof_jbyte_fill"); aoqi@0: StubRoutines::_arrayof_jshort_fill = generate_fill(T_SHORT, true, "arrayof_jshort_fill"); aoqi@0: StubRoutines::_arrayof_jint_fill = generate_fill(T_INT, true, "arrayof_jint_fill"); aoqi@0: aoqi@0: // We don't generate specialized code for HeapWord-aligned source aoqi@0: // arrays, so just use the code we've already generated aoqi@0: StubRoutines::_arrayof_jbyte_disjoint_arraycopy = StubRoutines::_jbyte_disjoint_arraycopy; aoqi@0: StubRoutines::_arrayof_jbyte_arraycopy = StubRoutines::_jbyte_arraycopy; aoqi@0: aoqi@0: StubRoutines::_arrayof_jshort_disjoint_arraycopy = StubRoutines::_jshort_disjoint_arraycopy; aoqi@0: StubRoutines::_arrayof_jshort_arraycopy = StubRoutines::_jshort_arraycopy; aoqi@0: aoqi@0: StubRoutines::_arrayof_jint_disjoint_arraycopy = StubRoutines::_jint_disjoint_arraycopy; aoqi@0: StubRoutines::_arrayof_jint_arraycopy = StubRoutines::_jint_arraycopy; aoqi@0: aoqi@0: StubRoutines::_arrayof_jlong_disjoint_arraycopy = StubRoutines::_jlong_disjoint_arraycopy; aoqi@0: StubRoutines::_arrayof_jlong_arraycopy = StubRoutines::_jlong_arraycopy; aoqi@0: aoqi@0: StubRoutines::_arrayof_oop_disjoint_arraycopy = StubRoutines::_oop_disjoint_arraycopy; aoqi@0: StubRoutines::_arrayof_oop_arraycopy = StubRoutines::_oop_arraycopy; aoqi@0: aoqi@0: StubRoutines::_arrayof_oop_disjoint_arraycopy_uninit = StubRoutines::_oop_disjoint_arraycopy_uninit; aoqi@0: StubRoutines::_arrayof_oop_arraycopy_uninit = StubRoutines::_oop_arraycopy_uninit; aoqi@0: } aoqi@0: aoqi@0: void generate_math_stubs() { aoqi@0: { aoqi@0: StubCodeMark mark(this, "StubRoutines", "log"); aoqi@0: StubRoutines::_intrinsic_log = (double (*)(double)) __ pc(); aoqi@0: aoqi@0: __ subq(rsp, 8); aoqi@0: __ movdbl(Address(rsp, 0), xmm0); aoqi@0: __ fld_d(Address(rsp, 0)); aoqi@0: __ flog(); aoqi@0: __ fstp_d(Address(rsp, 0)); aoqi@0: __ movdbl(xmm0, Address(rsp, 0)); aoqi@0: __ addq(rsp, 8); aoqi@0: __ ret(0); aoqi@0: } aoqi@0: { aoqi@0: StubCodeMark mark(this, "StubRoutines", "log10"); aoqi@0: StubRoutines::_intrinsic_log10 = (double (*)(double)) __ pc(); aoqi@0: aoqi@0: __ subq(rsp, 8); aoqi@0: __ movdbl(Address(rsp, 0), xmm0); aoqi@0: __ fld_d(Address(rsp, 0)); aoqi@0: __ flog10(); aoqi@0: __ fstp_d(Address(rsp, 0)); aoqi@0: __ movdbl(xmm0, Address(rsp, 0)); aoqi@0: __ addq(rsp, 8); aoqi@0: __ ret(0); aoqi@0: } aoqi@0: { aoqi@0: StubCodeMark mark(this, "StubRoutines", "sin"); aoqi@0: StubRoutines::_intrinsic_sin = (double (*)(double)) __ pc(); aoqi@0: aoqi@0: __ subq(rsp, 8); aoqi@0: __ movdbl(Address(rsp, 0), xmm0); aoqi@0: __ fld_d(Address(rsp, 0)); aoqi@0: __ trigfunc('s'); aoqi@0: __ fstp_d(Address(rsp, 0)); aoqi@0: __ movdbl(xmm0, Address(rsp, 0)); aoqi@0: __ addq(rsp, 8); aoqi@0: __ ret(0); aoqi@0: } aoqi@0: { aoqi@0: StubCodeMark mark(this, "StubRoutines", "cos"); aoqi@0: StubRoutines::_intrinsic_cos = (double (*)(double)) __ pc(); aoqi@0: aoqi@0: __ subq(rsp, 8); aoqi@0: __ movdbl(Address(rsp, 0), xmm0); aoqi@0: __ fld_d(Address(rsp, 0)); aoqi@0: __ trigfunc('c'); aoqi@0: __ fstp_d(Address(rsp, 0)); aoqi@0: __ movdbl(xmm0, Address(rsp, 0)); aoqi@0: __ addq(rsp, 8); aoqi@0: __ ret(0); aoqi@0: } aoqi@0: { aoqi@0: StubCodeMark mark(this, "StubRoutines", "tan"); aoqi@0: StubRoutines::_intrinsic_tan = (double (*)(double)) __ pc(); aoqi@0: aoqi@0: __ subq(rsp, 8); aoqi@0: __ movdbl(Address(rsp, 0), xmm0); aoqi@0: __ fld_d(Address(rsp, 0)); aoqi@0: __ trigfunc('t'); aoqi@0: __ fstp_d(Address(rsp, 0)); aoqi@0: __ movdbl(xmm0, Address(rsp, 0)); aoqi@0: __ addq(rsp, 8); aoqi@0: __ ret(0); aoqi@0: } aoqi@0: { aoqi@0: StubCodeMark mark(this, "StubRoutines", "exp"); aoqi@0: StubRoutines::_intrinsic_exp = (double (*)(double)) __ pc(); aoqi@0: aoqi@0: __ subq(rsp, 8); aoqi@0: __ movdbl(Address(rsp, 0), xmm0); aoqi@0: __ fld_d(Address(rsp, 0)); aoqi@0: __ exp_with_fallback(0); aoqi@0: __ fstp_d(Address(rsp, 0)); aoqi@0: __ movdbl(xmm0, Address(rsp, 0)); aoqi@0: __ addq(rsp, 8); aoqi@0: __ ret(0); aoqi@0: } aoqi@0: { aoqi@0: StubCodeMark mark(this, "StubRoutines", "pow"); aoqi@0: StubRoutines::_intrinsic_pow = (double (*)(double,double)) __ pc(); aoqi@0: aoqi@0: __ subq(rsp, 8); aoqi@0: __ movdbl(Address(rsp, 0), xmm1); aoqi@0: __ fld_d(Address(rsp, 0)); aoqi@0: __ movdbl(Address(rsp, 0), xmm0); aoqi@0: __ fld_d(Address(rsp, 0)); aoqi@0: __ pow_with_fallback(0); aoqi@0: __ fstp_d(Address(rsp, 0)); aoqi@0: __ movdbl(xmm0, Address(rsp, 0)); aoqi@0: __ addq(rsp, 8); aoqi@0: __ ret(0); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // AES intrinsic stubs aoqi@0: enum {AESBlockSize = 16}; aoqi@0: aoqi@0: address generate_key_shuffle_mask() { aoqi@0: __ align(16); aoqi@0: StubCodeMark mark(this, "StubRoutines", "key_shuffle_mask"); aoqi@0: address start = __ pc(); aoqi@0: __ emit_data64( 0x0405060700010203, relocInfo::none ); aoqi@0: __ emit_data64( 0x0c0d0e0f08090a0b, relocInfo::none ); aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Utility routine for loading a 128-bit key word in little endian format aoqi@0: // can optionally specify that the shuffle mask is already in an xmmregister aoqi@0: void load_key(XMMRegister xmmdst, Register key, int offset, XMMRegister xmm_shuf_mask=NULL) { aoqi@0: __ movdqu(xmmdst, Address(key, offset)); aoqi@0: if (xmm_shuf_mask != NULL) { aoqi@0: __ pshufb(xmmdst, xmm_shuf_mask); aoqi@0: } else { aoqi@0: __ pshufb(xmmdst, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr())); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Arguments: aoqi@0: // aoqi@0: // Inputs: aoqi@0: // c_rarg0 - source byte array address aoqi@0: // c_rarg1 - destination byte array address aoqi@0: // c_rarg2 - K (key) in little endian int array aoqi@0: // aoqi@0: address generate_aescrypt_encryptBlock() { aoqi@0: assert(UseAES, "need AES instructions and misaligned SSE support"); aoqi@0: __ align(CodeEntryAlignment); aoqi@0: StubCodeMark mark(this, "StubRoutines", "aescrypt_encryptBlock"); aoqi@0: Label L_doLast; aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: const Register from = c_rarg0; // source array address aoqi@0: const Register to = c_rarg1; // destination array address aoqi@0: const Register key = c_rarg2; // key array address aoqi@0: const Register keylen = rax; aoqi@0: aoqi@0: const XMMRegister xmm_result = xmm0; aoqi@0: const XMMRegister xmm_key_shuf_mask = xmm1; aoqi@0: // On win64 xmm6-xmm15 must be preserved so don't use them. aoqi@0: const XMMRegister xmm_temp1 = xmm2; aoqi@0: const XMMRegister xmm_temp2 = xmm3; aoqi@0: const XMMRegister xmm_temp3 = xmm4; aoqi@0: const XMMRegister xmm_temp4 = xmm5; aoqi@0: aoqi@0: __ enter(); // required for proper stackwalking of RuntimeStub frame aoqi@0: aoqi@0: // keylen could be only {11, 13, 15} * 4 = {44, 52, 60} aoqi@0: __ movl(keylen, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT))); aoqi@0: aoqi@0: __ movdqu(xmm_key_shuf_mask, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr())); aoqi@0: __ movdqu(xmm_result, Address(from, 0)); // get 16 bytes of input aoqi@0: aoqi@0: // For encryption, the java expanded key ordering is just what we need aoqi@0: // we don't know if the key is aligned, hence not using load-execute form aoqi@0: aoqi@0: load_key(xmm_temp1, key, 0x00, xmm_key_shuf_mask); aoqi@0: __ pxor(xmm_result, xmm_temp1); aoqi@0: aoqi@0: load_key(xmm_temp1, key, 0x10, xmm_key_shuf_mask); aoqi@0: load_key(xmm_temp2, key, 0x20, xmm_key_shuf_mask); aoqi@0: load_key(xmm_temp3, key, 0x30, xmm_key_shuf_mask); aoqi@0: load_key(xmm_temp4, key, 0x40, xmm_key_shuf_mask); aoqi@0: aoqi@0: __ aesenc(xmm_result, xmm_temp1); aoqi@0: __ aesenc(xmm_result, xmm_temp2); aoqi@0: __ aesenc(xmm_result, xmm_temp3); aoqi@0: __ aesenc(xmm_result, xmm_temp4); aoqi@0: aoqi@0: load_key(xmm_temp1, key, 0x50, xmm_key_shuf_mask); aoqi@0: load_key(xmm_temp2, key, 0x60, xmm_key_shuf_mask); aoqi@0: load_key(xmm_temp3, key, 0x70, xmm_key_shuf_mask); aoqi@0: load_key(xmm_temp4, key, 0x80, xmm_key_shuf_mask); aoqi@0: aoqi@0: __ aesenc(xmm_result, xmm_temp1); aoqi@0: __ aesenc(xmm_result, xmm_temp2); aoqi@0: __ aesenc(xmm_result, xmm_temp3); aoqi@0: __ aesenc(xmm_result, xmm_temp4); aoqi@0: aoqi@0: load_key(xmm_temp1, key, 0x90, xmm_key_shuf_mask); aoqi@0: load_key(xmm_temp2, key, 0xa0, xmm_key_shuf_mask); aoqi@0: aoqi@0: __ cmpl(keylen, 44); aoqi@0: __ jccb(Assembler::equal, L_doLast); aoqi@0: aoqi@0: __ aesenc(xmm_result, xmm_temp1); aoqi@0: __ aesenc(xmm_result, xmm_temp2); aoqi@0: aoqi@0: load_key(xmm_temp1, key, 0xb0, xmm_key_shuf_mask); aoqi@0: load_key(xmm_temp2, key, 0xc0, xmm_key_shuf_mask); aoqi@0: aoqi@0: __ cmpl(keylen, 52); aoqi@0: __ jccb(Assembler::equal, L_doLast); aoqi@0: aoqi@0: __ aesenc(xmm_result, xmm_temp1); aoqi@0: __ aesenc(xmm_result, xmm_temp2); aoqi@0: aoqi@0: load_key(xmm_temp1, key, 0xd0, xmm_key_shuf_mask); aoqi@0: load_key(xmm_temp2, key, 0xe0, xmm_key_shuf_mask); aoqi@0: aoqi@0: __ BIND(L_doLast); aoqi@0: __ aesenc(xmm_result, xmm_temp1); aoqi@0: __ aesenclast(xmm_result, xmm_temp2); aoqi@0: __ movdqu(Address(to, 0), xmm_result); // store the result aoqi@0: __ xorptr(rax, rax); // return 0 aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Arguments: aoqi@0: // aoqi@0: // Inputs: aoqi@0: // c_rarg0 - source byte array address aoqi@0: // c_rarg1 - destination byte array address aoqi@0: // c_rarg2 - K (key) in little endian int array aoqi@0: // aoqi@0: address generate_aescrypt_decryptBlock() { aoqi@0: assert(UseAES, "need AES instructions and misaligned SSE support"); aoqi@0: __ align(CodeEntryAlignment); aoqi@0: StubCodeMark mark(this, "StubRoutines", "aescrypt_decryptBlock"); aoqi@0: Label L_doLast; aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: const Register from = c_rarg0; // source array address aoqi@0: const Register to = c_rarg1; // destination array address aoqi@0: const Register key = c_rarg2; // key array address aoqi@0: const Register keylen = rax; aoqi@0: aoqi@0: const XMMRegister xmm_result = xmm0; aoqi@0: const XMMRegister xmm_key_shuf_mask = xmm1; aoqi@0: // On win64 xmm6-xmm15 must be preserved so don't use them. aoqi@0: const XMMRegister xmm_temp1 = xmm2; aoqi@0: const XMMRegister xmm_temp2 = xmm3; aoqi@0: const XMMRegister xmm_temp3 = xmm4; aoqi@0: const XMMRegister xmm_temp4 = xmm5; aoqi@0: aoqi@0: __ enter(); // required for proper stackwalking of RuntimeStub frame aoqi@0: aoqi@0: // keylen could be only {11, 13, 15} * 4 = {44, 52, 60} aoqi@0: __ movl(keylen, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT))); aoqi@0: aoqi@0: __ movdqu(xmm_key_shuf_mask, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr())); aoqi@0: __ movdqu(xmm_result, Address(from, 0)); aoqi@0: aoqi@0: // for decryption java expanded key ordering is rotated one position from what we want aoqi@0: // so we start from 0x10 here and hit 0x00 last aoqi@0: // we don't know if the key is aligned, hence not using load-execute form aoqi@0: load_key(xmm_temp1, key, 0x10, xmm_key_shuf_mask); aoqi@0: load_key(xmm_temp2, key, 0x20, xmm_key_shuf_mask); aoqi@0: load_key(xmm_temp3, key, 0x30, xmm_key_shuf_mask); aoqi@0: load_key(xmm_temp4, key, 0x40, xmm_key_shuf_mask); aoqi@0: aoqi@0: __ pxor (xmm_result, xmm_temp1); aoqi@0: __ aesdec(xmm_result, xmm_temp2); aoqi@0: __ aesdec(xmm_result, xmm_temp3); aoqi@0: __ aesdec(xmm_result, xmm_temp4); aoqi@0: aoqi@0: load_key(xmm_temp1, key, 0x50, xmm_key_shuf_mask); aoqi@0: load_key(xmm_temp2, key, 0x60, xmm_key_shuf_mask); aoqi@0: load_key(xmm_temp3, key, 0x70, xmm_key_shuf_mask); aoqi@0: load_key(xmm_temp4, key, 0x80, xmm_key_shuf_mask); aoqi@0: aoqi@0: __ aesdec(xmm_result, xmm_temp1); aoqi@0: __ aesdec(xmm_result, xmm_temp2); aoqi@0: __ aesdec(xmm_result, xmm_temp3); aoqi@0: __ aesdec(xmm_result, xmm_temp4); aoqi@0: aoqi@0: load_key(xmm_temp1, key, 0x90, xmm_key_shuf_mask); aoqi@0: load_key(xmm_temp2, key, 0xa0, xmm_key_shuf_mask); aoqi@0: load_key(xmm_temp3, key, 0x00, xmm_key_shuf_mask); aoqi@0: aoqi@0: __ cmpl(keylen, 44); aoqi@0: __ jccb(Assembler::equal, L_doLast); aoqi@0: aoqi@0: __ aesdec(xmm_result, xmm_temp1); aoqi@0: __ aesdec(xmm_result, xmm_temp2); aoqi@0: aoqi@0: load_key(xmm_temp1, key, 0xb0, xmm_key_shuf_mask); aoqi@0: load_key(xmm_temp2, key, 0xc0, xmm_key_shuf_mask); aoqi@0: aoqi@0: __ cmpl(keylen, 52); aoqi@0: __ jccb(Assembler::equal, L_doLast); aoqi@0: aoqi@0: __ aesdec(xmm_result, xmm_temp1); aoqi@0: __ aesdec(xmm_result, xmm_temp2); aoqi@0: aoqi@0: load_key(xmm_temp1, key, 0xd0, xmm_key_shuf_mask); aoqi@0: load_key(xmm_temp2, key, 0xe0, xmm_key_shuf_mask); aoqi@0: aoqi@0: __ BIND(L_doLast); aoqi@0: __ aesdec(xmm_result, xmm_temp1); aoqi@0: __ aesdec(xmm_result, xmm_temp2); aoqi@0: aoqi@0: // for decryption the aesdeclast operation is always on key+0x00 aoqi@0: __ aesdeclast(xmm_result, xmm_temp3); aoqi@0: __ movdqu(Address(to, 0), xmm_result); // store the result aoqi@0: __ xorptr(rax, rax); // return 0 aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Arguments: aoqi@0: // aoqi@0: // Inputs: aoqi@0: // c_rarg0 - source byte array address aoqi@0: // c_rarg1 - destination byte array address aoqi@0: // c_rarg2 - K (key) in little endian int array aoqi@0: // c_rarg3 - r vector byte array address aoqi@0: // c_rarg4 - input length aoqi@0: // aoqi@0: // Output: aoqi@0: // rax - input length aoqi@0: // aoqi@0: address generate_cipherBlockChaining_encryptAESCrypt() { aoqi@0: assert(UseAES, "need AES instructions and misaligned SSE support"); aoqi@0: __ align(CodeEntryAlignment); aoqi@0: StubCodeMark mark(this, "StubRoutines", "cipherBlockChaining_encryptAESCrypt"); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: Label L_exit, L_key_192_256, L_key_256, L_loopTop_128, L_loopTop_192, L_loopTop_256; aoqi@0: const Register from = c_rarg0; // source array address aoqi@0: const Register to = c_rarg1; // destination array address aoqi@0: const Register key = c_rarg2; // key array address aoqi@0: const Register rvec = c_rarg3; // r byte array initialized from initvector array address aoqi@0: // and left with the results of the last encryption block aoqi@0: #ifndef _WIN64 aoqi@0: const Register len_reg = c_rarg4; // src len (must be multiple of blocksize 16) aoqi@0: #else aoqi@0: const Address len_mem(rbp, 6 * wordSize); // length is on stack on Win64 aoqi@0: const Register len_reg = r10; // pick the first volatile windows register aoqi@0: #endif aoqi@0: const Register pos = rax; aoqi@0: aoqi@0: // xmm register assignments for the loops below aoqi@0: const XMMRegister xmm_result = xmm0; aoqi@0: const XMMRegister xmm_temp = xmm1; aoqi@0: // keys 0-10 preloaded into xmm2-xmm12 aoqi@0: const int XMM_REG_NUM_KEY_FIRST = 2; aoqi@0: const int XMM_REG_NUM_KEY_LAST = 15; aoqi@0: const XMMRegister xmm_key0 = as_XMMRegister(XMM_REG_NUM_KEY_FIRST); aoqi@0: const XMMRegister xmm_key10 = as_XMMRegister(XMM_REG_NUM_KEY_FIRST+10); aoqi@0: const XMMRegister xmm_key11 = as_XMMRegister(XMM_REG_NUM_KEY_FIRST+11); aoqi@0: const XMMRegister xmm_key12 = as_XMMRegister(XMM_REG_NUM_KEY_FIRST+12); aoqi@0: const XMMRegister xmm_key13 = as_XMMRegister(XMM_REG_NUM_KEY_FIRST+13); aoqi@0: aoqi@0: __ enter(); // required for proper stackwalking of RuntimeStub frame aoqi@0: aoqi@0: #ifdef _WIN64 aoqi@0: // on win64, fill len_reg from stack position aoqi@0: __ movl(len_reg, len_mem); aoqi@0: // save the xmm registers which must be preserved 6-15 aoqi@0: __ subptr(rsp, -rsp_after_call_off * wordSize); aoqi@0: for (int i = 6; i <= XMM_REG_NUM_KEY_LAST; i++) { aoqi@0: __ movdqu(xmm_save(i), as_XMMRegister(i)); aoqi@0: } aoqi@0: #else aoqi@0: __ push(len_reg); // Save aoqi@0: #endif aoqi@0: aoqi@0: const XMMRegister xmm_key_shuf_mask = xmm_temp; // used temporarily to swap key bytes up front aoqi@0: __ movdqu(xmm_key_shuf_mask, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr())); aoqi@0: // load up xmm regs xmm2 thru xmm12 with key 0x00 - 0xa0 aoqi@0: for (int rnum = XMM_REG_NUM_KEY_FIRST, offset = 0x00; rnum <= XMM_REG_NUM_KEY_FIRST+10; rnum++) { aoqi@0: load_key(as_XMMRegister(rnum), key, offset, xmm_key_shuf_mask); aoqi@0: offset += 0x10; aoqi@0: } aoqi@0: __ movdqu(xmm_result, Address(rvec, 0x00)); // initialize xmm_result with r vec aoqi@0: aoqi@0: // now split to different paths depending on the keylen (len in ints of AESCrypt.KLE array (52=192, or 60=256)) aoqi@0: __ movl(rax, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT))); aoqi@0: __ cmpl(rax, 44); aoqi@0: __ jcc(Assembler::notEqual, L_key_192_256); aoqi@0: aoqi@0: // 128 bit code follows here aoqi@0: __ movptr(pos, 0); aoqi@0: __ align(OptoLoopAlignment); aoqi@0: aoqi@0: __ BIND(L_loopTop_128); aoqi@0: __ movdqu(xmm_temp, Address(from, pos, Address::times_1, 0)); // get next 16 bytes of input aoqi@0: __ pxor (xmm_result, xmm_temp); // xor with the current r vector aoqi@0: __ pxor (xmm_result, xmm_key0); // do the aes rounds aoqi@0: for (int rnum = XMM_REG_NUM_KEY_FIRST + 1; rnum <= XMM_REG_NUM_KEY_FIRST + 9; rnum++) { aoqi@0: __ aesenc(xmm_result, as_XMMRegister(rnum)); aoqi@0: } aoqi@0: __ aesenclast(xmm_result, xmm_key10); aoqi@0: __ movdqu(Address(to, pos, Address::times_1, 0), xmm_result); // store into the next 16 bytes of output aoqi@0: // no need to store r to memory until we exit aoqi@0: __ addptr(pos, AESBlockSize); aoqi@0: __ subptr(len_reg, AESBlockSize); aoqi@0: __ jcc(Assembler::notEqual, L_loopTop_128); aoqi@0: aoqi@0: __ BIND(L_exit); aoqi@0: __ movdqu(Address(rvec, 0), xmm_result); // final value of r stored in rvec of CipherBlockChaining object aoqi@0: aoqi@0: #ifdef _WIN64 aoqi@0: // restore xmm regs belonging to calling function aoqi@0: for (int i = 6; i <= XMM_REG_NUM_KEY_LAST; i++) { aoqi@0: __ movdqu(as_XMMRegister(i), xmm_save(i)); aoqi@0: } aoqi@0: __ movl(rax, len_mem); aoqi@0: #else aoqi@0: __ pop(rax); // return length aoqi@0: #endif aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: aoqi@0: __ BIND(L_key_192_256); aoqi@0: // here rax = len in ints of AESCrypt.KLE array (52=192, or 60=256) aoqi@0: load_key(xmm_key11, key, 0xb0, xmm_key_shuf_mask); aoqi@0: load_key(xmm_key12, key, 0xc0, xmm_key_shuf_mask); aoqi@0: __ cmpl(rax, 52); aoqi@0: __ jcc(Assembler::notEqual, L_key_256); aoqi@0: aoqi@0: // 192-bit code follows here (could be changed to use more xmm registers) aoqi@0: __ movptr(pos, 0); aoqi@0: __ align(OptoLoopAlignment); aoqi@0: aoqi@0: __ BIND(L_loopTop_192); aoqi@0: __ movdqu(xmm_temp, Address(from, pos, Address::times_1, 0)); // get next 16 bytes of input aoqi@0: __ pxor (xmm_result, xmm_temp); // xor with the current r vector aoqi@0: __ pxor (xmm_result, xmm_key0); // do the aes rounds aoqi@0: for (int rnum = XMM_REG_NUM_KEY_FIRST + 1; rnum <= XMM_REG_NUM_KEY_FIRST + 11; rnum++) { aoqi@0: __ aesenc(xmm_result, as_XMMRegister(rnum)); aoqi@0: } aoqi@0: __ aesenclast(xmm_result, xmm_key12); aoqi@0: __ movdqu(Address(to, pos, Address::times_1, 0), xmm_result); // store into the next 16 bytes of output aoqi@0: // no need to store r to memory until we exit aoqi@0: __ addptr(pos, AESBlockSize); aoqi@0: __ subptr(len_reg, AESBlockSize); aoqi@0: __ jcc(Assembler::notEqual, L_loopTop_192); aoqi@0: __ jmp(L_exit); aoqi@0: aoqi@0: __ BIND(L_key_256); aoqi@0: // 256-bit code follows here (could be changed to use more xmm registers) aoqi@0: load_key(xmm_key13, key, 0xd0, xmm_key_shuf_mask); aoqi@0: __ movptr(pos, 0); aoqi@0: __ align(OptoLoopAlignment); aoqi@0: aoqi@0: __ BIND(L_loopTop_256); aoqi@0: __ movdqu(xmm_temp, Address(from, pos, Address::times_1, 0)); // get next 16 bytes of input aoqi@0: __ pxor (xmm_result, xmm_temp); // xor with the current r vector aoqi@0: __ pxor (xmm_result, xmm_key0); // do the aes rounds aoqi@0: for (int rnum = XMM_REG_NUM_KEY_FIRST + 1; rnum <= XMM_REG_NUM_KEY_FIRST + 13; rnum++) { aoqi@0: __ aesenc(xmm_result, as_XMMRegister(rnum)); aoqi@0: } aoqi@0: load_key(xmm_temp, key, 0xe0); aoqi@0: __ aesenclast(xmm_result, xmm_temp); aoqi@0: __ movdqu(Address(to, pos, Address::times_1, 0), xmm_result); // store into the next 16 bytes of output aoqi@0: // no need to store r to memory until we exit aoqi@0: __ addptr(pos, AESBlockSize); aoqi@0: __ subptr(len_reg, AESBlockSize); aoqi@0: __ jcc(Assembler::notEqual, L_loopTop_256); aoqi@0: __ jmp(L_exit); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: // Safefetch stubs. aoqi@0: void generate_safefetch(const char* name, int size, address* entry, aoqi@0: address* fault_pc, address* continuation_pc) { aoqi@0: // safefetch signatures: aoqi@0: // int SafeFetch32(int* adr, int errValue); aoqi@0: // intptr_t SafeFetchN (intptr_t* adr, intptr_t errValue); aoqi@0: // aoqi@0: // arguments: aoqi@0: // c_rarg0 = adr aoqi@0: // c_rarg1 = errValue aoqi@0: // aoqi@0: // result: aoqi@0: // PPC_RET = *adr or errValue aoqi@0: aoqi@0: StubCodeMark mark(this, "StubRoutines", name); aoqi@0: aoqi@0: // Entry point, pc or function descriptor. aoqi@0: *entry = __ pc(); aoqi@0: aoqi@0: // Load *adr into c_rarg1, may fault. aoqi@0: *fault_pc = __ pc(); aoqi@0: switch (size) { aoqi@0: case 4: aoqi@0: // int32_t aoqi@0: __ movl(c_rarg1, Address(c_rarg0, 0)); aoqi@0: break; aoqi@0: case 8: aoqi@0: // int64_t aoqi@0: __ movq(c_rarg1, Address(c_rarg0, 0)); aoqi@0: break; aoqi@0: default: aoqi@0: ShouldNotReachHere(); aoqi@0: } aoqi@0: aoqi@0: // return errValue or *adr aoqi@0: *continuation_pc = __ pc(); aoqi@0: __ movq(rax, c_rarg1); aoqi@0: __ ret(0); aoqi@0: } aoqi@0: aoqi@0: // This is a version of CBC/AES Decrypt which does 4 blocks in a loop at a time aoqi@0: // to hide instruction latency aoqi@0: // aoqi@0: // Arguments: aoqi@0: // aoqi@0: // Inputs: aoqi@0: // c_rarg0 - source byte array address aoqi@0: // c_rarg1 - destination byte array address aoqi@0: // c_rarg2 - K (key) in little endian int array aoqi@0: // c_rarg3 - r vector byte array address aoqi@0: // c_rarg4 - input length aoqi@0: // aoqi@0: // Output: aoqi@0: // rax - input length aoqi@0: // aoqi@0: aoqi@0: address generate_cipherBlockChaining_decryptAESCrypt_Parallel() { aoqi@0: assert(UseAES, "need AES instructions and misaligned SSE support"); aoqi@0: __ align(CodeEntryAlignment); aoqi@0: StubCodeMark mark(this, "StubRoutines", "cipherBlockChaining_decryptAESCrypt"); aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: Label L_exit, L_key_192_256, L_key_256; aoqi@0: Label L_singleBlock_loopTop_128, L_multiBlock_loopTop_128; aoqi@0: Label L_singleBlock_loopTop_192, L_singleBlock_loopTop_256; aoqi@0: const Register from = c_rarg0; // source array address aoqi@0: const Register to = c_rarg1; // destination array address aoqi@0: const Register key = c_rarg2; // key array address aoqi@0: const Register rvec = c_rarg3; // r byte array initialized from initvector array address aoqi@0: // and left with the results of the last encryption block aoqi@0: #ifndef _WIN64 aoqi@0: const Register len_reg = c_rarg4; // src len (must be multiple of blocksize 16) aoqi@0: #else aoqi@0: const Address len_mem(rbp, 6 * wordSize); // length is on stack on Win64 aoqi@0: const Register len_reg = r10; // pick the first volatile windows register aoqi@0: #endif aoqi@0: const Register pos = rax; aoqi@0: aoqi@0: // keys 0-10 preloaded into xmm2-xmm12 aoqi@0: const int XMM_REG_NUM_KEY_FIRST = 5; aoqi@0: const int XMM_REG_NUM_KEY_LAST = 15; aoqi@0: const XMMRegister xmm_key_first = as_XMMRegister(XMM_REG_NUM_KEY_FIRST); aoqi@0: const XMMRegister xmm_key_last = as_XMMRegister(XMM_REG_NUM_KEY_LAST); aoqi@0: aoqi@0: __ enter(); // required for proper stackwalking of RuntimeStub frame aoqi@0: aoqi@0: #ifdef _WIN64 aoqi@0: // on win64, fill len_reg from stack position aoqi@0: __ movl(len_reg, len_mem); aoqi@0: // save the xmm registers which must be preserved 6-15 aoqi@0: __ subptr(rsp, -rsp_after_call_off * wordSize); aoqi@0: for (int i = 6; i <= XMM_REG_NUM_KEY_LAST; i++) { aoqi@0: __ movdqu(xmm_save(i), as_XMMRegister(i)); aoqi@0: } aoqi@0: #else aoqi@0: __ push(len_reg); // Save aoqi@0: #endif aoqi@0: aoqi@0: // the java expanded key ordering is rotated one position from what we want aoqi@0: // so we start from 0x10 here and hit 0x00 last aoqi@0: const XMMRegister xmm_key_shuf_mask = xmm1; // used temporarily to swap key bytes up front aoqi@0: __ movdqu(xmm_key_shuf_mask, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr())); aoqi@0: // load up xmm regs 5 thru 15 with key 0x10 - 0xa0 - 0x00 aoqi@0: for (int rnum = XMM_REG_NUM_KEY_FIRST, offset = 0x10; rnum < XMM_REG_NUM_KEY_LAST; rnum++) { aoqi@0: load_key(as_XMMRegister(rnum), key, offset, xmm_key_shuf_mask); aoqi@0: offset += 0x10; aoqi@0: } aoqi@0: load_key(xmm_key_last, key, 0x00, xmm_key_shuf_mask); aoqi@0: aoqi@0: const XMMRegister xmm_prev_block_cipher = xmm1; // holds cipher of previous block aoqi@0: aoqi@0: // registers holding the four results in the parallelized loop aoqi@0: const XMMRegister xmm_result0 = xmm0; aoqi@0: const XMMRegister xmm_result1 = xmm2; aoqi@0: const XMMRegister xmm_result2 = xmm3; aoqi@0: const XMMRegister xmm_result3 = xmm4; aoqi@0: aoqi@0: __ movdqu(xmm_prev_block_cipher, Address(rvec, 0x00)); // initialize with initial rvec aoqi@0: aoqi@0: // now split to different paths depending on the keylen (len in ints of AESCrypt.KLE array (52=192, or 60=256)) aoqi@0: __ movl(rax, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT))); aoqi@0: __ cmpl(rax, 44); aoqi@0: __ jcc(Assembler::notEqual, L_key_192_256); aoqi@0: aoqi@0: aoqi@0: // 128-bit code follows here, parallelized aoqi@0: __ movptr(pos, 0); aoqi@0: __ align(OptoLoopAlignment); aoqi@0: __ BIND(L_multiBlock_loopTop_128); aoqi@0: __ cmpptr(len_reg, 4*AESBlockSize); // see if at least 4 blocks left aoqi@0: __ jcc(Assembler::less, L_singleBlock_loopTop_128); aoqi@0: aoqi@0: __ movdqu(xmm_result0, Address(from, pos, Address::times_1, 0*AESBlockSize)); // get next 4 blocks into xmmresult registers aoqi@0: __ movdqu(xmm_result1, Address(from, pos, Address::times_1, 1*AESBlockSize)); aoqi@0: __ movdqu(xmm_result2, Address(from, pos, Address::times_1, 2*AESBlockSize)); aoqi@0: __ movdqu(xmm_result3, Address(from, pos, Address::times_1, 3*AESBlockSize)); aoqi@0: aoqi@0: #define DoFour(opc, src_reg) \ aoqi@0: __ opc(xmm_result0, src_reg); \ aoqi@0: __ opc(xmm_result1, src_reg); \ aoqi@0: __ opc(xmm_result2, src_reg); \ aoqi@0: __ opc(xmm_result3, src_reg); aoqi@0: aoqi@0: DoFour(pxor, xmm_key_first); aoqi@0: for (int rnum = XMM_REG_NUM_KEY_FIRST + 1; rnum <= XMM_REG_NUM_KEY_LAST - 1; rnum++) { aoqi@0: DoFour(aesdec, as_XMMRegister(rnum)); aoqi@0: } aoqi@0: DoFour(aesdeclast, xmm_key_last); aoqi@0: // for each result, xor with the r vector of previous cipher block aoqi@0: __ pxor(xmm_result0, xmm_prev_block_cipher); aoqi@0: __ movdqu(xmm_prev_block_cipher, Address(from, pos, Address::times_1, 0*AESBlockSize)); aoqi@0: __ pxor(xmm_result1, xmm_prev_block_cipher); aoqi@0: __ movdqu(xmm_prev_block_cipher, Address(from, pos, Address::times_1, 1*AESBlockSize)); aoqi@0: __ pxor(xmm_result2, xmm_prev_block_cipher); aoqi@0: __ movdqu(xmm_prev_block_cipher, Address(from, pos, Address::times_1, 2*AESBlockSize)); aoqi@0: __ pxor(xmm_result3, xmm_prev_block_cipher); aoqi@0: __ movdqu(xmm_prev_block_cipher, Address(from, pos, Address::times_1, 3*AESBlockSize)); // this will carry over to next set of blocks aoqi@0: aoqi@0: __ movdqu(Address(to, pos, Address::times_1, 0*AESBlockSize), xmm_result0); // store 4 results into the next 64 bytes of output aoqi@0: __ movdqu(Address(to, pos, Address::times_1, 1*AESBlockSize), xmm_result1); aoqi@0: __ movdqu(Address(to, pos, Address::times_1, 2*AESBlockSize), xmm_result2); aoqi@0: __ movdqu(Address(to, pos, Address::times_1, 3*AESBlockSize), xmm_result3); aoqi@0: aoqi@0: __ addptr(pos, 4*AESBlockSize); aoqi@0: __ subptr(len_reg, 4*AESBlockSize); aoqi@0: __ jmp(L_multiBlock_loopTop_128); aoqi@0: aoqi@0: // registers used in the non-parallelized loops aoqi@0: // xmm register assignments for the loops below aoqi@0: const XMMRegister xmm_result = xmm0; aoqi@0: const XMMRegister xmm_prev_block_cipher_save = xmm2; aoqi@0: const XMMRegister xmm_key11 = xmm3; aoqi@0: const XMMRegister xmm_key12 = xmm4; aoqi@0: const XMMRegister xmm_temp = xmm4; aoqi@0: aoqi@0: __ align(OptoLoopAlignment); aoqi@0: __ BIND(L_singleBlock_loopTop_128); aoqi@0: __ cmpptr(len_reg, 0); // any blocks left?? aoqi@0: __ jcc(Assembler::equal, L_exit); aoqi@0: __ movdqu(xmm_result, Address(from, pos, Address::times_1, 0)); // get next 16 bytes of cipher input aoqi@0: __ movdqa(xmm_prev_block_cipher_save, xmm_result); // save for next r vector aoqi@0: __ pxor (xmm_result, xmm_key_first); // do the aes dec rounds aoqi@0: for (int rnum = XMM_REG_NUM_KEY_FIRST + 1; rnum <= XMM_REG_NUM_KEY_LAST - 1; rnum++) { aoqi@0: __ aesdec(xmm_result, as_XMMRegister(rnum)); aoqi@0: } aoqi@0: __ aesdeclast(xmm_result, xmm_key_last); aoqi@0: __ pxor (xmm_result, xmm_prev_block_cipher); // xor with the current r vector aoqi@0: __ movdqu(Address(to, pos, Address::times_1, 0), xmm_result); // store into the next 16 bytes of output aoqi@0: // no need to store r to memory until we exit aoqi@0: __ movdqa(xmm_prev_block_cipher, xmm_prev_block_cipher_save); // set up next r vector with cipher input from this block aoqi@0: aoqi@0: __ addptr(pos, AESBlockSize); aoqi@0: __ subptr(len_reg, AESBlockSize); aoqi@0: __ jmp(L_singleBlock_loopTop_128); aoqi@0: aoqi@0: aoqi@0: __ BIND(L_exit); aoqi@0: __ movdqu(Address(rvec, 0), xmm_prev_block_cipher); // final value of r stored in rvec of CipherBlockChaining object aoqi@0: #ifdef _WIN64 aoqi@0: // restore regs belonging to calling function aoqi@0: for (int i = 6; i <= XMM_REG_NUM_KEY_LAST; i++) { aoqi@0: __ movdqu(as_XMMRegister(i), xmm_save(i)); aoqi@0: } aoqi@0: __ movl(rax, len_mem); aoqi@0: #else aoqi@0: __ pop(rax); // return length aoqi@0: #endif aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: aoqi@0: aoqi@0: __ BIND(L_key_192_256); aoqi@0: // here rax = len in ints of AESCrypt.KLE array (52=192, or 60=256) aoqi@0: load_key(xmm_key11, key, 0xb0); aoqi@0: __ cmpl(rax, 52); aoqi@0: __ jcc(Assembler::notEqual, L_key_256); aoqi@0: aoqi@0: // 192-bit code follows here (could be optimized to use parallelism) aoqi@0: load_key(xmm_key12, key, 0xc0); // 192-bit key goes up to c0 aoqi@0: __ movptr(pos, 0); aoqi@0: __ align(OptoLoopAlignment); aoqi@0: aoqi@0: __ BIND(L_singleBlock_loopTop_192); aoqi@0: __ movdqu(xmm_result, Address(from, pos, Address::times_1, 0)); // get next 16 bytes of cipher input aoqi@0: __ movdqa(xmm_prev_block_cipher_save, xmm_result); // save for next r vector aoqi@0: __ pxor (xmm_result, xmm_key_first); // do the aes dec rounds aoqi@0: for (int rnum = XMM_REG_NUM_KEY_FIRST + 1; rnum <= XMM_REG_NUM_KEY_LAST - 1; rnum++) { aoqi@0: __ aesdec(xmm_result, as_XMMRegister(rnum)); aoqi@0: } aoqi@0: __ aesdec(xmm_result, xmm_key11); aoqi@0: __ aesdec(xmm_result, xmm_key12); aoqi@0: __ aesdeclast(xmm_result, xmm_key_last); // xmm15 always came from key+0 aoqi@0: __ pxor (xmm_result, xmm_prev_block_cipher); // xor with the current r vector aoqi@0: __ movdqu(Address(to, pos, Address::times_1, 0), xmm_result); // store into the next 16 bytes of output aoqi@0: // no need to store r to memory until we exit aoqi@0: __ movdqa(xmm_prev_block_cipher, xmm_prev_block_cipher_save); // set up next r vector with cipher input from this block aoqi@0: __ addptr(pos, AESBlockSize); aoqi@0: __ subptr(len_reg, AESBlockSize); aoqi@0: __ jcc(Assembler::notEqual,L_singleBlock_loopTop_192); aoqi@0: __ jmp(L_exit); aoqi@0: aoqi@0: __ BIND(L_key_256); aoqi@0: // 256-bit code follows here (could be optimized to use parallelism) aoqi@0: __ movptr(pos, 0); aoqi@0: __ align(OptoLoopAlignment); aoqi@0: aoqi@0: __ BIND(L_singleBlock_loopTop_256); aoqi@0: __ movdqu(xmm_result, Address(from, pos, Address::times_1, 0)); // get next 16 bytes of cipher input aoqi@0: __ movdqa(xmm_prev_block_cipher_save, xmm_result); // save for next r vector aoqi@0: __ pxor (xmm_result, xmm_key_first); // do the aes dec rounds aoqi@0: for (int rnum = XMM_REG_NUM_KEY_FIRST + 1; rnum <= XMM_REG_NUM_KEY_LAST - 1; rnum++) { aoqi@0: __ aesdec(xmm_result, as_XMMRegister(rnum)); aoqi@0: } aoqi@0: __ aesdec(xmm_result, xmm_key11); aoqi@0: load_key(xmm_temp, key, 0xc0); aoqi@0: __ aesdec(xmm_result, xmm_temp); aoqi@0: load_key(xmm_temp, key, 0xd0); aoqi@0: __ aesdec(xmm_result, xmm_temp); aoqi@0: load_key(xmm_temp, key, 0xe0); // 256-bit key goes up to e0 aoqi@0: __ aesdec(xmm_result, xmm_temp); aoqi@0: __ aesdeclast(xmm_result, xmm_key_last); // xmm15 came from key+0 aoqi@0: __ pxor (xmm_result, xmm_prev_block_cipher); // xor with the current r vector aoqi@0: __ movdqu(Address(to, pos, Address::times_1, 0), xmm_result); // store into the next 16 bytes of output aoqi@0: // no need to store r to memory until we exit aoqi@0: __ movdqa(xmm_prev_block_cipher, xmm_prev_block_cipher_save); // set up next r vector with cipher input from this block aoqi@0: __ addptr(pos, AESBlockSize); aoqi@0: __ subptr(len_reg, AESBlockSize); aoqi@0: __ jcc(Assembler::notEqual,L_singleBlock_loopTop_256); aoqi@0: __ jmp(L_exit); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Arguments: aoqi@0: * aoqi@0: * Inputs: aoqi@0: * c_rarg0 - int crc aoqi@0: * c_rarg1 - byte* buf aoqi@0: * c_rarg2 - int length aoqi@0: * aoqi@0: * Ouput: aoqi@0: * rax - int crc result aoqi@0: */ aoqi@0: address generate_updateBytesCRC32() { aoqi@0: assert(UseCRC32Intrinsics, "need AVX and CLMUL instructions"); aoqi@0: aoqi@0: __ align(CodeEntryAlignment); aoqi@0: StubCodeMark mark(this, "StubRoutines", "updateBytesCRC32"); aoqi@0: aoqi@0: address start = __ pc(); aoqi@0: // Win64: rcx, rdx, r8, r9 (c_rarg0, c_rarg1, ...) aoqi@0: // Unix: rdi, rsi, rdx, rcx, r8, r9 (c_rarg0, c_rarg1, ...) aoqi@0: // rscratch1: r10 aoqi@0: const Register crc = c_rarg0; // crc aoqi@0: const Register buf = c_rarg1; // source java byte array address aoqi@0: const Register len = c_rarg2; // length aoqi@0: const Register table = c_rarg3; // crc_table address (reuse register) aoqi@0: const Register tmp = r11; aoqi@0: assert_different_registers(crc, buf, len, table, tmp, rax); aoqi@0: aoqi@0: BLOCK_COMMENT("Entry:"); aoqi@0: __ enter(); // required for proper stackwalking of RuntimeStub frame aoqi@0: aoqi@0: __ kernel_crc32(crc, buf, len, table, tmp); aoqi@0: aoqi@0: __ movl(rax, crc); aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: __ ret(0); aoqi@0: aoqi@0: return start; aoqi@0: } aoqi@0: aoqi@0: #undef __ aoqi@0: #define __ masm-> aoqi@0: aoqi@0: // Continuation point for throwing of implicit exceptions that are aoqi@0: // not handled in the current activation. Fabricates an exception aoqi@0: // oop and initiates normal exception dispatching in this aoqi@0: // frame. Since we need to preserve callee-saved values (currently aoqi@0: // only for C2, but done for C1 as well) we need a callee-saved oop aoqi@0: // map and therefore have to make these stubs into RuntimeStubs aoqi@0: // rather than BufferBlobs. If the compiler needs all registers to aoqi@0: // be preserved between the fault point and the exception handler aoqi@0: // then it must assume responsibility for that in aoqi@0: // AbstractCompiler::continuation_for_implicit_null_exception or aoqi@0: // continuation_for_implicit_division_by_zero_exception. All other aoqi@0: // implicit exceptions (e.g., NullPointerException or aoqi@0: // AbstractMethodError on entry) are either at call sites or aoqi@0: // otherwise assume that stack unwinding will be initiated, so aoqi@0: // caller saved registers were assumed volatile in the compiler. aoqi@0: address generate_throw_exception(const char* name, aoqi@0: address runtime_entry, aoqi@0: Register arg1 = noreg, aoqi@0: Register arg2 = noreg) { aoqi@0: // Information about frame layout at time of blocking runtime call. aoqi@0: // Note that we only have to preserve callee-saved registers since aoqi@0: // the compilers are responsible for supplying a continuation point aoqi@0: // if they expect all registers to be preserved. aoqi@0: enum layout { aoqi@0: rbp_off = frame::arg_reg_save_area_bytes/BytesPerInt, aoqi@0: rbp_off2, aoqi@0: return_off, aoqi@0: return_off2, aoqi@0: framesize // inclusive of return address aoqi@0: }; aoqi@0: aoqi@0: int insts_size = 512; aoqi@0: int locs_size = 64; aoqi@0: aoqi@0: CodeBuffer code(name, insts_size, locs_size); aoqi@0: OopMapSet* oop_maps = new OopMapSet(); aoqi@0: MacroAssembler* masm = new MacroAssembler(&code); aoqi@0: aoqi@0: address start = __ pc(); aoqi@0: aoqi@0: // This is an inlined and slightly modified version of call_VM aoqi@0: // which has the ability to fetch the return PC out of aoqi@0: // thread-local storage and also sets up last_Java_sp slightly aoqi@0: // differently than the real call_VM aoqi@0: aoqi@0: __ enter(); // required for proper stackwalking of RuntimeStub frame aoqi@0: aoqi@0: assert(is_even(framesize/2), "sp not 16-byte aligned"); aoqi@0: aoqi@0: // return address and rbp are already in place aoqi@0: __ subptr(rsp, (framesize-4) << LogBytesPerInt); // prolog aoqi@0: aoqi@0: int frame_complete = __ pc() - start; aoqi@0: aoqi@0: // Set up last_Java_sp and last_Java_fp aoqi@0: address the_pc = __ pc(); aoqi@0: __ set_last_Java_frame(rsp, rbp, the_pc); aoqi@0: __ andptr(rsp, -(StackAlignmentInBytes)); // Align stack aoqi@0: aoqi@0: // Call runtime aoqi@0: if (arg1 != noreg) { aoqi@0: assert(arg2 != c_rarg1, "clobbered"); aoqi@0: __ movptr(c_rarg1, arg1); aoqi@0: } aoqi@0: if (arg2 != noreg) { aoqi@0: __ movptr(c_rarg2, arg2); aoqi@0: } aoqi@0: __ movptr(c_rarg0, r15_thread); aoqi@0: BLOCK_COMMENT("call runtime_entry"); aoqi@0: __ call(RuntimeAddress(runtime_entry)); aoqi@0: aoqi@0: // Generate oop map aoqi@0: OopMap* map = new OopMap(framesize, 0); aoqi@0: aoqi@0: oop_maps->add_gc_map(the_pc - start, map); aoqi@0: aoqi@0: __ reset_last_Java_frame(true, true); aoqi@0: aoqi@0: __ leave(); // required for proper stackwalking of RuntimeStub frame aoqi@0: aoqi@0: // check for pending exceptions aoqi@0: #ifdef ASSERT aoqi@0: Label L; aoqi@0: __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), aoqi@0: (int32_t) NULL_WORD); aoqi@0: __ jcc(Assembler::notEqual, L); aoqi@0: __ should_not_reach_here(); aoqi@0: __ bind(L); aoqi@0: #endif // ASSERT aoqi@0: __ jump(RuntimeAddress(StubRoutines::forward_exception_entry())); aoqi@0: aoqi@0: aoqi@0: // codeBlob framesize is in words (not VMRegImpl::slot_size) aoqi@0: RuntimeStub* stub = aoqi@0: RuntimeStub::new_runtime_stub(name, aoqi@0: &code, aoqi@0: frame_complete, aoqi@0: (framesize >> (LogBytesPerWord - LogBytesPerInt)), aoqi@0: oop_maps, false); aoqi@0: return stub->entry_point(); aoqi@0: } aoqi@0: aoqi@0: void create_control_words() { aoqi@0: // Round to nearest, 53-bit mode, exceptions masked aoqi@0: StubRoutines::_fpu_cntrl_wrd_std = 0x027F; aoqi@0: // Round to zero, 53-bit mode, exception mased aoqi@0: StubRoutines::_fpu_cntrl_wrd_trunc = 0x0D7F; aoqi@0: // Round to nearest, 24-bit mode, exceptions masked aoqi@0: StubRoutines::_fpu_cntrl_wrd_24 = 0x007F; aoqi@0: // Round to nearest, 64-bit mode, exceptions masked aoqi@0: StubRoutines::_fpu_cntrl_wrd_64 = 0x037F; aoqi@0: // Round to nearest, 64-bit mode, exceptions masked aoqi@0: StubRoutines::_mxcsr_std = 0x1F80; aoqi@0: // Note: the following two constants are 80-bit values aoqi@0: // layout is critical for correct loading by FPU. aoqi@0: // Bias for strict fp multiply/divide aoqi@0: StubRoutines::_fpu_subnormal_bias1[0]= 0x00000000; // 2^(-15360) == 0x03ff 8000 0000 0000 0000 aoqi@0: StubRoutines::_fpu_subnormal_bias1[1]= 0x80000000; aoqi@0: StubRoutines::_fpu_subnormal_bias1[2]= 0x03ff; aoqi@0: // Un-Bias for strict fp multiply/divide aoqi@0: StubRoutines::_fpu_subnormal_bias2[0]= 0x00000000; // 2^(+15360) == 0x7bff 8000 0000 0000 0000 aoqi@0: StubRoutines::_fpu_subnormal_bias2[1]= 0x80000000; aoqi@0: StubRoutines::_fpu_subnormal_bias2[2]= 0x7bff; aoqi@0: } aoqi@0: aoqi@0: // Initialization aoqi@0: void generate_initial() { aoqi@0: // Generates all stubs and initializes the entry points aoqi@0: aoqi@0: // This platform-specific settings are needed by generate_call_stub() aoqi@0: create_control_words(); aoqi@0: aoqi@0: // entry points that exist in all platforms Note: This is code aoqi@0: // that could be shared among different platforms - however the aoqi@0: // benefit seems to be smaller than the disadvantage of having a aoqi@0: // much more complicated generator structure. See also comment in aoqi@0: // stubRoutines.hpp. aoqi@0: aoqi@0: StubRoutines::_forward_exception_entry = generate_forward_exception(); aoqi@0: aoqi@0: StubRoutines::_call_stub_entry = aoqi@0: generate_call_stub(StubRoutines::_call_stub_return_address); aoqi@0: aoqi@0: // is referenced by megamorphic call aoqi@0: StubRoutines::_catch_exception_entry = generate_catch_exception(); aoqi@0: aoqi@0: // atomic calls aoqi@0: StubRoutines::_atomic_xchg_entry = generate_atomic_xchg(); aoqi@0: StubRoutines::_atomic_xchg_ptr_entry = generate_atomic_xchg_ptr(); aoqi@0: StubRoutines::_atomic_cmpxchg_entry = generate_atomic_cmpxchg(); aoqi@0: StubRoutines::_atomic_cmpxchg_long_entry = generate_atomic_cmpxchg_long(); aoqi@0: StubRoutines::_atomic_add_entry = generate_atomic_add(); aoqi@0: StubRoutines::_atomic_add_ptr_entry = generate_atomic_add_ptr(); aoqi@0: StubRoutines::_fence_entry = generate_orderaccess_fence(); aoqi@0: aoqi@0: StubRoutines::_handler_for_unsafe_access_entry = aoqi@0: generate_handler_for_unsafe_access(); aoqi@0: aoqi@0: // platform dependent aoqi@0: StubRoutines::x86::_get_previous_fp_entry = generate_get_previous_fp(); aoqi@0: StubRoutines::x86::_get_previous_sp_entry = generate_get_previous_sp(); aoqi@0: aoqi@0: StubRoutines::x86::_verify_mxcsr_entry = generate_verify_mxcsr(); aoqi@0: aoqi@0: // Build this early so it's available for the interpreter. aoqi@0: StubRoutines::_throw_StackOverflowError_entry = aoqi@0: generate_throw_exception("StackOverflowError throw_exception", aoqi@0: CAST_FROM_FN_PTR(address, aoqi@0: SharedRuntime:: aoqi@0: throw_StackOverflowError)); aoqi@0: if (UseCRC32Intrinsics) { aoqi@0: // set table address before stub generation which use it aoqi@0: StubRoutines::_crc_table_adr = (address)StubRoutines::x86::_crc_table; aoqi@0: StubRoutines::_updateBytesCRC32 = generate_updateBytesCRC32(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void generate_all() { aoqi@0: // Generates all stubs and initializes the entry points aoqi@0: aoqi@0: // These entry points require SharedInfo::stack0 to be set up in aoqi@0: // non-core builds and need to be relocatable, so they each aoqi@0: // fabricate a RuntimeStub internally. aoqi@0: StubRoutines::_throw_AbstractMethodError_entry = aoqi@0: generate_throw_exception("AbstractMethodError throw_exception", aoqi@0: CAST_FROM_FN_PTR(address, aoqi@0: SharedRuntime:: aoqi@0: throw_AbstractMethodError)); aoqi@0: aoqi@0: StubRoutines::_throw_IncompatibleClassChangeError_entry = aoqi@0: generate_throw_exception("IncompatibleClassChangeError throw_exception", aoqi@0: CAST_FROM_FN_PTR(address, aoqi@0: SharedRuntime:: aoqi@0: throw_IncompatibleClassChangeError)); aoqi@0: aoqi@0: StubRoutines::_throw_NullPointerException_at_call_entry = aoqi@0: generate_throw_exception("NullPointerException at call throw_exception", aoqi@0: CAST_FROM_FN_PTR(address, aoqi@0: SharedRuntime:: aoqi@0: throw_NullPointerException_at_call)); aoqi@0: aoqi@0: // entry points that are platform specific aoqi@0: StubRoutines::x86::_f2i_fixup = generate_f2i_fixup(); aoqi@0: StubRoutines::x86::_f2l_fixup = generate_f2l_fixup(); aoqi@0: StubRoutines::x86::_d2i_fixup = generate_d2i_fixup(); aoqi@0: StubRoutines::x86::_d2l_fixup = generate_d2l_fixup(); aoqi@0: aoqi@0: StubRoutines::x86::_float_sign_mask = generate_fp_mask("float_sign_mask", 0x7FFFFFFF7FFFFFFF); aoqi@0: StubRoutines::x86::_float_sign_flip = generate_fp_mask("float_sign_flip", 0x8000000080000000); aoqi@0: StubRoutines::x86::_double_sign_mask = generate_fp_mask("double_sign_mask", 0x7FFFFFFFFFFFFFFF); aoqi@0: StubRoutines::x86::_double_sign_flip = generate_fp_mask("double_sign_flip", 0x8000000000000000); aoqi@0: aoqi@0: // support for verify_oop (must happen after universe_init) aoqi@0: StubRoutines::_verify_oop_subroutine_entry = generate_verify_oop(); aoqi@0: aoqi@0: // arraycopy stubs used by compilers aoqi@0: generate_arraycopy_stubs(); aoqi@0: aoqi@0: generate_math_stubs(); aoqi@0: aoqi@0: // don't bother generating these AES intrinsic stubs unless global flag is set aoqi@0: if (UseAESIntrinsics) { aoqi@0: StubRoutines::x86::_key_shuffle_mask_addr = generate_key_shuffle_mask(); // needed by the others aoqi@0: aoqi@0: StubRoutines::_aescrypt_encryptBlock = generate_aescrypt_encryptBlock(); aoqi@0: StubRoutines::_aescrypt_decryptBlock = generate_aescrypt_decryptBlock(); aoqi@0: StubRoutines::_cipherBlockChaining_encryptAESCrypt = generate_cipherBlockChaining_encryptAESCrypt(); aoqi@0: StubRoutines::_cipherBlockChaining_decryptAESCrypt = generate_cipherBlockChaining_decryptAESCrypt_Parallel(); aoqi@0: } aoqi@0: aoqi@0: // Safefetch stubs. aoqi@0: generate_safefetch("SafeFetch32", sizeof(int), &StubRoutines::_safefetch32_entry, aoqi@0: &StubRoutines::_safefetch32_fault_pc, aoqi@0: &StubRoutines::_safefetch32_continuation_pc); aoqi@0: generate_safefetch("SafeFetchN", sizeof(intptr_t), &StubRoutines::_safefetchN_entry, aoqi@0: &StubRoutines::_safefetchN_fault_pc, aoqi@0: &StubRoutines::_safefetchN_continuation_pc); aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: StubGenerator(CodeBuffer* code, bool all) : StubCodeGenerator(code) { aoqi@0: if (all) { aoqi@0: generate_all(); aoqi@0: } else { aoqi@0: generate_initial(); aoqi@0: } aoqi@0: } aoqi@0: }; // end class declaration aoqi@0: aoqi@0: void StubGenerator_generate(CodeBuffer* code, bool all) { aoqi@0: StubGenerator g(code, all); aoqi@0: }