src/hotspot/share/gc/z/c2/zBarrierSetC2.cpp
author chegar
Thu, 17 Oct 2019 20:53:35 +0100
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 54327 a4d19817609c
child 58679 9c3209ff7550
permissions -rw-r--r--
datagramsocketimpl-branch: update to default
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"
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    25
#include "classfile/javaClasses.hpp"
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    26
#include "gc/z/c2/zBarrierSetC2.hpp"
53407
690aed53fef0 8217342: Build failed with excluding JFR
zgu
parents: 53226
diff changeset
    27
#include "gc/z/zBarrierSet.hpp"
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    28
#include "gc/z/zBarrierSetAssembler.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    29
#include "gc/z/zBarrierSetRuntime.hpp"
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    30
#include "opto/block.hpp"
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    31
#include "opto/compile.hpp"
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    32
#include "opto/graphKit.hpp"
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    33
#include "opto/machnode.hpp"
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    34
#include "opto/memnode.hpp"
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    35
#include "opto/node.hpp"
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    36
#include "opto/regalloc.hpp"
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    37
#include "opto/rootnode.hpp"
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    38
#include "utilities/growableArray.hpp"
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    39
#include "utilities/macros.hpp"
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    40
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    41
class ZBarrierSetC2State : public ResourceObj {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    42
private:
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    43
  GrowableArray<ZLoadBarrierStubC2*>* _stubs;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    44
  Node_Array                          _live;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    45
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    46
public:
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    47
  ZBarrierSetC2State(Arena* arena) :
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    48
    _stubs(new (arena) GrowableArray<ZLoadBarrierStubC2*>(arena, 8,  0, NULL)),
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    49
    _live(arena) {}
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    50
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    51
  GrowableArray<ZLoadBarrierStubC2*>* stubs() {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    52
    return _stubs;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    53
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    54
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    55
  RegMask* live(const Node* node) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    56
    if (!node->is_Mach()) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    57
      // Don't need liveness for non-MachNodes
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    58
      return NULL;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    59
    }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    60
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    61
    const MachNode* const mach = node->as_Mach();
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    62
    if (mach->barrier_data() != ZLoadBarrierStrong &&
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    63
        mach->barrier_data() != ZLoadBarrierWeak) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    64
      // Don't need liveness data for nodes without barriers
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    65
      return NULL;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    66
    }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    67
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    68
    RegMask* live = (RegMask*)_live[node->_idx];
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    69
    if (live == NULL) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    70
      live = new (Compile::current()->comp_arena()->Amalloc_D(sizeof(RegMask))) RegMask();
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    71
      _live.map(node->_idx, (Node*)live);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    72
    }
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    73
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    74
    return live;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    75
  }
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    76
};
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    77
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    78
static ZBarrierSetC2State* barrier_set_state() {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    79
  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
    80
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    81
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    82
ZLoadBarrierStubC2* ZLoadBarrierStubC2::create(const MachNode* node, Address ref_addr, Register ref, Register tmp, bool weak) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    83
  ZLoadBarrierStubC2* const stub = new (Compile::current()->comp_arena()) ZLoadBarrierStubC2(node, ref_addr, ref, tmp, weak);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    84
  if (!Compile::current()->in_scratch_emit_size()) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    85
    barrier_set_state()->stubs()->append(stub);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    86
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    87
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    88
  return stub;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    89
}
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
    90
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    91
ZLoadBarrierStubC2::ZLoadBarrierStubC2(const MachNode* node, Address ref_addr, Register ref, Register tmp, bool weak) :
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    92
    _node(node),
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    93
    _ref_addr(ref_addr),
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    94
    _ref(ref),
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    95
    _tmp(tmp),
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    96
    _weak(weak),
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    97
    _entry(),
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    98
    _continuation() {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
    99
  assert_different_registers(ref, ref_addr.base());
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   100
  assert_different_registers(ref, ref_addr.index());
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   101
}
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   102
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   103
Address ZLoadBarrierStubC2::ref_addr() const {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   104
  return _ref_addr;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   105
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   106
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   107
Register ZLoadBarrierStubC2::ref() const {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   108
  return _ref;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   109
}
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   110
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   111
Register ZLoadBarrierStubC2::tmp() const {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   112
  return _tmp;
53223
df6cbf676c70 8215708: ZGC: Add missing LoadBarrierNode::size_of()
pliden
parents: 52829
diff changeset
   113
}
df6cbf676c70 8215708: ZGC: Add missing LoadBarrierNode::size_of()
pliden
parents: 52829
diff changeset
   114
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   115
address ZLoadBarrierStubC2::slow_path() const {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   116
  const DecoratorSet decorators = _weak ? ON_WEAK_OOP_REF : ON_STRONG_OOP_REF;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   117
  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
   118
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   119
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   120
RegMask& ZLoadBarrierStubC2::live() const {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   121
  return *barrier_set_state()->live(_node);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   122
}
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   123
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   124
Label* ZLoadBarrierStubC2::entry() {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   125
  // The _entry will never be bound when in_scratch_emit_size() is true.
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   126
  // However, we still need to return a label that is not bound now, but
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   127
  // will eventually be bound. Any lable will do, as it will only act as
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   128
  // a placeholder, so we return the _continuation label.
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   129
  return Compile::current()->in_scratch_emit_size() ? &_continuation : &_entry;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   130
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   131
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   132
Label* ZLoadBarrierStubC2::continuation() {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   133
  return &_continuation;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   134
}
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   135
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   136
void* ZBarrierSetC2::create_barrier_state(Arena* comp_arena) const {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   137
  return new (comp_arena) ZBarrierSetC2State(comp_arena);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   138
}
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   139
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   140
void ZBarrierSetC2::late_barrier_analysis() const {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   141
  analyze_dominating_barriers();
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   142
  compute_liveness_at_stubs();
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   143
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   144
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   145
void ZBarrierSetC2::emit_stubs(CodeBuffer& cb) const {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   146
  MacroAssembler masm(&cb);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   147
  GrowableArray<ZLoadBarrierStubC2*>* const stubs = barrier_set_state()->stubs();
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   148
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   149
  for (int i = 0; i < stubs->length(); i++) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   150
    // Make sure there is enough space in the code buffer
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   151
    if (cb.insts()->maybe_expand_to_ensure_remaining(Compile::MAX_inst_size) && cb.blob() == NULL) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   152
      ciEnv::current()->record_failure("CodeCache is full");
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   153
      return;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   154
    }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   155
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   156
    ZBarrierSet::assembler()->generate_c2_load_barrier_stub(&masm, stubs->at(i));
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   157
  }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   158
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   159
  masm.flush();
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   160
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   161
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   162
int ZBarrierSetC2::estimate_stub_size() const {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   163
  Compile* const C = Compile::current();
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   164
  BufferBlob* const blob = C->scratch_buffer_blob();
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   165
  GrowableArray<ZLoadBarrierStubC2*>* const stubs = barrier_set_state()->stubs();
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   166
  int size = 0;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   167
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   168
  for (int i = 0; i < stubs->length(); i++) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   169
    CodeBuffer cb(blob->content_begin(), (address)C->scratch_locs_memory() - blob->content_begin());
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   170
    MacroAssembler masm(&cb);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   171
    ZBarrierSet::assembler()->generate_c2_load_barrier_stub(&masm, stubs->at(i));
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   172
    size += cb.insts_size();
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   173
  }
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   174
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   175
  return size;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   176
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   177
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 52224
diff changeset
   178
static bool barrier_needed(C2Access& access) {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   179
  return ZBarrierSet::barrier_needed(access.decorators(), access.type());
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
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   182
Node* ZBarrierSetC2::load_at_resolved(C2Access& access, const Type* val_type) const {
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   183
  Node* result = BarrierSetC2::load_at_resolved(access, val_type);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   184
  if (barrier_needed(access) && access.raw_access()->is_Mem()) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   185
    if ((access.decorators() & ON_WEAK_OOP_REF) != 0) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   186
      access.raw_access()->as_Load()->set_barrier_data(ZLoadBarrierWeak);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   187
    } else {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   188
      access.raw_access()->as_Load()->set_barrier_data(ZLoadBarrierStrong);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
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
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   192
  return result;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   193
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   194
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 52224
diff changeset
   195
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
   196
                                                    Node* new_val, const Type* val_type) const {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   197
  Node* result = BarrierSetC2::atomic_cmpxchg_val_at_resolved(access, expected_val, new_val, val_type);
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   198
  if (barrier_needed(access)) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   199
    access.raw_access()->as_LoadStore()->set_barrier_data(ZLoadBarrierStrong);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   200
  }
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   201
  return result;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   202
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   203
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 52224
diff changeset
   204
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
   205
                                                     Node* new_val, const Type* value_type) const {
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   206
  Node* result = BarrierSetC2::atomic_cmpxchg_bool_at_resolved(access, expected_val, new_val, value_type);
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   207
  if (barrier_needed(access)) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   208
    access.raw_access()->as_LoadStore()->set_barrier_data(ZLoadBarrierStrong);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   209
  }
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   210
  return result;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   211
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   212
52424
e3d79743f57d 8212243: More gc interface tweaks for arraycopy
roland
parents: 52224
diff changeset
   213
Node* ZBarrierSetC2::atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* new_val, const Type* val_type) const {
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   214
  Node* result = BarrierSetC2::atomic_xchg_at_resolved(access, new_val, val_type);
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   215
  if (barrier_needed(access)) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   216
    access.raw_access()->as_LoadStore()->set_barrier_data(ZLoadBarrierStrong);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   217
  }
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   218
  return result;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   219
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   220
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   221
bool ZBarrierSetC2::array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type,
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   222
                                                    bool is_clone, ArrayCopyPhase phase) const {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   223
  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
   224
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   225
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   226
// == Dominating barrier elision ==
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   227
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   228
static bool block_has_safepoint(const Block* block, uint from, uint to) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   229
  for (uint i = from; i < to; i++) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   230
    if (block->get_node(i)->is_MachSafePoint()) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   231
      // Safepoint found
53439
4b42f828e0c3 8217257: ZGC: Minor cleanup of ZBarrierSetC2
pliden
parents: 53438
diff changeset
   232
      return true;
4b42f828e0c3 8217257: ZGC: Minor cleanup of ZBarrierSetC2
pliden
parents: 53438
diff changeset
   233
    }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   234
  }
53439
4b42f828e0c3 8217257: ZGC: Minor cleanup of ZBarrierSetC2
pliden
parents: 53438
diff changeset
   235
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   236
  // Safepoint not found
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   237
  return false;
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   238
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   239
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   240
static bool block_has_safepoint(const Block* block) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   241
  return block_has_safepoint(block, 0, block->number_of_nodes());
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   242
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   243
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   244
static uint block_index(const Block* block, const Node* node) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   245
  for (uint j = 0; j < block->number_of_nodes(); ++j) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   246
    if (block->get_node(j) == node) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   247
      return j;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   248
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   249
  }
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   250
  ShouldNotReachHere();
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   251
  return 0;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   252
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   253
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   254
void ZBarrierSetC2::analyze_dominating_barriers() const {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   255
  ResourceMark rm;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   256
  Compile* const C = Compile::current();
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   257
  PhaseCFG* const cfg = C->cfg();
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   258
  Block_List worklist;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   259
  Node_List mem_ops;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   260
  Node_List barrier_loads;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   261
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   262
  // Step 1 - Find accesses, and track them in lists
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   263
  for (uint i = 0; i < cfg->number_of_blocks(); ++i) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   264
    const Block* const block = cfg->get_block(i);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   265
    for (uint j = 0; j < block->number_of_nodes(); ++j) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   266
      const Node* const node = block->get_node(j);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   267
      if (!node->is_Mach()) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   268
        continue;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   269
      }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   270
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   271
      MachNode* const mach = node->as_Mach();
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   272
      switch (mach->ideal_Opcode()) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   273
      case Op_LoadP:
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   274
      case Op_CompareAndExchangeP:
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   275
      case Op_CompareAndSwapP:
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   276
      case Op_GetAndSetP:
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   277
        if (mach->barrier_data() == ZLoadBarrierStrong) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   278
          barrier_loads.push(mach);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   279
        }
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   280
      case Op_StoreP:
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   281
        mem_ops.push(mach);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   282
        break;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   283
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   284
      default:
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   285
        break;
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   286
      }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   287
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   288
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   289
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   290
  // Step 2 - Find dominating accesses for each load
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   291
  for (uint i = 0; i < barrier_loads.size(); i++) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   292
    MachNode* const load = barrier_loads.at(i)->as_Mach();
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   293
    const TypePtr* load_adr_type = NULL;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   294
    intptr_t load_offset = 0;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   295
    const Node* const load_obj = load->get_base_and_disp(load_offset, load_adr_type);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   296
    Block* const load_block = cfg->get_block_for_node(load);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   297
    const uint load_index = block_index(load_block, load);
51485
0c7040d1d1ca 8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents: 50875
diff changeset
   298
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   299
    for (uint j = 0; j < mem_ops.size(); j++) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   300
      MachNode* mem = mem_ops.at(j)->as_Mach();
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   301
      const TypePtr* mem_adr_type = NULL;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   302
      intptr_t mem_offset = 0;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   303
      const Node* mem_obj = mem_obj = mem->get_base_and_disp(mem_offset, mem_adr_type);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   304
      Block* mem_block = cfg->get_block_for_node(mem);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   305
      uint mem_index = block_index(mem_block, mem);
51485
0c7040d1d1ca 8208601: Introduce native oop barriers in C2 for OopHandle
eosterlund
parents: 50875
diff changeset
   306
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   307
      if (load_obj == NodeSentinel || mem_obj == NodeSentinel ||
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   308
          load_obj == NULL || mem_obj == NULL ||
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   309
          load_offset < 0 || mem_offset < 0) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   310
        continue;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   311
      }
53439
4b42f828e0c3 8217257: ZGC: Minor cleanup of ZBarrierSetC2
pliden
parents: 53438
diff changeset
   312
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   313
      if (mem_obj != load_obj || mem_offset != load_offset) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   314
        // Not the same addresses, not a candidate
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   315
        continue;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   316
      }
52471
04d7e790aa2e 8213489: GC/C2 abstraction for Compile::final_graph_reshaping()
rkennke
parents: 52426
diff changeset
   317
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   318
      if (load_block == mem_block) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   319
        // Earlier accesses in the same block
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   320
        if (mem_index < load_index && !block_has_safepoint(mem_block, mem_index + 1, load_index)) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   321
          load->set_barrier_data(ZLoadBarrierElided);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   322
        }
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   323
      } else if (mem_block->dominates(load_block)) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   324
        // Dominating block? Look around for safepoints
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   325
        ResourceMark rm;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   326
        Block_List stack;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   327
        VectorSet visited(Thread::current()->resource_area());
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   328
        stack.push(load_block);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   329
        bool safepoint_found = block_has_safepoint(load_block);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   330
        while (!safepoint_found && stack.size() > 0) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   331
          Block* block = stack.pop();
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   332
          if (visited.test_set(block->_pre_order)) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   333
            continue;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   334
          }
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   335
          if (block_has_safepoint(block)) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   336
            safepoint_found = true;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   337
            break;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   338
          }
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   339
          if (block == mem_block) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   340
            continue;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   341
          }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   342
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   343
          // Push predecessor blocks
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   344
          for (uint p = 1; p < block->num_preds(); ++p) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   345
            Block* pred = cfg->get_block_for_node(block->pred(p));
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   346
            stack.push(pred);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   347
          }
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   348
        }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   349
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   350
        if (!safepoint_found) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   351
          load->set_barrier_data(ZLoadBarrierElided);
50525
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   352
        }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   353
      }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   354
    }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   355
  }
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   356
}
767cdb97f103 8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff changeset
   357
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   358
// == Reduced spilling optimization ==
52568
40474b7105f4 8213615: GC/C2 abstraction for escape analysis
rkennke
parents: 52471
diff changeset
   359
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   360
void ZBarrierSetC2::compute_liveness_at_stubs() const {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   361
  ResourceMark rm;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   362
  Compile* const C = Compile::current();
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   363
  Arena* const A = Thread::current()->resource_area();
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   364
  PhaseCFG* const cfg = C->cfg();
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   365
  PhaseRegAlloc* const regalloc = C->regalloc();
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   366
  RegMask* const live = NEW_ARENA_ARRAY(A, RegMask, cfg->number_of_blocks() * sizeof(RegMask));
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   367
  ZBarrierSetAssembler* const bs = ZBarrierSet::assembler();
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   368
  Block_List worklist;
53439
4b42f828e0c3 8217257: ZGC: Minor cleanup of ZBarrierSetC2
pliden
parents: 53438
diff changeset
   369
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   370
  for (uint i = 0; i < cfg->number_of_blocks(); ++i) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   371
    new ((void*)(live + i)) RegMask();
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   372
    worklist.push(cfg->get_block(i));
52568
40474b7105f4 8213615: GC/C2 abstraction for escape analysis
rkennke
parents: 52471
diff changeset
   373
  }
53439
4b42f828e0c3 8217257: ZGC: Minor cleanup of ZBarrierSetC2
pliden
parents: 53438
diff changeset
   374
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   375
  while (worklist.size() > 0) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   376
    const Block* const block = worklist.pop();
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   377
    RegMask& old_live = live[block->_pre_order];
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   378
    RegMask new_live;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   379
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   380
    // Initialize to union of successors
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   381
    for (uint i = 0; i < block->_num_succs; i++) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   382
      const uint succ_id = block->_succs[i]->_pre_order;
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   383
      new_live.OR(live[succ_id]);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   384
    }
52568
40474b7105f4 8213615: GC/C2 abstraction for escape analysis
rkennke
parents: 52471
diff changeset
   385
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   386
    // Walk block backwards, computing liveness
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   387
    for (int i = block->number_of_nodes() - 1; i >= 0; --i) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   388
      const Node* const node = block->get_node(i);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   389
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   390
      // Remove def bits
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   391
      const OptoReg::Name first = bs->refine_register(node, regalloc->get_reg_first(node));
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   392
      const OptoReg::Name second = bs->refine_register(node, regalloc->get_reg_second(node));
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   393
      if (first != OptoReg::Bad) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   394
        new_live.Remove(first);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   395
      }
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   396
      if (second != OptoReg::Bad) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   397
        new_live.Remove(second);
52568
40474b7105f4 8213615: GC/C2 abstraction for escape analysis
rkennke
parents: 52471
diff changeset
   398
      }
53439
4b42f828e0c3 8217257: ZGC: Minor cleanup of ZBarrierSetC2
pliden
parents: 53438
diff changeset
   399
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   400
      // Add use bits
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   401
      for (uint j = 1; j < node->req(); ++j) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   402
        const Node* const use = node->in(j);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   403
        const OptoReg::Name first = bs->refine_register(use, regalloc->get_reg_first(use));
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   404
        const OptoReg::Name second = bs->refine_register(use, regalloc->get_reg_second(use));
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   405
        if (first != OptoReg::Bad) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   406
          new_live.Insert(first);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   407
        }
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   408
        if (second != OptoReg::Bad) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   409
          new_live.Insert(second);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   410
        }
52568
40474b7105f4 8213615: GC/C2 abstraction for escape analysis
rkennke
parents: 52471
diff changeset
   411
      }
58678
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   412
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   413
      // If this node tracks liveness, update it
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   414
      RegMask* const regs = barrier_set_state()->live(node);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   415
      if (regs != NULL) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   416
        regs->OR(new_live);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   417
      }
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   418
    }
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   419
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   420
    // Now at block top, see if we have any changes
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   421
    new_live.SUBTRACT(old_live);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   422
    if (new_live.is_NotEmpty()) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   423
      // Liveness has refined, update and propagate to prior blocks
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   424
      old_live.OR(new_live);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   425
      for (uint i = 1; i < block->num_preds(); ++i) {
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   426
        Block* const pred = cfg->get_block_for_node(block->pred(i));
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   427
        worklist.push(pred);
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   428
      }
9cf78a70fa4f datagramsocketimpl-branch: update to default
chegar
parents: 54327
diff changeset
   429
    }
52568
40474b7105f4 8213615: GC/C2 abstraction for escape analysis
rkennke
parents: 52471
diff changeset
   430
  }
52711
f480ad035c73 8214172: GC interface entry points for loop opts
roland
parents: 52627
diff changeset
   431
}