src/cpu/x86/vm/stubGenerator_x86_64.cpp

Tue, 17 Oct 2017 12:58:25 +0800

author
aoqi
date
Tue, 17 Oct 2017 12:58:25 +0800
changeset 7994
04ff2f6cd0eb
parent 7816
5f8824f56f39
parent 7535
7ae4e26cb1e0
child 8604
04d83ba48607
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "asm/macroAssembler.hpp"
aoqi@0 27 #include "asm/macroAssembler.inline.hpp"
aoqi@0 28 #include "interpreter/interpreter.hpp"
aoqi@0 29 #include "nativeInst_x86.hpp"
aoqi@0 30 #include "oops/instanceOop.hpp"
aoqi@0 31 #include "oops/method.hpp"
aoqi@0 32 #include "oops/objArrayKlass.hpp"
aoqi@0 33 #include "oops/oop.inline.hpp"
aoqi@0 34 #include "prims/methodHandles.hpp"
aoqi@0 35 #include "runtime/frame.inline.hpp"
aoqi@0 36 #include "runtime/handles.inline.hpp"
aoqi@0 37 #include "runtime/sharedRuntime.hpp"
aoqi@0 38 #include "runtime/stubCodeGenerator.hpp"
aoqi@0 39 #include "runtime/stubRoutines.hpp"
aoqi@0 40 #include "runtime/thread.inline.hpp"
aoqi@0 41 #include "utilities/top.hpp"
aoqi@0 42 #ifdef COMPILER2
aoqi@0 43 #include "opto/runtime.hpp"
aoqi@0 44 #endif
aoqi@0 45
aoqi@0 46 // Declaration and definition of StubGenerator (no .hpp file).
aoqi@0 47 // For a more detailed description of the stub routine structure
aoqi@0 48 // see the comment in stubRoutines.hpp
aoqi@0 49
aoqi@0 50 #define __ _masm->
aoqi@0 51 #define TIMES_OOP (UseCompressedOops ? Address::times_4 : Address::times_8)
aoqi@0 52 #define a__ ((Assembler*)_masm)->
aoqi@0 53
aoqi@0 54 #ifdef PRODUCT
aoqi@0 55 #define BLOCK_COMMENT(str) /* nothing */
aoqi@0 56 #else
aoqi@0 57 #define BLOCK_COMMENT(str) __ block_comment(str)
aoqi@0 58 #endif
aoqi@0 59
aoqi@0 60 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
aoqi@0 61 const int MXCSR_MASK = 0xFFC0; // Mask out any pending exceptions
aoqi@0 62
aoqi@0 63 // Stub Code definitions
aoqi@0 64
aoqi@0 65 static address handle_unsafe_access() {
aoqi@0 66 JavaThread* thread = JavaThread::current();
aoqi@0 67 address pc = thread->saved_exception_pc();
aoqi@0 68 // pc is the instruction which we must emulate
aoqi@0 69 // doing a no-op is fine: return garbage from the load
aoqi@0 70 // therefore, compute npc
aoqi@0 71 address npc = Assembler::locate_next_instruction(pc);
aoqi@0 72
aoqi@0 73 // request an async exception
aoqi@0 74 thread->set_pending_unsafe_access_error();
aoqi@0 75
aoqi@0 76 // return address of next instruction to execute
aoqi@0 77 return npc;
aoqi@0 78 }
aoqi@0 79
aoqi@0 80 class StubGenerator: public StubCodeGenerator {
aoqi@0 81 private:
aoqi@0 82
aoqi@0 83 #ifdef PRODUCT
aoqi@0 84 #define inc_counter_np(counter) ((void)0)
aoqi@0 85 #else
aoqi@0 86 void inc_counter_np_(int& counter) {
aoqi@0 87 // This can destroy rscratch1 if counter is far from the code cache
aoqi@0 88 __ incrementl(ExternalAddress((address)&counter));
aoqi@0 89 }
aoqi@0 90 #define inc_counter_np(counter) \
aoqi@0 91 BLOCK_COMMENT("inc_counter " #counter); \
aoqi@0 92 inc_counter_np_(counter);
aoqi@0 93 #endif
aoqi@0 94
aoqi@0 95 // Call stubs are used to call Java from C
aoqi@0 96 //
aoqi@0 97 // Linux Arguments:
aoqi@0 98 // c_rarg0: call wrapper address address
aoqi@0 99 // c_rarg1: result address
aoqi@0 100 // c_rarg2: result type BasicType
aoqi@0 101 // c_rarg3: method Method*
aoqi@0 102 // c_rarg4: (interpreter) entry point address
aoqi@0 103 // c_rarg5: parameters intptr_t*
aoqi@0 104 // 16(rbp): parameter size (in words) int
aoqi@0 105 // 24(rbp): thread Thread*
aoqi@0 106 //
aoqi@0 107 // [ return_from_Java ] <--- rsp
aoqi@0 108 // [ argument word n ]
aoqi@0 109 // ...
aoqi@0 110 // -12 [ argument word 1 ]
aoqi@0 111 // -11 [ saved r15 ] <--- rsp_after_call
aoqi@0 112 // -10 [ saved r14 ]
aoqi@0 113 // -9 [ saved r13 ]
aoqi@0 114 // -8 [ saved r12 ]
aoqi@0 115 // -7 [ saved rbx ]
aoqi@0 116 // -6 [ call wrapper ]
aoqi@0 117 // -5 [ result ]
aoqi@0 118 // -4 [ result type ]
aoqi@0 119 // -3 [ method ]
aoqi@0 120 // -2 [ entry point ]
aoqi@0 121 // -1 [ parameters ]
aoqi@0 122 // 0 [ saved rbp ] <--- rbp
aoqi@0 123 // 1 [ return address ]
aoqi@0 124 // 2 [ parameter size ]
aoqi@0 125 // 3 [ thread ]
aoqi@0 126 //
aoqi@0 127 // Windows Arguments:
aoqi@0 128 // c_rarg0: call wrapper address address
aoqi@0 129 // c_rarg1: result address
aoqi@0 130 // c_rarg2: result type BasicType
aoqi@0 131 // c_rarg3: method Method*
aoqi@0 132 // 48(rbp): (interpreter) entry point address
aoqi@0 133 // 56(rbp): parameters intptr_t*
aoqi@0 134 // 64(rbp): parameter size (in words) int
aoqi@0 135 // 72(rbp): thread Thread*
aoqi@0 136 //
aoqi@0 137 // [ return_from_Java ] <--- rsp
aoqi@0 138 // [ argument word n ]
aoqi@0 139 // ...
aoqi@0 140 // -28 [ argument word 1 ]
aoqi@0 141 // -27 [ saved xmm15 ] <--- rsp_after_call
aoqi@0 142 // [ saved xmm7-xmm14 ]
aoqi@0 143 // -9 [ saved xmm6 ] (each xmm register takes 2 slots)
aoqi@0 144 // -7 [ saved r15 ]
aoqi@0 145 // -6 [ saved r14 ]
aoqi@0 146 // -5 [ saved r13 ]
aoqi@0 147 // -4 [ saved r12 ]
aoqi@0 148 // -3 [ saved rdi ]
aoqi@0 149 // -2 [ saved rsi ]
aoqi@0 150 // -1 [ saved rbx ]
aoqi@0 151 // 0 [ saved rbp ] <--- rbp
aoqi@0 152 // 1 [ return address ]
aoqi@0 153 // 2 [ call wrapper ]
aoqi@0 154 // 3 [ result ]
aoqi@0 155 // 4 [ result type ]
aoqi@0 156 // 5 [ method ]
aoqi@0 157 // 6 [ entry point ]
aoqi@0 158 // 7 [ parameters ]
aoqi@0 159 // 8 [ parameter size ]
aoqi@0 160 // 9 [ thread ]
aoqi@0 161 //
aoqi@0 162 // Windows reserves the callers stack space for arguments 1-4.
aoqi@0 163 // We spill c_rarg0-c_rarg3 to this space.
aoqi@0 164
aoqi@0 165 // Call stub stack layout word offsets from rbp
aoqi@0 166 enum call_stub_layout {
aoqi@0 167 #ifdef _WIN64
aoqi@0 168 xmm_save_first = 6, // save from xmm6
aoqi@0 169 xmm_save_last = 15, // to xmm15
aoqi@0 170 xmm_save_base = -9,
aoqi@0 171 rsp_after_call_off = xmm_save_base - 2 * (xmm_save_last - xmm_save_first), // -27
aoqi@0 172 r15_off = -7,
aoqi@0 173 r14_off = -6,
aoqi@0 174 r13_off = -5,
aoqi@0 175 r12_off = -4,
aoqi@0 176 rdi_off = -3,
aoqi@0 177 rsi_off = -2,
aoqi@0 178 rbx_off = -1,
aoqi@0 179 rbp_off = 0,
aoqi@0 180 retaddr_off = 1,
aoqi@0 181 call_wrapper_off = 2,
aoqi@0 182 result_off = 3,
aoqi@0 183 result_type_off = 4,
aoqi@0 184 method_off = 5,
aoqi@0 185 entry_point_off = 6,
aoqi@0 186 parameters_off = 7,
aoqi@0 187 parameter_size_off = 8,
aoqi@0 188 thread_off = 9
aoqi@0 189 #else
aoqi@0 190 rsp_after_call_off = -12,
aoqi@0 191 mxcsr_off = rsp_after_call_off,
aoqi@0 192 r15_off = -11,
aoqi@0 193 r14_off = -10,
aoqi@0 194 r13_off = -9,
aoqi@0 195 r12_off = -8,
aoqi@0 196 rbx_off = -7,
aoqi@0 197 call_wrapper_off = -6,
aoqi@0 198 result_off = -5,
aoqi@0 199 result_type_off = -4,
aoqi@0 200 method_off = -3,
aoqi@0 201 entry_point_off = -2,
aoqi@0 202 parameters_off = -1,
aoqi@0 203 rbp_off = 0,
aoqi@0 204 retaddr_off = 1,
aoqi@0 205 parameter_size_off = 2,
aoqi@0 206 thread_off = 3
aoqi@0 207 #endif
aoqi@0 208 };
aoqi@0 209
aoqi@0 210 #ifdef _WIN64
aoqi@0 211 Address xmm_save(int reg) {
aoqi@0 212 assert(reg >= xmm_save_first && reg <= xmm_save_last, "XMM register number out of range");
aoqi@0 213 return Address(rbp, (xmm_save_base - (reg - xmm_save_first) * 2) * wordSize);
aoqi@0 214 }
aoqi@0 215 #endif
aoqi@0 216
aoqi@0 217 address generate_call_stub(address& return_address) {
aoqi@0 218 assert((int)frame::entry_frame_after_call_words == -(int)rsp_after_call_off + 1 &&
aoqi@0 219 (int)frame::entry_frame_call_wrapper_offset == (int)call_wrapper_off,
aoqi@0 220 "adjust this code");
aoqi@0 221 StubCodeMark mark(this, "StubRoutines", "call_stub");
aoqi@0 222 address start = __ pc();
aoqi@0 223
aoqi@0 224 // same as in generate_catch_exception()!
aoqi@0 225 const Address rsp_after_call(rbp, rsp_after_call_off * wordSize);
aoqi@0 226
aoqi@0 227 const Address call_wrapper (rbp, call_wrapper_off * wordSize);
aoqi@0 228 const Address result (rbp, result_off * wordSize);
aoqi@0 229 const Address result_type (rbp, result_type_off * wordSize);
aoqi@0 230 const Address method (rbp, method_off * wordSize);
aoqi@0 231 const Address entry_point (rbp, entry_point_off * wordSize);
aoqi@0 232 const Address parameters (rbp, parameters_off * wordSize);
aoqi@0 233 const Address parameter_size(rbp, parameter_size_off * wordSize);
aoqi@0 234
aoqi@0 235 // same as in generate_catch_exception()!
aoqi@0 236 const Address thread (rbp, thread_off * wordSize);
aoqi@0 237
aoqi@0 238 const Address r15_save(rbp, r15_off * wordSize);
aoqi@0 239 const Address r14_save(rbp, r14_off * wordSize);
aoqi@0 240 const Address r13_save(rbp, r13_off * wordSize);
aoqi@0 241 const Address r12_save(rbp, r12_off * wordSize);
aoqi@0 242 const Address rbx_save(rbp, rbx_off * wordSize);
aoqi@0 243
aoqi@0 244 // stub code
aoqi@0 245 __ enter();
aoqi@0 246 __ subptr(rsp, -rsp_after_call_off * wordSize);
aoqi@0 247
aoqi@0 248 // save register parameters
aoqi@0 249 #ifndef _WIN64
aoqi@0 250 __ movptr(parameters, c_rarg5); // parameters
aoqi@0 251 __ movptr(entry_point, c_rarg4); // entry_point
aoqi@0 252 #endif
aoqi@0 253
aoqi@0 254 __ movptr(method, c_rarg3); // method
aoqi@0 255 __ movl(result_type, c_rarg2); // result type
aoqi@0 256 __ movptr(result, c_rarg1); // result
aoqi@0 257 __ movptr(call_wrapper, c_rarg0); // call wrapper
aoqi@0 258
aoqi@0 259 // save regs belonging to calling function
aoqi@0 260 __ movptr(rbx_save, rbx);
aoqi@0 261 __ movptr(r12_save, r12);
aoqi@0 262 __ movptr(r13_save, r13);
aoqi@0 263 __ movptr(r14_save, r14);
aoqi@0 264 __ movptr(r15_save, r15);
aoqi@0 265 #ifdef _WIN64
aoqi@0 266 for (int i = 6; i <= 15; i++) {
aoqi@0 267 __ movdqu(xmm_save(i), as_XMMRegister(i));
aoqi@0 268 }
aoqi@0 269
aoqi@0 270 const Address rdi_save(rbp, rdi_off * wordSize);
aoqi@0 271 const Address rsi_save(rbp, rsi_off * wordSize);
aoqi@0 272
aoqi@0 273 __ movptr(rsi_save, rsi);
aoqi@0 274 __ movptr(rdi_save, rdi);
aoqi@0 275 #else
aoqi@0 276 const Address mxcsr_save(rbp, mxcsr_off * wordSize);
aoqi@0 277 {
aoqi@0 278 Label skip_ldmx;
aoqi@0 279 __ stmxcsr(mxcsr_save);
aoqi@0 280 __ movl(rax, mxcsr_save);
aoqi@0 281 __ andl(rax, MXCSR_MASK); // Only check control and mask bits
aoqi@0 282 ExternalAddress mxcsr_std(StubRoutines::addr_mxcsr_std());
aoqi@0 283 __ cmp32(rax, mxcsr_std);
aoqi@0 284 __ jcc(Assembler::equal, skip_ldmx);
aoqi@0 285 __ ldmxcsr(mxcsr_std);
aoqi@0 286 __ bind(skip_ldmx);
aoqi@0 287 }
aoqi@0 288 #endif
aoqi@0 289
aoqi@0 290 // Load up thread register
aoqi@0 291 __ movptr(r15_thread, thread);
aoqi@0 292 __ reinit_heapbase();
aoqi@0 293
aoqi@0 294 #ifdef ASSERT
aoqi@0 295 // make sure we have no pending exceptions
aoqi@0 296 {
aoqi@0 297 Label L;
aoqi@0 298 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
aoqi@0 299 __ jcc(Assembler::equal, L);
aoqi@0 300 __ stop("StubRoutines::call_stub: entered with pending exception");
aoqi@0 301 __ bind(L);
aoqi@0 302 }
aoqi@0 303 #endif
aoqi@0 304
aoqi@0 305 // pass parameters if any
aoqi@0 306 BLOCK_COMMENT("pass parameters if any");
aoqi@0 307 Label parameters_done;
aoqi@0 308 __ movl(c_rarg3, parameter_size);
aoqi@0 309 __ testl(c_rarg3, c_rarg3);
aoqi@0 310 __ jcc(Assembler::zero, parameters_done);
aoqi@0 311
aoqi@0 312 Label loop;
aoqi@0 313 __ movptr(c_rarg2, parameters); // parameter pointer
aoqi@0 314 __ movl(c_rarg1, c_rarg3); // parameter counter is in c_rarg1
aoqi@0 315 __ BIND(loop);
aoqi@0 316 __ movptr(rax, Address(c_rarg2, 0));// get parameter
aoqi@0 317 __ addptr(c_rarg2, wordSize); // advance to next parameter
aoqi@0 318 __ decrementl(c_rarg1); // decrement counter
aoqi@0 319 __ push(rax); // pass parameter
aoqi@0 320 __ jcc(Assembler::notZero, loop);
aoqi@0 321
aoqi@0 322 // call Java function
aoqi@0 323 __ BIND(parameters_done);
aoqi@0 324 __ movptr(rbx, method); // get Method*
aoqi@0 325 __ movptr(c_rarg1, entry_point); // get entry_point
aoqi@0 326 __ mov(r13, rsp); // set sender sp
aoqi@0 327 BLOCK_COMMENT("call Java function");
aoqi@0 328 __ call(c_rarg1);
aoqi@0 329
aoqi@0 330 BLOCK_COMMENT("call_stub_return_address:");
aoqi@0 331 return_address = __ pc();
aoqi@0 332
aoqi@0 333 // store result depending on type (everything that is not
aoqi@0 334 // T_OBJECT, T_LONG, T_FLOAT or T_DOUBLE is treated as T_INT)
aoqi@0 335 __ movptr(c_rarg0, result);
aoqi@0 336 Label is_long, is_float, is_double, exit;
aoqi@0 337 __ movl(c_rarg1, result_type);
aoqi@0 338 __ cmpl(c_rarg1, T_OBJECT);
aoqi@0 339 __ jcc(Assembler::equal, is_long);
aoqi@0 340 __ cmpl(c_rarg1, T_LONG);
aoqi@0 341 __ jcc(Assembler::equal, is_long);
aoqi@0 342 __ cmpl(c_rarg1, T_FLOAT);
aoqi@0 343 __ jcc(Assembler::equal, is_float);
aoqi@0 344 __ cmpl(c_rarg1, T_DOUBLE);
aoqi@0 345 __ jcc(Assembler::equal, is_double);
aoqi@0 346
aoqi@0 347 // handle T_INT case
aoqi@0 348 __ movl(Address(c_rarg0, 0), rax);
aoqi@0 349
aoqi@0 350 __ BIND(exit);
aoqi@0 351
aoqi@0 352 // pop parameters
aoqi@0 353 __ lea(rsp, rsp_after_call);
aoqi@0 354
aoqi@0 355 #ifdef ASSERT
aoqi@0 356 // verify that threads correspond
aoqi@0 357 {
aoqi@0 358 Label L, S;
aoqi@0 359 __ cmpptr(r15_thread, thread);
aoqi@0 360 __ jcc(Assembler::notEqual, S);
aoqi@0 361 __ get_thread(rbx);
aoqi@0 362 __ cmpptr(r15_thread, rbx);
aoqi@0 363 __ jcc(Assembler::equal, L);
aoqi@0 364 __ bind(S);
aoqi@0 365 __ jcc(Assembler::equal, L);
aoqi@0 366 __ stop("StubRoutines::call_stub: threads must correspond");
aoqi@0 367 __ bind(L);
aoqi@0 368 }
aoqi@0 369 #endif
aoqi@0 370
aoqi@0 371 // restore regs belonging to calling function
aoqi@0 372 #ifdef _WIN64
aoqi@0 373 for (int i = 15; i >= 6; i--) {
aoqi@0 374 __ movdqu(as_XMMRegister(i), xmm_save(i));
aoqi@0 375 }
aoqi@0 376 #endif
aoqi@0 377 __ movptr(r15, r15_save);
aoqi@0 378 __ movptr(r14, r14_save);
aoqi@0 379 __ movptr(r13, r13_save);
aoqi@0 380 __ movptr(r12, r12_save);
aoqi@0 381 __ movptr(rbx, rbx_save);
aoqi@0 382
aoqi@0 383 #ifdef _WIN64
aoqi@0 384 __ movptr(rdi, rdi_save);
aoqi@0 385 __ movptr(rsi, rsi_save);
aoqi@0 386 #else
aoqi@0 387 __ ldmxcsr(mxcsr_save);
aoqi@0 388 #endif
aoqi@0 389
aoqi@0 390 // restore rsp
aoqi@0 391 __ addptr(rsp, -rsp_after_call_off * wordSize);
aoqi@0 392
aoqi@0 393 // return
aoqi@0 394 __ pop(rbp);
aoqi@0 395 __ ret(0);
aoqi@0 396
aoqi@0 397 // handle return types different from T_INT
aoqi@0 398 __ BIND(is_long);
aoqi@0 399 __ movq(Address(c_rarg0, 0), rax);
aoqi@0 400 __ jmp(exit);
aoqi@0 401
aoqi@0 402 __ BIND(is_float);
aoqi@0 403 __ movflt(Address(c_rarg0, 0), xmm0);
aoqi@0 404 __ jmp(exit);
aoqi@0 405
aoqi@0 406 __ BIND(is_double);
aoqi@0 407 __ movdbl(Address(c_rarg0, 0), xmm0);
aoqi@0 408 __ jmp(exit);
aoqi@0 409
aoqi@0 410 return start;
aoqi@0 411 }
aoqi@0 412
aoqi@0 413 // Return point for a Java call if there's an exception thrown in
aoqi@0 414 // Java code. The exception is caught and transformed into a
aoqi@0 415 // pending exception stored in JavaThread that can be tested from
aoqi@0 416 // within the VM.
aoqi@0 417 //
aoqi@0 418 // Note: Usually the parameters are removed by the callee. In case
aoqi@0 419 // of an exception crossing an activation frame boundary, that is
aoqi@0 420 // not the case if the callee is compiled code => need to setup the
aoqi@0 421 // rsp.
aoqi@0 422 //
aoqi@0 423 // rax: exception oop
aoqi@0 424
aoqi@0 425 address generate_catch_exception() {
aoqi@0 426 StubCodeMark mark(this, "StubRoutines", "catch_exception");
aoqi@0 427 address start = __ pc();
aoqi@0 428
aoqi@0 429 // same as in generate_call_stub():
aoqi@0 430 const Address rsp_after_call(rbp, rsp_after_call_off * wordSize);
aoqi@0 431 const Address thread (rbp, thread_off * wordSize);
aoqi@0 432
aoqi@0 433 #ifdef ASSERT
aoqi@0 434 // verify that threads correspond
aoqi@0 435 {
aoqi@0 436 Label L, S;
aoqi@0 437 __ cmpptr(r15_thread, thread);
aoqi@0 438 __ jcc(Assembler::notEqual, S);
aoqi@0 439 __ get_thread(rbx);
aoqi@0 440 __ cmpptr(r15_thread, rbx);
aoqi@0 441 __ jcc(Assembler::equal, L);
aoqi@0 442 __ bind(S);
aoqi@0 443 __ stop("StubRoutines::catch_exception: threads must correspond");
aoqi@0 444 __ bind(L);
aoqi@0 445 }
aoqi@0 446 #endif
aoqi@0 447
aoqi@0 448 // set pending exception
aoqi@0 449 __ verify_oop(rax);
aoqi@0 450
aoqi@0 451 __ movptr(Address(r15_thread, Thread::pending_exception_offset()), rax);
aoqi@0 452 __ lea(rscratch1, ExternalAddress((address)__FILE__));
aoqi@0 453 __ movptr(Address(r15_thread, Thread::exception_file_offset()), rscratch1);
aoqi@0 454 __ movl(Address(r15_thread, Thread::exception_line_offset()), (int) __LINE__);
aoqi@0 455
aoqi@0 456 // complete return to VM
aoqi@0 457 assert(StubRoutines::_call_stub_return_address != NULL,
aoqi@0 458 "_call_stub_return_address must have been generated before");
aoqi@0 459 __ jump(RuntimeAddress(StubRoutines::_call_stub_return_address));
aoqi@0 460
aoqi@0 461 return start;
aoqi@0 462 }
aoqi@0 463
aoqi@0 464 // Continuation point for runtime calls returning with a pending
aoqi@0 465 // exception. The pending exception check happened in the runtime
aoqi@0 466 // or native call stub. The pending exception in Thread is
aoqi@0 467 // converted into a Java-level exception.
aoqi@0 468 //
aoqi@0 469 // Contract with Java-level exception handlers:
aoqi@0 470 // rax: exception
aoqi@0 471 // rdx: throwing pc
aoqi@0 472 //
aoqi@0 473 // NOTE: At entry of this stub, exception-pc must be on stack !!
aoqi@0 474
aoqi@0 475 address generate_forward_exception() {
aoqi@0 476 StubCodeMark mark(this, "StubRoutines", "forward exception");
aoqi@0 477 address start = __ pc();
aoqi@0 478
aoqi@0 479 // Upon entry, the sp points to the return address returning into
aoqi@0 480 // Java (interpreted or compiled) code; i.e., the return address
aoqi@0 481 // becomes the throwing pc.
aoqi@0 482 //
aoqi@0 483 // Arguments pushed before the runtime call are still on the stack
aoqi@0 484 // but the exception handler will reset the stack pointer ->
aoqi@0 485 // ignore them. A potential result in registers can be ignored as
aoqi@0 486 // well.
aoqi@0 487
aoqi@0 488 #ifdef ASSERT
aoqi@0 489 // make sure this code is only executed if there is a pending exception
aoqi@0 490 {
aoqi@0 491 Label L;
aoqi@0 492 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t) NULL);
aoqi@0 493 __ jcc(Assembler::notEqual, L);
aoqi@0 494 __ stop("StubRoutines::forward exception: no pending exception (1)");
aoqi@0 495 __ bind(L);
aoqi@0 496 }
aoqi@0 497 #endif
aoqi@0 498
aoqi@0 499 // compute exception handler into rbx
aoqi@0 500 __ movptr(c_rarg0, Address(rsp, 0));
aoqi@0 501 BLOCK_COMMENT("call exception_handler_for_return_address");
aoqi@0 502 __ call_VM_leaf(CAST_FROM_FN_PTR(address,
aoqi@0 503 SharedRuntime::exception_handler_for_return_address),
aoqi@0 504 r15_thread, c_rarg0);
aoqi@0 505 __ mov(rbx, rax);
aoqi@0 506
aoqi@0 507 // setup rax & rdx, remove return address & clear pending exception
aoqi@0 508 __ pop(rdx);
aoqi@0 509 __ movptr(rax, Address(r15_thread, Thread::pending_exception_offset()));
aoqi@0 510 __ movptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
aoqi@0 511
aoqi@0 512 #ifdef ASSERT
aoqi@0 513 // make sure exception is set
aoqi@0 514 {
aoqi@0 515 Label L;
aoqi@0 516 __ testptr(rax, rax);
aoqi@0 517 __ jcc(Assembler::notEqual, L);
aoqi@0 518 __ stop("StubRoutines::forward exception: no pending exception (2)");
aoqi@0 519 __ bind(L);
aoqi@0 520 }
aoqi@0 521 #endif
aoqi@0 522
aoqi@0 523 // continue at exception handler (return address removed)
aoqi@0 524 // rax: exception
aoqi@0 525 // rbx: exception handler
aoqi@0 526 // rdx: throwing pc
aoqi@0 527 __ verify_oop(rax);
aoqi@0 528 __ jmp(rbx);
aoqi@0 529
aoqi@0 530 return start;
aoqi@0 531 }
aoqi@0 532
aoqi@0 533 // Support for jint atomic::xchg(jint exchange_value, volatile jint* dest)
aoqi@0 534 //
aoqi@0 535 // Arguments :
aoqi@0 536 // c_rarg0: exchange_value
aoqi@0 537 // c_rarg0: dest
aoqi@0 538 //
aoqi@0 539 // Result:
aoqi@0 540 // *dest <- ex, return (orig *dest)
aoqi@0 541 address generate_atomic_xchg() {
aoqi@0 542 StubCodeMark mark(this, "StubRoutines", "atomic_xchg");
aoqi@0 543 address start = __ pc();
aoqi@0 544
aoqi@0 545 __ movl(rax, c_rarg0); // Copy to eax we need a return value anyhow
aoqi@0 546 __ xchgl(rax, Address(c_rarg1, 0)); // automatic LOCK
aoqi@0 547 __ ret(0);
aoqi@0 548
aoqi@0 549 return start;
aoqi@0 550 }
aoqi@0 551
aoqi@0 552 // Support for intptr_t atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest)
aoqi@0 553 //
aoqi@0 554 // Arguments :
aoqi@0 555 // c_rarg0: exchange_value
aoqi@0 556 // c_rarg1: dest
aoqi@0 557 //
aoqi@0 558 // Result:
aoqi@0 559 // *dest <- ex, return (orig *dest)
aoqi@0 560 address generate_atomic_xchg_ptr() {
aoqi@0 561 StubCodeMark mark(this, "StubRoutines", "atomic_xchg_ptr");
aoqi@0 562 address start = __ pc();
aoqi@0 563
aoqi@0 564 __ movptr(rax, c_rarg0); // Copy to eax we need a return value anyhow
aoqi@0 565 __ xchgptr(rax, Address(c_rarg1, 0)); // automatic LOCK
aoqi@0 566 __ ret(0);
aoqi@0 567
aoqi@0 568 return start;
aoqi@0 569 }
aoqi@0 570
aoqi@0 571 // Support for jint atomic::atomic_cmpxchg(jint exchange_value, volatile jint* dest,
aoqi@0 572 // jint compare_value)
aoqi@0 573 //
aoqi@0 574 // Arguments :
aoqi@0 575 // c_rarg0: exchange_value
aoqi@0 576 // c_rarg1: dest
aoqi@0 577 // c_rarg2: compare_value
aoqi@0 578 //
aoqi@0 579 // Result:
aoqi@0 580 // if ( compare_value == *dest ) {
aoqi@0 581 // *dest = exchange_value
aoqi@0 582 // return compare_value;
aoqi@0 583 // else
aoqi@0 584 // return *dest;
aoqi@0 585 address generate_atomic_cmpxchg() {
aoqi@0 586 StubCodeMark mark(this, "StubRoutines", "atomic_cmpxchg");
aoqi@0 587 address start = __ pc();
aoqi@0 588
aoqi@0 589 __ movl(rax, c_rarg2);
aoqi@0 590 if ( os::is_MP() ) __ lock();
aoqi@0 591 __ cmpxchgl(c_rarg0, Address(c_rarg1, 0));
aoqi@0 592 __ ret(0);
aoqi@0 593
aoqi@0 594 return start;
aoqi@0 595 }
aoqi@0 596
aoqi@0 597 // Support for jint atomic::atomic_cmpxchg_long(jlong exchange_value,
aoqi@0 598 // volatile jlong* dest,
aoqi@0 599 // jlong compare_value)
aoqi@0 600 // Arguments :
aoqi@0 601 // c_rarg0: exchange_value
aoqi@0 602 // c_rarg1: dest
aoqi@0 603 // c_rarg2: compare_value
aoqi@0 604 //
aoqi@0 605 // Result:
aoqi@0 606 // if ( compare_value == *dest ) {
aoqi@0 607 // *dest = exchange_value
aoqi@0 608 // return compare_value;
aoqi@0 609 // else
aoqi@0 610 // return *dest;
aoqi@0 611 address generate_atomic_cmpxchg_long() {
aoqi@0 612 StubCodeMark mark(this, "StubRoutines", "atomic_cmpxchg_long");
aoqi@0 613 address start = __ pc();
aoqi@0 614
aoqi@0 615 __ movq(rax, c_rarg2);
aoqi@0 616 if ( os::is_MP() ) __ lock();
aoqi@0 617 __ cmpxchgq(c_rarg0, Address(c_rarg1, 0));
aoqi@0 618 __ ret(0);
aoqi@0 619
aoqi@0 620 return start;
aoqi@0 621 }
aoqi@0 622
aoqi@0 623 // Support for jint atomic::add(jint add_value, volatile jint* dest)
aoqi@0 624 //
aoqi@0 625 // Arguments :
aoqi@0 626 // c_rarg0: add_value
aoqi@0 627 // c_rarg1: dest
aoqi@0 628 //
aoqi@0 629 // Result:
aoqi@0 630 // *dest += add_value
aoqi@0 631 // return *dest;
aoqi@0 632 address generate_atomic_add() {
aoqi@0 633 StubCodeMark mark(this, "StubRoutines", "atomic_add");
aoqi@0 634 address start = __ pc();
aoqi@0 635
aoqi@0 636 __ movl(rax, c_rarg0);
aoqi@0 637 if ( os::is_MP() ) __ lock();
aoqi@0 638 __ xaddl(Address(c_rarg1, 0), c_rarg0);
aoqi@0 639 __ addl(rax, c_rarg0);
aoqi@0 640 __ ret(0);
aoqi@0 641
aoqi@0 642 return start;
aoqi@0 643 }
aoqi@0 644
aoqi@0 645 // Support for intptr_t atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest)
aoqi@0 646 //
aoqi@0 647 // Arguments :
aoqi@0 648 // c_rarg0: add_value
aoqi@0 649 // c_rarg1: dest
aoqi@0 650 //
aoqi@0 651 // Result:
aoqi@0 652 // *dest += add_value
aoqi@0 653 // return *dest;
aoqi@0 654 address generate_atomic_add_ptr() {
aoqi@0 655 StubCodeMark mark(this, "StubRoutines", "atomic_add_ptr");
aoqi@0 656 address start = __ pc();
aoqi@0 657
aoqi@0 658 __ movptr(rax, c_rarg0); // Copy to eax we need a return value anyhow
aoqi@0 659 if ( os::is_MP() ) __ lock();
aoqi@0 660 __ xaddptr(Address(c_rarg1, 0), c_rarg0);
aoqi@0 661 __ addptr(rax, c_rarg0);
aoqi@0 662 __ ret(0);
aoqi@0 663
aoqi@0 664 return start;
aoqi@0 665 }
aoqi@0 666
aoqi@0 667 // Support for intptr_t OrderAccess::fence()
aoqi@0 668 //
aoqi@0 669 // Arguments :
aoqi@0 670 //
aoqi@0 671 // Result:
aoqi@0 672 address generate_orderaccess_fence() {
aoqi@0 673 StubCodeMark mark(this, "StubRoutines", "orderaccess_fence");
aoqi@0 674 address start = __ pc();
aoqi@0 675 __ membar(Assembler::StoreLoad);
aoqi@0 676 __ ret(0);
aoqi@0 677
aoqi@0 678 return start;
aoqi@0 679 }
aoqi@0 680
aoqi@0 681 // Support for intptr_t get_previous_fp()
aoqi@0 682 //
aoqi@0 683 // This routine is used to find the previous frame pointer for the
aoqi@0 684 // caller (current_frame_guess). This is used as part of debugging
aoqi@0 685 // ps() is seemingly lost trying to find frames.
aoqi@0 686 // This code assumes that caller current_frame_guess) has a frame.
aoqi@0 687 address generate_get_previous_fp() {
aoqi@0 688 StubCodeMark mark(this, "StubRoutines", "get_previous_fp");
aoqi@0 689 const Address old_fp(rbp, 0);
aoqi@0 690 const Address older_fp(rax, 0);
aoqi@0 691 address start = __ pc();
aoqi@0 692
aoqi@0 693 __ enter();
aoqi@0 694 __ movptr(rax, old_fp); // callers fp
aoqi@0 695 __ movptr(rax, older_fp); // the frame for ps()
aoqi@0 696 __ pop(rbp);
aoqi@0 697 __ ret(0);
aoqi@0 698
aoqi@0 699 return start;
aoqi@0 700 }
aoqi@0 701
aoqi@0 702 // Support for intptr_t get_previous_sp()
aoqi@0 703 //
aoqi@0 704 // This routine is used to find the previous stack pointer for the
aoqi@0 705 // caller.
aoqi@0 706 address generate_get_previous_sp() {
aoqi@0 707 StubCodeMark mark(this, "StubRoutines", "get_previous_sp");
aoqi@0 708 address start = __ pc();
aoqi@0 709
aoqi@0 710 __ movptr(rax, rsp);
aoqi@0 711 __ addptr(rax, 8); // return address is at the top of the stack.
aoqi@0 712 __ ret(0);
aoqi@0 713
aoqi@0 714 return start;
aoqi@0 715 }
aoqi@0 716
aoqi@0 717 //----------------------------------------------------------------------------------------------------
aoqi@0 718 // Support for void verify_mxcsr()
aoqi@0 719 //
aoqi@0 720 // This routine is used with -Xcheck:jni to verify that native
aoqi@0 721 // JNI code does not return to Java code without restoring the
aoqi@0 722 // MXCSR register to our expected state.
aoqi@0 723
aoqi@0 724 address generate_verify_mxcsr() {
aoqi@0 725 StubCodeMark mark(this, "StubRoutines", "verify_mxcsr");
aoqi@0 726 address start = __ pc();
aoqi@0 727
aoqi@0 728 const Address mxcsr_save(rsp, 0);
aoqi@0 729
aoqi@0 730 if (CheckJNICalls) {
aoqi@0 731 Label ok_ret;
aoqi@0 732 ExternalAddress mxcsr_std(StubRoutines::addr_mxcsr_std());
aoqi@0 733 __ push(rax);
aoqi@0 734 __ subptr(rsp, wordSize); // allocate a temp location
aoqi@0 735 __ stmxcsr(mxcsr_save);
aoqi@0 736 __ movl(rax, mxcsr_save);
aoqi@0 737 __ andl(rax, MXCSR_MASK); // Only check control and mask bits
aoqi@0 738 __ cmp32(rax, mxcsr_std);
aoqi@0 739 __ jcc(Assembler::equal, ok_ret);
aoqi@0 740
aoqi@0 741 __ warn("MXCSR changed by native JNI code, use -XX:+RestoreMXCSROnJNICall");
aoqi@0 742
aoqi@0 743 __ ldmxcsr(mxcsr_std);
aoqi@0 744
aoqi@0 745 __ bind(ok_ret);
aoqi@0 746 __ addptr(rsp, wordSize);
aoqi@0 747 __ pop(rax);
aoqi@0 748 }
aoqi@0 749
aoqi@0 750 __ ret(0);
aoqi@0 751
aoqi@0 752 return start;
aoqi@0 753 }
aoqi@0 754
aoqi@0 755 address generate_f2i_fixup() {
aoqi@0 756 StubCodeMark mark(this, "StubRoutines", "f2i_fixup");
aoqi@0 757 Address inout(rsp, 5 * wordSize); // return address + 4 saves
aoqi@0 758
aoqi@0 759 address start = __ pc();
aoqi@0 760
aoqi@0 761 Label L;
aoqi@0 762
aoqi@0 763 __ push(rax);
aoqi@0 764 __ push(c_rarg3);
aoqi@0 765 __ push(c_rarg2);
aoqi@0 766 __ push(c_rarg1);
aoqi@0 767
aoqi@0 768 __ movl(rax, 0x7f800000);
aoqi@0 769 __ xorl(c_rarg3, c_rarg3);
aoqi@0 770 __ movl(c_rarg2, inout);
aoqi@0 771 __ movl(c_rarg1, c_rarg2);
aoqi@0 772 __ andl(c_rarg1, 0x7fffffff);
aoqi@0 773 __ cmpl(rax, c_rarg1); // NaN? -> 0
aoqi@0 774 __ jcc(Assembler::negative, L);
aoqi@0 775 __ testl(c_rarg2, c_rarg2); // signed ? min_jint : max_jint
aoqi@0 776 __ movl(c_rarg3, 0x80000000);
aoqi@0 777 __ movl(rax, 0x7fffffff);
aoqi@0 778 __ cmovl(Assembler::positive, c_rarg3, rax);
aoqi@0 779
aoqi@0 780 __ bind(L);
aoqi@0 781 __ movptr(inout, c_rarg3);
aoqi@0 782
aoqi@0 783 __ pop(c_rarg1);
aoqi@0 784 __ pop(c_rarg2);
aoqi@0 785 __ pop(c_rarg3);
aoqi@0 786 __ pop(rax);
aoqi@0 787
aoqi@0 788 __ ret(0);
aoqi@0 789
aoqi@0 790 return start;
aoqi@0 791 }
aoqi@0 792
aoqi@0 793 address generate_f2l_fixup() {
aoqi@0 794 StubCodeMark mark(this, "StubRoutines", "f2l_fixup");
aoqi@0 795 Address inout(rsp, 5 * wordSize); // return address + 4 saves
aoqi@0 796 address start = __ pc();
aoqi@0 797
aoqi@0 798 Label L;
aoqi@0 799
aoqi@0 800 __ push(rax);
aoqi@0 801 __ push(c_rarg3);
aoqi@0 802 __ push(c_rarg2);
aoqi@0 803 __ push(c_rarg1);
aoqi@0 804
aoqi@0 805 __ movl(rax, 0x7f800000);
aoqi@0 806 __ xorl(c_rarg3, c_rarg3);
aoqi@0 807 __ movl(c_rarg2, inout);
aoqi@0 808 __ movl(c_rarg1, c_rarg2);
aoqi@0 809 __ andl(c_rarg1, 0x7fffffff);
aoqi@0 810 __ cmpl(rax, c_rarg1); // NaN? -> 0
aoqi@0 811 __ jcc(Assembler::negative, L);
aoqi@0 812 __ testl(c_rarg2, c_rarg2); // signed ? min_jlong : max_jlong
aoqi@0 813 __ mov64(c_rarg3, 0x8000000000000000);
aoqi@0 814 __ mov64(rax, 0x7fffffffffffffff);
aoqi@0 815 __ cmov(Assembler::positive, c_rarg3, rax);
aoqi@0 816
aoqi@0 817 __ bind(L);
aoqi@0 818 __ movptr(inout, c_rarg3);
aoqi@0 819
aoqi@0 820 __ pop(c_rarg1);
aoqi@0 821 __ pop(c_rarg2);
aoqi@0 822 __ pop(c_rarg3);
aoqi@0 823 __ pop(rax);
aoqi@0 824
aoqi@0 825 __ ret(0);
aoqi@0 826
aoqi@0 827 return start;
aoqi@0 828 }
aoqi@0 829
aoqi@0 830 address generate_d2i_fixup() {
aoqi@0 831 StubCodeMark mark(this, "StubRoutines", "d2i_fixup");
aoqi@0 832 Address inout(rsp, 6 * wordSize); // return address + 5 saves
aoqi@0 833
aoqi@0 834 address start = __ pc();
aoqi@0 835
aoqi@0 836 Label L;
aoqi@0 837
aoqi@0 838 __ push(rax);
aoqi@0 839 __ push(c_rarg3);
aoqi@0 840 __ push(c_rarg2);
aoqi@0 841 __ push(c_rarg1);
aoqi@0 842 __ push(c_rarg0);
aoqi@0 843
aoqi@0 844 __ movl(rax, 0x7ff00000);
aoqi@0 845 __ movq(c_rarg2, inout);
aoqi@0 846 __ movl(c_rarg3, c_rarg2);
aoqi@0 847 __ mov(c_rarg1, c_rarg2);
aoqi@0 848 __ mov(c_rarg0, c_rarg2);
aoqi@0 849 __ negl(c_rarg3);
aoqi@0 850 __ shrptr(c_rarg1, 0x20);
aoqi@0 851 __ orl(c_rarg3, c_rarg2);
aoqi@0 852 __ andl(c_rarg1, 0x7fffffff);
aoqi@0 853 __ xorl(c_rarg2, c_rarg2);
aoqi@0 854 __ shrl(c_rarg3, 0x1f);
aoqi@0 855 __ orl(c_rarg1, c_rarg3);
aoqi@0 856 __ cmpl(rax, c_rarg1);
aoqi@0 857 __ jcc(Assembler::negative, L); // NaN -> 0
aoqi@0 858 __ testptr(c_rarg0, c_rarg0); // signed ? min_jint : max_jint
aoqi@0 859 __ movl(c_rarg2, 0x80000000);
aoqi@0 860 __ movl(rax, 0x7fffffff);
aoqi@0 861 __ cmov(Assembler::positive, c_rarg2, rax);
aoqi@0 862
aoqi@0 863 __ bind(L);
aoqi@0 864 __ movptr(inout, c_rarg2);
aoqi@0 865
aoqi@0 866 __ pop(c_rarg0);
aoqi@0 867 __ pop(c_rarg1);
aoqi@0 868 __ pop(c_rarg2);
aoqi@0 869 __ pop(c_rarg3);
aoqi@0 870 __ pop(rax);
aoqi@0 871
aoqi@0 872 __ ret(0);
aoqi@0 873
aoqi@0 874 return start;
aoqi@0 875 }
aoqi@0 876
aoqi@0 877 address generate_d2l_fixup() {
aoqi@0 878 StubCodeMark mark(this, "StubRoutines", "d2l_fixup");
aoqi@0 879 Address inout(rsp, 6 * wordSize); // return address + 5 saves
aoqi@0 880
aoqi@0 881 address start = __ pc();
aoqi@0 882
aoqi@0 883 Label L;
aoqi@0 884
aoqi@0 885 __ push(rax);
aoqi@0 886 __ push(c_rarg3);
aoqi@0 887 __ push(c_rarg2);
aoqi@0 888 __ push(c_rarg1);
aoqi@0 889 __ push(c_rarg0);
aoqi@0 890
aoqi@0 891 __ movl(rax, 0x7ff00000);
aoqi@0 892 __ movq(c_rarg2, inout);
aoqi@0 893 __ movl(c_rarg3, c_rarg2);
aoqi@0 894 __ mov(c_rarg1, c_rarg2);
aoqi@0 895 __ mov(c_rarg0, c_rarg2);
aoqi@0 896 __ negl(c_rarg3);
aoqi@0 897 __ shrptr(c_rarg1, 0x20);
aoqi@0 898 __ orl(c_rarg3, c_rarg2);
aoqi@0 899 __ andl(c_rarg1, 0x7fffffff);
aoqi@0 900 __ xorl(c_rarg2, c_rarg2);
aoqi@0 901 __ shrl(c_rarg3, 0x1f);
aoqi@0 902 __ orl(c_rarg1, c_rarg3);
aoqi@0 903 __ cmpl(rax, c_rarg1);
aoqi@0 904 __ jcc(Assembler::negative, L); // NaN -> 0
aoqi@0 905 __ testq(c_rarg0, c_rarg0); // signed ? min_jlong : max_jlong
aoqi@0 906 __ mov64(c_rarg2, 0x8000000000000000);
aoqi@0 907 __ mov64(rax, 0x7fffffffffffffff);
aoqi@0 908 __ cmovq(Assembler::positive, c_rarg2, rax);
aoqi@0 909
aoqi@0 910 __ bind(L);
aoqi@0 911 __ movq(inout, c_rarg2);
aoqi@0 912
aoqi@0 913 __ pop(c_rarg0);
aoqi@0 914 __ pop(c_rarg1);
aoqi@0 915 __ pop(c_rarg2);
aoqi@0 916 __ pop(c_rarg3);
aoqi@0 917 __ pop(rax);
aoqi@0 918
aoqi@0 919 __ ret(0);
aoqi@0 920
aoqi@0 921 return start;
aoqi@0 922 }
aoqi@0 923
aoqi@0 924 address generate_fp_mask(const char *stub_name, int64_t mask) {
aoqi@0 925 __ align(CodeEntryAlignment);
aoqi@0 926 StubCodeMark mark(this, "StubRoutines", stub_name);
aoqi@0 927 address start = __ pc();
aoqi@0 928
aoqi@0 929 __ emit_data64( mask, relocInfo::none );
aoqi@0 930 __ emit_data64( mask, relocInfo::none );
aoqi@0 931
aoqi@0 932 return start;
aoqi@0 933 }
aoqi@0 934
aoqi@0 935 // The following routine generates a subroutine to throw an
aoqi@0 936 // asynchronous UnknownError when an unsafe access gets a fault that
aoqi@0 937 // could not be reasonably prevented by the programmer. (Example:
aoqi@0 938 // SIGBUS/OBJERR.)
aoqi@0 939 address generate_handler_for_unsafe_access() {
aoqi@0 940 StubCodeMark mark(this, "StubRoutines", "handler_for_unsafe_access");
aoqi@0 941 address start = __ pc();
aoqi@0 942
aoqi@0 943 __ push(0); // hole for return address-to-be
aoqi@0 944 __ pusha(); // push registers
aoqi@0 945 Address next_pc(rsp, RegisterImpl::number_of_registers * BytesPerWord);
aoqi@0 946
aoqi@0 947 // FIXME: this probably needs alignment logic
aoqi@0 948
aoqi@0 949 __ subptr(rsp, frame::arg_reg_save_area_bytes);
aoqi@0 950 BLOCK_COMMENT("call handle_unsafe_access");
aoqi@0 951 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, handle_unsafe_access)));
aoqi@0 952 __ addptr(rsp, frame::arg_reg_save_area_bytes);
aoqi@0 953
aoqi@0 954 __ movptr(next_pc, rax); // stuff next address
aoqi@0 955 __ popa();
aoqi@0 956 __ ret(0); // jump to next address
aoqi@0 957
aoqi@0 958 return start;
aoqi@0 959 }
aoqi@0 960
aoqi@0 961 // Non-destructive plausibility checks for oops
aoqi@0 962 //
aoqi@0 963 // Arguments:
aoqi@0 964 // all args on stack!
aoqi@0 965 //
aoqi@0 966 // Stack after saving c_rarg3:
aoqi@0 967 // [tos + 0]: saved c_rarg3
aoqi@0 968 // [tos + 1]: saved c_rarg2
aoqi@0 969 // [tos + 2]: saved r12 (several TemplateTable methods use it)
aoqi@0 970 // [tos + 3]: saved flags
aoqi@0 971 // [tos + 4]: return address
aoqi@0 972 // * [tos + 5]: error message (char*)
aoqi@0 973 // * [tos + 6]: object to verify (oop)
aoqi@0 974 // * [tos + 7]: saved rax - saved by caller and bashed
aoqi@0 975 // * [tos + 8]: saved r10 (rscratch1) - saved by caller
aoqi@0 976 // * = popped on exit
aoqi@0 977 address generate_verify_oop() {
aoqi@0 978 StubCodeMark mark(this, "StubRoutines", "verify_oop");
aoqi@0 979 address start = __ pc();
aoqi@0 980
aoqi@0 981 Label exit, error;
aoqi@0 982
aoqi@0 983 __ pushf();
aoqi@0 984 __ incrementl(ExternalAddress((address) StubRoutines::verify_oop_count_addr()));
aoqi@0 985
aoqi@0 986 __ push(r12);
aoqi@0 987
aoqi@0 988 // save c_rarg2 and c_rarg3
aoqi@0 989 __ push(c_rarg2);
aoqi@0 990 __ push(c_rarg3);
aoqi@0 991
aoqi@0 992 enum {
aoqi@0 993 // After previous pushes.
aoqi@0 994 oop_to_verify = 6 * wordSize,
aoqi@0 995 saved_rax = 7 * wordSize,
aoqi@0 996 saved_r10 = 8 * wordSize,
aoqi@0 997
aoqi@0 998 // Before the call to MacroAssembler::debug(), see below.
aoqi@0 999 return_addr = 16 * wordSize,
aoqi@0 1000 error_msg = 17 * wordSize
aoqi@0 1001 };
aoqi@0 1002
aoqi@0 1003 // get object
aoqi@0 1004 __ movptr(rax, Address(rsp, oop_to_verify));
aoqi@0 1005
aoqi@0 1006 // make sure object is 'reasonable'
aoqi@0 1007 __ testptr(rax, rax);
aoqi@0 1008 __ jcc(Assembler::zero, exit); // if obj is NULL it is OK
aoqi@0 1009 // Check if the oop is in the right area of memory
aoqi@0 1010 __ movptr(c_rarg2, rax);
aoqi@0 1011 __ movptr(c_rarg3, (intptr_t) Universe::verify_oop_mask());
aoqi@0 1012 __ andptr(c_rarg2, c_rarg3);
aoqi@0 1013 __ movptr(c_rarg3, (intptr_t) Universe::verify_oop_bits());
aoqi@0 1014 __ cmpptr(c_rarg2, c_rarg3);
aoqi@0 1015 __ jcc(Assembler::notZero, error);
aoqi@0 1016
aoqi@0 1017 // set r12 to heapbase for load_klass()
aoqi@0 1018 __ reinit_heapbase();
aoqi@0 1019
aoqi@0 1020 // make sure klass is 'reasonable', which is not zero.
aoqi@0 1021 __ load_klass(rax, rax); // get klass
aoqi@0 1022 __ testptr(rax, rax);
aoqi@0 1023 __ jcc(Assembler::zero, error); // if klass is NULL it is broken
aoqi@0 1024
aoqi@0 1025 // return if everything seems ok
aoqi@0 1026 __ bind(exit);
aoqi@0 1027 __ movptr(rax, Address(rsp, saved_rax)); // get saved rax back
aoqi@0 1028 __ movptr(rscratch1, Address(rsp, saved_r10)); // get saved r10 back
aoqi@0 1029 __ pop(c_rarg3); // restore c_rarg3
aoqi@0 1030 __ pop(c_rarg2); // restore c_rarg2
aoqi@0 1031 __ pop(r12); // restore r12
aoqi@0 1032 __ popf(); // restore flags
aoqi@0 1033 __ ret(4 * wordSize); // pop caller saved stuff
aoqi@0 1034
aoqi@0 1035 // handle errors
aoqi@0 1036 __ bind(error);
aoqi@0 1037 __ movptr(rax, Address(rsp, saved_rax)); // get saved rax back
aoqi@0 1038 __ movptr(rscratch1, Address(rsp, saved_r10)); // get saved r10 back
aoqi@0 1039 __ pop(c_rarg3); // get saved c_rarg3 back
aoqi@0 1040 __ pop(c_rarg2); // get saved c_rarg2 back
aoqi@0 1041 __ pop(r12); // get saved r12 back
aoqi@0 1042 __ popf(); // get saved flags off stack --
aoqi@0 1043 // will be ignored
aoqi@0 1044
aoqi@0 1045 __ pusha(); // push registers
aoqi@0 1046 // (rip is already
aoqi@0 1047 // already pushed)
aoqi@0 1048 // debug(char* msg, int64_t pc, int64_t regs[])
aoqi@0 1049 // We've popped the registers we'd saved (c_rarg3, c_rarg2 and flags), and
aoqi@0 1050 // pushed all the registers, so now the stack looks like:
aoqi@0 1051 // [tos + 0] 16 saved registers
aoqi@0 1052 // [tos + 16] return address
aoqi@0 1053 // * [tos + 17] error message (char*)
aoqi@0 1054 // * [tos + 18] object to verify (oop)
aoqi@0 1055 // * [tos + 19] saved rax - saved by caller and bashed
aoqi@0 1056 // * [tos + 20] saved r10 (rscratch1) - saved by caller
aoqi@0 1057 // * = popped on exit
aoqi@0 1058
aoqi@0 1059 __ movptr(c_rarg0, Address(rsp, error_msg)); // pass address of error message
aoqi@0 1060 __ movptr(c_rarg1, Address(rsp, return_addr)); // pass return address
aoqi@0 1061 __ movq(c_rarg2, rsp); // pass address of regs on stack
aoqi@0 1062 __ mov(r12, rsp); // remember rsp
aoqi@0 1063 __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
aoqi@0 1064 __ andptr(rsp, -16); // align stack as required by ABI
aoqi@0 1065 BLOCK_COMMENT("call MacroAssembler::debug");
aoqi@0 1066 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, MacroAssembler::debug64)));
aoqi@0 1067 __ mov(rsp, r12); // restore rsp
aoqi@0 1068 __ popa(); // pop registers (includes r12)
aoqi@0 1069 __ ret(4 * wordSize); // pop caller saved stuff
aoqi@0 1070
aoqi@0 1071 return start;
aoqi@0 1072 }
aoqi@0 1073
aoqi@0 1074 //
aoqi@0 1075 // Verify that a register contains clean 32-bits positive value
aoqi@0 1076 // (high 32-bits are 0) so it could be used in 64-bits shifts.
aoqi@0 1077 //
aoqi@0 1078 // Input:
aoqi@0 1079 // Rint - 32-bits value
aoqi@0 1080 // Rtmp - scratch
aoqi@0 1081 //
aoqi@0 1082 void assert_clean_int(Register Rint, Register Rtmp) {
aoqi@0 1083 #ifdef ASSERT
aoqi@0 1084 Label L;
aoqi@0 1085 assert_different_registers(Rtmp, Rint);
aoqi@0 1086 __ movslq(Rtmp, Rint);
aoqi@0 1087 __ cmpq(Rtmp, Rint);
aoqi@0 1088 __ jcc(Assembler::equal, L);
aoqi@0 1089 __ stop("high 32-bits of int value are not 0");
aoqi@0 1090 __ bind(L);
aoqi@0 1091 #endif
aoqi@0 1092 }
aoqi@0 1093
aoqi@0 1094 // Generate overlap test for array copy stubs
aoqi@0 1095 //
aoqi@0 1096 // Input:
aoqi@0 1097 // c_rarg0 - from
aoqi@0 1098 // c_rarg1 - to
aoqi@0 1099 // c_rarg2 - element count
aoqi@0 1100 //
aoqi@0 1101 // Output:
aoqi@0 1102 // rax - &from[element count - 1]
aoqi@0 1103 //
aoqi@0 1104 void array_overlap_test(address no_overlap_target, Address::ScaleFactor sf) {
aoqi@0 1105 assert(no_overlap_target != NULL, "must be generated");
aoqi@0 1106 array_overlap_test(no_overlap_target, NULL, sf);
aoqi@0 1107 }
aoqi@0 1108 void array_overlap_test(Label& L_no_overlap, Address::ScaleFactor sf) {
aoqi@0 1109 array_overlap_test(NULL, &L_no_overlap, sf);
aoqi@0 1110 }
aoqi@0 1111 void array_overlap_test(address no_overlap_target, Label* NOLp, Address::ScaleFactor sf) {
aoqi@0 1112 const Register from = c_rarg0;
aoqi@0 1113 const Register to = c_rarg1;
aoqi@0 1114 const Register count = c_rarg2;
aoqi@0 1115 const Register end_from = rax;
aoqi@0 1116
aoqi@0 1117 __ cmpptr(to, from);
aoqi@0 1118 __ lea(end_from, Address(from, count, sf, 0));
aoqi@0 1119 if (NOLp == NULL) {
aoqi@0 1120 ExternalAddress no_overlap(no_overlap_target);
aoqi@0 1121 __ jump_cc(Assembler::belowEqual, no_overlap);
aoqi@0 1122 __ cmpptr(to, end_from);
aoqi@0 1123 __ jump_cc(Assembler::aboveEqual, no_overlap);
aoqi@0 1124 } else {
aoqi@0 1125 __ jcc(Assembler::belowEqual, (*NOLp));
aoqi@0 1126 __ cmpptr(to, end_from);
aoqi@0 1127 __ jcc(Assembler::aboveEqual, (*NOLp));
aoqi@0 1128 }
aoqi@0 1129 }
aoqi@0 1130
aoqi@0 1131 // Shuffle first three arg regs on Windows into Linux/Solaris locations.
aoqi@0 1132 //
aoqi@0 1133 // Outputs:
aoqi@0 1134 // rdi - rcx
aoqi@0 1135 // rsi - rdx
aoqi@0 1136 // rdx - r8
aoqi@0 1137 // rcx - r9
aoqi@0 1138 //
aoqi@0 1139 // Registers r9 and r10 are used to save rdi and rsi on Windows, which latter
aoqi@0 1140 // are non-volatile. r9 and r10 should not be used by the caller.
aoqi@0 1141 //
aoqi@0 1142 void setup_arg_regs(int nargs = 3) {
aoqi@0 1143 const Register saved_rdi = r9;
aoqi@0 1144 const Register saved_rsi = r10;
aoqi@0 1145 assert(nargs == 3 || nargs == 4, "else fix");
aoqi@0 1146 #ifdef _WIN64
aoqi@0 1147 assert(c_rarg0 == rcx && c_rarg1 == rdx && c_rarg2 == r8 && c_rarg3 == r9,
aoqi@0 1148 "unexpected argument registers");
aoqi@0 1149 if (nargs >= 4)
aoqi@0 1150 __ mov(rax, r9); // r9 is also saved_rdi
aoqi@0 1151 __ movptr(saved_rdi, rdi);
aoqi@0 1152 __ movptr(saved_rsi, rsi);
aoqi@0 1153 __ mov(rdi, rcx); // c_rarg0
aoqi@0 1154 __ mov(rsi, rdx); // c_rarg1
aoqi@0 1155 __ mov(rdx, r8); // c_rarg2
aoqi@0 1156 if (nargs >= 4)
aoqi@0 1157 __ mov(rcx, rax); // c_rarg3 (via rax)
aoqi@0 1158 #else
aoqi@0 1159 assert(c_rarg0 == rdi && c_rarg1 == rsi && c_rarg2 == rdx && c_rarg3 == rcx,
aoqi@0 1160 "unexpected argument registers");
aoqi@0 1161 #endif
aoqi@0 1162 }
aoqi@0 1163
aoqi@0 1164 void restore_arg_regs() {
aoqi@0 1165 const Register saved_rdi = r9;
aoqi@0 1166 const Register saved_rsi = r10;
aoqi@0 1167 #ifdef _WIN64
aoqi@0 1168 __ movptr(rdi, saved_rdi);
aoqi@0 1169 __ movptr(rsi, saved_rsi);
aoqi@0 1170 #endif
aoqi@0 1171 }
aoqi@0 1172
aoqi@0 1173 // Generate code for an array write pre barrier
aoqi@0 1174 //
aoqi@0 1175 // addr - starting address
aoqi@0 1176 // count - element count
aoqi@0 1177 // tmp - scratch register
aoqi@0 1178 //
aoqi@0 1179 // Destroy no registers!
aoqi@0 1180 //
aoqi@0 1181 void gen_write_ref_array_pre_barrier(Register addr, Register count, bool dest_uninitialized) {
aoqi@0 1182 BarrierSet* bs = Universe::heap()->barrier_set();
aoqi@0 1183 switch (bs->kind()) {
aoqi@0 1184 case BarrierSet::G1SATBCT:
aoqi@0 1185 case BarrierSet::G1SATBCTLogging:
aoqi@0 1186 // With G1, don't generate the call if we statically know that the target in uninitialized
aoqi@0 1187 if (!dest_uninitialized) {
aoqi@0 1188 __ pusha(); // push registers
aoqi@0 1189 if (count == c_rarg0) {
aoqi@0 1190 if (addr == c_rarg1) {
aoqi@0 1191 // exactly backwards!!
aoqi@0 1192 __ xchgptr(c_rarg1, c_rarg0);
aoqi@0 1193 } else {
aoqi@0 1194 __ movptr(c_rarg1, count);
aoqi@0 1195 __ movptr(c_rarg0, addr);
aoqi@0 1196 }
aoqi@0 1197 } else {
aoqi@0 1198 __ movptr(c_rarg0, addr);
aoqi@0 1199 __ movptr(c_rarg1, count);
aoqi@0 1200 }
aoqi@0 1201 __ call_VM_leaf(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_pre), 2);
aoqi@0 1202 __ popa();
aoqi@0 1203 }
aoqi@0 1204 break;
aoqi@0 1205 case BarrierSet::CardTableModRef:
aoqi@0 1206 case BarrierSet::CardTableExtension:
aoqi@0 1207 case BarrierSet::ModRef:
aoqi@0 1208 break;
aoqi@0 1209 default:
aoqi@0 1210 ShouldNotReachHere();
aoqi@0 1211
aoqi@0 1212 }
aoqi@0 1213 }
aoqi@0 1214
aoqi@0 1215 //
aoqi@0 1216 // Generate code for an array write post barrier
aoqi@0 1217 //
aoqi@0 1218 // Input:
aoqi@0 1219 // start - register containing starting address of destination array
aoqi@0 1220 // count - elements count
aoqi@0 1221 // scratch - scratch register
aoqi@0 1222 //
aoqi@0 1223 // The input registers are overwritten.
aoqi@0 1224 //
aoqi@0 1225 void gen_write_ref_array_post_barrier(Register start, Register count, Register scratch) {
aoqi@0 1226 assert_different_registers(start, count, scratch);
aoqi@0 1227 BarrierSet* bs = Universe::heap()->barrier_set();
aoqi@0 1228 switch (bs->kind()) {
aoqi@0 1229 case BarrierSet::G1SATBCT:
aoqi@0 1230 case BarrierSet::G1SATBCTLogging:
aoqi@0 1231 {
aoqi@0 1232 __ pusha(); // push registers (overkill)
aoqi@0 1233 if (c_rarg0 == count) { // On win64 c_rarg0 == rcx
aoqi@0 1234 assert_different_registers(c_rarg1, start);
aoqi@0 1235 __ mov(c_rarg1, count);
aoqi@0 1236 __ mov(c_rarg0, start);
aoqi@0 1237 } else {
aoqi@0 1238 assert_different_registers(c_rarg0, count);
aoqi@0 1239 __ mov(c_rarg0, start);
aoqi@0 1240 __ mov(c_rarg1, count);
aoqi@0 1241 }
aoqi@0 1242 __ call_VM_leaf(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_post), 2);
aoqi@0 1243 __ popa();
aoqi@0 1244 }
aoqi@0 1245 break;
aoqi@0 1246 case BarrierSet::CardTableModRef:
aoqi@0 1247 case BarrierSet::CardTableExtension:
aoqi@0 1248 {
aoqi@0 1249 CardTableModRefBS* ct = (CardTableModRefBS*)bs;
aoqi@0 1250 assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code");
aoqi@0 1251
aoqi@0 1252 Label L_loop;
aoqi@0 1253 const Register end = count;
aoqi@0 1254
aoqi@0 1255 __ leaq(end, Address(start, count, TIMES_OOP, 0)); // end == start+count*oop_size
aoqi@0 1256 __ subptr(end, BytesPerHeapOop); // end - 1 to make inclusive
aoqi@0 1257 __ shrptr(start, CardTableModRefBS::card_shift);
aoqi@0 1258 __ shrptr(end, CardTableModRefBS::card_shift);
aoqi@0 1259 __ subptr(end, start); // end --> cards count
aoqi@0 1260
aoqi@0 1261 int64_t disp = (int64_t) ct->byte_map_base;
aoqi@0 1262 __ mov64(scratch, disp);
aoqi@0 1263 __ addptr(start, scratch);
aoqi@0 1264 __ BIND(L_loop);
aoqi@0 1265 __ movb(Address(start, count, Address::times_1), 0);
aoqi@0 1266 __ decrement(count);
aoqi@0 1267 __ jcc(Assembler::greaterEqual, L_loop);
aoqi@0 1268 }
aoqi@0 1269 break;
aoqi@0 1270 default:
aoqi@0 1271 ShouldNotReachHere();
aoqi@0 1272
aoqi@0 1273 }
aoqi@0 1274 }
aoqi@0 1275
aoqi@0 1276
aoqi@0 1277 // Copy big chunks forward
aoqi@0 1278 //
aoqi@0 1279 // Inputs:
aoqi@0 1280 // end_from - source arrays end address
aoqi@0 1281 // end_to - destination array end address
aoqi@0 1282 // qword_count - 64-bits element count, negative
aoqi@0 1283 // to - scratch
aoqi@0 1284 // L_copy_bytes - entry label
aoqi@0 1285 // L_copy_8_bytes - exit label
aoqi@0 1286 //
aoqi@0 1287 void copy_bytes_forward(Register end_from, Register end_to,
aoqi@0 1288 Register qword_count, Register to,
aoqi@0 1289 Label& L_copy_bytes, Label& L_copy_8_bytes) {
aoqi@0 1290 DEBUG_ONLY(__ stop("enter at entry label, not here"));
aoqi@0 1291 Label L_loop;
aoqi@0 1292 __ align(OptoLoopAlignment);
aoqi@0 1293 if (UseUnalignedLoadStores) {
aoqi@0 1294 Label L_end;
aoqi@0 1295 // Copy 64-bytes per iteration
aoqi@0 1296 __ BIND(L_loop);
aoqi@0 1297 if (UseAVX >= 2) {
aoqi@0 1298 __ vmovdqu(xmm0, Address(end_from, qword_count, Address::times_8, -56));
aoqi@0 1299 __ vmovdqu(Address(end_to, qword_count, Address::times_8, -56), xmm0);
aoqi@0 1300 __ vmovdqu(xmm1, Address(end_from, qword_count, Address::times_8, -24));
aoqi@0 1301 __ vmovdqu(Address(end_to, qword_count, Address::times_8, -24), xmm1);
aoqi@0 1302 } else {
aoqi@0 1303 __ movdqu(xmm0, Address(end_from, qword_count, Address::times_8, -56));
aoqi@0 1304 __ movdqu(Address(end_to, qword_count, Address::times_8, -56), xmm0);
aoqi@0 1305 __ movdqu(xmm1, Address(end_from, qword_count, Address::times_8, -40));
aoqi@0 1306 __ movdqu(Address(end_to, qword_count, Address::times_8, -40), xmm1);
aoqi@0 1307 __ movdqu(xmm2, Address(end_from, qword_count, Address::times_8, -24));
aoqi@0 1308 __ movdqu(Address(end_to, qword_count, Address::times_8, -24), xmm2);
aoqi@0 1309 __ movdqu(xmm3, Address(end_from, qword_count, Address::times_8, - 8));
aoqi@0 1310 __ movdqu(Address(end_to, qword_count, Address::times_8, - 8), xmm3);
aoqi@0 1311 }
aoqi@0 1312 __ BIND(L_copy_bytes);
aoqi@0 1313 __ addptr(qword_count, 8);
aoqi@0 1314 __ jcc(Assembler::lessEqual, L_loop);
aoqi@0 1315 __ subptr(qword_count, 4); // sub(8) and add(4)
aoqi@0 1316 __ jccb(Assembler::greater, L_end);
aoqi@0 1317 // Copy trailing 32 bytes
aoqi@0 1318 if (UseAVX >= 2) {
aoqi@0 1319 __ vmovdqu(xmm0, Address(end_from, qword_count, Address::times_8, -24));
aoqi@0 1320 __ vmovdqu(Address(end_to, qword_count, Address::times_8, -24), xmm0);
aoqi@0 1321 } else {
aoqi@0 1322 __ movdqu(xmm0, Address(end_from, qword_count, Address::times_8, -24));
aoqi@0 1323 __ movdqu(Address(end_to, qword_count, Address::times_8, -24), xmm0);
aoqi@0 1324 __ movdqu(xmm1, Address(end_from, qword_count, Address::times_8, - 8));
aoqi@0 1325 __ movdqu(Address(end_to, qword_count, Address::times_8, - 8), xmm1);
aoqi@0 1326 }
aoqi@0 1327 __ addptr(qword_count, 4);
aoqi@0 1328 __ BIND(L_end);
aoqi@0 1329 if (UseAVX >= 2) {
aoqi@0 1330 // clean upper bits of YMM registers
kvn@7816 1331 __ vpxor(xmm0, xmm0);
kvn@7816 1332 __ vpxor(xmm1, xmm1);
aoqi@0 1333 }
aoqi@0 1334 } else {
aoqi@0 1335 // Copy 32-bytes per iteration
aoqi@0 1336 __ BIND(L_loop);
aoqi@0 1337 __ movq(to, Address(end_from, qword_count, Address::times_8, -24));
aoqi@0 1338 __ movq(Address(end_to, qword_count, Address::times_8, -24), to);
aoqi@0 1339 __ movq(to, Address(end_from, qword_count, Address::times_8, -16));
aoqi@0 1340 __ movq(Address(end_to, qword_count, Address::times_8, -16), to);
aoqi@0 1341 __ movq(to, Address(end_from, qword_count, Address::times_8, - 8));
aoqi@0 1342 __ movq(Address(end_to, qword_count, Address::times_8, - 8), to);
aoqi@0 1343 __ movq(to, Address(end_from, qword_count, Address::times_8, - 0));
aoqi@0 1344 __ movq(Address(end_to, qword_count, Address::times_8, - 0), to);
aoqi@0 1345
aoqi@0 1346 __ BIND(L_copy_bytes);
aoqi@0 1347 __ addptr(qword_count, 4);
aoqi@0 1348 __ jcc(Assembler::lessEqual, L_loop);
aoqi@0 1349 }
aoqi@0 1350 __ subptr(qword_count, 4);
aoqi@0 1351 __ jcc(Assembler::less, L_copy_8_bytes); // Copy trailing qwords
aoqi@0 1352 }
aoqi@0 1353
aoqi@0 1354 // Copy big chunks backward
aoqi@0 1355 //
aoqi@0 1356 // Inputs:
aoqi@0 1357 // from - source arrays address
aoqi@0 1358 // dest - destination array address
aoqi@0 1359 // qword_count - 64-bits element count
aoqi@0 1360 // to - scratch
aoqi@0 1361 // L_copy_bytes - entry label
aoqi@0 1362 // L_copy_8_bytes - exit label
aoqi@0 1363 //
aoqi@0 1364 void copy_bytes_backward(Register from, Register dest,
aoqi@0 1365 Register qword_count, Register to,
aoqi@0 1366 Label& L_copy_bytes, Label& L_copy_8_bytes) {
aoqi@0 1367 DEBUG_ONLY(__ stop("enter at entry label, not here"));
aoqi@0 1368 Label L_loop;
aoqi@0 1369 __ align(OptoLoopAlignment);
aoqi@0 1370 if (UseUnalignedLoadStores) {
aoqi@0 1371 Label L_end;
aoqi@0 1372 // Copy 64-bytes per iteration
aoqi@0 1373 __ BIND(L_loop);
aoqi@0 1374 if (UseAVX >= 2) {
aoqi@0 1375 __ vmovdqu(xmm0, Address(from, qword_count, Address::times_8, 32));
aoqi@0 1376 __ vmovdqu(Address(dest, qword_count, Address::times_8, 32), xmm0);
aoqi@0 1377 __ vmovdqu(xmm1, Address(from, qword_count, Address::times_8, 0));
aoqi@0 1378 __ vmovdqu(Address(dest, qword_count, Address::times_8, 0), xmm1);
aoqi@0 1379 } else {
aoqi@0 1380 __ movdqu(xmm0, Address(from, qword_count, Address::times_8, 48));
aoqi@0 1381 __ movdqu(Address(dest, qword_count, Address::times_8, 48), xmm0);
aoqi@0 1382 __ movdqu(xmm1, Address(from, qword_count, Address::times_8, 32));
aoqi@0 1383 __ movdqu(Address(dest, qword_count, Address::times_8, 32), xmm1);
aoqi@0 1384 __ movdqu(xmm2, Address(from, qword_count, Address::times_8, 16));
aoqi@0 1385 __ movdqu(Address(dest, qword_count, Address::times_8, 16), xmm2);
aoqi@0 1386 __ movdqu(xmm3, Address(from, qword_count, Address::times_8, 0));
aoqi@0 1387 __ movdqu(Address(dest, qword_count, Address::times_8, 0), xmm3);
aoqi@0 1388 }
aoqi@0 1389 __ BIND(L_copy_bytes);
aoqi@0 1390 __ subptr(qword_count, 8);
aoqi@0 1391 __ jcc(Assembler::greaterEqual, L_loop);
aoqi@0 1392
aoqi@0 1393 __ addptr(qword_count, 4); // add(8) and sub(4)
aoqi@0 1394 __ jccb(Assembler::less, L_end);
aoqi@0 1395 // Copy trailing 32 bytes
aoqi@0 1396 if (UseAVX >= 2) {
aoqi@0 1397 __ vmovdqu(xmm0, Address(from, qword_count, Address::times_8, 0));
aoqi@0 1398 __ vmovdqu(Address(dest, qword_count, Address::times_8, 0), xmm0);
aoqi@0 1399 } else {
aoqi@0 1400 __ movdqu(xmm0, Address(from, qword_count, Address::times_8, 16));
aoqi@0 1401 __ movdqu(Address(dest, qword_count, Address::times_8, 16), xmm0);
aoqi@0 1402 __ movdqu(xmm1, Address(from, qword_count, Address::times_8, 0));
aoqi@0 1403 __ movdqu(Address(dest, qword_count, Address::times_8, 0), xmm1);
aoqi@0 1404 }
aoqi@0 1405 __ subptr(qword_count, 4);
aoqi@0 1406 __ BIND(L_end);
aoqi@0 1407 if (UseAVX >= 2) {
aoqi@0 1408 // clean upper bits of YMM registers
kvn@7816 1409 __ vpxor(xmm0, xmm0);
kvn@7816 1410 __ vpxor(xmm1, xmm1);
aoqi@0 1411 }
aoqi@0 1412 } else {
aoqi@0 1413 // Copy 32-bytes per iteration
aoqi@0 1414 __ BIND(L_loop);
aoqi@0 1415 __ movq(to, Address(from, qword_count, Address::times_8, 24));
aoqi@0 1416 __ movq(Address(dest, qword_count, Address::times_8, 24), to);
aoqi@0 1417 __ movq(to, Address(from, qword_count, Address::times_8, 16));
aoqi@0 1418 __ movq(Address(dest, qword_count, Address::times_8, 16), to);
aoqi@0 1419 __ movq(to, Address(from, qword_count, Address::times_8, 8));
aoqi@0 1420 __ movq(Address(dest, qword_count, Address::times_8, 8), to);
aoqi@0 1421 __ movq(to, Address(from, qword_count, Address::times_8, 0));
aoqi@0 1422 __ movq(Address(dest, qword_count, Address::times_8, 0), to);
aoqi@0 1423
aoqi@0 1424 __ BIND(L_copy_bytes);
aoqi@0 1425 __ subptr(qword_count, 4);
aoqi@0 1426 __ jcc(Assembler::greaterEqual, L_loop);
aoqi@0 1427 }
aoqi@0 1428 __ addptr(qword_count, 4);
aoqi@0 1429 __ jcc(Assembler::greater, L_copy_8_bytes); // Copy trailing qwords
aoqi@0 1430 }
aoqi@0 1431
aoqi@0 1432
aoqi@0 1433 // Arguments:
aoqi@0 1434 // aligned - true => Input and output aligned on a HeapWord == 8-byte boundary
aoqi@0 1435 // ignored
aoqi@0 1436 // name - stub name string
aoqi@0 1437 //
aoqi@0 1438 // Inputs:
aoqi@0 1439 // c_rarg0 - source array address
aoqi@0 1440 // c_rarg1 - destination array address
aoqi@0 1441 // c_rarg2 - element count, treated as ssize_t, can be zero
aoqi@0 1442 //
aoqi@0 1443 // If 'from' and/or 'to' are aligned on 4-, 2-, or 1-byte boundaries,
aoqi@0 1444 // we let the hardware handle it. The one to eight bytes within words,
aoqi@0 1445 // dwords or qwords that span cache line boundaries will still be loaded
aoqi@0 1446 // and stored atomically.
aoqi@0 1447 //
aoqi@0 1448 // Side Effects:
aoqi@0 1449 // disjoint_byte_copy_entry is set to the no-overlap entry point
aoqi@0 1450 // used by generate_conjoint_byte_copy().
aoqi@0 1451 //
aoqi@0 1452 address generate_disjoint_byte_copy(bool aligned, address* entry, const char *name) {
aoqi@0 1453 __ align(CodeEntryAlignment);
aoqi@0 1454 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 1455 address start = __ pc();
aoqi@0 1456
aoqi@0 1457 Label L_copy_bytes, L_copy_8_bytes, L_copy_4_bytes, L_copy_2_bytes;
aoqi@0 1458 Label L_copy_byte, L_exit;
aoqi@0 1459 const Register from = rdi; // source array address
aoqi@0 1460 const Register to = rsi; // destination array address
aoqi@0 1461 const Register count = rdx; // elements count
aoqi@0 1462 const Register byte_count = rcx;
aoqi@0 1463 const Register qword_count = count;
aoqi@0 1464 const Register end_from = from; // source array end address
aoqi@0 1465 const Register end_to = to; // destination array end address
aoqi@0 1466 // End pointers are inclusive, and if count is not zero they point
aoqi@0 1467 // to the last unit copied: end_to[0] := end_from[0]
aoqi@0 1468
aoqi@0 1469 __ enter(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 1470 assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int.
aoqi@0 1471
aoqi@0 1472 if (entry != NULL) {
aoqi@0 1473 *entry = __ pc();
aoqi@0 1474 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
aoqi@0 1475 BLOCK_COMMENT("Entry:");
aoqi@0 1476 }
aoqi@0 1477
aoqi@0 1478 setup_arg_regs(); // from => rdi, to => rsi, count => rdx
aoqi@0 1479 // r9 and r10 may be used to save non-volatile registers
aoqi@0 1480
aoqi@0 1481 // 'from', 'to' and 'count' are now valid
aoqi@0 1482 __ movptr(byte_count, count);
aoqi@0 1483 __ shrptr(count, 3); // count => qword_count
aoqi@0 1484
aoqi@0 1485 // Copy from low to high addresses. Use 'to' as scratch.
aoqi@0 1486 __ lea(end_from, Address(from, qword_count, Address::times_8, -8));
aoqi@0 1487 __ lea(end_to, Address(to, qword_count, Address::times_8, -8));
aoqi@0 1488 __ negptr(qword_count); // make the count negative
aoqi@0 1489 __ jmp(L_copy_bytes);
aoqi@0 1490
aoqi@0 1491 // Copy trailing qwords
aoqi@0 1492 __ BIND(L_copy_8_bytes);
aoqi@0 1493 __ movq(rax, Address(end_from, qword_count, Address::times_8, 8));
aoqi@0 1494 __ movq(Address(end_to, qword_count, Address::times_8, 8), rax);
aoqi@0 1495 __ increment(qword_count);
aoqi@0 1496 __ jcc(Assembler::notZero, L_copy_8_bytes);
aoqi@0 1497
aoqi@0 1498 // Check for and copy trailing dword
aoqi@0 1499 __ BIND(L_copy_4_bytes);
aoqi@0 1500 __ testl(byte_count, 4);
aoqi@0 1501 __ jccb(Assembler::zero, L_copy_2_bytes);
aoqi@0 1502 __ movl(rax, Address(end_from, 8));
aoqi@0 1503 __ movl(Address(end_to, 8), rax);
aoqi@0 1504
aoqi@0 1505 __ addptr(end_from, 4);
aoqi@0 1506 __ addptr(end_to, 4);
aoqi@0 1507
aoqi@0 1508 // Check for and copy trailing word
aoqi@0 1509 __ BIND(L_copy_2_bytes);
aoqi@0 1510 __ testl(byte_count, 2);
aoqi@0 1511 __ jccb(Assembler::zero, L_copy_byte);
aoqi@0 1512 __ movw(rax, Address(end_from, 8));
aoqi@0 1513 __ movw(Address(end_to, 8), rax);
aoqi@0 1514
aoqi@0 1515 __ addptr(end_from, 2);
aoqi@0 1516 __ addptr(end_to, 2);
aoqi@0 1517
aoqi@0 1518 // Check for and copy trailing byte
aoqi@0 1519 __ BIND(L_copy_byte);
aoqi@0 1520 __ testl(byte_count, 1);
aoqi@0 1521 __ jccb(Assembler::zero, L_exit);
aoqi@0 1522 __ movb(rax, Address(end_from, 8));
aoqi@0 1523 __ movb(Address(end_to, 8), rax);
aoqi@0 1524
aoqi@0 1525 __ BIND(L_exit);
aoqi@0 1526 restore_arg_regs();
aoqi@0 1527 inc_counter_np(SharedRuntime::_jbyte_array_copy_ctr); // Update counter after rscratch1 is free
aoqi@0 1528 __ xorptr(rax, rax); // return 0
aoqi@0 1529 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 1530 __ ret(0);
aoqi@0 1531
aoqi@0 1532 // Copy in multi-bytes chunks
aoqi@0 1533 copy_bytes_forward(end_from, end_to, qword_count, rax, L_copy_bytes, L_copy_8_bytes);
aoqi@0 1534 __ jmp(L_copy_4_bytes);
aoqi@0 1535
aoqi@0 1536 return start;
aoqi@0 1537 }
aoqi@0 1538
aoqi@0 1539 // Arguments:
aoqi@0 1540 // aligned - true => Input and output aligned on a HeapWord == 8-byte boundary
aoqi@0 1541 // ignored
aoqi@0 1542 // name - stub name string
aoqi@0 1543 //
aoqi@0 1544 // Inputs:
aoqi@0 1545 // c_rarg0 - source array address
aoqi@0 1546 // c_rarg1 - destination array address
aoqi@0 1547 // c_rarg2 - element count, treated as ssize_t, can be zero
aoqi@0 1548 //
aoqi@0 1549 // If 'from' and/or 'to' are aligned on 4-, 2-, or 1-byte boundaries,
aoqi@0 1550 // we let the hardware handle it. The one to eight bytes within words,
aoqi@0 1551 // dwords or qwords that span cache line boundaries will still be loaded
aoqi@0 1552 // and stored atomically.
aoqi@0 1553 //
aoqi@0 1554 address generate_conjoint_byte_copy(bool aligned, address nooverlap_target,
aoqi@0 1555 address* entry, const char *name) {
aoqi@0 1556 __ align(CodeEntryAlignment);
aoqi@0 1557 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 1558 address start = __ pc();
aoqi@0 1559
aoqi@0 1560 Label L_copy_bytes, L_copy_8_bytes, L_copy_4_bytes, L_copy_2_bytes;
aoqi@0 1561 const Register from = rdi; // source array address
aoqi@0 1562 const Register to = rsi; // destination array address
aoqi@0 1563 const Register count = rdx; // elements count
aoqi@0 1564 const Register byte_count = rcx;
aoqi@0 1565 const Register qword_count = count;
aoqi@0 1566
aoqi@0 1567 __ enter(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 1568 assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int.
aoqi@0 1569
aoqi@0 1570 if (entry != NULL) {
aoqi@0 1571 *entry = __ pc();
aoqi@0 1572 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
aoqi@0 1573 BLOCK_COMMENT("Entry:");
aoqi@0 1574 }
aoqi@0 1575
aoqi@0 1576 array_overlap_test(nooverlap_target, Address::times_1);
aoqi@0 1577 setup_arg_regs(); // from => rdi, to => rsi, count => rdx
aoqi@0 1578 // r9 and r10 may be used to save non-volatile registers
aoqi@0 1579
aoqi@0 1580 // 'from', 'to' and 'count' are now valid
aoqi@0 1581 __ movptr(byte_count, count);
aoqi@0 1582 __ shrptr(count, 3); // count => qword_count
aoqi@0 1583
aoqi@0 1584 // Copy from high to low addresses.
aoqi@0 1585
aoqi@0 1586 // Check for and copy trailing byte
aoqi@0 1587 __ testl(byte_count, 1);
aoqi@0 1588 __ jcc(Assembler::zero, L_copy_2_bytes);
aoqi@0 1589 __ movb(rax, Address(from, byte_count, Address::times_1, -1));
aoqi@0 1590 __ movb(Address(to, byte_count, Address::times_1, -1), rax);
aoqi@0 1591 __ decrement(byte_count); // Adjust for possible trailing word
aoqi@0 1592
aoqi@0 1593 // Check for and copy trailing word
aoqi@0 1594 __ BIND(L_copy_2_bytes);
aoqi@0 1595 __ testl(byte_count, 2);
aoqi@0 1596 __ jcc(Assembler::zero, L_copy_4_bytes);
aoqi@0 1597 __ movw(rax, Address(from, byte_count, Address::times_1, -2));
aoqi@0 1598 __ movw(Address(to, byte_count, Address::times_1, -2), rax);
aoqi@0 1599
aoqi@0 1600 // Check for and copy trailing dword
aoqi@0 1601 __ BIND(L_copy_4_bytes);
aoqi@0 1602 __ testl(byte_count, 4);
aoqi@0 1603 __ jcc(Assembler::zero, L_copy_bytes);
aoqi@0 1604 __ movl(rax, Address(from, qword_count, Address::times_8));
aoqi@0 1605 __ movl(Address(to, qword_count, Address::times_8), rax);
aoqi@0 1606 __ jmp(L_copy_bytes);
aoqi@0 1607
aoqi@0 1608 // Copy trailing qwords
aoqi@0 1609 __ BIND(L_copy_8_bytes);
aoqi@0 1610 __ movq(rax, Address(from, qword_count, Address::times_8, -8));
aoqi@0 1611 __ movq(Address(to, qword_count, Address::times_8, -8), rax);
aoqi@0 1612 __ decrement(qword_count);
aoqi@0 1613 __ jcc(Assembler::notZero, L_copy_8_bytes);
aoqi@0 1614
aoqi@0 1615 restore_arg_regs();
aoqi@0 1616 inc_counter_np(SharedRuntime::_jbyte_array_copy_ctr); // Update counter after rscratch1 is free
aoqi@0 1617 __ xorptr(rax, rax); // return 0
aoqi@0 1618 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 1619 __ ret(0);
aoqi@0 1620
aoqi@0 1621 // Copy in multi-bytes chunks
aoqi@0 1622 copy_bytes_backward(from, to, qword_count, rax, L_copy_bytes, L_copy_8_bytes);
aoqi@0 1623
aoqi@0 1624 restore_arg_regs();
aoqi@0 1625 inc_counter_np(SharedRuntime::_jbyte_array_copy_ctr); // Update counter after rscratch1 is free
aoqi@0 1626 __ xorptr(rax, rax); // return 0
aoqi@0 1627 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 1628 __ ret(0);
aoqi@0 1629
aoqi@0 1630 return start;
aoqi@0 1631 }
aoqi@0 1632
aoqi@0 1633 // Arguments:
aoqi@0 1634 // aligned - true => Input and output aligned on a HeapWord == 8-byte boundary
aoqi@0 1635 // ignored
aoqi@0 1636 // name - stub name string
aoqi@0 1637 //
aoqi@0 1638 // Inputs:
aoqi@0 1639 // c_rarg0 - source array address
aoqi@0 1640 // c_rarg1 - destination array address
aoqi@0 1641 // c_rarg2 - element count, treated as ssize_t, can be zero
aoqi@0 1642 //
aoqi@0 1643 // If 'from' and/or 'to' are aligned on 4- or 2-byte boundaries, we
aoqi@0 1644 // let the hardware handle it. The two or four words within dwords
aoqi@0 1645 // or qwords that span cache line boundaries will still be loaded
aoqi@0 1646 // and stored atomically.
aoqi@0 1647 //
aoqi@0 1648 // Side Effects:
aoqi@0 1649 // disjoint_short_copy_entry is set to the no-overlap entry point
aoqi@0 1650 // used by generate_conjoint_short_copy().
aoqi@0 1651 //
aoqi@0 1652 address generate_disjoint_short_copy(bool aligned, address *entry, const char *name) {
aoqi@0 1653 __ align(CodeEntryAlignment);
aoqi@0 1654 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 1655 address start = __ pc();
aoqi@0 1656
aoqi@0 1657 Label L_copy_bytes, L_copy_8_bytes, L_copy_4_bytes,L_copy_2_bytes,L_exit;
aoqi@0 1658 const Register from = rdi; // source array address
aoqi@0 1659 const Register to = rsi; // destination array address
aoqi@0 1660 const Register count = rdx; // elements count
aoqi@0 1661 const Register word_count = rcx;
aoqi@0 1662 const Register qword_count = count;
aoqi@0 1663 const Register end_from = from; // source array end address
aoqi@0 1664 const Register end_to = to; // destination array end address
aoqi@0 1665 // End pointers are inclusive, and if count is not zero they point
aoqi@0 1666 // to the last unit copied: end_to[0] := end_from[0]
aoqi@0 1667
aoqi@0 1668 __ enter(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 1669 assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int.
aoqi@0 1670
aoqi@0 1671 if (entry != NULL) {
aoqi@0 1672 *entry = __ pc();
aoqi@0 1673 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
aoqi@0 1674 BLOCK_COMMENT("Entry:");
aoqi@0 1675 }
aoqi@0 1676
aoqi@0 1677 setup_arg_regs(); // from => rdi, to => rsi, count => rdx
aoqi@0 1678 // r9 and r10 may be used to save non-volatile registers
aoqi@0 1679
aoqi@0 1680 // 'from', 'to' and 'count' are now valid
aoqi@0 1681 __ movptr(word_count, count);
aoqi@0 1682 __ shrptr(count, 2); // count => qword_count
aoqi@0 1683
aoqi@0 1684 // Copy from low to high addresses. Use 'to' as scratch.
aoqi@0 1685 __ lea(end_from, Address(from, qword_count, Address::times_8, -8));
aoqi@0 1686 __ lea(end_to, Address(to, qword_count, Address::times_8, -8));
aoqi@0 1687 __ negptr(qword_count);
aoqi@0 1688 __ jmp(L_copy_bytes);
aoqi@0 1689
aoqi@0 1690 // Copy trailing qwords
aoqi@0 1691 __ BIND(L_copy_8_bytes);
aoqi@0 1692 __ movq(rax, Address(end_from, qword_count, Address::times_8, 8));
aoqi@0 1693 __ movq(Address(end_to, qword_count, Address::times_8, 8), rax);
aoqi@0 1694 __ increment(qword_count);
aoqi@0 1695 __ jcc(Assembler::notZero, L_copy_8_bytes);
aoqi@0 1696
aoqi@0 1697 // Original 'dest' is trashed, so we can't use it as a
aoqi@0 1698 // base register for a possible trailing word copy
aoqi@0 1699
aoqi@0 1700 // Check for and copy trailing dword
aoqi@0 1701 __ BIND(L_copy_4_bytes);
aoqi@0 1702 __ testl(word_count, 2);
aoqi@0 1703 __ jccb(Assembler::zero, L_copy_2_bytes);
aoqi@0 1704 __ movl(rax, Address(end_from, 8));
aoqi@0 1705 __ movl(Address(end_to, 8), rax);
aoqi@0 1706
aoqi@0 1707 __ addptr(end_from, 4);
aoqi@0 1708 __ addptr(end_to, 4);
aoqi@0 1709
aoqi@0 1710 // Check for and copy trailing word
aoqi@0 1711 __ BIND(L_copy_2_bytes);
aoqi@0 1712 __ testl(word_count, 1);
aoqi@0 1713 __ jccb(Assembler::zero, L_exit);
aoqi@0 1714 __ movw(rax, Address(end_from, 8));
aoqi@0 1715 __ movw(Address(end_to, 8), rax);
aoqi@0 1716
aoqi@0 1717 __ BIND(L_exit);
aoqi@0 1718 restore_arg_regs();
aoqi@0 1719 inc_counter_np(SharedRuntime::_jshort_array_copy_ctr); // Update counter after rscratch1 is free
aoqi@0 1720 __ xorptr(rax, rax); // return 0
aoqi@0 1721 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 1722 __ ret(0);
aoqi@0 1723
aoqi@0 1724 // Copy in multi-bytes chunks
aoqi@0 1725 copy_bytes_forward(end_from, end_to, qword_count, rax, L_copy_bytes, L_copy_8_bytes);
aoqi@0 1726 __ jmp(L_copy_4_bytes);
aoqi@0 1727
aoqi@0 1728 return start;
aoqi@0 1729 }
aoqi@0 1730
aoqi@0 1731 address generate_fill(BasicType t, bool aligned, const char *name) {
aoqi@0 1732 __ align(CodeEntryAlignment);
aoqi@0 1733 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 1734 address start = __ pc();
aoqi@0 1735
aoqi@0 1736 BLOCK_COMMENT("Entry:");
aoqi@0 1737
aoqi@0 1738 const Register to = c_rarg0; // source array address
aoqi@0 1739 const Register value = c_rarg1; // value
aoqi@0 1740 const Register count = c_rarg2; // elements count
aoqi@0 1741
aoqi@0 1742 __ enter(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 1743
aoqi@0 1744 __ generate_fill(t, aligned, to, value, count, rax, xmm0);
aoqi@0 1745
aoqi@0 1746 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 1747 __ ret(0);
aoqi@0 1748 return start;
aoqi@0 1749 }
aoqi@0 1750
aoqi@0 1751 // Arguments:
aoqi@0 1752 // aligned - true => Input and output aligned on a HeapWord == 8-byte boundary
aoqi@0 1753 // ignored
aoqi@0 1754 // name - stub name string
aoqi@0 1755 //
aoqi@0 1756 // Inputs:
aoqi@0 1757 // c_rarg0 - source array address
aoqi@0 1758 // c_rarg1 - destination array address
aoqi@0 1759 // c_rarg2 - element count, treated as ssize_t, can be zero
aoqi@0 1760 //
aoqi@0 1761 // If 'from' and/or 'to' are aligned on 4- or 2-byte boundaries, we
aoqi@0 1762 // let the hardware handle it. The two or four words within dwords
aoqi@0 1763 // or qwords that span cache line boundaries will still be loaded
aoqi@0 1764 // and stored atomically.
aoqi@0 1765 //
aoqi@0 1766 address generate_conjoint_short_copy(bool aligned, address nooverlap_target,
aoqi@0 1767 address *entry, const char *name) {
aoqi@0 1768 __ align(CodeEntryAlignment);
aoqi@0 1769 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 1770 address start = __ pc();
aoqi@0 1771
aoqi@0 1772 Label L_copy_bytes, L_copy_8_bytes, L_copy_4_bytes;
aoqi@0 1773 const Register from = rdi; // source array address
aoqi@0 1774 const Register to = rsi; // destination array address
aoqi@0 1775 const Register count = rdx; // elements count
aoqi@0 1776 const Register word_count = rcx;
aoqi@0 1777 const Register qword_count = count;
aoqi@0 1778
aoqi@0 1779 __ enter(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 1780 assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int.
aoqi@0 1781
aoqi@0 1782 if (entry != NULL) {
aoqi@0 1783 *entry = __ pc();
aoqi@0 1784 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
aoqi@0 1785 BLOCK_COMMENT("Entry:");
aoqi@0 1786 }
aoqi@0 1787
aoqi@0 1788 array_overlap_test(nooverlap_target, Address::times_2);
aoqi@0 1789 setup_arg_regs(); // from => rdi, to => rsi, count => rdx
aoqi@0 1790 // r9 and r10 may be used to save non-volatile registers
aoqi@0 1791
aoqi@0 1792 // 'from', 'to' and 'count' are now valid
aoqi@0 1793 __ movptr(word_count, count);
aoqi@0 1794 __ shrptr(count, 2); // count => qword_count
aoqi@0 1795
aoqi@0 1796 // Copy from high to low addresses. Use 'to' as scratch.
aoqi@0 1797
aoqi@0 1798 // Check for and copy trailing word
aoqi@0 1799 __ testl(word_count, 1);
aoqi@0 1800 __ jccb(Assembler::zero, L_copy_4_bytes);
aoqi@0 1801 __ movw(rax, Address(from, word_count, Address::times_2, -2));
aoqi@0 1802 __ movw(Address(to, word_count, Address::times_2, -2), rax);
aoqi@0 1803
aoqi@0 1804 // Check for and copy trailing dword
aoqi@0 1805 __ BIND(L_copy_4_bytes);
aoqi@0 1806 __ testl(word_count, 2);
aoqi@0 1807 __ jcc(Assembler::zero, L_copy_bytes);
aoqi@0 1808 __ movl(rax, Address(from, qword_count, Address::times_8));
aoqi@0 1809 __ movl(Address(to, qword_count, Address::times_8), rax);
aoqi@0 1810 __ jmp(L_copy_bytes);
aoqi@0 1811
aoqi@0 1812 // Copy trailing qwords
aoqi@0 1813 __ BIND(L_copy_8_bytes);
aoqi@0 1814 __ movq(rax, Address(from, qword_count, Address::times_8, -8));
aoqi@0 1815 __ movq(Address(to, qword_count, Address::times_8, -8), rax);
aoqi@0 1816 __ decrement(qword_count);
aoqi@0 1817 __ jcc(Assembler::notZero, L_copy_8_bytes);
aoqi@0 1818
aoqi@0 1819 restore_arg_regs();
aoqi@0 1820 inc_counter_np(SharedRuntime::_jshort_array_copy_ctr); // Update counter after rscratch1 is free
aoqi@0 1821 __ xorptr(rax, rax); // return 0
aoqi@0 1822 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 1823 __ ret(0);
aoqi@0 1824
aoqi@0 1825 // Copy in multi-bytes chunks
aoqi@0 1826 copy_bytes_backward(from, to, qword_count, rax, L_copy_bytes, L_copy_8_bytes);
aoqi@0 1827
aoqi@0 1828 restore_arg_regs();
aoqi@0 1829 inc_counter_np(SharedRuntime::_jshort_array_copy_ctr); // Update counter after rscratch1 is free
aoqi@0 1830 __ xorptr(rax, rax); // return 0
aoqi@0 1831 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 1832 __ ret(0);
aoqi@0 1833
aoqi@0 1834 return start;
aoqi@0 1835 }
aoqi@0 1836
aoqi@0 1837 // Arguments:
aoqi@0 1838 // aligned - true => Input and output aligned on a HeapWord == 8-byte boundary
aoqi@0 1839 // ignored
aoqi@0 1840 // is_oop - true => oop array, so generate store check code
aoqi@0 1841 // name - stub name string
aoqi@0 1842 //
aoqi@0 1843 // Inputs:
aoqi@0 1844 // c_rarg0 - source array address
aoqi@0 1845 // c_rarg1 - destination array address
aoqi@0 1846 // c_rarg2 - element count, treated as ssize_t, can be zero
aoqi@0 1847 //
aoqi@0 1848 // If 'from' and/or 'to' are aligned on 4-byte boundaries, we let
aoqi@0 1849 // the hardware handle it. The two dwords within qwords that span
aoqi@0 1850 // cache line boundaries will still be loaded and stored atomicly.
aoqi@0 1851 //
aoqi@0 1852 // Side Effects:
aoqi@0 1853 // disjoint_int_copy_entry is set to the no-overlap entry point
aoqi@0 1854 // used by generate_conjoint_int_oop_copy().
aoqi@0 1855 //
aoqi@0 1856 address generate_disjoint_int_oop_copy(bool aligned, bool is_oop, address* entry,
aoqi@0 1857 const char *name, bool dest_uninitialized = false) {
aoqi@0 1858 __ align(CodeEntryAlignment);
aoqi@0 1859 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 1860 address start = __ pc();
aoqi@0 1861
aoqi@0 1862 Label L_copy_bytes, L_copy_8_bytes, L_copy_4_bytes, L_exit;
aoqi@0 1863 const Register from = rdi; // source array address
aoqi@0 1864 const Register to = rsi; // destination array address
aoqi@0 1865 const Register count = rdx; // elements count
aoqi@0 1866 const Register dword_count = rcx;
aoqi@0 1867 const Register qword_count = count;
aoqi@0 1868 const Register end_from = from; // source array end address
aoqi@0 1869 const Register end_to = to; // destination array end address
aoqi@0 1870 const Register saved_to = r11; // saved destination array address
aoqi@0 1871 // End pointers are inclusive, and if count is not zero they point
aoqi@0 1872 // to the last unit copied: end_to[0] := end_from[0]
aoqi@0 1873
aoqi@0 1874 __ enter(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 1875 assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int.
aoqi@0 1876
aoqi@0 1877 if (entry != NULL) {
aoqi@0 1878 *entry = __ pc();
aoqi@0 1879 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
aoqi@0 1880 BLOCK_COMMENT("Entry:");
aoqi@0 1881 }
aoqi@0 1882
aoqi@0 1883 setup_arg_regs(); // from => rdi, to => rsi, count => rdx
aoqi@0 1884 // r9 and r10 may be used to save non-volatile registers
aoqi@0 1885 if (is_oop) {
aoqi@0 1886 __ movq(saved_to, to);
aoqi@0 1887 gen_write_ref_array_pre_barrier(to, count, dest_uninitialized);
aoqi@0 1888 }
aoqi@0 1889
aoqi@0 1890 // 'from', 'to' and 'count' are now valid
aoqi@0 1891 __ movptr(dword_count, count);
aoqi@0 1892 __ shrptr(count, 1); // count => qword_count
aoqi@0 1893
aoqi@0 1894 // Copy from low to high addresses. Use 'to' as scratch.
aoqi@0 1895 __ lea(end_from, Address(from, qword_count, Address::times_8, -8));
aoqi@0 1896 __ lea(end_to, Address(to, qword_count, Address::times_8, -8));
aoqi@0 1897 __ negptr(qword_count);
aoqi@0 1898 __ jmp(L_copy_bytes);
aoqi@0 1899
aoqi@0 1900 // Copy trailing qwords
aoqi@0 1901 __ BIND(L_copy_8_bytes);
aoqi@0 1902 __ movq(rax, Address(end_from, qword_count, Address::times_8, 8));
aoqi@0 1903 __ movq(Address(end_to, qword_count, Address::times_8, 8), rax);
aoqi@0 1904 __ increment(qword_count);
aoqi@0 1905 __ jcc(Assembler::notZero, L_copy_8_bytes);
aoqi@0 1906
aoqi@0 1907 // Check for and copy trailing dword
aoqi@0 1908 __ BIND(L_copy_4_bytes);
aoqi@0 1909 __ testl(dword_count, 1); // Only byte test since the value is 0 or 1
aoqi@0 1910 __ jccb(Assembler::zero, L_exit);
aoqi@0 1911 __ movl(rax, Address(end_from, 8));
aoqi@0 1912 __ movl(Address(end_to, 8), rax);
aoqi@0 1913
aoqi@0 1914 __ BIND(L_exit);
aoqi@0 1915 if (is_oop) {
aoqi@0 1916 gen_write_ref_array_post_barrier(saved_to, dword_count, rax);
aoqi@0 1917 }
aoqi@0 1918 restore_arg_regs();
aoqi@0 1919 inc_counter_np(SharedRuntime::_jint_array_copy_ctr); // Update counter after rscratch1 is free
aoqi@0 1920 __ xorptr(rax, rax); // return 0
aoqi@0 1921 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 1922 __ ret(0);
aoqi@0 1923
aoqi@0 1924 // Copy in multi-bytes chunks
aoqi@0 1925 copy_bytes_forward(end_from, end_to, qword_count, rax, L_copy_bytes, L_copy_8_bytes);
aoqi@0 1926 __ jmp(L_copy_4_bytes);
aoqi@0 1927
aoqi@0 1928 return start;
aoqi@0 1929 }
aoqi@0 1930
aoqi@0 1931 // Arguments:
aoqi@0 1932 // aligned - true => Input and output aligned on a HeapWord == 8-byte boundary
aoqi@0 1933 // ignored
aoqi@0 1934 // is_oop - true => oop array, so generate store check code
aoqi@0 1935 // name - stub name string
aoqi@0 1936 //
aoqi@0 1937 // Inputs:
aoqi@0 1938 // c_rarg0 - source array address
aoqi@0 1939 // c_rarg1 - destination array address
aoqi@0 1940 // c_rarg2 - element count, treated as ssize_t, can be zero
aoqi@0 1941 //
aoqi@0 1942 // If 'from' and/or 'to' are aligned on 4-byte boundaries, we let
aoqi@0 1943 // the hardware handle it. The two dwords within qwords that span
aoqi@0 1944 // cache line boundaries will still be loaded and stored atomicly.
aoqi@0 1945 //
aoqi@0 1946 address generate_conjoint_int_oop_copy(bool aligned, bool is_oop, address nooverlap_target,
aoqi@0 1947 address *entry, const char *name,
aoqi@0 1948 bool dest_uninitialized = false) {
aoqi@0 1949 __ align(CodeEntryAlignment);
aoqi@0 1950 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 1951 address start = __ pc();
aoqi@0 1952
aoqi@0 1953 Label L_copy_bytes, L_copy_8_bytes, L_copy_2_bytes, L_exit;
aoqi@0 1954 const Register from = rdi; // source array address
aoqi@0 1955 const Register to = rsi; // destination array address
aoqi@0 1956 const Register count = rdx; // elements count
aoqi@0 1957 const Register dword_count = rcx;
aoqi@0 1958 const Register qword_count = count;
aoqi@0 1959
aoqi@0 1960 __ enter(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 1961 assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int.
aoqi@0 1962
aoqi@0 1963 if (entry != NULL) {
aoqi@0 1964 *entry = __ pc();
aoqi@0 1965 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
aoqi@0 1966 BLOCK_COMMENT("Entry:");
aoqi@0 1967 }
aoqi@0 1968
aoqi@0 1969 array_overlap_test(nooverlap_target, Address::times_4);
aoqi@0 1970 setup_arg_regs(); // from => rdi, to => rsi, count => rdx
aoqi@0 1971 // r9 and r10 may be used to save non-volatile registers
aoqi@0 1972
aoqi@0 1973 if (is_oop) {
aoqi@0 1974 // no registers are destroyed by this call
aoqi@0 1975 gen_write_ref_array_pre_barrier(to, count, dest_uninitialized);
aoqi@0 1976 }
aoqi@0 1977
aoqi@0 1978 assert_clean_int(count, rax); // Make sure 'count' is clean int.
aoqi@0 1979 // 'from', 'to' and 'count' are now valid
aoqi@0 1980 __ movptr(dword_count, count);
aoqi@0 1981 __ shrptr(count, 1); // count => qword_count
aoqi@0 1982
aoqi@0 1983 // Copy from high to low addresses. Use 'to' as scratch.
aoqi@0 1984
aoqi@0 1985 // Check for and copy trailing dword
aoqi@0 1986 __ testl(dword_count, 1);
aoqi@0 1987 __ jcc(Assembler::zero, L_copy_bytes);
aoqi@0 1988 __ movl(rax, Address(from, dword_count, Address::times_4, -4));
aoqi@0 1989 __ movl(Address(to, dword_count, Address::times_4, -4), rax);
aoqi@0 1990 __ jmp(L_copy_bytes);
aoqi@0 1991
aoqi@0 1992 // Copy trailing qwords
aoqi@0 1993 __ BIND(L_copy_8_bytes);
aoqi@0 1994 __ movq(rax, Address(from, qword_count, Address::times_8, -8));
aoqi@0 1995 __ movq(Address(to, qword_count, Address::times_8, -8), rax);
aoqi@0 1996 __ decrement(qword_count);
aoqi@0 1997 __ jcc(Assembler::notZero, L_copy_8_bytes);
aoqi@0 1998
aoqi@0 1999 if (is_oop) {
aoqi@0 2000 __ jmp(L_exit);
aoqi@0 2001 }
aoqi@0 2002 restore_arg_regs();
aoqi@0 2003 inc_counter_np(SharedRuntime::_jint_array_copy_ctr); // Update counter after rscratch1 is free
aoqi@0 2004 __ xorptr(rax, rax); // return 0
aoqi@0 2005 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 2006 __ ret(0);
aoqi@0 2007
aoqi@0 2008 // Copy in multi-bytes chunks
aoqi@0 2009 copy_bytes_backward(from, to, qword_count, rax, L_copy_bytes, L_copy_8_bytes);
aoqi@0 2010
aoqi@0 2011 __ BIND(L_exit);
aoqi@0 2012 if (is_oop) {
aoqi@0 2013 gen_write_ref_array_post_barrier(to, dword_count, rax);
aoqi@0 2014 }
aoqi@0 2015 restore_arg_regs();
aoqi@0 2016 inc_counter_np(SharedRuntime::_jint_array_copy_ctr); // Update counter after rscratch1 is free
aoqi@0 2017 __ xorptr(rax, rax); // return 0
aoqi@0 2018 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 2019 __ ret(0);
aoqi@0 2020
aoqi@0 2021 return start;
aoqi@0 2022 }
aoqi@0 2023
aoqi@0 2024 // Arguments:
aoqi@0 2025 // aligned - true => Input and output aligned on a HeapWord boundary == 8 bytes
aoqi@0 2026 // ignored
aoqi@0 2027 // is_oop - true => oop array, so generate store check code
aoqi@0 2028 // name - stub name string
aoqi@0 2029 //
aoqi@0 2030 // Inputs:
aoqi@0 2031 // c_rarg0 - source array address
aoqi@0 2032 // c_rarg1 - destination array address
aoqi@0 2033 // c_rarg2 - element count, treated as ssize_t, can be zero
aoqi@0 2034 //
aoqi@0 2035 // Side Effects:
aoqi@0 2036 // disjoint_oop_copy_entry or disjoint_long_copy_entry is set to the
aoqi@0 2037 // no-overlap entry point used by generate_conjoint_long_oop_copy().
aoqi@0 2038 //
aoqi@0 2039 address generate_disjoint_long_oop_copy(bool aligned, bool is_oop, address *entry,
aoqi@0 2040 const char *name, bool dest_uninitialized = false) {
aoqi@0 2041 __ align(CodeEntryAlignment);
aoqi@0 2042 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 2043 address start = __ pc();
aoqi@0 2044
aoqi@0 2045 Label L_copy_bytes, L_copy_8_bytes, L_exit;
aoqi@0 2046 const Register from = rdi; // source array address
aoqi@0 2047 const Register to = rsi; // destination array address
aoqi@0 2048 const Register qword_count = rdx; // elements count
aoqi@0 2049 const Register end_from = from; // source array end address
aoqi@0 2050 const Register end_to = rcx; // destination array end address
aoqi@0 2051 const Register saved_to = to;
aoqi@0 2052 const Register saved_count = r11;
aoqi@0 2053 // End pointers are inclusive, and if count is not zero they point
aoqi@0 2054 // to the last unit copied: end_to[0] := end_from[0]
aoqi@0 2055
aoqi@0 2056 __ enter(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 2057 // Save no-overlap entry point for generate_conjoint_long_oop_copy()
aoqi@0 2058 assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int.
aoqi@0 2059
aoqi@0 2060 if (entry != NULL) {
aoqi@0 2061 *entry = __ pc();
aoqi@0 2062 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
aoqi@0 2063 BLOCK_COMMENT("Entry:");
aoqi@0 2064 }
aoqi@0 2065
aoqi@0 2066 setup_arg_regs(); // from => rdi, to => rsi, count => rdx
aoqi@0 2067 // r9 and r10 may be used to save non-volatile registers
aoqi@0 2068 // 'from', 'to' and 'qword_count' are now valid
aoqi@0 2069 if (is_oop) {
aoqi@0 2070 // Save to and count for store barrier
aoqi@0 2071 __ movptr(saved_count, qword_count);
aoqi@0 2072 // no registers are destroyed by this call
aoqi@0 2073 gen_write_ref_array_pre_barrier(to, qword_count, dest_uninitialized);
aoqi@0 2074 }
aoqi@0 2075
aoqi@0 2076 // Copy from low to high addresses. Use 'to' as scratch.
aoqi@0 2077 __ lea(end_from, Address(from, qword_count, Address::times_8, -8));
aoqi@0 2078 __ lea(end_to, Address(to, qword_count, Address::times_8, -8));
aoqi@0 2079 __ negptr(qword_count);
aoqi@0 2080 __ jmp(L_copy_bytes);
aoqi@0 2081
aoqi@0 2082 // Copy trailing qwords
aoqi@0 2083 __ BIND(L_copy_8_bytes);
aoqi@0 2084 __ movq(rax, Address(end_from, qword_count, Address::times_8, 8));
aoqi@0 2085 __ movq(Address(end_to, qword_count, Address::times_8, 8), rax);
aoqi@0 2086 __ increment(qword_count);
aoqi@0 2087 __ jcc(Assembler::notZero, L_copy_8_bytes);
aoqi@0 2088
aoqi@0 2089 if (is_oop) {
aoqi@0 2090 __ jmp(L_exit);
aoqi@0 2091 } else {
aoqi@0 2092 restore_arg_regs();
aoqi@0 2093 inc_counter_np(SharedRuntime::_jlong_array_copy_ctr); // Update counter after rscratch1 is free
aoqi@0 2094 __ xorptr(rax, rax); // return 0
aoqi@0 2095 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 2096 __ ret(0);
aoqi@0 2097 }
aoqi@0 2098
aoqi@0 2099 // Copy in multi-bytes chunks
aoqi@0 2100 copy_bytes_forward(end_from, end_to, qword_count, rax, L_copy_bytes, L_copy_8_bytes);
aoqi@0 2101
aoqi@0 2102 if (is_oop) {
aoqi@0 2103 __ BIND(L_exit);
aoqi@0 2104 gen_write_ref_array_post_barrier(saved_to, saved_count, rax);
aoqi@0 2105 }
aoqi@0 2106 restore_arg_regs();
aoqi@0 2107 if (is_oop) {
aoqi@0 2108 inc_counter_np(SharedRuntime::_oop_array_copy_ctr); // Update counter after rscratch1 is free
aoqi@0 2109 } else {
aoqi@0 2110 inc_counter_np(SharedRuntime::_jlong_array_copy_ctr); // Update counter after rscratch1 is free
aoqi@0 2111 }
aoqi@0 2112 __ xorptr(rax, rax); // return 0
aoqi@0 2113 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 2114 __ ret(0);
aoqi@0 2115
aoqi@0 2116 return start;
aoqi@0 2117 }
aoqi@0 2118
aoqi@0 2119 // Arguments:
aoqi@0 2120 // aligned - true => Input and output aligned on a HeapWord boundary == 8 bytes
aoqi@0 2121 // ignored
aoqi@0 2122 // is_oop - true => oop array, so generate store check code
aoqi@0 2123 // name - stub name string
aoqi@0 2124 //
aoqi@0 2125 // Inputs:
aoqi@0 2126 // c_rarg0 - source array address
aoqi@0 2127 // c_rarg1 - destination array address
aoqi@0 2128 // c_rarg2 - element count, treated as ssize_t, can be zero
aoqi@0 2129 //
aoqi@0 2130 address generate_conjoint_long_oop_copy(bool aligned, bool is_oop,
aoqi@0 2131 address nooverlap_target, address *entry,
aoqi@0 2132 const char *name, bool dest_uninitialized = false) {
aoqi@0 2133 __ align(CodeEntryAlignment);
aoqi@0 2134 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 2135 address start = __ pc();
aoqi@0 2136
aoqi@0 2137 Label L_copy_bytes, L_copy_8_bytes, L_exit;
aoqi@0 2138 const Register from = rdi; // source array address
aoqi@0 2139 const Register to = rsi; // destination array address
aoqi@0 2140 const Register qword_count = rdx; // elements count
aoqi@0 2141 const Register saved_count = rcx;
aoqi@0 2142
aoqi@0 2143 __ enter(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 2144 assert_clean_int(c_rarg2, rax); // Make sure 'count' is clean int.
aoqi@0 2145
aoqi@0 2146 if (entry != NULL) {
aoqi@0 2147 *entry = __ pc();
aoqi@0 2148 // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
aoqi@0 2149 BLOCK_COMMENT("Entry:");
aoqi@0 2150 }
aoqi@0 2151
aoqi@0 2152 array_overlap_test(nooverlap_target, Address::times_8);
aoqi@0 2153 setup_arg_regs(); // from => rdi, to => rsi, count => rdx
aoqi@0 2154 // r9 and r10 may be used to save non-volatile registers
aoqi@0 2155 // 'from', 'to' and 'qword_count' are now valid
aoqi@0 2156 if (is_oop) {
aoqi@0 2157 // Save to and count for store barrier
aoqi@0 2158 __ movptr(saved_count, qword_count);
aoqi@0 2159 // No registers are destroyed by this call
aoqi@0 2160 gen_write_ref_array_pre_barrier(to, saved_count, dest_uninitialized);
aoqi@0 2161 }
aoqi@0 2162
aoqi@0 2163 __ jmp(L_copy_bytes);
aoqi@0 2164
aoqi@0 2165 // Copy trailing qwords
aoqi@0 2166 __ BIND(L_copy_8_bytes);
aoqi@0 2167 __ movq(rax, Address(from, qword_count, Address::times_8, -8));
aoqi@0 2168 __ movq(Address(to, qword_count, Address::times_8, -8), rax);
aoqi@0 2169 __ decrement(qword_count);
aoqi@0 2170 __ jcc(Assembler::notZero, L_copy_8_bytes);
aoqi@0 2171
aoqi@0 2172 if (is_oop) {
aoqi@0 2173 __ jmp(L_exit);
aoqi@0 2174 } else {
aoqi@0 2175 restore_arg_regs();
aoqi@0 2176 inc_counter_np(SharedRuntime::_jlong_array_copy_ctr); // Update counter after rscratch1 is free
aoqi@0 2177 __ xorptr(rax, rax); // return 0
aoqi@0 2178 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 2179 __ ret(0);
aoqi@0 2180 }
aoqi@0 2181
aoqi@0 2182 // Copy in multi-bytes chunks
aoqi@0 2183 copy_bytes_backward(from, to, qword_count, rax, L_copy_bytes, L_copy_8_bytes);
aoqi@0 2184
aoqi@0 2185 if (is_oop) {
aoqi@0 2186 __ BIND(L_exit);
aoqi@0 2187 gen_write_ref_array_post_barrier(to, saved_count, rax);
aoqi@0 2188 }
aoqi@0 2189 restore_arg_regs();
aoqi@0 2190 if (is_oop) {
aoqi@0 2191 inc_counter_np(SharedRuntime::_oop_array_copy_ctr); // Update counter after rscratch1 is free
aoqi@0 2192 } else {
aoqi@0 2193 inc_counter_np(SharedRuntime::_jlong_array_copy_ctr); // Update counter after rscratch1 is free
aoqi@0 2194 }
aoqi@0 2195 __ xorptr(rax, rax); // return 0
aoqi@0 2196 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 2197 __ ret(0);
aoqi@0 2198
aoqi@0 2199 return start;
aoqi@0 2200 }
aoqi@0 2201
aoqi@0 2202
aoqi@0 2203 // Helper for generating a dynamic type check.
aoqi@0 2204 // Smashes no registers.
aoqi@0 2205 void generate_type_check(Register sub_klass,
aoqi@0 2206 Register super_check_offset,
aoqi@0 2207 Register super_klass,
aoqi@0 2208 Label& L_success) {
aoqi@0 2209 assert_different_registers(sub_klass, super_check_offset, super_klass);
aoqi@0 2210
aoqi@0 2211 BLOCK_COMMENT("type_check:");
aoqi@0 2212
aoqi@0 2213 Label L_miss;
aoqi@0 2214
aoqi@0 2215 __ check_klass_subtype_fast_path(sub_klass, super_klass, noreg, &L_success, &L_miss, NULL,
aoqi@0 2216 super_check_offset);
aoqi@0 2217 __ check_klass_subtype_slow_path(sub_klass, super_klass, noreg, noreg, &L_success, NULL);
aoqi@0 2218
aoqi@0 2219 // Fall through on failure!
aoqi@0 2220 __ BIND(L_miss);
aoqi@0 2221 }
aoqi@0 2222
aoqi@0 2223 //
aoqi@0 2224 // Generate checkcasting array copy stub
aoqi@0 2225 //
aoqi@0 2226 // Input:
aoqi@0 2227 // c_rarg0 - source array address
aoqi@0 2228 // c_rarg1 - destination array address
aoqi@0 2229 // c_rarg2 - element count, treated as ssize_t, can be zero
aoqi@0 2230 // c_rarg3 - size_t ckoff (super_check_offset)
aoqi@0 2231 // not Win64
aoqi@0 2232 // c_rarg4 - oop ckval (super_klass)
aoqi@0 2233 // Win64
aoqi@0 2234 // rsp+40 - oop ckval (super_klass)
aoqi@0 2235 //
aoqi@0 2236 // Output:
aoqi@0 2237 // rax == 0 - success
aoqi@0 2238 // rax == -1^K - failure, where K is partial transfer count
aoqi@0 2239 //
aoqi@0 2240 address generate_checkcast_copy(const char *name, address *entry,
aoqi@0 2241 bool dest_uninitialized = false) {
aoqi@0 2242
aoqi@0 2243 Label L_load_element, L_store_element, L_do_card_marks, L_done;
aoqi@0 2244
aoqi@0 2245 // Input registers (after setup_arg_regs)
aoqi@0 2246 const Register from = rdi; // source array address
aoqi@0 2247 const Register to = rsi; // destination array address
aoqi@0 2248 const Register length = rdx; // elements count
aoqi@0 2249 const Register ckoff = rcx; // super_check_offset
aoqi@0 2250 const Register ckval = r8; // super_klass
aoqi@0 2251
aoqi@0 2252 // Registers used as temps (r13, r14 are save-on-entry)
aoqi@0 2253 const Register end_from = from; // source array end address
aoqi@0 2254 const Register end_to = r13; // destination array end address
aoqi@0 2255 const Register count = rdx; // -(count_remaining)
aoqi@0 2256 const Register r14_length = r14; // saved copy of length
aoqi@0 2257 // End pointers are inclusive, and if length is not zero they point
aoqi@0 2258 // to the last unit copied: end_to[0] := end_from[0]
aoqi@0 2259
aoqi@0 2260 const Register rax_oop = rax; // actual oop copied
aoqi@0 2261 const Register r11_klass = r11; // oop._klass
aoqi@0 2262
aoqi@0 2263 //---------------------------------------------------------------
aoqi@0 2264 // Assembler stub will be used for this call to arraycopy
aoqi@0 2265 // if the two arrays are subtypes of Object[] but the
aoqi@0 2266 // destination array type is not equal to or a supertype
aoqi@0 2267 // of the source type. Each element must be separately
aoqi@0 2268 // checked.
aoqi@0 2269
aoqi@0 2270 __ align(CodeEntryAlignment);
aoqi@0 2271 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 2272 address start = __ pc();
aoqi@0 2273
aoqi@0 2274 __ enter(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 2275
aoqi@0 2276 #ifdef ASSERT
aoqi@0 2277 // caller guarantees that the arrays really are different
aoqi@0 2278 // otherwise, we would have to make conjoint checks
aoqi@0 2279 { Label L;
aoqi@0 2280 array_overlap_test(L, TIMES_OOP);
aoqi@0 2281 __ stop("checkcast_copy within a single array");
aoqi@0 2282 __ bind(L);
aoqi@0 2283 }
aoqi@0 2284 #endif //ASSERT
aoqi@0 2285
aoqi@0 2286 setup_arg_regs(4); // from => rdi, to => rsi, length => rdx
aoqi@0 2287 // ckoff => rcx, ckval => r8
aoqi@0 2288 // r9 and r10 may be used to save non-volatile registers
aoqi@0 2289 #ifdef _WIN64
aoqi@0 2290 // last argument (#4) is on stack on Win64
aoqi@0 2291 __ movptr(ckval, Address(rsp, 6 * wordSize));
aoqi@0 2292 #endif
aoqi@0 2293
aoqi@0 2294 // Caller of this entry point must set up the argument registers.
aoqi@0 2295 if (entry != NULL) {
aoqi@0 2296 *entry = __ pc();
aoqi@0 2297 BLOCK_COMMENT("Entry:");
aoqi@0 2298 }
aoqi@0 2299
aoqi@0 2300 // allocate spill slots for r13, r14
aoqi@0 2301 enum {
aoqi@0 2302 saved_r13_offset,
aoqi@0 2303 saved_r14_offset,
aoqi@0 2304 saved_rbp_offset
aoqi@0 2305 };
aoqi@0 2306 __ subptr(rsp, saved_rbp_offset * wordSize);
aoqi@0 2307 __ movptr(Address(rsp, saved_r13_offset * wordSize), r13);
aoqi@0 2308 __ movptr(Address(rsp, saved_r14_offset * wordSize), r14);
aoqi@0 2309
aoqi@0 2310 // check that int operands are properly extended to size_t
aoqi@0 2311 assert_clean_int(length, rax);
aoqi@0 2312 assert_clean_int(ckoff, rax);
aoqi@0 2313
aoqi@0 2314 #ifdef ASSERT
aoqi@0 2315 BLOCK_COMMENT("assert consistent ckoff/ckval");
aoqi@0 2316 // The ckoff and ckval must be mutually consistent,
aoqi@0 2317 // even though caller generates both.
aoqi@0 2318 { Label L;
aoqi@0 2319 int sco_offset = in_bytes(Klass::super_check_offset_offset());
aoqi@0 2320 __ cmpl(ckoff, Address(ckval, sco_offset));
aoqi@0 2321 __ jcc(Assembler::equal, L);
aoqi@0 2322 __ stop("super_check_offset inconsistent");
aoqi@0 2323 __ bind(L);
aoqi@0 2324 }
aoqi@0 2325 #endif //ASSERT
aoqi@0 2326
aoqi@0 2327 // Loop-invariant addresses. They are exclusive end pointers.
aoqi@0 2328 Address end_from_addr(from, length, TIMES_OOP, 0);
aoqi@0 2329 Address end_to_addr(to, length, TIMES_OOP, 0);
aoqi@0 2330 // Loop-variant addresses. They assume post-incremented count < 0.
aoqi@0 2331 Address from_element_addr(end_from, count, TIMES_OOP, 0);
aoqi@0 2332 Address to_element_addr(end_to, count, TIMES_OOP, 0);
aoqi@0 2333
aoqi@0 2334 gen_write_ref_array_pre_barrier(to, count, dest_uninitialized);
aoqi@0 2335
aoqi@0 2336 // Copy from low to high addresses, indexed from the end of each array.
aoqi@0 2337 __ lea(end_from, end_from_addr);
aoqi@0 2338 __ lea(end_to, end_to_addr);
aoqi@0 2339 __ movptr(r14_length, length); // save a copy of the length
aoqi@0 2340 assert(length == count, ""); // else fix next line:
aoqi@0 2341 __ negptr(count); // negate and test the length
aoqi@0 2342 __ jcc(Assembler::notZero, L_load_element);
aoqi@0 2343
aoqi@0 2344 // Empty array: Nothing to do.
aoqi@0 2345 __ xorptr(rax, rax); // return 0 on (trivial) success
aoqi@0 2346 __ jmp(L_done);
aoqi@0 2347
aoqi@0 2348 // ======== begin loop ========
aoqi@0 2349 // (Loop is rotated; its entry is L_load_element.)
aoqi@0 2350 // Loop control:
aoqi@0 2351 // for (count = -count; count != 0; count++)
aoqi@0 2352 // Base pointers src, dst are biased by 8*(count-1),to last element.
aoqi@0 2353 __ align(OptoLoopAlignment);
aoqi@0 2354
aoqi@0 2355 __ BIND(L_store_element);
aoqi@0 2356 __ store_heap_oop(to_element_addr, rax_oop); // store the oop
aoqi@0 2357 __ increment(count); // increment the count toward zero
aoqi@0 2358 __ jcc(Assembler::zero, L_do_card_marks);
aoqi@0 2359
aoqi@0 2360 // ======== loop entry is here ========
aoqi@0 2361 __ BIND(L_load_element);
aoqi@0 2362 __ load_heap_oop(rax_oop, from_element_addr); // load the oop
aoqi@0 2363 __ testptr(rax_oop, rax_oop);
aoqi@0 2364 __ jcc(Assembler::zero, L_store_element);
aoqi@0 2365
aoqi@0 2366 __ load_klass(r11_klass, rax_oop);// query the object klass
aoqi@0 2367 generate_type_check(r11_klass, ckoff, ckval, L_store_element);
aoqi@0 2368 // ======== end loop ========
aoqi@0 2369
aoqi@0 2370 // It was a real error; we must depend on the caller to finish the job.
aoqi@0 2371 // Register rdx = -1 * number of *remaining* oops, r14 = *total* oops.
aoqi@0 2372 // Emit GC store barriers for the oops we have copied (r14 + rdx),
aoqi@0 2373 // and report their number to the caller.
aoqi@0 2374 assert_different_registers(rax, r14_length, count, to, end_to, rcx, rscratch1);
aoqi@0 2375 Label L_post_barrier;
aoqi@0 2376 __ addptr(r14_length, count); // K = (original - remaining) oops
aoqi@0 2377 __ movptr(rax, r14_length); // save the value
aoqi@0 2378 __ notptr(rax); // report (-1^K) to caller (does not affect flags)
aoqi@0 2379 __ jccb(Assembler::notZero, L_post_barrier);
aoqi@0 2380 __ jmp(L_done); // K == 0, nothing was copied, skip post barrier
aoqi@0 2381
aoqi@0 2382 // Come here on success only.
aoqi@0 2383 __ BIND(L_do_card_marks);
aoqi@0 2384 __ xorptr(rax, rax); // return 0 on success
aoqi@0 2385
aoqi@0 2386 __ BIND(L_post_barrier);
aoqi@0 2387 gen_write_ref_array_post_barrier(to, r14_length, rscratch1);
aoqi@0 2388
aoqi@0 2389 // Common exit point (success or failure).
aoqi@0 2390 __ BIND(L_done);
aoqi@0 2391 __ movptr(r13, Address(rsp, saved_r13_offset * wordSize));
aoqi@0 2392 __ movptr(r14, Address(rsp, saved_r14_offset * wordSize));
aoqi@0 2393 restore_arg_regs();
aoqi@0 2394 inc_counter_np(SharedRuntime::_checkcast_array_copy_ctr); // Update counter after rscratch1 is free
aoqi@0 2395 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 2396 __ ret(0);
aoqi@0 2397
aoqi@0 2398 return start;
aoqi@0 2399 }
aoqi@0 2400
aoqi@0 2401 //
aoqi@0 2402 // Generate 'unsafe' array copy stub
aoqi@0 2403 // Though just as safe as the other stubs, it takes an unscaled
aoqi@0 2404 // size_t argument instead of an element count.
aoqi@0 2405 //
aoqi@0 2406 // Input:
aoqi@0 2407 // c_rarg0 - source array address
aoqi@0 2408 // c_rarg1 - destination array address
aoqi@0 2409 // c_rarg2 - byte count, treated as ssize_t, can be zero
aoqi@0 2410 //
aoqi@0 2411 // Examines the alignment of the operands and dispatches
aoqi@0 2412 // to a long, int, short, or byte copy loop.
aoqi@0 2413 //
aoqi@0 2414 address generate_unsafe_copy(const char *name,
aoqi@0 2415 address byte_copy_entry, address short_copy_entry,
aoqi@0 2416 address int_copy_entry, address long_copy_entry) {
aoqi@0 2417
aoqi@0 2418 Label L_long_aligned, L_int_aligned, L_short_aligned;
aoqi@0 2419
aoqi@0 2420 // Input registers (before setup_arg_regs)
aoqi@0 2421 const Register from = c_rarg0; // source array address
aoqi@0 2422 const Register to = c_rarg1; // destination array address
aoqi@0 2423 const Register size = c_rarg2; // byte count (size_t)
aoqi@0 2424
aoqi@0 2425 // Register used as a temp
aoqi@0 2426 const Register bits = rax; // test copy of low bits
aoqi@0 2427
aoqi@0 2428 __ align(CodeEntryAlignment);
aoqi@0 2429 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 2430 address start = __ pc();
aoqi@0 2431
aoqi@0 2432 __ enter(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 2433
aoqi@0 2434 // bump this on entry, not on exit:
aoqi@0 2435 inc_counter_np(SharedRuntime::_unsafe_array_copy_ctr);
aoqi@0 2436
aoqi@0 2437 __ mov(bits, from);
aoqi@0 2438 __ orptr(bits, to);
aoqi@0 2439 __ orptr(bits, size);
aoqi@0 2440
aoqi@0 2441 __ testb(bits, BytesPerLong-1);
aoqi@0 2442 __ jccb(Assembler::zero, L_long_aligned);
aoqi@0 2443
aoqi@0 2444 __ testb(bits, BytesPerInt-1);
aoqi@0 2445 __ jccb(Assembler::zero, L_int_aligned);
aoqi@0 2446
aoqi@0 2447 __ testb(bits, BytesPerShort-1);
aoqi@0 2448 __ jump_cc(Assembler::notZero, RuntimeAddress(byte_copy_entry));
aoqi@0 2449
aoqi@0 2450 __ BIND(L_short_aligned);
aoqi@0 2451 __ shrptr(size, LogBytesPerShort); // size => short_count
aoqi@0 2452 __ jump(RuntimeAddress(short_copy_entry));
aoqi@0 2453
aoqi@0 2454 __ BIND(L_int_aligned);
aoqi@0 2455 __ shrptr(size, LogBytesPerInt); // size => int_count
aoqi@0 2456 __ jump(RuntimeAddress(int_copy_entry));
aoqi@0 2457
aoqi@0 2458 __ BIND(L_long_aligned);
aoqi@0 2459 __ shrptr(size, LogBytesPerLong); // size => qword_count
aoqi@0 2460 __ jump(RuntimeAddress(long_copy_entry));
aoqi@0 2461
aoqi@0 2462 return start;
aoqi@0 2463 }
aoqi@0 2464
aoqi@0 2465 // Perform range checks on the proposed arraycopy.
aoqi@0 2466 // Kills temp, but nothing else.
aoqi@0 2467 // Also, clean the sign bits of src_pos and dst_pos.
aoqi@0 2468 void arraycopy_range_checks(Register src, // source array oop (c_rarg0)
aoqi@0 2469 Register src_pos, // source position (c_rarg1)
aoqi@0 2470 Register dst, // destination array oo (c_rarg2)
aoqi@0 2471 Register dst_pos, // destination position (c_rarg3)
aoqi@0 2472 Register length,
aoqi@0 2473 Register temp,
aoqi@0 2474 Label& L_failed) {
aoqi@0 2475 BLOCK_COMMENT("arraycopy_range_checks:");
aoqi@0 2476
aoqi@0 2477 // if (src_pos + length > arrayOop(src)->length()) FAIL;
aoqi@0 2478 __ movl(temp, length);
aoqi@0 2479 __ addl(temp, src_pos); // src_pos + length
aoqi@0 2480 __ cmpl(temp, Address(src, arrayOopDesc::length_offset_in_bytes()));
aoqi@0 2481 __ jcc(Assembler::above, L_failed);
aoqi@0 2482
aoqi@0 2483 // if (dst_pos + length > arrayOop(dst)->length()) FAIL;
aoqi@0 2484 __ movl(temp, length);
aoqi@0 2485 __ addl(temp, dst_pos); // dst_pos + length
aoqi@0 2486 __ cmpl(temp, Address(dst, arrayOopDesc::length_offset_in_bytes()));
aoqi@0 2487 __ jcc(Assembler::above, L_failed);
aoqi@0 2488
aoqi@0 2489 // Have to clean up high 32-bits of 'src_pos' and 'dst_pos'.
aoqi@0 2490 // Move with sign extension can be used since they are positive.
aoqi@0 2491 __ movslq(src_pos, src_pos);
aoqi@0 2492 __ movslq(dst_pos, dst_pos);
aoqi@0 2493
aoqi@0 2494 BLOCK_COMMENT("arraycopy_range_checks done");
aoqi@0 2495 }
aoqi@0 2496
aoqi@0 2497 //
aoqi@0 2498 // Generate generic array copy stubs
aoqi@0 2499 //
aoqi@0 2500 // Input:
aoqi@0 2501 // c_rarg0 - src oop
aoqi@0 2502 // c_rarg1 - src_pos (32-bits)
aoqi@0 2503 // c_rarg2 - dst oop
aoqi@0 2504 // c_rarg3 - dst_pos (32-bits)
aoqi@0 2505 // not Win64
aoqi@0 2506 // c_rarg4 - element count (32-bits)
aoqi@0 2507 // Win64
aoqi@0 2508 // rsp+40 - element count (32-bits)
aoqi@0 2509 //
aoqi@0 2510 // Output:
aoqi@0 2511 // rax == 0 - success
aoqi@0 2512 // rax == -1^K - failure, where K is partial transfer count
aoqi@0 2513 //
aoqi@0 2514 address generate_generic_copy(const char *name,
aoqi@0 2515 address byte_copy_entry, address short_copy_entry,
aoqi@0 2516 address int_copy_entry, address oop_copy_entry,
aoqi@0 2517 address long_copy_entry, address checkcast_copy_entry) {
aoqi@0 2518
aoqi@0 2519 Label L_failed, L_failed_0, L_objArray;
aoqi@0 2520 Label L_copy_bytes, L_copy_shorts, L_copy_ints, L_copy_longs;
aoqi@0 2521
aoqi@0 2522 // Input registers
aoqi@0 2523 const Register src = c_rarg0; // source array oop
aoqi@0 2524 const Register src_pos = c_rarg1; // source position
aoqi@0 2525 const Register dst = c_rarg2; // destination array oop
aoqi@0 2526 const Register dst_pos = c_rarg3; // destination position
aoqi@0 2527 #ifndef _WIN64
aoqi@0 2528 const Register length = c_rarg4;
aoqi@0 2529 #else
aoqi@0 2530 const Address length(rsp, 6 * wordSize); // elements count is on stack on Win64
aoqi@0 2531 #endif
aoqi@0 2532
aoqi@0 2533 { int modulus = CodeEntryAlignment;
aoqi@0 2534 int target = modulus - 5; // 5 = sizeof jmp(L_failed)
aoqi@0 2535 int advance = target - (__ offset() % modulus);
aoqi@0 2536 if (advance < 0) advance += modulus;
aoqi@0 2537 if (advance > 0) __ nop(advance);
aoqi@0 2538 }
aoqi@0 2539 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 2540
aoqi@0 2541 // Short-hop target to L_failed. Makes for denser prologue code.
aoqi@0 2542 __ BIND(L_failed_0);
aoqi@0 2543 __ jmp(L_failed);
aoqi@0 2544 assert(__ offset() % CodeEntryAlignment == 0, "no further alignment needed");
aoqi@0 2545
aoqi@0 2546 __ align(CodeEntryAlignment);
aoqi@0 2547 address start = __ pc();
aoqi@0 2548
aoqi@0 2549 __ enter(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 2550
aoqi@0 2551 // bump this on entry, not on exit:
aoqi@0 2552 inc_counter_np(SharedRuntime::_generic_array_copy_ctr);
aoqi@0 2553
aoqi@0 2554 //-----------------------------------------------------------------------
aoqi@0 2555 // Assembler stub will be used for this call to arraycopy
aoqi@0 2556 // if the following conditions are met:
aoqi@0 2557 //
aoqi@0 2558 // (1) src and dst must not be null.
aoqi@0 2559 // (2) src_pos must not be negative.
aoqi@0 2560 // (3) dst_pos must not be negative.
aoqi@0 2561 // (4) length must not be negative.
aoqi@0 2562 // (5) src klass and dst klass should be the same and not NULL.
aoqi@0 2563 // (6) src and dst should be arrays.
aoqi@0 2564 // (7) src_pos + length must not exceed length of src.
aoqi@0 2565 // (8) dst_pos + length must not exceed length of dst.
aoqi@0 2566 //
aoqi@0 2567
aoqi@0 2568 // if (src == NULL) return -1;
aoqi@0 2569 __ testptr(src, src); // src oop
aoqi@0 2570 size_t j1off = __ offset();
aoqi@0 2571 __ jccb(Assembler::zero, L_failed_0);
aoqi@0 2572
aoqi@0 2573 // if (src_pos < 0) return -1;
aoqi@0 2574 __ testl(src_pos, src_pos); // src_pos (32-bits)
aoqi@0 2575 __ jccb(Assembler::negative, L_failed_0);
aoqi@0 2576
aoqi@0 2577 // if (dst == NULL) return -1;
aoqi@0 2578 __ testptr(dst, dst); // dst oop
aoqi@0 2579 __ jccb(Assembler::zero, L_failed_0);
aoqi@0 2580
aoqi@0 2581 // if (dst_pos < 0) return -1;
aoqi@0 2582 __ testl(dst_pos, dst_pos); // dst_pos (32-bits)
aoqi@0 2583 size_t j4off = __ offset();
aoqi@0 2584 __ jccb(Assembler::negative, L_failed_0);
aoqi@0 2585
aoqi@0 2586 // The first four tests are very dense code,
aoqi@0 2587 // but not quite dense enough to put four
aoqi@0 2588 // jumps in a 16-byte instruction fetch buffer.
aoqi@0 2589 // That's good, because some branch predicters
aoqi@0 2590 // do not like jumps so close together.
aoqi@0 2591 // Make sure of this.
aoqi@0 2592 guarantee(((j1off ^ j4off) & ~15) != 0, "I$ line of 1st & 4th jumps");
aoqi@0 2593
aoqi@0 2594 // registers used as temp
aoqi@0 2595 const Register r11_length = r11; // elements count to copy
aoqi@0 2596 const Register r10_src_klass = r10; // array klass
aoqi@0 2597
aoqi@0 2598 // if (length < 0) return -1;
aoqi@0 2599 __ movl(r11_length, length); // length (elements count, 32-bits value)
aoqi@0 2600 __ testl(r11_length, r11_length);
aoqi@0 2601 __ jccb(Assembler::negative, L_failed_0);
aoqi@0 2602
aoqi@0 2603 __ load_klass(r10_src_klass, src);
aoqi@0 2604 #ifdef ASSERT
aoqi@0 2605 // assert(src->klass() != NULL);
aoqi@0 2606 {
aoqi@0 2607 BLOCK_COMMENT("assert klasses not null {");
aoqi@0 2608 Label L1, L2;
aoqi@0 2609 __ testptr(r10_src_klass, r10_src_klass);
aoqi@0 2610 __ jcc(Assembler::notZero, L2); // it is broken if klass is NULL
aoqi@0 2611 __ bind(L1);
aoqi@0 2612 __ stop("broken null klass");
aoqi@0 2613 __ bind(L2);
aoqi@0 2614 __ load_klass(rax, dst);
aoqi@0 2615 __ cmpq(rax, 0);
aoqi@0 2616 __ jcc(Assembler::equal, L1); // this would be broken also
aoqi@0 2617 BLOCK_COMMENT("} assert klasses not null done");
aoqi@0 2618 }
aoqi@0 2619 #endif
aoqi@0 2620
aoqi@0 2621 // Load layout helper (32-bits)
aoqi@0 2622 //
aoqi@0 2623 // |array_tag| | header_size | element_type | |log2_element_size|
aoqi@0 2624 // 32 30 24 16 8 2 0
aoqi@0 2625 //
aoqi@0 2626 // array_tag: typeArray = 0x3, objArray = 0x2, non-array = 0x0
aoqi@0 2627 //
aoqi@0 2628
aoqi@0 2629 const int lh_offset = in_bytes(Klass::layout_helper_offset());
aoqi@0 2630
aoqi@0 2631 // Handle objArrays completely differently...
aoqi@0 2632 const jint objArray_lh = Klass::array_layout_helper(T_OBJECT);
aoqi@0 2633 __ cmpl(Address(r10_src_klass, lh_offset), objArray_lh);
aoqi@0 2634 __ jcc(Assembler::equal, L_objArray);
aoqi@0 2635
aoqi@0 2636 // if (src->klass() != dst->klass()) return -1;
aoqi@0 2637 __ load_klass(rax, dst);
aoqi@0 2638 __ cmpq(r10_src_klass, rax);
aoqi@0 2639 __ jcc(Assembler::notEqual, L_failed);
aoqi@0 2640
aoqi@0 2641 const Register rax_lh = rax; // layout helper
aoqi@0 2642 __ movl(rax_lh, Address(r10_src_klass, lh_offset));
aoqi@0 2643
aoqi@0 2644 // if (!src->is_Array()) return -1;
aoqi@0 2645 __ cmpl(rax_lh, Klass::_lh_neutral_value);
aoqi@0 2646 __ jcc(Assembler::greaterEqual, L_failed);
aoqi@0 2647
aoqi@0 2648 // At this point, it is known to be a typeArray (array_tag 0x3).
aoqi@0 2649 #ifdef ASSERT
aoqi@0 2650 {
aoqi@0 2651 BLOCK_COMMENT("assert primitive array {");
aoqi@0 2652 Label L;
aoqi@0 2653 __ cmpl(rax_lh, (Klass::_lh_array_tag_type_value << Klass::_lh_array_tag_shift));
aoqi@0 2654 __ jcc(Assembler::greaterEqual, L);
aoqi@0 2655 __ stop("must be a primitive array");
aoqi@0 2656 __ bind(L);
aoqi@0 2657 BLOCK_COMMENT("} assert primitive array done");
aoqi@0 2658 }
aoqi@0 2659 #endif
aoqi@0 2660
aoqi@0 2661 arraycopy_range_checks(src, src_pos, dst, dst_pos, r11_length,
aoqi@0 2662 r10, L_failed);
aoqi@0 2663
aoqi@0 2664 // TypeArrayKlass
aoqi@0 2665 //
aoqi@0 2666 // src_addr = (src + array_header_in_bytes()) + (src_pos << log2elemsize);
aoqi@0 2667 // dst_addr = (dst + array_header_in_bytes()) + (dst_pos << log2elemsize);
aoqi@0 2668 //
aoqi@0 2669
aoqi@0 2670 const Register r10_offset = r10; // array offset
aoqi@0 2671 const Register rax_elsize = rax_lh; // element size
aoqi@0 2672
aoqi@0 2673 __ movl(r10_offset, rax_lh);
aoqi@0 2674 __ shrl(r10_offset, Klass::_lh_header_size_shift);
aoqi@0 2675 __ andptr(r10_offset, Klass::_lh_header_size_mask); // array_offset
aoqi@0 2676 __ addptr(src, r10_offset); // src array offset
aoqi@0 2677 __ addptr(dst, r10_offset); // dst array offset
aoqi@0 2678 BLOCK_COMMENT("choose copy loop based on element size");
aoqi@0 2679 __ andl(rax_lh, Klass::_lh_log2_element_size_mask); // rax_lh -> rax_elsize
aoqi@0 2680
aoqi@0 2681 // next registers should be set before the jump to corresponding stub
aoqi@0 2682 const Register from = c_rarg0; // source array address
aoqi@0 2683 const Register to = c_rarg1; // destination array address
aoqi@0 2684 const Register count = c_rarg2; // elements count
aoqi@0 2685
aoqi@0 2686 // 'from', 'to', 'count' registers should be set in such order
aoqi@0 2687 // since they are the same as 'src', 'src_pos', 'dst'.
aoqi@0 2688
aoqi@0 2689 __ BIND(L_copy_bytes);
aoqi@0 2690 __ cmpl(rax_elsize, 0);
aoqi@0 2691 __ jccb(Assembler::notEqual, L_copy_shorts);
aoqi@0 2692 __ lea(from, Address(src, src_pos, Address::times_1, 0));// src_addr
aoqi@0 2693 __ lea(to, Address(dst, dst_pos, Address::times_1, 0));// dst_addr
aoqi@0 2694 __ movl2ptr(count, r11_length); // length
aoqi@0 2695 __ jump(RuntimeAddress(byte_copy_entry));
aoqi@0 2696
aoqi@0 2697 __ BIND(L_copy_shorts);
aoqi@0 2698 __ cmpl(rax_elsize, LogBytesPerShort);
aoqi@0 2699 __ jccb(Assembler::notEqual, L_copy_ints);
aoqi@0 2700 __ lea(from, Address(src, src_pos, Address::times_2, 0));// src_addr
aoqi@0 2701 __ lea(to, Address(dst, dst_pos, Address::times_2, 0));// dst_addr
aoqi@0 2702 __ movl2ptr(count, r11_length); // length
aoqi@0 2703 __ jump(RuntimeAddress(short_copy_entry));
aoqi@0 2704
aoqi@0 2705 __ BIND(L_copy_ints);
aoqi@0 2706 __ cmpl(rax_elsize, LogBytesPerInt);
aoqi@0 2707 __ jccb(Assembler::notEqual, L_copy_longs);
aoqi@0 2708 __ lea(from, Address(src, src_pos, Address::times_4, 0));// src_addr
aoqi@0 2709 __ lea(to, Address(dst, dst_pos, Address::times_4, 0));// dst_addr
aoqi@0 2710 __ movl2ptr(count, r11_length); // length
aoqi@0 2711 __ jump(RuntimeAddress(int_copy_entry));
aoqi@0 2712
aoqi@0 2713 __ BIND(L_copy_longs);
aoqi@0 2714 #ifdef ASSERT
aoqi@0 2715 {
aoqi@0 2716 BLOCK_COMMENT("assert long copy {");
aoqi@0 2717 Label L;
aoqi@0 2718 __ cmpl(rax_elsize, LogBytesPerLong);
aoqi@0 2719 __ jcc(Assembler::equal, L);
aoqi@0 2720 __ stop("must be long copy, but elsize is wrong");
aoqi@0 2721 __ bind(L);
aoqi@0 2722 BLOCK_COMMENT("} assert long copy done");
aoqi@0 2723 }
aoqi@0 2724 #endif
aoqi@0 2725 __ lea(from, Address(src, src_pos, Address::times_8, 0));// src_addr
aoqi@0 2726 __ lea(to, Address(dst, dst_pos, Address::times_8, 0));// dst_addr
aoqi@0 2727 __ movl2ptr(count, r11_length); // length
aoqi@0 2728 __ jump(RuntimeAddress(long_copy_entry));
aoqi@0 2729
aoqi@0 2730 // ObjArrayKlass
aoqi@0 2731 __ BIND(L_objArray);
aoqi@0 2732 // live at this point: r10_src_klass, r11_length, src[_pos], dst[_pos]
aoqi@0 2733
aoqi@0 2734 Label L_plain_copy, L_checkcast_copy;
aoqi@0 2735 // test array classes for subtyping
aoqi@0 2736 __ load_klass(rax, dst);
aoqi@0 2737 __ cmpq(r10_src_klass, rax); // usual case is exact equality
aoqi@0 2738 __ jcc(Assembler::notEqual, L_checkcast_copy);
aoqi@0 2739
aoqi@0 2740 // Identically typed arrays can be copied without element-wise checks.
aoqi@0 2741 arraycopy_range_checks(src, src_pos, dst, dst_pos, r11_length,
aoqi@0 2742 r10, L_failed);
aoqi@0 2743
aoqi@0 2744 __ lea(from, Address(src, src_pos, TIMES_OOP,
aoqi@0 2745 arrayOopDesc::base_offset_in_bytes(T_OBJECT))); // src_addr
aoqi@0 2746 __ lea(to, Address(dst, dst_pos, TIMES_OOP,
aoqi@0 2747 arrayOopDesc::base_offset_in_bytes(T_OBJECT))); // dst_addr
aoqi@0 2748 __ movl2ptr(count, r11_length); // length
aoqi@0 2749 __ BIND(L_plain_copy);
aoqi@0 2750 __ jump(RuntimeAddress(oop_copy_entry));
aoqi@0 2751
aoqi@0 2752 __ BIND(L_checkcast_copy);
aoqi@0 2753 // live at this point: r10_src_klass, r11_length, rax (dst_klass)
aoqi@0 2754 {
aoqi@0 2755 // Before looking at dst.length, make sure dst is also an objArray.
aoqi@0 2756 __ cmpl(Address(rax, lh_offset), objArray_lh);
aoqi@0 2757 __ jcc(Assembler::notEqual, L_failed);
aoqi@0 2758
aoqi@0 2759 // It is safe to examine both src.length and dst.length.
aoqi@0 2760 arraycopy_range_checks(src, src_pos, dst, dst_pos, r11_length,
aoqi@0 2761 rax, L_failed);
aoqi@0 2762
aoqi@0 2763 const Register r11_dst_klass = r11;
aoqi@0 2764 __ load_klass(r11_dst_klass, dst); // reload
aoqi@0 2765
aoqi@0 2766 // Marshal the base address arguments now, freeing registers.
aoqi@0 2767 __ lea(from, Address(src, src_pos, TIMES_OOP,
aoqi@0 2768 arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
aoqi@0 2769 __ lea(to, Address(dst, dst_pos, TIMES_OOP,
aoqi@0 2770 arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
aoqi@0 2771 __ movl(count, length); // length (reloaded)
aoqi@0 2772 Register sco_temp = c_rarg3; // this register is free now
aoqi@0 2773 assert_different_registers(from, to, count, sco_temp,
aoqi@0 2774 r11_dst_klass, r10_src_klass);
aoqi@0 2775 assert_clean_int(count, sco_temp);
aoqi@0 2776
aoqi@0 2777 // Generate the type check.
aoqi@0 2778 const int sco_offset = in_bytes(Klass::super_check_offset_offset());
aoqi@0 2779 __ movl(sco_temp, Address(r11_dst_klass, sco_offset));
aoqi@0 2780 assert_clean_int(sco_temp, rax);
aoqi@0 2781 generate_type_check(r10_src_klass, sco_temp, r11_dst_klass, L_plain_copy);
aoqi@0 2782
aoqi@0 2783 // Fetch destination element klass from the ObjArrayKlass header.
aoqi@0 2784 int ek_offset = in_bytes(ObjArrayKlass::element_klass_offset());
aoqi@0 2785 __ movptr(r11_dst_klass, Address(r11_dst_klass, ek_offset));
aoqi@0 2786 __ movl( sco_temp, Address(r11_dst_klass, sco_offset));
aoqi@0 2787 assert_clean_int(sco_temp, rax);
aoqi@0 2788
aoqi@0 2789 // the checkcast_copy loop needs two extra arguments:
aoqi@0 2790 assert(c_rarg3 == sco_temp, "#3 already in place");
aoqi@0 2791 // Set up arguments for checkcast_copy_entry.
aoqi@0 2792 setup_arg_regs(4);
aoqi@0 2793 __ movptr(r8, r11_dst_klass); // dst.klass.element_klass, r8 is c_rarg4 on Linux/Solaris
aoqi@0 2794 __ jump(RuntimeAddress(checkcast_copy_entry));
aoqi@0 2795 }
aoqi@0 2796
aoqi@0 2797 __ BIND(L_failed);
aoqi@0 2798 __ xorptr(rax, rax);
aoqi@0 2799 __ notptr(rax); // return -1
aoqi@0 2800 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 2801 __ ret(0);
aoqi@0 2802
aoqi@0 2803 return start;
aoqi@0 2804 }
aoqi@0 2805
aoqi@0 2806 void generate_arraycopy_stubs() {
aoqi@0 2807 address entry;
aoqi@0 2808 address entry_jbyte_arraycopy;
aoqi@0 2809 address entry_jshort_arraycopy;
aoqi@0 2810 address entry_jint_arraycopy;
aoqi@0 2811 address entry_oop_arraycopy;
aoqi@0 2812 address entry_jlong_arraycopy;
aoqi@0 2813 address entry_checkcast_arraycopy;
aoqi@0 2814
aoqi@0 2815 StubRoutines::_jbyte_disjoint_arraycopy = generate_disjoint_byte_copy(false, &entry,
aoqi@0 2816 "jbyte_disjoint_arraycopy");
aoqi@0 2817 StubRoutines::_jbyte_arraycopy = generate_conjoint_byte_copy(false, entry, &entry_jbyte_arraycopy,
aoqi@0 2818 "jbyte_arraycopy");
aoqi@0 2819
aoqi@0 2820 StubRoutines::_jshort_disjoint_arraycopy = generate_disjoint_short_copy(false, &entry,
aoqi@0 2821 "jshort_disjoint_arraycopy");
aoqi@0 2822 StubRoutines::_jshort_arraycopy = generate_conjoint_short_copy(false, entry, &entry_jshort_arraycopy,
aoqi@0 2823 "jshort_arraycopy");
aoqi@0 2824
aoqi@0 2825 StubRoutines::_jint_disjoint_arraycopy = generate_disjoint_int_oop_copy(false, false, &entry,
aoqi@0 2826 "jint_disjoint_arraycopy");
aoqi@0 2827 StubRoutines::_jint_arraycopy = generate_conjoint_int_oop_copy(false, false, entry,
aoqi@0 2828 &entry_jint_arraycopy, "jint_arraycopy");
aoqi@0 2829
aoqi@0 2830 StubRoutines::_jlong_disjoint_arraycopy = generate_disjoint_long_oop_copy(false, false, &entry,
aoqi@0 2831 "jlong_disjoint_arraycopy");
aoqi@0 2832 StubRoutines::_jlong_arraycopy = generate_conjoint_long_oop_copy(false, false, entry,
aoqi@0 2833 &entry_jlong_arraycopy, "jlong_arraycopy");
aoqi@0 2834
aoqi@0 2835
aoqi@0 2836 if (UseCompressedOops) {
aoqi@0 2837 StubRoutines::_oop_disjoint_arraycopy = generate_disjoint_int_oop_copy(false, true, &entry,
aoqi@0 2838 "oop_disjoint_arraycopy");
aoqi@0 2839 StubRoutines::_oop_arraycopy = generate_conjoint_int_oop_copy(false, true, entry,
aoqi@0 2840 &entry_oop_arraycopy, "oop_arraycopy");
aoqi@0 2841 StubRoutines::_oop_disjoint_arraycopy_uninit = generate_disjoint_int_oop_copy(false, true, &entry,
aoqi@0 2842 "oop_disjoint_arraycopy_uninit",
aoqi@0 2843 /*dest_uninitialized*/true);
aoqi@0 2844 StubRoutines::_oop_arraycopy_uninit = generate_conjoint_int_oop_copy(false, true, entry,
aoqi@0 2845 NULL, "oop_arraycopy_uninit",
aoqi@0 2846 /*dest_uninitialized*/true);
aoqi@0 2847 } else {
aoqi@0 2848 StubRoutines::_oop_disjoint_arraycopy = generate_disjoint_long_oop_copy(false, true, &entry,
aoqi@0 2849 "oop_disjoint_arraycopy");
aoqi@0 2850 StubRoutines::_oop_arraycopy = generate_conjoint_long_oop_copy(false, true, entry,
aoqi@0 2851 &entry_oop_arraycopy, "oop_arraycopy");
aoqi@0 2852 StubRoutines::_oop_disjoint_arraycopy_uninit = generate_disjoint_long_oop_copy(false, true, &entry,
aoqi@0 2853 "oop_disjoint_arraycopy_uninit",
aoqi@0 2854 /*dest_uninitialized*/true);
aoqi@0 2855 StubRoutines::_oop_arraycopy_uninit = generate_conjoint_long_oop_copy(false, true, entry,
aoqi@0 2856 NULL, "oop_arraycopy_uninit",
aoqi@0 2857 /*dest_uninitialized*/true);
aoqi@0 2858 }
aoqi@0 2859
aoqi@0 2860 StubRoutines::_checkcast_arraycopy = generate_checkcast_copy("checkcast_arraycopy", &entry_checkcast_arraycopy);
aoqi@0 2861 StubRoutines::_checkcast_arraycopy_uninit = generate_checkcast_copy("checkcast_arraycopy_uninit", NULL,
aoqi@0 2862 /*dest_uninitialized*/true);
aoqi@0 2863
aoqi@0 2864 StubRoutines::_unsafe_arraycopy = generate_unsafe_copy("unsafe_arraycopy",
aoqi@0 2865 entry_jbyte_arraycopy,
aoqi@0 2866 entry_jshort_arraycopy,
aoqi@0 2867 entry_jint_arraycopy,
aoqi@0 2868 entry_jlong_arraycopy);
aoqi@0 2869 StubRoutines::_generic_arraycopy = generate_generic_copy("generic_arraycopy",
aoqi@0 2870 entry_jbyte_arraycopy,
aoqi@0 2871 entry_jshort_arraycopy,
aoqi@0 2872 entry_jint_arraycopy,
aoqi@0 2873 entry_oop_arraycopy,
aoqi@0 2874 entry_jlong_arraycopy,
aoqi@0 2875 entry_checkcast_arraycopy);
aoqi@0 2876
aoqi@0 2877 StubRoutines::_jbyte_fill = generate_fill(T_BYTE, false, "jbyte_fill");
aoqi@0 2878 StubRoutines::_jshort_fill = generate_fill(T_SHORT, false, "jshort_fill");
aoqi@0 2879 StubRoutines::_jint_fill = generate_fill(T_INT, false, "jint_fill");
aoqi@0 2880 StubRoutines::_arrayof_jbyte_fill = generate_fill(T_BYTE, true, "arrayof_jbyte_fill");
aoqi@0 2881 StubRoutines::_arrayof_jshort_fill = generate_fill(T_SHORT, true, "arrayof_jshort_fill");
aoqi@0 2882 StubRoutines::_arrayof_jint_fill = generate_fill(T_INT, true, "arrayof_jint_fill");
aoqi@0 2883
aoqi@0 2884 // We don't generate specialized code for HeapWord-aligned source
aoqi@0 2885 // arrays, so just use the code we've already generated
aoqi@0 2886 StubRoutines::_arrayof_jbyte_disjoint_arraycopy = StubRoutines::_jbyte_disjoint_arraycopy;
aoqi@0 2887 StubRoutines::_arrayof_jbyte_arraycopy = StubRoutines::_jbyte_arraycopy;
aoqi@0 2888
aoqi@0 2889 StubRoutines::_arrayof_jshort_disjoint_arraycopy = StubRoutines::_jshort_disjoint_arraycopy;
aoqi@0 2890 StubRoutines::_arrayof_jshort_arraycopy = StubRoutines::_jshort_arraycopy;
aoqi@0 2891
aoqi@0 2892 StubRoutines::_arrayof_jint_disjoint_arraycopy = StubRoutines::_jint_disjoint_arraycopy;
aoqi@0 2893 StubRoutines::_arrayof_jint_arraycopy = StubRoutines::_jint_arraycopy;
aoqi@0 2894
aoqi@0 2895 StubRoutines::_arrayof_jlong_disjoint_arraycopy = StubRoutines::_jlong_disjoint_arraycopy;
aoqi@0 2896 StubRoutines::_arrayof_jlong_arraycopy = StubRoutines::_jlong_arraycopy;
aoqi@0 2897
aoqi@0 2898 StubRoutines::_arrayof_oop_disjoint_arraycopy = StubRoutines::_oop_disjoint_arraycopy;
aoqi@0 2899 StubRoutines::_arrayof_oop_arraycopy = StubRoutines::_oop_arraycopy;
aoqi@0 2900
aoqi@0 2901 StubRoutines::_arrayof_oop_disjoint_arraycopy_uninit = StubRoutines::_oop_disjoint_arraycopy_uninit;
aoqi@0 2902 StubRoutines::_arrayof_oop_arraycopy_uninit = StubRoutines::_oop_arraycopy_uninit;
aoqi@0 2903 }
aoqi@0 2904
aoqi@0 2905 void generate_math_stubs() {
aoqi@0 2906 {
aoqi@0 2907 StubCodeMark mark(this, "StubRoutines", "log");
aoqi@0 2908 StubRoutines::_intrinsic_log = (double (*)(double)) __ pc();
aoqi@0 2909
aoqi@0 2910 __ subq(rsp, 8);
aoqi@0 2911 __ movdbl(Address(rsp, 0), xmm0);
aoqi@0 2912 __ fld_d(Address(rsp, 0));
aoqi@0 2913 __ flog();
aoqi@0 2914 __ fstp_d(Address(rsp, 0));
aoqi@0 2915 __ movdbl(xmm0, Address(rsp, 0));
aoqi@0 2916 __ addq(rsp, 8);
aoqi@0 2917 __ ret(0);
aoqi@0 2918 }
aoqi@0 2919 {
aoqi@0 2920 StubCodeMark mark(this, "StubRoutines", "log10");
aoqi@0 2921 StubRoutines::_intrinsic_log10 = (double (*)(double)) __ pc();
aoqi@0 2922
aoqi@0 2923 __ subq(rsp, 8);
aoqi@0 2924 __ movdbl(Address(rsp, 0), xmm0);
aoqi@0 2925 __ fld_d(Address(rsp, 0));
aoqi@0 2926 __ flog10();
aoqi@0 2927 __ fstp_d(Address(rsp, 0));
aoqi@0 2928 __ movdbl(xmm0, Address(rsp, 0));
aoqi@0 2929 __ addq(rsp, 8);
aoqi@0 2930 __ ret(0);
aoqi@0 2931 }
aoqi@0 2932 {
aoqi@0 2933 StubCodeMark mark(this, "StubRoutines", "sin");
aoqi@0 2934 StubRoutines::_intrinsic_sin = (double (*)(double)) __ pc();
aoqi@0 2935
aoqi@0 2936 __ subq(rsp, 8);
aoqi@0 2937 __ movdbl(Address(rsp, 0), xmm0);
aoqi@0 2938 __ fld_d(Address(rsp, 0));
aoqi@0 2939 __ trigfunc('s');
aoqi@0 2940 __ fstp_d(Address(rsp, 0));
aoqi@0 2941 __ movdbl(xmm0, Address(rsp, 0));
aoqi@0 2942 __ addq(rsp, 8);
aoqi@0 2943 __ ret(0);
aoqi@0 2944 }
aoqi@0 2945 {
aoqi@0 2946 StubCodeMark mark(this, "StubRoutines", "cos");
aoqi@0 2947 StubRoutines::_intrinsic_cos = (double (*)(double)) __ pc();
aoqi@0 2948
aoqi@0 2949 __ subq(rsp, 8);
aoqi@0 2950 __ movdbl(Address(rsp, 0), xmm0);
aoqi@0 2951 __ fld_d(Address(rsp, 0));
aoqi@0 2952 __ trigfunc('c');
aoqi@0 2953 __ fstp_d(Address(rsp, 0));
aoqi@0 2954 __ movdbl(xmm0, Address(rsp, 0));
aoqi@0 2955 __ addq(rsp, 8);
aoqi@0 2956 __ ret(0);
aoqi@0 2957 }
aoqi@0 2958 {
aoqi@0 2959 StubCodeMark mark(this, "StubRoutines", "tan");
aoqi@0 2960 StubRoutines::_intrinsic_tan = (double (*)(double)) __ pc();
aoqi@0 2961
aoqi@0 2962 __ subq(rsp, 8);
aoqi@0 2963 __ movdbl(Address(rsp, 0), xmm0);
aoqi@0 2964 __ fld_d(Address(rsp, 0));
aoqi@0 2965 __ trigfunc('t');
aoqi@0 2966 __ fstp_d(Address(rsp, 0));
aoqi@0 2967 __ movdbl(xmm0, Address(rsp, 0));
aoqi@0 2968 __ addq(rsp, 8);
aoqi@0 2969 __ ret(0);
aoqi@0 2970 }
aoqi@0 2971 {
aoqi@0 2972 StubCodeMark mark(this, "StubRoutines", "exp");
aoqi@0 2973 StubRoutines::_intrinsic_exp = (double (*)(double)) __ pc();
aoqi@0 2974
aoqi@0 2975 __ subq(rsp, 8);
aoqi@0 2976 __ movdbl(Address(rsp, 0), xmm0);
aoqi@0 2977 __ fld_d(Address(rsp, 0));
aoqi@0 2978 __ exp_with_fallback(0);
aoqi@0 2979 __ fstp_d(Address(rsp, 0));
aoqi@0 2980 __ movdbl(xmm0, Address(rsp, 0));
aoqi@0 2981 __ addq(rsp, 8);
aoqi@0 2982 __ ret(0);
aoqi@0 2983 }
aoqi@0 2984 {
aoqi@0 2985 StubCodeMark mark(this, "StubRoutines", "pow");
aoqi@0 2986 StubRoutines::_intrinsic_pow = (double (*)(double,double)) __ pc();
aoqi@0 2987
aoqi@0 2988 __ subq(rsp, 8);
aoqi@0 2989 __ movdbl(Address(rsp, 0), xmm1);
aoqi@0 2990 __ fld_d(Address(rsp, 0));
aoqi@0 2991 __ movdbl(Address(rsp, 0), xmm0);
aoqi@0 2992 __ fld_d(Address(rsp, 0));
aoqi@0 2993 __ pow_with_fallback(0);
aoqi@0 2994 __ fstp_d(Address(rsp, 0));
aoqi@0 2995 __ movdbl(xmm0, Address(rsp, 0));
aoqi@0 2996 __ addq(rsp, 8);
aoqi@0 2997 __ ret(0);
aoqi@0 2998 }
aoqi@0 2999 }
aoqi@0 3000
aoqi@0 3001 // AES intrinsic stubs
aoqi@0 3002 enum {AESBlockSize = 16};
aoqi@0 3003
aoqi@0 3004 address generate_key_shuffle_mask() {
aoqi@0 3005 __ align(16);
aoqi@0 3006 StubCodeMark mark(this, "StubRoutines", "key_shuffle_mask");
aoqi@0 3007 address start = __ pc();
aoqi@0 3008 __ emit_data64( 0x0405060700010203, relocInfo::none );
aoqi@0 3009 __ emit_data64( 0x0c0d0e0f08090a0b, relocInfo::none );
aoqi@0 3010 return start;
aoqi@0 3011 }
aoqi@0 3012
aoqi@0 3013 // Utility routine for loading a 128-bit key word in little endian format
aoqi@0 3014 // can optionally specify that the shuffle mask is already in an xmmregister
aoqi@0 3015 void load_key(XMMRegister xmmdst, Register key, int offset, XMMRegister xmm_shuf_mask=NULL) {
aoqi@0 3016 __ movdqu(xmmdst, Address(key, offset));
aoqi@0 3017 if (xmm_shuf_mask != NULL) {
aoqi@0 3018 __ pshufb(xmmdst, xmm_shuf_mask);
aoqi@0 3019 } else {
aoqi@0 3020 __ pshufb(xmmdst, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr()));
aoqi@0 3021 }
aoqi@0 3022 }
aoqi@0 3023
aoqi@0 3024 // Arguments:
aoqi@0 3025 //
aoqi@0 3026 // Inputs:
aoqi@0 3027 // c_rarg0 - source byte array address
aoqi@0 3028 // c_rarg1 - destination byte array address
aoqi@0 3029 // c_rarg2 - K (key) in little endian int array
aoqi@0 3030 //
aoqi@0 3031 address generate_aescrypt_encryptBlock() {
aoqi@0 3032 assert(UseAES, "need AES instructions and misaligned SSE support");
aoqi@0 3033 __ align(CodeEntryAlignment);
aoqi@0 3034 StubCodeMark mark(this, "StubRoutines", "aescrypt_encryptBlock");
aoqi@0 3035 Label L_doLast;
aoqi@0 3036 address start = __ pc();
aoqi@0 3037
aoqi@0 3038 const Register from = c_rarg0; // source array address
aoqi@0 3039 const Register to = c_rarg1; // destination array address
aoqi@0 3040 const Register key = c_rarg2; // key array address
aoqi@0 3041 const Register keylen = rax;
aoqi@0 3042
aoqi@0 3043 const XMMRegister xmm_result = xmm0;
aoqi@0 3044 const XMMRegister xmm_key_shuf_mask = xmm1;
aoqi@0 3045 // On win64 xmm6-xmm15 must be preserved so don't use them.
aoqi@0 3046 const XMMRegister xmm_temp1 = xmm2;
aoqi@0 3047 const XMMRegister xmm_temp2 = xmm3;
aoqi@0 3048 const XMMRegister xmm_temp3 = xmm4;
aoqi@0 3049 const XMMRegister xmm_temp4 = xmm5;
aoqi@0 3050
aoqi@0 3051 __ enter(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 3052
aoqi@0 3053 // keylen could be only {11, 13, 15} * 4 = {44, 52, 60}
aoqi@0 3054 __ movl(keylen, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)));
aoqi@0 3055
aoqi@0 3056 __ movdqu(xmm_key_shuf_mask, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr()));
aoqi@0 3057 __ movdqu(xmm_result, Address(from, 0)); // get 16 bytes of input
aoqi@0 3058
aoqi@0 3059 // For encryption, the java expanded key ordering is just what we need
aoqi@0 3060 // we don't know if the key is aligned, hence not using load-execute form
aoqi@0 3061
aoqi@0 3062 load_key(xmm_temp1, key, 0x00, xmm_key_shuf_mask);
aoqi@0 3063 __ pxor(xmm_result, xmm_temp1);
aoqi@0 3064
aoqi@0 3065 load_key(xmm_temp1, key, 0x10, xmm_key_shuf_mask);
aoqi@0 3066 load_key(xmm_temp2, key, 0x20, xmm_key_shuf_mask);
aoqi@0 3067 load_key(xmm_temp3, key, 0x30, xmm_key_shuf_mask);
aoqi@0 3068 load_key(xmm_temp4, key, 0x40, xmm_key_shuf_mask);
aoqi@0 3069
aoqi@0 3070 __ aesenc(xmm_result, xmm_temp1);
aoqi@0 3071 __ aesenc(xmm_result, xmm_temp2);
aoqi@0 3072 __ aesenc(xmm_result, xmm_temp3);
aoqi@0 3073 __ aesenc(xmm_result, xmm_temp4);
aoqi@0 3074
aoqi@0 3075 load_key(xmm_temp1, key, 0x50, xmm_key_shuf_mask);
aoqi@0 3076 load_key(xmm_temp2, key, 0x60, xmm_key_shuf_mask);
aoqi@0 3077 load_key(xmm_temp3, key, 0x70, xmm_key_shuf_mask);
aoqi@0 3078 load_key(xmm_temp4, key, 0x80, xmm_key_shuf_mask);
aoqi@0 3079
aoqi@0 3080 __ aesenc(xmm_result, xmm_temp1);
aoqi@0 3081 __ aesenc(xmm_result, xmm_temp2);
aoqi@0 3082 __ aesenc(xmm_result, xmm_temp3);
aoqi@0 3083 __ aesenc(xmm_result, xmm_temp4);
aoqi@0 3084
aoqi@0 3085 load_key(xmm_temp1, key, 0x90, xmm_key_shuf_mask);
aoqi@0 3086 load_key(xmm_temp2, key, 0xa0, xmm_key_shuf_mask);
aoqi@0 3087
aoqi@0 3088 __ cmpl(keylen, 44);
aoqi@0 3089 __ jccb(Assembler::equal, L_doLast);
aoqi@0 3090
aoqi@0 3091 __ aesenc(xmm_result, xmm_temp1);
aoqi@0 3092 __ aesenc(xmm_result, xmm_temp2);
aoqi@0 3093
aoqi@0 3094 load_key(xmm_temp1, key, 0xb0, xmm_key_shuf_mask);
aoqi@0 3095 load_key(xmm_temp2, key, 0xc0, xmm_key_shuf_mask);
aoqi@0 3096
aoqi@0 3097 __ cmpl(keylen, 52);
aoqi@0 3098 __ jccb(Assembler::equal, L_doLast);
aoqi@0 3099
aoqi@0 3100 __ aesenc(xmm_result, xmm_temp1);
aoqi@0 3101 __ aesenc(xmm_result, xmm_temp2);
aoqi@0 3102
aoqi@0 3103 load_key(xmm_temp1, key, 0xd0, xmm_key_shuf_mask);
aoqi@0 3104 load_key(xmm_temp2, key, 0xe0, xmm_key_shuf_mask);
aoqi@0 3105
aoqi@0 3106 __ BIND(L_doLast);
aoqi@0 3107 __ aesenc(xmm_result, xmm_temp1);
aoqi@0 3108 __ aesenclast(xmm_result, xmm_temp2);
aoqi@0 3109 __ movdqu(Address(to, 0), xmm_result); // store the result
aoqi@0 3110 __ xorptr(rax, rax); // return 0
aoqi@0 3111 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 3112 __ ret(0);
aoqi@0 3113
aoqi@0 3114 return start;
aoqi@0 3115 }
aoqi@0 3116
aoqi@0 3117
aoqi@0 3118 // Arguments:
aoqi@0 3119 //
aoqi@0 3120 // Inputs:
aoqi@0 3121 // c_rarg0 - source byte array address
aoqi@0 3122 // c_rarg1 - destination byte array address
aoqi@0 3123 // c_rarg2 - K (key) in little endian int array
aoqi@0 3124 //
aoqi@0 3125 address generate_aescrypt_decryptBlock() {
aoqi@0 3126 assert(UseAES, "need AES instructions and misaligned SSE support");
aoqi@0 3127 __ align(CodeEntryAlignment);
aoqi@0 3128 StubCodeMark mark(this, "StubRoutines", "aescrypt_decryptBlock");
aoqi@0 3129 Label L_doLast;
aoqi@0 3130 address start = __ pc();
aoqi@0 3131
aoqi@0 3132 const Register from = c_rarg0; // source array address
aoqi@0 3133 const Register to = c_rarg1; // destination array address
aoqi@0 3134 const Register key = c_rarg2; // key array address
aoqi@0 3135 const Register keylen = rax;
aoqi@0 3136
aoqi@0 3137 const XMMRegister xmm_result = xmm0;
aoqi@0 3138 const XMMRegister xmm_key_shuf_mask = xmm1;
aoqi@0 3139 // On win64 xmm6-xmm15 must be preserved so don't use them.
aoqi@0 3140 const XMMRegister xmm_temp1 = xmm2;
aoqi@0 3141 const XMMRegister xmm_temp2 = xmm3;
aoqi@0 3142 const XMMRegister xmm_temp3 = xmm4;
aoqi@0 3143 const XMMRegister xmm_temp4 = xmm5;
aoqi@0 3144
aoqi@0 3145 __ enter(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 3146
aoqi@0 3147 // keylen could be only {11, 13, 15} * 4 = {44, 52, 60}
aoqi@0 3148 __ movl(keylen, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)));
aoqi@0 3149
aoqi@0 3150 __ movdqu(xmm_key_shuf_mask, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr()));
aoqi@0 3151 __ movdqu(xmm_result, Address(from, 0));
aoqi@0 3152
aoqi@0 3153 // for decryption java expanded key ordering is rotated one position from what we want
aoqi@0 3154 // so we start from 0x10 here and hit 0x00 last
aoqi@0 3155 // we don't know if the key is aligned, hence not using load-execute form
aoqi@0 3156 load_key(xmm_temp1, key, 0x10, xmm_key_shuf_mask);
aoqi@0 3157 load_key(xmm_temp2, key, 0x20, xmm_key_shuf_mask);
aoqi@0 3158 load_key(xmm_temp3, key, 0x30, xmm_key_shuf_mask);
aoqi@0 3159 load_key(xmm_temp4, key, 0x40, xmm_key_shuf_mask);
aoqi@0 3160
aoqi@0 3161 __ pxor (xmm_result, xmm_temp1);
aoqi@0 3162 __ aesdec(xmm_result, xmm_temp2);
aoqi@0 3163 __ aesdec(xmm_result, xmm_temp3);
aoqi@0 3164 __ aesdec(xmm_result, xmm_temp4);
aoqi@0 3165
aoqi@0 3166 load_key(xmm_temp1, key, 0x50, xmm_key_shuf_mask);
aoqi@0 3167 load_key(xmm_temp2, key, 0x60, xmm_key_shuf_mask);
aoqi@0 3168 load_key(xmm_temp3, key, 0x70, xmm_key_shuf_mask);
aoqi@0 3169 load_key(xmm_temp4, key, 0x80, xmm_key_shuf_mask);
aoqi@0 3170
aoqi@0 3171 __ aesdec(xmm_result, xmm_temp1);
aoqi@0 3172 __ aesdec(xmm_result, xmm_temp2);
aoqi@0 3173 __ aesdec(xmm_result, xmm_temp3);
aoqi@0 3174 __ aesdec(xmm_result, xmm_temp4);
aoqi@0 3175
aoqi@0 3176 load_key(xmm_temp1, key, 0x90, xmm_key_shuf_mask);
aoqi@0 3177 load_key(xmm_temp2, key, 0xa0, xmm_key_shuf_mask);
aoqi@0 3178 load_key(xmm_temp3, key, 0x00, xmm_key_shuf_mask);
aoqi@0 3179
aoqi@0 3180 __ cmpl(keylen, 44);
aoqi@0 3181 __ jccb(Assembler::equal, L_doLast);
aoqi@0 3182
aoqi@0 3183 __ aesdec(xmm_result, xmm_temp1);
aoqi@0 3184 __ aesdec(xmm_result, xmm_temp2);
aoqi@0 3185
aoqi@0 3186 load_key(xmm_temp1, key, 0xb0, xmm_key_shuf_mask);
aoqi@0 3187 load_key(xmm_temp2, key, 0xc0, xmm_key_shuf_mask);
aoqi@0 3188
aoqi@0 3189 __ cmpl(keylen, 52);
aoqi@0 3190 __ jccb(Assembler::equal, L_doLast);
aoqi@0 3191
aoqi@0 3192 __ aesdec(xmm_result, xmm_temp1);
aoqi@0 3193 __ aesdec(xmm_result, xmm_temp2);
aoqi@0 3194
aoqi@0 3195 load_key(xmm_temp1, key, 0xd0, xmm_key_shuf_mask);
aoqi@0 3196 load_key(xmm_temp2, key, 0xe0, xmm_key_shuf_mask);
aoqi@0 3197
aoqi@0 3198 __ BIND(L_doLast);
aoqi@0 3199 __ aesdec(xmm_result, xmm_temp1);
aoqi@0 3200 __ aesdec(xmm_result, xmm_temp2);
aoqi@0 3201
aoqi@0 3202 // for decryption the aesdeclast operation is always on key+0x00
aoqi@0 3203 __ aesdeclast(xmm_result, xmm_temp3);
aoqi@0 3204 __ movdqu(Address(to, 0), xmm_result); // store the result
aoqi@0 3205 __ xorptr(rax, rax); // return 0
aoqi@0 3206 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 3207 __ ret(0);
aoqi@0 3208
aoqi@0 3209 return start;
aoqi@0 3210 }
aoqi@0 3211
aoqi@0 3212
aoqi@0 3213 // Arguments:
aoqi@0 3214 //
aoqi@0 3215 // Inputs:
aoqi@0 3216 // c_rarg0 - source byte array address
aoqi@0 3217 // c_rarg1 - destination byte array address
aoqi@0 3218 // c_rarg2 - K (key) in little endian int array
aoqi@0 3219 // c_rarg3 - r vector byte array address
aoqi@0 3220 // c_rarg4 - input length
aoqi@0 3221 //
aoqi@0 3222 // Output:
aoqi@0 3223 // rax - input length
aoqi@0 3224 //
aoqi@0 3225 address generate_cipherBlockChaining_encryptAESCrypt() {
aoqi@0 3226 assert(UseAES, "need AES instructions and misaligned SSE support");
aoqi@0 3227 __ align(CodeEntryAlignment);
aoqi@0 3228 StubCodeMark mark(this, "StubRoutines", "cipherBlockChaining_encryptAESCrypt");
aoqi@0 3229 address start = __ pc();
aoqi@0 3230
aoqi@0 3231 Label L_exit, L_key_192_256, L_key_256, L_loopTop_128, L_loopTop_192, L_loopTop_256;
aoqi@0 3232 const Register from = c_rarg0; // source array address
aoqi@0 3233 const Register to = c_rarg1; // destination array address
aoqi@0 3234 const Register key = c_rarg2; // key array address
aoqi@0 3235 const Register rvec = c_rarg3; // r byte array initialized from initvector array address
aoqi@0 3236 // and left with the results of the last encryption block
aoqi@0 3237 #ifndef _WIN64
aoqi@0 3238 const Register len_reg = c_rarg4; // src len (must be multiple of blocksize 16)
aoqi@0 3239 #else
aoqi@0 3240 const Address len_mem(rbp, 6 * wordSize); // length is on stack on Win64
aoqi@0 3241 const Register len_reg = r10; // pick the first volatile windows register
aoqi@0 3242 #endif
aoqi@0 3243 const Register pos = rax;
aoqi@0 3244
aoqi@0 3245 // xmm register assignments for the loops below
aoqi@0 3246 const XMMRegister xmm_result = xmm0;
aoqi@0 3247 const XMMRegister xmm_temp = xmm1;
aoqi@0 3248 // keys 0-10 preloaded into xmm2-xmm12
aoqi@0 3249 const int XMM_REG_NUM_KEY_FIRST = 2;
aoqi@0 3250 const int XMM_REG_NUM_KEY_LAST = 15;
aoqi@0 3251 const XMMRegister xmm_key0 = as_XMMRegister(XMM_REG_NUM_KEY_FIRST);
aoqi@0 3252 const XMMRegister xmm_key10 = as_XMMRegister(XMM_REG_NUM_KEY_FIRST+10);
aoqi@0 3253 const XMMRegister xmm_key11 = as_XMMRegister(XMM_REG_NUM_KEY_FIRST+11);
aoqi@0 3254 const XMMRegister xmm_key12 = as_XMMRegister(XMM_REG_NUM_KEY_FIRST+12);
aoqi@0 3255 const XMMRegister xmm_key13 = as_XMMRegister(XMM_REG_NUM_KEY_FIRST+13);
aoqi@0 3256
aoqi@0 3257 __ enter(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 3258
aoqi@0 3259 #ifdef _WIN64
aoqi@0 3260 // on win64, fill len_reg from stack position
aoqi@0 3261 __ movl(len_reg, len_mem);
aoqi@0 3262 // save the xmm registers which must be preserved 6-15
aoqi@0 3263 __ subptr(rsp, -rsp_after_call_off * wordSize);
aoqi@0 3264 for (int i = 6; i <= XMM_REG_NUM_KEY_LAST; i++) {
aoqi@0 3265 __ movdqu(xmm_save(i), as_XMMRegister(i));
aoqi@0 3266 }
aoqi@0 3267 #else
aoqi@0 3268 __ push(len_reg); // Save
aoqi@0 3269 #endif
aoqi@0 3270
aoqi@0 3271 const XMMRegister xmm_key_shuf_mask = xmm_temp; // used temporarily to swap key bytes up front
aoqi@0 3272 __ movdqu(xmm_key_shuf_mask, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr()));
aoqi@0 3273 // load up xmm regs xmm2 thru xmm12 with key 0x00 - 0xa0
aoqi@0 3274 for (int rnum = XMM_REG_NUM_KEY_FIRST, offset = 0x00; rnum <= XMM_REG_NUM_KEY_FIRST+10; rnum++) {
aoqi@0 3275 load_key(as_XMMRegister(rnum), key, offset, xmm_key_shuf_mask);
aoqi@0 3276 offset += 0x10;
aoqi@0 3277 }
aoqi@0 3278 __ movdqu(xmm_result, Address(rvec, 0x00)); // initialize xmm_result with r vec
aoqi@0 3279
aoqi@0 3280 // now split to different paths depending on the keylen (len in ints of AESCrypt.KLE array (52=192, or 60=256))
aoqi@0 3281 __ movl(rax, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)));
aoqi@0 3282 __ cmpl(rax, 44);
aoqi@0 3283 __ jcc(Assembler::notEqual, L_key_192_256);
aoqi@0 3284
aoqi@0 3285 // 128 bit code follows here
aoqi@0 3286 __ movptr(pos, 0);
aoqi@0 3287 __ align(OptoLoopAlignment);
aoqi@0 3288
aoqi@0 3289 __ BIND(L_loopTop_128);
aoqi@0 3290 __ movdqu(xmm_temp, Address(from, pos, Address::times_1, 0)); // get next 16 bytes of input
aoqi@0 3291 __ pxor (xmm_result, xmm_temp); // xor with the current r vector
aoqi@0 3292 __ pxor (xmm_result, xmm_key0); // do the aes rounds
aoqi@0 3293 for (int rnum = XMM_REG_NUM_KEY_FIRST + 1; rnum <= XMM_REG_NUM_KEY_FIRST + 9; rnum++) {
aoqi@0 3294 __ aesenc(xmm_result, as_XMMRegister(rnum));
aoqi@0 3295 }
aoqi@0 3296 __ aesenclast(xmm_result, xmm_key10);
aoqi@0 3297 __ movdqu(Address(to, pos, Address::times_1, 0), xmm_result); // store into the next 16 bytes of output
aoqi@0 3298 // no need to store r to memory until we exit
aoqi@0 3299 __ addptr(pos, AESBlockSize);
aoqi@0 3300 __ subptr(len_reg, AESBlockSize);
aoqi@0 3301 __ jcc(Assembler::notEqual, L_loopTop_128);
aoqi@0 3302
aoqi@0 3303 __ BIND(L_exit);
aoqi@0 3304 __ movdqu(Address(rvec, 0), xmm_result); // final value of r stored in rvec of CipherBlockChaining object
aoqi@0 3305
aoqi@0 3306 #ifdef _WIN64
aoqi@0 3307 // restore xmm regs belonging to calling function
aoqi@0 3308 for (int i = 6; i <= XMM_REG_NUM_KEY_LAST; i++) {
aoqi@0 3309 __ movdqu(as_XMMRegister(i), xmm_save(i));
aoqi@0 3310 }
aoqi@0 3311 __ movl(rax, len_mem);
aoqi@0 3312 #else
aoqi@0 3313 __ pop(rax); // return length
aoqi@0 3314 #endif
aoqi@0 3315 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 3316 __ ret(0);
aoqi@0 3317
aoqi@0 3318 __ BIND(L_key_192_256);
aoqi@0 3319 // here rax = len in ints of AESCrypt.KLE array (52=192, or 60=256)
aoqi@0 3320 load_key(xmm_key11, key, 0xb0, xmm_key_shuf_mask);
aoqi@0 3321 load_key(xmm_key12, key, 0xc0, xmm_key_shuf_mask);
aoqi@0 3322 __ cmpl(rax, 52);
aoqi@0 3323 __ jcc(Assembler::notEqual, L_key_256);
aoqi@0 3324
aoqi@0 3325 // 192-bit code follows here (could be changed to use more xmm registers)
aoqi@0 3326 __ movptr(pos, 0);
aoqi@0 3327 __ align(OptoLoopAlignment);
aoqi@0 3328
aoqi@0 3329 __ BIND(L_loopTop_192);
aoqi@0 3330 __ movdqu(xmm_temp, Address(from, pos, Address::times_1, 0)); // get next 16 bytes of input
aoqi@0 3331 __ pxor (xmm_result, xmm_temp); // xor with the current r vector
aoqi@0 3332 __ pxor (xmm_result, xmm_key0); // do the aes rounds
aoqi@0 3333 for (int rnum = XMM_REG_NUM_KEY_FIRST + 1; rnum <= XMM_REG_NUM_KEY_FIRST + 11; rnum++) {
aoqi@0 3334 __ aesenc(xmm_result, as_XMMRegister(rnum));
aoqi@0 3335 }
aoqi@0 3336 __ aesenclast(xmm_result, xmm_key12);
aoqi@0 3337 __ movdqu(Address(to, pos, Address::times_1, 0), xmm_result); // store into the next 16 bytes of output
aoqi@0 3338 // no need to store r to memory until we exit
aoqi@0 3339 __ addptr(pos, AESBlockSize);
aoqi@0 3340 __ subptr(len_reg, AESBlockSize);
aoqi@0 3341 __ jcc(Assembler::notEqual, L_loopTop_192);
aoqi@0 3342 __ jmp(L_exit);
aoqi@0 3343
aoqi@0 3344 __ BIND(L_key_256);
aoqi@0 3345 // 256-bit code follows here (could be changed to use more xmm registers)
aoqi@0 3346 load_key(xmm_key13, key, 0xd0, xmm_key_shuf_mask);
aoqi@0 3347 __ movptr(pos, 0);
aoqi@0 3348 __ align(OptoLoopAlignment);
aoqi@0 3349
aoqi@0 3350 __ BIND(L_loopTop_256);
aoqi@0 3351 __ movdqu(xmm_temp, Address(from, pos, Address::times_1, 0)); // get next 16 bytes of input
aoqi@0 3352 __ pxor (xmm_result, xmm_temp); // xor with the current r vector
aoqi@0 3353 __ pxor (xmm_result, xmm_key0); // do the aes rounds
aoqi@0 3354 for (int rnum = XMM_REG_NUM_KEY_FIRST + 1; rnum <= XMM_REG_NUM_KEY_FIRST + 13; rnum++) {
aoqi@0 3355 __ aesenc(xmm_result, as_XMMRegister(rnum));
aoqi@0 3356 }
aoqi@0 3357 load_key(xmm_temp, key, 0xe0);
aoqi@0 3358 __ aesenclast(xmm_result, xmm_temp);
aoqi@0 3359 __ movdqu(Address(to, pos, Address::times_1, 0), xmm_result); // store into the next 16 bytes of output
aoqi@0 3360 // no need to store r to memory until we exit
aoqi@0 3361 __ addptr(pos, AESBlockSize);
aoqi@0 3362 __ subptr(len_reg, AESBlockSize);
aoqi@0 3363 __ jcc(Assembler::notEqual, L_loopTop_256);
aoqi@0 3364 __ jmp(L_exit);
aoqi@0 3365
aoqi@0 3366 return start;
aoqi@0 3367 }
aoqi@0 3368
aoqi@0 3369 // Safefetch stubs.
aoqi@0 3370 void generate_safefetch(const char* name, int size, address* entry,
aoqi@0 3371 address* fault_pc, address* continuation_pc) {
aoqi@0 3372 // safefetch signatures:
aoqi@0 3373 // int SafeFetch32(int* adr, int errValue);
aoqi@0 3374 // intptr_t SafeFetchN (intptr_t* adr, intptr_t errValue);
aoqi@0 3375 //
aoqi@0 3376 // arguments:
aoqi@0 3377 // c_rarg0 = adr
aoqi@0 3378 // c_rarg1 = errValue
aoqi@0 3379 //
aoqi@0 3380 // result:
aoqi@0 3381 // PPC_RET = *adr or errValue
aoqi@0 3382
aoqi@0 3383 StubCodeMark mark(this, "StubRoutines", name);
aoqi@0 3384
aoqi@0 3385 // Entry point, pc or function descriptor.
aoqi@0 3386 *entry = __ pc();
aoqi@0 3387
aoqi@0 3388 // Load *adr into c_rarg1, may fault.
aoqi@0 3389 *fault_pc = __ pc();
aoqi@0 3390 switch (size) {
aoqi@0 3391 case 4:
aoqi@0 3392 // int32_t
aoqi@0 3393 __ movl(c_rarg1, Address(c_rarg0, 0));
aoqi@0 3394 break;
aoqi@0 3395 case 8:
aoqi@0 3396 // int64_t
aoqi@0 3397 __ movq(c_rarg1, Address(c_rarg0, 0));
aoqi@0 3398 break;
aoqi@0 3399 default:
aoqi@0 3400 ShouldNotReachHere();
aoqi@0 3401 }
aoqi@0 3402
aoqi@0 3403 // return errValue or *adr
aoqi@0 3404 *continuation_pc = __ pc();
aoqi@0 3405 __ movq(rax, c_rarg1);
aoqi@0 3406 __ ret(0);
aoqi@0 3407 }
aoqi@0 3408
aoqi@0 3409 // This is a version of CBC/AES Decrypt which does 4 blocks in a loop at a time
aoqi@0 3410 // to hide instruction latency
aoqi@0 3411 //
aoqi@0 3412 // Arguments:
aoqi@0 3413 //
aoqi@0 3414 // Inputs:
aoqi@0 3415 // c_rarg0 - source byte array address
aoqi@0 3416 // c_rarg1 - destination byte array address
aoqi@0 3417 // c_rarg2 - K (key) in little endian int array
aoqi@0 3418 // c_rarg3 - r vector byte array address
aoqi@0 3419 // c_rarg4 - input length
aoqi@0 3420 //
aoqi@0 3421 // Output:
aoqi@0 3422 // rax - input length
aoqi@0 3423 //
aoqi@0 3424
aoqi@0 3425 address generate_cipherBlockChaining_decryptAESCrypt_Parallel() {
aoqi@0 3426 assert(UseAES, "need AES instructions and misaligned SSE support");
aoqi@0 3427 __ align(CodeEntryAlignment);
aoqi@0 3428 StubCodeMark mark(this, "StubRoutines", "cipherBlockChaining_decryptAESCrypt");
aoqi@0 3429 address start = __ pc();
aoqi@0 3430
aoqi@0 3431 Label L_exit, L_key_192_256, L_key_256;
aoqi@0 3432 Label L_singleBlock_loopTop_128, L_multiBlock_loopTop_128;
aoqi@0 3433 Label L_singleBlock_loopTop_192, L_singleBlock_loopTop_256;
aoqi@0 3434 const Register from = c_rarg0; // source array address
aoqi@0 3435 const Register to = c_rarg1; // destination array address
aoqi@0 3436 const Register key = c_rarg2; // key array address
aoqi@0 3437 const Register rvec = c_rarg3; // r byte array initialized from initvector array address
aoqi@0 3438 // and left with the results of the last encryption block
aoqi@0 3439 #ifndef _WIN64
aoqi@0 3440 const Register len_reg = c_rarg4; // src len (must be multiple of blocksize 16)
aoqi@0 3441 #else
aoqi@0 3442 const Address len_mem(rbp, 6 * wordSize); // length is on stack on Win64
aoqi@0 3443 const Register len_reg = r10; // pick the first volatile windows register
aoqi@0 3444 #endif
aoqi@0 3445 const Register pos = rax;
aoqi@0 3446
aoqi@0 3447 // keys 0-10 preloaded into xmm2-xmm12
aoqi@0 3448 const int XMM_REG_NUM_KEY_FIRST = 5;
aoqi@0 3449 const int XMM_REG_NUM_KEY_LAST = 15;
aoqi@0 3450 const XMMRegister xmm_key_first = as_XMMRegister(XMM_REG_NUM_KEY_FIRST);
aoqi@0 3451 const XMMRegister xmm_key_last = as_XMMRegister(XMM_REG_NUM_KEY_LAST);
aoqi@0 3452
aoqi@0 3453 __ enter(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 3454
aoqi@0 3455 #ifdef _WIN64
aoqi@0 3456 // on win64, fill len_reg from stack position
aoqi@0 3457 __ movl(len_reg, len_mem);
aoqi@0 3458 // save the xmm registers which must be preserved 6-15
aoqi@0 3459 __ subptr(rsp, -rsp_after_call_off * wordSize);
aoqi@0 3460 for (int i = 6; i <= XMM_REG_NUM_KEY_LAST; i++) {
aoqi@0 3461 __ movdqu(xmm_save(i), as_XMMRegister(i));
aoqi@0 3462 }
aoqi@0 3463 #else
aoqi@0 3464 __ push(len_reg); // Save
aoqi@0 3465 #endif
aoqi@0 3466
aoqi@0 3467 // the java expanded key ordering is rotated one position from what we want
aoqi@0 3468 // so we start from 0x10 here and hit 0x00 last
aoqi@0 3469 const XMMRegister xmm_key_shuf_mask = xmm1; // used temporarily to swap key bytes up front
aoqi@0 3470 __ movdqu(xmm_key_shuf_mask, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr()));
aoqi@0 3471 // load up xmm regs 5 thru 15 with key 0x10 - 0xa0 - 0x00
aoqi@0 3472 for (int rnum = XMM_REG_NUM_KEY_FIRST, offset = 0x10; rnum < XMM_REG_NUM_KEY_LAST; rnum++) {
aoqi@0 3473 load_key(as_XMMRegister(rnum), key, offset, xmm_key_shuf_mask);
aoqi@0 3474 offset += 0x10;
aoqi@0 3475 }
aoqi@0 3476 load_key(xmm_key_last, key, 0x00, xmm_key_shuf_mask);
aoqi@0 3477
aoqi@0 3478 const XMMRegister xmm_prev_block_cipher = xmm1; // holds cipher of previous block
aoqi@0 3479
aoqi@0 3480 // registers holding the four results in the parallelized loop
aoqi@0 3481 const XMMRegister xmm_result0 = xmm0;
aoqi@0 3482 const XMMRegister xmm_result1 = xmm2;
aoqi@0 3483 const XMMRegister xmm_result2 = xmm3;
aoqi@0 3484 const XMMRegister xmm_result3 = xmm4;
aoqi@0 3485
aoqi@0 3486 __ movdqu(xmm_prev_block_cipher, Address(rvec, 0x00)); // initialize with initial rvec
aoqi@0 3487
aoqi@0 3488 // now split to different paths depending on the keylen (len in ints of AESCrypt.KLE array (52=192, or 60=256))
aoqi@0 3489 __ movl(rax, Address(key, arrayOopDesc::length_offset_in_bytes() - arrayOopDesc::base_offset_in_bytes(T_INT)));
aoqi@0 3490 __ cmpl(rax, 44);
aoqi@0 3491 __ jcc(Assembler::notEqual, L_key_192_256);
aoqi@0 3492
aoqi@0 3493
aoqi@0 3494 // 128-bit code follows here, parallelized
aoqi@0 3495 __ movptr(pos, 0);
aoqi@0 3496 __ align(OptoLoopAlignment);
aoqi@0 3497 __ BIND(L_multiBlock_loopTop_128);
aoqi@0 3498 __ cmpptr(len_reg, 4*AESBlockSize); // see if at least 4 blocks left
aoqi@0 3499 __ jcc(Assembler::less, L_singleBlock_loopTop_128);
aoqi@0 3500
aoqi@0 3501 __ movdqu(xmm_result0, Address(from, pos, Address::times_1, 0*AESBlockSize)); // get next 4 blocks into xmmresult registers
aoqi@0 3502 __ movdqu(xmm_result1, Address(from, pos, Address::times_1, 1*AESBlockSize));
aoqi@0 3503 __ movdqu(xmm_result2, Address(from, pos, Address::times_1, 2*AESBlockSize));
aoqi@0 3504 __ movdqu(xmm_result3, Address(from, pos, Address::times_1, 3*AESBlockSize));
aoqi@0 3505
aoqi@0 3506 #define DoFour(opc, src_reg) \
aoqi@0 3507 __ opc(xmm_result0, src_reg); \
aoqi@0 3508 __ opc(xmm_result1, src_reg); \
aoqi@0 3509 __ opc(xmm_result2, src_reg); \
aoqi@0 3510 __ opc(xmm_result3, src_reg);
aoqi@0 3511
aoqi@0 3512 DoFour(pxor, xmm_key_first);
aoqi@0 3513 for (int rnum = XMM_REG_NUM_KEY_FIRST + 1; rnum <= XMM_REG_NUM_KEY_LAST - 1; rnum++) {
aoqi@0 3514 DoFour(aesdec, as_XMMRegister(rnum));
aoqi@0 3515 }
aoqi@0 3516 DoFour(aesdeclast, xmm_key_last);
aoqi@0 3517 // for each result, xor with the r vector of previous cipher block
aoqi@0 3518 __ pxor(xmm_result0, xmm_prev_block_cipher);
aoqi@0 3519 __ movdqu(xmm_prev_block_cipher, Address(from, pos, Address::times_1, 0*AESBlockSize));
aoqi@0 3520 __ pxor(xmm_result1, xmm_prev_block_cipher);
aoqi@0 3521 __ movdqu(xmm_prev_block_cipher, Address(from, pos, Address::times_1, 1*AESBlockSize));
aoqi@0 3522 __ pxor(xmm_result2, xmm_prev_block_cipher);
aoqi@0 3523 __ movdqu(xmm_prev_block_cipher, Address(from, pos, Address::times_1, 2*AESBlockSize));
aoqi@0 3524 __ pxor(xmm_result3, xmm_prev_block_cipher);
aoqi@0 3525 __ movdqu(xmm_prev_block_cipher, Address(from, pos, Address::times_1, 3*AESBlockSize)); // this will carry over to next set of blocks
aoqi@0 3526
aoqi@0 3527 __ movdqu(Address(to, pos, Address::times_1, 0*AESBlockSize), xmm_result0); // store 4 results into the next 64 bytes of output
aoqi@0 3528 __ movdqu(Address(to, pos, Address::times_1, 1*AESBlockSize), xmm_result1);
aoqi@0 3529 __ movdqu(Address(to, pos, Address::times_1, 2*AESBlockSize), xmm_result2);
aoqi@0 3530 __ movdqu(Address(to, pos, Address::times_1, 3*AESBlockSize), xmm_result3);
aoqi@0 3531
aoqi@0 3532 __ addptr(pos, 4*AESBlockSize);
aoqi@0 3533 __ subptr(len_reg, 4*AESBlockSize);
aoqi@0 3534 __ jmp(L_multiBlock_loopTop_128);
aoqi@0 3535
aoqi@0 3536 // registers used in the non-parallelized loops
aoqi@0 3537 // xmm register assignments for the loops below
aoqi@0 3538 const XMMRegister xmm_result = xmm0;
aoqi@0 3539 const XMMRegister xmm_prev_block_cipher_save = xmm2;
aoqi@0 3540 const XMMRegister xmm_key11 = xmm3;
aoqi@0 3541 const XMMRegister xmm_key12 = xmm4;
aoqi@0 3542 const XMMRegister xmm_temp = xmm4;
aoqi@0 3543
aoqi@0 3544 __ align(OptoLoopAlignment);
aoqi@0 3545 __ BIND(L_singleBlock_loopTop_128);
aoqi@0 3546 __ cmpptr(len_reg, 0); // any blocks left??
aoqi@0 3547 __ jcc(Assembler::equal, L_exit);
aoqi@0 3548 __ movdqu(xmm_result, Address(from, pos, Address::times_1, 0)); // get next 16 bytes of cipher input
aoqi@0 3549 __ movdqa(xmm_prev_block_cipher_save, xmm_result); // save for next r vector
aoqi@0 3550 __ pxor (xmm_result, xmm_key_first); // do the aes dec rounds
aoqi@0 3551 for (int rnum = XMM_REG_NUM_KEY_FIRST + 1; rnum <= XMM_REG_NUM_KEY_LAST - 1; rnum++) {
aoqi@0 3552 __ aesdec(xmm_result, as_XMMRegister(rnum));
aoqi@0 3553 }
aoqi@0 3554 __ aesdeclast(xmm_result, xmm_key_last);
aoqi@0 3555 __ pxor (xmm_result, xmm_prev_block_cipher); // xor with the current r vector
aoqi@0 3556 __ movdqu(Address(to, pos, Address::times_1, 0), xmm_result); // store into the next 16 bytes of output
aoqi@0 3557 // no need to store r to memory until we exit
aoqi@0 3558 __ movdqa(xmm_prev_block_cipher, xmm_prev_block_cipher_save); // set up next r vector with cipher input from this block
aoqi@0 3559
aoqi@0 3560 __ addptr(pos, AESBlockSize);
aoqi@0 3561 __ subptr(len_reg, AESBlockSize);
aoqi@0 3562 __ jmp(L_singleBlock_loopTop_128);
aoqi@0 3563
aoqi@0 3564
aoqi@0 3565 __ BIND(L_exit);
aoqi@0 3566 __ movdqu(Address(rvec, 0), xmm_prev_block_cipher); // final value of r stored in rvec of CipherBlockChaining object
aoqi@0 3567 #ifdef _WIN64
aoqi@0 3568 // restore regs belonging to calling function
aoqi@0 3569 for (int i = 6; i <= XMM_REG_NUM_KEY_LAST; i++) {
aoqi@0 3570 __ movdqu(as_XMMRegister(i), xmm_save(i));
aoqi@0 3571 }
aoqi@0 3572 __ movl(rax, len_mem);
aoqi@0 3573 #else
aoqi@0 3574 __ pop(rax); // return length
aoqi@0 3575 #endif
aoqi@0 3576 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 3577 __ ret(0);
aoqi@0 3578
aoqi@0 3579
aoqi@0 3580 __ BIND(L_key_192_256);
aoqi@0 3581 // here rax = len in ints of AESCrypt.KLE array (52=192, or 60=256)
aoqi@0 3582 load_key(xmm_key11, key, 0xb0);
aoqi@0 3583 __ cmpl(rax, 52);
aoqi@0 3584 __ jcc(Assembler::notEqual, L_key_256);
aoqi@0 3585
aoqi@0 3586 // 192-bit code follows here (could be optimized to use parallelism)
aoqi@0 3587 load_key(xmm_key12, key, 0xc0); // 192-bit key goes up to c0
aoqi@0 3588 __ movptr(pos, 0);
aoqi@0 3589 __ align(OptoLoopAlignment);
aoqi@0 3590
aoqi@0 3591 __ BIND(L_singleBlock_loopTop_192);
aoqi@0 3592 __ movdqu(xmm_result, Address(from, pos, Address::times_1, 0)); // get next 16 bytes of cipher input
aoqi@0 3593 __ movdqa(xmm_prev_block_cipher_save, xmm_result); // save for next r vector
aoqi@0 3594 __ pxor (xmm_result, xmm_key_first); // do the aes dec rounds
aoqi@0 3595 for (int rnum = XMM_REG_NUM_KEY_FIRST + 1; rnum <= XMM_REG_NUM_KEY_LAST - 1; rnum++) {
aoqi@0 3596 __ aesdec(xmm_result, as_XMMRegister(rnum));
aoqi@0 3597 }
aoqi@0 3598 __ aesdec(xmm_result, xmm_key11);
aoqi@0 3599 __ aesdec(xmm_result, xmm_key12);
aoqi@0 3600 __ aesdeclast(xmm_result, xmm_key_last); // xmm15 always came from key+0
aoqi@0 3601 __ pxor (xmm_result, xmm_prev_block_cipher); // xor with the current r vector
aoqi@0 3602 __ movdqu(Address(to, pos, Address::times_1, 0), xmm_result); // store into the next 16 bytes of output
aoqi@0 3603 // no need to store r to memory until we exit
aoqi@0 3604 __ movdqa(xmm_prev_block_cipher, xmm_prev_block_cipher_save); // set up next r vector with cipher input from this block
aoqi@0 3605 __ addptr(pos, AESBlockSize);
aoqi@0 3606 __ subptr(len_reg, AESBlockSize);
aoqi@0 3607 __ jcc(Assembler::notEqual,L_singleBlock_loopTop_192);
aoqi@0 3608 __ jmp(L_exit);
aoqi@0 3609
aoqi@0 3610 __ BIND(L_key_256);
aoqi@0 3611 // 256-bit code follows here (could be optimized to use parallelism)
aoqi@0 3612 __ movptr(pos, 0);
aoqi@0 3613 __ align(OptoLoopAlignment);
aoqi@0 3614
aoqi@0 3615 __ BIND(L_singleBlock_loopTop_256);
aoqi@0 3616 __ movdqu(xmm_result, Address(from, pos, Address::times_1, 0)); // get next 16 bytes of cipher input
aoqi@0 3617 __ movdqa(xmm_prev_block_cipher_save, xmm_result); // save for next r vector
aoqi@0 3618 __ pxor (xmm_result, xmm_key_first); // do the aes dec rounds
aoqi@0 3619 for (int rnum = XMM_REG_NUM_KEY_FIRST + 1; rnum <= XMM_REG_NUM_KEY_LAST - 1; rnum++) {
aoqi@0 3620 __ aesdec(xmm_result, as_XMMRegister(rnum));
aoqi@0 3621 }
aoqi@0 3622 __ aesdec(xmm_result, xmm_key11);
aoqi@0 3623 load_key(xmm_temp, key, 0xc0);
aoqi@0 3624 __ aesdec(xmm_result, xmm_temp);
aoqi@0 3625 load_key(xmm_temp, key, 0xd0);
aoqi@0 3626 __ aesdec(xmm_result, xmm_temp);
aoqi@0 3627 load_key(xmm_temp, key, 0xe0); // 256-bit key goes up to e0
aoqi@0 3628 __ aesdec(xmm_result, xmm_temp);
aoqi@0 3629 __ aesdeclast(xmm_result, xmm_key_last); // xmm15 came from key+0
aoqi@0 3630 __ pxor (xmm_result, xmm_prev_block_cipher); // xor with the current r vector
aoqi@0 3631 __ movdqu(Address(to, pos, Address::times_1, 0), xmm_result); // store into the next 16 bytes of output
aoqi@0 3632 // no need to store r to memory until we exit
aoqi@0 3633 __ movdqa(xmm_prev_block_cipher, xmm_prev_block_cipher_save); // set up next r vector with cipher input from this block
aoqi@0 3634 __ addptr(pos, AESBlockSize);
aoqi@0 3635 __ subptr(len_reg, AESBlockSize);
aoqi@0 3636 __ jcc(Assembler::notEqual,L_singleBlock_loopTop_256);
aoqi@0 3637 __ jmp(L_exit);
aoqi@0 3638
aoqi@0 3639 return start;
aoqi@0 3640 }
aoqi@0 3641
aoqi@0 3642 /**
aoqi@0 3643 * Arguments:
aoqi@0 3644 *
aoqi@0 3645 * Inputs:
aoqi@0 3646 * c_rarg0 - int crc
aoqi@0 3647 * c_rarg1 - byte* buf
aoqi@0 3648 * c_rarg2 - int length
aoqi@0 3649 *
aoqi@0 3650 * Ouput:
aoqi@0 3651 * rax - int crc result
aoqi@0 3652 */
aoqi@0 3653 address generate_updateBytesCRC32() {
aoqi@0 3654 assert(UseCRC32Intrinsics, "need AVX and CLMUL instructions");
aoqi@0 3655
aoqi@0 3656 __ align(CodeEntryAlignment);
aoqi@0 3657 StubCodeMark mark(this, "StubRoutines", "updateBytesCRC32");
aoqi@0 3658
aoqi@0 3659 address start = __ pc();
aoqi@0 3660 // Win64: rcx, rdx, r8, r9 (c_rarg0, c_rarg1, ...)
aoqi@0 3661 // Unix: rdi, rsi, rdx, rcx, r8, r9 (c_rarg0, c_rarg1, ...)
aoqi@0 3662 // rscratch1: r10
aoqi@0 3663 const Register crc = c_rarg0; // crc
aoqi@0 3664 const Register buf = c_rarg1; // source java byte array address
aoqi@0 3665 const Register len = c_rarg2; // length
aoqi@0 3666 const Register table = c_rarg3; // crc_table address (reuse register)
aoqi@0 3667 const Register tmp = r11;
aoqi@0 3668 assert_different_registers(crc, buf, len, table, tmp, rax);
aoqi@0 3669
aoqi@0 3670 BLOCK_COMMENT("Entry:");
aoqi@0 3671 __ enter(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 3672
aoqi@0 3673 __ kernel_crc32(crc, buf, len, table, tmp);
aoqi@0 3674
aoqi@0 3675 __ movl(rax, crc);
aoqi@0 3676 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 3677 __ ret(0);
aoqi@0 3678
aoqi@0 3679 return start;
aoqi@0 3680 }
aoqi@0 3681
kvn@7152 3682
kvn@7152 3683 /**
kvn@7152 3684 * Arguments:
kvn@7152 3685 *
kvn@7152 3686 * Input:
kvn@7152 3687 * c_rarg0 - x address
kvn@7152 3688 * c_rarg1 - x length
kvn@7152 3689 * c_rarg2 - y address
kvn@7152 3690 * c_rarg3 - y lenth
kvn@7152 3691 * not Win64
kvn@7152 3692 * c_rarg4 - z address
kvn@7152 3693 * c_rarg5 - z length
kvn@7152 3694 * Win64
kvn@7152 3695 * rsp+40 - z address
kvn@7152 3696 * rsp+48 - z length
kvn@7152 3697 */
kvn@7152 3698 address generate_multiplyToLen() {
kvn@7152 3699 __ align(CodeEntryAlignment);
kvn@7152 3700 StubCodeMark mark(this, "StubRoutines", "multiplyToLen");
kvn@7152 3701
kvn@7152 3702 address start = __ pc();
kvn@7152 3703 // Win64: rcx, rdx, r8, r9 (c_rarg0, c_rarg1, ...)
kvn@7152 3704 // Unix: rdi, rsi, rdx, rcx, r8, r9 (c_rarg0, c_rarg1, ...)
kvn@7152 3705 const Register x = rdi;
kvn@7152 3706 const Register xlen = rax;
kvn@7152 3707 const Register y = rsi;
kvn@7152 3708 const Register ylen = rcx;
kvn@7152 3709 const Register z = r8;
kvn@7152 3710 const Register zlen = r11;
kvn@7152 3711
kvn@7152 3712 // Next registers will be saved on stack in multiply_to_len().
kvn@7152 3713 const Register tmp1 = r12;
kvn@7152 3714 const Register tmp2 = r13;
kvn@7152 3715 const Register tmp3 = r14;
kvn@7152 3716 const Register tmp4 = r15;
kvn@7152 3717 const Register tmp5 = rbx;
kvn@7152 3718
kvn@7152 3719 BLOCK_COMMENT("Entry:");
kvn@7152 3720 __ enter(); // required for proper stackwalking of RuntimeStub frame
kvn@7152 3721
kvn@7152 3722 #ifndef _WIN64
kvn@7152 3723 __ movptr(zlen, r9); // Save r9 in r11 - zlen
kvn@7152 3724 #endif
kvn@7152 3725 setup_arg_regs(4); // x => rdi, xlen => rsi, y => rdx
kvn@7152 3726 // ylen => rcx, z => r8, zlen => r11
kvn@7152 3727 // r9 and r10 may be used to save non-volatile registers
kvn@7152 3728 #ifdef _WIN64
kvn@7152 3729 // last 2 arguments (#4, #5) are on stack on Win64
kvn@7152 3730 __ movptr(z, Address(rsp, 6 * wordSize));
kvn@7152 3731 __ movptr(zlen, Address(rsp, 7 * wordSize));
kvn@7152 3732 #endif
kvn@7152 3733
kvn@7152 3734 __ movptr(xlen, rsi);
kvn@7152 3735 __ movptr(y, rdx);
kvn@7152 3736 __ multiply_to_len(x, xlen, y, ylen, z, zlen, tmp1, tmp2, tmp3, tmp4, tmp5);
kvn@7152 3737
kvn@7152 3738 restore_arg_regs();
kvn@7152 3739
kvn@7152 3740 __ leave(); // required for proper stackwalking of RuntimeStub frame
kvn@7152 3741 __ ret(0);
kvn@7152 3742
kvn@7152 3743 return start;
kvn@7152 3744 }
kvn@7152 3745
aoqi@0 3746 #undef __
aoqi@0 3747 #define __ masm->
aoqi@0 3748
aoqi@0 3749 // Continuation point for throwing of implicit exceptions that are
aoqi@0 3750 // not handled in the current activation. Fabricates an exception
aoqi@0 3751 // oop and initiates normal exception dispatching in this
aoqi@0 3752 // frame. Since we need to preserve callee-saved values (currently
aoqi@0 3753 // only for C2, but done for C1 as well) we need a callee-saved oop
aoqi@0 3754 // map and therefore have to make these stubs into RuntimeStubs
aoqi@0 3755 // rather than BufferBlobs. If the compiler needs all registers to
aoqi@0 3756 // be preserved between the fault point and the exception handler
aoqi@0 3757 // then it must assume responsibility for that in
aoqi@0 3758 // AbstractCompiler::continuation_for_implicit_null_exception or
aoqi@0 3759 // continuation_for_implicit_division_by_zero_exception. All other
aoqi@0 3760 // implicit exceptions (e.g., NullPointerException or
aoqi@0 3761 // AbstractMethodError on entry) are either at call sites or
aoqi@0 3762 // otherwise assume that stack unwinding will be initiated, so
aoqi@0 3763 // caller saved registers were assumed volatile in the compiler.
aoqi@0 3764 address generate_throw_exception(const char* name,
aoqi@0 3765 address runtime_entry,
aoqi@0 3766 Register arg1 = noreg,
aoqi@0 3767 Register arg2 = noreg) {
aoqi@0 3768 // Information about frame layout at time of blocking runtime call.
aoqi@0 3769 // Note that we only have to preserve callee-saved registers since
aoqi@0 3770 // the compilers are responsible for supplying a continuation point
aoqi@0 3771 // if they expect all registers to be preserved.
aoqi@0 3772 enum layout {
aoqi@0 3773 rbp_off = frame::arg_reg_save_area_bytes/BytesPerInt,
aoqi@0 3774 rbp_off2,
aoqi@0 3775 return_off,
aoqi@0 3776 return_off2,
aoqi@0 3777 framesize // inclusive of return address
aoqi@0 3778 };
aoqi@0 3779
aoqi@0 3780 int insts_size = 512;
aoqi@0 3781 int locs_size = 64;
aoqi@0 3782
aoqi@0 3783 CodeBuffer code(name, insts_size, locs_size);
aoqi@0 3784 OopMapSet* oop_maps = new OopMapSet();
aoqi@0 3785 MacroAssembler* masm = new MacroAssembler(&code);
aoqi@0 3786
aoqi@0 3787 address start = __ pc();
aoqi@0 3788
aoqi@0 3789 // This is an inlined and slightly modified version of call_VM
aoqi@0 3790 // which has the ability to fetch the return PC out of
aoqi@0 3791 // thread-local storage and also sets up last_Java_sp slightly
aoqi@0 3792 // differently than the real call_VM
aoqi@0 3793
aoqi@0 3794 __ enter(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 3795
aoqi@0 3796 assert(is_even(framesize/2), "sp not 16-byte aligned");
aoqi@0 3797
aoqi@0 3798 // return address and rbp are already in place
aoqi@0 3799 __ subptr(rsp, (framesize-4) << LogBytesPerInt); // prolog
aoqi@0 3800
aoqi@0 3801 int frame_complete = __ pc() - start;
aoqi@0 3802
aoqi@0 3803 // Set up last_Java_sp and last_Java_fp
aoqi@0 3804 address the_pc = __ pc();
aoqi@0 3805 __ set_last_Java_frame(rsp, rbp, the_pc);
aoqi@0 3806 __ andptr(rsp, -(StackAlignmentInBytes)); // Align stack
aoqi@0 3807
aoqi@0 3808 // Call runtime
aoqi@0 3809 if (arg1 != noreg) {
aoqi@0 3810 assert(arg2 != c_rarg1, "clobbered");
aoqi@0 3811 __ movptr(c_rarg1, arg1);
aoqi@0 3812 }
aoqi@0 3813 if (arg2 != noreg) {
aoqi@0 3814 __ movptr(c_rarg2, arg2);
aoqi@0 3815 }
aoqi@0 3816 __ movptr(c_rarg0, r15_thread);
aoqi@0 3817 BLOCK_COMMENT("call runtime_entry");
aoqi@0 3818 __ call(RuntimeAddress(runtime_entry));
aoqi@0 3819
aoqi@0 3820 // Generate oop map
aoqi@0 3821 OopMap* map = new OopMap(framesize, 0);
aoqi@0 3822
aoqi@0 3823 oop_maps->add_gc_map(the_pc - start, map);
aoqi@0 3824
aoqi@0 3825 __ reset_last_Java_frame(true, true);
aoqi@0 3826
aoqi@0 3827 __ leave(); // required for proper stackwalking of RuntimeStub frame
aoqi@0 3828
aoqi@0 3829 // check for pending exceptions
aoqi@0 3830 #ifdef ASSERT
aoqi@0 3831 Label L;
aoqi@0 3832 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()),
aoqi@0 3833 (int32_t) NULL_WORD);
aoqi@0 3834 __ jcc(Assembler::notEqual, L);
aoqi@0 3835 __ should_not_reach_here();
aoqi@0 3836 __ bind(L);
aoqi@0 3837 #endif // ASSERT
aoqi@0 3838 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
aoqi@0 3839
aoqi@0 3840
aoqi@0 3841 // codeBlob framesize is in words (not VMRegImpl::slot_size)
aoqi@0 3842 RuntimeStub* stub =
aoqi@0 3843 RuntimeStub::new_runtime_stub(name,
aoqi@0 3844 &code,
aoqi@0 3845 frame_complete,
aoqi@0 3846 (framesize >> (LogBytesPerWord - LogBytesPerInt)),
aoqi@0 3847 oop_maps, false);
aoqi@0 3848 return stub->entry_point();
aoqi@0 3849 }
aoqi@0 3850
aoqi@0 3851 void create_control_words() {
aoqi@0 3852 // Round to nearest, 53-bit mode, exceptions masked
aoqi@0 3853 StubRoutines::_fpu_cntrl_wrd_std = 0x027F;
aoqi@0 3854 // Round to zero, 53-bit mode, exception mased
aoqi@0 3855 StubRoutines::_fpu_cntrl_wrd_trunc = 0x0D7F;
aoqi@0 3856 // Round to nearest, 24-bit mode, exceptions masked
aoqi@0 3857 StubRoutines::_fpu_cntrl_wrd_24 = 0x007F;
aoqi@0 3858 // Round to nearest, 64-bit mode, exceptions masked
aoqi@0 3859 StubRoutines::_fpu_cntrl_wrd_64 = 0x037F;
aoqi@0 3860 // Round to nearest, 64-bit mode, exceptions masked
aoqi@0 3861 StubRoutines::_mxcsr_std = 0x1F80;
aoqi@0 3862 // Note: the following two constants are 80-bit values
aoqi@0 3863 // layout is critical for correct loading by FPU.
aoqi@0 3864 // Bias for strict fp multiply/divide
aoqi@0 3865 StubRoutines::_fpu_subnormal_bias1[0]= 0x00000000; // 2^(-15360) == 0x03ff 8000 0000 0000 0000
aoqi@0 3866 StubRoutines::_fpu_subnormal_bias1[1]= 0x80000000;
aoqi@0 3867 StubRoutines::_fpu_subnormal_bias1[2]= 0x03ff;
aoqi@0 3868 // Un-Bias for strict fp multiply/divide
aoqi@0 3869 StubRoutines::_fpu_subnormal_bias2[0]= 0x00000000; // 2^(+15360) == 0x7bff 8000 0000 0000 0000
aoqi@0 3870 StubRoutines::_fpu_subnormal_bias2[1]= 0x80000000;
aoqi@0 3871 StubRoutines::_fpu_subnormal_bias2[2]= 0x7bff;
aoqi@0 3872 }
aoqi@0 3873
aoqi@0 3874 // Initialization
aoqi@0 3875 void generate_initial() {
aoqi@0 3876 // Generates all stubs and initializes the entry points
aoqi@0 3877
aoqi@0 3878 // This platform-specific settings are needed by generate_call_stub()
aoqi@0 3879 create_control_words();
aoqi@0 3880
aoqi@0 3881 // entry points that exist in all platforms Note: This is code
aoqi@0 3882 // that could be shared among different platforms - however the
aoqi@0 3883 // benefit seems to be smaller than the disadvantage of having a
aoqi@0 3884 // much more complicated generator structure. See also comment in
aoqi@0 3885 // stubRoutines.hpp.
aoqi@0 3886
aoqi@0 3887 StubRoutines::_forward_exception_entry = generate_forward_exception();
aoqi@0 3888
aoqi@0 3889 StubRoutines::_call_stub_entry =
aoqi@0 3890 generate_call_stub(StubRoutines::_call_stub_return_address);
aoqi@0 3891
aoqi@0 3892 // is referenced by megamorphic call
aoqi@0 3893 StubRoutines::_catch_exception_entry = generate_catch_exception();
aoqi@0 3894
aoqi@0 3895 // atomic calls
aoqi@0 3896 StubRoutines::_atomic_xchg_entry = generate_atomic_xchg();
aoqi@0 3897 StubRoutines::_atomic_xchg_ptr_entry = generate_atomic_xchg_ptr();
aoqi@0 3898 StubRoutines::_atomic_cmpxchg_entry = generate_atomic_cmpxchg();
aoqi@0 3899 StubRoutines::_atomic_cmpxchg_long_entry = generate_atomic_cmpxchg_long();
aoqi@0 3900 StubRoutines::_atomic_add_entry = generate_atomic_add();
aoqi@0 3901 StubRoutines::_atomic_add_ptr_entry = generate_atomic_add_ptr();
aoqi@0 3902 StubRoutines::_fence_entry = generate_orderaccess_fence();
aoqi@0 3903
aoqi@0 3904 StubRoutines::_handler_for_unsafe_access_entry =
aoqi@0 3905 generate_handler_for_unsafe_access();
aoqi@0 3906
aoqi@0 3907 // platform dependent
aoqi@0 3908 StubRoutines::x86::_get_previous_fp_entry = generate_get_previous_fp();
aoqi@0 3909 StubRoutines::x86::_get_previous_sp_entry = generate_get_previous_sp();
aoqi@0 3910
aoqi@0 3911 StubRoutines::x86::_verify_mxcsr_entry = generate_verify_mxcsr();
aoqi@0 3912
aoqi@0 3913 // Build this early so it's available for the interpreter.
aoqi@0 3914 StubRoutines::_throw_StackOverflowError_entry =
aoqi@0 3915 generate_throw_exception("StackOverflowError throw_exception",
aoqi@0 3916 CAST_FROM_FN_PTR(address,
aoqi@0 3917 SharedRuntime::
aoqi@0 3918 throw_StackOverflowError));
aoqi@0 3919 if (UseCRC32Intrinsics) {
aoqi@0 3920 // set table address before stub generation which use it
aoqi@0 3921 StubRoutines::_crc_table_adr = (address)StubRoutines::x86::_crc_table;
aoqi@0 3922 StubRoutines::_updateBytesCRC32 = generate_updateBytesCRC32();
aoqi@0 3923 }
aoqi@0 3924 }
aoqi@0 3925
aoqi@0 3926 void generate_all() {
aoqi@0 3927 // Generates all stubs and initializes the entry points
aoqi@0 3928
aoqi@0 3929 // These entry points require SharedInfo::stack0 to be set up in
aoqi@0 3930 // non-core builds and need to be relocatable, so they each
aoqi@0 3931 // fabricate a RuntimeStub internally.
aoqi@0 3932 StubRoutines::_throw_AbstractMethodError_entry =
aoqi@0 3933 generate_throw_exception("AbstractMethodError throw_exception",
aoqi@0 3934 CAST_FROM_FN_PTR(address,
aoqi@0 3935 SharedRuntime::
aoqi@0 3936 throw_AbstractMethodError));
aoqi@0 3937
aoqi@0 3938 StubRoutines::_throw_IncompatibleClassChangeError_entry =
aoqi@0 3939 generate_throw_exception("IncompatibleClassChangeError throw_exception",
aoqi@0 3940 CAST_FROM_FN_PTR(address,
aoqi@0 3941 SharedRuntime::
aoqi@0 3942 throw_IncompatibleClassChangeError));
aoqi@0 3943
aoqi@0 3944 StubRoutines::_throw_NullPointerException_at_call_entry =
aoqi@0 3945 generate_throw_exception("NullPointerException at call throw_exception",
aoqi@0 3946 CAST_FROM_FN_PTR(address,
aoqi@0 3947 SharedRuntime::
aoqi@0 3948 throw_NullPointerException_at_call));
aoqi@0 3949
aoqi@0 3950 // entry points that are platform specific
aoqi@0 3951 StubRoutines::x86::_f2i_fixup = generate_f2i_fixup();
aoqi@0 3952 StubRoutines::x86::_f2l_fixup = generate_f2l_fixup();
aoqi@0 3953 StubRoutines::x86::_d2i_fixup = generate_d2i_fixup();
aoqi@0 3954 StubRoutines::x86::_d2l_fixup = generate_d2l_fixup();
aoqi@0 3955
aoqi@0 3956 StubRoutines::x86::_float_sign_mask = generate_fp_mask("float_sign_mask", 0x7FFFFFFF7FFFFFFF);
aoqi@0 3957 StubRoutines::x86::_float_sign_flip = generate_fp_mask("float_sign_flip", 0x8000000080000000);
aoqi@0 3958 StubRoutines::x86::_double_sign_mask = generate_fp_mask("double_sign_mask", 0x7FFFFFFFFFFFFFFF);
aoqi@0 3959 StubRoutines::x86::_double_sign_flip = generate_fp_mask("double_sign_flip", 0x8000000000000000);
aoqi@0 3960
aoqi@0 3961 // support for verify_oop (must happen after universe_init)
aoqi@0 3962 StubRoutines::_verify_oop_subroutine_entry = generate_verify_oop();
aoqi@0 3963
aoqi@0 3964 // arraycopy stubs used by compilers
aoqi@0 3965 generate_arraycopy_stubs();
aoqi@0 3966
aoqi@0 3967 generate_math_stubs();
aoqi@0 3968
aoqi@0 3969 // don't bother generating these AES intrinsic stubs unless global flag is set
aoqi@0 3970 if (UseAESIntrinsics) {
aoqi@0 3971 StubRoutines::x86::_key_shuffle_mask_addr = generate_key_shuffle_mask(); // needed by the others
aoqi@0 3972
aoqi@0 3973 StubRoutines::_aescrypt_encryptBlock = generate_aescrypt_encryptBlock();
aoqi@0 3974 StubRoutines::_aescrypt_decryptBlock = generate_aescrypt_decryptBlock();
aoqi@0 3975 StubRoutines::_cipherBlockChaining_encryptAESCrypt = generate_cipherBlockChaining_encryptAESCrypt();
aoqi@0 3976 StubRoutines::_cipherBlockChaining_decryptAESCrypt = generate_cipherBlockChaining_decryptAESCrypt_Parallel();
aoqi@0 3977 }
aoqi@0 3978
aoqi@0 3979 // Safefetch stubs.
aoqi@0 3980 generate_safefetch("SafeFetch32", sizeof(int), &StubRoutines::_safefetch32_entry,
aoqi@0 3981 &StubRoutines::_safefetch32_fault_pc,
aoqi@0 3982 &StubRoutines::_safefetch32_continuation_pc);
aoqi@0 3983 generate_safefetch("SafeFetchN", sizeof(intptr_t), &StubRoutines::_safefetchN_entry,
aoqi@0 3984 &StubRoutines::_safefetchN_fault_pc,
aoqi@0 3985 &StubRoutines::_safefetchN_continuation_pc);
kvn@7152 3986 #ifdef COMPILER2
kvn@7152 3987 if (UseMultiplyToLenIntrinsic) {
kvn@7152 3988 StubRoutines::_multiplyToLen = generate_multiplyToLen();
kvn@7152 3989 }
kvn@7152 3990 #endif
aoqi@0 3991 }
aoqi@0 3992
aoqi@0 3993 public:
aoqi@0 3994 StubGenerator(CodeBuffer* code, bool all) : StubCodeGenerator(code) {
aoqi@0 3995 if (all) {
aoqi@0 3996 generate_all();
aoqi@0 3997 } else {
aoqi@0 3998 generate_initial();
aoqi@0 3999 }
aoqi@0 4000 }
aoqi@0 4001 }; // end class declaration
aoqi@0 4002
aoqi@0 4003 void StubGenerator_generate(CodeBuffer* code, bool all) {
aoqi@0 4004 StubGenerator g(code, all);
aoqi@0 4005 }

mercurial