Thu, 05 Jun 2008 15:57:56 -0700
6711316: Open source the Garbage-First garbage collector
Summary: First mercurial integration of the code for the Garbage-First garbage collector.
Reviewed-by: apetrusenko, iveresov, jmasa, sgoldman, tonyp, ysr
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | #include "incls/_precompiled.incl" |
duke@435 | 26 | #include "incls/_stubGenerator_x86_32.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | // Declaration and definition of StubGenerator (no .hpp file). |
duke@435 | 29 | // For a more detailed description of the stub routine structure |
duke@435 | 30 | // see the comment in stubRoutines.hpp |
duke@435 | 31 | |
duke@435 | 32 | #define __ _masm-> |
duke@435 | 33 | |
duke@435 | 34 | #ifdef PRODUCT |
duke@435 | 35 | #define BLOCK_COMMENT(str) /* nothing */ |
duke@435 | 36 | #else |
duke@435 | 37 | #define BLOCK_COMMENT(str) __ block_comment(str) |
duke@435 | 38 | #endif |
duke@435 | 39 | |
duke@435 | 40 | #define BIND(label) bind(label); BLOCK_COMMENT(#label ":") |
duke@435 | 41 | |
duke@435 | 42 | const int MXCSR_MASK = 0xFFC0; // Mask out any pending exceptions |
duke@435 | 43 | const int FPU_CNTRL_WRD_MASK = 0xFFFF; |
duke@435 | 44 | |
duke@435 | 45 | // ------------------------------------------------------------------------------------------------------------------------- |
duke@435 | 46 | // Stub Code definitions |
duke@435 | 47 | |
duke@435 | 48 | static address handle_unsafe_access() { |
duke@435 | 49 | JavaThread* thread = JavaThread::current(); |
duke@435 | 50 | address pc = thread->saved_exception_pc(); |
duke@435 | 51 | // pc is the instruction which we must emulate |
duke@435 | 52 | // doing a no-op is fine: return garbage from the load |
duke@435 | 53 | // therefore, compute npc |
duke@435 | 54 | address npc = Assembler::locate_next_instruction(pc); |
duke@435 | 55 | |
duke@435 | 56 | // request an async exception |
duke@435 | 57 | thread->set_pending_unsafe_access_error(); |
duke@435 | 58 | |
duke@435 | 59 | // return address of next instruction to execute |
duke@435 | 60 | return npc; |
duke@435 | 61 | } |
duke@435 | 62 | |
duke@435 | 63 | class StubGenerator: public StubCodeGenerator { |
duke@435 | 64 | private: |
duke@435 | 65 | |
duke@435 | 66 | #ifdef PRODUCT |
duke@435 | 67 | #define inc_counter_np(counter) (0) |
duke@435 | 68 | #else |
duke@435 | 69 | void inc_counter_np_(int& counter) { |
duke@435 | 70 | __ increment(ExternalAddress((address)&counter)); |
duke@435 | 71 | } |
duke@435 | 72 | #define inc_counter_np(counter) \ |
duke@435 | 73 | BLOCK_COMMENT("inc_counter " #counter); \ |
duke@435 | 74 | inc_counter_np_(counter); |
duke@435 | 75 | #endif //PRODUCT |
duke@435 | 76 | |
duke@435 | 77 | void inc_copy_counter_np(BasicType t) { |
duke@435 | 78 | #ifndef PRODUCT |
duke@435 | 79 | switch (t) { |
duke@435 | 80 | case T_BYTE: inc_counter_np(SharedRuntime::_jbyte_array_copy_ctr); return; |
duke@435 | 81 | case T_SHORT: inc_counter_np(SharedRuntime::_jshort_array_copy_ctr); return; |
duke@435 | 82 | case T_INT: inc_counter_np(SharedRuntime::_jint_array_copy_ctr); return; |
duke@435 | 83 | case T_LONG: inc_counter_np(SharedRuntime::_jlong_array_copy_ctr); return; |
duke@435 | 84 | case T_OBJECT: inc_counter_np(SharedRuntime::_oop_array_copy_ctr); return; |
duke@435 | 85 | } |
duke@435 | 86 | ShouldNotReachHere(); |
duke@435 | 87 | #endif //PRODUCT |
duke@435 | 88 | } |
duke@435 | 89 | |
duke@435 | 90 | //------------------------------------------------------------------------------------------------------------------------ |
duke@435 | 91 | // Call stubs are used to call Java from C |
duke@435 | 92 | // |
duke@435 | 93 | // [ return_from_Java ] <--- rsp |
duke@435 | 94 | // [ argument word n ] |
duke@435 | 95 | // ... |
duke@435 | 96 | // -N [ argument word 1 ] |
duke@435 | 97 | // -7 [ Possible padding for stack alignment ] |
duke@435 | 98 | // -6 [ Possible padding for stack alignment ] |
duke@435 | 99 | // -5 [ Possible padding for stack alignment ] |
duke@435 | 100 | // -4 [ mxcsr save ] <--- rsp_after_call |
duke@435 | 101 | // -3 [ saved rbx, ] |
duke@435 | 102 | // -2 [ saved rsi ] |
duke@435 | 103 | // -1 [ saved rdi ] |
duke@435 | 104 | // 0 [ saved rbp, ] <--- rbp, |
duke@435 | 105 | // 1 [ return address ] |
duke@435 | 106 | // 2 [ ptr. to call wrapper ] |
duke@435 | 107 | // 3 [ result ] |
duke@435 | 108 | // 4 [ result_type ] |
duke@435 | 109 | // 5 [ method ] |
duke@435 | 110 | // 6 [ entry_point ] |
duke@435 | 111 | // 7 [ parameters ] |
duke@435 | 112 | // 8 [ parameter_size ] |
duke@435 | 113 | // 9 [ thread ] |
duke@435 | 114 | |
duke@435 | 115 | |
duke@435 | 116 | address generate_call_stub(address& return_address) { |
duke@435 | 117 | StubCodeMark mark(this, "StubRoutines", "call_stub"); |
duke@435 | 118 | address start = __ pc(); |
duke@435 | 119 | |
duke@435 | 120 | // stub code parameters / addresses |
duke@435 | 121 | assert(frame::entry_frame_call_wrapper_offset == 2, "adjust this code"); |
duke@435 | 122 | bool sse_save = false; |
duke@435 | 123 | const Address rsp_after_call(rbp, -4 * wordSize); // same as in generate_catch_exception()! |
duke@435 | 124 | const int locals_count_in_bytes (4*wordSize); |
duke@435 | 125 | const Address mxcsr_save (rbp, -4 * wordSize); |
duke@435 | 126 | const Address saved_rbx (rbp, -3 * wordSize); |
duke@435 | 127 | const Address saved_rsi (rbp, -2 * wordSize); |
duke@435 | 128 | const Address saved_rdi (rbp, -1 * wordSize); |
duke@435 | 129 | const Address result (rbp, 3 * wordSize); |
duke@435 | 130 | const Address result_type (rbp, 4 * wordSize); |
duke@435 | 131 | const Address method (rbp, 5 * wordSize); |
duke@435 | 132 | const Address entry_point (rbp, 6 * wordSize); |
duke@435 | 133 | const Address parameters (rbp, 7 * wordSize); |
duke@435 | 134 | const Address parameter_size(rbp, 8 * wordSize); |
duke@435 | 135 | const Address thread (rbp, 9 * wordSize); // same as in generate_catch_exception()! |
duke@435 | 136 | sse_save = UseSSE > 0; |
duke@435 | 137 | |
duke@435 | 138 | // stub code |
duke@435 | 139 | __ enter(); |
duke@435 | 140 | __ movl(rcx, parameter_size); // parameter counter |
duke@435 | 141 | __ shll(rcx, Interpreter::logStackElementSize()); // convert parameter count to bytes |
duke@435 | 142 | __ addl(rcx, locals_count_in_bytes); // reserve space for register saves |
duke@435 | 143 | __ subl(rsp, rcx); |
duke@435 | 144 | __ andl(rsp, -(StackAlignmentInBytes)); // Align stack |
duke@435 | 145 | |
duke@435 | 146 | // save rdi, rsi, & rbx, according to C calling conventions |
duke@435 | 147 | __ movl(saved_rdi, rdi); |
duke@435 | 148 | __ movl(saved_rsi, rsi); |
duke@435 | 149 | __ movl(saved_rbx, rbx); |
duke@435 | 150 | // save and initialize %mxcsr |
duke@435 | 151 | if (sse_save) { |
duke@435 | 152 | Label skip_ldmx; |
duke@435 | 153 | __ stmxcsr(mxcsr_save); |
duke@435 | 154 | __ movl(rax, mxcsr_save); |
duke@435 | 155 | __ andl(rax, MXCSR_MASK); // Only check control and mask bits |
duke@435 | 156 | ExternalAddress mxcsr_std(StubRoutines::addr_mxcsr_std()); |
duke@435 | 157 | __ cmp32(rax, mxcsr_std); |
duke@435 | 158 | __ jcc(Assembler::equal, skip_ldmx); |
duke@435 | 159 | __ ldmxcsr(mxcsr_std); |
duke@435 | 160 | __ bind(skip_ldmx); |
duke@435 | 161 | } |
duke@435 | 162 | |
duke@435 | 163 | // make sure the control word is correct. |
duke@435 | 164 | __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_std())); |
duke@435 | 165 | |
duke@435 | 166 | #ifdef ASSERT |
duke@435 | 167 | // make sure we have no pending exceptions |
duke@435 | 168 | { Label L; |
duke@435 | 169 | __ movl(rcx, thread); |
duke@435 | 170 | __ cmpl(Address(rcx, Thread::pending_exception_offset()), NULL_WORD); |
duke@435 | 171 | __ jcc(Assembler::equal, L); |
duke@435 | 172 | __ stop("StubRoutines::call_stub: entered with pending exception"); |
duke@435 | 173 | __ bind(L); |
duke@435 | 174 | } |
duke@435 | 175 | #endif |
duke@435 | 176 | |
duke@435 | 177 | // pass parameters if any |
duke@435 | 178 | BLOCK_COMMENT("pass parameters if any"); |
duke@435 | 179 | Label parameters_done; |
duke@435 | 180 | __ movl(rcx, parameter_size); // parameter counter |
duke@435 | 181 | __ testl(rcx, rcx); |
duke@435 | 182 | __ jcc(Assembler::zero, parameters_done); |
duke@435 | 183 | |
duke@435 | 184 | // parameter passing loop |
duke@435 | 185 | |
duke@435 | 186 | Label loop; |
duke@435 | 187 | // Copy Java parameters in reverse order (receiver last) |
duke@435 | 188 | // Note that the argument order is inverted in the process |
duke@435 | 189 | // source is rdx[rcx: N-1..0] |
duke@435 | 190 | // dest is rsp[rbx: 0..N-1] |
duke@435 | 191 | |
duke@435 | 192 | __ movl(rdx, parameters); // parameter pointer |
duke@435 | 193 | __ xorl(rbx, rbx); |
duke@435 | 194 | |
duke@435 | 195 | __ BIND(loop); |
duke@435 | 196 | if (TaggedStackInterpreter) { |
duke@435 | 197 | __ movl(rax, Address(rdx, rcx, Interpreter::stackElementScale(), |
duke@435 | 198 | -2*wordSize)); // get tag |
duke@435 | 199 | __ movl(Address(rsp, rbx, Interpreter::stackElementScale(), |
duke@435 | 200 | Interpreter::expr_tag_offset_in_bytes(0)), rax); // store tag |
duke@435 | 201 | } |
duke@435 | 202 | |
duke@435 | 203 | // get parameter |
duke@435 | 204 | __ movl(rax, Address(rdx, rcx, Interpreter::stackElementScale(), -wordSize)); |
duke@435 | 205 | __ movl(Address(rsp, rbx, Interpreter::stackElementScale(), |
duke@435 | 206 | Interpreter::expr_offset_in_bytes(0)), rax); // store parameter |
duke@435 | 207 | __ increment(rbx); |
duke@435 | 208 | __ decrement(rcx); |
duke@435 | 209 | __ jcc(Assembler::notZero, loop); |
duke@435 | 210 | |
duke@435 | 211 | // call Java function |
duke@435 | 212 | __ BIND(parameters_done); |
duke@435 | 213 | __ movl(rbx, method); // get methodOop |
duke@435 | 214 | __ movl(rax, entry_point); // get entry_point |
duke@435 | 215 | __ movl(rsi, rsp); // set sender sp |
duke@435 | 216 | BLOCK_COMMENT("call Java function"); |
duke@435 | 217 | __ call(rax); |
duke@435 | 218 | |
duke@435 | 219 | BLOCK_COMMENT("call_stub_return_address:"); |
duke@435 | 220 | return_address = __ pc(); |
duke@435 | 221 | |
duke@435 | 222 | Label common_return; |
duke@435 | 223 | |
duke@435 | 224 | __ BIND(common_return); |
duke@435 | 225 | |
duke@435 | 226 | // store result depending on type |
duke@435 | 227 | // (everything that is not T_LONG, T_FLOAT or T_DOUBLE is treated as T_INT) |
duke@435 | 228 | __ movl(rdi, result); |
duke@435 | 229 | Label is_long, is_float, is_double, exit; |
duke@435 | 230 | __ movl(rsi, result_type); |
duke@435 | 231 | __ cmpl(rsi, T_LONG); |
duke@435 | 232 | __ jcc(Assembler::equal, is_long); |
duke@435 | 233 | __ cmpl(rsi, T_FLOAT); |
duke@435 | 234 | __ jcc(Assembler::equal, is_float); |
duke@435 | 235 | __ cmpl(rsi, T_DOUBLE); |
duke@435 | 236 | __ jcc(Assembler::equal, is_double); |
duke@435 | 237 | |
duke@435 | 238 | // handle T_INT case |
duke@435 | 239 | __ movl(Address(rdi, 0), rax); |
duke@435 | 240 | __ BIND(exit); |
duke@435 | 241 | |
duke@435 | 242 | // check that FPU stack is empty |
duke@435 | 243 | __ verify_FPU(0, "generate_call_stub"); |
duke@435 | 244 | |
duke@435 | 245 | // pop parameters |
duke@435 | 246 | __ leal(rsp, rsp_after_call); |
duke@435 | 247 | |
duke@435 | 248 | // restore %mxcsr |
duke@435 | 249 | if (sse_save) { |
duke@435 | 250 | __ ldmxcsr(mxcsr_save); |
duke@435 | 251 | } |
duke@435 | 252 | |
duke@435 | 253 | // restore rdi, rsi and rbx, |
duke@435 | 254 | __ movl(rbx, saved_rbx); |
duke@435 | 255 | __ movl(rsi, saved_rsi); |
duke@435 | 256 | __ movl(rdi, saved_rdi); |
duke@435 | 257 | __ addl(rsp, 4*wordSize); |
duke@435 | 258 | |
duke@435 | 259 | // return |
duke@435 | 260 | __ popl(rbp); |
duke@435 | 261 | __ ret(0); |
duke@435 | 262 | |
duke@435 | 263 | // handle return types different from T_INT |
duke@435 | 264 | __ BIND(is_long); |
duke@435 | 265 | __ movl(Address(rdi, 0 * wordSize), rax); |
duke@435 | 266 | __ movl(Address(rdi, 1 * wordSize), rdx); |
duke@435 | 267 | __ jmp(exit); |
duke@435 | 268 | |
duke@435 | 269 | __ BIND(is_float); |
duke@435 | 270 | // interpreter uses xmm0 for return values |
duke@435 | 271 | if (UseSSE >= 1) { |
duke@435 | 272 | __ movflt(Address(rdi, 0), xmm0); |
duke@435 | 273 | } else { |
duke@435 | 274 | __ fstp_s(Address(rdi, 0)); |
duke@435 | 275 | } |
duke@435 | 276 | __ jmp(exit); |
duke@435 | 277 | |
duke@435 | 278 | __ BIND(is_double); |
duke@435 | 279 | // interpreter uses xmm0 for return values |
duke@435 | 280 | if (UseSSE >= 2) { |
duke@435 | 281 | __ movdbl(Address(rdi, 0), xmm0); |
duke@435 | 282 | } else { |
duke@435 | 283 | __ fstp_d(Address(rdi, 0)); |
duke@435 | 284 | } |
duke@435 | 285 | __ jmp(exit); |
duke@435 | 286 | |
duke@435 | 287 | // If we call compiled code directly from the call stub we will |
duke@435 | 288 | // need to adjust the return back to the call stub to a specialized |
duke@435 | 289 | // piece of code that can handle compiled results and cleaning the fpu |
duke@435 | 290 | // stack. compiled code will be set to return here instead of the |
duke@435 | 291 | // return above that handles interpreter returns. |
duke@435 | 292 | |
duke@435 | 293 | BLOCK_COMMENT("call_stub_compiled_return:"); |
duke@435 | 294 | StubRoutines::i486::set_call_stub_compiled_return( __ pc()); |
duke@435 | 295 | |
duke@435 | 296 | #ifdef COMPILER2 |
duke@435 | 297 | if (UseSSE >= 2) { |
duke@435 | 298 | __ verify_FPU(0, "call_stub_compiled_return"); |
duke@435 | 299 | } else { |
duke@435 | 300 | for (int i = 1; i < 8; i++) { |
duke@435 | 301 | __ ffree(i); |
duke@435 | 302 | } |
duke@435 | 303 | |
duke@435 | 304 | // UseSSE <= 1 so double result should be left on TOS |
duke@435 | 305 | __ movl(rsi, result_type); |
duke@435 | 306 | __ cmpl(rsi, T_DOUBLE); |
duke@435 | 307 | __ jcc(Assembler::equal, common_return); |
duke@435 | 308 | if (UseSSE == 0) { |
duke@435 | 309 | // UseSSE == 0 so float result should be left on TOS |
duke@435 | 310 | __ cmpl(rsi, T_FLOAT); |
duke@435 | 311 | __ jcc(Assembler::equal, common_return); |
duke@435 | 312 | } |
duke@435 | 313 | __ ffree(0); |
duke@435 | 314 | } |
duke@435 | 315 | #endif /* COMPILER2 */ |
duke@435 | 316 | __ jmp(common_return); |
duke@435 | 317 | |
duke@435 | 318 | return start; |
duke@435 | 319 | } |
duke@435 | 320 | |
duke@435 | 321 | |
duke@435 | 322 | //------------------------------------------------------------------------------------------------------------------------ |
duke@435 | 323 | // Return point for a Java call if there's an exception thrown in Java code. |
duke@435 | 324 | // The exception is caught and transformed into a pending exception stored in |
duke@435 | 325 | // JavaThread that can be tested from within the VM. |
duke@435 | 326 | // |
duke@435 | 327 | // Note: Usually the parameters are removed by the callee. In case of an exception |
duke@435 | 328 | // crossing an activation frame boundary, that is not the case if the callee |
duke@435 | 329 | // is compiled code => need to setup the rsp. |
duke@435 | 330 | // |
duke@435 | 331 | // rax,: exception oop |
duke@435 | 332 | |
duke@435 | 333 | address generate_catch_exception() { |
duke@435 | 334 | StubCodeMark mark(this, "StubRoutines", "catch_exception"); |
duke@435 | 335 | const Address rsp_after_call(rbp, -4 * wordSize); // same as in generate_call_stub()! |
duke@435 | 336 | const Address thread (rbp, 9 * wordSize); // same as in generate_call_stub()! |
duke@435 | 337 | address start = __ pc(); |
duke@435 | 338 | |
duke@435 | 339 | // get thread directly |
duke@435 | 340 | __ movl(rcx, thread); |
duke@435 | 341 | #ifdef ASSERT |
duke@435 | 342 | // verify that threads correspond |
duke@435 | 343 | { Label L; |
duke@435 | 344 | __ get_thread(rbx); |
duke@435 | 345 | __ cmpl(rbx, rcx); |
duke@435 | 346 | __ jcc(Assembler::equal, L); |
duke@435 | 347 | __ stop("StubRoutines::catch_exception: threads must correspond"); |
duke@435 | 348 | __ bind(L); |
duke@435 | 349 | } |
duke@435 | 350 | #endif |
duke@435 | 351 | // set pending exception |
duke@435 | 352 | __ verify_oop(rax); |
duke@435 | 353 | __ movl(Address(rcx, Thread::pending_exception_offset()), rax ); |
duke@435 | 354 | __ lea(Address(rcx, Thread::exception_file_offset ()), |
duke@435 | 355 | ExternalAddress((address)__FILE__)); |
duke@435 | 356 | __ movl(Address(rcx, Thread::exception_line_offset ()), __LINE__ ); |
duke@435 | 357 | // complete return to VM |
duke@435 | 358 | assert(StubRoutines::_call_stub_return_address != NULL, "_call_stub_return_address must have been generated before"); |
duke@435 | 359 | __ jump(RuntimeAddress(StubRoutines::_call_stub_return_address)); |
duke@435 | 360 | |
duke@435 | 361 | return start; |
duke@435 | 362 | } |
duke@435 | 363 | |
duke@435 | 364 | |
duke@435 | 365 | //------------------------------------------------------------------------------------------------------------------------ |
duke@435 | 366 | // Continuation point for runtime calls returning with a pending exception. |
duke@435 | 367 | // The pending exception check happened in the runtime or native call stub. |
duke@435 | 368 | // The pending exception in Thread is converted into a Java-level exception. |
duke@435 | 369 | // |
duke@435 | 370 | // Contract with Java-level exception handlers: |
duke@435 | 371 | // rax,: exception |
duke@435 | 372 | // rdx: throwing pc |
duke@435 | 373 | // |
duke@435 | 374 | // NOTE: At entry of this stub, exception-pc must be on stack !! |
duke@435 | 375 | |
duke@435 | 376 | address generate_forward_exception() { |
duke@435 | 377 | StubCodeMark mark(this, "StubRoutines", "forward exception"); |
duke@435 | 378 | address start = __ pc(); |
duke@435 | 379 | |
duke@435 | 380 | // Upon entry, the sp points to the return address returning into Java |
duke@435 | 381 | // (interpreted or compiled) code; i.e., the return address becomes the |
duke@435 | 382 | // throwing pc. |
duke@435 | 383 | // |
duke@435 | 384 | // Arguments pushed before the runtime call are still on the stack but |
duke@435 | 385 | // the exception handler will reset the stack pointer -> ignore them. |
duke@435 | 386 | // A potential result in registers can be ignored as well. |
duke@435 | 387 | |
duke@435 | 388 | #ifdef ASSERT |
duke@435 | 389 | // make sure this code is only executed if there is a pending exception |
duke@435 | 390 | { Label L; |
duke@435 | 391 | __ get_thread(rcx); |
duke@435 | 392 | __ cmpl(Address(rcx, Thread::pending_exception_offset()), NULL_WORD); |
duke@435 | 393 | __ jcc(Assembler::notEqual, L); |
duke@435 | 394 | __ stop("StubRoutines::forward exception: no pending exception (1)"); |
duke@435 | 395 | __ bind(L); |
duke@435 | 396 | } |
duke@435 | 397 | #endif |
duke@435 | 398 | |
duke@435 | 399 | // compute exception handler into rbx, |
duke@435 | 400 | __ movl(rax, Address(rsp, 0)); |
duke@435 | 401 | BLOCK_COMMENT("call exception_handler_for_return_address"); |
duke@435 | 402 | __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), rax); |
duke@435 | 403 | __ movl(rbx, rax); |
duke@435 | 404 | |
duke@435 | 405 | // setup rax, & rdx, remove return address & clear pending exception |
duke@435 | 406 | __ get_thread(rcx); |
duke@435 | 407 | __ popl(rdx); |
duke@435 | 408 | __ movl(rax, Address(rcx, Thread::pending_exception_offset())); |
duke@435 | 409 | __ movl(Address(rcx, Thread::pending_exception_offset()), NULL_WORD); |
duke@435 | 410 | |
duke@435 | 411 | #ifdef ASSERT |
duke@435 | 412 | // make sure exception is set |
duke@435 | 413 | { Label L; |
duke@435 | 414 | __ testl(rax, rax); |
duke@435 | 415 | __ jcc(Assembler::notEqual, L); |
duke@435 | 416 | __ stop("StubRoutines::forward exception: no pending exception (2)"); |
duke@435 | 417 | __ bind(L); |
duke@435 | 418 | } |
duke@435 | 419 | #endif |
duke@435 | 420 | |
duke@435 | 421 | // continue at exception handler (return address removed) |
duke@435 | 422 | // rax,: exception |
duke@435 | 423 | // rbx,: exception handler |
duke@435 | 424 | // rdx: throwing pc |
duke@435 | 425 | __ verify_oop(rax); |
duke@435 | 426 | __ jmp(rbx); |
duke@435 | 427 | |
duke@435 | 428 | return start; |
duke@435 | 429 | } |
duke@435 | 430 | |
duke@435 | 431 | |
duke@435 | 432 | //---------------------------------------------------------------------------------------------------- |
duke@435 | 433 | // Support for jint Atomic::xchg(jint exchange_value, volatile jint* dest) |
duke@435 | 434 | // |
duke@435 | 435 | // xchg exists as far back as 8086, lock needed for MP only |
duke@435 | 436 | // Stack layout immediately after call: |
duke@435 | 437 | // |
duke@435 | 438 | // 0 [ret addr ] <--- rsp |
duke@435 | 439 | // 1 [ ex ] |
duke@435 | 440 | // 2 [ dest ] |
duke@435 | 441 | // |
duke@435 | 442 | // Result: *dest <- ex, return (old *dest) |
duke@435 | 443 | // |
duke@435 | 444 | // Note: win32 does not currently use this code |
duke@435 | 445 | |
duke@435 | 446 | address generate_atomic_xchg() { |
duke@435 | 447 | StubCodeMark mark(this, "StubRoutines", "atomic_xchg"); |
duke@435 | 448 | address start = __ pc(); |
duke@435 | 449 | |
duke@435 | 450 | __ pushl(rdx); |
duke@435 | 451 | Address exchange(rsp, 2 * wordSize); |
duke@435 | 452 | Address dest_addr(rsp, 3 * wordSize); |
duke@435 | 453 | __ movl(rax, exchange); |
duke@435 | 454 | __ movl(rdx, dest_addr); |
duke@435 | 455 | __ xchg(rax, Address(rdx, 0)); |
duke@435 | 456 | __ popl(rdx); |
duke@435 | 457 | __ ret(0); |
duke@435 | 458 | |
duke@435 | 459 | return start; |
duke@435 | 460 | } |
duke@435 | 461 | |
duke@435 | 462 | //---------------------------------------------------------------------------------------------------- |
duke@435 | 463 | // Support for void verify_mxcsr() |
duke@435 | 464 | // |
duke@435 | 465 | // This routine is used with -Xcheck:jni to verify that native |
duke@435 | 466 | // JNI code does not return to Java code without restoring the |
duke@435 | 467 | // MXCSR register to our expected state. |
duke@435 | 468 | |
duke@435 | 469 | |
duke@435 | 470 | address generate_verify_mxcsr() { |
duke@435 | 471 | StubCodeMark mark(this, "StubRoutines", "verify_mxcsr"); |
duke@435 | 472 | address start = __ pc(); |
duke@435 | 473 | |
duke@435 | 474 | const Address mxcsr_save(rsp, 0); |
duke@435 | 475 | |
duke@435 | 476 | if (CheckJNICalls && UseSSE > 0 ) { |
duke@435 | 477 | Label ok_ret; |
duke@435 | 478 | ExternalAddress mxcsr_std(StubRoutines::addr_mxcsr_std()); |
duke@435 | 479 | __ pushl(rax); |
duke@435 | 480 | __ subl(rsp, wordSize); // allocate a temp location |
duke@435 | 481 | __ stmxcsr(mxcsr_save); |
duke@435 | 482 | __ movl(rax, mxcsr_save); |
duke@435 | 483 | __ andl(rax, MXCSR_MASK); |
duke@435 | 484 | __ cmp32(rax, mxcsr_std); |
duke@435 | 485 | __ jcc(Assembler::equal, ok_ret); |
duke@435 | 486 | |
duke@435 | 487 | __ warn("MXCSR changed by native JNI code."); |
duke@435 | 488 | |
duke@435 | 489 | __ ldmxcsr(mxcsr_std); |
duke@435 | 490 | |
duke@435 | 491 | __ bind(ok_ret); |
duke@435 | 492 | __ addl(rsp, wordSize); |
duke@435 | 493 | __ popl(rax); |
duke@435 | 494 | } |
duke@435 | 495 | |
duke@435 | 496 | __ ret(0); |
duke@435 | 497 | |
duke@435 | 498 | return start; |
duke@435 | 499 | } |
duke@435 | 500 | |
duke@435 | 501 | |
duke@435 | 502 | //--------------------------------------------------------------------------- |
duke@435 | 503 | // Support for void verify_fpu_cntrl_wrd() |
duke@435 | 504 | // |
duke@435 | 505 | // This routine is used with -Xcheck:jni to verify that native |
duke@435 | 506 | // JNI code does not return to Java code without restoring the |
duke@435 | 507 | // FP control word to our expected state. |
duke@435 | 508 | |
duke@435 | 509 | address generate_verify_fpu_cntrl_wrd() { |
duke@435 | 510 | StubCodeMark mark(this, "StubRoutines", "verify_spcw"); |
duke@435 | 511 | address start = __ pc(); |
duke@435 | 512 | |
duke@435 | 513 | const Address fpu_cntrl_wrd_save(rsp, 0); |
duke@435 | 514 | |
duke@435 | 515 | if (CheckJNICalls) { |
duke@435 | 516 | Label ok_ret; |
duke@435 | 517 | __ pushl(rax); |
duke@435 | 518 | __ subl(rsp, wordSize); // allocate a temp location |
duke@435 | 519 | __ fnstcw(fpu_cntrl_wrd_save); |
duke@435 | 520 | __ movl(rax, fpu_cntrl_wrd_save); |
duke@435 | 521 | __ andl(rax, FPU_CNTRL_WRD_MASK); |
duke@435 | 522 | ExternalAddress fpu_std(StubRoutines::addr_fpu_cntrl_wrd_std()); |
duke@435 | 523 | __ cmp32(rax, fpu_std); |
duke@435 | 524 | __ jcc(Assembler::equal, ok_ret); |
duke@435 | 525 | |
duke@435 | 526 | __ warn("Floating point control word changed by native JNI code."); |
duke@435 | 527 | |
duke@435 | 528 | __ fldcw(fpu_std); |
duke@435 | 529 | |
duke@435 | 530 | __ bind(ok_ret); |
duke@435 | 531 | __ addl(rsp, wordSize); |
duke@435 | 532 | __ popl(rax); |
duke@435 | 533 | } |
duke@435 | 534 | |
duke@435 | 535 | __ ret(0); |
duke@435 | 536 | |
duke@435 | 537 | return start; |
duke@435 | 538 | } |
duke@435 | 539 | |
duke@435 | 540 | //--------------------------------------------------------------------------- |
duke@435 | 541 | // Wrapper for slow-case handling of double-to-integer conversion |
duke@435 | 542 | // d2i or f2i fast case failed either because it is nan or because |
duke@435 | 543 | // of under/overflow. |
duke@435 | 544 | // Input: FPU TOS: float value |
duke@435 | 545 | // Output: rax, (rdx): integer (long) result |
duke@435 | 546 | |
duke@435 | 547 | address generate_d2i_wrapper(BasicType t, address fcn) { |
duke@435 | 548 | StubCodeMark mark(this, "StubRoutines", "d2i_wrapper"); |
duke@435 | 549 | address start = __ pc(); |
duke@435 | 550 | |
duke@435 | 551 | // Capture info about frame layout |
duke@435 | 552 | enum layout { FPUState_off = 0, |
duke@435 | 553 | rbp_off = FPUStateSizeInWords, |
duke@435 | 554 | rdi_off, |
duke@435 | 555 | rsi_off, |
duke@435 | 556 | rcx_off, |
duke@435 | 557 | rbx_off, |
duke@435 | 558 | saved_argument_off, |
duke@435 | 559 | saved_argument_off2, // 2nd half of double |
duke@435 | 560 | framesize |
duke@435 | 561 | }; |
duke@435 | 562 | |
duke@435 | 563 | assert(FPUStateSizeInWords == 27, "update stack layout"); |
duke@435 | 564 | |
duke@435 | 565 | // Save outgoing argument to stack across push_FPU_state() |
duke@435 | 566 | __ subl(rsp, wordSize * 2); |
duke@435 | 567 | __ fstp_d(Address(rsp, 0)); |
duke@435 | 568 | |
duke@435 | 569 | // Save CPU & FPU state |
duke@435 | 570 | __ pushl(rbx); |
duke@435 | 571 | __ pushl(rcx); |
duke@435 | 572 | __ pushl(rsi); |
duke@435 | 573 | __ pushl(rdi); |
duke@435 | 574 | __ pushl(rbp); |
duke@435 | 575 | __ push_FPU_state(); |
duke@435 | 576 | |
duke@435 | 577 | // push_FPU_state() resets the FP top of stack |
duke@435 | 578 | // Load original double into FP top of stack |
duke@435 | 579 | __ fld_d(Address(rsp, saved_argument_off * wordSize)); |
duke@435 | 580 | // Store double into stack as outgoing argument |
duke@435 | 581 | __ subl(rsp, wordSize*2); |
duke@435 | 582 | __ fst_d(Address(rsp, 0)); |
duke@435 | 583 | |
duke@435 | 584 | // Prepare FPU for doing math in C-land |
duke@435 | 585 | __ empty_FPU_stack(); |
duke@435 | 586 | // Call the C code to massage the double. Result in EAX |
duke@435 | 587 | if (t == T_INT) |
duke@435 | 588 | { BLOCK_COMMENT("SharedRuntime::d2i"); } |
duke@435 | 589 | else if (t == T_LONG) |
duke@435 | 590 | { BLOCK_COMMENT("SharedRuntime::d2l"); } |
duke@435 | 591 | __ call_VM_leaf( fcn, 2 ); |
duke@435 | 592 | |
duke@435 | 593 | // Restore CPU & FPU state |
duke@435 | 594 | __ pop_FPU_state(); |
duke@435 | 595 | __ popl(rbp); |
duke@435 | 596 | __ popl(rdi); |
duke@435 | 597 | __ popl(rsi); |
duke@435 | 598 | __ popl(rcx); |
duke@435 | 599 | __ popl(rbx); |
duke@435 | 600 | __ addl(rsp, wordSize * 2); |
duke@435 | 601 | |
duke@435 | 602 | __ ret(0); |
duke@435 | 603 | |
duke@435 | 604 | return start; |
duke@435 | 605 | } |
duke@435 | 606 | |
duke@435 | 607 | |
duke@435 | 608 | //--------------------------------------------------------------------------- |
duke@435 | 609 | // The following routine generates a subroutine to throw an asynchronous |
duke@435 | 610 | // UnknownError when an unsafe access gets a fault that could not be |
duke@435 | 611 | // reasonably prevented by the programmer. (Example: SIGBUS/OBJERR.) |
duke@435 | 612 | address generate_handler_for_unsafe_access() { |
duke@435 | 613 | StubCodeMark mark(this, "StubRoutines", "handler_for_unsafe_access"); |
duke@435 | 614 | address start = __ pc(); |
duke@435 | 615 | |
duke@435 | 616 | __ pushl(0); // hole for return address-to-be |
duke@435 | 617 | __ pushad(); // push registers |
duke@435 | 618 | Address next_pc(rsp, RegisterImpl::number_of_registers * BytesPerWord); |
duke@435 | 619 | BLOCK_COMMENT("call handle_unsafe_access"); |
duke@435 | 620 | __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, handle_unsafe_access))); |
duke@435 | 621 | __ movl(next_pc, rax); // stuff next address |
duke@435 | 622 | __ popad(); |
duke@435 | 623 | __ ret(0); // jump to next address |
duke@435 | 624 | |
duke@435 | 625 | return start; |
duke@435 | 626 | } |
duke@435 | 627 | |
duke@435 | 628 | |
duke@435 | 629 | //---------------------------------------------------------------------------------------------------- |
duke@435 | 630 | // Non-destructive plausibility checks for oops |
duke@435 | 631 | |
duke@435 | 632 | address generate_verify_oop() { |
duke@435 | 633 | StubCodeMark mark(this, "StubRoutines", "verify_oop"); |
duke@435 | 634 | address start = __ pc(); |
duke@435 | 635 | |
duke@435 | 636 | // Incoming arguments on stack after saving rax,: |
duke@435 | 637 | // |
duke@435 | 638 | // [tos ]: saved rdx |
duke@435 | 639 | // [tos + 1]: saved EFLAGS |
duke@435 | 640 | // [tos + 2]: return address |
duke@435 | 641 | // [tos + 3]: char* error message |
duke@435 | 642 | // [tos + 4]: oop object to verify |
duke@435 | 643 | // [tos + 5]: saved rax, - saved by caller and bashed |
duke@435 | 644 | |
duke@435 | 645 | Label exit, error; |
duke@435 | 646 | __ pushfd(); |
duke@435 | 647 | __ increment(ExternalAddress((address) StubRoutines::verify_oop_count_addr())); |
duke@435 | 648 | __ pushl(rdx); // save rdx |
duke@435 | 649 | // make sure object is 'reasonable' |
duke@435 | 650 | __ movl(rax, Address(rsp, 4 * wordSize)); // get object |
duke@435 | 651 | __ testl(rax, rax); |
duke@435 | 652 | __ jcc(Assembler::zero, exit); // if obj is NULL it is ok |
duke@435 | 653 | |
duke@435 | 654 | // Check if the oop is in the right area of memory |
duke@435 | 655 | const int oop_mask = Universe::verify_oop_mask(); |
duke@435 | 656 | const int oop_bits = Universe::verify_oop_bits(); |
duke@435 | 657 | __ movl(rdx, rax); |
duke@435 | 658 | __ andl(rdx, oop_mask); |
duke@435 | 659 | __ cmpl(rdx, oop_bits); |
duke@435 | 660 | __ jcc(Assembler::notZero, error); |
duke@435 | 661 | |
duke@435 | 662 | // make sure klass is 'reasonable' |
duke@435 | 663 | __ movl(rax, Address(rax, oopDesc::klass_offset_in_bytes())); // get klass |
duke@435 | 664 | __ testl(rax, rax); |
duke@435 | 665 | __ jcc(Assembler::zero, error); // if klass is NULL it is broken |
duke@435 | 666 | |
duke@435 | 667 | // Check if the klass is in the right area of memory |
duke@435 | 668 | const int klass_mask = Universe::verify_klass_mask(); |
duke@435 | 669 | const int klass_bits = Universe::verify_klass_bits(); |
duke@435 | 670 | __ movl(rdx, rax); |
duke@435 | 671 | __ andl(rdx, klass_mask); |
duke@435 | 672 | __ cmpl(rdx, klass_bits); |
duke@435 | 673 | __ jcc(Assembler::notZero, error); |
duke@435 | 674 | |
duke@435 | 675 | // make sure klass' klass is 'reasonable' |
duke@435 | 676 | __ movl(rax, Address(rax, oopDesc::klass_offset_in_bytes())); // get klass' klass |
duke@435 | 677 | __ testl(rax, rax); |
duke@435 | 678 | __ jcc(Assembler::zero, error); // if klass' klass is NULL it is broken |
duke@435 | 679 | |
duke@435 | 680 | __ movl(rdx, rax); |
duke@435 | 681 | __ andl(rdx, klass_mask); |
duke@435 | 682 | __ cmpl(rdx, klass_bits); |
duke@435 | 683 | __ jcc(Assembler::notZero, error); // if klass not in right area |
duke@435 | 684 | // of memory it is broken too. |
duke@435 | 685 | |
duke@435 | 686 | // return if everything seems ok |
duke@435 | 687 | __ bind(exit); |
duke@435 | 688 | __ movl(rax, Address(rsp, 5 * wordSize)); // get saved rax, back |
duke@435 | 689 | __ popl(rdx); // restore rdx |
duke@435 | 690 | __ popfd(); // restore EFLAGS |
duke@435 | 691 | __ ret(3 * wordSize); // pop arguments |
duke@435 | 692 | |
duke@435 | 693 | // handle errors |
duke@435 | 694 | __ bind(error); |
duke@435 | 695 | __ movl(rax, Address(rsp, 5 * wordSize)); // get saved rax, back |
duke@435 | 696 | __ popl(rdx); // get saved rdx back |
duke@435 | 697 | __ popfd(); // get saved EFLAGS off stack -- will be ignored |
duke@435 | 698 | __ pushad(); // push registers (eip = return address & msg are already pushed) |
duke@435 | 699 | BLOCK_COMMENT("call MacroAssembler::debug"); |
duke@435 | 700 | __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, MacroAssembler::debug))); |
duke@435 | 701 | __ popad(); |
duke@435 | 702 | __ ret(3 * wordSize); // pop arguments |
duke@435 | 703 | return start; |
duke@435 | 704 | } |
duke@435 | 705 | |
duke@435 | 706 | // |
duke@435 | 707 | // Generate pre-barrier for array stores |
duke@435 | 708 | // |
duke@435 | 709 | // Input: |
duke@435 | 710 | // start - starting address |
duke@435 | 711 | // end - element count |
duke@435 | 712 | void gen_write_ref_array_pre_barrier(Register start, Register count) { |
duke@435 | 713 | assert_different_registers(start, count); |
duke@435 | 714 | BarrierSet* bs = Universe::heap()->barrier_set(); |
duke@435 | 715 | switch (bs->kind()) { |
duke@435 | 716 | case BarrierSet::G1SATBCT: |
duke@435 | 717 | case BarrierSet::G1SATBCTLogging: |
duke@435 | 718 | { |
duke@435 | 719 | __ pushad(); // push registers |
duke@435 | 720 | __ pushl(count); |
duke@435 | 721 | __ pushl(start); |
ysr@777 | 722 | __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_pre))); |
ysr@777 | 723 | __ addl(rsp, wordSize * 2); |
duke@435 | 724 | __ popad(); |
duke@435 | 725 | } |
duke@435 | 726 | break; |
duke@435 | 727 | case BarrierSet::CardTableModRef: |
duke@435 | 728 | case BarrierSet::CardTableExtension: |
duke@435 | 729 | case BarrierSet::ModRef: |
duke@435 | 730 | break; |
duke@435 | 731 | default : |
duke@435 | 732 | ShouldNotReachHere(); |
duke@435 | 733 | |
duke@435 | 734 | } |
duke@435 | 735 | } |
duke@435 | 736 | |
duke@435 | 737 | |
duke@435 | 738 | // |
duke@435 | 739 | // Generate a post-barrier for an array store |
duke@435 | 740 | // |
duke@435 | 741 | // start - starting address |
duke@435 | 742 | // count - element count |
duke@435 | 743 | // |
duke@435 | 744 | // The two input registers are overwritten. |
duke@435 | 745 | // |
duke@435 | 746 | void gen_write_ref_array_post_barrier(Register start, Register count) { |
duke@435 | 747 | BarrierSet* bs = Universe::heap()->barrier_set(); |
duke@435 | 748 | assert_different_registers(start, count); |
duke@435 | 749 | switch (bs->kind()) { |
duke@435 | 750 | case BarrierSet::G1SATBCT: |
duke@435 | 751 | case BarrierSet::G1SATBCTLogging: |
duke@435 | 752 | { |
duke@435 | 753 | __ pushad(); // push registers |
duke@435 | 754 | __ pushl(count); |
duke@435 | 755 | __ pushl(start); |
ysr@777 | 756 | __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_post))); |
ysr@777 | 757 | __ addl(rsp, wordSize * 2); |
duke@435 | 758 | __ popad(); |
duke@435 | 759 | |
duke@435 | 760 | } |
duke@435 | 761 | break; |
duke@435 | 762 | |
duke@435 | 763 | case BarrierSet::CardTableModRef: |
duke@435 | 764 | case BarrierSet::CardTableExtension: |
duke@435 | 765 | { |
duke@435 | 766 | CardTableModRefBS* ct = (CardTableModRefBS*)bs; |
duke@435 | 767 | assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code"); |
duke@435 | 768 | |
duke@435 | 769 | Label L_loop; |
duke@435 | 770 | const Register end = count; // elements count; end == start+count-1 |
duke@435 | 771 | assert_different_registers(start, end); |
duke@435 | 772 | |
duke@435 | 773 | __ leal(end, Address(start, count, Address::times_4, -4)); |
duke@435 | 774 | __ shrl(start, CardTableModRefBS::card_shift); |
duke@435 | 775 | __ shrl(end, CardTableModRefBS::card_shift); |
duke@435 | 776 | __ subl(end, start); // end --> count |
duke@435 | 777 | __ BIND(L_loop); |
duke@435 | 778 | ExternalAddress base((address)ct->byte_map_base); |
duke@435 | 779 | Address index(start, count, Address::times_1, 0); |
duke@435 | 780 | __ movbyte(ArrayAddress(base, index), 0); |
duke@435 | 781 | __ decrement(count); |
duke@435 | 782 | __ jcc(Assembler::greaterEqual, L_loop); |
duke@435 | 783 | } |
duke@435 | 784 | break; |
duke@435 | 785 | case BarrierSet::ModRef: |
duke@435 | 786 | break; |
duke@435 | 787 | default : |
duke@435 | 788 | ShouldNotReachHere(); |
duke@435 | 789 | |
duke@435 | 790 | } |
duke@435 | 791 | } |
duke@435 | 792 | |
duke@435 | 793 | // Copy 64 bytes chunks |
duke@435 | 794 | // |
duke@435 | 795 | // Inputs: |
duke@435 | 796 | // from - source array address |
duke@435 | 797 | // to_from - destination array address - from |
duke@435 | 798 | // qword_count - 8-bytes element count, negative |
duke@435 | 799 | // |
duke@435 | 800 | void mmx_copy_forward(Register from, Register to_from, Register qword_count) { |
duke@435 | 801 | Label L_copy_64_bytes_loop, L_copy_64_bytes, L_copy_8_bytes, L_exit; |
duke@435 | 802 | // Copy 64-byte chunks |
duke@435 | 803 | __ jmpb(L_copy_64_bytes); |
duke@435 | 804 | __ align(16); |
duke@435 | 805 | __ BIND(L_copy_64_bytes_loop); |
duke@435 | 806 | __ movq(mmx0, Address(from, 0)); |
duke@435 | 807 | __ movq(mmx1, Address(from, 8)); |
duke@435 | 808 | __ movq(mmx2, Address(from, 16)); |
duke@435 | 809 | __ movq(Address(from, to_from, Address::times_1, 0), mmx0); |
duke@435 | 810 | __ movq(mmx3, Address(from, 24)); |
duke@435 | 811 | __ movq(Address(from, to_from, Address::times_1, 8), mmx1); |
duke@435 | 812 | __ movq(mmx4, Address(from, 32)); |
duke@435 | 813 | __ movq(Address(from, to_from, Address::times_1, 16), mmx2); |
duke@435 | 814 | __ movq(mmx5, Address(from, 40)); |
duke@435 | 815 | __ movq(Address(from, to_from, Address::times_1, 24), mmx3); |
duke@435 | 816 | __ movq(mmx6, Address(from, 48)); |
duke@435 | 817 | __ movq(Address(from, to_from, Address::times_1, 32), mmx4); |
duke@435 | 818 | __ movq(mmx7, Address(from, 56)); |
duke@435 | 819 | __ movq(Address(from, to_from, Address::times_1, 40), mmx5); |
duke@435 | 820 | __ movq(Address(from, to_from, Address::times_1, 48), mmx6); |
duke@435 | 821 | __ movq(Address(from, to_from, Address::times_1, 56), mmx7); |
duke@435 | 822 | __ addl(from, 64); |
duke@435 | 823 | __ BIND(L_copy_64_bytes); |
duke@435 | 824 | __ subl(qword_count, 8); |
duke@435 | 825 | __ jcc(Assembler::greaterEqual, L_copy_64_bytes_loop); |
duke@435 | 826 | __ addl(qword_count, 8); |
duke@435 | 827 | __ jccb(Assembler::zero, L_exit); |
duke@435 | 828 | // |
duke@435 | 829 | // length is too short, just copy qwords |
duke@435 | 830 | // |
duke@435 | 831 | __ BIND(L_copy_8_bytes); |
duke@435 | 832 | __ movq(mmx0, Address(from, 0)); |
duke@435 | 833 | __ movq(Address(from, to_from, Address::times_1), mmx0); |
duke@435 | 834 | __ addl(from, 8); |
duke@435 | 835 | __ decrement(qword_count); |
duke@435 | 836 | __ jcc(Assembler::greater, L_copy_8_bytes); |
duke@435 | 837 | __ BIND(L_exit); |
duke@435 | 838 | __ emms(); |
duke@435 | 839 | } |
duke@435 | 840 | |
duke@435 | 841 | address generate_disjoint_copy(BasicType t, bool aligned, |
duke@435 | 842 | Address::ScaleFactor sf, |
duke@435 | 843 | address* entry, const char *name) { |
duke@435 | 844 | __ align(CodeEntryAlignment); |
duke@435 | 845 | StubCodeMark mark(this, "StubRoutines", name); |
duke@435 | 846 | address start = __ pc(); |
duke@435 | 847 | |
duke@435 | 848 | Label L_0_count, L_exit, L_skip_align1, L_skip_align2, L_copy_byte; |
duke@435 | 849 | Label L_copy_2_bytes, L_copy_4_bytes, L_copy_64_bytes; |
duke@435 | 850 | |
duke@435 | 851 | int shift = Address::times_4 - sf; |
duke@435 | 852 | |
duke@435 | 853 | const Register from = rsi; // source array address |
duke@435 | 854 | const Register to = rdi; // destination array address |
duke@435 | 855 | const Register count = rcx; // elements count |
duke@435 | 856 | const Register to_from = to; // (to - from) |
duke@435 | 857 | const Register saved_to = rdx; // saved destination array address |
duke@435 | 858 | |
duke@435 | 859 | __ enter(); // required for proper stackwalking of RuntimeStub frame |
duke@435 | 860 | __ pushl(rsi); |
duke@435 | 861 | __ pushl(rdi); |
duke@435 | 862 | __ movl(from , Address(rsp, 12+ 4)); |
duke@435 | 863 | __ movl(to , Address(rsp, 12+ 8)); |
duke@435 | 864 | __ movl(count, Address(rsp, 12+ 12)); |
duke@435 | 865 | if (t == T_OBJECT) { |
duke@435 | 866 | __ testl(count, count); |
duke@435 | 867 | __ jcc(Assembler::zero, L_0_count); |
duke@435 | 868 | gen_write_ref_array_pre_barrier(to, count); |
duke@435 | 869 | __ movl(saved_to, to); // save 'to' |
duke@435 | 870 | } |
duke@435 | 871 | |
duke@435 | 872 | *entry = __ pc(); // Entry point from conjoint arraycopy stub. |
duke@435 | 873 | BLOCK_COMMENT("Entry:"); |
duke@435 | 874 | |
duke@435 | 875 | __ subl(to, from); // to --> to_from |
duke@435 | 876 | __ cmpl(count, 2<<shift); // Short arrays (< 8 bytes) copy by element |
duke@435 | 877 | __ jcc(Assembler::below, L_copy_4_bytes); // use unsigned cmp |
duke@435 | 878 | if (!aligned && (t == T_BYTE || t == T_SHORT)) { |
duke@435 | 879 | // align source address at 4 bytes address boundary |
duke@435 | 880 | if (t == T_BYTE) { |
duke@435 | 881 | // One byte misalignment happens only for byte arrays |
duke@435 | 882 | __ testl(from, 1); |
duke@435 | 883 | __ jccb(Assembler::zero, L_skip_align1); |
duke@435 | 884 | __ movb(rax, Address(from, 0)); |
duke@435 | 885 | __ movb(Address(from, to_from, Address::times_1, 0), rax); |
duke@435 | 886 | __ increment(from); |
duke@435 | 887 | __ decrement(count); |
duke@435 | 888 | __ BIND(L_skip_align1); |
duke@435 | 889 | } |
duke@435 | 890 | // Two bytes misalignment happens only for byte and short (char) arrays |
duke@435 | 891 | __ testl(from, 2); |
duke@435 | 892 | __ jccb(Assembler::zero, L_skip_align2); |
duke@435 | 893 | __ movw(rax, Address(from, 0)); |
duke@435 | 894 | __ movw(Address(from, to_from, Address::times_1, 0), rax); |
duke@435 | 895 | __ addl(from, 2); |
duke@435 | 896 | __ subl(count, 1<<(shift-1)); |
duke@435 | 897 | __ BIND(L_skip_align2); |
duke@435 | 898 | } |
duke@435 | 899 | if (!VM_Version::supports_mmx()) { |
duke@435 | 900 | __ movl(rax, count); // save 'count' |
duke@435 | 901 | __ shrl(count, shift); // bytes count |
duke@435 | 902 | __ addl(to_from, from); // restore 'to' |
duke@435 | 903 | __ rep_movl(); |
duke@435 | 904 | __ subl(to_from, from); // restore 'to_from' |
duke@435 | 905 | __ movl(count, rax); // restore 'count' |
duke@435 | 906 | __ jmpb(L_copy_2_bytes); // all dwords were copied |
duke@435 | 907 | } else { |
duke@435 | 908 | // align to 8 bytes, we know we are 4 byte aligned to start |
duke@435 | 909 | __ testl(from, 4); |
duke@435 | 910 | __ jccb(Assembler::zero, L_copy_64_bytes); |
duke@435 | 911 | __ movl(rax, Address(from, 0)); |
duke@435 | 912 | __ movl(Address(from, to_from, Address::times_1, 0), rax); |
duke@435 | 913 | __ addl(from, 4); |
duke@435 | 914 | __ subl(count, 1<<shift); |
duke@435 | 915 | __ BIND(L_copy_64_bytes); |
duke@435 | 916 | __ movl(rax, count); |
duke@435 | 917 | __ shrl(rax, shift+1); // 8 bytes chunk count |
duke@435 | 918 | // |
duke@435 | 919 | // Copy 8-byte chunks through MMX registers, 8 per iteration of the loop |
duke@435 | 920 | // |
duke@435 | 921 | mmx_copy_forward(from, to_from, rax); |
duke@435 | 922 | } |
duke@435 | 923 | // copy tailing dword |
duke@435 | 924 | __ BIND(L_copy_4_bytes); |
duke@435 | 925 | __ testl(count, 1<<shift); |
duke@435 | 926 | __ jccb(Assembler::zero, L_copy_2_bytes); |
duke@435 | 927 | __ movl(rax, Address(from, 0)); |
duke@435 | 928 | __ movl(Address(from, to_from, Address::times_1, 0), rax); |
duke@435 | 929 | if (t == T_BYTE || t == T_SHORT) { |
duke@435 | 930 | __ addl(from, 4); |
duke@435 | 931 | __ BIND(L_copy_2_bytes); |
duke@435 | 932 | // copy tailing word |
duke@435 | 933 | __ testl(count, 1<<(shift-1)); |
duke@435 | 934 | __ jccb(Assembler::zero, L_copy_byte); |
duke@435 | 935 | __ movw(rax, Address(from, 0)); |
duke@435 | 936 | __ movw(Address(from, to_from, Address::times_1, 0), rax); |
duke@435 | 937 | if (t == T_BYTE) { |
duke@435 | 938 | __ addl(from, 2); |
duke@435 | 939 | __ BIND(L_copy_byte); |
duke@435 | 940 | // copy tailing byte |
duke@435 | 941 | __ testl(count, 1); |
duke@435 | 942 | __ jccb(Assembler::zero, L_exit); |
duke@435 | 943 | __ movb(rax, Address(from, 0)); |
duke@435 | 944 | __ movb(Address(from, to_from, Address::times_1, 0), rax); |
duke@435 | 945 | __ BIND(L_exit); |
duke@435 | 946 | } else { |
duke@435 | 947 | __ BIND(L_copy_byte); |
duke@435 | 948 | } |
duke@435 | 949 | } else { |
duke@435 | 950 | __ BIND(L_copy_2_bytes); |
duke@435 | 951 | } |
duke@435 | 952 | |
duke@435 | 953 | if (t == T_OBJECT) { |
duke@435 | 954 | __ movl(count, Address(rsp, 12+12)); // reread 'count' |
duke@435 | 955 | __ movl(to, saved_to); // restore 'to' |
duke@435 | 956 | gen_write_ref_array_post_barrier(to, count); |
duke@435 | 957 | __ BIND(L_0_count); |
duke@435 | 958 | } |
duke@435 | 959 | inc_copy_counter_np(t); |
duke@435 | 960 | __ popl(rdi); |
duke@435 | 961 | __ popl(rsi); |
duke@435 | 962 | __ leave(); // required for proper stackwalking of RuntimeStub frame |
duke@435 | 963 | __ xorl(rax, rax); // return 0 |
duke@435 | 964 | __ ret(0); |
duke@435 | 965 | return start; |
duke@435 | 966 | } |
duke@435 | 967 | |
duke@435 | 968 | |
duke@435 | 969 | address generate_conjoint_copy(BasicType t, bool aligned, |
duke@435 | 970 | Address::ScaleFactor sf, |
duke@435 | 971 | address nooverlap_target, |
duke@435 | 972 | address* entry, const char *name) { |
duke@435 | 973 | __ align(CodeEntryAlignment); |
duke@435 | 974 | StubCodeMark mark(this, "StubRoutines", name); |
duke@435 | 975 | address start = __ pc(); |
duke@435 | 976 | |
duke@435 | 977 | Label L_0_count, L_exit, L_skip_align1, L_skip_align2, L_copy_byte; |
duke@435 | 978 | Label L_copy_2_bytes, L_copy_4_bytes, L_copy_8_bytes, L_copy_8_bytes_loop; |
duke@435 | 979 | |
duke@435 | 980 | int shift = Address::times_4 - sf; |
duke@435 | 981 | |
duke@435 | 982 | const Register src = rax; // source array address |
duke@435 | 983 | const Register dst = rdx; // destination array address |
duke@435 | 984 | const Register from = rsi; // source array address |
duke@435 | 985 | const Register to = rdi; // destination array address |
duke@435 | 986 | const Register count = rcx; // elements count |
duke@435 | 987 | const Register end = rax; // array end address |
duke@435 | 988 | |
duke@435 | 989 | __ enter(); // required for proper stackwalking of RuntimeStub frame |
duke@435 | 990 | __ pushl(rsi); |
duke@435 | 991 | __ pushl(rdi); |
duke@435 | 992 | __ movl(src , Address(rsp, 12+ 4)); // from |
duke@435 | 993 | __ movl(dst , Address(rsp, 12+ 8)); // to |
duke@435 | 994 | __ movl(count, Address(rsp, 12+12)); // count |
duke@435 | 995 | if (t == T_OBJECT) { |
duke@435 | 996 | gen_write_ref_array_pre_barrier(dst, count); |
duke@435 | 997 | } |
duke@435 | 998 | |
duke@435 | 999 | if (entry != NULL) { |
duke@435 | 1000 | *entry = __ pc(); // Entry point from generic arraycopy stub. |
duke@435 | 1001 | BLOCK_COMMENT("Entry:"); |
duke@435 | 1002 | } |
duke@435 | 1003 | |
duke@435 | 1004 | if (t == T_OBJECT) { |
duke@435 | 1005 | __ testl(count, count); |
duke@435 | 1006 | __ jcc(Assembler::zero, L_0_count); |
duke@435 | 1007 | } |
duke@435 | 1008 | __ movl(from, src); |
duke@435 | 1009 | __ movl(to , dst); |
duke@435 | 1010 | |
duke@435 | 1011 | // arrays overlap test |
duke@435 | 1012 | RuntimeAddress nooverlap(nooverlap_target); |
duke@435 | 1013 | __ cmpl(dst, src); |
duke@435 | 1014 | __ leal(end, Address(src, count, sf, 0)); // src + count * elem_size |
duke@435 | 1015 | __ jump_cc(Assembler::belowEqual, nooverlap); |
duke@435 | 1016 | __ cmpl(dst, end); |
duke@435 | 1017 | __ jump_cc(Assembler::aboveEqual, nooverlap); |
duke@435 | 1018 | |
duke@435 | 1019 | // copy from high to low |
duke@435 | 1020 | __ cmpl(count, 2<<shift); // Short arrays (< 8 bytes) copy by element |
duke@435 | 1021 | __ jcc(Assembler::below, L_copy_4_bytes); // use unsigned cmp |
duke@435 | 1022 | if (t == T_BYTE || t == T_SHORT) { |
duke@435 | 1023 | // Align the end of destination array at 4 bytes address boundary |
duke@435 | 1024 | __ leal(end, Address(dst, count, sf, 0)); |
duke@435 | 1025 | if (t == T_BYTE) { |
duke@435 | 1026 | // One byte misalignment happens only for byte arrays |
duke@435 | 1027 | __ testl(end, 1); |
duke@435 | 1028 | __ jccb(Assembler::zero, L_skip_align1); |
duke@435 | 1029 | __ decrement(count); |
duke@435 | 1030 | __ movb(rdx, Address(from, count, sf, 0)); |
duke@435 | 1031 | __ movb(Address(to, count, sf, 0), rdx); |
duke@435 | 1032 | __ BIND(L_skip_align1); |
duke@435 | 1033 | } |
duke@435 | 1034 | // Two bytes misalignment happens only for byte and short (char) arrays |
duke@435 | 1035 | __ testl(end, 2); |
duke@435 | 1036 | __ jccb(Assembler::zero, L_skip_align2); |
duke@435 | 1037 | __ subl(count, 1<<(shift-1)); |
duke@435 | 1038 | __ movw(rdx, Address(from, count, sf, 0)); |
duke@435 | 1039 | __ movw(Address(to, count, sf, 0), rdx); |
duke@435 | 1040 | __ BIND(L_skip_align2); |
duke@435 | 1041 | __ cmpl(count, 2<<shift); // Short arrays (< 8 bytes) copy by element |
duke@435 | 1042 | __ jcc(Assembler::below, L_copy_4_bytes); |
duke@435 | 1043 | } |
duke@435 | 1044 | |
duke@435 | 1045 | if (!VM_Version::supports_mmx()) { |
duke@435 | 1046 | __ std(); |
duke@435 | 1047 | __ movl(rax, count); // Save 'count' |
duke@435 | 1048 | __ movl(rdx, to); // Save 'to' |
duke@435 | 1049 | __ leal(rsi, Address(from, count, sf, -4)); |
duke@435 | 1050 | __ leal(rdi, Address(to , count, sf, -4)); |
duke@435 | 1051 | __ shrl(count, shift); // bytes count |
duke@435 | 1052 | __ rep_movl(); |
duke@435 | 1053 | __ cld(); |
duke@435 | 1054 | __ movl(count, rax); // restore 'count' |
duke@435 | 1055 | __ andl(count, (1<<shift)-1); // mask the number of rest elements |
duke@435 | 1056 | __ movl(from, Address(rsp, 12+4)); // reread 'from' |
duke@435 | 1057 | __ movl(to, rdx); // restore 'to' |
duke@435 | 1058 | __ jmpb(L_copy_2_bytes); // all dword were copied |
duke@435 | 1059 | } else { |
duke@435 | 1060 | // Align to 8 bytes the end of array. It is aligned to 4 bytes already. |
duke@435 | 1061 | __ testl(end, 4); |
duke@435 | 1062 | __ jccb(Assembler::zero, L_copy_8_bytes); |
duke@435 | 1063 | __ subl(count, 1<<shift); |
duke@435 | 1064 | __ movl(rdx, Address(from, count, sf, 0)); |
duke@435 | 1065 | __ movl(Address(to, count, sf, 0), rdx); |
duke@435 | 1066 | __ jmpb(L_copy_8_bytes); |
duke@435 | 1067 | |
duke@435 | 1068 | __ align(16); |
duke@435 | 1069 | // Move 8 bytes |
duke@435 | 1070 | __ BIND(L_copy_8_bytes_loop); |
duke@435 | 1071 | __ movq(mmx0, Address(from, count, sf, 0)); |
duke@435 | 1072 | __ movq(Address(to, count, sf, 0), mmx0); |
duke@435 | 1073 | __ BIND(L_copy_8_bytes); |
duke@435 | 1074 | __ subl(count, 2<<shift); |
duke@435 | 1075 | __ jcc(Assembler::greaterEqual, L_copy_8_bytes_loop); |
duke@435 | 1076 | __ addl(count, 2<<shift); |
duke@435 | 1077 | __ emms(); |
duke@435 | 1078 | } |
duke@435 | 1079 | __ BIND(L_copy_4_bytes); |
duke@435 | 1080 | // copy prefix qword |
duke@435 | 1081 | __ testl(count, 1<<shift); |
duke@435 | 1082 | __ jccb(Assembler::zero, L_copy_2_bytes); |
duke@435 | 1083 | __ movl(rdx, Address(from, count, sf, -4)); |
duke@435 | 1084 | __ movl(Address(to, count, sf, -4), rdx); |
duke@435 | 1085 | |
duke@435 | 1086 | if (t == T_BYTE || t == T_SHORT) { |
duke@435 | 1087 | __ subl(count, (1<<shift)); |
duke@435 | 1088 | __ BIND(L_copy_2_bytes); |
duke@435 | 1089 | // copy prefix dword |
duke@435 | 1090 | __ testl(count, 1<<(shift-1)); |
duke@435 | 1091 | __ jccb(Assembler::zero, L_copy_byte); |
duke@435 | 1092 | __ movw(rdx, Address(from, count, sf, -2)); |
duke@435 | 1093 | __ movw(Address(to, count, sf, -2), rdx); |
duke@435 | 1094 | if (t == T_BYTE) { |
duke@435 | 1095 | __ subl(count, 1<<(shift-1)); |
duke@435 | 1096 | __ BIND(L_copy_byte); |
duke@435 | 1097 | // copy prefix byte |
duke@435 | 1098 | __ testl(count, 1); |
duke@435 | 1099 | __ jccb(Assembler::zero, L_exit); |
duke@435 | 1100 | __ movb(rdx, Address(from, 0)); |
duke@435 | 1101 | __ movb(Address(to, 0), rdx); |
duke@435 | 1102 | __ BIND(L_exit); |
duke@435 | 1103 | } else { |
duke@435 | 1104 | __ BIND(L_copy_byte); |
duke@435 | 1105 | } |
duke@435 | 1106 | } else { |
duke@435 | 1107 | __ BIND(L_copy_2_bytes); |
duke@435 | 1108 | } |
duke@435 | 1109 | if (t == T_OBJECT) { |
duke@435 | 1110 | __ movl(count, Address(rsp, 12+12)); // reread count |
duke@435 | 1111 | gen_write_ref_array_post_barrier(to, count); |
duke@435 | 1112 | __ BIND(L_0_count); |
duke@435 | 1113 | } |
duke@435 | 1114 | inc_copy_counter_np(t); |
duke@435 | 1115 | __ popl(rdi); |
duke@435 | 1116 | __ popl(rsi); |
duke@435 | 1117 | __ leave(); // required for proper stackwalking of RuntimeStub frame |
duke@435 | 1118 | __ xorl(rax, rax); // return 0 |
duke@435 | 1119 | __ ret(0); |
duke@435 | 1120 | return start; |
duke@435 | 1121 | } |
duke@435 | 1122 | |
duke@435 | 1123 | |
duke@435 | 1124 | address generate_disjoint_long_copy(address* entry, const char *name) { |
duke@435 | 1125 | __ align(CodeEntryAlignment); |
duke@435 | 1126 | StubCodeMark mark(this, "StubRoutines", name); |
duke@435 | 1127 | address start = __ pc(); |
duke@435 | 1128 | |
duke@435 | 1129 | Label L_copy_8_bytes, L_copy_8_bytes_loop; |
duke@435 | 1130 | const Register from = rax; // source array address |
duke@435 | 1131 | const Register to = rdx; // destination array address |
duke@435 | 1132 | const Register count = rcx; // elements count |
duke@435 | 1133 | const Register to_from = rdx; // (to - from) |
duke@435 | 1134 | |
duke@435 | 1135 | __ enter(); // required for proper stackwalking of RuntimeStub frame |
duke@435 | 1136 | __ movl(from , Address(rsp, 8+0)); // from |
duke@435 | 1137 | __ movl(to , Address(rsp, 8+4)); // to |
duke@435 | 1138 | __ movl(count, Address(rsp, 8+8)); // count |
duke@435 | 1139 | |
duke@435 | 1140 | *entry = __ pc(); // Entry point from conjoint arraycopy stub. |
duke@435 | 1141 | BLOCK_COMMENT("Entry:"); |
duke@435 | 1142 | |
duke@435 | 1143 | __ subl(to, from); // to --> to_from |
duke@435 | 1144 | if (VM_Version::supports_mmx()) { |
duke@435 | 1145 | mmx_copy_forward(from, to_from, count); |
duke@435 | 1146 | } else { |
duke@435 | 1147 | __ jmpb(L_copy_8_bytes); |
duke@435 | 1148 | __ align(16); |
duke@435 | 1149 | __ BIND(L_copy_8_bytes_loop); |
duke@435 | 1150 | __ fild_d(Address(from, 0)); |
duke@435 | 1151 | __ fistp_d(Address(from, to_from, Address::times_1)); |
duke@435 | 1152 | __ addl(from, 8); |
duke@435 | 1153 | __ BIND(L_copy_8_bytes); |
duke@435 | 1154 | __ decrement(count); |
duke@435 | 1155 | __ jcc(Assembler::greaterEqual, L_copy_8_bytes_loop); |
duke@435 | 1156 | } |
duke@435 | 1157 | inc_copy_counter_np(T_LONG); |
duke@435 | 1158 | __ leave(); // required for proper stackwalking of RuntimeStub frame |
duke@435 | 1159 | __ xorl(rax, rax); // return 0 |
duke@435 | 1160 | __ ret(0); |
duke@435 | 1161 | return start; |
duke@435 | 1162 | } |
duke@435 | 1163 | |
duke@435 | 1164 | address generate_conjoint_long_copy(address nooverlap_target, |
duke@435 | 1165 | address* entry, const char *name) { |
duke@435 | 1166 | __ align(CodeEntryAlignment); |
duke@435 | 1167 | StubCodeMark mark(this, "StubRoutines", name); |
duke@435 | 1168 | address start = __ pc(); |
duke@435 | 1169 | |
duke@435 | 1170 | Label L_copy_8_bytes, L_copy_8_bytes_loop; |
duke@435 | 1171 | const Register from = rax; // source array address |
duke@435 | 1172 | const Register to = rdx; // destination array address |
duke@435 | 1173 | const Register count = rcx; // elements count |
duke@435 | 1174 | const Register end_from = rax; // source array end address |
duke@435 | 1175 | |
duke@435 | 1176 | __ enter(); // required for proper stackwalking of RuntimeStub frame |
duke@435 | 1177 | __ movl(from , Address(rsp, 8+0)); // from |
duke@435 | 1178 | __ movl(to , Address(rsp, 8+4)); // to |
duke@435 | 1179 | __ movl(count, Address(rsp, 8+8)); // count |
duke@435 | 1180 | |
duke@435 | 1181 | *entry = __ pc(); // Entry point from generic arraycopy stub. |
duke@435 | 1182 | BLOCK_COMMENT("Entry:"); |
duke@435 | 1183 | |
duke@435 | 1184 | // arrays overlap test |
duke@435 | 1185 | __ cmpl(to, from); |
duke@435 | 1186 | RuntimeAddress nooverlap(nooverlap_target); |
duke@435 | 1187 | __ jump_cc(Assembler::belowEqual, nooverlap); |
duke@435 | 1188 | __ leal(end_from, Address(from, count, Address::times_8, 0)); |
duke@435 | 1189 | __ cmpl(to, end_from); |
duke@435 | 1190 | __ movl(from, Address(rsp, 8)); // from |
duke@435 | 1191 | __ jump_cc(Assembler::aboveEqual, nooverlap); |
duke@435 | 1192 | |
duke@435 | 1193 | __ jmpb(L_copy_8_bytes); |
duke@435 | 1194 | |
duke@435 | 1195 | __ align(16); |
duke@435 | 1196 | __ BIND(L_copy_8_bytes_loop); |
duke@435 | 1197 | if (VM_Version::supports_mmx()) { |
duke@435 | 1198 | __ movq(mmx0, Address(from, count, Address::times_8)); |
duke@435 | 1199 | __ movq(Address(to, count, Address::times_8), mmx0); |
duke@435 | 1200 | } else { |
duke@435 | 1201 | __ fild_d(Address(from, count, Address::times_8)); |
duke@435 | 1202 | __ fistp_d(Address(to, count, Address::times_8)); |
duke@435 | 1203 | } |
duke@435 | 1204 | __ BIND(L_copy_8_bytes); |
duke@435 | 1205 | __ decrement(count); |
duke@435 | 1206 | __ jcc(Assembler::greaterEqual, L_copy_8_bytes_loop); |
duke@435 | 1207 | |
duke@435 | 1208 | if (VM_Version::supports_mmx()) { |
duke@435 | 1209 | __ emms(); |
duke@435 | 1210 | } |
duke@435 | 1211 | inc_copy_counter_np(T_LONG); |
duke@435 | 1212 | __ leave(); // required for proper stackwalking of RuntimeStub frame |
duke@435 | 1213 | __ xorl(rax, rax); // return 0 |
duke@435 | 1214 | __ ret(0); |
duke@435 | 1215 | return start; |
duke@435 | 1216 | } |
duke@435 | 1217 | |
duke@435 | 1218 | |
duke@435 | 1219 | // Helper for generating a dynamic type check. |
duke@435 | 1220 | // The sub_klass must be one of {rbx, rdx, rsi}. |
duke@435 | 1221 | // The temp is killed. |
duke@435 | 1222 | void generate_type_check(Register sub_klass, |
duke@435 | 1223 | Address& super_check_offset_addr, |
duke@435 | 1224 | Address& super_klass_addr, |
duke@435 | 1225 | Register temp, |
duke@435 | 1226 | Label* L_success_ptr, Label* L_failure_ptr) { |
duke@435 | 1227 | BLOCK_COMMENT("type_check:"); |
duke@435 | 1228 | |
duke@435 | 1229 | Label L_fallthrough; |
duke@435 | 1230 | bool fall_through_on_success = (L_success_ptr == NULL); |
duke@435 | 1231 | if (fall_through_on_success) { |
duke@435 | 1232 | L_success_ptr = &L_fallthrough; |
duke@435 | 1233 | } else { |
duke@435 | 1234 | L_failure_ptr = &L_fallthrough; |
duke@435 | 1235 | } |
duke@435 | 1236 | Label& L_success = *L_success_ptr; |
duke@435 | 1237 | Label& L_failure = *L_failure_ptr; |
duke@435 | 1238 | |
duke@435 | 1239 | assert_different_registers(sub_klass, temp); |
duke@435 | 1240 | |
duke@435 | 1241 | // a couple of useful fields in sub_klass: |
duke@435 | 1242 | int ss_offset = (klassOopDesc::header_size() * HeapWordSize + |
duke@435 | 1243 | Klass::secondary_supers_offset_in_bytes()); |
duke@435 | 1244 | int sc_offset = (klassOopDesc::header_size() * HeapWordSize + |
duke@435 | 1245 | Klass::secondary_super_cache_offset_in_bytes()); |
duke@435 | 1246 | Address secondary_supers_addr(sub_klass, ss_offset); |
duke@435 | 1247 | Address super_cache_addr( sub_klass, sc_offset); |
duke@435 | 1248 | |
duke@435 | 1249 | // if the pointers are equal, we are done (e.g., String[] elements) |
duke@435 | 1250 | __ cmpl(sub_klass, super_klass_addr); |
duke@435 | 1251 | __ jcc(Assembler::equal, L_success); |
duke@435 | 1252 | |
duke@435 | 1253 | // check the supertype display: |
duke@435 | 1254 | __ movl(temp, super_check_offset_addr); |
duke@435 | 1255 | Address super_check_addr(sub_klass, temp, Address::times_1, 0); |
duke@435 | 1256 | __ movl(temp, super_check_addr); // load displayed supertype |
duke@435 | 1257 | __ cmpl(temp, super_klass_addr); // test the super type |
duke@435 | 1258 | __ jcc(Assembler::equal, L_success); |
duke@435 | 1259 | |
duke@435 | 1260 | // if it was a primary super, we can just fail immediately |
duke@435 | 1261 | __ cmpl(super_check_offset_addr, sc_offset); |
duke@435 | 1262 | __ jcc(Assembler::notEqual, L_failure); |
duke@435 | 1263 | |
duke@435 | 1264 | // Now do a linear scan of the secondary super-klass chain. |
duke@435 | 1265 | // This code is rarely used, so simplicity is a virtue here. |
duke@435 | 1266 | inc_counter_np(SharedRuntime::_partial_subtype_ctr); |
duke@435 | 1267 | { |
duke@435 | 1268 | // The repne_scan instruction uses fixed registers, which we must spill. |
duke@435 | 1269 | // (We need a couple more temps in any case.) |
duke@435 | 1270 | __ pushl(rax); |
duke@435 | 1271 | __ pushl(rcx); |
duke@435 | 1272 | __ pushl(rdi); |
duke@435 | 1273 | assert_different_registers(sub_klass, rax, rcx, rdi); |
duke@435 | 1274 | |
duke@435 | 1275 | __ movl(rdi, secondary_supers_addr); |
duke@435 | 1276 | // Load the array length. |
duke@435 | 1277 | __ movl(rcx, Address(rdi, arrayOopDesc::length_offset_in_bytes())); |
duke@435 | 1278 | // Skip to start of data. |
duke@435 | 1279 | __ addl(rdi, arrayOopDesc::base_offset_in_bytes(T_OBJECT)); |
duke@435 | 1280 | // Scan rcx words at [edi] for occurance of rax, |
duke@435 | 1281 | // Set NZ/Z based on last compare |
duke@435 | 1282 | __ movl(rax, super_klass_addr); |
duke@435 | 1283 | __ repne_scan(); |
duke@435 | 1284 | |
duke@435 | 1285 | // Unspill the temp. registers: |
duke@435 | 1286 | __ popl(rdi); |
duke@435 | 1287 | __ popl(rcx); |
duke@435 | 1288 | __ popl(rax); |
duke@435 | 1289 | } |
duke@435 | 1290 | __ jcc(Assembler::notEqual, L_failure); |
duke@435 | 1291 | |
duke@435 | 1292 | // Success. Cache the super we found and proceed in triumph. |
duke@435 | 1293 | __ movl(temp, super_klass_addr); // note: rax, is dead |
duke@435 | 1294 | __ movl(super_cache_addr, temp); |
duke@435 | 1295 | |
duke@435 | 1296 | if (!fall_through_on_success) |
duke@435 | 1297 | __ jmp(L_success); |
duke@435 | 1298 | |
duke@435 | 1299 | // Fall through on failure! |
duke@435 | 1300 | __ bind(L_fallthrough); |
duke@435 | 1301 | } |
duke@435 | 1302 | |
duke@435 | 1303 | // |
duke@435 | 1304 | // Generate checkcasting array copy stub |
duke@435 | 1305 | // |
duke@435 | 1306 | // Input: |
duke@435 | 1307 | // 4(rsp) - source array address |
duke@435 | 1308 | // 8(rsp) - destination array address |
duke@435 | 1309 | // 12(rsp) - element count, can be zero |
duke@435 | 1310 | // 16(rsp) - size_t ckoff (super_check_offset) |
duke@435 | 1311 | // 20(rsp) - oop ckval (super_klass) |
duke@435 | 1312 | // |
duke@435 | 1313 | // Output: |
duke@435 | 1314 | // rax, == 0 - success |
duke@435 | 1315 | // rax, == -1^K - failure, where K is partial transfer count |
duke@435 | 1316 | // |
duke@435 | 1317 | address generate_checkcast_copy(const char *name, address* entry) { |
duke@435 | 1318 | __ align(CodeEntryAlignment); |
duke@435 | 1319 | StubCodeMark mark(this, "StubRoutines", name); |
duke@435 | 1320 | address start = __ pc(); |
duke@435 | 1321 | |
duke@435 | 1322 | Label L_load_element, L_store_element, L_do_card_marks, L_done; |
duke@435 | 1323 | |
duke@435 | 1324 | // register use: |
duke@435 | 1325 | // rax, rdx, rcx -- loop control (end_from, end_to, count) |
duke@435 | 1326 | // rdi, rsi -- element access (oop, klass) |
duke@435 | 1327 | // rbx, -- temp |
duke@435 | 1328 | const Register from = rax; // source array address |
duke@435 | 1329 | const Register to = rdx; // destination array address |
duke@435 | 1330 | const Register length = rcx; // elements count |
duke@435 | 1331 | const Register elem = rdi; // each oop copied |
duke@435 | 1332 | const Register elem_klass = rsi; // each elem._klass (sub_klass) |
duke@435 | 1333 | const Register temp = rbx; // lone remaining temp |
duke@435 | 1334 | |
duke@435 | 1335 | __ enter(); // required for proper stackwalking of RuntimeStub frame |
duke@435 | 1336 | |
duke@435 | 1337 | __ pushl(rsi); |
duke@435 | 1338 | __ pushl(rdi); |
duke@435 | 1339 | __ pushl(rbx); |
duke@435 | 1340 | |
duke@435 | 1341 | Address from_arg(rsp, 16+ 4); // from |
duke@435 | 1342 | Address to_arg(rsp, 16+ 8); // to |
duke@435 | 1343 | Address length_arg(rsp, 16+12); // elements count |
duke@435 | 1344 | Address ckoff_arg(rsp, 16+16); // super_check_offset |
duke@435 | 1345 | Address ckval_arg(rsp, 16+20); // super_klass |
duke@435 | 1346 | |
duke@435 | 1347 | // Load up: |
duke@435 | 1348 | __ movl(from, from_arg); |
duke@435 | 1349 | __ movl(to, to_arg); |
duke@435 | 1350 | __ movl(length, length_arg); |
duke@435 | 1351 | |
duke@435 | 1352 | *entry = __ pc(); // Entry point from generic arraycopy stub. |
duke@435 | 1353 | BLOCK_COMMENT("Entry:"); |
duke@435 | 1354 | |
duke@435 | 1355 | //--------------------------------------------------------------- |
duke@435 | 1356 | // Assembler stub will be used for this call to arraycopy |
duke@435 | 1357 | // if the two arrays are subtypes of Object[] but the |
duke@435 | 1358 | // destination array type is not equal to or a supertype |
duke@435 | 1359 | // of the source type. Each element must be separately |
duke@435 | 1360 | // checked. |
duke@435 | 1361 | |
duke@435 | 1362 | // Loop-invariant addresses. They are exclusive end pointers. |
duke@435 | 1363 | Address end_from_addr(from, length, Address::times_4, 0); |
duke@435 | 1364 | Address end_to_addr(to, length, Address::times_4, 0); |
duke@435 | 1365 | |
duke@435 | 1366 | Register end_from = from; // re-use |
duke@435 | 1367 | Register end_to = to; // re-use |
duke@435 | 1368 | Register count = length; // re-use |
duke@435 | 1369 | |
duke@435 | 1370 | // Loop-variant addresses. They assume post-incremented count < 0. |
duke@435 | 1371 | Address from_element_addr(end_from, count, Address::times_4, 0); |
duke@435 | 1372 | Address to_element_addr(end_to, count, Address::times_4, 0); |
duke@435 | 1373 | Address elem_klass_addr(elem, oopDesc::klass_offset_in_bytes()); |
duke@435 | 1374 | |
duke@435 | 1375 | // Copy from low to high addresses, indexed from the end of each array. |
ysr@777 | 1376 | gen_write_ref_array_pre_barrier(to, count); |
duke@435 | 1377 | __ leal(end_from, end_from_addr); |
duke@435 | 1378 | __ leal(end_to, end_to_addr); |
duke@435 | 1379 | assert(length == count, ""); // else fix next line: |
duke@435 | 1380 | __ negl(count); // negate and test the length |
duke@435 | 1381 | __ jccb(Assembler::notZero, L_load_element); |
duke@435 | 1382 | |
duke@435 | 1383 | // Empty array: Nothing to do. |
duke@435 | 1384 | __ xorl(rax, rax); // return 0 on (trivial) success |
duke@435 | 1385 | __ jmp(L_done); |
duke@435 | 1386 | |
duke@435 | 1387 | // ======== begin loop ======== |
duke@435 | 1388 | // (Loop is rotated; its entry is L_load_element.) |
duke@435 | 1389 | // Loop control: |
duke@435 | 1390 | // for (count = -count; count != 0; count++) |
duke@435 | 1391 | // Base pointers src, dst are biased by 8*count,to last element. |
duke@435 | 1392 | __ align(16); |
duke@435 | 1393 | |
duke@435 | 1394 | __ BIND(L_store_element); |
duke@435 | 1395 | __ movl(to_element_addr, elem); // store the oop |
duke@435 | 1396 | __ increment(count); // increment the count toward zero |
duke@435 | 1397 | __ jccb(Assembler::zero, L_do_card_marks); |
duke@435 | 1398 | |
duke@435 | 1399 | // ======== loop entry is here ======== |
duke@435 | 1400 | __ BIND(L_load_element); |
duke@435 | 1401 | __ movl(elem, from_element_addr); // load the oop |
duke@435 | 1402 | __ testl(elem, elem); |
duke@435 | 1403 | __ jccb(Assembler::zero, L_store_element); |
duke@435 | 1404 | |
duke@435 | 1405 | // (Could do a trick here: Remember last successful non-null |
duke@435 | 1406 | // element stored and make a quick oop equality check on it.) |
duke@435 | 1407 | |
duke@435 | 1408 | __ movl(elem_klass, elem_klass_addr); // query the object klass |
duke@435 | 1409 | generate_type_check(elem_klass, ckoff_arg, ckval_arg, temp, |
duke@435 | 1410 | &L_store_element, NULL); |
duke@435 | 1411 | // (On fall-through, we have failed the element type check.) |
duke@435 | 1412 | // ======== end loop ======== |
duke@435 | 1413 | |
duke@435 | 1414 | // It was a real error; we must depend on the caller to finish the job. |
rasbold@454 | 1415 | // Register "count" = -1 * number of *remaining* oops, length_arg = *total* oops. |
rasbold@454 | 1416 | // Emit GC store barriers for the oops we have copied (length_arg + count), |
duke@435 | 1417 | // and report their number to the caller. |
duke@435 | 1418 | __ addl(count, length_arg); // transfers = (length - remaining) |
duke@435 | 1419 | __ movl(rax, count); // save the value |
duke@435 | 1420 | __ notl(rax); // report (-1^K) to caller |
duke@435 | 1421 | __ movl(to, to_arg); // reload |
duke@435 | 1422 | assert_different_registers(to, count, rax); |
duke@435 | 1423 | gen_write_ref_array_post_barrier(to, count); |
duke@435 | 1424 | __ jmpb(L_done); |
duke@435 | 1425 | |
duke@435 | 1426 | // Come here on success only. |
duke@435 | 1427 | __ BIND(L_do_card_marks); |
duke@435 | 1428 | __ movl(count, length_arg); |
rasbold@454 | 1429 | __ movl(to, to_arg); // reload |
duke@435 | 1430 | gen_write_ref_array_post_barrier(to, count); |
duke@435 | 1431 | __ xorl(rax, rax); // return 0 on success |
duke@435 | 1432 | |
duke@435 | 1433 | // Common exit point (success or failure). |
duke@435 | 1434 | __ BIND(L_done); |
duke@435 | 1435 | __ popl(rbx); |
duke@435 | 1436 | __ popl(rdi); |
duke@435 | 1437 | __ popl(rsi); |
duke@435 | 1438 | inc_counter_np(SharedRuntime::_checkcast_array_copy_ctr); |
duke@435 | 1439 | __ leave(); // required for proper stackwalking of RuntimeStub frame |
duke@435 | 1440 | __ ret(0); |
duke@435 | 1441 | |
duke@435 | 1442 | return start; |
duke@435 | 1443 | } |
duke@435 | 1444 | |
duke@435 | 1445 | // |
duke@435 | 1446 | // Generate 'unsafe' array copy stub |
duke@435 | 1447 | // Though just as safe as the other stubs, it takes an unscaled |
duke@435 | 1448 | // size_t argument instead of an element count. |
duke@435 | 1449 | // |
duke@435 | 1450 | // Input: |
duke@435 | 1451 | // 4(rsp) - source array address |
duke@435 | 1452 | // 8(rsp) - destination array address |
duke@435 | 1453 | // 12(rsp) - byte count, can be zero |
duke@435 | 1454 | // |
duke@435 | 1455 | // Output: |
duke@435 | 1456 | // rax, == 0 - success |
duke@435 | 1457 | // rax, == -1 - need to call System.arraycopy |
duke@435 | 1458 | // |
duke@435 | 1459 | // Examines the alignment of the operands and dispatches |
duke@435 | 1460 | // to a long, int, short, or byte copy loop. |
duke@435 | 1461 | // |
duke@435 | 1462 | address generate_unsafe_copy(const char *name, |
duke@435 | 1463 | address byte_copy_entry, |
duke@435 | 1464 | address short_copy_entry, |
duke@435 | 1465 | address int_copy_entry, |
duke@435 | 1466 | address long_copy_entry) { |
duke@435 | 1467 | |
duke@435 | 1468 | Label L_long_aligned, L_int_aligned, L_short_aligned; |
duke@435 | 1469 | |
duke@435 | 1470 | __ align(CodeEntryAlignment); |
duke@435 | 1471 | StubCodeMark mark(this, "StubRoutines", name); |
duke@435 | 1472 | address start = __ pc(); |
duke@435 | 1473 | |
duke@435 | 1474 | const Register from = rax; // source array address |
duke@435 | 1475 | const Register to = rdx; // destination array address |
duke@435 | 1476 | const Register count = rcx; // elements count |
duke@435 | 1477 | |
duke@435 | 1478 | __ enter(); // required for proper stackwalking of RuntimeStub frame |
duke@435 | 1479 | __ pushl(rsi); |
duke@435 | 1480 | __ pushl(rdi); |
duke@435 | 1481 | Address from_arg(rsp, 12+ 4); // from |
duke@435 | 1482 | Address to_arg(rsp, 12+ 8); // to |
duke@435 | 1483 | Address count_arg(rsp, 12+12); // byte count |
duke@435 | 1484 | |
duke@435 | 1485 | // Load up: |
duke@435 | 1486 | __ movl(from , from_arg); |
duke@435 | 1487 | __ movl(to , to_arg); |
duke@435 | 1488 | __ movl(count, count_arg); |
duke@435 | 1489 | |
duke@435 | 1490 | // bump this on entry, not on exit: |
duke@435 | 1491 | inc_counter_np(SharedRuntime::_unsafe_array_copy_ctr); |
duke@435 | 1492 | |
duke@435 | 1493 | const Register bits = rsi; |
duke@435 | 1494 | __ movl(bits, from); |
duke@435 | 1495 | __ orl(bits, to); |
duke@435 | 1496 | __ orl(bits, count); |
duke@435 | 1497 | |
duke@435 | 1498 | __ testl(bits, BytesPerLong-1); |
duke@435 | 1499 | __ jccb(Assembler::zero, L_long_aligned); |
duke@435 | 1500 | |
duke@435 | 1501 | __ testl(bits, BytesPerInt-1); |
duke@435 | 1502 | __ jccb(Assembler::zero, L_int_aligned); |
duke@435 | 1503 | |
duke@435 | 1504 | __ testl(bits, BytesPerShort-1); |
duke@435 | 1505 | __ jump_cc(Assembler::notZero, RuntimeAddress(byte_copy_entry)); |
duke@435 | 1506 | |
duke@435 | 1507 | __ BIND(L_short_aligned); |
duke@435 | 1508 | __ shrl(count, LogBytesPerShort); // size => short_count |
duke@435 | 1509 | __ movl(count_arg, count); // update 'count' |
duke@435 | 1510 | __ jump(RuntimeAddress(short_copy_entry)); |
duke@435 | 1511 | |
duke@435 | 1512 | __ BIND(L_int_aligned); |
duke@435 | 1513 | __ shrl(count, LogBytesPerInt); // size => int_count |
duke@435 | 1514 | __ movl(count_arg, count); // update 'count' |
duke@435 | 1515 | __ jump(RuntimeAddress(int_copy_entry)); |
duke@435 | 1516 | |
duke@435 | 1517 | __ BIND(L_long_aligned); |
duke@435 | 1518 | __ shrl(count, LogBytesPerLong); // size => qword_count |
duke@435 | 1519 | __ movl(count_arg, count); // update 'count' |
duke@435 | 1520 | __ popl(rdi); // Do pops here since jlong_arraycopy stub does not do it. |
duke@435 | 1521 | __ popl(rsi); |
duke@435 | 1522 | __ jump(RuntimeAddress(long_copy_entry)); |
duke@435 | 1523 | |
duke@435 | 1524 | return start; |
duke@435 | 1525 | } |
duke@435 | 1526 | |
duke@435 | 1527 | |
duke@435 | 1528 | // Perform range checks on the proposed arraycopy. |
duke@435 | 1529 | // Smashes src_pos and dst_pos. (Uses them up for temps.) |
duke@435 | 1530 | void arraycopy_range_checks(Register src, |
duke@435 | 1531 | Register src_pos, |
duke@435 | 1532 | Register dst, |
duke@435 | 1533 | Register dst_pos, |
duke@435 | 1534 | Address& length, |
duke@435 | 1535 | Label& L_failed) { |
duke@435 | 1536 | BLOCK_COMMENT("arraycopy_range_checks:"); |
duke@435 | 1537 | const Register src_end = src_pos; // source array end position |
duke@435 | 1538 | const Register dst_end = dst_pos; // destination array end position |
duke@435 | 1539 | __ addl(src_end, length); // src_pos + length |
duke@435 | 1540 | __ addl(dst_end, length); // dst_pos + length |
duke@435 | 1541 | |
duke@435 | 1542 | // if (src_pos + length > arrayOop(src)->length() ) FAIL; |
duke@435 | 1543 | __ cmpl(src_end, Address(src, arrayOopDesc::length_offset_in_bytes())); |
duke@435 | 1544 | __ jcc(Assembler::above, L_failed); |
duke@435 | 1545 | |
duke@435 | 1546 | // if (dst_pos + length > arrayOop(dst)->length() ) FAIL; |
duke@435 | 1547 | __ cmpl(dst_end, Address(dst, arrayOopDesc::length_offset_in_bytes())); |
duke@435 | 1548 | __ jcc(Assembler::above, L_failed); |
duke@435 | 1549 | |
duke@435 | 1550 | BLOCK_COMMENT("arraycopy_range_checks done"); |
duke@435 | 1551 | } |
duke@435 | 1552 | |
duke@435 | 1553 | |
duke@435 | 1554 | // |
duke@435 | 1555 | // Generate generic array copy stubs |
duke@435 | 1556 | // |
duke@435 | 1557 | // Input: |
duke@435 | 1558 | // 4(rsp) - src oop |
duke@435 | 1559 | // 8(rsp) - src_pos |
duke@435 | 1560 | // 12(rsp) - dst oop |
duke@435 | 1561 | // 16(rsp) - dst_pos |
duke@435 | 1562 | // 20(rsp) - element count |
duke@435 | 1563 | // |
duke@435 | 1564 | // Output: |
duke@435 | 1565 | // rax, == 0 - success |
duke@435 | 1566 | // rax, == -1^K - failure, where K is partial transfer count |
duke@435 | 1567 | // |
duke@435 | 1568 | address generate_generic_copy(const char *name, |
duke@435 | 1569 | address entry_jbyte_arraycopy, |
duke@435 | 1570 | address entry_jshort_arraycopy, |
duke@435 | 1571 | address entry_jint_arraycopy, |
duke@435 | 1572 | address entry_oop_arraycopy, |
duke@435 | 1573 | address entry_jlong_arraycopy, |
duke@435 | 1574 | address entry_checkcast_arraycopy) { |
duke@435 | 1575 | Label L_failed, L_failed_0, L_objArray; |
duke@435 | 1576 | |
duke@435 | 1577 | { int modulus = CodeEntryAlignment; |
duke@435 | 1578 | int target = modulus - 5; // 5 = sizeof jmp(L_failed) |
duke@435 | 1579 | int advance = target - (__ offset() % modulus); |
duke@435 | 1580 | if (advance < 0) advance += modulus; |
duke@435 | 1581 | if (advance > 0) __ nop(advance); |
duke@435 | 1582 | } |
duke@435 | 1583 | StubCodeMark mark(this, "StubRoutines", name); |
duke@435 | 1584 | |
duke@435 | 1585 | // Short-hop target to L_failed. Makes for denser prologue code. |
duke@435 | 1586 | __ BIND(L_failed_0); |
duke@435 | 1587 | __ jmp(L_failed); |
duke@435 | 1588 | assert(__ offset() % CodeEntryAlignment == 0, "no further alignment needed"); |
duke@435 | 1589 | |
duke@435 | 1590 | __ align(CodeEntryAlignment); |
duke@435 | 1591 | address start = __ pc(); |
duke@435 | 1592 | |
duke@435 | 1593 | __ enter(); // required for proper stackwalking of RuntimeStub frame |
duke@435 | 1594 | __ pushl(rsi); |
duke@435 | 1595 | __ pushl(rdi); |
duke@435 | 1596 | |
duke@435 | 1597 | // bump this on entry, not on exit: |
duke@435 | 1598 | inc_counter_np(SharedRuntime::_generic_array_copy_ctr); |
duke@435 | 1599 | |
duke@435 | 1600 | // Input values |
duke@435 | 1601 | Address SRC (rsp, 12+ 4); |
duke@435 | 1602 | Address SRC_POS (rsp, 12+ 8); |
duke@435 | 1603 | Address DST (rsp, 12+12); |
duke@435 | 1604 | Address DST_POS (rsp, 12+16); |
duke@435 | 1605 | Address LENGTH (rsp, 12+20); |
duke@435 | 1606 | |
duke@435 | 1607 | //----------------------------------------------------------------------- |
duke@435 | 1608 | // Assembler stub will be used for this call to arraycopy |
duke@435 | 1609 | // if the following conditions are met: |
duke@435 | 1610 | // |
duke@435 | 1611 | // (1) src and dst must not be null. |
duke@435 | 1612 | // (2) src_pos must not be negative. |
duke@435 | 1613 | // (3) dst_pos must not be negative. |
duke@435 | 1614 | // (4) length must not be negative. |
duke@435 | 1615 | // (5) src klass and dst klass should be the same and not NULL. |
duke@435 | 1616 | // (6) src and dst should be arrays. |
duke@435 | 1617 | // (7) src_pos + length must not exceed length of src. |
duke@435 | 1618 | // (8) dst_pos + length must not exceed length of dst. |
duke@435 | 1619 | // |
duke@435 | 1620 | |
duke@435 | 1621 | const Register src = rax; // source array oop |
duke@435 | 1622 | const Register src_pos = rsi; |
duke@435 | 1623 | const Register dst = rdx; // destination array oop |
duke@435 | 1624 | const Register dst_pos = rdi; |
duke@435 | 1625 | const Register length = rcx; // transfer count |
duke@435 | 1626 | |
duke@435 | 1627 | // if (src == NULL) return -1; |
duke@435 | 1628 | __ movl(src, SRC); // src oop |
duke@435 | 1629 | __ testl(src, src); |
duke@435 | 1630 | __ jccb(Assembler::zero, L_failed_0); |
duke@435 | 1631 | |
duke@435 | 1632 | // if (src_pos < 0) return -1; |
duke@435 | 1633 | __ movl(src_pos, SRC_POS); // src_pos |
duke@435 | 1634 | __ testl(src_pos, src_pos); |
duke@435 | 1635 | __ jccb(Assembler::negative, L_failed_0); |
duke@435 | 1636 | |
duke@435 | 1637 | // if (dst == NULL) return -1; |
duke@435 | 1638 | __ movl(dst, DST); // dst oop |
duke@435 | 1639 | __ testl(dst, dst); |
duke@435 | 1640 | __ jccb(Assembler::zero, L_failed_0); |
duke@435 | 1641 | |
duke@435 | 1642 | // if (dst_pos < 0) return -1; |
duke@435 | 1643 | __ movl(dst_pos, DST_POS); // dst_pos |
duke@435 | 1644 | __ testl(dst_pos, dst_pos); |
duke@435 | 1645 | __ jccb(Assembler::negative, L_failed_0); |
duke@435 | 1646 | |
duke@435 | 1647 | // if (length < 0) return -1; |
duke@435 | 1648 | __ movl(length, LENGTH); // length |
duke@435 | 1649 | __ testl(length, length); |
duke@435 | 1650 | __ jccb(Assembler::negative, L_failed_0); |
duke@435 | 1651 | |
duke@435 | 1652 | // if (src->klass() == NULL) return -1; |
duke@435 | 1653 | Address src_klass_addr(src, oopDesc::klass_offset_in_bytes()); |
duke@435 | 1654 | Address dst_klass_addr(dst, oopDesc::klass_offset_in_bytes()); |
duke@435 | 1655 | const Register rcx_src_klass = rcx; // array klass |
duke@435 | 1656 | __ movl(rcx_src_klass, Address(src, oopDesc::klass_offset_in_bytes())); |
duke@435 | 1657 | |
duke@435 | 1658 | #ifdef ASSERT |
duke@435 | 1659 | // assert(src->klass() != NULL); |
duke@435 | 1660 | BLOCK_COMMENT("assert klasses not null"); |
duke@435 | 1661 | { Label L1, L2; |
duke@435 | 1662 | __ testl(rcx_src_klass, rcx_src_klass); |
duke@435 | 1663 | __ jccb(Assembler::notZero, L2); // it is broken if klass is NULL |
duke@435 | 1664 | __ bind(L1); |
duke@435 | 1665 | __ stop("broken null klass"); |
duke@435 | 1666 | __ bind(L2); |
duke@435 | 1667 | __ cmpl(dst_klass_addr, 0); |
duke@435 | 1668 | __ jccb(Assembler::equal, L1); // this would be broken also |
duke@435 | 1669 | BLOCK_COMMENT("assert done"); |
duke@435 | 1670 | } |
duke@435 | 1671 | #endif //ASSERT |
duke@435 | 1672 | |
duke@435 | 1673 | // Load layout helper (32-bits) |
duke@435 | 1674 | // |
duke@435 | 1675 | // |array_tag| | header_size | element_type | |log2_element_size| |
duke@435 | 1676 | // 32 30 24 16 8 2 0 |
duke@435 | 1677 | // |
duke@435 | 1678 | // array_tag: typeArray = 0x3, objArray = 0x2, non-array = 0x0 |
duke@435 | 1679 | // |
duke@435 | 1680 | |
duke@435 | 1681 | int lh_offset = klassOopDesc::header_size() * HeapWordSize + |
duke@435 | 1682 | Klass::layout_helper_offset_in_bytes(); |
duke@435 | 1683 | Address src_klass_lh_addr(rcx_src_klass, lh_offset); |
duke@435 | 1684 | |
duke@435 | 1685 | // Handle objArrays completely differently... |
duke@435 | 1686 | jint objArray_lh = Klass::array_layout_helper(T_OBJECT); |
duke@435 | 1687 | __ cmpl(src_klass_lh_addr, objArray_lh); |
duke@435 | 1688 | __ jcc(Assembler::equal, L_objArray); |
duke@435 | 1689 | |
duke@435 | 1690 | // if (src->klass() != dst->klass()) return -1; |
duke@435 | 1691 | __ cmpl(rcx_src_klass, dst_klass_addr); |
duke@435 | 1692 | __ jccb(Assembler::notEqual, L_failed_0); |
duke@435 | 1693 | |
duke@435 | 1694 | const Register rcx_lh = rcx; // layout helper |
duke@435 | 1695 | assert(rcx_lh == rcx_src_klass, "known alias"); |
duke@435 | 1696 | __ movl(rcx_lh, src_klass_lh_addr); |
duke@435 | 1697 | |
duke@435 | 1698 | // if (!src->is_Array()) return -1; |
duke@435 | 1699 | __ cmpl(rcx_lh, Klass::_lh_neutral_value); |
duke@435 | 1700 | __ jcc(Assembler::greaterEqual, L_failed_0); // signed cmp |
duke@435 | 1701 | |
duke@435 | 1702 | // At this point, it is known to be a typeArray (array_tag 0x3). |
duke@435 | 1703 | #ifdef ASSERT |
duke@435 | 1704 | { Label L; |
duke@435 | 1705 | __ cmpl(rcx_lh, (Klass::_lh_array_tag_type_value << Klass::_lh_array_tag_shift)); |
duke@435 | 1706 | __ jcc(Assembler::greaterEqual, L); // signed cmp |
duke@435 | 1707 | __ stop("must be a primitive array"); |
duke@435 | 1708 | __ bind(L); |
duke@435 | 1709 | } |
duke@435 | 1710 | #endif |
duke@435 | 1711 | |
duke@435 | 1712 | assert_different_registers(src, src_pos, dst, dst_pos, rcx_lh); |
duke@435 | 1713 | arraycopy_range_checks(src, src_pos, dst, dst_pos, LENGTH, L_failed); |
duke@435 | 1714 | |
duke@435 | 1715 | // typeArrayKlass |
duke@435 | 1716 | // |
duke@435 | 1717 | // src_addr = (src + array_header_in_bytes()) + (src_pos << log2elemsize); |
duke@435 | 1718 | // dst_addr = (dst + array_header_in_bytes()) + (dst_pos << log2elemsize); |
duke@435 | 1719 | // |
duke@435 | 1720 | const Register rsi_offset = rsi; // array offset |
duke@435 | 1721 | const Register src_array = src; // src array offset |
duke@435 | 1722 | const Register dst_array = dst; // dst array offset |
duke@435 | 1723 | const Register rdi_elsize = rdi; // log2 element size |
duke@435 | 1724 | |
duke@435 | 1725 | __ movl(rsi_offset, rcx_lh); |
duke@435 | 1726 | __ shrl(rsi_offset, Klass::_lh_header_size_shift); |
duke@435 | 1727 | __ andl(rsi_offset, Klass::_lh_header_size_mask); // array_offset |
duke@435 | 1728 | __ addl(src_array, rsi_offset); // src array offset |
duke@435 | 1729 | __ addl(dst_array, rsi_offset); // dst array offset |
duke@435 | 1730 | __ andl(rcx_lh, Klass::_lh_log2_element_size_mask); // log2 elsize |
duke@435 | 1731 | |
duke@435 | 1732 | // next registers should be set before the jump to corresponding stub |
duke@435 | 1733 | const Register from = src; // source array address |
duke@435 | 1734 | const Register to = dst; // destination array address |
duke@435 | 1735 | const Register count = rcx; // elements count |
duke@435 | 1736 | // some of them should be duplicated on stack |
duke@435 | 1737 | #define FROM Address(rsp, 12+ 4) |
duke@435 | 1738 | #define TO Address(rsp, 12+ 8) // Not used now |
duke@435 | 1739 | #define COUNT Address(rsp, 12+12) // Only for oop arraycopy |
duke@435 | 1740 | |
duke@435 | 1741 | BLOCK_COMMENT("scale indexes to element size"); |
duke@435 | 1742 | __ movl(rsi, SRC_POS); // src_pos |
duke@435 | 1743 | __ shll(rsi); // src_pos << rcx (log2 elsize) |
duke@435 | 1744 | assert(src_array == from, ""); |
duke@435 | 1745 | __ addl(from, rsi); // from = src_array + SRC_POS << log2 elsize |
duke@435 | 1746 | __ movl(rdi, DST_POS); // dst_pos |
duke@435 | 1747 | __ shll(rdi); // dst_pos << rcx (log2 elsize) |
duke@435 | 1748 | assert(dst_array == to, ""); |
duke@435 | 1749 | __ addl(to, rdi); // to = dst_array + DST_POS << log2 elsize |
duke@435 | 1750 | __ movl(FROM, from); // src_addr |
duke@435 | 1751 | __ movl(rdi_elsize, rcx_lh); // log2 elsize |
duke@435 | 1752 | __ movl(count, LENGTH); // elements count |
duke@435 | 1753 | |
duke@435 | 1754 | BLOCK_COMMENT("choose copy loop based on element size"); |
duke@435 | 1755 | __ cmpl(rdi_elsize, 0); |
duke@435 | 1756 | |
duke@435 | 1757 | __ jump_cc(Assembler::equal, RuntimeAddress(entry_jbyte_arraycopy)); |
duke@435 | 1758 | __ cmpl(rdi_elsize, LogBytesPerShort); |
duke@435 | 1759 | __ jump_cc(Assembler::equal, RuntimeAddress(entry_jshort_arraycopy)); |
duke@435 | 1760 | __ cmpl(rdi_elsize, LogBytesPerInt); |
duke@435 | 1761 | __ jump_cc(Assembler::equal, RuntimeAddress(entry_jint_arraycopy)); |
duke@435 | 1762 | #ifdef ASSERT |
duke@435 | 1763 | __ cmpl(rdi_elsize, LogBytesPerLong); |
duke@435 | 1764 | __ jccb(Assembler::notEqual, L_failed); |
duke@435 | 1765 | #endif |
duke@435 | 1766 | __ popl(rdi); // Do pops here since jlong_arraycopy stub does not do it. |
duke@435 | 1767 | __ popl(rsi); |
duke@435 | 1768 | __ jump(RuntimeAddress(entry_jlong_arraycopy)); |
duke@435 | 1769 | |
duke@435 | 1770 | __ BIND(L_failed); |
duke@435 | 1771 | __ xorl(rax, rax); |
duke@435 | 1772 | __ notl(rax); // return -1 |
duke@435 | 1773 | __ popl(rdi); |
duke@435 | 1774 | __ popl(rsi); |
duke@435 | 1775 | __ leave(); // required for proper stackwalking of RuntimeStub frame |
duke@435 | 1776 | __ ret(0); |
duke@435 | 1777 | |
duke@435 | 1778 | // objArrayKlass |
duke@435 | 1779 | __ BIND(L_objArray); |
duke@435 | 1780 | // live at this point: rcx_src_klass, src[_pos], dst[_pos] |
duke@435 | 1781 | |
duke@435 | 1782 | Label L_plain_copy, L_checkcast_copy; |
duke@435 | 1783 | // test array classes for subtyping |
duke@435 | 1784 | __ cmpl(rcx_src_klass, dst_klass_addr); // usual case is exact equality |
duke@435 | 1785 | __ jccb(Assembler::notEqual, L_checkcast_copy); |
duke@435 | 1786 | |
duke@435 | 1787 | // Identically typed arrays can be copied without element-wise checks. |
duke@435 | 1788 | assert_different_registers(src, src_pos, dst, dst_pos, rcx_src_klass); |
duke@435 | 1789 | arraycopy_range_checks(src, src_pos, dst, dst_pos, LENGTH, L_failed); |
duke@435 | 1790 | |
duke@435 | 1791 | __ BIND(L_plain_copy); |
duke@435 | 1792 | __ movl(count, LENGTH); // elements count |
duke@435 | 1793 | __ movl(src_pos, SRC_POS); // reload src_pos |
duke@435 | 1794 | __ leal(from, Address(src, src_pos, Address::times_4, |
duke@435 | 1795 | arrayOopDesc::base_offset_in_bytes(T_OBJECT))); // src_addr |
duke@435 | 1796 | __ movl(dst_pos, DST_POS); // reload dst_pos |
duke@435 | 1797 | __ leal(to, Address(dst, dst_pos, Address::times_4, |
duke@435 | 1798 | arrayOopDesc::base_offset_in_bytes(T_OBJECT))); // dst_addr |
duke@435 | 1799 | __ movl(FROM, from); // src_addr |
duke@435 | 1800 | __ movl(TO, to); // dst_addr |
duke@435 | 1801 | __ movl(COUNT, count); // count |
duke@435 | 1802 | __ jump(RuntimeAddress(entry_oop_arraycopy)); |
duke@435 | 1803 | |
duke@435 | 1804 | __ BIND(L_checkcast_copy); |
duke@435 | 1805 | // live at this point: rcx_src_klass, dst[_pos], src[_pos] |
duke@435 | 1806 | { |
duke@435 | 1807 | // Handy offsets: |
duke@435 | 1808 | int ek_offset = (klassOopDesc::header_size() * HeapWordSize + |
duke@435 | 1809 | objArrayKlass::element_klass_offset_in_bytes()); |
duke@435 | 1810 | int sco_offset = (klassOopDesc::header_size() * HeapWordSize + |
duke@435 | 1811 | Klass::super_check_offset_offset_in_bytes()); |
duke@435 | 1812 | |
duke@435 | 1813 | Register rsi_dst_klass = rsi; |
duke@435 | 1814 | Register rdi_temp = rdi; |
duke@435 | 1815 | assert(rsi_dst_klass == src_pos, "expected alias w/ src_pos"); |
duke@435 | 1816 | assert(rdi_temp == dst_pos, "expected alias w/ dst_pos"); |
duke@435 | 1817 | Address dst_klass_lh_addr(rsi_dst_klass, lh_offset); |
duke@435 | 1818 | |
duke@435 | 1819 | // Before looking at dst.length, make sure dst is also an objArray. |
duke@435 | 1820 | __ movl(rsi_dst_klass, dst_klass_addr); |
duke@435 | 1821 | __ cmpl(dst_klass_lh_addr, objArray_lh); |
duke@435 | 1822 | __ jccb(Assembler::notEqual, L_failed); |
duke@435 | 1823 | |
duke@435 | 1824 | // It is safe to examine both src.length and dst.length. |
duke@435 | 1825 | __ movl(src_pos, SRC_POS); // reload rsi |
duke@435 | 1826 | arraycopy_range_checks(src, src_pos, dst, dst_pos, LENGTH, L_failed); |
duke@435 | 1827 | // (Now src_pos and dst_pos are killed, but not src and dst.) |
duke@435 | 1828 | |
duke@435 | 1829 | // We'll need this temp (don't forget to pop it after the type check). |
duke@435 | 1830 | __ pushl(rbx); |
duke@435 | 1831 | Register rbx_src_klass = rbx; |
duke@435 | 1832 | |
duke@435 | 1833 | __ movl(rbx_src_klass, rcx_src_klass); // spill away from rcx |
duke@435 | 1834 | __ movl(rsi_dst_klass, dst_klass_addr); |
duke@435 | 1835 | Address super_check_offset_addr(rsi_dst_klass, sco_offset); |
duke@435 | 1836 | Label L_fail_array_check; |
duke@435 | 1837 | generate_type_check(rbx_src_klass, |
duke@435 | 1838 | super_check_offset_addr, dst_klass_addr, |
duke@435 | 1839 | rdi_temp, NULL, &L_fail_array_check); |
duke@435 | 1840 | // (On fall-through, we have passed the array type check.) |
duke@435 | 1841 | __ popl(rbx); |
duke@435 | 1842 | __ jmp(L_plain_copy); |
duke@435 | 1843 | |
duke@435 | 1844 | __ BIND(L_fail_array_check); |
duke@435 | 1845 | // Reshuffle arguments so we can call checkcast_arraycopy: |
duke@435 | 1846 | |
duke@435 | 1847 | // match initial saves for checkcast_arraycopy |
duke@435 | 1848 | // pushl(rsi); // already done; see above |
duke@435 | 1849 | // pushl(rdi); // already done; see above |
duke@435 | 1850 | // pushl(rbx); // already done; see above |
duke@435 | 1851 | |
duke@435 | 1852 | // Marshal outgoing arguments now, freeing registers. |
duke@435 | 1853 | Address from_arg(rsp, 16+ 4); // from |
duke@435 | 1854 | Address to_arg(rsp, 16+ 8); // to |
duke@435 | 1855 | Address length_arg(rsp, 16+12); // elements count |
duke@435 | 1856 | Address ckoff_arg(rsp, 16+16); // super_check_offset |
duke@435 | 1857 | Address ckval_arg(rsp, 16+20); // super_klass |
duke@435 | 1858 | |
duke@435 | 1859 | Address SRC_POS_arg(rsp, 16+ 8); |
duke@435 | 1860 | Address DST_POS_arg(rsp, 16+16); |
duke@435 | 1861 | Address LENGTH_arg(rsp, 16+20); |
duke@435 | 1862 | // push rbx, changed the incoming offsets (why not just use rbp,??) |
duke@435 | 1863 | // assert(SRC_POS_arg.disp() == SRC_POS.disp() + 4, ""); |
duke@435 | 1864 | |
duke@435 | 1865 | __ movl(rbx, Address(rsi_dst_klass, ek_offset)); |
duke@435 | 1866 | __ movl(length, LENGTH_arg); // reload elements count |
duke@435 | 1867 | __ movl(src_pos, SRC_POS_arg); // reload src_pos |
duke@435 | 1868 | __ movl(dst_pos, DST_POS_arg); // reload dst_pos |
duke@435 | 1869 | |
duke@435 | 1870 | __ movl(ckval_arg, rbx); // destination element type |
duke@435 | 1871 | __ movl(rbx, Address(rbx, sco_offset)); |
duke@435 | 1872 | __ movl(ckoff_arg, rbx); // corresponding class check offset |
duke@435 | 1873 | |
duke@435 | 1874 | __ movl(length_arg, length); // outgoing length argument |
duke@435 | 1875 | |
duke@435 | 1876 | __ leal(from, Address(src, src_pos, Address::times_4, |
duke@435 | 1877 | arrayOopDesc::base_offset_in_bytes(T_OBJECT))); |
duke@435 | 1878 | __ movl(from_arg, from); |
duke@435 | 1879 | |
duke@435 | 1880 | __ leal(to, Address(dst, dst_pos, Address::times_4, |
duke@435 | 1881 | arrayOopDesc::base_offset_in_bytes(T_OBJECT))); |
duke@435 | 1882 | __ movl(to_arg, to); |
duke@435 | 1883 | __ jump(RuntimeAddress(entry_checkcast_arraycopy)); |
duke@435 | 1884 | } |
duke@435 | 1885 | |
duke@435 | 1886 | return start; |
duke@435 | 1887 | } |
duke@435 | 1888 | |
duke@435 | 1889 | void generate_arraycopy_stubs() { |
duke@435 | 1890 | address entry; |
duke@435 | 1891 | address entry_jbyte_arraycopy; |
duke@435 | 1892 | address entry_jshort_arraycopy; |
duke@435 | 1893 | address entry_jint_arraycopy; |
duke@435 | 1894 | address entry_oop_arraycopy; |
duke@435 | 1895 | address entry_jlong_arraycopy; |
duke@435 | 1896 | address entry_checkcast_arraycopy; |
duke@435 | 1897 | |
duke@435 | 1898 | StubRoutines::_arrayof_jbyte_disjoint_arraycopy = |
duke@435 | 1899 | generate_disjoint_copy(T_BYTE, true, Address::times_1, &entry, |
duke@435 | 1900 | "arrayof_jbyte_disjoint_arraycopy"); |
duke@435 | 1901 | StubRoutines::_arrayof_jbyte_arraycopy = |
duke@435 | 1902 | generate_conjoint_copy(T_BYTE, true, Address::times_1, entry, |
duke@435 | 1903 | NULL, "arrayof_jbyte_arraycopy"); |
duke@435 | 1904 | StubRoutines::_jbyte_disjoint_arraycopy = |
duke@435 | 1905 | generate_disjoint_copy(T_BYTE, false, Address::times_1, &entry, |
duke@435 | 1906 | "jbyte_disjoint_arraycopy"); |
duke@435 | 1907 | StubRoutines::_jbyte_arraycopy = |
duke@435 | 1908 | generate_conjoint_copy(T_BYTE, false, Address::times_1, entry, |
duke@435 | 1909 | &entry_jbyte_arraycopy, "jbyte_arraycopy"); |
duke@435 | 1910 | |
duke@435 | 1911 | StubRoutines::_arrayof_jshort_disjoint_arraycopy = |
duke@435 | 1912 | generate_disjoint_copy(T_SHORT, true, Address::times_2, &entry, |
duke@435 | 1913 | "arrayof_jshort_disjoint_arraycopy"); |
duke@435 | 1914 | StubRoutines::_arrayof_jshort_arraycopy = |
duke@435 | 1915 | generate_conjoint_copy(T_SHORT, true, Address::times_2, entry, |
duke@435 | 1916 | NULL, "arrayof_jshort_arraycopy"); |
duke@435 | 1917 | StubRoutines::_jshort_disjoint_arraycopy = |
duke@435 | 1918 | generate_disjoint_copy(T_SHORT, false, Address::times_2, &entry, |
duke@435 | 1919 | "jshort_disjoint_arraycopy"); |
duke@435 | 1920 | StubRoutines::_jshort_arraycopy = |
duke@435 | 1921 | generate_conjoint_copy(T_SHORT, false, Address::times_2, entry, |
duke@435 | 1922 | &entry_jshort_arraycopy, "jshort_arraycopy"); |
duke@435 | 1923 | |
duke@435 | 1924 | // Next arrays are always aligned on 4 bytes at least. |
duke@435 | 1925 | StubRoutines::_jint_disjoint_arraycopy = |
duke@435 | 1926 | generate_disjoint_copy(T_INT, true, Address::times_4, &entry, |
duke@435 | 1927 | "jint_disjoint_arraycopy"); |
duke@435 | 1928 | StubRoutines::_jint_arraycopy = |
duke@435 | 1929 | generate_conjoint_copy(T_INT, true, Address::times_4, entry, |
duke@435 | 1930 | &entry_jint_arraycopy, "jint_arraycopy"); |
duke@435 | 1931 | |
duke@435 | 1932 | StubRoutines::_oop_disjoint_arraycopy = |
duke@435 | 1933 | generate_disjoint_copy(T_OBJECT, true, Address::times_4, &entry, |
duke@435 | 1934 | "oop_disjoint_arraycopy"); |
duke@435 | 1935 | StubRoutines::_oop_arraycopy = |
duke@435 | 1936 | generate_conjoint_copy(T_OBJECT, true, Address::times_4, entry, |
duke@435 | 1937 | &entry_oop_arraycopy, "oop_arraycopy"); |
duke@435 | 1938 | |
duke@435 | 1939 | StubRoutines::_jlong_disjoint_arraycopy = |
duke@435 | 1940 | generate_disjoint_long_copy(&entry, "jlong_disjoint_arraycopy"); |
duke@435 | 1941 | StubRoutines::_jlong_arraycopy = |
duke@435 | 1942 | generate_conjoint_long_copy(entry, &entry_jlong_arraycopy, |
duke@435 | 1943 | "jlong_arraycopy"); |
duke@435 | 1944 | |
duke@435 | 1945 | StubRoutines::_arrayof_jint_disjoint_arraycopy = |
duke@435 | 1946 | StubRoutines::_jint_disjoint_arraycopy; |
duke@435 | 1947 | StubRoutines::_arrayof_oop_disjoint_arraycopy = |
duke@435 | 1948 | StubRoutines::_oop_disjoint_arraycopy; |
duke@435 | 1949 | StubRoutines::_arrayof_jlong_disjoint_arraycopy = |
duke@435 | 1950 | StubRoutines::_jlong_disjoint_arraycopy; |
duke@435 | 1951 | |
duke@435 | 1952 | StubRoutines::_arrayof_jint_arraycopy = StubRoutines::_jint_arraycopy; |
duke@435 | 1953 | StubRoutines::_arrayof_oop_arraycopy = StubRoutines::_oop_arraycopy; |
duke@435 | 1954 | StubRoutines::_arrayof_jlong_arraycopy = StubRoutines::_jlong_arraycopy; |
duke@435 | 1955 | |
duke@435 | 1956 | StubRoutines::_checkcast_arraycopy = |
duke@435 | 1957 | generate_checkcast_copy("checkcast_arraycopy", |
duke@435 | 1958 | &entry_checkcast_arraycopy); |
duke@435 | 1959 | |
duke@435 | 1960 | StubRoutines::_unsafe_arraycopy = |
duke@435 | 1961 | generate_unsafe_copy("unsafe_arraycopy", |
duke@435 | 1962 | entry_jbyte_arraycopy, |
duke@435 | 1963 | entry_jshort_arraycopy, |
duke@435 | 1964 | entry_jint_arraycopy, |
duke@435 | 1965 | entry_jlong_arraycopy); |
duke@435 | 1966 | |
duke@435 | 1967 | StubRoutines::_generic_arraycopy = |
duke@435 | 1968 | generate_generic_copy("generic_arraycopy", |
duke@435 | 1969 | entry_jbyte_arraycopy, |
duke@435 | 1970 | entry_jshort_arraycopy, |
duke@435 | 1971 | entry_jint_arraycopy, |
duke@435 | 1972 | entry_oop_arraycopy, |
duke@435 | 1973 | entry_jlong_arraycopy, |
duke@435 | 1974 | entry_checkcast_arraycopy); |
duke@435 | 1975 | } |
duke@435 | 1976 | |
duke@435 | 1977 | public: |
duke@435 | 1978 | // Information about frame layout at time of blocking runtime call. |
duke@435 | 1979 | // Note that we only have to preserve callee-saved registers since |
duke@435 | 1980 | // the compilers are responsible for supplying a continuation point |
duke@435 | 1981 | // if they expect all registers to be preserved. |
duke@435 | 1982 | enum layout { |
duke@435 | 1983 | thread_off, // last_java_sp |
duke@435 | 1984 | rbp_off, // callee saved register |
duke@435 | 1985 | ret_pc, |
duke@435 | 1986 | framesize |
duke@435 | 1987 | }; |
duke@435 | 1988 | |
duke@435 | 1989 | private: |
duke@435 | 1990 | |
duke@435 | 1991 | #undef __ |
duke@435 | 1992 | #define __ masm-> |
duke@435 | 1993 | |
duke@435 | 1994 | //------------------------------------------------------------------------------------------------------------------------ |
duke@435 | 1995 | // Continuation point for throwing of implicit exceptions that are not handled in |
duke@435 | 1996 | // the current activation. Fabricates an exception oop and initiates normal |
duke@435 | 1997 | // exception dispatching in this frame. |
duke@435 | 1998 | // |
duke@435 | 1999 | // Previously the compiler (c2) allowed for callee save registers on Java calls. |
duke@435 | 2000 | // This is no longer true after adapter frames were removed but could possibly |
duke@435 | 2001 | // be brought back in the future if the interpreter code was reworked and it |
duke@435 | 2002 | // was deemed worthwhile. The comment below was left to describe what must |
duke@435 | 2003 | // happen here if callee saves were resurrected. As it stands now this stub |
duke@435 | 2004 | // could actually be a vanilla BufferBlob and have now oopMap at all. |
duke@435 | 2005 | // Since it doesn't make much difference we've chosen to leave it the |
duke@435 | 2006 | // way it was in the callee save days and keep the comment. |
duke@435 | 2007 | |
duke@435 | 2008 | // If we need to preserve callee-saved values we need a callee-saved oop map and |
duke@435 | 2009 | // therefore have to make these stubs into RuntimeStubs rather than BufferBlobs. |
duke@435 | 2010 | // If the compiler needs all registers to be preserved between the fault |
duke@435 | 2011 | // point and the exception handler then it must assume responsibility for that in |
duke@435 | 2012 | // AbstractCompiler::continuation_for_implicit_null_exception or |
duke@435 | 2013 | // continuation_for_implicit_division_by_zero_exception. All other implicit |
duke@435 | 2014 | // exceptions (e.g., NullPointerException or AbstractMethodError on entry) are |
duke@435 | 2015 | // either at call sites or otherwise assume that stack unwinding will be initiated, |
duke@435 | 2016 | // so caller saved registers were assumed volatile in the compiler. |
duke@435 | 2017 | address generate_throw_exception(const char* name, address runtime_entry, |
duke@435 | 2018 | bool restore_saved_exception_pc) { |
duke@435 | 2019 | |
duke@435 | 2020 | int insts_size = 256; |
duke@435 | 2021 | int locs_size = 32; |
duke@435 | 2022 | |
duke@435 | 2023 | CodeBuffer code(name, insts_size, locs_size); |
duke@435 | 2024 | OopMapSet* oop_maps = new OopMapSet(); |
duke@435 | 2025 | MacroAssembler* masm = new MacroAssembler(&code); |
duke@435 | 2026 | |
duke@435 | 2027 | address start = __ pc(); |
duke@435 | 2028 | |
duke@435 | 2029 | // This is an inlined and slightly modified version of call_VM |
duke@435 | 2030 | // which has the ability to fetch the return PC out of |
duke@435 | 2031 | // thread-local storage and also sets up last_Java_sp slightly |
duke@435 | 2032 | // differently than the real call_VM |
duke@435 | 2033 | Register java_thread = rbx; |
duke@435 | 2034 | __ get_thread(java_thread); |
duke@435 | 2035 | if (restore_saved_exception_pc) { |
duke@435 | 2036 | __ movl(rax, Address(java_thread, in_bytes(JavaThread::saved_exception_pc_offset()))); |
duke@435 | 2037 | __ pushl(rax); |
duke@435 | 2038 | } |
duke@435 | 2039 | |
duke@435 | 2040 | __ enter(); // required for proper stackwalking of RuntimeStub frame |
duke@435 | 2041 | |
duke@435 | 2042 | // pc and rbp, already pushed |
duke@435 | 2043 | __ subl(rsp, (framesize-2) * wordSize); // prolog |
duke@435 | 2044 | |
duke@435 | 2045 | // Frame is now completed as far as size and linkage. |
duke@435 | 2046 | |
duke@435 | 2047 | int frame_complete = __ pc() - start; |
duke@435 | 2048 | |
duke@435 | 2049 | // push java thread (becomes first argument of C function) |
duke@435 | 2050 | __ movl(Address(rsp, thread_off * wordSize), java_thread); |
duke@435 | 2051 | |
duke@435 | 2052 | // Set up last_Java_sp and last_Java_fp |
duke@435 | 2053 | __ set_last_Java_frame(java_thread, rsp, rbp, NULL); |
duke@435 | 2054 | |
duke@435 | 2055 | // Call runtime |
duke@435 | 2056 | BLOCK_COMMENT("call runtime_entry"); |
duke@435 | 2057 | __ call(RuntimeAddress(runtime_entry)); |
duke@435 | 2058 | // Generate oop map |
duke@435 | 2059 | OopMap* map = new OopMap(framesize, 0); |
duke@435 | 2060 | oop_maps->add_gc_map(__ pc() - start, map); |
duke@435 | 2061 | |
duke@435 | 2062 | // restore the thread (cannot use the pushed argument since arguments |
duke@435 | 2063 | // may be overwritten by C code generated by an optimizing compiler); |
duke@435 | 2064 | // however can use the register value directly if it is callee saved. |
duke@435 | 2065 | __ get_thread(java_thread); |
duke@435 | 2066 | |
duke@435 | 2067 | __ reset_last_Java_frame(java_thread, true, false); |
duke@435 | 2068 | |
duke@435 | 2069 | __ leave(); // required for proper stackwalking of RuntimeStub frame |
duke@435 | 2070 | |
duke@435 | 2071 | // check for pending exceptions |
duke@435 | 2072 | #ifdef ASSERT |
duke@435 | 2073 | Label L; |
duke@435 | 2074 | __ cmpl(Address(java_thread, Thread::pending_exception_offset()), NULL_WORD); |
duke@435 | 2075 | __ jcc(Assembler::notEqual, L); |
duke@435 | 2076 | __ should_not_reach_here(); |
duke@435 | 2077 | __ bind(L); |
duke@435 | 2078 | #endif /* ASSERT */ |
duke@435 | 2079 | __ jump(RuntimeAddress(StubRoutines::forward_exception_entry())); |
duke@435 | 2080 | |
duke@435 | 2081 | |
duke@435 | 2082 | RuntimeStub* stub = RuntimeStub::new_runtime_stub(name, &code, frame_complete, framesize, oop_maps, false); |
duke@435 | 2083 | return stub->entry_point(); |
duke@435 | 2084 | } |
duke@435 | 2085 | |
duke@435 | 2086 | |
duke@435 | 2087 | void create_control_words() { |
duke@435 | 2088 | // Round to nearest, 53-bit mode, exceptions masked |
duke@435 | 2089 | StubRoutines::_fpu_cntrl_wrd_std = 0x027F; |
duke@435 | 2090 | // Round to zero, 53-bit mode, exception mased |
duke@435 | 2091 | StubRoutines::_fpu_cntrl_wrd_trunc = 0x0D7F; |
duke@435 | 2092 | // Round to nearest, 24-bit mode, exceptions masked |
duke@435 | 2093 | StubRoutines::_fpu_cntrl_wrd_24 = 0x007F; |
duke@435 | 2094 | // Round to nearest, 64-bit mode, exceptions masked |
duke@435 | 2095 | StubRoutines::_fpu_cntrl_wrd_64 = 0x037F; |
duke@435 | 2096 | // Round to nearest, 64-bit mode, exceptions masked |
duke@435 | 2097 | StubRoutines::_mxcsr_std = 0x1F80; |
duke@435 | 2098 | // Note: the following two constants are 80-bit values |
duke@435 | 2099 | // layout is critical for correct loading by FPU. |
duke@435 | 2100 | // Bias for strict fp multiply/divide |
duke@435 | 2101 | StubRoutines::_fpu_subnormal_bias1[0]= 0x00000000; // 2^(-15360) == 0x03ff 8000 0000 0000 0000 |
duke@435 | 2102 | StubRoutines::_fpu_subnormal_bias1[1]= 0x80000000; |
duke@435 | 2103 | StubRoutines::_fpu_subnormal_bias1[2]= 0x03ff; |
duke@435 | 2104 | // Un-Bias for strict fp multiply/divide |
duke@435 | 2105 | StubRoutines::_fpu_subnormal_bias2[0]= 0x00000000; // 2^(+15360) == 0x7bff 8000 0000 0000 0000 |
duke@435 | 2106 | StubRoutines::_fpu_subnormal_bias2[1]= 0x80000000; |
duke@435 | 2107 | StubRoutines::_fpu_subnormal_bias2[2]= 0x7bff; |
duke@435 | 2108 | } |
duke@435 | 2109 | |
duke@435 | 2110 | //--------------------------------------------------------------------------- |
duke@435 | 2111 | // Initialization |
duke@435 | 2112 | |
duke@435 | 2113 | void generate_initial() { |
duke@435 | 2114 | // Generates all stubs and initializes the entry points |
duke@435 | 2115 | |
duke@435 | 2116 | //------------------------------------------------------------------------------------------------------------------------ |
duke@435 | 2117 | // entry points that exist in all platforms |
duke@435 | 2118 | // Note: This is code that could be shared among different platforms - however the benefit seems to be smaller than |
duke@435 | 2119 | // the disadvantage of having a much more complicated generator structure. See also comment in stubRoutines.hpp. |
duke@435 | 2120 | StubRoutines::_forward_exception_entry = generate_forward_exception(); |
duke@435 | 2121 | |
duke@435 | 2122 | StubRoutines::_call_stub_entry = |
duke@435 | 2123 | generate_call_stub(StubRoutines::_call_stub_return_address); |
duke@435 | 2124 | // is referenced by megamorphic call |
duke@435 | 2125 | StubRoutines::_catch_exception_entry = generate_catch_exception(); |
duke@435 | 2126 | |
duke@435 | 2127 | // These are currently used by Solaris/Intel |
duke@435 | 2128 | StubRoutines::_atomic_xchg_entry = generate_atomic_xchg(); |
duke@435 | 2129 | |
duke@435 | 2130 | StubRoutines::_handler_for_unsafe_access_entry = |
duke@435 | 2131 | generate_handler_for_unsafe_access(); |
duke@435 | 2132 | |
duke@435 | 2133 | // platform dependent |
duke@435 | 2134 | create_control_words(); |
duke@435 | 2135 | |
duke@435 | 2136 | StubRoutines::i486::_verify_mxcsr_entry = generate_verify_mxcsr(); |
duke@435 | 2137 | StubRoutines::i486::_verify_fpu_cntrl_wrd_entry = generate_verify_fpu_cntrl_wrd(); |
duke@435 | 2138 | StubRoutines::_d2i_wrapper = generate_d2i_wrapper(T_INT, |
duke@435 | 2139 | CAST_FROM_FN_PTR(address, SharedRuntime::d2i)); |
duke@435 | 2140 | StubRoutines::_d2l_wrapper = generate_d2i_wrapper(T_LONG, |
duke@435 | 2141 | CAST_FROM_FN_PTR(address, SharedRuntime::d2l)); |
duke@435 | 2142 | } |
duke@435 | 2143 | |
duke@435 | 2144 | |
duke@435 | 2145 | void generate_all() { |
duke@435 | 2146 | // Generates all stubs and initializes the entry points |
duke@435 | 2147 | |
duke@435 | 2148 | // These entry points require SharedInfo::stack0 to be set up in non-core builds |
duke@435 | 2149 | // and need to be relocatable, so they each fabricate a RuntimeStub internally. |
duke@435 | 2150 | StubRoutines::_throw_AbstractMethodError_entry = generate_throw_exception("AbstractMethodError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_AbstractMethodError), false); |
dcubed@451 | 2151 | StubRoutines::_throw_IncompatibleClassChangeError_entry= generate_throw_exception("IncompatibleClassChangeError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_IncompatibleClassChangeError), false); |
duke@435 | 2152 | StubRoutines::_throw_ArithmeticException_entry = generate_throw_exception("ArithmeticException throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_ArithmeticException), true); |
duke@435 | 2153 | StubRoutines::_throw_NullPointerException_entry = generate_throw_exception("NullPointerException throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_NullPointerException), true); |
duke@435 | 2154 | StubRoutines::_throw_NullPointerException_at_call_entry= generate_throw_exception("NullPointerException at call throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_NullPointerException_at_call), false); |
duke@435 | 2155 | StubRoutines::_throw_StackOverflowError_entry = generate_throw_exception("StackOverflowError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_StackOverflowError), false); |
duke@435 | 2156 | |
duke@435 | 2157 | //------------------------------------------------------------------------------------------------------------------------ |
duke@435 | 2158 | // entry points that are platform specific |
duke@435 | 2159 | |
duke@435 | 2160 | // support for verify_oop (must happen after universe_init) |
duke@435 | 2161 | StubRoutines::_verify_oop_subroutine_entry = generate_verify_oop(); |
duke@435 | 2162 | |
duke@435 | 2163 | // arraycopy stubs used by compilers |
duke@435 | 2164 | generate_arraycopy_stubs(); |
duke@435 | 2165 | } |
duke@435 | 2166 | |
duke@435 | 2167 | |
duke@435 | 2168 | public: |
duke@435 | 2169 | StubGenerator(CodeBuffer* code, bool all) : StubCodeGenerator(code) { |
duke@435 | 2170 | if (all) { |
duke@435 | 2171 | generate_all(); |
duke@435 | 2172 | } else { |
duke@435 | 2173 | generate_initial(); |
duke@435 | 2174 | } |
duke@435 | 2175 | } |
duke@435 | 2176 | }; // end class declaration |
duke@435 | 2177 | |
duke@435 | 2178 | |
duke@435 | 2179 | void StubGenerator_generate(CodeBuffer* code, bool all) { |
duke@435 | 2180 | StubGenerator g(code, all); |
duke@435 | 2181 | } |