src/cpu/x86/vm/stubGenerator_x86_64.cpp

Fri, 25 Jan 2013 10:04:08 -0500

author
zgu
date
Fri, 25 Jan 2013 10:04:08 -0500
changeset 4492
8b46b0196eb0
parent 4411
e2e6bf86682c
child 4873
e961c11b85fe
permissions
-rw-r--r--

8000692: Remove old KERNEL code
Summary: Removed depreciated kernel VM source code from hotspot VM
Reviewed-by: dholmes, acorn

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

mercurial