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