duke@435: /* twisti@2552: * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "asm/assembler.hpp" stefank@2314: #include "assembler_x86.inline.hpp" stefank@2314: #include "interpreter/interpreter.hpp" stefank@2314: #include "nativeInst_x86.hpp" stefank@2314: #include "oops/instanceOop.hpp" stefank@2314: #include "oops/methodOop.hpp" stefank@2314: #include "oops/objArrayKlass.hpp" stefank@2314: #include "oops/oop.inline.hpp" stefank@2314: #include "prims/methodHandles.hpp" stefank@2314: #include "runtime/frame.inline.hpp" stefank@2314: #include "runtime/handles.inline.hpp" stefank@2314: #include "runtime/sharedRuntime.hpp" stefank@2314: #include "runtime/stubCodeGenerator.hpp" stefank@2314: #include "runtime/stubRoutines.hpp" stefank@2314: #include "utilities/top.hpp" stefank@2314: #ifdef TARGET_OS_FAMILY_linux stefank@2314: # include "thread_linux.inline.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_OS_FAMILY_solaris stefank@2314: # include "thread_solaris.inline.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_OS_FAMILY_windows stefank@2314: # include "thread_windows.inline.hpp" stefank@2314: #endif never@3156: #ifdef TARGET_OS_FAMILY_bsd never@3156: # include "thread_bsd.inline.hpp" never@3156: #endif stefank@2314: #ifdef COMPILER2 stefank@2314: #include "opto/runtime.hpp" stefank@2314: #endif duke@435: duke@435: // Declaration and definition of StubGenerator (no .hpp file). duke@435: // For a more detailed description of the stub routine structure duke@435: // see the comment in stubRoutines.hpp duke@435: duke@435: #define __ _masm-> never@739: #define a__ ((Assembler*)_masm)-> duke@435: duke@435: #ifdef PRODUCT duke@435: #define BLOCK_COMMENT(str) /* nothing */ duke@435: #else duke@435: #define BLOCK_COMMENT(str) __ block_comment(str) duke@435: #endif duke@435: duke@435: #define BIND(label) bind(label); BLOCK_COMMENT(#label ":") duke@435: duke@435: const int MXCSR_MASK = 0xFFC0; // Mask out any pending exceptions duke@435: const int FPU_CNTRL_WRD_MASK = 0xFFFF; duke@435: duke@435: // ------------------------------------------------------------------------------------------------------------------------- duke@435: // Stub Code definitions duke@435: duke@435: static address handle_unsafe_access() { duke@435: JavaThread* thread = JavaThread::current(); duke@435: address pc = thread->saved_exception_pc(); duke@435: // pc is the instruction which we must emulate duke@435: // doing a no-op is fine: return garbage from the load duke@435: // therefore, compute npc duke@435: address npc = Assembler::locate_next_instruction(pc); duke@435: duke@435: // request an async exception duke@435: thread->set_pending_unsafe_access_error(); duke@435: duke@435: // return address of next instruction to execute duke@435: return npc; duke@435: } duke@435: duke@435: class StubGenerator: public StubCodeGenerator { duke@435: private: duke@435: duke@435: #ifdef PRODUCT duke@435: #define inc_counter_np(counter) (0) duke@435: #else duke@435: void inc_counter_np_(int& counter) { never@739: __ incrementl(ExternalAddress((address)&counter)); duke@435: } duke@435: #define inc_counter_np(counter) \ duke@435: BLOCK_COMMENT("inc_counter " #counter); \ duke@435: inc_counter_np_(counter); duke@435: #endif //PRODUCT duke@435: duke@435: void inc_copy_counter_np(BasicType t) { duke@435: #ifndef PRODUCT duke@435: switch (t) { duke@435: case T_BYTE: inc_counter_np(SharedRuntime::_jbyte_array_copy_ctr); return; duke@435: case T_SHORT: inc_counter_np(SharedRuntime::_jshort_array_copy_ctr); return; duke@435: case T_INT: inc_counter_np(SharedRuntime::_jint_array_copy_ctr); return; duke@435: case T_LONG: inc_counter_np(SharedRuntime::_jlong_array_copy_ctr); return; duke@435: case T_OBJECT: inc_counter_np(SharedRuntime::_oop_array_copy_ctr); return; duke@435: } duke@435: ShouldNotReachHere(); duke@435: #endif //PRODUCT duke@435: } duke@435: duke@435: //------------------------------------------------------------------------------------------------------------------------ duke@435: // Call stubs are used to call Java from C duke@435: // duke@435: // [ return_from_Java ] <--- rsp duke@435: // [ argument word n ] duke@435: // ... duke@435: // -N [ argument word 1 ] duke@435: // -7 [ Possible padding for stack alignment ] duke@435: // -6 [ Possible padding for stack alignment ] duke@435: // -5 [ Possible padding for stack alignment ] duke@435: // -4 [ mxcsr save ] <--- rsp_after_call duke@435: // -3 [ saved rbx, ] duke@435: // -2 [ saved rsi ] duke@435: // -1 [ saved rdi ] duke@435: // 0 [ saved rbp, ] <--- rbp, duke@435: // 1 [ return address ] duke@435: // 2 [ ptr. to call wrapper ] duke@435: // 3 [ result ] duke@435: // 4 [ result_type ] duke@435: // 5 [ method ] duke@435: // 6 [ entry_point ] duke@435: // 7 [ parameters ] duke@435: // 8 [ parameter_size ] duke@435: // 9 [ thread ] duke@435: duke@435: duke@435: address generate_call_stub(address& return_address) { duke@435: StubCodeMark mark(this, "StubRoutines", "call_stub"); duke@435: address start = __ pc(); duke@435: duke@435: // stub code parameters / addresses duke@435: assert(frame::entry_frame_call_wrapper_offset == 2, "adjust this code"); duke@435: bool sse_save = false; duke@435: const Address rsp_after_call(rbp, -4 * wordSize); // same as in generate_catch_exception()! duke@435: const int locals_count_in_bytes (4*wordSize); duke@435: const Address mxcsr_save (rbp, -4 * wordSize); duke@435: const Address saved_rbx (rbp, -3 * wordSize); duke@435: const Address saved_rsi (rbp, -2 * wordSize); duke@435: const Address saved_rdi (rbp, -1 * wordSize); duke@435: const Address result (rbp, 3 * wordSize); duke@435: const Address result_type (rbp, 4 * wordSize); duke@435: const Address method (rbp, 5 * wordSize); duke@435: const Address entry_point (rbp, 6 * wordSize); duke@435: const Address parameters (rbp, 7 * wordSize); duke@435: const Address parameter_size(rbp, 8 * wordSize); duke@435: const Address thread (rbp, 9 * wordSize); // same as in generate_catch_exception()! duke@435: sse_save = UseSSE > 0; duke@435: duke@435: // stub code duke@435: __ enter(); never@739: __ movptr(rcx, parameter_size); // parameter counter twisti@1861: __ shlptr(rcx, Interpreter::logStackElementSize); // convert parameter count to bytes never@739: __ addptr(rcx, locals_count_in_bytes); // reserve space for register saves never@739: __ subptr(rsp, rcx); never@739: __ andptr(rsp, -(StackAlignmentInBytes)); // Align stack duke@435: duke@435: // save rdi, rsi, & rbx, according to C calling conventions never@739: __ movptr(saved_rdi, rdi); never@739: __ movptr(saved_rsi, rsi); never@739: __ movptr(saved_rbx, rbx); duke@435: // save and initialize %mxcsr duke@435: if (sse_save) { duke@435: Label skip_ldmx; duke@435: __ stmxcsr(mxcsr_save); duke@435: __ movl(rax, mxcsr_save); duke@435: __ andl(rax, MXCSR_MASK); // Only check control and mask bits duke@435: ExternalAddress mxcsr_std(StubRoutines::addr_mxcsr_std()); duke@435: __ cmp32(rax, mxcsr_std); duke@435: __ jcc(Assembler::equal, skip_ldmx); duke@435: __ ldmxcsr(mxcsr_std); duke@435: __ bind(skip_ldmx); duke@435: } duke@435: duke@435: // make sure the control word is correct. duke@435: __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_std())); duke@435: duke@435: #ifdef ASSERT duke@435: // make sure we have no pending exceptions duke@435: { Label L; never@739: __ movptr(rcx, thread); never@739: __ cmpptr(Address(rcx, Thread::pending_exception_offset()), (int32_t)NULL_WORD); duke@435: __ jcc(Assembler::equal, L); duke@435: __ stop("StubRoutines::call_stub: entered with pending exception"); duke@435: __ bind(L); duke@435: } duke@435: #endif duke@435: duke@435: // pass parameters if any duke@435: BLOCK_COMMENT("pass parameters if any"); duke@435: Label parameters_done; duke@435: __ movl(rcx, parameter_size); // parameter counter duke@435: __ testl(rcx, rcx); duke@435: __ jcc(Assembler::zero, parameters_done); duke@435: duke@435: // parameter passing loop duke@435: duke@435: Label loop; duke@435: // Copy Java parameters in reverse order (receiver last) duke@435: // Note that the argument order is inverted in the process duke@435: // source is rdx[rcx: N-1..0] duke@435: // dest is rsp[rbx: 0..N-1] duke@435: never@739: __ movptr(rdx, parameters); // parameter pointer never@739: __ xorptr(rbx, rbx); duke@435: duke@435: __ BIND(loop); duke@435: duke@435: // get parameter never@739: __ movptr(rax, Address(rdx, rcx, Interpreter::stackElementScale(), -wordSize)); never@739: __ movptr(Address(rsp, rbx, Interpreter::stackElementScale(), duke@435: Interpreter::expr_offset_in_bytes(0)), rax); // store parameter duke@435: __ increment(rbx); duke@435: __ decrement(rcx); duke@435: __ jcc(Assembler::notZero, loop); duke@435: duke@435: // call Java function duke@435: __ BIND(parameters_done); never@739: __ movptr(rbx, method); // get methodOop never@739: __ movptr(rax, entry_point); // get entry_point never@739: __ mov(rsi, rsp); // set sender sp duke@435: BLOCK_COMMENT("call Java function"); duke@435: __ call(rax); duke@435: duke@435: BLOCK_COMMENT("call_stub_return_address:"); duke@435: return_address = __ pc(); duke@435: twisti@2552: #ifdef COMPILER2 twisti@2552: { twisti@2552: Label L_skip; twisti@2552: if (UseSSE >= 2) { twisti@2552: __ verify_FPU(0, "call_stub_return"); twisti@2552: } else { twisti@2552: for (int i = 1; i < 8; i++) { twisti@2552: __ ffree(i); twisti@2552: } duke@435: twisti@2552: // UseSSE <= 1 so double result should be left on TOS twisti@2552: __ movl(rsi, result_type); twisti@2552: __ cmpl(rsi, T_DOUBLE); twisti@2552: __ jcc(Assembler::equal, L_skip); twisti@2552: if (UseSSE == 0) { twisti@2552: // UseSSE == 0 so float result should be left on TOS twisti@2552: __ cmpl(rsi, T_FLOAT); twisti@2552: __ jcc(Assembler::equal, L_skip); twisti@2552: } twisti@2552: __ ffree(0); twisti@2552: } twisti@2552: __ BIND(L_skip); twisti@2552: } twisti@2552: #endif // COMPILER2 duke@435: duke@435: // store result depending on type duke@435: // (everything that is not T_LONG, T_FLOAT or T_DOUBLE is treated as T_INT) never@739: __ movptr(rdi, result); duke@435: Label is_long, is_float, is_double, exit; duke@435: __ movl(rsi, result_type); duke@435: __ cmpl(rsi, T_LONG); duke@435: __ jcc(Assembler::equal, is_long); duke@435: __ cmpl(rsi, T_FLOAT); duke@435: __ jcc(Assembler::equal, is_float); duke@435: __ cmpl(rsi, T_DOUBLE); duke@435: __ jcc(Assembler::equal, is_double); duke@435: duke@435: // handle T_INT case duke@435: __ movl(Address(rdi, 0), rax); duke@435: __ BIND(exit); duke@435: duke@435: // check that FPU stack is empty duke@435: __ verify_FPU(0, "generate_call_stub"); duke@435: duke@435: // pop parameters never@739: __ lea(rsp, rsp_after_call); duke@435: duke@435: // restore %mxcsr duke@435: if (sse_save) { duke@435: __ ldmxcsr(mxcsr_save); duke@435: } duke@435: duke@435: // restore rdi, rsi and rbx, never@739: __ movptr(rbx, saved_rbx); never@739: __ movptr(rsi, saved_rsi); never@739: __ movptr(rdi, saved_rdi); never@739: __ addptr(rsp, 4*wordSize); duke@435: duke@435: // return never@739: __ pop(rbp); duke@435: __ ret(0); duke@435: duke@435: // handle return types different from T_INT duke@435: __ BIND(is_long); duke@435: __ movl(Address(rdi, 0 * wordSize), rax); duke@435: __ movl(Address(rdi, 1 * wordSize), rdx); duke@435: __ jmp(exit); duke@435: duke@435: __ BIND(is_float); duke@435: // interpreter uses xmm0 for return values duke@435: if (UseSSE >= 1) { duke@435: __ movflt(Address(rdi, 0), xmm0); duke@435: } else { duke@435: __ fstp_s(Address(rdi, 0)); duke@435: } duke@435: __ jmp(exit); duke@435: duke@435: __ BIND(is_double); duke@435: // interpreter uses xmm0 for return values duke@435: if (UseSSE >= 2) { duke@435: __ movdbl(Address(rdi, 0), xmm0); duke@435: } else { duke@435: __ fstp_d(Address(rdi, 0)); duke@435: } duke@435: __ jmp(exit); duke@435: duke@435: return start; duke@435: } duke@435: duke@435: duke@435: //------------------------------------------------------------------------------------------------------------------------ duke@435: // Return point for a Java call if there's an exception thrown in Java code. duke@435: // The exception is caught and transformed into a pending exception stored in duke@435: // JavaThread that can be tested from within the VM. duke@435: // duke@435: // Note: Usually the parameters are removed by the callee. In case of an exception duke@435: // crossing an activation frame boundary, that is not the case if the callee duke@435: // is compiled code => need to setup the rsp. duke@435: // duke@435: // rax,: exception oop duke@435: duke@435: address generate_catch_exception() { duke@435: StubCodeMark mark(this, "StubRoutines", "catch_exception"); duke@435: const Address rsp_after_call(rbp, -4 * wordSize); // same as in generate_call_stub()! duke@435: const Address thread (rbp, 9 * wordSize); // same as in generate_call_stub()! duke@435: address start = __ pc(); duke@435: duke@435: // get thread directly never@739: __ movptr(rcx, thread); duke@435: #ifdef ASSERT duke@435: // verify that threads correspond duke@435: { Label L; duke@435: __ get_thread(rbx); never@739: __ cmpptr(rbx, rcx); duke@435: __ jcc(Assembler::equal, L); duke@435: __ stop("StubRoutines::catch_exception: threads must correspond"); duke@435: __ bind(L); duke@435: } duke@435: #endif duke@435: // set pending exception duke@435: __ verify_oop(rax); never@739: __ movptr(Address(rcx, Thread::pending_exception_offset()), rax ); duke@435: __ lea(Address(rcx, Thread::exception_file_offset ()), duke@435: ExternalAddress((address)__FILE__)); duke@435: __ movl(Address(rcx, Thread::exception_line_offset ()), __LINE__ ); duke@435: // complete return to VM duke@435: assert(StubRoutines::_call_stub_return_address != NULL, "_call_stub_return_address must have been generated before"); duke@435: __ jump(RuntimeAddress(StubRoutines::_call_stub_return_address)); duke@435: duke@435: return start; duke@435: } duke@435: duke@435: duke@435: //------------------------------------------------------------------------------------------------------------------------ duke@435: // Continuation point for runtime calls returning with a pending exception. duke@435: // The pending exception check happened in the runtime or native call stub. duke@435: // The pending exception in Thread is converted into a Java-level exception. duke@435: // duke@435: // Contract with Java-level exception handlers: twisti@1730: // rax: exception duke@435: // rdx: throwing pc duke@435: // duke@435: // NOTE: At entry of this stub, exception-pc must be on stack !! duke@435: duke@435: address generate_forward_exception() { duke@435: StubCodeMark mark(this, "StubRoutines", "forward exception"); duke@435: address start = __ pc(); twisti@1730: const Register thread = rcx; twisti@1730: twisti@1730: // other registers used in this stub twisti@1730: const Register exception_oop = rax; twisti@1730: const Register handler_addr = rbx; twisti@1730: const Register exception_pc = rdx; duke@435: duke@435: // Upon entry, the sp points to the return address returning into Java duke@435: // (interpreted or compiled) code; i.e., the return address becomes the duke@435: // throwing pc. duke@435: // duke@435: // Arguments pushed before the runtime call are still on the stack but duke@435: // the exception handler will reset the stack pointer -> ignore them. duke@435: // A potential result in registers can be ignored as well. duke@435: duke@435: #ifdef ASSERT duke@435: // make sure this code is only executed if there is a pending exception duke@435: { Label L; twisti@1730: __ get_thread(thread); twisti@1730: __ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD); duke@435: __ jcc(Assembler::notEqual, L); duke@435: __ stop("StubRoutines::forward exception: no pending exception (1)"); duke@435: __ bind(L); duke@435: } duke@435: #endif duke@435: duke@435: // compute exception handler into rbx, twisti@1730: __ get_thread(thread); twisti@1730: __ movptr(exception_pc, Address(rsp, 0)); duke@435: BLOCK_COMMENT("call exception_handler_for_return_address"); twisti@1730: __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), thread, exception_pc); twisti@1730: __ mov(handler_addr, rax); duke@435: twisti@1730: // setup rax & rdx, remove return address & clear pending exception twisti@1730: __ get_thread(thread); twisti@1730: __ pop(exception_pc); twisti@1730: __ movptr(exception_oop, Address(thread, Thread::pending_exception_offset())); twisti@1730: __ movptr(Address(thread, Thread::pending_exception_offset()), NULL_WORD); duke@435: duke@435: #ifdef ASSERT duke@435: // make sure exception is set duke@435: { Label L; twisti@1730: __ testptr(exception_oop, exception_oop); duke@435: __ jcc(Assembler::notEqual, L); duke@435: __ stop("StubRoutines::forward exception: no pending exception (2)"); duke@435: __ bind(L); duke@435: } duke@435: #endif duke@435: twisti@1730: // Verify that there is really a valid exception in RAX. twisti@1730: __ verify_oop(exception_oop); twisti@1730: duke@435: // continue at exception handler (return address removed) twisti@1730: // rax: exception twisti@1730: // rbx: exception handler duke@435: // rdx: throwing pc twisti@1730: __ jmp(handler_addr); duke@435: duke@435: return start; duke@435: } duke@435: duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Support for jint Atomic::xchg(jint exchange_value, volatile jint* dest) duke@435: // duke@435: // xchg exists as far back as 8086, lock needed for MP only duke@435: // Stack layout immediately after call: duke@435: // duke@435: // 0 [ret addr ] <--- rsp duke@435: // 1 [ ex ] duke@435: // 2 [ dest ] duke@435: // duke@435: // Result: *dest <- ex, return (old *dest) duke@435: // duke@435: // Note: win32 does not currently use this code duke@435: duke@435: address generate_atomic_xchg() { duke@435: StubCodeMark mark(this, "StubRoutines", "atomic_xchg"); duke@435: address start = __ pc(); duke@435: never@739: __ push(rdx); duke@435: Address exchange(rsp, 2 * wordSize); duke@435: Address dest_addr(rsp, 3 * wordSize); duke@435: __ movl(rax, exchange); never@739: __ movptr(rdx, dest_addr); never@739: __ xchgl(rax, Address(rdx, 0)); never@739: __ pop(rdx); duke@435: __ ret(0); duke@435: duke@435: return start; duke@435: } duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Support for void verify_mxcsr() duke@435: // duke@435: // This routine is used with -Xcheck:jni to verify that native duke@435: // JNI code does not return to Java code without restoring the duke@435: // MXCSR register to our expected state. duke@435: duke@435: duke@435: address generate_verify_mxcsr() { duke@435: StubCodeMark mark(this, "StubRoutines", "verify_mxcsr"); duke@435: address start = __ pc(); duke@435: duke@435: const Address mxcsr_save(rsp, 0); duke@435: duke@435: if (CheckJNICalls && UseSSE > 0 ) { duke@435: Label ok_ret; duke@435: ExternalAddress mxcsr_std(StubRoutines::addr_mxcsr_std()); never@739: __ push(rax); never@739: __ subptr(rsp, wordSize); // allocate a temp location duke@435: __ stmxcsr(mxcsr_save); duke@435: __ movl(rax, mxcsr_save); duke@435: __ andl(rax, MXCSR_MASK); duke@435: __ cmp32(rax, mxcsr_std); duke@435: __ jcc(Assembler::equal, ok_ret); duke@435: duke@435: __ warn("MXCSR changed by native JNI code."); duke@435: duke@435: __ ldmxcsr(mxcsr_std); duke@435: duke@435: __ bind(ok_ret); never@739: __ addptr(rsp, wordSize); never@739: __ pop(rax); duke@435: } duke@435: duke@435: __ ret(0); duke@435: duke@435: return start; duke@435: } duke@435: duke@435: duke@435: //--------------------------------------------------------------------------- duke@435: // Support for void verify_fpu_cntrl_wrd() duke@435: // duke@435: // This routine is used with -Xcheck:jni to verify that native duke@435: // JNI code does not return to Java code without restoring the duke@435: // FP control word to our expected state. duke@435: duke@435: address generate_verify_fpu_cntrl_wrd() { duke@435: StubCodeMark mark(this, "StubRoutines", "verify_spcw"); duke@435: address start = __ pc(); duke@435: duke@435: const Address fpu_cntrl_wrd_save(rsp, 0); duke@435: duke@435: if (CheckJNICalls) { duke@435: Label ok_ret; never@739: __ push(rax); never@739: __ subptr(rsp, wordSize); // allocate a temp location duke@435: __ fnstcw(fpu_cntrl_wrd_save); duke@435: __ movl(rax, fpu_cntrl_wrd_save); duke@435: __ andl(rax, FPU_CNTRL_WRD_MASK); duke@435: ExternalAddress fpu_std(StubRoutines::addr_fpu_cntrl_wrd_std()); duke@435: __ cmp32(rax, fpu_std); duke@435: __ jcc(Assembler::equal, ok_ret); duke@435: duke@435: __ warn("Floating point control word changed by native JNI code."); duke@435: duke@435: __ fldcw(fpu_std); duke@435: duke@435: __ bind(ok_ret); never@739: __ addptr(rsp, wordSize); never@739: __ pop(rax); duke@435: } duke@435: duke@435: __ ret(0); duke@435: duke@435: return start; duke@435: } duke@435: duke@435: //--------------------------------------------------------------------------- duke@435: // Wrapper for slow-case handling of double-to-integer conversion duke@435: // d2i or f2i fast case failed either because it is nan or because duke@435: // of under/overflow. duke@435: // Input: FPU TOS: float value duke@435: // Output: rax, (rdx): integer (long) result duke@435: duke@435: address generate_d2i_wrapper(BasicType t, address fcn) { duke@435: StubCodeMark mark(this, "StubRoutines", "d2i_wrapper"); duke@435: address start = __ pc(); duke@435: duke@435: // Capture info about frame layout duke@435: enum layout { FPUState_off = 0, duke@435: rbp_off = FPUStateSizeInWords, duke@435: rdi_off, duke@435: rsi_off, duke@435: rcx_off, duke@435: rbx_off, duke@435: saved_argument_off, duke@435: saved_argument_off2, // 2nd half of double duke@435: framesize duke@435: }; duke@435: duke@435: assert(FPUStateSizeInWords == 27, "update stack layout"); duke@435: duke@435: // Save outgoing argument to stack across push_FPU_state() never@739: __ subptr(rsp, wordSize * 2); duke@435: __ fstp_d(Address(rsp, 0)); duke@435: duke@435: // Save CPU & FPU state never@739: __ push(rbx); never@739: __ push(rcx); never@739: __ push(rsi); never@739: __ push(rdi); never@739: __ push(rbp); duke@435: __ push_FPU_state(); duke@435: duke@435: // push_FPU_state() resets the FP top of stack duke@435: // Load original double into FP top of stack duke@435: __ fld_d(Address(rsp, saved_argument_off * wordSize)); duke@435: // Store double into stack as outgoing argument never@739: __ subptr(rsp, wordSize*2); duke@435: __ fst_d(Address(rsp, 0)); duke@435: duke@435: // Prepare FPU for doing math in C-land duke@435: __ empty_FPU_stack(); duke@435: // Call the C code to massage the double. Result in EAX duke@435: if (t == T_INT) duke@435: { BLOCK_COMMENT("SharedRuntime::d2i"); } duke@435: else if (t == T_LONG) duke@435: { BLOCK_COMMENT("SharedRuntime::d2l"); } duke@435: __ call_VM_leaf( fcn, 2 ); duke@435: duke@435: // Restore CPU & FPU state duke@435: __ pop_FPU_state(); never@739: __ pop(rbp); never@739: __ pop(rdi); never@739: __ pop(rsi); never@739: __ pop(rcx); never@739: __ pop(rbx); never@739: __ addptr(rsp, wordSize * 2); duke@435: duke@435: __ ret(0); duke@435: duke@435: return start; duke@435: } duke@435: duke@435: duke@435: //--------------------------------------------------------------------------- duke@435: // The following routine generates a subroutine to throw an asynchronous duke@435: // UnknownError when an unsafe access gets a fault that could not be duke@435: // reasonably prevented by the programmer. (Example: SIGBUS/OBJERR.) duke@435: address generate_handler_for_unsafe_access() { duke@435: StubCodeMark mark(this, "StubRoutines", "handler_for_unsafe_access"); duke@435: address start = __ pc(); duke@435: never@739: __ push(0); // hole for return address-to-be never@739: __ pusha(); // push registers duke@435: Address next_pc(rsp, RegisterImpl::number_of_registers * BytesPerWord); duke@435: BLOCK_COMMENT("call handle_unsafe_access"); duke@435: __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, handle_unsafe_access))); never@739: __ movptr(next_pc, rax); // stuff next address never@739: __ popa(); duke@435: __ ret(0); // jump to next address duke@435: duke@435: return start; duke@435: } duke@435: duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Non-destructive plausibility checks for oops duke@435: duke@435: address generate_verify_oop() { duke@435: StubCodeMark mark(this, "StubRoutines", "verify_oop"); duke@435: address start = __ pc(); duke@435: duke@435: // Incoming arguments on stack after saving rax,: duke@435: // duke@435: // [tos ]: saved rdx duke@435: // [tos + 1]: saved EFLAGS duke@435: // [tos + 2]: return address duke@435: // [tos + 3]: char* error message duke@435: // [tos + 4]: oop object to verify duke@435: // [tos + 5]: saved rax, - saved by caller and bashed duke@435: duke@435: Label exit, error; never@739: __ pushf(); never@739: __ incrementl(ExternalAddress((address) StubRoutines::verify_oop_count_addr())); never@739: __ push(rdx); // save rdx duke@435: // make sure object is 'reasonable' never@739: __ movptr(rax, Address(rsp, 4 * wordSize)); // get object never@739: __ testptr(rax, rax); duke@435: __ jcc(Assembler::zero, exit); // if obj is NULL it is ok duke@435: duke@435: // Check if the oop is in the right area of memory duke@435: const int oop_mask = Universe::verify_oop_mask(); duke@435: const int oop_bits = Universe::verify_oop_bits(); never@739: __ mov(rdx, rax); never@739: __ andptr(rdx, oop_mask); never@739: __ cmpptr(rdx, oop_bits); duke@435: __ jcc(Assembler::notZero, error); duke@435: duke@435: // make sure klass is 'reasonable' never@739: __ movptr(rax, Address(rax, oopDesc::klass_offset_in_bytes())); // get klass never@739: __ testptr(rax, rax); duke@435: __ jcc(Assembler::zero, error); // if klass is NULL it is broken duke@435: duke@435: // Check if the klass is in the right area of memory duke@435: const int klass_mask = Universe::verify_klass_mask(); duke@435: const int klass_bits = Universe::verify_klass_bits(); never@739: __ mov(rdx, rax); never@739: __ andptr(rdx, klass_mask); never@739: __ cmpptr(rdx, klass_bits); duke@435: __ jcc(Assembler::notZero, error); duke@435: duke@435: // make sure klass' klass is 'reasonable' never@739: __ movptr(rax, Address(rax, oopDesc::klass_offset_in_bytes())); // get klass' klass never@739: __ testptr(rax, rax); duke@435: __ jcc(Assembler::zero, error); // if klass' klass is NULL it is broken duke@435: never@739: __ mov(rdx, rax); never@739: __ andptr(rdx, klass_mask); never@739: __ cmpptr(rdx, klass_bits); duke@435: __ jcc(Assembler::notZero, error); // if klass not in right area duke@435: // of memory it is broken too. duke@435: duke@435: // return if everything seems ok duke@435: __ bind(exit); never@739: __ movptr(rax, Address(rsp, 5 * wordSize)); // get saved rax, back never@739: __ pop(rdx); // restore rdx never@739: __ popf(); // restore EFLAGS duke@435: __ ret(3 * wordSize); // pop arguments duke@435: duke@435: // handle errors duke@435: __ bind(error); never@739: __ movptr(rax, Address(rsp, 5 * wordSize)); // get saved rax, back never@739: __ pop(rdx); // get saved rdx back never@739: __ popf(); // get saved EFLAGS off stack -- will be ignored never@739: __ pusha(); // push registers (eip = return address & msg are already pushed) duke@435: BLOCK_COMMENT("call MacroAssembler::debug"); never@739: __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, MacroAssembler::debug32))); never@739: __ popa(); duke@435: __ ret(3 * wordSize); // pop arguments duke@435: return start; duke@435: } duke@435: duke@435: // duke@435: // Generate pre-barrier for array stores duke@435: // duke@435: // Input: duke@435: // start - starting address ysr@1280: // count - element count iveresov@2606: void gen_write_ref_array_pre_barrier(Register start, Register count, bool uninitialized_target) { duke@435: assert_different_registers(start, count); duke@435: BarrierSet* bs = Universe::heap()->barrier_set(); duke@435: switch (bs->kind()) { duke@435: case BarrierSet::G1SATBCT: duke@435: case BarrierSet::G1SATBCTLogging: iveresov@2606: // With G1, don't generate the call if we statically know that the target in uninitialized iveresov@2606: if (!uninitialized_target) { iveresov@2606: __ pusha(); // push registers iveresov@2606: __ call_VM_leaf(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_pre), iveresov@2606: start, count); iveresov@2606: __ popa(); iveresov@2606: } duke@435: break; duke@435: case BarrierSet::CardTableModRef: duke@435: case BarrierSet::CardTableExtension: duke@435: case BarrierSet::ModRef: duke@435: break; duke@435: default : duke@435: ShouldNotReachHere(); duke@435: duke@435: } duke@435: } duke@435: duke@435: duke@435: // duke@435: // Generate a post-barrier for an array store duke@435: // duke@435: // start - starting address duke@435: // count - element count duke@435: // duke@435: // The two input registers are overwritten. duke@435: // duke@435: void gen_write_ref_array_post_barrier(Register start, Register count) { duke@435: BarrierSet* bs = Universe::heap()->barrier_set(); duke@435: assert_different_registers(start, count); duke@435: switch (bs->kind()) { duke@435: case BarrierSet::G1SATBCT: duke@435: case BarrierSet::G1SATBCTLogging: duke@435: { never@739: __ pusha(); // push registers apetrusenko@1627: __ call_VM_leaf(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_post), apetrusenko@1627: start, count); never@739: __ popa(); duke@435: } duke@435: break; duke@435: duke@435: case BarrierSet::CardTableModRef: duke@435: case BarrierSet::CardTableExtension: duke@435: { duke@435: CardTableModRefBS* ct = (CardTableModRefBS*)bs; duke@435: assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code"); duke@435: duke@435: Label L_loop; duke@435: const Register end = count; // elements count; end == start+count-1 duke@435: assert_different_registers(start, end); duke@435: never@739: __ lea(end, Address(start, count, Address::times_ptr, -wordSize)); never@739: __ shrptr(start, CardTableModRefBS::card_shift); never@739: __ shrptr(end, CardTableModRefBS::card_shift); never@739: __ subptr(end, start); // end --> count duke@435: __ BIND(L_loop); never@684: intptr_t disp = (intptr_t) ct->byte_map_base; never@684: Address cardtable(start, count, Address::times_1, disp); never@684: __ movb(cardtable, 0); duke@435: __ decrement(count); duke@435: __ jcc(Assembler::greaterEqual, L_loop); duke@435: } duke@435: break; duke@435: case BarrierSet::ModRef: duke@435: break; duke@435: default : duke@435: ShouldNotReachHere(); duke@435: duke@435: } duke@435: } duke@435: kvn@840: kvn@840: // Copy 64 bytes chunks kvn@840: // kvn@840: // Inputs: kvn@840: // from - source array address kvn@840: // to_from - destination array address - from kvn@840: // qword_count - 8-bytes element count, negative kvn@840: // kvn@840: void xmm_copy_forward(Register from, Register to_from, Register qword_count) { kvn@840: assert( UseSSE >= 2, "supported cpu only" ); kvn@840: Label L_copy_64_bytes_loop, L_copy_64_bytes, L_copy_8_bytes, L_exit; kvn@840: // Copy 64-byte chunks kvn@840: __ jmpb(L_copy_64_bytes); kvn@1800: __ align(OptoLoopAlignment); kvn@840: __ BIND(L_copy_64_bytes_loop); kvn@840: kvn@840: if(UseUnalignedLoadStores) { kvn@840: __ movdqu(xmm0, Address(from, 0)); kvn@840: __ movdqu(Address(from, to_from, Address::times_1, 0), xmm0); kvn@840: __ movdqu(xmm1, Address(from, 16)); kvn@840: __ movdqu(Address(from, to_from, Address::times_1, 16), xmm1); kvn@840: __ movdqu(xmm2, Address(from, 32)); kvn@840: __ movdqu(Address(from, to_from, Address::times_1, 32), xmm2); kvn@840: __ movdqu(xmm3, Address(from, 48)); kvn@840: __ movdqu(Address(from, to_from, Address::times_1, 48), xmm3); kvn@840: kvn@840: } else { kvn@840: __ movq(xmm0, Address(from, 0)); kvn@840: __ movq(Address(from, to_from, Address::times_1, 0), xmm0); kvn@840: __ movq(xmm1, Address(from, 8)); kvn@840: __ movq(Address(from, to_from, Address::times_1, 8), xmm1); kvn@840: __ movq(xmm2, Address(from, 16)); kvn@840: __ movq(Address(from, to_from, Address::times_1, 16), xmm2); kvn@840: __ movq(xmm3, Address(from, 24)); kvn@840: __ movq(Address(from, to_from, Address::times_1, 24), xmm3); kvn@840: __ movq(xmm4, Address(from, 32)); kvn@840: __ movq(Address(from, to_from, Address::times_1, 32), xmm4); kvn@840: __ movq(xmm5, Address(from, 40)); kvn@840: __ movq(Address(from, to_from, Address::times_1, 40), xmm5); kvn@840: __ movq(xmm6, Address(from, 48)); kvn@840: __ movq(Address(from, to_from, Address::times_1, 48), xmm6); kvn@840: __ movq(xmm7, Address(from, 56)); kvn@840: __ movq(Address(from, to_from, Address::times_1, 56), xmm7); kvn@840: } kvn@840: kvn@840: __ addl(from, 64); kvn@840: __ BIND(L_copy_64_bytes); kvn@840: __ subl(qword_count, 8); kvn@840: __ jcc(Assembler::greaterEqual, L_copy_64_bytes_loop); kvn@840: __ addl(qword_count, 8); kvn@840: __ jccb(Assembler::zero, L_exit); kvn@840: // kvn@840: // length is too short, just copy qwords kvn@840: // kvn@840: __ BIND(L_copy_8_bytes); kvn@840: __ movq(xmm0, Address(from, 0)); kvn@840: __ movq(Address(from, to_from, Address::times_1), xmm0); kvn@840: __ addl(from, 8); kvn@840: __ decrement(qword_count); kvn@840: __ jcc(Assembler::greater, L_copy_8_bytes); kvn@840: __ BIND(L_exit); kvn@840: } kvn@840: duke@435: // Copy 64 bytes chunks duke@435: // duke@435: // Inputs: duke@435: // from - source array address duke@435: // to_from - destination array address - from duke@435: // qword_count - 8-bytes element count, negative duke@435: // duke@435: void mmx_copy_forward(Register from, Register to_from, Register qword_count) { kvn@840: assert( VM_Version::supports_mmx(), "supported cpu only" ); duke@435: Label L_copy_64_bytes_loop, L_copy_64_bytes, L_copy_8_bytes, L_exit; duke@435: // Copy 64-byte chunks duke@435: __ jmpb(L_copy_64_bytes); kvn@1800: __ align(OptoLoopAlignment); duke@435: __ BIND(L_copy_64_bytes_loop); duke@435: __ movq(mmx0, Address(from, 0)); duke@435: __ movq(mmx1, Address(from, 8)); duke@435: __ movq(mmx2, Address(from, 16)); duke@435: __ movq(Address(from, to_from, Address::times_1, 0), mmx0); duke@435: __ movq(mmx3, Address(from, 24)); duke@435: __ movq(Address(from, to_from, Address::times_1, 8), mmx1); duke@435: __ movq(mmx4, Address(from, 32)); duke@435: __ movq(Address(from, to_from, Address::times_1, 16), mmx2); duke@435: __ movq(mmx5, Address(from, 40)); duke@435: __ movq(Address(from, to_from, Address::times_1, 24), mmx3); duke@435: __ movq(mmx6, Address(from, 48)); duke@435: __ movq(Address(from, to_from, Address::times_1, 32), mmx4); duke@435: __ movq(mmx7, Address(from, 56)); duke@435: __ movq(Address(from, to_from, Address::times_1, 40), mmx5); duke@435: __ movq(Address(from, to_from, Address::times_1, 48), mmx6); duke@435: __ movq(Address(from, to_from, Address::times_1, 56), mmx7); never@739: __ addptr(from, 64); duke@435: __ BIND(L_copy_64_bytes); duke@435: __ subl(qword_count, 8); duke@435: __ jcc(Assembler::greaterEqual, L_copy_64_bytes_loop); duke@435: __ addl(qword_count, 8); duke@435: __ jccb(Assembler::zero, L_exit); duke@435: // duke@435: // length is too short, just copy qwords duke@435: // duke@435: __ BIND(L_copy_8_bytes); duke@435: __ movq(mmx0, Address(from, 0)); duke@435: __ movq(Address(from, to_from, Address::times_1), mmx0); never@739: __ addptr(from, 8); duke@435: __ decrement(qword_count); duke@435: __ jcc(Assembler::greater, L_copy_8_bytes); duke@435: __ BIND(L_exit); duke@435: __ emms(); duke@435: } duke@435: duke@435: address generate_disjoint_copy(BasicType t, bool aligned, duke@435: Address::ScaleFactor sf, iveresov@2606: address* entry, const char *name, iveresov@2606: bool dest_uninitialized = false) { duke@435: __ align(CodeEntryAlignment); duke@435: StubCodeMark mark(this, "StubRoutines", name); duke@435: address start = __ pc(); duke@435: duke@435: Label L_0_count, L_exit, L_skip_align1, L_skip_align2, L_copy_byte; duke@435: Label L_copy_2_bytes, L_copy_4_bytes, L_copy_64_bytes; duke@435: never@739: int shift = Address::times_ptr - sf; duke@435: duke@435: const Register from = rsi; // source array address duke@435: const Register to = rdi; // destination array address duke@435: const Register count = rcx; // elements count duke@435: const Register to_from = to; // (to - from) duke@435: const Register saved_to = rdx; // saved destination array address duke@435: duke@435: __ enter(); // required for proper stackwalking of RuntimeStub frame never@739: __ push(rsi); never@739: __ push(rdi); never@739: __ movptr(from , Address(rsp, 12+ 4)); never@739: __ movptr(to , Address(rsp, 12+ 8)); duke@435: __ movl(count, Address(rsp, 12+ 12)); iveresov@2595: iveresov@2595: if (entry != NULL) { iveresov@2595: *entry = __ pc(); // Entry point from conjoint arraycopy stub. iveresov@2595: BLOCK_COMMENT("Entry:"); iveresov@2595: } iveresov@2595: duke@435: if (t == T_OBJECT) { duke@435: __ testl(count, count); duke@435: __ jcc(Assembler::zero, L_0_count); iveresov@2606: gen_write_ref_array_pre_barrier(to, count, dest_uninitialized); never@739: __ mov(saved_to, to); // save 'to' duke@435: } duke@435: never@739: __ subptr(to, from); // to --> to_from duke@435: __ cmpl(count, 2< to_from duke@435: if (VM_Version::supports_mmx()) { kvn@840: if (UseXMMForArrayCopy) { kvn@840: xmm_copy_forward(from, to_from, count); kvn@840: } else { kvn@840: mmx_copy_forward(from, to_from, count); kvn@840: } duke@435: } else { duke@435: __ jmpb(L_copy_8_bytes); kvn@1800: __ align(OptoLoopAlignment); duke@435: __ BIND(L_copy_8_bytes_loop); duke@435: __ fild_d(Address(from, 0)); duke@435: __ fistp_d(Address(from, to_from, Address::times_1)); never@739: __ addptr(from, 8); duke@435: __ BIND(L_copy_8_bytes); duke@435: __ decrement(count); duke@435: __ jcc(Assembler::greaterEqual, L_copy_8_bytes_loop); duke@435: } duke@435: inc_copy_counter_np(T_LONG); duke@435: __ leave(); // required for proper stackwalking of RuntimeStub frame never@739: __ xorptr(rax, rax); // return 0 duke@435: __ ret(0); duke@435: return start; duke@435: } duke@435: duke@435: address generate_conjoint_long_copy(address nooverlap_target, duke@435: address* entry, const char *name) { duke@435: __ align(CodeEntryAlignment); duke@435: StubCodeMark mark(this, "StubRoutines", name); duke@435: address start = __ pc(); duke@435: duke@435: Label L_copy_8_bytes, L_copy_8_bytes_loop; duke@435: const Register from = rax; // source array address duke@435: const Register to = rdx; // destination array address duke@435: const Register count = rcx; // elements count duke@435: const Register end_from = rax; // source array end address duke@435: duke@435: __ enter(); // required for proper stackwalking of RuntimeStub frame never@739: __ movptr(from , Address(rsp, 8+0)); // from never@739: __ movptr(to , Address(rsp, 8+4)); // to never@739: __ movl2ptr(count, Address(rsp, 8+8)); // count duke@435: duke@435: *entry = __ pc(); // Entry point from generic arraycopy stub. duke@435: BLOCK_COMMENT("Entry:"); duke@435: duke@435: // arrays overlap test never@739: __ cmpptr(to, from); duke@435: RuntimeAddress nooverlap(nooverlap_target); duke@435: __ jump_cc(Assembler::belowEqual, nooverlap); never@739: __ lea(end_from, Address(from, count, Address::times_8, 0)); never@739: __ cmpptr(to, end_from); never@739: __ movptr(from, Address(rsp, 8)); // from duke@435: __ jump_cc(Assembler::aboveEqual, nooverlap); duke@435: duke@435: __ jmpb(L_copy_8_bytes); duke@435: kvn@1800: __ align(OptoLoopAlignment); duke@435: __ BIND(L_copy_8_bytes_loop); duke@435: if (VM_Version::supports_mmx()) { kvn@840: if (UseXMMForArrayCopy) { kvn@840: __ movq(xmm0, Address(from, count, Address::times_8)); kvn@840: __ movq(Address(to, count, Address::times_8), xmm0); kvn@840: } else { kvn@840: __ movq(mmx0, Address(from, count, Address::times_8)); kvn@840: __ movq(Address(to, count, Address::times_8), mmx0); kvn@840: } duke@435: } else { duke@435: __ fild_d(Address(from, count, Address::times_8)); duke@435: __ fistp_d(Address(to, count, Address::times_8)); duke@435: } duke@435: __ BIND(L_copy_8_bytes); duke@435: __ decrement(count); duke@435: __ jcc(Assembler::greaterEqual, L_copy_8_bytes_loop); duke@435: kvn@840: if (VM_Version::supports_mmx() && !UseXMMForArrayCopy) { duke@435: __ emms(); duke@435: } duke@435: inc_copy_counter_np(T_LONG); duke@435: __ leave(); // required for proper stackwalking of RuntimeStub frame never@739: __ xorptr(rax, rax); // return 0 duke@435: __ ret(0); duke@435: return start; duke@435: } duke@435: duke@435: duke@435: // Helper for generating a dynamic type check. duke@435: // The sub_klass must be one of {rbx, rdx, rsi}. duke@435: // The temp is killed. duke@435: void generate_type_check(Register sub_klass, duke@435: Address& super_check_offset_addr, duke@435: Address& super_klass_addr, duke@435: Register temp, jrose@1079: Label* L_success, Label* L_failure) { duke@435: BLOCK_COMMENT("type_check:"); duke@435: duke@435: Label L_fallthrough; jrose@1079: #define LOCAL_JCC(assembler_con, label_ptr) \ jrose@1079: if (label_ptr != NULL) __ jcc(assembler_con, *(label_ptr)); \ jrose@1079: else __ jcc(assembler_con, L_fallthrough) /*omit semi*/ duke@435: jrose@1079: // The following is a strange variation of the fast path which requires jrose@1079: // one less register, because needed values are on the argument stack. jrose@1079: // __ check_klass_subtype_fast_path(sub_klass, *super_klass*, temp, jrose@1079: // L_success, L_failure, NULL); duke@435: assert_different_registers(sub_klass, temp); duke@435: stefank@3391: int sc_offset = in_bytes(Klass::secondary_super_cache_offset()); duke@435: duke@435: // if the pointers are equal, we are done (e.g., String[] elements) never@739: __ cmpptr(sub_klass, super_klass_addr); jrose@1079: LOCAL_JCC(Assembler::equal, L_success); duke@435: duke@435: // check the supertype display: never@739: __ movl2ptr(temp, super_check_offset_addr); duke@435: Address super_check_addr(sub_klass, temp, Address::times_1, 0); never@739: __ movptr(temp, super_check_addr); // load displayed supertype never@739: __ cmpptr(temp, super_klass_addr); // test the super type jrose@1079: LOCAL_JCC(Assembler::equal, L_success); duke@435: duke@435: // if it was a primary super, we can just fail immediately duke@435: __ cmpl(super_check_offset_addr, sc_offset); jrose@1079: LOCAL_JCC(Assembler::notEqual, L_failure); duke@435: jrose@1079: // The repne_scan instruction uses fixed registers, which will get spilled. jrose@1079: // We happen to know this works best when super_klass is in rax. jrose@1079: Register super_klass = temp; jrose@1079: __ movptr(super_klass, super_klass_addr); jrose@1079: __ check_klass_subtype_slow_path(sub_klass, super_klass, noreg, noreg, jrose@1079: L_success, L_failure); duke@435: jrose@1079: __ bind(L_fallthrough); duke@435: jrose@1079: if (L_success == NULL) { BLOCK_COMMENT("L_success:"); } jrose@1079: if (L_failure == NULL) { BLOCK_COMMENT("L_failure:"); } duke@435: jrose@1079: #undef LOCAL_JCC duke@435: } duke@435: duke@435: // duke@435: // Generate checkcasting array copy stub duke@435: // duke@435: // Input: duke@435: // 4(rsp) - source array address duke@435: // 8(rsp) - destination array address duke@435: // 12(rsp) - element count, can be zero duke@435: // 16(rsp) - size_t ckoff (super_check_offset) duke@435: // 20(rsp) - oop ckval (super_klass) duke@435: // duke@435: // Output: duke@435: // rax, == 0 - success duke@435: // rax, == -1^K - failure, where K is partial transfer count duke@435: // iveresov@2606: address generate_checkcast_copy(const char *name, address* entry, bool dest_uninitialized = false) { duke@435: __ align(CodeEntryAlignment); duke@435: StubCodeMark mark(this, "StubRoutines", name); duke@435: address start = __ pc(); duke@435: duke@435: Label L_load_element, L_store_element, L_do_card_marks, L_done; duke@435: duke@435: // register use: duke@435: // rax, rdx, rcx -- loop control (end_from, end_to, count) duke@435: // rdi, rsi -- element access (oop, klass) duke@435: // rbx, -- temp duke@435: const Register from = rax; // source array address duke@435: const Register to = rdx; // destination array address duke@435: const Register length = rcx; // elements count duke@435: const Register elem = rdi; // each oop copied duke@435: const Register elem_klass = rsi; // each elem._klass (sub_klass) duke@435: const Register temp = rbx; // lone remaining temp duke@435: duke@435: __ enter(); // required for proper stackwalking of RuntimeStub frame duke@435: never@739: __ push(rsi); never@739: __ push(rdi); never@739: __ push(rbx); duke@435: duke@435: Address from_arg(rsp, 16+ 4); // from duke@435: Address to_arg(rsp, 16+ 8); // to duke@435: Address length_arg(rsp, 16+12); // elements count duke@435: Address ckoff_arg(rsp, 16+16); // super_check_offset duke@435: Address ckval_arg(rsp, 16+20); // super_klass duke@435: duke@435: // Load up: never@739: __ movptr(from, from_arg); never@739: __ movptr(to, to_arg); never@739: __ movl2ptr(length, length_arg); duke@435: iveresov@2595: if (entry != NULL) { iveresov@2595: *entry = __ pc(); // Entry point from generic arraycopy stub. iveresov@2595: BLOCK_COMMENT("Entry:"); iveresov@2595: } duke@435: duke@435: //--------------------------------------------------------------- duke@435: // Assembler stub will be used for this call to arraycopy duke@435: // if the two arrays are subtypes of Object[] but the duke@435: // destination array type is not equal to or a supertype duke@435: // of the source type. Each element must be separately duke@435: // checked. duke@435: duke@435: // Loop-invariant addresses. They are exclusive end pointers. never@739: Address end_from_addr(from, length, Address::times_ptr, 0); never@739: Address end_to_addr(to, length, Address::times_ptr, 0); duke@435: duke@435: Register end_from = from; // re-use duke@435: Register end_to = to; // re-use duke@435: Register count = length; // re-use duke@435: duke@435: // Loop-variant addresses. They assume post-incremented count < 0. never@739: Address from_element_addr(end_from, count, Address::times_ptr, 0); never@739: Address to_element_addr(end_to, count, Address::times_ptr, 0); duke@435: Address elem_klass_addr(elem, oopDesc::klass_offset_in_bytes()); duke@435: duke@435: // Copy from low to high addresses, indexed from the end of each array. iveresov@2606: gen_write_ref_array_pre_barrier(to, count, dest_uninitialized); never@739: __ lea(end_from, end_from_addr); never@739: __ lea(end_to, end_to_addr); duke@435: assert(length == count, ""); // else fix next line: never@739: __ negptr(count); // negate and test the length duke@435: __ jccb(Assembler::notZero, L_load_element); duke@435: duke@435: // Empty array: Nothing to do. never@739: __ xorptr(rax, rax); // return 0 on (trivial) success duke@435: __ jmp(L_done); duke@435: duke@435: // ======== begin loop ======== duke@435: // (Loop is rotated; its entry is L_load_element.) duke@435: // Loop control: duke@435: // for (count = -count; count != 0; count++) duke@435: // Base pointers src, dst are biased by 8*count,to last element. kvn@1800: __ align(OptoLoopAlignment); duke@435: duke@435: __ BIND(L_store_element); never@739: __ movptr(to_element_addr, elem); // store the oop duke@435: __ increment(count); // increment the count toward zero duke@435: __ jccb(Assembler::zero, L_do_card_marks); duke@435: duke@435: // ======== loop entry is here ======== duke@435: __ BIND(L_load_element); never@739: __ movptr(elem, from_element_addr); // load the oop never@739: __ testptr(elem, elem); duke@435: __ jccb(Assembler::zero, L_store_element); duke@435: duke@435: // (Could do a trick here: Remember last successful non-null duke@435: // element stored and make a quick oop equality check on it.) duke@435: never@739: __ movptr(elem_klass, elem_klass_addr); // query the object klass duke@435: generate_type_check(elem_klass, ckoff_arg, ckval_arg, temp, duke@435: &L_store_element, NULL); duke@435: // (On fall-through, we have failed the element type check.) duke@435: // ======== end loop ======== duke@435: duke@435: // It was a real error; we must depend on the caller to finish the job. rasbold@454: // Register "count" = -1 * number of *remaining* oops, length_arg = *total* oops. rasbold@454: // Emit GC store barriers for the oops we have copied (length_arg + count), duke@435: // and report their number to the caller. duke@435: __ addl(count, length_arg); // transfers = (length - remaining) never@739: __ movl2ptr(rax, count); // save the value never@739: __ notptr(rax); // report (-1^K) to caller never@739: __ movptr(to, to_arg); // reload duke@435: assert_different_registers(to, count, rax); duke@435: gen_write_ref_array_post_barrier(to, count); duke@435: __ jmpb(L_done); duke@435: duke@435: // Come here on success only. duke@435: __ BIND(L_do_card_marks); never@739: __ movl2ptr(count, length_arg); never@739: __ movptr(to, to_arg); // reload duke@435: gen_write_ref_array_post_barrier(to, count); never@739: __ xorptr(rax, rax); // return 0 on success duke@435: duke@435: // Common exit point (success or failure). duke@435: __ BIND(L_done); never@739: __ pop(rbx); never@739: __ pop(rdi); never@739: __ pop(rsi); duke@435: inc_counter_np(SharedRuntime::_checkcast_array_copy_ctr); duke@435: __ leave(); // required for proper stackwalking of RuntimeStub frame duke@435: __ ret(0); duke@435: duke@435: return start; duke@435: } duke@435: duke@435: // duke@435: // Generate 'unsafe' array copy stub duke@435: // Though just as safe as the other stubs, it takes an unscaled duke@435: // size_t argument instead of an element count. duke@435: // duke@435: // Input: duke@435: // 4(rsp) - source array address duke@435: // 8(rsp) - destination array address duke@435: // 12(rsp) - byte count, can be zero duke@435: // duke@435: // Output: duke@435: // rax, == 0 - success duke@435: // rax, == -1 - need to call System.arraycopy duke@435: // duke@435: // Examines the alignment of the operands and dispatches duke@435: // to a long, int, short, or byte copy loop. duke@435: // duke@435: address generate_unsafe_copy(const char *name, duke@435: address byte_copy_entry, duke@435: address short_copy_entry, duke@435: address int_copy_entry, duke@435: address long_copy_entry) { duke@435: duke@435: Label L_long_aligned, L_int_aligned, L_short_aligned; duke@435: duke@435: __ align(CodeEntryAlignment); duke@435: StubCodeMark mark(this, "StubRoutines", name); duke@435: address start = __ pc(); duke@435: duke@435: const Register from = rax; // source array address duke@435: const Register to = rdx; // destination array address duke@435: const Register count = rcx; // elements count duke@435: duke@435: __ enter(); // required for proper stackwalking of RuntimeStub frame never@739: __ push(rsi); never@739: __ push(rdi); duke@435: Address from_arg(rsp, 12+ 4); // from duke@435: Address to_arg(rsp, 12+ 8); // to duke@435: Address count_arg(rsp, 12+12); // byte count duke@435: duke@435: // Load up: never@739: __ movptr(from , from_arg); never@739: __ movptr(to , to_arg); never@739: __ movl2ptr(count, count_arg); duke@435: duke@435: // bump this on entry, not on exit: duke@435: inc_counter_np(SharedRuntime::_unsafe_array_copy_ctr); duke@435: duke@435: const Register bits = rsi; never@739: __ mov(bits, from); never@739: __ orptr(bits, to); never@739: __ orptr(bits, count); duke@435: duke@435: __ testl(bits, BytesPerLong-1); duke@435: __ jccb(Assembler::zero, L_long_aligned); duke@435: duke@435: __ testl(bits, BytesPerInt-1); duke@435: __ jccb(Assembler::zero, L_int_aligned); duke@435: duke@435: __ testl(bits, BytesPerShort-1); duke@435: __ jump_cc(Assembler::notZero, RuntimeAddress(byte_copy_entry)); duke@435: duke@435: __ BIND(L_short_aligned); never@739: __ shrptr(count, LogBytesPerShort); // size => short_count duke@435: __ movl(count_arg, count); // update 'count' duke@435: __ jump(RuntimeAddress(short_copy_entry)); duke@435: duke@435: __ BIND(L_int_aligned); never@739: __ shrptr(count, LogBytesPerInt); // size => int_count duke@435: __ movl(count_arg, count); // update 'count' duke@435: __ jump(RuntimeAddress(int_copy_entry)); duke@435: duke@435: __ BIND(L_long_aligned); never@739: __ shrptr(count, LogBytesPerLong); // size => qword_count duke@435: __ movl(count_arg, count); // update 'count' never@739: __ pop(rdi); // Do pops here since jlong_arraycopy stub does not do it. never@739: __ pop(rsi); duke@435: __ jump(RuntimeAddress(long_copy_entry)); duke@435: duke@435: return start; duke@435: } duke@435: duke@435: duke@435: // Perform range checks on the proposed arraycopy. duke@435: // Smashes src_pos and dst_pos. (Uses them up for temps.) duke@435: void arraycopy_range_checks(Register src, duke@435: Register src_pos, duke@435: Register dst, duke@435: Register dst_pos, duke@435: Address& length, duke@435: Label& L_failed) { duke@435: BLOCK_COMMENT("arraycopy_range_checks:"); duke@435: const Register src_end = src_pos; // source array end position duke@435: const Register dst_end = dst_pos; // destination array end position duke@435: __ addl(src_end, length); // src_pos + length duke@435: __ addl(dst_end, length); // dst_pos + length duke@435: duke@435: // if (src_pos + length > arrayOop(src)->length() ) FAIL; duke@435: __ cmpl(src_end, Address(src, arrayOopDesc::length_offset_in_bytes())); duke@435: __ jcc(Assembler::above, L_failed); duke@435: duke@435: // if (dst_pos + length > arrayOop(dst)->length() ) FAIL; duke@435: __ cmpl(dst_end, Address(dst, arrayOopDesc::length_offset_in_bytes())); duke@435: __ jcc(Assembler::above, L_failed); duke@435: duke@435: BLOCK_COMMENT("arraycopy_range_checks done"); duke@435: } duke@435: duke@435: duke@435: // duke@435: // Generate generic array copy stubs duke@435: // duke@435: // Input: duke@435: // 4(rsp) - src oop duke@435: // 8(rsp) - src_pos duke@435: // 12(rsp) - dst oop duke@435: // 16(rsp) - dst_pos duke@435: // 20(rsp) - element count duke@435: // duke@435: // Output: duke@435: // rax, == 0 - success duke@435: // rax, == -1^K - failure, where K is partial transfer count duke@435: // duke@435: address generate_generic_copy(const char *name, duke@435: address entry_jbyte_arraycopy, duke@435: address entry_jshort_arraycopy, duke@435: address entry_jint_arraycopy, duke@435: address entry_oop_arraycopy, duke@435: address entry_jlong_arraycopy, duke@435: address entry_checkcast_arraycopy) { duke@435: Label L_failed, L_failed_0, L_objArray; duke@435: duke@435: { int modulus = CodeEntryAlignment; duke@435: int target = modulus - 5; // 5 = sizeof jmp(L_failed) duke@435: int advance = target - (__ offset() % modulus); duke@435: if (advance < 0) advance += modulus; duke@435: if (advance > 0) __ nop(advance); duke@435: } duke@435: StubCodeMark mark(this, "StubRoutines", name); duke@435: duke@435: // Short-hop target to L_failed. Makes for denser prologue code. duke@435: __ BIND(L_failed_0); duke@435: __ jmp(L_failed); duke@435: assert(__ offset() % CodeEntryAlignment == 0, "no further alignment needed"); duke@435: duke@435: __ align(CodeEntryAlignment); duke@435: address start = __ pc(); duke@435: duke@435: __ enter(); // required for proper stackwalking of RuntimeStub frame never@739: __ push(rsi); never@739: __ push(rdi); duke@435: duke@435: // bump this on entry, not on exit: duke@435: inc_counter_np(SharedRuntime::_generic_array_copy_ctr); duke@435: duke@435: // Input values duke@435: Address SRC (rsp, 12+ 4); duke@435: Address SRC_POS (rsp, 12+ 8); duke@435: Address DST (rsp, 12+12); duke@435: Address DST_POS (rsp, 12+16); duke@435: Address LENGTH (rsp, 12+20); duke@435: duke@435: //----------------------------------------------------------------------- duke@435: // Assembler stub will be used for this call to arraycopy duke@435: // if the following conditions are met: duke@435: // duke@435: // (1) src and dst must not be null. duke@435: // (2) src_pos must not be negative. duke@435: // (3) dst_pos must not be negative. duke@435: // (4) length must not be negative. duke@435: // (5) src klass and dst klass should be the same and not NULL. duke@435: // (6) src and dst should be arrays. duke@435: // (7) src_pos + length must not exceed length of src. duke@435: // (8) dst_pos + length must not exceed length of dst. duke@435: // duke@435: duke@435: const Register src = rax; // source array oop duke@435: const Register src_pos = rsi; duke@435: const Register dst = rdx; // destination array oop duke@435: const Register dst_pos = rdi; duke@435: const Register length = rcx; // transfer count duke@435: duke@435: // if (src == NULL) return -1; never@739: __ movptr(src, SRC); // src oop never@739: __ testptr(src, src); duke@435: __ jccb(Assembler::zero, L_failed_0); duke@435: duke@435: // if (src_pos < 0) return -1; never@739: __ movl2ptr(src_pos, SRC_POS); // src_pos duke@435: __ testl(src_pos, src_pos); duke@435: __ jccb(Assembler::negative, L_failed_0); duke@435: duke@435: // if (dst == NULL) return -1; never@739: __ movptr(dst, DST); // dst oop never@739: __ testptr(dst, dst); duke@435: __ jccb(Assembler::zero, L_failed_0); duke@435: duke@435: // if (dst_pos < 0) return -1; never@739: __ movl2ptr(dst_pos, DST_POS); // dst_pos duke@435: __ testl(dst_pos, dst_pos); duke@435: __ jccb(Assembler::negative, L_failed_0); duke@435: duke@435: // if (length < 0) return -1; never@739: __ movl2ptr(length, LENGTH); // length duke@435: __ testl(length, length); duke@435: __ jccb(Assembler::negative, L_failed_0); duke@435: duke@435: // if (src->klass() == NULL) return -1; duke@435: Address src_klass_addr(src, oopDesc::klass_offset_in_bytes()); duke@435: Address dst_klass_addr(dst, oopDesc::klass_offset_in_bytes()); duke@435: const Register rcx_src_klass = rcx; // array klass never@739: __ movptr(rcx_src_klass, Address(src, oopDesc::klass_offset_in_bytes())); duke@435: duke@435: #ifdef ASSERT duke@435: // assert(src->klass() != NULL); duke@435: BLOCK_COMMENT("assert klasses not null"); duke@435: { Label L1, L2; never@739: __ testptr(rcx_src_klass, rcx_src_klass); duke@435: __ jccb(Assembler::notZero, L2); // it is broken if klass is NULL duke@435: __ bind(L1); duke@435: __ stop("broken null klass"); duke@435: __ bind(L2); never@739: __ cmpptr(dst_klass_addr, (int32_t)NULL_WORD); duke@435: __ jccb(Assembler::equal, L1); // this would be broken also duke@435: BLOCK_COMMENT("assert done"); duke@435: } duke@435: #endif //ASSERT duke@435: duke@435: // Load layout helper (32-bits) duke@435: // duke@435: // |array_tag| | header_size | element_type | |log2_element_size| duke@435: // 32 30 24 16 8 2 0 duke@435: // duke@435: // array_tag: typeArray = 0x3, objArray = 0x2, non-array = 0x0 duke@435: // duke@435: stefank@3391: int lh_offset = in_bytes(Klass::layout_helper_offset()); duke@435: Address src_klass_lh_addr(rcx_src_klass, lh_offset); duke@435: duke@435: // Handle objArrays completely differently... duke@435: jint objArray_lh = Klass::array_layout_helper(T_OBJECT); duke@435: __ cmpl(src_klass_lh_addr, objArray_lh); duke@435: __ jcc(Assembler::equal, L_objArray); duke@435: duke@435: // if (src->klass() != dst->klass()) return -1; never@739: __ cmpptr(rcx_src_klass, dst_klass_addr); duke@435: __ jccb(Assembler::notEqual, L_failed_0); duke@435: duke@435: const Register rcx_lh = rcx; // layout helper duke@435: assert(rcx_lh == rcx_src_klass, "known alias"); duke@435: __ movl(rcx_lh, src_klass_lh_addr); duke@435: duke@435: // if (!src->is_Array()) return -1; duke@435: __ cmpl(rcx_lh, Klass::_lh_neutral_value); duke@435: __ jcc(Assembler::greaterEqual, L_failed_0); // signed cmp duke@435: duke@435: // At this point, it is known to be a typeArray (array_tag 0x3). duke@435: #ifdef ASSERT duke@435: { Label L; duke@435: __ cmpl(rcx_lh, (Klass::_lh_array_tag_type_value << Klass::_lh_array_tag_shift)); duke@435: __ jcc(Assembler::greaterEqual, L); // signed cmp duke@435: __ stop("must be a primitive array"); duke@435: __ bind(L); duke@435: } duke@435: #endif duke@435: duke@435: assert_different_registers(src, src_pos, dst, dst_pos, rcx_lh); duke@435: arraycopy_range_checks(src, src_pos, dst, dst_pos, LENGTH, L_failed); duke@435: duke@435: // typeArrayKlass duke@435: // duke@435: // src_addr = (src + array_header_in_bytes()) + (src_pos << log2elemsize); duke@435: // dst_addr = (dst + array_header_in_bytes()) + (dst_pos << log2elemsize); duke@435: // duke@435: const Register rsi_offset = rsi; // array offset duke@435: const Register src_array = src; // src array offset duke@435: const Register dst_array = dst; // dst array offset duke@435: const Register rdi_elsize = rdi; // log2 element size duke@435: never@739: __ mov(rsi_offset, rcx_lh); never@739: __ shrptr(rsi_offset, Klass::_lh_header_size_shift); never@739: __ andptr(rsi_offset, Klass::_lh_header_size_mask); // array_offset never@739: __ addptr(src_array, rsi_offset); // src array offset never@739: __ addptr(dst_array, rsi_offset); // dst array offset never@739: __ andptr(rcx_lh, Klass::_lh_log2_element_size_mask); // log2 elsize duke@435: duke@435: // next registers should be set before the jump to corresponding stub duke@435: const Register from = src; // source array address duke@435: const Register to = dst; // destination array address duke@435: const Register count = rcx; // elements count duke@435: // some of them should be duplicated on stack duke@435: #define FROM Address(rsp, 12+ 4) duke@435: #define TO Address(rsp, 12+ 8) // Not used now duke@435: #define COUNT Address(rsp, 12+12) // Only for oop arraycopy duke@435: duke@435: BLOCK_COMMENT("scale indexes to element size"); never@739: __ movl2ptr(rsi, SRC_POS); // src_pos never@739: __ shlptr(rsi); // src_pos << rcx (log2 elsize) duke@435: assert(src_array == from, ""); never@739: __ addptr(from, rsi); // from = src_array + SRC_POS << log2 elsize never@739: __ movl2ptr(rdi, DST_POS); // dst_pos never@739: __ shlptr(rdi); // dst_pos << rcx (log2 elsize) duke@435: assert(dst_array == to, ""); never@739: __ addptr(to, rdi); // to = dst_array + DST_POS << log2 elsize never@739: __ movptr(FROM, from); // src_addr never@739: __ mov(rdi_elsize, rcx_lh); // log2 elsize never@739: __ movl2ptr(count, LENGTH); // elements count duke@435: duke@435: BLOCK_COMMENT("choose copy loop based on element size"); duke@435: __ cmpl(rdi_elsize, 0); duke@435: duke@435: __ jump_cc(Assembler::equal, RuntimeAddress(entry_jbyte_arraycopy)); duke@435: __ cmpl(rdi_elsize, LogBytesPerShort); duke@435: __ jump_cc(Assembler::equal, RuntimeAddress(entry_jshort_arraycopy)); duke@435: __ cmpl(rdi_elsize, LogBytesPerInt); duke@435: __ jump_cc(Assembler::equal, RuntimeAddress(entry_jint_arraycopy)); duke@435: #ifdef ASSERT duke@435: __ cmpl(rdi_elsize, LogBytesPerLong); duke@435: __ jccb(Assembler::notEqual, L_failed); duke@435: #endif never@739: __ pop(rdi); // Do pops here since jlong_arraycopy stub does not do it. never@739: __ pop(rsi); duke@435: __ jump(RuntimeAddress(entry_jlong_arraycopy)); duke@435: duke@435: __ BIND(L_failed); never@739: __ xorptr(rax, rax); never@739: __ notptr(rax); // return -1 never@739: __ pop(rdi); never@739: __ pop(rsi); duke@435: __ leave(); // required for proper stackwalking of RuntimeStub frame duke@435: __ ret(0); duke@435: duke@435: // objArrayKlass duke@435: __ BIND(L_objArray); duke@435: // live at this point: rcx_src_klass, src[_pos], dst[_pos] duke@435: duke@435: Label L_plain_copy, L_checkcast_copy; duke@435: // test array classes for subtyping never@739: __ cmpptr(rcx_src_klass, dst_klass_addr); // usual case is exact equality duke@435: __ jccb(Assembler::notEqual, L_checkcast_copy); duke@435: duke@435: // Identically typed arrays can be copied without element-wise checks. duke@435: assert_different_registers(src, src_pos, dst, dst_pos, rcx_src_klass); duke@435: arraycopy_range_checks(src, src_pos, dst, dst_pos, LENGTH, L_failed); duke@435: duke@435: __ BIND(L_plain_copy); never@739: __ movl2ptr(count, LENGTH); // elements count never@739: __ movl2ptr(src_pos, SRC_POS); // reload src_pos never@739: __ lea(from, Address(src, src_pos, Address::times_ptr, never@739: arrayOopDesc::base_offset_in_bytes(T_OBJECT))); // src_addr never@739: __ movl2ptr(dst_pos, DST_POS); // reload dst_pos never@739: __ lea(to, Address(dst, dst_pos, Address::times_ptr, never@739: arrayOopDesc::base_offset_in_bytes(T_OBJECT))); // dst_addr never@739: __ movptr(FROM, from); // src_addr never@739: __ movptr(TO, to); // dst_addr duke@435: __ movl(COUNT, count); // count duke@435: __ jump(RuntimeAddress(entry_oop_arraycopy)); duke@435: duke@435: __ BIND(L_checkcast_copy); duke@435: // live at this point: rcx_src_klass, dst[_pos], src[_pos] duke@435: { duke@435: // Handy offsets: stefank@3391: int ek_offset = in_bytes(objArrayKlass::element_klass_offset()); stefank@3391: int sco_offset = in_bytes(Klass::super_check_offset_offset()); duke@435: duke@435: Register rsi_dst_klass = rsi; duke@435: Register rdi_temp = rdi; duke@435: assert(rsi_dst_klass == src_pos, "expected alias w/ src_pos"); duke@435: assert(rdi_temp == dst_pos, "expected alias w/ dst_pos"); duke@435: Address dst_klass_lh_addr(rsi_dst_klass, lh_offset); duke@435: duke@435: // Before looking at dst.length, make sure dst is also an objArray. never@739: __ movptr(rsi_dst_klass, dst_klass_addr); duke@435: __ cmpl(dst_klass_lh_addr, objArray_lh); duke@435: __ jccb(Assembler::notEqual, L_failed); duke@435: duke@435: // It is safe to examine both src.length and dst.length. never@739: __ movl2ptr(src_pos, SRC_POS); // reload rsi duke@435: arraycopy_range_checks(src, src_pos, dst, dst_pos, LENGTH, L_failed); duke@435: // (Now src_pos and dst_pos are killed, but not src and dst.) duke@435: duke@435: // We'll need this temp (don't forget to pop it after the type check). never@739: __ push(rbx); duke@435: Register rbx_src_klass = rbx; duke@435: never@739: __ mov(rbx_src_klass, rcx_src_klass); // spill away from rcx never@739: __ movptr(rsi_dst_klass, dst_klass_addr); duke@435: Address super_check_offset_addr(rsi_dst_klass, sco_offset); duke@435: Label L_fail_array_check; duke@435: generate_type_check(rbx_src_klass, duke@435: super_check_offset_addr, dst_klass_addr, duke@435: rdi_temp, NULL, &L_fail_array_check); duke@435: // (On fall-through, we have passed the array type check.) never@739: __ pop(rbx); duke@435: __ jmp(L_plain_copy); duke@435: duke@435: __ BIND(L_fail_array_check); duke@435: // Reshuffle arguments so we can call checkcast_arraycopy: duke@435: duke@435: // match initial saves for checkcast_arraycopy never@739: // push(rsi); // already done; see above never@739: // push(rdi); // already done; see above never@739: // push(rbx); // already done; see above duke@435: duke@435: // Marshal outgoing arguments now, freeing registers. duke@435: Address from_arg(rsp, 16+ 4); // from duke@435: Address to_arg(rsp, 16+ 8); // to duke@435: Address length_arg(rsp, 16+12); // elements count duke@435: Address ckoff_arg(rsp, 16+16); // super_check_offset duke@435: Address ckval_arg(rsp, 16+20); // super_klass duke@435: duke@435: Address SRC_POS_arg(rsp, 16+ 8); duke@435: Address DST_POS_arg(rsp, 16+16); duke@435: Address LENGTH_arg(rsp, 16+20); duke@435: // push rbx, changed the incoming offsets (why not just use rbp,??) duke@435: // assert(SRC_POS_arg.disp() == SRC_POS.disp() + 4, ""); duke@435: never@739: __ movptr(rbx, Address(rsi_dst_klass, ek_offset)); never@739: __ movl2ptr(length, LENGTH_arg); // reload elements count never@739: __ movl2ptr(src_pos, SRC_POS_arg); // reload src_pos never@739: __ movl2ptr(dst_pos, DST_POS_arg); // reload dst_pos duke@435: never@739: __ movptr(ckval_arg, rbx); // destination element type duke@435: __ movl(rbx, Address(rbx, sco_offset)); duke@435: __ movl(ckoff_arg, rbx); // corresponding class check offset duke@435: duke@435: __ movl(length_arg, length); // outgoing length argument duke@435: never@739: __ lea(from, Address(src, src_pos, Address::times_ptr, duke@435: arrayOopDesc::base_offset_in_bytes(T_OBJECT))); never@739: __ movptr(from_arg, from); duke@435: never@739: __ lea(to, Address(dst, dst_pos, Address::times_ptr, duke@435: arrayOopDesc::base_offset_in_bytes(T_OBJECT))); never@739: __ movptr(to_arg, to); duke@435: __ jump(RuntimeAddress(entry_checkcast_arraycopy)); duke@435: } duke@435: duke@435: return start; duke@435: } duke@435: duke@435: void generate_arraycopy_stubs() { duke@435: address entry; duke@435: address entry_jbyte_arraycopy; duke@435: address entry_jshort_arraycopy; duke@435: address entry_jint_arraycopy; duke@435: address entry_oop_arraycopy; duke@435: address entry_jlong_arraycopy; duke@435: address entry_checkcast_arraycopy; duke@435: duke@435: StubRoutines::_arrayof_jbyte_disjoint_arraycopy = duke@435: generate_disjoint_copy(T_BYTE, true, Address::times_1, &entry, duke@435: "arrayof_jbyte_disjoint_arraycopy"); duke@435: StubRoutines::_arrayof_jbyte_arraycopy = duke@435: generate_conjoint_copy(T_BYTE, true, Address::times_1, entry, duke@435: NULL, "arrayof_jbyte_arraycopy"); duke@435: StubRoutines::_jbyte_disjoint_arraycopy = duke@435: generate_disjoint_copy(T_BYTE, false, Address::times_1, &entry, duke@435: "jbyte_disjoint_arraycopy"); duke@435: StubRoutines::_jbyte_arraycopy = duke@435: generate_conjoint_copy(T_BYTE, false, Address::times_1, entry, duke@435: &entry_jbyte_arraycopy, "jbyte_arraycopy"); duke@435: duke@435: StubRoutines::_arrayof_jshort_disjoint_arraycopy = duke@435: generate_disjoint_copy(T_SHORT, true, Address::times_2, &entry, duke@435: "arrayof_jshort_disjoint_arraycopy"); duke@435: StubRoutines::_arrayof_jshort_arraycopy = duke@435: generate_conjoint_copy(T_SHORT, true, Address::times_2, entry, duke@435: NULL, "arrayof_jshort_arraycopy"); duke@435: StubRoutines::_jshort_disjoint_arraycopy = duke@435: generate_disjoint_copy(T_SHORT, false, Address::times_2, &entry, duke@435: "jshort_disjoint_arraycopy"); duke@435: StubRoutines::_jshort_arraycopy = duke@435: generate_conjoint_copy(T_SHORT, false, Address::times_2, entry, duke@435: &entry_jshort_arraycopy, "jshort_arraycopy"); duke@435: duke@435: // Next arrays are always aligned on 4 bytes at least. duke@435: StubRoutines::_jint_disjoint_arraycopy = duke@435: generate_disjoint_copy(T_INT, true, Address::times_4, &entry, duke@435: "jint_disjoint_arraycopy"); duke@435: StubRoutines::_jint_arraycopy = duke@435: generate_conjoint_copy(T_INT, true, Address::times_4, entry, duke@435: &entry_jint_arraycopy, "jint_arraycopy"); duke@435: duke@435: StubRoutines::_oop_disjoint_arraycopy = never@739: generate_disjoint_copy(T_OBJECT, true, Address::times_ptr, &entry, duke@435: "oop_disjoint_arraycopy"); duke@435: StubRoutines::_oop_arraycopy = never@739: generate_conjoint_copy(T_OBJECT, true, Address::times_ptr, entry, duke@435: &entry_oop_arraycopy, "oop_arraycopy"); duke@435: iveresov@2606: StubRoutines::_oop_disjoint_arraycopy_uninit = iveresov@2606: generate_disjoint_copy(T_OBJECT, true, Address::times_ptr, &entry, iveresov@2606: "oop_disjoint_arraycopy_uninit", iveresov@2606: /*dest_uninitialized*/true); iveresov@2606: StubRoutines::_oop_arraycopy_uninit = iveresov@2606: generate_conjoint_copy(T_OBJECT, true, Address::times_ptr, entry, iveresov@2606: NULL, "oop_arraycopy_uninit", iveresov@2606: /*dest_uninitialized*/true); iveresov@2606: duke@435: StubRoutines::_jlong_disjoint_arraycopy = duke@435: generate_disjoint_long_copy(&entry, "jlong_disjoint_arraycopy"); duke@435: StubRoutines::_jlong_arraycopy = duke@435: generate_conjoint_long_copy(entry, &entry_jlong_arraycopy, duke@435: "jlong_arraycopy"); duke@435: never@2118: StubRoutines::_jbyte_fill = generate_fill(T_BYTE, false, "jbyte_fill"); never@2118: StubRoutines::_jshort_fill = generate_fill(T_SHORT, false, "jshort_fill"); never@2118: StubRoutines::_jint_fill = generate_fill(T_INT, false, "jint_fill"); never@2118: StubRoutines::_arrayof_jbyte_fill = generate_fill(T_BYTE, true, "arrayof_jbyte_fill"); never@2118: StubRoutines::_arrayof_jshort_fill = generate_fill(T_SHORT, true, "arrayof_jshort_fill"); never@2118: StubRoutines::_arrayof_jint_fill = generate_fill(T_INT, true, "arrayof_jint_fill"); never@2118: iveresov@2606: StubRoutines::_arrayof_jint_disjoint_arraycopy = StubRoutines::_jint_disjoint_arraycopy; iveresov@2606: StubRoutines::_arrayof_oop_disjoint_arraycopy = StubRoutines::_oop_disjoint_arraycopy; iveresov@2606: StubRoutines::_arrayof_oop_disjoint_arraycopy_uninit = StubRoutines::_oop_disjoint_arraycopy_uninit; iveresov@2606: StubRoutines::_arrayof_jlong_disjoint_arraycopy = StubRoutines::_jlong_disjoint_arraycopy; duke@435: iveresov@2606: StubRoutines::_arrayof_jint_arraycopy = StubRoutines::_jint_arraycopy; iveresov@2606: StubRoutines::_arrayof_oop_arraycopy = StubRoutines::_oop_arraycopy; iveresov@2606: StubRoutines::_arrayof_oop_arraycopy_uninit = StubRoutines::_oop_arraycopy_uninit; iveresov@2606: StubRoutines::_arrayof_jlong_arraycopy = StubRoutines::_jlong_arraycopy; duke@435: duke@435: StubRoutines::_checkcast_arraycopy = iveresov@2606: generate_checkcast_copy("checkcast_arraycopy", &entry_checkcast_arraycopy); iveresov@2606: StubRoutines::_checkcast_arraycopy_uninit = iveresov@2606: generate_checkcast_copy("checkcast_arraycopy_uninit", NULL, /*dest_uninitialized*/true); duke@435: duke@435: StubRoutines::_unsafe_arraycopy = duke@435: generate_unsafe_copy("unsafe_arraycopy", duke@435: entry_jbyte_arraycopy, duke@435: entry_jshort_arraycopy, duke@435: entry_jint_arraycopy, duke@435: entry_jlong_arraycopy); duke@435: duke@435: StubRoutines::_generic_arraycopy = duke@435: generate_generic_copy("generic_arraycopy", duke@435: entry_jbyte_arraycopy, duke@435: entry_jshort_arraycopy, duke@435: entry_jint_arraycopy, duke@435: entry_oop_arraycopy, duke@435: entry_jlong_arraycopy, duke@435: entry_checkcast_arraycopy); duke@435: } duke@435: never@1609: void generate_math_stubs() { never@1609: { never@1609: StubCodeMark mark(this, "StubRoutines", "log"); never@1609: StubRoutines::_intrinsic_log = (double (*)(double)) __ pc(); never@1609: never@1609: __ fld_d(Address(rsp, 4)); never@1609: __ flog(); never@1609: __ ret(0); never@1609: } never@1609: { never@1609: StubCodeMark mark(this, "StubRoutines", "log10"); never@1609: StubRoutines::_intrinsic_log10 = (double (*)(double)) __ pc(); never@1609: never@1609: __ fld_d(Address(rsp, 4)); never@1609: __ flog10(); never@1609: __ ret(0); never@1609: } never@1609: { never@1609: StubCodeMark mark(this, "StubRoutines", "sin"); never@1609: StubRoutines::_intrinsic_sin = (double (*)(double)) __ pc(); never@1609: never@1609: __ fld_d(Address(rsp, 4)); never@1609: __ trigfunc('s'); never@1609: __ ret(0); never@1609: } never@1609: { never@1609: StubCodeMark mark(this, "StubRoutines", "cos"); never@1609: StubRoutines::_intrinsic_cos = (double (*)(double)) __ pc(); never@1609: never@1609: __ fld_d(Address(rsp, 4)); never@1609: __ trigfunc('c'); never@1609: __ ret(0); never@1609: } never@1609: { never@1609: StubCodeMark mark(this, "StubRoutines", "tan"); never@1609: StubRoutines::_intrinsic_tan = (double (*)(double)) __ pc(); never@1609: never@1609: __ fld_d(Address(rsp, 4)); never@1609: __ trigfunc('t'); never@1609: __ ret(0); never@1609: } roland@3787: { roland@3787: StubCodeMark mark(this, "StubRoutines", "exp"); roland@3787: StubRoutines::_intrinsic_exp = (double (*)(double)) __ pc(); never@1609: roland@3787: __ fld_d(Address(rsp, 4)); roland@3787: __ exp_with_fallback(0); roland@3787: __ ret(0); roland@3787: } roland@3787: { roland@3787: StubCodeMark mark(this, "StubRoutines", "pow"); roland@3787: StubRoutines::_intrinsic_pow = (double (*)(double,double)) __ pc(); roland@3787: roland@3787: __ fld_d(Address(rsp, 12)); roland@3787: __ fld_d(Address(rsp, 4)); roland@3787: __ pow_with_fallback(0); roland@3787: __ ret(0); roland@3787: } never@1609: } never@1609: duke@435: public: duke@435: // Information about frame layout at time of blocking runtime call. duke@435: // Note that we only have to preserve callee-saved registers since duke@435: // the compilers are responsible for supplying a continuation point duke@435: // if they expect all registers to be preserved. duke@435: enum layout { duke@435: thread_off, // last_java_sp never@2978: arg1_off, never@2978: arg2_off, duke@435: rbp_off, // callee saved register duke@435: ret_pc, duke@435: framesize duke@435: }; duke@435: duke@435: private: duke@435: duke@435: #undef __ duke@435: #define __ masm-> duke@435: duke@435: //------------------------------------------------------------------------------------------------------------------------ duke@435: // Continuation point for throwing of implicit exceptions that are not handled in duke@435: // the current activation. Fabricates an exception oop and initiates normal duke@435: // exception dispatching in this frame. duke@435: // duke@435: // Previously the compiler (c2) allowed for callee save registers on Java calls. duke@435: // This is no longer true after adapter frames were removed but could possibly duke@435: // be brought back in the future if the interpreter code was reworked and it duke@435: // was deemed worthwhile. The comment below was left to describe what must duke@435: // happen here if callee saves were resurrected. As it stands now this stub duke@435: // could actually be a vanilla BufferBlob and have now oopMap at all. duke@435: // Since it doesn't make much difference we've chosen to leave it the duke@435: // way it was in the callee save days and keep the comment. duke@435: duke@435: // If we need to preserve callee-saved values we need a callee-saved oop map and duke@435: // therefore have to make these stubs into RuntimeStubs rather than BufferBlobs. duke@435: // If the compiler needs all registers to be preserved between the fault duke@435: // point and the exception handler then it must assume responsibility for that in duke@435: // AbstractCompiler::continuation_for_implicit_null_exception or duke@435: // continuation_for_implicit_division_by_zero_exception. All other implicit duke@435: // exceptions (e.g., NullPointerException or AbstractMethodError on entry) are duke@435: // either at call sites or otherwise assume that stack unwinding will be initiated, duke@435: // so caller saved registers were assumed volatile in the compiler. duke@435: address generate_throw_exception(const char* name, address runtime_entry, never@3136: Register arg1 = noreg, Register arg2 = noreg) { duke@435: duke@435: int insts_size = 256; duke@435: int locs_size = 32; duke@435: duke@435: CodeBuffer code(name, insts_size, locs_size); duke@435: OopMapSet* oop_maps = new OopMapSet(); duke@435: MacroAssembler* masm = new MacroAssembler(&code); duke@435: duke@435: address start = __ pc(); duke@435: duke@435: // This is an inlined and slightly modified version of call_VM duke@435: // which has the ability to fetch the return PC out of duke@435: // thread-local storage and also sets up last_Java_sp slightly duke@435: // differently than the real call_VM duke@435: Register java_thread = rbx; duke@435: __ get_thread(java_thread); duke@435: duke@435: __ enter(); // required for proper stackwalking of RuntimeStub frame duke@435: duke@435: // pc and rbp, already pushed never@739: __ subptr(rsp, (framesize-2) * wordSize); // prolog duke@435: duke@435: // Frame is now completed as far as size and linkage. duke@435: duke@435: int frame_complete = __ pc() - start; duke@435: duke@435: // push java thread (becomes first argument of C function) never@739: __ movptr(Address(rsp, thread_off * wordSize), java_thread); never@2978: if (arg1 != noreg) { never@2978: __ movptr(Address(rsp, arg1_off * wordSize), arg1); never@2978: } never@2978: if (arg2 != noreg) { never@2978: assert(arg1 != noreg, "missing reg arg"); never@2978: __ movptr(Address(rsp, arg2_off * wordSize), arg2); never@2978: } duke@435: duke@435: // Set up last_Java_sp and last_Java_fp duke@435: __ set_last_Java_frame(java_thread, rsp, rbp, NULL); duke@435: duke@435: // Call runtime duke@435: BLOCK_COMMENT("call runtime_entry"); duke@435: __ call(RuntimeAddress(runtime_entry)); duke@435: // Generate oop map duke@435: OopMap* map = new OopMap(framesize, 0); duke@435: oop_maps->add_gc_map(__ pc() - start, map); duke@435: duke@435: // restore the thread (cannot use the pushed argument since arguments duke@435: // may be overwritten by C code generated by an optimizing compiler); duke@435: // however can use the register value directly if it is callee saved. duke@435: __ get_thread(java_thread); duke@435: duke@435: __ reset_last_Java_frame(java_thread, true, false); duke@435: duke@435: __ leave(); // required for proper stackwalking of RuntimeStub frame duke@435: duke@435: // check for pending exceptions duke@435: #ifdef ASSERT duke@435: Label L; never@739: __ cmpptr(Address(java_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD); duke@435: __ jcc(Assembler::notEqual, L); duke@435: __ should_not_reach_here(); duke@435: __ bind(L); duke@435: #endif /* ASSERT */ duke@435: __ jump(RuntimeAddress(StubRoutines::forward_exception_entry())); duke@435: duke@435: duke@435: RuntimeStub* stub = RuntimeStub::new_runtime_stub(name, &code, frame_complete, framesize, oop_maps, false); duke@435: return stub->entry_point(); duke@435: } duke@435: duke@435: duke@435: void create_control_words() { duke@435: // Round to nearest, 53-bit mode, exceptions masked duke@435: StubRoutines::_fpu_cntrl_wrd_std = 0x027F; duke@435: // Round to zero, 53-bit mode, exception mased duke@435: StubRoutines::_fpu_cntrl_wrd_trunc = 0x0D7F; duke@435: // Round to nearest, 24-bit mode, exceptions masked duke@435: StubRoutines::_fpu_cntrl_wrd_24 = 0x007F; duke@435: // Round to nearest, 64-bit mode, exceptions masked duke@435: StubRoutines::_fpu_cntrl_wrd_64 = 0x037F; duke@435: // Round to nearest, 64-bit mode, exceptions masked duke@435: StubRoutines::_mxcsr_std = 0x1F80; duke@435: // Note: the following two constants are 80-bit values duke@435: // layout is critical for correct loading by FPU. duke@435: // Bias for strict fp multiply/divide duke@435: StubRoutines::_fpu_subnormal_bias1[0]= 0x00000000; // 2^(-15360) == 0x03ff 8000 0000 0000 0000 duke@435: StubRoutines::_fpu_subnormal_bias1[1]= 0x80000000; duke@435: StubRoutines::_fpu_subnormal_bias1[2]= 0x03ff; duke@435: // Un-Bias for strict fp multiply/divide duke@435: StubRoutines::_fpu_subnormal_bias2[0]= 0x00000000; // 2^(+15360) == 0x7bff 8000 0000 0000 0000 duke@435: StubRoutines::_fpu_subnormal_bias2[1]= 0x80000000; duke@435: StubRoutines::_fpu_subnormal_bias2[2]= 0x7bff; duke@435: } duke@435: duke@435: //--------------------------------------------------------------------------- duke@435: // Initialization duke@435: duke@435: void generate_initial() { duke@435: // Generates all stubs and initializes the entry points duke@435: duke@435: //------------------------------------------------------------------------------------------------------------------------ duke@435: // entry points that exist in all platforms duke@435: // Note: This is code that could be shared among different platforms - however the benefit seems to be smaller than duke@435: // the disadvantage of having a much more complicated generator structure. See also comment in stubRoutines.hpp. duke@435: StubRoutines::_forward_exception_entry = generate_forward_exception(); duke@435: duke@435: StubRoutines::_call_stub_entry = duke@435: generate_call_stub(StubRoutines::_call_stub_return_address); duke@435: // is referenced by megamorphic call duke@435: StubRoutines::_catch_exception_entry = generate_catch_exception(); duke@435: duke@435: // These are currently used by Solaris/Intel duke@435: StubRoutines::_atomic_xchg_entry = generate_atomic_xchg(); duke@435: duke@435: StubRoutines::_handler_for_unsafe_access_entry = duke@435: generate_handler_for_unsafe_access(); duke@435: duke@435: // platform dependent duke@435: create_control_words(); duke@435: never@739: StubRoutines::x86::_verify_mxcsr_entry = generate_verify_mxcsr(); never@739: StubRoutines::x86::_verify_fpu_cntrl_wrd_entry = generate_verify_fpu_cntrl_wrd(); duke@435: StubRoutines::_d2i_wrapper = generate_d2i_wrapper(T_INT, duke@435: CAST_FROM_FN_PTR(address, SharedRuntime::d2i)); duke@435: StubRoutines::_d2l_wrapper = generate_d2i_wrapper(T_LONG, duke@435: CAST_FROM_FN_PTR(address, SharedRuntime::d2l)); never@2978: never@2978: // Build this early so it's available for the interpreter never@2978: StubRoutines::_throw_WrongMethodTypeException_entry = never@2978: generate_throw_exception("WrongMethodTypeException throw_exception", never@2978: CAST_FROM_FN_PTR(address, SharedRuntime::throw_WrongMethodTypeException), never@3136: rax, rcx); bdelsart@3372: bdelsart@3372: // Build this early so it's available for the interpreter bdelsart@3372: StubRoutines::_throw_StackOverflowError_entry = generate_throw_exception("StackOverflowError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_StackOverflowError)); duke@435: } duke@435: duke@435: duke@435: void generate_all() { duke@435: // Generates all stubs and initializes the entry points duke@435: duke@435: // These entry points require SharedInfo::stack0 to be set up in non-core builds duke@435: // and need to be relocatable, so they each fabricate a RuntimeStub internally. never@3136: StubRoutines::_throw_AbstractMethodError_entry = generate_throw_exception("AbstractMethodError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_AbstractMethodError)); never@3136: StubRoutines::_throw_IncompatibleClassChangeError_entry= generate_throw_exception("IncompatibleClassChangeError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_IncompatibleClassChangeError)); never@3136: StubRoutines::_throw_NullPointerException_at_call_entry= generate_throw_exception("NullPointerException at call throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_NullPointerException_at_call)); duke@435: duke@435: //------------------------------------------------------------------------------------------------------------------------ duke@435: // entry points that are platform specific duke@435: duke@435: // support for verify_oop (must happen after universe_init) duke@435: StubRoutines::_verify_oop_subroutine_entry = generate_verify_oop(); duke@435: duke@435: // arraycopy stubs used by compilers duke@435: generate_arraycopy_stubs(); jrose@1145: never@1609: generate_math_stubs(); duke@435: } duke@435: duke@435: duke@435: public: duke@435: StubGenerator(CodeBuffer* code, bool all) : StubCodeGenerator(code) { duke@435: if (all) { duke@435: generate_all(); duke@435: } else { duke@435: generate_initial(); duke@435: } duke@435: } duke@435: }; // end class declaration duke@435: duke@435: duke@435: void StubGenerator_generate(CodeBuffer* code, bool all) { duke@435: StubGenerator g(code, all); duke@435: }