src/hotspot/share/opto/macroArrayCopy.cpp
author neliasso
Thu, 31 Oct 2019 17:16:36 +0100
changeset 58931 304c63b17b07
parent 58273 08a5148e7c4e
permissions -rw-r--r--
8232896: ZGC: Enable C2 clone intrinsic Reviewed-by: pliden, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
     1
/*
58273
08a5148e7c4e 8230505: Replace JVM type comparisons to T_OBJECT and T_ARRAY with call to is_reference_type
lfoltan
parents: 58217
diff changeset
     2
 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
     4
 *
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
     8
 *
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    13
 * accompanied this code).
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    14
 *
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    18
 *
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    21
 * questions.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    22
 *
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    23
 */
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    24
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    25
#include "precompiled.hpp"
50399
ee87876734c9 8203787: Hotspot build broken on linux-sparc after 8202377
glaubitz
parents: 50180
diff changeset
    26
#include "gc/shared/barrierSet.hpp"
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents: 28396
diff changeset
    27
#include "opto/arraycopynode.hpp"
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    28
#include "oops/objArrayKlass.hpp"
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    29
#include "opto/convertnode.hpp"
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    30
#include "opto/graphKit.hpp"
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    31
#include "opto/macro.hpp"
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    32
#include "opto/runtime.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46620
diff changeset
    33
#include "utilities/align.hpp"
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    34
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    35
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    36
void PhaseMacroExpand::insert_mem_bar(Node** ctrl, Node** mem, int opcode, Node* precedent) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    37
  MemBarNode* mb = MemBarNode::make(C, opcode, Compile::AliasIdxBot, precedent);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    38
  mb->init_req(TypeFunc::Control, *ctrl);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    39
  mb->init_req(TypeFunc::Memory, *mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    40
  transform_later(mb);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    41
  *ctrl = new ProjNode(mb,TypeFunc::Control);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    42
  transform_later(*ctrl);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    43
  Node* mem_proj = new ProjNode(mb,TypeFunc::Memory);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    44
  transform_later(mem_proj);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    45
  *mem = mem_proj;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    46
}
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    47
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    48
Node* PhaseMacroExpand::array_element_address(Node* ary, Node* idx, BasicType elembt) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    49
  uint shift  = exact_log2(type2aelembytes(elembt));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    50
  uint header = arrayOopDesc::base_offset_in_bytes(elembt);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    51
  Node* base =  basic_plus_adr(ary, header);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    52
#ifdef _LP64
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    53
  // see comment in GraphKit::array_element_address
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    54
  int index_max = max_jint - 1;  // array size is max_jint, index is one less
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    55
  const TypeLong* lidxtype = TypeLong::make(CONST64(0), index_max, Type::WidenMax);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    56
  idx = transform_later( new ConvI2LNode(idx, lidxtype) );
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    57
#endif
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    58
  Node* scale = new LShiftXNode(idx, intcon(shift));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    59
  transform_later(scale);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    60
  return basic_plus_adr(ary, base, scale);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    61
}
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    62
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    63
Node* PhaseMacroExpand::ConvI2L(Node* offset) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    64
  return transform_later(new ConvI2LNode(offset));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    65
}
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    66
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    67
Node* PhaseMacroExpand::make_leaf_call(Node* ctrl, Node* mem,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    68
                                       const TypeFunc* call_type, address call_addr,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    69
                                       const char* call_name,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    70
                                       const TypePtr* adr_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    71
                                       Node* parm0, Node* parm1,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    72
                                       Node* parm2, Node* parm3,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    73
                                       Node* parm4, Node* parm5,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    74
                                       Node* parm6, Node* parm7) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    75
  Node* call = new CallLeafNoFPNode(call_type, call_addr, call_name, adr_type);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    76
  call->init_req(TypeFunc::Control, ctrl);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    77
  call->init_req(TypeFunc::I_O    , top());
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    78
  call->init_req(TypeFunc::Memory , mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    79
  call->init_req(TypeFunc::ReturnAdr, top());
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    80
  call->init_req(TypeFunc::FramePtr, top());
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    81
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    82
  // Hook each parm in order.  Stop looking at the first NULL.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    83
  if (parm0 != NULL) { call->init_req(TypeFunc::Parms+0, parm0);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    84
  if (parm1 != NULL) { call->init_req(TypeFunc::Parms+1, parm1);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    85
  if (parm2 != NULL) { call->init_req(TypeFunc::Parms+2, parm2);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    86
  if (parm3 != NULL) { call->init_req(TypeFunc::Parms+3, parm3);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    87
  if (parm4 != NULL) { call->init_req(TypeFunc::Parms+4, parm4);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    88
  if (parm5 != NULL) { call->init_req(TypeFunc::Parms+5, parm5);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    89
  if (parm6 != NULL) { call->init_req(TypeFunc::Parms+6, parm6);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    90
  if (parm7 != NULL) { call->init_req(TypeFunc::Parms+7, parm7);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    91
    /* close each nested if ===> */  } } } } } } } }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    92
  assert(call->in(call->req()-1) != NULL, "must initialize all parms");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    93
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    94
  return call;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    95
}
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    96
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    97
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    98
//------------------------------generate_guard---------------------------
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
    99
// Helper function for generating guarded fast-slow graph structures.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   100
// The given 'test', if true, guards a slow path.  If the test fails
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   101
// then a fast path can be taken.  (We generally hope it fails.)
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   102
// In all cases, GraphKit::control() is updated to the fast path.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   103
// The returned value represents the control for the slow path.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   104
// The return value is never 'top'; it is either a valid control
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   105
// or NULL if it is obvious that the slow path can never be taken.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   106
// Also, if region and the slow control are not NULL, the slow edge
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   107
// is appended to the region.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   108
Node* PhaseMacroExpand::generate_guard(Node** ctrl, Node* test, RegionNode* region, float true_prob) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   109
  if ((*ctrl)->is_top()) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   110
    // Already short circuited.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   111
    return NULL;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   112
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   113
  // Build an if node and its projections.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   114
  // If test is true we take the slow path, which we assume is uncommon.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   115
  if (_igvn.type(test) == TypeInt::ZERO) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   116
    // The slow branch is never taken.  No need to build this guard.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   117
    return NULL;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   118
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   119
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   120
  IfNode* iff = new IfNode(*ctrl, test, true_prob, COUNT_UNKNOWN);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   121
  transform_later(iff);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   122
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   123
  Node* if_slow = new IfTrueNode(iff);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   124
  transform_later(if_slow);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   125
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   126
  if (region != NULL) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   127
    region->add_req(if_slow);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   128
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   129
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   130
  Node* if_fast = new IfFalseNode(iff);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   131
  transform_later(if_fast);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   132
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   133
  *ctrl = if_fast;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   134
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   135
  return if_slow;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   136
}
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   137
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   138
inline Node* PhaseMacroExpand::generate_slow_guard(Node** ctrl, Node* test, RegionNode* region) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   139
  return generate_guard(ctrl, test, region, PROB_UNLIKELY_MAG(3));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   140
}
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   141
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   142
void PhaseMacroExpand::generate_negative_guard(Node** ctrl, Node* index, RegionNode* region) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   143
  if ((*ctrl)->is_top())
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   144
    return;                // already stopped
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   145
  if (_igvn.type(index)->higher_equal(TypeInt::POS)) // [0,maxint]
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   146
    return;                // index is already adequately typed
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   147
  Node* cmp_lt = new CmpINode(index, intcon(0));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   148
  transform_later(cmp_lt);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   149
  Node* bol_lt = new BoolNode(cmp_lt, BoolTest::lt);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   150
  transform_later(bol_lt);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   151
  generate_guard(ctrl, bol_lt, region, PROB_MIN);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   152
}
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   153
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   154
void PhaseMacroExpand::generate_limit_guard(Node** ctrl, Node* offset, Node* subseq_length, Node* array_length, RegionNode* region) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   155
  if ((*ctrl)->is_top())
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   156
    return;                // already stopped
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   157
  bool zero_offset = _igvn.type(offset) == TypeInt::ZERO;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   158
  if (zero_offset && subseq_length->eqv_uncast(array_length))
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   159
    return;                // common case of whole-array copy
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   160
  Node* last = subseq_length;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   161
  if (!zero_offset) {            // last += offset
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   162
    last = new AddINode(last, offset);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   163
    transform_later(last);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   164
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   165
  Node* cmp_lt = new CmpUNode(array_length, last);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   166
  transform_later(cmp_lt);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   167
  Node* bol_lt = new BoolNode(cmp_lt, BoolTest::lt);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   168
  transform_later(bol_lt);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   169
  generate_guard(ctrl, bol_lt, region, PROB_MIN);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   170
}
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   171
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   172
Node* PhaseMacroExpand::generate_nonpositive_guard(Node** ctrl, Node* index, bool never_negative) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   173
  if ((*ctrl)->is_top())  return NULL;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   174
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   175
  if (_igvn.type(index)->higher_equal(TypeInt::POS1)) // [1,maxint]
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   176
    return NULL;                // index is already adequately typed
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   177
  Node* cmp_le = new CmpINode(index, intcon(0));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   178
  transform_later(cmp_le);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   179
  BoolTest::mask le_or_eq = (never_negative ? BoolTest::eq : BoolTest::le);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   180
  Node* bol_le = new BoolNode(cmp_le, le_or_eq);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   181
  transform_later(bol_le);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   182
  Node* is_notp = generate_guard(ctrl, bol_le, NULL, PROB_MIN);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   183
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   184
  return is_notp;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   185
}
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   186
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   187
void PhaseMacroExpand::finish_arraycopy_call(Node* call, Node** ctrl, MergeMemNode** mem, const TypePtr* adr_type) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   188
  transform_later(call);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   189
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   190
  *ctrl = new ProjNode(call,TypeFunc::Control);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   191
  transform_later(*ctrl);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   192
  Node* newmem = new ProjNode(call, TypeFunc::Memory);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   193
  transform_later(newmem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   194
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   195
  uint alias_idx = C->get_alias_index(adr_type);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   196
  if (alias_idx != Compile::AliasIdxBot) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   197
    *mem = MergeMemNode::make(*mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   198
    (*mem)->set_memory_at(alias_idx, newmem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   199
  } else {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   200
    *mem = MergeMemNode::make(newmem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   201
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   202
  transform_later(*mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   203
}
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   204
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   205
address PhaseMacroExpand::basictype2arraycopy(BasicType t,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   206
                                              Node* src_offset,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   207
                                              Node* dest_offset,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   208
                                              bool disjoint_bases,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   209
                                              const char* &name,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   210
                                              bool dest_uninitialized) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   211
  const TypeInt* src_offset_inttype  = _igvn.find_int_type(src_offset);;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   212
  const TypeInt* dest_offset_inttype = _igvn.find_int_type(dest_offset);;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   213
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   214
  bool aligned = false;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   215
  bool disjoint = disjoint_bases;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   216
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   217
  // if the offsets are the same, we can treat the memory regions as
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   218
  // disjoint, because either the memory regions are in different arrays,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   219
  // or they are identical (which we can treat as disjoint.)  We can also
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   220
  // treat a copy with a destination index  less that the source index
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   221
  // as disjoint since a low->high copy will work correctly in this case.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   222
  if (src_offset_inttype != NULL && src_offset_inttype->is_con() &&
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   223
      dest_offset_inttype != NULL && dest_offset_inttype->is_con()) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   224
    // both indices are constants
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   225
    int s_offs = src_offset_inttype->get_con();
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   226
    int d_offs = dest_offset_inttype->get_con();
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   227
    int element_size = type2aelembytes(t);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   228
    aligned = ((arrayOopDesc::base_offset_in_bytes(t) + s_offs * element_size) % HeapWordSize == 0) &&
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   229
              ((arrayOopDesc::base_offset_in_bytes(t) + d_offs * element_size) % HeapWordSize == 0);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   230
    if (s_offs >= d_offs)  disjoint = true;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   231
  } else if (src_offset == dest_offset && src_offset != NULL) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   232
    // This can occur if the offsets are identical non-constants.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   233
    disjoint = true;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   234
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   235
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   236
  return StubRoutines::select_arraycopy_function(t, aligned, disjoint, name, dest_uninitialized);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   237
}
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   238
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   239
#define XTOP LP64_ONLY(COMMA top())
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   240
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   241
// Generate an optimized call to arraycopy.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   242
// Caller must guard against non-arrays.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   243
// Caller must determine a common array basic-type for both arrays.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   244
// Caller must validate offsets against array bounds.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   245
// The slow_region has already collected guard failure paths
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   246
// (such as out of bounds length or non-conformable array types).
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   247
// The generated code has this shape, in general:
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   248
//
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   249
//     if (length == 0)  return   // via zero_path
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   250
//     slowval = -1
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   251
//     if (types unknown) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   252
//       slowval = call generic copy loop
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   253
//       if (slowval == 0)  return  // via checked_path
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   254
//     } else if (indexes in bounds) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   255
//       if ((is object array) && !(array type check)) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   256
//         slowval = call checked copy loop
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   257
//         if (slowval == 0)  return  // via checked_path
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   258
//       } else {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   259
//         call bulk copy loop
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   260
//         return  // via fast_path
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   261
//       }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   262
//     }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   263
//     // adjust params for remaining work:
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   264
//     if (slowval != -1) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   265
//       n = -1^slowval; src_offset += n; dest_offset += n; length -= n
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   266
//     }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   267
//   slow_region:
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   268
//     call slow arraycopy(src, src_offset, dest, dest_offset, length)
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   269
//     return  // via slow_call_path
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   270
//
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   271
// This routine is used from several intrinsics:  System.arraycopy,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   272
// Object.clone (the array subcase), and Arrays.copyOf[Range].
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   273
//
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   274
Node* PhaseMacroExpand::generate_arraycopy(ArrayCopyNode *ac, AllocateArrayNode* alloc,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   275
                                           Node** ctrl, MergeMemNode* mem, Node** io,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   276
                                           const TypePtr* adr_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   277
                                           BasicType basic_elem_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   278
                                           Node* src,  Node* src_offset,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   279
                                           Node* dest, Node* dest_offset,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   280
                                           Node* copy_length,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   281
                                           bool disjoint_bases,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   282
                                           bool length_never_negative,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   283
                                           RegionNode* slow_region) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   284
  if (slow_region == NULL) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   285
    slow_region = new RegionNode(1);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   286
    transform_later(slow_region);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   287
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   288
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   289
  Node* original_dest      = dest;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   290
  bool  dest_uninitialized = false;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   291
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   292
  // See if this is the initialization of a newly-allocated array.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   293
  // If so, we will take responsibility here for initializing it to zero.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   294
  // (Note:  Because tightly_coupled_allocation performs checks on the
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   295
  // out-edges of the dest, we need to avoid making derived pointers
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   296
  // from it until we have checked its uses.)
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   297
  if (ReduceBulkZeroing
35548
8d3afe96ffea 8086053: Address inconsistencies regarding ZeroTLAB
zmajo
parents: 30629
diff changeset
   298
      && !(UseTLAB && ZeroTLAB) // pointless if already zeroed
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   299
      && basic_elem_type != T_CONFLICT // avoid corner case
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   300
      && !src->eqv_uncast(dest)
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   301
      && alloc != NULL
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   302
      && _igvn.find_int_con(alloc->in(AllocateNode::ALength), 1) > 0
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   303
      && alloc->maybe_set_complete(&_igvn)) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   304
    // "You break it, you buy it."
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   305
    InitializeNode* init = alloc->initialization();
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   306
    assert(init->is_complete(), "we just did this");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   307
    init->set_complete_with_arraycopy();
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   308
    assert(dest->is_CheckCastPP(), "sanity");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   309
    assert(dest->in(0)->in(0) == init, "dest pinned");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   310
    adr_type = TypeRawPtr::BOTTOM;  // all initializations are into raw memory
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   311
    // From this point on, every exit path is responsible for
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   312
    // initializing any non-copied parts of the object to zero.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   313
    // Also, if this flag is set we make sure that arraycopy interacts properly
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   314
    // with G1, eliding pre-barriers. See CR 6627983.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   315
    dest_uninitialized = true;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   316
  } else {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   317
    // No zeroing elimination here.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   318
    alloc             = NULL;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   319
    //original_dest   = dest;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   320
    //dest_uninitialized = false;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   321
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   322
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   323
  uint alias_idx = C->get_alias_index(adr_type);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   324
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   325
  // Results are placed here:
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   326
  enum { fast_path        = 1,  // normal void-returning assembly stub
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   327
         checked_path     = 2,  // special assembly stub with cleanup
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   328
         slow_call_path   = 3,  // something went wrong; call the VM
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   329
         zero_path        = 4,  // bypass when length of copy is zero
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   330
         bcopy_path       = 5,  // copy primitive array by 64-bit blocks
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   331
         PATH_LIMIT       = 6
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   332
  };
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   333
  RegionNode* result_region = new RegionNode(PATH_LIMIT);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   334
  PhiNode*    result_i_o    = new PhiNode(result_region, Type::ABIO);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   335
  PhiNode*    result_memory = new PhiNode(result_region, Type::MEMORY, adr_type);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   336
  assert(adr_type != TypePtr::BOTTOM, "must be RawMem or a T[] slice");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   337
  transform_later(result_region);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   338
  transform_later(result_i_o);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   339
  transform_later(result_memory);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   340
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   341
  // The slow_control path:
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   342
  Node* slow_control;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   343
  Node* slow_i_o = *io;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   344
  Node* slow_mem = mem->memory_at(alias_idx);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   345
  DEBUG_ONLY(slow_control = (Node*) badAddress);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   346
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   347
  // Checked control path:
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   348
  Node* checked_control = top();
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   349
  Node* checked_mem     = NULL;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   350
  Node* checked_i_o     = NULL;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   351
  Node* checked_value   = NULL;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   352
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   353
  if (basic_elem_type == T_CONFLICT) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   354
    assert(!dest_uninitialized, "");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   355
    Node* cv = generate_generic_arraycopy(ctrl, &mem,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   356
                                          adr_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   357
                                          src, src_offset, dest, dest_offset,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   358
                                          copy_length, dest_uninitialized);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   359
    if (cv == NULL)  cv = intcon(-1);  // failure (no stub available)
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   360
    checked_control = *ctrl;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   361
    checked_i_o     = *io;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   362
    checked_mem     = mem->memory_at(alias_idx);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   363
    checked_value   = cv;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   364
    *ctrl = top();
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   365
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   366
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   367
  Node* not_pos = generate_nonpositive_guard(ctrl, copy_length, length_never_negative);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   368
  if (not_pos != NULL) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   369
    Node* local_ctrl = not_pos, *local_io = *io;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   370
    MergeMemNode* local_mem = MergeMemNode::make(mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   371
    transform_later(local_mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   372
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   373
    // (6) length must not be negative.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   374
    if (!length_never_negative) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   375
      generate_negative_guard(&local_ctrl, copy_length, slow_region);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   376
    }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   377
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   378
    // copy_length is 0.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   379
    if (dest_uninitialized) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   380
      assert(!local_ctrl->is_top(), "no ctrl?");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   381
      Node* dest_length = alloc->in(AllocateNode::ALength);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   382
      if (copy_length->eqv_uncast(dest_length)
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   383
          || _igvn.find_int_con(dest_length, 1) <= 0) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   384
        // There is no zeroing to do. No need for a secondary raw memory barrier.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   385
      } else {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   386
        // Clear the whole thing since there are no source elements to copy.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   387
        generate_clear_array(local_ctrl, local_mem,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   388
                             adr_type, dest, basic_elem_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   389
                             intcon(0), NULL,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   390
                             alloc->in(AllocateNode::AllocSize));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   391
        // Use a secondary InitializeNode as raw memory barrier.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   392
        // Currently it is needed only on this path since other
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   393
        // paths have stub or runtime calls as raw memory barriers.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   394
        MemBarNode* mb = MemBarNode::make(C, Op_Initialize,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   395
                                          Compile::AliasIdxRaw,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   396
                                          top());
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   397
        transform_later(mb);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   398
        mb->set_req(TypeFunc::Control,local_ctrl);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   399
        mb->set_req(TypeFunc::Memory, local_mem->memory_at(Compile::AliasIdxRaw));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   400
        local_ctrl = transform_later(new ProjNode(mb, TypeFunc::Control));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   401
        local_mem->set_memory_at(Compile::AliasIdxRaw, transform_later(new ProjNode(mb, TypeFunc::Memory)));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   402
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   403
        InitializeNode* init = mb->as_Initialize();
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   404
        init->set_complete(&_igvn);  // (there is no corresponding AllocateNode)
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   405
      }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   406
    }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   407
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   408
    // Present the results of the fast call.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   409
    result_region->init_req(zero_path, local_ctrl);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   410
    result_i_o   ->init_req(zero_path, local_io);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   411
    result_memory->init_req(zero_path, local_mem->memory_at(alias_idx));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   412
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   413
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   414
  if (!(*ctrl)->is_top() && dest_uninitialized) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   415
    // We have to initialize the *uncopied* part of the array to zero.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   416
    // The copy destination is the slice dest[off..off+len].  The other slices
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   417
    // are dest_head = dest[0..off] and dest_tail = dest[off+len..dest.length].
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   418
    Node* dest_size   = alloc->in(AllocateNode::AllocSize);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   419
    Node* dest_length = alloc->in(AllocateNode::ALength);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   420
    Node* dest_tail   = transform_later( new AddINode(dest_offset, copy_length));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   421
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   422
    // If there is a head section that needs zeroing, do it now.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   423
    if (_igvn.find_int_con(dest_offset, -1) != 0) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   424
      generate_clear_array(*ctrl, mem,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   425
                           adr_type, dest, basic_elem_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   426
                           intcon(0), dest_offset,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   427
                           NULL);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   428
    }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   429
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   430
    // Next, perform a dynamic check on the tail length.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   431
    // It is often zero, and we can win big if we prove this.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   432
    // There are two wins:  Avoid generating the ClearArray
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   433
    // with its attendant messy index arithmetic, and upgrade
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   434
    // the copy to a more hardware-friendly word size of 64 bits.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   435
    Node* tail_ctl = NULL;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   436
    if (!(*ctrl)->is_top() && !dest_tail->eqv_uncast(dest_length)) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   437
      Node* cmp_lt   = transform_later( new CmpINode(dest_tail, dest_length) );
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   438
      Node* bol_lt   = transform_later( new BoolNode(cmp_lt, BoolTest::lt) );
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   439
      tail_ctl = generate_slow_guard(ctrl, bol_lt, NULL);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   440
      assert(tail_ctl != NULL || !(*ctrl)->is_top(), "must be an outcome");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   441
    }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   442
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   443
    // At this point, let's assume there is no tail.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   444
    if (!(*ctrl)->is_top() && alloc != NULL && basic_elem_type != T_OBJECT) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   445
      // There is no tail.  Try an upgrade to a 64-bit copy.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   446
      bool didit = false;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   447
      {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   448
        Node* local_ctrl = *ctrl, *local_io = *io;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   449
        MergeMemNode* local_mem = MergeMemNode::make(mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   450
        transform_later(local_mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   451
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   452
        didit = generate_block_arraycopy(&local_ctrl, &local_mem, local_io,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   453
                                         adr_type, basic_elem_type, alloc,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   454
                                         src, src_offset, dest, dest_offset,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   455
                                         dest_size, dest_uninitialized);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   456
        if (didit) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   457
          // Present the results of the block-copying fast call.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   458
          result_region->init_req(bcopy_path, local_ctrl);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   459
          result_i_o   ->init_req(bcopy_path, local_io);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   460
          result_memory->init_req(bcopy_path, local_mem->memory_at(alias_idx));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   461
        }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   462
      }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   463
      if (didit) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   464
        *ctrl = top();     // no regular fast path
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   465
      }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   466
    }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   467
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   468
    // Clear the tail, if any.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   469
    if (tail_ctl != NULL) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   470
      Node* notail_ctl = (*ctrl)->is_top() ? NULL : *ctrl;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   471
      *ctrl = tail_ctl;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   472
      if (notail_ctl == NULL) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   473
        generate_clear_array(*ctrl, mem,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   474
                             adr_type, dest, basic_elem_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   475
                             dest_tail, NULL,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   476
                             dest_size);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   477
      } else {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   478
        // Make a local merge.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   479
        Node* done_ctl = transform_later(new RegionNode(3));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   480
        Node* done_mem = transform_later(new PhiNode(done_ctl, Type::MEMORY, adr_type));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   481
        done_ctl->init_req(1, notail_ctl);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   482
        done_mem->init_req(1, mem->memory_at(alias_idx));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   483
        generate_clear_array(*ctrl, mem,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   484
                             adr_type, dest, basic_elem_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   485
                             dest_tail, NULL,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   486
                             dest_size);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   487
        done_ctl->init_req(2, *ctrl);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   488
        done_mem->init_req(2, mem->memory_at(alias_idx));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   489
        *ctrl = done_ctl;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   490
        mem->set_memory_at(alias_idx, done_mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   491
      }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   492
    }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   493
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   494
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   495
  BasicType copy_type = basic_elem_type;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   496
  assert(basic_elem_type != T_ARRAY, "caller must fix this");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   497
  if (!(*ctrl)->is_top() && copy_type == T_OBJECT) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   498
    // If src and dest have compatible element types, we can copy bits.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   499
    // Types S[] and D[] are compatible if D is a supertype of S.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   500
    //
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   501
    // If they are not, we will use checked_oop_disjoint_arraycopy,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   502
    // which performs a fast optimistic per-oop check, and backs off
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   503
    // further to JVM_ArrayCopy on the first per-oop check that fails.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   504
    // (Actually, we don't move raw bits only; the GC requires card marks.)
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   505
38675
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   506
    // We don't need a subtype check for validated copies and Object[].clone()
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   507
    bool skip_subtype_check = ac->is_arraycopy_validated() || ac->is_copyof_validated() ||
58931
304c63b17b07 8232896: ZGC: Enable C2 clone intrinsic
neliasso
parents: 58273
diff changeset
   508
                              ac->is_copyofrange_validated() || ac->is_clone_oop_array();
38675
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   509
    if (!skip_subtype_check) {
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   510
      // Get the klass* for both src and dest
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   511
      Node* src_klass  = ac->in(ArrayCopyNode::SrcKlass);
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   512
      Node* dest_klass = ac->in(ArrayCopyNode::DestKlass);
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   513
38675
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   514
      assert(src_klass != NULL && dest_klass != NULL, "should have klasses");
26435
b446202ac824 8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents: 26180
diff changeset
   515
38675
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   516
      // Generate the subtype check.
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   517
      // This might fold up statically, or then again it might not.
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   518
      //
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   519
      // Non-static example:  Copying List<String>.elements to a new String[].
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   520
      // The backing store for a List<String> is always an Object[],
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   521
      // but its elements are always type String, if the generic types
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   522
      // are correct at the source level.
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   523
      //
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   524
      // Test S[] against D[], not S against D, because (probably)
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   525
      // the secondary supertype cache is less busy for S[] than S.
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   526
      // This usually only matters when D is an interface.
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   527
      Node* not_subtype_ctrl = Phase::gen_subtype_check(src_klass, dest_klass, ctrl, mem, &_igvn);
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   528
      // Plug failing path into checked_oop_disjoint_arraycopy
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   529
      if (not_subtype_ctrl != top()) {
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   530
        Node* local_ctrl = not_subtype_ctrl;
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   531
        MergeMemNode* local_mem = MergeMemNode::make(mem);
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   532
        transform_later(local_mem);
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   533
38675
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   534
        // (At this point we can assume disjoint_bases, since types differ.)
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   535
        int ek_offset = in_bytes(ObjArrayKlass::element_klass_offset());
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   536
        Node* p1 = basic_plus_adr(dest_klass, ek_offset);
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   537
        Node* n1 = LoadKlassNode::make(_igvn, NULL, C->immutable_memory(), p1, TypeRawPtr::BOTTOM);
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   538
        Node* dest_elem_klass = transform_later(n1);
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   539
        Node* cv = generate_checkcast_arraycopy(&local_ctrl, &local_mem,
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   540
                                                adr_type,
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   541
                                                dest_elem_klass,
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   542
                                                src, src_offset, dest, dest_offset,
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   543
                                                ConvI2X(copy_length), dest_uninitialized);
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   544
        if (cv == NULL)  cv = intcon(-1);  // failure (no stub available)
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   545
        checked_control = local_ctrl;
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   546
        checked_i_o     = *io;
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   547
        checked_mem     = local_mem->memory_at(alias_idx);
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   548
        checked_value   = cv;
066fcb1eb80a 8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks
thartmann
parents: 36342
diff changeset
   549
      }
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   550
    }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   551
    // At this point we know we do not need type checks on oop stores.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   552
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents: 47216
diff changeset
   553
    BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
51984
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 50399
diff changeset
   554
    if (!bs->array_copy_requires_gc_barriers(alloc != NULL, copy_type, false, BarrierSetC2::Expansion)) {
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents: 47216
diff changeset
   555
      // If we do not need gc barriers, copy using the jint or jlong stub.
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   556
      copy_type = LP64_ONLY(UseCompressedOops ? T_INT : T_LONG) NOT_LP64(T_INT);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   557
      assert(type2aelembytes(basic_elem_type) == type2aelembytes(copy_type),
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   558
             "sizes agree");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   559
    }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   560
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   561
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   562
  if (!(*ctrl)->is_top()) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   563
    // Generate the fast path, if possible.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   564
    Node* local_ctrl = *ctrl;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   565
    MergeMemNode* local_mem = MergeMemNode::make(mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   566
    transform_later(local_mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   567
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   568
    generate_unchecked_arraycopy(&local_ctrl, &local_mem,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   569
                                 adr_type, copy_type, disjoint_bases,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   570
                                 src, src_offset, dest, dest_offset,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   571
                                 ConvI2X(copy_length), dest_uninitialized);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   572
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   573
    // Present the results of the fast call.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   574
    result_region->init_req(fast_path, local_ctrl);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   575
    result_i_o   ->init_req(fast_path, *io);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   576
    result_memory->init_req(fast_path, local_mem->memory_at(alias_idx));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   577
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   578
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   579
  // Here are all the slow paths up to this point, in one bundle:
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   580
  assert(slow_region != NULL, "allocated on entry");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   581
  slow_control = slow_region;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   582
  DEBUG_ONLY(slow_region = (RegionNode*)badAddress);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   583
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   584
  *ctrl = checked_control;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   585
  if (!(*ctrl)->is_top()) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   586
    // Clean up after the checked call.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   587
    // The returned value is either 0 or -1^K,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   588
    // where K = number of partially transferred array elements.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   589
    Node* cmp = new CmpINode(checked_value, intcon(0));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   590
    transform_later(cmp);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   591
    Node* bol = new BoolNode(cmp, BoolTest::eq);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   592
    transform_later(bol);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   593
    IfNode* iff = new IfNode(*ctrl, bol, PROB_MAX, COUNT_UNKNOWN);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   594
    transform_later(iff);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   595
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   596
    // If it is 0, we are done, so transfer to the end.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   597
    Node* checks_done = new IfTrueNode(iff);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   598
    transform_later(checks_done);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   599
    result_region->init_req(checked_path, checks_done);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   600
    result_i_o   ->init_req(checked_path, checked_i_o);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   601
    result_memory->init_req(checked_path, checked_mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   602
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   603
    // If it is not zero, merge into the slow call.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   604
    *ctrl = new IfFalseNode(iff);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   605
    transform_later(*ctrl);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   606
    RegionNode* slow_reg2 = new RegionNode(3);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   607
    PhiNode*    slow_i_o2 = new PhiNode(slow_reg2, Type::ABIO);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   608
    PhiNode*    slow_mem2 = new PhiNode(slow_reg2, Type::MEMORY, adr_type);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   609
    transform_later(slow_reg2);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   610
    transform_later(slow_i_o2);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   611
    transform_later(slow_mem2);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   612
    slow_reg2  ->init_req(1, slow_control);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   613
    slow_i_o2  ->init_req(1, slow_i_o);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   614
    slow_mem2  ->init_req(1, slow_mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   615
    slow_reg2  ->init_req(2, *ctrl);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   616
    slow_i_o2  ->init_req(2, checked_i_o);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   617
    slow_mem2  ->init_req(2, checked_mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   618
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   619
    slow_control = slow_reg2;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   620
    slow_i_o     = slow_i_o2;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   621
    slow_mem     = slow_mem2;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   622
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   623
    if (alloc != NULL) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   624
      // We'll restart from the very beginning, after zeroing the whole thing.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   625
      // This can cause double writes, but that's OK since dest is brand new.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   626
      // So we ignore the low 31 bits of the value returned from the stub.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   627
    } else {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   628
      // We must continue the copy exactly where it failed, or else
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   629
      // another thread might see the wrong number of writes to dest.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   630
      Node* checked_offset = new XorINode(checked_value, intcon(-1));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   631
      Node* slow_offset    = new PhiNode(slow_reg2, TypeInt::INT);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   632
      transform_later(checked_offset);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   633
      transform_later(slow_offset);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   634
      slow_offset->init_req(1, intcon(0));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   635
      slow_offset->init_req(2, checked_offset);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   636
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   637
      // Adjust the arguments by the conditionally incoming offset.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   638
      Node* src_off_plus  = new AddINode(src_offset,  slow_offset);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   639
      transform_later(src_off_plus);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   640
      Node* dest_off_plus = new AddINode(dest_offset, slow_offset);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   641
      transform_later(dest_off_plus);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   642
      Node* length_minus  = new SubINode(copy_length, slow_offset);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   643
      transform_later(length_minus);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   644
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   645
      // Tweak the node variables to adjust the code produced below:
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   646
      src_offset  = src_off_plus;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   647
      dest_offset = dest_off_plus;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   648
      copy_length = length_minus;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   649
    }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   650
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   651
  *ctrl = slow_control;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   652
  if (!(*ctrl)->is_top()) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   653
    Node* local_ctrl = *ctrl, *local_io = slow_i_o;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   654
    MergeMemNode* local_mem = MergeMemNode::make(mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   655
    transform_later(local_mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   656
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   657
    // Generate the slow path, if needed.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   658
    local_mem->set_memory_at(alias_idx, slow_mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   659
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   660
    if (dest_uninitialized) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   661
      generate_clear_array(local_ctrl, local_mem,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   662
                           adr_type, dest, basic_elem_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   663
                           intcon(0), NULL,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   664
                           alloc->in(AllocateNode::AllocSize));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   665
    }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   666
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   667
    local_mem = generate_slow_arraycopy(ac,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   668
                                        &local_ctrl, local_mem, &local_io,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   669
                                        adr_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   670
                                        src, src_offset, dest, dest_offset,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   671
                                        copy_length, /*dest_uninitialized*/false);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   672
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   673
    result_region->init_req(slow_call_path, local_ctrl);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   674
    result_i_o   ->init_req(slow_call_path, local_io);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   675
    result_memory->init_req(slow_call_path, local_mem->memory_at(alias_idx));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   676
  } else {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   677
    ShouldNotReachHere(); // no call to generate_slow_arraycopy:
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   678
                          // projections were not extracted
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   679
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   680
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   681
  // Remove unused edges.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   682
  for (uint i = 1; i < result_region->req(); i++) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   683
    if (result_region->in(i) == NULL) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   684
      result_region->init_req(i, top());
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   685
    }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   686
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   687
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   688
  // Finished; return the combined state.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   689
  *ctrl = result_region;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   690
  *io = result_i_o;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   691
  mem->set_memory_at(alias_idx, result_memory);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   692
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   693
  // mem no longer guaranteed to stay a MergeMemNode
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   694
  Node* out_mem = mem;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   695
  DEBUG_ONLY(mem = NULL);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   696
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   697
  // The memory edges above are precise in order to model effects around
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   698
  // array copies accurately to allow value numbering of field loads around
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   699
  // arraycopy.  Such field loads, both before and after, are common in Java
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   700
  // collections and similar classes involving header/array data structures.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   701
  //
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   702
  // But with low number of register or when some registers are used or killed
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   703
  // by arraycopy calls it causes registers spilling on stack. See 6544710.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   704
  // The next memory barrier is added to avoid it. If the arraycopy can be
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   705
  // optimized away (which it can, sometimes) then we can manually remove
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   706
  // the membar also.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   707
  //
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   708
  // Do not let reads from the cloned object float above the arraycopy.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   709
  if (alloc != NULL && !alloc->initialization()->does_not_escape()) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   710
    // Do not let stores that initialize this object be reordered with
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   711
    // a subsequent store that would make this object accessible by
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   712
    // other threads.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   713
    insert_mem_bar(ctrl, &out_mem, Op_MemBarStoreStore);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   714
  } else if (InsertMemBarAfterArraycopy) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   715
    insert_mem_bar(ctrl, &out_mem, Op_MemBarCPUOrder);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   716
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   717
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   718
  _igvn.replace_node(_memproj_fallthrough, out_mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   719
  _igvn.replace_node(_ioproj_fallthrough, *io);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   720
  _igvn.replace_node(_fallthroughcatchproj, *ctrl);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   721
45427
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
   722
#ifdef ASSERT
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
   723
  const TypeOopPtr* dest_t = _igvn.type(dest)->is_oopptr();
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
   724
  if (dest_t->is_known_instance()) {
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
   725
    ArrayCopyNode* ac = NULL;
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
   726
    assert(ArrayCopyNode::may_modify(dest_t, (*ctrl)->in(0)->as_MemBar(), &_igvn, ac), "dependency on arraycopy lost");
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
   727
    assert(ac == NULL, "no arraycopy anymore");
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
   728
  }
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
   729
#endif
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
   730
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   731
  return out_mem;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   732
}
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   733
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   734
// Helper for initialization of arrays, creating a ClearArray.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   735
// It writes zero bits in [start..end), within the body of an array object.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   736
// The memory effects are all chained onto the 'adr_type' alias category.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   737
//
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   738
// Since the object is otherwise uninitialized, we are free
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   739
// to put a little "slop" around the edges of the cleared area,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   740
// as long as it does not go back into the array's header,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   741
// or beyond the array end within the heap.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   742
//
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   743
// The lower edge can be rounded down to the nearest jint and the
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   744
// upper edge can be rounded up to the nearest MinObjAlignmentInBytes.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   745
//
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   746
// Arguments:
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   747
//   adr_type           memory slice where writes are generated
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   748
//   dest               oop of the destination array
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   749
//   basic_elem_type    element type of the destination
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   750
//   slice_idx          array index of first element to store
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   751
//   slice_len          number of elements to store (or NULL)
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   752
//   dest_size          total size in bytes of the array object
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   753
//
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   754
// Exactly one of slice_len or dest_size must be non-NULL.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   755
// If dest_size is non-NULL, zeroing extends to the end of the object.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   756
// If slice_len is non-NULL, the slice_idx value must be a constant.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   757
void PhaseMacroExpand::generate_clear_array(Node* ctrl, MergeMemNode* merge_mem,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   758
                                            const TypePtr* adr_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   759
                                            Node* dest,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   760
                                            BasicType basic_elem_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   761
                                            Node* slice_idx,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   762
                                            Node* slice_len,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   763
                                            Node* dest_size) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   764
  // one or the other but not both of slice_len and dest_size:
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   765
  assert((slice_len != NULL? 1: 0) + (dest_size != NULL? 1: 0) == 1, "");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   766
  if (slice_len == NULL)  slice_len = top();
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   767
  if (dest_size == NULL)  dest_size = top();
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   768
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   769
  uint alias_idx = C->get_alias_index(adr_type);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   770
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   771
  // operate on this memory slice:
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   772
  Node* mem = merge_mem->memory_at(alias_idx); // memory slice to operate on
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   773
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   774
  // scaling and rounding of indexes:
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   775
  int scale = exact_log2(type2aelembytes(basic_elem_type));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   776
  int abase = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   777
  int clear_low = (-1 << scale) & (BytesPerInt  - 1);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   778
  int bump_bit  = (-1 << scale) & BytesPerInt;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   779
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   780
  // determine constant starts and ends
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   781
  const intptr_t BIG_NEG = -128;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   782
  assert(BIG_NEG + 2*abase < 0, "neg enough");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   783
  intptr_t slice_idx_con = (intptr_t) _igvn.find_int_con(slice_idx, BIG_NEG);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   784
  intptr_t slice_len_con = (intptr_t) _igvn.find_int_con(slice_len, BIG_NEG);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   785
  if (slice_len_con == 0) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   786
    return;                     // nothing to do here
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   787
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   788
  intptr_t start_con = (abase + (slice_idx_con << scale)) & ~clear_low;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   789
  intptr_t end_con   = _igvn.find_intptr_t_con(dest_size, -1);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   790
  if (slice_idx_con >= 0 && slice_len_con >= 0) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   791
    assert(end_con < 0, "not two cons");
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 45427
diff changeset
   792
    end_con = align_up(abase + ((slice_idx_con + slice_len_con) << scale),
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   793
                       BytesPerLong);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   794
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   795
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   796
  if (start_con >= 0 && end_con >= 0) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   797
    // Constant start and end.  Simple.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   798
    mem = ClearArrayNode::clear_memory(ctrl, mem, dest,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   799
                                       start_con, end_con, &_igvn);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   800
  } else if (start_con >= 0 && dest_size != top()) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   801
    // Constant start, pre-rounded end after the tail of the array.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   802
    Node* end = dest_size;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   803
    mem = ClearArrayNode::clear_memory(ctrl, mem, dest,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   804
                                       start_con, end, &_igvn);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   805
  } else if (start_con >= 0 && slice_len != top()) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   806
    // Constant start, non-constant end.  End needs rounding up.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   807
    // End offset = round_up(abase + ((slice_idx_con + slice_len) << scale), 8)
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   808
    intptr_t end_base  = abase + (slice_idx_con << scale);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   809
    int      end_round = (-1 << scale) & (BytesPerLong  - 1);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   810
    Node*    end       = ConvI2X(slice_len);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   811
    if (scale != 0)
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   812
      end = transform_later(new LShiftXNode(end, intcon(scale) ));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   813
    end_base += end_round;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   814
    end = transform_later(new AddXNode(end, MakeConX(end_base)) );
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   815
    end = transform_later(new AndXNode(end, MakeConX(~end_round)) );
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   816
    mem = ClearArrayNode::clear_memory(ctrl, mem, dest,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   817
                                       start_con, end, &_igvn);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   818
  } else if (start_con < 0 && dest_size != top()) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   819
    // Non-constant start, pre-rounded end after the tail of the array.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   820
    // This is almost certainly a "round-to-end" operation.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   821
    Node* start = slice_idx;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   822
    start = ConvI2X(start);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   823
    if (scale != 0)
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   824
      start = transform_later(new LShiftXNode( start, intcon(scale) ));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   825
    start = transform_later(new AddXNode(start, MakeConX(abase)) );
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   826
    if ((bump_bit | clear_low) != 0) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   827
      int to_clear = (bump_bit | clear_low);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   828
      // Align up mod 8, then store a jint zero unconditionally
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   829
      // just before the mod-8 boundary.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   830
      if (((abase + bump_bit) & ~to_clear) - bump_bit
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   831
          < arrayOopDesc::length_offset_in_bytes() + BytesPerInt) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   832
        bump_bit = 0;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   833
        assert((abase & to_clear) == 0, "array base must be long-aligned");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   834
      } else {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   835
        // Bump 'start' up to (or past) the next jint boundary:
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   836
        start = transform_later( new AddXNode(start, MakeConX(bump_bit)) );
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   837
        assert((abase & clear_low) == 0, "array base must be int-aligned");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   838
      }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   839
      // Round bumped 'start' down to jlong boundary in body of array.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   840
      start = transform_later(new AndXNode(start, MakeConX(~to_clear)) );
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   841
      if (bump_bit != 0) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   842
        // Store a zero to the immediately preceding jint:
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   843
        Node* x1 = transform_later(new AddXNode(start, MakeConX(-bump_bit)) );
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   844
        Node* p1 = basic_plus_adr(dest, x1);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   845
        mem = StoreNode::make(_igvn, ctrl, mem, p1, adr_type, intcon(0), T_INT, MemNode::unordered);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   846
        mem = transform_later(mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   847
      }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   848
    }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   849
    Node* end = dest_size; // pre-rounded
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   850
    mem = ClearArrayNode::clear_memory(ctrl, mem, dest,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   851
                                       start, end, &_igvn);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   852
  } else {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   853
    // Non-constant start, unrounded non-constant end.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   854
    // (Nobody zeroes a random midsection of an array using this routine.)
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   855
    ShouldNotReachHere();       // fix caller
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   856
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   857
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   858
  // Done.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   859
  merge_mem->set_memory_at(alias_idx, mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   860
}
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   861
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   862
bool PhaseMacroExpand::generate_block_arraycopy(Node** ctrl, MergeMemNode** mem, Node* io,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   863
                                                const TypePtr* adr_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   864
                                                BasicType basic_elem_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   865
                                                AllocateNode* alloc,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   866
                                                Node* src,  Node* src_offset,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   867
                                                Node* dest, Node* dest_offset,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   868
                                                Node* dest_size, bool dest_uninitialized) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   869
  // See if there is an advantage from block transfer.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   870
  int scale = exact_log2(type2aelembytes(basic_elem_type));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   871
  if (scale >= LogBytesPerLong)
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   872
    return false;               // it is already a block transfer
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   873
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   874
  // Look at the alignment of the starting offsets.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   875
  int abase = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   876
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   877
  intptr_t src_off_con  = (intptr_t) _igvn.find_int_con(src_offset, -1);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   878
  intptr_t dest_off_con = (intptr_t) _igvn.find_int_con(dest_offset, -1);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   879
  if (src_off_con < 0 || dest_off_con < 0) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   880
    // At present, we can only understand constants.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   881
    return false;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   882
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   883
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   884
  intptr_t src_off  = abase + (src_off_con  << scale);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   885
  intptr_t dest_off = abase + (dest_off_con << scale);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   886
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   887
  if (((src_off | dest_off) & (BytesPerLong-1)) != 0) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   888
    // Non-aligned; too bad.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   889
    // One more chance:  Pick off an initial 32-bit word.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   890
    // This is a common case, since abase can be odd mod 8.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   891
    if (((src_off | dest_off) & (BytesPerLong-1)) == BytesPerInt &&
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   892
        ((src_off ^ dest_off) & (BytesPerLong-1)) == 0) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   893
      Node* sptr = basic_plus_adr(src,  src_off);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   894
      Node* dptr = basic_plus_adr(dest, dest_off);
46754
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents: 46625
diff changeset
   895
      const TypePtr* s_adr_type = _igvn.type(sptr)->is_ptr();
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents: 46625
diff changeset
   896
      assert(s_adr_type->isa_aryptr(), "impossible slice");
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents: 46625
diff changeset
   897
      uint s_alias_idx = C->get_alias_index(s_adr_type);
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents: 46625
diff changeset
   898
      uint d_alias_idx = C->get_alias_index(adr_type);
36342
7e8c466d9ffe 8150933: System::arraycopy intrinsic doesn't mark mismatched loads
vlivanov
parents: 35548
diff changeset
   899
      bool is_mismatched = (basic_elem_type != T_INT);
7e8c466d9ffe 8150933: System::arraycopy intrinsic doesn't mark mismatched loads
vlivanov
parents: 35548
diff changeset
   900
      Node* sval = transform_later(
46754
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents: 46625
diff changeset
   901
          LoadNode::make(_igvn, *ctrl, (*mem)->memory_at(s_alias_idx), sptr, s_adr_type,
36342
7e8c466d9ffe 8150933: System::arraycopy intrinsic doesn't mark mismatched loads
vlivanov
parents: 35548
diff changeset
   902
                         TypeInt::INT, T_INT, MemNode::unordered, LoadNode::DependsOnlyOnTest,
7e8c466d9ffe 8150933: System::arraycopy intrinsic doesn't mark mismatched loads
vlivanov
parents: 35548
diff changeset
   903
                         false /*unaligned*/, is_mismatched));
7e8c466d9ffe 8150933: System::arraycopy intrinsic doesn't mark mismatched loads
vlivanov
parents: 35548
diff changeset
   904
      Node* st = transform_later(
46754
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents: 46625
diff changeset
   905
          StoreNode::make(_igvn, *ctrl, (*mem)->memory_at(d_alias_idx), dptr, adr_type,
36342
7e8c466d9ffe 8150933: System::arraycopy intrinsic doesn't mark mismatched loads
vlivanov
parents: 35548
diff changeset
   906
                          sval, T_INT, MemNode::unordered));
46754
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents: 46625
diff changeset
   907
      if (is_mismatched) {
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents: 46625
diff changeset
   908
        st->as_Store()->set_mismatched_access();
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents: 46625
diff changeset
   909
      }
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents: 46625
diff changeset
   910
      (*mem)->set_memory_at(d_alias_idx, st);
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   911
      src_off += BytesPerInt;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   912
      dest_off += BytesPerInt;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   913
    } else {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   914
      return false;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   915
    }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   916
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   917
  assert(src_off % BytesPerLong == 0, "");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   918
  assert(dest_off % BytesPerLong == 0, "");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   919
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   920
  // Do this copy by giant steps.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   921
  Node* sptr  = basic_plus_adr(src,  src_off);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   922
  Node* dptr  = basic_plus_adr(dest, dest_off);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   923
  Node* countx = dest_size;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   924
  countx = transform_later(new SubXNode(countx, MakeConX(dest_off)));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   925
  countx = transform_later(new URShiftXNode(countx, intcon(LogBytesPerLong)));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   926
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   927
  bool disjoint_bases = true;   // since alloc != NULL
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   928
  generate_unchecked_arraycopy(ctrl, mem,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   929
                               adr_type, T_LONG, disjoint_bases,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   930
                               sptr, NULL, dptr, NULL, countx, dest_uninitialized);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   931
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   932
  return true;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   933
}
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   934
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   935
// Helper function; generates code for the slow case.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   936
// We make a call to a runtime method which emulates the native method,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   937
// but without the native wrapper overhead.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   938
MergeMemNode* PhaseMacroExpand::generate_slow_arraycopy(ArrayCopyNode *ac,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   939
                                                        Node** ctrl, Node* mem, Node** io,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   940
                                                        const TypePtr* adr_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   941
                                                        Node* src,  Node* src_offset,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   942
                                                        Node* dest, Node* dest_offset,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   943
                                                        Node* copy_length, bool dest_uninitialized) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   944
  assert(!dest_uninitialized, "Invariant");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   945
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   946
  const TypeFunc* call_type = OptoRuntime::slow_arraycopy_Type();
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   947
  CallNode* call = new CallStaticJavaNode(call_type, OptoRuntime::slow_arraycopy_Java(),
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   948
                                          "slow_arraycopy",
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   949
                                          ac->jvms()->bci(), TypePtr::BOTTOM);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   950
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   951
  call->init_req(TypeFunc::Control, *ctrl);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   952
  call->init_req(TypeFunc::I_O    , *io);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   953
  call->init_req(TypeFunc::Memory , mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   954
  call->init_req(TypeFunc::ReturnAdr, top());
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   955
  call->init_req(TypeFunc::FramePtr, top());
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   956
  call->init_req(TypeFunc::Parms+0, src);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   957
  call->init_req(TypeFunc::Parms+1, src_offset);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   958
  call->init_req(TypeFunc::Parms+2, dest);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   959
  call->init_req(TypeFunc::Parms+3, dest_offset);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   960
  call->init_req(TypeFunc::Parms+4, copy_length);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   961
  copy_call_debug_info(ac, call);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   962
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   963
  call->set_cnt(PROB_UNLIKELY_MAG(4));  // Same effect as RC_UNCOMMON.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   964
  _igvn.replace_node(ac, call);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   965
  transform_later(call);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   966
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   967
  extract_call_projections(call);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   968
  *ctrl = _fallthroughcatchproj->clone();
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   969
  transform_later(*ctrl);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   970
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   971
  Node* m = _memproj_fallthrough->clone();
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   972
  transform_later(m);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   973
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   974
  uint alias_idx = C->get_alias_index(adr_type);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   975
  MergeMemNode* out_mem;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   976
  if (alias_idx != Compile::AliasIdxBot) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   977
    out_mem = MergeMemNode::make(mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   978
    out_mem->set_memory_at(alias_idx, m);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   979
  } else {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   980
    out_mem = MergeMemNode::make(m);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   981
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   982
  transform_later(out_mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   983
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   984
  *io = _ioproj_fallthrough->clone();
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   985
  transform_later(*io);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   986
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   987
  return out_mem;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   988
}
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   989
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   990
// Helper function; generates code for cases requiring runtime checks.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   991
Node* PhaseMacroExpand::generate_checkcast_arraycopy(Node** ctrl, MergeMemNode** mem,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   992
                                                     const TypePtr* adr_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   993
                                                     Node* dest_elem_klass,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   994
                                                     Node* src,  Node* src_offset,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   995
                                                     Node* dest, Node* dest_offset,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   996
                                                     Node* copy_length, bool dest_uninitialized) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   997
  if ((*ctrl)->is_top())  return NULL;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   998
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
   999
  address copyfunc_addr = StubRoutines::checkcast_arraycopy(dest_uninitialized);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1000
  if (copyfunc_addr == NULL) { // Stub was not generated, go slow path.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1001
    return NULL;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1002
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1003
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1004
  // Pick out the parameters required to perform a store-check
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1005
  // for the target array.  This is an optimistic check.  It will
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1006
  // look in each non-null element's class, at the desired klass's
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1007
  // super_check_offset, for the desired klass.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1008
  int sco_offset = in_bytes(Klass::super_check_offset_offset());
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1009
  Node* p3 = basic_plus_adr(dest_elem_klass, sco_offset);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1010
  Node* n3 = new LoadINode(NULL, *mem /*memory(p3)*/, p3, _igvn.type(p3)->is_ptr(), TypeInt::INT, MemNode::unordered);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1011
  Node* check_offset = ConvI2X(transform_later(n3));
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1012
  Node* check_value  = dest_elem_klass;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1013
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1014
  Node* src_start  = array_element_address(src,  src_offset,  T_OBJECT);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1015
  Node* dest_start = array_element_address(dest, dest_offset, T_OBJECT);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1016
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1017
  const TypeFunc* call_type = OptoRuntime::checkcast_arraycopy_Type();
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1018
  Node* call = make_leaf_call(*ctrl, *mem, call_type, copyfunc_addr, "checkcast_arraycopy", adr_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1019
                              src_start, dest_start, copy_length XTOP, check_offset XTOP, check_value);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1020
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1021
  finish_arraycopy_call(call, ctrl, mem, adr_type);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1022
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1023
  Node* proj =  new ProjNode(call, TypeFunc::Parms);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1024
  transform_later(proj);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1025
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1026
  return proj;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1027
}
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1028
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1029
// Helper function; generates code for cases requiring runtime checks.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1030
Node* PhaseMacroExpand::generate_generic_arraycopy(Node** ctrl, MergeMemNode** mem,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1031
                                                   const TypePtr* adr_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1032
                                                   Node* src,  Node* src_offset,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1033
                                                   Node* dest, Node* dest_offset,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1034
                                                   Node* copy_length, bool dest_uninitialized) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1035
  if ((*ctrl)->is_top()) return NULL;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1036
  assert(!dest_uninitialized, "Invariant");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1037
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1038
  address copyfunc_addr = StubRoutines::generic_arraycopy();
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1039
  if (copyfunc_addr == NULL) { // Stub was not generated, go slow path.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1040
    return NULL;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1041
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1042
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1043
  const TypeFunc* call_type = OptoRuntime::generic_arraycopy_Type();
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1044
  Node* call = make_leaf_call(*ctrl, *mem, call_type, copyfunc_addr, "generic_arraycopy", adr_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1045
                              src, src_offset, dest, dest_offset, copy_length);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1046
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1047
  finish_arraycopy_call(call, ctrl, mem, adr_type);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1048
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1049
  Node* proj =  new ProjNode(call, TypeFunc::Parms);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1050
  transform_later(proj);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1051
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1052
  return proj;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1053
}
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1054
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1055
// Helper function; generates the fast out-of-line call to an arraycopy stub.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1056
void PhaseMacroExpand::generate_unchecked_arraycopy(Node** ctrl, MergeMemNode** mem,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1057
                                                    const TypePtr* adr_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1058
                                                    BasicType basic_elem_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1059
                                                    bool disjoint_bases,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1060
                                                    Node* src,  Node* src_offset,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1061
                                                    Node* dest, Node* dest_offset,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1062
                                                    Node* copy_length, bool dest_uninitialized) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1063
  if ((*ctrl)->is_top()) return;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1064
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1065
  Node* src_start  = src;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1066
  Node* dest_start = dest;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1067
  if (src_offset != NULL || dest_offset != NULL) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1068
    src_start =  array_element_address(src, src_offset, basic_elem_type);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1069
    dest_start = array_element_address(dest, dest_offset, basic_elem_type);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1070
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1071
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1072
  // Figure out which arraycopy runtime method to call.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1073
  const char* copyfunc_name = "arraycopy";
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1074
  address     copyfunc_addr =
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1075
      basictype2arraycopy(basic_elem_type, src_offset, dest_offset,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1076
                          disjoint_bases, copyfunc_name, dest_uninitialized);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1077
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1078
  const TypeFunc* call_type = OptoRuntime::fast_arraycopy_Type();
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1079
  Node* call = make_leaf_call(*ctrl, *mem, call_type, copyfunc_addr, copyfunc_name, adr_type,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1080
                              src_start, dest_start, copy_length XTOP);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1081
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1082
  finish_arraycopy_call(call, ctrl, mem, adr_type);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1083
}
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1084
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1085
void PhaseMacroExpand::expand_arraycopy_node(ArrayCopyNode *ac) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1086
  Node* ctrl = ac->in(TypeFunc::Control);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1087
  Node* io = ac->in(TypeFunc::I_O);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1088
  Node* src = ac->in(ArrayCopyNode::Src);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1089
  Node* src_offset = ac->in(ArrayCopyNode::SrcPos);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1090
  Node* dest = ac->in(ArrayCopyNode::Dest);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1091
  Node* dest_offset = ac->in(ArrayCopyNode::DestPos);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1092
  Node* length = ac->in(ArrayCopyNode::Length);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1093
  MergeMemNode* merge_mem = NULL;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1094
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1095
  if (ac->is_clonebasic()) {
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
  1096
    BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
58217
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 52424
diff changeset
  1097
    bs->clone_at_expansion(this, ac);
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1098
    return;
58931
304c63b17b07 8232896: ZGC: Enable C2 clone intrinsic
neliasso
parents: 58273
diff changeset
  1099
  } else if (ac->is_copyof() || ac->is_copyofrange() || ac->is_clone_oop_array()) {
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1100
    Node* mem = ac->in(TypeFunc::Memory);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1101
    merge_mem = MergeMemNode::make(mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1102
    transform_later(merge_mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1103
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1104
    RegionNode* slow_region = new RegionNode(1);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1105
    transform_later(slow_region);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1106
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1107
    AllocateArrayNode* alloc = NULL;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1108
    if (ac->is_alloc_tightly_coupled()) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1109
      alloc = AllocateArrayNode::Ideal_array_allocation(dest, &_igvn);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1110
      assert(alloc != NULL, "expect alloc");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1111
    }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1112
30629
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29337
diff changeset
  1113
    const TypePtr* adr_type = _igvn.type(dest)->is_oopptr()->add_offset(Type::OffsetBot);
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29337
diff changeset
  1114
    if (ac->_dest_type != TypeOopPtr::BOTTOM) {
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29337
diff changeset
  1115
      adr_type = ac->_dest_type->add_offset(Type::OffsetBot)->is_ptr();
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29337
diff changeset
  1116
    }
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1117
    generate_arraycopy(ac, alloc, &ctrl, merge_mem, &io,
30629
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29337
diff changeset
  1118
                       adr_type, T_OBJECT,
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1119
                       src, src_offset, dest, dest_offset, length,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1120
                       true, !ac->is_copyofrange());
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1121
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1122
    return;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1123
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1124
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1125
  AllocateArrayNode* alloc = NULL;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1126
  if (ac->is_alloc_tightly_coupled()) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1127
    alloc = AllocateArrayNode::Ideal_array_allocation(dest, &_igvn);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1128
    assert(alloc != NULL, "expect alloc");
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1129
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1130
28396
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents: 27637
diff changeset
  1131
  assert(ac->is_arraycopy() || ac->is_arraycopy_validated(), "should be an arraycopy");
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1132
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1133
  // Compile time checks.  If any of these checks cannot be verified at compile time,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1134
  // we do not make a fast path for this call.  Instead, we let the call remain as it
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1135
  // is.  The checks we choose to mandate at compile time are:
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1136
  //
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1137
  // (1) src and dest are arrays.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1138
  const Type* src_type = src->Value(&_igvn);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1139
  const Type* dest_type = dest->Value(&_igvn);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1140
  const TypeAryPtr* top_src = src_type->isa_aryptr();
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1141
  const TypeAryPtr* top_dest = dest_type->isa_aryptr();
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1142
45427
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
  1143
  BasicType src_elem = T_CONFLICT;
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
  1144
  BasicType dest_elem = T_CONFLICT;
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
  1145
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
  1146
  if (top_dest != NULL && top_dest->klass() != NULL) {
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
  1147
    dest_elem = top_dest->klass()->as_array_klass()->element_type()->basic_type();
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
  1148
  }
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
  1149
  if (top_src != NULL && top_src->klass() != NULL) {
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
  1150
    src_elem = top_src->klass()->as_array_klass()->element_type()->basic_type();
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
  1151
  }
58273
08a5148e7c4e 8230505: Replace JVM type comparisons to T_OBJECT and T_ARRAY with call to is_reference_type
lfoltan
parents: 58217
diff changeset
  1152
  if (is_reference_type(src_elem))  src_elem  = T_OBJECT;
08a5148e7c4e 8230505: Replace JVM type comparisons to T_OBJECT and T_ARRAY with call to is_reference_type
lfoltan
parents: 58217
diff changeset
  1153
  if (is_reference_type(dest_elem)) dest_elem = T_OBJECT;
45427
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
  1154
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
  1155
  if (ac->is_arraycopy_validated() &&
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
  1156
      dest_elem != T_CONFLICT &&
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
  1157
      src_elem == T_CONFLICT) {
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
  1158
    src_elem = dest_elem;
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
  1159
  }
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
  1160
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
  1161
  if (src_elem == T_CONFLICT || dest_elem == T_CONFLICT) {
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1162
    // Conservatively insert a memory barrier on all memory slices.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1163
    // Do not let writes into the source float below the arraycopy.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1164
    {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1165
      Node* mem = ac->in(TypeFunc::Memory);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1166
      insert_mem_bar(&ctrl, &mem, Op_MemBarCPUOrder);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1167
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1168
      merge_mem = MergeMemNode::make(mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1169
      transform_later(merge_mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1170
    }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1171
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1172
    // Call StubRoutines::generic_arraycopy stub.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1173
    Node* mem = generate_arraycopy(ac, NULL, &ctrl, merge_mem, &io,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1174
                                   TypeRawPtr::BOTTOM, T_CONFLICT,
42086
feac795f345d 8159611: C2: ArrayCopy elimination skips required parameter checks
simonis
parents: 38704
diff changeset
  1175
                                   src, src_offset, dest, dest_offset, length,
feac795f345d 8159611: C2: ArrayCopy elimination skips required parameter checks
simonis
parents: 38704
diff changeset
  1176
                                   // If a  negative length guard was generated for the ArrayCopyNode,
feac795f345d 8159611: C2: ArrayCopy elimination skips required parameter checks
simonis
parents: 38704
diff changeset
  1177
                                   // the length of the array can never be negative.
feac795f345d 8159611: C2: ArrayCopy elimination skips required parameter checks
simonis
parents: 38704
diff changeset
  1178
                                   false, ac->has_negative_length_guard());
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1179
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1180
    // Do not let reads from the destination float above the arraycopy.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1181
    // Since we cannot type the arrays, we don't know which slices
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1182
    // might be affected.  We could restrict this barrier only to those
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1183
    // memory slices which pertain to array elements--but don't bother.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1184
    if (!InsertMemBarAfterArraycopy) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1185
      // (If InsertMemBarAfterArraycopy, there is already one in place.)
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1186
      insert_mem_bar(&ctrl, &mem, Op_MemBarCPUOrder);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1187
    }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1188
    return;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1189
  }
45427
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
  1190
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
  1191
  assert(!ac->is_arraycopy_validated() || (src_elem == dest_elem && dest_elem != T_VOID), "validated but different basic types");
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 42086
diff changeset
  1192
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1193
  // (2) src and dest arrays must have elements of the same BasicType
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1194
  // Figure out the size and type of the elements we will be copying.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1195
  if (src_elem != dest_elem || dest_elem == T_VOID) {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1196
    // The component types are not the same or are not recognized.  Punt.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1197
    // (But, avoid the native method wrapper to JVM_ArrayCopy.)
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1198
    {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1199
      Node* mem = ac->in(TypeFunc::Memory);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1200
      merge_mem = generate_slow_arraycopy(ac, &ctrl, mem, &io, TypePtr::BOTTOM, src, src_offset, dest, dest_offset, length, false);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1201
    }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1202
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1203
    _igvn.replace_node(_memproj_fallthrough, merge_mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1204
    _igvn.replace_node(_ioproj_fallthrough, io);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1205
    _igvn.replace_node(_fallthroughcatchproj, ctrl);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1206
    return;
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1207
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1208
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1209
  //---------------------------------------------------------------------------
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1210
  // We will make a fast path for this call to arraycopy.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1211
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1212
  // We have the following tests left to perform:
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1213
  //
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1214
  // (3) src and dest must not be null.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1215
  // (4) src_offset must not be negative.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1216
  // (5) dest_offset must not be negative.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1217
  // (6) length must not be negative.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1218
  // (7) src_offset + length must not exceed length of src.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1219
  // (8) dest_offset + length must not exceed length of dest.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1220
  // (9) each element of an oop array must be assignable
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1221
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1222
  {
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1223
    Node* mem = ac->in(TypeFunc::Memory);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1224
    merge_mem = MergeMemNode::make(mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1225
    transform_later(merge_mem);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1226
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1227
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1228
  RegionNode* slow_region = new RegionNode(1);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1229
  transform_later(slow_region);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1230
28396
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents: 27637
diff changeset
  1231
  if (!ac->is_arraycopy_validated()) {
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1232
    // (3) operands must not be null
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1233
    // We currently perform our null checks with the null_check routine.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1234
    // This means that the null exceptions will be reported in the caller
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1235
    // rather than (correctly) reported inside of the native arraycopy call.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1236
    // This should be corrected, given time.  We do our null check with the
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1237
    // stack pointer restored.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1238
    // null checks done library_call.cpp
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1239
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1240
    // (4) src_offset must not be negative.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1241
    generate_negative_guard(&ctrl, src_offset, slow_region);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1242
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1243
    // (5) dest_offset must not be negative.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1244
    generate_negative_guard(&ctrl, dest_offset, slow_region);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1245
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1246
    // (6) length must not be negative (moved to generate_arraycopy()).
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1247
    // generate_negative_guard(length, slow_region);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1248
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1249
    // (7) src_offset + length must not exceed length of src.
26180
2fbed11af70e 8055153: nsk/stress/jck60/jck60014 crashes on sparc
roland
parents: 26166
diff changeset
  1250
    Node* alen = ac->in(ArrayCopyNode::SrcLen);
26435
b446202ac824 8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents: 26180
diff changeset
  1251
    assert(alen != NULL, "need src len");
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1252
    generate_limit_guard(&ctrl,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1253
                         src_offset, length,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1254
                         alen,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1255
                         slow_region);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1256
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1257
    // (8) dest_offset + length must not exceed length of dest.
26180
2fbed11af70e 8055153: nsk/stress/jck60/jck60014 crashes on sparc
roland
parents: 26166
diff changeset
  1258
    alen = ac->in(ArrayCopyNode::DestLen);
26435
b446202ac824 8055910: closed/java/util/Collections/CheckedCollections.java failed with ClassCastException not thrown
roland
parents: 26180
diff changeset
  1259
    assert(alen != NULL, "need dest len");
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1260
    generate_limit_guard(&ctrl,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1261
                         dest_offset, length,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1262
                         alen,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1263
                         slow_region);
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1264
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1265
    // (9) each element of an oop array must be assignable
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1266
    // The generate_arraycopy subroutine checks this.
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1267
  }
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1268
  // This is where the memory effects are placed:
46754
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents: 46625
diff changeset
  1269
  const TypePtr* adr_type = NULL;
30629
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29337
diff changeset
  1270
  if (ac->_dest_type != TypeOopPtr::BOTTOM) {
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29337
diff changeset
  1271
    adr_type = ac->_dest_type->add_offset(Type::OffsetBot)->is_ptr();
46754
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents: 46625
diff changeset
  1272
  } else {
2e49bb347cbc 8182036: Load from initializing arraycopy uses wrong memory state
roland
parents: 46625
diff changeset
  1273
    adr_type = TypeAryPtr::get_array_body_type(dest_elem);
30629
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29337
diff changeset
  1274
  }
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29337
diff changeset
  1275
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1276
  generate_arraycopy(ac, alloc, &ctrl, merge_mem, &io,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1277
                     adr_type, dest_elem,
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1278
                     src, src_offset, dest, dest_offset, length,
42086
feac795f345d 8159611: C2: ArrayCopy elimination skips required parameter checks
simonis
parents: 38704
diff changeset
  1279
                     // If a  negative length guard was generated for the ArrayCopyNode,
feac795f345d 8159611: C2: ArrayCopy elimination skips required parameter checks
simonis
parents: 38704
diff changeset
  1280
                     // the length of the array can never be negative.
feac795f345d 8159611: C2: ArrayCopy elimination skips required parameter checks
simonis
parents: 38704
diff changeset
  1281
                     false, ac->has_negative_length_guard(), slow_region);
26166
4b49fd58bbd9 7173584: Implement arraycopy as a macro node
roland
parents:
diff changeset
  1282
}