duke@435: /* iveresov@2595: * Copyright (c) 1997, 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_sparc.inline.hpp" stefank@2314: #include "interpreter/interpreter.hpp" stefank@2314: #include "nativeInst_sparc.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 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-> 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: // Note: The register L7 is used as L7_thread_cache, and may not be used duke@435: // any other way within this module. duke@435: duke@435: duke@435: static const Register& Lstub_temp = L2; 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: address npc = thread->saved_exception_npc(); 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: 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(a,b,c) (0) duke@435: #else duke@435: #define inc_counter_np(counter, t1, t2) \ duke@435: BLOCK_COMMENT("inc_counter " #counter); \ twisti@1162: __ inc_counter(&counter, t1, t2); duke@435: #endif duke@435: duke@435: //---------------------------------------------------------------------------------------------------- duke@435: // Call stubs are used to call Java from C duke@435: duke@435: address generate_call_stub(address& return_pc) { duke@435: StubCodeMark mark(this, "StubRoutines", "call_stub"); duke@435: address start = __ pc(); duke@435: duke@435: // Incoming arguments: duke@435: // duke@435: // o0 : call wrapper address duke@435: // o1 : result (address) duke@435: // o2 : result type duke@435: // o3 : method duke@435: // o4 : (interpreter) entry point duke@435: // o5 : parameters (address) duke@435: // [sp + 0x5c]: parameter size (in words) duke@435: // [sp + 0x60]: thread duke@435: // duke@435: // +---------------+ <--- sp + 0 duke@435: // | | duke@435: // . reg save area . duke@435: // | | duke@435: // +---------------+ <--- sp + 0x40 duke@435: // | | duke@435: // . extra 7 slots . duke@435: // | | duke@435: // +---------------+ <--- sp + 0x5c duke@435: // | param. size | duke@435: // +---------------+ <--- sp + 0x60 duke@435: // | thread | duke@435: // +---------------+ duke@435: // | | duke@435: duke@435: // note: if the link argument position changes, adjust duke@435: // the code in frame::entry_frame_call_wrapper() duke@435: duke@435: const Argument link = Argument(0, false); // used only for GC duke@435: const Argument result = Argument(1, false); duke@435: const Argument result_type = Argument(2, false); duke@435: const Argument method = Argument(3, false); duke@435: const Argument entry_point = Argument(4, false); duke@435: const Argument parameters = Argument(5, false); duke@435: const Argument parameter_size = Argument(6, false); duke@435: const Argument thread = Argument(7, false); duke@435: duke@435: // setup thread register duke@435: __ ld_ptr(thread.as_address(), G2_thread); coleenp@548: __ reinit_heapbase(); duke@435: duke@435: #ifdef ASSERT duke@435: // make sure we have no pending exceptions duke@435: { const Register t = G3_scratch; duke@435: Label L; duke@435: __ ld_ptr(G2_thread, in_bytes(Thread::pending_exception_offset()), t); kvn@3037: __ br_null_short(t, Assembler::pt, L); duke@435: __ stop("StubRoutines::call_stub: entered with pending exception"); duke@435: __ bind(L); duke@435: } duke@435: #endif duke@435: duke@435: // create activation frame & allocate space for parameters duke@435: { const Register t = G3_scratch; duke@435: __ ld_ptr(parameter_size.as_address(), t); // get parameter size (in words) duke@435: __ add(t, frame::memory_parameter_word_sp_offset, t); // add space for save area (in words) duke@435: __ round_to(t, WordsPerLong); // make sure it is multiple of 2 (in words) twisti@1861: __ sll(t, Interpreter::logStackElementSize, t); // compute number of bytes duke@435: __ neg(t); // negate so it can be used with save duke@435: __ save(SP, t, SP); // setup new frame duke@435: } duke@435: duke@435: // +---------------+ <--- sp + 0 duke@435: // | | duke@435: // . reg save area . duke@435: // | | duke@435: // +---------------+ <--- sp + 0x40 duke@435: // | | duke@435: // . extra 7 slots . duke@435: // | | duke@435: // +---------------+ <--- sp + 0x5c duke@435: // | empty slot | (only if parameter size is even) duke@435: // +---------------+ duke@435: // | | duke@435: // . parameters . duke@435: // | | duke@435: // +---------------+ <--- fp + 0 duke@435: // | | duke@435: // . reg save area . duke@435: // | | duke@435: // +---------------+ <--- fp + 0x40 duke@435: // | | duke@435: // . extra 7 slots . duke@435: // | | duke@435: // +---------------+ <--- fp + 0x5c duke@435: // | param. size | duke@435: // +---------------+ <--- fp + 0x60 duke@435: // | thread | duke@435: // +---------------+ duke@435: // | | duke@435: duke@435: // pass parameters if any duke@435: BLOCK_COMMENT("pass parameters if any"); duke@435: { const Register src = parameters.as_in().as_register(); duke@435: const Register dst = Lentry_args; duke@435: const Register tmp = G3_scratch; duke@435: const Register cnt = G4_scratch; duke@435: duke@435: // test if any parameters & setup of Lentry_args duke@435: Label exit; duke@435: __ ld_ptr(parameter_size.as_in().as_address(), cnt); // parameter counter duke@435: __ add( FP, STACK_BIAS, dst ); kvn@3037: __ cmp_zero_and_br(Assembler::zero, cnt, exit); duke@435: __ delayed()->sub(dst, BytesPerWord, dst); // setup Lentry_args duke@435: duke@435: // copy parameters if any duke@435: Label loop; duke@435: __ BIND(loop); duke@435: // Store parameter value duke@435: __ ld_ptr(src, 0, tmp); duke@435: __ add(src, BytesPerWord, src); twisti@1861: __ st_ptr(tmp, dst, 0); duke@435: __ deccc(cnt); duke@435: __ br(Assembler::greater, false, Assembler::pt, loop); twisti@1861: __ delayed()->sub(dst, Interpreter::stackElementSize, dst); duke@435: duke@435: // done duke@435: __ BIND(exit); duke@435: } duke@435: duke@435: // setup parameters, method & call Java function duke@435: #ifdef ASSERT duke@435: // layout_activation_impl checks it's notion of saved SP against duke@435: // this register, so if this changes update it as well. duke@435: const Register saved_SP = Lscratch; duke@435: __ mov(SP, saved_SP); // keep track of SP before call duke@435: #endif duke@435: duke@435: // setup parameters duke@435: const Register t = G3_scratch; duke@435: __ ld_ptr(parameter_size.as_in().as_address(), t); // get parameter size (in words) twisti@1861: __ sll(t, Interpreter::logStackElementSize, t); // compute number of bytes duke@435: __ sub(FP, t, Gargs); // setup parameter pointer duke@435: #ifdef _LP64 duke@435: __ add( Gargs, STACK_BIAS, Gargs ); // Account for LP64 stack bias duke@435: #endif duke@435: __ mov(SP, O5_savedSP); duke@435: duke@435: duke@435: // do the call duke@435: // duke@435: // the following register must be setup: duke@435: // duke@435: // G2_thread duke@435: // G5_method duke@435: // Gargs duke@435: BLOCK_COMMENT("call Java function"); duke@435: __ jmpl(entry_point.as_in().as_register(), G0, O7); duke@435: __ delayed()->mov(method.as_in().as_register(), G5_method); // setup method duke@435: duke@435: BLOCK_COMMENT("call_stub_return_address:"); duke@435: return_pc = __ pc(); duke@435: duke@435: // The callee, if it wasn't interpreted, can return with SP changed so duke@435: // we can no longer assert of change of SP. duke@435: duke@435: // store result depending on type duke@435: // (everything that is not T_OBJECT, T_LONG, T_FLOAT, or T_DOUBLE duke@435: // is treated as T_INT) duke@435: { const Register addr = result .as_in().as_register(); duke@435: const Register type = result_type.as_in().as_register(); duke@435: Label is_long, is_float, is_double, is_object, exit; duke@435: __ cmp(type, T_OBJECT); __ br(Assembler::equal, false, Assembler::pn, is_object); duke@435: __ delayed()->cmp(type, T_FLOAT); __ br(Assembler::equal, false, Assembler::pn, is_float); duke@435: __ delayed()->cmp(type, T_DOUBLE); __ br(Assembler::equal, false, Assembler::pn, is_double); duke@435: __ delayed()->cmp(type, T_LONG); __ br(Assembler::equal, false, Assembler::pn, is_long); duke@435: __ delayed()->nop(); duke@435: duke@435: // store int result duke@435: __ st(O0, addr, G0); duke@435: duke@435: __ BIND(exit); duke@435: __ ret(); duke@435: __ delayed()->restore(); duke@435: duke@435: __ BIND(is_object); kvn@3037: __ ba(exit); duke@435: __ delayed()->st_ptr(O0, addr, G0); duke@435: duke@435: __ BIND(is_float); kvn@3037: __ ba(exit); duke@435: __ delayed()->stf(FloatRegisterImpl::S, F0, addr, G0); duke@435: duke@435: __ BIND(is_double); kvn@3037: __ ba(exit); duke@435: __ delayed()->stf(FloatRegisterImpl::D, F0, addr, G0); duke@435: duke@435: __ BIND(is_long); duke@435: #ifdef _LP64 kvn@3037: __ ba(exit); duke@435: __ delayed()->st_long(O0, addr, G0); // store entire long duke@435: #else duke@435: #if defined(COMPILER2) duke@435: // All return values are where we want them, except for Longs. C2 returns duke@435: // longs in G1 in the 32-bit build whereas the interpreter wants them in O0/O1. duke@435: // Since the interpreter will return longs in G1 and O0/O1 in the 32bit duke@435: // build we simply always use G1. duke@435: // Note: I tried to make c2 return longs in O0/O1 and G1 so we wouldn't have to duke@435: // do this here. Unfortunately if we did a rethrow we'd see an machepilog node duke@435: // first which would move g1 -> O0/O1 and destroy the exception we were throwing. duke@435: kvn@3037: __ ba(exit); duke@435: __ delayed()->stx(G1, addr, G0); // store entire long duke@435: #else duke@435: __ st(O1, addr, BytesPerInt); kvn@3037: __ ba(exit); duke@435: __ delayed()->st(O0, addr, G0); duke@435: #endif /* COMPILER2 */ duke@435: #endif /* _LP64 */ 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: // Oexception: exception oop duke@435: duke@435: address generate_catch_exception() { duke@435: StubCodeMark mark(this, "StubRoutines", "catch_exception"); duke@435: duke@435: address start = __ pc(); duke@435: // verify that thread corresponds duke@435: __ verify_thread(); duke@435: duke@435: const Register& temp_reg = Gtemp; twisti@1162: Address pending_exception_addr (G2_thread, Thread::pending_exception_offset()); twisti@1162: Address exception_file_offset_addr(G2_thread, Thread::exception_file_offset ()); twisti@1162: Address exception_line_offset_addr(G2_thread, Thread::exception_line_offset ()); duke@435: duke@435: // set pending exception duke@435: __ verify_oop(Oexception); duke@435: __ st_ptr(Oexception, pending_exception_addr); duke@435: __ set((intptr_t)__FILE__, temp_reg); duke@435: __ st_ptr(temp_reg, exception_file_offset_addr); duke@435: __ set((intptr_t)__LINE__, temp_reg); duke@435: __ st(temp_reg, exception_line_offset_addr); duke@435: duke@435: // complete return to VM duke@435: assert(StubRoutines::_call_stub_return_address != NULL, "must have been generated before"); duke@435: twisti@1162: AddressLiteral stub_ret(StubRoutines::_call_stub_return_address); twisti@1162: __ jump_to(stub_ret, temp_reg); duke@435: __ delayed()->nop(); 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 handler: O0 = exception duke@435: // O1 = throwing pc duke@435: duke@435: address generate_forward_exception() { duke@435: StubCodeMark mark(this, "StubRoutines", "forward_exception"); duke@435: address start = __ pc(); duke@435: duke@435: // Upon entry, O7 has the return address returning into Java duke@435: // (interpreted or compiled) code; i.e. the return address duke@435: // becomes the throwing pc. duke@435: duke@435: const Register& handler_reg = Gtemp; duke@435: twisti@1162: Address exception_addr(G2_thread, Thread::pending_exception_offset()); duke@435: duke@435: #ifdef ASSERT duke@435: // make sure that this code is only executed if there is a pending exception duke@435: { Label L; duke@435: __ ld_ptr(exception_addr, Gtemp); kvn@3037: __ br_notnull_short(Gtemp, Assembler::pt, 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 handler_reg duke@435: __ get_thread(); duke@435: __ ld_ptr(exception_addr, Oexception); duke@435: __ verify_oop(Oexception); duke@435: __ save_frame(0); // compensates for compiler weakness duke@435: __ add(O7->after_save(), frame::pc_return_offset, Lscratch); // save the issuing PC duke@435: BLOCK_COMMENT("call exception_handler_for_return_address"); twisti@1730: __ call_VM_leaf(L7_thread_cache, CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), G2_thread, Lscratch); duke@435: __ mov(O0, handler_reg); duke@435: __ restore(); // compensates for compiler weakness duke@435: duke@435: __ ld_ptr(exception_addr, Oexception); duke@435: __ add(O7, frame::pc_return_offset, Oissuing_pc); // save the issuing PC duke@435: duke@435: #ifdef ASSERT duke@435: // make sure exception is set duke@435: { Label L; kvn@3037: __ br_notnull_short(Oexception, Assembler::pt, L); duke@435: __ stop("StubRoutines::forward exception: no pending exception (2)"); duke@435: __ bind(L); duke@435: } duke@435: #endif duke@435: // jump to exception handler duke@435: __ jmp(handler_reg, 0); duke@435: // clear pending exception duke@435: __ delayed()->st_ptr(G0, exception_addr); duke@435: duke@435: return start; duke@435: } duke@435: 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. Only callee-saved registers are preserved duke@435: // (through the normal register window / RegisterMap handling). 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: duke@435: // Note that we generate only this stub into a RuntimeStub, because it needs to be duke@435: // properly traversed and ignored during GC, so we change the meaning of the "__" duke@435: // macro within this method. duke@435: #undef __ duke@435: #define __ masm-> duke@435: never@3136: address generate_throw_exception(const char* name, address runtime_entry, never@2978: Register arg1 = noreg, Register arg2 = noreg) { duke@435: #ifdef ASSERT duke@435: int insts_size = VerifyThread ? 1 * K : 600; duke@435: #else duke@435: int insts_size = VerifyThread ? 1 * K : 256; duke@435: #endif /* ASSERT */ duke@435: int locs_size = 32; duke@435: duke@435: CodeBuffer code(name, insts_size, locs_size); duke@435: MacroAssembler* masm = new MacroAssembler(&code); duke@435: duke@435: __ verify_thread(); 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 thread-local storage duke@435: __ assert_not_delayed(); duke@435: duke@435: // Note that we always push a frame because on the SPARC duke@435: // architecture, for all of our implicit exception kinds at call duke@435: // sites, the implicit exception is taken before the callee frame duke@435: // is pushed. duke@435: __ save_frame(0); duke@435: duke@435: int frame_complete = __ offset(); duke@435: duke@435: // Note that we always have a runtime stub frame on the top of stack by this point duke@435: Register last_java_sp = SP; duke@435: // 64-bit last_java_sp is biased! duke@435: __ set_last_Java_frame(last_java_sp, G0); duke@435: if (VerifyThread) __ mov(G2_thread, O0); // about to be smashed; pass early duke@435: __ save_thread(noreg); never@2978: if (arg1 != noreg) { never@2978: assert(arg2 != O1, "clobbered"); never@2978: __ mov(arg1, O1); never@2978: } never@2978: if (arg2 != noreg) { never@2978: __ mov(arg2, O2); never@2978: } duke@435: // do the call duke@435: BLOCK_COMMENT("call runtime_entry"); duke@435: __ call(runtime_entry, relocInfo::runtime_call_type); duke@435: if (!VerifyThread) duke@435: __ delayed()->mov(G2_thread, O0); // pass thread as first argument duke@435: else duke@435: __ delayed()->nop(); // (thread already passed) duke@435: __ restore_thread(noreg); duke@435: __ reset_last_Java_frame(); duke@435: duke@435: // check for pending exceptions. use Gtemp as scratch register. duke@435: #ifdef ASSERT duke@435: Label L; duke@435: twisti@1162: Address exception_addr(G2_thread, Thread::pending_exception_offset()); duke@435: Register scratch_reg = Gtemp; duke@435: __ ld_ptr(exception_addr, scratch_reg); kvn@3037: __ br_notnull_short(scratch_reg, Assembler::pt, L); duke@435: __ should_not_reach_here(); duke@435: __ bind(L); duke@435: #endif // ASSERT duke@435: BLOCK_COMMENT("call forward_exception_entry"); duke@435: __ call(StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type); duke@435: // we use O7 linkage so that forward_exception_entry has the issuing PC duke@435: __ delayed()->restore(); duke@435: duke@435: RuntimeStub* stub = RuntimeStub::new_runtime_stub(name, &code, frame_complete, masm->total_frame_size_in_bytes(0), NULL, false); duke@435: return stub->entry_point(); duke@435: } duke@435: duke@435: #undef __ duke@435: #define __ _masm-> duke@435: duke@435: duke@435: // Generate a routine that sets all the registers so we duke@435: // can tell if the stop routine prints them correctly. duke@435: address generate_test_stop() { duke@435: StubCodeMark mark(this, "StubRoutines", "test_stop"); duke@435: address start = __ pc(); duke@435: duke@435: int i; duke@435: duke@435: __ save_frame(0); duke@435: duke@435: static jfloat zero = 0.0, one = 1.0; duke@435: duke@435: // put addr in L0, then load through L0 to F0 duke@435: __ set((intptr_t)&zero, L0); __ ldf( FloatRegisterImpl::S, L0, 0, F0); duke@435: __ set((intptr_t)&one, L0); __ ldf( FloatRegisterImpl::S, L0, 0, F1); // 1.0 to F1 duke@435: duke@435: // use add to put 2..18 in F2..F18 duke@435: for ( i = 2; i <= 18; ++i ) { duke@435: __ fadd( FloatRegisterImpl::S, F1, as_FloatRegister(i-1), as_FloatRegister(i)); duke@435: } duke@435: duke@435: // Now put double 2 in F16, double 18 in F18 duke@435: __ ftof( FloatRegisterImpl::S, FloatRegisterImpl::D, F2, F16 ); duke@435: __ ftof( FloatRegisterImpl::S, FloatRegisterImpl::D, F18, F18 ); duke@435: duke@435: // use add to put 20..32 in F20..F32 duke@435: for (i = 20; i < 32; i += 2) { duke@435: __ fadd( FloatRegisterImpl::D, F16, as_FloatRegister(i-2), as_FloatRegister(i)); duke@435: } duke@435: duke@435: // put 0..7 in i's, 8..15 in l's, 16..23 in o's, 24..31 in g's duke@435: for ( i = 0; i < 8; ++i ) { duke@435: if (i < 6) { duke@435: __ set( i, as_iRegister(i)); duke@435: __ set(16 + i, as_oRegister(i)); duke@435: __ set(24 + i, as_gRegister(i)); duke@435: } duke@435: __ set( 8 + i, as_lRegister(i)); duke@435: } duke@435: duke@435: __ stop("testing stop"); duke@435: duke@435: duke@435: __ ret(); duke@435: __ delayed()->restore(); duke@435: duke@435: return start; duke@435: } duke@435: duke@435: duke@435: address generate_stop_subroutine() { duke@435: StubCodeMark mark(this, "StubRoutines", "stop_subroutine"); duke@435: address start = __ pc(); duke@435: duke@435: __ stop_subroutine(); duke@435: duke@435: return start; duke@435: } duke@435: duke@435: address generate_flush_callers_register_windows() { duke@435: StubCodeMark mark(this, "StubRoutines", "flush_callers_register_windows"); duke@435: address start = __ pc(); duke@435: duke@435: __ flush_windows(); duke@435: __ retl(false); duke@435: __ delayed()->add( FP, STACK_BIAS, O0 ); duke@435: // The returned value must be a stack pointer whose register save area duke@435: // is flushed, and will stay flushed while the caller executes. duke@435: duke@435: return start; duke@435: } duke@435: duke@435: // Helper functions for v8 atomic operations. duke@435: // duke@435: void get_v8_oop_lock_ptr(Register lock_ptr_reg, Register mark_oop_reg, Register scratch_reg) { duke@435: if (mark_oop_reg == noreg) { duke@435: address lock_ptr = (address)StubRoutines::Sparc::atomic_memory_operation_lock_addr(); duke@435: __ set((intptr_t)lock_ptr, lock_ptr_reg); duke@435: } else { duke@435: assert(scratch_reg != noreg, "just checking"); duke@435: address lock_ptr = (address)StubRoutines::Sparc::_v8_oop_lock_cache; duke@435: __ set((intptr_t)lock_ptr, lock_ptr_reg); duke@435: __ and3(mark_oop_reg, StubRoutines::Sparc::v8_oop_lock_mask_in_place, scratch_reg); duke@435: __ add(lock_ptr_reg, scratch_reg, lock_ptr_reg); duke@435: } duke@435: } duke@435: duke@435: void generate_v8_lock_prologue(Register lock_reg, Register lock_ptr_reg, Register yield_reg, Label& retry, Label& dontyield, Register mark_oop_reg = noreg, Register scratch_reg = noreg) { duke@435: duke@435: get_v8_oop_lock_ptr(lock_ptr_reg, mark_oop_reg, scratch_reg); duke@435: __ set(StubRoutines::Sparc::locked, lock_reg); duke@435: // Initialize yield counter duke@435: __ mov(G0,yield_reg); duke@435: duke@435: __ BIND(retry); kvn@3037: __ cmp_and_br_short(yield_reg, V8AtomicOperationUnderLockSpinCount, Assembler::less, Assembler::pt, dontyield); duke@435: duke@435: // This code can only be called from inside the VM, this duke@435: // stub is only invoked from Atomic::add(). We do not duke@435: // want to use call_VM, because _last_java_sp and such duke@435: // must already be set. duke@435: // duke@435: // Save the regs and make space for a C call duke@435: __ save(SP, -96, SP); duke@435: __ save_all_globals_into_locals(); duke@435: BLOCK_COMMENT("call os::naked_sleep"); duke@435: __ call(CAST_FROM_FN_PTR(address, os::naked_sleep)); duke@435: __ delayed()->nop(); duke@435: __ restore_globals_from_locals(); duke@435: __ restore(); duke@435: // reset the counter duke@435: __ mov(G0,yield_reg); duke@435: duke@435: __ BIND(dontyield); duke@435: duke@435: // try to get lock duke@435: __ swap(lock_ptr_reg, 0, lock_reg); duke@435: duke@435: // did we get the lock? duke@435: __ cmp(lock_reg, StubRoutines::Sparc::unlocked); duke@435: __ br(Assembler::notEqual, true, Assembler::pn, retry); duke@435: __ delayed()->add(yield_reg,1,yield_reg); duke@435: duke@435: // yes, got lock. do the operation here. duke@435: } duke@435: duke@435: void generate_v8_lock_epilogue(Register lock_reg, Register lock_ptr_reg, Register yield_reg, Label& retry, Label& dontyield, Register mark_oop_reg = noreg, Register scratch_reg = noreg) { duke@435: __ st(lock_reg, lock_ptr_reg, 0); // unlock duke@435: } duke@435: duke@435: // Support for jint Atomic::xchg(jint exchange_value, volatile jint* dest). duke@435: // duke@435: // Arguments : duke@435: // duke@435: // exchange_value: O0 duke@435: // dest: O1 duke@435: // duke@435: // Results: duke@435: // duke@435: // O0: the value previously stored in dest duke@435: // duke@435: address generate_atomic_xchg() { duke@435: StubCodeMark mark(this, "StubRoutines", "atomic_xchg"); duke@435: address start = __ pc(); duke@435: duke@435: if (UseCASForSwap) { duke@435: // Use CAS instead of swap, just in case the MP hardware duke@435: // prefers to work with just one kind of synch. instruction. duke@435: Label retry; duke@435: __ BIND(retry); duke@435: __ mov(O0, O3); // scratch copy of exchange value duke@435: __ ld(O1, 0, O2); // observe the previous value duke@435: // try to replace O2 with O3 duke@435: __ cas_under_lock(O1, O2, O3, duke@435: (address)StubRoutines::Sparc::atomic_memory_operation_lock_addr(),false); kvn@3037: __ cmp_and_br_short(O2, O3, Assembler::notEqual, Assembler::pn, retry); duke@435: duke@435: __ retl(false); duke@435: __ delayed()->mov(O2, O0); // report previous value to caller duke@435: duke@435: } else { duke@435: if (VM_Version::v9_instructions_work()) { duke@435: __ retl(false); duke@435: __ delayed()->swap(O1, 0, O0); duke@435: } else { duke@435: const Register& lock_reg = O2; duke@435: const Register& lock_ptr_reg = O3; duke@435: const Register& yield_reg = O4; duke@435: duke@435: Label retry; duke@435: Label dontyield; duke@435: duke@435: generate_v8_lock_prologue(lock_reg, lock_ptr_reg, yield_reg, retry, dontyield); duke@435: // got the lock, do the swap duke@435: __ swap(O1, 0, O0); duke@435: duke@435: generate_v8_lock_epilogue(lock_reg, lock_ptr_reg, yield_reg, retry, dontyield); duke@435: __ retl(false); duke@435: __ delayed()->nop(); duke@435: } duke@435: } duke@435: duke@435: return start; duke@435: } duke@435: duke@435: duke@435: // Support for jint Atomic::cmpxchg(jint exchange_value, volatile jint* dest, jint compare_value) duke@435: // duke@435: // Arguments : duke@435: // duke@435: // exchange_value: O0 duke@435: // dest: O1 duke@435: // compare_value: O2 duke@435: // duke@435: // Results: duke@435: // duke@435: // O0: the value previously stored in dest duke@435: // duke@435: // Overwrites (v8): O3,O4,O5 duke@435: // duke@435: address generate_atomic_cmpxchg() { duke@435: StubCodeMark mark(this, "StubRoutines", "atomic_cmpxchg"); duke@435: address start = __ pc(); duke@435: duke@435: // cmpxchg(dest, compare_value, exchange_value) duke@435: __ cas_under_lock(O1, O2, O0, duke@435: (address)StubRoutines::Sparc::atomic_memory_operation_lock_addr(),false); duke@435: __ retl(false); duke@435: __ delayed()->nop(); duke@435: duke@435: return start; duke@435: } duke@435: duke@435: // Support for jlong Atomic::cmpxchg(jlong exchange_value, volatile jlong *dest, jlong compare_value) duke@435: // duke@435: // Arguments : duke@435: // duke@435: // exchange_value: O1:O0 duke@435: // dest: O2 duke@435: // compare_value: O4:O3 duke@435: // duke@435: // Results: duke@435: // duke@435: // O1:O0: the value previously stored in dest duke@435: // duke@435: // This only works on V9, on V8 we don't generate any duke@435: // code and just return NULL. duke@435: // duke@435: // Overwrites: G1,G2,G3 duke@435: // duke@435: address generate_atomic_cmpxchg_long() { duke@435: StubCodeMark mark(this, "StubRoutines", "atomic_cmpxchg_long"); duke@435: address start = __ pc(); duke@435: duke@435: if (!VM_Version::supports_cx8()) duke@435: return NULL;; duke@435: __ sllx(O0, 32, O0); duke@435: __ srl(O1, 0, O1); duke@435: __ or3(O0,O1,O0); // O0 holds 64-bit value from compare_value duke@435: __ sllx(O3, 32, O3); duke@435: __ srl(O4, 0, O4); duke@435: __ or3(O3,O4,O3); // O3 holds 64-bit value from exchange_value duke@435: __ casx(O2, O3, O0); duke@435: __ srl(O0, 0, O1); // unpacked return value in O1:O0 duke@435: __ retl(false); duke@435: __ delayed()->srlx(O0, 32, O0); duke@435: duke@435: return start; duke@435: } duke@435: duke@435: duke@435: // Support for jint Atomic::add(jint add_value, volatile jint* dest). duke@435: // duke@435: // Arguments : duke@435: // duke@435: // add_value: O0 (e.g., +1 or -1) duke@435: // dest: O1 duke@435: // duke@435: // Results: duke@435: // duke@435: // O0: the new value stored in dest duke@435: // duke@435: // Overwrites (v9): O3 duke@435: // Overwrites (v8): O3,O4,O5 duke@435: // duke@435: address generate_atomic_add() { duke@435: StubCodeMark mark(this, "StubRoutines", "atomic_add"); duke@435: address start = __ pc(); duke@435: __ BIND(_atomic_add_stub); duke@435: duke@435: if (VM_Version::v9_instructions_work()) { duke@435: Label(retry); duke@435: __ BIND(retry); duke@435: duke@435: __ lduw(O1, 0, O2); kvn@3037: __ add(O0, O2, O3); kvn@3037: __ cas(O1, O2, O3); kvn@3037: __ cmp_and_br_short(O2, O3, Assembler::notEqual, Assembler::pn, retry); duke@435: __ retl(false); duke@435: __ delayed()->add(O0, O2, O0); // note that cas made O2==O3 duke@435: } else { duke@435: const Register& lock_reg = O2; duke@435: const Register& lock_ptr_reg = O3; duke@435: const Register& value_reg = O4; duke@435: const Register& yield_reg = O5; duke@435: duke@435: Label(retry); duke@435: Label(dontyield); duke@435: duke@435: generate_v8_lock_prologue(lock_reg, lock_ptr_reg, yield_reg, retry, dontyield); duke@435: // got lock, do the increment duke@435: __ ld(O1, 0, value_reg); duke@435: __ add(O0, value_reg, value_reg); duke@435: __ st(value_reg, O1, 0); duke@435: duke@435: // %%% only for RMO and PSO duke@435: __ membar(Assembler::StoreStore); duke@435: duke@435: generate_v8_lock_epilogue(lock_reg, lock_ptr_reg, yield_reg, retry, dontyield); duke@435: duke@435: __ retl(false); duke@435: __ delayed()->mov(value_reg, O0); duke@435: } duke@435: duke@435: return start; duke@435: } duke@435: Label _atomic_add_stub; // called from other stubs 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: // duke@435: // Arguments : duke@435: // duke@435: // trapping PC: O7 duke@435: // duke@435: // Results: duke@435: // posts an asynchronous exception, skips the trapping instruction duke@435: // duke@435: 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: duke@435: const int preserve_register_words = (64 * 2); twisti@1162: Address preserve_addr(FP, (-preserve_register_words * wordSize) + STACK_BIAS); duke@435: duke@435: Register Lthread = L7_thread_cache; duke@435: int i; duke@435: duke@435: __ save_frame(0); duke@435: __ mov(G1, L1); duke@435: __ mov(G2, L2); duke@435: __ mov(G3, L3); duke@435: __ mov(G4, L4); duke@435: __ mov(G5, L5); duke@435: for (i = 0; i < (VM_Version::v9_instructions_work() ? 64 : 32); i += 2) { duke@435: __ stf(FloatRegisterImpl::D, as_FloatRegister(i), preserve_addr, i * wordSize); duke@435: } duke@435: duke@435: address entry_point = CAST_FROM_FN_PTR(address, handle_unsafe_access); duke@435: BLOCK_COMMENT("call handle_unsafe_access"); duke@435: __ call(entry_point, relocInfo::runtime_call_type); duke@435: __ delayed()->nop(); duke@435: duke@435: __ mov(L1, G1); duke@435: __ mov(L2, G2); duke@435: __ mov(L3, G3); duke@435: __ mov(L4, G4); duke@435: __ mov(L5, G5); duke@435: for (i = 0; i < (VM_Version::v9_instructions_work() ? 64 : 32); i += 2) { duke@435: __ ldf(FloatRegisterImpl::D, preserve_addr, as_FloatRegister(i), i * wordSize); duke@435: } duke@435: duke@435: __ verify_thread(); duke@435: duke@435: __ jmp(O0, 0); duke@435: __ delayed()->restore(); duke@435: duke@435: return start; duke@435: } duke@435: duke@435: duke@435: // Support for uint StubRoutine::Sparc::partial_subtype_check( Klass sub, Klass super ); duke@435: // Arguments : duke@435: // duke@435: // ret : O0, returned duke@435: // icc/xcc: set as O0 (depending on wordSize) duke@435: // sub : O1, argument, not changed duke@435: // super: O2, argument, not changed duke@435: // raddr: O7, blown by call duke@435: address generate_partial_subtype_check() { coleenp@548: __ align(CodeEntryAlignment); duke@435: StubCodeMark mark(this, "StubRoutines", "partial_subtype_check"); duke@435: address start = __ pc(); jrose@1079: Label miss; duke@435: duke@435: #if defined(COMPILER2) && !defined(_LP64) duke@435: // Do not use a 'save' because it blows the 64-bit O registers. coleenp@548: __ add(SP,-4*wordSize,SP); // Make space for 4 temps (stack must be 2 words aligned) duke@435: __ st_ptr(L0,SP,(frame::register_save_words+0)*wordSize); duke@435: __ st_ptr(L1,SP,(frame::register_save_words+1)*wordSize); duke@435: __ st_ptr(L2,SP,(frame::register_save_words+2)*wordSize); duke@435: __ st_ptr(L3,SP,(frame::register_save_words+3)*wordSize); duke@435: Register Rret = O0; duke@435: Register Rsub = O1; duke@435: Register Rsuper = O2; duke@435: #else duke@435: __ save_frame(0); duke@435: Register Rret = I0; duke@435: Register Rsub = I1; duke@435: Register Rsuper = I2; duke@435: #endif duke@435: duke@435: Register L0_ary_len = L0; duke@435: Register L1_ary_ptr = L1; duke@435: Register L2_super = L2; duke@435: Register L3_index = L3; duke@435: jrose@1079: __ check_klass_subtype_slow_path(Rsub, Rsuper, jrose@1079: L0, L1, L2, L3, jrose@1079: NULL, &miss); jrose@1079: jrose@1079: // Match falls through here. jrose@1079: __ addcc(G0,0,Rret); // set Z flags, Z result duke@435: duke@435: #if defined(COMPILER2) && !defined(_LP64) duke@435: __ ld_ptr(SP,(frame::register_save_words+0)*wordSize,L0); duke@435: __ ld_ptr(SP,(frame::register_save_words+1)*wordSize,L1); duke@435: __ ld_ptr(SP,(frame::register_save_words+2)*wordSize,L2); duke@435: __ ld_ptr(SP,(frame::register_save_words+3)*wordSize,L3); duke@435: __ retl(); // Result in Rret is zero; flags set to Z duke@435: __ delayed()->add(SP,4*wordSize,SP); duke@435: #else duke@435: __ ret(); // Result in Rret is zero; flags set to Z duke@435: __ delayed()->restore(); duke@435: #endif duke@435: duke@435: __ BIND(miss); duke@435: __ addcc(G0,1,Rret); // set NZ flags, NZ result duke@435: duke@435: #if defined(COMPILER2) && !defined(_LP64) duke@435: __ ld_ptr(SP,(frame::register_save_words+0)*wordSize,L0); duke@435: __ ld_ptr(SP,(frame::register_save_words+1)*wordSize,L1); duke@435: __ ld_ptr(SP,(frame::register_save_words+2)*wordSize,L2); duke@435: __ ld_ptr(SP,(frame::register_save_words+3)*wordSize,L3); duke@435: __ retl(); // Result in Rret is != 0; flags set to NZ duke@435: __ delayed()->add(SP,4*wordSize,SP); duke@435: #else duke@435: __ ret(); // Result in Rret is != 0; flags set to NZ duke@435: __ delayed()->restore(); duke@435: #endif duke@435: duke@435: return start; duke@435: } duke@435: duke@435: duke@435: // Called from MacroAssembler::verify_oop duke@435: // duke@435: address generate_verify_oop_subroutine() { duke@435: StubCodeMark mark(this, "StubRoutines", "verify_oop_stub"); duke@435: duke@435: address start = __ pc(); duke@435: duke@435: __ verify_oop_subroutine(); duke@435: duke@435: return start; duke@435: } duke@435: duke@435: duke@435: // duke@435: // Verify that a register contains clean 32-bits positive value duke@435: // (high 32-bits are 0) so it could be used in 64-bits shifts (sllx, srax). duke@435: // duke@435: // Input: duke@435: // Rint - 32-bits value duke@435: // Rtmp - scratch duke@435: // duke@435: void assert_clean_int(Register Rint, Register Rtmp) { duke@435: #if defined(ASSERT) && defined(_LP64) duke@435: __ signx(Rint, Rtmp); duke@435: __ cmp(Rint, Rtmp); duke@435: __ breakpoint_trap(Assembler::notEqual, Assembler::xcc); duke@435: #endif duke@435: } duke@435: duke@435: // duke@435: // Generate overlap test for array copy stubs duke@435: // duke@435: // Input: duke@435: // O0 - array1 duke@435: // O1 - array2 duke@435: // O2 - element count duke@435: // duke@435: // Kills temps: O3, O4 duke@435: // duke@435: void array_overlap_test(address no_overlap_target, int log2_elem_size) { duke@435: assert(no_overlap_target != NULL, "must be generated"); duke@435: array_overlap_test(no_overlap_target, NULL, log2_elem_size); duke@435: } duke@435: void array_overlap_test(Label& L_no_overlap, int log2_elem_size) { duke@435: array_overlap_test(NULL, &L_no_overlap, log2_elem_size); duke@435: } duke@435: void array_overlap_test(address no_overlap_target, Label* NOLp, int log2_elem_size) { duke@435: const Register from = O0; duke@435: const Register to = O1; duke@435: const Register count = O2; duke@435: const Register to_from = O3; // to - from duke@435: const Register byte_count = O4; // count << log2_elem_size duke@435: duke@435: __ subcc(to, from, to_from); duke@435: __ sll_ptr(count, log2_elem_size, byte_count); duke@435: if (NOLp == NULL) duke@435: __ brx(Assembler::lessEqualUnsigned, false, Assembler::pt, no_overlap_target); duke@435: else duke@435: __ brx(Assembler::lessEqualUnsigned, false, Assembler::pt, (*NOLp)); duke@435: __ delayed()->cmp(to_from, byte_count); duke@435: if (NOLp == NULL) tonyp@2010: __ brx(Assembler::greaterEqualUnsigned, false, Assembler::pt, no_overlap_target); duke@435: else tonyp@2010: __ brx(Assembler::greaterEqualUnsigned, false, Assembler::pt, (*NOLp)); duke@435: __ delayed()->nop(); duke@435: } duke@435: duke@435: // duke@435: // Generate pre-write barrier for array. duke@435: // duke@435: // Input: duke@435: // addr - register containing starting address duke@435: // count - register containing element count duke@435: // tmp - scratch register duke@435: // duke@435: // The input registers are overwritten. duke@435: // iveresov@2606: void gen_write_ref_array_pre_barrier(Register addr, Register count, bool dest_uninitialized) { duke@435: BarrierSet* bs = Universe::heap()->barrier_set(); iveresov@2606: switch (bs->kind()) { iveresov@2606: case BarrierSet::G1SATBCT: iveresov@2606: case BarrierSet::G1SATBCTLogging: iveresov@2606: // With G1, don't generate the call if we statically know that the target in uninitialized iveresov@2606: if (!dest_uninitialized) { iveresov@2606: __ save_frame(0); iveresov@2606: // Save the necessary global regs... will be used after. iveresov@2606: if (addr->is_global()) { iveresov@2606: __ mov(addr, L0); iveresov@2606: } iveresov@2606: if (count->is_global()) { iveresov@2606: __ mov(count, L1); iveresov@2606: } iveresov@2606: __ mov(addr->after_save(), O0); iveresov@2606: // Get the count into O1 iveresov@2606: __ call(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_pre)); iveresov@2606: __ delayed()->mov(count->after_save(), O1); iveresov@2606: if (addr->is_global()) { iveresov@2606: __ mov(L0, addr); iveresov@2606: } iveresov@2606: if (count->is_global()) { iveresov@2606: __ mov(L1, count); iveresov@2606: } iveresov@2606: __ restore(); iveresov@2606: } iveresov@2606: break; iveresov@2606: case BarrierSet::CardTableModRef: iveresov@2606: case BarrierSet::CardTableExtension: iveresov@2606: case BarrierSet::ModRef: iveresov@2606: break; iveresov@2606: default: iveresov@2606: ShouldNotReachHere(); duke@435: } duke@435: } duke@435: // duke@435: // Generate post-write barrier for array. duke@435: // duke@435: // Input: duke@435: // addr - register containing starting address duke@435: // count - register containing element count duke@435: // tmp - scratch register duke@435: // duke@435: // The input registers are overwritten. duke@435: // duke@435: void gen_write_ref_array_post_barrier(Register addr, Register count, iveresov@2606: Register tmp) { duke@435: BarrierSet* bs = Universe::heap()->barrier_set(); duke@435: duke@435: switch (bs->kind()) { duke@435: case BarrierSet::G1SATBCT: duke@435: case BarrierSet::G1SATBCTLogging: duke@435: { duke@435: // Get some new fresh output registers. duke@435: __ save_frame(0); ysr@777: __ mov(addr->after_save(), O0); duke@435: __ call(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_post)); ysr@777: __ delayed()->mov(count->after_save(), O1); duke@435: __ restore(); duke@435: } duke@435: break; 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: assert_different_registers(addr, count, tmp); duke@435: duke@435: Label L_loop; duke@435: coleenp@548: __ sll_ptr(count, LogBytesPerHeapOop, count); coleenp@548: __ sub(count, BytesPerHeapOop, count); duke@435: __ add(count, addr, count); duke@435: // Use two shifts to clear out those low order two bits! (Cannot opt. into 1.) duke@435: __ srl_ptr(addr, CardTableModRefBS::card_shift, addr); duke@435: __ srl_ptr(count, CardTableModRefBS::card_shift, count); duke@435: __ sub(count, addr, count); twisti@1162: AddressLiteral rs(ct->byte_map_base); twisti@1162: __ set(rs, tmp); duke@435: __ BIND(L_loop); twisti@1162: __ stb(G0, tmp, addr); duke@435: __ subcc(count, 1, count); duke@435: __ brx(Assembler::greaterEqual, false, Assembler::pt, L_loop); duke@435: __ delayed()->add(addr, 1, addr); twisti@1162: } duke@435: break; duke@435: case BarrierSet::ModRef: duke@435: break; twisti@1162: default: duke@435: ShouldNotReachHere(); duke@435: } duke@435: } duke@435: kvn@3103: // kvn@3103: // Generate main code for disjoint arraycopy kvn@3103: // kvn@3103: typedef void (StubGenerator::*CopyLoopFunc)(Register from, Register to, Register count, int count_dec, kvn@3103: Label& L_loop, bool use_prefetch, bool use_bis); kvn@3103: kvn@3103: void disjoint_copy_core(Register from, Register to, Register count, int log2_elem_size, kvn@3103: int iter_size, CopyLoopFunc copy_loop_func) { kvn@3103: Label L_copy; kvn@3103: kvn@3103: assert(log2_elem_size <= 3, "the following code should be changed"); kvn@3103: int count_dec = 16>>log2_elem_size; kvn@3103: kvn@3103: int prefetch_dist = MAX2(ArraycopySrcPrefetchDistance, ArraycopyDstPrefetchDistance); kvn@3103: assert(prefetch_dist < 4096, "invalid value"); kvn@3103: prefetch_dist = (prefetch_dist + (iter_size-1)) & (-iter_size); // round up to one iteration copy size kvn@3103: int prefetch_count = (prefetch_dist >> log2_elem_size); // elements count kvn@3103: kvn@3103: if (UseBlockCopy) { kvn@3103: Label L_block_copy, L_block_copy_prefetch, L_skip_block_copy; kvn@3103: kvn@3103: // 64 bytes tail + bytes copied in one loop iteration kvn@3103: int tail_size = 64 + iter_size; kvn@3103: int block_copy_count = (MAX2(tail_size, (int)BlockCopyLowLimit)) >> log2_elem_size; kvn@3103: // Use BIS copy only for big arrays since it requires membar. kvn@3103: __ set(block_copy_count, O4); kvn@3103: __ cmp_and_br_short(count, O4, Assembler::lessUnsigned, Assembler::pt, L_skip_block_copy); kvn@3103: // This code is for disjoint source and destination: kvn@3103: // to <= from || to >= from+count kvn@3103: // but BIS will stomp over 'from' if (to > from-tail_size && to <= from) kvn@3103: __ sub(from, to, O4); kvn@3103: __ srax(O4, 4, O4); // divide by 16 since following short branch have only 5 bits for imm. kvn@3103: __ cmp_and_br_short(O4, (tail_size>>4), Assembler::lessEqualUnsigned, Assembler::pn, L_skip_block_copy); kvn@3103: kvn@3103: __ wrasi(G0, Assembler::ASI_ST_BLKINIT_PRIMARY); kvn@3103: // BIS should not be used to copy tail (64 bytes+iter_size) kvn@3103: // to avoid zeroing of following values. kvn@3103: __ sub(count, (tail_size>>log2_elem_size), count); // count is still positive >= 0 kvn@3103: kvn@3103: if (prefetch_count > 0) { // rounded up to one iteration count kvn@3103: // Do prefetching only if copy size is bigger kvn@3103: // than prefetch distance. kvn@3103: __ set(prefetch_count, O4); kvn@3103: __ cmp_and_brx_short(count, O4, Assembler::less, Assembler::pt, L_block_copy); kvn@3103: __ sub(count, prefetch_count, count); kvn@3103: kvn@3103: (this->*copy_loop_func)(from, to, count, count_dec, L_block_copy_prefetch, true, true); kvn@3103: __ add(count, prefetch_count, count); // restore count kvn@3103: kvn@3103: } // prefetch_count > 0 kvn@3103: kvn@3103: (this->*copy_loop_func)(from, to, count, count_dec, L_block_copy, false, true); kvn@3103: __ add(count, (tail_size>>log2_elem_size), count); // restore count kvn@3103: kvn@3103: __ wrasi(G0, Assembler::ASI_PRIMARY_NOFAULT); kvn@3103: // BIS needs membar. kvn@3103: __ membar(Assembler::StoreLoad); kvn@3103: // Copy tail kvn@3103: __ ba_short(L_copy); kvn@3103: kvn@3103: __ BIND(L_skip_block_copy); kvn@3103: } // UseBlockCopy kvn@3103: kvn@3103: if (prefetch_count > 0) { // rounded up to one iteration count kvn@3103: // Do prefetching only if copy size is bigger kvn@3103: // than prefetch distance. kvn@3103: __ set(prefetch_count, O4); kvn@3103: __ cmp_and_brx_short(count, O4, Assembler::lessUnsigned, Assembler::pt, L_copy); kvn@3103: __ sub(count, prefetch_count, count); kvn@3103: kvn@3103: Label L_copy_prefetch; kvn@3103: (this->*copy_loop_func)(from, to, count, count_dec, L_copy_prefetch, true, false); kvn@3103: __ add(count, prefetch_count, count); // restore count kvn@3103: kvn@3103: } // prefetch_count > 0 kvn@3103: kvn@3103: (this->*copy_loop_func)(from, to, count, count_dec, L_copy, false, false); kvn@3103: } kvn@3103: kvn@3103: kvn@3103: kvn@3103: // kvn@3103: // Helper methods for copy_16_bytes_forward_with_shift() kvn@3103: // kvn@3103: void copy_16_bytes_shift_loop(Register from, Register to, Register count, int count_dec, kvn@3103: Label& L_loop, bool use_prefetch, bool use_bis) { kvn@3103: kvn@3103: const Register left_shift = G1; // left shift bit counter kvn@3103: const Register right_shift = G5; // right shift bit counter kvn@3103: kvn@3103: __ align(OptoLoopAlignment); kvn@3103: __ BIND(L_loop); kvn@3103: if (use_prefetch) { kvn@3103: if (ArraycopySrcPrefetchDistance > 0) { kvn@3103: __ prefetch(from, ArraycopySrcPrefetchDistance, Assembler::severalReads); kvn@3103: } kvn@3103: if (ArraycopyDstPrefetchDistance > 0) { kvn@3103: __ prefetch(to, ArraycopyDstPrefetchDistance, Assembler::severalWritesAndPossiblyReads); kvn@3103: } kvn@3103: } kvn@3103: __ ldx(from, 0, O4); kvn@3103: __ ldx(from, 8, G4); kvn@3103: __ inc(to, 16); kvn@3103: __ inc(from, 16); kvn@3103: __ deccc(count, count_dec); // Can we do next iteration after this one? kvn@3103: __ srlx(O4, right_shift, G3); kvn@3103: __ bset(G3, O3); kvn@3103: __ sllx(O4, left_shift, O4); kvn@3103: __ srlx(G4, right_shift, G3); kvn@3103: __ bset(G3, O4); kvn@3103: if (use_bis) { kvn@3103: __ stxa(O3, to, -16); kvn@3103: __ stxa(O4, to, -8); kvn@3103: } else { kvn@3103: __ stx(O3, to, -16); kvn@3103: __ stx(O4, to, -8); kvn@3103: } kvn@3103: __ brx(Assembler::greaterEqual, false, Assembler::pt, L_loop); kvn@3103: __ delayed()->sllx(G4, left_shift, O3); kvn@3103: } duke@435: duke@435: // Copy big chunks forward with shift duke@435: // duke@435: // Inputs: duke@435: // from - source arrays duke@435: // to - destination array aligned to 8-bytes duke@435: // count - elements count to copy >= the count equivalent to 16 bytes duke@435: // count_dec - elements count's decrement equivalent to 16 bytes duke@435: // L_copy_bytes - copy exit label duke@435: // duke@435: void copy_16_bytes_forward_with_shift(Register from, Register to, kvn@3103: Register count, int log2_elem_size, Label& L_copy_bytes) { kvn@3103: Label L_aligned_copy, L_copy_last_bytes; kvn@3103: assert(log2_elem_size <= 3, "the following code should be changed"); kvn@3103: int count_dec = 16>>log2_elem_size; duke@435: duke@435: // if both arrays have the same alignment mod 8, do 8 bytes aligned copy kvn@3103: __ andcc(from, 7, G1); // misaligned bytes kvn@3103: __ br(Assembler::zero, false, Assembler::pt, L_aligned_copy); kvn@3103: __ delayed()->nop(); duke@435: duke@435: const Register left_shift = G1; // left shift bit counter duke@435: const Register right_shift = G5; // right shift bit counter duke@435: kvn@3103: __ sll(G1, LogBitsPerByte, left_shift); kvn@3103: __ mov(64, right_shift); kvn@3103: __ sub(right_shift, left_shift, right_shift); duke@435: duke@435: // duke@435: // Load 2 aligned 8-bytes chunks and use one from previous iteration duke@435: // to form 2 aligned 8-bytes chunks to store. duke@435: // kvn@3103: __ dec(count, count_dec); // Pre-decrement 'count' kvn@3103: __ andn(from, 7, from); // Align address kvn@3103: __ ldx(from, 0, O3); kvn@3103: __ inc(from, 8); kvn@3103: __ sllx(O3, left_shift, O3); kvn@3103: kvn@3103: disjoint_copy_core(from, to, count, log2_elem_size, 16, copy_16_bytes_shift_loop); kvn@3103: kvn@3103: __ inccc(count, count_dec>>1 ); // + 8 bytes kvn@3103: __ brx(Assembler::negative, true, Assembler::pn, L_copy_last_bytes); kvn@3103: __ delayed()->inc(count, count_dec>>1); // restore 'count' kvn@3103: kvn@3103: // copy 8 bytes, part of them already loaded in O3 kvn@3103: __ ldx(from, 0, O4); kvn@3103: __ inc(to, 8); kvn@3103: __ inc(from, 8); kvn@3103: __ srlx(O4, right_shift, G3); kvn@3103: __ bset(O3, G3); kvn@3103: __ stx(G3, to, -8); duke@435: duke@435: __ BIND(L_copy_last_bytes); kvn@3103: __ srl(right_shift, LogBitsPerByte, right_shift); // misaligned bytes kvn@3103: __ br(Assembler::always, false, Assembler::pt, L_copy_bytes); kvn@3103: __ delayed()->sub(from, right_shift, from); // restore address duke@435: duke@435: __ BIND(L_aligned_copy); duke@435: } duke@435: duke@435: // Copy big chunks backward with shift duke@435: // duke@435: // Inputs: duke@435: // end_from - source arrays end address duke@435: // end_to - destination array end address aligned to 8-bytes duke@435: // count - elements count to copy >= the count equivalent to 16 bytes duke@435: // count_dec - elements count's decrement equivalent to 16 bytes duke@435: // L_aligned_copy - aligned copy exit label duke@435: // L_copy_bytes - copy exit label duke@435: // duke@435: void copy_16_bytes_backward_with_shift(Register end_from, Register end_to, duke@435: Register count, int count_dec, duke@435: Label& L_aligned_copy, Label& L_copy_bytes) { duke@435: Label L_loop, L_copy_last_bytes; duke@435: duke@435: // if both arrays have the same alignment mod 8, do 8 bytes aligned copy duke@435: __ andcc(end_from, 7, G1); // misaligned bytes duke@435: __ br(Assembler::zero, false, Assembler::pt, L_aligned_copy); duke@435: __ delayed()->deccc(count, count_dec); // Pre-decrement 'count' duke@435: duke@435: const Register left_shift = G1; // left shift bit counter duke@435: const Register right_shift = G5; // right shift bit counter duke@435: duke@435: __ sll(G1, LogBitsPerByte, left_shift); duke@435: __ mov(64, right_shift); duke@435: __ sub(right_shift, left_shift, right_shift); duke@435: duke@435: // duke@435: // Load 2 aligned 8-bytes chunks and use one from previous iteration duke@435: // to form 2 aligned 8-bytes chunks to store. duke@435: // duke@435: __ andn(end_from, 7, end_from); // Align address duke@435: __ ldx(end_from, 0, O3); kvn@1800: __ align(OptoLoopAlignment); duke@435: __ BIND(L_loop); duke@435: __ ldx(end_from, -8, O4); duke@435: __ deccc(count, count_dec); // Can we do next iteration after this one? duke@435: __ ldx(end_from, -16, G4); duke@435: __ dec(end_to, 16); duke@435: __ dec(end_from, 16); duke@435: __ srlx(O3, right_shift, O3); duke@435: __ sllx(O4, left_shift, G3); duke@435: __ bset(G3, O3); duke@435: __ stx(O3, end_to, 8); duke@435: __ srlx(O4, right_shift, O4); duke@435: __ sllx(G4, left_shift, G3); duke@435: __ bset(G3, O4); duke@435: __ stx(O4, end_to, 0); duke@435: __ brx(Assembler::greaterEqual, false, Assembler::pt, L_loop); duke@435: __ delayed()->mov(G4, O3); duke@435: duke@435: __ inccc(count, count_dec>>1 ); // + 8 bytes duke@435: __ brx(Assembler::negative, true, Assembler::pn, L_copy_last_bytes); duke@435: __ delayed()->inc(count, count_dec>>1); // restore 'count' duke@435: duke@435: // copy 8 bytes, part of them already loaded in O3 duke@435: __ ldx(end_from, -8, O4); duke@435: __ dec(end_to, 8); duke@435: __ dec(end_from, 8); duke@435: __ srlx(O3, right_shift, O3); duke@435: __ sllx(O4, left_shift, G3); duke@435: __ bset(O3, G3); duke@435: __ stx(G3, end_to, 0); duke@435: duke@435: __ BIND(L_copy_last_bytes); duke@435: __ srl(left_shift, LogBitsPerByte, left_shift); // misaligned bytes duke@435: __ br(Assembler::always, false, Assembler::pt, L_copy_bytes); duke@435: __ delayed()->add(end_from, left_shift, end_from); // restore address duke@435: } duke@435: duke@435: // duke@435: // Generate stub for disjoint byte copy. If "aligned" is true, the duke@435: // "from" and "to" addresses are assumed to be heapword aligned. duke@435: // duke@435: // Arguments for generated stub: duke@435: // from: O0 duke@435: // to: O1 duke@435: // count: O2 treated as signed duke@435: // iveresov@2595: address generate_disjoint_byte_copy(bool aligned, 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_skip_alignment, L_align; duke@435: Label L_copy_byte, L_copy_byte_loop, L_exit; duke@435: duke@435: const Register from = O0; // source array address duke@435: const Register to = O1; // destination array address duke@435: const Register count = O2; // elements count duke@435: const Register offset = O5; // offset from start of arrays duke@435: // O3, O4, G3, G4 are used as temp registers duke@435: duke@435: assert_clean_int(count, O3); // Make sure 'count' is clean int. duke@435: iveresov@2595: if (entry != NULL) { iveresov@2595: *entry = __ pc(); iveresov@2595: // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) iveresov@2595: BLOCK_COMMENT("Entry:"); iveresov@2595: } duke@435: duke@435: // for short arrays, just do single element copy duke@435: __ cmp(count, 23); // 16 + 7 duke@435: __ brx(Assembler::less, false, Assembler::pn, L_copy_byte); duke@435: __ delayed()->mov(G0, offset); duke@435: duke@435: if (aligned) { duke@435: // 'aligned' == true when it is known statically during compilation duke@435: // of this arraycopy call site that both 'from' and 'to' addresses duke@435: // are HeapWordSize aligned (see LibraryCallKit::basictype2arraycopy()). duke@435: // duke@435: // Aligned arrays have 4 bytes alignment in 32-bits VM duke@435: // and 8 bytes - in 64-bits VM. So we do it only for 32-bits VM duke@435: // duke@435: #ifndef _LP64 duke@435: // copy a 4-bytes word if necessary to align 'to' to 8 bytes duke@435: __ andcc(to, 7, G0); duke@435: __ br(Assembler::zero, false, Assembler::pn, L_skip_alignment); duke@435: __ delayed()->ld(from, 0, O3); duke@435: __ inc(from, 4); duke@435: __ inc(to, 4); duke@435: __ dec(count, 4); duke@435: __ st(O3, to, -4); duke@435: __ BIND(L_skip_alignment); duke@435: #endif duke@435: } else { duke@435: // copy bytes to align 'to' on 8 byte boundary duke@435: __ andcc(to, 7, G1); // misaligned bytes duke@435: __ br(Assembler::zero, false, Assembler::pt, L_skip_alignment); duke@435: __ delayed()->neg(G1); duke@435: __ inc(G1, 8); // bytes need to copy to next 8-bytes alignment duke@435: __ sub(count, G1, count); duke@435: __ BIND(L_align); duke@435: __ ldub(from, 0, O3); duke@435: __ deccc(G1); duke@435: __ inc(from); duke@435: __ stb(O3, to, 0); duke@435: __ br(Assembler::notZero, false, Assembler::pt, L_align); duke@435: __ delayed()->inc(to); duke@435: __ BIND(L_skip_alignment); duke@435: } duke@435: #ifdef _LP64 duke@435: if (!aligned) duke@435: #endif duke@435: { duke@435: // Copy with shift 16 bytes per iteration if arrays do not have duke@435: // the same alignment mod 8, otherwise fall through to the next duke@435: // code for aligned copy. duke@435: // The compare above (count >= 23) guarantes 'count' >= 16 bytes. duke@435: // Also jump over aligned copy after the copy with shift completed. duke@435: kvn@3103: copy_16_bytes_forward_with_shift(from, to, count, 0, L_copy_byte); duke@435: } duke@435: duke@435: // Both array are 8 bytes aligned, copy 16 bytes at a time duke@435: __ and3(count, 7, G4); // Save count duke@435: __ srl(count, 3, count); duke@435: generate_disjoint_long_copy_core(aligned); duke@435: __ mov(G4, count); // Restore count duke@435: duke@435: // copy tailing bytes duke@435: __ BIND(L_copy_byte); kvn@3037: __ cmp_and_br_short(count, 0, Assembler::equal, Assembler::pt, L_exit); kvn@1800: __ align(OptoLoopAlignment); duke@435: __ BIND(L_copy_byte_loop); duke@435: __ ldub(from, offset, O3); duke@435: __ deccc(count); duke@435: __ stb(O3, to, offset); duke@435: __ brx(Assembler::notZero, false, Assembler::pt, L_copy_byte_loop); duke@435: __ delayed()->inc(offset); duke@435: duke@435: __ BIND(L_exit); duke@435: // O3, O4 are used as temp registers duke@435: inc_counter_np(SharedRuntime::_jbyte_array_copy_ctr, O3, O4); duke@435: __ retl(); duke@435: __ delayed()->mov(G0, O0); // return 0 duke@435: return start; duke@435: } duke@435: duke@435: // duke@435: // Generate stub for conjoint byte copy. If "aligned" is true, the duke@435: // "from" and "to" addresses are assumed to be heapword aligned. duke@435: // duke@435: // Arguments for generated stub: duke@435: // from: O0 duke@435: // to: O1 duke@435: // count: O2 treated as signed duke@435: // iveresov@2595: address generate_conjoint_byte_copy(bool aligned, address nooverlap_target, iveresov@2595: address *entry, const char *name) { duke@435: // Do reverse copy. duke@435: duke@435: __ align(CodeEntryAlignment); duke@435: StubCodeMark mark(this, "StubRoutines", name); duke@435: address start = __ pc(); duke@435: duke@435: Label L_skip_alignment, L_align, L_aligned_copy; duke@435: Label L_copy_byte, L_copy_byte_loop, L_exit; duke@435: duke@435: const Register from = O0; // source array address duke@435: const Register to = O1; // destination array address duke@435: const Register count = O2; // elements count duke@435: const Register end_from = from; // source array end address duke@435: const Register end_to = to; // destination array end address duke@435: duke@435: assert_clean_int(count, O3); // Make sure 'count' is clean int. duke@435: iveresov@2595: if (entry != NULL) { iveresov@2595: *entry = __ pc(); iveresov@2595: // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) iveresov@2595: BLOCK_COMMENT("Entry:"); iveresov@2595: } duke@435: duke@435: array_overlap_test(nooverlap_target, 0); duke@435: duke@435: __ add(to, count, end_to); // offset after last copied element duke@435: duke@435: // for short arrays, just do single element copy duke@435: __ cmp(count, 23); // 16 + 7 duke@435: __ brx(Assembler::less, false, Assembler::pn, L_copy_byte); duke@435: __ delayed()->add(from, count, end_from); duke@435: duke@435: { duke@435: // Align end of arrays since they could be not aligned even duke@435: // when arrays itself are aligned. duke@435: duke@435: // copy bytes to align 'end_to' on 8 byte boundary duke@435: __ andcc(end_to, 7, G1); // misaligned bytes duke@435: __ br(Assembler::zero, false, Assembler::pt, L_skip_alignment); duke@435: __ delayed()->nop(); duke@435: __ sub(count, G1, count); duke@435: __ BIND(L_align); duke@435: __ dec(end_from); duke@435: __ dec(end_to); duke@435: __ ldub(end_from, 0, O3); duke@435: __ deccc(G1); duke@435: __ brx(Assembler::notZero, false, Assembler::pt, L_align); duke@435: __ delayed()->stb(O3, end_to, 0); duke@435: __ BIND(L_skip_alignment); duke@435: } duke@435: #ifdef _LP64 duke@435: if (aligned) { duke@435: // Both arrays are aligned to 8-bytes in 64-bits VM. duke@435: // The 'count' is decremented in copy_16_bytes_backward_with_shift() duke@435: // in unaligned case. duke@435: __ dec(count, 16); duke@435: } else duke@435: #endif duke@435: { duke@435: // Copy with shift 16 bytes per iteration if arrays do not have duke@435: // the same alignment mod 8, otherwise jump to the next duke@435: // code for aligned copy (and substracting 16 from 'count' before jump). duke@435: // The compare above (count >= 11) guarantes 'count' >= 16 bytes. duke@435: // Also jump over aligned copy after the copy with shift completed. duke@435: duke@435: copy_16_bytes_backward_with_shift(end_from, end_to, count, 16, duke@435: L_aligned_copy, L_copy_byte); duke@435: } duke@435: // copy 4 elements (16 bytes) at a time kvn@1800: __ align(OptoLoopAlignment); duke@435: __ BIND(L_aligned_copy); duke@435: __ dec(end_from, 16); duke@435: __ ldx(end_from, 8, O3); duke@435: __ ldx(end_from, 0, O4); duke@435: __ dec(end_to, 16); duke@435: __ deccc(count, 16); duke@435: __ stx(O3, end_to, 8); duke@435: __ brx(Assembler::greaterEqual, false, Assembler::pt, L_aligned_copy); duke@435: __ delayed()->stx(O4, end_to, 0); duke@435: __ inc(count, 16); duke@435: duke@435: // copy 1 element (2 bytes) at a time duke@435: __ BIND(L_copy_byte); kvn@3037: __ cmp_and_br_short(count, 0, Assembler::equal, Assembler::pt, L_exit); kvn@1800: __ align(OptoLoopAlignment); duke@435: __ BIND(L_copy_byte_loop); duke@435: __ dec(end_from); duke@435: __ dec(end_to); duke@435: __ ldub(end_from, 0, O4); duke@435: __ deccc(count); duke@435: __ brx(Assembler::greater, false, Assembler::pt, L_copy_byte_loop); duke@435: __ delayed()->stb(O4, end_to, 0); duke@435: duke@435: __ BIND(L_exit); duke@435: // O3, O4 are used as temp registers duke@435: inc_counter_np(SharedRuntime::_jbyte_array_copy_ctr, O3, O4); duke@435: __ retl(); duke@435: __ delayed()->mov(G0, O0); // return 0 duke@435: return start; duke@435: } duke@435: duke@435: // duke@435: // Generate stub for disjoint short copy. If "aligned" is true, the duke@435: // "from" and "to" addresses are assumed to be heapword aligned. duke@435: // duke@435: // Arguments for generated stub: duke@435: // from: O0 duke@435: // to: O1 duke@435: // count: O2 treated as signed duke@435: // iveresov@2595: address generate_disjoint_short_copy(bool aligned, 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_skip_alignment, L_skip_alignment2; duke@435: Label L_copy_2_bytes, L_copy_2_bytes_loop, L_exit; duke@435: duke@435: const Register from = O0; // source array address duke@435: const Register to = O1; // destination array address duke@435: const Register count = O2; // elements count duke@435: const Register offset = O5; // offset from start of arrays duke@435: // O3, O4, G3, G4 are used as temp registers duke@435: duke@435: assert_clean_int(count, O3); // Make sure 'count' is clean int. duke@435: iveresov@2595: if (entry != NULL) { iveresov@2595: *entry = __ pc(); iveresov@2595: // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) iveresov@2595: BLOCK_COMMENT("Entry:"); iveresov@2595: } duke@435: duke@435: // for short arrays, just do single element copy duke@435: __ cmp(count, 11); // 8 + 3 (22 bytes) duke@435: __ brx(Assembler::less, false, Assembler::pn, L_copy_2_bytes); duke@435: __ delayed()->mov(G0, offset); duke@435: duke@435: if (aligned) { duke@435: // 'aligned' == true when it is known statically during compilation duke@435: // of this arraycopy call site that both 'from' and 'to' addresses duke@435: // are HeapWordSize aligned (see LibraryCallKit::basictype2arraycopy()). duke@435: // duke@435: // Aligned arrays have 4 bytes alignment in 32-bits VM duke@435: // and 8 bytes - in 64-bits VM. duke@435: // duke@435: #ifndef _LP64 duke@435: // copy a 2-elements word if necessary to align 'to' to 8 bytes duke@435: __ andcc(to, 7, G0); duke@435: __ br(Assembler::zero, false, Assembler::pt, L_skip_alignment); duke@435: __ delayed()->ld(from, 0, O3); duke@435: __ inc(from, 4); duke@435: __ inc(to, 4); duke@435: __ dec(count, 2); duke@435: __ st(O3, to, -4); duke@435: __ BIND(L_skip_alignment); duke@435: #endif duke@435: } else { duke@435: // copy 1 element if necessary to align 'to' on an 4 bytes duke@435: __ andcc(to, 3, G0); duke@435: __ br(Assembler::zero, false, Assembler::pt, L_skip_alignment); duke@435: __ delayed()->lduh(from, 0, O3); duke@435: __ inc(from, 2); duke@435: __ inc(to, 2); duke@435: __ dec(count); duke@435: __ sth(O3, to, -2); duke@435: __ BIND(L_skip_alignment); duke@435: duke@435: // copy 2 elements to align 'to' on an 8 byte boundary duke@435: __ andcc(to, 7, G0); duke@435: __ br(Assembler::zero, false, Assembler::pn, L_skip_alignment2); duke@435: __ delayed()->lduh(from, 0, O3); duke@435: __ dec(count, 2); duke@435: __ lduh(from, 2, O4); duke@435: __ inc(from, 4); duke@435: __ inc(to, 4); duke@435: __ sth(O3, to, -4); duke@435: __ sth(O4, to, -2); duke@435: __ BIND(L_skip_alignment2); duke@435: } duke@435: #ifdef _LP64 duke@435: if (!aligned) duke@435: #endif duke@435: { duke@435: // Copy with shift 16 bytes per iteration if arrays do not have duke@435: // the same alignment mod 8, otherwise fall through to the next duke@435: // code for aligned copy. duke@435: // The compare above (count >= 11) guarantes 'count' >= 16 bytes. duke@435: // Also jump over aligned copy after the copy with shift completed. duke@435: kvn@3103: copy_16_bytes_forward_with_shift(from, to, count, 1, L_copy_2_bytes); duke@435: } duke@435: duke@435: // Both array are 8 bytes aligned, copy 16 bytes at a time duke@435: __ and3(count, 3, G4); // Save duke@435: __ srl(count, 2, count); duke@435: generate_disjoint_long_copy_core(aligned); duke@435: __ mov(G4, count); // restore duke@435: duke@435: // copy 1 element at a time duke@435: __ BIND(L_copy_2_bytes); kvn@3037: __ cmp_and_br_short(count, 0, Assembler::equal, Assembler::pt, L_exit); kvn@1800: __ align(OptoLoopAlignment); duke@435: __ BIND(L_copy_2_bytes_loop); duke@435: __ lduh(from, offset, O3); duke@435: __ deccc(count); duke@435: __ sth(O3, to, offset); duke@435: __ brx(Assembler::notZero, false, Assembler::pt, L_copy_2_bytes_loop); duke@435: __ delayed()->inc(offset, 2); duke@435: duke@435: __ BIND(L_exit); duke@435: // O3, O4 are used as temp registers duke@435: inc_counter_np(SharedRuntime::_jshort_array_copy_ctr, O3, O4); duke@435: __ retl(); duke@435: __ delayed()->mov(G0, O0); // return 0 duke@435: return start; duke@435: } duke@435: duke@435: // never@2118: // Generate stub for disjoint short fill. If "aligned" is true, the never@2118: // "to" address is assumed to be heapword aligned. never@2118: // never@2118: // Arguments for generated stub: never@2118: // to: O0 never@2118: // value: O1 never@2118: // count: O2 treated as signed never@2118: // never@2118: address generate_fill(BasicType t, bool aligned, const char* name) { never@2118: __ align(CodeEntryAlignment); never@2118: StubCodeMark mark(this, "StubRoutines", name); never@2118: address start = __ pc(); never@2118: never@2118: const Register to = O0; // source array address never@2118: const Register value = O1; // fill value never@2118: const Register count = O2; // elements count never@2118: // O3 is used as a temp register never@2118: never@2118: assert_clean_int(count, O3); // Make sure 'count' is clean int. never@2118: never@2118: Label L_exit, L_skip_align1, L_skip_align2, L_fill_byte; never@2149: Label L_fill_2_bytes, L_fill_elements, L_fill_32_bytes; never@2118: never@2118: int shift = -1; never@2118: switch (t) { never@2118: case T_BYTE: never@2118: shift = 2; never@2118: break; never@2118: case T_SHORT: never@2118: shift = 1; never@2118: break; never@2118: case T_INT: never@2118: shift = 0; never@2118: break; never@2118: default: ShouldNotReachHere(); never@2118: } never@2118: never@2118: BLOCK_COMMENT("Entry:"); never@2118: never@2118: if (t == T_BYTE) { never@2118: // Zero extend value never@2118: __ and3(value, 0xff, value); never@2118: __ sllx(value, 8, O3); never@2118: __ or3(value, O3, value); never@2118: } never@2118: if (t == T_SHORT) { never@2118: // Zero extend value never@2149: __ sllx(value, 48, value); never@2149: __ srlx(value, 48, value); never@2118: } never@2118: if (t == T_BYTE || t == T_SHORT) { never@2118: __ sllx(value, 16, O3); never@2118: __ or3(value, O3, value); never@2118: } never@2118: never@2118: __ cmp(count, 2<andcc(count, 1, G0); never@2118: never@2118: if (!aligned && (t == T_BYTE || t == T_SHORT)) { never@2118: // align source address at 4 bytes address boundary never@2118: if (t == T_BYTE) { never@2118: // One byte misalignment happens only for byte arrays never@2118: __ andcc(to, 1, G0); never@2118: __ br(Assembler::zero, false, Assembler::pt, L_skip_align1); never@2118: __ delayed()->nop(); never@2118: __ stb(value, to, 0); never@2118: __ inc(to, 1); never@2118: __ dec(count, 1); never@2118: __ BIND(L_skip_align1); never@2118: } never@2118: // Two bytes misalignment happens only for byte and short (char) arrays never@2118: __ andcc(to, 2, G0); never@2118: __ br(Assembler::zero, false, Assembler::pt, L_skip_align2); never@2118: __ delayed()->nop(); never@2118: __ sth(value, to, 0); never@2118: __ inc(to, 2); never@2118: __ dec(count, 1 << (shift - 1)); never@2118: __ BIND(L_skip_align2); never@2118: } never@2118: #ifdef _LP64 never@2118: if (!aligned) { never@2118: #endif never@2118: // align to 8 bytes, we know we are 4 byte aligned to start never@2118: __ andcc(to, 7, G0); never@2118: __ br(Assembler::zero, false, Assembler::pt, L_fill_32_bytes); never@2118: __ delayed()->nop(); never@2118: __ stw(value, to, 0); never@2118: __ inc(to, 4); never@2118: __ dec(count, 1 << shift); never@2118: __ BIND(L_fill_32_bytes); never@2118: #ifdef _LP64 never@2118: } never@2118: #endif never@2118: never@2118: if (t == T_INT) { never@2118: // Zero extend value never@2118: __ srl(value, 0, value); never@2118: } never@2118: if (t == T_BYTE || t == T_SHORT || t == T_INT) { never@2118: __ sllx(value, 32, O3); never@2118: __ or3(value, O3, value); never@2118: } never@2118: never@2137: Label L_check_fill_8_bytes; never@2137: // Fill 32-byte chunks never@2137: __ subcc(count, 8 << shift, count); never@2137: __ brx(Assembler::less, false, Assembler::pt, L_check_fill_8_bytes); never@2137: __ delayed()->nop(); never@2137: never@2149: Label L_fill_32_bytes_loop, L_fill_4_bytes; never@2118: __ align(16); never@2118: __ BIND(L_fill_32_bytes_loop); never@2118: never@2118: __ stx(value, to, 0); never@2118: __ stx(value, to, 8); never@2118: __ stx(value, to, 16); never@2118: __ stx(value, to, 24); never@2118: never@2118: __ subcc(count, 8 << shift, count); never@2118: __ brx(Assembler::greaterEqual, false, Assembler::pt, L_fill_32_bytes_loop); never@2118: __ delayed()->add(to, 32, to); never@2118: never@2118: __ BIND(L_check_fill_8_bytes); never@2118: __ addcc(count, 8 << shift, count); never@2118: __ brx(Assembler::zero, false, Assembler::pn, L_exit); never@2118: __ delayed()->subcc(count, 1 << (shift + 1), count); never@2118: __ brx(Assembler::less, false, Assembler::pn, L_fill_4_bytes); never@2118: __ delayed()->andcc(count, 1<add(to, 8, to); never@2118: never@2118: // fill trailing 4 bytes never@2118: __ andcc(count, 1<andcc(count, 1<<(shift-1), G0); never@2118: } else { never@2118: __ delayed()->nop(); never@2118: } never@2118: __ stw(value, to, 0); never@2118: if (t == T_BYTE || t == T_SHORT) { never@2118: __ inc(to, 4); never@2118: // fill trailing 2 bytes never@2118: __ andcc(count, 1<<(shift-1), G0); // in delay slot of branches never@2118: __ BIND(L_fill_2_bytes); never@2118: __ brx(Assembler::zero, false, Assembler::pt, L_fill_byte); never@2118: __ delayed()->andcc(count, 1, count); never@2118: __ sth(value, to, 0); never@2118: if (t == T_BYTE) { never@2118: __ inc(to, 2); never@2118: // fill trailing byte never@2118: __ andcc(count, 1, count); // in delay slot of branches never@2118: __ BIND(L_fill_byte); never@2118: __ brx(Assembler::zero, false, Assembler::pt, L_exit); never@2118: __ delayed()->nop(); never@2118: __ stb(value, to, 0); never@2118: } else { never@2118: __ BIND(L_fill_byte); never@2118: } never@2118: } else { never@2118: __ BIND(L_fill_2_bytes); never@2118: } never@2118: __ BIND(L_exit); never@2118: __ retl(); never@2149: __ delayed()->nop(); never@2149: never@2149: // Handle copies less than 8 bytes. Int is handled elsewhere. never@2149: if (t == T_BYTE) { never@2149: __ BIND(L_fill_elements); never@2149: Label L_fill_2, L_fill_4; never@2149: // in delay slot __ andcc(count, 1, G0); never@2149: __ brx(Assembler::zero, false, Assembler::pt, L_fill_2); never@2149: __ delayed()->andcc(count, 2, G0); never@2149: __ stb(value, to, 0); never@2149: __ inc(to, 1); never@2149: __ BIND(L_fill_2); never@2149: __ brx(Assembler::zero, false, Assembler::pt, L_fill_4); never@2149: __ delayed()->andcc(count, 4, G0); never@2149: __ stb(value, to, 0); never@2149: __ stb(value, to, 1); never@2149: __ inc(to, 2); never@2149: __ BIND(L_fill_4); never@2149: __ brx(Assembler::zero, false, Assembler::pt, L_exit); never@2149: __ delayed()->nop(); never@2149: __ stb(value, to, 0); never@2149: __ stb(value, to, 1); never@2149: __ stb(value, to, 2); never@2149: __ retl(); never@2149: __ delayed()->stb(value, to, 3); never@2149: } never@2149: never@2149: if (t == T_SHORT) { never@2149: Label L_fill_2; never@2149: __ BIND(L_fill_elements); never@2149: // in delay slot __ andcc(count, 1, G0); never@2149: __ brx(Assembler::zero, false, Assembler::pt, L_fill_2); never@2149: __ delayed()->andcc(count, 2, G0); never@2149: __ sth(value, to, 0); never@2149: __ inc(to, 2); never@2149: __ BIND(L_fill_2); never@2149: __ brx(Assembler::zero, false, Assembler::pt, L_exit); never@2149: __ delayed()->nop(); never@2149: __ sth(value, to, 0); never@2149: __ retl(); never@2149: __ delayed()->sth(value, to, 2); never@2149: } never@2118: return start; never@2118: } never@2118: never@2118: // duke@435: // Generate stub for conjoint short copy. If "aligned" is true, the duke@435: // "from" and "to" addresses are assumed to be heapword aligned. duke@435: // duke@435: // Arguments for generated stub: duke@435: // from: O0 duke@435: // to: O1 duke@435: // count: O2 treated as signed duke@435: // iveresov@2595: address generate_conjoint_short_copy(bool aligned, address nooverlap_target, iveresov@2595: address *entry, const char *name) { duke@435: // Do reverse copy. duke@435: duke@435: __ align(CodeEntryAlignment); duke@435: StubCodeMark mark(this, "StubRoutines", name); duke@435: address start = __ pc(); duke@435: duke@435: Label L_skip_alignment, L_skip_alignment2, L_aligned_copy; duke@435: Label L_copy_2_bytes, L_copy_2_bytes_loop, L_exit; duke@435: duke@435: const Register from = O0; // source array address duke@435: const Register to = O1; // destination array address duke@435: const Register count = O2; // elements count duke@435: const Register end_from = from; // source array end address duke@435: const Register end_to = to; // destination array end address duke@435: duke@435: const Register byte_count = O3; // bytes count to copy duke@435: duke@435: assert_clean_int(count, O3); // Make sure 'count' is clean int. duke@435: iveresov@2595: if (entry != NULL) { iveresov@2595: *entry = __ pc(); iveresov@2595: // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) iveresov@2595: BLOCK_COMMENT("Entry:"); iveresov@2595: } duke@435: duke@435: array_overlap_test(nooverlap_target, 1); duke@435: duke@435: __ sllx(count, LogBytesPerShort, byte_count); duke@435: __ add(to, byte_count, end_to); // offset after last copied element duke@435: duke@435: // for short arrays, just do single element copy duke@435: __ cmp(count, 11); // 8 + 3 (22 bytes) duke@435: __ brx(Assembler::less, false, Assembler::pn, L_copy_2_bytes); duke@435: __ delayed()->add(from, byte_count, end_from); duke@435: duke@435: { duke@435: // Align end of arrays since they could be not aligned even duke@435: // when arrays itself are aligned. duke@435: duke@435: // copy 1 element if necessary to align 'end_to' on an 4 bytes duke@435: __ andcc(end_to, 3, G0); duke@435: __ br(Assembler::zero, false, Assembler::pt, L_skip_alignment); duke@435: __ delayed()->lduh(end_from, -2, O3); duke@435: __ dec(end_from, 2); duke@435: __ dec(end_to, 2); duke@435: __ dec(count); duke@435: __ sth(O3, end_to, 0); duke@435: __ BIND(L_skip_alignment); duke@435: duke@435: // copy 2 elements to align 'end_to' on an 8 byte boundary duke@435: __ andcc(end_to, 7, G0); duke@435: __ br(Assembler::zero, false, Assembler::pn, L_skip_alignment2); duke@435: __ delayed()->lduh(end_from, -2, O3); duke@435: __ dec(count, 2); duke@435: __ lduh(end_from, -4, O4); duke@435: __ dec(end_from, 4); duke@435: __ dec(end_to, 4); duke@435: __ sth(O3, end_to, 2); duke@435: __ sth(O4, end_to, 0); duke@435: __ BIND(L_skip_alignment2); duke@435: } duke@435: #ifdef _LP64 duke@435: if (aligned) { duke@435: // Both arrays are aligned to 8-bytes in 64-bits VM. duke@435: // The 'count' is decremented in copy_16_bytes_backward_with_shift() duke@435: // in unaligned case. duke@435: __ dec(count, 8); duke@435: } else duke@435: #endif duke@435: { duke@435: // Copy with shift 16 bytes per iteration if arrays do not have duke@435: // the same alignment mod 8, otherwise jump to the next duke@435: // code for aligned copy (and substracting 8 from 'count' before jump). duke@435: // The compare above (count >= 11) guarantes 'count' >= 16 bytes. duke@435: // Also jump over aligned copy after the copy with shift completed. duke@435: duke@435: copy_16_bytes_backward_with_shift(end_from, end_to, count, 8, duke@435: L_aligned_copy, L_copy_2_bytes); duke@435: } duke@435: // copy 4 elements (16 bytes) at a time kvn@1800: __ align(OptoLoopAlignment); duke@435: __ BIND(L_aligned_copy); duke@435: __ dec(end_from, 16); duke@435: __ ldx(end_from, 8, O3); duke@435: __ ldx(end_from, 0, O4); duke@435: __ dec(end_to, 16); duke@435: __ deccc(count, 8); duke@435: __ stx(O3, end_to, 8); duke@435: __ brx(Assembler::greaterEqual, false, Assembler::pt, L_aligned_copy); duke@435: __ delayed()->stx(O4, end_to, 0); duke@435: __ inc(count, 8); duke@435: duke@435: // copy 1 element (2 bytes) at a time duke@435: __ BIND(L_copy_2_bytes); kvn@3037: __ cmp_and_br_short(count, 0, Assembler::equal, Assembler::pt, L_exit); duke@435: __ BIND(L_copy_2_bytes_loop); duke@435: __ dec(end_from, 2); duke@435: __ dec(end_to, 2); duke@435: __ lduh(end_from, 0, O4); duke@435: __ deccc(count); duke@435: __ brx(Assembler::greater, false, Assembler::pt, L_copy_2_bytes_loop); duke@435: __ delayed()->sth(O4, end_to, 0); duke@435: duke@435: __ BIND(L_exit); duke@435: // O3, O4 are used as temp registers duke@435: inc_counter_np(SharedRuntime::_jshort_array_copy_ctr, O3, O4); duke@435: __ retl(); duke@435: __ delayed()->mov(G0, O0); // return 0 duke@435: return start; duke@435: } duke@435: duke@435: // kvn@3103: // Helper methods for generate_disjoint_int_copy_core() kvn@3103: // kvn@3103: void copy_16_bytes_loop(Register from, Register to, Register count, int count_dec, kvn@3103: Label& L_loop, bool use_prefetch, bool use_bis) { kvn@3103: kvn@3103: __ align(OptoLoopAlignment); kvn@3103: __ BIND(L_loop); kvn@3103: if (use_prefetch) { kvn@3103: if (ArraycopySrcPrefetchDistance > 0) { kvn@3103: __ prefetch(from, ArraycopySrcPrefetchDistance, Assembler::severalReads); kvn@3103: } kvn@3103: if (ArraycopyDstPrefetchDistance > 0) { kvn@3103: __ prefetch(to, ArraycopyDstPrefetchDistance, Assembler::severalWritesAndPossiblyReads); kvn@3103: } kvn@3103: } kvn@3103: __ ldx(from, 4, O4); kvn@3103: __ ldx(from, 12, G4); kvn@3103: __ inc(to, 16); kvn@3103: __ inc(from, 16); kvn@3103: __ deccc(count, 4); // Can we do next iteration after this one? kvn@3103: kvn@3103: __ srlx(O4, 32, G3); kvn@3103: __ bset(G3, O3); kvn@3103: __ sllx(O4, 32, O4); kvn@3103: __ srlx(G4, 32, G3); kvn@3103: __ bset(G3, O4); kvn@3103: if (use_bis) { kvn@3103: __ stxa(O3, to, -16); kvn@3103: __ stxa(O4, to, -8); kvn@3103: } else { kvn@3103: __ stx(O3, to, -16); kvn@3103: __ stx(O4, to, -8); kvn@3103: } kvn@3103: __ brx(Assembler::greaterEqual, false, Assembler::pt, L_loop); kvn@3103: __ delayed()->sllx(G4, 32, O3); kvn@3103: kvn@3103: } kvn@3103: kvn@3103: // duke@435: // Generate core code for disjoint int copy (and oop copy on 32-bit). duke@435: // If "aligned" is true, the "from" and "to" addresses are assumed duke@435: // to be heapword aligned. duke@435: // duke@435: // Arguments: duke@435: // from: O0 duke@435: // to: O1 duke@435: // count: O2 treated as signed duke@435: // duke@435: void generate_disjoint_int_copy_core(bool aligned) { duke@435: duke@435: Label L_skip_alignment, L_aligned_copy; kvn@3103: Label L_copy_4_bytes, L_copy_4_bytes_loop, L_exit; duke@435: duke@435: const Register from = O0; // source array address duke@435: const Register to = O1; // destination array address duke@435: const Register count = O2; // elements count duke@435: const Register offset = O5; // offset from start of arrays duke@435: // O3, O4, G3, G4 are used as temp registers duke@435: duke@435: // 'aligned' == true when it is known statically during compilation duke@435: // of this arraycopy call site that both 'from' and 'to' addresses duke@435: // are HeapWordSize aligned (see LibraryCallKit::basictype2arraycopy()). duke@435: // duke@435: // Aligned arrays have 4 bytes alignment in 32-bits VM duke@435: // and 8 bytes - in 64-bits VM. duke@435: // duke@435: #ifdef _LP64 duke@435: if (!aligned) duke@435: #endif duke@435: { duke@435: // The next check could be put under 'ifndef' since the code in duke@435: // generate_disjoint_long_copy_core() has own checks and set 'offset'. duke@435: duke@435: // for short arrays, just do single element copy duke@435: __ cmp(count, 5); // 4 + 1 (20 bytes) duke@435: __ brx(Assembler::lessEqual, false, Assembler::pn, L_copy_4_bytes); duke@435: __ delayed()->mov(G0, offset); duke@435: duke@435: // copy 1 element to align 'to' on an 8 byte boundary duke@435: __ andcc(to, 7, G0); duke@435: __ br(Assembler::zero, false, Assembler::pt, L_skip_alignment); duke@435: __ delayed()->ld(from, 0, O3); duke@435: __ inc(from, 4); duke@435: __ inc(to, 4); duke@435: __ dec(count); duke@435: __ st(O3, to, -4); duke@435: __ BIND(L_skip_alignment); duke@435: duke@435: // if arrays have same alignment mod 8, do 4 elements copy duke@435: __ andcc(from, 7, G0); duke@435: __ br(Assembler::zero, false, Assembler::pt, L_aligned_copy); duke@435: __ delayed()->ld(from, 0, O3); duke@435: duke@435: // duke@435: // Load 2 aligned 8-bytes chunks and use one from previous iteration duke@435: // to form 2 aligned 8-bytes chunks to store. duke@435: // duke@435: // copy_16_bytes_forward_with_shift() is not used here since this duke@435: // code is more optimal. duke@435: duke@435: // copy with shift 4 elements (16 bytes) at a time duke@435: __ dec(count, 4); // The cmp at the beginning guaranty count >= 4 kvn@3103: __ sllx(O3, 32, O3); kvn@3103: kvn@3103: disjoint_copy_core(from, to, count, 2, 16, copy_16_bytes_loop); duke@435: duke@435: __ br(Assembler::always, false, Assembler::pt, L_copy_4_bytes); duke@435: __ delayed()->inc(count, 4); // restore 'count' duke@435: duke@435: __ BIND(L_aligned_copy); kvn@3103: } // !aligned kvn@3103: duke@435: // copy 4 elements (16 bytes) at a time duke@435: __ and3(count, 1, G4); // Save duke@435: __ srl(count, 1, count); duke@435: generate_disjoint_long_copy_core(aligned); duke@435: __ mov(G4, count); // Restore duke@435: duke@435: // copy 1 element at a time duke@435: __ BIND(L_copy_4_bytes); kvn@3037: __ cmp_and_br_short(count, 0, Assembler::equal, Assembler::pt, L_exit); duke@435: __ BIND(L_copy_4_bytes_loop); duke@435: __ ld(from, offset, O3); duke@435: __ deccc(count); duke@435: __ st(O3, to, offset); duke@435: __ brx(Assembler::notZero, false, Assembler::pt, L_copy_4_bytes_loop); duke@435: __ delayed()->inc(offset, 4); duke@435: __ BIND(L_exit); duke@435: } duke@435: duke@435: // duke@435: // Generate stub for disjoint int copy. If "aligned" is true, the duke@435: // "from" and "to" addresses are assumed to be heapword aligned. duke@435: // duke@435: // Arguments for generated stub: duke@435: // from: O0 duke@435: // to: O1 duke@435: // count: O2 treated as signed duke@435: // iveresov@2595: address generate_disjoint_int_copy(bool aligned, 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: const Register count = O2; duke@435: assert_clean_int(count, O3); // Make sure 'count' is clean int. duke@435: iveresov@2595: if (entry != NULL) { iveresov@2595: *entry = __ pc(); iveresov@2595: // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) iveresov@2595: BLOCK_COMMENT("Entry:"); iveresov@2595: } duke@435: duke@435: generate_disjoint_int_copy_core(aligned); duke@435: duke@435: // O3, O4 are used as temp registers duke@435: inc_counter_np(SharedRuntime::_jint_array_copy_ctr, O3, O4); duke@435: __ retl(); duke@435: __ delayed()->mov(G0, O0); // return 0 duke@435: return start; duke@435: } duke@435: duke@435: // duke@435: // Generate core code for conjoint int copy (and oop copy on 32-bit). duke@435: // If "aligned" is true, the "from" and "to" addresses are assumed duke@435: // to be heapword aligned. duke@435: // duke@435: // Arguments: duke@435: // from: O0 duke@435: // to: O1 duke@435: // count: O2 treated as signed duke@435: // duke@435: void generate_conjoint_int_copy_core(bool aligned) { duke@435: // Do reverse copy. duke@435: duke@435: Label L_skip_alignment, L_aligned_copy; duke@435: Label L_copy_16_bytes, L_copy_4_bytes, L_copy_4_bytes_loop, L_exit; duke@435: duke@435: const Register from = O0; // source array address duke@435: const Register to = O1; // destination array address duke@435: const Register count = O2; // elements count duke@435: const Register end_from = from; // source array end address duke@435: const Register end_to = to; // destination array end address duke@435: // O3, O4, O5, G3 are used as temp registers duke@435: duke@435: const Register byte_count = O3; // bytes count to copy duke@435: duke@435: __ sllx(count, LogBytesPerInt, byte_count); duke@435: __ add(to, byte_count, end_to); // offset after last copied element duke@435: duke@435: __ cmp(count, 5); // for short arrays, just do single element copy duke@435: __ brx(Assembler::lessEqual, false, Assembler::pn, L_copy_4_bytes); duke@435: __ delayed()->add(from, byte_count, end_from); duke@435: duke@435: // copy 1 element to align 'to' on an 8 byte boundary duke@435: __ andcc(end_to, 7, G0); duke@435: __ br(Assembler::zero, false, Assembler::pt, L_skip_alignment); duke@435: __ delayed()->nop(); duke@435: __ dec(count); duke@435: __ dec(end_from, 4); duke@435: __ dec(end_to, 4); duke@435: __ ld(end_from, 0, O4); duke@435: __ st(O4, end_to, 0); duke@435: __ BIND(L_skip_alignment); duke@435: duke@435: // Check if 'end_from' and 'end_to' has the same alignment. duke@435: __ andcc(end_from, 7, G0); duke@435: __ br(Assembler::zero, false, Assembler::pt, L_aligned_copy); duke@435: __ delayed()->dec(count, 4); // The cmp at the start guaranty cnt >= 4 duke@435: duke@435: // copy with shift 4 elements (16 bytes) at a time duke@435: // duke@435: // Load 2 aligned 8-bytes chunks and use one from previous iteration duke@435: // to form 2 aligned 8-bytes chunks to store. duke@435: // duke@435: __ ldx(end_from, -4, O3); kvn@1800: __ align(OptoLoopAlignment); duke@435: __ BIND(L_copy_16_bytes); duke@435: __ ldx(end_from, -12, O4); duke@435: __ deccc(count, 4); duke@435: __ ldx(end_from, -20, O5); duke@435: __ dec(end_to, 16); duke@435: __ dec(end_from, 16); duke@435: __ srlx(O3, 32, O3); duke@435: __ sllx(O4, 32, G3); duke@435: __ bset(G3, O3); duke@435: __ stx(O3, end_to, 8); duke@435: __ srlx(O4, 32, O4); duke@435: __ sllx(O5, 32, G3); duke@435: __ bset(O4, G3); duke@435: __ stx(G3, end_to, 0); duke@435: __ brx(Assembler::greaterEqual, false, Assembler::pt, L_copy_16_bytes); duke@435: __ delayed()->mov(O5, O3); duke@435: duke@435: __ br(Assembler::always, false, Assembler::pt, L_copy_4_bytes); duke@435: __ delayed()->inc(count, 4); duke@435: duke@435: // copy 4 elements (16 bytes) at a time kvn@1800: __ align(OptoLoopAlignment); duke@435: __ BIND(L_aligned_copy); duke@435: __ dec(end_from, 16); duke@435: __ ldx(end_from, 8, O3); duke@435: __ ldx(end_from, 0, O4); duke@435: __ dec(end_to, 16); duke@435: __ deccc(count, 4); duke@435: __ stx(O3, end_to, 8); duke@435: __ brx(Assembler::greaterEqual, false, Assembler::pt, L_aligned_copy); duke@435: __ delayed()->stx(O4, end_to, 0); duke@435: __ inc(count, 4); duke@435: duke@435: // copy 1 element (4 bytes) at a time duke@435: __ BIND(L_copy_4_bytes); kvn@3037: __ cmp_and_br_short(count, 0, Assembler::equal, Assembler::pt, L_exit); duke@435: __ BIND(L_copy_4_bytes_loop); duke@435: __ dec(end_from, 4); duke@435: __ dec(end_to, 4); duke@435: __ ld(end_from, 0, O4); duke@435: __ deccc(count); duke@435: __ brx(Assembler::greater, false, Assembler::pt, L_copy_4_bytes_loop); duke@435: __ delayed()->st(O4, end_to, 0); duke@435: __ BIND(L_exit); duke@435: } duke@435: duke@435: // duke@435: // Generate stub for conjoint int copy. If "aligned" is true, the duke@435: // "from" and "to" addresses are assumed to be heapword aligned. duke@435: // duke@435: // Arguments for generated stub: duke@435: // from: O0 duke@435: // to: O1 duke@435: // count: O2 treated as signed duke@435: // iveresov@2595: address generate_conjoint_int_copy(bool aligned, address nooverlap_target, iveresov@2595: 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: assert_clean_int(O2, O3); // Make sure 'count' is clean int. duke@435: iveresov@2595: if (entry != NULL) { iveresov@2595: *entry = __ pc(); iveresov@2595: // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) iveresov@2595: BLOCK_COMMENT("Entry:"); iveresov@2595: } duke@435: duke@435: array_overlap_test(nooverlap_target, 2); duke@435: duke@435: generate_conjoint_int_copy_core(aligned); duke@435: duke@435: // O3, O4 are used as temp registers duke@435: inc_counter_np(SharedRuntime::_jint_array_copy_ctr, O3, O4); duke@435: __ retl(); duke@435: __ delayed()->mov(G0, O0); // return 0 duke@435: return start; duke@435: } duke@435: duke@435: // kvn@3103: // Helper methods for generate_disjoint_long_copy_core() kvn@3103: // kvn@3103: void copy_64_bytes_loop(Register from, Register to, Register count, int count_dec, kvn@3103: Label& L_loop, bool use_prefetch, bool use_bis) { kvn@3103: __ align(OptoLoopAlignment); kvn@3103: __ BIND(L_loop); kvn@3103: for (int off = 0; off < 64; off += 16) { kvn@3103: if (use_prefetch && (off & 31) == 0) { kvn@3103: if (ArraycopySrcPrefetchDistance > 0) { kvn@3157: __ prefetch(from, ArraycopySrcPrefetchDistance+off, Assembler::severalReads); kvn@3103: } kvn@3103: if (ArraycopyDstPrefetchDistance > 0) { kvn@3157: __ prefetch(to, ArraycopyDstPrefetchDistance+off, Assembler::severalWritesAndPossiblyReads); kvn@3103: } kvn@3103: } kvn@3103: __ ldx(from, off+0, O4); kvn@3103: __ ldx(from, off+8, O5); kvn@3103: if (use_bis) { kvn@3103: __ stxa(O4, to, off+0); kvn@3103: __ stxa(O5, to, off+8); kvn@3103: } else { kvn@3103: __ stx(O4, to, off+0); kvn@3103: __ stx(O5, to, off+8); kvn@3103: } kvn@3103: } kvn@3103: __ deccc(count, 8); kvn@3103: __ inc(from, 64); kvn@3103: __ brx(Assembler::greaterEqual, false, Assembler::pt, L_loop); kvn@3103: __ delayed()->inc(to, 64); kvn@3103: } kvn@3103: kvn@3103: // duke@435: // Generate core code for disjoint long copy (and oop copy on 64-bit). duke@435: // "aligned" is ignored, because we must make the stronger duke@435: // assumption that both addresses are always 64-bit aligned. duke@435: // duke@435: // Arguments: duke@435: // from: O0 duke@435: // to: O1 duke@435: // count: O2 treated as signed duke@435: // kvn@1799: // count -= 2; kvn@1799: // if ( count >= 0 ) { // >= 2 elements kvn@1799: // if ( count > 6) { // >= 8 elements kvn@1799: // count -= 6; // original count - 8 kvn@1799: // do { kvn@1799: // copy_8_elements; kvn@1799: // count -= 8; kvn@1799: // } while ( count >= 0 ); kvn@1799: // count += 6; kvn@1799: // } kvn@1799: // if ( count >= 0 ) { // >= 2 elements kvn@1799: // do { kvn@1799: // copy_2_elements; kvn@1799: // } while ( (count=count-2) >= 0 ); kvn@1799: // } kvn@1799: // } kvn@1799: // count += 2; kvn@1799: // if ( count != 0 ) { // 1 element left kvn@1799: // copy_1_element; kvn@1799: // } kvn@1799: // duke@435: void generate_disjoint_long_copy_core(bool aligned) { duke@435: Label L_copy_8_bytes, L_copy_16_bytes, L_exit; duke@435: const Register from = O0; // source array address duke@435: const Register to = O1; // destination array address duke@435: const Register count = O2; // elements count duke@435: const Register offset0 = O4; // element offset duke@435: const Register offset8 = O5; // next element offset duke@435: kvn@3103: __ deccc(count, 2); kvn@3103: __ mov(G0, offset0); // offset from start of arrays (0) kvn@3103: __ brx(Assembler::negative, false, Assembler::pn, L_copy_8_bytes ); kvn@3103: __ delayed()->add(offset0, 8, offset8); kvn@1799: kvn@1799: // Copy by 64 bytes chunks kvn@3103: kvn@1799: const Register from64 = O3; // source address kvn@1799: const Register to64 = G3; // destination address kvn@3103: __ subcc(count, 6, O3); kvn@3103: __ brx(Assembler::negative, false, Assembler::pt, L_copy_16_bytes ); kvn@3103: __ delayed()->mov(to, to64); kvn@3103: // Now we can use O4(offset0), O5(offset8) as temps kvn@3103: __ mov(O3, count); kvn@3103: // count >= 0 (original count - 8) kvn@3103: __ mov(from, from64); kvn@3103: kvn@3103: disjoint_copy_core(from64, to64, count, 3, 64, copy_64_bytes_loop); kvn@1799: kvn@1799: // Restore O4(offset0), O5(offset8) kvn@1799: __ sub(from64, from, offset0); kvn@3103: __ inccc(count, 6); // restore count kvn@1799: __ brx(Assembler::negative, false, Assembler::pn, L_copy_8_bytes ); kvn@1799: __ delayed()->add(offset0, 8, offset8); kvn@1799: kvn@1799: // Copy by 16 bytes chunks kvn@1800: __ align(OptoLoopAlignment); duke@435: __ BIND(L_copy_16_bytes); duke@435: __ ldx(from, offset0, O3); duke@435: __ ldx(from, offset8, G3); duke@435: __ deccc(count, 2); duke@435: __ stx(O3, to, offset0); duke@435: __ inc(offset0, 16); duke@435: __ stx(G3, to, offset8); duke@435: __ brx(Assembler::greaterEqual, false, Assembler::pt, L_copy_16_bytes); duke@435: __ delayed()->inc(offset8, 16); duke@435: kvn@1799: // Copy last 8 bytes duke@435: __ BIND(L_copy_8_bytes); duke@435: __ inccc(count, 2); duke@435: __ brx(Assembler::zero, true, Assembler::pn, L_exit ); duke@435: __ delayed()->mov(offset0, offset8); // Set O5 used by other stubs duke@435: __ ldx(from, offset0, O3); duke@435: __ stx(O3, to, offset0); duke@435: __ BIND(L_exit); duke@435: } duke@435: duke@435: // duke@435: // Generate stub for disjoint long copy. duke@435: // "aligned" is ignored, because we must make the stronger duke@435: // assumption that both addresses are always 64-bit aligned. duke@435: // duke@435: // Arguments for generated stub: duke@435: // from: O0 duke@435: // to: O1 duke@435: // count: O2 treated as signed duke@435: // iveresov@2595: address generate_disjoint_long_copy(bool aligned, 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: assert_clean_int(O2, O3); // Make sure 'count' is clean int. duke@435: iveresov@2595: if (entry != NULL) { iveresov@2595: *entry = __ pc(); iveresov@2595: // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) iveresov@2595: BLOCK_COMMENT("Entry:"); iveresov@2595: } duke@435: duke@435: generate_disjoint_long_copy_core(aligned); duke@435: duke@435: // O3, O4 are used as temp registers duke@435: inc_counter_np(SharedRuntime::_jlong_array_copy_ctr, O3, O4); duke@435: __ retl(); duke@435: __ delayed()->mov(G0, O0); // return 0 duke@435: return start; duke@435: } duke@435: duke@435: // duke@435: // Generate core code for conjoint long copy (and oop copy on 64-bit). duke@435: // "aligned" is ignored, because we must make the stronger duke@435: // assumption that both addresses are always 64-bit aligned. duke@435: // duke@435: // Arguments: duke@435: // from: O0 duke@435: // to: O1 duke@435: // count: O2 treated as signed duke@435: // duke@435: void generate_conjoint_long_copy_core(bool aligned) { duke@435: // Do reverse copy. duke@435: Label L_copy_8_bytes, L_copy_16_bytes, L_exit; duke@435: const Register from = O0; // source array address duke@435: const Register to = O1; // destination array address duke@435: const Register count = O2; // elements count duke@435: const Register offset8 = O4; // element offset duke@435: const Register offset0 = O5; // previous element offset duke@435: duke@435: __ subcc(count, 1, count); duke@435: __ brx(Assembler::lessEqual, false, Assembler::pn, L_copy_8_bytes ); duke@435: __ delayed()->sllx(count, LogBytesPerLong, offset8); duke@435: __ sub(offset8, 8, offset0); kvn@1800: __ align(OptoLoopAlignment); duke@435: __ BIND(L_copy_16_bytes); duke@435: __ ldx(from, offset8, O2); duke@435: __ ldx(from, offset0, O3); duke@435: __ stx(O2, to, offset8); duke@435: __ deccc(offset8, 16); // use offset8 as counter duke@435: __ stx(O3, to, offset0); duke@435: __ brx(Assembler::greater, false, Assembler::pt, L_copy_16_bytes); duke@435: __ delayed()->dec(offset0, 16); duke@435: duke@435: __ BIND(L_copy_8_bytes); duke@435: __ brx(Assembler::negative, false, Assembler::pn, L_exit ); duke@435: __ delayed()->nop(); duke@435: __ ldx(from, 0, O3); duke@435: __ stx(O3, to, 0); duke@435: __ BIND(L_exit); duke@435: } duke@435: duke@435: // Generate stub for conjoint long copy. duke@435: // "aligned" is ignored, because we must make the stronger duke@435: // assumption that both addresses are always 64-bit aligned. duke@435: // duke@435: // Arguments for generated stub: duke@435: // from: O0 duke@435: // to: O1 duke@435: // count: O2 treated as signed duke@435: // iveresov@2595: address generate_conjoint_long_copy(bool aligned, address nooverlap_target, iveresov@2595: address *entry, const char *name) { duke@435: __ align(CodeEntryAlignment); duke@435: StubCodeMark mark(this, "StubRoutines", name); duke@435: address start = __ pc(); duke@435: iveresov@2606: assert(aligned, "Should always be aligned"); duke@435: duke@435: assert_clean_int(O2, O3); // Make sure 'count' is clean int. duke@435: iveresov@2595: if (entry != NULL) { iveresov@2595: *entry = __ pc(); iveresov@2595: // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) iveresov@2595: BLOCK_COMMENT("Entry:"); iveresov@2595: } duke@435: duke@435: array_overlap_test(nooverlap_target, 3); duke@435: duke@435: generate_conjoint_long_copy_core(aligned); duke@435: duke@435: // O3, O4 are used as temp registers duke@435: inc_counter_np(SharedRuntime::_jlong_array_copy_ctr, O3, O4); duke@435: __ retl(); duke@435: __ delayed()->mov(G0, O0); // return 0 duke@435: return start; duke@435: } duke@435: duke@435: // Generate stub for disjoint oop copy. If "aligned" is true, the duke@435: // "from" and "to" addresses are assumed to be heapword aligned. duke@435: // duke@435: // Arguments for generated stub: duke@435: // from: O0 duke@435: // to: O1 duke@435: // count: O2 treated as signed duke@435: // iveresov@2606: address generate_disjoint_oop_copy(bool aligned, address *entry, const char *name, iveresov@2606: bool dest_uninitialized = false) { duke@435: duke@435: const Register from = O0; // source array address duke@435: const Register to = O1; // destination array address duke@435: const Register count = O2; // elements count duke@435: duke@435: __ align(CodeEntryAlignment); duke@435: StubCodeMark mark(this, "StubRoutines", name); duke@435: address start = __ pc(); duke@435: duke@435: assert_clean_int(count, O3); // Make sure 'count' is clean int. duke@435: iveresov@2595: if (entry != NULL) { iveresov@2595: *entry = __ pc(); iveresov@2595: // caller can pass a 64-bit byte count here iveresov@2595: BLOCK_COMMENT("Entry:"); iveresov@2595: } duke@435: duke@435: // save arguments for barrier generation duke@435: __ mov(to, G1); duke@435: __ mov(count, G5); iveresov@2606: gen_write_ref_array_pre_barrier(G1, G5, dest_uninitialized); duke@435: #ifdef _LP64 coleenp@548: assert_clean_int(count, O3); // Make sure 'count' is clean int. coleenp@548: if (UseCompressedOops) { coleenp@548: generate_disjoint_int_copy_core(aligned); coleenp@548: } else { coleenp@548: generate_disjoint_long_copy_core(aligned); coleenp@548: } duke@435: #else duke@435: generate_disjoint_int_copy_core(aligned); duke@435: #endif duke@435: // O0 is used as temp register duke@435: gen_write_ref_array_post_barrier(G1, G5, O0); duke@435: duke@435: // O3, O4 are used as temp registers duke@435: inc_counter_np(SharedRuntime::_oop_array_copy_ctr, O3, O4); duke@435: __ retl(); duke@435: __ delayed()->mov(G0, O0); // return 0 duke@435: return start; duke@435: } duke@435: duke@435: // Generate stub for conjoint oop copy. If "aligned" is true, the duke@435: // "from" and "to" addresses are assumed to be heapword aligned. duke@435: // duke@435: // Arguments for generated stub: duke@435: // from: O0 duke@435: // to: O1 duke@435: // count: O2 treated as signed duke@435: // iveresov@2595: address generate_conjoint_oop_copy(bool aligned, address nooverlap_target, iveresov@2606: address *entry, const char *name, iveresov@2606: bool dest_uninitialized = false) { duke@435: duke@435: const Register from = O0; // source array address duke@435: const Register to = O1; // destination array address duke@435: const Register count = O2; // elements count duke@435: duke@435: __ align(CodeEntryAlignment); duke@435: StubCodeMark mark(this, "StubRoutines", name); duke@435: address start = __ pc(); duke@435: duke@435: assert_clean_int(count, O3); // Make sure 'count' is clean int. duke@435: iveresov@2595: if (entry != NULL) { iveresov@2595: *entry = __ pc(); iveresov@2595: // caller can pass a 64-bit byte count here iveresov@2595: BLOCK_COMMENT("Entry:"); iveresov@2595: } iveresov@2595: iveresov@2595: array_overlap_test(nooverlap_target, LogBytesPerHeapOop); duke@435: duke@435: // save arguments for barrier generation duke@435: __ mov(to, G1); duke@435: __ mov(count, G5); iveresov@2606: gen_write_ref_array_pre_barrier(G1, G5, dest_uninitialized); duke@435: duke@435: #ifdef _LP64 coleenp@548: if (UseCompressedOops) { coleenp@548: generate_conjoint_int_copy_core(aligned); coleenp@548: } else { coleenp@548: generate_conjoint_long_copy_core(aligned); coleenp@548: } duke@435: #else duke@435: generate_conjoint_int_copy_core(aligned); duke@435: #endif duke@435: duke@435: // O0 is used as temp register duke@435: gen_write_ref_array_post_barrier(G1, G5, O0); duke@435: duke@435: // O3, O4 are used as temp registers duke@435: inc_counter_np(SharedRuntime::_oop_array_copy_ctr, O3, O4); duke@435: __ retl(); duke@435: __ delayed()->mov(G0, O0); // return 0 duke@435: return start; duke@435: } duke@435: duke@435: duke@435: // Helper for generating a dynamic type check. duke@435: // Smashes only the given temp registers. duke@435: void generate_type_check(Register sub_klass, duke@435: Register super_check_offset, duke@435: Register super_klass, duke@435: Register temp, jrose@1079: Label& L_success) { duke@435: assert_different_registers(sub_klass, super_check_offset, super_klass, temp); duke@435: duke@435: BLOCK_COMMENT("type_check:"); duke@435: jrose@1079: Label L_miss, L_pop_to_miss; duke@435: duke@435: assert_clean_int(super_check_offset, temp); duke@435: jrose@1079: __ check_klass_subtype_fast_path(sub_klass, super_klass, temp, noreg, jrose@1079: &L_success, &L_miss, NULL, jrose@1079: super_check_offset); jrose@1079: jrose@1079: BLOCK_COMMENT("type_check_slow_path:"); duke@435: __ save_frame(0); jrose@1079: __ check_klass_subtype_slow_path(sub_klass->after_save(), jrose@1079: super_klass->after_save(), jrose@1079: L0, L1, L2, L4, jrose@1079: NULL, &L_pop_to_miss); kvn@3037: __ ba(L_success); jrose@1079: __ delayed()->restore(); jrose@1079: jrose@1079: __ bind(L_pop_to_miss); duke@435: __ restore(); duke@435: duke@435: // Fall through on failure! duke@435: __ BIND(L_miss); duke@435: } duke@435: duke@435: duke@435: // Generate stub for checked oop copy. duke@435: // duke@435: // Arguments for generated stub: duke@435: // from: O0 duke@435: // to: O1 duke@435: // count: O2 treated as signed duke@435: // ckoff: O3 (super_check_offset) duke@435: // ckval: O4 (super_klass) duke@435: // ret: O0 zero for success; (-1^K) 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: duke@435: const Register O0_from = O0; // source array address duke@435: const Register O1_to = O1; // destination array address duke@435: const Register O2_count = O2; // elements count duke@435: const Register O3_ckoff = O3; // super_check_offset duke@435: const Register O4_ckval = O4; // super_klass duke@435: duke@435: const Register O5_offset = O5; // loop var, with stride wordSize duke@435: const Register G1_remain = G1; // loop var, with stride -1 duke@435: const Register G3_oop = G3; // actual oop copied duke@435: const Register G4_klass = G4; // oop._klass duke@435: const Register G5_super = G5; // oop._klass._primary_supers[ckval] duke@435: duke@435: __ align(CodeEntryAlignment); duke@435: StubCodeMark mark(this, "StubRoutines", name); duke@435: address start = __ pc(); duke@435: duke@435: #ifdef ASSERT jrose@1079: // We sometimes save a frame (see generate_type_check below). duke@435: // If this will cause trouble, let's fail now instead of later. duke@435: __ save_frame(0); duke@435: __ restore(); duke@435: #endif duke@435: never@2199: assert_clean_int(O2_count, G1); // Make sure 'count' is clean int. never@2199: duke@435: #ifdef ASSERT duke@435: // caller guarantees that the arrays really are different duke@435: // otherwise, we would have to make conjoint checks duke@435: { Label L; duke@435: __ mov(O3, G1); // spill: overlap test smashes O3 duke@435: __ mov(O4, G4); // spill: overlap test smashes O4 coleenp@548: array_overlap_test(L, LogBytesPerHeapOop); duke@435: __ stop("checkcast_copy within a single array"); duke@435: __ bind(L); duke@435: __ mov(G1, O3); duke@435: __ mov(G4, O4); duke@435: } duke@435: #endif //ASSERT duke@435: iveresov@2595: if (entry != NULL) { iveresov@2595: *entry = __ pc(); iveresov@2595: // caller can pass a 64-bit byte count here (from generic stub) iveresov@2595: BLOCK_COMMENT("Entry:"); iveresov@2595: } iveresov@2606: gen_write_ref_array_pre_barrier(O1_to, O2_count, dest_uninitialized); duke@435: duke@435: Label load_element, store_element, do_card_marks, fail, done; duke@435: __ addcc(O2_count, 0, G1_remain); // initialize loop index, and test it duke@435: __ brx(Assembler::notZero, false, Assembler::pt, load_element); duke@435: __ delayed()->mov(G0, O5_offset); // offset from start of arrays duke@435: duke@435: // Empty array: Nothing to do. duke@435: inc_counter_np(SharedRuntime::_checkcast_array_copy_ctr, O3, O4); duke@435: __ retl(); duke@435: __ delayed()->set(0, O0); // return 0 on (trivial) success duke@435: duke@435: // ======== begin loop ======== duke@435: // (Loop is rotated; its entry is load_element.) duke@435: // Loop variables: duke@435: // (O5 = 0; ; O5 += wordSize) --- offset from src, dest arrays duke@435: // (O2 = len; O2 != 0; O2--) --- number of oops *remaining* duke@435: // G3, G4, G5 --- current oop, oop.klass, oop.klass.super kvn@1800: __ align(OptoLoopAlignment); duke@435: jrose@1079: __ BIND(store_element); jrose@1079: __ deccc(G1_remain); // decrement the count coleenp@548: __ store_heap_oop(G3_oop, O1_to, O5_offset); // store the oop coleenp@548: __ inc(O5_offset, heapOopSize); // step to next offset duke@435: __ brx(Assembler::zero, true, Assembler::pt, do_card_marks); duke@435: __ delayed()->set(0, O0); // return -1 on success duke@435: duke@435: // ======== loop entry is here ======== jrose@1079: __ BIND(load_element); coleenp@548: __ load_heap_oop(O0_from, O5_offset, G3_oop); // load the oop kvn@3037: __ br_null_short(G3_oop, Assembler::pt, store_element); duke@435: coleenp@548: __ load_klass(G3_oop, G4_klass); // query the object klass duke@435: duke@435: generate_type_check(G4_klass, O3_ckoff, O4_ckval, G5_super, duke@435: // branch to this on success: jrose@1079: store_element); duke@435: // ======== end loop ======== duke@435: duke@435: // It was a real error; we must depend on the caller to finish the job. duke@435: // Register G1 has number of *remaining* oops, O2 number of *total* oops. duke@435: // Emit GC store barriers for the oops we have copied (O2 minus G1), duke@435: // and report their number to the caller. jrose@1079: __ BIND(fail); duke@435: __ subcc(O2_count, G1_remain, O2_count); duke@435: __ brx(Assembler::zero, false, Assembler::pt, done); duke@435: __ delayed()->not1(O2_count, O0); // report (-1^K) to caller duke@435: jrose@1079: __ BIND(do_card_marks); duke@435: gen_write_ref_array_post_barrier(O1_to, O2_count, O3); // store check on O1[0..O2] duke@435: jrose@1079: __ BIND(done); duke@435: inc_counter_np(SharedRuntime::_checkcast_array_copy_ctr, O3, O4); duke@435: __ retl(); duke@435: __ delayed()->nop(); // return value in 00 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: // Arguments for generated stub: duke@435: // from: O0 duke@435: // to: O1 duke@435: // count: O2 byte count, treated as ssize_t, can be zero 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: // iveresov@2595: address generate_unsafe_copy(const char* name, iveresov@2595: address byte_copy_entry, iveresov@2595: address short_copy_entry, iveresov@2595: address int_copy_entry, iveresov@2595: address long_copy_entry) { duke@435: duke@435: const Register O0_from = O0; // source array address duke@435: const Register O1_to = O1; // destination array address duke@435: const Register O2_count = O2; // elements count duke@435: duke@435: const Register G1_bits = G1; // test copy of low bits duke@435: duke@435: __ align(CodeEntryAlignment); duke@435: StubCodeMark mark(this, "StubRoutines", name); duke@435: address start = __ pc(); duke@435: duke@435: // bump this on entry, not on exit: duke@435: inc_counter_np(SharedRuntime::_unsafe_array_copy_ctr, G1, G3); duke@435: duke@435: __ or3(O0_from, O1_to, G1_bits); duke@435: __ or3(O2_count, G1_bits, G1_bits); duke@435: duke@435: __ btst(BytesPerLong-1, G1_bits); duke@435: __ br(Assembler::zero, true, Assembler::pt, duke@435: long_copy_entry, relocInfo::runtime_call_type); duke@435: // scale the count on the way out: duke@435: __ delayed()->srax(O2_count, LogBytesPerLong, O2_count); duke@435: duke@435: __ btst(BytesPerInt-1, G1_bits); duke@435: __ br(Assembler::zero, true, Assembler::pt, duke@435: int_copy_entry, relocInfo::runtime_call_type); duke@435: // scale the count on the way out: duke@435: __ delayed()->srax(O2_count, LogBytesPerInt, O2_count); duke@435: duke@435: __ btst(BytesPerShort-1, G1_bits); duke@435: __ br(Assembler::zero, true, Assembler::pt, duke@435: short_copy_entry, relocInfo::runtime_call_type); duke@435: // scale the count on the way out: duke@435: __ delayed()->srax(O2_count, LogBytesPerShort, O2_count); duke@435: duke@435: __ br(Assembler::always, false, Assembler::pt, duke@435: byte_copy_entry, relocInfo::runtime_call_type); duke@435: __ delayed()->nop(); duke@435: duke@435: return start; duke@435: } duke@435: duke@435: duke@435: // Perform range checks on the proposed arraycopy. duke@435: // Kills the two temps, but nothing else. duke@435: // Also, clean the sign bits of src_pos and dst_pos. duke@435: void arraycopy_range_checks(Register src, // source array oop (O0) duke@435: Register src_pos, // source position (O1) duke@435: Register dst, // destination array oo (O2) duke@435: Register dst_pos, // destination position (O3) duke@435: Register length, // length of copy (O4) duke@435: Register temp1, Register temp2, duke@435: Label& L_failed) { duke@435: BLOCK_COMMENT("arraycopy_range_checks:"); duke@435: duke@435: // if (src_pos + length > arrayOop(src)->length() ) FAIL; duke@435: duke@435: const Register array_length = temp1; // scratch duke@435: const Register end_pos = temp2; // scratch duke@435: duke@435: // Note: This next instruction may be in the delay slot of a branch: duke@435: __ add(length, src_pos, end_pos); // src_pos + length duke@435: __ lduw(src, arrayOopDesc::length_offset_in_bytes(), array_length); duke@435: __ cmp(end_pos, array_length); duke@435: __ br(Assembler::greater, false, Assembler::pn, L_failed); duke@435: duke@435: // if (dst_pos + length > arrayOop(dst)->length() ) FAIL; duke@435: __ delayed()->add(length, dst_pos, end_pos); // dst_pos + length duke@435: __ lduw(dst, arrayOopDesc::length_offset_in_bytes(), array_length); duke@435: __ cmp(end_pos, array_length); duke@435: __ br(Assembler::greater, false, Assembler::pn, L_failed); duke@435: duke@435: // Have to clean up high 32-bits of 'src_pos' and 'dst_pos'. duke@435: // Move with sign extension can be used since they are positive. duke@435: __ delayed()->signx(src_pos, src_pos); duke@435: __ signx(dst_pos, dst_pos); 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: // O0 - src oop duke@435: // O1 - src_pos duke@435: // O2 - dst oop duke@435: // O3 - dst_pos duke@435: // O4 - element count duke@435: // duke@435: // Output: duke@435: // O0 == 0 - success duke@435: // O0 == -1 - need to call System.arraycopy duke@435: // iveresov@2595: address generate_generic_copy(const char *name, iveresov@2595: address entry_jbyte_arraycopy, iveresov@2595: address entry_jshort_arraycopy, iveresov@2595: address entry_jint_arraycopy, iveresov@2595: address entry_oop_arraycopy, iveresov@2595: address entry_jlong_arraycopy, iveresov@2595: address entry_checkcast_arraycopy) { duke@435: Label L_failed, L_objArray; duke@435: duke@435: // Input registers duke@435: const Register src = O0; // source array oop duke@435: const Register src_pos = O1; // source position duke@435: const Register dst = O2; // destination array oop duke@435: const Register dst_pos = O3; // destination position duke@435: const Register length = O4; // elements count duke@435: duke@435: // registers used as temp duke@435: const Register G3_src_klass = G3; // source array klass duke@435: const Register G4_dst_klass = G4; // destination array klass duke@435: const Register G5_lh = G5; // layout handler duke@435: const Register O5_temp = O5; duke@435: duke@435: __ align(CodeEntryAlignment); duke@435: StubCodeMark mark(this, "StubRoutines", name); duke@435: address start = __ pc(); duke@435: duke@435: // bump this on entry, not on exit: duke@435: inc_counter_np(SharedRuntime::_generic_array_copy_ctr, G1, G3); duke@435: duke@435: // In principle, the int arguments could be dirty. duke@435: //assert_clean_int(src_pos, G1); duke@435: //assert_clean_int(dst_pos, G1); duke@435: //assert_clean_int(length, G1); duke@435: duke@435: //----------------------------------------------------------------------- duke@435: // Assembler stubs 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: BLOCK_COMMENT("arraycopy initial argument checks"); duke@435: duke@435: // if (src == NULL) return -1; duke@435: __ br_null(src, false, Assembler::pn, L_failed); duke@435: duke@435: // if (src_pos < 0) return -1; duke@435: __ delayed()->tst(src_pos); duke@435: __ br(Assembler::negative, false, Assembler::pn, L_failed); duke@435: __ delayed()->nop(); duke@435: duke@435: // if (dst == NULL) return -1; duke@435: __ br_null(dst, false, Assembler::pn, L_failed); duke@435: duke@435: // if (dst_pos < 0) return -1; duke@435: __ delayed()->tst(dst_pos); duke@435: __ br(Assembler::negative, false, Assembler::pn, L_failed); duke@435: duke@435: // if (length < 0) return -1; duke@435: __ delayed()->tst(length); duke@435: __ br(Assembler::negative, false, Assembler::pn, L_failed); duke@435: duke@435: BLOCK_COMMENT("arraycopy argument klass checks"); duke@435: // get src->klass() coleenp@548: if (UseCompressedOops) { coleenp@548: __ delayed()->nop(); // ??? not good coleenp@548: __ load_klass(src, G3_src_klass); coleenp@548: } else { coleenp@548: __ delayed()->ld_ptr(src, oopDesc::klass_offset_in_bytes(), G3_src_klass); coleenp@548: } duke@435: duke@435: #ifdef ASSERT duke@435: // assert(src->klass() != NULL); duke@435: BLOCK_COMMENT("assert klasses not null"); duke@435: { Label L_a, L_b; kvn@3037: __ br_notnull_short(G3_src_klass, Assembler::pt, L_b); // it is broken if klass is NULL duke@435: __ bind(L_a); duke@435: __ stop("broken null klass"); duke@435: __ bind(L_b); coleenp@548: __ load_klass(dst, G4_dst_klass); duke@435: __ br_null(G4_dst_klass, false, Assembler::pn, L_a); // this would be broken also duke@435: __ delayed()->mov(G0, G4_dst_klass); // scribble the temp duke@435: BLOCK_COMMENT("assert done"); duke@435: } duke@435: #endif duke@435: duke@435: // Load layout helper 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: duke@435: // Load 32-bits signed value. Use br() instruction with it to check icc. duke@435: __ lduw(G3_src_klass, lh_offset, G5_lh); duke@435: coleenp@548: if (UseCompressedOops) { coleenp@548: __ load_klass(dst, G4_dst_klass); coleenp@548: } duke@435: // Handle objArrays completely differently... duke@435: juint objArray_lh = Klass::array_layout_helper(T_OBJECT); duke@435: __ set(objArray_lh, O5_temp); duke@435: __ cmp(G5_lh, O5_temp); duke@435: __ br(Assembler::equal, false, Assembler::pt, L_objArray); coleenp@548: if (UseCompressedOops) { coleenp@548: __ delayed()->nop(); coleenp@548: } else { coleenp@548: __ delayed()->ld_ptr(dst, oopDesc::klass_offset_in_bytes(), G4_dst_klass); coleenp@548: } duke@435: duke@435: // if (src->klass() != dst->klass()) return -1; kvn@3037: __ cmp_and_brx_short(G3_src_klass, G4_dst_klass, Assembler::notEqual, Assembler::pn, L_failed); duke@435: duke@435: // if (!src->is_Array()) return -1; duke@435: __ cmp(G5_lh, Klass::_lh_neutral_value); // < 0 duke@435: __ br(Assembler::greaterEqual, false, Assembler::pn, L_failed); duke@435: duke@435: // At this point, it is known to be a typeArray (array_tag 0x3). duke@435: #ifdef ASSERT duke@435: __ delayed()->nop(); duke@435: { Label L; duke@435: jint lh_prim_tag_in_place = (Klass::_lh_array_tag_type_value << Klass::_lh_array_tag_shift); duke@435: __ set(lh_prim_tag_in_place, O5_temp); duke@435: __ cmp(G5_lh, O5_temp); duke@435: __ br(Assembler::greaterEqual, false, Assembler::pt, L); duke@435: __ delayed()->nop(); duke@435: __ stop("must be a primitive array"); duke@435: __ bind(L); duke@435: } duke@435: #else duke@435: __ delayed(); // match next insn to prev branch duke@435: #endif duke@435: duke@435: arraycopy_range_checks(src, src_pos, dst, dst_pos, length, duke@435: O5_temp, G4_dst_klass, 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: duke@435: const Register G4_offset = G4_dst_klass; // array offset duke@435: const Register G3_elsize = G3_src_klass; // log2 element size duke@435: duke@435: __ srl(G5_lh, Klass::_lh_header_size_shift, G4_offset); duke@435: __ and3(G4_offset, Klass::_lh_header_size_mask, G4_offset); // array_offset duke@435: __ add(src, G4_offset, src); // src array offset duke@435: __ add(dst, G4_offset, dst); // dst array offset duke@435: __ and3(G5_lh, Klass::_lh_log2_element_size_mask, G3_elsize); // log2 element size duke@435: duke@435: // next registers should be set before the jump to corresponding stub duke@435: const Register from = O0; // source array address duke@435: const Register to = O1; // destination array address duke@435: const Register count = O2; // elements count duke@435: duke@435: // 'from', 'to', 'count' registers should be set in this order duke@435: // since they are the same as 'src', 'src_pos', 'dst'. duke@435: duke@435: BLOCK_COMMENT("scale indexes to element size"); duke@435: __ sll_ptr(src_pos, G3_elsize, src_pos); duke@435: __ sll_ptr(dst_pos, G3_elsize, dst_pos); duke@435: __ add(src, src_pos, from); // src_addr duke@435: __ add(dst, dst_pos, to); // dst_addr duke@435: duke@435: BLOCK_COMMENT("choose copy loop based on element size"); duke@435: __ cmp(G3_elsize, 0); iveresov@2595: __ br(Assembler::equal, true, Assembler::pt, entry_jbyte_arraycopy); duke@435: __ delayed()->signx(length, count); // length duke@435: duke@435: __ cmp(G3_elsize, LogBytesPerShort); iveresov@2595: __ br(Assembler::equal, true, Assembler::pt, entry_jshort_arraycopy); duke@435: __ delayed()->signx(length, count); // length duke@435: duke@435: __ cmp(G3_elsize, LogBytesPerInt); iveresov@2595: __ br(Assembler::equal, true, Assembler::pt, entry_jint_arraycopy); duke@435: __ delayed()->signx(length, count); // length duke@435: #ifdef ASSERT duke@435: { Label L; kvn@3037: __ cmp_and_br_short(G3_elsize, LogBytesPerLong, Assembler::equal, Assembler::pt, L); duke@435: __ stop("must be long copy, but elsize is wrong"); duke@435: __ bind(L); duke@435: } duke@435: #endif iveresov@2595: __ br(Assembler::always, false, Assembler::pt, entry_jlong_arraycopy); duke@435: __ delayed()->signx(length, count); // length duke@435: duke@435: // objArrayKlass duke@435: __ BIND(L_objArray); duke@435: // live at this point: G3_src_klass, G4_dst_klass, src[_pos], dst[_pos], length duke@435: duke@435: Label L_plain_copy, L_checkcast_copy; duke@435: // test array classes for subtyping duke@435: __ cmp(G3_src_klass, G4_dst_klass); // usual case is exact equality duke@435: __ brx(Assembler::notEqual, true, Assembler::pn, L_checkcast_copy); duke@435: __ delayed()->lduw(G4_dst_klass, lh_offset, O5_temp); // hoisted from below duke@435: duke@435: // Identically typed arrays can be copied without element-wise checks. duke@435: arraycopy_range_checks(src, src_pos, dst, dst_pos, length, duke@435: O5_temp, G5_lh, L_failed); duke@435: duke@435: __ add(src, arrayOopDesc::base_offset_in_bytes(T_OBJECT), src); //src offset duke@435: __ add(dst, arrayOopDesc::base_offset_in_bytes(T_OBJECT), dst); //dst offset coleenp@548: __ sll_ptr(src_pos, LogBytesPerHeapOop, src_pos); coleenp@548: __ sll_ptr(dst_pos, LogBytesPerHeapOop, dst_pos); duke@435: __ add(src, src_pos, from); // src_addr duke@435: __ add(dst, dst_pos, to); // dst_addr duke@435: __ BIND(L_plain_copy); iveresov@2595: __ br(Assembler::always, false, Assembler::pt, entry_oop_arraycopy); duke@435: __ delayed()->signx(length, count); // length duke@435: duke@435: __ BIND(L_checkcast_copy); duke@435: // live at this point: G3_src_klass, G4_dst_klass duke@435: { duke@435: // Before looking at dst.length, make sure dst is also an objArray. duke@435: // lduw(G4_dst_klass, lh_offset, O5_temp); // hoisted to delay slot duke@435: __ cmp(G5_lh, O5_temp); duke@435: __ br(Assembler::notEqual, false, Assembler::pn, L_failed); duke@435: duke@435: // It is safe to examine both src.length and dst.length. duke@435: __ delayed(); // match next insn to prev branch duke@435: arraycopy_range_checks(src, src_pos, dst, dst_pos, length, duke@435: O5_temp, G5_lh, L_failed); duke@435: duke@435: // Marshal the base address arguments now, freeing registers. duke@435: __ add(src, arrayOopDesc::base_offset_in_bytes(T_OBJECT), src); //src offset duke@435: __ add(dst, arrayOopDesc::base_offset_in_bytes(T_OBJECT), dst); //dst offset coleenp@548: __ sll_ptr(src_pos, LogBytesPerHeapOop, src_pos); coleenp@548: __ sll_ptr(dst_pos, LogBytesPerHeapOop, dst_pos); duke@435: __ add(src, src_pos, from); // src_addr duke@435: __ add(dst, dst_pos, to); // dst_addr duke@435: __ signx(length, count); // length (reloaded) duke@435: duke@435: Register sco_temp = O3; // this register is free now duke@435: assert_different_registers(from, to, count, sco_temp, duke@435: G4_dst_klass, G3_src_klass); duke@435: duke@435: // Generate the type check. stefank@3391: int sco_offset = in_bytes(Klass::super_check_offset_offset()); duke@435: __ lduw(G4_dst_klass, sco_offset, sco_temp); duke@435: generate_type_check(G3_src_klass, sco_temp, G4_dst_klass, duke@435: O5_temp, L_plain_copy); duke@435: duke@435: // Fetch destination element klass from the objArrayKlass header. stefank@3391: int ek_offset = in_bytes(objArrayKlass::element_klass_offset()); duke@435: duke@435: // the checkcast_copy loop needs two extra arguments: duke@435: __ ld_ptr(G4_dst_klass, ek_offset, O4); // dest elem klass duke@435: // lduw(O4, sco_offset, O3); // sco of elem klass duke@435: iveresov@2595: __ br(Assembler::always, false, Assembler::pt, entry_checkcast_arraycopy); duke@435: __ delayed()->lduw(O4, sco_offset, O3); duke@435: } duke@435: duke@435: __ BIND(L_failed); duke@435: __ retl(); duke@435: __ delayed()->sub(G0, 1, O0); // return -1 duke@435: return start; duke@435: } duke@435: kvn@3092: // kvn@3092: // Generate stub for heap zeroing. kvn@3092: // "to" address is aligned to jlong (8 bytes). kvn@3092: // kvn@3092: // Arguments for generated stub: kvn@3092: // to: O0 kvn@3092: // count: O1 treated as signed (count of HeapWord) kvn@3092: // count could be 0 kvn@3092: // kvn@3092: address generate_zero_aligned_words(const char* name) { kvn@3092: __ align(CodeEntryAlignment); kvn@3092: StubCodeMark mark(this, "StubRoutines", name); kvn@3092: address start = __ pc(); kvn@3092: kvn@3092: const Register to = O0; // source array address kvn@3092: const Register count = O1; // HeapWords count kvn@3092: const Register temp = O2; // scratch kvn@3092: kvn@3092: Label Ldone; kvn@3092: __ sllx(count, LogHeapWordSize, count); // to bytes count kvn@3092: // Use BIS for zeroing kvn@3092: __ bis_zeroing(to, count, temp, Ldone); kvn@3092: __ bind(Ldone); kvn@3092: __ retl(); kvn@3092: __ delayed()->nop(); kvn@3092: return start; kvn@3092: } kvn@3092: duke@435: void generate_arraycopy_stubs() { iveresov@2595: address entry; iveresov@2595: address entry_jbyte_arraycopy; iveresov@2595: address entry_jshort_arraycopy; iveresov@2595: address entry_jint_arraycopy; iveresov@2595: address entry_oop_arraycopy; iveresov@2595: address entry_jlong_arraycopy; iveresov@2595: address entry_checkcast_arraycopy; iveresov@2595: iveresov@2606: //*** jbyte iveresov@2606: // Always need aligned and unaligned versions iveresov@2606: StubRoutines::_jbyte_disjoint_arraycopy = generate_disjoint_byte_copy(false, &entry, iveresov@2606: "jbyte_disjoint_arraycopy"); iveresov@2606: StubRoutines::_jbyte_arraycopy = generate_conjoint_byte_copy(false, entry, iveresov@2606: &entry_jbyte_arraycopy, iveresov@2606: "jbyte_arraycopy"); iveresov@2606: StubRoutines::_arrayof_jbyte_disjoint_arraycopy = generate_disjoint_byte_copy(true, &entry, iveresov@2606: "arrayof_jbyte_disjoint_arraycopy"); iveresov@2606: StubRoutines::_arrayof_jbyte_arraycopy = generate_conjoint_byte_copy(true, entry, NULL, iveresov@2606: "arrayof_jbyte_arraycopy"); iveresov@2606: iveresov@2606: //*** jshort iveresov@2606: // Always need aligned and unaligned versions iveresov@2606: StubRoutines::_jshort_disjoint_arraycopy = generate_disjoint_short_copy(false, &entry, iveresov@2606: "jshort_disjoint_arraycopy"); iveresov@2606: StubRoutines::_jshort_arraycopy = generate_conjoint_short_copy(false, entry, iveresov@2606: &entry_jshort_arraycopy, iveresov@2606: "jshort_arraycopy"); iveresov@2595: StubRoutines::_arrayof_jshort_disjoint_arraycopy = generate_disjoint_short_copy(true, &entry, iveresov@2595: "arrayof_jshort_disjoint_arraycopy"); iveresov@2595: StubRoutines::_arrayof_jshort_arraycopy = generate_conjoint_short_copy(true, entry, NULL, iveresov@2595: "arrayof_jshort_arraycopy"); iveresov@2595: iveresov@2606: //*** jint iveresov@2606: // Aligned versions iveresov@2606: StubRoutines::_arrayof_jint_disjoint_arraycopy = generate_disjoint_int_copy(true, &entry, iveresov@2606: "arrayof_jint_disjoint_arraycopy"); iveresov@2606: StubRoutines::_arrayof_jint_arraycopy = generate_conjoint_int_copy(true, entry, &entry_jint_arraycopy, iveresov@2606: "arrayof_jint_arraycopy"); duke@435: #ifdef _LP64 iveresov@2606: // In 64 bit we need both aligned and unaligned versions of jint arraycopy. iveresov@2606: // entry_jint_arraycopy always points to the unaligned version (notice that we overwrite it). iveresov@2606: StubRoutines::_jint_disjoint_arraycopy = generate_disjoint_int_copy(false, &entry, iveresov@2606: "jint_disjoint_arraycopy"); iveresov@2606: StubRoutines::_jint_arraycopy = generate_conjoint_int_copy(false, entry, iveresov@2606: &entry_jint_arraycopy, iveresov@2606: "jint_arraycopy"); iveresov@2606: #else iveresov@2606: // In 32 bit jints are always HeapWordSize aligned, so always use the aligned version iveresov@2606: // (in fact in 32bit we always have a pre-loop part even in the aligned version, iveresov@2606: // because it uses 64-bit loads/stores, so the aligned flag is actually ignored). iveresov@2606: StubRoutines::_jint_disjoint_arraycopy = StubRoutines::_arrayof_jint_disjoint_arraycopy; iveresov@2606: StubRoutines::_jint_arraycopy = StubRoutines::_arrayof_jint_arraycopy; duke@435: #endif iveresov@2595: iveresov@2606: iveresov@2606: //*** jlong iveresov@2606: // It is always aligned iveresov@2606: StubRoutines::_arrayof_jlong_disjoint_arraycopy = generate_disjoint_long_copy(true, &entry, iveresov@2606: "arrayof_jlong_disjoint_arraycopy"); iveresov@2606: StubRoutines::_arrayof_jlong_arraycopy = generate_conjoint_long_copy(true, entry, &entry_jlong_arraycopy, iveresov@2606: "arrayof_jlong_arraycopy"); iveresov@2606: StubRoutines::_jlong_disjoint_arraycopy = StubRoutines::_arrayof_jlong_disjoint_arraycopy; iveresov@2606: StubRoutines::_jlong_arraycopy = StubRoutines::_arrayof_jlong_arraycopy; iveresov@2606: iveresov@2606: iveresov@2606: //*** oops iveresov@2606: // Aligned versions iveresov@2606: StubRoutines::_arrayof_oop_disjoint_arraycopy = generate_disjoint_oop_copy(true, &entry, iveresov@2606: "arrayof_oop_disjoint_arraycopy"); iveresov@2606: StubRoutines::_arrayof_oop_arraycopy = generate_conjoint_oop_copy(true, entry, &entry_oop_arraycopy, iveresov@2606: "arrayof_oop_arraycopy"); iveresov@2606: // Aligned versions without pre-barriers iveresov@2606: StubRoutines::_arrayof_oop_disjoint_arraycopy_uninit = generate_disjoint_oop_copy(true, &entry, iveresov@2606: "arrayof_oop_disjoint_arraycopy_uninit", iveresov@2606: /*dest_uninitialized*/true); iveresov@2606: StubRoutines::_arrayof_oop_arraycopy_uninit = generate_conjoint_oop_copy(true, entry, NULL, iveresov@2606: "arrayof_oop_arraycopy_uninit", iveresov@2606: /*dest_uninitialized*/true); iveresov@2606: #ifdef _LP64 iveresov@2606: if (UseCompressedOops) { iveresov@2606: // With compressed oops we need unaligned versions, notice that we overwrite entry_oop_arraycopy. iveresov@2606: StubRoutines::_oop_disjoint_arraycopy = generate_disjoint_oop_copy(false, &entry, iveresov@2606: "oop_disjoint_arraycopy"); iveresov@2606: StubRoutines::_oop_arraycopy = generate_conjoint_oop_copy(false, entry, &entry_oop_arraycopy, iveresov@2606: "oop_arraycopy"); iveresov@2606: // Unaligned versions without pre-barriers iveresov@2606: StubRoutines::_oop_disjoint_arraycopy_uninit = generate_disjoint_oop_copy(false, &entry, iveresov@2606: "oop_disjoint_arraycopy_uninit", iveresov@2606: /*dest_uninitialized*/true); iveresov@2606: StubRoutines::_oop_arraycopy_uninit = generate_conjoint_oop_copy(false, entry, NULL, iveresov@2606: "oop_arraycopy_uninit", iveresov@2606: /*dest_uninitialized*/true); iveresov@2606: } else iveresov@2606: #endif iveresov@2606: { iveresov@2606: // oop arraycopy is always aligned on 32bit and 64bit without compressed oops iveresov@2606: StubRoutines::_oop_disjoint_arraycopy = StubRoutines::_arrayof_oop_disjoint_arraycopy; iveresov@2606: StubRoutines::_oop_arraycopy = StubRoutines::_arrayof_oop_arraycopy; iveresov@2606: StubRoutines::_oop_disjoint_arraycopy_uninit = StubRoutines::_arrayof_oop_disjoint_arraycopy_uninit; iveresov@2606: StubRoutines::_oop_arraycopy_uninit = StubRoutines::_arrayof_oop_arraycopy_uninit; iveresov@2606: } iveresov@2606: iveresov@2606: StubRoutines::_checkcast_arraycopy = generate_checkcast_copy("checkcast_arraycopy", &entry_checkcast_arraycopy); iveresov@2606: StubRoutines::_checkcast_arraycopy_uninit = generate_checkcast_copy("checkcast_arraycopy_uninit", NULL, iveresov@2606: /*dest_uninitialized*/true); iveresov@2606: iveresov@2595: StubRoutines::_unsafe_arraycopy = generate_unsafe_copy("unsafe_arraycopy", iveresov@2595: entry_jbyte_arraycopy, iveresov@2595: entry_jshort_arraycopy, iveresov@2595: entry_jint_arraycopy, iveresov@2595: entry_jlong_arraycopy); iveresov@2595: StubRoutines::_generic_arraycopy = generate_generic_copy("generic_arraycopy", iveresov@2595: entry_jbyte_arraycopy, iveresov@2595: entry_jshort_arraycopy, iveresov@2595: entry_jint_arraycopy, iveresov@2595: entry_oop_arraycopy, iveresov@2595: entry_jlong_arraycopy, iveresov@2595: entry_checkcast_arraycopy); never@2118: 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"); kvn@3092: kvn@3092: if (UseBlockZeroing) { kvn@3092: StubRoutines::_zero_aligned_words = generate_zero_aligned_words("zero_aligned_words"); kvn@3092: } duke@435: } 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 = generate_call_stub(StubRoutines::_call_stub_return_address); duke@435: StubRoutines::_catch_exception_entry = generate_catch_exception(); duke@435: duke@435: //------------------------------------------------------------------------------------------------------------------------ duke@435: // entry points that are platform specific duke@435: StubRoutines::Sparc::_test_stop_entry = generate_test_stop(); duke@435: duke@435: StubRoutines::Sparc::_stop_subroutine_entry = generate_stop_subroutine(); duke@435: StubRoutines::Sparc::_flush_callers_register_windows_entry = generate_flush_callers_register_windows(); duke@435: duke@435: #if !defined(COMPILER2) && !defined(_LP64) duke@435: StubRoutines::_atomic_xchg_entry = generate_atomic_xchg(); duke@435: StubRoutines::_atomic_cmpxchg_entry = generate_atomic_cmpxchg(); duke@435: StubRoutines::_atomic_add_entry = generate_atomic_add(); duke@435: StubRoutines::_atomic_xchg_ptr_entry = StubRoutines::_atomic_xchg_entry; duke@435: StubRoutines::_atomic_cmpxchg_ptr_entry = StubRoutines::_atomic_cmpxchg_entry; duke@435: StubRoutines::_atomic_cmpxchg_long_entry = generate_atomic_cmpxchg_long(); duke@435: StubRoutines::_atomic_add_ptr_entry = StubRoutines::_atomic_add_entry; duke@435: #endif // COMPILER2 !=> _LP64 never@2978: 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: kvn@1077: // Generate partial_subtype_check first here since its code depends on kvn@1077: // UseZeroBaseCompressedOops which is defined after heap initialization. kvn@1077: StubRoutines::Sparc::_partial_subtype_check = generate_partial_subtype_check(); duke@435: // These entry points require SharedInfo::stack0 to be set up in non-core builds 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: StubRoutines::_handler_for_unsafe_access_entry = duke@435: generate_handler_for_unsafe_access(); duke@435: duke@435: // support for verify_oop (must happen after universe_init) duke@435: StubRoutines::_verify_oop_subroutine_entry = generate_verify_oop_subroutine(); duke@435: duke@435: // arraycopy stubs used by compilers duke@435: generate_arraycopy_stubs(); never@1609: never@1609: // Don't initialize the platform math functions since sparc never@1609: // doesn't have intrinsics for these operations. duke@435: } duke@435: duke@435: duke@435: public: duke@435: StubGenerator(CodeBuffer* code, bool all) : StubCodeGenerator(code) { duke@435: // replace the standard masm with a special one: duke@435: _masm = new MacroAssembler(code); duke@435: duke@435: _stub_count = !all ? 0x100 : 0x200; duke@435: if (all) { duke@435: generate_all(); duke@435: } else { duke@435: generate_initial(); duke@435: } duke@435: duke@435: // make sure this stub is available for all local calls duke@435: if (_atomic_add_stub.is_unbound()) { duke@435: // generate a second time, if necessary duke@435: (void) generate_atomic_add(); duke@435: } duke@435: } duke@435: duke@435: duke@435: private: duke@435: int _stub_count; duke@435: void stub_prolog(StubCodeDesc* cdesc) { duke@435: # ifdef ASSERT duke@435: // put extra information in the stub code, to make it more readable duke@435: #ifdef _LP64 duke@435: // Write the high part of the address duke@435: // [RGV] Check if there is a dependency on the size of this prolog duke@435: __ emit_data((intptr_t)cdesc >> 32, relocInfo::none); duke@435: #endif duke@435: __ emit_data((intptr_t)cdesc, relocInfo::none); duke@435: __ emit_data(++_stub_count, relocInfo::none); duke@435: # endif duke@435: align(true); duke@435: } duke@435: duke@435: void align(bool at_header = false) { duke@435: // %%%%% move this constant somewhere else duke@435: // UltraSPARC cache line size is 8 instructions: duke@435: const unsigned int icache_line_size = 32; duke@435: const unsigned int icache_half_line_size = 16; duke@435: duke@435: if (at_header) { duke@435: while ((intptr_t)(__ pc()) % icache_line_size != 0) { duke@435: __ emit_data(0, relocInfo::none); duke@435: } duke@435: } else { duke@435: while ((intptr_t)(__ pc()) % icache_half_line_size != 0) { duke@435: __ nop(); duke@435: } duke@435: } duke@435: } duke@435: duke@435: }; // end class declaration duke@435: duke@435: void StubGenerator_generate(CodeBuffer* code, bool all) { duke@435: StubGenerator g(code, all); duke@435: }