src/cpu/x86/vm/stubGenerator_x86_64.cpp

Thu, 02 Oct 2008 19:58:19 -0700

author
xdono
date
Thu, 02 Oct 2008 19:58:19 -0700
changeset 772
9ee9cf798b59
parent 739
dc7f315e41f7
child 797
f8199438385b
permissions
-rw-r--r--

6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell

     1 /*
     2  * Copyright 2003-2008 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 #include "incls/_precompiled.incl"
    26 #include "incls/_stubGenerator_x86_64.cpp.incl"
    28 // Declaration and definition of StubGenerator (no .hpp file).
    29 // For a more detailed description of the stub routine structure
    30 // see the comment in stubRoutines.hpp
    32 #define __ _masm->
    33 #define TIMES_OOP (UseCompressedOops ? Address::times_4 : Address::times_8)
    34 #define a__ ((Assembler*)_masm)->
    36 #ifdef PRODUCT
    37 #define BLOCK_COMMENT(str) /* nothing */
    38 #else
    39 #define BLOCK_COMMENT(str) __ block_comment(str)
    40 #endif
    42 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
    43 const int MXCSR_MASK = 0xFFC0;  // Mask out any pending exceptions
    45 // Stub Code definitions
    47 static address handle_unsafe_access() {
    48   JavaThread* thread = JavaThread::current();
    49   address pc = thread->saved_exception_pc();
    50   // pc is the instruction which we must emulate
    51   // doing a no-op is fine:  return garbage from the load
    52   // therefore, compute npc
    53   address npc = Assembler::locate_next_instruction(pc);
    55   // request an async exception
    56   thread->set_pending_unsafe_access_error();
    58   // return address of next instruction to execute
    59   return npc;
    60 }
    62 class StubGenerator: public StubCodeGenerator {
    63  private:
    65 #ifdef PRODUCT
    66 #define inc_counter_np(counter) (0)
    67 #else
    68   void inc_counter_np_(int& counter) {
    69     __ incrementl(ExternalAddress((address)&counter));
    70   }
    71 #define inc_counter_np(counter) \
    72   BLOCK_COMMENT("inc_counter " #counter); \
    73   inc_counter_np_(counter);
    74 #endif
    76   // Call stubs are used to call Java from C
    77   //
    78   // Linux Arguments:
    79   //    c_rarg0:   call wrapper address                   address
    80   //    c_rarg1:   result                                 address
    81   //    c_rarg2:   result type                            BasicType
    82   //    c_rarg3:   method                                 methodOop
    83   //    c_rarg4:   (interpreter) entry point              address
    84   //    c_rarg5:   parameters                             intptr_t*
    85   //    16(rbp): parameter size (in words)              int
    86   //    24(rbp): thread                                 Thread*
    87   //
    88   //     [ return_from_Java     ] <--- rsp
    89   //     [ argument word n      ]
    90   //      ...
    91   // -12 [ argument word 1      ]
    92   // -11 [ saved r15            ] <--- rsp_after_call
    93   // -10 [ saved r14            ]
    94   //  -9 [ saved r13            ]
    95   //  -8 [ saved r12            ]
    96   //  -7 [ saved rbx            ]
    97   //  -6 [ call wrapper         ]
    98   //  -5 [ result               ]
    99   //  -4 [ result type          ]
   100   //  -3 [ method               ]
   101   //  -2 [ entry point          ]
   102   //  -1 [ parameters           ]
   103   //   0 [ saved rbp            ] <--- rbp
   104   //   1 [ return address       ]
   105   //   2 [ parameter size       ]
   106   //   3 [ thread               ]
   107   //
   108   // Windows Arguments:
   109   //    c_rarg0:   call wrapper address                   address
   110   //    c_rarg1:   result                                 address
   111   //    c_rarg2:   result type                            BasicType
   112   //    c_rarg3:   method                                 methodOop
   113   //    48(rbp): (interpreter) entry point              address
   114   //    56(rbp): parameters                             intptr_t*
   115   //    64(rbp): parameter size (in words)              int
   116   //    72(rbp): thread                                 Thread*
   117   //
   118   //     [ return_from_Java     ] <--- rsp
   119   //     [ argument word n      ]
   120   //      ...
   121   //  -8 [ argument word 1      ]
   122   //  -7 [ saved r15            ] <--- rsp_after_call
   123   //  -6 [ saved r14            ]
   124   //  -5 [ saved r13            ]
   125   //  -4 [ saved r12            ]
   126   //  -3 [ saved rdi            ]
   127   //  -2 [ saved rsi            ]
   128   //  -1 [ saved rbx            ]
   129   //   0 [ saved rbp            ] <--- rbp
   130   //   1 [ return address       ]
   131   //   2 [ call wrapper         ]
   132   //   3 [ result               ]
   133   //   4 [ result type          ]
   134   //   5 [ method               ]
   135   //   6 [ entry point          ]
   136   //   7 [ parameters           ]
   137   //   8 [ parameter size       ]
   138   //   9 [ thread               ]
   139   //
   140   //    Windows reserves the callers stack space for arguments 1-4.
   141   //    We spill c_rarg0-c_rarg3 to this space.
   143   // Call stub stack layout word offsets from rbp
   144   enum call_stub_layout {
   145 #ifdef _WIN64
   146     rsp_after_call_off = -7,
   147     r15_off            = rsp_after_call_off,
   148     r14_off            = -6,
   149     r13_off            = -5,
   150     r12_off            = -4,
   151     rdi_off            = -3,
   152     rsi_off            = -2,
   153     rbx_off            = -1,
   154     rbp_off            =  0,
   155     retaddr_off        =  1,
   156     call_wrapper_off   =  2,
   157     result_off         =  3,
   158     result_type_off    =  4,
   159     method_off         =  5,
   160     entry_point_off    =  6,
   161     parameters_off     =  7,
   162     parameter_size_off =  8,
   163     thread_off         =  9
   164 #else
   165     rsp_after_call_off = -12,
   166     mxcsr_off          = rsp_after_call_off,
   167     r15_off            = -11,
   168     r14_off            = -10,
   169     r13_off            = -9,
   170     r12_off            = -8,
   171     rbx_off            = -7,
   172     call_wrapper_off   = -6,
   173     result_off         = -5,
   174     result_type_off    = -4,
   175     method_off         = -3,
   176     entry_point_off    = -2,
   177     parameters_off     = -1,
   178     rbp_off            =  0,
   179     retaddr_off        =  1,
   180     parameter_size_off =  2,
   181     thread_off         =  3
   182 #endif
   183   };
   185   address generate_call_stub(address& return_address) {
   186     assert((int)frame::entry_frame_after_call_words == -(int)rsp_after_call_off + 1 &&
   187            (int)frame::entry_frame_call_wrapper_offset == (int)call_wrapper_off,
   188            "adjust this code");
   189     StubCodeMark mark(this, "StubRoutines", "call_stub");
   190     address start = __ pc();
   192     // same as in generate_catch_exception()!
   193     const Address rsp_after_call(rbp, rsp_after_call_off * wordSize);
   195     const Address call_wrapper  (rbp, call_wrapper_off   * wordSize);
   196     const Address result        (rbp, result_off         * wordSize);
   197     const Address result_type   (rbp, result_type_off    * wordSize);
   198     const Address method        (rbp, method_off         * wordSize);
   199     const Address entry_point   (rbp, entry_point_off    * wordSize);
   200     const Address parameters    (rbp, parameters_off     * wordSize);
   201     const Address parameter_size(rbp, parameter_size_off * wordSize);
   203     // same as in generate_catch_exception()!
   204     const Address thread        (rbp, thread_off         * wordSize);
   206     const Address r15_save(rbp, r15_off * wordSize);
   207     const Address r14_save(rbp, r14_off * wordSize);
   208     const Address r13_save(rbp, r13_off * wordSize);
   209     const Address r12_save(rbp, r12_off * wordSize);
   210     const Address rbx_save(rbp, rbx_off * wordSize);
   212     // stub code
   213     __ enter();
   214     __ subptr(rsp, -rsp_after_call_off * wordSize);
   216     // save register parameters
   217 #ifndef _WIN64
   218     __ movptr(parameters,   c_rarg5); // parameters
   219     __ movptr(entry_point,  c_rarg4); // entry_point
   220 #endif
   222     __ movptr(method,       c_rarg3); // method
   223     __ movl(result_type,  c_rarg2);   // result type
   224     __ movptr(result,       c_rarg1); // result
   225     __ movptr(call_wrapper, c_rarg0); // call wrapper
   227     // save regs belonging to calling function
   228     __ movptr(rbx_save, rbx);
   229     __ movptr(r12_save, r12);
   230     __ movptr(r13_save, r13);
   231     __ movptr(r14_save, r14);
   232     __ movptr(r15_save, r15);
   234 #ifdef _WIN64
   235     const Address rdi_save(rbp, rdi_off * wordSize);
   236     const Address rsi_save(rbp, rsi_off * wordSize);
   238     __ movptr(rsi_save, rsi);
   239     __ movptr(rdi_save, rdi);
   240 #else
   241     const Address mxcsr_save(rbp, mxcsr_off * wordSize);
   242     {
   243       Label skip_ldmx;
   244       __ stmxcsr(mxcsr_save);
   245       __ movl(rax, mxcsr_save);
   246       __ andl(rax, MXCSR_MASK);    // Only check control and mask bits
   247       ExternalAddress mxcsr_std(StubRoutines::x86::mxcsr_std());
   248       __ cmp32(rax, mxcsr_std);
   249       __ jcc(Assembler::equal, skip_ldmx);
   250       __ ldmxcsr(mxcsr_std);
   251       __ bind(skip_ldmx);
   252     }
   253 #endif
   255     // Load up thread register
   256     __ movptr(r15_thread, thread);
   257     __ reinit_heapbase();
   259 #ifdef ASSERT
   260     // make sure we have no pending exceptions
   261     {
   262       Label L;
   263       __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
   264       __ jcc(Assembler::equal, L);
   265       __ stop("StubRoutines::call_stub: entered with pending exception");
   266       __ bind(L);
   267     }
   268 #endif
   270     // pass parameters if any
   271     BLOCK_COMMENT("pass parameters if any");
   272     Label parameters_done;
   273     __ movl(c_rarg3, parameter_size);
   274     __ testl(c_rarg3, c_rarg3);
   275     __ jcc(Assembler::zero, parameters_done);
   277     Label loop;
   278     __ movptr(c_rarg2, parameters);       // parameter pointer
   279     __ movl(c_rarg1, c_rarg3);            // parameter counter is in c_rarg1
   280     __ BIND(loop);
   281     if (TaggedStackInterpreter) {
   282       __ movl(rax, Address(c_rarg2, 0)); // get tag
   283       __ addptr(c_rarg2, wordSize);      // advance to next tag
   284       __ push(rax);                      // pass tag
   285     }
   286     __ movptr(rax, Address(c_rarg2, 0));// get parameter
   287     __ addptr(c_rarg2, wordSize);       // advance to next parameter
   288     __ decrementl(c_rarg1);             // decrement counter
   289     __ push(rax);                       // pass parameter
   290     __ jcc(Assembler::notZero, loop);
   292     // call Java function
   293     __ BIND(parameters_done);
   294     __ movptr(rbx, method);             // get methodOop
   295     __ movptr(c_rarg1, entry_point);    // get entry_point
   296     __ mov(r13, rsp);                   // set sender sp
   297     BLOCK_COMMENT("call Java function");
   298     __ call(c_rarg1);
   300     BLOCK_COMMENT("call_stub_return_address:");
   301     return_address = __ pc();
   303     // store result depending on type (everything that is not
   304     // T_OBJECT, T_LONG, T_FLOAT or T_DOUBLE is treated as T_INT)
   305     __ movptr(c_rarg0, result);
   306     Label is_long, is_float, is_double, exit;
   307     __ movl(c_rarg1, result_type);
   308     __ cmpl(c_rarg1, T_OBJECT);
   309     __ jcc(Assembler::equal, is_long);
   310     __ cmpl(c_rarg1, T_LONG);
   311     __ jcc(Assembler::equal, is_long);
   312     __ cmpl(c_rarg1, T_FLOAT);
   313     __ jcc(Assembler::equal, is_float);
   314     __ cmpl(c_rarg1, T_DOUBLE);
   315     __ jcc(Assembler::equal, is_double);
   317     // handle T_INT case
   318     __ movl(Address(c_rarg0, 0), rax);
   320     __ BIND(exit);
   322     // pop parameters
   323     __ lea(rsp, rsp_after_call);
   325 #ifdef ASSERT
   326     // verify that threads correspond
   327     {
   328       Label L, S;
   329       __ cmpptr(r15_thread, thread);
   330       __ jcc(Assembler::notEqual, S);
   331       __ get_thread(rbx);
   332       __ cmpptr(r15_thread, rbx);
   333       __ jcc(Assembler::equal, L);
   334       __ bind(S);
   335       __ jcc(Assembler::equal, L);
   336       __ stop("StubRoutines::call_stub: threads must correspond");
   337       __ bind(L);
   338     }
   339 #endif
   341     // restore regs belonging to calling function
   342     __ movptr(r15, r15_save);
   343     __ movptr(r14, r14_save);
   344     __ movptr(r13, r13_save);
   345     __ movptr(r12, r12_save);
   346     __ movptr(rbx, rbx_save);
   348 #ifdef _WIN64
   349     __ movptr(rdi, rdi_save);
   350     __ movptr(rsi, rsi_save);
   351 #else
   352     __ ldmxcsr(mxcsr_save);
   353 #endif
   355     // restore rsp
   356     __ addptr(rsp, -rsp_after_call_off * wordSize);
   358     // return
   359     __ pop(rbp);
   360     __ ret(0);
   362     // handle return types different from T_INT
   363     __ BIND(is_long);
   364     __ movq(Address(c_rarg0, 0), rax);
   365     __ jmp(exit);
   367     __ BIND(is_float);
   368     __ movflt(Address(c_rarg0, 0), xmm0);
   369     __ jmp(exit);
   371     __ BIND(is_double);
   372     __ movdbl(Address(c_rarg0, 0), xmm0);
   373     __ jmp(exit);
   375     return start;
   376   }
   378   // Return point for a Java call if there's an exception thrown in
   379   // Java code.  The exception is caught and transformed into a
   380   // pending exception stored in JavaThread that can be tested from
   381   // within the VM.
   382   //
   383   // Note: Usually the parameters are removed by the callee. In case
   384   // of an exception crossing an activation frame boundary, that is
   385   // not the case if the callee is compiled code => need to setup the
   386   // rsp.
   387   //
   388   // rax: exception oop
   390   address generate_catch_exception() {
   391     StubCodeMark mark(this, "StubRoutines", "catch_exception");
   392     address start = __ pc();
   394     // same as in generate_call_stub():
   395     const Address rsp_after_call(rbp, rsp_after_call_off * wordSize);
   396     const Address thread        (rbp, thread_off         * wordSize);
   398 #ifdef ASSERT
   399     // verify that threads correspond
   400     {
   401       Label L, S;
   402       __ cmpptr(r15_thread, thread);
   403       __ jcc(Assembler::notEqual, S);
   404       __ get_thread(rbx);
   405       __ cmpptr(r15_thread, rbx);
   406       __ jcc(Assembler::equal, L);
   407       __ bind(S);
   408       __ stop("StubRoutines::catch_exception: threads must correspond");
   409       __ bind(L);
   410     }
   411 #endif
   413     // set pending exception
   414     __ verify_oop(rax);
   416     __ movptr(Address(r15_thread, Thread::pending_exception_offset()), rax);
   417     __ lea(rscratch1, ExternalAddress((address)__FILE__));
   418     __ movptr(Address(r15_thread, Thread::exception_file_offset()), rscratch1);
   419     __ movl(Address(r15_thread, Thread::exception_line_offset()), (int)  __LINE__);
   421     // complete return to VM
   422     assert(StubRoutines::_call_stub_return_address != NULL,
   423            "_call_stub_return_address must have been generated before");
   424     __ jump(RuntimeAddress(StubRoutines::_call_stub_return_address));
   426     return start;
   427   }
   429   // Continuation point for runtime calls returning with a pending
   430   // exception.  The pending exception check happened in the runtime
   431   // or native call stub.  The pending exception in Thread is
   432   // converted into a Java-level exception.
   433   //
   434   // Contract with Java-level exception handlers:
   435   // rax: exception
   436   // rdx: throwing pc
   437   //
   438   // NOTE: At entry of this stub, exception-pc must be on stack !!
   440   address generate_forward_exception() {
   441     StubCodeMark mark(this, "StubRoutines", "forward exception");
   442     address start = __ pc();
   444     // Upon entry, the sp points to the return address returning into
   445     // Java (interpreted or compiled) code; i.e., the return address
   446     // becomes the throwing pc.
   447     //
   448     // Arguments pushed before the runtime call are still on the stack
   449     // but the exception handler will reset the stack pointer ->
   450     // ignore them.  A potential result in registers can be ignored as
   451     // well.
   453 #ifdef ASSERT
   454     // make sure this code is only executed if there is a pending exception
   455     {
   456       Label L;
   457       __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t) NULL);
   458       __ jcc(Assembler::notEqual, L);
   459       __ stop("StubRoutines::forward exception: no pending exception (1)");
   460       __ bind(L);
   461     }
   462 #endif
   464     // compute exception handler into rbx
   465     __ movptr(c_rarg0, Address(rsp, 0));
   466     BLOCK_COMMENT("call exception_handler_for_return_address");
   467     __ call_VM_leaf(CAST_FROM_FN_PTR(address,
   468                          SharedRuntime::exception_handler_for_return_address),
   469                     c_rarg0);
   470     __ mov(rbx, rax);
   472     // setup rax & rdx, remove return address & clear pending exception
   473     __ pop(rdx);
   474     __ movptr(rax, Address(r15_thread, Thread::pending_exception_offset()));
   475     __ movptr(Address(r15_thread, Thread::pending_exception_offset()), (int)NULL_WORD);
   477 #ifdef ASSERT
   478     // make sure exception is set
   479     {
   480       Label L;
   481       __ testptr(rax, rax);
   482       __ jcc(Assembler::notEqual, L);
   483       __ stop("StubRoutines::forward exception: no pending exception (2)");
   484       __ bind(L);
   485     }
   486 #endif
   488     // continue at exception handler (return address removed)
   489     // rax: exception
   490     // rbx: exception handler
   491     // rdx: throwing pc
   492     __ verify_oop(rax);
   493     __ jmp(rbx);
   495     return start;
   496   }
   498   // Support for jint atomic::xchg(jint exchange_value, volatile jint* dest)
   499   //
   500   // Arguments :
   501   //    c_rarg0: exchange_value
   502   //    c_rarg0: dest
   503   //
   504   // Result:
   505   //    *dest <- ex, return (orig *dest)
   506   address generate_atomic_xchg() {
   507     StubCodeMark mark(this, "StubRoutines", "atomic_xchg");
   508     address start = __ pc();
   510     __ movl(rax, c_rarg0); // Copy to eax we need a return value anyhow
   511     __ xchgl(rax, Address(c_rarg1, 0)); // automatic LOCK
   512     __ ret(0);
   514     return start;
   515   }
   517   // Support for intptr_t atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest)
   518   //
   519   // Arguments :
   520   //    c_rarg0: exchange_value
   521   //    c_rarg1: dest
   522   //
   523   // Result:
   524   //    *dest <- ex, return (orig *dest)
   525   address generate_atomic_xchg_ptr() {
   526     StubCodeMark mark(this, "StubRoutines", "atomic_xchg_ptr");
   527     address start = __ pc();
   529     __ movptr(rax, c_rarg0); // Copy to eax we need a return value anyhow
   530     __ xchgptr(rax, Address(c_rarg1, 0)); // automatic LOCK
   531     __ ret(0);
   533     return start;
   534   }
   536   // Support for jint atomic::atomic_cmpxchg(jint exchange_value, volatile jint* dest,
   537   //                                         jint compare_value)
   538   //
   539   // Arguments :
   540   //    c_rarg0: exchange_value
   541   //    c_rarg1: dest
   542   //    c_rarg2: compare_value
   543   //
   544   // Result:
   545   //    if ( compare_value == *dest ) {
   546   //       *dest = exchange_value
   547   //       return compare_value;
   548   //    else
   549   //       return *dest;
   550   address generate_atomic_cmpxchg() {
   551     StubCodeMark mark(this, "StubRoutines", "atomic_cmpxchg");
   552     address start = __ pc();
   554     __ movl(rax, c_rarg2);
   555    if ( os::is_MP() ) __ lock();
   556     __ cmpxchgl(c_rarg0, Address(c_rarg1, 0));
   557     __ ret(0);
   559     return start;
   560   }
   562   // Support for jint atomic::atomic_cmpxchg_long(jlong exchange_value,
   563   //                                             volatile jlong* dest,
   564   //                                             jlong compare_value)
   565   // Arguments :
   566   //    c_rarg0: exchange_value
   567   //    c_rarg1: dest
   568   //    c_rarg2: compare_value
   569   //
   570   // Result:
   571   //    if ( compare_value == *dest ) {
   572   //       *dest = exchange_value
   573   //       return compare_value;
   574   //    else
   575   //       return *dest;
   576   address generate_atomic_cmpxchg_long() {
   577     StubCodeMark mark(this, "StubRoutines", "atomic_cmpxchg_long");
   578     address start = __ pc();
   580     __ movq(rax, c_rarg2);
   581    if ( os::is_MP() ) __ lock();
   582     __ cmpxchgq(c_rarg0, Address(c_rarg1, 0));
   583     __ ret(0);
   585     return start;
   586   }
   588   // Support for jint atomic::add(jint add_value, volatile jint* dest)
   589   //
   590   // Arguments :
   591   //    c_rarg0: add_value
   592   //    c_rarg1: dest
   593   //
   594   // Result:
   595   //    *dest += add_value
   596   //    return *dest;
   597   address generate_atomic_add() {
   598     StubCodeMark mark(this, "StubRoutines", "atomic_add");
   599     address start = __ pc();
   601     __ movl(rax, c_rarg0);
   602    if ( os::is_MP() ) __ lock();
   603     __ xaddl(Address(c_rarg1, 0), c_rarg0);
   604     __ addl(rax, c_rarg0);
   605     __ ret(0);
   607     return start;
   608   }
   610   // Support for intptr_t atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest)
   611   //
   612   // Arguments :
   613   //    c_rarg0: add_value
   614   //    c_rarg1: dest
   615   //
   616   // Result:
   617   //    *dest += add_value
   618   //    return *dest;
   619   address generate_atomic_add_ptr() {
   620     StubCodeMark mark(this, "StubRoutines", "atomic_add_ptr");
   621     address start = __ pc();
   623     __ movptr(rax, c_rarg0); // Copy to eax we need a return value anyhow
   624    if ( os::is_MP() ) __ lock();
   625     __ xaddptr(Address(c_rarg1, 0), c_rarg0);
   626     __ addptr(rax, c_rarg0);
   627     __ ret(0);
   629     return start;
   630   }
   632   // Support for intptr_t OrderAccess::fence()
   633   //
   634   // Arguments :
   635   //
   636   // Result:
   637   address generate_orderaccess_fence() {
   638     StubCodeMark mark(this, "StubRoutines", "orderaccess_fence");
   639     address start = __ pc();
   640     __ mfence();
   641     __ ret(0);
   643     return start;
   644   }
   646   // Support for intptr_t get_previous_fp()
   647   //
   648   // This routine is used to find the previous frame pointer for the
   649   // caller (current_frame_guess). This is used as part of debugging
   650   // ps() is seemingly lost trying to find frames.
   651   // This code assumes that caller current_frame_guess) has a frame.
   652   address generate_get_previous_fp() {
   653     StubCodeMark mark(this, "StubRoutines", "get_previous_fp");
   654     const Address old_fp(rbp, 0);
   655     const Address older_fp(rax, 0);
   656     address start = __ pc();
   658     __ enter();
   659     __ movptr(rax, old_fp); // callers fp
   660     __ movptr(rax, older_fp); // the frame for ps()
   661     __ pop(rbp);
   662     __ ret(0);
   664     return start;
   665   }
   667   //----------------------------------------------------------------------------------------------------
   668   // Support for void verify_mxcsr()
   669   //
   670   // This routine is used with -Xcheck:jni to verify that native
   671   // JNI code does not return to Java code without restoring the
   672   // MXCSR register to our expected state.
   674   address generate_verify_mxcsr() {
   675     StubCodeMark mark(this, "StubRoutines", "verify_mxcsr");
   676     address start = __ pc();
   678     const Address mxcsr_save(rsp, 0);
   680     if (CheckJNICalls) {
   681       Label ok_ret;
   682       __ push(rax);
   683       __ subptr(rsp, wordSize);      // allocate a temp location
   684       __ stmxcsr(mxcsr_save);
   685       __ movl(rax, mxcsr_save);
   686       __ andl(rax, MXCSR_MASK);    // Only check control and mask bits
   687       __ cmpl(rax, *(int *)(StubRoutines::x86::mxcsr_std()));
   688       __ jcc(Assembler::equal, ok_ret);
   690       __ warn("MXCSR changed by native JNI code, use -XX:+RestoreMXCSROnJNICall");
   692       __ ldmxcsr(ExternalAddress(StubRoutines::x86::mxcsr_std()));
   694       __ bind(ok_ret);
   695       __ addptr(rsp, wordSize);
   696       __ pop(rax);
   697     }
   699     __ ret(0);
   701     return start;
   702   }
   704   address generate_f2i_fixup() {
   705     StubCodeMark mark(this, "StubRoutines", "f2i_fixup");
   706     Address inout(rsp, 5 * wordSize); // return address + 4 saves
   708     address start = __ pc();
   710     Label L;
   712     __ push(rax);
   713     __ push(c_rarg3);
   714     __ push(c_rarg2);
   715     __ push(c_rarg1);
   717     __ movl(rax, 0x7f800000);
   718     __ xorl(c_rarg3, c_rarg3);
   719     __ movl(c_rarg2, inout);
   720     __ movl(c_rarg1, c_rarg2);
   721     __ andl(c_rarg1, 0x7fffffff);
   722     __ cmpl(rax, c_rarg1); // NaN? -> 0
   723     __ jcc(Assembler::negative, L);
   724     __ testl(c_rarg2, c_rarg2); // signed ? min_jint : max_jint
   725     __ movl(c_rarg3, 0x80000000);
   726     __ movl(rax, 0x7fffffff);
   727     __ cmovl(Assembler::positive, c_rarg3, rax);
   729     __ bind(L);
   730     __ movptr(inout, c_rarg3);
   732     __ pop(c_rarg1);
   733     __ pop(c_rarg2);
   734     __ pop(c_rarg3);
   735     __ pop(rax);
   737     __ ret(0);
   739     return start;
   740   }
   742   address generate_f2l_fixup() {
   743     StubCodeMark mark(this, "StubRoutines", "f2l_fixup");
   744     Address inout(rsp, 5 * wordSize); // return address + 4 saves
   745     address start = __ pc();
   747     Label L;
   749     __ push(rax);
   750     __ push(c_rarg3);
   751     __ push(c_rarg2);
   752     __ push(c_rarg1);
   754     __ movl(rax, 0x7f800000);
   755     __ xorl(c_rarg3, c_rarg3);
   756     __ movl(c_rarg2, inout);
   757     __ movl(c_rarg1, c_rarg2);
   758     __ andl(c_rarg1, 0x7fffffff);
   759     __ cmpl(rax, c_rarg1); // NaN? -> 0
   760     __ jcc(Assembler::negative, L);
   761     __ testl(c_rarg2, c_rarg2); // signed ? min_jlong : max_jlong
   762     __ mov64(c_rarg3, 0x8000000000000000);
   763     __ mov64(rax, 0x7fffffffffffffff);
   764     __ cmov(Assembler::positive, c_rarg3, rax);
   766     __ bind(L);
   767     __ movptr(inout, c_rarg3);
   769     __ pop(c_rarg1);
   770     __ pop(c_rarg2);
   771     __ pop(c_rarg3);
   772     __ pop(rax);
   774     __ ret(0);
   776     return start;
   777   }
   779   address generate_d2i_fixup() {
   780     StubCodeMark mark(this, "StubRoutines", "d2i_fixup");
   781     Address inout(rsp, 6 * wordSize); // return address + 5 saves
   783     address start = __ pc();
   785     Label L;
   787     __ push(rax);
   788     __ push(c_rarg3);
   789     __ push(c_rarg2);
   790     __ push(c_rarg1);
   791     __ push(c_rarg0);
   793     __ movl(rax, 0x7ff00000);
   794     __ movq(c_rarg2, inout);
   795     __ movl(c_rarg3, c_rarg2);
   796     __ mov(c_rarg1, c_rarg2);
   797     __ mov(c_rarg0, c_rarg2);
   798     __ negl(c_rarg3);
   799     __ shrptr(c_rarg1, 0x20);
   800     __ orl(c_rarg3, c_rarg2);
   801     __ andl(c_rarg1, 0x7fffffff);
   802     __ xorl(c_rarg2, c_rarg2);
   803     __ shrl(c_rarg3, 0x1f);
   804     __ orl(c_rarg1, c_rarg3);
   805     __ cmpl(rax, c_rarg1);
   806     __ jcc(Assembler::negative, L); // NaN -> 0
   807     __ testptr(c_rarg0, c_rarg0); // signed ? min_jint : max_jint
   808     __ movl(c_rarg2, 0x80000000);
   809     __ movl(rax, 0x7fffffff);
   810     __ cmov(Assembler::positive, c_rarg2, rax);
   812     __ bind(L);
   813     __ movptr(inout, c_rarg2);
   815     __ pop(c_rarg0);
   816     __ pop(c_rarg1);
   817     __ pop(c_rarg2);
   818     __ pop(c_rarg3);
   819     __ pop(rax);
   821     __ ret(0);
   823     return start;
   824   }
   826   address generate_d2l_fixup() {
   827     StubCodeMark mark(this, "StubRoutines", "d2l_fixup");
   828     Address inout(rsp, 6 * wordSize); // return address + 5 saves
   830     address start = __ pc();
   832     Label L;
   834     __ push(rax);
   835     __ push(c_rarg3);
   836     __ push(c_rarg2);
   837     __ push(c_rarg1);
   838     __ push(c_rarg0);
   840     __ movl(rax, 0x7ff00000);
   841     __ movq(c_rarg2, inout);
   842     __ movl(c_rarg3, c_rarg2);
   843     __ mov(c_rarg1, c_rarg2);
   844     __ mov(c_rarg0, c_rarg2);
   845     __ negl(c_rarg3);
   846     __ shrptr(c_rarg1, 0x20);
   847     __ orl(c_rarg3, c_rarg2);
   848     __ andl(c_rarg1, 0x7fffffff);
   849     __ xorl(c_rarg2, c_rarg2);
   850     __ shrl(c_rarg3, 0x1f);
   851     __ orl(c_rarg1, c_rarg3);
   852     __ cmpl(rax, c_rarg1);
   853     __ jcc(Assembler::negative, L); // NaN -> 0
   854     __ testq(c_rarg0, c_rarg0); // signed ? min_jlong : max_jlong
   855     __ mov64(c_rarg2, 0x8000000000000000);
   856     __ mov64(rax, 0x7fffffffffffffff);
   857     __ cmovq(Assembler::positive, c_rarg2, rax);
   859     __ bind(L);
   860     __ movq(inout, c_rarg2);
   862     __ pop(c_rarg0);
   863     __ pop(c_rarg1);
   864     __ pop(c_rarg2);
   865     __ pop(c_rarg3);
   866     __ pop(rax);
   868     __ ret(0);
   870     return start;
   871   }
   873   address generate_fp_mask(const char *stub_name, int64_t mask) {
   874     StubCodeMark mark(this, "StubRoutines", stub_name);
   876     __ align(16);
   877     address start = __ pc();
   879     __ emit_data64( mask, relocInfo::none );
   880     __ emit_data64( mask, relocInfo::none );
   882     return start;
   883   }
   885   // The following routine generates a subroutine to throw an
   886   // asynchronous UnknownError when an unsafe access gets a fault that
   887   // could not be reasonably prevented by the programmer.  (Example:
   888   // SIGBUS/OBJERR.)
   889   address generate_handler_for_unsafe_access() {
   890     StubCodeMark mark(this, "StubRoutines", "handler_for_unsafe_access");
   891     address start = __ pc();
   893     __ push(0);                       // hole for return address-to-be
   894     __ pusha();                       // push registers
   895     Address next_pc(rsp, RegisterImpl::number_of_registers * BytesPerWord);
   897     __ subptr(rsp, frame::arg_reg_save_area_bytes);
   898     BLOCK_COMMENT("call handle_unsafe_access");
   899     __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, handle_unsafe_access)));
   900     __ addptr(rsp, frame::arg_reg_save_area_bytes);
   902     __ movptr(next_pc, rax);          // stuff next address
   903     __ popa();
   904     __ ret(0);                        // jump to next address
   906     return start;
   907   }
   909   // Non-destructive plausibility checks for oops
   910   //
   911   // Arguments:
   912   //    all args on stack!
   913   //
   914   // Stack after saving c_rarg3:
   915   //    [tos + 0]: saved c_rarg3
   916   //    [tos + 1]: saved c_rarg2
   917   //    [tos + 2]: saved r12 (several TemplateTable methods use it)
   918   //    [tos + 3]: saved flags
   919   //    [tos + 4]: return address
   920   //  * [tos + 5]: error message (char*)
   921   //  * [tos + 6]: object to verify (oop)
   922   //  * [tos + 7]: saved rax - saved by caller and bashed
   923   //  * = popped on exit
   924   address generate_verify_oop() {
   925     StubCodeMark mark(this, "StubRoutines", "verify_oop");
   926     address start = __ pc();
   928     Label exit, error;
   930     __ pushf();
   931     __ incrementl(ExternalAddress((address) StubRoutines::verify_oop_count_addr()));
   933     __ push(r12);
   935     // save c_rarg2 and c_rarg3
   936     __ push(c_rarg2);
   937     __ push(c_rarg3);
   939     enum {
   940            // After previous pushes.
   941            oop_to_verify = 6 * wordSize,
   942            saved_rax     = 7 * wordSize,
   944            // Before the call to MacroAssembler::debug(), see below.
   945            return_addr   = 16 * wordSize,
   946            error_msg     = 17 * wordSize
   947     };
   949     // get object
   950     __ movptr(rax, Address(rsp, oop_to_verify));
   952     // make sure object is 'reasonable'
   953     __ testptr(rax, rax);
   954     __ jcc(Assembler::zero, exit); // if obj is NULL it is OK
   955     // Check if the oop is in the right area of memory
   956     __ movptr(c_rarg2, rax);
   957     __ movptr(c_rarg3, (int64_t) Universe::verify_oop_mask());
   958     __ andptr(c_rarg2, c_rarg3);
   959     __ movptr(c_rarg3, (int64_t) Universe::verify_oop_bits());
   960     __ cmpptr(c_rarg2, c_rarg3);
   961     __ jcc(Assembler::notZero, error);
   963     // set r12 to heapbase for load_klass()
   964     __ reinit_heapbase();
   966     // make sure klass is 'reasonable'
   967     __ load_klass(rax, rax);  // get klass
   968     __ testptr(rax, rax);
   969     __ jcc(Assembler::zero, error); // if klass is NULL it is broken
   970     // Check if the klass is in the right area of memory
   971     __ mov(c_rarg2, rax);
   972     __ movptr(c_rarg3, (int64_t) Universe::verify_klass_mask());
   973     __ andptr(c_rarg2, c_rarg3);
   974     __ movptr(c_rarg3, (int64_t) Universe::verify_klass_bits());
   975     __ cmpptr(c_rarg2, c_rarg3);
   976     __ jcc(Assembler::notZero, error);
   978     // make sure klass' klass is 'reasonable'
   979     __ load_klass(rax, rax);
   980     __ testptr(rax, rax);
   981     __ jcc(Assembler::zero, error); // if klass' klass is NULL it is broken
   982     // Check if the klass' klass is in the right area of memory
   983     __ movptr(c_rarg3, (int64_t) Universe::verify_klass_mask());
   984     __ andptr(rax, c_rarg3);
   985     __ movptr(c_rarg3, (int64_t) Universe::verify_klass_bits());
   986     __ cmpptr(rax, c_rarg3);
   987     __ jcc(Assembler::notZero, error);
   989     // return if everything seems ok
   990     __ bind(exit);
   991     __ movptr(rax, Address(rsp, saved_rax));     // get saved rax back
   992     __ pop(c_rarg3);                             // restore c_rarg3
   993     __ pop(c_rarg2);                             // restore c_rarg2
   994     __ pop(r12);                                 // restore r12
   995     __ popf();                                   // restore flags
   996     __ ret(3 * wordSize);                        // pop caller saved stuff
   998     // handle errors
   999     __ bind(error);
  1000     __ movptr(rax, Address(rsp, saved_rax));     // get saved rax back
  1001     __ pop(c_rarg3);                             // get saved c_rarg3 back
  1002     __ pop(c_rarg2);                             // get saved c_rarg2 back
  1003     __ pop(r12);                                 // get saved r12 back
  1004     __ popf();                                   // get saved flags off stack --
  1005                                                  // will be ignored
  1007     __ pusha();                                  // push registers
  1008                                                  // (rip is already
  1009                                                  // already pushed)
  1010     // debug(char* msg, int64_t pc, int64_t regs[])
  1011     // We've popped the registers we'd saved (c_rarg3, c_rarg2 and flags), and
  1012     // pushed all the registers, so now the stack looks like:
  1013     //     [tos +  0] 16 saved registers
  1014     //     [tos + 16] return address
  1015     //   * [tos + 17] error message (char*)
  1016     //   * [tos + 18] object to verify (oop)
  1017     //   * [tos + 19] saved rax - saved by caller and bashed
  1018     //   * = popped on exit
  1020     __ movptr(c_rarg0, Address(rsp, error_msg));    // pass address of error message
  1021     __ movptr(c_rarg1, Address(rsp, return_addr));  // pass return address
  1022     __ movq(c_rarg2, rsp);                          // pass address of regs on stack
  1023     __ mov(r12, rsp);                               // remember rsp
  1024     __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
  1025     __ andptr(rsp, -16);                            // align stack as required by ABI
  1026     BLOCK_COMMENT("call MacroAssembler::debug");
  1027     __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, MacroAssembler::debug64)));
  1028     __ mov(rsp, r12);                               // restore rsp
  1029     __ popa();                                      // pop registers (includes r12)
  1030     __ ret(3 * wordSize);                           // pop caller saved stuff
  1032     return start;
  1035   static address disjoint_byte_copy_entry;
  1036   static address disjoint_short_copy_entry;
  1037   static address disjoint_int_copy_entry;
  1038   static address disjoint_long_copy_entry;
  1039   static address disjoint_oop_copy_entry;
  1041   static address byte_copy_entry;
  1042   static address short_copy_entry;
  1043   static address int_copy_entry;
  1044   static address long_copy_entry;
  1045   static address oop_copy_entry;
  1047   static address checkcast_copy_entry;
  1049   //
  1050   // Verify that a register contains clean 32-bits positive value
  1051   // (high 32-bits are 0) so it could be used in 64-bits shifts.
  1052   //
  1053   //  Input:
  1054   //    Rint  -  32-bits value
  1055   //    Rtmp  -  scratch
  1056   //
  1057   void assert_clean_int(Register Rint, Register Rtmp) {
  1058 #ifdef ASSERT
  1059     Label L;
  1060     assert_different_registers(Rtmp, Rint);
  1061     __ movslq(Rtmp, Rint);
  1062     __ cmpq(Rtmp, Rint);
  1063     __ jcc(Assembler::equal, L);
  1064     __ stop("high 32-bits of int value are not 0");
  1065     __ bind(L);
  1066 #endif
  1069   //  Generate overlap test for array copy stubs
  1070   //
  1071   //  Input:
  1072   //     c_rarg0 - from
  1073   //     c_rarg1 - to
  1074   //     c_rarg2 - element count
  1075   //
  1076   //  Output:
  1077   //     rax   - &from[element count - 1]
  1078   //
  1079   void array_overlap_test(address no_overlap_target, Address::ScaleFactor sf) {
  1080     assert(no_overlap_target != NULL, "must be generated");
  1081     array_overlap_test(no_overlap_target, NULL, sf);
  1083   void array_overlap_test(Label& L_no_overlap, Address::ScaleFactor sf) {
  1084     array_overlap_test(NULL, &L_no_overlap, sf);
  1086   void array_overlap_test(address no_overlap_target, Label* NOLp, Address::ScaleFactor sf) {
  1087     const Register from     = c_rarg0;
  1088     const Register to       = c_rarg1;
  1089     const Register count    = c_rarg2;
  1090     const Register end_from = rax;
  1092     __ cmpptr(to, from);
  1093     __ lea(end_from, Address(from, count, sf, 0));
  1094     if (NOLp == NULL) {
  1095       ExternalAddress no_overlap(no_overlap_target);
  1096       __ jump_cc(Assembler::belowEqual, no_overlap);
  1097       __ cmpptr(to, end_from);
  1098       __ jump_cc(Assembler::aboveEqual, no_overlap);
  1099     } else {
  1100       __ jcc(Assembler::belowEqual, (*NOLp));
  1101       __ cmpptr(to, end_from);
  1102       __ jcc(Assembler::aboveEqual, (*NOLp));
  1106   // Shuffle first three arg regs on Windows into Linux/Solaris locations.
  1107   //
  1108   // Outputs:
  1109   //    rdi - rcx
  1110   //    rsi - rdx
  1111   //    rdx - r8
  1112   //    rcx - r9
  1113   //
  1114   // Registers r9 and r10 are used to save rdi and rsi on Windows, which latter
  1115   // are non-volatile.  r9 and r10 should not be used by the caller.
  1116   //
  1117   void setup_arg_regs(int nargs = 3) {
  1118     const Register saved_rdi = r9;
  1119     const Register saved_rsi = r10;
  1120     assert(nargs == 3 || nargs == 4, "else fix");
  1121 #ifdef _WIN64
  1122     assert(c_rarg0 == rcx && c_rarg1 == rdx && c_rarg2 == r8 && c_rarg3 == r9,
  1123            "unexpected argument registers");
  1124     if (nargs >= 4)
  1125       __ mov(rax, r9);  // r9 is also saved_rdi
  1126     __ movptr(saved_rdi, rdi);
  1127     __ movptr(saved_rsi, rsi);
  1128     __ mov(rdi, rcx); // c_rarg0
  1129     __ mov(rsi, rdx); // c_rarg1
  1130     __ mov(rdx, r8);  // c_rarg2
  1131     if (nargs >= 4)
  1132       __ mov(rcx, rax); // c_rarg3 (via rax)
  1133 #else
  1134     assert(c_rarg0 == rdi && c_rarg1 == rsi && c_rarg2 == rdx && c_rarg3 == rcx,
  1135            "unexpected argument registers");
  1136 #endif
  1139   void restore_arg_regs() {
  1140     const Register saved_rdi = r9;
  1141     const Register saved_rsi = r10;
  1142 #ifdef _WIN64
  1143     __ movptr(rdi, saved_rdi);
  1144     __ movptr(rsi, saved_rsi);
  1145 #endif
  1148   // Generate code for an array write pre barrier
  1149   //
  1150   //     addr    -  starting address
  1151   //     count    -  element count
  1152   //
  1153   //     Destroy no registers!
  1154   //
  1155   void  gen_write_ref_array_pre_barrier(Register addr, Register count) {
  1156 #if 0 // G1 - only
  1157     assert_different_registers(addr, c_rarg1);
  1158     assert_different_registers(count, c_rarg0);
  1159     BarrierSet* bs = Universe::heap()->barrier_set();
  1160     switch (bs->kind()) {
  1161       case BarrierSet::G1SATBCT:
  1162       case BarrierSet::G1SATBCTLogging:
  1164           __ pusha();                      // push registers
  1165           __ movptr(c_rarg0, addr);
  1166           __ movptr(c_rarg1, count);
  1167           __ call(RuntimeAddress(BarrierSet::static_write_ref_array_pre));
  1168           __ popa();
  1170         break;
  1171       case BarrierSet::CardTableModRef:
  1172       case BarrierSet::CardTableExtension:
  1173       case BarrierSet::ModRef:
  1174         break;
  1175       default      :
  1176         ShouldNotReachHere();
  1179 #endif // 0 G1 - only
  1182   //
  1183   // Generate code for an array write post barrier
  1184   //
  1185   //  Input:
  1186   //     start    - register containing starting address of destination array
  1187   //     end      - register containing ending address of destination array
  1188   //     scratch  - scratch register
  1189   //
  1190   //  The input registers are overwritten.
  1191   //  The ending address is inclusive.
  1192   void  gen_write_ref_array_post_barrier(Register start, Register end, Register scratch) {
  1193     assert_different_registers(start, end, scratch);
  1194     BarrierSet* bs = Universe::heap()->barrier_set();
  1195     switch (bs->kind()) {
  1196 #if 0 // G1 - only
  1197       case BarrierSet::G1SATBCT:
  1198       case BarrierSet::G1SATBCTLogging:
  1201           __ pusha();                      // push registers (overkill)
  1202           // must compute element count unless barrier set interface is changed (other platforms supply count)
  1203           assert_different_registers(start, end, scratch);
  1204           __ lea(scratch, Address(end, wordSize));
  1205           __ subptr(scratch, start);
  1206           __ shrptr(scratch, LogBytesPerWord);
  1207           __ mov(c_rarg0, start);
  1208           __ mov(c_rarg1, scratch);
  1209           __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_post));
  1210           __ popa();
  1212         break;
  1213 #endif // 0 G1 - only
  1214       case BarrierSet::CardTableModRef:
  1215       case BarrierSet::CardTableExtension:
  1217           CardTableModRefBS* ct = (CardTableModRefBS*)bs;
  1218           assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code");
  1220           Label L_loop;
  1222            __ shrptr(start, CardTableModRefBS::card_shift);
  1223            __ shrptr(end, CardTableModRefBS::card_shift);
  1224            __ subptr(end, start); // number of bytes to copy
  1226           intptr_t disp = (intptr_t) ct->byte_map_base;
  1227           if (__ is_simm32(disp)) {
  1228             Address cardtable(noreg, noreg, Address::no_scale, disp);
  1229             __ lea(scratch, cardtable);
  1230           } else {
  1231             ExternalAddress cardtable((address)disp);
  1232             __ lea(scratch, cardtable);
  1235           const Register count = end; // 'end' register contains bytes count now
  1236           __ addptr(start, scratch);
  1237         __ BIND(L_loop);
  1238           __ movb(Address(start, count, Address::times_1), 0);
  1239           __ decrement(count);
  1240           __ jcc(Assembler::greaterEqual, L_loop);
  1245   // Copy big chunks forward
  1246   //
  1247   // Inputs:
  1248   //   end_from     - source arrays end address
  1249   //   end_to       - destination array end address
  1250   //   qword_count  - 64-bits element count, negative
  1251   //   to           - scratch
  1252   //   L_copy_32_bytes - entry label
  1253   //   L_copy_8_bytes  - exit  label
  1254   //
  1255   void copy_32_bytes_forward(Register end_from, Register end_to,
  1256                              Register qword_count, Register to,
  1257                              Label& L_copy_32_bytes, Label& L_copy_8_bytes) {
  1258     DEBUG_ONLY(__ stop("enter at entry label, not here"));
  1259     Label L_loop;
  1260     __ align(16);
  1261   __ BIND(L_loop);
  1262     __ movq(to, Address(end_from, qword_count, Address::times_8, -24));
  1263     __ movq(Address(end_to, qword_count, Address::times_8, -24), to);
  1264     __ movq(to, Address(end_from, qword_count, Address::times_8, -16));
  1265     __ movq(Address(end_to, qword_count, Address::times_8, -16), to);
  1266     __ movq(to, Address(end_from, qword_count, Address::times_8, - 8));
  1267     __ movq(Address(end_to, qword_count, Address::times_8, - 8), to);
  1268     __ movq(to, Address(end_from, qword_count, Address::times_8, - 0));
  1269     __ movq(Address(end_to, qword_count, Address::times_8, - 0), to);
  1270   __ BIND(L_copy_32_bytes);
  1271     __ addptr(qword_count, 4);
  1272     __ jcc(Assembler::lessEqual, L_loop);
  1273     __ subptr(qword_count, 4);
  1274     __ jcc(Assembler::less, L_copy_8_bytes); // Copy trailing qwords
  1278   // Copy big chunks backward
  1279   //
  1280   // Inputs:
  1281   //   from         - source arrays address
  1282   //   dest         - destination array address
  1283   //   qword_count  - 64-bits element count
  1284   //   to           - scratch
  1285   //   L_copy_32_bytes - entry label
  1286   //   L_copy_8_bytes  - exit  label
  1287   //
  1288   void copy_32_bytes_backward(Register from, Register dest,
  1289                               Register qword_count, Register to,
  1290                               Label& L_copy_32_bytes, Label& L_copy_8_bytes) {
  1291     DEBUG_ONLY(__ stop("enter at entry label, not here"));
  1292     Label L_loop;
  1293     __ align(16);
  1294   __ BIND(L_loop);
  1295     __ movq(to, Address(from, qword_count, Address::times_8, 24));
  1296     __ movq(Address(dest, qword_count, Address::times_8, 24), to);
  1297     __ movq(to, Address(from, qword_count, Address::times_8, 16));
  1298     __ movq(Address(dest, qword_count, Address::times_8, 16), to);
  1299     __ movq(to, Address(from, qword_count, Address::times_8,  8));
  1300     __ movq(Address(dest, qword_count, Address::times_8,  8), to);
  1301     __ movq(to, Address(from, qword_count, Address::times_8,  0));
  1302     __ movq(Address(dest, qword_count, Address::times_8,  0), to);
  1303   __ BIND(L_copy_32_bytes);
  1304     __ subptr(qword_count, 4);
  1305     __ jcc(Assembler::greaterEqual, L_loop);
  1306     __ addptr(qword_count, 4);
  1307     __ jcc(Assembler::greater, L_copy_8_bytes); // Copy trailing qwords
  1311   // Arguments:
  1312   //   aligned - true => Input and output aligned on a HeapWord == 8-byte boundary
  1313   //             ignored
  1314   //   name    - stub name string
  1315   //
  1316   // Inputs:
  1317   //   c_rarg0   - source array address
  1318   //   c_rarg1   - destination array address
  1319   //   c_rarg2   - element count, treated as ssize_t, can be zero
  1320   //
  1321   // If 'from' and/or 'to' are aligned on 4-, 2-, or 1-byte boundaries,
  1322   // we let the hardware handle it.  The one to eight bytes within words,
  1323   // dwords or qwords that span cache line boundaries will still be loaded
  1324   // and stored atomically.
  1325   //
  1326   // Side Effects:
  1327   //   disjoint_byte_copy_entry is set to the no-overlap entry point
  1328   //   used by generate_conjoint_byte_copy().
  1329   //
  1330   address generate_disjoint_byte_copy(bool aligned, const char *name) {
  1331     __ align(CodeEntryAlignment);
  1332     StubCodeMark mark(this, "StubRoutines", name);
  1333     address start = __ pc();
  1335     Label L_copy_32_bytes, L_copy_8_bytes, L_copy_4_bytes, L_copy_2_bytes;
  1336     Label L_copy_byte, L_exit;
  1337     const Register from        = rdi;  // source array address
  1338     const Register to          = rsi;  // destination array address
  1339     const Register count       = rdx;  // elements count
  1340     const Register byte_count  = rcx;
  1341     const Register qword_count = count;
  1342     const Register end_from    = from; // source array end address
  1343     const Register end_to      = to;   // destination array end address
  1344     // End pointers are inclusive, and if count is not zero they point
  1345     // to the last unit copied:  end_to[0] := end_from[0]
  1347     __ enter(); // required for proper stackwalking of RuntimeStub frame
  1348     assert_clean_int(c_rarg2, rax);    // Make sure 'count' is clean int.
  1350     disjoint_byte_copy_entry = __ pc();
  1351     BLOCK_COMMENT("Entry:");
  1352     // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
  1354     setup_arg_regs(); // from => rdi, to => rsi, count => rdx
  1355                       // r9 and r10 may be used to save non-volatile registers
  1357     // 'from', 'to' and 'count' are now valid
  1358     __ movptr(byte_count, count);
  1359     __ shrptr(count, 3); // count => qword_count
  1361     // Copy from low to high addresses.  Use 'to' as scratch.
  1362     __ lea(end_from, Address(from, qword_count, Address::times_8, -8));
  1363     __ lea(end_to,   Address(to,   qword_count, Address::times_8, -8));
  1364     __ negptr(qword_count); // make the count negative
  1365     __ jmp(L_copy_32_bytes);
  1367     // Copy trailing qwords
  1368   __ BIND(L_copy_8_bytes);
  1369     __ movq(rax, Address(end_from, qword_count, Address::times_8, 8));
  1370     __ movq(Address(end_to, qword_count, Address::times_8, 8), rax);
  1371     __ increment(qword_count);
  1372     __ jcc(Assembler::notZero, L_copy_8_bytes);
  1374     // Check for and copy trailing dword
  1375   __ BIND(L_copy_4_bytes);
  1376     __ testl(byte_count, 4);
  1377     __ jccb(Assembler::zero, L_copy_2_bytes);
  1378     __ movl(rax, Address(end_from, 8));
  1379     __ movl(Address(end_to, 8), rax);
  1381     __ addptr(end_from, 4);
  1382     __ addptr(end_to, 4);
  1384     // Check for and copy trailing word
  1385   __ BIND(L_copy_2_bytes);
  1386     __ testl(byte_count, 2);
  1387     __ jccb(Assembler::zero, L_copy_byte);
  1388     __ movw(rax, Address(end_from, 8));
  1389     __ movw(Address(end_to, 8), rax);
  1391     __ addptr(end_from, 2);
  1392     __ addptr(end_to, 2);
  1394     // Check for and copy trailing byte
  1395   __ BIND(L_copy_byte);
  1396     __ testl(byte_count, 1);
  1397     __ jccb(Assembler::zero, L_exit);
  1398     __ movb(rax, Address(end_from, 8));
  1399     __ movb(Address(end_to, 8), rax);
  1401   __ BIND(L_exit);
  1402     inc_counter_np(SharedRuntime::_jbyte_array_copy_ctr);
  1403     restore_arg_regs();
  1404     __ xorptr(rax, rax); // return 0
  1405     __ leave(); // required for proper stackwalking of RuntimeStub frame
  1406     __ ret(0);
  1408     // Copy in 32-bytes chunks
  1409     copy_32_bytes_forward(end_from, end_to, qword_count, rax, L_copy_32_bytes, L_copy_8_bytes);
  1410     __ jmp(L_copy_4_bytes);
  1412     return start;
  1415   // Arguments:
  1416   //   aligned - true => Input and output aligned on a HeapWord == 8-byte boundary
  1417   //             ignored
  1418   //   name    - stub name string
  1419   //
  1420   // Inputs:
  1421   //   c_rarg0   - source array address
  1422   //   c_rarg1   - destination array address
  1423   //   c_rarg2   - element count, treated as ssize_t, can be zero
  1424   //
  1425   // If 'from' and/or 'to' are aligned on 4-, 2-, or 1-byte boundaries,
  1426   // we let the hardware handle it.  The one to eight bytes within words,
  1427   // dwords or qwords that span cache line boundaries will still be loaded
  1428   // and stored atomically.
  1429   //
  1430   address generate_conjoint_byte_copy(bool aligned, const char *name) {
  1431     __ align(CodeEntryAlignment);
  1432     StubCodeMark mark(this, "StubRoutines", name);
  1433     address start = __ pc();
  1435     Label L_copy_32_bytes, L_copy_8_bytes, L_copy_4_bytes, L_copy_2_bytes;
  1436     const Register from        = rdi;  // source array address
  1437     const Register to          = rsi;  // destination array address
  1438     const Register count       = rdx;  // elements count
  1439     const Register byte_count  = rcx;
  1440     const Register qword_count = count;
  1442     __ enter(); // required for proper stackwalking of RuntimeStub frame
  1443     assert_clean_int(c_rarg2, rax);    // Make sure 'count' is clean int.
  1445     byte_copy_entry = __ pc();
  1446     BLOCK_COMMENT("Entry:");
  1447     // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
  1449     array_overlap_test(disjoint_byte_copy_entry, Address::times_1);
  1450     setup_arg_regs(); // from => rdi, to => rsi, count => rdx
  1451                       // r9 and r10 may be used to save non-volatile registers
  1453     // 'from', 'to' and 'count' are now valid
  1454     __ movptr(byte_count, count);
  1455     __ shrptr(count, 3);   // count => qword_count
  1457     // Copy from high to low addresses.
  1459     // Check for and copy trailing byte
  1460     __ testl(byte_count, 1);
  1461     __ jcc(Assembler::zero, L_copy_2_bytes);
  1462     __ movb(rax, Address(from, byte_count, Address::times_1, -1));
  1463     __ movb(Address(to, byte_count, Address::times_1, -1), rax);
  1464     __ decrement(byte_count); // Adjust for possible trailing word
  1466     // Check for and copy trailing word
  1467   __ BIND(L_copy_2_bytes);
  1468     __ testl(byte_count, 2);
  1469     __ jcc(Assembler::zero, L_copy_4_bytes);
  1470     __ movw(rax, Address(from, byte_count, Address::times_1, -2));
  1471     __ movw(Address(to, byte_count, Address::times_1, -2), rax);
  1473     // Check for and copy trailing dword
  1474   __ BIND(L_copy_4_bytes);
  1475     __ testl(byte_count, 4);
  1476     __ jcc(Assembler::zero, L_copy_32_bytes);
  1477     __ movl(rax, Address(from, qword_count, Address::times_8));
  1478     __ movl(Address(to, qword_count, Address::times_8), rax);
  1479     __ jmp(L_copy_32_bytes);
  1481     // Copy trailing qwords
  1482   __ BIND(L_copy_8_bytes);
  1483     __ movq(rax, Address(from, qword_count, Address::times_8, -8));
  1484     __ movq(Address(to, qword_count, Address::times_8, -8), rax);
  1485     __ decrement(qword_count);
  1486     __ jcc(Assembler::notZero, L_copy_8_bytes);
  1488     inc_counter_np(SharedRuntime::_jbyte_array_copy_ctr);
  1489     restore_arg_regs();
  1490     __ xorptr(rax, rax); // return 0
  1491     __ leave(); // required for proper stackwalking of RuntimeStub frame
  1492     __ ret(0);
  1494     // Copy in 32-bytes chunks
  1495     copy_32_bytes_backward(from, to, qword_count, rax, L_copy_32_bytes, L_copy_8_bytes);
  1497     inc_counter_np(SharedRuntime::_jbyte_array_copy_ctr);
  1498     restore_arg_regs();
  1499     __ xorptr(rax, rax); // return 0
  1500     __ leave(); // required for proper stackwalking of RuntimeStub frame
  1501     __ ret(0);
  1503     return start;
  1506   // Arguments:
  1507   //   aligned - true => Input and output aligned on a HeapWord == 8-byte boundary
  1508   //             ignored
  1509   //   name    - stub name string
  1510   //
  1511   // Inputs:
  1512   //   c_rarg0   - source array address
  1513   //   c_rarg1   - destination array address
  1514   //   c_rarg2   - element count, treated as ssize_t, can be zero
  1515   //
  1516   // If 'from' and/or 'to' are aligned on 4- or 2-byte boundaries, we
  1517   // let the hardware handle it.  The two or four words within dwords
  1518   // or qwords that span cache line boundaries will still be loaded
  1519   // and stored atomically.
  1520   //
  1521   // Side Effects:
  1522   //   disjoint_short_copy_entry is set to the no-overlap entry point
  1523   //   used by generate_conjoint_short_copy().
  1524   //
  1525   address generate_disjoint_short_copy(bool aligned, const char *name) {
  1526     __ align(CodeEntryAlignment);
  1527     StubCodeMark mark(this, "StubRoutines", name);
  1528     address start = __ pc();
  1530     Label L_copy_32_bytes, L_copy_8_bytes, L_copy_4_bytes,L_copy_2_bytes,L_exit;
  1531     const Register from        = rdi;  // source array address
  1532     const Register to          = rsi;  // destination array address
  1533     const Register count       = rdx;  // elements count
  1534     const Register word_count  = rcx;
  1535     const Register qword_count = count;
  1536     const Register end_from    = from; // source array end address
  1537     const Register end_to      = to;   // destination array end address
  1538     // End pointers are inclusive, and if count is not zero they point
  1539     // to the last unit copied:  end_to[0] := end_from[0]
  1541     __ enter(); // required for proper stackwalking of RuntimeStub frame
  1542     assert_clean_int(c_rarg2, rax);    // Make sure 'count' is clean int.
  1544     disjoint_short_copy_entry = __ pc();
  1545     BLOCK_COMMENT("Entry:");
  1546     // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
  1548     setup_arg_regs(); // from => rdi, to => rsi, count => rdx
  1549                       // r9 and r10 may be used to save non-volatile registers
  1551     // 'from', 'to' and 'count' are now valid
  1552     __ movptr(word_count, count);
  1553     __ shrptr(count, 2); // count => qword_count
  1555     // Copy from low to high addresses.  Use 'to' as scratch.
  1556     __ lea(end_from, Address(from, qword_count, Address::times_8, -8));
  1557     __ lea(end_to,   Address(to,   qword_count, Address::times_8, -8));
  1558     __ negptr(qword_count);
  1559     __ jmp(L_copy_32_bytes);
  1561     // Copy trailing qwords
  1562   __ BIND(L_copy_8_bytes);
  1563     __ movq(rax, Address(end_from, qword_count, Address::times_8, 8));
  1564     __ movq(Address(end_to, qword_count, Address::times_8, 8), rax);
  1565     __ increment(qword_count);
  1566     __ jcc(Assembler::notZero, L_copy_8_bytes);
  1568     // Original 'dest' is trashed, so we can't use it as a
  1569     // base register for a possible trailing word copy
  1571     // Check for and copy trailing dword
  1572   __ BIND(L_copy_4_bytes);
  1573     __ testl(word_count, 2);
  1574     __ jccb(Assembler::zero, L_copy_2_bytes);
  1575     __ movl(rax, Address(end_from, 8));
  1576     __ movl(Address(end_to, 8), rax);
  1578     __ addptr(end_from, 4);
  1579     __ addptr(end_to, 4);
  1581     // Check for and copy trailing word
  1582   __ BIND(L_copy_2_bytes);
  1583     __ testl(word_count, 1);
  1584     __ jccb(Assembler::zero, L_exit);
  1585     __ movw(rax, Address(end_from, 8));
  1586     __ movw(Address(end_to, 8), rax);
  1588   __ BIND(L_exit);
  1589     inc_counter_np(SharedRuntime::_jshort_array_copy_ctr);
  1590     restore_arg_regs();
  1591     __ xorptr(rax, rax); // return 0
  1592     __ leave(); // required for proper stackwalking of RuntimeStub frame
  1593     __ ret(0);
  1595     // Copy in 32-bytes chunks
  1596     copy_32_bytes_forward(end_from, end_to, qword_count, rax, L_copy_32_bytes, L_copy_8_bytes);
  1597     __ jmp(L_copy_4_bytes);
  1599     return start;
  1602   // Arguments:
  1603   //   aligned - true => Input and output aligned on a HeapWord == 8-byte boundary
  1604   //             ignored
  1605   //   name    - stub name string
  1606   //
  1607   // Inputs:
  1608   //   c_rarg0   - source array address
  1609   //   c_rarg1   - destination array address
  1610   //   c_rarg2   - element count, treated as ssize_t, can be zero
  1611   //
  1612   // If 'from' and/or 'to' are aligned on 4- or 2-byte boundaries, we
  1613   // let the hardware handle it.  The two or four words within dwords
  1614   // or qwords that span cache line boundaries will still be loaded
  1615   // and stored atomically.
  1616   //
  1617   address generate_conjoint_short_copy(bool aligned, const char *name) {
  1618     __ align(CodeEntryAlignment);
  1619     StubCodeMark mark(this, "StubRoutines", name);
  1620     address start = __ pc();
  1622     Label L_copy_32_bytes, L_copy_8_bytes, L_copy_4_bytes;
  1623     const Register from        = rdi;  // source array address
  1624     const Register to          = rsi;  // destination array address
  1625     const Register count       = rdx;  // elements count
  1626     const Register word_count  = rcx;
  1627     const Register qword_count = count;
  1629     __ enter(); // required for proper stackwalking of RuntimeStub frame
  1630     assert_clean_int(c_rarg2, rax);    // Make sure 'count' is clean int.
  1632     short_copy_entry = __ pc();
  1633     BLOCK_COMMENT("Entry:");
  1634     // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
  1636     array_overlap_test(disjoint_short_copy_entry, Address::times_2);
  1637     setup_arg_regs(); // from => rdi, to => rsi, count => rdx
  1638                       // r9 and r10 may be used to save non-volatile registers
  1640     // 'from', 'to' and 'count' are now valid
  1641     __ movptr(word_count, count);
  1642     __ shrptr(count, 2); // count => qword_count
  1644     // Copy from high to low addresses.  Use 'to' as scratch.
  1646     // Check for and copy trailing word
  1647     __ testl(word_count, 1);
  1648     __ jccb(Assembler::zero, L_copy_4_bytes);
  1649     __ movw(rax, Address(from, word_count, Address::times_2, -2));
  1650     __ movw(Address(to, word_count, Address::times_2, -2), rax);
  1652     // Check for and copy trailing dword
  1653   __ BIND(L_copy_4_bytes);
  1654     __ testl(word_count, 2);
  1655     __ jcc(Assembler::zero, L_copy_32_bytes);
  1656     __ movl(rax, Address(from, qword_count, Address::times_8));
  1657     __ movl(Address(to, qword_count, Address::times_8), rax);
  1658     __ jmp(L_copy_32_bytes);
  1660     // Copy trailing qwords
  1661   __ BIND(L_copy_8_bytes);
  1662     __ movq(rax, Address(from, qword_count, Address::times_8, -8));
  1663     __ movq(Address(to, qword_count, Address::times_8, -8), rax);
  1664     __ decrement(qword_count);
  1665     __ jcc(Assembler::notZero, L_copy_8_bytes);
  1667     inc_counter_np(SharedRuntime::_jshort_array_copy_ctr);
  1668     restore_arg_regs();
  1669     __ xorptr(rax, rax); // return 0
  1670     __ leave(); // required for proper stackwalking of RuntimeStub frame
  1671     __ ret(0);
  1673     // Copy in 32-bytes chunks
  1674     copy_32_bytes_backward(from, to, qword_count, rax, L_copy_32_bytes, L_copy_8_bytes);
  1676     inc_counter_np(SharedRuntime::_jshort_array_copy_ctr);
  1677     restore_arg_regs();
  1678     __ xorptr(rax, rax); // return 0
  1679     __ leave(); // required for proper stackwalking of RuntimeStub frame
  1680     __ ret(0);
  1682     return start;
  1685   // Arguments:
  1686   //   aligned - true => Input and output aligned on a HeapWord == 8-byte boundary
  1687   //             ignored
  1688   //   is_oop  - true => oop array, so generate store check code
  1689   //   name    - stub name string
  1690   //
  1691   // Inputs:
  1692   //   c_rarg0   - source array address
  1693   //   c_rarg1   - destination array address
  1694   //   c_rarg2   - element count, treated as ssize_t, can be zero
  1695   //
  1696   // If 'from' and/or 'to' are aligned on 4-byte boundaries, we let
  1697   // the hardware handle it.  The two dwords within qwords that span
  1698   // cache line boundaries will still be loaded and stored atomicly.
  1699   //
  1700   // Side Effects:
  1701   //   disjoint_int_copy_entry is set to the no-overlap entry point
  1702   //   used by generate_conjoint_int_oop_copy().
  1703   //
  1704   address generate_disjoint_int_oop_copy(bool aligned, bool is_oop, const char *name) {
  1705     __ align(CodeEntryAlignment);
  1706     StubCodeMark mark(this, "StubRoutines", name);
  1707     address start = __ pc();
  1709     Label L_copy_32_bytes, L_copy_8_bytes, L_copy_4_bytes, L_exit;
  1710     const Register from        = rdi;  // source array address
  1711     const Register to          = rsi;  // destination array address
  1712     const Register count       = rdx;  // elements count
  1713     const Register dword_count = rcx;
  1714     const Register qword_count = count;
  1715     const Register end_from    = from; // source array end address
  1716     const Register end_to      = to;   // destination array end address
  1717     const Register saved_to    = r11;  // saved destination array address
  1718     // End pointers are inclusive, and if count is not zero they point
  1719     // to the last unit copied:  end_to[0] := end_from[0]
  1721     __ enter(); // required for proper stackwalking of RuntimeStub frame
  1722     assert_clean_int(c_rarg2, rax);    // Make sure 'count' is clean int.
  1724     (is_oop ? disjoint_oop_copy_entry : disjoint_int_copy_entry) = __ pc();
  1726     if (is_oop) {
  1727       // no registers are destroyed by this call
  1728       gen_write_ref_array_pre_barrier(/* dest */ c_rarg1, /* count */ c_rarg2);
  1731     BLOCK_COMMENT("Entry:");
  1732     // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
  1734     setup_arg_regs(); // from => rdi, to => rsi, count => rdx
  1735                       // r9 and r10 may be used to save non-volatile registers
  1737     if (is_oop) {
  1738       __ movq(saved_to, to);
  1741     // 'from', 'to' and 'count' are now valid
  1742     __ movptr(dword_count, count);
  1743     __ shrptr(count, 1); // count => qword_count
  1745     // Copy from low to high addresses.  Use 'to' as scratch.
  1746     __ lea(end_from, Address(from, qword_count, Address::times_8, -8));
  1747     __ lea(end_to,   Address(to,   qword_count, Address::times_8, -8));
  1748     __ negptr(qword_count);
  1749     __ jmp(L_copy_32_bytes);
  1751     // Copy trailing qwords
  1752   __ BIND(L_copy_8_bytes);
  1753     __ movq(rax, Address(end_from, qword_count, Address::times_8, 8));
  1754     __ movq(Address(end_to, qword_count, Address::times_8, 8), rax);
  1755     __ increment(qword_count);
  1756     __ jcc(Assembler::notZero, L_copy_8_bytes);
  1758     // Check for and copy trailing dword
  1759   __ BIND(L_copy_4_bytes);
  1760     __ testl(dword_count, 1); // Only byte test since the value is 0 or 1
  1761     __ jccb(Assembler::zero, L_exit);
  1762     __ movl(rax, Address(end_from, 8));
  1763     __ movl(Address(end_to, 8), rax);
  1765   __ BIND(L_exit);
  1766     if (is_oop) {
  1767       __ leaq(end_to, Address(saved_to, dword_count, Address::times_4, -4));
  1768       gen_write_ref_array_post_barrier(saved_to, end_to, rax);
  1770     inc_counter_np(SharedRuntime::_jint_array_copy_ctr);
  1771     restore_arg_regs();
  1772     __ xorptr(rax, rax); // return 0
  1773     __ leave(); // required for proper stackwalking of RuntimeStub frame
  1774     __ ret(0);
  1776     // Copy 32-bytes chunks
  1777     copy_32_bytes_forward(end_from, end_to, qword_count, rax, L_copy_32_bytes, L_copy_8_bytes);
  1778     __ jmp(L_copy_4_bytes);
  1780     return start;
  1783   // Arguments:
  1784   //   aligned - true => Input and output aligned on a HeapWord == 8-byte boundary
  1785   //             ignored
  1786   //   is_oop  - true => oop array, so generate store check code
  1787   //   name    - stub name string
  1788   //
  1789   // Inputs:
  1790   //   c_rarg0   - source array address
  1791   //   c_rarg1   - destination array address
  1792   //   c_rarg2   - element count, treated as ssize_t, can be zero
  1793   //
  1794   // If 'from' and/or 'to' are aligned on 4-byte boundaries, we let
  1795   // the hardware handle it.  The two dwords within qwords that span
  1796   // cache line boundaries will still be loaded and stored atomicly.
  1797   //
  1798   address generate_conjoint_int_oop_copy(bool aligned, bool is_oop, const char *name) {
  1799     __ align(CodeEntryAlignment);
  1800     StubCodeMark mark(this, "StubRoutines", name);
  1801     address start = __ pc();
  1803     Label L_copy_32_bytes, L_copy_8_bytes, L_copy_2_bytes, L_exit;
  1804     const Register from        = rdi;  // source array address
  1805     const Register to          = rsi;  // destination array address
  1806     const Register count       = rdx;  // elements count
  1807     const Register dword_count = rcx;
  1808     const Register qword_count = count;
  1810     __ enter(); // required for proper stackwalking of RuntimeStub frame
  1811     assert_clean_int(c_rarg2, rax);    // Make sure 'count' is clean int.
  1813     if (is_oop) {
  1814       // no registers are destroyed by this call
  1815       gen_write_ref_array_pre_barrier(/* dest */ c_rarg1, /* count */ c_rarg2);
  1818     (is_oop ? oop_copy_entry : int_copy_entry) = __ pc();
  1819     BLOCK_COMMENT("Entry:");
  1820     // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
  1822     array_overlap_test(is_oop ? disjoint_oop_copy_entry : disjoint_int_copy_entry,
  1823                        Address::times_4);
  1824     setup_arg_regs(); // from => rdi, to => rsi, count => rdx
  1825                       // r9 and r10 may be used to save non-volatile registers
  1827     assert_clean_int(count, rax); // Make sure 'count' is clean int.
  1828     // 'from', 'to' and 'count' are now valid
  1829     __ movptr(dword_count, count);
  1830     __ shrptr(count, 1); // count => qword_count
  1832     // Copy from high to low addresses.  Use 'to' as scratch.
  1834     // Check for and copy trailing dword
  1835     __ testl(dword_count, 1);
  1836     __ jcc(Assembler::zero, L_copy_32_bytes);
  1837     __ movl(rax, Address(from, dword_count, Address::times_4, -4));
  1838     __ movl(Address(to, dword_count, Address::times_4, -4), rax);
  1839     __ jmp(L_copy_32_bytes);
  1841     // Copy trailing qwords
  1842   __ BIND(L_copy_8_bytes);
  1843     __ movq(rax, Address(from, qword_count, Address::times_8, -8));
  1844     __ movq(Address(to, qword_count, Address::times_8, -8), rax);
  1845     __ decrement(qword_count);
  1846     __ jcc(Assembler::notZero, L_copy_8_bytes);
  1848     inc_counter_np(SharedRuntime::_jint_array_copy_ctr);
  1849     if (is_oop) {
  1850       __ jmp(L_exit);
  1852     restore_arg_regs();
  1853     __ xorptr(rax, rax); // return 0
  1854     __ leave(); // required for proper stackwalking of RuntimeStub frame
  1855     __ ret(0);
  1857     // Copy in 32-bytes chunks
  1858     copy_32_bytes_backward(from, to, qword_count, rax, L_copy_32_bytes, L_copy_8_bytes);
  1860    inc_counter_np(SharedRuntime::_jint_array_copy_ctr);
  1861    __ bind(L_exit);
  1862      if (is_oop) {
  1863        Register end_to = rdx;
  1864        __ leaq(end_to, Address(to, dword_count, Address::times_4, -4));
  1865        gen_write_ref_array_post_barrier(to, end_to, rax);
  1867     restore_arg_regs();
  1868     __ xorptr(rax, rax); // return 0
  1869     __ leave(); // required for proper stackwalking of RuntimeStub frame
  1870     __ ret(0);
  1872     return start;
  1875   // Arguments:
  1876   //   aligned - true => Input and output aligned on a HeapWord boundary == 8 bytes
  1877   //             ignored
  1878   //   is_oop  - true => oop array, so generate store check code
  1879   //   name    - stub name string
  1880   //
  1881   // Inputs:
  1882   //   c_rarg0   - source array address
  1883   //   c_rarg1   - destination array address
  1884   //   c_rarg2   - element count, treated as ssize_t, can be zero
  1885   //
  1886  // Side Effects:
  1887   //   disjoint_oop_copy_entry or disjoint_long_copy_entry is set to the
  1888   //   no-overlap entry point used by generate_conjoint_long_oop_copy().
  1889   //
  1890   address generate_disjoint_long_oop_copy(bool aligned, bool is_oop, const char *name) {
  1891     __ align(CodeEntryAlignment);
  1892     StubCodeMark mark(this, "StubRoutines", name);
  1893     address start = __ pc();
  1895     Label L_copy_32_bytes, L_copy_8_bytes, L_exit;
  1896     const Register from        = rdi;  // source array address
  1897     const Register to          = rsi;  // destination array address
  1898     const Register qword_count = rdx;  // elements count
  1899     const Register end_from    = from; // source array end address
  1900     const Register end_to      = rcx;  // destination array end address
  1901     const Register saved_to    = to;
  1902     // End pointers are inclusive, and if count is not zero they point
  1903     // to the last unit copied:  end_to[0] := end_from[0]
  1905     __ enter(); // required for proper stackwalking of RuntimeStub frame
  1906     // Save no-overlap entry point for generate_conjoint_long_oop_copy()
  1907     assert_clean_int(c_rarg2, rax);    // Make sure 'count' is clean int.
  1909     if (is_oop) {
  1910       disjoint_oop_copy_entry  = __ pc();
  1911       // no registers are destroyed by this call
  1912       gen_write_ref_array_pre_barrier(/* dest */ c_rarg1, /* count */ c_rarg2);
  1913     } else {
  1914       disjoint_long_copy_entry = __ pc();
  1916     BLOCK_COMMENT("Entry:");
  1917     // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
  1919     setup_arg_regs(); // from => rdi, to => rsi, count => rdx
  1920                       // r9 and r10 may be used to save non-volatile registers
  1922     // 'from', 'to' and 'qword_count' are now valid
  1924     // Copy from low to high addresses.  Use 'to' as scratch.
  1925     __ lea(end_from, Address(from, qword_count, Address::times_8, -8));
  1926     __ lea(end_to,   Address(to,   qword_count, Address::times_8, -8));
  1927     __ negptr(qword_count);
  1928     __ jmp(L_copy_32_bytes);
  1930     // Copy trailing qwords
  1931   __ BIND(L_copy_8_bytes);
  1932     __ movq(rax, Address(end_from, qword_count, Address::times_8, 8));
  1933     __ movq(Address(end_to, qword_count, Address::times_8, 8), rax);
  1934     __ increment(qword_count);
  1935     __ jcc(Assembler::notZero, L_copy_8_bytes);
  1937     if (is_oop) {
  1938       __ jmp(L_exit);
  1939     } else {
  1940       inc_counter_np(SharedRuntime::_jlong_array_copy_ctr);
  1941       restore_arg_regs();
  1942       __ xorptr(rax, rax); // return 0
  1943       __ leave(); // required for proper stackwalking of RuntimeStub frame
  1944       __ ret(0);
  1947     // Copy 64-byte chunks
  1948     copy_32_bytes_forward(end_from, end_to, qword_count, rax, L_copy_32_bytes, L_copy_8_bytes);
  1950     if (is_oop) {
  1951     __ BIND(L_exit);
  1952       gen_write_ref_array_post_barrier(saved_to, end_to, rax);
  1953       inc_counter_np(SharedRuntime::_oop_array_copy_ctr);
  1954     } else {
  1955       inc_counter_np(SharedRuntime::_jlong_array_copy_ctr);
  1957     restore_arg_regs();
  1958     __ xorptr(rax, rax); // return 0
  1959     __ leave(); // required for proper stackwalking of RuntimeStub frame
  1960     __ ret(0);
  1962     return start;
  1965   // Arguments:
  1966   //   aligned - true => Input and output aligned on a HeapWord boundary == 8 bytes
  1967   //             ignored
  1968   //   is_oop  - true => oop array, so generate store check code
  1969   //   name    - stub name string
  1970   //
  1971   // Inputs:
  1972   //   c_rarg0   - source array address
  1973   //   c_rarg1   - destination array address
  1974   //   c_rarg2   - element count, treated as ssize_t, can be zero
  1975   //
  1976   address generate_conjoint_long_oop_copy(bool aligned, bool is_oop, const char *name) {
  1977     __ align(CodeEntryAlignment);
  1978     StubCodeMark mark(this, "StubRoutines", name);
  1979     address start = __ pc();
  1981     Label L_copy_32_bytes, L_copy_8_bytes, L_exit;
  1982     const Register from        = rdi;  // source array address
  1983     const Register to          = rsi;  // destination array address
  1984     const Register qword_count = rdx;  // elements count
  1985     const Register saved_count = rcx;
  1987     __ enter(); // required for proper stackwalking of RuntimeStub frame
  1988     assert_clean_int(c_rarg2, rax);    // Make sure 'count' is clean int.
  1990     address disjoint_copy_entry = NULL;
  1991     if (is_oop) {
  1992       assert(!UseCompressedOops, "shouldn't be called for compressed oops");
  1993       disjoint_copy_entry = disjoint_oop_copy_entry;
  1994       oop_copy_entry  = __ pc();
  1995       array_overlap_test(disjoint_oop_copy_entry, Address::times_8);
  1996     } else {
  1997       disjoint_copy_entry = disjoint_long_copy_entry;
  1998       long_copy_entry = __ pc();
  1999       array_overlap_test(disjoint_long_copy_entry, Address::times_8);
  2001     BLOCK_COMMENT("Entry:");
  2002     // caller can pass a 64-bit byte count here (from Unsafe.copyMemory)
  2004     array_overlap_test(disjoint_copy_entry, Address::times_8);
  2005     setup_arg_regs(); // from => rdi, to => rsi, count => rdx
  2006                       // r9 and r10 may be used to save non-volatile registers
  2008     // 'from', 'to' and 'qword_count' are now valid
  2010     if (is_oop) {
  2011       // Save to and count for store barrier
  2012       __ movptr(saved_count, qword_count);
  2013       // No registers are destroyed by this call
  2014       gen_write_ref_array_pre_barrier(to, saved_count);
  2017     __ jmp(L_copy_32_bytes);
  2019     // Copy trailing qwords
  2020   __ BIND(L_copy_8_bytes);
  2021     __ movq(rax, Address(from, qword_count, Address::times_8, -8));
  2022     __ movq(Address(to, qword_count, Address::times_8, -8), rax);
  2023     __ decrement(qword_count);
  2024     __ jcc(Assembler::notZero, L_copy_8_bytes);
  2026     if (is_oop) {
  2027       __ jmp(L_exit);
  2028     } else {
  2029       inc_counter_np(SharedRuntime::_jlong_array_copy_ctr);
  2030       restore_arg_regs();
  2031       __ xorptr(rax, rax); // return 0
  2032       __ leave(); // required for proper stackwalking of RuntimeStub frame
  2033       __ ret(0);
  2036     // Copy in 32-bytes chunks
  2037     copy_32_bytes_backward(from, to, qword_count, rax, L_copy_32_bytes, L_copy_8_bytes);
  2039     if (is_oop) {
  2040     __ BIND(L_exit);
  2041       __ lea(rcx, Address(to, saved_count, Address::times_8, -8));
  2042       gen_write_ref_array_post_barrier(to, rcx, rax);
  2043       inc_counter_np(SharedRuntime::_oop_array_copy_ctr);
  2044     } else {
  2045       inc_counter_np(SharedRuntime::_jlong_array_copy_ctr);
  2047     restore_arg_regs();
  2048     __ xorptr(rax, rax); // return 0
  2049     __ leave(); // required for proper stackwalking of RuntimeStub frame
  2050     __ ret(0);
  2052     return start;
  2056   // Helper for generating a dynamic type check.
  2057   // Smashes no registers.
  2058   void generate_type_check(Register sub_klass,
  2059                            Register super_check_offset,
  2060                            Register super_klass,
  2061                            Label& L_success) {
  2062     assert_different_registers(sub_klass, super_check_offset, super_klass);
  2064     BLOCK_COMMENT("type_check:");
  2066     Label L_miss;
  2068     // a couple of useful fields in sub_klass:
  2069     int ss_offset = (klassOopDesc::header_size() * HeapWordSize +
  2070                      Klass::secondary_supers_offset_in_bytes());
  2071     int sc_offset = (klassOopDesc::header_size() * HeapWordSize +
  2072                      Klass::secondary_super_cache_offset_in_bytes());
  2073     Address secondary_supers_addr(sub_klass, ss_offset);
  2074     Address super_cache_addr(     sub_klass, sc_offset);
  2076     // if the pointers are equal, we are done (e.g., String[] elements)
  2077     __ cmpptr(super_klass, sub_klass);
  2078     __ jcc(Assembler::equal, L_success);
  2080     // check the supertype display:
  2081     Address super_check_addr(sub_klass, super_check_offset, Address::times_1, 0);
  2082     __ cmpptr(super_klass, super_check_addr); // test the super type
  2083     __ jcc(Assembler::equal, L_success);
  2085     // if it was a primary super, we can just fail immediately
  2086     __ cmpl(super_check_offset, sc_offset);
  2087     __ jcc(Assembler::notEqual, L_miss);
  2089     // Now do a linear scan of the secondary super-klass chain.
  2090     // The repne_scan instruction uses fixed registers, which we must spill.
  2091     // (We need a couple more temps in any case.)
  2092     // This code is rarely used, so simplicity is a virtue here.
  2093     inc_counter_np(SharedRuntime::_partial_subtype_ctr);
  2095       __ push(rax);
  2096       __ push(rcx);
  2097       __ push(rdi);
  2098       assert_different_registers(sub_klass, super_klass, rax, rcx, rdi);
  2100       __ movptr(rdi, secondary_supers_addr);
  2101       // Load the array length.
  2102       __ movl(rcx, Address(rdi, arrayOopDesc::length_offset_in_bytes()));
  2103       // Skip to start of data.
  2104       __ addptr(rdi, arrayOopDesc::base_offset_in_bytes(T_OBJECT));
  2105       // Scan rcx words at [rdi] for occurance of rax
  2106       // Set NZ/Z based on last compare
  2107       __ movptr(rax, super_klass);
  2108       if (UseCompressedOops) {
  2109         // Compare against compressed form.  Don't need to uncompress because
  2110         // looks like orig rax is restored in popq below.
  2111         __ encode_heap_oop(rax);
  2112         __ repne_scanl();
  2113       } else {
  2114         __ repne_scan();
  2117       // Unspill the temp. registers:
  2118       __ pop(rdi);
  2119       __ pop(rcx);
  2120       __ pop(rax);
  2122       __ jcc(Assembler::notEqual, L_miss);
  2125     // Success.  Cache the super we found and proceed in triumph.
  2126     __ movptr(super_cache_addr, super_klass); // note: rax is dead
  2127     __ jmp(L_success);
  2129     // Fall through on failure!
  2130     __ BIND(L_miss);
  2133   //
  2134   //  Generate checkcasting array copy stub
  2135   //
  2136   //  Input:
  2137   //    c_rarg0   - source array address
  2138   //    c_rarg1   - destination array address
  2139   //    c_rarg2   - element count, treated as ssize_t, can be zero
  2140   //    c_rarg3   - size_t ckoff (super_check_offset)
  2141   // not Win64
  2142   //    c_rarg4   - oop ckval (super_klass)
  2143   // Win64
  2144   //    rsp+40    - oop ckval (super_klass)
  2145   //
  2146   //  Output:
  2147   //    rax ==  0  -  success
  2148   //    rax == -1^K - failure, where K is partial transfer count
  2149   //
  2150   address generate_checkcast_copy(const char *name) {
  2152     Label L_load_element, L_store_element, L_do_card_marks, L_done;
  2154     // Input registers (after setup_arg_regs)
  2155     const Register from        = rdi;   // source array address
  2156     const Register to          = rsi;   // destination array address
  2157     const Register length      = rdx;   // elements count
  2158     const Register ckoff       = rcx;   // super_check_offset
  2159     const Register ckval       = r8;    // super_klass
  2161     // Registers used as temps (r13, r14 are save-on-entry)
  2162     const Register end_from    = from;  // source array end address
  2163     const Register end_to      = r13;   // destination array end address
  2164     const Register count       = rdx;   // -(count_remaining)
  2165     const Register r14_length  = r14;   // saved copy of length
  2166     // End pointers are inclusive, and if length is not zero they point
  2167     // to the last unit copied:  end_to[0] := end_from[0]
  2169     const Register rax_oop    = rax;    // actual oop copied
  2170     const Register r11_klass  = r11;    // oop._klass
  2172     //---------------------------------------------------------------
  2173     // Assembler stub will be used for this call to arraycopy
  2174     // if the two arrays are subtypes of Object[] but the
  2175     // destination array type is not equal to or a supertype
  2176     // of the source type.  Each element must be separately
  2177     // checked.
  2179     __ align(CodeEntryAlignment);
  2180     StubCodeMark mark(this, "StubRoutines", name);
  2181     address start = __ pc();
  2183     __ enter(); // required for proper stackwalking of RuntimeStub frame
  2185     checkcast_copy_entry  = __ pc();
  2186     BLOCK_COMMENT("Entry:");
  2188 #ifdef ASSERT
  2189     // caller guarantees that the arrays really are different
  2190     // otherwise, we would have to make conjoint checks
  2191     { Label L;
  2192       array_overlap_test(L, TIMES_OOP);
  2193       __ stop("checkcast_copy within a single array");
  2194       __ bind(L);
  2196 #endif //ASSERT
  2198     // allocate spill slots for r13, r14
  2199     enum {
  2200       saved_r13_offset,
  2201       saved_r14_offset,
  2202       saved_rbp_offset,
  2203       saved_rip_offset,
  2204       saved_rarg0_offset
  2205     };
  2206     __ subptr(rsp, saved_rbp_offset * wordSize);
  2207     __ movptr(Address(rsp, saved_r13_offset * wordSize), r13);
  2208     __ movptr(Address(rsp, saved_r14_offset * wordSize), r14);
  2209     setup_arg_regs(4); // from => rdi, to => rsi, length => rdx
  2210                        // ckoff => rcx, ckval => r8
  2211                        // r9 and r10 may be used to save non-volatile registers
  2212 #ifdef _WIN64
  2213     // last argument (#4) is on stack on Win64
  2214     const int ckval_offset = saved_rarg0_offset + 4;
  2215     __ movptr(ckval, Address(rsp, ckval_offset * wordSize));
  2216 #endif
  2218     // check that int operands are properly extended to size_t
  2219     assert_clean_int(length, rax);
  2220     assert_clean_int(ckoff, rax);
  2222 #ifdef ASSERT
  2223     BLOCK_COMMENT("assert consistent ckoff/ckval");
  2224     // The ckoff and ckval must be mutually consistent,
  2225     // even though caller generates both.
  2226     { Label L;
  2227       int sco_offset = (klassOopDesc::header_size() * HeapWordSize +
  2228                         Klass::super_check_offset_offset_in_bytes());
  2229       __ cmpl(ckoff, Address(ckval, sco_offset));
  2230       __ jcc(Assembler::equal, L);
  2231       __ stop("super_check_offset inconsistent");
  2232       __ bind(L);
  2234 #endif //ASSERT
  2236     // Loop-invariant addresses.  They are exclusive end pointers.
  2237     Address end_from_addr(from, length, TIMES_OOP, 0);
  2238     Address   end_to_addr(to,   length, TIMES_OOP, 0);
  2239     // Loop-variant addresses.  They assume post-incremented count < 0.
  2240     Address from_element_addr(end_from, count, TIMES_OOP, 0);
  2241     Address   to_element_addr(end_to,   count, TIMES_OOP, 0);
  2243     gen_write_ref_array_pre_barrier(to, count);
  2245     // Copy from low to high addresses, indexed from the end of each array.
  2246     __ lea(end_from, end_from_addr);
  2247     __ lea(end_to,   end_to_addr);
  2248     __ movptr(r14_length, length);        // save a copy of the length
  2249     assert(length == count, "");          // else fix next line:
  2250     __ negptr(count);                     // negate and test the length
  2251     __ jcc(Assembler::notZero, L_load_element);
  2253     // Empty array:  Nothing to do.
  2254     __ xorptr(rax, rax);                  // return 0 on (trivial) success
  2255     __ jmp(L_done);
  2257     // ======== begin loop ========
  2258     // (Loop is rotated; its entry is L_load_element.)
  2259     // Loop control:
  2260     //   for (count = -count; count != 0; count++)
  2261     // Base pointers src, dst are biased by 8*(count-1),to last element.
  2262     __ align(16);
  2264     __ BIND(L_store_element);
  2265     __ store_heap_oop(to_element_addr, rax_oop);  // store the oop
  2266     __ increment(count);               // increment the count toward zero
  2267     __ jcc(Assembler::zero, L_do_card_marks);
  2269     // ======== loop entry is here ========
  2270     __ BIND(L_load_element);
  2271     __ load_heap_oop(rax_oop, from_element_addr); // load the oop
  2272     __ testptr(rax_oop, rax_oop);
  2273     __ jcc(Assembler::zero, L_store_element);
  2275     __ load_klass(r11_klass, rax_oop);// query the object klass
  2276     generate_type_check(r11_klass, ckoff, ckval, L_store_element);
  2277     // ======== end loop ========
  2279     // It was a real error; we must depend on the caller to finish the job.
  2280     // Register rdx = -1 * number of *remaining* oops, r14 = *total* oops.
  2281     // Emit GC store barriers for the oops we have copied (r14 + rdx),
  2282     // and report their number to the caller.
  2283     assert_different_registers(rax, r14_length, count, to, end_to, rcx);
  2284     __ lea(end_to, to_element_addr);
  2285     gen_write_ref_array_post_barrier(to, end_to, rcx);
  2286     __ movptr(rax, r14_length);           // original oops
  2287     __ addptr(rax, count);                // K = (original - remaining) oops
  2288     __ notptr(rax);                       // report (-1^K) to caller
  2289     __ jmp(L_done);
  2291     // Come here on success only.
  2292     __ BIND(L_do_card_marks);
  2293     __ addptr(end_to, -wordSize);         // make an inclusive end pointer
  2294     gen_write_ref_array_post_barrier(to, end_to, rcx);
  2295     __ xorptr(rax, rax);                  // return 0 on success
  2297     // Common exit point (success or failure).
  2298     __ BIND(L_done);
  2299     __ movptr(r13, Address(rsp, saved_r13_offset * wordSize));
  2300     __ movptr(r14, Address(rsp, saved_r14_offset * wordSize));
  2301     inc_counter_np(SharedRuntime::_checkcast_array_copy_ctr);
  2302     restore_arg_regs();
  2303     __ leave(); // required for proper stackwalking of RuntimeStub frame
  2304     __ ret(0);
  2306     return start;
  2309   //
  2310   //  Generate 'unsafe' array copy stub
  2311   //  Though just as safe as the other stubs, it takes an unscaled
  2312   //  size_t argument instead of an element count.
  2313   //
  2314   //  Input:
  2315   //    c_rarg0   - source array address
  2316   //    c_rarg1   - destination array address
  2317   //    c_rarg2   - byte count, treated as ssize_t, can be zero
  2318   //
  2319   // Examines the alignment of the operands and dispatches
  2320   // to a long, int, short, or byte copy loop.
  2321   //
  2322   address generate_unsafe_copy(const char *name) {
  2324     Label L_long_aligned, L_int_aligned, L_short_aligned;
  2326     // Input registers (before setup_arg_regs)
  2327     const Register from        = c_rarg0;  // source array address
  2328     const Register to          = c_rarg1;  // destination array address
  2329     const Register size        = c_rarg2;  // byte count (size_t)
  2331     // Register used as a temp
  2332     const Register bits        = rax;      // test copy of low bits
  2334     __ align(CodeEntryAlignment);
  2335     StubCodeMark mark(this, "StubRoutines", name);
  2336     address start = __ pc();
  2338     __ enter(); // required for proper stackwalking of RuntimeStub frame
  2340     // bump this on entry, not on exit:
  2341     inc_counter_np(SharedRuntime::_unsafe_array_copy_ctr);
  2343     __ mov(bits, from);
  2344     __ orptr(bits, to);
  2345     __ orptr(bits, size);
  2347     __ testb(bits, BytesPerLong-1);
  2348     __ jccb(Assembler::zero, L_long_aligned);
  2350     __ testb(bits, BytesPerInt-1);
  2351     __ jccb(Assembler::zero, L_int_aligned);
  2353     __ testb(bits, BytesPerShort-1);
  2354     __ jump_cc(Assembler::notZero, RuntimeAddress(byte_copy_entry));
  2356     __ BIND(L_short_aligned);
  2357     __ shrptr(size, LogBytesPerShort); // size => short_count
  2358     __ jump(RuntimeAddress(short_copy_entry));
  2360     __ BIND(L_int_aligned);
  2361     __ shrptr(size, LogBytesPerInt); // size => int_count
  2362     __ jump(RuntimeAddress(int_copy_entry));
  2364     __ BIND(L_long_aligned);
  2365     __ shrptr(size, LogBytesPerLong); // size => qword_count
  2366     __ jump(RuntimeAddress(long_copy_entry));
  2368     return start;
  2371   // Perform range checks on the proposed arraycopy.
  2372   // Kills temp, but nothing else.
  2373   // Also, clean the sign bits of src_pos and dst_pos.
  2374   void arraycopy_range_checks(Register src,     // source array oop (c_rarg0)
  2375                               Register src_pos, // source position (c_rarg1)
  2376                               Register dst,     // destination array oo (c_rarg2)
  2377                               Register dst_pos, // destination position (c_rarg3)
  2378                               Register length,
  2379                               Register temp,
  2380                               Label& L_failed) {
  2381     BLOCK_COMMENT("arraycopy_range_checks:");
  2383     //  if (src_pos + length > arrayOop(src)->length())  FAIL;
  2384     __ movl(temp, length);
  2385     __ addl(temp, src_pos);             // src_pos + length
  2386     __ cmpl(temp, Address(src, arrayOopDesc::length_offset_in_bytes()));
  2387     __ jcc(Assembler::above, L_failed);
  2389     //  if (dst_pos + length > arrayOop(dst)->length())  FAIL;
  2390     __ movl(temp, length);
  2391     __ addl(temp, dst_pos);             // dst_pos + length
  2392     __ cmpl(temp, Address(dst, arrayOopDesc::length_offset_in_bytes()));
  2393     __ jcc(Assembler::above, L_failed);
  2395     // Have to clean up high 32-bits of 'src_pos' and 'dst_pos'.
  2396     // Move with sign extension can be used since they are positive.
  2397     __ movslq(src_pos, src_pos);
  2398     __ movslq(dst_pos, dst_pos);
  2400     BLOCK_COMMENT("arraycopy_range_checks done");
  2403   //
  2404   //  Generate generic array copy stubs
  2405   //
  2406   //  Input:
  2407   //    c_rarg0    -  src oop
  2408   //    c_rarg1    -  src_pos (32-bits)
  2409   //    c_rarg2    -  dst oop
  2410   //    c_rarg3    -  dst_pos (32-bits)
  2411   // not Win64
  2412   //    c_rarg4    -  element count (32-bits)
  2413   // Win64
  2414   //    rsp+40     -  element count (32-bits)
  2415   //
  2416   //  Output:
  2417   //    rax ==  0  -  success
  2418   //    rax == -1^K - failure, where K is partial transfer count
  2419   //
  2420   address generate_generic_copy(const char *name) {
  2422     Label L_failed, L_failed_0, L_objArray;
  2423     Label L_copy_bytes, L_copy_shorts, L_copy_ints, L_copy_longs;
  2425     // Input registers
  2426     const Register src        = c_rarg0;  // source array oop
  2427     const Register src_pos    = c_rarg1;  // source position
  2428     const Register dst        = c_rarg2;  // destination array oop
  2429     const Register dst_pos    = c_rarg3;  // destination position
  2430     // elements count is on stack on Win64
  2431 #ifdef _WIN64
  2432 #define C_RARG4 Address(rsp, 6 * wordSize)
  2433 #else
  2434 #define C_RARG4 c_rarg4
  2435 #endif
  2437     { int modulus = CodeEntryAlignment;
  2438       int target  = modulus - 5; // 5 = sizeof jmp(L_failed)
  2439       int advance = target - (__ offset() % modulus);
  2440       if (advance < 0)  advance += modulus;
  2441       if (advance > 0)  __ nop(advance);
  2443     StubCodeMark mark(this, "StubRoutines", name);
  2445     // Short-hop target to L_failed.  Makes for denser prologue code.
  2446     __ BIND(L_failed_0);
  2447     __ jmp(L_failed);
  2448     assert(__ offset() % CodeEntryAlignment == 0, "no further alignment needed");
  2450     __ align(CodeEntryAlignment);
  2451     address start = __ pc();
  2453     __ enter(); // required for proper stackwalking of RuntimeStub frame
  2455     // bump this on entry, not on exit:
  2456     inc_counter_np(SharedRuntime::_generic_array_copy_ctr);
  2458     //-----------------------------------------------------------------------
  2459     // Assembler stub will be used for this call to arraycopy
  2460     // if the following conditions are met:
  2461     //
  2462     // (1) src and dst must not be null.
  2463     // (2) src_pos must not be negative.
  2464     // (3) dst_pos must not be negative.
  2465     // (4) length  must not be negative.
  2466     // (5) src klass and dst klass should be the same and not NULL.
  2467     // (6) src and dst should be arrays.
  2468     // (7) src_pos + length must not exceed length of src.
  2469     // (8) dst_pos + length must not exceed length of dst.
  2470     //
  2472     //  if (src == NULL) return -1;
  2473     __ testptr(src, src);         // src oop
  2474     size_t j1off = __ offset();
  2475     __ jccb(Assembler::zero, L_failed_0);
  2477     //  if (src_pos < 0) return -1;
  2478     __ testl(src_pos, src_pos); // src_pos (32-bits)
  2479     __ jccb(Assembler::negative, L_failed_0);
  2481     //  if (dst == NULL) return -1;
  2482     __ testptr(dst, dst);         // dst oop
  2483     __ jccb(Assembler::zero, L_failed_0);
  2485     //  if (dst_pos < 0) return -1;
  2486     __ testl(dst_pos, dst_pos); // dst_pos (32-bits)
  2487     size_t j4off = __ offset();
  2488     __ jccb(Assembler::negative, L_failed_0);
  2490     // The first four tests are very dense code,
  2491     // but not quite dense enough to put four
  2492     // jumps in a 16-byte instruction fetch buffer.
  2493     // That's good, because some branch predicters
  2494     // do not like jumps so close together.
  2495     // Make sure of this.
  2496     guarantee(((j1off ^ j4off) & ~15) != 0, "I$ line of 1st & 4th jumps");
  2498     // registers used as temp
  2499     const Register r11_length    = r11; // elements count to copy
  2500     const Register r10_src_klass = r10; // array klass
  2501     const Register r9_dst_klass  = r9;  // dest array klass
  2503     //  if (length < 0) return -1;
  2504     __ movl(r11_length, C_RARG4);       // length (elements count, 32-bits value)
  2505     __ testl(r11_length, r11_length);
  2506     __ jccb(Assembler::negative, L_failed_0);
  2508     __ load_klass(r10_src_klass, src);
  2509 #ifdef ASSERT
  2510     //  assert(src->klass() != NULL);
  2511     BLOCK_COMMENT("assert klasses not null");
  2512     { Label L1, L2;
  2513       __ testptr(r10_src_klass, r10_src_klass);
  2514       __ jcc(Assembler::notZero, L2);   // it is broken if klass is NULL
  2515       __ bind(L1);
  2516       __ stop("broken null klass");
  2517       __ bind(L2);
  2518       __ load_klass(r9_dst_klass, dst);
  2519       __ cmpq(r9_dst_klass, 0);
  2520       __ jcc(Assembler::equal, L1);     // this would be broken also
  2521       BLOCK_COMMENT("assert done");
  2523 #endif
  2525     // Load layout helper (32-bits)
  2526     //
  2527     //  |array_tag|     | header_size | element_type |     |log2_element_size|
  2528     // 32        30    24            16              8     2                 0
  2529     //
  2530     //   array_tag: typeArray = 0x3, objArray = 0x2, non-array = 0x0
  2531     //
  2533     int lh_offset = klassOopDesc::header_size() * HeapWordSize +
  2534                     Klass::layout_helper_offset_in_bytes();
  2536     const Register rax_lh = rax;  // layout helper
  2538     __ movl(rax_lh, Address(r10_src_klass, lh_offset));
  2540     // Handle objArrays completely differently...
  2541     jint objArray_lh = Klass::array_layout_helper(T_OBJECT);
  2542     __ cmpl(rax_lh, objArray_lh);
  2543     __ jcc(Assembler::equal, L_objArray);
  2545     //  if (src->klass() != dst->klass()) return -1;
  2546     __ load_klass(r9_dst_klass, dst);
  2547     __ cmpq(r10_src_klass, r9_dst_klass);
  2548     __ jcc(Assembler::notEqual, L_failed);
  2550     //  if (!src->is_Array()) return -1;
  2551     __ cmpl(rax_lh, Klass::_lh_neutral_value);
  2552     __ jcc(Assembler::greaterEqual, L_failed);
  2554     // At this point, it is known to be a typeArray (array_tag 0x3).
  2555 #ifdef ASSERT
  2556     { Label L;
  2557       __ cmpl(rax_lh, (Klass::_lh_array_tag_type_value << Klass::_lh_array_tag_shift));
  2558       __ jcc(Assembler::greaterEqual, L);
  2559       __ stop("must be a primitive array");
  2560       __ bind(L);
  2562 #endif
  2564     arraycopy_range_checks(src, src_pos, dst, dst_pos, r11_length,
  2565                            r10, L_failed);
  2567     // typeArrayKlass
  2568     //
  2569     // src_addr = (src + array_header_in_bytes()) + (src_pos << log2elemsize);
  2570     // dst_addr = (dst + array_header_in_bytes()) + (dst_pos << log2elemsize);
  2571     //
  2573     const Register r10_offset = r10;    // array offset
  2574     const Register rax_elsize = rax_lh; // element size
  2576     __ movl(r10_offset, rax_lh);
  2577     __ shrl(r10_offset, Klass::_lh_header_size_shift);
  2578     __ andptr(r10_offset, Klass::_lh_header_size_mask);   // array_offset
  2579     __ addptr(src, r10_offset);           // src array offset
  2580     __ addptr(dst, r10_offset);           // dst array offset
  2581     BLOCK_COMMENT("choose copy loop based on element size");
  2582     __ andl(rax_lh, Klass::_lh_log2_element_size_mask); // rax_lh -> rax_elsize
  2584     // next registers should be set before the jump to corresponding stub
  2585     const Register from     = c_rarg0;  // source array address
  2586     const Register to       = c_rarg1;  // destination array address
  2587     const Register count    = c_rarg2;  // elements count
  2589     // 'from', 'to', 'count' registers should be set in such order
  2590     // since they are the same as 'src', 'src_pos', 'dst'.
  2592   __ BIND(L_copy_bytes);
  2593     __ cmpl(rax_elsize, 0);
  2594     __ jccb(Assembler::notEqual, L_copy_shorts);
  2595     __ lea(from, Address(src, src_pos, Address::times_1, 0));// src_addr
  2596     __ lea(to,   Address(dst, dst_pos, Address::times_1, 0));// dst_addr
  2597     __ movl2ptr(count, r11_length); // length
  2598     __ jump(RuntimeAddress(byte_copy_entry));
  2600   __ BIND(L_copy_shorts);
  2601     __ cmpl(rax_elsize, LogBytesPerShort);
  2602     __ jccb(Assembler::notEqual, L_copy_ints);
  2603     __ lea(from, Address(src, src_pos, Address::times_2, 0));// src_addr
  2604     __ lea(to,   Address(dst, dst_pos, Address::times_2, 0));// dst_addr
  2605     __ movl2ptr(count, r11_length); // length
  2606     __ jump(RuntimeAddress(short_copy_entry));
  2608   __ BIND(L_copy_ints);
  2609     __ cmpl(rax_elsize, LogBytesPerInt);
  2610     __ jccb(Assembler::notEqual, L_copy_longs);
  2611     __ lea(from, Address(src, src_pos, Address::times_4, 0));// src_addr
  2612     __ lea(to,   Address(dst, dst_pos, Address::times_4, 0));// dst_addr
  2613     __ movl2ptr(count, r11_length); // length
  2614     __ jump(RuntimeAddress(int_copy_entry));
  2616   __ BIND(L_copy_longs);
  2617 #ifdef ASSERT
  2618     { Label L;
  2619       __ cmpl(rax_elsize, LogBytesPerLong);
  2620       __ jcc(Assembler::equal, L);
  2621       __ stop("must be long copy, but elsize is wrong");
  2622       __ bind(L);
  2624 #endif
  2625     __ lea(from, Address(src, src_pos, Address::times_8, 0));// src_addr
  2626     __ lea(to,   Address(dst, dst_pos, Address::times_8, 0));// dst_addr
  2627     __ movl2ptr(count, r11_length); // length
  2628     __ jump(RuntimeAddress(long_copy_entry));
  2630     // objArrayKlass
  2631   __ BIND(L_objArray);
  2632     // live at this point:  r10_src_klass, src[_pos], dst[_pos]
  2634     Label L_plain_copy, L_checkcast_copy;
  2635     //  test array classes for subtyping
  2636     __ load_klass(r9_dst_klass, dst);
  2637     __ cmpq(r10_src_klass, r9_dst_klass); // usual case is exact equality
  2638     __ jcc(Assembler::notEqual, L_checkcast_copy);
  2640     // Identically typed arrays can be copied without element-wise checks.
  2641     arraycopy_range_checks(src, src_pos, dst, dst_pos, r11_length,
  2642                            r10, L_failed);
  2644     __ lea(from, Address(src, src_pos, TIMES_OOP,
  2645                  arrayOopDesc::base_offset_in_bytes(T_OBJECT))); // src_addr
  2646     __ lea(to,   Address(dst, dst_pos, TIMES_OOP,
  2647                  arrayOopDesc::base_offset_in_bytes(T_OBJECT))); // dst_addr
  2648     __ movl2ptr(count, r11_length); // length
  2649   __ BIND(L_plain_copy);
  2650     __ jump(RuntimeAddress(oop_copy_entry));
  2652   __ BIND(L_checkcast_copy);
  2653     // live at this point:  r10_src_klass, !r11_length
  2655       // assert(r11_length == C_RARG4); // will reload from here
  2656       Register r11_dst_klass = r11;
  2657       __ load_klass(r11_dst_klass, dst);
  2659       // Before looking at dst.length, make sure dst is also an objArray.
  2660       __ cmpl(Address(r11_dst_klass, lh_offset), objArray_lh);
  2661       __ jcc(Assembler::notEqual, L_failed);
  2663       // It is safe to examine both src.length and dst.length.
  2664 #ifndef _WIN64
  2665       arraycopy_range_checks(src, src_pos, dst, dst_pos, C_RARG4,
  2666                              rax, L_failed);
  2667 #else
  2668       __ movl(r11_length, C_RARG4);     // reload
  2669       arraycopy_range_checks(src, src_pos, dst, dst_pos, r11_length,
  2670                              rax, L_failed);
  2671       __ load_klass(r11_dst_klass, dst); // reload
  2672 #endif
  2674       // Marshal the base address arguments now, freeing registers.
  2675       __ lea(from, Address(src, src_pos, TIMES_OOP,
  2676                    arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
  2677       __ lea(to,   Address(dst, dst_pos, TIMES_OOP,
  2678                    arrayOopDesc::base_offset_in_bytes(T_OBJECT)));
  2679       __ movl(count, C_RARG4);          // length (reloaded)
  2680       Register sco_temp = c_rarg3;      // this register is free now
  2681       assert_different_registers(from, to, count, sco_temp,
  2682                                  r11_dst_klass, r10_src_klass);
  2683       assert_clean_int(count, sco_temp);
  2685       // Generate the type check.
  2686       int sco_offset = (klassOopDesc::header_size() * HeapWordSize +
  2687                         Klass::super_check_offset_offset_in_bytes());
  2688       __ movl(sco_temp, Address(r11_dst_klass, sco_offset));
  2689       assert_clean_int(sco_temp, rax);
  2690       generate_type_check(r10_src_klass, sco_temp, r11_dst_klass, L_plain_copy);
  2692       // Fetch destination element klass from the objArrayKlass header.
  2693       int ek_offset = (klassOopDesc::header_size() * HeapWordSize +
  2694                        objArrayKlass::element_klass_offset_in_bytes());
  2695       __ movptr(r11_dst_klass, Address(r11_dst_klass, ek_offset));
  2696       __ movl(sco_temp,      Address(r11_dst_klass, sco_offset));
  2697       assert_clean_int(sco_temp, rax);
  2699       // the checkcast_copy loop needs two extra arguments:
  2700       assert(c_rarg3 == sco_temp, "#3 already in place");
  2701       __ movptr(C_RARG4, r11_dst_klass);  // dst.klass.element_klass
  2702       __ jump(RuntimeAddress(checkcast_copy_entry));
  2705   __ BIND(L_failed);
  2706     __ xorptr(rax, rax);
  2707     __ notptr(rax); // return -1
  2708     __ leave();   // required for proper stackwalking of RuntimeStub frame
  2709     __ ret(0);
  2711     return start;
  2714 #undef length_arg
  2716   void generate_arraycopy_stubs() {
  2717     // Call the conjoint generation methods immediately after
  2718     // the disjoint ones so that short branches from the former
  2719     // to the latter can be generated.
  2720     StubRoutines::_jbyte_disjoint_arraycopy  = generate_disjoint_byte_copy(false, "jbyte_disjoint_arraycopy");
  2721     StubRoutines::_jbyte_arraycopy           = generate_conjoint_byte_copy(false, "jbyte_arraycopy");
  2723     StubRoutines::_jshort_disjoint_arraycopy = generate_disjoint_short_copy(false, "jshort_disjoint_arraycopy");
  2724     StubRoutines::_jshort_arraycopy          = generate_conjoint_short_copy(false, "jshort_arraycopy");
  2726     StubRoutines::_jint_disjoint_arraycopy   = generate_disjoint_int_oop_copy(false, false, "jint_disjoint_arraycopy");
  2727     StubRoutines::_jint_arraycopy            = generate_conjoint_int_oop_copy(false, false, "jint_arraycopy");
  2729     StubRoutines::_jlong_disjoint_arraycopy  = generate_disjoint_long_oop_copy(false, false, "jlong_disjoint_arraycopy");
  2730     StubRoutines::_jlong_arraycopy           = generate_conjoint_long_oop_copy(false, false, "jlong_arraycopy");
  2733     if (UseCompressedOops) {
  2734       StubRoutines::_oop_disjoint_arraycopy  = generate_disjoint_int_oop_copy(false, true, "oop_disjoint_arraycopy");
  2735       StubRoutines::_oop_arraycopy           = generate_conjoint_int_oop_copy(false, true, "oop_arraycopy");
  2736     } else {
  2737       StubRoutines::_oop_disjoint_arraycopy  = generate_disjoint_long_oop_copy(false, true, "oop_disjoint_arraycopy");
  2738       StubRoutines::_oop_arraycopy           = generate_conjoint_long_oop_copy(false, true, "oop_arraycopy");
  2741     StubRoutines::_checkcast_arraycopy = generate_checkcast_copy("checkcast_arraycopy");
  2742     StubRoutines::_unsafe_arraycopy    = generate_unsafe_copy("unsafe_arraycopy");
  2743     StubRoutines::_generic_arraycopy   = generate_generic_copy("generic_arraycopy");
  2745     // We don't generate specialized code for HeapWord-aligned source
  2746     // arrays, so just use the code we've already generated
  2747     StubRoutines::_arrayof_jbyte_disjoint_arraycopy  = StubRoutines::_jbyte_disjoint_arraycopy;
  2748     StubRoutines::_arrayof_jbyte_arraycopy           = StubRoutines::_jbyte_arraycopy;
  2750     StubRoutines::_arrayof_jshort_disjoint_arraycopy = StubRoutines::_jshort_disjoint_arraycopy;
  2751     StubRoutines::_arrayof_jshort_arraycopy          = StubRoutines::_jshort_arraycopy;
  2753     StubRoutines::_arrayof_jint_disjoint_arraycopy   = StubRoutines::_jint_disjoint_arraycopy;
  2754     StubRoutines::_arrayof_jint_arraycopy            = StubRoutines::_jint_arraycopy;
  2756     StubRoutines::_arrayof_jlong_disjoint_arraycopy  = StubRoutines::_jlong_disjoint_arraycopy;
  2757     StubRoutines::_arrayof_jlong_arraycopy           = StubRoutines::_jlong_arraycopy;
  2759     StubRoutines::_arrayof_oop_disjoint_arraycopy    = StubRoutines::_oop_disjoint_arraycopy;
  2760     StubRoutines::_arrayof_oop_arraycopy             = StubRoutines::_oop_arraycopy;
  2763 #undef __
  2764 #define __ masm->
  2766   // Continuation point for throwing of implicit exceptions that are
  2767   // not handled in the current activation. Fabricates an exception
  2768   // oop and initiates normal exception dispatching in this
  2769   // frame. Since we need to preserve callee-saved values (currently
  2770   // only for C2, but done for C1 as well) we need a callee-saved oop
  2771   // map and therefore have to make these stubs into RuntimeStubs
  2772   // rather than BufferBlobs.  If the compiler needs all registers to
  2773   // be preserved between the fault point and the exception handler
  2774   // then it must assume responsibility for that in
  2775   // AbstractCompiler::continuation_for_implicit_null_exception or
  2776   // continuation_for_implicit_division_by_zero_exception. All other
  2777   // implicit exceptions (e.g., NullPointerException or
  2778   // AbstractMethodError on entry) are either at call sites or
  2779   // otherwise assume that stack unwinding will be initiated, so
  2780   // caller saved registers were assumed volatile in the compiler.
  2781   address generate_throw_exception(const char* name,
  2782                                    address runtime_entry,
  2783                                    bool restore_saved_exception_pc) {
  2784     // Information about frame layout at time of blocking runtime call.
  2785     // Note that we only have to preserve callee-saved registers since
  2786     // the compilers are responsible for supplying a continuation point
  2787     // if they expect all registers to be preserved.
  2788     enum layout {
  2789       rbp_off = frame::arg_reg_save_area_bytes/BytesPerInt,
  2790       rbp_off2,
  2791       return_off,
  2792       return_off2,
  2793       framesize // inclusive of return address
  2794     };
  2796     int insts_size = 512;
  2797     int locs_size  = 64;
  2799     CodeBuffer code(name, insts_size, locs_size);
  2800     OopMapSet* oop_maps  = new OopMapSet();
  2801     MacroAssembler* masm = new MacroAssembler(&code);
  2803     address start = __ pc();
  2805     // This is an inlined and slightly modified version of call_VM
  2806     // which has the ability to fetch the return PC out of
  2807     // thread-local storage and also sets up last_Java_sp slightly
  2808     // differently than the real call_VM
  2809     if (restore_saved_exception_pc) {
  2810       __ movptr(rax,
  2811                 Address(r15_thread,
  2812                         in_bytes(JavaThread::saved_exception_pc_offset())));
  2813       __ push(rax);
  2816     __ enter(); // required for proper stackwalking of RuntimeStub frame
  2818     assert(is_even(framesize/2), "sp not 16-byte aligned");
  2820     // return address and rbp are already in place
  2821     __ subptr(rsp, (framesize-4) << LogBytesPerInt); // prolog
  2823     int frame_complete = __ pc() - start;
  2825     // Set up last_Java_sp and last_Java_fp
  2826     __ set_last_Java_frame(rsp, rbp, NULL);
  2828     // Call runtime
  2829     __ movptr(c_rarg0, r15_thread);
  2830     BLOCK_COMMENT("call runtime_entry");
  2831     __ call(RuntimeAddress(runtime_entry));
  2833     // Generate oop map
  2834     OopMap* map = new OopMap(framesize, 0);
  2836     oop_maps->add_gc_map(__ pc() - start, map);
  2838     __ reset_last_Java_frame(true, false);
  2840     __ leave(); // required for proper stackwalking of RuntimeStub frame
  2842     // check for pending exceptions
  2843 #ifdef ASSERT
  2844     Label L;
  2845     __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()),
  2846             (int32_t) NULL_WORD);
  2847     __ jcc(Assembler::notEqual, L);
  2848     __ should_not_reach_here();
  2849     __ bind(L);
  2850 #endif // ASSERT
  2851     __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
  2854     // codeBlob framesize is in words (not VMRegImpl::slot_size)
  2855     RuntimeStub* stub =
  2856       RuntimeStub::new_runtime_stub(name,
  2857                                     &code,
  2858                                     frame_complete,
  2859                                     (framesize >> (LogBytesPerWord - LogBytesPerInt)),
  2860                                     oop_maps, false);
  2861     return stub->entry_point();
  2864   // Initialization
  2865   void generate_initial() {
  2866     // Generates all stubs and initializes the entry points
  2868     // This platform-specific stub is needed by generate_call_stub()
  2869     StubRoutines::x86::_mxcsr_std        = generate_fp_mask("mxcsr_std",        0x0000000000001F80);
  2871     // entry points that exist in all platforms Note: This is code
  2872     // that could be shared among different platforms - however the
  2873     // benefit seems to be smaller than the disadvantage of having a
  2874     // much more complicated generator structure. See also comment in
  2875     // stubRoutines.hpp.
  2877     StubRoutines::_forward_exception_entry = generate_forward_exception();
  2879     StubRoutines::_call_stub_entry =
  2880       generate_call_stub(StubRoutines::_call_stub_return_address);
  2882     // is referenced by megamorphic call
  2883     StubRoutines::_catch_exception_entry = generate_catch_exception();
  2885     // atomic calls
  2886     StubRoutines::_atomic_xchg_entry         = generate_atomic_xchg();
  2887     StubRoutines::_atomic_xchg_ptr_entry     = generate_atomic_xchg_ptr();
  2888     StubRoutines::_atomic_cmpxchg_entry      = generate_atomic_cmpxchg();
  2889     StubRoutines::_atomic_cmpxchg_long_entry = generate_atomic_cmpxchg_long();
  2890     StubRoutines::_atomic_add_entry          = generate_atomic_add();
  2891     StubRoutines::_atomic_add_ptr_entry      = generate_atomic_add_ptr();
  2892     StubRoutines::_fence_entry               = generate_orderaccess_fence();
  2894     StubRoutines::_handler_for_unsafe_access_entry =
  2895       generate_handler_for_unsafe_access();
  2897     // platform dependent
  2898     StubRoutines::x86::_get_previous_fp_entry = generate_get_previous_fp();
  2900     StubRoutines::x86::_verify_mxcsr_entry    = generate_verify_mxcsr();
  2903   void generate_all() {
  2904     // Generates all stubs and initializes the entry points
  2906     // These entry points require SharedInfo::stack0 to be set up in
  2907     // non-core builds and need to be relocatable, so they each
  2908     // fabricate a RuntimeStub internally.
  2909     StubRoutines::_throw_AbstractMethodError_entry =
  2910       generate_throw_exception("AbstractMethodError throw_exception",
  2911                                CAST_FROM_FN_PTR(address,
  2912                                                 SharedRuntime::
  2913                                                 throw_AbstractMethodError),
  2914                                false);
  2916     StubRoutines::_throw_IncompatibleClassChangeError_entry =
  2917       generate_throw_exception("IncompatibleClassChangeError throw_exception",
  2918                                CAST_FROM_FN_PTR(address,
  2919                                                 SharedRuntime::
  2920                                                 throw_IncompatibleClassChangeError),
  2921                                false);
  2923     StubRoutines::_throw_ArithmeticException_entry =
  2924       generate_throw_exception("ArithmeticException throw_exception",
  2925                                CAST_FROM_FN_PTR(address,
  2926                                                 SharedRuntime::
  2927                                                 throw_ArithmeticException),
  2928                                true);
  2930     StubRoutines::_throw_NullPointerException_entry =
  2931       generate_throw_exception("NullPointerException throw_exception",
  2932                                CAST_FROM_FN_PTR(address,
  2933                                                 SharedRuntime::
  2934                                                 throw_NullPointerException),
  2935                                true);
  2937     StubRoutines::_throw_NullPointerException_at_call_entry =
  2938       generate_throw_exception("NullPointerException at call throw_exception",
  2939                                CAST_FROM_FN_PTR(address,
  2940                                                 SharedRuntime::
  2941                                                 throw_NullPointerException_at_call),
  2942                                false);
  2944     StubRoutines::_throw_StackOverflowError_entry =
  2945       generate_throw_exception("StackOverflowError throw_exception",
  2946                                CAST_FROM_FN_PTR(address,
  2947                                                 SharedRuntime::
  2948                                                 throw_StackOverflowError),
  2949                                false);
  2951     // entry points that are platform specific
  2952     StubRoutines::x86::_f2i_fixup = generate_f2i_fixup();
  2953     StubRoutines::x86::_f2l_fixup = generate_f2l_fixup();
  2954     StubRoutines::x86::_d2i_fixup = generate_d2i_fixup();
  2955     StubRoutines::x86::_d2l_fixup = generate_d2l_fixup();
  2957     StubRoutines::x86::_float_sign_mask  = generate_fp_mask("float_sign_mask",  0x7FFFFFFF7FFFFFFF);
  2958     StubRoutines::x86::_float_sign_flip  = generate_fp_mask("float_sign_flip",  0x8000000080000000);
  2959     StubRoutines::x86::_double_sign_mask = generate_fp_mask("double_sign_mask", 0x7FFFFFFFFFFFFFFF);
  2960     StubRoutines::x86::_double_sign_flip = generate_fp_mask("double_sign_flip", 0x8000000000000000);
  2962     // support for verify_oop (must happen after universe_init)
  2963     StubRoutines::_verify_oop_subroutine_entry = generate_verify_oop();
  2965     // arraycopy stubs used by compilers
  2966     generate_arraycopy_stubs();
  2969  public:
  2970   StubGenerator(CodeBuffer* code, bool all) : StubCodeGenerator(code) {
  2971     if (all) {
  2972       generate_all();
  2973     } else {
  2974       generate_initial();
  2977 }; // end class declaration
  2979 address StubGenerator::disjoint_byte_copy_entry  = NULL;
  2980 address StubGenerator::disjoint_short_copy_entry = NULL;
  2981 address StubGenerator::disjoint_int_copy_entry   = NULL;
  2982 address StubGenerator::disjoint_long_copy_entry  = NULL;
  2983 address StubGenerator::disjoint_oop_copy_entry   = NULL;
  2985 address StubGenerator::byte_copy_entry  = NULL;
  2986 address StubGenerator::short_copy_entry = NULL;
  2987 address StubGenerator::int_copy_entry   = NULL;
  2988 address StubGenerator::long_copy_entry  = NULL;
  2989 address StubGenerator::oop_copy_entry   = NULL;
  2991 address StubGenerator::checkcast_copy_entry = NULL;
  2993 void StubGenerator_generate(CodeBuffer* code, bool all) {
  2994   StubGenerator g(code, all);

mercurial