1 /* 2 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "asm/assembler.hpp" 27 #include "assembler_x86.inline.hpp" 28 #include "interpreter/interpreter.hpp" 29 #include "nativeInst_x86.hpp" 30 #include "oops/instanceOop.hpp" 31 #include "oops/methodOop.hpp" 32 #include "oops/objArrayKlass.hpp" 33 #include "oops/oop.inline.hpp" 34 #include "prims/methodHandles.hpp" 35 #include "runtime/frame.inline.hpp" 36 #include "runtime/handles.inline.hpp" 37 #include "runtime/sharedRuntime.hpp" 38 #include "runtime/stubCodeGenerator.hpp" 39 #include "runtime/stubRoutines.hpp" 40 #include "utilities/top.hpp" 41 #ifdef TARGET_OS_FAMILY_linux 42 # include "thread_linux.inline.hpp" 43 #endif 44 #ifdef TARGET_OS_FAMILY_solaris 45 # include "thread_solaris.inline.hpp" 46 #endif 47 #ifdef TARGET_OS_FAMILY_windows 48 # include "thread_windows.inline.hpp" 49 #endif 50 #ifdef COMPILER2 51 #include "opto/runtime.hpp" 52 #endif 53 54 // Declaration and definition of StubGenerator (no .hpp file). 55 // For a more detailed description of the stub routine structure 56 // see the comment in stubRoutines.hpp 57 58 #define __ _masm-> 59 #define TIMES_OOP (UseCompressedOops ? Address::times_4 : Address::times_8) 60 #define a__ ((Assembler*)_masm)-> 61 62 #ifdef PRODUCT 63 #define BLOCK_COMMENT(str) /* nothing */ 64 #else 65 #define BLOCK_COMMENT(str) __ block_comment(str) 66 #endif 67 68 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":") 69 const int MXCSR_MASK = 0xFFC0; // Mask out any pending exceptions 70 71 // Stub Code definitions 72 73 static address handle_unsafe_access() { 74 JavaThread* thread = JavaThread::current(); 75 address pc = thread->saved_exception_pc(); 76 // pc is the instruction which we must emulate 77 // doing a no-op is fine: return garbage from the load 78 // therefore, compute npc 79 address npc = Assembler::locate_next_instruction(pc); 80 81 // request an async exception 82 thread->set_pending_unsafe_access_error(); 83 84 // return address of next instruction to execute 85 return npc; 86 } 87 88 class StubGenerator: public StubCodeGenerator { 89 private: 90 91 #ifdef PRODUCT 92 #define inc_counter_np(counter) (0) 93 #else 94 void inc_counter_np_(int& counter) { 95 __ incrementl(ExternalAddress((address)&counter)); 96 } 97 #define inc_counter_np(counter) \ 98 BLOCK_COMMENT("inc_counter " #counter); \ 99 inc_counter_np_(counter); 100 #endif 101 102 // Call stubs are used to call Java from C 103 // 104 // Linux Arguments: 105 // c_rarg0: call wrapper address address 106 // c_rarg1: result address 107 // c_rarg2: result type BasicType 108 // c_rarg3: method methodOop 109 // c_rarg4: (interpreter) entry point address 110 // c_rarg5: parameters intptr_t* 111 // 16(rbp): parameter size (in words) int 112 // 24(rbp): thread Thread* 113 // 114 // [ return_from_Java ] <--- rsp 115 // [ argument word n ] 116 // ... 117 // -12 [ argument word 1 ] 118 // -11 [ saved r15 ] <--- rsp_after_call 119 // -10 [ saved r14 ] 120 // -9 [ saved r13 ] 121 // -8 [ saved r12 ] 122 // -7 [ saved rbx ] 123 // -6 [ call wrapper ] 124 // -5 [ result ] 125 // -4 [ result type ] 126 // -3 [ method ] 127 // -2 [ entry point ] 128 // -1 [ parameters ] 129 // 0 [ saved rbp ] <--- rbp 130 // 1 [ return address ] 131 // 2 [ parameter size ] 132 // 3 [ thread ] 133 // 134 // Windows Arguments: 135 // c_rarg0: call wrapper address address 136 // c_rarg1: result address 137 // c_rarg2: result type BasicType 138 // c_rarg3: method methodOop 139 // 48(rbp): (interpreter) entry point address 140 // 56(rbp): parameters intptr_t* 141 // 64(rbp): parameter size (in words) int 142 // 72(rbp): thread Thread* 143 // 144 // [ return_from_Java ] <--- rsp 145 // [ argument word n ] 146 // ... 147 // -8 [ argument word 1 ] 148 // -7 [ saved r15 ] <--- rsp_after_call 149 // -6 [ saved r14 ] 150 // -5 [ saved r13 ] 151 // -4 [ saved r12 ] 152 // -3 [ saved rdi ] 153 // -2 [ saved rsi ] 154 // -1 [ saved rbx ] 155 // 0 [ saved rbp ] <--- rbp 156 // 1 [ return address ] 157 // 2 [ call wrapper ] 158 // 3 [ result ] 159 // 4 [ result type ] 160 // 5 [ method ] 161 // 6 [ entry point ] 162 // 7 [ parameters ] 163 // 8 [ parameter size ] 164 // 9 [ thread ] 165 // 166 // Windows reserves the callers stack space for arguments 1-4. 167 // We spill c_rarg0-c_rarg3 to this space. 168 169 // Call stub stack layout word offsets from rbp 170 enum call_stub_layout { 171 #ifdef _WIN64 172 rsp_after_call_off = -7, 173 r15_off = rsp_after_call_off, 174 r14_off = -6, 175 r13_off = -5, 176 r12_off = -4, 177 rdi_off = -3, 178 rsi_off = -2, 179 rbx_off = -1, 180 rbp_off = 0, 181 retaddr_off = 1, 182 call_wrapper_off = 2, 183 result_off = 3, 184 result_type_off = 4, 185 method_off = 5, 186 entry_point_off = 6, 187 parameters_off = 7, 188 parameter_size_off = 8, 189 thread_off = 9 190 #else 191 rsp_after_call_off = -12, 192 mxcsr_off = rsp_after_call_off, 193 r15_off = -11, 194 r14_off = -10, 195 r13_off = -9, 196 r12_off = -8, 197 rbx_off = -7, 198 call_wrapper_off = -6, 199 result_off = -5, 200 result_type_off = -4, 201 method_off = -3, 202 entry_point_off = -2, 203 parameters_off = -1, 204 rbp_off = 0, 205 retaddr_off = 1, 206 parameter_size_off = 2, 207 thread_off = 3 208 #endif 209 }; 210 211 address generate_call_stub(address& return_address) { 212 assert((int)frame::entry_frame_after_call_words == -(int)rsp_after_call_off + 1 && 213 (int)frame::entry_frame_call_wrapper_offset == (int)call_wrapper_off, 214 "adjust this code"); 215 StubCodeMark mark(this, "StubRoutines", "call_stub"); 216 address start = __ pc(); 217 218 // same as in generate_catch_exception()! 219 const Address rsp_after_call(rbp, rsp_after_call_off * wordSize); 220 221 const Address call_wrapper (rbp, call_wrapper_off * wordSize); 222 const Address result (rbp, result_off * wordSize); 223 const Address result_type (rbp, result_type_off * wordSize); 224 const Address method (rbp, method_off * wordSize); 225 const Address entry_point (rbp, entry_point_off * wordSize); 226 const Address parameters (rbp, parameters_off * wordSize); 227 const Address parameter_size(rbp, parameter_size_off * wordSize); 228 229 // same as in generate_catch_exception()! 230 const Address thread (rbp, thread_off * wordSize); 231 232 const Address r15_save(rbp, r15_off * wordSize); 233 const Address r14_save(rbp, r14_off * wordSize); 234 const Address r13_save(rbp, r13_off * wordSize); 235 const Address r12_save(rbp, r12_off * wordSize); 236 const Address rbx_save(rbp, rbx_off * wordSize); 237 238 // stub code 239 __ enter(); 240 __ subptr(rsp, -rsp_after_call_off * wordSize); 241 242 // save register parameters 243 #ifndef _WIN64 244 __ movptr(parameters, c_rarg5); // parameters 245 __ movptr(entry_point, c_rarg4); // entry_point 246 #endif 247 248 __ movptr(method, c_rarg3); // method 249 __ movl(result_type, c_rarg2); // result type 250 __ movptr(result, c_rarg1); // result 251 __ movptr(call_wrapper, c_rarg0); // call wrapper 252 253 // save regs belonging to calling function 254 __ movptr(rbx_save, rbx); 255 __ movptr(r12_save, r12); 256 __ movptr(r13_save, r13); 257 __ movptr(r14_save, r14); 258 __ movptr(r15_save, r15); 259 260 #ifdef _WIN64 261 const Address rdi_save(rbp, rdi_off * wordSize); 262 const Address rsi_save(rbp, rsi_off * wordSize); 263 264 __ movptr(rsi_save, rsi); 265 __ movptr(rdi_save, rdi); 266 #else 267 const Address mxcsr_save(rbp, mxcsr_off * wordSize); 268 { 269 Label skip_ldmx; 270 __ stmxcsr(mxcsr_save); 271 __ movl(rax, mxcsr_save); 272 __ andl(rax, MXCSR_MASK); // Only check control and mask bits 273 ExternalAddress mxcsr_std(StubRoutines::x86::mxcsr_std()); 274 __ cmp32(rax, mxcsr_std); 275 __ jcc(Assembler::equal, skip_ldmx); 276 __ ldmxcsr(mxcsr_std); 277 __ bind(skip_ldmx); 278 } 279 #endif 280 281 // Load up thread register 282 __ movptr(r15_thread, thread); 283 __ reinit_heapbase(); 284 285 #ifdef ASSERT 286 // make sure we have no pending exceptions 287 { 288 Label L; 289 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD); 290 __ jcc(Assembler::equal, L); 291 __ stop("StubRoutines::call_stub: entered with pending exception"); 292 __ bind(L); 293 } 294 #endif 295 296 // pass parameters if any 297 BLOCK_COMMENT("pass parameters if any"); 298 Label parameters_done; 299 __ movl(c_rarg3, parameter_size); 300 __ testl(c_rarg3, c_rarg3); 301 __ jcc(Assembler::zero, parameters_done); 302 303 Label loop; 304 __ movptr(c_rarg2, parameters); // parameter pointer 305 __ movl(c_rarg1, c_rarg3); // parameter counter is in c_rarg1 306 __ BIND(loop); 307 __ movptr(rax, Address(c_rarg2, 0));// get parameter 308 __ addptr(c_rarg2, wordSize); // advance to next parameter 309 __ decrementl(c_rarg1); // decrement counter 310 __ push(rax); // pass parameter 311 __ jcc(Assembler::notZero, loop); 312 313 // call Java function 314 __ BIND(parameters_done); 315 __ movptr(rbx, method); // get methodOop 316 __ movptr(c_rarg1, entry_point); // get entry_point 317 __ mov(r13, rsp); // set sender sp 318 BLOCK_COMMENT("call Java function"); 319 __ call(c_rarg1); 320 321 BLOCK_COMMENT("call_stub_return_address:"); 322 return_address = __ pc(); 323 324 // store result depending on type (everything that is not 325 // T_OBJECT, T_LONG, T_FLOAT or T_DOUBLE is treated as T_INT) 326 __ movptr(c_rarg0, result); 327 Label is_long, is_float, is_double, exit; 328 __ movl(c_rarg1, result_type); 329 __ cmpl(c_rarg1, T_OBJECT); 330 __ jcc(Assembler::equal, is_long); 331 __ cmpl(c_rarg1, T_LONG); 332 __ jcc(Assembler::equal, is_long); 333 __ cmpl(c_rarg1, T_FLOAT); 334 __ jcc(Assembler::equal, is_float); 335 __ cmpl(c_rarg1, T_DOUBLE); 336 __ jcc(Assembler::equal, is_double); 337 338 // handle T_INT case 339 __ movl(Address(c_rarg0, 0), rax); 340 341 __ BIND(exit); 342 343 // pop parameters 344 __ lea(rsp, rsp_after_call); 345 346 #ifdef ASSERT 347 // verify that threads correspond 348 { 349 Label L, S; 350 __ cmpptr(r15_thread, thread); 351 __ jcc(Assembler::notEqual, S); 352 __ get_thread(rbx); 353 __ cmpptr(r15_thread, rbx); 354 __ jcc(Assembler::equal, L); 355 __ bind(S); 356 __ jcc(Assembler::equal, L); 357 __ stop("StubRoutines::call_stub: threads must correspond"); 358 __ bind(L); 359 } 360 #endif 361 362 // restore regs belonging to calling function 363 __ movptr(r15, r15_save); 364 __ movptr(r14, r14_save); 365 __ movptr(r13, r13_save); 366 __ movptr(r12, r12_save); 367 __ movptr(rbx, rbx_save); 368 369 #ifdef _WIN64 370 __ movptr(rdi, rdi_save); 371 __ movptr(rsi, rsi_save); 372 #else 373 __ ldmxcsr(mxcsr_save); 374 #endif 375 376 // restore rsp 377 __ addptr(rsp, -rsp_after_call_off * wordSize); 378 379 // return 380 __ pop(rbp); 381 __ ret(0); 382 383 // handle return types different from T_INT 384 __ BIND(is_long); 385 __ movq(Address(c_rarg0, 0), rax); 386 __ jmp(exit); 387 388 __ BIND(is_float); 389 __ movflt(Address(c_rarg0, 0), xmm0); 390 __ jmp(exit); 391 392 __ BIND(is_double); 393 __ movdbl(Address(c_rarg0, 0), xmm0); 394 __ jmp(exit); 395 396 return start; 397 } 398 399 // Return point for a Java call if there's an exception thrown in 400 // Java code. The exception is caught and transformed into a 401 // pending exception stored in JavaThread that can be tested from 402 // within the VM. 403 // 404 // Note: Usually the parameters are removed by the callee. In case 405 // of an exception crossing an activation frame boundary, that is 406 // not the case if the callee is compiled code => need to setup the 407 // rsp. 408 // 409 // rax: exception oop 410 411 address generate_catch_exception() { 412 StubCodeMark mark(this, "StubRoutines", "catch_exception"); 413 address start = __ pc(); 414 415 // same as in generate_call_stub(): 416 const Address rsp_after_call(rbp, rsp_after_call_off * wordSize); 417 const Address thread (rbp, thread_off * wordSize); 418 419 #ifdef ASSERT 420 // verify that threads correspond 421 { 422 Label L, S; 423 __ cmpptr(r15_thread, thread); 424 __ jcc(Assembler::notEqual, S); 425 __ get_thread(rbx); 426 __ cmpptr(r15_thread, rbx); 427 __ jcc(Assembler::equal, L); 428 __ bind(S); 429 __ stop("StubRoutines::catch_exception: threads must correspond"); 430 __ bind(L); 431 } 432 #endif 433 434 // set pending exception 435 __ verify_oop(rax); 436 437 __ movptr(Address(r15_thread, Thread::pending_exception_offset()), rax); 438 __ lea(rscratch1, ExternalAddress((address)__FILE__)); 439 __ movptr(Address(r15_thread, Thread::exception_file_offset()), rscratch1); 440 __ movl(Address(r15_thread, Thread::exception_line_offset()), (int) __LINE__); 441 442 // complete return to VM 443 assert(StubRoutines::_call_stub_return_address != NULL, 444 "_call_stub_return_address must have been generated before"); 445 __ jump(RuntimeAddress(StubRoutines::_call_stub_return_address)); 446 447 return start; 448 } 449 450 // Continuation point for runtime calls returning with a pending 451 // exception. The pending exception check happened in the runtime 452 // or native call stub. The pending exception in Thread is 453 // converted into a Java-level exception. 454 // 455 // Contract with Java-level exception handlers: 456 // rax: exception 457 // rdx: throwing pc 458 // 459 // NOTE: At entry of this stub, exception-pc must be on stack !! 460 461 address generate_forward_exception() { 462 StubCodeMark mark(this, "StubRoutines", "forward exception"); 463 address start = __ pc(); 464 465 // Upon entry, the sp points to the return address returning into 466 // Java (interpreted or compiled) code; i.e., the return address 467 // becomes the throwing pc. 468 // 469 // Arguments pushed before the runtime call are still on the stack 470 // but the exception handler will reset the stack pointer -> 471 // ignore them. A potential result in registers can be ignored as 472 // well. 473 474 #ifdef ASSERT 475 // make sure this code is only executed if there is a pending exception 476 { 477 Label L; 478 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t) NULL); 479 __ jcc(Assembler::notEqual, L); 480 __ stop("StubRoutines::forward exception: no pending exception (1)"); 481 __ bind(L); 482 } 483 #endif 484 485 // compute exception handler into rbx 486 __ movptr(c_rarg0, Address(rsp, 0)); 487 BLOCK_COMMENT("call exception_handler_for_return_address"); 488 __ call_VM_leaf(CAST_FROM_FN_PTR(address, 489 SharedRuntime::exception_handler_for_return_address), 490 r15_thread, c_rarg0); 491 __ mov(rbx, rax); 492 493 // setup rax & rdx, remove return address & clear pending exception 494 __ pop(rdx); 495 __ movptr(rax, Address(r15_thread, Thread::pending_exception_offset())); 496 __ movptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD); 497 498 #ifdef ASSERT 499 // make sure exception is set 500 { 501 Label L; 502 __ testptr(rax, rax); 503 __ jcc(Assembler::notEqual, L); 504 __ stop("StubRoutines::forward exception: no pending exception (2)"); 505 __ bind(L); 506 } 507 #endif 508 509 // continue at exception handler (return address removed) 510 // rax: exception 511 // rbx: exception handler 512 // rdx: throwing pc 513 __ verify_oop(rax); 514 __ jmp(rbx); 515 516 return start; 517 } 518 519 // Support for jint atomic::xchg(jint exchange_value, volatile jint* dest) 520 // 521 // Arguments : 522 // c_rarg0: exchange_value 523 // c_rarg0: dest 524 // 525 // Result: 526 // *dest <- ex, return (orig *dest) 527 address generate_atomic_xchg() { 528 StubCodeMark mark(this, "StubRoutines", "atomic_xchg"); 529 address start = __ pc(); 530 531 __ movl(rax, c_rarg0); // Copy to eax we need a return value anyhow 532 __ xchgl(rax, Address(c_rarg1, 0)); // automatic LOCK 533 __ ret(0); 534 535 return start; 536 } 537 538 // Support for intptr_t atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) 539 // 540 // Arguments : 541 // c_rarg0: exchange_value 542 // c_rarg1: dest 543 // 544 // Result: 545 // *dest <- ex, return (orig *dest) 546 address generate_atomic_xchg_ptr() { 547 StubCodeMark mark(this, "StubRoutines", "atomic_xchg_ptr"); 548 address start = __ pc(); 549 550 __ movptr(rax, c_rarg0); // Copy to eax we need a return value anyhow 551 __ xchgptr(rax, Address(c_rarg1, 0)); // automatic LOCK 552 __ ret(0); 553 554 return start; 555 } 556 557 // Support for jint atomic::atomic_cmpxchg(jint exchange_value, volatile jint* dest, 558 // jint compare_value) 559 // 560 // Arguments : 561 // c_rarg0: exchange_value 562 // c_rarg1: dest 563 // c_rarg2: compare_value 564 // 565 // Result: 566 // if ( compare_value == *dest ) { 567 // *dest = exchange_value 568 // return compare_value; 569 // else 570 // return *dest; 571 address generate_atomic_cmpxchg() { 572 StubCodeMark mark(this, "StubRoutines", "atomic_cmpxchg"); 573 address start = __ pc(); 574 575 __ movl(rax, c_rarg2); 576 if ( os::is_MP() ) __ lock(); 577 __ cmpxchgl(c_rarg0, Address(c_rarg1, 0)); 578 __ ret(0); 579 580 return start; 581 } 582 583 // Support for jint atomic::atomic_cmpxchg_long(jlong exchange_value, 584 // volatile jlong* dest, 585 // jlong compare_value) 586 // Arguments : 587 // c_rarg0: exchange_value 588 // c_rarg1: dest 589 // c_rarg2: compare_value 590 // 591 // Result: 592 // if ( compare_value == *dest ) { 593 // *dest = exchange_value 594 // return compare_value; 595 // else 596 // return *dest; 597 address generate_atomic_cmpxchg_long() { 598 StubCodeMark mark(this, "StubRoutines", "atomic_cmpxchg_long"); 599 address start = __ pc(); 600 601 __ movq(rax, c_rarg2); 602 if ( os::is_MP() ) __ lock(); 603 __ cmpxchgq(c_rarg0, Address(c_rarg1, 0)); 604 __ ret(0); 605 606 return start; 607 } 608 609 // Support for jint atomic::add(jint add_value, volatile jint* dest) 610 // 611 // Arguments : 612 // c_rarg0: add_value 613 // c_rarg1: dest 614 // 615 // Result: 616 // *dest += add_value 617 // return *dest; 618 address generate_atomic_add() { 619 StubCodeMark mark(this, "StubRoutines", "atomic_add"); 620 address start = __ pc(); 621 622 __ movl(rax, c_rarg0); 623 if ( os::is_MP() ) __ lock(); 624 __ xaddl(Address(c_rarg1, 0), c_rarg0); 625 __ addl(rax, c_rarg0); 626 __ ret(0); 627 628 return start; 629 } 630 631 // Support for intptr_t atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) 632 // 633 // Arguments : 634 // c_rarg0: add_value 635 // c_rarg1: dest 636 // 637 // Result: 638 // *dest += add_value 639 // return *dest; 640 address generate_atomic_add_ptr() { 641 StubCodeMark mark(this, "StubRoutines", "atomic_add_ptr"); 642 address start = __ pc(); 643 644 __ movptr(rax, c_rarg0); // Copy to eax we need a return value anyhow 645 if ( os::is_MP() ) __ lock(); 646 __ xaddptr(Address(c_rarg1, 0), c_rarg0); 647 __ addptr(rax, c_rarg0); 648 __ ret(0); 649 650 return start; 651 } 652 653 // Support for intptr_t OrderAccess::fence() 654 // 655 // Arguments : 656 // 657 // Result: 658 address generate_orderaccess_fence() { 659 StubCodeMark mark(this, "StubRoutines", "orderaccess_fence"); 660 address start = __ pc(); 661 __ membar(Assembler::StoreLoad); 662 __ ret(0); 663 664 return start; 665 } 666 667 // Support for intptr_t get_previous_fp() 668 // 669 // This routine is used to find the previous frame pointer for the 670 // caller (current_frame_guess). This is used as part of debugging 671 // ps() is seemingly lost trying to find frames. 672 // This code assumes that caller current_frame_guess) has a frame. 673 address generate_get_previous_fp() { 674 StubCodeMark mark(this, "StubRoutines", "get_previous_fp"); 675 const Address old_fp(rbp, 0); 676 const Address older_fp(rax, 0); 677 address start = __ pc(); 678 679 __ enter(); 680 __ movptr(rax, old_fp); // callers fp 681 __ movptr(rax, older_fp); // the frame for ps() 682 __ pop(rbp); 683 __ ret(0); 684 685 return start; 686 } 687 688 //---------------------------------------------------------------------------------------------------- 689 // Support for void verify_mxcsr() 690 // 691 // This routine is used with -Xcheck:jni to verify that native 692 // JNI code does not return to Java code without restoring the 693 // MXCSR register to our expected state. 694 695 address generate_verify_mxcsr() { 696 StubCodeMark mark(this, "StubRoutines", "verify_mxcsr"); 697 address start = __ pc(); 698 699 const Address mxcsr_save(rsp, 0); 700 701 if (CheckJNICalls) { 702 Label ok_ret; 703 __ push(rax); 704 __ subptr(rsp, wordSize); // allocate a temp location 705 __ stmxcsr(mxcsr_save); 706 __ movl(rax, mxcsr_save); 707 __ andl(rax, MXCSR_MASK); // Only check control and mask bits 708 __ cmpl(rax, *(int *)(StubRoutines::x86::mxcsr_std())); 709 __ jcc(Assembler::equal, ok_ret); 710 711 __ warn("MXCSR changed by native JNI code, use -XX:+RestoreMXCSROnJNICall"); 712 713 __ ldmxcsr(ExternalAddress(StubRoutines::x86::mxcsr_std())); 714 715 __ bind(ok_ret); 716 __ addptr(rsp, wordSize); 717 __ pop(rax); 718 } 719 720 __ ret(0); 721 722 return start; 723 } 724 725 address generate_f2i_fixup() { 726 StubCodeMark mark(this, "StubRoutines", "f2i_fixup"); 727 Address inout(rsp, 5 * wordSize); // return address + 4 saves 728 729 address start = __ pc(); 730 731 Label L; 732 733 __ push(rax); 734 __ push(c_rarg3); 735 __ push(c_rarg2); 736 __ push(c_rarg1); 737 738 __ movl(rax, 0x7f800000); 739 __ xorl(c_rarg3, c_rarg3); 740 __ movl(c_rarg2, inout); 741 __ movl(c_rarg1, c_rarg2); 742 __ andl(c_rarg1, 0x7fffffff); 743 __ cmpl(rax, c_rarg1); // NaN? -> 0 744 __ jcc(Assembler::negative, L); 745 __ testl(c_rarg2, c_rarg2); // signed ? min_jint : max_jint 746 __ movl(c_rarg3, 0x80000000); 747 __ movl(rax, 0x7fffffff); 748 __ cmovl(Assembler::positive, c_rarg3, rax); 749 750 __ bind(L); 751 __ movptr(inout, c_rarg3); 752 753 __ pop(c_rarg1); 754 __ pop(c_rarg2); 755 __ pop(c_rarg3); 756 __ pop(rax); 757 758 __ ret(0); 759 760 return start; 761 } 762 763 address generate_f2l_fixup() { 764 StubCodeMark mark(this, "StubRoutines", "f2l_fixup"); 765 Address inout(rsp, 5 * wordSize); // return address + 4 saves 766 address start = __ pc(); 767 768 Label L; 769 770 __ push(rax); 771 __ push(c_rarg3); 772 __ push(c_rarg2); 773 __ push(c_rarg1); 774 775 __ movl(rax, 0x7f800000); 776 __ xorl(c_rarg3, c_rarg3); 777 __ movl(c_rarg2, inout); 778 __ movl(c_rarg1, c_rarg2); 779 __ andl(c_rarg1, 0x7fffffff); 780 __ cmpl(rax, c_rarg1); // NaN? -> 0 781 __ jcc(Assembler::negative, L); 782 __ testl(c_rarg2, c_rarg2); // signed ? min_jlong : max_jlong 783 __ mov64(c_rarg3, 0x8000000000000000); 784 __ mov64(rax, 0x7fffffffffffffff); 785 __ cmov(Assembler::positive, c_rarg3, rax); 786 787 __ bind(L); 788 __ movptr(inout, c_rarg3); 789 790 __ pop(c_rarg1); 791 __ pop(c_rarg2); 792 __ pop(c_rarg3); 793 __ pop(rax); 794 795 __ ret(0); 796 797 return start; 798 } 799 800 address generate_d2i_fixup() { 801 StubCodeMark mark(this, "StubRoutines", "d2i_fixup"); 802 Address inout(rsp, 6 * wordSize); // return address + 5 saves 803 804 address start = __ pc(); 805 806 Label L; 807 808 __ push(rax); 809 __ push(c_rarg3); 810 __ push(c_rarg2); 811 __ push(c_rarg1); 812 __ push(c_rarg0); 813 814 __ movl(rax, 0x7ff00000); 815 __ movq(c_rarg2, inout); 816 __ movl(c_rarg3, c_rarg2); 817 __ mov(c_rarg1, c_rarg2); 818 __ mov(c_rarg0, c_rarg2); 819 __ negl(c_rarg3); 820 __ shrptr(c_rarg1, 0x20); 821 __ orl(c_rarg3, c_rarg2); 822 __ andl(c_rarg1, 0x7fffffff); 823 __ xorl(c_rarg2, c_rarg2); 824 __ shrl(c_rarg3, 0x1f); 825 __ orl(c_rarg1, c_rarg3); 826 __ cmpl(rax, c_rarg1); 827 __ jcc(Assembler::negative, L); // NaN -> 0 828 __ testptr(c_rarg0, c_rarg0); // signed ? min_jint : max_jint 829 __ movl(c_rarg2, 0x80000000); 830 __ movl(rax, 0x7fffffff); 831 __ cmov(Assembler::positive, c_rarg2, rax); 832 833 __ bind(L); 834 __ movptr(inout, c_rarg2); 835 836 __ pop(c_rarg0); 837 __ pop(c_rarg1); 838 __ pop(c_rarg2); 839 __ pop(c_rarg3); 840 __ pop(rax); 841 842 __ ret(0); 843 844 return start; 845 } 846 847 address generate_d2l_fixup() { 848 StubCodeMark mark(this, "StubRoutines", "d2l_fixup"); 849 Address inout(rsp, 6 * wordSize); // return address + 5 saves 850 851 address start = __ pc(); 852 853 Label L; 854 855 __ push(rax); 856 __ push(c_rarg3); 857 __ push(c_rarg2); 858 __ push(c_rarg1); 859 __ push(c_rarg0); 860 861 __ movl(rax, 0x7ff00000); 862 __ movq(c_rarg2, inout); 863 __ movl(c_rarg3, c_rarg2); 864 __ mov(c_rarg1, c_rarg2); 865 __ mov(c_rarg0, c_rarg2); 866 __ negl(c_rarg3); 867 __ shrptr(c_rarg1, 0x20); 868 __ orl(c_rarg3, c_rarg2); 869 __ andl(c_rarg1, 0x7fffffff); 870 __ xorl(c_rarg2, c_rarg2); 871 __ shrl(c_rarg3, 0x1f); 872 __ orl(c_rarg1, c_rarg3); 873 __ cmpl(rax, c_rarg1); 874 __ jcc(Assembler::negative, L); // NaN -> 0 875 __ testq(c_rarg0, c_rarg0); // signed ? min_jlong : max_jlong 876 __ mov64(c_rarg2, 0x8000000000000000); 877 __ mov64(rax, 0x7fffffffffffffff); 878 __ cmovq(Assembler::positive, c_rarg2, rax); 879 880 __ bind(L); 881 __ movq(inout, c_rarg2); 882 883 __ pop(c_rarg0); 884 __ pop(c_rarg1); 885 __ pop(c_rarg2); 886 __ pop(c_rarg3); 887 __ pop(rax); 888 889 __ ret(0); 890 891 return start; 892 } 893 894 address generate_fp_mask(const char *stub_name, int64_t mask) { 895 __ align(CodeEntryAlignment); 896 StubCodeMark mark(this, "StubRoutines", stub_name); 897 address start = __ pc(); 898 899 __ emit_data64( mask, relocInfo::none ); 900 __ emit_data64( mask, relocInfo::none ); 901 902 return start; 903 } 904 905 // The following routine generates a subroutine to throw an 906 // asynchronous UnknownError when an unsafe access gets a fault that 907 // could not be reasonably prevented by the programmer. (Example: 908 // SIGBUS/OBJERR.) 909 address generate_handler_for_unsafe_access() { 910 StubCodeMark mark(this, "StubRoutines", "handler_for_unsafe_access"); 911 address start = __ pc(); 912 913 __ push(0); // hole for return address-to-be 914 __ pusha(); // push registers 915 Address next_pc(rsp, RegisterImpl::number_of_registers * BytesPerWord); 916 917 __ subptr(rsp, frame::arg_reg_save_area_bytes); 918 BLOCK_COMMENT("call handle_unsafe_access"); 919 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, handle_unsafe_access))); 920 __ addptr(rsp, frame::arg_reg_save_area_bytes); 921 922 __ movptr(next_pc, rax); // stuff next address 923 __ popa(); 924 __ ret(0); // jump to next address 925 926 return start; 927 } 928 929 // Non-destructive plausibility checks for oops 930 // 931 // Arguments: 932 // all args on stack! 933 // 934 // Stack after saving c_rarg3: 935 // [tos + 0]: saved c_rarg3 936 // [tos + 1]: saved c_rarg2 937 // [tos + 2]: saved r12 (several TemplateTable methods use it) 938 // [tos + 3]: saved flags 939 // [tos + 4]: return address 940 // * [tos + 5]: error message (char*) 941 // * [tos + 6]: object to verify (oop) 942 // * [tos + 7]: saved rax - saved by caller and bashed 943 // * [tos + 8]: saved r10 (rscratch1) - saved by caller 944 // * = popped on exit 945 address generate_verify_oop() { 946 StubCodeMark mark(this, "StubRoutines", "verify_oop"); 947 address start = __ pc(); 948 949 Label exit, error; 950 951 __ pushf(); 952 __ incrementl(ExternalAddress((address) StubRoutines::verify_oop_count_addr())); 953 954 __ push(r12); 955 956 // save c_rarg2 and c_rarg3 957 __ push(c_rarg2); 958 __ push(c_rarg3); 959 960 enum { 961 // After previous pushes. 962 oop_to_verify = 6 * wordSize, 963 saved_rax = 7 * wordSize, 964 saved_r10 = 8 * wordSize, 965 966 // Before the call to MacroAssembler::debug(), see below. 967 return_addr = 16 * wordSize, 968 error_msg = 17 * wordSize 969 }; 970 971 // get object 972 __ movptr(rax, Address(rsp, oop_to_verify)); 973 974 // make sure object is 'reasonable' 975 __ testptr(rax, rax); 976 __ jcc(Assembler::zero, exit); // if obj is NULL it is OK 977 // Check if the oop is in the right area of memory 978 __ movptr(c_rarg2, rax); 979 __ movptr(c_rarg3, (intptr_t) Universe::verify_oop_mask()); 980 __ andptr(c_rarg2, c_rarg3); 981 __ movptr(c_rarg3, (intptr_t) Universe::verify_oop_bits()); 982 __ cmpptr(c_rarg2, c_rarg3); 983 __ jcc(Assembler::notZero, error); 984 985 // set r12 to heapbase for load_klass() 986 __ reinit_heapbase(); 987 988 // make sure klass is 'reasonable' 989 __ load_klass(rax, rax); // get klass 990 __ testptr(rax, rax); 991 __ jcc(Assembler::zero, error); // if klass is NULL it is broken 992 // Check if the klass is in the right area of memory 993 __ mov(c_rarg2, rax); 994 __ movptr(c_rarg3, (intptr_t) Universe::verify_klass_mask()); 995 __ andptr(c_rarg2, c_rarg3); 996 __ movptr(c_rarg3, (intptr_t) Universe::verify_klass_bits()); 997 __ cmpptr(c_rarg2, c_rarg3); 998 __ jcc(Assembler::notZero, error); 999 1000 // make sure klass' klass is 'reasonable' 1001 __ load_klass(rax, rax); 1002 __ testptr(rax, rax); 1003 __ jcc(Assembler::zero, error); // if klass' klass is NULL it is broken 1004 // Check if the klass' klass is in the right area of memory 1005 __ movptr(c_rarg3, (intptr_t) Universe::verify_klass_mask()); 1006 __ andptr(rax, c_rarg3); 1007 __ movptr(c_rarg3, (intptr_t) Universe::verify_klass_bits()); 1008 __ cmpptr(rax, c_rarg3); 1009 __ jcc(Assembler::notZero, error); 1010 1011 // return if everything seems ok 1012 __ bind(exit); 1013 __ movptr(rax, Address(rsp, saved_rax)); // get saved rax back 1014 __ movptr(rscratch1, Address(rsp, saved_r10)); // get saved r10 back 1015 __ pop(c_rarg3); // restore c_rarg3 1016 __ pop(c_rarg2); // restore c_rarg2 1017 __ pop(r12); // restore r12 1018 __ popf(); // restore flags 1019 __ ret(4 * wordSize); // pop caller saved stuff 1020 1021 // handle errors 1022 __ bind(error); 1023 __ movptr(rax, Address(rsp, saved_rax)); // get saved rax back 1024 __ movptr(rscratch1, Address(rsp, saved_r10)); // get saved r10 back 1025 __ pop(c_rarg3); // get saved c_rarg3 back 1026 __ pop(c_rarg2); // get saved c_rarg2 back 1027 __ pop(r12); // get saved r12 back 1028 __ popf(); // get saved flags off stack -- 1029 // will be ignored 1030 1031 __ pusha(); // push registers 1032 // (rip is already 1033 // already pushed) 1034 // debug(char* msg, int64_t pc, int64_t regs[]) 1035 // We've popped the registers we'd saved (c_rarg3, c_rarg2 and flags), and 1036 // pushed all the registers, so now the stack looks like: 1037 // [tos + 0] 16 saved registers 1038 // [tos + 16] return address 1039 // * [tos + 17] error message (char*) 1040 // * [tos + 18] object to verify (oop) 1041 // * [tos + 19] saved rax - saved by caller and bashed 1042 // * [tos + 20] saved r10 (rscratch1) - saved by caller 1043 // * = popped on exit 1044 1045 __ movptr(c_rarg0, Address(rsp, error_msg)); // pass address of error message 1046 __ movptr(c_rarg1, Address(rsp, return_addr)); // pass return address 1047 __ movq(c_rarg2, rsp); // pass address of regs on stack 1048 __ mov(r12, rsp); // remember rsp 1049 __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows 1050 __ andptr(rsp, -16); // align stack as required by ABI 1051 BLOCK_COMMENT("call MacroAssembler::debug"); 1052 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, MacroAssembler::debug64))); 1053 __ mov(rsp, r12); // restore rsp 1054 __ popa(); // pop registers (includes r12) 1055 __ ret(4 * wordSize); // pop caller saved stuff 1056 1057 return start; 1058 } 1059 1060 // 1061 // Verify that a register contains clean 32-bits positive value 1062 // (high 32-bits are 0) so it could be used in 64-bits shifts. 1063 // 1064 // Input: 1065 // Rint - 32-bits value 1066 // Rtmp - scratch 1067 // 1068 void assert_clean_int(Register Rint, Register Rtmp) { 1069 #ifdef ASSERT 1070 Label L; 1071 assert_different_registers(Rtmp, Rint); 1072 __ movslq(Rtmp, Rint); 1073 __ cmpq(Rtmp, Rint); 1074 __ jcc(Assembler::equal, L); 1075 __ stop("high 32-bits of int value are not 0"); 1076 __ bind(L); 1077 #endif 1078 } 1079 1080 // Generate overlap test for array copy stubs 1081 // 1082 // Input: 1083 // c_rarg0 - from 1084 // c_rarg1 - to 1085 // c_rarg2 - element count 1086 // 1087 // Output: 1088 // rax - &from[element count - 1] 1089 // 1090 void array_overlap_test(address no_overlap_target, Address::ScaleFactor sf) { 1091 assert(no_overlap_target != NULL, "must be generated"); 1092 array_overlap_test(no_overlap_target, NULL, sf); 1093 } 1094 void array_overlap_test(Label& L_no_overlap, Address::ScaleFactor sf) { 1095 array_overlap_test(NULL, &L_no_overlap, sf); 1096 } 1097 void array_overlap_test(address no_overlap_target, Label* NOLp, Address::ScaleFactor sf) { 1098 const Register from = c_rarg0; 1099 const Register to = c_rarg1; 1100 const Register count = c_rarg2; 1101 const Register end_from = rax; 1102 1103 __ cmpptr(to, from); 1104 __ lea(end_from, Address(from, count, sf, 0)); 1105 if (NOLp == NULL) { 1106 ExternalAddress no_overlap(no_overlap_target); 1107 __ jump_cc(Assembler::belowEqual, no_overlap); 1108 __ cmpptr(to, end_from); 1109 __ jump_cc(Assembler::aboveEqual, no_overlap); 1110 } else { 1111 __ jcc(Assembler::belowEqual, (*NOLp)); 1112 __ cmpptr(to, end_from); 1113 __ jcc(Assembler::aboveEqual, (*NOLp)); 1114 } 1115 } 1116 1117 // Shuffle first three arg regs on Windows into Linux/Solaris locations. 1118 // 1119 // Outputs: 1120 // rdi - rcx 1121 // rsi - rdx 1122 // rdx - r8 1123 // rcx - r9 1124 // 1125 // Registers r9 and r10 are used to save rdi and rsi on Windows, which latter 1126 // are non-volatile. r9 and r10 should not be used by the caller. 1127 // 1128 void setup_arg_regs(int nargs = 3) { 1129 const Register saved_rdi = r9; 1130 const Register saved_rsi = r10; 1131 assert(nargs == 3 || nargs == 4, "else fix"); 1132 #ifdef _WIN64 1133 assert(c_rarg0 == rcx && c_rarg1 == rdx && c_rarg2 == r8 && c_rarg3 == r9, 1134 "unexpected argument registers"); 1135 if (nargs >= 4) 1136 __ mov(rax, r9); // r9 is also saved_rdi 1137 __ movptr(saved_rdi, rdi); 1138 __ movptr(saved_rsi, rsi); 1139 __ mov(rdi, rcx); // c_rarg0 1140 __ mov(rsi, rdx); // c_rarg1 1141 __ mov(rdx, r8); // c_rarg2 1142 if (nargs >= 4) 1143 __ mov(rcx, rax); // c_rarg3 (via rax) 1144 #else 1145 assert(c_rarg0 == rdi && c_rarg1 == rsi && c_rarg2 == rdx && c_rarg3 == rcx, 1146 "unexpected argument registers"); 1147 #endif 1148 } 1149 1150 void restore_arg_regs() { 1151 const Register saved_rdi = r9; 1152 const Register saved_rsi = r10; 1153 #ifdef _WIN64 1154 __ movptr(rdi, saved_rdi); 1155 __ movptr(rsi, saved_rsi); 1156 #endif 1157 } 1158 1159 // Generate code for an array write pre barrier 1160 // 1161 // addr - starting address 1162 // count - element count 1163 // 1164 // Destroy no registers! 1165 // 1166 void gen_write_ref_array_pre_barrier(Register addr, Register count) { 1167 BarrierSet* bs = Universe::heap()->barrier_set(); 1168 switch (bs->kind()) { 1169 case BarrierSet::G1SATBCT: 1170 case BarrierSet::G1SATBCTLogging: 1171 { 1172 __ pusha(); // push registers 1173 if (count == c_rarg0) { 1174 if (addr == c_rarg1) { 1175 // exactly backwards!! 1176 __ xchgptr(c_rarg1, c_rarg0); 1177 } else { 1178 __ movptr(c_rarg1, count); 1179 __ movptr(c_rarg0, addr); 1180 } 1181 1182 } else { 1183 __ movptr(c_rarg0, addr); 1184 __ movptr(c_rarg1, count); 1185 } 1186 __ call_VM_leaf(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_pre), 2); 1187 __ popa(); 1188 } 1189 break; 1190 case BarrierSet::CardTableModRef: 1191 case BarrierSet::CardTableExtension: 1192 case BarrierSet::ModRef: 1193 break; 1194 default: 1195 ShouldNotReachHere(); 1196 1197 } 1198 } 1199 1200 // 1201 // Generate code for an array write post barrier 1202 // 1203 // Input: 1204 // start - register containing starting address of destination array 1205 // end - register containing ending address of destination array 1206 // scratch - scratch register 1207 // 1208 // The input registers are overwritten. 1209 // The ending address is inclusive. 1210 void gen_write_ref_array_post_barrier(Register start, Register end, Register scratch) { 1211 assert_different_registers(start, end, scratch); 1212 BarrierSet* bs = Universe::heap()->barrier_set(); 1213 switch (bs->kind()) { 1214 case BarrierSet::G1SATBCT: 1215 case BarrierSet::G1SATBCTLogging: 1216 1217 { 1218 __ pusha(); // push registers (overkill) 1219 // must compute element count unless barrier set interface is changed (other platforms supply count) 1220 assert_different_registers(start, end, scratch); 1221 __ lea(scratch, Address(end, BytesPerHeapOop)); 1222 __ subptr(scratch, start); // subtract start to get #bytes 1223 __ shrptr(scratch, LogBytesPerHeapOop); // convert to element count 1224 __ mov(c_rarg0, start); 1225 __ mov(c_rarg1, scratch); 1226 __ call_VM_leaf(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_post), 2); 1227 __ popa(); 1228 } 1229 break; 1230 case BarrierSet::CardTableModRef: 1231 case BarrierSet::CardTableExtension: 1232 { 1233 CardTableModRefBS* ct = (CardTableModRefBS*)bs; 1234 assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code"); 1235 1236 Label L_loop; 1237 1238 __ shrptr(start, CardTableModRefBS::card_shift); 1239 __ addptr(end, BytesPerHeapOop); 1240 __ shrptr(end, CardTableModRefBS::card_shift); 1241 __ subptr(end, start); // number of bytes to copy 1242 1243 intptr_t disp = (intptr_t) ct->byte_map_base; 1244 if (__ is_simm32(disp)) { 1245 Address cardtable(noreg, noreg, Address::no_scale, disp); 1246 __ lea(scratch, cardtable); 1247 } else { 1248 ExternalAddress cardtable((address)disp); 1249 __ lea(scratch, cardtable); 1250 } 1251 1252 const Register count = end; // 'end' register contains bytes count now 1253 __ addptr(start, scratch); 1254 __ BIND(L_loop); 1255 __ movb(Address(start, count, Address::times_1), 0); 1256 __ decrement(count); 1257 __ jcc(Assembler::greaterEqual, L_loop); 1258 } 1259 break; 1260 default: 1261 ShouldNotReachHere(); 1262 1263 } 1264 } 1265 1266 1267 // Copy big chunks forward 1268 // 1269 // Inputs: 1270 // end_from - source arrays end address 1271 // end_to - destination array end address 1272 // qword_count - 64-bits element count, negative 1273 // to - scratch 1274 // L_copy_32_bytes - entry label 1275 // L_copy_8_bytes - exit label 1276 // 1277 void copy_32_bytes_forward(Register end_from, Register end_to, 1278 Register qword_count, Register to, 1279 Label& L_copy_32_bytes, Label& L_copy_8_bytes) { 1280 DEBUG_ONLY(__ stop("enter at entry label, not here")); 1281 Label L_loop; 1282 __ align(OptoLoopAlignment); 1283 __ BIND(L_loop); 1284 if(UseUnalignedLoadStores) { 1285 __ movdqu(xmm0, Address(end_from, qword_count, Address::times_8, -24)); 1286 __ movdqu(Address(end_to, qword_count, Address::times_8, -24), xmm0); 1287 __ movdqu(xmm1, Address(end_from, qword_count, Address::times_8, - 8)); 1288 __ movdqu(Address(end_to, qword_count, Address::times_8, - 8), xmm1); 1289 1290 } else { 1291 __ movq(to, Address(end_from, qword_count, Address::times_8, -24)); 1292 __ movq(Address(end_to, qword_count, Address::times_8, -24), to); 1293 __ movq(to, Address(end_from, qword_count, Address::times_8, -16)); 1294 __ movq(Address(end_to, qword_count, Address::times_8, -16), to); 1295 __ movq(to, Address(end_from, qword_count, Address::times_8, - 8)); 1296 __ movq(Address(end_to, qword_count, Address::times_8, - 8), to); 1297 __ movq(to, Address(end_from, qword_count, Address::times_8, - 0)); 1298 __ movq(Address(end_to, qword_count, Address::times_8, - 0), to); 1299 } 1300 __ BIND(L_copy_32_bytes); 1301 __ addptr(qword_count, 4); 1302 __ jcc(Assembler::lessEqual, L_loop); 1303 __ subptr(qword_count, 4); 1304 __ jcc(Assembler::less, L_copy_8_bytes); // Copy trailing qwords 1305 } 1306 1307 1308 // Copy big chunks backward 1309 // 1310 // Inputs: 1311 // from - source arrays address 1312 // dest - destination array address 1313 // qword_count - 64-bits element count 1314 // to - scratch 1315 // L_copy_32_bytes - entry label 1316 // L_copy_8_bytes - exit label 1317 // 1318 void copy_32_bytes_backward(Register from, Register dest, 1319 Register qword_count, Register to, 1320 Label& L_copy_32_bytes, Label& L_copy_8_bytes) { 1321 DEBUG_ONLY(__ stop("enter at entry label, not here")); 1322 Label L_loop; 1323 __ align(OptoLoopAlignment); 1324 __ BIND(L_loop); 1325 if(UseUnalignedLoadStores) { 1326 __ movdqu(xmm0, Address(from, qword_count, Address::times_8, 16)); 1327 __ movdqu(Address(dest, qword_count, Address::times_8, 16), xmm0); 1328 __ movdqu(xmm1, Address(from, qword_count, Address::times_8, 0)); 1329 __ movdqu(Address(dest, qword_count, Address::times_8, 0), xmm1); 1330 1331 } else { 1332 __ movq(to, Address(from, qword_count, Address::times_8, 24)); 1333 __ movq(Address(dest, qword_count, Address::times_8, 24), to); 1334 __ movq(to, Address(from, qword_count, Address::times_8, 16)); 1335 __ movq(Address(dest, qword_count, Address::times_8, 16), to); 1336 __ movq(to, Address(from, qword_count, Address::times_8, 8)); 1337 __ movq(Address(dest, qword_count, Address::times_8, 8), to); 1338 __ movq(to, Address(from, qword_count, Address::times_8, 0)); 1339 __ movq(Address(dest, qword_count, Address::times_8, 0), to); 1340 } 1341 __ BIND(L_copy_32_bytes); 1342 __ subptr(qword_count, 4); 1343 __ jcc(Assembler::greaterEqual, L_loop); 1344 __ addptr(qword_count, 4); 1345 __ jcc(Assembler::greater, L_copy_8_bytes); // Copy trailing qwords 1346 } 1347 1348 1349 // Arguments: 1350 // aligned - true => Input and output aligned on a HeapWord == 8-byte boundary 1351 // ignored 1352 // name - stub name string 1353 // 1354 // Inputs: 1355 // c_rarg0 - source array address 1356 // c_rarg1 - destination array address 1357 // c_rarg2 - element count, treated as ssize_t, can be zero 1358 // 1359 // If 'from' and/or 'to' are aligned on 4-, 2-, or 1-byte boundaries, 1360 // we let the hardware handle it. The one to eight bytes within words, 1361 // dwords or qwords that span cache line boundaries will still be loaded 1362 // and stored atomically. 1363 // 1364 // Side Effects: 1365 // disjoint_byte_copy_entry is set to the no-overlap entry point 1366 // used by generate_conjoint_byte_copy(). 1367 // 1368 address generate_disjoint_byte_copy(bool aligned, address* entry, const char *name) { 1369 __ align(CodeEntryAlignment); 1370 StubCodeMark mark(this, "StubRoutines", name); 1371 address start = __ pc(); 1372 1373 Label L_copy_32_bytes, L_copy_8_bytes, L_copy_4_bytes, L_copy_2_bytes; 1374 Label L_copy_byte, L_exit; 1375 const Register from = rdi; // source array address 1376 const Register to = rsi; // destination array address 1377 const Register count = rdx; // elements count 1378 const Register byte_count = rcx; 1379 const Register qword_count = count; 1380 const Register end_from = from; // source array end address 1381 const Register end_to = to; // destination array end address 1382 // End pointers are inclusive, and if count is not zero they point 1383 // to the last unit copied: end_to[0] := end_from[0] 1384 1385 __ enter(); // required for proper stackwalking of RuntimeStub frame 1386 assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. 1387 1388 if (entry != NULL) { 1389 *entry = __ pc(); 1390 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) 1391 BLOCK_COMMENT("Entry:"); 1392 } 1393 1394 setup_arg_regs(); // from => rdi, to => rsi, count => rdx 1395 // r9 and r10 may be used to save non-volatile registers 1396 1397 // 'from', 'to' and 'count' are now valid 1398 __ movptr(byte_count, count); 1399 __ shrptr(count, 3); // count => qword_count 1400 1401 // Copy from low to high addresses. Use 'to' as scratch. 1402 __ lea(end_from, Address(from, qword_count, Address::times_8, -8)); 1403 __ lea(end_to, Address(to, qword_count, Address::times_8, -8)); 1404 __ negptr(qword_count); // make the count negative 1405 __ jmp(L_copy_32_bytes); 1406 1407 // Copy trailing qwords 1408 __ BIND(L_copy_8_bytes); 1409 __ movq(rax, Address(end_from, qword_count, Address::times_8, 8)); 1410 __ movq(Address(end_to, qword_count, Address::times_8, 8), rax); 1411 __ increment(qword_count); 1412 __ jcc(Assembler::notZero, L_copy_8_bytes); 1413 1414 // Check for and copy trailing dword 1415 __ BIND(L_copy_4_bytes); 1416 __ testl(byte_count, 4); 1417 __ jccb(Assembler::zero, L_copy_2_bytes); 1418 __ movl(rax, Address(end_from, 8)); 1419 __ movl(Address(end_to, 8), rax); 1420 1421 __ addptr(end_from, 4); 1422 __ addptr(end_to, 4); 1423 1424 // Check for and copy trailing word 1425 __ BIND(L_copy_2_bytes); 1426 __ testl(byte_count, 2); 1427 __ jccb(Assembler::zero, L_copy_byte); 1428 __ movw(rax, Address(end_from, 8)); 1429 __ movw(Address(end_to, 8), rax); 1430 1431 __ addptr(end_from, 2); 1432 __ addptr(end_to, 2); 1433 1434 // Check for and copy trailing byte 1435 __ BIND(L_copy_byte); 1436 __ testl(byte_count, 1); 1437 __ jccb(Assembler::zero, L_exit); 1438 __ movb(rax, Address(end_from, 8)); 1439 __ movb(Address(end_to, 8), rax); 1440 1441 __ BIND(L_exit); 1442 inc_counter_np(SharedRuntime::_jbyte_array_copy_ctr); 1443 restore_arg_regs(); 1444 __ xorptr(rax, rax); // return 0 1445 __ leave(); // required for proper stackwalking of RuntimeStub frame 1446 __ ret(0); 1447 1448 // Copy in 32-bytes chunks 1449 copy_32_bytes_forward(end_from, end_to, qword_count, rax, L_copy_32_bytes, L_copy_8_bytes); 1450 __ jmp(L_copy_4_bytes); 1451 1452 return start; 1453 } 1454 1455 // Arguments: 1456 // aligned - true => Input and output aligned on a HeapWord == 8-byte boundary 1457 // ignored 1458 // name - stub name string 1459 // 1460 // Inputs: 1461 // c_rarg0 - source array address 1462 // c_rarg1 - destination array address 1463 // c_rarg2 - element count, treated as ssize_t, can be zero 1464 // 1465 // If 'from' and/or 'to' are aligned on 4-, 2-, or 1-byte boundaries, 1466 // we let the hardware handle it. The one to eight bytes within words, 1467 // dwords or qwords that span cache line boundaries will still be loaded 1468 // and stored atomically. 1469 // 1470 address generate_conjoint_byte_copy(bool aligned, address nooverlap_target, 1471 address* entry, const char *name) { 1472 __ align(CodeEntryAlignment); 1473 StubCodeMark mark(this, "StubRoutines", name); 1474 address start = __ pc(); 1475 1476 Label L_copy_32_bytes, L_copy_8_bytes, L_copy_4_bytes, L_copy_2_bytes; 1477 const Register from = rdi; // source array address 1478 const Register to = rsi; // destination array address 1479 const Register count = rdx; // elements count 1480 const Register byte_count = rcx; 1481 const Register qword_count = count; 1482 1483 __ enter(); // required for proper stackwalking of RuntimeStub frame 1484 assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. 1485 1486 if (entry != NULL) { 1487 *entry = __ pc(); 1488 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) 1489 BLOCK_COMMENT("Entry:"); 1490 } 1491 1492 array_overlap_test(nooverlap_target, Address::times_1); 1493 setup_arg_regs(); // from => rdi, to => rsi, count => rdx 1494 // r9 and r10 may be used to save non-volatile registers 1495 1496 // 'from', 'to' and 'count' are now valid 1497 __ movptr(byte_count, count); 1498 __ shrptr(count, 3); // count => qword_count 1499 1500 // Copy from high to low addresses. 1501 1502 // Check for and copy trailing byte 1503 __ testl(byte_count, 1); 1504 __ jcc(Assembler::zero, L_copy_2_bytes); 1505 __ movb(rax, Address(from, byte_count, Address::times_1, -1)); 1506 __ movb(Address(to, byte_count, Address::times_1, -1), rax); 1507 __ decrement(byte_count); // Adjust for possible trailing word 1508 1509 // Check for and copy trailing word 1510 __ BIND(L_copy_2_bytes); 1511 __ testl(byte_count, 2); 1512 __ jcc(Assembler::zero, L_copy_4_bytes); 1513 __ movw(rax, Address(from, byte_count, Address::times_1, -2)); 1514 __ movw(Address(to, byte_count, Address::times_1, -2), rax); 1515 1516 // Check for and copy trailing dword 1517 __ BIND(L_copy_4_bytes); 1518 __ testl(byte_count, 4); 1519 __ jcc(Assembler::zero, L_copy_32_bytes); 1520 __ movl(rax, Address(from, qword_count, Address::times_8)); 1521 __ movl(Address(to, qword_count, Address::times_8), rax); 1522 __ jmp(L_copy_32_bytes); 1523 1524 // Copy trailing qwords 1525 __ BIND(L_copy_8_bytes); 1526 __ movq(rax, Address(from, qword_count, Address::times_8, -8)); 1527 __ movq(Address(to, qword_count, Address::times_8, -8), rax); 1528 __ decrement(qword_count); 1529 __ jcc(Assembler::notZero, L_copy_8_bytes); 1530 1531 inc_counter_np(SharedRuntime::_jbyte_array_copy_ctr); 1532 restore_arg_regs(); 1533 __ xorptr(rax, rax); // return 0 1534 __ leave(); // required for proper stackwalking of RuntimeStub frame 1535 __ ret(0); 1536 1537 // Copy in 32-bytes chunks 1538 copy_32_bytes_backward(from, to, qword_count, rax, L_copy_32_bytes, L_copy_8_bytes); 1539 1540 inc_counter_np(SharedRuntime::_jbyte_array_copy_ctr); 1541 restore_arg_regs(); 1542 __ xorptr(rax, rax); // return 0 1543 __ leave(); // required for proper stackwalking of RuntimeStub frame 1544 __ ret(0); 1545 1546 return start; 1547 } 1548 1549 // Arguments: 1550 // aligned - true => Input and output aligned on a HeapWord == 8-byte boundary 1551 // ignored 1552 // name - stub name string 1553 // 1554 // Inputs: 1555 // c_rarg0 - source array address 1556 // c_rarg1 - destination array address 1557 // c_rarg2 - element count, treated as ssize_t, can be zero 1558 // 1559 // If 'from' and/or 'to' are aligned on 4- or 2-byte boundaries, we 1560 // let the hardware handle it. The two or four words within dwords 1561 // or qwords that span cache line boundaries will still be loaded 1562 // and stored atomically. 1563 // 1564 // Side Effects: 1565 // disjoint_short_copy_entry is set to the no-overlap entry point 1566 // used by generate_conjoint_short_copy(). 1567 // 1568 address generate_disjoint_short_copy(bool aligned, address *entry, const char *name) { 1569 __ align(CodeEntryAlignment); 1570 StubCodeMark mark(this, "StubRoutines", name); 1571 address start = __ pc(); 1572 1573 Label L_copy_32_bytes, L_copy_8_bytes, L_copy_4_bytes,L_copy_2_bytes,L_exit; 1574 const Register from = rdi; // source array address 1575 const Register to = rsi; // destination array address 1576 const Register count = rdx; // elements count 1577 const Register word_count = rcx; 1578 const Register qword_count = count; 1579 const Register end_from = from; // source array end address 1580 const Register end_to = to; // destination array end address 1581 // End pointers are inclusive, and if count is not zero they point 1582 // to the last unit copied: end_to[0] := end_from[0] 1583 1584 __ enter(); // required for proper stackwalking of RuntimeStub frame 1585 assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. 1586 1587 if (entry != NULL) { 1588 *entry = __ pc(); 1589 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) 1590 BLOCK_COMMENT("Entry:"); 1591 } 1592 1593 setup_arg_regs(); // from => rdi, to => rsi, count => rdx 1594 // r9 and r10 may be used to save non-volatile registers 1595 1596 // 'from', 'to' and 'count' are now valid 1597 __ movptr(word_count, count); 1598 __ shrptr(count, 2); // count => qword_count 1599 1600 // Copy from low to high addresses. Use 'to' as scratch. 1601 __ lea(end_from, Address(from, qword_count, Address::times_8, -8)); 1602 __ lea(end_to, Address(to, qword_count, Address::times_8, -8)); 1603 __ negptr(qword_count); 1604 __ jmp(L_copy_32_bytes); 1605 1606 // Copy trailing qwords 1607 __ BIND(L_copy_8_bytes); 1608 __ movq(rax, Address(end_from, qword_count, Address::times_8, 8)); 1609 __ movq(Address(end_to, qword_count, Address::times_8, 8), rax); 1610 __ increment(qword_count); 1611 __ jcc(Assembler::notZero, L_copy_8_bytes); 1612 1613 // Original 'dest' is trashed, so we can't use it as a 1614 // base register for a possible trailing word copy 1615 1616 // Check for and copy trailing dword 1617 __ BIND(L_copy_4_bytes); 1618 __ testl(word_count, 2); 1619 __ jccb(Assembler::zero, L_copy_2_bytes); 1620 __ movl(rax, Address(end_from, 8)); 1621 __ movl(Address(end_to, 8), rax); 1622 1623 __ addptr(end_from, 4); 1624 __ addptr(end_to, 4); 1625 1626 // Check for and copy trailing word 1627 __ BIND(L_copy_2_bytes); 1628 __ testl(word_count, 1); 1629 __ jccb(Assembler::zero, L_exit); 1630 __ movw(rax, Address(end_from, 8)); 1631 __ movw(Address(end_to, 8), rax); 1632 1633 __ BIND(L_exit); 1634 inc_counter_np(SharedRuntime::_jshort_array_copy_ctr); 1635 restore_arg_regs(); 1636 __ xorptr(rax, rax); // return 0 1637 __ leave(); // required for proper stackwalking of RuntimeStub frame 1638 __ ret(0); 1639 1640 // Copy in 32-bytes chunks 1641 copy_32_bytes_forward(end_from, end_to, qword_count, rax, L_copy_32_bytes, L_copy_8_bytes); 1642 __ jmp(L_copy_4_bytes); 1643 1644 return start; 1645 } 1646 1647 address generate_fill(BasicType t, bool aligned, const char *name) { 1648 __ align(CodeEntryAlignment); 1649 StubCodeMark mark(this, "StubRoutines", name); 1650 address start = __ pc(); 1651 1652 BLOCK_COMMENT("Entry:"); 1653 1654 const Register to = c_rarg0; // source array address 1655 const Register value = c_rarg1; // value 1656 const Register count = c_rarg2; // elements count 1657 1658 __ enter(); // required for proper stackwalking of RuntimeStub frame 1659 1660 __ generate_fill(t, aligned, to, value, count, rax, xmm0); 1661 1662 __ leave(); // required for proper stackwalking of RuntimeStub frame 1663 __ ret(0); 1664 return start; 1665 } 1666 1667 // Arguments: 1668 // aligned - true => Input and output aligned on a HeapWord == 8-byte boundary 1669 // ignored 1670 // name - stub name string 1671 // 1672 // Inputs: 1673 // c_rarg0 - source array address 1674 // c_rarg1 - destination array address 1675 // c_rarg2 - element count, treated as ssize_t, can be zero 1676 // 1677 // If 'from' and/or 'to' are aligned on 4- or 2-byte boundaries, we 1678 // let the hardware handle it. The two or four words within dwords 1679 // or qwords that span cache line boundaries will still be loaded 1680 // and stored atomically. 1681 // 1682 address generate_conjoint_short_copy(bool aligned, address nooverlap_target, 1683 address *entry, const char *name) { 1684 __ align(CodeEntryAlignment); 1685 StubCodeMark mark(this, "StubRoutines", name); 1686 address start = __ pc(); 1687 1688 Label L_copy_32_bytes, L_copy_8_bytes, L_copy_4_bytes; 1689 const Register from = rdi; // source array address 1690 const Register to = rsi; // destination array address 1691 const Register count = rdx; // elements count 1692 const Register word_count = rcx; 1693 const Register qword_count = count; 1694 1695 __ enter(); // required for proper stackwalking of RuntimeStub frame 1696 assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. 1697 1698 if (entry != NULL) { 1699 *entry = __ pc(); 1700 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) 1701 BLOCK_COMMENT("Entry:"); 1702 } 1703 1704 array_overlap_test(nooverlap_target, Address::times_2); 1705 setup_arg_regs(); // from => rdi, to => rsi, count => rdx 1706 // r9 and r10 may be used to save non-volatile registers 1707 1708 // 'from', 'to' and 'count' are now valid 1709 __ movptr(word_count, count); 1710 __ shrptr(count, 2); // count => qword_count 1711 1712 // Copy from high to low addresses. Use 'to' as scratch. 1713 1714 // Check for and copy trailing word 1715 __ testl(word_count, 1); 1716 __ jccb(Assembler::zero, L_copy_4_bytes); 1717 __ movw(rax, Address(from, word_count, Address::times_2, -2)); 1718 __ movw(Address(to, word_count, Address::times_2, -2), rax); 1719 1720 // Check for and copy trailing dword 1721 __ BIND(L_copy_4_bytes); 1722 __ testl(word_count, 2); 1723 __ jcc(Assembler::zero, L_copy_32_bytes); 1724 __ movl(rax, Address(from, qword_count, Address::times_8)); 1725 __ movl(Address(to, qword_count, Address::times_8), rax); 1726 __ jmp(L_copy_32_bytes); 1727 1728 // Copy trailing qwords 1729 __ BIND(L_copy_8_bytes); 1730 __ movq(rax, Address(from, qword_count, Address::times_8, -8)); 1731 __ movq(Address(to, qword_count, Address::times_8, -8), rax); 1732 __ decrement(qword_count); 1733 __ jcc(Assembler::notZero, L_copy_8_bytes); 1734 1735 inc_counter_np(SharedRuntime::_jshort_array_copy_ctr); 1736 restore_arg_regs(); 1737 __ xorptr(rax, rax); // return 0 1738 __ leave(); // required for proper stackwalking of RuntimeStub frame 1739 __ ret(0); 1740 1741 // Copy in 32-bytes chunks 1742 copy_32_bytes_backward(from, to, qword_count, rax, L_copy_32_bytes, L_copy_8_bytes); 1743 1744 inc_counter_np(SharedRuntime::_jshort_array_copy_ctr); 1745 restore_arg_regs(); 1746 __ xorptr(rax, rax); // return 0 1747 __ leave(); // required for proper stackwalking of RuntimeStub frame 1748 __ ret(0); 1749 1750 return start; 1751 } 1752 1753 // Arguments: 1754 // aligned - true => Input and output aligned on a HeapWord == 8-byte boundary 1755 // ignored 1756 // is_oop - true => oop array, so generate store check code 1757 // name - stub name string 1758 // 1759 // Inputs: 1760 // c_rarg0 - source array address 1761 // c_rarg1 - destination array address 1762 // c_rarg2 - element count, treated as ssize_t, can be zero 1763 // 1764 // If 'from' and/or 'to' are aligned on 4-byte boundaries, we let 1765 // the hardware handle it. The two dwords within qwords that span 1766 // cache line boundaries will still be loaded and stored atomicly. 1767 // 1768 // Side Effects: 1769 // disjoint_int_copy_entry is set to the no-overlap entry point 1770 // used by generate_conjoint_int_oop_copy(). 1771 // 1772 address generate_disjoint_int_oop_copy(bool aligned, bool is_oop, address* entry, 1773 const char *name, bool need_pre_barrier = true) { 1774 __ align(CodeEntryAlignment); 1775 StubCodeMark mark(this, "StubRoutines", name); 1776 address start = __ pc(); 1777 1778 Label L_copy_32_bytes, L_copy_8_bytes, L_copy_4_bytes, L_exit; 1779 const Register from = rdi; // source array address 1780 const Register to = rsi; // destination array address 1781 const Register count = rdx; // elements count 1782 const Register dword_count = rcx; 1783 const Register qword_count = count; 1784 const Register end_from = from; // source array end address 1785 const Register end_to = to; // destination array end address 1786 const Register saved_to = r11; // saved destination array address 1787 // End pointers are inclusive, and if count is not zero they point 1788 // to the last unit copied: end_to[0] := end_from[0] 1789 1790 __ enter(); // required for proper stackwalking of RuntimeStub frame 1791 assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. 1792 1793 if (entry != NULL) { 1794 *entry = __ pc(); 1795 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) 1796 BLOCK_COMMENT("Entry:"); 1797 } 1798 1799 setup_arg_regs(); // from => rdi, to => rsi, count => rdx 1800 // r9 and r10 may be used to save non-volatile registers 1801 if (is_oop) { 1802 __ movq(saved_to, to); 1803 if (need_pre_barrier) { 1804 gen_write_ref_array_pre_barrier(to, count); 1805 } 1806 } 1807 1808 // 'from', 'to' and 'count' are now valid 1809 __ movptr(dword_count, count); 1810 __ shrptr(count, 1); // count => qword_count 1811 1812 // Copy from low to high addresses. Use 'to' as scratch. 1813 __ lea(end_from, Address(from, qword_count, Address::times_8, -8)); 1814 __ lea(end_to, Address(to, qword_count, Address::times_8, -8)); 1815 __ negptr(qword_count); 1816 __ jmp(L_copy_32_bytes); 1817 1818 // Copy trailing qwords 1819 __ BIND(L_copy_8_bytes); 1820 __ movq(rax, Address(end_from, qword_count, Address::times_8, 8)); 1821 __ movq(Address(end_to, qword_count, Address::times_8, 8), rax); 1822 __ increment(qword_count); 1823 __ jcc(Assembler::notZero, L_copy_8_bytes); 1824 1825 // Check for and copy trailing dword 1826 __ BIND(L_copy_4_bytes); 1827 __ testl(dword_count, 1); // Only byte test since the value is 0 or 1 1828 __ jccb(Assembler::zero, L_exit); 1829 __ movl(rax, Address(end_from, 8)); 1830 __ movl(Address(end_to, 8), rax); 1831 1832 __ BIND(L_exit); 1833 if (is_oop) { 1834 __ leaq(end_to, Address(saved_to, dword_count, Address::times_4, -4)); 1835 gen_write_ref_array_post_barrier(saved_to, end_to, rax); 1836 } 1837 inc_counter_np(SharedRuntime::_jint_array_copy_ctr); 1838 restore_arg_regs(); 1839 __ xorptr(rax, rax); // return 0 1840 __ leave(); // required for proper stackwalking of RuntimeStub frame 1841 __ ret(0); 1842 1843 // Copy 32-bytes chunks 1844 copy_32_bytes_forward(end_from, end_to, qword_count, rax, L_copy_32_bytes, L_copy_8_bytes); 1845 __ jmp(L_copy_4_bytes); 1846 1847 return start; 1848 } 1849 1850 // Arguments: 1851 // aligned - true => Input and output aligned on a HeapWord == 8-byte boundary 1852 // ignored 1853 // is_oop - true => oop array, so generate store check code 1854 // name - stub name string 1855 // 1856 // Inputs: 1857 // c_rarg0 - source array address 1858 // c_rarg1 - destination array address 1859 // c_rarg2 - element count, treated as ssize_t, can be zero 1860 // 1861 // If 'from' and/or 'to' are aligned on 4-byte boundaries, we let 1862 // the hardware handle it. The two dwords within qwords that span 1863 // cache line boundaries will still be loaded and stored atomicly. 1864 // 1865 address generate_conjoint_int_oop_copy(bool aligned, bool is_oop, address nooverlap_target, 1866 address *entry, const char *name, 1867 bool need_pre_barrier = true) { 1868 __ align(CodeEntryAlignment); 1869 StubCodeMark mark(this, "StubRoutines", name); 1870 address start = __ pc(); 1871 1872 Label L_copy_32_bytes, L_copy_8_bytes, L_copy_2_bytes, L_exit; 1873 const Register from = rdi; // source array address 1874 const Register to = rsi; // destination array address 1875 const Register count = rdx; // elements count 1876 const Register dword_count = rcx; 1877 const Register qword_count = count; 1878 1879 __ enter(); // required for proper stackwalking of RuntimeStub frame 1880 assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. 1881 1882 if (entry != NULL) { 1883 *entry = __ pc(); 1884 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) 1885 BLOCK_COMMENT("Entry:"); 1886 } 1887 1888 array_overlap_test(nooverlap_target, Address::times_4); 1889 setup_arg_regs(); // from => rdi, to => rsi, count => rdx 1890 // r9 and r10 may be used to save non-volatile registers 1891 1892 if (is_oop && need_pre_barrier) { 1893 // no registers are destroyed by this call 1894 gen_write_ref_array_pre_barrier(to, count); 1895 } 1896 1897 assert_clean_int(count, rax); // Make sure 'count' is clean int. 1898 // 'from', 'to' and 'count' are now valid 1899 __ movptr(dword_count, count); 1900 __ shrptr(count, 1); // count => qword_count 1901 1902 // Copy from high to low addresses. Use 'to' as scratch. 1903 1904 // Check for and copy trailing dword 1905 __ testl(dword_count, 1); 1906 __ jcc(Assembler::zero, L_copy_32_bytes); 1907 __ movl(rax, Address(from, dword_count, Address::times_4, -4)); 1908 __ movl(Address(to, dword_count, Address::times_4, -4), rax); 1909 __ jmp(L_copy_32_bytes); 1910 1911 // Copy trailing qwords 1912 __ BIND(L_copy_8_bytes); 1913 __ movq(rax, Address(from, qword_count, Address::times_8, -8)); 1914 __ movq(Address(to, qword_count, Address::times_8, -8), rax); 1915 __ decrement(qword_count); 1916 __ jcc(Assembler::notZero, L_copy_8_bytes); 1917 1918 inc_counter_np(SharedRuntime::_jint_array_copy_ctr); 1919 if (is_oop) { 1920 __ jmp(L_exit); 1921 } 1922 restore_arg_regs(); 1923 __ xorptr(rax, rax); // return 0 1924 __ leave(); // required for proper stackwalking of RuntimeStub frame 1925 __ ret(0); 1926 1927 // Copy in 32-bytes chunks 1928 copy_32_bytes_backward(from, to, qword_count, rax, L_copy_32_bytes, L_copy_8_bytes); 1929 1930 inc_counter_np(SharedRuntime::_jint_array_copy_ctr); 1931 __ bind(L_exit); 1932 if (is_oop) { 1933 Register end_to = rdx; 1934 __ leaq(end_to, Address(to, dword_count, Address::times_4, -4)); 1935 gen_write_ref_array_post_barrier(to, end_to, rax); 1936 } 1937 restore_arg_regs(); 1938 __ xorptr(rax, rax); // return 0 1939 __ leave(); // required for proper stackwalking of RuntimeStub frame 1940 __ ret(0); 1941 1942 return start; 1943 } 1944 1945 // Arguments: 1946 // aligned - true => Input and output aligned on a HeapWord boundary == 8 bytes 1947 // ignored 1948 // is_oop - true => oop array, so generate store check code 1949 // name - stub name string 1950 // 1951 // Inputs: 1952 // c_rarg0 - source array address 1953 // c_rarg1 - destination array address 1954 // c_rarg2 - element count, treated as ssize_t, can be zero 1955 // 1956 // Side Effects: 1957 // disjoint_oop_copy_entry or disjoint_long_copy_entry is set to the 1958 // no-overlap entry point used by generate_conjoint_long_oop_copy(). 1959 // 1960 address generate_disjoint_long_oop_copy(bool aligned, bool is_oop, address *entry, 1961 const char *name, bool need_pre_barrier = true) { 1962 __ align(CodeEntryAlignment); 1963 StubCodeMark mark(this, "StubRoutines", name); 1964 address start = __ pc(); 1965 1966 Label L_copy_32_bytes, L_copy_8_bytes, L_exit; 1967 const Register from = rdi; // source array address 1968 const Register to = rsi; // destination array address 1969 const Register qword_count = rdx; // elements count 1970 const Register end_from = from; // source array end address 1971 const Register end_to = rcx; // destination array end address 1972 const Register saved_to = to; 1973 // End pointers are inclusive, and if count is not zero they point 1974 // to the last unit copied: end_to[0] := end_from[0] 1975 1976 __ enter(); // required for proper stackwalking of RuntimeStub frame 1977 // Save no-overlap entry point for generate_conjoint_long_oop_copy() 1978 assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. 1979 1980 if (entry != NULL) { 1981 *entry = __ pc(); 1982 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) 1983 BLOCK_COMMENT("Entry:"); 1984 } 1985 1986 setup_arg_regs(); // from => rdi, to => rsi, count => rdx 1987 // r9 and r10 may be used to save non-volatile registers 1988 // 'from', 'to' and 'qword_count' are now valid 1989 if (is_oop && need_pre_barrier) { 1990 // no registers are destroyed by this call 1991 gen_write_ref_array_pre_barrier(to, qword_count); 1992 } 1993 1994 // Copy from low to high addresses. Use 'to' as scratch. 1995 __ lea(end_from, Address(from, qword_count, Address::times_8, -8)); 1996 __ lea(end_to, Address(to, qword_count, Address::times_8, -8)); 1997 __ negptr(qword_count); 1998 __ jmp(L_copy_32_bytes); 1999 2000 // Copy trailing qwords 2001 __ BIND(L_copy_8_bytes); 2002 __ movq(rax, Address(end_from, qword_count, Address::times_8, 8)); 2003 __ movq(Address(end_to, qword_count, Address::times_8, 8), rax); 2004 __ increment(qword_count); 2005 __ jcc(Assembler::notZero, L_copy_8_bytes); 2006 2007 if (is_oop) { 2008 __ jmp(L_exit); 2009 } else { 2010 inc_counter_np(SharedRuntime::_jlong_array_copy_ctr); 2011 restore_arg_regs(); 2012 __ xorptr(rax, rax); // return 0 2013 __ leave(); // required for proper stackwalking of RuntimeStub frame 2014 __ ret(0); 2015 } 2016 2017 // Copy 64-byte chunks 2018 copy_32_bytes_forward(end_from, end_to, qword_count, rax, L_copy_32_bytes, L_copy_8_bytes); 2019 2020 if (is_oop) { 2021 __ BIND(L_exit); 2022 gen_write_ref_array_post_barrier(saved_to, end_to, rax); 2023 inc_counter_np(SharedRuntime::_oop_array_copy_ctr); 2024 } else { 2025 inc_counter_np(SharedRuntime::_jlong_array_copy_ctr); 2026 } 2027 restore_arg_regs(); 2028 __ xorptr(rax, rax); // return 0 2029 __ leave(); // required for proper stackwalking of RuntimeStub frame 2030 __ ret(0); 2031 2032 return start; 2033 } 2034 2035 // Arguments: 2036 // aligned - true => Input and output aligned on a HeapWord boundary == 8 bytes 2037 // ignored 2038 // is_oop - true => oop array, so generate store check code 2039 // name - stub name string 2040 // 2041 // Inputs: 2042 // c_rarg0 - source array address 2043 // c_rarg1 - destination array address 2044 // c_rarg2 - element count, treated as ssize_t, can be zero 2045 // 2046 address generate_conjoint_long_oop_copy(bool aligned, bool is_oop, 2047 address nooverlap_target, address *entry, 2048 const char *name, bool need_pre_barrier = true) { 2049 __ align(CodeEntryAlignment); 2050 StubCodeMark mark(this, "StubRoutines", name); 2051 address start = __ pc(); 2052 2053 Label L_copy_32_bytes, L_copy_8_bytes, L_exit; 2054 const Register from = rdi; // source array address 2055 const Register to = rsi; // destination array address 2056 const Register qword_count = rdx; // elements count 2057 const Register saved_count = rcx; 2058 2059 __ enter(); // required for proper stackwalking of RuntimeStub frame 2060 assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int. 2061 2062 if (entry != NULL) { 2063 *entry = __ pc(); 2064 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory) 2065 BLOCK_COMMENT("Entry:"); 2066 } 2067 2068 array_overlap_test(nooverlap_target, Address::times_8); 2069 setup_arg_regs(); // from => rdi, to => rsi, count => rdx 2070 // r9 and r10 may be used to save non-volatile registers 2071 // 'from', 'to' and 'qword_count' are now valid 2072 if (is_oop) { 2073 // Save to and count for store barrier 2074 __ movptr(saved_count, qword_count); 2075 if (need_pre_barrier) { 2076 // No registers are destroyed by this call 2077 gen_write_ref_array_pre_barrier(to, saved_count); 2078 } 2079 } 2080 2081 __ jmp(L_copy_32_bytes); 2082 2083 // Copy trailing qwords 2084 __ BIND(L_copy_8_bytes); 2085 __ movq(rax, Address(from, qword_count, Address::times_8, -8)); 2086 __ movq(Address(to, qword_count, Address::times_8, -8), rax); 2087 __ decrement(qword_count); 2088 __ jcc(Assembler::notZero, L_copy_8_bytes); 2089 2090 if (is_oop) { 2091 __ jmp(L_exit); 2092 } else { 2093 inc_counter_np(SharedRuntime::_jlong_array_copy_ctr); 2094 restore_arg_regs(); 2095 __ xorptr(rax, rax); // return 0 2096 __ leave(); // required for proper stackwalking of RuntimeStub frame 2097 __ ret(0); 2098 } 2099 2100 // Copy in 32-bytes chunks 2101 copy_32_bytes_backward(from, to, qword_count, rax, L_copy_32_bytes, L_copy_8_bytes); 2102 2103 if (is_oop) { 2104 __ BIND(L_exit); 2105 __ lea(rcx, Address(to, saved_count, Address::times_8, -8)); 2106 gen_write_ref_array_post_barrier(to, rcx, rax); 2107 inc_counter_np(SharedRuntime::_oop_array_copy_ctr); 2108 } else { 2109 inc_counter_np(SharedRuntime::_jlong_array_copy_ctr); 2110 } 2111 restore_arg_regs(); 2112 __ xorptr(rax, rax); // return 0 2113 __ leave(); // required for proper stackwalking of RuntimeStub frame 2114 __ ret(0); 2115 2116 return start; 2117 } 2118 2119 2120 // Helper for generating a dynamic type check. 2121 // Smashes no registers. 2122 void generate_type_check(Register sub_klass, 2123 Register super_check_offset, 2124 Register super_klass, 2125 Label& L_success) { 2126 assert_different_registers(sub_klass, super_check_offset, super_klass); 2127 2128 BLOCK_COMMENT("type_check:"); 2129 2130 Label L_miss; 2131 2132 __ check_klass_subtype_fast_path(sub_klass, super_klass, noreg, &L_success, &L_miss, NULL, 2133 super_check_offset); 2134 __ check_klass_subtype_slow_path(sub_klass, super_klass, noreg, noreg, &L_success, NULL); 2135 2136 // Fall through on failure! 2137 __ BIND(L_miss); 2138 } 2139 2140 // 2141 // Generate checkcasting array copy stub 2142 // 2143 // Input: 2144 // c_rarg0 - source array address 2145 // c_rarg1 - destination array address 2146 // c_rarg2 - element count, treated as ssize_t, can be zero 2147 // c_rarg3 - size_t ckoff (super_check_offset) 2148 // not Win64 2149 // c_rarg4 - oop ckval (super_klass) 2150 // Win64 2151 // rsp+40 - oop ckval (super_klass) 2152 // 2153 // Output: 2154 // rax == 0 - success 2155 // rax == -1^K - failure, where K is partial transfer count 2156 // 2157 address generate_checkcast_copy(const char *name, address *entry, bool need_pre_barrier = true) { 2158 2159 Label L_load_element, L_store_element, L_do_card_marks, L_done; 2160 2161 // Input registers (after setup_arg_regs) 2162 const Register from = rdi; // source array address 2163 const Register to = rsi; // destination array address 2164 const Register length = rdx; // elements count 2165 const Register ckoff = rcx; // super_check_offset 2166 const Register ckval = r8; // super_klass 2167 2168 // Registers used as temps (r13, r14 are save-on-entry) 2169 const Register end_from = from; // source array end address 2170 const Register end_to = r13; // destination array end address 2171 const Register count = rdx; // -(count_remaining) 2172 const Register r14_length = r14; // saved copy of length 2173 // End pointers are inclusive, and if length is not zero they point 2174 // to the last unit copied: end_to[0] := end_from[0] 2175 2176 const Register rax_oop = rax; // actual oop copied 2177 const Register r11_klass = r11; // oop._klass 2178 2179 //--------------------------------------------------------------- 2180 // Assembler stub will be used for this call to arraycopy 2181 // if the two arrays are subtypes of Object[] but the 2182 // destination array type is not equal to or a supertype 2183 // of the source type. Each element must be separately 2184 // checked. 2185 2186 __ align(CodeEntryAlignment); 2187 StubCodeMark mark(this, "StubRoutines", name); 2188 address start = __ pc(); 2189 2190 __ enter(); // required for proper stackwalking of RuntimeStub frame 2191 2192 #ifdef ASSERT 2193 // caller guarantees that the arrays really are different 2194 // otherwise, we would have to make conjoint checks 2195 { Label L; 2196 array_overlap_test(L, TIMES_OOP); 2197 __ stop("checkcast_copy within a single array"); 2198 __ bind(L); 2199 } 2200 #endif //ASSERT 2201 2202 setup_arg_regs(4); // from => rdi, to => rsi, length => rdx 2203 // ckoff => rcx, ckval => r8 2204 // r9 and r10 may be used to save non-volatile registers 2205 #ifdef _WIN64 2206 // last argument (#4) is on stack on Win64 2207 __ movptr(ckval, Address(rsp, 6 * wordSize)); 2208 #endif 2209 2210 // Caller of this entry point must set up the argument registers. 2211 if (entry != NULL) { 2212 *entry = __ pc(); 2213 BLOCK_COMMENT("Entry:"); 2214 } 2215 2216 // allocate spill slots for r13, r14 2217 enum { 2218 saved_r13_offset, 2219 saved_r14_offset, 2220 saved_rbp_offset 2221 }; 2222 __ subptr(rsp, saved_rbp_offset * wordSize); 2223 __ movptr(Address(rsp, saved_r13_offset * wordSize), r13); 2224 __ movptr(Address(rsp, saved_r14_offset * wordSize), r14); 2225 2226 // check that int operands are properly extended to size_t 2227 assert_clean_int(length, rax); 2228 assert_clean_int(ckoff, rax); 2229 2230 #ifdef ASSERT 2231 BLOCK_COMMENT("assert consistent ckoff/ckval"); 2232 // The ckoff and ckval must be mutually consistent, 2233 // even though caller generates both. 2234 { Label L; 2235 int sco_offset = (klassOopDesc::header_size() * HeapWordSize + 2236 Klass::super_check_offset_offset_in_bytes()); 2237 __ cmpl(ckoff, Address(ckval, sco_offset)); 2238 __ jcc(Assembler::equal, L); 2239 __ stop("super_check_offset inconsistent"); 2240 __ bind(L); 2241 } 2242 #endif //ASSERT 2243 2244 // Loop-invariant addresses. They are exclusive end pointers. 2245 Address end_from_addr(from, length, TIMES_OOP, 0); 2246 Address end_to_addr(to, length, TIMES_OOP, 0); 2247 // Loop-variant addresses. They assume post-incremented count < 0. 2248 Address from_element_addr(end_from, count, TIMES_OOP, 0); 2249 Address to_element_addr(end_to, count, TIMES_OOP, 0); 2250 2251 if (need_pre_barrier) { 2252 gen_write_ref_array_pre_barrier(to, count); 2253 } 2254 2255 // Copy from low to high addresses, indexed from the end of each array. 2256 __ lea(end_from, end_from_addr); 2257 __ lea(end_to, end_to_addr); 2258 __ movptr(r14_length, length); // save a copy of the length 2259 assert(length == count, ""); // else fix next line: 2260 __ negptr(count); // negate and test the length 2261 __ jcc(Assembler::notZero, L_load_element); 2262 2263 // Empty array: Nothing to do. 2264 __ xorptr(rax, rax); // return 0 on (trivial) success 2265 __ jmp(L_done); 2266 2267 // ======== begin loop ======== 2268 // (Loop is rotated; its entry is L_load_element.) 2269 // Loop control: 2270 // for (count = -count; count != 0; count++) 2271 // Base pointers src, dst are biased by 8*(count-1),to last element. 2272 __ align(OptoLoopAlignment); 2273 2274 __ BIND(L_store_element); 2275 __ store_heap_oop(to_element_addr, rax_oop); // store the oop 2276 __ increment(count); // increment the count toward zero 2277 __ jcc(Assembler::zero, L_do_card_marks); 2278 2279 // ======== loop entry is here ======== 2280 __ BIND(L_load_element); 2281 __ load_heap_oop(rax_oop, from_element_addr); // load the oop 2282 __ testptr(rax_oop, rax_oop); 2283 __ jcc(Assembler::zero, L_store_element); 2284 2285 __ load_klass(r11_klass, rax_oop);// query the object klass 2286 generate_type_check(r11_klass, ckoff, ckval, L_store_element); 2287 // ======== end loop ======== 2288 2289 // It was a real error; we must depend on the caller to finish the job. 2290 // Register rdx = -1 * number of *remaining* oops, r14 = *total* oops. 2291 // Emit GC store barriers for the oops we have copied (r14 + rdx), 2292 // and report their number to the caller. 2293 assert_different_registers(rax, r14_length, count, to, end_to, rcx); 2294 __ lea(end_to, to_element_addr); 2295 __ addptr(end_to, -heapOopSize); // make an inclusive end pointer 2296 gen_write_ref_array_post_barrier(to, end_to, rscratch1); 2297 __ movptr(rax, r14_length); // original oops 2298 __ addptr(rax, count); // K = (original - remaining) oops 2299 __ notptr(rax); // report (-1^K) to caller 2300 __ jmp(L_done); 2301 2302 // Come here on success only. 2303 __ BIND(L_do_card_marks); 2304 __ addptr(end_to, -heapOopSize); // make an inclusive end pointer 2305 gen_write_ref_array_post_barrier(to, end_to, rscratch1); 2306 __ xorptr(rax, rax); // return 0 on success 2307 2308 // Common exit point (success or failure). 2309 __ BIND(L_done); 2310 __ movptr(r13, Address(rsp, saved_r13_offset * wordSize)); 2311 __ movptr(r14, Address(rsp, saved_r14_offset * wordSize)); 2312 inc_counter_np(SharedRuntime::_checkcast_array_copy_ctr); 2313 restore_arg_regs(); 2314 __ leave(); // required for proper stackwalking of RuntimeStub frame 2315 __ ret(0); 2316 2317 return start; 2318 } 2319 2320 // 2321 // Generate 'unsafe' array copy stub 2322 // Though just as safe as the other stubs, it takes an unscaled 2323 // size_t argument instead of an element count. 2324 // 2325 // Input: 2326 // c_rarg0 - source array address 2327 // c_rarg1 - destination array address 2328 // c_rarg2 - byte count, treated as ssize_t, can be zero 2329 // 2330 // Examines the alignment of the operands and dispatches 2331 // to a long, int, short, or byte copy loop. 2332 // 2333 address generate_unsafe_copy(const char *name, 2334 address byte_copy_entry, address short_copy_entry, 2335 address int_copy_entry, address long_copy_entry) { 2336 2337 Label L_long_aligned, L_int_aligned, L_short_aligned; 2338 2339 // Input registers (before setup_arg_regs) 2340 const Register from = c_rarg0; // source array address 2341 const Register to = c_rarg1; // destination array address 2342 const Register size = c_rarg2; // byte count (size_t) 2343 2344 // Register used as a temp 2345 const Register bits = rax; // test copy of low bits 2346 2347 __ align(CodeEntryAlignment); 2348 StubCodeMark mark(this, "StubRoutines", name); 2349 address start = __ pc(); 2350 2351 __ enter(); // required for proper stackwalking of RuntimeStub frame 2352 2353 // bump this on entry, not on exit: 2354 inc_counter_np(SharedRuntime::_unsafe_array_copy_ctr); 2355 2356 __ mov(bits, from); 2357 __ orptr(bits, to); 2358 __ orptr(bits, size); 2359 2360 __ testb(bits, BytesPerLong-1); 2361 __ jccb(Assembler::zero, L_long_aligned); 2362 2363 __ testb(bits, BytesPerInt-1); 2364 __ jccb(Assembler::zero, L_int_aligned); 2365 2366 __ testb(bits, BytesPerShort-1); 2367 __ jump_cc(Assembler::notZero, RuntimeAddress(byte_copy_entry)); 2368 2369 __ BIND(L_short_aligned); 2370 __ shrptr(size, LogBytesPerShort); // size => short_count 2371 __ jump(RuntimeAddress(short_copy_entry)); 2372 2373 __ BIND(L_int_aligned); 2374 __ shrptr(size, LogBytesPerInt); // size => int_count 2375 __ jump(RuntimeAddress(int_copy_entry)); 2376 2377 __ BIND(L_long_aligned); 2378 __ shrptr(size, LogBytesPerLong); // size => qword_count 2379 __ jump(RuntimeAddress(long_copy_entry)); 2380 2381 return start; 2382 } 2383 2384 // Perform range checks on the proposed arraycopy. 2385 // Kills temp, but nothing else. 2386 // Also, clean the sign bits of src_pos and dst_pos. 2387 void arraycopy_range_checks(Register src, // source array oop (c_rarg0) 2388 Register src_pos, // source position (c_rarg1) 2389 Register dst, // destination array oo (c_rarg2) 2390 Register dst_pos, // destination position (c_rarg3) 2391 Register length, 2392 Register temp, 2393 Label& L_failed) { 2394 BLOCK_COMMENT("arraycopy_range_checks:"); 2395 2396 // if (src_pos + length > arrayOop(src)->length()) FAIL; 2397 __ movl(temp, length); 2398 __ addl(temp, src_pos); // src_pos + length 2399 __ cmpl(temp, Address(src, arrayOopDesc::length_offset_in_bytes())); 2400 __ jcc(Assembler::above, L_failed); 2401 2402 // if (dst_pos + length > arrayOop(dst)->length()) FAIL; 2403 __ movl(temp, length); 2404 __ addl(temp, dst_pos); // dst_pos + length 2405 __ cmpl(temp, Address(dst, arrayOopDesc::length_offset_in_bytes())); 2406 __ jcc(Assembler::above, L_failed); 2407 2408 // Have to clean up high 32-bits of 'src_pos' and 'dst_pos'. 2409 // Move with sign extension can be used since they are positive. 2410 __ movslq(src_pos, src_pos); 2411 __ movslq(dst_pos, dst_pos); 2412 2413 BLOCK_COMMENT("arraycopy_range_checks done"); 2414 } 2415 2416 // 2417 // Generate generic array copy stubs 2418 // 2419 // Input: 2420 // c_rarg0 - src oop 2421 // c_rarg1 - src_pos (32-bits) 2422 // c_rarg2 - dst oop 2423 // c_rarg3 - dst_pos (32-bits) 2424 // not Win64 2425 // c_rarg4 - element count (32-bits) 2426 // Win64 2427 // rsp+40 - element count (32-bits) 2428 // 2429 // Output: 2430 // rax == 0 - success 2431 // rax == -1^K - failure, where K is partial transfer count 2432 // 2433 address generate_generic_copy(const char *name, 2434 address byte_copy_entry, address short_copy_entry, 2435 address int_copy_entry, address long_copy_entry, 2436 address oop_copy_entry, address checkcast_copy_entry) { 2437 2438 Label L_failed, L_failed_0, L_objArray; 2439 Label L_copy_bytes, L_copy_shorts, L_copy_ints, L_copy_longs; 2440 2441 // Input registers 2442 const Register src = c_rarg0; // source array oop 2443 const Register src_pos = c_rarg1; // source position 2444 const Register dst = c_rarg2; // destination array oop 2445 const Register dst_pos = c_rarg3; // destination position 2446 #ifndef _WIN64 2447 const Register length = c_rarg4; 2448 #else 2449 const Address length(rsp, 6 * wordSize); // elements count is on stack on Win64 2450 #endif 2451 2452 { int modulus = CodeEntryAlignment; 2453 int target = modulus - 5; // 5 = sizeof jmp(L_failed) 2454 int advance = target - (__ offset() % modulus); 2455 if (advance < 0) advance += modulus; 2456 if (advance > 0) __ nop(advance); 2457 } 2458 StubCodeMark mark(this, "StubRoutines", name); 2459 2460 // Short-hop target to L_failed. Makes for denser prologue code. 2461 __ BIND(L_failed_0); 2462 __ jmp(L_failed); 2463 assert(__ offset() % CodeEntryAlignment == 0, "no further alignment needed"); 2464 2465 __ align(CodeEntryAlignment); 2466 address start = __ pc(); 2467 2468 __ enter(); // required for proper stackwalking of RuntimeStub frame 2469 2470 // bump this on entry, not on exit: 2471 inc_counter_np(SharedRuntime::_generic_array_copy_ctr); 2472 2473 //----------------------------------------------------------------------- 2474 // Assembler stub will be used for this call to arraycopy 2475 // if the following conditions are met: 2476 // 2477 // (1) src and dst must not be null. 2478 // (2) src_pos must not be negative. 2479 // (3) dst_pos must not be negative. 2480 // (4) length must not be negative. 2481 // (5) src klass and dst klass should be the same and not NULL. 2482 // (6) src and dst should be arrays. 2483 // (7) src_pos + length must not exceed length of src. 2484 // (8) dst_pos + length must not exceed length of dst. 2485 // 2486 2487 // if (src == NULL) return -1; 2488 __ testptr(src, src); // src oop 2489 size_t j1off = __ offset(); 2490 __ jccb(Assembler::zero, L_failed_0); 2491 2492 // if (src_pos < 0) return -1; 2493 __ testl(src_pos, src_pos); // src_pos (32-bits) 2494 __ jccb(Assembler::negative, L_failed_0); 2495 2496 // if (dst == NULL) return -1; 2497 __ testptr(dst, dst); // dst oop 2498 __ jccb(Assembler::zero, L_failed_0); 2499 2500 // if (dst_pos < 0) return -1; 2501 __ testl(dst_pos, dst_pos); // dst_pos (32-bits) 2502 size_t j4off = __ offset(); 2503 __ jccb(Assembler::negative, L_failed_0); 2504 2505 // The first four tests are very dense code, 2506 // but not quite dense enough to put four 2507 // jumps in a 16-byte instruction fetch buffer. 2508 // That's good, because some branch predicters 2509 // do not like jumps so close together. 2510 // Make sure of this. 2511 guarantee(((j1off ^ j4off) & ~15) != 0, "I$ line of 1st & 4th jumps"); 2512 2513 // registers used as temp 2514 const Register r11_length = r11; // elements count to copy 2515 const Register r10_src_klass = r10; // array klass 2516 2517 // if (length < 0) return -1; 2518 __ movl(r11_length, length); // length (elements count, 32-bits value) 2519 __ testl(r11_length, r11_length); 2520 __ jccb(Assembler::negative, L_failed_0); 2521 2522 __ load_klass(r10_src_klass, src); 2523 #ifdef ASSERT 2524 // assert(src->klass() != NULL); 2525 { 2526 BLOCK_COMMENT("assert klasses not null {"); 2527 Label L1, L2; 2528 __ testptr(r10_src_klass, r10_src_klass); 2529 __ jcc(Assembler::notZero, L2); // it is broken if klass is NULL 2530 __ bind(L1); 2531 __ stop("broken null klass"); 2532 __ bind(L2); 2533 __ load_klass(rax, dst); 2534 __ cmpq(rax, 0); 2535 __ jcc(Assembler::equal, L1); // this would be broken also 2536 BLOCK_COMMENT("} assert klasses not null done"); 2537 } 2538 #endif 2539 2540 // Load layout helper (32-bits) 2541 // 2542 // |array_tag| | header_size | element_type | |log2_element_size| 2543 // 32 30 24 16 8 2 0 2544 // 2545 // array_tag: typeArray = 0x3, objArray = 0x2, non-array = 0x0 2546 // 2547 2548 const int lh_offset = klassOopDesc::header_size() * HeapWordSize + 2549 Klass::layout_helper_offset_in_bytes(); 2550 2551 // Handle objArrays completely differently... 2552 const jint objArray_lh = Klass::array_layout_helper(T_OBJECT); 2553 __ cmpl(Address(r10_src_klass, lh_offset), objArray_lh); 2554 __ jcc(Assembler::equal, L_objArray); 2555 2556 // if (src->klass() != dst->klass()) return -1; 2557 __ load_klass(rax, dst); 2558 __ cmpq(r10_src_klass, rax); 2559 __ jcc(Assembler::notEqual, L_failed); 2560 2561 const Register rax_lh = rax; // layout helper 2562 __ movl(rax_lh, Address(r10_src_klass, lh_offset)); 2563 2564 // if (!src->is_Array()) return -1; 2565 __ cmpl(rax_lh, Klass::_lh_neutral_value); 2566 __ jcc(Assembler::greaterEqual, L_failed); 2567 2568 // At this point, it is known to be a typeArray (array_tag 0x3). 2569 #ifdef ASSERT 2570 { 2571 BLOCK_COMMENT("assert primitive array {"); 2572 Label L; 2573 __ cmpl(rax_lh, (Klass::_lh_array_tag_type_value << Klass::_lh_array_tag_shift)); 2574 __ jcc(Assembler::greaterEqual, L); 2575 __ stop("must be a primitive array"); 2576 __ bind(L); 2577 BLOCK_COMMENT("} assert primitive array done"); 2578 } 2579 #endif 2580 2581 arraycopy_range_checks(src, src_pos, dst, dst_pos, r11_length, 2582 r10, L_failed); 2583 2584 // typeArrayKlass 2585 // 2586 // src_addr = (src + array_header_in_bytes()) + (src_pos << log2elemsize); 2587 // dst_addr = (dst + array_header_in_bytes()) + (dst_pos << log2elemsize); 2588 // 2589 2590 const Register r10_offset = r10; // array offset 2591 const Register rax_elsize = rax_lh; // element size 2592 2593 __ movl(r10_offset, rax_lh); 2594 __ shrl(r10_offset, Klass::_lh_header_size_shift); 2595 __ andptr(r10_offset, Klass::_lh_header_size_mask); // array_offset 2596 __ addptr(src, r10_offset); // src array offset 2597 __ addptr(dst, r10_offset); // dst array offset 2598 BLOCK_COMMENT("choose copy loop based on element size"); 2599 __ andl(rax_lh, Klass::_lh_log2_element_size_mask); // rax_lh -> rax_elsize 2600 2601 // next registers should be set before the jump to corresponding stub 2602 const Register from = c_rarg0; // source array address 2603 const Register to = c_rarg1; // destination array address 2604 const Register count = c_rarg2; // elements count 2605 2606 // 'from', 'to', 'count' registers should be set in such order 2607 // since they are the same as 'src', 'src_pos', 'dst'. 2608 2609 __ BIND(L_copy_bytes); 2610 __ cmpl(rax_elsize, 0); 2611 __ jccb(Assembler::notEqual, L_copy_shorts); 2612 __ lea(from, Address(src, src_pos, Address::times_1, 0));// src_addr 2613 __ lea(to, Address(dst, dst_pos, Address::times_1, 0));// dst_addr 2614 __ movl2ptr(count, r11_length); // length 2615 __ jump(RuntimeAddress(byte_copy_entry)); 2616 2617 __ BIND(L_copy_shorts); 2618 __ cmpl(rax_elsize, LogBytesPerShort); 2619 __ jccb(Assembler::notEqual, L_copy_ints); 2620 __ lea(from, Address(src, src_pos, Address::times_2, 0));// src_addr 2621 __ lea(to, Address(dst, dst_pos, Address::times_2, 0));// dst_addr 2622 __ movl2ptr(count, r11_length); // length 2623 __ jump(RuntimeAddress(short_copy_entry)); 2624 2625 __ BIND(L_copy_ints); 2626 __ cmpl(rax_elsize, LogBytesPerInt); 2627 __ jccb(Assembler::notEqual, L_copy_longs); 2628 __ lea(from, Address(src, src_pos, Address::times_4, 0));// src_addr 2629 __ lea(to, Address(dst, dst_pos, Address::times_4, 0));// dst_addr 2630 __ movl2ptr(count, r11_length); // length 2631 __ jump(RuntimeAddress(int_copy_entry)); 2632 2633 __ BIND(L_copy_longs); 2634 #ifdef ASSERT 2635 { 2636 BLOCK_COMMENT("assert long copy {"); 2637 Label L; 2638 __ cmpl(rax_elsize, LogBytesPerLong); 2639 __ jcc(Assembler::equal, L); 2640 __ stop("must be long copy, but elsize is wrong"); 2641 __ bind(L); 2642 BLOCK_COMMENT("} assert long copy done"); 2643 } 2644 #endif 2645 __ lea(from, Address(src, src_pos, Address::times_8, 0));// src_addr 2646 __ lea(to, Address(dst, dst_pos, Address::times_8, 0));// dst_addr 2647 __ movl2ptr(count, r11_length); // length 2648 __ jump(RuntimeAddress(long_copy_entry)); 2649 2650 // objArrayKlass 2651 __ BIND(L_objArray); 2652 // live at this point: r10_src_klass, r11_length, src[_pos], dst[_pos] 2653 2654 Label L_plain_copy, L_checkcast_copy; 2655 // test array classes for subtyping 2656 __ load_klass(rax, dst); 2657 __ cmpq(r10_src_klass, rax); // usual case is exact equality 2658 __ jcc(Assembler::notEqual, L_checkcast_copy); 2659 2660 // Identically typed arrays can be copied without element-wise checks. 2661 arraycopy_range_checks(src, src_pos, dst, dst_pos, r11_length, 2662 r10, L_failed); 2663 2664 __ lea(from, Address(src, src_pos, TIMES_OOP, 2665 arrayOopDesc::base_offset_in_bytes(T_OBJECT))); // src_addr 2666 __ lea(to, Address(dst, dst_pos, TIMES_OOP, 2667 arrayOopDesc::base_offset_in_bytes(T_OBJECT))); // dst_addr 2668 __ movl2ptr(count, r11_length); // length 2669 __ BIND(L_plain_copy); 2670 __ jump(RuntimeAddress(oop_copy_entry)); 2671 2672 __ BIND(L_checkcast_copy); 2673 // live at this point: r10_src_klass, r11_length, rax (dst_klass) 2674 { 2675 // Before looking at dst.length, make sure dst is also an objArray. 2676 __ cmpl(Address(rax, lh_offset), objArray_lh); 2677 __ jcc(Assembler::notEqual, L_failed); 2678 2679 // It is safe to examine both src.length and dst.length. 2680 arraycopy_range_checks(src, src_pos, dst, dst_pos, r11_length, 2681 rax, L_failed); 2682 2683 const Register r11_dst_klass = r11; 2684 __ load_klass(r11_dst_klass, dst); // reload 2685 2686 // Marshal the base address arguments now, freeing registers. 2687 __ lea(from, Address(src, src_pos, TIMES_OOP, 2688 arrayOopDesc::base_offset_in_bytes(T_OBJECT))); 2689 __ lea(to, Address(dst, dst_pos, TIMES_OOP, 2690 arrayOopDesc::base_offset_in_bytes(T_OBJECT))); 2691 __ movl(count, length); // length (reloaded) 2692 Register sco_temp = c_rarg3; // this register is free now 2693 assert_different_registers(from, to, count, sco_temp, 2694 r11_dst_klass, r10_src_klass); 2695 assert_clean_int(count, sco_temp); 2696 2697 // Generate the type check. 2698 const int sco_offset = (klassOopDesc::header_size() * HeapWordSize + 2699 Klass::super_check_offset_offset_in_bytes()); 2700 __ movl(sco_temp, Address(r11_dst_klass, sco_offset)); 2701 assert_clean_int(sco_temp, rax); 2702 generate_type_check(r10_src_klass, sco_temp, r11_dst_klass, L_plain_copy); 2703 2704 // Fetch destination element klass from the objArrayKlass header. 2705 int ek_offset = (klassOopDesc::header_size() * HeapWordSize + 2706 objArrayKlass::element_klass_offset_in_bytes()); 2707 __ movptr(r11_dst_klass, Address(r11_dst_klass, ek_offset)); 2708 __ movl( sco_temp, Address(r11_dst_klass, sco_offset)); 2709 assert_clean_int(sco_temp, rax); 2710 2711 // the checkcast_copy loop needs two extra arguments: 2712 assert(c_rarg3 == sco_temp, "#3 already in place"); 2713 // Set up arguments for checkcast_copy_entry. 2714 setup_arg_regs(4); 2715 __ movptr(r8, r11_dst_klass); // dst.klass.element_klass, r8 is c_rarg4 on Linux/Solaris 2716 __ jump(RuntimeAddress(checkcast_copy_entry)); 2717 } 2718 2719 __ BIND(L_failed); 2720 __ xorptr(rax, rax); 2721 __ notptr(rax); // return -1 2722 __ leave(); // required for proper stackwalking of RuntimeStub frame 2723 __ ret(0); 2724 2725 return start; 2726 } 2727 2728 void generate_arraycopy_stubs() { 2729 address entry; 2730 address entry_jbyte_arraycopy; 2731 address entry_jshort_arraycopy; 2732 address entry_jint_arraycopy; 2733 address entry_oop_arraycopy; 2734 address entry_jlong_arraycopy; 2735 address entry_checkcast_arraycopy; 2736 2737 StubRoutines::_jbyte_disjoint_arraycopy = generate_disjoint_byte_copy(false, &entry, 2738 "jbyte_disjoint_arraycopy"); 2739 StubRoutines::_jbyte_arraycopy = generate_conjoint_byte_copy(false, entry, &entry_jbyte_arraycopy, 2740 "jbyte_arraycopy"); 2741 2742 StubRoutines::_jshort_disjoint_arraycopy = generate_disjoint_short_copy(false, &entry, 2743 "jshort_disjoint_arraycopy"); 2744 StubRoutines::_jshort_arraycopy = generate_conjoint_short_copy(false, entry, &entry_jshort_arraycopy, 2745 "jshort_arraycopy"); 2746 2747 StubRoutines::_jint_disjoint_arraycopy = generate_disjoint_int_oop_copy(false, false, &entry, 2748 "jint_disjoint_arraycopy"); 2749 StubRoutines::_jint_arraycopy = generate_conjoint_int_oop_copy(false, false, entry, 2750 &entry_jint_arraycopy, "jint_arraycopy"); 2751 2752 StubRoutines::_jlong_disjoint_arraycopy = generate_disjoint_long_oop_copy(false, false, &entry, 2753 "jlong_disjoint_arraycopy"); 2754 StubRoutines::_jlong_arraycopy = generate_conjoint_long_oop_copy(false, false, entry, 2755 &entry_jlong_arraycopy, "jlong_arraycopy"); 2756 2757 2758 if (UseCompressedOops) { 2759 StubRoutines::_oop_disjoint_arraycopy = generate_disjoint_int_oop_copy(false, true, &entry, 2760 "oop_disjoint_arraycopy"); 2761 StubRoutines::_oop_arraycopy = generate_conjoint_int_oop_copy(false, true, entry, 2762 &entry_oop_arraycopy, "oop_arraycopy"); 2763 StubRoutines::_oop_disjoint_arraycopy_no_pre = generate_disjoint_int_oop_copy(false, true, &entry, 2764 "oop_disjoint_arraycopy_no_pre", false); 2765 StubRoutines::_oop_arraycopy_no_pre = generate_conjoint_int_oop_copy(false, true, entry, 2766 NULL, "oop_arraycopy_no_pre", false); 2767 } else { 2768 StubRoutines::_oop_disjoint_arraycopy = generate_disjoint_long_oop_copy(false, true, &entry, 2769 "oop_disjoint_arraycopy"); 2770 StubRoutines::_oop_arraycopy = generate_conjoint_long_oop_copy(false, true, entry, 2771 &entry_oop_arraycopy, "oop_arraycopy"); 2772 StubRoutines::_oop_disjoint_arraycopy_no_pre = generate_disjoint_long_oop_copy(false, true, &entry, 2773 "oop_disjoint_arraycopy_no_pre", false); 2774 StubRoutines::_oop_arraycopy_no_pre = generate_conjoint_long_oop_copy(false, true, entry, 2775 NULL, "oop_arraycopy_no_pre", false); 2776 } 2777 2778 StubRoutines::_checkcast_arraycopy = generate_checkcast_copy("checkcast_arraycopy", &entry_checkcast_arraycopy); 2779 StubRoutines::_checkcast_arraycopy_no_pre = generate_checkcast_copy("checkcast_arraycopy_no_pre", NULL, false); 2780 2781 StubRoutines::_unsafe_arraycopy = generate_unsafe_copy("unsafe_arraycopy", 2782 entry_jbyte_arraycopy, 2783 entry_jshort_arraycopy, 2784 entry_jint_arraycopy, 2785 entry_jlong_arraycopy); 2786 StubRoutines::_generic_arraycopy = generate_generic_copy("generic_arraycopy", 2787 entry_jbyte_arraycopy, 2788 entry_jshort_arraycopy, 2789 entry_jint_arraycopy, 2790 entry_oop_arraycopy, 2791 entry_jlong_arraycopy, 2792 entry_checkcast_arraycopy); 2793 2794 StubRoutines::_jbyte_fill = generate_fill(T_BYTE, false, "jbyte_fill"); 2795 StubRoutines::_jshort_fill = generate_fill(T_SHORT, false, "jshort_fill"); 2796 StubRoutines::_jint_fill = generate_fill(T_INT, false, "jint_fill"); 2797 StubRoutines::_arrayof_jbyte_fill = generate_fill(T_BYTE, true, "arrayof_jbyte_fill"); 2798 StubRoutines::_arrayof_jshort_fill = generate_fill(T_SHORT, true, "arrayof_jshort_fill"); 2799 StubRoutines::_arrayof_jint_fill = generate_fill(T_INT, true, "arrayof_jint_fill"); 2800 2801 // We don't generate specialized code for HeapWord-aligned source 2802 // arrays, so just use the code we've already generated 2803 StubRoutines::_arrayof_jbyte_disjoint_arraycopy = StubRoutines::_jbyte_disjoint_arraycopy; 2804 StubRoutines::_arrayof_jbyte_arraycopy = StubRoutines::_jbyte_arraycopy; 2805 2806 StubRoutines::_arrayof_jshort_disjoint_arraycopy = StubRoutines::_jshort_disjoint_arraycopy; 2807 StubRoutines::_arrayof_jshort_arraycopy = StubRoutines::_jshort_arraycopy; 2808 2809 StubRoutines::_arrayof_jint_disjoint_arraycopy = StubRoutines::_jint_disjoint_arraycopy; 2810 StubRoutines::_arrayof_jint_arraycopy = StubRoutines::_jint_arraycopy; 2811 2812 StubRoutines::_arrayof_jlong_disjoint_arraycopy = StubRoutines::_jlong_disjoint_arraycopy; 2813 StubRoutines::_arrayof_jlong_arraycopy = StubRoutines::_jlong_arraycopy; 2814 2815 StubRoutines::_arrayof_oop_disjoint_arraycopy = StubRoutines::_oop_disjoint_arraycopy; 2816 StubRoutines::_arrayof_oop_arraycopy = StubRoutines::_oop_arraycopy; 2817 2818 StubRoutines::_arrayof_oop_disjoint_arraycopy_no_pre = StubRoutines::_oop_disjoint_arraycopy_no_pre; 2819 StubRoutines::_arrayof_oop_arraycopy_no_pre = StubRoutines::_oop_arraycopy_no_pre; 2820 } 2821 2822 void generate_math_stubs() { 2823 { 2824 StubCodeMark mark(this, "StubRoutines", "log"); 2825 StubRoutines::_intrinsic_log = (double (*)(double)) __ pc(); 2826 2827 __ subq(rsp, 8); 2828 __ movdbl(Address(rsp, 0), xmm0); 2829 __ fld_d(Address(rsp, 0)); 2830 __ flog(); 2831 __ fstp_d(Address(rsp, 0)); 2832 __ movdbl(xmm0, Address(rsp, 0)); 2833 __ addq(rsp, 8); 2834 __ ret(0); 2835 } 2836 { 2837 StubCodeMark mark(this, "StubRoutines", "log10"); 2838 StubRoutines::_intrinsic_log10 = (double (*)(double)) __ pc(); 2839 2840 __ subq(rsp, 8); 2841 __ movdbl(Address(rsp, 0), xmm0); 2842 __ fld_d(Address(rsp, 0)); 2843 __ flog10(); 2844 __ fstp_d(Address(rsp, 0)); 2845 __ movdbl(xmm0, Address(rsp, 0)); 2846 __ addq(rsp, 8); 2847 __ ret(0); 2848 } 2849 { 2850 StubCodeMark mark(this, "StubRoutines", "sin"); 2851 StubRoutines::_intrinsic_sin = (double (*)(double)) __ pc(); 2852 2853 __ subq(rsp, 8); 2854 __ movdbl(Address(rsp, 0), xmm0); 2855 __ fld_d(Address(rsp, 0)); 2856 __ trigfunc('s'); 2857 __ fstp_d(Address(rsp, 0)); 2858 __ movdbl(xmm0, Address(rsp, 0)); 2859 __ addq(rsp, 8); 2860 __ ret(0); 2861 } 2862 { 2863 StubCodeMark mark(this, "StubRoutines", "cos"); 2864 StubRoutines::_intrinsic_cos = (double (*)(double)) __ pc(); 2865 2866 __ subq(rsp, 8); 2867 __ movdbl(Address(rsp, 0), xmm0); 2868 __ fld_d(Address(rsp, 0)); 2869 __ trigfunc('c'); 2870 __ fstp_d(Address(rsp, 0)); 2871 __ movdbl(xmm0, Address(rsp, 0)); 2872 __ addq(rsp, 8); 2873 __ ret(0); 2874 } 2875 { 2876 StubCodeMark mark(this, "StubRoutines", "tan"); 2877 StubRoutines::_intrinsic_tan = (double (*)(double)) __ pc(); 2878 2879 __ subq(rsp, 8); 2880 __ movdbl(Address(rsp, 0), xmm0); 2881 __ fld_d(Address(rsp, 0)); 2882 __ trigfunc('t'); 2883 __ fstp_d(Address(rsp, 0)); 2884 __ movdbl(xmm0, Address(rsp, 0)); 2885 __ addq(rsp, 8); 2886 __ ret(0); 2887 } 2888 2889 // The intrinsic version of these seem to return the same value as 2890 // the strict version. 2891 StubRoutines::_intrinsic_exp = SharedRuntime::dexp; 2892 StubRoutines::_intrinsic_pow = SharedRuntime::dpow; 2893 } 2894 2895 #undef __ 2896 #define __ masm-> 2897 2898 // Continuation point for throwing of implicit exceptions that are 2899 // not handled in the current activation. Fabricates an exception 2900 // oop and initiates normal exception dispatching in this 2901 // frame. Since we need to preserve callee-saved values (currently 2902 // only for C2, but done for C1 as well) we need a callee-saved oop 2903 // map and therefore have to make these stubs into RuntimeStubs 2904 // rather than BufferBlobs. If the compiler needs all registers to 2905 // be preserved between the fault point and the exception handler 2906 // then it must assume responsibility for that in 2907 // AbstractCompiler::continuation_for_implicit_null_exception or 2908 // continuation_for_implicit_division_by_zero_exception. All other 2909 // implicit exceptions (e.g., NullPointerException or 2910 // AbstractMethodError on entry) are either at call sites or 2911 // otherwise assume that stack unwinding will be initiated, so 2912 // caller saved registers were assumed volatile in the compiler. 2913 address generate_throw_exception(const char* name, 2914 address runtime_entry, 2915 bool restore_saved_exception_pc) { 2916 // Information about frame layout at time of blocking runtime call. 2917 // Note that we only have to preserve callee-saved registers since 2918 // the compilers are responsible for supplying a continuation point 2919 // if they expect all registers to be preserved. 2920 enum layout { 2921 rbp_off = frame::arg_reg_save_area_bytes/BytesPerInt, 2922 rbp_off2, 2923 return_off, 2924 return_off2, 2925 framesize // inclusive of return address 2926 }; 2927 2928 int insts_size = 512; 2929 int locs_size = 64; 2930 2931 CodeBuffer code(name, insts_size, locs_size); 2932 OopMapSet* oop_maps = new OopMapSet(); 2933 MacroAssembler* masm = new MacroAssembler(&code); 2934 2935 address start = __ pc(); 2936 2937 // This is an inlined and slightly modified version of call_VM 2938 // which has the ability to fetch the return PC out of 2939 // thread-local storage and also sets up last_Java_sp slightly 2940 // differently than the real call_VM 2941 if (restore_saved_exception_pc) { 2942 __ movptr(rax, 2943 Address(r15_thread, 2944 in_bytes(JavaThread::saved_exception_pc_offset()))); 2945 __ push(rax); 2946 } 2947 2948 __ enter(); // required for proper stackwalking of RuntimeStub frame 2949 2950 assert(is_even(framesize/2), "sp not 16-byte aligned"); 2951 2952 // return address and rbp are already in place 2953 __ subptr(rsp, (framesize-4) << LogBytesPerInt); // prolog 2954 2955 int frame_complete = __ pc() - start; 2956 2957 // Set up last_Java_sp and last_Java_fp 2958 __ set_last_Java_frame(rsp, rbp, NULL); 2959 2960 // Call runtime 2961 __ movptr(c_rarg0, r15_thread); 2962 BLOCK_COMMENT("call runtime_entry"); 2963 __ call(RuntimeAddress(runtime_entry)); 2964 2965 // Generate oop map 2966 OopMap* map = new OopMap(framesize, 0); 2967 2968 oop_maps->add_gc_map(__ pc() - start, map); 2969 2970 __ reset_last_Java_frame(true, false); 2971 2972 __ leave(); // required for proper stackwalking of RuntimeStub frame 2973 2974 // check for pending exceptions 2975 #ifdef ASSERT 2976 Label L; 2977 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), 2978 (int32_t) NULL_WORD); 2979 __ jcc(Assembler::notEqual, L); 2980 __ should_not_reach_here(); 2981 __ bind(L); 2982 #endif // ASSERT 2983 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry())); 2984 2985 2986 // codeBlob framesize is in words (not VMRegImpl::slot_size) 2987 RuntimeStub* stub = 2988 RuntimeStub::new_runtime_stub(name, 2989 &code, 2990 frame_complete, 2991 (framesize >> (LogBytesPerWord - LogBytesPerInt)), 2992 oop_maps, false); 2993 return stub->entry_point(); 2994 } 2995 2996 // Initialization 2997 void generate_initial() { 2998 // Generates all stubs and initializes the entry points 2999 3000 // This platform-specific stub is needed by generate_call_stub() 3001 StubRoutines::x86::_mxcsr_std = generate_fp_mask("mxcsr_std", 0x0000000000001F80); 3002 3003 // entry points that exist in all platforms Note: This is code 3004 // that could be shared among different platforms - however the 3005 // benefit seems to be smaller than the disadvantage of having a 3006 // much more complicated generator structure. See also comment in 3007 // stubRoutines.hpp. 3008 3009 StubRoutines::_forward_exception_entry = generate_forward_exception(); 3010 3011 StubRoutines::_call_stub_entry = 3012 generate_call_stub(StubRoutines::_call_stub_return_address); 3013 3014 // is referenced by megamorphic call 3015 StubRoutines::_catch_exception_entry = generate_catch_exception(); 3016 3017 // atomic calls 3018 StubRoutines::_atomic_xchg_entry = generate_atomic_xchg(); 3019 StubRoutines::_atomic_xchg_ptr_entry = generate_atomic_xchg_ptr(); 3020 StubRoutines::_atomic_cmpxchg_entry = generate_atomic_cmpxchg(); 3021 StubRoutines::_atomic_cmpxchg_long_entry = generate_atomic_cmpxchg_long(); 3022 StubRoutines::_atomic_add_entry = generate_atomic_add(); 3023 StubRoutines::_atomic_add_ptr_entry = generate_atomic_add_ptr(); 3024 StubRoutines::_fence_entry = generate_orderaccess_fence(); 3025 3026 StubRoutines::_handler_for_unsafe_access_entry = 3027 generate_handler_for_unsafe_access(); 3028 3029 // platform dependent 3030 StubRoutines::x86::_get_previous_fp_entry = generate_get_previous_fp(); 3031 3032 StubRoutines::x86::_verify_mxcsr_entry = generate_verify_mxcsr(); 3033 } 3034 3035 void generate_all() { 3036 // Generates all stubs and initializes the entry points 3037 3038 // These entry points require SharedInfo::stack0 to be set up in 3039 // non-core builds and need to be relocatable, so they each 3040 // fabricate a RuntimeStub internally. 3041 StubRoutines::_throw_AbstractMethodError_entry = 3042 generate_throw_exception("AbstractMethodError throw_exception", 3043 CAST_FROM_FN_PTR(address, 3044 SharedRuntime:: 3045 throw_AbstractMethodError), 3046 false); 3047 3048 StubRoutines::_throw_IncompatibleClassChangeError_entry = 3049 generate_throw_exception("IncompatibleClassChangeError throw_exception", 3050 CAST_FROM_FN_PTR(address, 3051 SharedRuntime:: 3052 throw_IncompatibleClassChangeError), 3053 false); 3054 3055 StubRoutines::_throw_ArithmeticException_entry = 3056 generate_throw_exception("ArithmeticException throw_exception", 3057 CAST_FROM_FN_PTR(address, 3058 SharedRuntime:: 3059 throw_ArithmeticException), 3060 true); 3061 3062 StubRoutines::_throw_NullPointerException_entry = 3063 generate_throw_exception("NullPointerException throw_exception", 3064 CAST_FROM_FN_PTR(address, 3065 SharedRuntime:: 3066 throw_NullPointerException), 3067 true); 3068 3069 StubRoutines::_throw_NullPointerException_at_call_entry = 3070 generate_throw_exception("NullPointerException at call throw_exception", 3071 CAST_FROM_FN_PTR(address, 3072 SharedRuntime:: 3073 throw_NullPointerException_at_call), 3074 false); 3075 3076 StubRoutines::_throw_StackOverflowError_entry = 3077 generate_throw_exception("StackOverflowError throw_exception", 3078 CAST_FROM_FN_PTR(address, 3079 SharedRuntime:: 3080 throw_StackOverflowError), 3081 false); 3082 3083 // entry points that are platform specific 3084 StubRoutines::x86::_f2i_fixup = generate_f2i_fixup(); 3085 StubRoutines::x86::_f2l_fixup = generate_f2l_fixup(); 3086 StubRoutines::x86::_d2i_fixup = generate_d2i_fixup(); 3087 StubRoutines::x86::_d2l_fixup = generate_d2l_fixup(); 3088 3089 StubRoutines::x86::_float_sign_mask = generate_fp_mask("float_sign_mask", 0x7FFFFFFF7FFFFFFF); 3090 StubRoutines::x86::_float_sign_flip = generate_fp_mask("float_sign_flip", 0x8000000080000000); 3091 StubRoutines::x86::_double_sign_mask = generate_fp_mask("double_sign_mask", 0x7FFFFFFFFFFFFFFF); 3092 StubRoutines::x86::_double_sign_flip = generate_fp_mask("double_sign_flip", 0x8000000000000000); 3093 3094 // support for verify_oop (must happen after universe_init) 3095 StubRoutines::_verify_oop_subroutine_entry = generate_verify_oop(); 3096 3097 // arraycopy stubs used by compilers 3098 generate_arraycopy_stubs(); 3099 3100 generate_math_stubs(); 3101 } 3102 3103 public: 3104 StubGenerator(CodeBuffer* code, bool all) : StubCodeGenerator(code) { 3105 if (all) { 3106 generate_all(); 3107 } else { 3108 generate_initial(); 3109 } 3110 } 3111 }; // end class declaration 3112 3113 void StubGenerator_generate(CodeBuffer* code, bool all) { 3114 StubGenerator g(code, all); 3115 }