src/hotspot/share/gc/shared/c2/barrierSetC2.cpp
author neliasso
Fri, 29 Nov 2019 11:26:25 +0100
changeset 59324 5e8f9713e343
parent 59025 b398685dd029
permissions -rw-r--r--
8234520: ZGC: C2: Oop instance cloning causing skipped compiles Reviewed-by: pliden, vlivanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
     1
/*
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
     4
 *
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
     8
 *
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    13
 * accompanied this code).
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    14
 *
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    18
 *
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    21
 * questions.
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    22
 *
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    23
 */
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    24
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    25
#include "precompiled.hpp"
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    26
#include "gc/shared/c2/barrierSetC2.hpp"
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    27
#include "opto/arraycopynode.hpp"
51826
e777e997e7c1 8210963: Build failures after "8210829: Modularize allocations in C2"
shade
parents: 51806
diff changeset
    28
#include "opto/convertnode.hpp"
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    29
#include "opto/graphKit.hpp"
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    30
#include "opto/idealKit.hpp"
51806
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
    31
#include "opto/macro.hpp"
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    32
#include "opto/narrowptrnode.hpp"
58217
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
    33
#include "opto/runtime.hpp"
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    34
#include "utilities/macros.hpp"
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    35
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    36
// By default this is a no-op.
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    37
void BarrierSetC2::resolve_address(C2Access& access) const { }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    38
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
    39
void* C2ParseAccess::barrier_set_state() const {
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    40
  return _kit->barrier_set_state();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    41
}
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    42
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
    43
PhaseGVN& C2ParseAccess::gvn() const { return _kit->gvn(); }
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
    44
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    45
bool C2Access::needs_cpu_membar() const {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    46
  bool mismatched = (_decorators & C2_MISMATCHED) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    47
  bool is_unordered = (_decorators & MO_UNORDERED) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    48
  bool anonymous = (_decorators & C2_UNSAFE_ACCESS) != 0;
50599
ecc2af326b5f 8204939: Change Access nomenclature: root to native
kbarrett
parents: 50180
diff changeset
    49
  bool in_heap = (_decorators & IN_HEAP) != 0;
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    50
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    51
  bool is_write = (_decorators & C2_WRITE_ACCESS) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    52
  bool is_read = (_decorators & C2_READ_ACCESS) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    53
  bool is_atomic = is_read && is_write;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    54
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    55
  if (is_atomic) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    56
    // Atomics always need to be wrapped in CPU membars
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    57
    return true;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    58
  }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    59
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    60
  if (anonymous) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    61
    // We will need memory barriers unless we can determine a unique
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    62
    // alias category for this reference.  (Note:  If for some reason
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    63
    // the barriers get omitted and the unsafe reference begins to "pollute"
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    64
    // the alias analysis of the rest of the graph, either Compile::can_alias
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    65
    // or Compile::must_alias will throw a diagnostic assert.)
50599
ecc2af326b5f 8204939: Change Access nomenclature: root to native
kbarrett
parents: 50180
diff changeset
    66
    if (!in_heap || !is_unordered || (mismatched && !_addr.type()->isa_aryptr())) {
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    67
      return true;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    68
    }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    69
  }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    70
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    71
  return false;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    72
}
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    73
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    74
Node* BarrierSetC2::store_at_resolved(C2Access& access, C2AccessValue& val) const {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    75
  DecoratorSet decorators = access.decorators();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    76
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    77
  bool mismatched = (decorators & C2_MISMATCHED) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    78
  bool unaligned = (decorators & C2_UNALIGNED) != 0;
53765
e002408eb0c0 8218879: Keep track of memory accesses originated from Unsafe
vlivanov
parents: 52424
diff changeset
    79
  bool unsafe = (decorators & C2_UNSAFE_ACCESS) != 0;
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    80
  bool requires_atomic_access = (decorators & MO_UNORDERED) == 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    81
50599
ecc2af326b5f 8204939: Change Access nomenclature: root to native
kbarrett
parents: 50180
diff changeset
    82
  bool in_native = (decorators & IN_NATIVE) != 0;
ecc2af326b5f 8204939: Change Access nomenclature: root to native
kbarrett
parents: 50180
diff changeset
    83
  assert(!in_native, "not supported yet");
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    84
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    85
  MemNode::MemOrd mo = access.mem_node_mo();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
    86
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
    87
  Node* store;
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
    88
  if (access.is_parse_access()) {
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
    89
    C2ParseAccess& parse_access = static_cast<C2ParseAccess&>(access);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
    90
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
    91
    GraphKit* kit = parse_access.kit();
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
    92
    if (access.type() == T_DOUBLE) {
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
    93
      Node* new_val = kit->dstore_rounding(val.node());
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
    94
      val.set_node(new_val);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
    95
    }
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
    96
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
    97
    store = kit->store_to_memory(kit->control(), access.addr().node(), val.node(), access.type(),
53765
e002408eb0c0 8218879: Keep track of memory accesses originated from Unsafe
vlivanov
parents: 52424
diff changeset
    98
                                     access.addr().type(), mo, requires_atomic_access, unaligned, mismatched, unsafe);
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
    99
  } else {
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   100
    assert(!requires_atomic_access, "not yet supported");
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   101
    assert(access.is_opt_access(), "either parse or opt access");
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   102
    C2OptAccess& opt_access = static_cast<C2OptAccess&>(access);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   103
    Node* ctl = opt_access.ctl();
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   104
    MergeMemNode* mm = opt_access.mem();
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   105
    PhaseGVN& gvn = opt_access.gvn();
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   106
    const TypePtr* adr_type = access.addr().type();
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   107
    int alias = gvn.C->get_alias_index(adr_type);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   108
    Node* mem = mm->memory_at(alias);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   109
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   110
    StoreNode* st = StoreNode::make(gvn, ctl, mem, access.addr().node(), adr_type, val.node(), access.type(), mo);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   111
    if (unaligned) {
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   112
      st->set_unaligned_access();
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   113
    }
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   114
    if (mismatched) {
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   115
      st->set_mismatched_access();
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   116
    }
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   117
    store = gvn.transform(st);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   118
    if (store == st) {
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   119
      mm->set_memory_at(alias, st);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   120
    }
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   121
  }
58931
304c63b17b07 8232896: ZGC: Enable C2 clone intrinsic
neliasso
parents: 58217
diff changeset
   122
  access.set_raw_access(store);
304c63b17b07 8232896: ZGC: Enable C2 clone intrinsic
neliasso
parents: 58217
diff changeset
   123
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   124
  return store;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   125
}
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   126
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   127
Node* BarrierSetC2::load_at_resolved(C2Access& access, const Type* val_type) const {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   128
  DecoratorSet decorators = access.decorators();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   129
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   130
  Node* adr = access.addr().node();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   131
  const TypePtr* adr_type = access.addr().type();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   132
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   133
  bool mismatched = (decorators & C2_MISMATCHED) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   134
  bool requires_atomic_access = (decorators & MO_UNORDERED) == 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   135
  bool unaligned = (decorators & C2_UNALIGNED) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   136
  bool control_dependent = (decorators & C2_CONTROL_DEPENDENT_LOAD) != 0;
57582
a79a819a8218 8227407: ZGC: C2 loads and load barriers can get separated by safepoints
eosterlund
parents: 53765
diff changeset
   137
  bool unknown_control = (decorators & C2_UNKNOWN_CONTROL_LOAD) != 0;
53765
e002408eb0c0 8218879: Keep track of memory accesses originated from Unsafe
vlivanov
parents: 52424
diff changeset
   138
  bool unsafe = (decorators & C2_UNSAFE_ACCESS) != 0;
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   139
50599
ecc2af326b5f 8204939: Change Access nomenclature: root to native
kbarrett
parents: 50180
diff changeset
   140
  bool in_native = (decorators & IN_NATIVE) != 0;
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   141
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   142
  MemNode::MemOrd mo = access.mem_node_mo();
57582
a79a819a8218 8227407: ZGC: C2 loads and load barriers can get separated by safepoints
eosterlund
parents: 53765
diff changeset
   143
  LoadNode::ControlDependency dep = unknown_control ? LoadNode::UnknownControl : LoadNode::DependsOnlyOnTest;
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   144
51485
0c7040d1d1ca 8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents: 51482
diff changeset
   145
  Node* load;
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   146
  if (access.is_parse_access()) {
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   147
    C2ParseAccess& parse_access = static_cast<C2ParseAccess&>(access);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   148
    GraphKit* kit = parse_access.kit();
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   149
    Node* control = control_dependent ? kit->control() : NULL;
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   150
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   151
    if (in_native) {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   152
      load = kit->make_load(control, adr, val_type, access.type(), mo, dep,
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   153
                            requires_atomic_access, unaligned,
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   154
                            mismatched, unsafe, access.barrier_data());
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   155
    } else {
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   156
      load = kit->make_load(control, adr, val_type, access.type(), adr_type, mo,
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   157
                            dep, requires_atomic_access, unaligned, mismatched, unsafe,
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   158
                            access.barrier_data());
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   159
    }
51485
0c7040d1d1ca 8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents: 51482
diff changeset
   160
  } else {
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   161
    assert(!requires_atomic_access, "not yet supported");
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   162
    assert(access.is_opt_access(), "either parse or opt access");
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   163
    C2OptAccess& opt_access = static_cast<C2OptAccess&>(access);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   164
    Node* control = control_dependent ? opt_access.ctl() : NULL;
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   165
    MergeMemNode* mm = opt_access.mem();
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   166
    PhaseGVN& gvn = opt_access.gvn();
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   167
    Node* mem = mm->memory_at(gvn.C->get_alias_index(adr_type));
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   168
    load = LoadNode::make(gvn, control, mem, adr, adr_type, val_type, access.type(), mo,
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   169
                          dep, unaligned, mismatched, unsafe, access.barrier_data());
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   170
    load = gvn.transform(load);
51485
0c7040d1d1ca 8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents: 51482
diff changeset
   171
  }
58931
304c63b17b07 8232896: ZGC: Enable C2 clone intrinsic
neliasso
parents: 58217
diff changeset
   172
  access.set_raw_access(load);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   173
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   174
  return load;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   175
}
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   176
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   177
class C2AccessFence: public StackObj {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   178
  C2Access& _access;
51482
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   179
  Node* _leading_membar;
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   181
public:
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   182
  C2AccessFence(C2Access& access) :
51482
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   183
    _access(access), _leading_membar(NULL) {
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   184
    GraphKit* kit = NULL;
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   185
    if (access.is_parse_access()) {
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   186
      C2ParseAccess& parse_access = static_cast<C2ParseAccess&>(access);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   187
      kit = parse_access.kit();
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   188
    }
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   189
    DecoratorSet decorators = access.decorators();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   190
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   191
    bool is_write = (decorators & C2_WRITE_ACCESS) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   192
    bool is_read = (decorators & C2_READ_ACCESS) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   193
    bool is_atomic = is_read && is_write;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   194
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   195
    bool is_volatile = (decorators & MO_SEQ_CST) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   196
    bool is_release = (decorators & MO_RELEASE) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   197
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   198
    if (is_atomic) {
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   199
      assert(kit != NULL, "unsupported at optimization time");
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   200
      // Memory-model-wise, a LoadStore acts like a little synchronized
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   201
      // block, so needs barriers on each side.  These don't translate
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   202
      // into actual barriers on most machines, but we still need rest of
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   203
      // compiler to respect ordering.
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   204
      if (is_release) {
51482
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   205
        _leading_membar = kit->insert_mem_bar(Op_MemBarRelease);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   206
      } else if (is_volatile) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   207
        if (support_IRIW_for_not_multiple_copy_atomic_cpu) {
51482
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   208
          _leading_membar = kit->insert_mem_bar(Op_MemBarVolatile);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   209
        } else {
51482
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   210
          _leading_membar = kit->insert_mem_bar(Op_MemBarRelease);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   211
        }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   212
      }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   213
    } else if (is_write) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   214
      // If reference is volatile, prevent following memory ops from
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   215
      // floating down past the volatile write.  Also prevents commoning
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   216
      // another volatile read.
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   217
      if (is_volatile || is_release) {
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   218
        assert(kit != NULL, "unsupported at optimization time");
51482
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   219
        _leading_membar = kit->insert_mem_bar(Op_MemBarRelease);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   220
      }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   221
    } else {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   222
      // Memory barrier to prevent normal and 'unsafe' accesses from
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   223
      // bypassing each other.  Happens after null checks, so the
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   224
      // exception paths do not take memory state from the memory barrier,
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   225
      // so there's no problems making a strong assert about mixing users
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   226
      // of safe & unsafe memory.
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   227
      if (is_volatile && support_IRIW_for_not_multiple_copy_atomic_cpu) {
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   228
        assert(kit != NULL, "unsupported at optimization time");
51482
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   229
        _leading_membar = kit->insert_mem_bar(Op_MemBarVolatile);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   230
      }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   231
    }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   232
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   233
    if (access.needs_cpu_membar()) {
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   234
      assert(kit != NULL, "unsupported at optimization time");
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   235
      kit->insert_mem_bar(Op_MemBarCPUOrder);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   236
    }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   237
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   238
    if (is_atomic) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   239
      // 4984716: MemBars must be inserted before this
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   240
      //          memory node in order to avoid a false
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   241
      //          dependency which will confuse the scheduler.
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   242
      access.set_memory();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   243
    }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   244
  }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   245
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   246
  ~C2AccessFence() {
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   247
    GraphKit* kit = NULL;
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   248
    if (_access.is_parse_access()) {
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   249
      C2ParseAccess& parse_access = static_cast<C2ParseAccess&>(_access);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   250
      kit = parse_access.kit();
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   251
    }
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   252
    DecoratorSet decorators = _access.decorators();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   253
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   254
    bool is_write = (decorators & C2_WRITE_ACCESS) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   255
    bool is_read = (decorators & C2_READ_ACCESS) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   256
    bool is_atomic = is_read && is_write;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   257
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   258
    bool is_volatile = (decorators & MO_SEQ_CST) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   259
    bool is_acquire = (decorators & MO_ACQUIRE) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   260
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   261
    // If reference is volatile, prevent following volatiles ops from
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   262
    // floating up before the volatile access.
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   263
    if (_access.needs_cpu_membar()) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   264
      kit->insert_mem_bar(Op_MemBarCPUOrder);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   265
    }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   266
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   267
    if (is_atomic) {
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   268
      assert(kit != NULL, "unsupported at optimization time");
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   269
      if (is_acquire || is_volatile) {
51482
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   270
        Node* n = _access.raw_access();
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   271
        Node* mb = kit->insert_mem_bar(Op_MemBarAcquire, n);
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   272
        if (_leading_membar != NULL) {
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   273
          MemBarNode::set_load_store_pair(_leading_membar->as_MemBar(), mb->as_MemBar());
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   274
        }
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   275
      }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   276
    } else if (is_write) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   277
      // If not multiple copy atomic, we do the MemBarVolatile before the load.
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   278
      if (is_volatile && !support_IRIW_for_not_multiple_copy_atomic_cpu) {
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   279
        assert(kit != NULL, "unsupported at optimization time");
51482
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   280
        Node* n = _access.raw_access();
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   281
        Node* mb = kit->insert_mem_bar(Op_MemBarVolatile, n); // Use fat membar
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   282
        if (_leading_membar != NULL) {
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   283
          MemBarNode::set_store_pair(_leading_membar->as_MemBar(), mb->as_MemBar());
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   284
        }
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   285
      }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   286
    } else {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   287
      if (is_volatile || is_acquire) {
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   288
        assert(kit != NULL, "unsupported at optimization time");
51482
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   289
        Node* n = _access.raw_access();
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   290
        assert(_leading_membar == NULL || support_IRIW_for_not_multiple_copy_atomic_cpu, "no leading membar expected");
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   291
        Node* mb = kit->insert_mem_bar(Op_MemBarAcquire, n);
d7029542d67a 8209420: Track membars for volatile accesses so they can be properly optimized
roland
parents: 50599
diff changeset
   292
        mb->as_MemBar()->set_trailing_load();
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   293
      }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   294
    }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   295
  }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   296
};
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   297
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   298
Node* BarrierSetC2::store_at(C2Access& access, C2AccessValue& val) const {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   299
  C2AccessFence fence(access);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   300
  resolve_address(access);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   301
  return store_at_resolved(access, val);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   302
}
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   303
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   304
Node* BarrierSetC2::load_at(C2Access& access, const Type* val_type) const {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   305
  C2AccessFence fence(access);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   306
  resolve_address(access);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   307
  return load_at_resolved(access, val_type);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   308
}
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   309
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   310
MemNode::MemOrd C2Access::mem_node_mo() const {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   311
  bool is_write = (_decorators & C2_WRITE_ACCESS) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   312
  bool is_read = (_decorators & C2_READ_ACCESS) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   313
  if ((_decorators & MO_SEQ_CST) != 0) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   314
    if (is_write && is_read) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   315
      // For atomic operations
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   316
      return MemNode::seqcst;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   317
    } else if (is_write) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   318
      return MemNode::release;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   319
    } else {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   320
      assert(is_read, "what else?");
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   321
      return MemNode::acquire;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   322
    }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   323
  } else if ((_decorators & MO_RELEASE) != 0) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   324
    return MemNode::release;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   325
  } else if ((_decorators & MO_ACQUIRE) != 0) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   326
    return MemNode::acquire;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   327
  } else if (is_write) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   328
    // Volatile fields need releasing stores.
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   329
    // Non-volatile fields also need releasing stores if they hold an
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   330
    // object reference, because the object reference might point to
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   331
    // a freshly created object.
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   332
    // Conservatively release stores of object references.
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   333
    return StoreNode::release_if_reference(_type);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   334
  } else {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   335
    return MemNode::unordered;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   336
  }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   337
}
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   338
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   339
void C2Access::fixup_decorators() {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   340
  bool default_mo = (_decorators & MO_DECORATOR_MASK) == 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   341
  bool is_unordered = (_decorators & MO_UNORDERED) != 0 || default_mo;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   342
  bool anonymous = (_decorators & C2_UNSAFE_ACCESS) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   343
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   344
  bool is_read = (_decorators & C2_READ_ACCESS) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   345
  bool is_write = (_decorators & C2_WRITE_ACCESS) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   346
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   347
  if (AlwaysAtomicAccesses && is_unordered) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   348
    _decorators &= ~MO_DECORATOR_MASK; // clear the MO bits
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   349
    _decorators |= MO_RELAXED; // Force the MO_RELAXED decorator with AlwaysAtomicAccess
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   350
  }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   351
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   352
  _decorators = AccessInternal::decorator_fixup(_decorators);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   353
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   354
  if (is_read && !is_write && anonymous) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   355
    // To be valid, unsafe loads may depend on other conditions than
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   356
    // the one that guards them: pin the Load node
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   357
    _decorators |= C2_CONTROL_DEPENDENT_LOAD;
57582
a79a819a8218 8227407: ZGC: C2 loads and load barriers can get separated by safepoints
eosterlund
parents: 53765
diff changeset
   358
    _decorators |= C2_UNKNOWN_CONTROL_LOAD;
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   359
    const TypePtr* adr_type = _addr.type();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   360
    Node* adr = _addr.node();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   361
    if (!needs_cpu_membar() && adr_type->isa_instptr()) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   362
      assert(adr_type->meet(TypePtr::NULL_PTR) != adr_type->remove_speculative(), "should be not null");
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   363
      intptr_t offset = Type::OffsetBot;
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   364
      AddPNode::Ideal_base_and_offset(adr, &gvn(), offset);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   365
      if (offset >= 0) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   366
        int s = Klass::layout_helper_size_in_bytes(adr_type->isa_instptr()->klass()->layout_helper());
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   367
        if (offset < s) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   368
          // Guaranteed to be a valid access, no need to pin it
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   369
          _decorators ^= C2_CONTROL_DEPENDENT_LOAD;
57582
a79a819a8218 8227407: ZGC: C2 loads and load barriers can get separated by safepoints
eosterlund
parents: 53765
diff changeset
   370
          _decorators ^= C2_UNKNOWN_CONTROL_LOAD;
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   371
        }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   372
      }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   373
    }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   374
  }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   375
}
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   376
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   377
//--------------------------- atomic operations---------------------------------
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   378
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   379
void BarrierSetC2::pin_atomic_op(C2AtomicParseAccess& access) const {
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   380
  if (!access.needs_pinning()) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   381
    return;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   382
  }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   383
  // SCMemProjNodes represent the memory state of a LoadStore. Their
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   384
  // main role is to prevent LoadStore nodes from being optimized away
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   385
  // when their results aren't used.
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   386
  assert(access.is_parse_access(), "entry not supported at optimization time");
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   387
  C2ParseAccess& parse_access = static_cast<C2ParseAccess&>(access);
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   388
  GraphKit* kit = parse_access.kit();
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   389
  Node* load_store = access.raw_access();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   390
  assert(load_store != NULL, "must pin atomic op");
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   391
  Node* proj = kit->gvn().transform(new SCMemProjNode(load_store));
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   392
  kit->set_memory(proj, access.alias_idx());
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   393
}
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   394
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   395
void C2AtomicParseAccess::set_memory() {
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   396
  Node *mem = _kit->memory(_alias_idx);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   397
  _memory = mem;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   398
}
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   399
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   400
Node* BarrierSetC2::atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   401
                                                   Node* new_val, const Type* value_type) const {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   402
  GraphKit* kit = access.kit();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   403
  MemNode::MemOrd mo = access.mem_node_mo();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   404
  Node* mem = access.memory();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   405
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   406
  Node* adr = access.addr().node();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   407
  const TypePtr* adr_type = access.addr().type();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   408
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   409
  Node* load_store = NULL;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   410
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   411
  if (access.is_oop()) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   412
#ifdef _LP64
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   413
    if (adr->bottom_type()->is_ptr_to_narrowoop()) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   414
      Node *newval_enc = kit->gvn().transform(new EncodePNode(new_val, new_val->bottom_type()->make_narrowoop()));
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   415
      Node *oldval_enc = kit->gvn().transform(new EncodePNode(expected_val, expected_val->bottom_type()->make_narrowoop()));
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   416
      load_store = new CompareAndExchangeNNode(kit->control(), mem, adr, newval_enc, oldval_enc, adr_type, value_type->make_narrowoop(), mo);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   417
    } else
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   418
#endif
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   419
    {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   420
      load_store = new CompareAndExchangePNode(kit->control(), mem, adr, new_val, expected_val, adr_type, value_type->is_oopptr(), mo);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   421
    }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   422
  } else {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   423
    switch (access.type()) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   424
      case T_BYTE: {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   425
        load_store = new CompareAndExchangeBNode(kit->control(), mem, adr, new_val, expected_val, adr_type, mo);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   426
        break;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   427
      }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   428
      case T_SHORT: {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   429
        load_store = new CompareAndExchangeSNode(kit->control(), mem, adr, new_val, expected_val, adr_type, mo);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   430
        break;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   431
      }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   432
      case T_INT: {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   433
        load_store = new CompareAndExchangeINode(kit->control(), mem, adr, new_val, expected_val, adr_type, mo);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   434
        break;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   435
      }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   436
      case T_LONG: {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   437
        load_store = new CompareAndExchangeLNode(kit->control(), mem, adr, new_val, expected_val, adr_type, mo);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   438
        break;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   439
      }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   440
      default:
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   441
        ShouldNotReachHere();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   442
    }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   443
  }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   444
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   445
  load_store->as_LoadStore()->set_barrier_data(access.barrier_data());
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   446
  load_store = kit->gvn().transform(load_store);
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   447
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   448
  access.set_raw_access(load_store);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   449
  pin_atomic_op(access);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   450
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   451
#ifdef _LP64
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   452
  if (access.is_oop() && adr->bottom_type()->is_ptr_to_narrowoop()) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   453
    return kit->gvn().transform(new DecodeNNode(load_store, load_store->get_ptr_type()));
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   454
  }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   455
#endif
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   456
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   457
  return load_store;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   458
}
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   459
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   460
Node* BarrierSetC2::atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   461
                                                    Node* new_val, const Type* value_type) const {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   462
  GraphKit* kit = access.kit();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   463
  DecoratorSet decorators = access.decorators();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   464
  MemNode::MemOrd mo = access.mem_node_mo();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   465
  Node* mem = access.memory();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   466
  bool is_weak_cas = (decorators & C2_WEAK_CMPXCHG) != 0;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   467
  Node* load_store = NULL;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   468
  Node* adr = access.addr().node();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   469
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   470
  if (access.is_oop()) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   471
#ifdef _LP64
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   472
    if (adr->bottom_type()->is_ptr_to_narrowoop()) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   473
      Node *newval_enc = kit->gvn().transform(new EncodePNode(new_val, new_val->bottom_type()->make_narrowoop()));
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   474
      Node *oldval_enc = kit->gvn().transform(new EncodePNode(expected_val, expected_val->bottom_type()->make_narrowoop()));
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   475
      if (is_weak_cas) {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   476
        load_store = new WeakCompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   477
      } else {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   478
        load_store = new CompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   479
      }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   480
    } else
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   481
#endif
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   482
    {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   483
      if (is_weak_cas) {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   484
        load_store = new WeakCompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   485
      } else {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   486
        load_store = new CompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   487
      }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   488
    }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   489
  } else {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   490
    switch(access.type()) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   491
      case T_BYTE: {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   492
        if (is_weak_cas) {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   493
          load_store = new WeakCompareAndSwapBNode(kit->control(), mem, adr, new_val, expected_val, mo);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   494
        } else {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   495
          load_store = new CompareAndSwapBNode(kit->control(), mem, adr, new_val, expected_val, mo);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   496
        }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   497
        break;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   498
      }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   499
      case T_SHORT: {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   500
        if (is_weak_cas) {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   501
          load_store = new WeakCompareAndSwapSNode(kit->control(), mem, adr, new_val, expected_val, mo);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   502
        } else {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   503
          load_store = new CompareAndSwapSNode(kit->control(), mem, adr, new_val, expected_val, mo);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   504
        }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   505
        break;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   506
      }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   507
      case T_INT: {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   508
        if (is_weak_cas) {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   509
          load_store = new WeakCompareAndSwapINode(kit->control(), mem, adr, new_val, expected_val, mo);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   510
        } else {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   511
          load_store = new CompareAndSwapINode(kit->control(), mem, adr, new_val, expected_val, mo);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   512
        }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   513
        break;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   514
      }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   515
      case T_LONG: {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   516
        if (is_weak_cas) {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   517
          load_store = new WeakCompareAndSwapLNode(kit->control(), mem, adr, new_val, expected_val, mo);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   518
        } else {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   519
          load_store = new CompareAndSwapLNode(kit->control(), mem, adr, new_val, expected_val, mo);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   520
        }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   521
        break;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   522
      }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   523
      default:
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   524
        ShouldNotReachHere();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   525
    }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   526
  }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   527
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   528
  load_store->as_LoadStore()->set_barrier_data(access.barrier_data());
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   529
  load_store = kit->gvn().transform(load_store);
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   530
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   531
  access.set_raw_access(load_store);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   532
  pin_atomic_op(access);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   533
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   534
  return load_store;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   535
}
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   536
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   537
Node* BarrierSetC2::atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* new_val, const Type* value_type) const {
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   538
  GraphKit* kit = access.kit();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   539
  Node* mem = access.memory();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   540
  Node* adr = access.addr().node();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   541
  const TypePtr* adr_type = access.addr().type();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   542
  Node* load_store = NULL;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   543
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   544
  if (access.is_oop()) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   545
#ifdef _LP64
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   546
    if (adr->bottom_type()->is_ptr_to_narrowoop()) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   547
      Node *newval_enc = kit->gvn().transform(new EncodePNode(new_val, new_val->bottom_type()->make_narrowoop()));
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   548
      load_store = kit->gvn().transform(new GetAndSetNNode(kit->control(), mem, adr, newval_enc, adr_type, value_type->make_narrowoop()));
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   549
    } else
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   550
#endif
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   551
    {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   552
      load_store = new GetAndSetPNode(kit->control(), mem, adr, new_val, adr_type, value_type->is_oopptr());
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   553
    }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   554
  } else  {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   555
    switch (access.type()) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   556
      case T_BYTE:
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   557
        load_store = new GetAndSetBNode(kit->control(), mem, adr, new_val, adr_type);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   558
        break;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   559
      case T_SHORT:
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   560
        load_store = new GetAndSetSNode(kit->control(), mem, adr, new_val, adr_type);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   561
        break;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   562
      case T_INT:
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   563
        load_store = new GetAndSetINode(kit->control(), mem, adr, new_val, adr_type);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   564
        break;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   565
      case T_LONG:
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   566
        load_store = new GetAndSetLNode(kit->control(), mem, adr, new_val, adr_type);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   567
        break;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   568
      default:
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   569
        ShouldNotReachHere();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   570
    }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   571
  }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   572
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   573
  load_store->as_LoadStore()->set_barrier_data(access.barrier_data());
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   574
  load_store = kit->gvn().transform(load_store);
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   575
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   576
  access.set_raw_access(load_store);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   577
  pin_atomic_op(access);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   578
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   579
#ifdef _LP64
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   580
  if (access.is_oop() && adr->bottom_type()->is_ptr_to_narrowoop()) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   581
    return kit->gvn().transform(new DecodeNNode(load_store, load_store->get_ptr_type()));
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   582
  }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   583
#endif
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   584
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   585
  return load_store;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   586
}
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   587
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   588
Node* BarrierSetC2::atomic_add_at_resolved(C2AtomicParseAccess& access, Node* new_val, const Type* value_type) const {
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   589
  Node* load_store = NULL;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   590
  GraphKit* kit = access.kit();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   591
  Node* adr = access.addr().node();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   592
  const TypePtr* adr_type = access.addr().type();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   593
  Node* mem = access.memory();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   594
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   595
  switch(access.type()) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   596
    case T_BYTE:
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   597
      load_store = new GetAndAddBNode(kit->control(), mem, adr, new_val, adr_type);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   598
      break;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   599
    case T_SHORT:
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   600
      load_store = new GetAndAddSNode(kit->control(), mem, adr, new_val, adr_type);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   601
      break;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   602
    case T_INT:
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   603
      load_store = new GetAndAddINode(kit->control(), mem, adr, new_val, adr_type);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   604
      break;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   605
    case T_LONG:
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   606
      load_store = new GetAndAddLNode(kit->control(), mem, adr, new_val, adr_type);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   607
      break;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   608
    default:
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   609
      ShouldNotReachHere();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   610
  }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   611
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   612
  load_store->as_LoadStore()->set_barrier_data(access.barrier_data());
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   613
  load_store = kit->gvn().transform(load_store);
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58931
diff changeset
   614
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   615
  access.set_raw_access(load_store);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   616
  pin_atomic_op(access);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   617
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   618
  return load_store;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   619
}
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   620
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   621
Node* BarrierSetC2::atomic_cmpxchg_val_at(C2AtomicParseAccess& access, Node* expected_val,
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   622
                                          Node* new_val, const Type* value_type) const {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   623
  C2AccessFence fence(access);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   624
  resolve_address(access);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   625
  return atomic_cmpxchg_val_at_resolved(access, expected_val, new_val, value_type);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   626
}
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   627
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   628
Node* BarrierSetC2::atomic_cmpxchg_bool_at(C2AtomicParseAccess& access, Node* expected_val,
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   629
                                           Node* new_val, const Type* value_type) const {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   630
  C2AccessFence fence(access);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   631
  resolve_address(access);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   632
  return atomic_cmpxchg_bool_at_resolved(access, expected_val, new_val, value_type);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   633
}
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   634
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   635
Node* BarrierSetC2::atomic_xchg_at(C2AtomicParseAccess& access, Node* new_val, const Type* value_type) const {
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   636
  C2AccessFence fence(access);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   637
  resolve_address(access);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   638
  return atomic_xchg_at_resolved(access, new_val, value_type);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   639
}
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   640
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   641
Node* BarrierSetC2::atomic_add_at(C2AtomicParseAccess& access, Node* new_val, const Type* value_type) const {
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   642
  C2AccessFence fence(access);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   643
  resolve_address(access);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   644
  return atomic_add_at_resolved(access, new_val, value_type);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   645
}
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   646
59324
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   647
int BarrierSetC2::arraycopy_payload_base_offset(bool is_array) {
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   648
  // Exclude the header but include array length to copy by 8 bytes words.
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   649
  // Can't use base_offset_in_bytes(bt) since basic type is unknown.
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   650
  int base_off = is_array ? arrayOopDesc::length_offset_in_bytes() :
59324
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   651
                 instanceOopDesc::base_offset_in_bytes();
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   652
  // base_off:
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   653
  // 8  - 32-bit VM
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   654
  // 12 - 64-bit VM, compressed klass
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   655
  // 16 - 64-bit VM, normal klass
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   656
  if (base_off % BytesPerLong != 0) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   657
    assert(UseCompressedClassPointers, "");
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   658
    if (is_array) {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   659
      // Exclude length to copy by 8 bytes words.
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   660
      base_off += sizeof(int);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   661
    } else {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   662
      // Include klass to copy by 8 bytes words.
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   663
      base_off = instanceOopDesc::klass_offset_in_bytes();
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   664
    }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   665
    assert(base_off % BytesPerLong == 0, "expect 8 bytes alignment");
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   666
  }
59324
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   667
  return base_off;
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   668
}
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   669
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   670
void BarrierSetC2::clone(GraphKit* kit, Node* src_base, Node* dst_base, Node* size, bool is_array) const {
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   671
  int base_off = arraycopy_payload_base_offset(is_array);
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   672
  Node* payload_src = kit->basic_plus_adr(src_base,  base_off);
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   673
  Node* payload_dst = kit->basic_plus_adr(dst_base, base_off);
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   674
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   675
  // Compute the length also, if needed:
59324
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   676
  Node* payload_size = size;
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   677
  payload_size = kit->gvn().transform(new SubXNode(payload_size, kit->MakeConX(base_off)));
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   678
  payload_size = kit->gvn().transform(new URShiftXNode(payload_size, kit->intcon(LogBytesPerLong) ));
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   679
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   680
  const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM;
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   681
59324
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   682
  ArrayCopyNode* ac = ArrayCopyNode::make(kit, false, payload_src, NULL, payload_dst, NULL, payload_size, true, false);
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   683
  if (is_array) {
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   684
    ac->set_clone_array();
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   685
  } else {
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   686
    ac->set_clone_inst();
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   687
  }
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   688
  Node* n = kit->gvn().transform(ac);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   689
  if (n == ac) {
51984
2ef304ee001d 8210887: Tweak C2 gc api for arraycopy
roland
parents: 51880
diff changeset
   690
    ac->_adr_type = TypeRawPtr::BOTTOM;
50180
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   691
    kit->set_predefined_output_for_runtime_call(ac, ac->in(TypeFunc::Memory), raw_adr_type);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   692
  } else {
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   693
    kit->set_all_memory(n);
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   694
  }
ffa644980dff 8202377: Modularize C2 GC barriers
eosterlund
parents:
diff changeset
   695
}
51806
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   696
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   697
Node* BarrierSetC2::obj_allocate(PhaseMacroExpand* macro, Node* ctrl, Node* mem, Node* toobig_false, Node* size_in_bytes,
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   698
                                 Node*& i_o, Node*& needgc_ctrl,
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   699
                                 Node*& fast_oop_ctrl, Node*& fast_oop_rawmem,
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   700
                                 intx prefetch_lines) const {
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   701
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   702
  Node* eden_top_adr;
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   703
  Node* eden_end_adr;
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   704
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   705
  macro->set_eden_pointers(eden_top_adr, eden_end_adr);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   706
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   707
  // Load Eden::end.  Loop invariant and hoisted.
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   708
  //
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   709
  // Note: We set the control input on "eden_end" and "old_eden_top" when using
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   710
  //       a TLAB to work around a bug where these values were being moved across
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   711
  //       a safepoint.  These are not oops, so they cannot be include in the oop
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   712
  //       map, but they can be changed by a GC.   The proper way to fix this would
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   713
  //       be to set the raw memory state when generating a  SafepointNode.  However
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   714
  //       this will require extensive changes to the loop optimization in order to
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   715
  //       prevent a degradation of the optimization.
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   716
  //       See comment in memnode.hpp, around line 227 in class LoadPNode.
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   717
  Node *eden_end = macro->make_load(ctrl, mem, eden_end_adr, 0, TypeRawPtr::BOTTOM, T_ADDRESS);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   718
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   719
  // We need a Region for the loop-back contended case.
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   720
  enum { fall_in_path = 1, contended_loopback_path = 2 };
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   721
  Node *contended_region;
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   722
  Node *contended_phi_rawmem;
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   723
  if (UseTLAB) {
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   724
    contended_region = toobig_false;
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   725
    contended_phi_rawmem = mem;
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   726
  } else {
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   727
    contended_region = new RegionNode(3);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   728
    contended_phi_rawmem = new PhiNode(contended_region, Type::MEMORY, TypeRawPtr::BOTTOM);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   729
    // Now handle the passing-too-big test.  We fall into the contended
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   730
    // loop-back merge point.
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   731
    contended_region    ->init_req(fall_in_path, toobig_false);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   732
    contended_phi_rawmem->init_req(fall_in_path, mem);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   733
    macro->transform_later(contended_region);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   734
    macro->transform_later(contended_phi_rawmem);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   735
  }
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   736
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   737
  // Load(-locked) the heap top.
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   738
  // See note above concerning the control input when using a TLAB
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   739
  Node *old_eden_top = UseTLAB
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   740
    ? new LoadPNode      (ctrl, contended_phi_rawmem, eden_top_adr, TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM, MemNode::unordered)
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   741
    : new LoadPLockedNode(contended_region, contended_phi_rawmem, eden_top_adr, MemNode::acquire);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   742
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   743
  macro->transform_later(old_eden_top);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   744
  // Add to heap top to get a new heap top
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   745
  Node *new_eden_top = new AddPNode(macro->top(), old_eden_top, size_in_bytes);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   746
  macro->transform_later(new_eden_top);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   747
  // Check for needing a GC; compare against heap end
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   748
  Node *needgc_cmp = new CmpPNode(new_eden_top, eden_end);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   749
  macro->transform_later(needgc_cmp);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   750
  Node *needgc_bol = new BoolNode(needgc_cmp, BoolTest::ge);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   751
  macro->transform_later(needgc_bol);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   752
  IfNode *needgc_iff = new IfNode(contended_region, needgc_bol, PROB_UNLIKELY_MAG(4), COUNT_UNKNOWN);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   753
  macro->transform_later(needgc_iff);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   754
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   755
  // Plug the failing-heap-space-need-gc test into the slow-path region
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   756
  Node *needgc_true = new IfTrueNode(needgc_iff);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   757
  macro->transform_later(needgc_true);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   758
  needgc_ctrl = needgc_true;
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   759
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   760
  // No need for a GC.  Setup for the Store-Conditional
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   761
  Node *needgc_false = new IfFalseNode(needgc_iff);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   762
  macro->transform_later(needgc_false);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   763
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   764
  i_o = macro->prefetch_allocation(i_o, needgc_false, contended_phi_rawmem,
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   765
                                   old_eden_top, new_eden_top, prefetch_lines);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   766
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   767
  Node* fast_oop = old_eden_top;
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   768
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   769
  // Store (-conditional) the modified eden top back down.
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   770
  // StorePConditional produces flags for a test PLUS a modified raw
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   771
  // memory state.
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   772
  if (UseTLAB) {
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   773
    Node* store_eden_top =
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   774
      new StorePNode(needgc_false, contended_phi_rawmem, eden_top_adr,
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   775
                     TypeRawPtr::BOTTOM, new_eden_top, MemNode::unordered);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   776
    macro->transform_later(store_eden_top);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   777
    fast_oop_ctrl = needgc_false; // No contention, so this is the fast path
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   778
    fast_oop_rawmem = store_eden_top;
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   779
  } else {
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   780
    Node* store_eden_top =
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   781
      new StorePConditionalNode(needgc_false, contended_phi_rawmem, eden_top_adr,
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   782
                                new_eden_top, fast_oop/*old_eden_top*/);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   783
    macro->transform_later(store_eden_top);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   784
    Node *contention_check = new BoolNode(store_eden_top, BoolTest::ne);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   785
    macro->transform_later(contention_check);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   786
    store_eden_top = new SCMemProjNode(store_eden_top);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   787
    macro->transform_later(store_eden_top);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   788
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   789
    // If not using TLABs, check to see if there was contention.
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   790
    IfNode *contention_iff = new IfNode (needgc_false, contention_check, PROB_MIN, COUNT_UNKNOWN);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   791
    macro->transform_later(contention_iff);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   792
    Node *contention_true = new IfTrueNode(contention_iff);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   793
    macro->transform_later(contention_true);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   794
    // If contention, loopback and try again.
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   795
    contended_region->init_req(contended_loopback_path, contention_true);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   796
    contended_phi_rawmem->init_req(contended_loopback_path, store_eden_top);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   797
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   798
    // Fast-path succeeded with no contention!
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   799
    Node *contention_false = new IfFalseNode(contention_iff);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   800
    macro->transform_later(contention_false);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   801
    fast_oop_ctrl = contention_false;
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   802
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   803
    // Bump total allocated bytes for this thread
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   804
    Node* thread = new ThreadLocalNode();
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   805
    macro->transform_later(thread);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   806
    Node* alloc_bytes_adr = macro->basic_plus_adr(macro->top()/*not oop*/, thread,
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   807
                                                  in_bytes(JavaThread::allocated_bytes_offset()));
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   808
    Node* alloc_bytes = macro->make_load(fast_oop_ctrl, store_eden_top, alloc_bytes_adr,
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   809
                                         0, TypeLong::LONG, T_LONG);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   810
#ifdef _LP64
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   811
    Node* alloc_size = size_in_bytes;
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   812
#else
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   813
    Node* alloc_size = new ConvI2LNode(size_in_bytes);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   814
    macro->transform_later(alloc_size);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   815
#endif
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   816
    Node* new_alloc_bytes = new AddLNode(alloc_bytes, alloc_size);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   817
    macro->transform_later(new_alloc_bytes);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   818
    fast_oop_rawmem = macro->make_store(fast_oop_ctrl, store_eden_top, alloc_bytes_adr,
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   819
                                        0, new_alloc_bytes, T_LONG);
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   820
  }
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   821
  return fast_oop;
1ecc914fb707 8210829: Modularize allocations in C2
rkennke
parents: 51485
diff changeset
   822
}
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   823
58217
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   824
#define XTOP LP64_ONLY(COMMA phase->top())
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   825
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   826
void BarrierSetC2::clone_at_expansion(PhaseMacroExpand* phase, ArrayCopyNode* ac) const {
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   827
  Node* ctrl = ac->in(TypeFunc::Control);
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   828
  Node* mem = ac->in(TypeFunc::Memory);
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   829
  Node* src = ac->in(ArrayCopyNode::Src);
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   830
  Node* src_offset = ac->in(ArrayCopyNode::SrcPos);
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   831
  Node* dest = ac->in(ArrayCopyNode::Dest);
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   832
  Node* dest_offset = ac->in(ArrayCopyNode::DestPos);
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   833
  Node* length = ac->in(ArrayCopyNode::Length);
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   834
58931
304c63b17b07 8232896: ZGC: Enable C2 clone intrinsic
neliasso
parents: 58217
diff changeset
   835
  assert (src_offset == NULL,  "for clone offsets should be null");
304c63b17b07 8232896: ZGC: Enable C2 clone intrinsic
neliasso
parents: 58217
diff changeset
   836
  assert (dest_offset == NULL, "for clone offsets should be null");
58217
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   837
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   838
  const char* copyfunc_name = "arraycopy";
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   839
  address     copyfunc_addr =
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   840
          phase->basictype2arraycopy(T_LONG, NULL, NULL,
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   841
                              true, copyfunc_name, true);
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   842
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   843
  const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM;
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   844
  const TypeFunc* call_type = OptoRuntime::fast_arraycopy_Type();
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   845
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   846
  Node* call = phase->make_leaf_call(ctrl, mem, call_type, copyfunc_addr, copyfunc_name, raw_adr_type, src, dest, length XTOP);
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   847
  phase->transform_later(call);
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   848
b1a394e15ae9 8231085: C2/GC: Better GC-interface for expanding clone
rkennke
parents: 57582
diff changeset
   849
  phase->igvn().replace_node(ac, call);
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 51984
diff changeset
   850
}