src/hotspot/share/opto/arraycopynode.cpp
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58273 08a5148e7c4e
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
     1
/*
54048
744dc9c33676 8217417: Decorator name typo: C2_TIGHLY_COUPLED_ALLOC
kbarrett
parents: 52925
diff changeset
     2
 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
     4
 *
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
     8
 *
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    13
 * accompanied this code).
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    14
 *
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    18
 *
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    21
 * questions.
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    22
 *
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    23
 */
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    24
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    25
#include "precompiled.hpp"
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents: 49982
diff changeset
    26
#include "gc/shared/barrierSet.hpp"
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents: 49982
diff changeset
    27
#include "gc/shared/c2/barrierSetC2.hpp"
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents: 49982
diff changeset
    28
#include "gc/shared/c2/cardTableBarrierSetC2.hpp"
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    29
#include "opto/arraycopynode.hpp"
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    30
#include "opto/graphKit.hpp"
45427
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
    31
#include "runtime/sharedRuntime.hpp"
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents: 49982
diff changeset
    32
#include "utilities/macros.hpp"
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    33
42086
feac795f345d 8159611: C2: ArrayCopy elimination skips required parameter checks
simonis
parents: 40365
diff changeset
    34
ArrayCopyNode::ArrayCopyNode(Compile* C, bool alloc_tightly_coupled, bool has_negative_length_guard)
51984
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
    35
  : CallNode(arraycopy_type(), NULL, TypePtr::BOTTOM),
51333
f6641fcf7b7e 8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents: 51085
diff changeset
    36
    _kind(None),
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    37
    _alloc_tightly_coupled(alloc_tightly_coupled),
42086
feac795f345d 8159611: C2: ArrayCopy elimination skips required parameter checks
simonis
parents: 40365
diff changeset
    38
    _has_negative_length_guard(has_negative_length_guard),
30629
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29360
diff changeset
    39
    _arguments_validated(false),
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29360
diff changeset
    40
    _src_type(TypeOopPtr::BOTTOM),
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29360
diff changeset
    41
    _dest_type(TypeOopPtr::BOTTOM) {
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    42
  init_class_id(Class_ArrayCopy);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    43
  init_flags(Flag_is_macro);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    44
  C->add_macro_node(this);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    45
}
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    46
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    47
uint ArrayCopyNode::size_of() const { return sizeof(*this); }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    48
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    49
ArrayCopyNode* ArrayCopyNode::make(GraphKit* kit, bool may_throw,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    50
                                   Node* src, Node* src_offset,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    51
                                   Node* dest, Node* dest_offset,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    52
                                   Node* length,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    53
                                   bool alloc_tightly_coupled,
42086
feac795f345d 8159611: C2: ArrayCopy elimination skips required parameter checks
simonis
parents: 40365
diff changeset
    54
                                   bool has_negative_length_guard,
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    55
                                   Node* src_klass, Node* dest_klass,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    56
                                   Node* src_length, Node* dest_length) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    57
42086
feac795f345d 8159611: C2: ArrayCopy elimination skips required parameter checks
simonis
parents: 40365
diff changeset
    58
  ArrayCopyNode* ac = new ArrayCopyNode(kit->C, alloc_tightly_coupled, has_negative_length_guard);
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    59
  Node* prev_mem = kit->set_predefined_input_for_runtime_call(ac);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    60
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    61
  ac->init_req(ArrayCopyNode::Src, src);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    62
  ac->init_req(ArrayCopyNode::SrcPos, src_offset);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    63
  ac->init_req(ArrayCopyNode::Dest, dest);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    64
  ac->init_req(ArrayCopyNode::DestPos, dest_offset);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    65
  ac->init_req(ArrayCopyNode::Length, length);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    66
  ac->init_req(ArrayCopyNode::SrcLen, src_length);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    67
  ac->init_req(ArrayCopyNode::DestLen, dest_length);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    68
  ac->init_req(ArrayCopyNode::SrcKlass, src_klass);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    69
  ac->init_req(ArrayCopyNode::DestKlass, dest_klass);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    70
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    71
  if (may_throw) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    72
    ac->set_req(TypeFunc::I_O , kit->i_o());
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    73
    kit->add_safepoint_edges(ac, false);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    74
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    75
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    76
  return ac;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    77
}
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    78
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    79
void ArrayCopyNode::connect_outputs(GraphKit* kit) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    80
  kit->set_all_memory_call(this, true);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    81
  kit->set_control(kit->gvn().transform(new ProjNode(this,TypeFunc::Control)));
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    82
  kit->set_i_o(kit->gvn().transform(new ProjNode(this, TypeFunc::I_O)));
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    83
  kit->make_slow_call_ex(this, kit->env()->Throwable_klass(), true);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    84
  kit->set_all_memory_call(this);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    85
}
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    86
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    87
#ifndef PRODUCT
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    88
const char* ArrayCopyNode::_kind_names[] = {"arraycopy", "arraycopy, validated arguments", "clone", "oop array clone", "CopyOf", "CopyOfRange"};
32084
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 31233
diff changeset
    89
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    90
void ArrayCopyNode::dump_spec(outputStream *st) const {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    91
  CallNode::dump_spec(st);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    92
  st->print(" (%s%s)", _kind_names[_kind], _alloc_tightly_coupled ? ", tightly coupled allocation" : "");
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    93
}
32084
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 31233
diff changeset
    94
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 31233
diff changeset
    95
void ArrayCopyNode::dump_compact_spec(outputStream* st) const {
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 31233
diff changeset
    96
  st->print("%s%s", _kind_names[_kind], _alloc_tightly_coupled ? ",tight" : "");
7743e6943cdf 8004073: Implement C2 Ideal node specific dump() method
mhaupt
parents: 31233
diff changeset
    97
}
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    98
#endif
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
    99
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   100
intptr_t ArrayCopyNode::get_length_if_constant(PhaseGVN *phase) const {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   101
  // check that length is constant
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   102
  Node* length = in(ArrayCopyNode::Length);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   103
  const Type* length_type = phase->type(length);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   104
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   105
  if (length_type == Type::TOP) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   106
    return -1;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   107
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   108
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   109
  assert(is_clonebasic() || is_arraycopy() || is_copyof() || is_copyofrange(), "unexpected array copy type");
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   110
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   111
  return is_clonebasic() ? length->find_intptr_t_con(-1) : length->find_int_con(-1);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   112
}
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   113
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   114
int ArrayCopyNode::get_count(PhaseGVN *phase) const {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   115
  Node* src = in(ArrayCopyNode::Src);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   116
  const Type* src_type = phase->type(src);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   117
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   118
  if (is_clonebasic()) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   119
    if (src_type->isa_instptr()) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   120
      const TypeInstPtr* inst_src = src_type->is_instptr();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   121
      ciInstanceKlass* ik = inst_src->klass()->as_instance_klass();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   122
      // ciInstanceKlass::nof_nonstatic_fields() doesn't take injected
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   123
      // fields into account. They are rare anyway so easier to simply
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   124
      // skip instances with injected fields.
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   125
      if ((!inst_src->klass_is_exact() && (ik->is_interface() || ik->has_subklass())) || ik->has_injected_fields()) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   126
        return -1;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   127
      }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   128
      int nb_fields = ik->nof_nonstatic_fields();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   129
      return nb_fields;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   130
    } else {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   131
      const TypeAryPtr* ary_src = src_type->isa_aryptr();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   132
      assert (ary_src != NULL, "not an array or instance?");
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   133
      // clone passes a length as a rounded number of longs. If we're
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   134
      // cloning an array we'll do it element by element. If the
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   135
      // length input to ArrayCopyNode is constant, length of input
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   136
      // array must be too.
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   137
29345
e8f6ba59748f 8073792: assert((get_length_if_constant(phase) == -1) == !ary_src->size()->is_con()) failed: inconsistent
roland
parents: 29340
diff changeset
   138
      assert((get_length_if_constant(phase) == -1) == !ary_src->size()->is_con() ||
57560
1fdace0fb2f4 8223769: Assert triggers with -XX:+StressReflectiveCode
thartmann
parents: 55003
diff changeset
   139
             phase->is_IterGVN() || StressReflectiveCode, "inconsistent");
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   140
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   141
      if (ary_src->size()->is_con()) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   142
        return ary_src->size()->get_con();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   143
      }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   144
      return -1;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   145
    }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   146
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   147
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   148
  return get_length_if_constant(phase);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   149
}
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   150
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   151
Node* ArrayCopyNode::load(BarrierSetC2* bs, PhaseGVN *phase, Node*& ctl, MergeMemNode* mem, Node* adr, const TypePtr* adr_type, const Type *type, BasicType bt) {
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   152
  DecoratorSet decorators = C2_READ_ACCESS | C2_CONTROL_DEPENDENT_LOAD | IN_HEAP | C2_ARRAY_COPY;
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   153
  C2AccessValuePtr addr(adr, adr_type);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   154
  C2OptAccess access(*phase, ctl, mem, decorators, bt, adr->in(AddPNode::Base), addr);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   155
  Node* res = bs->load_at(access, type);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   156
  ctl = access.ctl();
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   157
  return res;
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   158
}
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   159
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   160
void ArrayCopyNode::store(BarrierSetC2* bs, PhaseGVN *phase, Node*& ctl, MergeMemNode* mem, Node* adr, const TypePtr* adr_type, Node* val, const Type *type, BasicType bt) {
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   161
  DecoratorSet decorators = C2_WRITE_ACCESS | IN_HEAP | C2_ARRAY_COPY;
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   162
  if (is_alloc_tightly_coupled()) {
54048
744dc9c33676 8217417: Decorator name typo: C2_TIGHLY_COUPLED_ALLOC
kbarrett
parents: 52925
diff changeset
   163
    decorators |= C2_TIGHTLY_COUPLED_ALLOC;
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   164
  }
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   165
  C2AccessValuePtr addr(adr, adr_type);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   166
  C2AccessValue value(val, type);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   167
  C2OptAccess access(*phase, ctl, mem, decorators, bt, adr->in(AddPNode::Base), addr);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   168
  bs->store_at(access, value);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   169
  ctl = access.ctl();
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   170
}
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   171
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   172
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   173
Node* ArrayCopyNode::try_clone_instance(PhaseGVN *phase, bool can_reshape, int count) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   174
  if (!is_clonebasic()) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   175
    return NULL;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   176
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   177
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   178
  Node* src = in(ArrayCopyNode::Src);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   179
  Node* dest = in(ArrayCopyNode::Dest);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   180
  Node* ctl = in(TypeFunc::Control);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   181
  Node* in_mem = in(TypeFunc::Memory);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   182
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   183
  const Type* src_type = phase->type(src);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   184
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   185
  assert(src->is_AddP(), "should be base + off");
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   186
  assert(dest->is_AddP(), "should be base + off");
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   187
  Node* base_src = src->in(AddPNode::Base);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   188
  Node* base_dest = dest->in(AddPNode::Base);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   189
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   190
  MergeMemNode* mem = MergeMemNode::make(in_mem);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   191
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   192
  const TypeInstPtr* inst_src = src_type->isa_instptr();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   193
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   194
  if (inst_src == NULL) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   195
    return NULL;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   196
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   197
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   198
  if (!inst_src->klass_is_exact()) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   199
    ciInstanceKlass* ik = inst_src->klass()->as_instance_klass();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   200
    assert(!ik->is_interface() && !ik->has_subklass(), "inconsistent klass hierarchy");
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   201
    phase->C->dependencies()->assert_leaf_type(ik);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   202
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   203
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   204
  ciInstanceKlass* ik = inst_src->klass()->as_instance_klass();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   205
  assert(ik->nof_nonstatic_fields() <= ArrayCopyLoadStoreMaxElem, "too many fields");
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   206
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   207
  BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   208
  for (int i = 0; i < count; i++) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   209
    ciField* field = ik->nonstatic_field_at(i);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   210
    int fieldidx = phase->C->alias_type(field)->index();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   211
    const TypePtr* adr_type = phase->C->alias_type(field)->adr_type();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   212
    Node* off = phase->MakeConX(field->offset());
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   213
    Node* next_src = phase->transform(new AddPNode(base_src,base_src,off));
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   214
    Node* next_dest = phase->transform(new AddPNode(base_dest,base_dest,off));
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   215
    BasicType bt = field->layout_type();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   216
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   217
    const Type *type;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   218
    if (bt == T_OBJECT) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   219
      if (!field->type()->is_loaded()) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   220
        type = TypeInstPtr::BOTTOM;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   221
      } else {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   222
        ciType* field_klass = field->type();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   223
        type = TypeOopPtr::make_from_klass(field_klass->as_klass());
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   224
      }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   225
    } else {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   226
      type = Type::get_const_basic_type(bt);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   227
    }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   228
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   229
    Node* v = load(bs, phase, ctl, mem, next_src, adr_type, type, bt);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   230
    store(bs, phase, ctl, mem, next_dest, adr_type, v, type, bt);
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   231
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   232
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   233
  if (!finish_transform(phase, can_reshape, ctl, mem)) {
39254
fb4492288b01 8156760: VM crashes if -XX:-ReduceInitialCardMarks is set
thartmann
parents: 32576
diff changeset
   234
    // Return NodeSentinel to indicate that the transform failed
fb4492288b01 8156760: VM crashes if -XX:-ReduceInitialCardMarks is set
thartmann
parents: 32576
diff changeset
   235
    return NodeSentinel;
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   236
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   237
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   238
  return mem;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   239
}
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   240
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   241
bool ArrayCopyNode::prepare_array_copy(PhaseGVN *phase, bool can_reshape,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   242
                                       Node*& adr_src,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   243
                                       Node*& base_src,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   244
                                       Node*& adr_dest,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   245
                                       Node*& base_dest,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   246
                                       BasicType& copy_type,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   247
                                       const Type*& value_type,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   248
                                       bool& disjoint_bases) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   249
  Node* src = in(ArrayCopyNode::Src);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   250
  Node* dest = in(ArrayCopyNode::Dest);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   251
  const Type* src_type = phase->type(src);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   252
  const TypeAryPtr* ary_src = src_type->isa_aryptr();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   253
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   254
  if (is_arraycopy() || is_copyofrange() || is_copyof()) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   255
    const Type* dest_type = phase->type(dest);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   256
    const TypeAryPtr* ary_dest = dest_type->isa_aryptr();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   257
    Node* src_offset = in(ArrayCopyNode::SrcPos);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   258
    Node* dest_offset = in(ArrayCopyNode::DestPos);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   259
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   260
    // newly allocated object is guaranteed to not overlap with source object
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   261
    disjoint_bases = is_alloc_tightly_coupled();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   262
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   263
    if (ary_src  == NULL || ary_src->klass()  == NULL ||
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   264
        ary_dest == NULL || ary_dest->klass() == NULL) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   265
      // We don't know if arguments are arrays
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   266
      return false;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   267
    }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   268
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   269
    BasicType src_elem  = ary_src->klass()->as_array_klass()->element_type()->basic_type();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   270
    BasicType dest_elem = ary_dest->klass()->as_array_klass()->element_type()->basic_type();
58273
08a5148e7c4e 8230505: Replace JVM type comparisons to T_OBJECT and T_ARRAY with call to is_reference_type
lfoltan
parents: 57560
diff changeset
   271
    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: 57560
diff changeset
   272
    if (is_reference_type(dest_elem))  dest_elem = T_OBJECT;
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   273
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   274
    if (src_elem != dest_elem || dest_elem == T_VOID) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   275
      // We don't know if arguments are arrays of the same type
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   276
      return false;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   277
    }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   278
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents: 49982
diff changeset
   279
    BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
51984
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   280
    if (bs->array_copy_requires_gc_barriers(is_alloc_tightly_coupled(), dest_elem, false, BarrierSetC2::Optimization)) {
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   281
      // It's an object array copy but we can't emit the card marking
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   282
      // that is needed
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   283
      return false;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   284
    }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   285
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   286
    value_type = ary_src->elem();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   287
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   288
    base_src = src;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   289
    base_dest = dest;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   290
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   291
    uint shift  = exact_log2(type2aelembytes(dest_elem));
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   292
    uint header = arrayOopDesc::base_offset_in_bytes(dest_elem);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   293
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   294
    adr_src = src;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   295
    adr_dest = dest;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   296
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   297
    src_offset = Compile::conv_I2X_index(phase, src_offset, ary_src->size());
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   298
    dest_offset = Compile::conv_I2X_index(phase, dest_offset, ary_dest->size());
55003
bec1bb783c7e 8224539: C2 compilation fails during ArrayCopyNode optimizations with assert(i < _max) failed: oob: i=1, _max=1
thartmann
parents: 54048
diff changeset
   299
    if (src_offset->is_top() || dest_offset->is_top()) {
bec1bb783c7e 8224539: C2 compilation fails during ArrayCopyNode optimizations with assert(i < _max) failed: oob: i=1, _max=1
thartmann
parents: 54048
diff changeset
   300
      // Offset is out of bounds (the ArrayCopyNode will be removed)
bec1bb783c7e 8224539: C2 compilation fails during ArrayCopyNode optimizations with assert(i < _max) failed: oob: i=1, _max=1
thartmann
parents: 54048
diff changeset
   301
      return false;
bec1bb783c7e 8224539: C2 compilation fails during ArrayCopyNode optimizations with assert(i < _max) failed: oob: i=1, _max=1
thartmann
parents: 54048
diff changeset
   302
    }
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   303
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   304
    Node* src_scale = phase->transform(new LShiftXNode(src_offset, phase->intcon(shift)));
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   305
    Node* dest_scale = phase->transform(new LShiftXNode(dest_offset, phase->intcon(shift)));
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   306
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   307
    adr_src = phase->transform(new AddPNode(base_src, adr_src, src_scale));
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   308
    adr_dest = phase->transform(new AddPNode(base_dest, adr_dest, dest_scale));
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   309
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   310
    adr_src = new AddPNode(base_src, adr_src, phase->MakeConX(header));
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   311
    adr_dest = new AddPNode(base_dest, adr_dest, phase->MakeConX(header));
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   312
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   313
    adr_src = phase->transform(adr_src);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   314
    adr_dest = phase->transform(adr_dest);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   315
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   316
    copy_type = dest_elem;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   317
  } else {
44322
051426f34a5e 8176505: Wrong assertion 'should be an array copy/clone' in arraycopynode.cpp
simonis
parents: 42086
diff changeset
   318
    assert(ary_src != NULL, "should be a clone");
051426f34a5e 8176505: Wrong assertion 'should be an array copy/clone' in arraycopynode.cpp
simonis
parents: 42086
diff changeset
   319
    assert(is_clonebasic(), "should be");
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   320
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   321
    disjoint_bases = true;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   322
    assert(src->is_AddP(), "should be base + off");
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   323
    assert(dest->is_AddP(), "should be base + off");
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   324
    adr_src = src;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   325
    base_src = src->in(AddPNode::Base);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   326
    adr_dest = dest;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   327
    base_dest = dest->in(AddPNode::Base);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   328
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   329
    assert(phase->type(src->in(AddPNode::Offset))->is_intptr_t()->get_con() == phase->type(dest->in(AddPNode::Offset))->is_intptr_t()->get_con(), "same start offset?");
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   330
    BasicType elem = ary_src->klass()->as_array_klass()->element_type()->basic_type();
58273
08a5148e7c4e 8230505: Replace JVM type comparisons to T_OBJECT and T_ARRAY with call to is_reference_type
lfoltan
parents: 57560
diff changeset
   331
    if (is_reference_type(elem))  elem = T_OBJECT;
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   332
51984
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   333
    BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   334
    if (bs->array_copy_requires_gc_barriers(true, elem, true, BarrierSetC2::Optimization)) {
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   335
      return false;
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   336
    }
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   337
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   338
    int diff = arrayOopDesc::base_offset_in_bytes(elem) - phase->type(src->in(AddPNode::Offset))->is_intptr_t()->get_con();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   339
    assert(diff >= 0, "clone should not start after 1st array element");
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   340
    if (diff > 0) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   341
      adr_src = phase->transform(new AddPNode(base_src, adr_src, phase->MakeConX(diff)));
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   342
      adr_dest = phase->transform(new AddPNode(base_dest, adr_dest, phase->MakeConX(diff)));
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   343
    }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   344
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   345
    copy_type = elem;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   346
    value_type = ary_src->elem();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   347
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   348
  return true;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   349
}
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   350
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   351
const TypePtr* ArrayCopyNode::get_address_type(PhaseGVN *phase, Node* n) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   352
  const Type* at = phase->type(n);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   353
  assert(at != Type::TOP, "unexpected type");
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   354
  const TypePtr* atp = at->isa_ptr();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   355
  // adjust atp to be the correct array element address type
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   356
  atp = atp->add_offset(Type::OffsetBot);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   357
  return atp;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   358
}
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   359
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   360
void ArrayCopyNode::array_copy_test_overlap(PhaseGVN *phase, bool can_reshape, bool disjoint_bases, int count, Node*& forward_ctl, Node*& backward_ctl) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   361
  Node* ctl = in(TypeFunc::Control);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   362
  if (!disjoint_bases && count > 1) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   363
    Node* src_offset = in(ArrayCopyNode::SrcPos);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   364
    Node* dest_offset = in(ArrayCopyNode::DestPos);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   365
    assert(src_offset != NULL && dest_offset != NULL, "should be");
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   366
    Node* cmp = phase->transform(new CmpINode(src_offset, dest_offset));
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   367
    Node *bol = phase->transform(new BoolNode(cmp, BoolTest::lt));
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   368
    IfNode *iff = new IfNode(ctl, bol, PROB_FAIR, COUNT_UNKNOWN);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   369
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   370
    phase->transform(iff);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   371
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   372
    forward_ctl = phase->transform(new IfFalseNode(iff));
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   373
    backward_ctl = phase->transform(new IfTrueNode(iff));
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   374
  } else {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   375
    forward_ctl = ctl;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   376
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   377
}
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   378
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   379
Node* ArrayCopyNode::array_copy_forward(PhaseGVN *phase,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   380
                                        bool can_reshape,
51984
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   381
                                        Node*& forward_ctl,
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   382
                                        MergeMemNode* mm,
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   383
                                        const TypePtr* atp_src,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   384
                                        const TypePtr* atp_dest,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   385
                                        Node* adr_src,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   386
                                        Node* base_src,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   387
                                        Node* adr_dest,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   388
                                        Node* base_dest,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   389
                                        BasicType copy_type,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   390
                                        const Type* value_type,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   391
                                        int count) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   392
  if (!forward_ctl->is_top()) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   393
    // copy forward
51984
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   394
    mm = mm->clone()->as_MergeMem();
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   395
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   396
    if (count > 0) {
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   397
      BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   398
      Node* v = load(bs, phase, forward_ctl, mm, adr_src, atp_src, value_type, copy_type);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   399
      store(bs, phase, forward_ctl, mm, adr_dest, atp_dest, v, value_type, copy_type);
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   400
      for (int i = 1; i < count; i++) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   401
        Node* off  = phase->MakeConX(type2aelembytes(copy_type) * i);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   402
        Node* next_src = phase->transform(new AddPNode(base_src,adr_src,off));
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   403
        Node* next_dest = phase->transform(new AddPNode(base_dest,adr_dest,off));
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   404
        v = load(bs, phase, forward_ctl, mm, next_src, atp_src, value_type, copy_type);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   405
        store(bs, phase, forward_ctl, mm, next_dest, atp_dest, v, value_type, copy_type);
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   406
      }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   407
    } else if(can_reshape) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   408
      PhaseIterGVN* igvn = phase->is_IterGVN();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   409
      igvn->_worklist.push(adr_src);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   410
      igvn->_worklist.push(adr_dest);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   411
    }
51984
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   412
    return mm;
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   413
  }
51984
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   414
  return phase->C->top();
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   415
}
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   416
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   417
Node* ArrayCopyNode::array_copy_backward(PhaseGVN *phase,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   418
                                         bool can_reshape,
51984
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   419
                                         Node*& backward_ctl,
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   420
                                         MergeMemNode* mm,
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   421
                                         const TypePtr* atp_src,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   422
                                         const TypePtr* atp_dest,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   423
                                         Node* adr_src,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   424
                                         Node* base_src,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   425
                                         Node* adr_dest,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   426
                                         Node* base_dest,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   427
                                         BasicType copy_type,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   428
                                         const Type* value_type,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   429
                                         int count) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   430
  if (!backward_ctl->is_top()) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   431
    // copy backward
51984
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   432
    mm = mm->clone()->as_MergeMem();
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   433
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   434
    BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   435
    assert(copy_type != T_OBJECT || !bs->array_copy_requires_gc_barriers(false, T_OBJECT, false, BarrierSetC2::Optimization), "only tightly coupled allocations for object arrays");
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   436
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   437
    if (count > 0) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   438
      for (int i = count-1; i >= 1; i--) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   439
        Node* off  = phase->MakeConX(type2aelembytes(copy_type) * i);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   440
        Node* next_src = phase->transform(new AddPNode(base_src,adr_src,off));
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   441
        Node* next_dest = phase->transform(new AddPNode(base_dest,adr_dest,off));
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   442
        Node* v = load(bs, phase, backward_ctl, mm, next_src, atp_src, value_type, copy_type);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   443
        store(bs, phase, backward_ctl, mm, next_dest, atp_dest, v, value_type, copy_type);
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   444
      }
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   445
      Node* v = load(bs, phase, backward_ctl, mm, adr_src, atp_src, value_type, copy_type);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   446
      store(bs, phase, backward_ctl, mm, adr_dest, atp_dest, v, value_type, copy_type);
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   447
    } else if(can_reshape) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   448
      PhaseIterGVN* igvn = phase->is_IterGVN();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   449
      igvn->_worklist.push(adr_src);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   450
      igvn->_worklist.push(adr_dest);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   451
    }
51984
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   452
    return phase->transform(mm);
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   453
  }
51984
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   454
  return phase->C->top();
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   455
}
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   456
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   457
bool ArrayCopyNode::finish_transform(PhaseGVN *phase, bool can_reshape,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   458
                                     Node* ctl, Node *mem) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   459
  if (can_reshape) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   460
    PhaseIterGVN* igvn = phase->is_IterGVN();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   461
    igvn->set_delay_transform(false);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   462
    if (is_clonebasic()) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   463
      Node* out_mem = proj_out(TypeFunc::Memory);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   464
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents: 49982
diff changeset
   465
      BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   466
      if (out_mem->outcnt() != 1 || !out_mem->raw_out(0)->is_MergeMem() ||
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   467
          out_mem->raw_out(0)->outcnt() != 1 || !out_mem->raw_out(0)->raw_out(0)->is_MemBar()) {
51984
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   468
        assert(bs->array_copy_requires_gc_barriers(true, T_OBJECT, true, BarrierSetC2::Optimization), "can only happen with card marking");
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   469
        return false;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   470
      }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   471
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   472
      igvn->replace_node(out_mem->raw_out(0), mem);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   473
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   474
      Node* out_ctl = proj_out(TypeFunc::Control);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   475
      igvn->replace_node(out_ctl, ctl);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   476
    } else {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   477
      // replace fallthrough projections of the ArrayCopyNode by the
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   478
      // new memory, control and the input IO.
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   479
      CallProjections callprojs;
31233
7033a9f3e2f1 8086016: closed/java/text/Format/NumberFormat/BigDecimalCompatibilityTest.java is crashing
roland
parents: 31044
diff changeset
   480
      extract_projections(&callprojs, true, false);
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   481
31233
7033a9f3e2f1 8086016: closed/java/text/Format/NumberFormat/BigDecimalCompatibilityTest.java is crashing
roland
parents: 31044
diff changeset
   482
      if (callprojs.fallthrough_ioproj != NULL) {
7033a9f3e2f1 8086016: closed/java/text/Format/NumberFormat/BigDecimalCompatibilityTest.java is crashing
roland
parents: 31044
diff changeset
   483
        igvn->replace_node(callprojs.fallthrough_ioproj, in(TypeFunc::I_O));
7033a9f3e2f1 8086016: closed/java/text/Format/NumberFormat/BigDecimalCompatibilityTest.java is crashing
roland
parents: 31044
diff changeset
   484
      }
7033a9f3e2f1 8086016: closed/java/text/Format/NumberFormat/BigDecimalCompatibilityTest.java is crashing
roland
parents: 31044
diff changeset
   485
      if (callprojs.fallthrough_memproj != NULL) {
7033a9f3e2f1 8086016: closed/java/text/Format/NumberFormat/BigDecimalCompatibilityTest.java is crashing
roland
parents: 31044
diff changeset
   486
        igvn->replace_node(callprojs.fallthrough_memproj, mem);
7033a9f3e2f1 8086016: closed/java/text/Format/NumberFormat/BigDecimalCompatibilityTest.java is crashing
roland
parents: 31044
diff changeset
   487
      }
7033a9f3e2f1 8086016: closed/java/text/Format/NumberFormat/BigDecimalCompatibilityTest.java is crashing
roland
parents: 31044
diff changeset
   488
      if (callprojs.fallthrough_catchproj != NULL) {
7033a9f3e2f1 8086016: closed/java/text/Format/NumberFormat/BigDecimalCompatibilityTest.java is crashing
roland
parents: 31044
diff changeset
   489
        igvn->replace_node(callprojs.fallthrough_catchproj, ctl);
7033a9f3e2f1 8086016: closed/java/text/Format/NumberFormat/BigDecimalCompatibilityTest.java is crashing
roland
parents: 31044
diff changeset
   490
      }
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   491
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   492
      // The ArrayCopyNode is not disconnected. It still has the
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   493
      // projections for the exception case. Replace current
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   494
      // ArrayCopyNode with a dummy new one with a top() control so
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   495
      // that this part of the graph stays consistent but is
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   496
      // eventually removed.
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   497
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   498
      set_req(0, phase->C->top());
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   499
      remove_dead_region(phase, can_reshape);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   500
    }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   501
  } else {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   502
    if (in(TypeFunc::Control) != ctl) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   503
      // we can't return new memory and control from Ideal at parse time
52925
9c18c9d839d3 8214259: Implementation: JEP 189: Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)
rkennke
parents: 52424
diff changeset
   504
      assert(!is_clonebasic() || UseShenandoahGC, "added control for clone?");
51984
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   505
      phase->record_for_igvn(this);
29340
e5ee51840b93 8073624: Fix waring "converting to non-pointer type 'bool' from NULL" in arraycopynode.cpp
simonis
parents: 29337
diff changeset
   506
      return false;
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   507
    }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   508
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   509
  return true;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   510
}
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   511
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   512
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   513
Node *ArrayCopyNode::Ideal(PhaseGVN *phase, bool can_reshape) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   514
  if (remove_dead_region(phase, can_reshape))  return this;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   515
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   516
  if (StressArrayCopyMacroNode && !can_reshape) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   517
    phase->record_for_igvn(this);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   518
    return NULL;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   519
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   520
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   521
  // See if it's a small array copy and we can inline it as
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   522
  // loads/stores
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   523
  // Here we can only do:
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   524
  // - arraycopy if all arguments were validated before and we don't
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   525
  // need card marking
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   526
  // - clone for which we don't need to do card marking
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   527
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   528
  if (!is_clonebasic() && !is_arraycopy_validated() &&
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   529
      !is_copyofrange_validated() && !is_copyof_validated()) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   530
    return NULL;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   531
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   532
29360
dd9daceb5f3d 8073957: assert(ary_src != 0) failed: not an array or instance?
roland
parents: 29345
diff changeset
   533
  assert(in(TypeFunc::Control) != NULL &&
dd9daceb5f3d 8073957: assert(ary_src != 0) failed: not an array or instance?
roland
parents: 29345
diff changeset
   534
         in(TypeFunc::Memory) != NULL &&
dd9daceb5f3d 8073957: assert(ary_src != 0) failed: not an array or instance?
roland
parents: 29345
diff changeset
   535
         in(ArrayCopyNode::Src) != NULL &&
dd9daceb5f3d 8073957: assert(ary_src != 0) failed: not an array or instance?
roland
parents: 29345
diff changeset
   536
         in(ArrayCopyNode::Dest) != NULL &&
dd9daceb5f3d 8073957: assert(ary_src != 0) failed: not an array or instance?
roland
parents: 29345
diff changeset
   537
         in(ArrayCopyNode::Length) != NULL &&
dd9daceb5f3d 8073957: assert(ary_src != 0) failed: not an array or instance?
roland
parents: 29345
diff changeset
   538
         ((in(ArrayCopyNode::SrcPos) != NULL && in(ArrayCopyNode::DestPos) != NULL) ||
dd9daceb5f3d 8073957: assert(ary_src != 0) failed: not an array or instance?
roland
parents: 29345
diff changeset
   539
          is_clonebasic()), "broken inputs");
dd9daceb5f3d 8073957: assert(ary_src != 0) failed: not an array or instance?
roland
parents: 29345
diff changeset
   540
dd9daceb5f3d 8073957: assert(ary_src != 0) failed: not an array or instance?
roland
parents: 29345
diff changeset
   541
  if (in(TypeFunc::Control)->is_top() ||
dd9daceb5f3d 8073957: assert(ary_src != 0) failed: not an array or instance?
roland
parents: 29345
diff changeset
   542
      in(TypeFunc::Memory)->is_top() ||
dd9daceb5f3d 8073957: assert(ary_src != 0) failed: not an array or instance?
roland
parents: 29345
diff changeset
   543
      phase->type(in(ArrayCopyNode::Src)) == Type::TOP ||
dd9daceb5f3d 8073957: assert(ary_src != 0) failed: not an array or instance?
roland
parents: 29345
diff changeset
   544
      phase->type(in(ArrayCopyNode::Dest)) == Type::TOP ||
dd9daceb5f3d 8073957: assert(ary_src != 0) failed: not an array or instance?
roland
parents: 29345
diff changeset
   545
      (in(ArrayCopyNode::SrcPos) != NULL && in(ArrayCopyNode::SrcPos)->is_top()) ||
dd9daceb5f3d 8073957: assert(ary_src != 0) failed: not an array or instance?
roland
parents: 29345
diff changeset
   546
      (in(ArrayCopyNode::DestPos) != NULL && in(ArrayCopyNode::DestPos)->is_top())) {
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   547
    return NULL;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   548
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   549
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   550
  int count = get_count(phase);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   551
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   552
  if (count < 0 || count > ArrayCopyLoadStoreMaxElem) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   553
    return NULL;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   554
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   555
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   556
  Node* mem = try_clone_instance(phase, can_reshape, count);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   557
  if (mem != NULL) {
39254
fb4492288b01 8156760: VM crashes if -XX:-ReduceInitialCardMarks is set
thartmann
parents: 32576
diff changeset
   558
    return (mem == NodeSentinel) ? NULL : mem;
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   559
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   560
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   561
  Node* adr_src = NULL;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   562
  Node* base_src = NULL;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   563
  Node* adr_dest = NULL;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   564
  Node* base_dest = NULL;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   565
  BasicType copy_type = T_ILLEGAL;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   566
  const Type* value_type = NULL;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   567
  bool disjoint_bases = false;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   568
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   569
  if (!prepare_array_copy(phase, can_reshape,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   570
                          adr_src, base_src, adr_dest, base_dest,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   571
                          copy_type, value_type, disjoint_bases)) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   572
    return NULL;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   573
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   574
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   575
  Node* src = in(ArrayCopyNode::Src);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   576
  Node* dest = in(ArrayCopyNode::Dest);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   577
  const TypePtr* atp_src = get_address_type(phase, src);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   578
  const TypePtr* atp_dest = get_address_type(phase, dest);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   579
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   580
  Node *in_mem = in(TypeFunc::Memory);
51984
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   581
  if (!in_mem->is_MergeMem()) {
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   582
    in_mem = MergeMemNode::make(in_mem);
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   583
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   584
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   585
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   586
  if (can_reshape) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   587
    assert(!phase->is_IterGVN()->delay_transform(), "cannot delay transforms");
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   588
    phase->is_IterGVN()->set_delay_transform(true);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   589
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   590
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   591
  Node* backward_ctl = phase->C->top();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   592
  Node* forward_ctl = phase->C->top();
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   593
  array_copy_test_overlap(phase, can_reshape, disjoint_bases, count, forward_ctl, backward_ctl);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   594
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   595
  Node* forward_mem = array_copy_forward(phase, can_reshape, forward_ctl,
51984
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   596
                                         in_mem->as_MergeMem(),
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   597
                                         atp_src, atp_dest,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   598
                                         adr_src, base_src, adr_dest, base_dest,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   599
                                         copy_type, value_type, count);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   600
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   601
  Node* backward_mem = array_copy_backward(phase, can_reshape, backward_ctl,
51984
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   602
                                           in_mem->as_MergeMem(),
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   603
                                           atp_src, atp_dest,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   604
                                           adr_src, base_src, adr_dest, base_dest,
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   605
                                           copy_type, value_type, count);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   606
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   607
  Node* ctl = NULL;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   608
  if (!forward_ctl->is_top() && !backward_ctl->is_top()) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   609
    ctl = new RegionNode(3);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   610
    ctl->init_req(1, forward_ctl);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   611
    ctl->init_req(2, backward_ctl);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   612
    ctl = phase->transform(ctl);
51984
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   613
    MergeMemNode* forward_mm = forward_mem->as_MergeMem();
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   614
    MergeMemNode* backward_mm = backward_mem->as_MergeMem();
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   615
    for (MergeMemStream mms(forward_mm, backward_mm); mms.next_non_empty2(); ) {
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   616
      if (mms.memory() != mms.memory2()) {
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   617
        Node* phi = new PhiNode(ctl, Type::MEMORY, phase->C->get_adr_type(mms.alias_idx()));
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   618
        phi->init_req(1, mms.memory());
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   619
        phi->init_req(2, mms.memory2());
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   620
        phi = phase->transform(phi);
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   621
        mms.set_memory(phi);
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   622
      }
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   623
    }
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51333
diff changeset
   624
    mem = forward_mem;
29337
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   625
  } else if (!forward_ctl->is_top()) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   626
    ctl = forward_ctl;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   627
    mem = forward_mem;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   628
  } else {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   629
    assert(!backward_ctl->is_top(), "no copy?");
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   630
    ctl = backward_ctl;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   631
    mem = backward_mem;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   632
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   633
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   634
  if (can_reshape) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   635
    assert(phase->is_IterGVN()->delay_transform(), "should be delaying transforms");
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   636
    phase->is_IterGVN()->set_delay_transform(false);
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   637
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   638
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   639
  if (!finish_transform(phase, can_reshape, ctl, mem)) {
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   640
    return NULL;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   641
  }
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   642
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   643
  return mem;
ef2be52deeaf 6912521: System.arraycopy works slower than the simple loop for little lengths
roland
parents:
diff changeset
   644
}
30629
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29360
diff changeset
   645
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29360
diff changeset
   646
bool ArrayCopyNode::may_modify(const TypeOopPtr *t_oop, PhaseTransform *phase) {
31044
9fecc7e87949 8080699: Assert failed: Not a Java pointer in JCK test
roland
parents: 30629
diff changeset
   647
  Node* dest = in(ArrayCopyNode::Dest);
9fecc7e87949 8080699: Assert failed: Not a Java pointer in JCK test
roland
parents: 30629
diff changeset
   648
  if (dest->is_top()) {
9fecc7e87949 8080699: Assert failed: Not a Java pointer in JCK test
roland
parents: 30629
diff changeset
   649
    return false;
9fecc7e87949 8080699: Assert failed: Not a Java pointer in JCK test
roland
parents: 30629
diff changeset
   650
  }
9fecc7e87949 8080699: Assert failed: Not a Java pointer in JCK test
roland
parents: 30629
diff changeset
   651
  const TypeOopPtr* dest_t = phase->type(dest)->is_oopptr();
30629
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29360
diff changeset
   652
  assert(!dest_t->is_known_instance() || _dest_type->is_known_instance(), "result of EA not recorded");
31044
9fecc7e87949 8080699: Assert failed: Not a Java pointer in JCK test
roland
parents: 30629
diff changeset
   653
  assert(in(ArrayCopyNode::Src)->is_top() || !phase->type(in(ArrayCopyNode::Src))->is_oopptr()->is_known_instance() ||
9fecc7e87949 8080699: Assert failed: Not a Java pointer in JCK test
roland
parents: 30629
diff changeset
   654
         _src_type->is_known_instance(), "result of EA not recorded");
30629
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29360
diff changeset
   655
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29360
diff changeset
   656
  if (_dest_type != TypeOopPtr::BOTTOM || t_oop->is_known_instance()) {
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29360
diff changeset
   657
    assert(_dest_type == TypeOopPtr::BOTTOM || _dest_type->is_known_instance(), "result of EA is known instance");
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29360
diff changeset
   658
    return t_oop->instance_id() == _dest_type->instance_id();
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29360
diff changeset
   659
  }
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29360
diff changeset
   660
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29360
diff changeset
   661
  return CallNode::may_modify_arraycopy_helper(dest_t, t_oop, phase);
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 29360
diff changeset
   662
}
32370
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   663
45427
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   664
bool ArrayCopyNode::may_modify_helper(const TypeOopPtr *t_oop, Node* n, PhaseTransform *phase, CallNode*& call) {
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   665
  if (n != NULL &&
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   666
      n->is_Call() &&
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   667
      n->as_Call()->may_modify(t_oop, phase) &&
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   668
      (n->as_Call()->is_ArrayCopy() || n->as_Call()->is_call_to_arraycopystub())) {
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   669
    call = n->as_Call();
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   670
    return true;
32370
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   671
  }
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   672
  return false;
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   673
}
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   674
45427
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   675
bool ArrayCopyNode::may_modify(const TypeOopPtr *t_oop, MemBarNode* mb, PhaseTransform *phase, ArrayCopyNode*& ac) {
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   676
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   677
  Node* c = mb->in(0);
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   678
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents: 49982
diff changeset
   679
  BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents: 49982
diff changeset
   680
  // step over g1 gc barrier if we're at e.g. a clone with ReduceInitialCardMarks off
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents: 49982
diff changeset
   681
  c = bs->step_over_gc_barrier(c);
45427
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   682
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   683
  CallNode* call = NULL;
51078
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 50180
diff changeset
   684
  guarantee(c != NULL, "step_over_gc_barrier failed, there must be something to step to.");
fc6cfe40e32a 8207049: Minor improvements of compiler code.
goetz
parents: 50180
diff changeset
   685
  if (c->is_Region()) {
45427
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   686
    for (uint i = 1; i < c->req(); i++) {
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   687
      if (c->in(i) != NULL) {
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   688
        Node* n = c->in(i)->in(0);
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   689
        if (may_modify_helper(t_oop, n, phase, call)) {
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   690
          ac = call->isa_ArrayCopy();
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   691
          assert(c == mb->in(0), "only for clone");
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   692
          return true;
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   693
        }
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   694
      }
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   695
    }
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   696
  } else if (may_modify_helper(t_oop, c->in(0), phase, call)) {
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   697
    ac = call->isa_ArrayCopy();
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents: 49982
diff changeset
   698
#ifdef ASSERT
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents: 49982
diff changeset
   699
    bool use_ReduceInitialCardMarks = BarrierSet::barrier_set()->is_a(BarrierSet::CardTableBarrierSet) &&
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents: 49982
diff changeset
   700
      static_cast<CardTableBarrierSetC2*>(bs)->use_ReduceInitialCardMarks();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents: 49982
diff changeset
   701
    assert(c == mb->in(0) || (ac != NULL && ac->is_clonebasic() && !use_ReduceInitialCardMarks), "only for clone");
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents: 49982
diff changeset
   702
#endif
45427
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   703
    return true;
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   704
  }
32370
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   705
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   706
  return false;
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   707
}
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   708
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   709
// Does this array copy modify offsets between offset_lo and offset_hi
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   710
// in the destination array
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   711
// if must_modify is false, return true if the copy could write
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   712
// between offset_lo and offset_hi
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   713
// if must_modify is true, return true if the copy is guaranteed to
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   714
// write between offset_lo and offset_hi
45427
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   715
bool ArrayCopyNode::modifies(intptr_t offset_lo, intptr_t offset_hi, PhaseTransform* phase, bool must_modify) const {
32370
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   716
  assert(_kind == ArrayCopy || _kind == CopyOf || _kind == CopyOfRange, "only for real array copies");
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   717
45427
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   718
  Node* dest = in(Dest);
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   719
  Node* dest_pos = in(DestPos);
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   720
  Node* len = in(Length);
32370
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   721
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   722
  const TypeInt *dest_pos_t = phase->type(dest_pos)->isa_int();
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   723
  const TypeInt *len_t = phase->type(len)->isa_int();
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   724
  const TypeAryPtr* ary_t = phase->type(dest)->isa_aryptr();
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   725
45427
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   726
  if (dest_pos_t == NULL || len_t == NULL || ary_t == NULL) {
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   727
    return !must_modify;
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   728
  }
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   729
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   730
  BasicType ary_elem = ary_t->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: 44322
diff changeset
   731
  uint header = arrayOopDesc::base_offset_in_bytes(ary_elem);
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   732
  uint elemsize = type2aelembytes(ary_elem);
32370
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   733
45427
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   734
  jlong dest_pos_plus_len_lo = (((jlong)dest_pos_t->_lo) + len_t->_lo) * elemsize + header;
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   735
  jlong dest_pos_plus_len_hi = (((jlong)dest_pos_t->_hi) + len_t->_hi) * elemsize + header;
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   736
  jlong dest_pos_lo = ((jlong)dest_pos_t->_lo) * elemsize + header;
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   737
  jlong dest_pos_hi = ((jlong)dest_pos_t->_hi) * elemsize + header;
32370
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   738
45427
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   739
  if (must_modify) {
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   740
    if (offset_lo >= dest_pos_hi && offset_hi < dest_pos_plus_len_lo) {
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   741
      return true;
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   742
    }
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   743
  } else {
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   744
    if (offset_hi >= dest_pos_lo && offset_lo < dest_pos_plus_len_hi) {
64e07017ce01 8179678: ArrayCopy with same src and dst can cause incorrect execution or compiler crash
roland
parents: 44322
diff changeset
   745
      return true;
32370
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   746
    }
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   747
  }
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   748
  return false;
38b7b5772b4f 8130847: Cloned object's fields observed as null after C2 escape analysis
roland
parents: 32084
diff changeset
   749
}