src/hotspot/share/gc/z/c2/zBarrierSetC2.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:
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     1
/*
53223
df6cbf676c70 8215708: ZGC: Add missing LoadBarrierNode::size_of()
pliden
parents: 52829
diff changeset
     2
 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     4
 *
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     7
 * published by the Free Software Foundation.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     8
 *
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    13
 * accompanied this code).
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    14
 *
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    18
 *
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    21
 * questions.
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    22
 */
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    23
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    24
#include "precompiled.hpp"
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    25
#include "classfile/javaClasses.hpp"
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    26
#include "gc/z/c2/zBarrierSetC2.hpp"
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    27
#include "gc/z/zBarrierSet.hpp"
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    28
#include "gc/z/zBarrierSetAssembler.hpp"
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    29
#include "gc/z/zBarrierSetRuntime.hpp"
58931
304c63b17b07 8232896: ZGC: Enable C2 clone intrinsic
neliasso
parents: 58516
diff changeset
    30
#include "opto/arraycopynode.hpp"
59324
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
    31
#include "opto/addnode.hpp"
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    32
#include "opto/block.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    33
#include "opto/compile.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    34
#include "opto/graphKit.hpp"
55307
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
    35
#include "opto/machnode.hpp"
58931
304c63b17b07 8232896: ZGC: Enable C2 clone intrinsic
neliasso
parents: 58516
diff changeset
    36
#include "opto/macro.hpp"
55307
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
    37
#include "opto/memnode.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    38
#include "opto/node.hpp"
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    39
#include "opto/regalloc.hpp"
55307
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
    40
#include "opto/rootnode.hpp"
58958
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
    41
#include "opto/type.hpp"
55307
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
    42
#include "utilities/growableArray.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    43
#include "utilities/macros.hpp"
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    44
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    45
class ZBarrierSetC2State : public ResourceObj {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    46
private:
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    47
  GrowableArray<ZLoadBarrierStubC2*>* _stubs;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    48
  Node_Array                          _live;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    49
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    50
public:
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    51
  ZBarrierSetC2State(Arena* arena) :
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    52
    _stubs(new (arena) GrowableArray<ZLoadBarrierStubC2*>(arena, 8,  0, NULL)),
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    53
    _live(arena) {}
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    54
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    55
  GrowableArray<ZLoadBarrierStubC2*>* stubs() {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    56
    return _stubs;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    57
  }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    58
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    59
  RegMask* live(const Node* node) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    60
    if (!node->is_Mach()) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    61
      // Don't need liveness for non-MachNodes
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    62
      return NULL;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    63
    }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    64
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    65
    const MachNode* const mach = node->as_Mach();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    66
    if (mach->barrier_data() != ZLoadBarrierStrong &&
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    67
        mach->barrier_data() != ZLoadBarrierWeak) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    68
      // Don't need liveness data for nodes without barriers
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    69
      return NULL;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    70
    }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    71
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    72
    RegMask* live = (RegMask*)_live[node->_idx];
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    73
    if (live == NULL) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    74
      live = new (Compile::current()->comp_arena()->Amalloc_D(sizeof(RegMask))) RegMask();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    75
      _live.map(node->_idx, (Node*)live);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    76
    }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    77
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    78
    return live;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    79
  }
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    80
};
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    81
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    82
static ZBarrierSetC2State* barrier_set_state() {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    83
  return reinterpret_cast<ZBarrierSetC2State*>(Compile::current()->barrier_set_state());
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    84
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    85
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    86
ZLoadBarrierStubC2* ZLoadBarrierStubC2::create(const MachNode* node, Address ref_addr, Register ref, Register tmp, bool weak) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    87
  ZLoadBarrierStubC2* const stub = new (Compile::current()->comp_arena()) ZLoadBarrierStubC2(node, ref_addr, ref, tmp, weak);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    88
  if (!Compile::current()->in_scratch_emit_size()) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    89
    barrier_set_state()->stubs()->append(stub);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    90
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    91
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    92
  return stub;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    93
}
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    94
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    95
ZLoadBarrierStubC2::ZLoadBarrierStubC2(const MachNode* node, Address ref_addr, Register ref, Register tmp, bool weak) :
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    96
    _node(node),
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    97
    _ref_addr(ref_addr),
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    98
    _ref(ref),
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
    99
    _tmp(tmp),
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   100
    _weak(weak),
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   101
    _entry(),
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   102
    _continuation() {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   103
  assert_different_registers(ref, ref_addr.base());
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   104
  assert_different_registers(ref, ref_addr.index());
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   105
}
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   106
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   107
Address ZLoadBarrierStubC2::ref_addr() const {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   108
  return _ref_addr;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   109
}
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   110
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   111
Register ZLoadBarrierStubC2::ref() const {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   112
  return _ref;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   113
}
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   114
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   115
Register ZLoadBarrierStubC2::tmp() const {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   116
  return _tmp;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   117
}
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   118
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   119
address ZLoadBarrierStubC2::slow_path() const {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   120
  const DecoratorSet decorators = _weak ? ON_WEAK_OOP_REF : ON_STRONG_OOP_REF;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   121
  return ZBarrierSetRuntime::load_barrier_on_oop_field_preloaded_addr(decorators);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   122
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   123
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   124
RegMask& ZLoadBarrierStubC2::live() const {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   125
  return *barrier_set_state()->live(_node);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   126
}
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   127
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   128
Label* ZLoadBarrierStubC2::entry() {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   129
  // The _entry will never be bound when in_scratch_emit_size() is true.
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   130
  // However, we still need to return a label that is not bound now, but
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   131
  // will eventually be bound. Any lable will do, as it will only act as
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   132
  // a placeholder, so we return the _continuation label.
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   133
  return Compile::current()->in_scratch_emit_size() ? &_continuation : &_entry;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   134
}
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   135
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   136
Label* ZLoadBarrierStubC2::continuation() {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   137
  return &_continuation;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   138
}
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   139
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   140
void* ZBarrierSetC2::create_barrier_state(Arena* comp_arena) const {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   141
  return new (comp_arena) ZBarrierSetC2State(comp_arena);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   142
}
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   143
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   144
void ZBarrierSetC2::late_barrier_analysis() const {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   145
  analyze_dominating_barriers();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   146
  compute_liveness_at_stubs();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   147
}
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   148
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   149
void ZBarrierSetC2::emit_stubs(CodeBuffer& cb) const {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   150
  MacroAssembler masm(&cb);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   151
  GrowableArray<ZLoadBarrierStubC2*>* const stubs = barrier_set_state()->stubs();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   152
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   153
  for (int i = 0; i < stubs->length(); i++) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   154
    // Make sure there is enough space in the code buffer
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   155
    if (cb.insts()->maybe_expand_to_ensure_remaining(Compile::MAX_inst_size) && cb.blob() == NULL) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   156
      ciEnv::current()->record_failure("CodeCache is full");
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   157
      return;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   158
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   159
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   160
    ZBarrierSet::assembler()->generate_c2_load_barrier_stub(&masm, stubs->at(i));
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   161
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   162
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   163
  masm.flush();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   164
}
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   165
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   166
int ZBarrierSetC2::estimate_stub_size() const {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   167
  Compile* const C = Compile::current();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   168
  BufferBlob* const blob = C->scratch_buffer_blob();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   169
  GrowableArray<ZLoadBarrierStubC2*>* const stubs = barrier_set_state()->stubs();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   170
  int size = 0;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   171
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   172
  for (int i = 0; i < stubs->length(); i++) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   173
    CodeBuffer cb(blob->content_begin(), (address)C->scratch_locs_memory() - blob->content_begin());
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   174
    MacroAssembler masm(&cb);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   175
    ZBarrierSet::assembler()->generate_c2_load_barrier_stub(&masm, stubs->at(i));
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   176
    size += cb.insts_size();
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   177
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   178
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   179
  return size;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   180
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   181
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58965
diff changeset
   182
static void set_barrier_data(C2Access& access) {
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58965
diff changeset
   183
  if (ZBarrierSet::barrier_needed(access.decorators(), access.type())) {
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58965
diff changeset
   184
    if (access.decorators() & ON_WEAK_OOP_REF) {
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58965
diff changeset
   185
      access.set_barrier_data(ZLoadBarrierWeak);
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58965
diff changeset
   186
    } else {
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58965
diff changeset
   187
      access.set_barrier_data(ZLoadBarrierStrong);
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58965
diff changeset
   188
    }
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58965
diff changeset
   189
  }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   190
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   191
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   192
Node* ZBarrierSetC2::load_at_resolved(C2Access& access, const Type* val_type) const {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58965
diff changeset
   193
  set_barrier_data(access);
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58965
diff changeset
   194
  return BarrierSetC2::load_at_resolved(access, val_type);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   195
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   196
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 52224
diff changeset
   197
Node* ZBarrierSetC2::atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   198
                                                    Node* new_val, const Type* val_type) const {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58965
diff changeset
   199
  set_barrier_data(access);
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58965
diff changeset
   200
  return BarrierSetC2::atomic_cmpxchg_val_at_resolved(access, expected_val, new_val, val_type);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   201
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   202
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 52224
diff changeset
   203
Node* ZBarrierSetC2::atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   204
                                                     Node* new_val, const Type* value_type) const {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58965
diff changeset
   205
  set_barrier_data(access);
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58965
diff changeset
   206
  return BarrierSetC2::atomic_cmpxchg_bool_at_resolved(access, expected_val, new_val, value_type);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   207
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   208
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 52224
diff changeset
   209
Node* ZBarrierSetC2::atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* new_val, const Type* val_type) const {
59025
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58965
diff changeset
   210
  set_barrier_data(access);
b398685dd029 8233506: ZGC: the load for Reference.get() can be converted to a load for strong refs
eosterlund
parents: 58965
diff changeset
   211
  return BarrierSetC2::atomic_xchg_at_resolved(access, new_val, val_type);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   212
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   213
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   214
bool ZBarrierSetC2::array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type,
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   215
                                                    bool is_clone, ArrayCopyPhase phase) const {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   216
  return type == T_OBJECT || type == T_ARRAY;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   217
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   218
59324
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   219
// This TypeFunc assumes a 64bit system
58958
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   220
static const TypeFunc* clone_type() {
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   221
  // Create input type (domain)
59324
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   222
  const Type** domain_fields = TypeTuple::fields(4);
58958
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   223
  domain_fields[TypeFunc::Parms + 0] = TypeInstPtr::NOTNULL;  // src
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   224
  domain_fields[TypeFunc::Parms + 1] = TypeInstPtr::NOTNULL;  // dst
59324
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   225
  domain_fields[TypeFunc::Parms + 2] = TypeLong::LONG;        // size lower
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   226
  domain_fields[TypeFunc::Parms + 3] = Type::HALF;            // size upper
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   227
  const TypeTuple* domain = TypeTuple::make(TypeFunc::Parms + 4, domain_fields);
58958
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   228
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   229
  // Create result type (range)
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   230
  const Type** range_fields = TypeTuple::fields(0);
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   231
  const TypeTuple* range = TypeTuple::make(TypeFunc::Parms + 0, range_fields);
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   232
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   233
  return TypeFunc::make(domain, range);
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   234
}
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   235
59324
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   236
// Node n is pointing to the start of oop payload - return base pointer
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   237
static Node* get_base_for_arracycopy_clone(PhaseMacroExpand* phase, Node* n) {
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   238
  // This would normally be handled by optimizations, but the type system
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   239
  // checks get confused when it thinks it already has a base pointer.
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   240
  const int base_offset = BarrierSetC2::arraycopy_payload_base_offset(false);
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   241
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   242
  if (n->is_AddP() &&
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   243
      n->in(AddPNode::Offset)->is_Con() &&
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   244
      n->in(AddPNode::Offset)->get_long() == base_offset) {
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   245
    assert(n->in(AddPNode::Base) == n->in(AddPNode::Address), "Sanity check");
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   246
    return n->in(AddPNode::Base);
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   247
  } else {
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   248
    return phase->basic_plus_adr(n, phase->longcon(-base_offset));
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   249
  }
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   250
}
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   251
58958
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   252
void ZBarrierSetC2::clone_at_expansion(PhaseMacroExpand* phase, ArrayCopyNode* ac) const {
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   253
  Node* const src = ac->in(ArrayCopyNode::Src);
59324
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   254
  if (ac->is_clone_array()) {
58958
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   255
    // Clone primitive array
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   256
    BarrierSetC2::clone_at_expansion(phase, ac);
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   257
    return;
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   258
  }
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   259
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   260
  // Clone instance
59324
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   261
  assert(ac->is_clone_inst(), "Sanity check");
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   262
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   263
  Node* const ctrl       = ac->in(TypeFunc::Control);
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   264
  Node* const mem        = ac->in(TypeFunc::Memory);
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   265
  Node* const dst        = ac->in(ArrayCopyNode::Dest);
58958
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   266
  Node* const src_offset = ac->in(ArrayCopyNode::SrcPos);
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   267
  Node* const dst_offset = ac->in(ArrayCopyNode::DestPos);
59324
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   268
  Node* const size       = ac->in(ArrayCopyNode::Length);
58958
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   269
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   270
  assert(src_offset == NULL, "Should be null");
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   271
  assert(dst_offset == NULL, "Should be null");
59324
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   272
  assert(size->bottom_type()->is_long(), "Should be long");
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   273
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   274
  // The src and dst point to the object payload rather than the object base
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   275
  Node* const src_base = get_base_for_arracycopy_clone(phase, src);
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   276
  Node* const dst_base = get_base_for_arracycopy_clone(phase, dst);
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   277
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   278
  // The size must also be increased to match the instance size
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   279
  Node* const base_offset = phase->longcon(arraycopy_payload_base_offset(false) >> LogBytesPerLong);
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   280
  Node* const full_size = phase->transform_later(new AddLNode(size, base_offset));
58958
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   281
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   282
  Node* const call = phase->make_leaf_call(ctrl,
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   283
                                           mem,
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   284
                                           clone_type(),
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   285
                                           ZBarrierSetRuntime::clone_addr(),
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   286
                                           "ZBarrierSetRuntime::clone",
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   287
                                           TypeRawPtr::BOTTOM,
59324
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   288
                                           src_base,
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   289
                                           dst_base,
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   290
                                           full_size,
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   291
                                           phase->top());
58958
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   292
  phase->transform_later(call);
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   293
  phase->igvn().replace_node(ac, call);
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   294
}
7bfe7df764a2 8233783: Make 8232896 patch complete
neliasso
parents: 58931
diff changeset
   295
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   296
// == Dominating barrier elision ==
55307
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
   297
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   298
static bool block_has_safepoint(const Block* block, uint from, uint to) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   299
  for (uint i = from; i < to; i++) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   300
    if (block->get_node(i)->is_MachSafePoint()) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   301
      // Safepoint found
53439
4b42f828e0c3 8217257: ZGC: Minor cleanup of ZBarrierSetC2
pliden
parents: 53438
diff changeset
   302
      return true;
4b42f828e0c3 8217257: ZGC: Minor cleanup of ZBarrierSetC2
pliden
parents: 53438
diff changeset
   303
    }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   304
  }
53439
4b42f828e0c3 8217257: ZGC: Minor cleanup of ZBarrierSetC2
pliden
parents: 53438
diff changeset
   305
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   306
  // Safepoint not found
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   307
  return false;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   308
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   309
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   310
static bool block_has_safepoint(const Block* block) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   311
  return block_has_safepoint(block, 0, block->number_of_nodes());
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   312
}
51485
0c7040d1d1ca 8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents: 50875
diff changeset
   313
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   314
static uint block_index(const Block* block, const Node* node) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   315
  for (uint j = 0; j < block->number_of_nodes(); ++j) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   316
    if (block->get_node(j) == node) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   317
      return j;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   318
    }
51485
0c7040d1d1ca 8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents: 50875
diff changeset
   319
  }
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   320
  ShouldNotReachHere();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   321
  return 0;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   322
}
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   323
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   324
void ZBarrierSetC2::analyze_dominating_barriers() const {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   325
  ResourceMark rm;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   326
  Compile* const C = Compile::current();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   327
  PhaseCFG* const cfg = C->cfg();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   328
  Block_List worklist;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   329
  Node_List mem_ops;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   330
  Node_List barrier_loads;
51485
0c7040d1d1ca 8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents: 50875
diff changeset
   331
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   332
  // Step 1 - Find accesses, and track them in lists
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   333
  for (uint i = 0; i < cfg->number_of_blocks(); ++i) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   334
    const Block* const block = cfg->get_block(i);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   335
    for (uint j = 0; j < block->number_of_nodes(); ++j) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   336
      const Node* const node = block->get_node(j);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   337
      if (!node->is_Mach()) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   338
        continue;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   339
      }
51485
0c7040d1d1ca 8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents: 50875
diff changeset
   340
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   341
      MachNode* const mach = node->as_Mach();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   342
      switch (mach->ideal_Opcode()) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   343
      case Op_LoadP:
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   344
      case Op_CompareAndExchangeP:
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   345
      case Op_CompareAndSwapP:
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   346
      case Op_GetAndSetP:
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   347
        if (mach->barrier_data() == ZLoadBarrierStrong) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   348
          barrier_loads.push(mach);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   349
        }
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   350
      case Op_StoreP:
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   351
        mem_ops.push(mach);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   352
        break;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   353
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   354
      default:
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   355
        break;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   356
      }
51485
0c7040d1d1ca 8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents: 50875
diff changeset
   357
    }
0c7040d1d1ca 8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents: 50875
diff changeset
   358
  }
0c7040d1d1ca 8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents: 50875
diff changeset
   359
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   360
  // Step 2 - Find dominating accesses for each load
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   361
  for (uint i = 0; i < barrier_loads.size(); i++) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   362
    MachNode* const load = barrier_loads.at(i)->as_Mach();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   363
    const TypePtr* load_adr_type = NULL;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   364
    intptr_t load_offset = 0;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   365
    const Node* const load_obj = load->get_base_and_disp(load_offset, load_adr_type);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   366
    Block* const load_block = cfg->get_block_for_node(load);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   367
    const uint load_index = block_index(load_block, load);
52471
04d7e790aa2e 8213489: GC/C2 abstraction for Compile::final_graph_reshaping()
rkennke
parents: 52426
diff changeset
   368
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   369
    for (uint j = 0; j < mem_ops.size(); j++) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   370
      MachNode* mem = mem_ops.at(j)->as_Mach();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   371
      const TypePtr* mem_adr_type = NULL;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   372
      intptr_t mem_offset = 0;
59324
5e8f9713e343 8234520: ZGC: C2: Oop instance cloning causing skipped compiles
neliasso
parents: 59025
diff changeset
   373
      const Node* mem_obj = mem->get_base_and_disp(mem_offset, mem_adr_type);
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   374
      Block* mem_block = cfg->get_block_for_node(mem);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   375
      uint mem_index = block_index(mem_block, mem);
55307
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
   376
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   377
      if (load_obj == NodeSentinel || mem_obj == NodeSentinel ||
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   378
          load_obj == NULL || mem_obj == NULL ||
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   379
          load_offset < 0 || mem_offset < 0) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   380
        continue;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   381
      }
55307
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
   382
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   383
      if (mem_obj != load_obj || mem_offset != load_offset) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   384
        // Not the same addresses, not a candidate
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   385
        continue;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   386
      }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   387
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   388
      if (load_block == mem_block) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   389
        // Earlier accesses in the same block
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   390
        if (mem_index < load_index && !block_has_safepoint(mem_block, mem_index + 1, load_index)) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   391
          load->set_barrier_data(ZLoadBarrierElided);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   392
        }
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   393
      } else if (mem_block->dominates(load_block)) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   394
        // Dominating block? Look around for safepoints
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   395
        ResourceMark rm;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   396
        Block_List stack;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   397
        VectorSet visited(Thread::current()->resource_area());
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   398
        stack.push(load_block);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   399
        bool safepoint_found = block_has_safepoint(load_block);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   400
        while (!safepoint_found && stack.size() > 0) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   401
          Block* block = stack.pop();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   402
          if (visited.test_set(block->_pre_order)) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   403
            continue;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   404
          }
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   405
          if (block_has_safepoint(block)) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   406
            safepoint_found = true;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   407
            break;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   408
          }
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   409
          if (block == mem_block) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   410
            continue;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   411
          }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   412
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   413
          // Push predecessor blocks
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   414
          for (uint p = 1; p < block->num_preds(); ++p) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   415
            Block* pred = cfg->get_block_for_node(block->pred(p));
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   416
            stack.push(pred);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   417
          }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   418
        }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   419
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   420
        if (!safepoint_found) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   421
          load->set_barrier_data(ZLoadBarrierElided);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   422
        }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   423
      }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   424
    }
55307
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
   425
  }
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
   426
}
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   427
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   428
// == Reduced spilling optimization ==
55307
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
   429
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   430
void ZBarrierSetC2::compute_liveness_at_stubs() const {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   431
  ResourceMark rm;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   432
  Compile* const C = Compile::current();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   433
  Arena* const A = Thread::current()->resource_area();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   434
  PhaseCFG* const cfg = C->cfg();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   435
  PhaseRegAlloc* const regalloc = C->regalloc();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   436
  RegMask* const live = NEW_ARENA_ARRAY(A, RegMask, cfg->number_of_blocks() * sizeof(RegMask));
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   437
  ZBarrierSetAssembler* const bs = ZBarrierSet::assembler();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   438
  Block_List worklist;
55307
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
   439
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   440
  for (uint i = 0; i < cfg->number_of_blocks(); ++i) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   441
    new ((void*)(live + i)) RegMask();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   442
    worklist.push(cfg->get_block(i));
55307
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
   443
  }
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
   444
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   445
  while (worklist.size() > 0) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   446
    const Block* const block = worklist.pop();
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   447
    RegMask& old_live = live[block->_pre_order];
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   448
    RegMask new_live;
55307
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
   449
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   450
    // Initialize to union of successors
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   451
    for (uint i = 0; i < block->_num_succs; i++) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   452
      const uint succ_id = block->_succs[i]->_pre_order;
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   453
      new_live.OR(live[succ_id]);
55307
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
   454
    }
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
   455
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   456
    // Walk block backwards, computing liveness
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   457
    for (int i = block->number_of_nodes() - 1; i >= 0; --i) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   458
      const Node* const node = block->get_node(i);
55307
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
   459
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   460
      // Remove def bits
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   461
      const OptoReg::Name first = bs->refine_register(node, regalloc->get_reg_first(node));
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   462
      const OptoReg::Name second = bs->refine_register(node, regalloc->get_reg_second(node));
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   463
      if (first != OptoReg::Bad) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   464
        new_live.Remove(first);
55307
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
   465
      }
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   466
      if (second != OptoReg::Bad) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   467
        new_live.Remove(second);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   468
      }
55307
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
   469
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   470
      // Add use bits
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   471
      for (uint j = 1; j < node->req(); ++j) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   472
        const Node* const use = node->in(j);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   473
        const OptoReg::Name first = bs->refine_register(use, regalloc->get_reg_first(use));
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   474
        const OptoReg::Name second = bs->refine_register(use, regalloc->get_reg_second(use));
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   475
        if (first != OptoReg::Bad) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   476
          new_live.Insert(first);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   477
        }
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   478
        if (second != OptoReg::Bad) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   479
          new_live.Insert(second);
55307
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
   480
        }
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
   481
      }
ed12027517c0 8224675: Late GC barrier insertion for ZGC
neliasso
parents: 55123
diff changeset
   482
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   483
      // If this node tracks liveness, update it
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   484
      RegMask* const regs = barrier_set_state()->live(node);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   485
      if (regs != NULL) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   486
        regs->OR(new_live);
55321
ddda023e6f66 8225509: clean_catch_blocks must add preds first
neliasso
parents: 55307
diff changeset
   487
      }
ddda023e6f66 8225509: clean_catch_blocks must add preds first
neliasso
parents: 55307
diff changeset
   488
    }
ddda023e6f66 8225509: clean_catch_blocks must add preds first
neliasso
parents: 55307
diff changeset
   489
58516
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   490
    // Now at block top, see if we have any changes
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   491
    new_live.SUBTRACT(old_live);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   492
    if (new_live.is_NotEmpty()) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   493
      // Liveness has refined, update and propagate to prior blocks
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   494
      old_live.OR(new_live);
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   495
      for (uint i = 1; i < block->num_preds(); ++i) {
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   496
        Block* const pred = cfg->get_block_for_node(block->pred(i));
d376d86b0a01 8230565: ZGC: Redesign C2 load barrier to expand on the MachNode level
eosterlund
parents: 58273
diff changeset
   497
        worklist.push(pred);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   498
      }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   499
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   500
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   501
}