annotate src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.cpp @ 54423:6c0ab8bd8da5

8221766: Load-reference barriers for Shenandoah Reviewed-by: kvn, erikj, aph, shade
author rkennke
date Tue, 02 Apr 2019 23:00:22 +0200
parents 744dc9c33676
children 1321f8cf9de5
rev   line source
rkennke@52925 1 /*
zgu@53407 2 * Copyright (c) 2018, 2019, Red Hat, Inc. All rights reserved.
rkennke@52925 3 *
rkennke@52925 4 * This code is free software; you can redistribute it and/or modify it
rkennke@52925 5 * under the terms of the GNU General Public License version 2 only, as
rkennke@52925 6 * published by the Free Software Foundation.
rkennke@52925 7 *
rkennke@52925 8 * This code is distributed in the hope that it will be useful, but WITHOUT
rkennke@52925 9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
rkennke@52925 10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
rkennke@52925 11 * version 2 for more details (a copy is included in the LICENSE file that
rkennke@52925 12 * accompanied this code).
rkennke@52925 13 *
rkennke@52925 14 * You should have received a copy of the GNU General Public License version
rkennke@52925 15 * 2 along with this work; if not, write to the Free Software Foundation,
rkennke@52925 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
rkennke@52925 17 *
rkennke@52925 18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
rkennke@52925 19 * or visit www.oracle.com if you need additional information or have any
rkennke@52925 20 * questions.
rkennke@52925 21 *
rkennke@52925 22 */
rkennke@52925 23
rkennke@52925 24 #include "precompiled.hpp"
zgu@53407 25 #include "gc/shared/barrierSet.hpp"
rkennke@52925 26 #include "gc/shenandoah/shenandoahHeap.hpp"
rkennke@52925 27 #include "gc/shenandoah/shenandoahHeuristics.hpp"
rkennke@52925 28 #include "gc/shenandoah/shenandoahRuntime.hpp"
zgu@53407 29 #include "gc/shenandoah/shenandoahThreadLocalData.hpp"
rkennke@52925 30 #include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
rkennke@52925 31 #include "gc/shenandoah/c2/shenandoahSupport.hpp"
rkennke@52925 32 #include "opto/arraycopynode.hpp"
rkennke@52925 33 #include "opto/escape.hpp"
rkennke@52925 34 #include "opto/graphKit.hpp"
rkennke@52925 35 #include "opto/idealKit.hpp"
rkennke@52925 36 #include "opto/macro.hpp"
rkennke@52925 37 #include "opto/movenode.hpp"
rkennke@52925 38 #include "opto/narrowptrnode.hpp"
rkennke@52925 39 #include "opto/rootnode.hpp"
rkennke@52925 40
rkennke@52925 41 ShenandoahBarrierSetC2* ShenandoahBarrierSetC2::bsc2() {
rkennke@52925 42 return reinterpret_cast<ShenandoahBarrierSetC2*>(BarrierSet::barrier_set()->barrier_set_c2());
rkennke@52925 43 }
rkennke@52925 44
rkennke@52925 45 ShenandoahBarrierSetC2State::ShenandoahBarrierSetC2State(Arena* comp_arena)
rkennke@54423 46 : _enqueue_barriers(new (comp_arena) GrowableArray<ShenandoahEnqueueBarrierNode*>(comp_arena, 8, 0, NULL)),
rkennke@54423 47 _load_reference_barriers(new (comp_arena) GrowableArray<ShenandoahLoadReferenceBarrierNode*>(comp_arena, 8, 0, NULL)) {
rkennke@52925 48 }
rkennke@52925 49
rkennke@54423 50 int ShenandoahBarrierSetC2State::enqueue_barriers_count() const {
rkennke@54423 51 return _enqueue_barriers->length();
rkennke@52925 52 }
rkennke@52925 53
rkennke@54423 54 ShenandoahEnqueueBarrierNode* ShenandoahBarrierSetC2State::enqueue_barrier(int idx) const {
rkennke@54423 55 return _enqueue_barriers->at(idx);
rkennke@52925 56 }
rkennke@52925 57
rkennke@54423 58 void ShenandoahBarrierSetC2State::add_enqueue_barrier(ShenandoahEnqueueBarrierNode * n) {
rkennke@54423 59 assert(!_enqueue_barriers->contains(n), "duplicate entry in barrier list");
rkennke@54423 60 _enqueue_barriers->append(n);
rkennke@52925 61 }
rkennke@52925 62
rkennke@54423 63 void ShenandoahBarrierSetC2State::remove_enqueue_barrier(ShenandoahEnqueueBarrierNode * n) {
rkennke@54423 64 if (_enqueue_barriers->contains(n)) {
rkennke@54423 65 _enqueue_barriers->remove(n);
rkennke@52925 66 }
rkennke@52925 67 }
rkennke@52925 68
rkennke@54423 69 int ShenandoahBarrierSetC2State::load_reference_barriers_count() const {
rkennke@54423 70 return _load_reference_barriers->length();
rkennke@54423 71 }
rkennke@52925 72
rkennke@54423 73 ShenandoahLoadReferenceBarrierNode* ShenandoahBarrierSetC2State::load_reference_barrier(int idx) const {
rkennke@54423 74 return _load_reference_barriers->at(idx);
rkennke@54423 75 }
rkennke@54423 76
rkennke@54423 77 void ShenandoahBarrierSetC2State::add_load_reference_barrier(ShenandoahLoadReferenceBarrierNode * n) {
rkennke@54423 78 assert(!_load_reference_barriers->contains(n), "duplicate entry in barrier list");
rkennke@54423 79 _load_reference_barriers->append(n);
rkennke@54423 80 }
rkennke@54423 81
rkennke@54423 82 void ShenandoahBarrierSetC2State::remove_load_reference_barrier(ShenandoahLoadReferenceBarrierNode * n) {
rkennke@54423 83 if (_load_reference_barriers->contains(n)) {
rkennke@54423 84 _load_reference_barriers->remove(n);
rkennke@54423 85 }
rkennke@54423 86 }
rkennke@54423 87
rkennke@54423 88 Node* ShenandoahBarrierSetC2::shenandoah_storeval_barrier(GraphKit* kit, Node* obj) const {
rkennke@54423 89 if (ShenandoahStoreValEnqueueBarrier) {
rkennke@54423 90 obj = shenandoah_enqueue_barrier(kit, obj);
rkennke@52925 91 }
rkennke@52925 92 return obj;
rkennke@52925 93 }
rkennke@52925 94
rkennke@54423 95 #define __ kit->
rkennke@52925 96
rkennke@52925 97 bool ShenandoahBarrierSetC2::satb_can_remove_pre_barrier(GraphKit* kit, PhaseTransform* phase, Node* adr,
rkennke@52925 98 BasicType bt, uint adr_idx) const {
rkennke@52925 99 intptr_t offset = 0;
rkennke@52925 100 Node* base = AddPNode::Ideal_base_and_offset(adr, phase, offset);
rkennke@52925 101 AllocateNode* alloc = AllocateNode::Ideal_allocation(base, phase);
rkennke@52925 102
rkennke@52925 103 if (offset == Type::OffsetBot) {
rkennke@52925 104 return false; // cannot unalias unless there are precise offsets
rkennke@52925 105 }
rkennke@52925 106
rkennke@52925 107 if (alloc == NULL) {
rkennke@52925 108 return false; // No allocation found
rkennke@52925 109 }
rkennke@52925 110
rkennke@52925 111 intptr_t size_in_bytes = type2aelembytes(bt);
rkennke@52925 112
rkennke@52925 113 Node* mem = __ memory(adr_idx); // start searching here...
rkennke@52925 114
rkennke@52925 115 for (int cnt = 0; cnt < 50; cnt++) {
rkennke@52925 116
rkennke@52925 117 if (mem->is_Store()) {
rkennke@52925 118
rkennke@52925 119 Node* st_adr = mem->in(MemNode::Address);
rkennke@52925 120 intptr_t st_offset = 0;
rkennke@52925 121 Node* st_base = AddPNode::Ideal_base_and_offset(st_adr, phase, st_offset);
rkennke@52925 122
rkennke@52925 123 if (st_base == NULL) {
rkennke@52925 124 break; // inscrutable pointer
rkennke@52925 125 }
rkennke@52925 126
rkennke@52925 127 // Break we have found a store with same base and offset as ours so break
rkennke@52925 128 if (st_base == base && st_offset == offset) {
rkennke@52925 129 break;
rkennke@52925 130 }
rkennke@52925 131
rkennke@52925 132 if (st_offset != offset && st_offset != Type::OffsetBot) {
rkennke@52925 133 const int MAX_STORE = BytesPerLong;
rkennke@52925 134 if (st_offset >= offset + size_in_bytes ||
rkennke@52925 135 st_offset <= offset - MAX_STORE ||
rkennke@52925 136 st_offset <= offset - mem->as_Store()->memory_size()) {
rkennke@52925 137 // Success: The offsets are provably independent.
rkennke@52925 138 // (You may ask, why not just test st_offset != offset and be done?
rkennke@52925 139 // The answer is that stores of different sizes can co-exist
rkennke@52925 140 // in the same sequence of RawMem effects. We sometimes initialize
rkennke@52925 141 // a whole 'tile' of array elements with a single jint or jlong.)
rkennke@52925 142 mem = mem->in(MemNode::Memory);
rkennke@52925 143 continue; // advance through independent store memory
rkennke@52925 144 }
rkennke@52925 145 }
rkennke@52925 146
rkennke@52925 147 if (st_base != base
rkennke@52925 148 && MemNode::detect_ptr_independence(base, alloc, st_base,
rkennke@52925 149 AllocateNode::Ideal_allocation(st_base, phase),
rkennke@52925 150 phase)) {
rkennke@52925 151 // Success: The bases are provably independent.
rkennke@52925 152 mem = mem->in(MemNode::Memory);
rkennke@52925 153 continue; // advance through independent store memory
rkennke@52925 154 }
rkennke@52925 155 } else if (mem->is_Proj() && mem->in(0)->is_Initialize()) {
rkennke@52925 156
rkennke@52925 157 InitializeNode* st_init = mem->in(0)->as_Initialize();
rkennke@52925 158 AllocateNode* st_alloc = st_init->allocation();
rkennke@52925 159
rkennke@52925 160 // Make sure that we are looking at the same allocation site.
rkennke@52925 161 // The alloc variable is guaranteed to not be null here from earlier check.
rkennke@52925 162 if (alloc == st_alloc) {
rkennke@52925 163 // Check that the initialization is storing NULL so that no previous store
rkennke@52925 164 // has been moved up and directly write a reference
rkennke@52925 165 Node* captured_store = st_init->find_captured_store(offset,
rkennke@52925 166 type2aelembytes(T_OBJECT),
rkennke@52925 167 phase);
rkennke@52925 168 if (captured_store == NULL || captured_store == st_init->zero_memory()) {
rkennke@52925 169 return true;
rkennke@52925 170 }
rkennke@52925 171 }
rkennke@52925 172 }
rkennke@52925 173
rkennke@52925 174 // Unless there is an explicit 'continue', we must bail out here,
rkennke@52925 175 // because 'mem' is an inscrutable memory state (e.g., a call).
rkennke@52925 176 break;
rkennke@52925 177 }
rkennke@52925 178
rkennke@52925 179 return false;
rkennke@52925 180 }
rkennke@52925 181
rkennke@52925 182 #undef __
rkennke@52925 183 #define __ ideal.
rkennke@52925 184
rkennke@52925 185 void ShenandoahBarrierSetC2::satb_write_barrier_pre(GraphKit* kit,
rkennke@52925 186 bool do_load,
rkennke@52925 187 Node* obj,
rkennke@52925 188 Node* adr,
rkennke@52925 189 uint alias_idx,
rkennke@52925 190 Node* val,
rkennke@52925 191 const TypeOopPtr* val_type,
rkennke@52925 192 Node* pre_val,
rkennke@52925 193 BasicType bt) const {
rkennke@52925 194 // Some sanity checks
rkennke@52925 195 // Note: val is unused in this routine.
rkennke@52925 196
rkennke@52925 197 if (do_load) {
rkennke@52925 198 // We need to generate the load of the previous value
rkennke@52925 199 assert(obj != NULL, "must have a base");
rkennke@52925 200 assert(adr != NULL, "where are loading from?");
rkennke@52925 201 assert(pre_val == NULL, "loaded already?");
rkennke@52925 202 assert(val_type != NULL, "need a type");
rkennke@52925 203
rkennke@52925 204 if (ReduceInitialCardMarks
rkennke@52925 205 && satb_can_remove_pre_barrier(kit, &kit->gvn(), adr, bt, alias_idx)) {
rkennke@52925 206 return;
rkennke@52925 207 }
rkennke@52925 208
rkennke@52925 209 } else {
rkennke@52925 210 // In this case both val_type and alias_idx are unused.
rkennke@52925 211 assert(pre_val != NULL, "must be loaded already");
rkennke@52925 212 // Nothing to be done if pre_val is null.
rkennke@52925 213 if (pre_val->bottom_type() == TypePtr::NULL_PTR) return;
rkennke@52925 214 assert(pre_val->bottom_type()->basic_type() == T_OBJECT, "or we shouldn't be here");
rkennke@52925 215 }
rkennke@52925 216 assert(bt == T_OBJECT, "or we shouldn't be here");
rkennke@52925 217
rkennke@52925 218 IdealKit ideal(kit, true);
rkennke@52925 219
rkennke@52925 220 Node* tls = __ thread(); // ThreadLocalStorage
rkennke@52925 221
rkennke@52925 222 Node* no_base = __ top();
rkennke@52925 223 Node* zero = __ ConI(0);
rkennke@52925 224 Node* zeroX = __ ConX(0);
rkennke@52925 225
rkennke@52925 226 float likely = PROB_LIKELY(0.999);
rkennke@52925 227 float unlikely = PROB_UNLIKELY(0.999);
rkennke@52925 228
rkennke@52925 229 // Offsets into the thread
rkennke@52925 230 const int index_offset = in_bytes(ShenandoahThreadLocalData::satb_mark_queue_index_offset());
rkennke@52925 231 const int buffer_offset = in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset());
rkennke@52925 232
rkennke@52925 233 // Now the actual pointers into the thread
rkennke@52925 234 Node* buffer_adr = __ AddP(no_base, tls, __ ConX(buffer_offset));
rkennke@52925 235 Node* index_adr = __ AddP(no_base, tls, __ ConX(index_offset));
rkennke@52925 236
rkennke@52925 237 // Now some of the values
rkennke@52925 238 Node* marking;
rkennke@52925 239 Node* gc_state = __ AddP(no_base, tls, __ ConX(in_bytes(ShenandoahThreadLocalData::gc_state_offset())));
rkennke@52925 240 Node* ld = __ load(__ ctrl(), gc_state, TypeInt::BYTE, T_BYTE, Compile::AliasIdxRaw);
rkennke@52925 241 marking = __ AndI(ld, __ ConI(ShenandoahHeap::MARKING));
rkennke@54423 242 assert(ShenandoahBarrierC2Support::is_gc_state_load(ld), "Should match the shape");
rkennke@52925 243
rkennke@52925 244 // if (!marking)
rkennke@52925 245 __ if_then(marking, BoolTest::ne, zero, unlikely); {
rkennke@52925 246 BasicType index_bt = TypeX_X->basic_type();
rkennke@52925 247 assert(sizeof(size_t) == type2aelembytes(index_bt), "Loading G1 SATBMarkQueue::_index with wrong size.");
rkennke@52925 248 Node* index = __ load(__ ctrl(), index_adr, TypeX_X, index_bt, Compile::AliasIdxRaw);
rkennke@52925 249
rkennke@52925 250 if (do_load) {
rkennke@52925 251 // load original value
rkennke@52925 252 // alias_idx correct??
rkennke@52925 253 pre_val = __ load(__ ctrl(), adr, val_type, bt, alias_idx);
rkennke@52925 254 }
rkennke@52925 255
rkennke@52925 256 // if (pre_val != NULL)
rkennke@52925 257 __ if_then(pre_val, BoolTest::ne, kit->null()); {
rkennke@52925 258 Node* buffer = __ load(__ ctrl(), buffer_adr, TypeRawPtr::NOTNULL, T_ADDRESS, Compile::AliasIdxRaw);
rkennke@52925 259
rkennke@52925 260 // is the queue for this thread full?
rkennke@52925 261 __ if_then(index, BoolTest::ne, zeroX, likely); {
rkennke@52925 262
rkennke@52925 263 // decrement the index
rkennke@52925 264 Node* next_index = kit->gvn().transform(new SubXNode(index, __ ConX(sizeof(intptr_t))));
rkennke@52925 265
rkennke@52925 266 // Now get the buffer location we will log the previous value into and store it
rkennke@52925 267 Node *log_addr = __ AddP(no_base, buffer, next_index);
rkennke@52925 268 __ store(__ ctrl(), log_addr, pre_val, T_OBJECT, Compile::AliasIdxRaw, MemNode::unordered);
rkennke@52925 269 // update the index
rkennke@52925 270 __ store(__ ctrl(), index_adr, next_index, index_bt, Compile::AliasIdxRaw, MemNode::unordered);
rkennke@52925 271
rkennke@52925 272 } __ else_(); {
rkennke@52925 273
rkennke@52925 274 // logging buffer is full, call the runtime
rkennke@52925 275 const TypeFunc *tf = ShenandoahBarrierSetC2::write_ref_field_pre_entry_Type();
rkennke@52925 276 __ make_leaf_call(tf, CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), "shenandoah_wb_pre", pre_val, tls);
rkennke@52925 277 } __ end_if(); // (!index)
rkennke@52925 278 } __ end_if(); // (pre_val != NULL)
rkennke@52925 279 } __ end_if(); // (!marking)
rkennke@52925 280
rkennke@52925 281 // Final sync IdealKit and GraphKit.
rkennke@52925 282 kit->final_sync(ideal);
rkennke@52925 283
rkennke@52925 284 if (ShenandoahSATBBarrier && adr != NULL) {
rkennke@52925 285 Node* c = kit->control();
rkennke@52925 286 Node* call = c->in(1)->in(1)->in(1)->in(0);
rkennke@52925 287 assert(is_shenandoah_wb_pre_call(call), "shenandoah_wb_pre call expected");
rkennke@52925 288 call->add_req(adr);
rkennke@52925 289 }
rkennke@52925 290 }
rkennke@52925 291
rkennke@52925 292 bool ShenandoahBarrierSetC2::is_shenandoah_wb_pre_call(Node* call) {
rkennke@52925 293 return call->is_CallLeaf() &&
rkennke@52925 294 call->as_CallLeaf()->entry_point() == CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry);
rkennke@52925 295 }
rkennke@52925 296
rkennke@52925 297 bool ShenandoahBarrierSetC2::is_shenandoah_wb_call(Node* call) {
rkennke@52925 298 return call->is_CallLeaf() &&
rkennke@54423 299 call->as_CallLeaf()->entry_point() == CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_JRT);
rkennke@52925 300 }
rkennke@52925 301
rkennke@52925 302 bool ShenandoahBarrierSetC2::is_shenandoah_marking_if(PhaseTransform *phase, Node* n) {
rkennke@52925 303 if (n->Opcode() != Op_If) {
rkennke@52925 304 return false;
rkennke@52925 305 }
rkennke@52925 306
rkennke@52925 307 Node* bol = n->in(1);
rkennke@52925 308 assert(bol->is_Bool(), "");
rkennke@52925 309 Node* cmpx = bol->in(1);
rkennke@52925 310 if (bol->as_Bool()->_test._test == BoolTest::ne &&
rkennke@52925 311 cmpx->is_Cmp() && cmpx->in(2) == phase->intcon(0) &&
rkennke@52925 312 is_shenandoah_state_load(cmpx->in(1)->in(1)) &&
rkennke@52925 313 cmpx->in(1)->in(2)->is_Con() &&
rkennke@52925 314 cmpx->in(1)->in(2) == phase->intcon(ShenandoahHeap::MARKING)) {
rkennke@52925 315 return true;
rkennke@52925 316 }
rkennke@52925 317
rkennke@52925 318 return false;
rkennke@52925 319 }
rkennke@52925 320
rkennke@52925 321 bool ShenandoahBarrierSetC2::is_shenandoah_state_load(Node* n) {
rkennke@52925 322 if (!n->is_Load()) return false;
rkennke@52925 323 const int state_offset = in_bytes(ShenandoahThreadLocalData::gc_state_offset());
rkennke@52925 324 return n->in(2)->is_AddP() && n->in(2)->in(2)->Opcode() == Op_ThreadLocal
rkennke@52925 325 && n->in(2)->in(3)->is_Con()
rkennke@52925 326 && n->in(2)->in(3)->bottom_type()->is_intptr_t()->get_con() == state_offset;
rkennke@52925 327 }
rkennke@52925 328
rkennke@52925 329 void ShenandoahBarrierSetC2::shenandoah_write_barrier_pre(GraphKit* kit,
rkennke@52925 330 bool do_load,
rkennke@52925 331 Node* obj,
rkennke@52925 332 Node* adr,
rkennke@52925 333 uint alias_idx,
rkennke@52925 334 Node* val,
rkennke@52925 335 const TypeOopPtr* val_type,
rkennke@52925 336 Node* pre_val,
rkennke@52925 337 BasicType bt) const {
rkennke@52925 338 if (ShenandoahSATBBarrier) {
rkennke@52925 339 IdealKit ideal(kit);
rkennke@52925 340 kit->sync_kit(ideal);
rkennke@52925 341
rkennke@52925 342 satb_write_barrier_pre(kit, do_load, obj, adr, alias_idx, val, val_type, pre_val, bt);
rkennke@52925 343
rkennke@52925 344 ideal.sync_kit(kit);
rkennke@52925 345 kit->final_sync(ideal);
rkennke@52925 346 }
rkennke@52925 347 }
rkennke@52925 348
rkennke@52925 349 Node* ShenandoahBarrierSetC2::shenandoah_enqueue_barrier(GraphKit* kit, Node* pre_val) const {
rkennke@52925 350 return kit->gvn().transform(new ShenandoahEnqueueBarrierNode(pre_val));
rkennke@52925 351 }
rkennke@52925 352
rkennke@52925 353 // Helper that guards and inserts a pre-barrier.
rkennke@52925 354 void ShenandoahBarrierSetC2::insert_pre_barrier(GraphKit* kit, Node* base_oop, Node* offset,
rkennke@52925 355 Node* pre_val, bool need_mem_bar) const {
rkennke@52925 356 // We could be accessing the referent field of a reference object. If so, when G1
rkennke@52925 357 // is enabled, we need to log the value in the referent field in an SATB buffer.
rkennke@52925 358 // This routine performs some compile time filters and generates suitable
rkennke@52925 359 // runtime filters that guard the pre-barrier code.
rkennke@52925 360 // Also add memory barrier for non volatile load from the referent field
rkennke@52925 361 // to prevent commoning of loads across safepoint.
rkennke@52925 362
rkennke@52925 363 // Some compile time checks.
rkennke@52925 364
rkennke@52925 365 // If offset is a constant, is it java_lang_ref_Reference::_reference_offset?
rkennke@52925 366 const TypeX* otype = offset->find_intptr_t_type();
rkennke@52925 367 if (otype != NULL && otype->is_con() &&
rkennke@52925 368 otype->get_con() != java_lang_ref_Reference::referent_offset) {
rkennke@52925 369 // Constant offset but not the reference_offset so just return
rkennke@52925 370 return;
rkennke@52925 371 }
rkennke@52925 372
rkennke@52925 373 // We only need to generate the runtime guards for instances.
rkennke@52925 374 const TypeOopPtr* btype = base_oop->bottom_type()->isa_oopptr();
rkennke@52925 375 if (btype != NULL) {
rkennke@52925 376 if (btype->isa_aryptr()) {
rkennke@52925 377 // Array type so nothing to do
rkennke@52925 378 return;
rkennke@52925 379 }
rkennke@52925 380
rkennke@52925 381 const TypeInstPtr* itype = btype->isa_instptr();
rkennke@52925 382 if (itype != NULL) {
rkennke@52925 383 // Can the klass of base_oop be statically determined to be
rkennke@52925 384 // _not_ a sub-class of Reference and _not_ Object?
rkennke@52925 385 ciKlass* klass = itype->klass();
rkennke@52925 386 if ( klass->is_loaded() &&
rkennke@52925 387 !klass->is_subtype_of(kit->env()->Reference_klass()) &&
rkennke@52925 388 !kit->env()->Object_klass()->is_subtype_of(klass)) {
rkennke@52925 389 return;
rkennke@52925 390 }
rkennke@52925 391 }
rkennke@52925 392 }
rkennke@52925 393
rkennke@52925 394 // The compile time filters did not reject base_oop/offset so
rkennke@52925 395 // we need to generate the following runtime filters
rkennke@52925 396 //
rkennke@52925 397 // if (offset == java_lang_ref_Reference::_reference_offset) {
rkennke@52925 398 // if (instance_of(base, java.lang.ref.Reference)) {
rkennke@52925 399 // pre_barrier(_, pre_val, ...);
rkennke@52925 400 // }
rkennke@52925 401 // }
rkennke@52925 402
rkennke@52925 403 float likely = PROB_LIKELY( 0.999);
rkennke@52925 404 float unlikely = PROB_UNLIKELY(0.999);
rkennke@52925 405
rkennke@52925 406 IdealKit ideal(kit);
rkennke@52925 407
rkennke@52925 408 Node* referent_off = __ ConX(java_lang_ref_Reference::referent_offset);
rkennke@52925 409
rkennke@52925 410 __ if_then(offset, BoolTest::eq, referent_off, unlikely); {
rkennke@52925 411 // Update graphKit memory and control from IdealKit.
rkennke@52925 412 kit->sync_kit(ideal);
rkennke@52925 413
rkennke@52925 414 Node* ref_klass_con = kit->makecon(TypeKlassPtr::make(kit->env()->Reference_klass()));
rkennke@52925 415 Node* is_instof = kit->gen_instanceof(base_oop, ref_klass_con);
rkennke@52925 416
rkennke@52925 417 // Update IdealKit memory and control from graphKit.
rkennke@52925 418 __ sync_kit(kit);
rkennke@52925 419
rkennke@52925 420 Node* one = __ ConI(1);
rkennke@52925 421 // is_instof == 0 if base_oop == NULL
rkennke@52925 422 __ if_then(is_instof, BoolTest::eq, one, unlikely); {
rkennke@52925 423
rkennke@52925 424 // Update graphKit from IdeakKit.
rkennke@52925 425 kit->sync_kit(ideal);
rkennke@52925 426
rkennke@52925 427 // Use the pre-barrier to record the value in the referent field
rkennke@52925 428 satb_write_barrier_pre(kit, false /* do_load */,
rkennke@52925 429 NULL /* obj */, NULL /* adr */, max_juint /* alias_idx */, NULL /* val */, NULL /* val_type */,
rkennke@52925 430 pre_val /* pre_val */,
rkennke@52925 431 T_OBJECT);
rkennke@52925 432 if (need_mem_bar) {
rkennke@52925 433 // Add memory barrier to prevent commoning reads from this field
rkennke@52925 434 // across safepoint since GC can change its value.
rkennke@52925 435 kit->insert_mem_bar(Op_MemBarCPUOrder);
rkennke@52925 436 }
rkennke@52925 437 // Update IdealKit from graphKit.
rkennke@52925 438 __ sync_kit(kit);
rkennke@52925 439
rkennke@52925 440 } __ end_if(); // _ref_type != ref_none
rkennke@52925 441 } __ end_if(); // offset == referent_offset
rkennke@52925 442
rkennke@52925 443 // Final sync IdealKit and GraphKit.
rkennke@52925 444 kit->final_sync(ideal);
rkennke@52925 445 }
rkennke@52925 446
rkennke@52925 447 #undef __
rkennke@52925 448
rkennke@52925 449 const TypeFunc* ShenandoahBarrierSetC2::write_ref_field_pre_entry_Type() {
rkennke@52925 450 const Type **fields = TypeTuple::fields(2);
rkennke@52925 451 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // original field value
rkennke@52925 452 fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // thread
rkennke@52925 453 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
rkennke@52925 454
rkennke@52925 455 // create result type (range)
rkennke@52925 456 fields = TypeTuple::fields(0);
rkennke@52925 457 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
rkennke@52925 458
rkennke@52925 459 return TypeFunc::make(domain, range);
rkennke@52925 460 }
rkennke@52925 461
rkennke@52925 462 const TypeFunc* ShenandoahBarrierSetC2::shenandoah_clone_barrier_Type() {
rkennke@52925 463 const Type **fields = TypeTuple::fields(1);
rkennke@52925 464 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // original field value
rkennke@52925 465 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
rkennke@52925 466
rkennke@52925 467 // create result type (range)
rkennke@52925 468 fields = TypeTuple::fields(0);
rkennke@52925 469 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
rkennke@52925 470
rkennke@52925 471 return TypeFunc::make(domain, range);
rkennke@52925 472 }
rkennke@52925 473
rkennke@52925 474 const TypeFunc* ShenandoahBarrierSetC2::shenandoah_write_barrier_Type() {
rkennke@52925 475 const Type **fields = TypeTuple::fields(1);
rkennke@52925 476 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // original field value
rkennke@52925 477 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
rkennke@52925 478
rkennke@52925 479 // create result type (range)
rkennke@52925 480 fields = TypeTuple::fields(1);
rkennke@52925 481 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;
rkennke@52925 482 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
rkennke@52925 483
rkennke@52925 484 return TypeFunc::make(domain, range);
rkennke@52925 485 }
rkennke@52925 486
rkennke@52925 487 Node* ShenandoahBarrierSetC2::store_at_resolved(C2Access& access, C2AccessValue& val) const {
rkennke@52925 488 DecoratorSet decorators = access.decorators();
rkennke@52925 489
rkennke@52925 490 const TypePtr* adr_type = access.addr().type();
rkennke@52925 491 Node* adr = access.addr().node();
rkennke@52925 492
rkennke@52925 493 bool anonymous = (decorators & ON_UNKNOWN_OOP_REF) != 0;
rkennke@52925 494 bool on_heap = (decorators & IN_HEAP) != 0;
rkennke@52925 495
rkennke@52925 496 if (!access.is_oop() || (!on_heap && !anonymous)) {
rkennke@52925 497 return BarrierSetC2::store_at_resolved(access, val);
rkennke@52925 498 }
rkennke@52925 499
rkennke@52925 500 if (access.is_parse_access()) {
rkennke@52925 501 C2ParseAccess& parse_access = static_cast<C2ParseAccess&>(access);
rkennke@52925 502 GraphKit* kit = parse_access.kit();
rkennke@52925 503
rkennke@52925 504 uint adr_idx = kit->C->get_alias_index(adr_type);
rkennke@52925 505 assert(adr_idx != Compile::AliasIdxTop, "use other store_to_memory factory" );
rkennke@52925 506 Node* value = val.node();
rkennke@52925 507 value = shenandoah_storeval_barrier(kit, value);
rkennke@52925 508 val.set_node(value);
rkennke@52925 509 shenandoah_write_barrier_pre(kit, true /* do_load */, /*kit->control(),*/ access.base(), adr, adr_idx, val.node(),
rkennke@52925 510 static_cast<const TypeOopPtr*>(val.type()), NULL /* pre_val */, access.type());
rkennke@52925 511 } else {
rkennke@52925 512 assert(access.is_opt_access(), "only for optimization passes");
kbarrett@54048 513 assert(((decorators & C2_TIGHTLY_COUPLED_ALLOC) != 0 || !ShenandoahSATBBarrier) && (decorators & C2_ARRAY_COPY) != 0, "unexpected caller of this code");
rkennke@52925 514 C2OptAccess& opt_access = static_cast<C2OptAccess&>(access);
rkennke@52925 515 PhaseGVN& gvn = opt_access.gvn();
rkennke@52925 516 MergeMemNode* mm = opt_access.mem();
rkennke@52925 517
rkennke@52925 518 if (ShenandoahStoreValEnqueueBarrier) {
rkennke@54423 519 Node* enqueue = gvn.transform(new ShenandoahEnqueueBarrierNode(val.node()));
rkennke@52925 520 val.set_node(enqueue);
rkennke@52925 521 }
rkennke@52925 522 }
rkennke@52925 523 return BarrierSetC2::store_at_resolved(access, val);
rkennke@52925 524 }
rkennke@52925 525
rkennke@52925 526 Node* ShenandoahBarrierSetC2::load_at_resolved(C2Access& access, const Type* val_type) const {
rkennke@52925 527 DecoratorSet decorators = access.decorators();
rkennke@52925 528
rkennke@52925 529 Node* adr = access.addr().node();
rkennke@52925 530 Node* obj = access.base();
rkennke@52925 531
rkennke@52925 532 bool mismatched = (decorators & C2_MISMATCHED) != 0;
rkennke@52925 533 bool unknown = (decorators & ON_UNKNOWN_OOP_REF) != 0;
rkennke@52925 534 bool on_heap = (decorators & IN_HEAP) != 0;
rkennke@52925 535 bool on_weak = (decorators & ON_WEAK_OOP_REF) != 0;
rkennke@52925 536 bool is_unordered = (decorators & MO_UNORDERED) != 0;
rkennke@52925 537 bool need_cpu_mem_bar = !is_unordered || mismatched || !on_heap;
rkennke@52925 538
rkennke@52925 539 Node* top = Compile::current()->top();
rkennke@52925 540
rkennke@52925 541 Node* offset = adr->is_AddP() ? adr->in(AddPNode::Offset) : top;
rkennke@52925 542 Node* load = BarrierSetC2::load_at_resolved(access, val_type);
rkennke@52925 543
rkennke@54423 544 if (access.is_oop()) {
rkennke@54423 545 if (ShenandoahLoadRefBarrier) {
rkennke@54423 546 load = new ShenandoahLoadReferenceBarrierNode(NULL, load);
rkennke@54423 547 if (access.is_parse_access()) {
rkennke@54423 548 load = static_cast<C2ParseAccess &>(access).kit()->gvn().transform(load);
rkennke@54423 549 } else {
rkennke@54423 550 load = static_cast<C2OptAccess &>(access).gvn().transform(load);
rkennke@54423 551 }
rkennke@54423 552 }
rkennke@54423 553 }
rkennke@54423 554
rkennke@52925 555 // If we are reading the value of the referent field of a Reference
rkennke@52925 556 // object (either by using Unsafe directly or through reflection)
rkennke@52925 557 // then, if SATB is enabled, we need to record the referent in an
rkennke@52925 558 // SATB log buffer using the pre-barrier mechanism.
rkennke@52925 559 // Also we need to add memory barrier to prevent commoning reads
rkennke@52925 560 // from this field across safepoint since GC can change its value.
rkennke@52925 561 bool need_read_barrier = ShenandoahKeepAliveBarrier &&
rkennke@52925 562 (on_heap && (on_weak || (unknown && offset != top && obj != top)));
rkennke@52925 563
rkennke@52925 564 if (!access.is_oop() || !need_read_barrier) {
rkennke@52925 565 return load;
rkennke@52925 566 }
rkennke@52925 567
rkennke@52925 568 assert(access.is_parse_access(), "entry not supported at optimization time");
rkennke@52925 569 C2ParseAccess& parse_access = static_cast<C2ParseAccess&>(access);
rkennke@52925 570 GraphKit* kit = parse_access.kit();
rkennke@52925 571
rkennke@52925 572 if (on_weak) {
rkennke@52925 573 // Use the pre-barrier to record the value in the referent field
rkennke@52925 574 satb_write_barrier_pre(kit, false /* do_load */,
rkennke@52925 575 NULL /* obj */, NULL /* adr */, max_juint /* alias_idx */, NULL /* val */, NULL /* val_type */,
rkennke@52925 576 load /* pre_val */, T_OBJECT);
rkennke@52925 577 // Add memory barrier to prevent commoning reads from this field
rkennke@52925 578 // across safepoint since GC can change its value.
rkennke@52925 579 kit->insert_mem_bar(Op_MemBarCPUOrder);
rkennke@52925 580 } else if (unknown) {
rkennke@52925 581 // We do not require a mem bar inside pre_barrier if need_mem_bar
rkennke@52925 582 // is set: the barriers would be emitted by us.
rkennke@52925 583 insert_pre_barrier(kit, obj, offset, load, !need_cpu_mem_bar);
rkennke@52925 584 }
rkennke@52925 585
rkennke@52925 586 return load;
rkennke@52925 587 }
rkennke@52925 588
rkennke@52925 589 Node* ShenandoahBarrierSetC2::atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
rkennke@52925 590 Node* new_val, const Type* value_type) const {
rkennke@52925 591 GraphKit* kit = access.kit();
rkennke@52925 592 if (access.is_oop()) {
rkennke@52925 593 new_val = shenandoah_storeval_barrier(kit, new_val);
rkennke@52925 594 shenandoah_write_barrier_pre(kit, false /* do_load */,
rkennke@52925 595 NULL, NULL, max_juint, NULL, NULL,
rkennke@52925 596 expected_val /* pre_val */, T_OBJECT);
rkennke@52925 597
rkennke@52925 598 MemNode::MemOrd mo = access.mem_node_mo();
rkennke@52925 599 Node* mem = access.memory();
rkennke@52925 600 Node* adr = access.addr().node();
rkennke@52925 601 const TypePtr* adr_type = access.addr().type();
rkennke@52925 602 Node* load_store = NULL;
rkennke@52925 603
rkennke@52925 604 #ifdef _LP64
rkennke@52925 605 if (adr->bottom_type()->is_ptr_to_narrowoop()) {
rkennke@52925 606 Node *newval_enc = kit->gvn().transform(new EncodePNode(new_val, new_val->bottom_type()->make_narrowoop()));
rkennke@52925 607 Node *oldval_enc = kit->gvn().transform(new EncodePNode(expected_val, expected_val->bottom_type()->make_narrowoop()));
rkennke@53519 608 if (ShenandoahCASBarrier) {
rkennke@53519 609 load_store = kit->gvn().transform(new ShenandoahCompareAndExchangeNNode(kit->control(), mem, adr, newval_enc, oldval_enc, adr_type, value_type->make_narrowoop(), mo));
rkennke@53519 610 } else {
rkennke@53519 611 load_store = kit->gvn().transform(new CompareAndExchangeNNode(kit->control(), mem, adr, newval_enc, oldval_enc, adr_type, value_type->make_narrowoop(), mo));
rkennke@53519 612 }
rkennke@52925 613 } else
rkennke@52925 614 #endif
rkennke@52925 615 {
rkennke@53519 616 if (ShenandoahCASBarrier) {
rkennke@53519 617 load_store = kit->gvn().transform(new ShenandoahCompareAndExchangePNode(kit->control(), mem, adr, new_val, expected_val, adr_type, value_type->is_oopptr(), mo));
rkennke@53519 618 } else {
rkennke@53519 619 load_store = kit->gvn().transform(new CompareAndExchangePNode(kit->control(), mem, adr, new_val, expected_val, adr_type, value_type->is_oopptr(), mo));
rkennke@53519 620 }
rkennke@52925 621 }
rkennke@52925 622
rkennke@52925 623 access.set_raw_access(load_store);
rkennke@52925 624 pin_atomic_op(access);
rkennke@52925 625
rkennke@52925 626 #ifdef _LP64
rkennke@52925 627 if (adr->bottom_type()->is_ptr_to_narrowoop()) {
rkennke@54423 628 load_store = kit->gvn().transform(new DecodeNNode(load_store, load_store->get_ptr_type()));
rkennke@52925 629 }
rkennke@52925 630 #endif
rkennke@54423 631 load_store = kit->gvn().transform(new ShenandoahLoadReferenceBarrierNode(NULL, load_store));
rkennke@52925 632 return load_store;
rkennke@52925 633 }
rkennke@52925 634 return BarrierSetC2::atomic_cmpxchg_val_at_resolved(access, expected_val, new_val, value_type);
rkennke@52925 635 }
rkennke@52925 636
rkennke@52925 637 Node* ShenandoahBarrierSetC2::atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
rkennke@52925 638 Node* new_val, const Type* value_type) const {
rkennke@52925 639 GraphKit* kit = access.kit();
rkennke@52925 640 if (access.is_oop()) {
rkennke@52925 641 new_val = shenandoah_storeval_barrier(kit, new_val);
rkennke@52925 642 shenandoah_write_barrier_pre(kit, false /* do_load */,
rkennke@52925 643 NULL, NULL, max_juint, NULL, NULL,
rkennke@52925 644 expected_val /* pre_val */, T_OBJECT);
rkennke@52925 645 DecoratorSet decorators = access.decorators();
rkennke@52925 646 MemNode::MemOrd mo = access.mem_node_mo();
rkennke@52925 647 Node* mem = access.memory();
rkennke@52925 648 bool is_weak_cas = (decorators & C2_WEAK_CMPXCHG) != 0;
rkennke@52925 649 Node* load_store = NULL;
rkennke@52925 650 Node* adr = access.addr().node();
rkennke@52925 651 #ifdef _LP64
rkennke@52925 652 if (adr->bottom_type()->is_ptr_to_narrowoop()) {
rkennke@52925 653 Node *newval_enc = kit->gvn().transform(new EncodePNode(new_val, new_val->bottom_type()->make_narrowoop()));
rkennke@52925 654 Node *oldval_enc = kit->gvn().transform(new EncodePNode(expected_val, expected_val->bottom_type()->make_narrowoop()));
rkennke@53519 655 if (ShenandoahCASBarrier) {
rkennke@53519 656 if (is_weak_cas) {
rkennke@53519 657 load_store = kit->gvn().transform(new ShenandoahWeakCompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo));
rkennke@53519 658 } else {
rkennke@53519 659 load_store = kit->gvn().transform(new ShenandoahCompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo));
rkennke@53519 660 }
rkennke@52925 661 } else {
rkennke@53519 662 if (is_weak_cas) {
rkennke@53519 663 load_store = kit->gvn().transform(new WeakCompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo));
rkennke@53519 664 } else {
rkennke@53519 665 load_store = kit->gvn().transform(new CompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo));
rkennke@53519 666 }
rkennke@52925 667 }
rkennke@52925 668 } else
rkennke@52925 669 #endif
rkennke@52925 670 {
rkennke@53519 671 if (ShenandoahCASBarrier) {
rkennke@53519 672 if (is_weak_cas) {
rkennke@53519 673 load_store = kit->gvn().transform(new ShenandoahWeakCompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo));
rkennke@53519 674 } else {
rkennke@53519 675 load_store = kit->gvn().transform(new ShenandoahCompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo));
rkennke@53519 676 }
rkennke@52925 677 } else {
rkennke@53519 678 if (is_weak_cas) {
rkennke@53519 679 load_store = kit->gvn().transform(new WeakCompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo));
rkennke@53519 680 } else {
rkennke@53519 681 load_store = kit->gvn().transform(new CompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo));
rkennke@53519 682 }
rkennke@52925 683 }
rkennke@52925 684 }
rkennke@52925 685 access.set_raw_access(load_store);
rkennke@52925 686 pin_atomic_op(access);
rkennke@52925 687 return load_store;
rkennke@52925 688 }
rkennke@52925 689 return BarrierSetC2::atomic_cmpxchg_bool_at_resolved(access, expected_val, new_val, value_type);
rkennke@52925 690 }
rkennke@52925 691
rkennke@52925 692 Node* ShenandoahBarrierSetC2::atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* val, const Type* value_type) const {
rkennke@52925 693 GraphKit* kit = access.kit();
rkennke@52925 694 if (access.is_oop()) {
rkennke@52925 695 val = shenandoah_storeval_barrier(kit, val);
rkennke@52925 696 }
rkennke@52925 697 Node* result = BarrierSetC2::atomic_xchg_at_resolved(access, val, value_type);
rkennke@52925 698 if (access.is_oop()) {
rkennke@54423 699 result = kit->gvn().transform(new ShenandoahLoadReferenceBarrierNode(NULL, result));
rkennke@52925 700 shenandoah_write_barrier_pre(kit, false /* do_load */,
rkennke@52925 701 NULL, NULL, max_juint, NULL, NULL,
rkennke@52925 702 result /* pre_val */, T_OBJECT);
rkennke@52925 703 }
rkennke@52925 704 return result;
rkennke@52925 705 }
rkennke@52925 706
rkennke@52925 707 void ShenandoahBarrierSetC2::clone(GraphKit* kit, Node* src, Node* dst, Node* size, bool is_array) const {
rkennke@52925 708 assert(!src->is_AddP(), "unexpected input");
rkennke@52925 709 BarrierSetC2::clone(kit, src, dst, size, is_array);
rkennke@52925 710 }
rkennke@52925 711
rkennke@52925 712 Node* ShenandoahBarrierSetC2::obj_allocate(PhaseMacroExpand* macro, Node* ctrl, Node* mem, Node* toobig_false, Node* size_in_bytes,
rkennke@52925 713 Node*& i_o, Node*& needgc_ctrl,
rkennke@52925 714 Node*& fast_oop_ctrl, Node*& fast_oop_rawmem,
rkennke@52925 715 intx prefetch_lines) const {
rkennke@52925 716 PhaseIterGVN& igvn = macro->igvn();
rkennke@52925 717
rkennke@52925 718 // Allocate several words more for the Shenandoah brooks pointer.
rkennke@52925 719 size_in_bytes = new AddXNode(size_in_bytes, igvn.MakeConX(ShenandoahBrooksPointer::byte_size()));
rkennke@52925 720 macro->transform_later(size_in_bytes);
rkennke@52925 721
rkennke@52925 722 Node* fast_oop = BarrierSetC2::obj_allocate(macro, ctrl, mem, toobig_false, size_in_bytes,
rkennke@52925 723 i_o, needgc_ctrl, fast_oop_ctrl, fast_oop_rawmem,
rkennke@52925 724 prefetch_lines);
rkennke@52925 725
rkennke@52925 726 // Bump up object for Shenandoah brooks pointer.
rkennke@52925 727 fast_oop = new AddPNode(macro->top(), fast_oop, igvn.MakeConX(ShenandoahBrooksPointer::byte_size()));
rkennke@52925 728 macro->transform_later(fast_oop);
rkennke@52925 729
rkennke@52925 730 // Initialize Shenandoah brooks pointer to point to the object itself.
rkennke@52925 731 fast_oop_rawmem = macro->make_store(fast_oop_ctrl, fast_oop_rawmem, fast_oop, ShenandoahBrooksPointer::byte_offset(), fast_oop, T_OBJECT);
rkennke@52925 732
rkennke@52925 733 return fast_oop;
rkennke@52925 734 }
rkennke@52925 735
rkennke@52925 736 // Support for GC barriers emitted during parsing
rkennke@52925 737 bool ShenandoahBarrierSetC2::is_gc_barrier_node(Node* node) const {
rkennke@54423 738 if (node->Opcode() == Op_ShenandoahLoadReferenceBarrier) return true;
rkennke@52925 739 if (node->Opcode() != Op_CallLeaf && node->Opcode() != Op_CallLeafNoFP) {
rkennke@52925 740 return false;
rkennke@52925 741 }
rkennke@52925 742 CallLeafNode *call = node->as_CallLeaf();
rkennke@52925 743 if (call->_name == NULL) {
rkennke@52925 744 return false;
rkennke@52925 745 }
rkennke@52925 746
rkennke@52925 747 return strcmp(call->_name, "shenandoah_clone_barrier") == 0 ||
rkennke@52925 748 strcmp(call->_name, "shenandoah_cas_obj") == 0 ||
rkennke@52925 749 strcmp(call->_name, "shenandoah_wb_pre") == 0;
rkennke@52925 750 }
rkennke@52925 751
rkennke@52925 752 Node* ShenandoahBarrierSetC2::step_over_gc_barrier(Node* c) const {
rkennke@54423 753 if (c->Opcode() == Op_ShenandoahLoadReferenceBarrier) {
rkennke@54423 754 return c->in(ShenandoahLoadReferenceBarrierNode::ValueIn);
rkennke@54423 755 }
rkennke@54423 756 if (c->Opcode() == Op_ShenandoahEnqueueBarrier) {
rkennke@54423 757 c = c->in(1);
rkennke@54423 758 }
rkennke@54423 759 return c;
rkennke@52925 760 }
rkennke@52925 761
rkennke@52925 762 bool ShenandoahBarrierSetC2::expand_barriers(Compile* C, PhaseIterGVN& igvn) const {
rkennke@54423 763 return !ShenandoahBarrierC2Support::expand(C, igvn);
rkennke@52925 764 }
rkennke@52925 765
rkennke@52925 766 bool ShenandoahBarrierSetC2::optimize_loops(PhaseIdealLoop* phase, LoopOptsMode mode, VectorSet& visited, Node_Stack& nstack, Node_List& worklist) const {
rkennke@52925 767 if (mode == LoopOptsShenandoahExpand) {
rkennke@52925 768 assert(UseShenandoahGC, "only for shenandoah");
rkennke@54423 769 ShenandoahBarrierC2Support::pin_and_expand(phase);
rkennke@52925 770 return true;
rkennke@52925 771 } else if (mode == LoopOptsShenandoahPostExpand) {
rkennke@52925 772 assert(UseShenandoahGC, "only for shenandoah");
rkennke@52925 773 visited.Clear();
rkennke@54423 774 ShenandoahBarrierC2Support::optimize_after_expansion(visited, nstack, worklist, phase);
rkennke@52925 775 return true;
rkennke@52925 776 }
rkennke@52925 777 return false;
rkennke@52925 778 }
rkennke@52925 779
rkennke@52925 780 bool ShenandoahBarrierSetC2::array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, ArrayCopyPhase phase) const {
rkennke@52925 781 bool is_oop = type == T_OBJECT || type == T_ARRAY;
rkennke@52925 782 if (!is_oop) {
rkennke@52925 783 return false;
rkennke@52925 784 }
rkennke@52925 785 if (tightly_coupled_alloc) {
rkennke@52925 786 if (phase == Optimization) {
rkennke@52925 787 return false;
rkennke@52925 788 }
rkennke@52925 789 return !is_clone;
rkennke@52925 790 }
rkennke@52925 791 if (phase == Optimization) {
rkennke@52925 792 return !ShenandoahStoreValEnqueueBarrier;
rkennke@52925 793 }
rkennke@52925 794 return true;
rkennke@52925 795 }
rkennke@52925 796
rkennke@52925 797 bool ShenandoahBarrierSetC2::clone_needs_postbarrier(ArrayCopyNode *ac, PhaseIterGVN& igvn) {
rkennke@52925 798 Node* src = ac->in(ArrayCopyNode::Src);
rkennke@52925 799 const TypeOopPtr* src_type = igvn.type(src)->is_oopptr();
rkennke@52925 800 if (src_type->isa_instptr() != NULL) {
rkennke@52925 801 ciInstanceKlass* ik = src_type->klass()->as_instance_klass();
rkennke@52925 802 if ((src_type->klass_is_exact() || (!ik->is_interface() && !ik->has_subklass())) && !ik->has_injected_fields()) {
rkennke@52925 803 if (ik->has_object_fields()) {
rkennke@52925 804 return true;
rkennke@52925 805 } else {
rkennke@52925 806 if (!src_type->klass_is_exact()) {
rkennke@52925 807 igvn.C->dependencies()->assert_leaf_type(ik);
rkennke@52925 808 }
rkennke@52925 809 }
rkennke@52925 810 } else {
rkennke@52925 811 return true;
rkennke@54423 812 }
rkennke@52925 813 } else if (src_type->isa_aryptr()) {
rkennke@52925 814 BasicType src_elem = src_type->klass()->as_array_klass()->element_type()->basic_type();
rkennke@52925 815 if (src_elem == T_OBJECT || src_elem == T_ARRAY) {
rkennke@52925 816 return true;
rkennke@52925 817 }
rkennke@52925 818 } else {
rkennke@52925 819 return true;
rkennke@52925 820 }
rkennke@52925 821 return false;
rkennke@52925 822 }
rkennke@52925 823
rkennke@52925 824 void ShenandoahBarrierSetC2::clone_barrier_at_expansion(ArrayCopyNode* ac, Node* call, PhaseIterGVN& igvn) const {
rkennke@52925 825 assert(ac->is_clonebasic(), "no other kind of arraycopy here");
rkennke@52925 826
rkennke@52925 827 if (!clone_needs_postbarrier(ac, igvn)) {
rkennke@52925 828 BarrierSetC2::clone_barrier_at_expansion(ac, call, igvn);
rkennke@52925 829 return;
rkennke@52925 830 }
rkennke@52925 831
rkennke@52925 832 const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM;
rkennke@52925 833 Node* c = new ProjNode(call,TypeFunc::Control);
rkennke@52925 834 c = igvn.transform(c);
rkennke@52925 835 Node* m = new ProjNode(call, TypeFunc::Memory);
roland@53235 836 m = igvn.transform(m);
rkennke@52925 837
rkennke@52925 838 Node* dest = ac->in(ArrayCopyNode::Dest);
rkennke@52925 839 assert(dest->is_AddP(), "bad input");
rkennke@52925 840 Node* barrier_call = new CallLeafNode(ShenandoahBarrierSetC2::shenandoah_clone_barrier_Type(),
rkennke@52925 841 CAST_FROM_FN_PTR(address, ShenandoahRuntime::shenandoah_clone_barrier),
rkennke@52925 842 "shenandoah_clone_barrier", raw_adr_type);
rkennke@52925 843 barrier_call->init_req(TypeFunc::Control, c);
rkennke@52925 844 barrier_call->init_req(TypeFunc::I_O , igvn.C->top());
rkennke@52925 845 barrier_call->init_req(TypeFunc::Memory , m);
rkennke@52925 846 barrier_call->init_req(TypeFunc::ReturnAdr, igvn.C->top());
rkennke@52925 847 barrier_call->init_req(TypeFunc::FramePtr, igvn.C->top());
rkennke@52925 848 barrier_call->init_req(TypeFunc::Parms+0, dest->in(AddPNode::Base));
rkennke@52925 849
rkennke@52925 850 barrier_call = igvn.transform(barrier_call);
rkennke@52925 851 c = new ProjNode(barrier_call,TypeFunc::Control);
rkennke@52925 852 c = igvn.transform(c);
rkennke@52925 853 m = new ProjNode(barrier_call, TypeFunc::Memory);
rkennke@52925 854 m = igvn.transform(m);
rkennke@52925 855
rkennke@52925 856 Node* out_c = ac->proj_out(TypeFunc::Control);
rkennke@52925 857 Node* out_m = ac->proj_out(TypeFunc::Memory);
rkennke@52925 858 igvn.replace_node(out_c, c);
rkennke@52925 859 igvn.replace_node(out_m, m);
rkennke@52925 860 }
rkennke@52925 861
rkennke@52925 862
rkennke@52925 863 // Support for macro expanded GC barriers
rkennke@52925 864 void ShenandoahBarrierSetC2::register_potential_barrier_node(Node* node) const {
rkennke@54423 865 if (node->Opcode() == Op_ShenandoahEnqueueBarrier) {
rkennke@54423 866 state()->add_enqueue_barrier((ShenandoahEnqueueBarrierNode*) node);
rkennke@54423 867 }
rkennke@54423 868 if (node->Opcode() == Op_ShenandoahLoadReferenceBarrier) {
rkennke@54423 869 state()->add_load_reference_barrier((ShenandoahLoadReferenceBarrierNode*) node);
rkennke@52925 870 }
rkennke@52925 871 }
rkennke@52925 872
rkennke@52925 873 void ShenandoahBarrierSetC2::unregister_potential_barrier_node(Node* node) const {
rkennke@54423 874 if (node->Opcode() == Op_ShenandoahEnqueueBarrier) {
rkennke@54423 875 state()->remove_enqueue_barrier((ShenandoahEnqueueBarrierNode*) node);
rkennke@54423 876 }
rkennke@54423 877 if (node->Opcode() == Op_ShenandoahLoadReferenceBarrier) {
rkennke@54423 878 state()->remove_load_reference_barrier((ShenandoahLoadReferenceBarrierNode*) node);
rkennke@52925 879 }
rkennke@52925 880 }
rkennke@52925 881
rkennke@52925 882 void ShenandoahBarrierSetC2::eliminate_gc_barrier(PhaseMacroExpand* macro, Node* n) const {
rkennke@52925 883 if (is_shenandoah_wb_pre_call(n)) {
rkennke@52925 884 shenandoah_eliminate_wb_pre(n, &macro->igvn());
rkennke@52925 885 }
rkennke@52925 886 }
rkennke@52925 887
rkennke@52925 888 void ShenandoahBarrierSetC2::shenandoah_eliminate_wb_pre(Node* call, PhaseIterGVN* igvn) const {
rkennke@52925 889 assert(UseShenandoahGC && is_shenandoah_wb_pre_call(call), "");
rkennke@52925 890 Node* c = call->as_Call()->proj_out(TypeFunc::Control);
rkennke@52925 891 c = c->unique_ctrl_out();
rkennke@52925 892 assert(c->is_Region() && c->req() == 3, "where's the pre barrier control flow?");
rkennke@52925 893 c = c->unique_ctrl_out();
rkennke@52925 894 assert(c->is_Region() && c->req() == 3, "where's the pre barrier control flow?");
rkennke@52925 895 Node* iff = c->in(1)->is_IfProj() ? c->in(1)->in(0) : c->in(2)->in(0);
rkennke@52925 896 assert(iff->is_If(), "expect test");
rkennke@52925 897 if (!is_shenandoah_marking_if(igvn, iff)) {
rkennke@52925 898 c = c->unique_ctrl_out();
rkennke@52925 899 assert(c->is_Region() && c->req() == 3, "where's the pre barrier control flow?");
rkennke@52925 900 iff = c->in(1)->is_IfProj() ? c->in(1)->in(0) : c->in(2)->in(0);
rkennke@52925 901 assert(is_shenandoah_marking_if(igvn, iff), "expect marking test");
rkennke@52925 902 }
rkennke@52925 903 Node* cmpx = iff->in(1)->in(1);
rkennke@52925 904 igvn->replace_node(cmpx, igvn->makecon(TypeInt::CC_EQ));
rkennke@52925 905 igvn->rehash_node_delayed(call);
rkennke@52925 906 call->del_req(call->req()-1);
rkennke@52925 907 }
rkennke@52925 908
rkennke@52925 909 void ShenandoahBarrierSetC2::enqueue_useful_gc_barrier(PhaseIterGVN* igvn, Node* node) const {
rkennke@52925 910 if (node->Opcode() == Op_AddP && ShenandoahBarrierSetC2::has_only_shenandoah_wb_pre_uses(node)) {
rkennke@52925 911 igvn->add_users_to_worklist(node);
rkennke@52925 912 }
rkennke@52925 913 }
rkennke@52925 914
rkennke@52925 915 void ShenandoahBarrierSetC2::eliminate_useless_gc_barriers(Unique_Node_List &useful, Compile* C) const {
rkennke@52925 916 for (uint i = 0; i < useful.size(); i++) {
rkennke@52925 917 Node* n = useful.at(i);
rkennke@52925 918 if (n->Opcode() == Op_AddP && ShenandoahBarrierSetC2::has_only_shenandoah_wb_pre_uses(n)) {
rkennke@52925 919 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
rkennke@52925 920 C->record_for_igvn(n->fast_out(i));
rkennke@52925 921 }
rkennke@52925 922 }
rkennke@52925 923 }
rkennke@54423 924 for (int i = state()->enqueue_barriers_count() - 1; i >= 0; i--) {
rkennke@54423 925 ShenandoahEnqueueBarrierNode* n = state()->enqueue_barrier(i);
rkennke@52925 926 if (!useful.member(n)) {
rkennke@54423 927 state()->remove_enqueue_barrier(n);
rkennke@52925 928 }
rkennke@52925 929 }
rkennke@54423 930 for (int i = state()->load_reference_barriers_count() - 1; i >= 0; i--) {
rkennke@54423 931 ShenandoahLoadReferenceBarrierNode* n = state()->load_reference_barrier(i);
rkennke@54423 932 if (!useful.member(n)) {
rkennke@54423 933 state()->remove_load_reference_barrier(n);
rkennke@54423 934 }
rkennke@54423 935 }
rkennke@52925 936 }
rkennke@52925 937
rkennke@52925 938 void ShenandoahBarrierSetC2::add_users_to_worklist(Unique_Node_List* worklist) const {}
rkennke@52925 939
rkennke@52925 940 void* ShenandoahBarrierSetC2::create_barrier_state(Arena* comp_arena) const {
rkennke@52925 941 return new(comp_arena) ShenandoahBarrierSetC2State(comp_arena);
rkennke@52925 942 }
rkennke@52925 943
rkennke@52925 944 ShenandoahBarrierSetC2State* ShenandoahBarrierSetC2::state() const {
rkennke@52925 945 return reinterpret_cast<ShenandoahBarrierSetC2State*>(Compile::current()->barrier_set_state());
rkennke@52925 946 }
rkennke@52925 947
rkennke@52925 948 // If the BarrierSetC2 state has kept macro nodes in its compilation unit state to be
rkennke@52925 949 // expanded later, then now is the time to do so.
rkennke@52925 950 bool ShenandoahBarrierSetC2::expand_macro_nodes(PhaseMacroExpand* macro) const { return false; }
rkennke@52925 951
rkennke@52925 952 #ifdef ASSERT
rkennke@52925 953 void ShenandoahBarrierSetC2::verify_gc_barriers(Compile* compile, CompilePhase phase) const {
rkennke@52925 954 if (ShenandoahVerifyOptoBarriers && phase == BarrierSetC2::BeforeExpand) {
rkennke@54423 955 ShenandoahBarrierC2Support::verify(Compile::current()->root());
rkennke@52925 956 } else if (phase == BarrierSetC2::BeforeCodeGen) {
rkennke@52925 957 // Verify G1 pre-barriers
rkennke@52925 958 const int marking_offset = in_bytes(ShenandoahThreadLocalData::satb_mark_queue_active_offset());
rkennke@52925 959
rkennke@52925 960 ResourceArea *area = Thread::current()->resource_area();
rkennke@52925 961 Unique_Node_List visited(area);
rkennke@52925 962 Node_List worklist(area);
rkennke@52925 963 // We're going to walk control flow backwards starting from the Root
rkennke@52925 964 worklist.push(compile->root());
rkennke@52925 965 while (worklist.size() > 0) {
rkennke@52925 966 Node *x = worklist.pop();
rkennke@52925 967 if (x == NULL || x == compile->top()) continue;
rkennke@52925 968 if (visited.member(x)) {
rkennke@52925 969 continue;
rkennke@52925 970 } else {
rkennke@52925 971 visited.push(x);
rkennke@52925 972 }
rkennke@52925 973
rkennke@52925 974 if (x->is_Region()) {
rkennke@52925 975 for (uint i = 1; i < x->req(); i++) {
rkennke@52925 976 worklist.push(x->in(i));
rkennke@52925 977 }
rkennke@52925 978 } else {
rkennke@52925 979 worklist.push(x->in(0));
rkennke@52925 980 // We are looking for the pattern:
rkennke@52925 981 // /->ThreadLocal
rkennke@52925 982 // If->Bool->CmpI->LoadB->AddP->ConL(marking_offset)
rkennke@52925 983 // \->ConI(0)
rkennke@52925 984 // We want to verify that the If and the LoadB have the same control
rkennke@52925 985 // See GraphKit::g1_write_barrier_pre()
rkennke@52925 986 if (x->is_If()) {
rkennke@52925 987 IfNode *iff = x->as_If();
rkennke@52925 988 if (iff->in(1)->is_Bool() && iff->in(1)->in(1)->is_Cmp()) {
rkennke@52925 989 CmpNode *cmp = iff->in(1)->in(1)->as_Cmp();
rkennke@52925 990 if (cmp->Opcode() == Op_CmpI && cmp->in(2)->is_Con() && cmp->in(2)->bottom_type()->is_int()->get_con() == 0
rkennke@52925 991 && cmp->in(1)->is_Load()) {
rkennke@52925 992 LoadNode *load = cmp->in(1)->as_Load();
rkennke@52925 993 if (load->Opcode() == Op_LoadB && load->in(2)->is_AddP() && load->in(2)->in(2)->Opcode() == Op_ThreadLocal
rkennke@52925 994 && load->in(2)->in(3)->is_Con()
rkennke@52925 995 && load->in(2)->in(3)->bottom_type()->is_intptr_t()->get_con() == marking_offset) {
rkennke@52925 996
rkennke@52925 997 Node *if_ctrl = iff->in(0);
rkennke@52925 998 Node *load_ctrl = load->in(0);
rkennke@52925 999
rkennke@52925 1000 if (if_ctrl != load_ctrl) {
rkennke@52925 1001 // Skip possible CProj->NeverBranch in infinite loops
rkennke@52925 1002 if ((if_ctrl->is_Proj() && if_ctrl->Opcode() == Op_CProj)
rkennke@52925 1003 && (if_ctrl->in(0)->is_MultiBranch() && if_ctrl->in(0)->Opcode() == Op_NeverBranch)) {
rkennke@52925 1004 if_ctrl = if_ctrl->in(0)->in(0);
rkennke@52925 1005 }
rkennke@52925 1006 }
rkennke@52925 1007 assert(load_ctrl != NULL && if_ctrl == load_ctrl, "controls must match");
rkennke@52925 1008 }
rkennke@52925 1009 }
rkennke@52925 1010 }
rkennke@52925 1011 }
rkennke@52925 1012 }
rkennke@52925 1013 }
rkennke@52925 1014 }
rkennke@52925 1015 }
rkennke@52925 1016 #endif
rkennke@52925 1017
rkennke@52925 1018 Node* ShenandoahBarrierSetC2::ideal_node(PhaseGVN* phase, Node* n, bool can_reshape) const {
rkennke@52925 1019 if (is_shenandoah_wb_pre_call(n)) {
rkennke@52925 1020 uint cnt = ShenandoahBarrierSetC2::write_ref_field_pre_entry_Type()->domain()->cnt();
rkennke@52925 1021 if (n->req() > cnt) {
rkennke@52925 1022 Node* addp = n->in(cnt);
rkennke@52925 1023 if (has_only_shenandoah_wb_pre_uses(addp)) {
rkennke@52925 1024 n->del_req(cnt);
rkennke@52925 1025 if (can_reshape) {
rkennke@52925 1026 phase->is_IterGVN()->_worklist.push(addp);
rkennke@52925 1027 }
rkennke@52925 1028 return n;
rkennke@52925 1029 }
rkennke@52925 1030 }
rkennke@52925 1031 }
rkennke@52925 1032 if (n->Opcode() == Op_CmpP) {
rkennke@52925 1033 Node* in1 = n->in(1);
rkennke@52925 1034 Node* in2 = n->in(2);
rkennke@52925 1035 if (in1->bottom_type() == TypePtr::NULL_PTR) {
rkennke@52925 1036 in2 = step_over_gc_barrier(in2);
rkennke@52925 1037 }
rkennke@52925 1038 if (in2->bottom_type() == TypePtr::NULL_PTR) {
rkennke@52925 1039 in1 = step_over_gc_barrier(in1);
rkennke@52925 1040 }
rkennke@52925 1041 PhaseIterGVN* igvn = phase->is_IterGVN();
rkennke@52925 1042 if (in1 != n->in(1)) {
rkennke@52925 1043 if (igvn != NULL) {
rkennke@52925 1044 n->set_req_X(1, in1, igvn);
rkennke@52925 1045 } else {
rkennke@52925 1046 n->set_req(1, in1);
rkennke@52925 1047 }
rkennke@52925 1048 assert(in2 == n->in(2), "only one change");
rkennke@52925 1049 return n;
rkennke@52925 1050 }
rkennke@52925 1051 if (in2 != n->in(2)) {
rkennke@52925 1052 if (igvn != NULL) {
rkennke@52925 1053 n->set_req_X(2, in2, igvn);
rkennke@52925 1054 } else {
rkennke@52925 1055 n->set_req(2, in2);
rkennke@52925 1056 }
rkennke@52925 1057 return n;
rkennke@52925 1058 }
rkennke@52925 1059 } else if (can_reshape &&
rkennke@52925 1060 n->Opcode() == Op_If &&
rkennke@54423 1061 ShenandoahBarrierC2Support::is_heap_stable_test(n) &&
rkennke@52925 1062 n->in(0) != NULL) {
rkennke@52925 1063 Node* dom = n->in(0);
rkennke@52925 1064 Node* prev_dom = n;
rkennke@52925 1065 int op = n->Opcode();
rkennke@52925 1066 int dist = 16;
rkennke@52925 1067 // Search up the dominator tree for another heap stable test
rkennke@52925 1068 while (dom->Opcode() != op || // Not same opcode?
rkennke@54423 1069 !ShenandoahBarrierC2Support::is_heap_stable_test(dom) || // Not same input 1?
rkennke@52925 1070 prev_dom->in(0) != dom) { // One path of test does not dominate?
rkennke@52925 1071 if (dist < 0) return NULL;
rkennke@52925 1072
rkennke@52925 1073 dist--;
rkennke@52925 1074 prev_dom = dom;
rkennke@52925 1075 dom = IfNode::up_one_dom(dom);
rkennke@52925 1076 if (!dom) return NULL;
rkennke@52925 1077 }
rkennke@52925 1078
rkennke@52925 1079 // Check that we did not follow a loop back to ourselves
rkennke@52925 1080 if (n == dom) {
rkennke@52925 1081 return NULL;
rkennke@52925 1082 }
rkennke@52925 1083
rkennke@52925 1084 return n->as_If()->dominated_by(prev_dom, phase->is_IterGVN());
rkennke@52925 1085 }
rkennke@52925 1086
rkennke@52925 1087 return NULL;
rkennke@52925 1088 }
rkennke@52925 1089
rkennke@52925 1090 bool ShenandoahBarrierSetC2::has_only_shenandoah_wb_pre_uses(Node* n) {
rkennke@52925 1091 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
rkennke@52925 1092 Node* u = n->fast_out(i);
rkennke@52925 1093 if (!is_shenandoah_wb_pre_call(u)) {
rkennke@52925 1094 return false;
rkennke@52925 1095 }
rkennke@52925 1096 }
rkennke@52925 1097 return n->outcnt() > 0;
rkennke@52925 1098 }
rkennke@52925 1099
rkennke@52925 1100 bool ShenandoahBarrierSetC2::final_graph_reshaping(Compile* compile, Node* n, uint opcode) const {
rkennke@52925 1101 switch (opcode) {
rkennke@52925 1102 case Op_CallLeaf:
rkennke@52925 1103 case Op_CallLeafNoFP: {
rkennke@52925 1104 assert (n->is_Call(), "");
rkennke@52925 1105 CallNode *call = n->as_Call();
rkennke@52925 1106 if (ShenandoahBarrierSetC2::is_shenandoah_wb_pre_call(call)) {
rkennke@52925 1107 uint cnt = ShenandoahBarrierSetC2::write_ref_field_pre_entry_Type()->domain()->cnt();
rkennke@52925 1108 if (call->req() > cnt) {
rkennke@52925 1109 assert(call->req() == cnt + 1, "only one extra input");
rkennke@52925 1110 Node *addp = call->in(cnt);
rkennke@52925 1111 assert(!ShenandoahBarrierSetC2::has_only_shenandoah_wb_pre_uses(addp), "useless address computation?");
rkennke@52925 1112 call->del_req(cnt);
rkennke@52925 1113 }
rkennke@52925 1114 }
rkennke@52925 1115 return false;
rkennke@52925 1116 }
rkennke@52925 1117 case Op_ShenandoahCompareAndSwapP:
rkennke@52925 1118 case Op_ShenandoahCompareAndSwapN:
rkennke@52925 1119 case Op_ShenandoahWeakCompareAndSwapN:
rkennke@52925 1120 case Op_ShenandoahWeakCompareAndSwapP:
rkennke@52925 1121 case Op_ShenandoahCompareAndExchangeP:
rkennke@52925 1122 case Op_ShenandoahCompareAndExchangeN:
rkennke@52925 1123 #ifdef ASSERT
rkennke@52925 1124 if( VerifyOptoOopOffsets ) {
rkennke@52925 1125 MemNode* mem = n->as_Mem();
rkennke@52925 1126 // Check to see if address types have grounded out somehow.
rkennke@52925 1127 const TypeInstPtr *tp = mem->in(MemNode::Address)->bottom_type()->isa_instptr();
rkennke@52925 1128 ciInstanceKlass *k = tp->klass()->as_instance_klass();
rkennke@52925 1129 bool oop_offset_is_sane = k->contains_field_offset(tp->offset());
rkennke@52925 1130 assert( !tp || oop_offset_is_sane, "" );
rkennke@52925 1131 }
rkennke@52925 1132 #endif
rkennke@52925 1133 return true;
rkennke@54423 1134 case Op_ShenandoahLoadReferenceBarrier:
rkennke@52925 1135 assert(false, "should have been expanded already");
rkennke@52925 1136 return true;
rkennke@52925 1137 default:
rkennke@52925 1138 return false;
rkennke@52925 1139 }
rkennke@52925 1140 }
rkennke@52925 1141
rkennke@52925 1142 bool ShenandoahBarrierSetC2::escape_add_to_con_graph(ConnectionGraph* conn_graph, PhaseGVN* gvn, Unique_Node_List* delayed_worklist, Node* n, uint opcode) const {
rkennke@52925 1143 switch (opcode) {
rkennke@52925 1144 case Op_ShenandoahCompareAndExchangeP:
rkennke@52925 1145 case Op_ShenandoahCompareAndExchangeN:
rkennke@52925 1146 conn_graph->add_objload_to_connection_graph(n, delayed_worklist);
rkennke@52925 1147 // fallthrough
rkennke@52925 1148 case Op_ShenandoahWeakCompareAndSwapP:
rkennke@52925 1149 case Op_ShenandoahWeakCompareAndSwapN:
rkennke@52925 1150 case Op_ShenandoahCompareAndSwapP:
rkennke@52925 1151 case Op_ShenandoahCompareAndSwapN:
rkennke@52925 1152 conn_graph->add_to_congraph_unsafe_access(n, opcode, delayed_worklist);
rkennke@52925 1153 return true;
rkennke@52925 1154 case Op_StoreP: {
rkennke@52925 1155 Node* adr = n->in(MemNode::Address);
rkennke@52925 1156 const Type* adr_type = gvn->type(adr);
rkennke@52925 1157 // Pointer stores in G1 barriers looks like unsafe access.
rkennke@52925 1158 // Ignore such stores to be able scalar replace non-escaping
rkennke@52925 1159 // allocations.
rkennke@52925 1160 if (adr_type->isa_rawptr() && adr->is_AddP()) {
rkennke@52925 1161 Node* base = conn_graph->get_addp_base(adr);
rkennke@52925 1162 if (base->Opcode() == Op_LoadP &&
rkennke@52925 1163 base->in(MemNode::Address)->is_AddP()) {
rkennke@52925 1164 adr = base->in(MemNode::Address);
rkennke@52925 1165 Node* tls = conn_graph->get_addp_base(adr);
rkennke@52925 1166 if (tls->Opcode() == Op_ThreadLocal) {
rkennke@52925 1167 int offs = (int) gvn->find_intptr_t_con(adr->in(AddPNode::Offset), Type::OffsetBot);
rkennke@52925 1168 const int buf_offset = in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset());
rkennke@52925 1169 if (offs == buf_offset) {
rkennke@52925 1170 return true; // Pre barrier previous oop value store.
rkennke@52925 1171 }
rkennke@52925 1172 }
rkennke@52925 1173 }
rkennke@52925 1174 }
rkennke@52925 1175 return false;
rkennke@52925 1176 }
rkennke@52925 1177 case Op_ShenandoahEnqueueBarrier:
rkennke@52925 1178 conn_graph->add_local_var_and_edge(n, PointsToNode::NoEscape, n->in(1), delayed_worklist);
rkennke@52925 1179 break;
rkennke@54423 1180 case Op_ShenandoahLoadReferenceBarrier:
rkennke@54423 1181 conn_graph->add_local_var_and_edge(n, PointsToNode::NoEscape, n->in(ShenandoahLoadReferenceBarrierNode::ValueIn), delayed_worklist);
rkennke@54423 1182 return true;
rkennke@52925 1183 default:
rkennke@52925 1184 // Nothing
rkennke@52925 1185 break;
rkennke@52925 1186 }
rkennke@52925 1187 return false;
rkennke@52925 1188 }
rkennke@52925 1189
rkennke@52925 1190 bool ShenandoahBarrierSetC2::escape_add_final_edges(ConnectionGraph* conn_graph, PhaseGVN* gvn, Node* n, uint opcode) const {
rkennke@52925 1191 switch (opcode) {
rkennke@52925 1192 case Op_ShenandoahCompareAndExchangeP:
rkennke@52925 1193 case Op_ShenandoahCompareAndExchangeN: {
rkennke@52925 1194 Node *adr = n->in(MemNode::Address);
rkennke@52925 1195 conn_graph->add_local_var_and_edge(n, PointsToNode::NoEscape, adr, NULL);
rkennke@52925 1196 // fallthrough
rkennke@52925 1197 }
rkennke@52925 1198 case Op_ShenandoahCompareAndSwapP:
rkennke@52925 1199 case Op_ShenandoahCompareAndSwapN:
rkennke@52925 1200 case Op_ShenandoahWeakCompareAndSwapP:
rkennke@52925 1201 case Op_ShenandoahWeakCompareAndSwapN:
rkennke@52925 1202 return conn_graph->add_final_edges_unsafe_access(n, opcode);
rkennke@52925 1203 case Op_ShenandoahEnqueueBarrier:
rkennke@52925 1204 conn_graph->add_local_var_and_edge(n, PointsToNode::NoEscape, n->in(1), NULL);
rkennke@52925 1205 return true;
rkennke@54423 1206 case Op_ShenandoahLoadReferenceBarrier:
rkennke@54423 1207 conn_graph->add_local_var_and_edge(n, PointsToNode::NoEscape, n->in(ShenandoahLoadReferenceBarrierNode::ValueIn), NULL);
rkennke@54423 1208 return true;
rkennke@52925 1209 default:
rkennke@52925 1210 // Nothing
rkennke@52925 1211 break;
rkennke@52925 1212 }
rkennke@52925 1213 return false;
rkennke@52925 1214 }
rkennke@52925 1215
rkennke@52925 1216 bool ShenandoahBarrierSetC2::escape_has_out_with_unsafe_object(Node* n) const {
rkennke@52925 1217 return n->has_out_with(Op_ShenandoahCompareAndExchangeP) || n->has_out_with(Op_ShenandoahCompareAndExchangeN) ||
rkennke@52925 1218 n->has_out_with(Op_ShenandoahCompareAndSwapP, Op_ShenandoahCompareAndSwapN, Op_ShenandoahWeakCompareAndSwapP, Op_ShenandoahWeakCompareAndSwapN);
rkennke@52925 1219
rkennke@52925 1220 }
rkennke@52925 1221
rkennke@52925 1222 bool ShenandoahBarrierSetC2::escape_is_barrier_node(Node* n) const {
rkennke@54423 1223 return n->Opcode() == Op_ShenandoahLoadReferenceBarrier;
rkennke@52925 1224 }
rkennke@52925 1225
rkennke@52925 1226 bool ShenandoahBarrierSetC2::matcher_find_shared_post_visit(Matcher* matcher, Node* n, uint opcode) const {
rkennke@52925 1227 switch (opcode) {
rkennke@52925 1228 case Op_ShenandoahCompareAndExchangeP:
rkennke@52925 1229 case Op_ShenandoahCompareAndExchangeN:
rkennke@52925 1230 case Op_ShenandoahWeakCompareAndSwapP:
rkennke@52925 1231 case Op_ShenandoahWeakCompareAndSwapN:
rkennke@52925 1232 case Op_ShenandoahCompareAndSwapP:
rkennke@52925 1233 case Op_ShenandoahCompareAndSwapN: { // Convert trinary to binary-tree
rkennke@52925 1234 Node* newval = n->in(MemNode::ValueIn);
rkennke@52925 1235 Node* oldval = n->in(LoadStoreConditionalNode::ExpectedIn);
rkennke@52925 1236 Node* pair = new BinaryNode(oldval, newval);
rkennke@52925 1237 n->set_req(MemNode::ValueIn,pair);
rkennke@52925 1238 n->del_req(LoadStoreConditionalNode::ExpectedIn);
rkennke@52925 1239 return true;
rkennke@52925 1240 }
rkennke@52925 1241 default:
rkennke@52925 1242 break;
rkennke@52925 1243 }
rkennke@52925 1244 return false;
rkennke@52925 1245 }
rkennke@52925 1246
rkennke@52925 1247 bool ShenandoahBarrierSetC2::matcher_is_store_load_barrier(Node* x, uint xop) const {
rkennke@52925 1248 return xop == Op_ShenandoahCompareAndExchangeP ||
rkennke@52925 1249 xop == Op_ShenandoahCompareAndExchangeN ||
rkennke@52925 1250 xop == Op_ShenandoahWeakCompareAndSwapP ||
rkennke@52925 1251 xop == Op_ShenandoahWeakCompareAndSwapN ||
rkennke@52925 1252 xop == Op_ShenandoahCompareAndSwapN ||
rkennke@52925 1253 xop == Op_ShenandoahCompareAndSwapP;
rkennke@52925 1254 }