src/cpu/x86/vm/stubGenerator_x86_32.cpp

Sat, 29 Sep 2012 06:40:00 -0400

author
coleenp
date
Sat, 29 Sep 2012 06:40:00 -0400
changeset 4142
d8ce2825b193
parent 4037
da91efe96a93
child 4205
a3ecd773a7b9
permissions
-rw-r--r--

8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
Summary: Capitalize these metadata types (and objArrayKlass)
Reviewed-by: stefank, twisti, kvn

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

mercurial