annotate src/cpu/x86/vm/stubGenerator_x86_32.cpp @ 3534:1d7922586cf6

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