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