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