annotate src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.cpp @ 54048:744dc9c33676

8217417: Decorator name typo: C2_TIGHLY_COUPLED_ALLOC Summary: Fixed typo in decorator name, variables, and comments. Reviewed-by: tschatzl
author kbarrett
date Mon, 11 Mar 2019 02:05:07 -0400
parents 74a5ef4c81cc
children 6c0ab8bd8da5
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@52925 46 : _shenandoah_barriers(new (comp_arena) GrowableArray<ShenandoahWriteBarrierNode*>(comp_arena, 8, 0, NULL)) {
rkennke@52925 47 }
rkennke@52925 48
rkennke@52925 49 int ShenandoahBarrierSetC2State::shenandoah_barriers_count() const {
rkennke@52925 50 return _shenandoah_barriers->length();
rkennke@52925 51 }
rkennke@52925 52
rkennke@52925 53 ShenandoahWriteBarrierNode* ShenandoahBarrierSetC2State::shenandoah_barrier(int idx) const {
rkennke@52925 54 return _shenandoah_barriers->at(idx);
rkennke@52925 55 }
rkennke@52925 56
rkennke@52925 57 void ShenandoahBarrierSetC2State::add_shenandoah_barrier(ShenandoahWriteBarrierNode * n) {
rkennke@52925 58 assert(!_shenandoah_barriers->contains(n), "duplicate entry in barrier list");
rkennke@52925 59 _shenandoah_barriers->append(n);
rkennke@52925 60 }
rkennke@52925 61
rkennke@52925 62 void ShenandoahBarrierSetC2State::remove_shenandoah_barrier(ShenandoahWriteBarrierNode * n) {
rkennke@52925 63 if (_shenandoah_barriers->contains(n)) {
rkennke@52925 64 _shenandoah_barriers->remove(n);
rkennke@52925 65 }
rkennke@52925 66 }
rkennke@52925 67
rkennke@52925 68 #define __ kit->
rkennke@52925 69
rkennke@52925 70 Node* ShenandoahBarrierSetC2::shenandoah_read_barrier(GraphKit* kit, Node* obj) const {
rkennke@52925 71 if (ShenandoahReadBarrier) {
rkennke@52925 72 obj = shenandoah_read_barrier_impl(kit, obj, false, true, true);
rkennke@52925 73 }
rkennke@52925 74 return obj;
rkennke@52925 75 }
rkennke@52925 76
rkennke@52925 77 Node* ShenandoahBarrierSetC2::shenandoah_storeval_barrier(GraphKit* kit, Node* obj) const {
rkennke@52925 78 if (ShenandoahStoreValEnqueueBarrier) {
rkennke@52925 79 obj = shenandoah_write_barrier(kit, obj);
rkennke@52925 80 obj = shenandoah_enqueue_barrier(kit, obj);
rkennke@52925 81 }
rkennke@52925 82 if (ShenandoahStoreValReadBarrier) {
rkennke@52925 83 obj = shenandoah_read_barrier_impl(kit, obj, true, false, false);
rkennke@52925 84 }
rkennke@52925 85 return obj;
rkennke@52925 86 }
rkennke@52925 87
rkennke@52925 88 Node* ShenandoahBarrierSetC2::shenandoah_read_barrier_impl(GraphKit* kit, Node* obj, bool use_ctrl, bool use_mem, bool allow_fromspace) const {
rkennke@52925 89 const Type* obj_type = obj->bottom_type();
rkennke@52925 90 if (obj_type->higher_equal(TypePtr::NULL_PTR)) {
rkennke@52925 91 return obj;
rkennke@52925 92 }
rkennke@52925 93 const TypePtr* adr_type = ShenandoahBarrierNode::brooks_pointer_type(obj_type);
rkennke@52925 94 Node* mem = use_mem ? __ memory(adr_type) : __ immutable_memory();
rkennke@52925 95
rkennke@52925 96 if (! ShenandoahBarrierNode::needs_barrier(&__ gvn(), NULL, obj, mem, allow_fromspace)) {
rkennke@52925 97 // We know it is null, no barrier needed.
rkennke@52925 98 return obj;
rkennke@52925 99 }
rkennke@52925 100
rkennke@52925 101 if (obj_type->meet(TypePtr::NULL_PTR) == obj_type->remove_speculative()) {
rkennke@52925 102
rkennke@52925 103 // We don't know if it's null or not. Need null-check.
rkennke@52925 104 enum { _not_null_path = 1, _null_path, PATH_LIMIT };
rkennke@52925 105 RegionNode* region = new RegionNode(PATH_LIMIT);
rkennke@52925 106 Node* phi = new PhiNode(region, obj_type);
rkennke@52925 107 Node* null_ctrl = __ top();
rkennke@52925 108 Node* not_null_obj = __ null_check_oop(obj, &null_ctrl);
rkennke@52925 109
rkennke@52925 110 region->init_req(_null_path, null_ctrl);
rkennke@52925 111 phi ->init_req(_null_path, __ zerocon(T_OBJECT));
rkennke@52925 112
rkennke@52925 113 Node* ctrl = use_ctrl ? __ control() : NULL;
rkennke@52925 114 ShenandoahReadBarrierNode* rb = new ShenandoahReadBarrierNode(ctrl, mem, not_null_obj, allow_fromspace);
rkennke@52925 115 Node* n = __ gvn().transform(rb);
rkennke@52925 116
rkennke@52925 117 region->init_req(_not_null_path, __ control());
rkennke@52925 118 phi ->init_req(_not_null_path, n);
rkennke@52925 119
rkennke@52925 120 __ set_control(__ gvn().transform(region));
rkennke@52925 121 __ record_for_igvn(region);
rkennke@52925 122 return __ gvn().transform(phi);
rkennke@52925 123
rkennke@52925 124 } else {
rkennke@52925 125 // We know it is not null. Simple barrier is sufficient.
rkennke@52925 126 Node* ctrl = use_ctrl ? __ control() : NULL;
rkennke@52925 127 ShenandoahReadBarrierNode* rb = new ShenandoahReadBarrierNode(ctrl, mem, obj, allow_fromspace);
rkennke@52925 128 Node* n = __ gvn().transform(rb);
rkennke@52925 129 __ record_for_igvn(n);
rkennke@52925 130 return n;
rkennke@52925 131 }
rkennke@52925 132 }
rkennke@52925 133
rkennke@52925 134 Node* ShenandoahBarrierSetC2::shenandoah_write_barrier_helper(GraphKit* kit, Node* obj, const TypePtr* adr_type) const {
rkennke@52925 135 ShenandoahWriteBarrierNode* wb = new ShenandoahWriteBarrierNode(kit->C, kit->control(), kit->memory(adr_type), obj);
rkennke@52925 136 Node* n = __ gvn().transform(wb);
rkennke@52925 137 if (n == wb) { // New barrier needs memory projection.
rkennke@52925 138 Node* proj = __ gvn().transform(new ShenandoahWBMemProjNode(n));
rkennke@52925 139 __ set_memory(proj, adr_type);
rkennke@52925 140 }
rkennke@52925 141 return n;
rkennke@52925 142 }
rkennke@52925 143
rkennke@52925 144 Node* ShenandoahBarrierSetC2::shenandoah_write_barrier(GraphKit* kit, Node* obj) const {
rkennke@52925 145 if (ShenandoahWriteBarrier) {
rkennke@52925 146 obj = shenandoah_write_barrier_impl(kit, obj);
rkennke@52925 147 }
rkennke@52925 148 return obj;
rkennke@52925 149 }
rkennke@52925 150
rkennke@52925 151 Node* ShenandoahBarrierSetC2::shenandoah_write_barrier_impl(GraphKit* kit, Node* obj) const {
rkennke@52925 152 if (! ShenandoahBarrierNode::needs_barrier(&__ gvn(), NULL, obj, NULL, true)) {
rkennke@52925 153 return obj;
rkennke@52925 154 }
rkennke@52925 155 const Type* obj_type = obj->bottom_type();
rkennke@52925 156 const TypePtr* adr_type = ShenandoahBarrierNode::brooks_pointer_type(obj_type);
rkennke@52925 157 Node* n = shenandoah_write_barrier_helper(kit, obj, adr_type);
rkennke@52925 158 __ record_for_igvn(n);
rkennke@52925 159 return n;
rkennke@52925 160 }
rkennke@52925 161
rkennke@52925 162 bool ShenandoahBarrierSetC2::satb_can_remove_pre_barrier(GraphKit* kit, PhaseTransform* phase, Node* adr,
rkennke@52925 163 BasicType bt, uint adr_idx) const {
rkennke@52925 164 intptr_t offset = 0;
rkennke@52925 165 Node* base = AddPNode::Ideal_base_and_offset(adr, phase, offset);
rkennke@52925 166 AllocateNode* alloc = AllocateNode::Ideal_allocation(base, phase);
rkennke@52925 167
rkennke@52925 168 if (offset == Type::OffsetBot) {
rkennke@52925 169 return false; // cannot unalias unless there are precise offsets
rkennke@52925 170 }
rkennke@52925 171
rkennke@52925 172 if (alloc == NULL) {
rkennke@52925 173 return false; // No allocation found
rkennke@52925 174 }
rkennke@52925 175
rkennke@52925 176 intptr_t size_in_bytes = type2aelembytes(bt);
rkennke@52925 177
rkennke@52925 178 Node* mem = __ memory(adr_idx); // start searching here...
rkennke@52925 179
rkennke@52925 180 for (int cnt = 0; cnt < 50; cnt++) {
rkennke@52925 181
rkennke@52925 182 if (mem->is_Store()) {
rkennke@52925 183
rkennke@52925 184 Node* st_adr = mem->in(MemNode::Address);
rkennke@52925 185 intptr_t st_offset = 0;
rkennke@52925 186 Node* st_base = AddPNode::Ideal_base_and_offset(st_adr, phase, st_offset);
rkennke@52925 187
rkennke@52925 188 if (st_base == NULL) {
rkennke@52925 189 break; // inscrutable pointer
rkennke@52925 190 }
rkennke@52925 191
rkennke@52925 192 // Break we have found a store with same base and offset as ours so break
rkennke@52925 193 if (st_base == base && st_offset == offset) {
rkennke@52925 194 break;
rkennke@52925 195 }
rkennke@52925 196
rkennke@52925 197 if (st_offset != offset && st_offset != Type::OffsetBot) {
rkennke@52925 198 const int MAX_STORE = BytesPerLong;
rkennke@52925 199 if (st_offset >= offset + size_in_bytes ||
rkennke@52925 200 st_offset <= offset - MAX_STORE ||
rkennke@52925 201 st_offset <= offset - mem->as_Store()->memory_size()) {
rkennke@52925 202 // Success: The offsets are provably independent.
rkennke@52925 203 // (You may ask, why not just test st_offset != offset and be done?
rkennke@52925 204 // The answer is that stores of different sizes can co-exist
rkennke@52925 205 // in the same sequence of RawMem effects. We sometimes initialize
rkennke@52925 206 // a whole 'tile' of array elements with a single jint or jlong.)
rkennke@52925 207 mem = mem->in(MemNode::Memory);
rkennke@52925 208 continue; // advance through independent store memory
rkennke@52925 209 }
rkennke@52925 210 }
rkennke@52925 211
rkennke@52925 212 if (st_base != base
rkennke@52925 213 && MemNode::detect_ptr_independence(base, alloc, st_base,
rkennke@52925 214 AllocateNode::Ideal_allocation(st_base, phase),
rkennke@52925 215 phase)) {
rkennke@52925 216 // Success: The bases are provably independent.
rkennke@52925 217 mem = mem->in(MemNode::Memory);
rkennke@52925 218 continue; // advance through independent store memory
rkennke@52925 219 }
rkennke@52925 220 } else if (mem->is_Proj() && mem->in(0)->is_Initialize()) {
rkennke@52925 221
rkennke@52925 222 InitializeNode* st_init = mem->in(0)->as_Initialize();
rkennke@52925 223 AllocateNode* st_alloc = st_init->allocation();
rkennke@52925 224
rkennke@52925 225 // Make sure that we are looking at the same allocation site.
rkennke@52925 226 // The alloc variable is guaranteed to not be null here from earlier check.
rkennke@52925 227 if (alloc == st_alloc) {
rkennke@52925 228 // Check that the initialization is storing NULL so that no previous store
rkennke@52925 229 // has been moved up and directly write a reference
rkennke@52925 230 Node* captured_store = st_init->find_captured_store(offset,
rkennke@52925 231 type2aelembytes(T_OBJECT),
rkennke@52925 232 phase);
rkennke@52925 233 if (captured_store == NULL || captured_store == st_init->zero_memory()) {
rkennke@52925 234 return true;
rkennke@52925 235 }
rkennke@52925 236 }
rkennke@52925 237 }
rkennke@52925 238
rkennke@52925 239 // Unless there is an explicit 'continue', we must bail out here,
rkennke@52925 240 // because 'mem' is an inscrutable memory state (e.g., a call).
rkennke@52925 241 break;
rkennke@52925 242 }
rkennke@52925 243
rkennke@52925 244 return false;
rkennke@52925 245 }
rkennke@52925 246
rkennke@52925 247 #undef __
rkennke@52925 248 #define __ ideal.
rkennke@52925 249
rkennke@52925 250 void ShenandoahBarrierSetC2::satb_write_barrier_pre(GraphKit* kit,
rkennke@52925 251 bool do_load,
rkennke@52925 252 Node* obj,
rkennke@52925 253 Node* adr,
rkennke@52925 254 uint alias_idx,
rkennke@52925 255 Node* val,
rkennke@52925 256 const TypeOopPtr* val_type,
rkennke@52925 257 Node* pre_val,
rkennke@52925 258 BasicType bt) const {
rkennke@52925 259 // Some sanity checks
rkennke@52925 260 // Note: val is unused in this routine.
rkennke@52925 261
rkennke@52925 262 if (do_load) {
rkennke@52925 263 // We need to generate the load of the previous value
rkennke@52925 264 assert(obj != NULL, "must have a base");
rkennke@52925 265 assert(adr != NULL, "where are loading from?");
rkennke@52925 266 assert(pre_val == NULL, "loaded already?");
rkennke@52925 267 assert(val_type != NULL, "need a type");
rkennke@52925 268
rkennke@52925 269 if (ReduceInitialCardMarks
rkennke@52925 270 && satb_can_remove_pre_barrier(kit, &kit->gvn(), adr, bt, alias_idx)) {
rkennke@52925 271 return;
rkennke@52925 272 }
rkennke@52925 273
rkennke@52925 274 } else {
rkennke@52925 275 // In this case both val_type and alias_idx are unused.
rkennke@52925 276 assert(pre_val != NULL, "must be loaded already");
rkennke@52925 277 // Nothing to be done if pre_val is null.
rkennke@52925 278 if (pre_val->bottom_type() == TypePtr::NULL_PTR) return;
rkennke@52925 279 assert(pre_val->bottom_type()->basic_type() == T_OBJECT, "or we shouldn't be here");
rkennke@52925 280 }
rkennke@52925 281 assert(bt == T_OBJECT, "or we shouldn't be here");
rkennke@52925 282
rkennke@52925 283 IdealKit ideal(kit, true);
rkennke@52925 284
rkennke@52925 285 Node* tls = __ thread(); // ThreadLocalStorage
rkennke@52925 286
rkennke@52925 287 Node* no_base = __ top();
rkennke@52925 288 Node* zero = __ ConI(0);
rkennke@52925 289 Node* zeroX = __ ConX(0);
rkennke@52925 290
rkennke@52925 291 float likely = PROB_LIKELY(0.999);
rkennke@52925 292 float unlikely = PROB_UNLIKELY(0.999);
rkennke@52925 293
rkennke@52925 294 // Offsets into the thread
rkennke@52925 295 const int index_offset = in_bytes(ShenandoahThreadLocalData::satb_mark_queue_index_offset());
rkennke@52925 296 const int buffer_offset = in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset());
rkennke@52925 297
rkennke@52925 298 // Now the actual pointers into the thread
rkennke@52925 299 Node* buffer_adr = __ AddP(no_base, tls, __ ConX(buffer_offset));
rkennke@52925 300 Node* index_adr = __ AddP(no_base, tls, __ ConX(index_offset));
rkennke@52925 301
rkennke@52925 302 // Now some of the values
rkennke@52925 303 Node* marking;
rkennke@52925 304 Node* gc_state = __ AddP(no_base, tls, __ ConX(in_bytes(ShenandoahThreadLocalData::gc_state_offset())));
rkennke@52925 305 Node* ld = __ load(__ ctrl(), gc_state, TypeInt::BYTE, T_BYTE, Compile::AliasIdxRaw);
rkennke@52925 306 marking = __ AndI(ld, __ ConI(ShenandoahHeap::MARKING));
rkennke@52925 307 assert(ShenandoahWriteBarrierNode::is_gc_state_load(ld), "Should match the shape");
rkennke@52925 308
rkennke@52925 309 // if (!marking)
rkennke@52925 310 __ if_then(marking, BoolTest::ne, zero, unlikely); {
rkennke@52925 311 BasicType index_bt = TypeX_X->basic_type();
rkennke@52925 312 assert(sizeof(size_t) == type2aelembytes(index_bt), "Loading G1 SATBMarkQueue::_index with wrong size.");
rkennke@52925 313 Node* index = __ load(__ ctrl(), index_adr, TypeX_X, index_bt, Compile::AliasIdxRaw);
rkennke@52925 314
rkennke@52925 315 if (do_load) {
rkennke@52925 316 // load original value
rkennke@52925 317 // alias_idx correct??
rkennke@52925 318 pre_val = __ load(__ ctrl(), adr, val_type, bt, alias_idx);
rkennke@52925 319 }
rkennke@52925 320
rkennke@52925 321 // if (pre_val != NULL)
rkennke@52925 322 __ if_then(pre_val, BoolTest::ne, kit->null()); {
rkennke@52925 323 Node* buffer = __ load(__ ctrl(), buffer_adr, TypeRawPtr::NOTNULL, T_ADDRESS, Compile::AliasIdxRaw);
rkennke@52925 324
rkennke@52925 325 // is the queue for this thread full?
rkennke@52925 326 __ if_then(index, BoolTest::ne, zeroX, likely); {
rkennke@52925 327
rkennke@52925 328 // decrement the index
rkennke@52925 329 Node* next_index = kit->gvn().transform(new SubXNode(index, __ ConX(sizeof(intptr_t))));
rkennke@52925 330
rkennke@52925 331 // Now get the buffer location we will log the previous value into and store it
rkennke@52925 332 Node *log_addr = __ AddP(no_base, buffer, next_index);
rkennke@52925 333 __ store(__ ctrl(), log_addr, pre_val, T_OBJECT, Compile::AliasIdxRaw, MemNode::unordered);
rkennke@52925 334 // update the index
rkennke@52925 335 __ store(__ ctrl(), index_adr, next_index, index_bt, Compile::AliasIdxRaw, MemNode::unordered);
rkennke@52925 336
rkennke@52925 337 } __ else_(); {
rkennke@52925 338
rkennke@52925 339 // logging buffer is full, call the runtime
rkennke@52925 340 const TypeFunc *tf = ShenandoahBarrierSetC2::write_ref_field_pre_entry_Type();
rkennke@52925 341 __ make_leaf_call(tf, CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), "shenandoah_wb_pre", pre_val, tls);
rkennke@52925 342 } __ end_if(); // (!index)
rkennke@52925 343 } __ end_if(); // (pre_val != NULL)
rkennke@52925 344 } __ end_if(); // (!marking)
rkennke@52925 345
rkennke@52925 346 // Final sync IdealKit and GraphKit.
rkennke@52925 347 kit->final_sync(ideal);
rkennke@52925 348
rkennke@52925 349 if (ShenandoahSATBBarrier && adr != NULL) {
rkennke@52925 350 Node* c = kit->control();
rkennke@52925 351 Node* call = c->in(1)->in(1)->in(1)->in(0);
rkennke@52925 352 assert(is_shenandoah_wb_pre_call(call), "shenandoah_wb_pre call expected");
rkennke@52925 353 call->add_req(adr);
rkennke@52925 354 }
rkennke@52925 355 }
rkennke@52925 356
rkennke@52925 357 bool ShenandoahBarrierSetC2::is_shenandoah_wb_pre_call(Node* call) {
rkennke@52925 358 return call->is_CallLeaf() &&
rkennke@52925 359 call->as_CallLeaf()->entry_point() == CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry);
rkennke@52925 360 }
rkennke@52925 361
rkennke@52925 362 bool ShenandoahBarrierSetC2::is_shenandoah_wb_call(Node* call) {
rkennke@52925 363 return call->is_CallLeaf() &&
rkennke@52925 364 call->as_CallLeaf()->entry_point() == CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_barrier_JRT);
rkennke@52925 365 }
rkennke@52925 366
rkennke@52925 367 bool ShenandoahBarrierSetC2::is_shenandoah_marking_if(PhaseTransform *phase, Node* n) {
rkennke@52925 368 if (n->Opcode() != Op_If) {
rkennke@52925 369 return false;
rkennke@52925 370 }
rkennke@52925 371
rkennke@52925 372 Node* bol = n->in(1);
rkennke@52925 373 assert(bol->is_Bool(), "");
rkennke@52925 374 Node* cmpx = bol->in(1);
rkennke@52925 375 if (bol->as_Bool()->_test._test == BoolTest::ne &&
rkennke@52925 376 cmpx->is_Cmp() && cmpx->in(2) == phase->intcon(0) &&
rkennke@52925 377 is_shenandoah_state_load(cmpx->in(1)->in(1)) &&
rkennke@52925 378 cmpx->in(1)->in(2)->is_Con() &&
rkennke@52925 379 cmpx->in(1)->in(2) == phase->intcon(ShenandoahHeap::MARKING)) {
rkennke@52925 380 return true;
rkennke@52925 381 }
rkennke@52925 382
rkennke@52925 383 return false;
rkennke@52925 384 }
rkennke@52925 385
rkennke@52925 386 bool ShenandoahBarrierSetC2::is_shenandoah_state_load(Node* n) {
rkennke@52925 387 if (!n->is_Load()) return false;
rkennke@52925 388 const int state_offset = in_bytes(ShenandoahThreadLocalData::gc_state_offset());
rkennke@52925 389 return n->in(2)->is_AddP() && n->in(2)->in(2)->Opcode() == Op_ThreadLocal
rkennke@52925 390 && n->in(2)->in(3)->is_Con()
rkennke@52925 391 && n->in(2)->in(3)->bottom_type()->is_intptr_t()->get_con() == state_offset;
rkennke@52925 392 }
rkennke@52925 393
rkennke@52925 394 void ShenandoahBarrierSetC2::shenandoah_write_barrier_pre(GraphKit* kit,
rkennke@52925 395 bool do_load,
rkennke@52925 396 Node* obj,
rkennke@52925 397 Node* adr,
rkennke@52925 398 uint alias_idx,
rkennke@52925 399 Node* val,
rkennke@52925 400 const TypeOopPtr* val_type,
rkennke@52925 401 Node* pre_val,
rkennke@52925 402 BasicType bt) const {
rkennke@52925 403 if (ShenandoahSATBBarrier) {
rkennke@52925 404 IdealKit ideal(kit);
rkennke@52925 405 kit->sync_kit(ideal);
rkennke@52925 406
rkennke@52925 407 satb_write_barrier_pre(kit, do_load, obj, adr, alias_idx, val, val_type, pre_val, bt);
rkennke@52925 408
rkennke@52925 409 ideal.sync_kit(kit);
rkennke@52925 410 kit->final_sync(ideal);
rkennke@52925 411 }
rkennke@52925 412 }
rkennke@52925 413
rkennke@52925 414 Node* ShenandoahBarrierSetC2::shenandoah_enqueue_barrier(GraphKit* kit, Node* pre_val) const {
rkennke@52925 415 return kit->gvn().transform(new ShenandoahEnqueueBarrierNode(pre_val));
rkennke@52925 416 }
rkennke@52925 417
rkennke@52925 418 // Helper that guards and inserts a pre-barrier.
rkennke@52925 419 void ShenandoahBarrierSetC2::insert_pre_barrier(GraphKit* kit, Node* base_oop, Node* offset,
rkennke@52925 420 Node* pre_val, bool need_mem_bar) const {
rkennke@52925 421 // We could be accessing the referent field of a reference object. If so, when G1
rkennke@52925 422 // is enabled, we need to log the value in the referent field in an SATB buffer.
rkennke@52925 423 // This routine performs some compile time filters and generates suitable
rkennke@52925 424 // runtime filters that guard the pre-barrier code.
rkennke@52925 425 // Also add memory barrier for non volatile load from the referent field
rkennke@52925 426 // to prevent commoning of loads across safepoint.
rkennke@52925 427
rkennke@52925 428 // Some compile time checks.
rkennke@52925 429
rkennke@52925 430 // If offset is a constant, is it java_lang_ref_Reference::_reference_offset?
rkennke@52925 431 const TypeX* otype = offset->find_intptr_t_type();
rkennke@52925 432 if (otype != NULL && otype->is_con() &&
rkennke@52925 433 otype->get_con() != java_lang_ref_Reference::referent_offset) {
rkennke@52925 434 // Constant offset but not the reference_offset so just return
rkennke@52925 435 return;
rkennke@52925 436 }
rkennke@52925 437
rkennke@52925 438 // We only need to generate the runtime guards for instances.
rkennke@52925 439 const TypeOopPtr* btype = base_oop->bottom_type()->isa_oopptr();
rkennke@52925 440 if (btype != NULL) {
rkennke@52925 441 if (btype->isa_aryptr()) {
rkennke@52925 442 // Array type so nothing to do
rkennke@52925 443 return;
rkennke@52925 444 }
rkennke@52925 445
rkennke@52925 446 const TypeInstPtr* itype = btype->isa_instptr();
rkennke@52925 447 if (itype != NULL) {
rkennke@52925 448 // Can the klass of base_oop be statically determined to be
rkennke@52925 449 // _not_ a sub-class of Reference and _not_ Object?
rkennke@52925 450 ciKlass* klass = itype->klass();
rkennke@52925 451 if ( klass->is_loaded() &&
rkennke@52925 452 !klass->is_subtype_of(kit->env()->Reference_klass()) &&
rkennke@52925 453 !kit->env()->Object_klass()->is_subtype_of(klass)) {
rkennke@52925 454 return;
rkennke@52925 455 }
rkennke@52925 456 }
rkennke@52925 457 }
rkennke@52925 458
rkennke@52925 459 // The compile time filters did not reject base_oop/offset so
rkennke@52925 460 // we need to generate the following runtime filters
rkennke@52925 461 //
rkennke@52925 462 // if (offset == java_lang_ref_Reference::_reference_offset) {
rkennke@52925 463 // if (instance_of(base, java.lang.ref.Reference)) {
rkennke@52925 464 // pre_barrier(_, pre_val, ...);
rkennke@52925 465 // }
rkennke@52925 466 // }
rkennke@52925 467
rkennke@52925 468 float likely = PROB_LIKELY( 0.999);
rkennke@52925 469 float unlikely = PROB_UNLIKELY(0.999);
rkennke@52925 470
rkennke@52925 471 IdealKit ideal(kit);
rkennke@52925 472
rkennke@52925 473 Node* referent_off = __ ConX(java_lang_ref_Reference::referent_offset);
rkennke@52925 474
rkennke@52925 475 __ if_then(offset, BoolTest::eq, referent_off, unlikely); {
rkennke@52925 476 // Update graphKit memory and control from IdealKit.
rkennke@52925 477 kit->sync_kit(ideal);
rkennke@52925 478
rkennke@52925 479 Node* ref_klass_con = kit->makecon(TypeKlassPtr::make(kit->env()->Reference_klass()));
rkennke@52925 480 Node* is_instof = kit->gen_instanceof(base_oop, ref_klass_con);
rkennke@52925 481
rkennke@52925 482 // Update IdealKit memory and control from graphKit.
rkennke@52925 483 __ sync_kit(kit);
rkennke@52925 484
rkennke@52925 485 Node* one = __ ConI(1);
rkennke@52925 486 // is_instof == 0 if base_oop == NULL
rkennke@52925 487 __ if_then(is_instof, BoolTest::eq, one, unlikely); {
rkennke@52925 488
rkennke@52925 489 // Update graphKit from IdeakKit.
rkennke@52925 490 kit->sync_kit(ideal);
rkennke@52925 491
rkennke@52925 492 // Use the pre-barrier to record the value in the referent field
rkennke@52925 493 satb_write_barrier_pre(kit, false /* do_load */,
rkennke@52925 494 NULL /* obj */, NULL /* adr */, max_juint /* alias_idx */, NULL /* val */, NULL /* val_type */,
rkennke@52925 495 pre_val /* pre_val */,
rkennke@52925 496 T_OBJECT);
rkennke@52925 497 if (need_mem_bar) {
rkennke@52925 498 // Add memory barrier to prevent commoning reads from this field
rkennke@52925 499 // across safepoint since GC can change its value.
rkennke@52925 500 kit->insert_mem_bar(Op_MemBarCPUOrder);
rkennke@52925 501 }
rkennke@52925 502 // Update IdealKit from graphKit.
rkennke@52925 503 __ sync_kit(kit);
rkennke@52925 504
rkennke@52925 505 } __ end_if(); // _ref_type != ref_none
rkennke@52925 506 } __ end_if(); // offset == referent_offset
rkennke@52925 507
rkennke@52925 508 // Final sync IdealKit and GraphKit.
rkennke@52925 509 kit->final_sync(ideal);
rkennke@52925 510 }
rkennke@52925 511
rkennke@52925 512 #undef __
rkennke@52925 513
rkennke@52925 514 const TypeFunc* ShenandoahBarrierSetC2::write_ref_field_pre_entry_Type() {
rkennke@52925 515 const Type **fields = TypeTuple::fields(2);
rkennke@52925 516 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // original field value
rkennke@52925 517 fields[TypeFunc::Parms+1] = TypeRawPtr::NOTNULL; // thread
rkennke@52925 518 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
rkennke@52925 519
rkennke@52925 520 // create result type (range)
rkennke@52925 521 fields = TypeTuple::fields(0);
rkennke@52925 522 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
rkennke@52925 523
rkennke@52925 524 return TypeFunc::make(domain, range);
rkennke@52925 525 }
rkennke@52925 526
rkennke@52925 527 const TypeFunc* ShenandoahBarrierSetC2::shenandoah_clone_barrier_Type() {
rkennke@52925 528 const Type **fields = TypeTuple::fields(1);
rkennke@52925 529 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // original field value
rkennke@52925 530 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
rkennke@52925 531
rkennke@52925 532 // create result type (range)
rkennke@52925 533 fields = TypeTuple::fields(0);
rkennke@52925 534 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
rkennke@52925 535
rkennke@52925 536 return TypeFunc::make(domain, range);
rkennke@52925 537 }
rkennke@52925 538
rkennke@52925 539 const TypeFunc* ShenandoahBarrierSetC2::shenandoah_write_barrier_Type() {
rkennke@52925 540 const Type **fields = TypeTuple::fields(1);
rkennke@52925 541 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // original field value
rkennke@52925 542 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
rkennke@52925 543
rkennke@52925 544 // create result type (range)
rkennke@52925 545 fields = TypeTuple::fields(1);
rkennke@52925 546 fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL;
rkennke@52925 547 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
rkennke@52925 548
rkennke@52925 549 return TypeFunc::make(domain, range);
rkennke@52925 550 }
rkennke@52925 551
rkennke@52925 552 void ShenandoahBarrierSetC2::resolve_address(C2Access& access) const {
rkennke@52925 553 const TypePtr* adr_type = access.addr().type();
rkennke@52925 554
rkennke@52925 555 if ((access.decorators() & IN_NATIVE) == 0 && (adr_type->isa_instptr() || adr_type->isa_aryptr())) {
rkennke@52925 556 int off = adr_type->is_ptr()->offset();
rkennke@52925 557 int base_off = adr_type->isa_instptr() ? instanceOopDesc::base_offset_in_bytes() :
rkennke@52925 558 arrayOopDesc::base_offset_in_bytes(adr_type->is_aryptr()->elem()->array_element_basic_type());
rkennke@52925 559 assert(off != Type::OffsetTop, "unexpected offset");
rkennke@52925 560 if (off == Type::OffsetBot || off >= base_off) {
rkennke@52925 561 DecoratorSet decorators = access.decorators();
rkennke@52925 562 bool is_write = (decorators & C2_WRITE_ACCESS) != 0;
rkennke@52925 563 GraphKit* kit = NULL;
rkennke@52925 564 if (access.is_parse_access()) {
rkennke@52925 565 C2ParseAccess& parse_access = static_cast<C2ParseAccess&>(access);
rkennke@52925 566 kit = parse_access.kit();
rkennke@52925 567 }
rkennke@52925 568 Node* adr = access.addr().node();
rkennke@52925 569 assert(adr->is_AddP(), "unexpected address shape");
rkennke@52925 570 Node* base = adr->in(AddPNode::Base);
rkennke@52925 571
rkennke@52925 572 if (is_write) {
rkennke@52925 573 if (kit != NULL) {
rkennke@52925 574 base = shenandoah_write_barrier(kit, base);
rkennke@52925 575 } else {
rkennke@52925 576 assert(access.is_opt_access(), "either parse or opt access");
rkennke@52925 577 assert((access.decorators() & C2_ARRAY_COPY) != 0, "can be skipped for clone");
rkennke@52925 578 }
rkennke@52925 579 } else {
rkennke@52925 580 if (adr_type->isa_instptr()) {
rkennke@52925 581 Compile* C = access.gvn().C;
rkennke@52925 582 ciField* field = C->alias_type(adr_type)->field();
rkennke@52925 583
rkennke@52925 584 // Insert read barrier for Shenandoah.
rkennke@52925 585 if (field != NULL &&
rkennke@52925 586 ((ShenandoahOptimizeStaticFinals && field->is_static() && field->is_final()) ||
rkennke@52925 587 (ShenandoahOptimizeInstanceFinals && !field->is_static() && field->is_final()) ||
rkennke@52925 588 (ShenandoahOptimizeStableFinals && field->is_stable()))) {
rkennke@52925 589 // Skip the barrier for special fields
rkennke@52925 590 } else {
rkennke@52925 591 if (kit != NULL) {
rkennke@52925 592 base = shenandoah_read_barrier(kit, base);
rkennke@52925 593 } else {
rkennke@52925 594 assert(access.is_opt_access(), "either parse or opt access");
rkennke@52925 595 assert((access.decorators() & C2_ARRAY_COPY) != 0, "can be skipped for arraycopy");
rkennke@52925 596 }
rkennke@52925 597 }
rkennke@52925 598 } else {
rkennke@52925 599 if (kit != NULL) {
rkennke@52925 600 base = shenandoah_read_barrier(kit, base);
rkennke@52925 601 } else {
rkennke@52925 602 assert(access.is_opt_access(), "either parse or opt access");
rkennke@52925 603 assert((access.decorators() & C2_ARRAY_COPY) != 0, "can be skipped for arraycopy");
rkennke@52925 604 }
rkennke@52925 605 }
rkennke@52925 606 }
rkennke@52925 607 if (base != adr->in(AddPNode::Base)) {
rkennke@52925 608 assert(kit != NULL, "no barrier should have been added");
rkennke@52925 609
rkennke@52925 610 Node* address = adr->in(AddPNode::Address);
rkennke@52925 611
rkennke@52925 612 if (address->is_AddP()) {
rkennke@52925 613 assert(address->in(AddPNode::Base) == adr->in(AddPNode::Base), "unexpected address shape");
rkennke@52925 614 assert(!address->in(AddPNode::Address)->is_AddP(), "unexpected address shape");
rkennke@52925 615 assert(address->in(AddPNode::Address) == adr->in(AddPNode::Base), "unexpected address shape");
rkennke@52925 616 address = address->clone();
rkennke@52925 617 address->set_req(AddPNode::Base, base);
rkennke@52925 618 address->set_req(AddPNode::Address, base);
rkennke@52925 619 address = kit->gvn().transform(address);
rkennke@52925 620 } else {
rkennke@52925 621 assert(address == adr->in(AddPNode::Base), "unexpected address shape");
rkennke@52925 622 address = base;
rkennke@52925 623 }
rkennke@52925 624 adr = adr->clone();
rkennke@52925 625 adr->set_req(AddPNode::Base, base);
rkennke@52925 626 adr->set_req(AddPNode::Address, address);
rkennke@52925 627 adr = kit->gvn().transform(adr);
rkennke@52925 628 access.addr().set_node(adr);
rkennke@52925 629 }
rkennke@52925 630 }
rkennke@52925 631 }
rkennke@52925 632 }
rkennke@52925 633
rkennke@52925 634 Node* ShenandoahBarrierSetC2::store_at_resolved(C2Access& access, C2AccessValue& val) const {
rkennke@52925 635 DecoratorSet decorators = access.decorators();
rkennke@52925 636
rkennke@52925 637 const TypePtr* adr_type = access.addr().type();
rkennke@52925 638 Node* adr = access.addr().node();
rkennke@52925 639
rkennke@52925 640 bool anonymous = (decorators & ON_UNKNOWN_OOP_REF) != 0;
rkennke@52925 641 bool on_heap = (decorators & IN_HEAP) != 0;
rkennke@52925 642
rkennke@52925 643 if (!access.is_oop() || (!on_heap && !anonymous)) {
rkennke@52925 644 return BarrierSetC2::store_at_resolved(access, val);
rkennke@52925 645 }
rkennke@52925 646
rkennke@52925 647 if (access.is_parse_access()) {
rkennke@52925 648 C2ParseAccess& parse_access = static_cast<C2ParseAccess&>(access);
rkennke@52925 649 GraphKit* kit = parse_access.kit();
rkennke@52925 650
rkennke@52925 651 uint adr_idx = kit->C->get_alias_index(adr_type);
rkennke@52925 652 assert(adr_idx != Compile::AliasIdxTop, "use other store_to_memory factory" );
rkennke@52925 653 Node* value = val.node();
rkennke@52925 654 value = shenandoah_storeval_barrier(kit, value);
rkennke@52925 655 val.set_node(value);
rkennke@52925 656 shenandoah_write_barrier_pre(kit, true /* do_load */, /*kit->control(),*/ access.base(), adr, adr_idx, val.node(),
rkennke@52925 657 static_cast<const TypeOopPtr*>(val.type()), NULL /* pre_val */, access.type());
rkennke@52925 658 } else {
rkennke@52925 659 assert(access.is_opt_access(), "only for optimization passes");
kbarrett@54048 660 assert(((decorators & C2_TIGHTLY_COUPLED_ALLOC) != 0 || !ShenandoahSATBBarrier) && (decorators & C2_ARRAY_COPY) != 0, "unexpected caller of this code");
rkennke@52925 661 C2OptAccess& opt_access = static_cast<C2OptAccess&>(access);
rkennke@52925 662 PhaseGVN& gvn = opt_access.gvn();
rkennke@52925 663 MergeMemNode* mm = opt_access.mem();
rkennke@52925 664
rkennke@52925 665 if (ShenandoahStoreValReadBarrier) {
rkennke@52925 666 RegionNode* region = new RegionNode(3);
rkennke@52925 667 const Type* v_t = gvn.type(val.node());
rkennke@52925 668 Node* phi = new PhiNode(region, v_t->isa_oopptr() ? v_t->is_oopptr()->cast_to_nonconst() : v_t);
rkennke@52925 669 Node* cmp = gvn.transform(new CmpPNode(val.node(), gvn.zerocon(T_OBJECT)));
rkennke@52925 670 Node* bol = gvn.transform(new BoolNode(cmp, BoolTest::ne));
rkennke@52925 671 IfNode* iff = new IfNode(opt_access.ctl(), bol, PROB_LIKELY_MAG(3), COUNT_UNKNOWN);
rkennke@52925 672
rkennke@52925 673 gvn.transform(iff);
rkennke@52925 674 if (gvn.is_IterGVN()) {
rkennke@52925 675 gvn.is_IterGVN()->_worklist.push(iff);
rkennke@52925 676 } else {
rkennke@52925 677 gvn.record_for_igvn(iff);
rkennke@52925 678 }
rkennke@52925 679
rkennke@52925 680 Node* null_true = gvn.transform(new IfFalseNode(iff));
rkennke@52925 681 Node* null_false = gvn.transform(new IfTrueNode(iff));
rkennke@52925 682 region->init_req(1, null_true);
rkennke@52925 683 region->init_req(2, null_false);
rkennke@52925 684 phi->init_req(1, gvn.zerocon(T_OBJECT));
rkennke@52925 685 Node* cast = new CastPPNode(val.node(), gvn.type(val.node())->join_speculative(TypePtr::NOTNULL));
rkennke@52925 686 cast->set_req(0, null_false);
rkennke@52925 687 cast = gvn.transform(cast);
rkennke@52925 688 Node* rb = gvn.transform(new ShenandoahReadBarrierNode(null_false, gvn.C->immutable_memory(), cast, false));
rkennke@52925 689 phi->init_req(2, rb);
rkennke@52925 690 opt_access.set_ctl(gvn.transform(region));
rkennke@52925 691 val.set_node(gvn.transform(phi));
rkennke@52925 692 }
rkennke@52925 693 if (ShenandoahStoreValEnqueueBarrier) {
rkennke@52925 694 const TypePtr* adr_type = ShenandoahBarrierNode::brooks_pointer_type(gvn.type(val.node()));
rkennke@52925 695 int alias = gvn.C->get_alias_index(adr_type);
rkennke@52925 696 Node* wb = new ShenandoahWriteBarrierNode(gvn.C, opt_access.ctl(), mm->memory_at(alias), val.node());
rkennke@52925 697 Node* wb_transformed = gvn.transform(wb);
rkennke@52925 698 Node* enqueue = gvn.transform(new ShenandoahEnqueueBarrierNode(wb_transformed));
rkennke@52925 699 if (wb_transformed == wb) {
rkennke@52925 700 Node* proj = gvn.transform(new ShenandoahWBMemProjNode(wb));
rkennke@52925 701 mm->set_memory_at(alias, proj);
rkennke@52925 702 }
rkennke@52925 703 val.set_node(enqueue);
rkennke@52925 704 }
rkennke@52925 705 }
rkennke@52925 706 return BarrierSetC2::store_at_resolved(access, val);
rkennke@52925 707 }
rkennke@52925 708
rkennke@52925 709 Node* ShenandoahBarrierSetC2::load_at_resolved(C2Access& access, const Type* val_type) const {
rkennke@52925 710 DecoratorSet decorators = access.decorators();
rkennke@52925 711
rkennke@52925 712 Node* adr = access.addr().node();
rkennke@52925 713 Node* obj = access.base();
rkennke@52925 714
rkennke@52925 715 bool mismatched = (decorators & C2_MISMATCHED) != 0;
rkennke@52925 716 bool unknown = (decorators & ON_UNKNOWN_OOP_REF) != 0;
rkennke@52925 717 bool on_heap = (decorators & IN_HEAP) != 0;
rkennke@52925 718 bool on_weak = (decorators & ON_WEAK_OOP_REF) != 0;
rkennke@52925 719 bool is_unordered = (decorators & MO_UNORDERED) != 0;
rkennke@52925 720 bool need_cpu_mem_bar = !is_unordered || mismatched || !on_heap;
rkennke@52925 721
rkennke@52925 722 Node* top = Compile::current()->top();
rkennke@52925 723
rkennke@52925 724 Node* offset = adr->is_AddP() ? adr->in(AddPNode::Offset) : top;
rkennke@52925 725 Node* load = BarrierSetC2::load_at_resolved(access, val_type);
rkennke@52925 726
rkennke@52925 727 // If we are reading the value of the referent field of a Reference
rkennke@52925 728 // object (either by using Unsafe directly or through reflection)
rkennke@52925 729 // then, if SATB is enabled, we need to record the referent in an
rkennke@52925 730 // SATB log buffer using the pre-barrier mechanism.
rkennke@52925 731 // Also we need to add memory barrier to prevent commoning reads
rkennke@52925 732 // from this field across safepoint since GC can change its value.
rkennke@52925 733 bool need_read_barrier = ShenandoahKeepAliveBarrier &&
rkennke@52925 734 (on_heap && (on_weak || (unknown && offset != top && obj != top)));
rkennke@52925 735
rkennke@52925 736 if (!access.is_oop() || !need_read_barrier) {
rkennke@52925 737 return load;
rkennke@52925 738 }
rkennke@52925 739
rkennke@52925 740 assert(access.is_parse_access(), "entry not supported at optimization time");
rkennke@52925 741 C2ParseAccess& parse_access = static_cast<C2ParseAccess&>(access);
rkennke@52925 742 GraphKit* kit = parse_access.kit();
rkennke@52925 743
rkennke@52925 744 if (on_weak) {
rkennke@52925 745 // Use the pre-barrier to record the value in the referent field
rkennke@52925 746 satb_write_barrier_pre(kit, false /* do_load */,
rkennke@52925 747 NULL /* obj */, NULL /* adr */, max_juint /* alias_idx */, NULL /* val */, NULL /* val_type */,
rkennke@52925 748 load /* pre_val */, T_OBJECT);
rkennke@52925 749 // Add memory barrier to prevent commoning reads from this field
rkennke@52925 750 // across safepoint since GC can change its value.
rkennke@52925 751 kit->insert_mem_bar(Op_MemBarCPUOrder);
rkennke@52925 752 } else if (unknown) {
rkennke@52925 753 // We do not require a mem bar inside pre_barrier if need_mem_bar
rkennke@52925 754 // is set: the barriers would be emitted by us.
rkennke@52925 755 insert_pre_barrier(kit, obj, offset, load, !need_cpu_mem_bar);
rkennke@52925 756 }
rkennke@52925 757
rkennke@52925 758 return load;
rkennke@52925 759 }
rkennke@52925 760
rkennke@52925 761 Node* ShenandoahBarrierSetC2::atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
rkennke@52925 762 Node* new_val, const Type* value_type) const {
rkennke@52925 763 GraphKit* kit = access.kit();
rkennke@52925 764 if (access.is_oop()) {
rkennke@52925 765 new_val = shenandoah_storeval_barrier(kit, new_val);
rkennke@52925 766 shenandoah_write_barrier_pre(kit, false /* do_load */,
rkennke@52925 767 NULL, NULL, max_juint, NULL, NULL,
rkennke@52925 768 expected_val /* pre_val */, T_OBJECT);
rkennke@52925 769
rkennke@52925 770 MemNode::MemOrd mo = access.mem_node_mo();
rkennke@52925 771 Node* mem = access.memory();
rkennke@52925 772 Node* adr = access.addr().node();
rkennke@52925 773 const TypePtr* adr_type = access.addr().type();
rkennke@52925 774 Node* load_store = NULL;
rkennke@52925 775
rkennke@52925 776 #ifdef _LP64
rkennke@52925 777 if (adr->bottom_type()->is_ptr_to_narrowoop()) {
rkennke@52925 778 Node *newval_enc = kit->gvn().transform(new EncodePNode(new_val, new_val->bottom_type()->make_narrowoop()));
rkennke@52925 779 Node *oldval_enc = kit->gvn().transform(new EncodePNode(expected_val, expected_val->bottom_type()->make_narrowoop()));
rkennke@53519 780 if (ShenandoahCASBarrier) {
rkennke@53519 781 load_store = kit->gvn().transform(new ShenandoahCompareAndExchangeNNode(kit->control(), mem, adr, newval_enc, oldval_enc, adr_type, value_type->make_narrowoop(), mo));
rkennke@53519 782 } else {
rkennke@53519 783 load_store = kit->gvn().transform(new CompareAndExchangeNNode(kit->control(), mem, adr, newval_enc, oldval_enc, adr_type, value_type->make_narrowoop(), mo));
rkennke@53519 784 }
rkennke@52925 785 } else
rkennke@52925 786 #endif
rkennke@52925 787 {
rkennke@53519 788 if (ShenandoahCASBarrier) {
rkennke@53519 789 load_store = kit->gvn().transform(new ShenandoahCompareAndExchangePNode(kit->control(), mem, adr, new_val, expected_val, adr_type, value_type->is_oopptr(), mo));
rkennke@53519 790 } else {
rkennke@53519 791 load_store = kit->gvn().transform(new CompareAndExchangePNode(kit->control(), mem, adr, new_val, expected_val, adr_type, value_type->is_oopptr(), mo));
rkennke@53519 792 }
rkennke@52925 793 }
rkennke@52925 794
rkennke@52925 795 access.set_raw_access(load_store);
rkennke@52925 796 pin_atomic_op(access);
rkennke@52925 797
rkennke@52925 798 #ifdef _LP64
rkennke@52925 799 if (adr->bottom_type()->is_ptr_to_narrowoop()) {
rkennke@52925 800 return kit->gvn().transform(new DecodeNNode(load_store, load_store->get_ptr_type()));
rkennke@52925 801 }
rkennke@52925 802 #endif
rkennke@52925 803 return load_store;
rkennke@52925 804 }
rkennke@52925 805 return BarrierSetC2::atomic_cmpxchg_val_at_resolved(access, expected_val, new_val, value_type);
rkennke@52925 806 }
rkennke@52925 807
rkennke@52925 808 Node* ShenandoahBarrierSetC2::atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
rkennke@52925 809 Node* new_val, const Type* value_type) const {
rkennke@52925 810 GraphKit* kit = access.kit();
rkennke@52925 811 if (access.is_oop()) {
rkennke@52925 812 new_val = shenandoah_storeval_barrier(kit, new_val);
rkennke@52925 813 shenandoah_write_barrier_pre(kit, false /* do_load */,
rkennke@52925 814 NULL, NULL, max_juint, NULL, NULL,
rkennke@52925 815 expected_val /* pre_val */, T_OBJECT);
rkennke@52925 816 DecoratorSet decorators = access.decorators();
rkennke@52925 817 MemNode::MemOrd mo = access.mem_node_mo();
rkennke@52925 818 Node* mem = access.memory();
rkennke@52925 819 bool is_weak_cas = (decorators & C2_WEAK_CMPXCHG) != 0;
rkennke@52925 820 Node* load_store = NULL;
rkennke@52925 821 Node* adr = access.addr().node();
rkennke@52925 822 #ifdef _LP64
rkennke@52925 823 if (adr->bottom_type()->is_ptr_to_narrowoop()) {
rkennke@52925 824 Node *newval_enc = kit->gvn().transform(new EncodePNode(new_val, new_val->bottom_type()->make_narrowoop()));
rkennke@52925 825 Node *oldval_enc = kit->gvn().transform(new EncodePNode(expected_val, expected_val->bottom_type()->make_narrowoop()));
rkennke@53519 826 if (ShenandoahCASBarrier) {
rkennke@53519 827 if (is_weak_cas) {
rkennke@53519 828 load_store = kit->gvn().transform(new ShenandoahWeakCompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo));
rkennke@53519 829 } else {
rkennke@53519 830 load_store = kit->gvn().transform(new ShenandoahCompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo));
rkennke@53519 831 }
rkennke@52925 832 } else {
rkennke@53519 833 if (is_weak_cas) {
rkennke@53519 834 load_store = kit->gvn().transform(new WeakCompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo));
rkennke@53519 835 } else {
rkennke@53519 836 load_store = kit->gvn().transform(new CompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo));
rkennke@53519 837 }
rkennke@52925 838 }
rkennke@52925 839 } else
rkennke@52925 840 #endif
rkennke@52925 841 {
rkennke@53519 842 if (ShenandoahCASBarrier) {
rkennke@53519 843 if (is_weak_cas) {
rkennke@53519 844 load_store = kit->gvn().transform(new ShenandoahWeakCompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo));
rkennke@53519 845 } else {
rkennke@53519 846 load_store = kit->gvn().transform(new ShenandoahCompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo));
rkennke@53519 847 }
rkennke@52925 848 } else {
rkennke@53519 849 if (is_weak_cas) {
rkennke@53519 850 load_store = kit->gvn().transform(new WeakCompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo));
rkennke@53519 851 } else {
rkennke@53519 852 load_store = kit->gvn().transform(new CompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo));
rkennke@53519 853 }
rkennke@52925 854 }
rkennke@52925 855 }
rkennke@52925 856 access.set_raw_access(load_store);
rkennke@52925 857 pin_atomic_op(access);
rkennke@52925 858 return load_store;
rkennke@52925 859 }
rkennke@52925 860 return BarrierSetC2::atomic_cmpxchg_bool_at_resolved(access, expected_val, new_val, value_type);
rkennke@52925 861 }
rkennke@52925 862
rkennke@52925 863 Node* ShenandoahBarrierSetC2::atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* val, const Type* value_type) const {
rkennke@52925 864 GraphKit* kit = access.kit();
rkennke@52925 865 if (access.is_oop()) {
rkennke@52925 866 val = shenandoah_storeval_barrier(kit, val);
rkennke@52925 867 }
rkennke@52925 868 Node* result = BarrierSetC2::atomic_xchg_at_resolved(access, val, value_type);
rkennke@52925 869 if (access.is_oop()) {
rkennke@52925 870 shenandoah_write_barrier_pre(kit, false /* do_load */,
rkennke@52925 871 NULL, NULL, max_juint, NULL, NULL,
rkennke@52925 872 result /* pre_val */, T_OBJECT);
rkennke@52925 873 }
rkennke@52925 874 return result;
rkennke@52925 875 }
rkennke@52925 876
rkennke@52925 877 void ShenandoahBarrierSetC2::clone(GraphKit* kit, Node* src, Node* dst, Node* size, bool is_array) const {
rkennke@52925 878 assert(!src->is_AddP(), "unexpected input");
rkennke@52925 879 src = shenandoah_read_barrier(kit, src);
rkennke@52925 880 BarrierSetC2::clone(kit, src, dst, size, is_array);
rkennke@52925 881 }
rkennke@52925 882
rkennke@52925 883 Node* ShenandoahBarrierSetC2::resolve(GraphKit* kit, Node* n, DecoratorSet decorators) const {
rkennke@52925 884 bool is_write = decorators & ACCESS_WRITE;
rkennke@52925 885 if (is_write) {
rkennke@52925 886 return shenandoah_write_barrier(kit, n);
rkennke@52925 887 } else {
rkennke@52925 888 return shenandoah_read_barrier(kit, n);
rkennke@52925 889 }
rkennke@52925 890 }
rkennke@52925 891
rkennke@52925 892 Node* ShenandoahBarrierSetC2::obj_allocate(PhaseMacroExpand* macro, Node* ctrl, Node* mem, Node* toobig_false, Node* size_in_bytes,
rkennke@52925 893 Node*& i_o, Node*& needgc_ctrl,
rkennke@52925 894 Node*& fast_oop_ctrl, Node*& fast_oop_rawmem,
rkennke@52925 895 intx prefetch_lines) const {
rkennke@52925 896 PhaseIterGVN& igvn = macro->igvn();
rkennke@52925 897
rkennke@52925 898 // Allocate several words more for the Shenandoah brooks pointer.
rkennke@52925 899 size_in_bytes = new AddXNode(size_in_bytes, igvn.MakeConX(ShenandoahBrooksPointer::byte_size()));
rkennke@52925 900 macro->transform_later(size_in_bytes);
rkennke@52925 901
rkennke@52925 902 Node* fast_oop = BarrierSetC2::obj_allocate(macro, ctrl, mem, toobig_false, size_in_bytes,
rkennke@52925 903 i_o, needgc_ctrl, fast_oop_ctrl, fast_oop_rawmem,
rkennke@52925 904 prefetch_lines);
rkennke@52925 905
rkennke@52925 906 // Bump up object for Shenandoah brooks pointer.
rkennke@52925 907 fast_oop = new AddPNode(macro->top(), fast_oop, igvn.MakeConX(ShenandoahBrooksPointer::byte_size()));
rkennke@52925 908 macro->transform_later(fast_oop);
rkennke@52925 909
rkennke@52925 910 // Initialize Shenandoah brooks pointer to point to the object itself.
rkennke@52925 911 fast_oop_rawmem = macro->make_store(fast_oop_ctrl, fast_oop_rawmem, fast_oop, ShenandoahBrooksPointer::byte_offset(), fast_oop, T_OBJECT);
rkennke@52925 912
rkennke@52925 913 return fast_oop;
rkennke@52925 914 }
rkennke@52925 915
rkennke@52925 916 // Support for GC barriers emitted during parsing
rkennke@52925 917 bool ShenandoahBarrierSetC2::is_gc_barrier_node(Node* node) const {
rkennke@52925 918 if (node->Opcode() != Op_CallLeaf && node->Opcode() != Op_CallLeafNoFP) {
rkennke@52925 919 return false;
rkennke@52925 920 }
rkennke@52925 921 CallLeafNode *call = node->as_CallLeaf();
rkennke@52925 922 if (call->_name == NULL) {
rkennke@52925 923 return false;
rkennke@52925 924 }
rkennke@52925 925
rkennke@52925 926 return strcmp(call->_name, "shenandoah_clone_barrier") == 0 ||
rkennke@52925 927 strcmp(call->_name, "shenandoah_cas_obj") == 0 ||
rkennke@52925 928 strcmp(call->_name, "shenandoah_wb_pre") == 0;
rkennke@52925 929 }
rkennke@52925 930
rkennke@52925 931 Node* ShenandoahBarrierSetC2::step_over_gc_barrier(Node* c) const {
rkennke@52925 932 return ShenandoahBarrierNode::skip_through_barrier(c);
rkennke@52925 933 }
rkennke@52925 934
rkennke@52925 935 bool ShenandoahBarrierSetC2::expand_barriers(Compile* C, PhaseIterGVN& igvn) const {
rkennke@52925 936 return !ShenandoahWriteBarrierNode::expand(C, igvn);
rkennke@52925 937 }
rkennke@52925 938
rkennke@52925 939 bool ShenandoahBarrierSetC2::optimize_loops(PhaseIdealLoop* phase, LoopOptsMode mode, VectorSet& visited, Node_Stack& nstack, Node_List& worklist) const {
rkennke@52925 940 if (mode == LoopOptsShenandoahExpand) {
rkennke@52925 941 assert(UseShenandoahGC, "only for shenandoah");
rkennke@52925 942 ShenandoahWriteBarrierNode::pin_and_expand(phase);
rkennke@52925 943 return true;
rkennke@52925 944 } else if (mode == LoopOptsShenandoahPostExpand) {
rkennke@52925 945 assert(UseShenandoahGC, "only for shenandoah");
rkennke@52925 946 visited.Clear();
rkennke@52925 947 ShenandoahWriteBarrierNode::optimize_after_expansion(visited, nstack, worklist, phase);
rkennke@52925 948 return true;
rkennke@52925 949 }
rkennke@52925 950 GrowableArray<MemoryGraphFixer*> memory_graph_fixers;
rkennke@52925 951 ShenandoahWriteBarrierNode::optimize_before_expansion(phase, memory_graph_fixers, false);
rkennke@52925 952 return false;
rkennke@52925 953 }
rkennke@52925 954
rkennke@52925 955 bool ShenandoahBarrierSetC2::array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, ArrayCopyPhase phase) const {
rkennke@52925 956 bool is_oop = type == T_OBJECT || type == T_ARRAY;
rkennke@52925 957 if (!is_oop) {
rkennke@52925 958 return false;
rkennke@52925 959 }
rkennke@52925 960
rkennke@52925 961 if (tightly_coupled_alloc) {
rkennke@52925 962 if (phase == Optimization) {
rkennke@52925 963 return false;
rkennke@52925 964 }
rkennke@52925 965 return !is_clone;
rkennke@52925 966 }
rkennke@52925 967 if (phase == Optimization) {
rkennke@52925 968 return !ShenandoahStoreValEnqueueBarrier;
rkennke@52925 969 }
rkennke@52925 970 return true;
rkennke@52925 971 }
rkennke@52925 972
rkennke@52925 973 bool ShenandoahBarrierSetC2::clone_needs_postbarrier(ArrayCopyNode *ac, PhaseIterGVN& igvn) {
rkennke@52925 974 Node* src = ac->in(ArrayCopyNode::Src);
rkennke@52925 975 const TypeOopPtr* src_type = igvn.type(src)->is_oopptr();
rkennke@52925 976 if (src_type->isa_instptr() != NULL) {
rkennke@52925 977 ciInstanceKlass* ik = src_type->klass()->as_instance_klass();
rkennke@52925 978 if ((src_type->klass_is_exact() || (!ik->is_interface() && !ik->has_subklass())) && !ik->has_injected_fields()) {
rkennke@52925 979 if (ik->has_object_fields()) {
rkennke@52925 980 return true;
rkennke@52925 981 } else {
rkennke@52925 982 if (!src_type->klass_is_exact()) {
rkennke@52925 983 igvn.C->dependencies()->assert_leaf_type(ik);
rkennke@52925 984 }
rkennke@52925 985 }
rkennke@52925 986 } else {
rkennke@52925 987 return true;
rkennke@52925 988 }
rkennke@52925 989 } else if (src_type->isa_aryptr()) {
rkennke@52925 990 BasicType src_elem = src_type->klass()->as_array_klass()->element_type()->basic_type();
rkennke@52925 991 if (src_elem == T_OBJECT || src_elem == T_ARRAY) {
rkennke@52925 992 return true;
rkennke@52925 993 }
rkennke@52925 994 } else {
rkennke@52925 995 return true;
rkennke@52925 996 }
rkennke@52925 997 return false;
rkennke@52925 998 }
rkennke@52925 999
rkennke@52925 1000 void ShenandoahBarrierSetC2::clone_barrier_at_expansion(ArrayCopyNode* ac, Node* call, PhaseIterGVN& igvn) const {
rkennke@52925 1001 assert(ac->is_clonebasic(), "no other kind of arraycopy here");
rkennke@52925 1002
rkennke@52925 1003 if (!clone_needs_postbarrier(ac, igvn)) {
rkennke@52925 1004 BarrierSetC2::clone_barrier_at_expansion(ac, call, igvn);
rkennke@52925 1005 return;
rkennke@52925 1006 }
rkennke@52925 1007
rkennke@52925 1008 const TypePtr* raw_adr_type = TypeRawPtr::BOTTOM;
rkennke@52925 1009 Node* c = new ProjNode(call,TypeFunc::Control);
rkennke@52925 1010 c = igvn.transform(c);
rkennke@52925 1011 Node* m = new ProjNode(call, TypeFunc::Memory);
roland@53235 1012 m = igvn.transform(m);
rkennke@52925 1013
rkennke@52925 1014 Node* dest = ac->in(ArrayCopyNode::Dest);
rkennke@52925 1015 assert(dest->is_AddP(), "bad input");
rkennke@52925 1016 Node* barrier_call = new CallLeafNode(ShenandoahBarrierSetC2::shenandoah_clone_barrier_Type(),
rkennke@52925 1017 CAST_FROM_FN_PTR(address, ShenandoahRuntime::shenandoah_clone_barrier),
rkennke@52925 1018 "shenandoah_clone_barrier", raw_adr_type);
rkennke@52925 1019 barrier_call->init_req(TypeFunc::Control, c);
rkennke@52925 1020 barrier_call->init_req(TypeFunc::I_O , igvn.C->top());
rkennke@52925 1021 barrier_call->init_req(TypeFunc::Memory , m);
rkennke@52925 1022 barrier_call->init_req(TypeFunc::ReturnAdr, igvn.C->top());
rkennke@52925 1023 barrier_call->init_req(TypeFunc::FramePtr, igvn.C->top());
rkennke@52925 1024 barrier_call->init_req(TypeFunc::Parms+0, dest->in(AddPNode::Base));
rkennke@52925 1025
rkennke@52925 1026 barrier_call = igvn.transform(barrier_call);
rkennke@52925 1027 c = new ProjNode(barrier_call,TypeFunc::Control);
rkennke@52925 1028 c = igvn.transform(c);
rkennke@52925 1029 m = new ProjNode(barrier_call, TypeFunc::Memory);
rkennke@52925 1030 m = igvn.transform(m);
rkennke@52925 1031
rkennke@52925 1032 Node* out_c = ac->proj_out(TypeFunc::Control);
rkennke@52925 1033 Node* out_m = ac->proj_out(TypeFunc::Memory);
rkennke@52925 1034 igvn.replace_node(out_c, c);
rkennke@52925 1035 igvn.replace_node(out_m, m);
rkennke@52925 1036 }
rkennke@52925 1037
rkennke@52925 1038
rkennke@52925 1039 // Support for macro expanded GC barriers
rkennke@52925 1040 void ShenandoahBarrierSetC2::register_potential_barrier_node(Node* node) const {
rkennke@52925 1041 if (node->Opcode() == Op_ShenandoahWriteBarrier) {
rkennke@52925 1042 state()->add_shenandoah_barrier((ShenandoahWriteBarrierNode*) node);
rkennke@52925 1043 }
rkennke@52925 1044 }
rkennke@52925 1045
rkennke@52925 1046 void ShenandoahBarrierSetC2::unregister_potential_barrier_node(Node* node) const {
rkennke@52925 1047 if (node->Opcode() == Op_ShenandoahWriteBarrier) {
rkennke@52925 1048 state()->remove_shenandoah_barrier((ShenandoahWriteBarrierNode*) node);
rkennke@52925 1049 }
rkennke@52925 1050 }
rkennke@52925 1051
rkennke@52925 1052 void ShenandoahBarrierSetC2::eliminate_gc_barrier(PhaseMacroExpand* macro, Node* n) const {
rkennke@52925 1053 if (is_shenandoah_wb_pre_call(n)) {
rkennke@52925 1054 shenandoah_eliminate_wb_pre(n, &macro->igvn());
rkennke@52925 1055 }
rkennke@52925 1056 }
rkennke@52925 1057
rkennke@52925 1058 void ShenandoahBarrierSetC2::shenandoah_eliminate_wb_pre(Node* call, PhaseIterGVN* igvn) const {
rkennke@52925 1059 assert(UseShenandoahGC && is_shenandoah_wb_pre_call(call), "");
rkennke@52925 1060 Node* c = call->as_Call()->proj_out(TypeFunc::Control);
rkennke@52925 1061 c = c->unique_ctrl_out();
rkennke@52925 1062 assert(c->is_Region() && c->req() == 3, "where's the pre barrier control flow?");
rkennke@52925 1063 c = c->unique_ctrl_out();
rkennke@52925 1064 assert(c->is_Region() && c->req() == 3, "where's the pre barrier control flow?");
rkennke@52925 1065 Node* iff = c->in(1)->is_IfProj() ? c->in(1)->in(0) : c->in(2)->in(0);
rkennke@52925 1066 assert(iff->is_If(), "expect test");
rkennke@52925 1067 if (!is_shenandoah_marking_if(igvn, iff)) {
rkennke@52925 1068 c = c->unique_ctrl_out();
rkennke@52925 1069 assert(c->is_Region() && c->req() == 3, "where's the pre barrier control flow?");
rkennke@52925 1070 iff = c->in(1)->is_IfProj() ? c->in(1)->in(0) : c->in(2)->in(0);
rkennke@52925 1071 assert(is_shenandoah_marking_if(igvn, iff), "expect marking test");
rkennke@52925 1072 }
rkennke@52925 1073 Node* cmpx = iff->in(1)->in(1);
rkennke@52925 1074 igvn->replace_node(cmpx, igvn->makecon(TypeInt::CC_EQ));
rkennke@52925 1075 igvn->rehash_node_delayed(call);
rkennke@52925 1076 call->del_req(call->req()-1);
rkennke@52925 1077 }
rkennke@52925 1078
rkennke@52925 1079 void ShenandoahBarrierSetC2::enqueue_useful_gc_barrier(PhaseIterGVN* igvn, Node* node) const {
rkennke@52925 1080 if (node->Opcode() == Op_AddP && ShenandoahBarrierSetC2::has_only_shenandoah_wb_pre_uses(node)) {
rkennke@52925 1081 igvn->add_users_to_worklist(node);
rkennke@52925 1082 }
rkennke@52925 1083 }
rkennke@52925 1084
rkennke@52925 1085 void ShenandoahBarrierSetC2::eliminate_useless_gc_barriers(Unique_Node_List &useful, Compile* C) const {
rkennke@52925 1086 for (uint i = 0; i < useful.size(); i++) {
rkennke@52925 1087 Node* n = useful.at(i);
rkennke@52925 1088 if (n->Opcode() == Op_AddP && ShenandoahBarrierSetC2::has_only_shenandoah_wb_pre_uses(n)) {
rkennke@52925 1089 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
rkennke@52925 1090 C->record_for_igvn(n->fast_out(i));
rkennke@52925 1091 }
rkennke@52925 1092 }
rkennke@52925 1093 }
rkennke@52925 1094 for (int i = state()->shenandoah_barriers_count()-1; i >= 0; i--) {
rkennke@52925 1095 ShenandoahWriteBarrierNode* n = state()->shenandoah_barrier(i);
rkennke@52925 1096 if (!useful.member(n)) {
rkennke@52925 1097 state()->remove_shenandoah_barrier(n);
rkennke@52925 1098 }
rkennke@52925 1099 }
rkennke@52925 1100
rkennke@52925 1101 }
rkennke@52925 1102
rkennke@52925 1103 bool ShenandoahBarrierSetC2::has_special_unique_user(const Node* node) const {
rkennke@52925 1104 assert(node->outcnt() == 1, "match only for unique out");
rkennke@52925 1105 Node* n = node->unique_out();
rkennke@52925 1106 return node->Opcode() == Op_ShenandoahWriteBarrier && n->Opcode() == Op_ShenandoahWBMemProj;
rkennke@52925 1107 }
rkennke@52925 1108
rkennke@52925 1109 void ShenandoahBarrierSetC2::add_users_to_worklist(Unique_Node_List* worklist) const {}
rkennke@52925 1110
rkennke@52925 1111 void* ShenandoahBarrierSetC2::create_barrier_state(Arena* comp_arena) const {
rkennke@52925 1112 return new(comp_arena) ShenandoahBarrierSetC2State(comp_arena);
rkennke@52925 1113 }
rkennke@52925 1114
rkennke@52925 1115 ShenandoahBarrierSetC2State* ShenandoahBarrierSetC2::state() const {
rkennke@52925 1116 return reinterpret_cast<ShenandoahBarrierSetC2State*>(Compile::current()->barrier_set_state());
rkennke@52925 1117 }
rkennke@52925 1118
rkennke@52925 1119 // If the BarrierSetC2 state has kept macro nodes in its compilation unit state to be
rkennke@52925 1120 // expanded later, then now is the time to do so.
rkennke@52925 1121 bool ShenandoahBarrierSetC2::expand_macro_nodes(PhaseMacroExpand* macro) const { return false; }
rkennke@52925 1122
rkennke@52925 1123 #ifdef ASSERT
rkennke@52925 1124 void ShenandoahBarrierSetC2::verify_gc_barriers(Compile* compile, CompilePhase phase) const {
rkennke@52925 1125 if (ShenandoahVerifyOptoBarriers && phase == BarrierSetC2::BeforeExpand) {
rkennke@52925 1126 ShenandoahBarrierNode::verify(Compile::current()->root());
rkennke@52925 1127 } else if (phase == BarrierSetC2::BeforeCodeGen) {
rkennke@52925 1128 // Verify G1 pre-barriers
rkennke@52925 1129 const int marking_offset = in_bytes(ShenandoahThreadLocalData::satb_mark_queue_active_offset());
rkennke@52925 1130
rkennke@52925 1131 ResourceArea *area = Thread::current()->resource_area();
rkennke@52925 1132 Unique_Node_List visited(area);
rkennke@52925 1133 Node_List worklist(area);
rkennke@52925 1134 // We're going to walk control flow backwards starting from the Root
rkennke@52925 1135 worklist.push(compile->root());
rkennke@52925 1136 while (worklist.size() > 0) {
rkennke@52925 1137 Node *x = worklist.pop();
rkennke@52925 1138 if (x == NULL || x == compile->top()) continue;
rkennke@52925 1139 if (visited.member(x)) {
rkennke@52925 1140 continue;
rkennke@52925 1141 } else {
rkennke@52925 1142 visited.push(x);
rkennke@52925 1143 }
rkennke@52925 1144
rkennke@52925 1145 if (x->is_Region()) {
rkennke@52925 1146 for (uint i = 1; i < x->req(); i++) {
rkennke@52925 1147 worklist.push(x->in(i));
rkennke@52925 1148 }
rkennke@52925 1149 } else {
rkennke@52925 1150 worklist.push(x->in(0));
rkennke@52925 1151 // We are looking for the pattern:
rkennke@52925 1152 // /->ThreadLocal
rkennke@52925 1153 // If->Bool->CmpI->LoadB->AddP->ConL(marking_offset)
rkennke@52925 1154 // \->ConI(0)
rkennke@52925 1155 // We want to verify that the If and the LoadB have the same control
rkennke@52925 1156 // See GraphKit::g1_write_barrier_pre()
rkennke@52925 1157 if (x->is_If()) {
rkennke@52925 1158 IfNode *iff = x->as_If();
rkennke@52925 1159 if (iff->in(1)->is_Bool() && iff->in(1)->in(1)->is_Cmp()) {
rkennke@52925 1160 CmpNode *cmp = iff->in(1)->in(1)->as_Cmp();
rkennke@52925 1161 if (cmp->Opcode() == Op_CmpI && cmp->in(2)->is_Con() && cmp->in(2)->bottom_type()->is_int()->get_con() == 0
rkennke@52925 1162 && cmp->in(1)->is_Load()) {
rkennke@52925 1163 LoadNode *load = cmp->in(1)->as_Load();
rkennke@52925 1164 if (load->Opcode() == Op_LoadB && load->in(2)->is_AddP() && load->in(2)->in(2)->Opcode() == Op_ThreadLocal
rkennke@52925 1165 && load->in(2)->in(3)->is_Con()
rkennke@52925 1166 && load->in(2)->in(3)->bottom_type()->is_intptr_t()->get_con() == marking_offset) {
rkennke@52925 1167
rkennke@52925 1168 Node *if_ctrl = iff->in(0);
rkennke@52925 1169 Node *load_ctrl = load->in(0);
rkennke@52925 1170
rkennke@52925 1171 if (if_ctrl != load_ctrl) {
rkennke@52925 1172 // Skip possible CProj->NeverBranch in infinite loops
rkennke@52925 1173 if ((if_ctrl->is_Proj() && if_ctrl->Opcode() == Op_CProj)
rkennke@52925 1174 && (if_ctrl->in(0)->is_MultiBranch() && if_ctrl->in(0)->Opcode() == Op_NeverBranch)) {
rkennke@52925 1175 if_ctrl = if_ctrl->in(0)->in(0);
rkennke@52925 1176 }
rkennke@52925 1177 }
rkennke@52925 1178 assert(load_ctrl != NULL && if_ctrl == load_ctrl, "controls must match");
rkennke@52925 1179 }
rkennke@52925 1180 }
rkennke@52925 1181 }
rkennke@52925 1182 }
rkennke@52925 1183 }
rkennke@52925 1184 }
rkennke@52925 1185 }
rkennke@52925 1186 }
rkennke@52925 1187 #endif
rkennke@52925 1188
rkennke@52925 1189 Node* ShenandoahBarrierSetC2::ideal_node(PhaseGVN* phase, Node* n, bool can_reshape) const {
rkennke@52925 1190 if (is_shenandoah_wb_pre_call(n)) {
rkennke@52925 1191 uint cnt = ShenandoahBarrierSetC2::write_ref_field_pre_entry_Type()->domain()->cnt();
rkennke@52925 1192 if (n->req() > cnt) {
rkennke@52925 1193 Node* addp = n->in(cnt);
rkennke@52925 1194 if (has_only_shenandoah_wb_pre_uses(addp)) {
rkennke@52925 1195 n->del_req(cnt);
rkennke@52925 1196 if (can_reshape) {
rkennke@52925 1197 phase->is_IterGVN()->_worklist.push(addp);
rkennke@52925 1198 }
rkennke@52925 1199 return n;
rkennke@52925 1200 }
rkennke@52925 1201 }
rkennke@52925 1202 }
rkennke@52925 1203 if (n->Opcode() == Op_CmpP) {
rkennke@52925 1204 Node* in1 = n->in(1);
rkennke@52925 1205 Node* in2 = n->in(2);
rkennke@52925 1206 if (in1->bottom_type() == TypePtr::NULL_PTR) {
rkennke@52925 1207 in2 = step_over_gc_barrier(in2);
rkennke@52925 1208 }
rkennke@52925 1209 if (in2->bottom_type() == TypePtr::NULL_PTR) {
rkennke@52925 1210 in1 = step_over_gc_barrier(in1);
rkennke@52925 1211 }
rkennke@52925 1212 PhaseIterGVN* igvn = phase->is_IterGVN();
rkennke@52925 1213 if (in1 != n->in(1)) {
rkennke@52925 1214 if (igvn != NULL) {
rkennke@52925 1215 n->set_req_X(1, in1, igvn);
rkennke@52925 1216 } else {
rkennke@52925 1217 n->set_req(1, in1);
rkennke@52925 1218 }
rkennke@52925 1219 assert(in2 == n->in(2), "only one change");
rkennke@52925 1220 return n;
rkennke@52925 1221 }
rkennke@52925 1222 if (in2 != n->in(2)) {
rkennke@52925 1223 if (igvn != NULL) {
rkennke@52925 1224 n->set_req_X(2, in2, igvn);
rkennke@52925 1225 } else {
rkennke@52925 1226 n->set_req(2, in2);
rkennke@52925 1227 }
rkennke@52925 1228 return n;
rkennke@52925 1229 }
rkennke@52925 1230 } else if (can_reshape &&
rkennke@52925 1231 n->Opcode() == Op_If &&
rkennke@52925 1232 ShenandoahWriteBarrierNode::is_heap_stable_test(n) &&
rkennke@52925 1233 n->in(0) != NULL) {
rkennke@52925 1234 Node* dom = n->in(0);
rkennke@52925 1235 Node* prev_dom = n;
rkennke@52925 1236 int op = n->Opcode();
rkennke@52925 1237 int dist = 16;
rkennke@52925 1238 // Search up the dominator tree for another heap stable test
rkennke@52925 1239 while (dom->Opcode() != op || // Not same opcode?
rkennke@52925 1240 !ShenandoahWriteBarrierNode::is_heap_stable_test(dom) || // Not same input 1?
rkennke@52925 1241 prev_dom->in(0) != dom) { // One path of test does not dominate?
rkennke@52925 1242 if (dist < 0) return NULL;
rkennke@52925 1243
rkennke@52925 1244 dist--;
rkennke@52925 1245 prev_dom = dom;
rkennke@52925 1246 dom = IfNode::up_one_dom(dom);
rkennke@52925 1247 if (!dom) return NULL;
rkennke@52925 1248 }
rkennke@52925 1249
rkennke@52925 1250 // Check that we did not follow a loop back to ourselves
rkennke@52925 1251 if (n == dom) {
rkennke@52925 1252 return NULL;
rkennke@52925 1253 }
rkennke@52925 1254
rkennke@52925 1255 return n->as_If()->dominated_by(prev_dom, phase->is_IterGVN());
rkennke@52925 1256 }
rkennke@52925 1257
rkennke@52925 1258 return NULL;
rkennke@52925 1259 }
rkennke@52925 1260
rkennke@52925 1261 Node* ShenandoahBarrierSetC2::identity_node(PhaseGVN* phase, Node* n) const {
rkennke@52925 1262 if (n->is_Load()) {
rkennke@52925 1263 Node *mem = n->in(MemNode::Memory);
rkennke@52925 1264 Node *value = n->as_Load()->can_see_stored_value(mem, phase);
rkennke@52925 1265 if (value) {
rkennke@52925 1266 PhaseIterGVN *igvn = phase->is_IterGVN();
rkennke@52925 1267 if (igvn != NULL &&
rkennke@52925 1268 value->is_Phi() &&
rkennke@52925 1269 value->req() > 2 &&
rkennke@52925 1270 value->in(1) != NULL &&
rkennke@52925 1271 value->in(1)->is_ShenandoahBarrier()) {
rkennke@52925 1272 if (igvn->_worklist.member(value) ||
rkennke@52925 1273 igvn->_worklist.member(value->in(0)) ||
rkennke@52925 1274 (value->in(0)->in(1) != NULL &&
rkennke@52925 1275 value->in(0)->in(1)->is_IfProj() &&
rkennke@52925 1276 (igvn->_worklist.member(value->in(0)->in(1)) ||
rkennke@52925 1277 (value->in(0)->in(1)->in(0) != NULL &&
rkennke@52925 1278 igvn->_worklist.member(value->in(0)->in(1)->in(0)))))) {
rkennke@52925 1279 igvn->_worklist.push(n);
rkennke@52925 1280 return n;
rkennke@52925 1281 }
rkennke@52925 1282 }
rkennke@52925 1283 // (This works even when value is a Con, but LoadNode::Value
rkennke@52925 1284 // usually runs first, producing the singleton type of the Con.)
rkennke@52925 1285 Node *value_no_barrier = step_over_gc_barrier(value->Opcode() == Op_EncodeP ? value->in(1) : value);
rkennke@52925 1286 if (value->Opcode() == Op_EncodeP) {
rkennke@52925 1287 if (value_no_barrier != value->in(1)) {
rkennke@52925 1288 Node *encode = value->clone();
rkennke@52925 1289 encode->set_req(1, value_no_barrier);
rkennke@52925 1290 encode = phase->transform(encode);
rkennke@52925 1291 return encode;
rkennke@52925 1292 }
rkennke@52925 1293 } else {
rkennke@52925 1294 return value_no_barrier;
rkennke@52925 1295 }
rkennke@52925 1296 }
rkennke@52925 1297 }
rkennke@52925 1298 return n;
rkennke@52925 1299 }
rkennke@52925 1300
rkennke@52925 1301 bool ShenandoahBarrierSetC2::has_only_shenandoah_wb_pre_uses(Node* n) {
rkennke@52925 1302 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
rkennke@52925 1303 Node* u = n->fast_out(i);
rkennke@52925 1304 if (!is_shenandoah_wb_pre_call(u)) {
rkennke@52925 1305 return false;
rkennke@52925 1306 }
rkennke@52925 1307 }
rkennke@52925 1308 return n->outcnt() > 0;
rkennke@52925 1309 }
rkennke@52925 1310
rkennke@52925 1311 bool ShenandoahBarrierSetC2::flatten_gc_alias_type(const TypePtr*& adr_type) const {
rkennke@52925 1312 int offset = adr_type->offset();
rkennke@52925 1313 if (offset == ShenandoahBrooksPointer::byte_offset()) {
rkennke@52925 1314 if (adr_type->isa_aryptr()) {
rkennke@52925 1315 adr_type = TypeAryPtr::make(adr_type->ptr(), adr_type->isa_aryptr()->ary(), adr_type->isa_aryptr()->klass(), false, offset);
rkennke@52925 1316 } else if (adr_type->isa_instptr()) {
rkennke@52925 1317 adr_type = TypeInstPtr::make(adr_type->ptr(), ciEnv::current()->Object_klass(), false, NULL, offset);
rkennke@52925 1318 }
rkennke@52925 1319 return true;
rkennke@52925 1320 } else {
rkennke@52925 1321 return false;
rkennke@52925 1322 }
rkennke@52925 1323 }
rkennke@52925 1324
rkennke@52925 1325 bool ShenandoahBarrierSetC2::final_graph_reshaping(Compile* compile, Node* n, uint opcode) const {
rkennke@52925 1326 switch (opcode) {
rkennke@52925 1327 case Op_CallLeaf:
rkennke@52925 1328 case Op_CallLeafNoFP: {
rkennke@52925 1329 assert (n->is_Call(), "");
rkennke@52925 1330 CallNode *call = n->as_Call();
rkennke@52925 1331 if (ShenandoahBarrierSetC2::is_shenandoah_wb_pre_call(call)) {
rkennke@52925 1332 uint cnt = ShenandoahBarrierSetC2::write_ref_field_pre_entry_Type()->domain()->cnt();
rkennke@52925 1333 if (call->req() > cnt) {
rkennke@52925 1334 assert(call->req() == cnt + 1, "only one extra input");
rkennke@52925 1335 Node *addp = call->in(cnt);
rkennke@52925 1336 assert(!ShenandoahBarrierSetC2::has_only_shenandoah_wb_pre_uses(addp), "useless address computation?");
rkennke@52925 1337 call->del_req(cnt);
rkennke@52925 1338 }
rkennke@52925 1339 }
rkennke@52925 1340 return false;
rkennke@52925 1341 }
rkennke@52925 1342 case Op_ShenandoahCompareAndSwapP:
rkennke@52925 1343 case Op_ShenandoahCompareAndSwapN:
rkennke@52925 1344 case Op_ShenandoahWeakCompareAndSwapN:
rkennke@52925 1345 case Op_ShenandoahWeakCompareAndSwapP:
rkennke@52925 1346 case Op_ShenandoahCompareAndExchangeP:
rkennke@52925 1347 case Op_ShenandoahCompareAndExchangeN:
rkennke@52925 1348 #ifdef ASSERT
rkennke@52925 1349 if( VerifyOptoOopOffsets ) {
rkennke@52925 1350 MemNode* mem = n->as_Mem();
rkennke@52925 1351 // Check to see if address types have grounded out somehow.
rkennke@52925 1352 const TypeInstPtr *tp = mem->in(MemNode::Address)->bottom_type()->isa_instptr();
rkennke@52925 1353 ciInstanceKlass *k = tp->klass()->as_instance_klass();
rkennke@52925 1354 bool oop_offset_is_sane = k->contains_field_offset(tp->offset());
rkennke@52925 1355 assert( !tp || oop_offset_is_sane, "" );
rkennke@52925 1356 }
rkennke@52925 1357 #endif
rkennke@52925 1358 return true;
rkennke@52925 1359 case Op_ShenandoahReadBarrier:
rkennke@52925 1360 return true;
rkennke@52925 1361 case Op_ShenandoahWriteBarrier:
rkennke@52925 1362 assert(false, "should have been expanded already");
rkennke@52925 1363 return true;
rkennke@52925 1364 default:
rkennke@52925 1365 return false;
rkennke@52925 1366 }
rkennke@52925 1367 }
rkennke@52925 1368
rkennke@52925 1369 #ifdef ASSERT
rkennke@52925 1370 bool ShenandoahBarrierSetC2::verify_gc_alias_type(const TypePtr* adr_type, int offset) const {
rkennke@52925 1371 if (offset == ShenandoahBrooksPointer::byte_offset() &&
rkennke@52925 1372 (adr_type->base() == Type::AryPtr || adr_type->base() == Type::OopPtr)) {
rkennke@52925 1373 return true;
rkennke@52925 1374 } else {
rkennke@52925 1375 return false;
rkennke@52925 1376 }
rkennke@52925 1377 }
rkennke@52925 1378 #endif
rkennke@52925 1379
rkennke@52925 1380 bool ShenandoahBarrierSetC2::escape_add_to_con_graph(ConnectionGraph* conn_graph, PhaseGVN* gvn, Unique_Node_List* delayed_worklist, Node* n, uint opcode) const {
rkennke@52925 1381 switch (opcode) {
rkennke@52925 1382 case Op_ShenandoahCompareAndExchangeP:
rkennke@52925 1383 case Op_ShenandoahCompareAndExchangeN:
rkennke@52925 1384 conn_graph->add_objload_to_connection_graph(n, delayed_worklist);
rkennke@52925 1385 // fallthrough
rkennke@52925 1386 case Op_ShenandoahWeakCompareAndSwapP:
rkennke@52925 1387 case Op_ShenandoahWeakCompareAndSwapN:
rkennke@52925 1388 case Op_ShenandoahCompareAndSwapP:
rkennke@52925 1389 case Op_ShenandoahCompareAndSwapN:
rkennke@52925 1390 conn_graph->add_to_congraph_unsafe_access(n, opcode, delayed_worklist);
rkennke@52925 1391 return true;
rkennke@52925 1392 case Op_StoreP: {
rkennke@52925 1393 Node* adr = n->in(MemNode::Address);
rkennke@52925 1394 const Type* adr_type = gvn->type(adr);
rkennke@52925 1395 // Pointer stores in G1 barriers looks like unsafe access.
rkennke@52925 1396 // Ignore such stores to be able scalar replace non-escaping
rkennke@52925 1397 // allocations.
rkennke@52925 1398 if (adr_type->isa_rawptr() && adr->is_AddP()) {
rkennke@52925 1399 Node* base = conn_graph->get_addp_base(adr);
rkennke@52925 1400 if (base->Opcode() == Op_LoadP &&
rkennke@52925 1401 base->in(MemNode::Address)->is_AddP()) {
rkennke@52925 1402 adr = base->in(MemNode::Address);
rkennke@52925 1403 Node* tls = conn_graph->get_addp_base(adr);
rkennke@52925 1404 if (tls->Opcode() == Op_ThreadLocal) {
rkennke@52925 1405 int offs = (int) gvn->find_intptr_t_con(adr->in(AddPNode::Offset), Type::OffsetBot);
rkennke@52925 1406 const int buf_offset = in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset());
rkennke@52925 1407 if (offs == buf_offset) {
rkennke@52925 1408 return true; // Pre barrier previous oop value store.
rkennke@52925 1409 }
rkennke@52925 1410 }
rkennke@52925 1411 }
rkennke@52925 1412 }
rkennke@52925 1413 return false;
rkennke@52925 1414 }
rkennke@52925 1415 case Op_ShenandoahReadBarrier:
rkennke@52925 1416 case Op_ShenandoahWriteBarrier:
rkennke@52925 1417 // Barriers 'pass through' its arguments. I.e. what goes in, comes out.
rkennke@52925 1418 // It doesn't escape.
rkennke@52925 1419 conn_graph->add_local_var_and_edge(n, PointsToNode::NoEscape, n->in(ShenandoahBarrierNode::ValueIn), delayed_worklist);
rkennke@52925 1420 break;
rkennke@52925 1421 case Op_ShenandoahEnqueueBarrier:
rkennke@52925 1422 conn_graph->add_local_var_and_edge(n, PointsToNode::NoEscape, n->in(1), delayed_worklist);
rkennke@52925 1423 break;
rkennke@52925 1424 default:
rkennke@52925 1425 // Nothing
rkennke@52925 1426 break;
rkennke@52925 1427 }
rkennke@52925 1428 return false;
rkennke@52925 1429 }
rkennke@52925 1430
rkennke@52925 1431 bool ShenandoahBarrierSetC2::escape_add_final_edges(ConnectionGraph* conn_graph, PhaseGVN* gvn, Node* n, uint opcode) const {
rkennke@52925 1432 switch (opcode) {
rkennke@52925 1433 case Op_ShenandoahCompareAndExchangeP:
rkennke@52925 1434 case Op_ShenandoahCompareAndExchangeN: {
rkennke@52925 1435 Node *adr = n->in(MemNode::Address);
rkennke@52925 1436 conn_graph->add_local_var_and_edge(n, PointsToNode::NoEscape, adr, NULL);
rkennke@52925 1437 // fallthrough
rkennke@52925 1438 }
rkennke@52925 1439 case Op_ShenandoahCompareAndSwapP:
rkennke@52925 1440 case Op_ShenandoahCompareAndSwapN:
rkennke@52925 1441 case Op_ShenandoahWeakCompareAndSwapP:
rkennke@52925 1442 case Op_ShenandoahWeakCompareAndSwapN:
rkennke@52925 1443 return conn_graph->add_final_edges_unsafe_access(n, opcode);
rkennke@52925 1444 case Op_ShenandoahReadBarrier:
rkennke@52925 1445 case Op_ShenandoahWriteBarrier:
rkennke@52925 1446 // Barriers 'pass through' its arguments. I.e. what goes in, comes out.
rkennke@52925 1447 // It doesn't escape.
rkennke@52925 1448 conn_graph->add_local_var_and_edge(n, PointsToNode::NoEscape, n->in(ShenandoahBarrierNode::ValueIn), NULL);
rkennke@52925 1449 return true;
rkennke@52925 1450 case Op_ShenandoahEnqueueBarrier:
rkennke@52925 1451 conn_graph->add_local_var_and_edge(n, PointsToNode::NoEscape, n->in(1), NULL);
rkennke@52925 1452 return true;
rkennke@52925 1453 default:
rkennke@52925 1454 // Nothing
rkennke@52925 1455 break;
rkennke@52925 1456 }
rkennke@52925 1457 return false;
rkennke@52925 1458 }
rkennke@52925 1459
rkennke@52925 1460 bool ShenandoahBarrierSetC2::escape_has_out_with_unsafe_object(Node* n) const {
rkennke@52925 1461 return n->has_out_with(Op_ShenandoahCompareAndExchangeP) || n->has_out_with(Op_ShenandoahCompareAndExchangeN) ||
rkennke@52925 1462 n->has_out_with(Op_ShenandoahCompareAndSwapP, Op_ShenandoahCompareAndSwapN, Op_ShenandoahWeakCompareAndSwapP, Op_ShenandoahWeakCompareAndSwapN);
rkennke@52925 1463
rkennke@52925 1464 }
rkennke@52925 1465
rkennke@52925 1466 bool ShenandoahBarrierSetC2::escape_is_barrier_node(Node* n) const {
rkennke@52925 1467 return n->is_ShenandoahBarrier();
rkennke@52925 1468 }
rkennke@52925 1469
rkennke@52925 1470 bool ShenandoahBarrierSetC2::matcher_find_shared_visit(Matcher* matcher, Matcher::MStack& mstack, Node* n, uint opcode, bool& mem_op, int& mem_addr_idx) const {
rkennke@52925 1471 switch (opcode) {
rkennke@52925 1472 case Op_ShenandoahReadBarrier:
rkennke@52925 1473 if (n->in(ShenandoahBarrierNode::ValueIn)->is_DecodeNarrowPtr()) {
rkennke@52925 1474 matcher->set_shared(n->in(ShenandoahBarrierNode::ValueIn)->in(1));
rkennke@52925 1475 }
rkennke@52925 1476 matcher->set_shared(n);
rkennke@52925 1477 return true;
rkennke@52925 1478 default:
rkennke@52925 1479 break;
rkennke@52925 1480 }
rkennke@52925 1481 return false;
rkennke@52925 1482 }
rkennke@52925 1483
rkennke@52925 1484 bool ShenandoahBarrierSetC2::matcher_find_shared_post_visit(Matcher* matcher, Node* n, uint opcode) const {
rkennke@52925 1485 switch (opcode) {
rkennke@52925 1486 case Op_ShenandoahCompareAndExchangeP:
rkennke@52925 1487 case Op_ShenandoahCompareAndExchangeN:
rkennke@52925 1488 case Op_ShenandoahWeakCompareAndSwapP:
rkennke@52925 1489 case Op_ShenandoahWeakCompareAndSwapN:
rkennke@52925 1490 case Op_ShenandoahCompareAndSwapP:
rkennke@52925 1491 case Op_ShenandoahCompareAndSwapN: { // Convert trinary to binary-tree
rkennke@52925 1492 Node* newval = n->in(MemNode::ValueIn);
rkennke@52925 1493 Node* oldval = n->in(LoadStoreConditionalNode::ExpectedIn);
rkennke@52925 1494 Node* pair = new BinaryNode(oldval, newval);
rkennke@52925 1495 n->set_req(MemNode::ValueIn,pair);
rkennke@52925 1496 n->del_req(LoadStoreConditionalNode::ExpectedIn);
rkennke@52925 1497 return true;
rkennke@52925 1498 }
rkennke@52925 1499 default:
rkennke@52925 1500 break;
rkennke@52925 1501 }
rkennke@52925 1502 return false;
rkennke@52925 1503 }
rkennke@52925 1504
rkennke@52925 1505 bool ShenandoahBarrierSetC2::matcher_is_store_load_barrier(Node* x, uint xop) const {
rkennke@52925 1506 return xop == Op_ShenandoahCompareAndExchangeP ||
rkennke@52925 1507 xop == Op_ShenandoahCompareAndExchangeN ||
rkennke@52925 1508 xop == Op_ShenandoahWeakCompareAndSwapP ||
rkennke@52925 1509 xop == Op_ShenandoahWeakCompareAndSwapN ||
rkennke@52925 1510 xop == Op_ShenandoahCompareAndSwapN ||
rkennke@52925 1511 xop == Op_ShenandoahCompareAndSwapP;
rkennke@52925 1512 }
rkennke@52925 1513
rkennke@52925 1514 void ShenandoahBarrierSetC2::igvn_add_users_to_worklist(PhaseIterGVN* igvn, Node* use) const {
rkennke@52925 1515 if (use->is_ShenandoahBarrier()) {
rkennke@52925 1516 for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
rkennke@52925 1517 Node* u = use->fast_out(i2);
rkennke@52925 1518 Node* cmp = use->find_out_with(Op_CmpP);
rkennke@52925 1519 if (u->Opcode() == Op_CmpP) {
rkennke@52925 1520 igvn->_worklist.push(cmp);
rkennke@52925 1521 }
rkennke@52925 1522 }
rkennke@52925 1523 }
rkennke@52925 1524 }
rkennke@52925 1525
rkennke@52925 1526 void ShenandoahBarrierSetC2::ccp_analyze(PhaseCCP* ccp, Unique_Node_List& worklist, Node* use) const {
rkennke@52925 1527 if (use->is_ShenandoahBarrier()) {
rkennke@52925 1528 for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
rkennke@52925 1529 Node* p = use->fast_out(i2);
rkennke@52925 1530 if (p->Opcode() == Op_AddP) {
rkennke@52925 1531 for (DUIterator_Fast i3max, i3 = p->fast_outs(i3max); i3 < i3max; i3++) {
rkennke@52925 1532 Node* q = p->fast_out(i3);
rkennke@52925 1533 if (q->is_Load()) {
rkennke@52925 1534 if(q->bottom_type() != ccp->type(q)) {
rkennke@52925 1535 worklist.push(q);
rkennke@52925 1536 }
rkennke@52925 1537 }
rkennke@52925 1538 }
rkennke@52925 1539 }
rkennke@52925 1540 }
rkennke@52925 1541 }
rkennke@52925 1542 }
rkennke@52925 1543
rkennke@52925 1544 Node* ShenandoahBarrierSetC2::split_if_pre(PhaseIdealLoop* phase, Node* n) const {
rkennke@52925 1545 if (n->Opcode() == Op_ShenandoahReadBarrier) {
rkennke@52925 1546 ((ShenandoahReadBarrierNode*)n)->try_move(phase);
rkennke@52925 1547 } else if (n->Opcode() == Op_ShenandoahWriteBarrier) {
rkennke@52925 1548 return ((ShenandoahWriteBarrierNode*)n)->try_split_thru_phi(phase);
rkennke@52925 1549 }
rkennke@52925 1550
rkennke@52925 1551 return NULL;
rkennke@52925 1552 }
rkennke@52925 1553
rkennke@52925 1554 bool ShenandoahBarrierSetC2::build_loop_late_post(PhaseIdealLoop* phase, Node* n) const {
rkennke@52925 1555 return ShenandoahBarrierNode::build_loop_late_post(phase, n);
rkennke@52925 1556 }
rkennke@52925 1557
rkennke@52925 1558 bool ShenandoahBarrierSetC2::sink_node(PhaseIdealLoop* phase, Node* n, Node* x, Node* x_ctrl, Node* n_ctrl) const {
rkennke@52925 1559 if (n->is_ShenandoahBarrier()) {
rkennke@52925 1560 return x->as_ShenandoahBarrier()->sink_node(phase, x_ctrl, n_ctrl);
rkennke@52925 1561 }
rkennke@52925 1562 if (n->is_MergeMem()) {
rkennke@52925 1563 // PhaseIdealLoop::split_if_with_blocks_post() would:
rkennke@52925 1564 // _igvn._worklist.yank(x);
rkennke@52925 1565 // which sometimes causes chains of MergeMem which some of
rkennke@52925 1566 // shenandoah specific code doesn't support
rkennke@52925 1567 phase->register_new_node(x, x_ctrl);
rkennke@52925 1568 return true;
rkennke@52925 1569 }
rkennke@52925 1570 return false;
rkennke@52925 1571 }