diff a/src/hotspot/cpu/aarch64/aarch64.ad b/src/hotspot/cpu/aarch64/aarch64.ad
--- a/src/hotspot/cpu/aarch64/aarch64.ad
+++ b/src/hotspot/cpu/aarch64/aarch64.ad
@@ -1510,12 +1510,10 @@
       // We handle these
     case Op_CompareAndSwapI:
     case Op_CompareAndSwapL:
     case Op_CompareAndSwapP:
     case Op_CompareAndSwapN:
-    case Op_ShenandoahCompareAndSwapP:
-    case Op_ShenandoahCompareAndSwapN:
     case Op_CompareAndSwapB:
     case Op_CompareAndSwapS:
     case Op_GetAndSetI:
     case Op_GetAndSetL:
     case Op_GetAndSetP:
@@ -1533,14 +1531,10 @@
     case Op_WeakCompareAndSwapS:
     case Op_WeakCompareAndSwapI:
     case Op_WeakCompareAndSwapL:
     case Op_WeakCompareAndSwapP:
     case Op_WeakCompareAndSwapN:
-    case Op_ShenandoahWeakCompareAndSwapP:
-    case Op_ShenandoahWeakCompareAndSwapN:
-    case Op_ShenandoahCompareAndExchangeP:
-    case Op_ShenandoahCompareAndExchangeN:
       return maybe_volatile;
     default:
       return false;
     }
   }
diff a/src/hotspot/cpu/aarch64/gc/shenandoah/shenandoahBarrierSetAssembler_aarch64.cpp b/src/hotspot/cpu/aarch64/gc/shenandoah/shenandoahBarrierSetAssembler_aarch64.cpp
--- a/src/hotspot/cpu/aarch64/gc/shenandoah/shenandoahBarrierSetAssembler_aarch64.cpp
+++ b/src/hotspot/cpu/aarch64/gc/shenandoah/shenandoahBarrierSetAssembler_aarch64.cpp
@@ -39,10 +39,13 @@
 #ifdef COMPILER1
 #include "c1/c1_LIRAssembler.hpp"
 #include "c1/c1_MacroAssembler.hpp"
 #include "gc/shenandoah/c1/shenandoahBarrierSetC1.hpp"
 #endif
+#ifdef COMPILER2
+#include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
+#endif
 
 #define __ masm->
 
 void ShenandoahBarrierSetAssembler::arraycopy_prologue(MacroAssembler* masm, DecoratorSet decorators, bool is_oop,
                                                        Register src, Register dst, Register count, RegSet saved_regs) {
@@ -604,10 +607,308 @@
   } else {
     __ cset(result, Assembler::EQ);
   }
 }
 
+#ifdef COMPILER2
+void ShenandoahBarrierSetAssembler::load_ref_barrier_c2(const MachNode* node, MacroAssembler* masm, Register obj, Register addr, Register tmp, bool narrow, bool maybe_null) {
+  if (!ShenandoahLoadRefBarrierStubC2::needs_barrier(node)) {
+    return;
+  }
+  Assembler::InlineSkippedInstructionsCounter skip_counter(masm);
+  Label done;
+  if (maybe_null) {
+    __ cbz(obj, done);
+  }
+  ShenandoahLoadRefBarrierStubC2* const stub = ShenandoahLoadRefBarrierStubC2::create(node, obj, addr, tmp, noreg, noreg, narrow);
+  // Don't preserve the obj across the runtime call, we override it from the return value anyway.
+  stub->dont_preserve(obj);
+  // Check if GC marking is in progress, otherwise we don't have to do anything.
+  Address gc_state(rthread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
+  __ ldrb(rscratch1, gc_state);
+  __ tstw(rscratch1, ShenandoahHeap::HAS_FORWARDED);
+  __ br(Assembler::NE, *stub->entry());
+  __ bind(*stub->continuation());
+  __ bind(done);
+}
+
+void ShenandoahBarrierSetAssembler::satb_barrier_c2(const MachNode* node, MacroAssembler* masm, Register addr, Register pre_val) {
+  assert_different_registers(addr, pre_val);
+  if (!ShenandoahSATBBarrierStubC2::needs_barrier(node)) {
+    return;
+  }
+  Assembler::InlineSkippedInstructionsCounter skip_counter(masm);
+  ShenandoahSATBBarrierStubC2* const stub = ShenandoahSATBBarrierStubC2::create(node, addr, pre_val);
+
+  // Check if GC marking is in progress, otherwise we don't have to do anything.
+  Address gc_state(rthread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
+  __ ldrb(rscratch1, gc_state);
+  __ tstw(rscratch1, ShenandoahHeap::MARKING);
+  __ br(Assembler::NE, *stub->entry());
+  __ bind(*stub->continuation());
+}
+
+void ShenandoahBarrierSetAssembler::card_barrier_c2(const MachNode* node, MacroAssembler* masm, Register addr, Register tmp) {
+  if (!ShenandoahCardBarrier ||
+      (node->barrier_data() & (ShenandoahBarrierCardMark | ShenandoahBarrierCardMarkNotNull)) == 0) {
+    return;
+  }
+
+  Assembler::InlineSkippedInstructionsCounter skip_counter(masm);
+  __ lsr(tmp, addr, CardTable::card_shift());
+
+  assert(CardTable::dirty_card_val() == 0, "must be");
+
+  Address curr_ct_holder_addr(rthread, in_bytes(ShenandoahThreadLocalData::card_table_offset()));
+  __ ldr(rscratch1, curr_ct_holder_addr);
+
+  if (UseCondCardMark) {
+    Label L_already_dirty;
+    __ ldrb(rscratch2, Address(tmp, rscratch1));
+    __ cbz(rscratch2, L_already_dirty);
+    __ strb(zr, Address(tmp, rscratch1));
+    __ bind(L_already_dirty);
+  } else {
+    __ strb(zr, Address(tmp, rscratch1));
+  }
+}
+
+void ShenandoahBarrierSetAssembler::cmpxchg_oop_c2(const MachNode* node,
+                                                   MacroAssembler* masm,
+                                                   Register addr,
+                                                   Register expected,
+                                                   Register new_val,
+                                                   Register result,
+                                                   bool acquire, bool release, bool weak,
+                                                   bool is_cae) {
+  Register tmp = rscratch2;
+  Assembler::operand_size size = UseCompressedOops ? Assembler::word : Assembler::xword;
+
+  assert_different_registers(addr, expected, result, tmp);
+  assert_different_registers(addr, new_val,  result, tmp);
+
+  ShenandoahCASBarrierSlowStubC2* const slow_stub = ShenandoahCASBarrierSlowStubC2::create(node, addr, expected, new_val, result, tmp, is_cae, acquire, release, weak);
+  ShenandoahCASBarrierMidStubC2* const mid_stub = ShenandoahCASBarrierMidStubC2::create(node, slow_stub, expected, result, tmp, is_cae);
+
+  // Step 1. Fast-path.
+  //
+  // Try to CAS with given arguments.  If successful, then we are done.
+  __ cmpxchg(addr, expected, new_val, size, acquire, release, weak, result);
+  // EQ flag set iff success. result holds value fetched.
+
+  __ br(Assembler::NE, *mid_stub->entry());
+
+  // Slow-stub re-enters with condition flags according to CAS, we may need to
+  // set result accordingly.
+  __ bind(*slow_stub->continuation());
+  if (!is_cae) {
+    __ cset(result, Assembler::EQ);
+  }
+
+  // Mid-stub re-enters with result set correctly.
+  __ bind(*mid_stub->continuation());
+}
+
+#undef __
+#define __ masm.
+
+void ShenandoahLoadRefBarrierStubC2::emit_code(MacroAssembler& masm) {
+  Assembler::InlineSkippedInstructionsCounter skip_counter(&masm);
+  __ bind(*entry());
+  Register obj = _obj;
+  if (_narrow) {
+    __ decode_heap_oop(_tmp1, _obj);
+    obj = _tmp1;
+  }
+  // Weak/phantom loads always need to go to runtime.
+  if ((_node->barrier_data() & ShenandoahBarrierStrong) != 0) {
+    // Check for object in cset.
+    __ mov(rscratch2, ShenandoahHeap::in_cset_fast_test_addr());
+    __ lsr(rscratch1, obj, ShenandoahHeapRegion::region_size_bytes_shift_jint());
+    __ ldrb(rscratch2, Address(rscratch2, rscratch1));
+    __ cbz(rscratch2, *continuation());
+  }
+  {
+    SaveLiveRegisters save_registers(&masm, this);
+    if (c_rarg0 != obj) {
+      if (c_rarg0 == _addr) {
+        __ mov(rscratch1, _addr);
+        _addr = rscratch1;
+      }
+      __ mov(c_rarg0, obj);
+    }
+    __ mov(c_rarg1, _addr);
+
+    if (_narrow) {
+      if ((_node->barrier_data() & ShenandoahBarrierStrong) != 0) {
+        __ mov(rscratch1, CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_strong_narrow));
+      } else if ((_node->barrier_data() & ShenandoahBarrierWeak) != 0) {
+        __ mov(rscratch1, CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_weak_narrow));
+      } else if ((_node->barrier_data() & ShenandoahBarrierPhantom) != 0) {
+        __ mov(rscratch1, CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_phantom_narrow));
+      }
+    } else {
+      if ((_node->barrier_data() & ShenandoahBarrierStrong) != 0) {
+        __ mov(rscratch1, CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_strong));
+      } else if ((_node->barrier_data() & ShenandoahBarrierWeak) != 0) {
+        __ mov(rscratch1, CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_weak));
+      } else if ((_node->barrier_data() & ShenandoahBarrierPhantom) != 0) {
+        __ mov(rscratch1, CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_phantom));
+      }
+    }
+    __ blr(rscratch1);
+    __ mov(_obj, r0);
+  }
+  if (_narrow) {
+    __ encode_heap_oop(_obj);
+  }
+  __ b(*continuation());
+}
+
+void ShenandoahSATBBarrierStubC2::emit_code(MacroAssembler& masm) {
+  Assembler::InlineSkippedInstructionsCounter skip_counter(&masm);
+  __ bind(*entry());
+  // Do we need to load the previous value?
+  if (_addr != noreg) {
+    __ load_heap_oop(_preval, Address(_addr, 0), noreg, noreg, AS_RAW);
+  }
+  // Is the previous value null?
+  __ cbz(_preval, *continuation());
+
+  Address index(rthread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_index_offset()));
+  Address buffer(rthread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset()));
+  Label runtime;
+  __ ldr(rscratch1, index);
+  // If buffer is full, call into runtime.
+  __ cbz(rscratch1, runtime);
+
+  // The buffer is not full, store value into it.
+  __ sub(rscratch1, rscratch1, wordSize);
+  __ str(rscratch1, index);
+  __ ldr(rscratch2, buffer);
+  __ str(_preval, Address(rscratch2, rscratch1));
+  __ b(*continuation());
+
+  // Runtime call
+  __ bind(runtime);
+  {
+    SaveLiveRegisters save_registers(&masm, this);
+    if (c_rarg0 != _preval) {
+      __ mov(c_rarg0, _preval);
+    }
+    __ mov(rscratch1, CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_barrier_pre_c2));
+    __ blr(rscratch1);
+  }
+  __ b(*continuation());
+}
+
+void ShenandoahCASBarrierMidStubC2::emit_code(MacroAssembler& masm) {
+  Assembler::InlineSkippedInstructionsCounter skip_counter(&masm);
+  __ bind(*entry());
+
+  // Check if CAS result is null. If it is, then we must have a legitimate failure.
+  // This makes loading the fwdptr in the slow-path simpler.
+  __ tst(_result, _result);
+  // In case of !CAE, this has the correct value for legitimate failure (0/false)
+  // in result register.
+  __ br(Assembler::EQ, *continuation());
+
+  // Check if GC is in progress, otherwise we must have a legitimate failure.
+  Address gc_state(rthread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
+  __ ldrb(_tmp, gc_state);
+  __ tstw(_tmp, ShenandoahHeap::HAS_FORWARDED);
+  __ br(Assembler::NE, *_slow_stub->entry());
+
+  if (!_cae) {
+    __ mov(_result, 0); // result = false
+  }
+  __ b(*continuation());
+}
+
+void ShenandoahCASBarrierSlowStubC2::emit_code(MacroAssembler& masm) {
+  Assembler::InlineSkippedInstructionsCounter skip_counter(&masm);
+  __ bind(*entry());
+  Assembler::operand_size size = UseCompressedOops ? Assembler::word : Assembler::xword;
+
+  // Step 2. CAS has failed because the value held at addr does not
+  // match expected.  This may be a false negative because the value fetched
+  // from addr (now held in result) may be a from-space pointer to the
+  // original copy of same object referenced by to-space pointer expected.
+  //
+  // To resolve this, it suffices to find the forward pointer associated
+  // with fetched value.  If this matches expected, retry CAS with new
+  // parameters.  If this mismatches, then we have a legitimate
+  // failure, and we're done.
+
+  // overwrite tmp with from-space pointer fetched from memory
+  __ mov(_tmp1, _result);
+
+  if (UseCompressedOops) {
+    // Decode tmp in order to resolve its forward pointer
+    __ decode_heap_oop_not_null(_tmp1, _tmp1);
+  }
+
+  // Load/decode forwarding pointer.
+  __ ldr(_tmp1, Address(_tmp1, oopDesc::mark_offset_in_bytes()));
+  // Negate the mark-word. This allows us to test lowest 2 bits easily while preserving the upper bits.
+  __ eon(_tmp1, _tmp1, zr);
+  __ ands(zr, _tmp1, markWord::lock_mask_in_place);
+  // Not forwarded, must have a legit CAS failure.
+  __ br(Assembler::NE, *continuation());
+  // Set the lowest two bits. This is equivalent to clearing the two bits after
+  // the subsequent inversion.
+  __ orr(_tmp1, _tmp1, markWord::marked_value);
+  // And invert back to get the forwardee.
+  __ eon(_tmp1, _tmp1, zr);
+
+  if (UseCompressedOops) {
+    // Encode tmp to compare against expected.
+    __ encode_heap_oop_not_null(_tmp1, _tmp1);
+  }
+
+  // Does forwarded value of fetched from-space pointer match original
+  // value of expected?  If result holds null, this comparison will fail
+  // because we know from step1 that expected is not null.  There is
+  // no need for a separate test for result (the value originally held
+  // in memory) equal to null.
+  __ cmp(_tmp1, _expected);
+
+  // If not, then the failure was legitimate and we're done.
+  // Branching to continuation with NE condition denotes failure.
+  __ br(Assembler::NE, *continuation());
+
+  // Fall through to step 3.
+
+  // Step 3.  We've confirmed that the value originally held in memory
+  // (now held in result) pointed to from-space version of original
+  // expected value.  Try the CAS again with the from-space expected
+  // value.  If it now succeeds, we're good.
+  //
+  // Note: result holds encoded from-space pointer that matches to-space
+  // object residing at expected. result is the new "expected".
+
+  // Note that macro implementation of __cmpxchg cannot use same register
+  // tmp2 for result and expected since it overwrites result before it
+  // compares result with expected.
+  __ mov(_tmp1, _result);
+  __ cmpxchg(_addr_reg, _tmp1, _new_val, size, _acquire, _release, _weak, _result);
+  // EQ flag set iff success. result holds value fetched, rscratch1 clobbered.
+
+  // If fetched value did not equal the new expected, this could
+  // still be a false negative because some other thread may have
+  // newly overwritten the memory value with its to-space equivalent.
+  __ br(Assembler::EQ, *continuation());
+
+  // Step 4. Retry CAS with original to-space expected.
+  __ cmpxchg(_addr_reg, _expected, _new_val, size, _acquire, _release, _weak, _result);
+
+  __ b(*continuation());
+}
+#undef __
+#define __ masm->
+#endif // COMPILER2
+
 void ShenandoahBarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssembler* masm, DecoratorSet decorators,
                                                                      Register start, Register count, Register scratch, RegSet saved_regs) {
   assert(ShenandoahCardBarrier, "Should have been checked by caller");
 
   Label L_loop, L_done;
diff a/src/hotspot/cpu/aarch64/gc/shenandoah/shenandoahBarrierSetAssembler_aarch64.hpp b/src/hotspot/cpu/aarch64/gc/shenandoah/shenandoahBarrierSetAssembler_aarch64.hpp
--- a/src/hotspot/cpu/aarch64/gc/shenandoah/shenandoahBarrierSetAssembler_aarch64.hpp
+++ b/src/hotspot/cpu/aarch64/gc/shenandoah/shenandoahBarrierSetAssembler_aarch64.hpp
@@ -33,13 +33,17 @@
 class LIR_Assembler;
 class ShenandoahPreBarrierStub;
 class ShenandoahLoadReferenceBarrierStub;
 class StubAssembler;
 #endif
+#ifdef COMPILER2
+class MachNode;
+#endif // COMPILER2
 class StubCodeGenerator;
 
 class ShenandoahBarrierSetAssembler: public BarrierSetAssembler {
+  friend class ShenandoahCASBarrierSlowStub;
 private:
 
   void satb_write_barrier_pre(MacroAssembler* masm,
                               Register obj,
                               Register pre_val,
@@ -86,8 +90,16 @@
                         Address dst, Register val, Register tmp1, Register tmp2, Register tmp3);
   virtual void try_resolve_jobject_in_native(MacroAssembler* masm, Register jni_env,
                                              Register obj, Register tmp, Label& slowpath);
   void cmpxchg_oop(MacroAssembler* masm, Register addr, Register expected, Register new_val,
                    bool acquire, bool release, bool is_cae, Register result);
+#ifdef COMPILER2
+
+  void load_ref_barrier_c2(const MachNode* node, MacroAssembler* masm, Register obj, Register addr, Register tmp, bool narrow, bool maybe_null);
+  void satb_barrier_c2(const MachNode* node, MacroAssembler* masm, Register obj, Register pre_val);
+  void card_barrier_c2(const MachNode* node, MacroAssembler* masm, Register addr, Register tmp);
+  void cmpxchg_oop_c2(const MachNode* node, MacroAssembler* masm, Register addr, Register expected, Register new_val, Register result,
+                      bool acquire, bool release, bool weak, bool is_cae);
+#endif
 };
 
 #endif // CPU_AARCH64_GC_SHENANDOAH_SHENANDOAHBARRIERSETASSEMBLER_AARCH64_HPP
diff a/src/hotspot/cpu/aarch64/gc/shenandoah/shenandoah_aarch64.ad b/src/hotspot/cpu/aarch64/gc/shenandoah/shenandoah_aarch64.ad
--- a/src/hotspot/cpu/aarch64/gc/shenandoah/shenandoah_aarch64.ad
+++ b/src/hotspot/cpu/aarch64/gc/shenandoah/shenandoah_aarch64.ad
@@ -20,240 +20,685 @@
 // or visit www.oracle.com if you need additional information or have any
 // questions.
 //
 //
 
-source_hpp %{
+source %{
 #include "gc/shenandoah/shenandoahBarrierSet.hpp"
-#include "gc/shenandoah/shenandoahBarrierSetAssembler.hpp"
+#include "gc/shenandoah/shenandoahBarrierSetAssembler_aarch64.hpp"
+#include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
 %}
 
-encode %{
-  enc_class aarch64_enc_cmpxchg_oop_shenandoah(memory mem, iRegP oldval, iRegP newval, iRegPNoSp tmp, iRegINoSp res) %{
-    guarantee($mem$$index == -1 && $mem$$disp == 0, "impossible encoding");
-    Register tmp = $tmp$$Register;
-    __ mov(tmp, $oldval$$Register); // Must not clobber oldval.
-    ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm, $mem$$Register, tmp, $newval$$Register,
-                                                   /*acquire*/ false, /*release*/ true, /*is_cae*/ false, $res$$Register);
+instruct storeP_shenandoah(indirect mem, iRegP src, iRegPNoSp tmp, rFlagsReg cr)
+%{
+  match(Set mem (StoreP mem src));
+  predicate(UseShenandoahGC && !needs_releasing_store(n) && n->as_Store()->barrier_data() != 0);
+  effect(TEMP tmp, KILL cr);
+  ins_cost(INSN_COST);
+  format %{ "str  $src, $mem\t# ptr" %}
+  ins_encode %{
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* pre_val */);
+    __ str($src$$Register, $mem$$Register);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
   %}
+  ins_pipe(istore_reg_mem);
+%}
 
-  enc_class aarch64_enc_cmpxchg_acq_oop_shenandoah(memory mem, iRegP oldval, iRegP newval, iRegPNoSp tmp, iRegINoSp res) %{
-    guarantee($mem$$index == -1 && $mem$$disp == 0, "impossible encoding");
-    Register tmp = $tmp$$Register;
-    __ mov(tmp, $oldval$$Register); // Must not clobber oldval.
-    ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm, $mem$$Register, tmp, $newval$$Register,
-                                                   /*acquire*/ true, /*release*/ true, /*is_cae*/ false, $res$$Register);
+instruct storePVolatile_shenandoah(indirect mem, iRegP src, iRegPNoSp tmp, rFlagsReg cr)
+%{
+  match(Set mem (StoreP mem src));
+  predicate(UseShenandoahGC && needs_releasing_store(n) && n->as_Store()->barrier_data() != 0);
+  effect(TEMP tmp, KILL cr);
+  ins_cost(VOLATILE_REF_COST);
+  format %{ "stlr  $src, $mem\t# ptr" %}
+  ins_encode %{
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                 $mem$$Register /* obj */,
+                 $tmp$$Register /* pre_val */);
+    __ stlr($src$$Register, $mem$$Register);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
+  %}
+  ins_pipe(pipe_class_memory);
+%}
+
+instruct storeN_shenandoah(indirect mem, iRegN src, iRegPNoSp tmp, rFlagsReg cr)
+%{
+  match(Set mem (StoreN mem src));
+  predicate(UseShenandoahGC && !needs_releasing_store(n) && n->as_Store()->barrier_data() != 0);
+  effect(TEMP tmp, KILL cr);
+  ins_cost(INSN_COST);
+  format %{ "strw  $src, $mem\t# compressed ptr" %}
+  ins_encode %{
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                 $mem$$Register /* obj */,
+                 $tmp$$Register /* pre_val */);
+    __ strw($src$$Register, $mem$$Register);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
+  %}
+  ins_pipe(istore_reg_mem);
+%}
+
+instruct storeNVolatile_shenandoah(indirect mem, iRegN src, iRegPNoSp tmp, rFlagsReg cr)
+%{
+  match(Set mem (StoreN mem src));
+  predicate(UseShenandoahGC && needs_releasing_store(n) && n->as_Store()->barrier_data() != 0);
+  effect(TEMP tmp, KILL cr);
+  ins_cost(VOLATILE_REF_COST);
+  format %{ "stlrw  $src, $mem\t# compressed ptr" %}
+  ins_encode %{
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                 $mem$$Register /* obj */,
+                 $tmp$$Register /* pre_val */);
+    __ stlrw($src$$Register, $mem$$Register);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
+  %}
+  ins_pipe(pipe_class_memory);
+%}
+
+instruct encodePAndStoreN_shenandoah(indirect mem, iRegP src, iRegPNoSp tmp, rFlagsReg cr)
+%{
+  match(Set mem (StoreN mem (EncodeP src)));
+  predicate(UseShenandoahGC && !needs_releasing_store(n) && n->as_Store()->barrier_data() != 0);
+  effect(TEMP tmp, KILL cr);
+  ins_cost(INSN_COST);
+  format %{ "encode_heap_oop $tmp, $src\n\t"
+            "strw  $tmp, $mem\t# compressed ptr" %}
+  ins_encode %{
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                 $mem$$Register /* obj */,
+                 $tmp$$Register /* pre_val */);
+    if ((barrier_data() & ShenandoahBarrierCardMarkNotNull) == 0) {
+      __ encode_heap_oop($tmp$$Register, $src$$Register);
+    } else {
+      __ encode_heap_oop_not_null($tmp$$Register, $src$$Register);
+    }
+    __ strw($tmp$$Register, $mem$$Register);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
+  %}
+  ins_pipe(istore_reg_mem);
+%}
+
+instruct encodePAndStoreNVolatile_shenandoah(indirect mem, iRegP src, iRegPNoSp tmp, rFlagsReg cr)
+%{
+  match(Set mem (StoreN mem (EncodeP src)));
+  predicate(UseShenandoahGC && needs_releasing_store(n) && n->as_Store()->barrier_data() != 0);
+  effect(TEMP tmp, KILL cr);
+  ins_cost(VOLATILE_REF_COST);
+  format %{ "encode_heap_oop $tmp, $src\n\t"
+            "stlrw  $tmp, $mem\t# compressed ptr" %}
+  ins_encode %{
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                 $mem$$Register /* obj */,
+                 $tmp$$Register /* pre_val */);
+    if ((barrier_data() & ShenandoahBarrierCardMarkNotNull) == 0) {
+      __ encode_heap_oop($tmp$$Register, $src$$Register);
+    } else {
+      __ encode_heap_oop_not_null($tmp$$Register, $src$$Register);
+    }
+    __ stlrw($tmp$$Register, $mem$$Register);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
   %}
+  ins_pipe(pipe_class_memory);
 %}
 
 instruct compareAndSwapP_shenandoah(iRegINoSp res, indirect mem, iRegP oldval, iRegP newval, iRegPNoSp tmp, rFlagsReg cr) %{
 
-  match(Set res (ShenandoahCompareAndSwapP mem (Binary oldval newval)));
+  match(Set res (CompareAndSwapP mem (Binary oldval newval)));
+  predicate(UseShenandoahGC && n->as_LoadStore()->barrier_data() != 0);
   ins_cost(2 * VOLATILE_REF_COST);
 
-  effect(TEMP tmp, KILL cr);
+  effect(TEMP_DEF res, TEMP tmp, KILL cr);
 
   format %{
-    "cmpxchg_shenandoah $mem, $oldval, $newval\t# (ptr) if $mem == $oldval then $mem <-- $newval with temp $tmp"
+    "cmpxchg_shenandoah $mem, $oldval, $newval\t# (ptr) if $mem == $oldval then $mem <-- $newval"
   %}
 
-  ins_encode(aarch64_enc_cmpxchg_oop_shenandoah(mem, oldval, newval, tmp, res));
+  ins_encode %{
+    guarantee($mem$$index == -1 && $mem$$disp == 0, "impossible encoding");
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                 noreg /* obj */,
+                 $oldval$$Register /* pre_val */);
+    ShenandoahBarrierSet::assembler()->cmpxchg_oop_c2(this, masm, $mem$$base$$Register, $oldval$$Register, $newval$$Register, $res$$Register,
+                                                      /*acquire*/ false, /*release*/ true, /*weak*/ false, /*is_cae*/ false);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
+  %}
 
   ins_pipe(pipe_slow);
 %}
 
-instruct compareAndSwapN_shenandoah(iRegINoSp res, indirect mem, iRegN oldval, iRegN newval, iRegNNoSp tmp, rFlagsReg cr) %{
+instruct compareAndSwapN_shenandoah(iRegINoSp res, indirect mem, iRegN oldval, iRegN newval, iRegPNoSp tmp, rFlagsReg cr) %{
 
-  match(Set res (ShenandoahCompareAndSwapN mem (Binary oldval newval)));
+  match(Set res (CompareAndSwapN mem (Binary oldval newval)));
+  predicate(UseShenandoahGC && n->as_LoadStore()->barrier_data() != 0);
   ins_cost(2 * VOLATILE_REF_COST);
 
-  effect(TEMP tmp, KILL cr);
+  effect(TEMP_DEF res, TEMP tmp, KILL cr);
 
   format %{
-    "cmpxchgw_shenandoah $mem, $oldval, $newval\t# (ptr) if $mem == $oldval then $mem <-- $newval with temp $tmp"
+    "cmpxchgw_shenandoah $mem, $oldval, $newval\t# (ptr) if $mem == $oldval then $mem <-- $newval"
   %}
 
   ins_encode %{
-    Register tmp = $tmp$$Register;
-    __ mov(tmp, $oldval$$Register); // Must not clobber oldval.
-    ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm, $mem$$Register, tmp, $newval$$Register, /*acquire*/ false, /*release*/ true, /*is_cae*/ false, $res$$Register);
+    guarantee($mem$$index == -1 && $mem$$disp == 0, "impossible encoding");
+    guarantee(UseCompressedOops, "must be compressed oops");
+    if (ShenandoahSATBBarrierStubC2::needs_barrier(this)) {
+      __ decode_heap_oop($tmp$$Register, $oldval$$Register);
+      ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                   noreg /* obj */,
+                   $tmp$$Register /* pre_val */);
+    }
+    ShenandoahBarrierSet::assembler()->cmpxchg_oop_c2(this, masm, $mem$$base$$Register, $oldval$$Register, $newval$$Register, $res$$Register,
+                                                      /*acquire*/ false, /*release*/ true, /*weak*/ false, /*is_cae*/ false);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
   %}
 
   ins_pipe(pipe_slow);
 %}
 
-instruct compareAndSwapPAcq_shenandoah(iRegINoSp res, indirect mem, iRegP oldval, iRegP newval, iRegPNoSp tmp, rFlagsReg cr) %{
+instruct compareAndSwapPAcq_shenandoah(iRegINoSp res, indirect mem, iRegP oldval, iRegP newval, iRegINoSp tmp, rFlagsReg cr) %{
 
+  match(Set res (CompareAndSwapP mem (Binary oldval newval)));
   predicate(needs_acquiring_load_exclusive(n));
-  match(Set res (ShenandoahCompareAndSwapP mem (Binary oldval newval)));
+  predicate(UseShenandoahGC && n->as_LoadStore()->barrier_data() != 0);
   ins_cost(VOLATILE_REF_COST);
 
-  effect(TEMP tmp, KILL cr);
+  effect(TEMP_DEF res, TEMP tmp, KILL cr);
 
   format %{
-    "cmpxchg_acq_shenandoah_oop $mem, $oldval, $newval\t# (ptr) if $mem == $oldval then $mem <-- $newval with temp $tmp"
+    "cmpxchg_acq_shenandoah $mem, $oldval, $newval\t# (ptr) if $mem == $oldval then $mem <-- $newval"
   %}
 
-  ins_encode(aarch64_enc_cmpxchg_acq_oop_shenandoah(mem, oldval, newval, tmp, res));
+  ins_encode %{
+    guarantee($mem$$index == -1 && $mem$$disp == 0, "impossible encoding");
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                 noreg /* obj */,
+                 $oldval$$Register /* pre_val */);
+    ShenandoahBarrierSet::assembler()->cmpxchg_oop_c2(this, masm, $mem$$base$$Register, $oldval$$Register, $newval$$Register, $res$$Register,
+                                                      /*acquire*/ true, /*release*/ true, /*weak*/ false, /*is_cae*/ false);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
+  %}
 
   ins_pipe(pipe_slow);
 %}
 
-instruct compareAndSwapNAcq_shenandoah(iRegINoSp res, indirect mem, iRegN oldval, iRegN newval, iRegNNoSp tmp, rFlagsReg cr) %{
+instruct compareAndSwapNAcq_shenandoah(iRegINoSp res, indirect mem, iRegN oldval, iRegN newval, iRegPNoSp tmp, rFlagsReg cr) %{
 
+  match(Set res (CompareAndSwapN mem (Binary oldval newval)));
   predicate(needs_acquiring_load_exclusive(n));
-  match(Set res (ShenandoahCompareAndSwapN mem (Binary oldval newval)));
+  predicate(UseShenandoahGC && n->as_LoadStore()->barrier_data() != 0);
   ins_cost(VOLATILE_REF_COST);
 
-  effect(TEMP tmp, KILL cr);
+  effect(TEMP_DEF res, TEMP tmp, KILL cr);
 
  format %{
-    "cmpxchgw_acq_shenandoah_narrow_oop $mem, $oldval, $newval\t# (ptr) if $mem == $oldval then $mem <-- $newval with temp $tmp"
+    "cmpxchgw_acq_shenandoah $mem, $oldval, $newval\t# (ptr) if $mem == $oldval then $mem <-- $newval"
  %}
 
   ins_encode %{
-    Register tmp = $tmp$$Register;
-    __ mov(tmp, $oldval$$Register); // Must not clobber oldval.
-    ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm, $mem$$Register, tmp, $newval$$Register, /*acquire*/ true, /*release*/ true, /*is_cae*/ false, $res$$Register);
+    guarantee($mem$$index == -1 && $mem$$disp == 0, "impossible encoding");
+    guarantee(UseCompressedOops, "must be compressed oops");
+    if (ShenandoahSATBBarrierStubC2::needs_barrier(this)) {
+      __ decode_heap_oop($tmp$$Register, $oldval$$Register);
+      ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                   noreg /* obj */,
+                   $tmp$$Register /* pre_val */);
+    }
+    ShenandoahBarrierSet::assembler()->cmpxchg_oop_c2(this, masm, $mem$$base$$Register, $oldval$$Register, $newval$$Register, $res$$Register,
+                                                      /*acquire*/ true, /*release*/ true, /*weak*/ false, /*is_cae*/ false);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
   %}
 
   ins_pipe(pipe_slow);
 %}
 
-instruct compareAndExchangeN_shenandoah(iRegNNoSp res, indirect mem, iRegN oldval, iRegN newval, iRegNNoSp tmp, rFlagsReg cr) %{
-  match(Set res (ShenandoahCompareAndExchangeN mem (Binary oldval newval)));
+instruct compareAndExchangeN_shenandoah(iRegNNoSp res, indirect mem, iRegN oldval, iRegN newval, iRegPNoSp tmp, rFlagsReg cr) %{
+  match(Set res (CompareAndExchangeN mem (Binary oldval newval)));
+  predicate(UseShenandoahGC && n->as_LoadStore()->barrier_data() != 0);
   ins_cost(2 * VOLATILE_REF_COST);
   effect(TEMP_DEF res, TEMP tmp, KILL cr);
   format %{
     "cmpxchgw_shenandoah $res = $mem, $oldval, $newval\t# (narrow oop, weak) if $mem == $oldval then $mem <-- $newval"
   %}
   ins_encode %{
-    Register tmp = $tmp$$Register;
-    __ mov(tmp, $oldval$$Register); // Must not clobber oldval.
-    ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm, $mem$$Register, tmp, $newval$$Register,
-                                                   /*acquire*/ false, /*release*/ true, /*is_cae*/ true, $res$$Register);
+    guarantee($mem$$index == -1 && $mem$$disp == 0, "impossible encoding");
+    guarantee(UseCompressedOops, "must be compressed oops");
+    if (ShenandoahSATBBarrierStubC2::needs_barrier(this)) {
+      __ decode_heap_oop($tmp$$Register, $oldval$$Register);
+      ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                   noreg /* obj */,
+                   $tmp$$Register /* pre_val */);
+    }
+    ShenandoahBarrierSet::assembler()->cmpxchg_oop_c2(this, masm, $mem$$base$$Register, $oldval$$Register, $newval$$Register, $res$$Register,
+                                                     /*acquire*/ false, /*release*/ true, /*weak*/ false, /*is_cae*/ true);
+    ShenandoahBarrierSet::assembler()->load_ref_barrier_c2(this, masm,
+                                                           $res$$Register /* obj */,
+                                                           $mem$$Register /* addr */,
+                                                           $tmp$$Register /* tmp */,
+                                                           true /* narrow */,
+                                                           true /* maybe_null */);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
   %}
   ins_pipe(pipe_slow);
 %}
 
 instruct compareAndExchangeP_shenandoah(iRegPNoSp res, indirect mem, iRegP oldval, iRegP newval, iRegPNoSp tmp, rFlagsReg cr) %{
-  match(Set res (ShenandoahCompareAndExchangeP mem (Binary oldval newval)));
+  match(Set res (CompareAndExchangeP mem (Binary oldval newval)));
+  predicate(UseShenandoahGC && n->as_LoadStore()->barrier_data() != 0);
   ins_cost(2 * VOLATILE_REF_COST);
   effect(TEMP_DEF res, TEMP tmp, KILL cr);
   format %{
-    "cmpxchg_shenandoah $mem, $oldval, $newval\t# (ptr) if $mem == $oldval then $mem <-- $newval with temp $tmp"
+    "cmpxchg_shenandoah $mem, $oldval, $newval\t# (ptr) if $mem == $oldval then $mem <-- $newval"
   %}
   ins_encode %{
-    Register tmp = $tmp$$Register;
-    __ mov(tmp, $oldval$$Register); // Must not clobber oldval.
-    ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm, $mem$$Register, tmp, $newval$$Register,
-                                                   /*acquire*/ false, /*release*/ true, /*is_cae*/ true, $res$$Register);
-  %}
+    guarantee($mem$$index == -1 && $mem$$disp == 0, "impossible encoding");
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                 noreg /* obj */,
+                 $oldval$$Register /* pre_val */);
+    ShenandoahBarrierSet::assembler()->cmpxchg_oop_c2(this, masm, $mem$$base$$Register, $oldval$$Register, $newval$$Register, $res$$Register,
+                                                      /*acquire*/ false, /*release*/ true, /*weak*/ false, /*is_cae*/ true);
+    ShenandoahBarrierSet::assembler()->load_ref_barrier_c2(this, masm,
+                                                           $res$$Register /* obj */,
+                                                           $mem$$Register /* addr */,
+                                                           $tmp$$Register /* tmp */,
+                                                           false /* narrow */,
+                                                           true /* maybe_null */);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
+   %}
   ins_pipe(pipe_slow);
 %}
 
-instruct compareAndExchangeNAcq_shenandoah(iRegNNoSp res, indirect mem, iRegN oldval, iRegN newval, iRegNNoSp tmp, rFlagsReg cr) %{
+instruct compareAndExchangeNAcq_shenandoah(iRegNNoSp res, indirect mem, iRegN oldval, iRegN newval, iRegPNoSp tmp, rFlagsReg cr) %{
+  match(Set res (CompareAndExchangeN mem (Binary oldval newval)));
   predicate(needs_acquiring_load_exclusive(n));
-  match(Set res (ShenandoahCompareAndExchangeN mem (Binary oldval newval)));
+  predicate(UseShenandoahGC && n->as_LoadStore()->barrier_data() != 0);
   ins_cost(VOLATILE_REF_COST);
   effect(TEMP_DEF res, TEMP tmp, KILL cr);
   format %{
     "cmpxchgw_acq_shenandoah $res = $mem, $oldval, $newval\t# (narrow oop, weak) if $mem == $oldval then $mem <-- $newval"
   %}
   ins_encode %{
-    Register tmp = $tmp$$Register;
-    __ mov(tmp, $oldval$$Register); // Must not clobber oldval.
-    ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm, $mem$$Register, tmp, $newval$$Register,
-                                                   /*acquire*/ true, /*release*/ true, /*is_cae*/ true, $res$$Register);
+    guarantee($mem$$index == -1 && $mem$$disp == 0, "impossible encoding");
+    guarantee(UseCompressedOops, "must be compressed oops");
+    if (ShenandoahSATBBarrierStubC2::needs_barrier(this)) {
+      __ decode_heap_oop($tmp$$Register, $oldval$$Register);
+      ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                   noreg /* obj */,
+                   $tmp$$Register /* pre_val */);
+    }
+    ShenandoahBarrierSet::assembler()->cmpxchg_oop_c2(this, masm, $mem$$base$$Register, $oldval$$Register, $newval$$Register, $res$$Register,
+                                                      /*acquire*/ true, /*release*/ true, /*weak*/ false, /*is_cae*/ true);
+    ShenandoahBarrierSet::assembler()->load_ref_barrier_c2(this, masm,
+                                                           $res$$Register /* obj */,
+                                                           $mem$$Register /* addr */,
+                                                           $tmp$$Register /* tmp */,
+                                                           true /* narrow */,
+                                                           true /* maybe_null */);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
   %}
   ins_pipe(pipe_slow);
 %}
 
 instruct compareAndExchangePAcq_shenandoah(iRegPNoSp res, indirect mem, iRegP oldval, iRegP newval, iRegPNoSp tmp, rFlagsReg cr) %{
+  match(Set res (CompareAndExchangeP mem (Binary oldval newval)));
   predicate(needs_acquiring_load_exclusive(n));
-  match(Set res (ShenandoahCompareAndExchangeP mem (Binary oldval newval)));
+  predicate(UseShenandoahGC && n->as_LoadStore()->barrier_data() != 0);
   ins_cost(VOLATILE_REF_COST);
   effect(TEMP_DEF res, TEMP tmp, KILL cr);
   format %{
-    "cmpxchg_acq_shenandoah $mem, $oldval, $newval\t# (ptr) if $mem == $oldval then $mem <-- $newval with temp $tmp"
+    "cmpxchg_acq_shenandoah $mem, $oldval, $newval\t# (ptr) if $mem == $oldval then $mem <-- $newval"
   %}
   ins_encode %{
-    Register tmp = $tmp$$Register;
-    __ mov(tmp, $oldval$$Register); // Must not clobber oldval.
-    ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm, $mem$$Register, tmp, $newval$$Register,
-                                                   /*acquire*/ true, /*release*/ true, /*is_cae*/ true, $res$$Register);
+    guarantee($mem$$index == -1 && $mem$$disp == 0, "impossible encoding");
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                 noreg /* obj */,
+                 $oldval$$Register /* pre_val */);
+    ShenandoahBarrierSet::assembler()->cmpxchg_oop_c2(this, masm, $mem$$base$$Register, $oldval$$Register, $newval$$Register, $res$$Register,
+                                                   /*acquire*/ true, /*release*/ true, /*weak*/ false, /*is_cae*/ true);
+    ShenandoahBarrierSet::assembler()->load_ref_barrier_c2(this, masm,
+                                                           $res$$Register /* obj */,
+                                                           $mem$$Register /* addr */,
+                                                           $tmp$$Register /* tmp */,
+                                                           false /* narrow */,
+                                                           true /* maybe_null */);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
   %}
   ins_pipe(pipe_slow);
 %}
 
-instruct weakCompareAndSwapN_shenandoah(iRegINoSp res, indirect mem, iRegN oldval, iRegN newval, iRegNNoSp tmp, rFlagsReg cr) %{
-  match(Set res (ShenandoahWeakCompareAndSwapN mem (Binary oldval newval)));
+instruct weakCompareAndSwapN_shenandoah(iRegINoSp res, indirect mem, iRegN oldval, iRegN newval, iRegPNoSp tmp, rFlagsReg cr) %{
+  match(Set res (WeakCompareAndSwapN mem (Binary oldval newval)));
+  predicate(UseShenandoahGC && n->as_LoadStore()->barrier_data() != 0);
   ins_cost(2 * VOLATILE_REF_COST);
-  effect(TEMP tmp, KILL cr);
+  effect(TEMP_DEF res, TEMP tmp, KILL cr);
   format %{
     "cmpxchgw_shenandoah $res = $mem, $oldval, $newval\t# (narrow oop, weak) if $mem == $oldval then $mem <-- $newval"
     "csetw $res, EQ\t# $res <-- (EQ ? 1 : 0)"
   %}
   ins_encode %{
-    Register tmp = $tmp$$Register;
-    __ mov(tmp, $oldval$$Register); // Must not clobber oldval.
-    // Weak is not currently supported by ShenandoahBarrierSet::cmpxchg_oop
-    ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm, $mem$$Register, tmp, $newval$$Register,
-                                                   /*acquire*/ false, /*release*/ true, /*is_cae*/ false, $res$$Register);
+    guarantee($mem$$index == -1 && $mem$$disp == 0, "impossible encoding");
+    guarantee(UseCompressedOops, "must be compressed oops");
+    if (ShenandoahSATBBarrierStubC2::needs_barrier(this)) {
+      __ decode_heap_oop($tmp$$Register, $oldval$$Register);
+      ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                   noreg /* obj */,
+                   $tmp$$Register /* pre_val */);
+    }
+    ShenandoahBarrierSet::assembler()->cmpxchg_oop_c2(this, masm, $mem$$base$$Register, $oldval$$Register, $newval$$Register, $res$$Register,
+                                                      /*acquire*/ false, /*release*/ true, /*weak*/ true, /*is_cae*/ false);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
   %}
   ins_pipe(pipe_slow);
 %}
 
-instruct weakCompareAndSwapP_shenandoah(iRegINoSp res, indirect mem, iRegP oldval, iRegP newval, iRegPNoSp tmp, rFlagsReg cr) %{
-  match(Set res (ShenandoahWeakCompareAndSwapP mem (Binary oldval newval)));
+instruct weakCompareAndSwapP_shenandoah(iRegINoSp res, indirect mem, iRegP oldval, iRegP newval, iRegINoSp tmp, rFlagsReg cr) %{
+  match(Set res (WeakCompareAndSwapP mem (Binary oldval newval)));
+  predicate(UseShenandoahGC && n->as_LoadStore()->barrier_data() != 0);
   ins_cost(2 * VOLATILE_REF_COST);
-  effect(TEMP tmp, KILL cr);
+  effect(TEMP_DEF res, TEMP tmp, KILL cr);
   format %{
     "cmpxchg_shenandoah $res = $mem, $oldval, $newval\t# (ptr, weak) if $mem == $oldval then $mem <-- $newval"
   %}
   ins_encode %{
-    Register tmp = $tmp$$Register;
-    __ mov(tmp, $oldval$$Register); // Must not clobber oldval.
-    // Weak is not currently supported by ShenandoahBarrierSet::cmpxchg_oop
-    ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm, $mem$$Register, tmp, $newval$$Register,
-                                                   /*acquire*/ false, /*release*/ true, /*is_cae*/ false, $res$$Register);
+    guarantee($mem$$index == -1 && $mem$$disp == 0, "impossible encoding");
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                 noreg /* obj */,
+                 $oldval$$Register /* pre_val */);
+    ShenandoahBarrierSet::assembler()->cmpxchg_oop_c2(this, masm, $mem$$base$$Register, $oldval$$Register, $newval$$Register, $res$$Register,
+                                                      /*acquire*/ false, /*release*/ true, /*weak*/ true, /*is_cae*/ false);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
   %}
   ins_pipe(pipe_slow);
 %}
 
-instruct weakCompareAndSwapNAcq_shenandoah(iRegINoSp res, indirect mem, iRegN oldval, iRegN newval, iRegNNoSp tmp, rFlagsReg cr) %{
+instruct weakCompareAndSwapNAcq_shenandoah(iRegINoSp res, indirect mem, iRegN oldval, iRegN newval, iRegPNoSp tmp, rFlagsReg cr) %{
+  match(Set res (WeakCompareAndSwapN mem (Binary oldval newval)));
   predicate(needs_acquiring_load_exclusive(n));
-  match(Set res (ShenandoahWeakCompareAndSwapN mem (Binary oldval newval)));
+  predicate(UseShenandoahGC && n->as_LoadStore()->barrier_data() != 0);
   ins_cost(VOLATILE_REF_COST);
-  effect(TEMP tmp, KILL cr);
+  effect(TEMP_DEF res, TEMP tmp, KILL cr);
   format %{
     "cmpxchgw_acq_shenandoah $res = $mem, $oldval, $newval\t# (narrow oop, weak) if $mem == $oldval then $mem <-- $newval"
     "csetw $res, EQ\t# $res <-- (EQ ? 1 : 0)"
   %}
   ins_encode %{
-    Register tmp = $tmp$$Register;
-    __ mov(tmp, $oldval$$Register); // Must not clobber oldval.
-    // Weak is not currently supported by ShenandoahBarrierSet::cmpxchg_oop
-    ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm, $mem$$Register, tmp, $newval$$Register,
-                                                   /*acquire*/ true, /*release*/ true, /*is_cae*/ false, $res$$Register);
+    guarantee($mem$$index == -1 && $mem$$disp == 0, "impossible encoding");
+    guarantee(UseCompressedOops, "must be compressed oops");
+    if (ShenandoahSATBBarrierStubC2::needs_barrier(this)) {
+      __ decode_heap_oop($tmp$$Register, $oldval$$Register);
+      ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                   noreg /* obj */,
+                   $tmp$$Register /* pre_val */);
+    }
+    ShenandoahBarrierSet::assembler()->cmpxchg_oop_c2(this, masm, $mem$$base$$Register, $oldval$$Register, $newval$$Register, $res$$Register,
+                                                   /*acquire*/ true, /*release*/ true, /*weak*/ true, /*is_cae*/ false);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
   %}
   ins_pipe(pipe_slow);
 %}
 
 instruct weakCompareAndSwapPAcq_shenandoah(iRegINoSp res, indirect mem, iRegP oldval, iRegP newval, iRegPNoSp tmp, rFlagsReg cr) %{
+  match(Set res (WeakCompareAndSwapP mem (Binary oldval newval)));
   predicate(needs_acquiring_load_exclusive(n));
-  match(Set res (ShenandoahWeakCompareAndSwapP mem (Binary oldval newval)));
+  predicate(UseShenandoahGC && n->as_LoadStore()->barrier_data() != 0);
   ins_cost(VOLATILE_REF_COST);
-  effect(TEMP tmp, KILL cr);
+  effect(TEMP_DEF res, TEMP tmp, KILL cr);
   format %{
     "cmpxchg_acq_shenandoah $res = $mem, $oldval, $newval\t# (ptr, weak) if $mem == $oldval then $mem <-- $newval"
     "csetw $res, EQ\t# $res <-- (EQ ? 1 : 0)"
   %}
   ins_encode %{
-    Register tmp = $tmp$$Register;
-    __ mov(tmp, $oldval$$Register); // Must not clobber oldval.
-    // Weak is not currently supported by ShenandoahBarrierSet::cmpxchg_oop
-    ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm, $mem$$Register, tmp, $newval$$Register,
-                                                   /*acquire*/ true, /*release*/ true, /*is_cae*/ false, $res$$Register);
+    guarantee($mem$$index == -1 && $mem$$disp == 0, "impossible encoding");
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                 noreg /* obj */,
+                 $oldval$$Register /* pre_val */);
+    ShenandoahBarrierSet::assembler()->cmpxchg_oop_c2(this, masm, $mem$$base$$Register, $oldval$$Register, $newval$$Register, $res$$Register,
+                                                   /*acquire*/ true, /*release*/ true, /*weak*/ true, /*is_cae*/ false);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
   %}
   ins_pipe(pipe_slow);
 %}
+
+instruct getAndSetP_shenandoah(indirect mem, iRegP newval, iRegPNoSp preval, iRegPNoSp tmp, rFlagsReg cr)
+%{
+  match(Set preval (GetAndSetP mem newval));
+  predicate(UseShenandoahGC && !needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() != 0);
+  effect(TEMP_DEF preval, TEMP tmp, KILL cr);
+  ins_cost(2 * VOLATILE_REF_COST);
+  format %{ "atomic_xchg  $preval, $newval, [$mem]" %}
+  ins_encode %{
+    assert_different_registers($mem$$Register, $newval$$Register);
+    __ atomic_xchg($preval$$Register, $newval$$Register, $mem$$Register);
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                 noreg /* obj */,
+                 $preval$$Register /* pre_val */);
+    ShenandoahBarrierSet::assembler()->load_ref_barrier_c2(this, masm,
+                                                           $preval$$Register /* obj */,
+                                                           $mem$$Register /* addr */,
+                                                           $tmp$$Register /* tmp */,
+                                                           false /* narrow */,
+                                                           true /* maybe_null */);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
+  %}
+  ins_pipe(pipe_serial);
+%}
+
+instruct getAndSetPAcq_shenandoah(indirect mem, iRegP newval, iRegPNoSp preval, iRegPNoSp tmp, rFlagsReg cr)
+%{
+  match(Set preval (GetAndSetP mem newval));
+  predicate(UseShenandoahGC && needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() != 0);
+  effect(TEMP_DEF preval, TEMP tmp, KILL cr);
+  ins_cost(VOLATILE_REF_COST);
+  format %{ "atomic_xchg_acq  $preval, $newval, [$mem]" %}
+  ins_encode %{
+    assert_different_registers($mem$$Register, $newval$$Register);
+    __ atomic_xchgal($preval$$Register, $newval$$Register, $mem$$Register);
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                 noreg /* obj */,
+                 $preval$$Register /* pre_val */);
+    ShenandoahBarrierSet::assembler()->load_ref_barrier_c2(this, masm,
+                                                           $preval$$Register /* obj */,
+                                                           $mem$$Register /* addr */,
+                                                           $tmp$$Register /* tmp */,
+                                                           false /* narrow */,
+                                                           true /* maybe_null */);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
+  %}
+  ins_pipe(pipe_serial);
+%}
+
+instruct getAndSetN_shenandoah(indirect mem, iRegN newval, iRegNNoSp preval, iRegPNoSp tmp, rFlagsReg cr)
+%{
+  match(Set preval (GetAndSetN mem newval));
+  predicate(UseShenandoahGC && !needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() != 0);
+  effect(TEMP preval, TEMP tmp, KILL cr);
+  ins_cost(2 * VOLATILE_REF_COST);
+  format %{ "atomic_xchgw $preval, $newval, [$mem]" %}
+  ins_encode %{
+    assert_different_registers($mem$$Register, $newval$$Register);
+    __ atomic_xchgw($preval$$Register, $newval$$Register, $mem$$Register);
+    if (ShenandoahSATBBarrierStubC2::needs_barrier(this)) {
+      __ decode_heap_oop($tmp$$Register, $preval$$Register);
+      ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                   noreg /* obj */,
+                   $tmp$$Register /* pre_val */);
+    }
+    ShenandoahBarrierSet::assembler()->load_ref_barrier_c2(this, masm,
+                                                           $preval$$Register /* obj */,
+                                                           $mem$$Register /* addr */,
+                                                           $tmp$$Register /* tmp */,
+                                                           true /* narrow */,
+                                                           true /* maybe_null */);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
+  %}
+  ins_pipe(pipe_serial);
+%}
+
+instruct getAndSetNAcq_shenandoah(indirect mem, iRegN newval, iRegNNoSp preval, iRegPNoSp tmp, rFlagsReg cr)
+%{
+  match(Set preval (GetAndSetN mem newval));
+  predicate(UseShenandoahGC && needs_acquiring_load_exclusive(n) && n->as_LoadStore()->barrier_data() != 0);
+  effect(TEMP preval, TEMP tmp, KILL cr);
+  ins_cost(VOLATILE_REF_COST);
+  format %{ "atomic_xchgw_acq $preval, $newval, [$mem]" %}
+  ins_encode %{
+    assert_different_registers($mem$$Register, $newval$$Register);
+    __ atomic_xchgalw($preval$$Register, $newval$$Register, $mem$$Register);
+    if (ShenandoahSATBBarrierStubC2::needs_barrier(this)) {
+      __ decode_heap_oop($tmp$$Register, $preval$$Register);
+      ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                   noreg /* obj */,
+                   $tmp$$Register /* pre_val */);
+    }
+    ShenandoahBarrierSet::assembler()->load_ref_barrier_c2(this, masm,
+                                                           $preval$$Register /* obj */,
+                                                           $mem$$Register /* addr */,
+                                                           $tmp$$Register /* tmp */,
+                                                           true /* narrow */,
+                                                           true /* maybe_null */);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp$$Register /* tmp */);
+  %}
+  ins_pipe(pipe_serial);
+%}
+
+instruct loadP_shenandoah(iRegPNoSp dst, indirect mem, rFlagsReg cr)
+%{
+  // This instruction does not need an acquiring counterpart because it is only
+  // used for reference loading (Reference::get()).
+  match(Set dst (LoadP mem));
+  predicate(UseShenandoahGC && !needs_acquiring_load(n) && n->as_Load()->barrier_data() != 0);
+  effect(TEMP_DEF dst, KILL cr);
+  ins_cost(4 * INSN_COST);
+  format %{ "ldr  $dst, $mem\t# ptr" %}
+  ins_encode %{
+    __ ldr($dst$$Register, $mem$$Register);
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                 noreg /* obj */,
+                 $dst$$Register /* pre_val */);
+    ShenandoahBarrierSet::assembler()->load_ref_barrier_c2(this, masm,
+                                                           $dst$$Register /* obj */,
+                                                           $mem$$Register /* addr */,
+                                                           noreg /* noreg - not needed */,
+                                                           false /* narrow */,
+                                                           true /* maybe_null */);
+  %}
+  ins_pipe(iload_reg_mem);
+%}
+
+instruct loadP_volatile_shenandoah(iRegPNoSp dst, indirect mem, rFlagsReg cr)
+%{
+  // This instruction does not need an acquiring counterpart because it is only
+  // used for reference loading (Reference::get()).
+  match(Set dst (LoadP mem));
+  predicate(UseShenandoahGC && needs_acquiring_load(n) && n->as_Load()->barrier_data() != 0);
+  effect(TEMP dst, KILL cr);
+  ins_cost(4 * INSN_COST);
+  format %{ "ldar  $dst, $mem\t# ptr" %}
+  ins_encode %{
+    __ ldar($dst$$Register, $mem$$Register);
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                 noreg /* obj */,
+                 $dst$$Register /* pre_val */);
+    ShenandoahBarrierSet::assembler()->load_ref_barrier_c2(this, masm,
+                                                           $dst$$Register /* obj */,
+                                                           $mem$$Register /* addr */,
+                                                           noreg /* noreg - not needed */,
+                                                           false /* narrow */,
+                                                           true /* maybe_null */);
+  %}
+  ins_pipe(iload_reg_mem);
+%}
+
+instruct loadN_shenandoah(iRegNNoSp dst, indirect mem, iRegPNoSp tmp, rFlagsReg cr) %{
+  match(Set dst (LoadN mem));
+  predicate(UseShenandoahGC && !needs_acquiring_load(n) && n->as_Load()->barrier_data() != 0);
+  effect(TEMP_DEF dst, TEMP tmp, KILL cr);
+  ins_cost(INSN_COST * 4);
+  format %{ "ldrw  $dst, $mem\t# compressed ptr" %}
+  ins_encode %{
+    __ ldrw($dst$$Register, $mem$$Register);
+    if (ShenandoahSATBBarrierStubC2::needs_barrier(this)) {
+      __ decode_heap_oop($tmp$$Register, $dst$$Register);
+      ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                                                         noreg /* obj */,
+                                                         $tmp$$Register /* pre_val */);
+    }
+    ShenandoahBarrierSet::assembler()->load_ref_barrier_c2(this, masm,
+                                                           $dst$$Register /* obj */,
+                                                           $mem$$Register /* addr */,
+                                                           $tmp$$Register /* tmp */,
+                                                           true /* narrow */,
+                                                           true /* maybe_null */);
+  %}
+  ins_pipe(ialu_reg);
+%}
+
+instruct loadN_volatile_shenandoah(iRegNNoSp dst, indirect mem, iRegPNoSp tmp, rFlagsReg cr) %{
+  predicate(UseShenandoahGC && /*needs_acquiring_load(n) && */ n->as_Load()->barrier_data() != 0);
+  match(Set dst (LoadN mem));
+  effect(TEMP_DEF dst, TEMP tmp, KILL cr);
+  ins_cost(INSN_COST * 3);
+  format %{ "ldarw  $dst, $mem\t# ptr"
+            "decode_heap_oop $dst, $dst"
+  %}
+  ins_encode %{
+    __ ldarw($dst$$Register, $mem$$Register);
+    if (ShenandoahSATBBarrierStubC2::needs_barrier(this)) {
+      __ decode_heap_oop($tmp$$Register, $dst$$Register);
+      ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                                                         noreg /* obj */,
+                                                         $tmp$$Register /* pre_val */);
+    }
+    ShenandoahBarrierSet::assembler()->load_ref_barrier_c2(this, masm,
+                                                           $dst$$Register /* obj */,
+                                                           $mem$$Register /* addr */,
+                                                           $tmp$$Register /* tmp */,
+                                                           true /* narrow */,
+                                                           true /* maybe_null */);
+  %}
+  ins_pipe(ialu_reg);
+%}
diff a/src/hotspot/cpu/x86/gc/shared/barrierSetAssembler_x86.hpp b/src/hotspot/cpu/x86/gc/shared/barrierSetAssembler_x86.hpp
--- a/src/hotspot/cpu/x86/gc/shared/barrierSetAssembler_x86.hpp
+++ b/src/hotspot/cpu/x86/gc/shared/barrierSetAssembler_x86.hpp
@@ -154,10 +154,11 @@
   void initialize(BarrierStubC2* stub);
 
 public:
   SaveLiveRegisters(MacroAssembler* masm, BarrierStubC2* stub);
   ~SaveLiveRegisters();
+  bool contains(Register r) const { return _gp_registers.contains(r); }
 };
 
 #endif // COMPILER2
 
 #endif // CPU_X86_GC_SHARED_BARRIERSETASSEMBLER_X86_HPP
diff a/src/hotspot/cpu/x86/gc/shenandoah/shenandoahBarrierSetAssembler_x86.cpp b/src/hotspot/cpu/x86/gc/shenandoah/shenandoahBarrierSetAssembler_x86.cpp
--- a/src/hotspot/cpu/x86/gc/shenandoah/shenandoahBarrierSetAssembler_x86.cpp
+++ b/src/hotspot/cpu/x86/gc/shenandoah/shenandoahBarrierSetAssembler_x86.cpp
@@ -39,10 +39,13 @@
 #ifdef COMPILER1
 #include "c1/c1_LIRAssembler.hpp"
 #include "c1/c1_MacroAssembler.hpp"
 #include "gc/shenandoah/c1/shenandoahBarrierSetC1.hpp"
 #endif
+#ifdef COMPILER2
+#include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
+#endif
 
 #define __ masm->
 
 static void save_machine_state(MacroAssembler* masm, bool handle_gpr, bool handle_fp) {
   if (handle_gpr) {
@@ -670,11 +673,15 @@
   //
   // Before reaching to resolve sequence, see if we can avoid the whole shebang
   // with filters.
 
   // Filter: when offending in-memory value is null, the failure is definitely legitimate
-  __ testptr(oldval, oldval);
+  if (UseCompressedOops) {
+    __ testl(oldval, oldval);
+  } else {
+    __ testptr(oldval, oldval);
+  }
   __ jcc(Assembler::zero, L_failure);
 
   // Filter: when heap is stable, the failure is definitely legitimate
   const Register thread = r15_thread;
   Address gc_state(thread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
@@ -772,10 +779,351 @@
     __ movptr(res, 1);
     __ bind(exit);
   }
 }
 
+#ifdef COMPILER2
+void ShenandoahBarrierSetAssembler::load_ref_barrier_c2(const MachNode* node, MacroAssembler* masm, Register obj, Register addr, Register tmp1, Register tmp2, Register tmp3, bool narrow) {
+  if (!ShenandoahLoadRefBarrierStubC2::needs_barrier(node)) {
+    return;
+  }
+  Assembler::InlineSkippedInstructionsCounter skip_counter(masm);
+
+  ShenandoahLoadRefBarrierStubC2* const stub = ShenandoahLoadRefBarrierStubC2::create(node, obj, addr, tmp1, tmp2, tmp3, narrow);
+  stub->dont_preserve(obj);
+
+  // Test for null.
+  if (narrow) {
+    __ testl(obj, obj);
+  } else {
+    __ testptr(obj, obj);
+  }
+  __ jccb(Assembler::zero, *stub->continuation());
+
+  Address gc_state(r15_thread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
+  int flags = ShenandoahHeap::HAS_FORWARDED;
+  bool is_strong = (node->barrier_data() & ShenandoahBarrierStrong) != 0;
+  if (!is_strong) {
+    flags |= ShenandoahHeap::WEAK_ROOTS;
+  }
+  __ testb(gc_state, flags);
+  __ jcc(Assembler::notZero, *stub->entry());
+  __ bind(*stub->continuation());
+}
+
+void ShenandoahBarrierSetAssembler::satb_barrier_c2(const MachNode* node, MacroAssembler* masm,
+                                                    Register addr, Register preval, Register tmp) {
+  if (!ShenandoahSATBBarrierStubC2::needs_barrier(node)) {
+    return;
+  }
+  ShenandoahSATBBarrierStubC2* const stub = ShenandoahSATBBarrierStubC2::create(node, addr, preval, tmp);
+  Assembler::InlineSkippedInstructionsCounter skip_counter(masm);
+  Address gc_state(r15_thread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
+  __ testb(gc_state, ShenandoahHeap::MARKING);
+  __ jcc(Assembler::notZero, *stub->entry());
+  __ bind(*stub->continuation());
+}
+
+void ShenandoahBarrierSetAssembler::card_barrier_c2(const MachNode* node, MacroAssembler* masm,
+                                                    Register addr, Register addr_tmp, Register tmp) {
+  if (!ShenandoahCardBarrier ||
+      (node->barrier_data() & (ShenandoahBarrierCardMark | ShenandoahBarrierCardMarkNotNull)) == 0) {
+    return;
+  }
+  Assembler::InlineSkippedInstructionsCounter skip_counter(masm);
+  if (addr != noreg) {
+    __ mov(addr_tmp, addr);
+  }
+  __ shrptr(addr_tmp, CardTable::card_shift());
+
+  Address curr_ct_holder_addr(r15_thread, in_bytes(ShenandoahThreadLocalData::card_table_offset()));
+  __ movptr(tmp, curr_ct_holder_addr);
+  Address card_addr(tmp, addr_tmp, Address::times_1);
+
+  int dirty = CardTable::dirty_card_val();
+  if (UseCondCardMark) {
+    Label L_already_dirty;
+    __ cmpb(card_addr, dirty);
+    __ jccb(Assembler::equal, L_already_dirty);
+    __ movb(card_addr, dirty);
+    __ bind(L_already_dirty);
+  } else {
+    __ movb(card_addr, dirty);
+  }
+}
+
+void ShenandoahBarrierSetAssembler::cmpxchg_oop_c2(const MachNode* node, MacroAssembler* masm,
+                                                Register res, Address addr, Register oldval, Register newval, Register tmp1, Register tmp2,
+                                                bool exchange) {
+  assert(oldval == rax, "must be in rax for implicit use in cmpxchg");
+  assert_different_registers(oldval, tmp1, tmp2);
+  assert_different_registers(newval, tmp1, tmp2);
+
+  ShenandoahCASBarrierSlowStubC2* const slow_stub = ShenandoahCASBarrierSlowStubC2::create(node, addr, oldval, newval, res, tmp1, tmp2, exchange);
+  ShenandoahCASBarrierMidStubC2* const mid_stub = ShenandoahCASBarrierMidStubC2::create(node, slow_stub, oldval, res, tmp1, exchange);
+
+  Label L_success, L_failure;
+
+  // Remember oldval for retry logic below. It will be overwritten by the CAS.
+  if (ShenandoahCASBarrier) {
+    __ movptr(tmp2, oldval);
+  }
+
+  // Step 1. Fast-path.
+  //
+  // Try to CAS with given arguments. If successful, then we are done.
+  __ lock();
+  if (UseCompressedOops) {
+    __ cmpxchgl(newval, addr);
+  } else {
+    __ cmpxchgptr(newval, addr);
+  }
+
+  if (!ShenandoahCASBarrier) {
+    if (!exchange) {
+      assert(res != noreg, "need result register");
+      __ setcc(Assembler::equal, res);
+    }
+    return;
+  }
+
+  __ jcc(Assembler::notEqual, *mid_stub->entry());
+
+  // Slow-stub re-enters with condition flags according to CAS, we may need to
+  // set result accordingly.
+  __ bind(*slow_stub->continuation());
+
+  // Step 5. If we need a boolean result out of CAS, set the flag appropriately.
+  // and promote the result. Note that we handle the flag from both the 1st and 2nd CAS.
+  // Otherwise, failure witness for CAE is in oldval on all paths, and we can return.
+
+  if (!exchange) {
+    assert(res != noreg, "need result register");
+    __ setcc(Assembler::equal, res);
+  }
+
+  // Mid-stub re-enters with result set correctly.
+  __ bind(*mid_stub->continuation());
+}
+
+#undef __
+#define __ masm.
+
+void ShenandoahLoadRefBarrierStubC2::emit_code(MacroAssembler& masm) {
+  Assembler::InlineSkippedInstructionsCounter skip_counter(&masm);
+  __ bind(*entry());
+
+  Register obj = _obj;
+  if (_narrow) {
+    __ movl(_tmp1, _obj);
+    __ decode_heap_oop(_tmp1);
+    obj = _tmp1;
+  }
+
+  // Weak/phantom loads always need to go to runtime.
+  if ((_node->barrier_data() & ShenandoahBarrierStrong) != 0) {
+    __ movptr(_tmp2, obj);
+    __ shrptr(_tmp2, ShenandoahHeapRegion::region_size_bytes_shift_jint());
+    __ movptr(_tmp3, (intptr_t) ShenandoahHeap::in_cset_fast_test_addr());
+    __ movbool(_tmp2, Address(_tmp2, _tmp3, Address::times_1));
+    __ testbool(_tmp2);
+    __ jcc(Assembler::zero, *continuation());
+  }
+
+  {
+    SaveLiveRegisters save_registers(&masm, this);
+    if (c_rarg0 != obj) {
+      if (c_rarg0 == _addr) {
+        __ movptr(_tmp2, _addr);
+        _addr = _tmp2;
+      }
+      __ movptr(c_rarg0, obj);
+    }
+    __ movptr(c_rarg1, _addr);
+
+    address entry;
+    if (_narrow) {
+      if ((_node->barrier_data() & ShenandoahBarrierStrong) != 0) {
+        entry = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_strong_narrow);
+      } else if ((_node->barrier_data() & ShenandoahBarrierWeak) != 0) {
+        entry = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_weak_narrow);
+      } else if ((_node->barrier_data() & ShenandoahBarrierPhantom) != 0) {
+        entry = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_phantom_narrow);
+      }
+    } else {
+      if ((_node->barrier_data() & ShenandoahBarrierStrong) != 0) {
+        entry = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_strong);
+      } else if ((_node->barrier_data() & ShenandoahBarrierWeak) != 0) {
+        entry = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_weak);
+      } else if ((_node->barrier_data() & ShenandoahBarrierPhantom) != 0) {
+        entry = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_phantom);
+      }
+    }
+    __ call(RuntimeAddress(entry), rax);
+    assert(!save_registers.contains(_obj), "must not save result register");
+    __ movptr(_obj, rax);
+  }
+  if (_narrow) {
+    __ encode_heap_oop(_obj);
+  }
+
+  __ jmp(*continuation());
+}
+
+void ShenandoahSATBBarrierStubC2::emit_code(MacroAssembler& masm) {
+  __ bind(*entry());
+  Address index(r15_thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_index_offset()));
+  Address buffer(r15_thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset()));
+
+  Label runtime;
+
+  // Do we need to load the previous value?
+  if (_addr != noreg) {
+    __ load_heap_oop(_preval, Address(_addr, 0), noreg, AS_RAW);
+  }
+  // Is the previous value null?
+  __ cmpptr(_preval, NULL_WORD);
+  __ jcc(Assembler::equal, *continuation());
+
+  // Can we store a value in the given thread's buffer?
+  // (The index field is typed as size_t.)
+  __ movptr(_tmp, index);
+  __ testptr(_tmp, _tmp);
+  __ jccb(Assembler::zero, runtime);
+  // The buffer is not full, store value into it.
+  __ subptr(_tmp, wordSize);
+  __ movptr(index, _tmp);
+  __ addptr(_tmp, buffer);
+  __ movptr(Address(_tmp, 0), _preval);
+
+  __ jmp(*continuation());
+
+  __ bind(runtime);
+  {
+    SaveLiveRegisters save_registers(&masm, this);
+    if (c_rarg0 != _preval) {
+      __ mov(c_rarg0, _preval);
+    }
+    // rax is a caller-saved, non-argument-passing register, so it does not
+    // interfere with c_rarg0 or c_rarg1. If it contained any live value before
+    // entering this stub, it is saved at this point, and restored after the
+    // call. If it did not contain any live value, it is free to be used. In
+    // either case, it is safe to use it here as a call scratch register.
+    __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_barrier_pre_c2)), rax);
+  }
+  __ jmp(*continuation());
+}
+
+void ShenandoahCASBarrierMidStubC2::emit_code(MacroAssembler& masm) {
+  __ bind(*entry());
+
+  if (!_cae) {
+    // Set result to false, in case that we fail the following tests.
+    // Failing those tests means legitimate failures.
+    // Otherwise, result will be set correctly after returning from
+    // the slow-path.
+    __ movl(_result, 0); // Result = false.
+  }
+  // Check if CAS result is null. If it is, then we must have a legitimate failure.
+  // This makes loading the fwdptr in the slow-path simpler.
+  if (UseCompressedOops) {
+    __ testl(_expected, _expected);
+  } else {
+    __ testptr(_expected, _expected);
+  }
+  __ jcc(Assembler::equal, *continuation());
+
+  // Check if GC is in progress, otherwise we must have a legitimate failure.
+  Address gc_state(r15_thread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
+  __ testb(gc_state, ShenandoahHeap::HAS_FORWARDED);
+  __ jcc(Assembler::notZero, *_slow_stub->entry());
+  __ jmp(*continuation());
+}
+
+void ShenandoahCASBarrierSlowStubC2::emit_code(MacroAssembler& masm) {
+  __ bind(*entry());
+
+  assert(_expected == rax, "expected must be rax");
+
+  // Step 2. CAS has failed because the value held at addr does not
+  // match expected.  This may be a false negative because the value fetched
+  // from addr (now held in result) may be a from-space pointer to the
+  // original copy of same object referenced by to-space pointer expected.
+  //
+  // To resolve this, it suffices to find the forward pointer associated
+  // with fetched value.  If this matches expected, retry CAS with new
+  // parameters.  If this mismatches, then we have a legitimate
+  // failure, and we're done.
+
+  // overwrite tmp1 with from-space pointer fetched from memory
+  __ movptr(_tmp1, _expected);
+
+  if (UseCompressedOops) {
+    __ decode_heap_oop_not_null(_tmp1);
+  }
+
+  // Load/decode forwarding pointer.
+  __ movq(_tmp1, Address(_tmp1, oopDesc::mark_offset_in_bytes()));
+  // Negate the mark-word. This allows us to test lowest 2 bits easily while preserving the upper bits.
+  __ negq(_tmp1);
+  __ testq(_tmp1, markWord::lock_mask_in_place);
+  // Not forwarded, must have a legit CAS failure.
+  __ jcc(Assembler::notEqual, *continuation());
+  // Set the lowest two bits. This is equivalent to clearing the two bits after
+  // the subsequent inversion.
+  __ orq(_tmp1, markWord::marked_value);
+  // And invert back to get the forwardee.
+  __ negq(_tmp1);
+
+  if (UseCompressedOops) {
+    __ encode_heap_oop_not_null(_tmp1); // encode for comparison
+  }
+
+  // Now we have the forwarded offender in tmp1.
+  // We preserved the original expected value in tmp2 in the fast-path.
+  // Compare and if they don't match, we have legitimate failure
+  __ cmpptr(_tmp1, _tmp2);
+  __ jcc(Assembler::notEqual, *continuation());
+
+  // Fall through to step 3.
+
+  // Step 3.  We've confirmed that the value originally held in memory
+  // (now held in result) pointed to from-space version of original
+  // expected value.  Try the CAS again with the from-space expected
+  // value.  If it now succeeds, we're good.
+  //
+  // Note: expected holds encoded from-space pointer that matches to-space
+  // object residing at tmp1.
+  __ lock();
+  if (UseCompressedOops) {
+    __ cmpxchgl(_new_val, _addr);
+  } else {
+    __ cmpxchgptr(_new_val, _addr);
+  }
+
+  // If fetched value did not equal the new expected, this could
+  // still be a false negative because some other (GC) thread may have
+  // newly overwritten the memory value with its to-space equivalent.
+  __ jcc(Assembler::equal, *continuation());
+
+  // Step 4. Try to CAS again, but with the original to-space expected.
+  // This should be very rare.
+  __ movptr(_expected, _tmp2);
+  __ lock();
+  if (UseCompressedOops) {
+    __ cmpxchgl(_new_val, _addr);
+  } else {
+    __ cmpxchgptr(_new_val, _addr);
+  }
+  // At this point, there can no longer be false negatives.
+  __ jmp(*continuation());
+}
+
+#undef __
+#define __ masm->
+#endif
+
 #ifdef PRODUCT
 #define BLOCK_COMMENT(str) /* nothing */
 #else
 #define BLOCK_COMMENT(str) __ block_comment(str)
 #endif
diff a/src/hotspot/cpu/x86/gc/shenandoah/shenandoahBarrierSetAssembler_x86.hpp b/src/hotspot/cpu/x86/gc/shenandoah/shenandoahBarrierSetAssembler_x86.hpp
--- a/src/hotspot/cpu/x86/gc/shenandoah/shenandoahBarrierSetAssembler_x86.hpp
+++ b/src/hotspot/cpu/x86/gc/shenandoah/shenandoahBarrierSetAssembler_x86.hpp
@@ -34,10 +34,13 @@
 class LIR_Assembler;
 class ShenandoahPreBarrierStub;
 class ShenandoahLoadReferenceBarrierStub;
 class StubAssembler;
 #endif
+#ifdef COMPILER2
+class MachNode;
+#endif
 class StubCodeGenerator;
 
 class ShenandoahBarrierSetAssembler: public BarrierSetAssembler {
 private:
 
@@ -72,10 +75,20 @@
   void load_reference_barrier(MacroAssembler* masm, Register dst, Address src, DecoratorSet decorators);
 
   void cmpxchg_oop(MacroAssembler* masm,
                    Register res, Address addr, Register oldval, Register newval,
                    bool exchange, Register tmp1, Register tmp2);
+#ifdef COMPILER2
+  void load_ref_barrier_c2(const MachNode* node, MacroAssembler* masm, Register obj, Register addr, Register tmp1, Register tmp2, Register tmp3, bool narrow);
+  void satb_barrier_c2(const MachNode* node, MacroAssembler* masm,
+                       Register addr, Register preval, Register tmp);
+  void card_barrier_c2(const MachNode* node, MacroAssembler* masm,
+                       Register addr, Register addr_tmp, Register tmp);
+  void cmpxchg_oop_c2(const MachNode* node, MacroAssembler* masm,
+                      Register res, Address addr, Register oldval, Register newval, Register tmp1, Register tmp2,
+                      bool exchange);
+#endif
   virtual void arraycopy_prologue(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
                                   Register src, Register dst, Register count);
   virtual void arraycopy_epilogue(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
                                   Register src, Register dst, Register count);
   virtual void load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
diff a/src/hotspot/cpu/x86/gc/shenandoah/shenandoah_x86_64.ad b/src/hotspot/cpu/x86/gc/shenandoah/shenandoah_x86_64.ad
--- a/src/hotspot/cpu/x86/gc/shenandoah/shenandoah_x86_64.ad
+++ b/src/hotspot/cpu/x86/gc/shenandoah/shenandoah_x86_64.ad
@@ -20,92 +20,331 @@
 // or visit www.oracle.com if you need additional information or have any
 // questions.
 //
 //
 
-source_hpp %{
-#include "gc/shenandoah/shenandoahBarrierSetAssembler.hpp"
-#include "gc/shenandoah/c2/shenandoahSupport.hpp"
+source %{
+#include "gc/shenandoah/shenandoahBarrierSet.hpp"
+#include "gc/shenandoah/shenandoahBarrierSetAssembler_x86.hpp"
+#include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
+%}
+
+instruct storeP_shenandoah(memory mem, any_RegP src, rRegP tmp1, rRegP tmp2, rRegP tmp3, rFlagsReg cr)
+%{
+  match(Set mem (StoreP mem src));
+  predicate(UseShenandoahGC && n->as_Store()->barrier_data() != 0);
+  effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr);
+  ins_cost(125); // XXX
+  format %{ "movq    $mem, $src\t# ptr" %}
+  ins_encode %{
+    __ lea($tmp1$$Register, $mem$$Address);
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                                                       $tmp1$$Register /* addr */,
+                                                       $tmp2$$Register /* pre_val */,
+                                                       $tmp3$$Register /* tmp */);
+    __ movq(Address($tmp1$$Register, 0), $src$$Register);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       noreg /* addr */,
+                                                       $tmp1$$Register /* addr_tmp */,
+                                                       $tmp2$$Register /* tmp */);
+  %}
+  ins_pipe(ialu_mem_reg);
+%}
+
+instruct storeN_shenandoah(memory mem, rRegN src, rRegP tmp1, rRegP tmp2, rRegP tmp3, rFlagsReg cr)
+%{
+  match(Set mem (StoreN mem src));
+  predicate(UseShenandoahGC && n->as_Store()->barrier_data() != 0);
+  effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr);
+  ins_cost(125); // XXX
+  format %{ "movl    $mem, $src\t# ptr" %}
+  ins_encode %{
+    __ lea($tmp1$$Register, $mem$$Address);
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                                                       $tmp1$$Register /* addr */,
+                                                       $tmp2$$Register /* pre_val */,
+                                                       $tmp3$$Register /* tmp */);
+    __ movl(Address($tmp1$$Register, 0), $src$$Register);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       noreg /* addr */,
+                                                       $tmp1$$Register /* addr_tmp */,
+                                                       $tmp2$$Register /* tmp */);
+  %}
+  ins_pipe(ialu_mem_reg);
+%}
+
+instruct encodePAndStoreN_shenandoah(memory mem, any_RegP src, rRegP tmp1, rRegP tmp2, rRegP tmp3, rFlagsReg cr)
+%{
+  match(Set mem (StoreN mem (EncodeP src)));
+  predicate(UseShenandoahGC && n->as_Store()->barrier_data() != 0);
+  effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr);
+  ins_cost(125); // XXX
+  format %{ "encode_heap_oop $src\n\t"
+            "movl   $mem, $src\t# ptr" %}
+  ins_encode %{
+    __ lea($tmp1$$Register, $mem$$Address);
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                                                       $tmp1$$Register /* addr */,
+                                                       $tmp2$$Register /* pre_val */,
+                                                       $tmp3$$Register /* tmp */);
+    __ movq($tmp3$$Register, $src$$Register);
+    if ((barrier_data() & ShenandoahBarrierCardMarkNotNull) == 0) {
+      __ encode_heap_oop($tmp3$$Register);
+    } else {
+      __ encode_heap_oop_not_null($tmp3$$Register);
+    }
+    __ movl(Address($tmp1$$Register, 0), $tmp3$$Register);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       noreg /* addr */,
+                                                       $tmp1$$Register /* addr_tmp */,
+                                                       $tmp2$$Register /* tmp */);
+  %}
+  ins_pipe(ialu_mem_reg);
 %}
 
 instruct compareAndSwapP_shenandoah(rRegI res,
-                                    memory mem_ptr,
+                                    indirect mem,
                                     rRegP tmp1, rRegP tmp2,
                                     rax_RegP oldval, rRegP newval,
                                     rFlagsReg cr)
 %{
-  match(Set res (ShenandoahCompareAndSwapP mem_ptr (Binary oldval newval)));
-  match(Set res (ShenandoahWeakCompareAndSwapP mem_ptr (Binary oldval newval)));
-  effect(TEMP tmp1, TEMP tmp2, KILL cr, KILL oldval);
+  match(Set res (CompareAndSwapP mem (Binary oldval newval)));
+  match(Set res (WeakCompareAndSwapP mem (Binary oldval newval)));
+  predicate(UseShenandoahGC && n->as_LoadStore()->barrier_data() != 0);
+  effect(TEMP_DEF res, TEMP tmp1, TEMP tmp2, KILL cr, KILL oldval);
 
-  format %{ "shenandoah_cas_oop $mem_ptr,$newval" %}
+  format %{ "shenandoah_cas_oop $mem,$newval" %}
 
   ins_encode %{
-    ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm,
-                                                   $res$$Register, $mem_ptr$$Address, $oldval$$Register, $newval$$Register,
-                                                   false, // swap
-                                                   $tmp1$$Register, $tmp2$$Register
-                                                   );
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                                                       noreg /* addr */,
+                                                       $oldval$$Register /* pre_val */,
+                                                       $tmp2$$Register /* tmp */);
+    ShenandoahBarrierSet::assembler()->cmpxchg_oop_c2(this, masm,
+                                                      $res$$Register, $mem$$Address, $oldval$$Register, $newval$$Register, $tmp1$$Register, $tmp2$$Register,
+                                                      /*exchange*/ false);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp1$$Register /* addr_tmp */,
+                                                       $tmp2$$Register /* tmp */);
   %}
   ins_pipe( pipe_cmpxchg );
 %}
 
 instruct compareAndSwapN_shenandoah(rRegI res,
-                                    memory mem_ptr,
+                                    indirect mem,
                                     rRegP tmp1, rRegP tmp2,
                                     rax_RegN oldval, rRegN newval,
                                     rFlagsReg cr) %{
-  match(Set res (ShenandoahCompareAndSwapN mem_ptr (Binary oldval newval)));
-  match(Set res (ShenandoahWeakCompareAndSwapN mem_ptr (Binary oldval newval)));
-  effect(TEMP tmp1, TEMP tmp2, KILL cr, KILL oldval);
+  match(Set res (CompareAndSwapN mem (Binary oldval newval)));
+  match(Set res (WeakCompareAndSwapN mem (Binary oldval newval)));
+  predicate(UseShenandoahGC && n->as_LoadStore()->barrier_data() != 0);
+  effect(TEMP_DEF res, TEMP tmp1, TEMP tmp2, KILL cr, KILL oldval);
 
-  format %{ "shenandoah_cas_oop $mem_ptr,$newval" %}
+  format %{ "shenandoah_cas_oop $mem,$newval" %}
 
   ins_encode %{
-    ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm,
-                                                   $res$$Register, $mem_ptr$$Address, $oldval$$Register, $newval$$Register,
-                                                   false, // swap
-                                                   $tmp1$$Register, $tmp2$$Register
-                                                   );
+    guarantee(UseCompressedOops, "must be compressed oops");
+    if (ShenandoahSATBBarrierStubC2::needs_barrier(this)) {
+      __ movl($tmp1$$Register, $oldval$$Register);
+      __ decode_heap_oop($tmp1$$Register);
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                                                       noreg /* addr */,
+                                                       $tmp1$$Register /* pre_val */,
+                                                       $tmp2$$Register /* tmp */);
+    }
+    ShenandoahBarrierSet::assembler()->cmpxchg_oop_c2(this, masm,
+                                                      $res$$Register, $mem$$Address, $oldval$$Register, $newval$$Register, $tmp1$$Register, $tmp2$$Register,
+                                                      /*exchange*/ false);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp1$$Register /* addr_tmp */,
+                                                       $tmp2$$Register /* tmp */);
   %}
   ins_pipe( pipe_cmpxchg );
 %}
 
-instruct compareAndExchangeN_shenandoah(memory mem_ptr,
+instruct compareAndExchangeN_shenandoah(indirect mem,
                                         rax_RegN oldval, rRegN newval,
-                                        rRegP tmp1, rRegP tmp2,
+                                        rRegP tmp1, rRegP tmp2, rRegP tmp3,
                                         rFlagsReg cr) %{
-  match(Set oldval (ShenandoahCompareAndExchangeN mem_ptr (Binary oldval newval)));
-  effect(TEMP tmp1, TEMP tmp2, KILL cr);
+  match(Set oldval (CompareAndExchangeN mem (Binary oldval newval)));
+  predicate(UseShenandoahGC && n->as_LoadStore()->barrier_data() != 0);
+  effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr);
 
-  format %{ "shenandoah_cas_oop $mem_ptr,$newval" %}
+  format %{ "shenandoah_cas_oop $mem,$newval" %}
 
   ins_encode %{
-    ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm,
-                                                   noreg, $mem_ptr$$Address, $oldval$$Register, $newval$$Register,
-                                                   true, // exchange
-                                                   $tmp1$$Register, $tmp2$$Register
-                                                   );
+    guarantee(UseCompressedOops, "must be compressed oops");
+    if (ShenandoahSATBBarrierStubC2::needs_barrier(this)) {
+      __ movl($tmp1$$Register, $oldval$$Register);
+      __ decode_heap_oop($tmp1$$Register);
+      ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                                                         noreg /* addr */,
+                                                         $tmp1$$Register /* pre_val */,
+                                                         $tmp2$$Register /* tmp */);
+    }
+    ShenandoahBarrierSet::assembler()->cmpxchg_oop_c2(this, masm,
+                                                      noreg, $mem$$Address, $oldval$$Register, $newval$$Register, $tmp1$$Register, $tmp2$$Register,
+                                                      /*exchange*/ true);
+    ShenandoahBarrierSet::assembler()->load_ref_barrier_c2(this, masm,
+                                                           $oldval$$Register /* obj */,
+                                                           $mem$$Register /* addr */,
+                                                           $tmp1$$Register /* tmp1 */,
+                                                           $tmp2$$Register /* tmp2 */,
+                                                           $tmp3$$Register /* tmp3 */,
+                                                           true /* narrow */);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp1$$Register /* addr_tmp */,
+                                                       $tmp2$$Register /* tmp */);
   %}
   ins_pipe( pipe_cmpxchg );
 %}
 
-instruct compareAndExchangeP_shenandoah(memory mem_ptr,
+instruct compareAndExchangeP_shenandoah(indirect mem,
                                         rax_RegP oldval, rRegP newval,
                                         rRegP tmp1, rRegP tmp2,
                                         rFlagsReg cr)
 %{
-  match(Set oldval (ShenandoahCompareAndExchangeP mem_ptr (Binary oldval newval)));
+  match(Set oldval (CompareAndExchangeP mem (Binary oldval newval)));
+  predicate(UseShenandoahGC && n->as_LoadStore()->barrier_data() != 0);
   effect(KILL cr, TEMP tmp1, TEMP tmp2);
   ins_cost(1000);
 
-  format %{ "shenandoah_cas_oop $mem_ptr,$newval" %}
+  format %{ "shenandoah_cas_oop $mem,$newval" %}
 
   ins_encode %{
-    ShenandoahBarrierSet::assembler()->cmpxchg_oop(masm,
-                                                   noreg, $mem_ptr$$Address, $oldval$$Register, $newval$$Register,
-                                                   true,  // exchange
-                                                   $tmp1$$Register, $tmp2$$Register
-                                                   );
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                                                       noreg /* addr */,
+                                                       $oldval$$Register /* pre_val */,
+                                                       $tmp2$$Register /* tmp */);
+    ShenandoahBarrierSet::assembler()->cmpxchg_oop_c2(this, masm,
+                                                      noreg, $mem$$Address, $oldval$$Register, $newval$$Register, $tmp1$$Register, $tmp2$$Register,
+                                                      /*exchange*/ true);
+    ShenandoahBarrierSet::assembler()->load_ref_barrier_c2(this, masm,
+                                                           $oldval$$Register /* obj */,
+                                                           $mem$$Register /* addr */,
+                                                           noreg /* tmp1 */,
+                                                           $tmp1$$Register /* tmp2 */,
+                                                           $tmp2$$Register /* tmp3 */,
+                                                           false /* narrow */);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp1$$Register /* addr_tmp */,
+                                                       $tmp2$$Register /* tmp */);
   %}
   ins_pipe( pipe_cmpxchg );
 %}
+
+instruct getAndSetP_shenandoah(indirect mem, rRegP newval, rRegP tmp1, rRegP tmp2, rFlagsReg cr)
+%{
+  match(Set newval (GetAndSetP mem newval));
+  predicate(UseShenandoahGC && n->as_LoadStore()->barrier_data() != 0);
+  effect(TEMP tmp1, TEMP tmp2, KILL cr);
+  format %{ "xchgq    $newval, $mem" %}
+  ins_encode %{
+    assert_different_registers($mem$$Register, $newval$$Register);
+    __ xchgq($newval$$Register, Address($mem$$Register, 0));
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                                                       noreg /* addr */,
+                                                       $newval$$Register /* pre_val */,
+                                                       $tmp1$$Register /* tmp */);
+    ShenandoahBarrierSet::assembler()->load_ref_barrier_c2(this, masm,
+                                                           $newval$$Register /* obj */,
+                                                           $mem$$Register /* addr */,
+                                                           noreg /* tmp1 */,
+                                                           $tmp1$$Register /* tmp2 */,
+                                                           $tmp2$$Register /* tmp3 */,
+                                                           false /* narrow */);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp1$$Register /* addr_tmp */,
+                                                       $tmp2$$Register /* tmp */);
+  %}
+  ins_pipe(pipe_cmpxchg);
+%}
+
+instruct getAndSetN_shenandoah(indirect mem, rRegN newval, rRegP tmp1, rRegP tmp2, rRegP tmp3, rFlagsReg cr)
+%{
+  match(Set newval (GetAndSetN mem newval));
+  predicate(UseShenandoahGC && n->as_LoadStore()->barrier_data() != 0);
+  effect(TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr);
+  format %{ "xchgq    $newval, $mem" %}
+  ins_encode %{
+    assert_different_registers($mem$$Register, $newval$$Register);
+    __ xchgl($newval$$Register, Address($mem$$Register, 0));
+    if (ShenandoahSATBBarrierStubC2::needs_barrier(this)) {
+      __ movl($tmp1$$Register, $newval$$Register);
+      __ decode_heap_oop($tmp1$$Register);
+      ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                                                         noreg /* addr */,
+                                                         $tmp1$$Register /* pre_val */,
+                                                         $tmp2$$Register /* tmp */);
+    }
+    ShenandoahBarrierSet::assembler()->load_ref_barrier_c2(this, masm,
+                                                           $newval$$Register /* obj */,
+                                                           $mem$$Register /* addr */,
+                                                           $tmp1$$Register /* tmp1 */,
+                                                           $tmp2$$Register /* tmp2 */,
+                                                           $tmp3$$Register /* tmp3 */,
+                                                           true /* narrow */);
+    ShenandoahBarrierSet::assembler()->card_barrier_c2(this, masm,
+                                                       $mem$$Register /* addr */,
+                                                       $tmp1$$Register /* addr_tmp */,
+                                                       $tmp2$$Register /* tmp */);
+  %}
+  ins_pipe(pipe_cmpxchg);
+%}
+
+instruct loadP_shenandaoh(rRegP dst, memory mem, rRegP tmp1, rRegP tmp2, rRegP tmp3, rFlagsReg cr)
+%{
+  match(Set dst (LoadP mem));
+  predicate(UseShenandoahGC && n->as_Load()->barrier_data() != 0);
+  effect(TEMP_DEF dst, TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr);
+  ins_cost(125); // XXX
+  format %{ "movq    $dst, $mem\t# ptr" %}
+  ins_encode %{
+    __ movq($dst$$Register, $mem$$Address);
+    ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                                                       noreg /* addr */,
+                                                       $dst$$Register /* pre_val */,
+                                                       $tmp1$$Register /* tmp */);
+    __ lea($tmp3$$Register, $mem$$Address);
+    ShenandoahBarrierSet::assembler()->load_ref_barrier_c2(this, masm,
+                                                           $dst$$Register /* obj */,
+                                                           $tmp3$$Register /* addr */,
+                                                           noreg /* tmp1 */,
+                                                           $tmp1$$Register /* tmp2 */,
+                                                           $tmp2$$Register /* tmp3 */,
+                                                           false /* narrow */);
+  %}
+  ins_pipe(ialu_reg_mem); // XXX
+%}
+
+instruct loadN_shenandoah(rRegN dst, indirect mem, rRegP tmp1, rRegP tmp2, rRegP tmp3, rFlagsReg cr)
+%{
+  match(Set dst (LoadN mem));
+  predicate(UseShenandoahGC && n->as_Load()->barrier_data() != 0);
+  effect(TEMP_DEF dst, TEMP tmp1, TEMP tmp2, TEMP tmp3, KILL cr);
+  ins_cost(125); // XXX
+  format %{ "movl    $dst, $mem\t# compressed ptr" %}
+  ins_encode %{
+    __ movl($dst$$Register, $mem$$Address);
+    if (ShenandoahSATBBarrierStubC2::needs_barrier(this)) {
+      __ movl($tmp1$$Register, $dst$$Register);
+      __ decode_heap_oop($tmp1$$Register);
+      ShenandoahBarrierSet::assembler()->satb_barrier_c2(this, masm,
+                                                         noreg /* addr */,
+                                                         $tmp1$$Register /* pre_val */,
+                                                         $tmp2$$Register /* tmp */);
+    }
+    ShenandoahBarrierSet::assembler()->load_ref_barrier_c2(this, masm,
+                                                           $dst$$Register /* obj */,
+                                                           $mem$$Register /* addr */,
+                                                           $tmp1$$Register /* tmp1 */,
+                                                           $tmp2$$Register /* tmp2 */,
+                                                           $tmp3$$Register /* tmp3 */,
+                                                           true /* narrow */);
+  %}
+  ins_pipe(ialu_reg_mem); // XXX
+%}
diff a/src/hotspot/share/adlc/formssel.cpp b/src/hotspot/share/adlc/formssel.cpp
--- a/src/hotspot/share/adlc/formssel.cpp
+++ b/src/hotspot/share/adlc/formssel.cpp
@@ -788,14 +788,10 @@
        !strcmp(_matrule->_rChild->_opType,"CheckCastPP")  ||
        !strcmp(_matrule->_rChild->_opType,"GetAndSetP")   ||
        !strcmp(_matrule->_rChild->_opType,"GetAndSetN")   ||
        !strcmp(_matrule->_rChild->_opType,"RotateLeft")   ||
        !strcmp(_matrule->_rChild->_opType,"RotateRight")   ||
-#if INCLUDE_SHENANDOAHGC
-       !strcmp(_matrule->_rChild->_opType,"ShenandoahCompareAndExchangeP") ||
-       !strcmp(_matrule->_rChild->_opType,"ShenandoahCompareAndExchangeN") ||
-#endif
        !strcmp(_matrule->_rChild->_opType,"StrInflatedCopy") ||
        !strcmp(_matrule->_rChild->_opType,"VectorCmpMasked")||
        !strcmp(_matrule->_rChild->_opType,"VectorMaskGen")||
        !strcmp(_matrule->_rChild->_opType,"VerifyVectorAlignment")||
        !strcmp(_matrule->_rChild->_opType,"CompareAndExchangeP") ||
@@ -3651,13 +3647,10 @@
     "LoadVectorGather", "StoreVectorScatter", "LoadVectorGatherMasked", "StoreVectorScatterMasked",
     "LoadRange", "LoadKlass", "LoadNKlass", "LoadL_unaligned", "LoadD_unaligned",
     "CompareAndSwapB", "CompareAndSwapS", "CompareAndSwapI", "CompareAndSwapL", "CompareAndSwapP", "CompareAndSwapN",
     "WeakCompareAndSwapB", "WeakCompareAndSwapS", "WeakCompareAndSwapI", "WeakCompareAndSwapL", "WeakCompareAndSwapP", "WeakCompareAndSwapN",
     "CompareAndExchangeB", "CompareAndExchangeS", "CompareAndExchangeI", "CompareAndExchangeL", "CompareAndExchangeP", "CompareAndExchangeN",
-#if INCLUDE_SHENANDOAHGC
-    "ShenandoahCompareAndSwapN", "ShenandoahCompareAndSwapP", "ShenandoahWeakCompareAndSwapP", "ShenandoahWeakCompareAndSwapN", "ShenandoahCompareAndExchangeP", "ShenandoahCompareAndExchangeN",
-#endif
     "GetAndSetB", "GetAndSetS", "GetAndAddI", "GetAndSetI", "GetAndSetP",
     "GetAndAddB", "GetAndAddS", "GetAndAddL", "GetAndSetL", "GetAndSetN",
     "ClearArray"
   };
   int cnt = sizeof(needs_ideal_memory_list)/sizeof(char*);
diff a/src/hotspot/share/gc/shared/c2/barrierSetC2.hpp b/src/hotspot/share/gc/shared/c2/barrierSetC2.hpp
--- a/src/hotspot/share/gc/shared/c2/barrierSetC2.hpp
+++ b/src/hotspot/share/gc/shared/c2/barrierSetC2.hpp
@@ -302,12 +302,10 @@
   virtual Node* obj_allocate(PhaseMacroExpand* macro, Node* mem, Node* toobig_false, Node* size_in_bytes,
                              Node*& i_o, Node*& needgc_ctrl,
                              Node*& fast_oop_ctrl, Node*& fast_oop_rawmem,
                              intx prefetch_lines) const;
 
-  virtual Node* ideal_node(PhaseGVN* phase, Node* n, bool can_reshape) const { return nullptr; }
-
   // These are general helper methods used by C2
   enum ArrayCopyPhase {
     Parsing,
     Optimization,
     Expansion
@@ -315,32 +313,22 @@
 
   virtual bool array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, bool is_clone_instance, ArrayCopyPhase phase) const { return false; }
   virtual void clone_at_expansion(PhaseMacroExpand* phase, ArrayCopyNode* ac) const;
 
   // Support for GC barriers emitted during parsing
-  virtual bool has_load_barrier_nodes() const { return false; }
-  virtual bool is_gc_pre_barrier_node(Node* node) const { return false; }
   virtual bool is_gc_barrier_node(Node* node) const { return false; }
-  virtual Node* step_over_gc_barrier(Node* c) const { return c; }
 
   // Support for macro expanded GC barriers
-  virtual void register_potential_barrier_node(Node* node) const { }
-  virtual void unregister_potential_barrier_node(Node* node) const { }
   virtual void eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const { }
   virtual void eliminate_gc_barrier_data(Node* node) const { }
-  virtual void enqueue_useful_gc_barrier(PhaseIterGVN* igvn, Node* node) const {}
-  virtual void eliminate_useless_gc_barriers(Unique_Node_List &useful, Compile* C) const {}
 
   // Allow barrier sets to have shared state that is preserved across a compilation unit.
   // This could for example comprise macro nodes to be expanded during macro expansion.
   virtual void* create_barrier_state(Arena* comp_arena) const { return nullptr; }
   // If the BarrierSetC2 state has barrier nodes in its compilation
   // unit state to be expanded later, then now is the time to do so.
   virtual bool expand_barriers(Compile* C, PhaseIterGVN& igvn) const { return false; }
-  virtual bool optimize_loops(PhaseIdealLoop* phase, LoopOptsMode mode, VectorSet& visited, Node_Stack& nstack, Node_List& worklist) const { return false; }
-  virtual bool strip_mined_loops_expanded(LoopOptsMode mode) const { return false; }
-  virtual bool is_gc_specific_loop_opts_pass(LoopOptsMode mode) const { return false; }
   // Estimated size of the node barrier in number of C2 Ideal nodes.
   // This is used to guide heuristics in C2, e.g. whether to unroll a loop.
   virtual uint estimated_barrier_size(const Node* node) const { return 0; }
   // Whether the given store can be used to initialize a newly allocated object.
   virtual bool can_initialize_object(const StoreNode* store) const { return true; }
@@ -353,19 +341,10 @@
 
 #ifdef ASSERT
   virtual void verify_gc_barriers(Compile* compile, CompilePhase phase) const {}
 #endif
 
-  virtual bool final_graph_reshaping(Compile* compile, Node* n, uint opcode, Unique_Node_List& dead_nodes) const { return false; }
-
-  virtual bool escape_add_to_con_graph(ConnectionGraph* conn_graph, PhaseGVN* gvn, Unique_Node_List* delayed_worklist, Node* n, uint opcode) const { return false; }
-  virtual bool escape_add_final_edges(ConnectionGraph* conn_graph, PhaseGVN* gvn, Node* n, uint opcode) const { return false; }
-  virtual bool escape_has_out_with_unsafe_object(Node* n) const { return false; }
-
-  virtual bool matcher_find_shared_post_visit(Matcher* matcher, Node* n, uint opcode) const { return false; };
-  virtual bool matcher_is_store_load_barrier(Node* x, uint xop) const { return false; }
-
   // Whether the given phi node joins OOPs from fast and slow allocation paths.
   static bool is_allocation(const Node* node);
   // Elide GC barriers from a Mach node according to elide_dominated_barriers().
   virtual void elide_dominated_barrier(MachNode* mach) const { }
   // Elide GC barriers from instructions in 'accesses' if they are dominated by
diff a/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.cpp b/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.cpp
--- a/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.cpp
+++ b/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.cpp
@@ -21,62 +21,41 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  *
  */
 
-#include "classfile/javaClasses.hpp"
 #include "gc/shared/barrierSet.hpp"
 #include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
-#include "gc/shenandoah/c2/shenandoahSupport.hpp"
 #include "gc/shenandoah/heuristics/shenandoahHeuristics.hpp"
-#include "gc/shenandoah/shenandoahBarrierSet.hpp"
-#include "gc/shenandoah/shenandoahCardTable.hpp"
 #include "gc/shenandoah/shenandoahForwarding.hpp"
 #include "gc/shenandoah/shenandoahHeap.hpp"
 #include "gc/shenandoah/shenandoahRuntime.hpp"
 #include "gc/shenandoah/shenandoahThreadLocalData.hpp"
 #include "opto/arraycopynode.hpp"
 #include "opto/escape.hpp"
 #include "opto/graphKit.hpp"
 #include "opto/idealKit.hpp"
 #include "opto/macro.hpp"
-#include "opto/movenode.hpp"
 #include "opto/narrowptrnode.hpp"
+#include "opto/output.hpp"
 #include "opto/rootnode.hpp"
 #include "opto/runtime.hpp"
 
 ShenandoahBarrierSetC2* ShenandoahBarrierSetC2::bsc2() {
   return reinterpret_cast<ShenandoahBarrierSetC2*>(BarrierSet::barrier_set()->barrier_set_c2());
 }
 
-ShenandoahBarrierSetC2State::ShenandoahBarrierSetC2State(Arena* comp_arena)
-  : _load_reference_barriers(new (comp_arena) GrowableArray<ShenandoahLoadReferenceBarrierNode*>(comp_arena, 8,  0, nullptr)) {
-}
-
-int ShenandoahBarrierSetC2State::load_reference_barriers_count() const {
-  return _load_reference_barriers->length();
-}
-
-ShenandoahLoadReferenceBarrierNode* ShenandoahBarrierSetC2State::load_reference_barrier(int idx) const {
-  return _load_reference_barriers->at(idx);
-}
-
-void ShenandoahBarrierSetC2State::add_load_reference_barrier(ShenandoahLoadReferenceBarrierNode * n) {
-  assert(!_load_reference_barriers->contains(n), "duplicate entry in barrier list");
-  _load_reference_barriers->append(n);
-}
-
-void ShenandoahBarrierSetC2State::remove_load_reference_barrier(ShenandoahLoadReferenceBarrierNode * n) {
-  if (_load_reference_barriers->contains(n)) {
-    _load_reference_barriers->remove(n);
-  }
+ShenandoahBarrierSetC2State::ShenandoahBarrierSetC2State(Arena* comp_arena) :
+    BarrierSetC2State(comp_arena),
+    _stubs(new (comp_arena) GrowableArray<ShenandoahBarrierStubC2*>(comp_arena, 8,  0, nullptr)),
+    _stubs_start_offset(0) {
 }
 
 #define __ kit->
 
-bool ShenandoahBarrierSetC2::satb_can_remove_pre_barrier(GraphKit* kit, PhaseValues* phase, Node* adr,
-                                                         BasicType bt, uint adr_idx) const {
+static bool satb_can_remove_pre_barrier(GraphKit* kit, PhaseValues* phase, Node* adr,
+                                        BasicType bt, uint adr_idx) {
   intptr_t offset = 0;
   Node* base = AddPNode::Ideal_base_and_offset(adr, phase, offset);
   AllocateNode* alloc = AllocateNode::Ideal_allocation(base);
 
   if (offset == Type::OffsetBot) {
@@ -156,383 +135,40 @@
   }
 
   return false;
 }
 
-#undef __
-#define __ ideal.
-
-void ShenandoahBarrierSetC2::satb_write_barrier_pre(GraphKit* kit,
-                                                    bool do_load,
-                                                    Node* obj,
-                                                    Node* adr,
-                                                    uint alias_idx,
-                                                    Node* val,
-                                                    const TypeOopPtr* val_type,
-                                                    Node* pre_val,
-                                                    BasicType bt) const {
-  // Some sanity checks
-  // Note: val is unused in this routine.
-
-  if (do_load) {
-    // We need to generate the load of the previous value
-    assert(adr != nullptr, "where are loading from?");
-    assert(pre_val == nullptr, "loaded already?");
-    assert(val_type != nullptr, "need a type");
-
-    if (ReduceInitialCardMarks
-        && satb_can_remove_pre_barrier(kit, &kit->gvn(), adr, bt, alias_idx)) {
-      return;
-    }
+static bool shenandoah_can_remove_post_barrier(GraphKit* kit, PhaseValues* phase, Node* store_ctrl, Node* adr) {
+  intptr_t      offset = 0;
+  Node*         base   = AddPNode::Ideal_base_and_offset(adr, phase, offset);
+  AllocateNode* alloc  = AllocateNode::Ideal_allocation(base);
 
-  } else {
-    // In this case both val_type and alias_idx are unused.
-    assert(pre_val != nullptr, "must be loaded already");
-    // Nothing to be done if pre_val is null.
-    if (pre_val->bottom_type() == TypePtr::NULL_PTR) return;
-    assert(pre_val->bottom_type()->basic_type() == T_OBJECT, "or we shouldn't be here");
+  if (offset == Type::OffsetBot) {
+    return false; // Cannot unalias unless there are precise offsets.
+  }
+  if (alloc == nullptr) {
+    return false; // No allocation found.
   }
-  assert(bt == T_OBJECT, "or we shouldn't be here");
-
-  IdealKit ideal(kit, true);
-
-  Node* tls = __ thread(); // ThreadLocalStorage
-
-  Node* no_base = __ top();
-  Node* zero  = __ ConI(0);
-  Node* zeroX = __ ConX(0);
-
-  float likely  = PROB_LIKELY(0.999);
-  float unlikely  = PROB_UNLIKELY(0.999);
-
-  // Offsets into the thread
-  const int index_offset   = in_bytes(ShenandoahThreadLocalData::satb_mark_queue_index_offset());
-  const int buffer_offset  = in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset());
-
-  // Now the actual pointers into the thread
-  Node* buffer_adr  = __ AddP(no_base, tls, __ ConX(buffer_offset));
-  Node* index_adr   = __ AddP(no_base, tls, __ ConX(index_offset));
-
-  // Now some of the values
-  Node* marking;
-  Node* gc_state = __ AddP(no_base, tls, __ ConX(in_bytes(ShenandoahThreadLocalData::gc_state_offset())));
-  Node* ld = __ load(__ ctrl(), gc_state, TypeInt::BYTE, T_BYTE, Compile::AliasIdxRaw);
-  marking = __ AndI(ld, __ ConI(ShenandoahHeap::MARKING));
-  assert(ShenandoahBarrierC2Support::is_gc_state_load(ld), "Should match the shape");
-
-  // if (!marking)
-  __ if_then(marking, BoolTest::ne, zero, unlikely); {
-    BasicType index_bt = TypeX_X->basic_type();
-    assert(sizeof(size_t) == type2aelembytes(index_bt), "Loading Shenandoah SATBMarkQueue::_index with wrong size.");
-    Node* index   = __ load(__ ctrl(), index_adr, TypeX_X, index_bt, Compile::AliasIdxRaw);
 
-    if (do_load) {
-      // load original value
-      // alias_idx correct??
-      pre_val = __ load(__ ctrl(), adr, val_type, bt, alias_idx);
+  Node* mem = store_ctrl;   // Start search from Store node.
+  if (mem->is_Proj() && mem->in(0)->is_Initialize()) {
+    InitializeNode* st_init = mem->in(0)->as_Initialize();
+    AllocateNode*  st_alloc = st_init->allocation();
+    // Make sure we are looking at the same allocation
+    if (alloc == st_alloc) {
+      return true;
     }
-
-    // if (pre_val != nullptr)
-    __ if_then(pre_val, BoolTest::ne, kit->null()); {
-      Node* buffer  = __ load(__ ctrl(), buffer_adr, TypeRawPtr::NOTNULL, T_ADDRESS, Compile::AliasIdxRaw);
-
-      // is the queue for this thread full?
-      __ if_then(index, BoolTest::ne, zeroX, likely); {
-
-        // decrement the index
-        Node* next_index = kit->gvn().transform(new SubXNode(index, __ ConX(sizeof(intptr_t))));
-
-        // Now get the buffer location we will log the previous value into and store it
-        Node *log_addr = __ AddP(no_base, buffer, next_index);
-        __ store(__ ctrl(), log_addr, pre_val, T_OBJECT, Compile::AliasIdxRaw, MemNode::unordered);
-        // update the index
-        __ store(__ ctrl(), index_adr, next_index, index_bt, Compile::AliasIdxRaw, MemNode::unordered);
-
-      } __ else_(); {
-
-        // logging buffer is full, call the runtime
-        const TypeFunc *tf = ShenandoahBarrierSetC2::write_barrier_pre_Type();
-        __ make_leaf_call(tf, CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_barrier_pre), "shenandoah_wb_pre", pre_val);
-      } __ end_if();  // (!index)
-    } __ end_if();  // (pre_val != nullptr)
-  } __ end_if();  // (!marking)
-
-  // Final sync IdealKit and GraphKit.
-  kit->final_sync(ideal);
-
-  if (ShenandoahSATBBarrier && adr != nullptr) {
-    Node* c = kit->control();
-    Node* call = c->in(1)->in(1)->in(1)->in(0);
-    assert(is_shenandoah_wb_pre_call(call), "shenandoah_wb_pre call expected");
-    call->add_req(adr);
   }
-}
 
-bool ShenandoahBarrierSetC2::is_shenandoah_wb_pre_call(Node* call) {
-  return call->is_CallLeaf() &&
-         call->as_CallLeaf()->entry_point() == CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_barrier_pre);
+  return false;
 }
 
 bool ShenandoahBarrierSetC2::is_shenandoah_clone_call(Node* call) {
   return call->is_CallLeaf() &&
          call->as_CallLeaf()->entry_point() == CAST_FROM_FN_PTR(address, ShenandoahRuntime::clone_barrier);
 }
 
-bool ShenandoahBarrierSetC2::is_shenandoah_lrb_call(Node* call) {
-  if (!call->is_CallLeaf()) {
-    return false;
-  }
-
-  address entry_point = call->as_CallLeaf()->entry_point();
-  return (entry_point == CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_strong)) ||
-         (entry_point == CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_strong_narrow)) ||
-         (entry_point == CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_weak)) ||
-         (entry_point == CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_weak_narrow)) ||
-         (entry_point == CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_phantom)) ||
-         (entry_point == CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_phantom_narrow));
-}
-
-bool ShenandoahBarrierSetC2::is_shenandoah_marking_if(PhaseValues* phase, Node* n) {
-  if (n->Opcode() != Op_If) {
-    return false;
-  }
-
-  Node* bol = n->in(1);
-  assert(bol->is_Bool(), "");
-  Node* cmpx = bol->in(1);
-  if (bol->as_Bool()->_test._test == BoolTest::ne &&
-      cmpx->is_Cmp() && cmpx->in(2) == phase->intcon(0) &&
-      is_shenandoah_state_load(cmpx->in(1)->in(1)) &&
-      cmpx->in(1)->in(2)->is_Con() &&
-      cmpx->in(1)->in(2) == phase->intcon(ShenandoahHeap::MARKING)) {
-    return true;
-  }
-
-  return false;
-}
-
-bool ShenandoahBarrierSetC2::is_shenandoah_state_load(Node* n) {
-  if (!n->is_Load()) return false;
-  const int state_offset = in_bytes(ShenandoahThreadLocalData::gc_state_offset());
-  return n->in(2)->is_AddP() && n->in(2)->in(2)->Opcode() == Op_ThreadLocal
-         && n->in(2)->in(3)->is_Con()
-         && n->in(2)->in(3)->bottom_type()->is_intptr_t()->get_con() == state_offset;
-}
-
-void ShenandoahBarrierSetC2::shenandoah_write_barrier_pre(GraphKit* kit,
-                                                          bool do_load,
-                                                          Node* obj,
-                                                          Node* adr,
-                                                          uint alias_idx,
-                                                          Node* val,
-                                                          const TypeOopPtr* val_type,
-                                                          Node* pre_val,
-                                                          BasicType bt) const {
-  if (ShenandoahSATBBarrier) {
-    IdealKit ideal(kit);
-    kit->sync_kit(ideal);
-
-    satb_write_barrier_pre(kit, do_load, obj, adr, alias_idx, val, val_type, pre_val, bt);
-
-    ideal.sync_kit(kit);
-    kit->final_sync(ideal);
-  }
-}
-
-// Helper that guards and inserts a pre-barrier.
-void ShenandoahBarrierSetC2::insert_pre_barrier(GraphKit* kit, Node* base_oop, Node* offset,
-                                                Node* pre_val, bool need_mem_bar) const {
-  // We could be accessing the referent field of a reference object. If so, when Shenandoah
-  // is enabled, we need to log the value in the referent field in an SATB buffer.
-  // This routine performs some compile time filters and generates suitable
-  // runtime filters that guard the pre-barrier code.
-  // Also add memory barrier for non volatile load from the referent field
-  // to prevent commoning of loads across safepoint.
-
-  // Some compile time checks.
-
-  // If offset is a constant, is it java_lang_ref_Reference::_reference_offset?
-  const TypeX* otype = offset->find_intptr_t_type();
-  if (otype != nullptr && otype->is_con() &&
-      otype->get_con() != java_lang_ref_Reference::referent_offset()) {
-    // Constant offset but not the reference_offset so just return
-    return;
-  }
-
-  // We only need to generate the runtime guards for instances.
-  const TypeOopPtr* btype = base_oop->bottom_type()->isa_oopptr();
-  if (btype != nullptr) {
-    if (btype->isa_aryptr()) {
-      // Array type so nothing to do
-      return;
-    }
-
-    const TypeInstPtr* itype = btype->isa_instptr();
-    if (itype != nullptr) {
-      // Can the klass of base_oop be statically determined to be
-      // _not_ a sub-class of Reference and _not_ Object?
-      ciKlass* klass = itype->instance_klass();
-      if (klass->is_loaded() &&
-          !klass->is_subtype_of(kit->env()->Reference_klass()) &&
-          !kit->env()->Object_klass()->is_subtype_of(klass)) {
-        return;
-      }
-    }
-  }
-
-  // The compile time filters did not reject base_oop/offset so
-  // we need to generate the following runtime filters
-  //
-  // if (offset == java_lang_ref_Reference::_reference_offset) {
-  //   if (instance_of(base, java.lang.ref.Reference)) {
-  //     pre_barrier(_, pre_val, ...);
-  //   }
-  // }
-
-  float likely   = PROB_LIKELY(  0.999);
-  float unlikely = PROB_UNLIKELY(0.999);
-
-  IdealKit ideal(kit);
-
-  Node* referent_off = __ ConX(java_lang_ref_Reference::referent_offset());
-
-  __ if_then(offset, BoolTest::eq, referent_off, unlikely); {
-      // Update graphKit memory and control from IdealKit.
-      kit->sync_kit(ideal);
-
-      Node* ref_klass_con = kit->makecon(TypeKlassPtr::make(kit->env()->Reference_klass()));
-      Node* is_instof = kit->gen_instanceof(base_oop, ref_klass_con);
-
-      // Update IdealKit memory and control from graphKit.
-      __ sync_kit(kit);
-
-      Node* one = __ ConI(1);
-      // is_instof == 0 if base_oop == nullptr
-      __ if_then(is_instof, BoolTest::eq, one, unlikely); {
-
-        // Update graphKit from IdeakKit.
-        kit->sync_kit(ideal);
-
-        // Use the pre-barrier to record the value in the referent field
-        satb_write_barrier_pre(kit, false /* do_load */,
-                               nullptr /* obj */, nullptr /* adr */, max_juint /* alias_idx */, nullptr /* val */, nullptr /* val_type */,
-                               pre_val /* pre_val */,
-                               T_OBJECT);
-        if (need_mem_bar) {
-          // Add memory barrier to prevent commoning reads from this field
-          // across safepoint since GC can change its value.
-          kit->insert_mem_bar(Op_MemBarCPUOrder);
-        }
-        // Update IdealKit from graphKit.
-        __ sync_kit(kit);
-
-      } __ end_if(); // _ref_type != ref_none
-  } __ end_if(); // offset == referent_offset
-
-  // Final sync IdealKit and GraphKit.
-  kit->final_sync(ideal);
-}
-
-void ShenandoahBarrierSetC2::post_barrier(GraphKit* kit,
-                                          Node* ctl,
-                                          Node* oop_store,
-                                          Node* obj,
-                                          Node* adr,
-                                          uint  adr_idx,
-                                          Node* val,
-                                          BasicType bt,
-                                          bool use_precise) const {
-  assert(ShenandoahCardBarrier, "Should have been checked by caller");
-
-  // No store check needed if we're storing a null.
-  if (val != nullptr && val->is_Con()) {
-    // must be either an oop or null
-    const Type* t = val->bottom_type();
-    if (t == TypePtr::NULL_PTR || t == Type::TOP)
-      return;
-  }
-
-  if (ReduceInitialCardMarks && obj == kit->just_allocated_object(kit->control())) {
-    // We use card marks to track old to young references in Generational Shenandoah;
-    // see flag ShenandoahCardBarrier above.
-    // Objects are always allocated in the young generation and initialized
-    // before they are promoted. There's always a safepoint (e.g. at final mark)
-    // before an object is promoted from young to old. Promotion entails dirtying of
-    // the cards backing promoted objects, so they will be guaranteed to be scanned
-    // at the next remembered set scan of the old generation.
-    // Thus, we can safely skip card-marking of initializing stores on a
-    // freshly-allocated object. If any of the assumptions above change in
-    // the future, this code will need to be re-examined; see check in
-    // ShenandoahCardBarrier::on_slowpath_allocation_exit().
-    return;
-  }
-
-  if (!use_precise) {
-    // All card marks for a (non-array) instance are in one place:
-    adr = obj;
-  }
-  // (Else it's an array (or unknown), and we want more precise card marks.)
-  assert(adr != nullptr, "");
-
-  IdealKit ideal(kit, true);
-
-  Node* tls = __ thread(); // ThreadLocalStorage
-
-  // Convert the pointer to an int prior to doing math on it
-  Node* cast = __ CastPX(__ ctrl(), adr);
-
-  Node* curr_ct_holder_offset = __ ConX(in_bytes(ShenandoahThreadLocalData::card_table_offset()));
-  Node* curr_ct_holder_addr  = __ AddP(__ top(), tls, curr_ct_holder_offset);
-  Node* curr_ct_base_addr = __ load( __ ctrl(), curr_ct_holder_addr, TypeRawPtr::NOTNULL, T_ADDRESS, Compile::AliasIdxRaw);
-
-  // Divide by card size
-  Node* card_offset = __ URShiftX( cast, __ ConI(CardTable::card_shift()) );
-
-  // Combine card table base and card offset
-  Node* card_adr = __ AddP(__ top(), curr_ct_base_addr, card_offset);
-
-  // Get the alias_index for raw card-mark memory
-  int adr_type = Compile::AliasIdxRaw;
-  Node*   zero = __ ConI(0); // Dirty card value
-
-  if (UseCondCardMark) {
-    // The classic GC reference write barrier is typically implemented
-    // as a store into the global card mark table.  Unfortunately
-    // unconditional stores can result in false sharing and excessive
-    // coherence traffic as well as false transactional aborts.
-    // UseCondCardMark enables MP "polite" conditional card mark
-    // stores.  In theory we could relax the load from ctrl() to
-    // no_ctrl, but that doesn't buy much latitude.
-    Node* card_val = __ load( __ ctrl(), card_adr, TypeInt::BYTE, T_BYTE, adr_type);
-    __ if_then(card_val, BoolTest::ne, zero);
-  }
-
-  // Smash zero into card
-  __ store(__ ctrl(), card_adr, zero, T_BYTE, adr_type, MemNode::unordered);
-
-  if (UseCondCardMark) {
-    __ end_if();
-  }
-
-  // Final sync IdealKit and GraphKit.
-  kit->final_sync(ideal);
-}
-
-#undef __
-
-const TypeFunc* ShenandoahBarrierSetC2::write_barrier_pre_Type() {
-  const Type **fields = TypeTuple::fields(1);
-  fields[TypeFunc::Parms+0] = TypeInstPtr::NOTNULL; // original field value
-  const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
-
-  // create result type (range)
-  fields = TypeTuple::fields(0);
-  const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
-
-  return TypeFunc::make(domain, range);
-}
-
 const TypeFunc* ShenandoahBarrierSetC2::clone_barrier_Type() {
   const Type **fields = TypeTuple::fields(1);
   fields[TypeFunc::Parms+0] = TypeOopPtr::NOTNULL; // src oop
   const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+1, fields);
 
@@ -541,291 +177,213 @@
   const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0, fields);
 
   return TypeFunc::make(domain, range);
 }
 
-const TypeFunc* ShenandoahBarrierSetC2::load_reference_barrier_Type() {
-  const Type **fields = TypeTuple::fields(2);
-  fields[TypeFunc::Parms+0] = TypeOopPtr::BOTTOM; // original field value
-  fields[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // original load address
+static uint8_t get_store_barrier(C2Access& access) {
+  if (!access.is_parse_access()) {
+    // Only support for eliding barriers at parse time for now.
+    return ShenandoahBarrierSATB | ShenandoahBarrierCardMark;
+  }
+  GraphKit* kit = (static_cast<C2ParseAccess&>(access)).kit();
+  Node* ctl = kit->control();
+  Node* adr = access.addr().node();
+  uint adr_idx = kit->C->get_alias_index(access.addr().type());
+  assert(adr_idx != Compile::AliasIdxTop, "use other store_to_memory factory");
 
-  const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2, fields);
+  bool can_remove_pre_barrier = satb_can_remove_pre_barrier(kit, &kit->gvn(), adr, access.type(), adr_idx);
 
-  // create result type (range)
-  fields = TypeTuple::fields(1);
-  fields[TypeFunc::Parms+0] = TypeOopPtr::BOTTOM;
-  const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields);
+  // We can skip marks on a freshly-allocated object in Eden. Keep this code in
+  // sync with CardTableBarrierSet::on_slowpath_allocation_exit. That routine
+  // informs GC to take appropriate compensating steps, upon a slow-path
+  // allocation, so as to make this card-mark elision safe.
+  // The post-barrier can also be removed if null is written. This case is
+  // handled by ShenandoahBarrierSetC2::expand_barriers, which runs at the end of C2's
+  // platform-independent optimizations to exploit stronger type information.
+  bool can_remove_post_barrier = ReduceInitialCardMarks &&
+    ((access.base() == kit->just_allocated_object(ctl)) ||
+     shenandoah_can_remove_post_barrier(kit, &kit->gvn(), ctl, adr));
 
-  return TypeFunc::make(domain, range);
+  int barriers = 0;
+  if (!can_remove_pre_barrier) {
+    barriers |= ShenandoahBarrierSATB;
+  }
+  if (!can_remove_post_barrier) {
+    barriers |= ShenandoahBarrierCardMark;
+  }
+
+  return barriers;
 }
 
 Node* ShenandoahBarrierSetC2::store_at_resolved(C2Access& access, C2AccessValue& val) const {
   DecoratorSet decorators = access.decorators();
-
-  const TypePtr* adr_type = access.addr().type();
-  Node* adr = access.addr().node();
-
+  bool anonymous = (decorators & ON_UNKNOWN_OOP_REF) != 0;
+  bool in_heap = (decorators & IN_HEAP) != 0;
+  bool tightly_coupled_alloc = (decorators & C2_TIGHTLY_COUPLED_ALLOC) != 0;
+  bool need_store_barrier = !(tightly_coupled_alloc && ReduceInitialCardMarks) && (in_heap || anonymous);
   bool no_keepalive = (decorators & AS_NO_KEEPALIVE) != 0;
-
-  if (!access.is_oop()) {
-    return BarrierSetC2::store_at_resolved(access, val);
+  if (access.is_oop() && need_store_barrier) {
+    access.set_barrier_data(get_store_barrier(access));
+    if (tightly_coupled_alloc) {
+      assert(!ReduceInitialCardMarks,
+             "post-barriers are only needed for tightly-coupled initialization stores when ReduceInitialCardMarks is disabled");
+      // Pre-barriers are unnecessary for tightly-coupled initialization stores.
+      access.set_barrier_data(access.barrier_data() & ~ShenandoahBarrierSATB);
+    }
   }
-
   if (no_keepalive) {
     // No keep-alive means no need for the pre-barrier.
-    return BarrierSetC2::store_at_resolved(access, val);
+    access.set_barrier_data(access.barrier_data() & ~ShenandoahBarrierSATB);
   }
+  return BarrierSetC2::store_at_resolved(access, val);
+}
 
-  if (access.is_parse_access()) {
-    C2ParseAccess& parse_access = static_cast<C2ParseAccess&>(access);
-    GraphKit* kit = parse_access.kit();
+static void set_barrier_data(C2Access& access) {
+  if (!access.is_oop()) {
+    return;
+  }
 
-    uint adr_idx = kit->C->get_alias_index(adr_type);
-    assert(adr_idx != Compile::AliasIdxTop, "use other store_to_memory factory" );
-    shenandoah_write_barrier_pre(kit, true /* do_load */, /*kit->control(),*/ access.base(), adr, adr_idx, val.node(),
-                                 static_cast<const TypeOopPtr*>(val.type()), nullptr /* pre_val */, access.type());
+  if (access.decorators() & C2_TIGHTLY_COUPLED_ALLOC) {
+    access.set_barrier_data(ShenandoahBarrierElided);
+    return;
+  }
 
-    Node* result = BarrierSetC2::store_at_resolved(access, val);
+  uint8_t barrier_data = 0;
 
-    if (ShenandoahCardBarrier) {
-      const bool anonymous = (decorators & ON_UNKNOWN_OOP_REF) != 0;
-      const bool is_array = (decorators & IS_ARRAY) != 0;
-      const bool use_precise = is_array || anonymous;
-      post_barrier(kit, kit->control(), access.raw_access(), access.base(),
-                   adr, adr_idx, val.node(), access.type(), use_precise);
-    }
-    return result;
+  if (access.decorators() & ON_PHANTOM_OOP_REF) {
+    barrier_data |= ShenandoahBarrierPhantom;
+  } else if (access.decorators() & ON_WEAK_OOP_REF) {
+    barrier_data |= ShenandoahBarrierWeak;
   } else {
-    assert(access.is_opt_access(), "only for optimization passes");
-    assert(((decorators & C2_TIGHTLY_COUPLED_ALLOC) != 0 || !ShenandoahSATBBarrier) && (decorators & C2_ARRAY_COPY) != 0, "unexpected caller of this code");
-    return BarrierSetC2::store_at_resolved(access, val);
+    barrier_data |= ShenandoahBarrierStrong;
+  }
+
+  if (access.decorators() & IN_NATIVE) {
+    barrier_data |= ShenandoahBarrierNative;
   }
+
+  access.set_barrier_data(barrier_data);
 }
 
 Node* ShenandoahBarrierSetC2::load_at_resolved(C2Access& access, const Type* val_type) const {
   // 1: non-reference load, no additional barrier is needed
   if (!access.is_oop()) {
     return BarrierSetC2::load_at_resolved(access, val_type);
   }
 
-  Node* load = BarrierSetC2::load_at_resolved(access, val_type);
-  DecoratorSet decorators = access.decorators();
-  BasicType type = access.type();
-
-  // 2: apply LRB if needed
-  if (ShenandoahBarrierSet::need_load_reference_barrier(decorators, type)) {
-    load = new ShenandoahLoadReferenceBarrierNode(nullptr, load, decorators);
-    if (access.is_parse_access()) {
-      load = static_cast<C2ParseAccess &>(access).kit()->gvn().transform(load);
-    } else {
-      load = static_cast<C2OptAccess &>(access).gvn().transform(load);
-    }
-  }
+  // 2. Set barrier data for LRB.
+  set_barrier_data(access);
 
-  // 3: apply keep-alive barrier for java.lang.ref.Reference if needed
-  if (ShenandoahBarrierSet::need_keep_alive_barrier(decorators, type)) {
-    Node* top = Compile::current()->top();
-    Node* adr = access.addr().node();
-    Node* offset = adr->is_AddP() ? adr->in(AddPNode::Offset) : top;
-    Node* obj = access.base();
-
-    bool unknown = (decorators & ON_UNKNOWN_OOP_REF) != 0;
-    bool on_weak_ref = (decorators & (ON_WEAK_OOP_REF | ON_PHANTOM_OOP_REF)) != 0;
-    bool keep_alive = (decorators & AS_NO_KEEPALIVE) == 0;
-
-    // If we are reading the value of the referent field of a Reference
-    // object (either by using Unsafe directly or through reflection)
-    // then, if SATB is enabled, we need to record the referent in an
-    // SATB log buffer using the pre-barrier mechanism.
-    // Also we need to add memory barrier to prevent commoning reads
-    // from this field across safepoint since GC can change its value.
-    if (!on_weak_ref || (unknown && (offset == top || obj == top)) || !keep_alive) {
-      return load;
-    }
-
-    assert(access.is_parse_access(), "entry not supported at optimization time");
-    C2ParseAccess& parse_access = static_cast<C2ParseAccess&>(access);
-    GraphKit* kit = parse_access.kit();
-    bool mismatched = (decorators & C2_MISMATCHED) != 0;
-    bool is_unordered = (decorators & MO_UNORDERED) != 0;
-    bool in_native = (decorators & IN_NATIVE) != 0;
-    bool need_cpu_mem_bar = !is_unordered || mismatched || in_native;
-
-    if (on_weak_ref) {
-      // Use the pre-barrier to record the value in the referent field
-      satb_write_barrier_pre(kit, false /* do_load */,
-                             nullptr /* obj */, nullptr /* adr */, max_juint /* alias_idx */, nullptr /* val */, nullptr /* val_type */,
-                             load /* pre_val */, T_OBJECT);
-      // Add memory barrier to prevent commoning reads from this field
-      // across safepoint since GC can change its value.
-      kit->insert_mem_bar(Op_MemBarCPUOrder);
-    } else if (unknown) {
-      // We do not require a mem bar inside pre_barrier if need_mem_bar
-      // is set: the barriers would be emitted by us.
-      insert_pre_barrier(kit, obj, offset, load, !need_cpu_mem_bar);
-    }
+  // 3. If we are reading the value of the referent field of a Reference object, we
+  // need to record the referent in an SATB log buffer using the pre-barrier
+  // mechanism.
+  DecoratorSet decorators = access.decorators();
+  bool on_weak = (decorators & ON_WEAK_OOP_REF) != 0;
+  bool on_phantom = (decorators & ON_PHANTOM_OOP_REF) != 0;
+  bool no_keepalive = (decorators & AS_NO_KEEPALIVE) != 0;
+  // If we are reading the value of the referent field of a Reference object, we
+  // need to record the referent in an SATB log buffer using the pre-barrier
+  // mechanism. Also we need to add a memory barrier to prevent commoning reads
+  // from this field across safepoints, since GC can change its value.
+  uint8_t barriers = access.barrier_data();
+  bool need_read_barrier = ((on_weak || on_phantom) && !no_keepalive);
+  if (access.is_oop() && need_read_barrier) {
+    barriers |= ShenandoahBarrierSATB;
   }
+  access.set_barrier_data(barriers);
 
-  return load;
+  return BarrierSetC2::load_at_resolved(access, val_type);
 }
 
 Node* ShenandoahBarrierSetC2::atomic_cmpxchg_val_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
                                                              Node* new_val, const Type* value_type) const {
-  GraphKit* kit = access.kit();
-  if (access.is_oop()) {
-    shenandoah_write_barrier_pre(kit, false /* do_load */,
-                                 nullptr, nullptr, max_juint, nullptr, nullptr,
-                                 expected_val /* pre_val */, T_OBJECT);
-
-    MemNode::MemOrd mo = access.mem_node_mo();
-    Node* mem = access.memory();
-    Node* adr = access.addr().node();
-    const TypePtr* adr_type = access.addr().type();
-    Node* load_store = nullptr;
-
-#ifdef _LP64
-    if (adr->bottom_type()->is_ptr_to_narrowoop()) {
-      Node *newval_enc = kit->gvn().transform(new EncodePNode(new_val, new_val->bottom_type()->make_narrowoop()));
-      Node *oldval_enc = kit->gvn().transform(new EncodePNode(expected_val, expected_val->bottom_type()->make_narrowoop()));
-      if (ShenandoahCASBarrier) {
-        load_store = kit->gvn().transform(new ShenandoahCompareAndExchangeNNode(kit->control(), mem, adr, newval_enc, oldval_enc, adr_type, value_type->make_narrowoop(), mo));
-      } else {
-        load_store = kit->gvn().transform(new CompareAndExchangeNNode(kit->control(), mem, adr, newval_enc, oldval_enc, adr_type, value_type->make_narrowoop(), mo));
-      }
-    } else
-#endif
-    {
-      if (ShenandoahCASBarrier) {
-        load_store = kit->gvn().transform(new ShenandoahCompareAndExchangePNode(kit->control(), mem, adr, new_val, expected_val, adr_type, value_type->is_oopptr(), mo));
-      } else {
-        load_store = kit->gvn().transform(new CompareAndExchangePNode(kit->control(), mem, adr, new_val, expected_val, adr_type, value_type->is_oopptr(), mo));
-      }
-    }
-
-    access.set_raw_access(load_store);
-    pin_atomic_op(access);
+  if (ShenandoahCASBarrier) {
+    set_barrier_data(access);
+  }
 
-#ifdef _LP64
-    if (adr->bottom_type()->is_ptr_to_narrowoop()) {
-      load_store = kit->gvn().transform(new DecodeNNode(load_store, load_store->get_ptr_type()));
-    }
-#endif
-    load_store = kit->gvn().transform(new ShenandoahLoadReferenceBarrierNode(nullptr, load_store, access.decorators()));
-    if (ShenandoahCardBarrier) {
-      post_barrier(kit, kit->control(), access.raw_access(), access.base(),
-                   access.addr().node(), access.alias_idx(), new_val, T_OBJECT, true);
-    }
-    return load_store;
+  if (access.is_oop()) {
+    access.set_barrier_data(access.barrier_data() | ShenandoahBarrierSATB | ShenandoahBarrierCardMark);
   }
   return BarrierSetC2::atomic_cmpxchg_val_at_resolved(access, expected_val, new_val, value_type);
 }
 
 Node* ShenandoahBarrierSetC2::atomic_cmpxchg_bool_at_resolved(C2AtomicParseAccess& access, Node* expected_val,
                                                               Node* new_val, const Type* value_type) const {
+  if (ShenandoahCASBarrier) {
+    set_barrier_data(access);
+  }
   GraphKit* kit = access.kit();
   if (access.is_oop()) {
-    shenandoah_write_barrier_pre(kit, false /* do_load */,
-                                 nullptr, nullptr, max_juint, nullptr, nullptr,
-                                 expected_val /* pre_val */, T_OBJECT);
-    DecoratorSet decorators = access.decorators();
-    MemNode::MemOrd mo = access.mem_node_mo();
-    Node* mem = access.memory();
-    bool is_weak_cas = (decorators & C2_WEAK_CMPXCHG) != 0;
-    Node* load_store = nullptr;
-    Node* adr = access.addr().node();
-#ifdef _LP64
-    if (adr->bottom_type()->is_ptr_to_narrowoop()) {
-      Node *newval_enc = kit->gvn().transform(new EncodePNode(new_val, new_val->bottom_type()->make_narrowoop()));
-      Node *oldval_enc = kit->gvn().transform(new EncodePNode(expected_val, expected_val->bottom_type()->make_narrowoop()));
-      if (ShenandoahCASBarrier) {
-        if (is_weak_cas) {
-          load_store = kit->gvn().transform(new ShenandoahWeakCompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo));
-        } else {
-          load_store = kit->gvn().transform(new ShenandoahCompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo));
-        }
-      } else {
-        if (is_weak_cas) {
-          load_store = kit->gvn().transform(new WeakCompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo));
-        } else {
-          load_store = kit->gvn().transform(new CompareAndSwapNNode(kit->control(), mem, adr, newval_enc, oldval_enc, mo));
-        }
-      }
-    } else
-#endif
-    {
-      if (ShenandoahCASBarrier) {
-        if (is_weak_cas) {
-          load_store = kit->gvn().transform(new ShenandoahWeakCompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo));
-        } else {
-          load_store = kit->gvn().transform(new ShenandoahCompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo));
-        }
-      } else {
-        if (is_weak_cas) {
-          load_store = kit->gvn().transform(new WeakCompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo));
-        } else {
-          load_store = kit->gvn().transform(new CompareAndSwapPNode(kit->control(), mem, adr, new_val, expected_val, mo));
-        }
-      }
-    }
-    access.set_raw_access(load_store);
-    pin_atomic_op(access);
-    if (ShenandoahCardBarrier) {
-      post_barrier(kit, kit->control(), access.raw_access(), access.base(),
-                   access.addr().node(), access.alias_idx(), new_val, T_OBJECT, true);
-    }
-    return load_store;
+    access.set_barrier_data(access.barrier_data() | ShenandoahBarrierSATB | ShenandoahBarrierCardMark);
   }
   return BarrierSetC2::atomic_cmpxchg_bool_at_resolved(access, expected_val, new_val, value_type);
 }
 
 Node* ShenandoahBarrierSetC2::atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* val, const Type* value_type) const {
-  GraphKit* kit = access.kit();
-  Node* result = BarrierSetC2::atomic_xchg_at_resolved(access, val, value_type);
   if (access.is_oop()) {
-    result = kit->gvn().transform(new ShenandoahLoadReferenceBarrierNode(nullptr, result, access.decorators()));
-    shenandoah_write_barrier_pre(kit, false /* do_load */,
-                                 nullptr, nullptr, max_juint, nullptr, nullptr,
-                                 result /* pre_val */, T_OBJECT);
-    if (ShenandoahCardBarrier) {
-      post_barrier(kit, kit->control(), access.raw_access(), access.base(),
-                   access.addr().node(), access.alias_idx(), val, T_OBJECT, true);
-    }
+    access.set_barrier_data(ShenandoahBarrierStrong | ShenandoahBarrierSATB | ShenandoahBarrierCardMark);
   }
-  return result;
+  return BarrierSetC2::atomic_xchg_at_resolved(access, val, value_type);
 }
 
 
-bool ShenandoahBarrierSetC2::is_gc_pre_barrier_node(Node* node) const {
-  return is_shenandoah_wb_pre_call(node);
-}
-
 bool ShenandoahBarrierSetC2::is_gc_barrier_node(Node* node) const {
-  return (node->Opcode() == Op_ShenandoahLoadReferenceBarrier) ||
-         is_shenandoah_lrb_call(node) ||
-         is_shenandoah_wb_pre_call(node) ||
-         is_shenandoah_clone_call(node);
+  return is_shenandoah_clone_call(node);
 }
 
-Node* ShenandoahBarrierSetC2::step_over_gc_barrier(Node* c) const {
-  if (c == nullptr) {
-    return c;
+static void refine_barrier_by_new_val_type(const Node* n) {
+  if (n->Opcode() != Op_StoreP && n->Opcode() != Op_StoreN) {
+    return;
+  }
+  MemNode* store = n->as_Mem();
+  const Node* newval = n->in(MemNode::ValueIn);
+  assert(newval != nullptr, "");
+  const Type* newval_bottom = newval->bottom_type();
+  TypePtr::PTR newval_type = newval_bottom->make_ptr()->ptr();
+  uint8_t barrier_data = store->barrier_data();
+  if (!newval_bottom->isa_oopptr() &&
+      !newval_bottom->isa_narrowoop() &&
+      newval_type != TypePtr::Null) {
+    // newval is neither an OOP nor null, so there is no barrier to refine.
+    assert(barrier_data == 0, "non-OOP stores should have no barrier data");
+    return;
+  }
+  if (barrier_data == 0) {
+    // No barrier to refine.
+    return;
   }
-  if (c->Opcode() == Op_ShenandoahLoadReferenceBarrier) {
-    return c->in(ShenandoahLoadReferenceBarrierNode::ValueIn);
+  if (newval_type == TypePtr::Null) {
+    // Simply elide post-barrier if writing null.
+    barrier_data &= ~ShenandoahBarrierCardMark;
+    barrier_data &= ~ShenandoahBarrierCardMarkNotNull;
+  } else if ((barrier_data & ShenandoahBarrierCardMark) != 0 &&
+             newval_type == TypePtr::NotNull) {
+    // If the post-barrier has not been elided yet (e.g. due to newval being
+    // freshly allocated), mark it as not-null (simplifies barrier tests and
+    // compressed OOPs logic).
+    barrier_data |= ShenandoahBarrierCardMarkNotNull;
   }
-  return c;
+  store->set_barrier_data(barrier_data);
 }
 
 bool ShenandoahBarrierSetC2::expand_barriers(Compile* C, PhaseIterGVN& igvn) const {
-  return !ShenandoahBarrierC2Support::expand(C, igvn);
-}
-
-bool ShenandoahBarrierSetC2::optimize_loops(PhaseIdealLoop* phase, LoopOptsMode mode, VectorSet& visited, Node_Stack& nstack, Node_List& worklist) const {
-  if (mode == LoopOptsShenandoahExpand) {
-    assert(UseShenandoahGC, "only for shenandoah");
-    ShenandoahBarrierC2Support::pin_and_expand(phase);
-    return true;
+  ResourceMark rm;
+  VectorSet visited;
+  Node_List worklist;
+  worklist.push(C->root());
+  while (worklist.size() > 0) {
+    Node* n = worklist.pop();
+    if (visited.test_set(n->_idx)) {
+      continue;
+    }
+    refine_barrier_by_new_val_type(n);
+    for (uint j = 0; j < n->req(); j++) {
+      Node* in = n->in(j);
+      if (in != nullptr) {
+        worklist.push(in);
+      }
+    }
   }
   return false;
 }
 
 bool ShenandoahBarrierSetC2::array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, bool is_clone_instance, ArrayCopyPhase phase) const {
@@ -943,380 +501,118 @@
   }
 }
 
 
 // Support for macro expanded GC barriers
-void ShenandoahBarrierSetC2::register_potential_barrier_node(Node* node) const {
-  if (node->Opcode() == Op_ShenandoahLoadReferenceBarrier) {
-    state()->add_load_reference_barrier((ShenandoahLoadReferenceBarrierNode*) node);
-  }
-}
-
-void ShenandoahBarrierSetC2::unregister_potential_barrier_node(Node* node) const {
-  if (node->Opcode() == Op_ShenandoahLoadReferenceBarrier) {
-    state()->remove_load_reference_barrier((ShenandoahLoadReferenceBarrierNode*) node);
+void ShenandoahBarrierSetC2::eliminate_gc_barrier_data(Node* node) const {
+  if (node->is_LoadStore()) {
+    LoadStoreNode* loadstore = node->as_LoadStore();
+    loadstore->set_barrier_data(0);
+  } else if (node->is_Mem()) {
+    MemNode* mem = node->as_Mem();
+    mem->set_barrier_data(0);
   }
 }
 
 void ShenandoahBarrierSetC2::eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const {
-  if (is_shenandoah_wb_pre_call(node)) {
-    shenandoah_eliminate_wb_pre(node, &macro->igvn());
-  }
-  if (ShenandoahCardBarrier && node->Opcode() == Op_CastP2X) {
-    Node* shift = node->unique_out();
-    Node* addp = shift->unique_out();
-    for (DUIterator_Last jmin, j = addp->last_outs(jmin); j >= jmin; --j) {
-      Node* mem = addp->last_out(j);
-      if (UseCondCardMark && mem->is_Load()) {
-        assert(mem->Opcode() == Op_LoadB, "unexpected code shape");
-        // The load is checking if the card has been written so
-        // replace it with zero to fold the test.
-        macro->replace_node(mem, macro->intcon(0));
-        continue;
-      }
-      assert(mem->is_Store(), "store required");
-      macro->replace_node(mem, mem->in(MemNode::Memory));
-    }
-  }
-}
-
-void ShenandoahBarrierSetC2::shenandoah_eliminate_wb_pre(Node* call, PhaseIterGVN* igvn) const {
-  assert(UseShenandoahGC && is_shenandoah_wb_pre_call(call), "");
-  Node* c = call->as_Call()->proj_out(TypeFunc::Control);
-  c = c->unique_ctrl_out();
-  assert(c->is_Region() && c->req() == 3, "where's the pre barrier control flow?");
-  c = c->unique_ctrl_out();
-  assert(c->is_Region() && c->req() == 3, "where's the pre barrier control flow?");
-  Node* iff = c->in(1)->is_IfProj() ? c->in(1)->in(0) : c->in(2)->in(0);
-  assert(iff->is_If(), "expect test");
-  if (!is_shenandoah_marking_if(igvn, iff)) {
-    c = c->unique_ctrl_out();
-    assert(c->is_Region() && c->req() == 3, "where's the pre barrier control flow?");
-    iff = c->in(1)->is_IfProj() ? c->in(1)->in(0) : c->in(2)->in(0);
-    assert(is_shenandoah_marking_if(igvn, iff), "expect marking test");
-  }
-  Node* cmpx = iff->in(1)->in(1);
-  igvn->replace_node(cmpx, igvn->makecon(TypeInt::CC_EQ));
-  igvn->rehash_node_delayed(call);
-  call->del_req(call->req()-1);
-}
-
-void ShenandoahBarrierSetC2::enqueue_useful_gc_barrier(PhaseIterGVN* igvn, Node* node) const {
-  if (node->Opcode() == Op_AddP && ShenandoahBarrierSetC2::has_only_shenandoah_wb_pre_uses(node)) {
-    igvn->add_users_to_worklist(node);
-  }
-}
-
-void ShenandoahBarrierSetC2::eliminate_useless_gc_barriers(Unique_Node_List &useful, Compile* C) const {
-  for (uint i = 0; i < useful.size(); i++) {
-    Node* n = useful.at(i);
-    if (n->Opcode() == Op_AddP && ShenandoahBarrierSetC2::has_only_shenandoah_wb_pre_uses(n)) {
-      for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
-        C->record_for_igvn(n->fast_out(i));
-      }
-    }
-  }
-
-  for (int i = state()->load_reference_barriers_count() - 1; i >= 0; i--) {
-    ShenandoahLoadReferenceBarrierNode* n = state()->load_reference_barrier(i);
-    if (!useful.member(n)) {
-      state()->remove_load_reference_barrier(n);
-    }
-  }
+  eliminate_gc_barrier_data(node);
 }
 
 void* ShenandoahBarrierSetC2::create_barrier_state(Arena* comp_arena) const {
   return new(comp_arena) ShenandoahBarrierSetC2State(comp_arena);
 }
 
 ShenandoahBarrierSetC2State* ShenandoahBarrierSetC2::state() const {
   return reinterpret_cast<ShenandoahBarrierSetC2State*>(Compile::current()->barrier_set_state());
 }
 
-// If the BarrierSetC2 state has kept macro nodes in its compilation unit state to be
-// expanded later, then now is the time to do so.
-bool ShenandoahBarrierSetC2::expand_macro_nodes(PhaseMacroExpand* macro) const { return false; }
-
 #ifdef ASSERT
 void ShenandoahBarrierSetC2::verify_gc_barriers(Compile* compile, CompilePhase phase) const {
-  if (ShenandoahVerifyOptoBarriers && phase == BarrierSetC2::BeforeMacroExpand) {
-    ShenandoahBarrierC2Support::verify(Compile::current()->root());
-  } else if (phase == BarrierSetC2::BeforeCodeGen) {
-    // Verify Shenandoah pre-barriers
-    const int gc_state_offset = in_bytes(ShenandoahThreadLocalData::gc_state_offset());
-
-    Unique_Node_List visited;
-    Node_List worklist;
-    // We're going to walk control flow backwards starting from the Root
-    worklist.push(compile->root());
-    while (worklist.size() > 0) {
-      Node *x = worklist.pop();
-      if (x == nullptr || x == compile->top()) {
-        continue;
-      }
-
-      if (visited.member(x)) {
-        continue;
-      } else {
-        visited.push(x);
-      }
-
-      if (x->is_Region()) {
-        for (uint i = 1; i < x->req(); i++) {
-          worklist.push(x->in(i));
-        }
-      } else {
-        worklist.push(x->in(0));
-        // We are looking for the pattern:
-        //                            /->ThreadLocal
-        // If->Bool->CmpI->LoadB->AddP->ConL(marking_offset)
-        //              \->ConI(0)
-        // We want to verify that the If and the LoadB have the same control
-        // See GraphKit::g1_write_barrier_pre()
-        if (x->is_If()) {
-          IfNode *iff = x->as_If();
-          if (iff->in(1)->is_Bool() && iff->in(1)->in(1)->is_Cmp()) {
-            CmpNode *cmp = iff->in(1)->in(1)->as_Cmp();
-            if (cmp->Opcode() == Op_CmpI && cmp->in(2)->is_Con() && cmp->in(2)->bottom_type()->is_int()->get_con() == 0
-                && cmp->in(1)->is_Load()) {
-              LoadNode *load = cmp->in(1)->as_Load();
-              if (load->Opcode() == Op_LoadB && load->in(2)->is_AddP() && load->in(2)->in(2)->Opcode() == Op_ThreadLocal
-                  && load->in(2)->in(3)->is_Con()
-                  && load->in(2)->in(3)->bottom_type()->is_intptr_t()->get_con() == gc_state_offset) {
-
-                Node *if_ctrl = iff->in(0);
-                Node *load_ctrl = load->in(0);
-
-                if (if_ctrl != load_ctrl) {
-                  // Skip possible CProj->NeverBranch in infinite loops
-                  if ((if_ctrl->is_Proj() && if_ctrl->Opcode() == Op_CProj)
-                      && if_ctrl->in(0)->is_NeverBranch()) {
-                    if_ctrl = if_ctrl->in(0)->in(0);
-                  }
-                }
-                assert(load_ctrl != nullptr && if_ctrl == load_ctrl, "controls must match");
-              }
-            }
-          }
-        }
-      }
-    }
-  }
+  // TODO: Re-implement C2 barrier verification.
 }
 #endif
 
-Node* ShenandoahBarrierSetC2::ideal_node(PhaseGVN* phase, Node* n, bool can_reshape) const {
-  if (is_shenandoah_wb_pre_call(n)) {
-    uint cnt = ShenandoahBarrierSetC2::write_barrier_pre_Type()->domain()->cnt();
-    if (n->req() > cnt) {
-      Node* addp = n->in(cnt);
-      if (has_only_shenandoah_wb_pre_uses(addp)) {
-        n->del_req(cnt);
-        if (can_reshape) {
-          phase->is_IterGVN()->_worklist.push(addp);
-        }
-        return n;
-      }
-    }
+static ShenandoahBarrierSetC2State* barrier_set_state() {
+  return reinterpret_cast<ShenandoahBarrierSetC2State*>(Compile::current()->barrier_set_state());
+}
+
+int ShenandoahBarrierSetC2::estimate_stub_size() const {
+  Compile* const C = Compile::current();
+  BufferBlob* const blob = C->output()->scratch_buffer_blob();
+  GrowableArray<ShenandoahBarrierStubC2*>* const stubs = barrier_set_state()->stubs();
+  int size = 0;
+
+  for (int i = 0; i < stubs->length(); i++) {
+    CodeBuffer cb(blob->content_begin(), checked_cast<CodeBuffer::csize_t>((address)C->output()->scratch_locs_memory() - blob->content_begin()));
+    MacroAssembler masm(&cb);
+    stubs->at(i)->emit_code(masm);
+    size += cb.insts_size();
   }
-  if (n->Opcode() == Op_CmpP) {
-    Node* in1 = n->in(1);
-    Node* in2 = n->in(2);
-
-    // If one input is null, then step over the strong LRB barriers on the other input
-    if (in1->bottom_type() == TypePtr::NULL_PTR &&
-        !((in2->Opcode() == Op_ShenandoahLoadReferenceBarrier) &&
-          !ShenandoahBarrierSet::is_strong_access(((ShenandoahLoadReferenceBarrierNode*)in2)->decorators()))) {
-      in2 = step_over_gc_barrier(in2);
-    }
-    if (in2->bottom_type() == TypePtr::NULL_PTR &&
-        !((in1->Opcode() == Op_ShenandoahLoadReferenceBarrier) &&
-          !ShenandoahBarrierSet::is_strong_access(((ShenandoahLoadReferenceBarrierNode*)in1)->decorators()))) {
-      in1 = step_over_gc_barrier(in1);
-    }
 
-    if (in1 != n->in(1)) {
-      n->set_req_X(1, in1, phase);
-      assert(in2 == n->in(2), "only one change");
-      return n;
-    }
-    if (in2 != n->in(2)) {
-      n->set_req_X(2, in2, phase);
-      return n;
-    }
-  } else if (can_reshape &&
-             n->Opcode() == Op_If &&
-             ShenandoahBarrierC2Support::is_heap_stable_test(n) &&
-             n->in(0) != nullptr &&
-             n->outcnt() == 2) {
-    Node* dom = n->in(0);
-    Node* prev_dom = n;
-    int op = n->Opcode();
-    int dist = 16;
-    // Search up the dominator tree for another heap stable test
-    while (dom->Opcode() != op    ||  // Not same opcode?
-           !ShenandoahBarrierC2Support::is_heap_stable_test(dom) ||  // Not same input 1?
-           prev_dom->in(0) != dom) {  // One path of test does not dominate?
-      if (dist < 0) return nullptr;
-
-      dist--;
-      prev_dom = dom;
-      dom = IfNode::up_one_dom(dom);
-      if (!dom) return nullptr;
-    }
+  return size;
+}
+
+void ShenandoahBarrierSetC2::emit_stubs(CodeBuffer& cb) const {
+  MacroAssembler masm(&cb);
+  GrowableArray<ShenandoahBarrierStubC2*>* const stubs = barrier_set_state()->stubs();
+  barrier_set_state()->set_stubs_start_offset(masm.offset());
 
-    // Check that we did not follow a loop back to ourselves
-    if (n == dom) {
-      return nullptr;
+  for (int i = 0; i < stubs->length(); i++) {
+    // Make sure there is enough space in the code buffer
+    if (cb.insts()->maybe_expand_to_ensure_remaining(PhaseOutput::MAX_inst_size) && cb.blob() == nullptr) {
+      ciEnv::current()->record_failure("CodeCache is full");
+      return;
     }
 
-    return n->as_If()->dominated_by(prev_dom, phase->is_IterGVN(), false);
+    stubs->at(i)->emit_code(masm);
   }
 
-  return nullptr;
+  masm.flush();
+
 }
 
-bool ShenandoahBarrierSetC2::has_only_shenandoah_wb_pre_uses(Node* n) {
-  for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
-    Node* u = n->fast_out(i);
-    if (!is_shenandoah_wb_pre_call(u)) {
-      return false;
-    }
+void ShenandoahBarrierStubC2::register_stub() {
+  if (!Compile::current()->output()->in_scratch_emit_size()) {
+    barrier_set_state()->stubs()->append(this);
   }
-  return n->outcnt() > 0;
 }
 
-bool ShenandoahBarrierSetC2::final_graph_reshaping(Compile* compile, Node* n, uint opcode, Unique_Node_List& dead_nodes) const {
-  switch (opcode) {
-    case Op_CallLeaf:
-    case Op_CallLeafNoFP: {
-      assert (n->is_Call(), "");
-      CallNode *call = n->as_Call();
-      if (ShenandoahBarrierSetC2::is_shenandoah_wb_pre_call(call)) {
-        uint cnt = ShenandoahBarrierSetC2::write_barrier_pre_Type()->domain()->cnt();
-        if (call->req() > cnt) {
-          assert(call->req() == cnt + 1, "only one extra input");
-          Node *addp = call->in(cnt);
-          assert(!ShenandoahBarrierSetC2::has_only_shenandoah_wb_pre_uses(addp), "useless address computation?");
-          call->del_req(cnt);
-        }
-      }
-      return false;
-    }
-    case Op_ShenandoahCompareAndSwapP:
-    case Op_ShenandoahCompareAndSwapN:
-    case Op_ShenandoahWeakCompareAndSwapN:
-    case Op_ShenandoahWeakCompareAndSwapP:
-    case Op_ShenandoahCompareAndExchangeP:
-    case Op_ShenandoahCompareAndExchangeN:
-      return true;
-    case Op_ShenandoahLoadReferenceBarrier:
-      assert(false, "should have been expanded already");
-      return true;
-    default:
-      return false;
-  }
+ShenandoahLoadRefBarrierStubC2* ShenandoahLoadRefBarrierStubC2::create(const MachNode* node, Register obj, Register addr, Register tmp1, Register tmp2, Register tmp3, bool narrow) {
+  auto* stub = new (Compile::current()->comp_arena()) ShenandoahLoadRefBarrierStubC2(node, obj, addr, tmp1, tmp2, tmp3, narrow);
+  stub->register_stub();
+  return stub;
 }
 
-bool ShenandoahBarrierSetC2::escape_add_to_con_graph(ConnectionGraph* conn_graph, PhaseGVN* gvn, Unique_Node_List* delayed_worklist, Node* n, uint opcode) const {
-  switch (opcode) {
-    case Op_ShenandoahCompareAndExchangeP:
-    case Op_ShenandoahCompareAndExchangeN:
-      conn_graph->add_objload_to_connection_graph(n, delayed_worklist);
-      // fallthrough
-    case Op_ShenandoahWeakCompareAndSwapP:
-    case Op_ShenandoahWeakCompareAndSwapN:
-    case Op_ShenandoahCompareAndSwapP:
-    case Op_ShenandoahCompareAndSwapN:
-      conn_graph->add_to_congraph_unsafe_access(n, opcode, delayed_worklist);
-      return true;
-    case Op_StoreP: {
-      Node* adr = n->in(MemNode::Address);
-      const Type* adr_type = gvn->type(adr);
-      // Pointer stores in Shenandoah barriers looks like unsafe access.
-      // Ignore such stores to be able scalar replace non-escaping
-      // allocations.
-      if (adr_type->isa_rawptr() && adr->is_AddP()) {
-        Node* base = conn_graph->get_addp_base(adr);
-        if (base->Opcode() == Op_LoadP &&
-          base->in(MemNode::Address)->is_AddP()) {
-          adr = base->in(MemNode::Address);
-          Node* tls = conn_graph->get_addp_base(adr);
-          if (tls->Opcode() == Op_ThreadLocal) {
-             int offs = (int) gvn->find_intptr_t_con(adr->in(AddPNode::Offset), Type::OffsetBot);
-             const int buf_offset = in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset());
-             if (offs == buf_offset) {
-               return true; // Pre barrier previous oop value store.
-             }
-          }
-        }
-      }
-      return false;
-    }
-    case Op_ShenandoahLoadReferenceBarrier:
-      conn_graph->add_local_var_and_edge(n, PointsToNode::NoEscape, n->in(ShenandoahLoadReferenceBarrierNode::ValueIn), delayed_worklist);
-      return true;
-    default:
-      // Nothing
-      break;
-  }
-  return false;
+ShenandoahSATBBarrierStubC2* ShenandoahSATBBarrierStubC2::create(const MachNode* node, Register addr, Register preval, Register tmp) {
+  auto* stub = new (Compile::current()->comp_arena()) ShenandoahSATBBarrierStubC2(node, addr, preval, tmp);
+  stub->register_stub();
+  return stub;
 }
 
-bool ShenandoahBarrierSetC2::escape_add_final_edges(ConnectionGraph* conn_graph, PhaseGVN* gvn, Node* n, uint opcode) const {
-  switch (opcode) {
-    case Op_ShenandoahCompareAndExchangeP:
-    case Op_ShenandoahCompareAndExchangeN: {
-      Node *adr = n->in(MemNode::Address);
-      conn_graph->add_local_var_and_edge(n, PointsToNode::NoEscape, adr, nullptr);
-      // fallthrough
-    }
-    case Op_ShenandoahCompareAndSwapP:
-    case Op_ShenandoahCompareAndSwapN:
-    case Op_ShenandoahWeakCompareAndSwapP:
-    case Op_ShenandoahWeakCompareAndSwapN:
-      return conn_graph->add_final_edges_unsafe_access(n, opcode);
-    case Op_ShenandoahLoadReferenceBarrier:
-      conn_graph->add_local_var_and_edge(n, PointsToNode::NoEscape, n->in(ShenandoahLoadReferenceBarrierNode::ValueIn), nullptr);
-      return true;
-    default:
-      // Nothing
-      break;
-  }
-  return false;
+ShenandoahCASBarrierSlowStubC2* ShenandoahCASBarrierSlowStubC2::create(const MachNode* node, Register addr, Register expected, Register new_val, Register result, Register tmp, bool cae, bool acquire, bool release, bool weak) {
+  auto* stub = new (Compile::current()->comp_arena()) ShenandoahCASBarrierSlowStubC2(node, addr, Address(), expected, new_val, result, tmp, noreg, cae, acquire, release, weak);
+  stub->register_stub();
+  return stub;
 }
 
-bool ShenandoahBarrierSetC2::escape_has_out_with_unsafe_object(Node* n) const {
-  return n->has_out_with(Op_ShenandoahCompareAndExchangeP) || n->has_out_with(Op_ShenandoahCompareAndExchangeN) ||
-         n->has_out_with(Op_ShenandoahCompareAndSwapP, Op_ShenandoahCompareAndSwapN, Op_ShenandoahWeakCompareAndSwapP, Op_ShenandoahWeakCompareAndSwapN);
+ShenandoahCASBarrierSlowStubC2* ShenandoahCASBarrierSlowStubC2::create(const MachNode* node, Address addr, Register expected, Register new_val, Register result, Register tmp1, Register tmp2, bool cae) {
+  auto* stub = new (Compile::current()->comp_arena()) ShenandoahCASBarrierSlowStubC2(node, noreg, addr, expected, new_val, result, tmp1, tmp2, cae, false, false, false);
+  stub->register_stub();
+  return stub;
+}
 
+ShenandoahCASBarrierMidStubC2* ShenandoahCASBarrierMidStubC2::create(const MachNode* node, ShenandoahCASBarrierSlowStubC2* slow_stub, Register expected, Register result, Register tmp, bool cae) {
+  auto* stub = new (Compile::current()->comp_arena()) ShenandoahCASBarrierMidStubC2(node, slow_stub, expected, result, tmp, cae);
+  stub->register_stub();
+  return stub;
 }
 
-bool ShenandoahBarrierSetC2::matcher_find_shared_post_visit(Matcher* matcher, Node* n, uint opcode) const {
-  switch (opcode) {
-    case Op_ShenandoahCompareAndExchangeP:
-    case Op_ShenandoahCompareAndExchangeN:
-    case Op_ShenandoahWeakCompareAndSwapP:
-    case Op_ShenandoahWeakCompareAndSwapN:
-    case Op_ShenandoahCompareAndSwapP:
-    case Op_ShenandoahCompareAndSwapN: {   // Convert trinary to binary-tree
-      Node* newval = n->in(MemNode::ValueIn);
-      Node* oldval = n->in(LoadStoreConditionalNode::ExpectedIn);
-      Node* pair = new BinaryNode(oldval, newval);
-      n->set_req(MemNode::ValueIn,pair);
-      n->del_req(LoadStoreConditionalNode::ExpectedIn);
-      return true;
-    }
-    default:
-      break;
-  }
-  return false;
+bool ShenandoahBarrierSetC2State::needs_liveness_data(const MachNode* mach) const {
+  //assert(mach->barrier_data() != 0, "what else?");
+  // return mach->barrier_data() != 0;
+  //return (mach->barrier_data() & ShenandoahSATBBarrier) != 0;
+  return ShenandoahSATBBarrierStubC2::needs_barrier(mach) || ShenandoahLoadRefBarrierStubC2::needs_barrier(mach);
 }
 
-bool ShenandoahBarrierSetC2::matcher_is_store_load_barrier(Node* x, uint xop) const {
-  return xop == Op_ShenandoahCompareAndExchangeP ||
-         xop == Op_ShenandoahCompareAndExchangeN ||
-         xop == Op_ShenandoahWeakCompareAndSwapP ||
-         xop == Op_ShenandoahWeakCompareAndSwapN ||
-         xop == Op_ShenandoahCompareAndSwapN ||
-         xop == Op_ShenandoahCompareAndSwapP;
+bool ShenandoahBarrierSetC2State::needs_livein_data() const {
+  return true;
 }
diff a/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.hpp b/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.hpp
--- a/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.hpp
+++ b/src/hotspot/share/gc/shenandoah/c2/shenandoahBarrierSetC2.hpp
@@ -23,64 +23,48 @@
  */
 
 #ifndef SHARE_GC_SHENANDOAH_C2_SHENANDOAHBARRIERSETC2_HPP
 #define SHARE_GC_SHENANDOAH_C2_SHENANDOAHBARRIERSETC2_HPP
 
+#include "shenandoahBarrierSetC2.hpp"
 #include "gc/shared/c2/barrierSetC2.hpp"
-#include "gc/shenandoah/c2/shenandoahSupport.hpp"
 #include "utilities/growableArray.hpp"
 
-class ShenandoahBarrierSetC2State : public ArenaObj {
-private:
-  GrowableArray<ShenandoahLoadReferenceBarrierNode*>* _load_reference_barriers;
+static const uint8_t ShenandoahBarrierStrong          = 1 << 0;
+static const uint8_t ShenandoahBarrierWeak            = 1 << 1;
+static const uint8_t ShenandoahBarrierPhantom         = 1 << 2;
+static const uint8_t ShenandoahBarrierNative          = 1 << 3;
+static const uint8_t ShenandoahBarrierElided          = 1 << 4;
+static const uint8_t ShenandoahBarrierSATB            = 1 << 5;
+static const uint8_t ShenandoahBarrierCardMark        = 1 << 6;
+static const uint8_t ShenandoahBarrierCardMarkNotNull = 1 << 7;
+
+class ShenandoahBarrierStubC2;
+
+class ShenandoahBarrierSetC2State : public BarrierSetC2State {
+  GrowableArray<ShenandoahBarrierStubC2*>* _stubs;
+  int _stubs_start_offset;
 
 public:
-  ShenandoahBarrierSetC2State(Arena* comp_arena);
+  explicit ShenandoahBarrierSetC2State(Arena* comp_arena);
 
-  int load_reference_barriers_count() const;
-  ShenandoahLoadReferenceBarrierNode* load_reference_barrier(int idx) const;
-  void add_load_reference_barrier(ShenandoahLoadReferenceBarrierNode* n);
-  void remove_load_reference_barrier(ShenandoahLoadReferenceBarrierNode * n);
-};
+  bool needs_liveness_data(const MachNode* mach) const override;
+  bool needs_livein_data() const override;
+
+  GrowableArray<ShenandoahBarrierStubC2*>* stubs() {
+    return _stubs;
+  }
+
+  void set_stubs_start_offset(int offset) {
+    _stubs_start_offset = offset;
+  }
+
+  int stubs_start_offset() {
+    return _stubs_start_offset;
+  }};
 
 class ShenandoahBarrierSetC2 : public BarrierSetC2 {
-private:
-  void shenandoah_eliminate_wb_pre(Node* call, PhaseIterGVN* igvn) const;
-
-  bool satb_can_remove_pre_barrier(GraphKit* kit, PhaseValues* phase, Node* adr,
-                                   BasicType bt, uint adr_idx) const;
-  void satb_write_barrier_pre(GraphKit* kit, bool do_load,
-                              Node* obj,
-                              Node* adr,
-                              uint alias_idx,
-                              Node* val,
-                              const TypeOopPtr* val_type,
-                              Node* pre_val,
-                              BasicType bt) const;
-
-  void shenandoah_write_barrier_pre(GraphKit* kit,
-                                    bool do_load,
-                                    Node* obj,
-                                    Node* adr,
-                                    uint alias_idx,
-                                    Node* val,
-                                    const TypeOopPtr* val_type,
-                                    Node* pre_val,
-                                    BasicType bt) const;
-
-  void post_barrier(GraphKit* kit,
-                    Node* ctl,
-                    Node* store,
-                    Node* obj,
-                    Node* adr,
-                    uint adr_idx,
-                    Node* val,
-                    BasicType bt,
-                    bool use_precise) const;
-
-  void insert_pre_barrier(GraphKit* kit, Node* base_oop, Node* offset,
-                          Node* pre_val, bool need_mem_bar) const;
 
   static bool clone_needs_barrier(Node* src, PhaseGVN& gvn);
 
 protected:
   virtual Node* load_at_resolved(C2Access& access, const Type* val_type) const;
@@ -92,64 +76,119 @@
   virtual Node* atomic_xchg_at_resolved(C2AtomicParseAccess& access, Node* new_val, const Type* val_type) const;
 
 public:
   static ShenandoahBarrierSetC2* bsc2();
 
-  static bool is_shenandoah_wb_pre_call(Node* call);
   static bool is_shenandoah_clone_call(Node* call);
-  static bool is_shenandoah_lrb_call(Node* call);
-  static bool is_shenandoah_marking_if(PhaseValues* phase, Node* n);
-  static bool is_shenandoah_state_load(Node* n);
-  static bool has_only_shenandoah_wb_pre_uses(Node* n);
 
   ShenandoahBarrierSetC2State* state() const;
 
-  static const TypeFunc* write_barrier_pre_Type();
   static const TypeFunc* clone_barrier_Type();
-  static const TypeFunc* load_reference_barrier_Type();
-  virtual bool has_load_barrier_nodes() const { return true; }
 
   // This is the entry-point for the backend to perform accesses through the Access API.
   virtual void clone_at_expansion(PhaseMacroExpand* phase, ArrayCopyNode* ac) const;
 
   // These are general helper methods used by C2
   virtual bool array_copy_requires_gc_barriers(bool tightly_coupled_alloc, BasicType type, bool is_clone, bool is_clone_instance, ArrayCopyPhase phase) const;
 
   // Support for GC barriers emitted during parsing
-  virtual bool is_gc_pre_barrier_node(Node* node) const;
   virtual bool is_gc_barrier_node(Node* node) const;
-  virtual Node* step_over_gc_barrier(Node* c) const;
   virtual bool expand_barriers(Compile* C, PhaseIterGVN& igvn) const;
-  virtual bool optimize_loops(PhaseIdealLoop* phase, LoopOptsMode mode, VectorSet& visited, Node_Stack& nstack, Node_List& worklist) const;
-  virtual bool strip_mined_loops_expanded(LoopOptsMode mode) const { return mode == LoopOptsShenandoahExpand; }
-  virtual bool is_gc_specific_loop_opts_pass(LoopOptsMode mode) const { return mode == LoopOptsShenandoahExpand; }
 
   // Support for macro expanded GC barriers
-  virtual void register_potential_barrier_node(Node* node) const;
-  virtual void unregister_potential_barrier_node(Node* node) const;
   virtual void eliminate_gc_barrier(PhaseMacroExpand* macro, Node* node) const;
-  virtual void enqueue_useful_gc_barrier(PhaseIterGVN* igvn, Node* node) const;
-  virtual void eliminate_useless_gc_barriers(Unique_Node_List &useful, Compile* C) const;
+  virtual void eliminate_gc_barrier_data(Node* node) const;
 
   // Allow barrier sets to have shared state that is preserved across a compilation unit.
   // This could for example comprise macro nodes to be expanded during macro expansion.
   virtual void* create_barrier_state(Arena* comp_arena) const;
-  // If the BarrierSetC2 state has kept macro nodes in its compilation unit state to be
-  // expanded later, then now is the time to do so.
-  virtual bool expand_macro_nodes(PhaseMacroExpand* macro) const;
 
 #ifdef ASSERT
   virtual void verify_gc_barriers(Compile* compile, CompilePhase phase) const;
 #endif
 
-  virtual Node* ideal_node(PhaseGVN* phase, Node* n, bool can_reshape) const;
-  virtual bool final_graph_reshaping(Compile* compile, Node* n, uint opcode, Unique_Node_List& dead_nodes) const;
+  int estimate_stub_size() const /* override */;
+  void emit_stubs(CodeBuffer& cb) const /* override */;
+  void late_barrier_analysis() const /* override*/ {
+    compute_liveness_at_stubs();
+  }
+
+};
+
+class ShenandoahBarrierStubC2 : public BarrierStubC2 {
+protected:
+  explicit ShenandoahBarrierStubC2(const MachNode* node) : BarrierStubC2(node) {}
+  void register_stub();
+public:
+  virtual void emit_code(MacroAssembler& masm) = 0;
+};
+
+class ShenandoahLoadRefBarrierStubC2 : public ShenandoahBarrierStubC2 {
+  Register _obj;
+  Register _addr;
+  Register _tmp1;
+  Register _tmp2;
+  Register _tmp3;
+  bool _narrow;
+  ShenandoahLoadRefBarrierStubC2(const MachNode* node, Register obj, Register addr, Register tmp1, Register tmp2, Register tmp3, bool narrow) :
+    ShenandoahBarrierStubC2(node), _obj(obj), _addr(addr), _tmp1(tmp1), _tmp2(tmp2), _tmp3(tmp3), _narrow(narrow) {}
+public:
+  static bool needs_barrier(const MachNode* node) {
+    return (node->barrier_data() & (ShenandoahBarrierStrong | ShenandoahBarrierWeak | ShenandoahBarrierPhantom | ShenandoahBarrierNative)) != 0;
+  }
+  static ShenandoahLoadRefBarrierStubC2* create(const MachNode* node, Register obj, Register addr, Register tmp1, Register tmp2, Register tmp3, bool narrow);
+  void emit_code(MacroAssembler& masm) override;
+};
+
+class ShenandoahSATBBarrierStubC2 : public ShenandoahBarrierStubC2 {
+  Register _addr;
+  Register _preval;
+  Register _tmp;
+  ShenandoahSATBBarrierStubC2(const MachNode* node, Register addr, Register preval, Register tmp) :
+    ShenandoahBarrierStubC2(node), _addr(addr), _preval(preval), _tmp(tmp) {}
+
+public:
+  static bool needs_barrier(const MachNode* node) {
+    return (node->barrier_data() & ShenandoahBarrierSATB) != 0;
+  }
+  static ShenandoahSATBBarrierStubC2* create(const MachNode* node, Register addr, Register preval, Register tmp = noreg);
+
+  void emit_code(MacroAssembler& masm) override;
+};
+
+class ShenandoahCASBarrierSlowStubC2 : public ShenandoahBarrierStubC2 {
+  Register _addr_reg;
+  Address  _addr;
+  Register _expected;
+  Register _new_val;
+  Register _result;
+  Register _tmp1;
+  Register _tmp2;
+  bool     _cae;
+  bool     _acquire;
+  bool     _release;
+  bool     _weak;
+
+  explicit ShenandoahCASBarrierSlowStubC2(const MachNode* node, Register addr_reg, Address addr, Register expected, Register new_val, Register result, Register tmp1, Register tmp2, bool cae, bool acquire, bool release, bool weak) :
+    ShenandoahBarrierStubC2(node),
+    _addr_reg(addr_reg), _addr(addr), _expected(expected), _new_val(new_val), _result(result), _tmp1(tmp1), _tmp2(tmp2), _cae(cae), _acquire(acquire), _release(release),  _weak(weak) {}
 
-  virtual bool escape_add_to_con_graph(ConnectionGraph* conn_graph, PhaseGVN* gvn, Unique_Node_List* delayed_worklist, Node* n, uint opcode) const;
-  virtual bool escape_add_final_edges(ConnectionGraph* conn_graph, PhaseGVN* gvn, Node* n, uint opcode) const;
-  virtual bool escape_has_out_with_unsafe_object(Node* n) const;
+public:
+  static ShenandoahCASBarrierSlowStubC2* create(const MachNode* node, Register addr, Register expected, Register new_val, Register result, Register tmp, bool cae, bool acquire, bool release, bool weak);
+  static ShenandoahCASBarrierSlowStubC2* create(const MachNode* node, Address addr, Register expected, Register new_val, Register result, Register tmp1, Register tmp2, bool cae);
+  void emit_code(MacroAssembler& masm) override;
+};
 
-  virtual bool matcher_find_shared_post_visit(Matcher* matcher, Node* n, uint opcode) const;
-  virtual bool matcher_is_store_load_barrier(Node* x, uint xop) const;
+class ShenandoahCASBarrierMidStubC2 : public ShenandoahBarrierStubC2 {
+  ShenandoahCASBarrierSlowStubC2* _slow_stub;
+  Register _expected;
+  Register _result;
+  Register _tmp;
+  bool _cae;
+  ShenandoahCASBarrierMidStubC2(const MachNode* node, ShenandoahCASBarrierSlowStubC2* slow_stub, Register expected, Register result, Register tmp, bool cae) :
+    ShenandoahBarrierStubC2(node), _slow_stub(slow_stub), _expected(expected), _result(result), _tmp(tmp), _cae(cae) {}
+public:
+  static ShenandoahCASBarrierMidStubC2* create(const MachNode* node, ShenandoahCASBarrierSlowStubC2* slow_stub, Register expected, Register result, Register tmp, bool cae);
+  void emit_code(MacroAssembler& masm) override;
 };
 
 #endif // SHARE_GC_SHENANDOAH_C2_SHENANDOAHBARRIERSETC2_HPP
diff a/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.cpp b/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.cpp
--- a/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.cpp
+++ /dev/null
@@ -1,2513 +0,0 @@
-/*
- * Copyright (c) 2015, 2021, Red Hat, Inc. All rights reserved.
- * Copyright (C) 2022, Tencent. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-
-#include "classfile/javaClasses.hpp"
-#include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
-#include "gc/shenandoah/c2/shenandoahSupport.hpp"
-#include "gc/shenandoah/shenandoahBarrierSetAssembler.hpp"
-#include "gc/shenandoah/shenandoahForwarding.hpp"
-#include "gc/shenandoah/shenandoahHeap.hpp"
-#include "gc/shenandoah/shenandoahHeapRegion.hpp"
-#include "gc/shenandoah/shenandoahRuntime.hpp"
-#include "gc/shenandoah/shenandoahThreadLocalData.hpp"
-#include "opto/arraycopynode.hpp"
-#include "opto/block.hpp"
-#include "opto/callnode.hpp"
-#include "opto/castnode.hpp"
-#include "opto/movenode.hpp"
-#include "opto/phaseX.hpp"
-#include "opto/rootnode.hpp"
-#include "opto/runtime.hpp"
-#include "opto/subnode.hpp"
-
-bool ShenandoahBarrierC2Support::expand(Compile* C, PhaseIterGVN& igvn) {
-  ShenandoahBarrierSetC2State* state = ShenandoahBarrierSetC2::bsc2()->state();
-  if (state->load_reference_barriers_count() > 0) {
-    assert(C->post_loop_opts_phase(), "no loop opts allowed");
-    C->reset_post_loop_opts_phase(); // ... but we know what we are doing
-    C->clear_major_progress();
-    PhaseIdealLoop::optimize(igvn, LoopOptsShenandoahExpand);
-    if (C->failing()) return false;
-    C->process_for_post_loop_opts_igvn(igvn);
-    if (C->failing()) return false;
-
-    C->set_post_loop_opts_phase(); // now for real!
-  }
-  return true;
-}
-
-bool ShenandoahBarrierC2Support::is_gc_state_test(Node* iff, int mask) {
-  if (!UseShenandoahGC) {
-    return false;
-  }
-  assert(iff->is_If(), "bad input");
-  if (iff->Opcode() != Op_If) {
-    return false;
-  }
-  Node* bol = iff->in(1);
-  if (!bol->is_Bool() || bol->as_Bool()->_test._test != BoolTest::ne) {
-    return false;
-  }
-  Node* cmp = bol->in(1);
-  if (cmp->Opcode() != Op_CmpI) {
-    return false;
-  }
-  Node* in1 = cmp->in(1);
-  Node* in2 = cmp->in(2);
-  if (in2->find_int_con(-1) != 0) {
-    return false;
-  }
-  if (in1->Opcode() != Op_AndI) {
-    return false;
-  }
-  in2 = in1->in(2);
-  if (in2->find_int_con(-1) != mask) {
-    return false;
-  }
-  in1 = in1->in(1);
-
-  return is_gc_state_load(in1);
-}
-
-bool ShenandoahBarrierC2Support::is_heap_stable_test(Node* iff) {
-  return is_gc_state_test(iff, ShenandoahHeap::HAS_FORWARDED);
-}
-
-bool ShenandoahBarrierC2Support::is_gc_state_load(Node *n) {
-  if (!UseShenandoahGC) {
-    return false;
-  }
-  if (n->Opcode() != Op_LoadB && n->Opcode() != Op_LoadUB) {
-    return false;
-  }
-  Node* addp = n->in(MemNode::Address);
-  if (!addp->is_AddP()) {
-    return false;
-  }
-  Node* base = addp->in(AddPNode::Address);
-  Node* off = addp->in(AddPNode::Offset);
-  if (base->Opcode() != Op_ThreadLocal) {
-    return false;
-  }
-  if (off->find_intptr_t_con(-1) != in_bytes(ShenandoahThreadLocalData::gc_state_offset())) {
-    return false;
-  }
-  return true;
-}
-
-bool ShenandoahBarrierC2Support::has_safepoint_between(Node* start, Node* stop, PhaseIdealLoop *phase) {
-  assert(phase->is_dominator(stop, start), "bad inputs");
-  ResourceMark rm;
-  Unique_Node_List wq;
-  wq.push(start);
-  for (uint next = 0; next < wq.size(); next++) {
-    Node *m = wq.at(next);
-    if (m == stop) {
-      continue;
-    }
-    if (m->is_SafePoint() && !m->is_CallLeaf()) {
-      return true;
-    }
-    if (m->is_Region()) {
-      for (uint i = 1; i < m->req(); i++) {
-        wq.push(m->in(i));
-      }
-    } else {
-      wq.push(m->in(0));
-    }
-  }
-  return false;
-}
-
-#ifdef ASSERT
-bool ShenandoahBarrierC2Support::verify_helper(Node* in, Node_Stack& phis, VectorSet& visited, verify_type t, bool trace, Unique_Node_List& barriers_used) {
-  assert(phis.size() == 0, "");
-
-  while (true) {
-    if (in->bottom_type() == TypePtr::NULL_PTR) {
-      if (trace) {tty->print_cr("null");}
-    } else if (!in->bottom_type()->make_ptr()->make_oopptr()) {
-      if (trace) {tty->print_cr("Non oop");}
-    } else {
-      if (in->is_ConstraintCast()) {
-        in = in->in(1);
-        continue;
-      } else if (in->is_AddP()) {
-        assert(!in->in(AddPNode::Address)->is_top(), "no raw memory access");
-        in = in->in(AddPNode::Address);
-        continue;
-      } else if (in->is_Con()) {
-        if (trace) {
-          tty->print("Found constant");
-          in->dump();
-        }
-      } else if (in->Opcode() == Op_Parm) {
-        if (trace) {
-          tty->print("Found argument");
-        }
-      } else if (in->Opcode() == Op_CreateEx) {
-        if (trace) {
-          tty->print("Found create-exception");
-        }
-      } else if (in->Opcode() == Op_LoadP && in->adr_type() == TypeRawPtr::BOTTOM) {
-        if (trace) {
-          tty->print("Found raw LoadP (OSR argument?)");
-        }
-      } else if (in->Opcode() == Op_ShenandoahLoadReferenceBarrier) {
-        if (t == ShenandoahOopStore) {
-          return false;
-        }
-        barriers_used.push(in);
-        if (trace) {tty->print("Found barrier"); in->dump();}
-      } else if (in->is_Proj() && in->in(0)->is_Allocate()) {
-        if (trace) {
-          tty->print("Found alloc");
-          in->in(0)->dump();
-        }
-      } else if (in->is_Proj() && (in->in(0)->Opcode() == Op_CallStaticJava || in->in(0)->Opcode() == Op_CallDynamicJava)) {
-        if (trace) {
-          tty->print("Found Java call");
-        }
-      } else if (in->is_Phi()) {
-        if (!visited.test_set(in->_idx)) {
-          if (trace) {tty->print("Pushed phi:"); in->dump();}
-          phis.push(in, 2);
-          in = in->in(1);
-          continue;
-        }
-        if (trace) {tty->print("Already seen phi:"); in->dump();}
-      } else if (in->Opcode() == Op_CMoveP || in->Opcode() == Op_CMoveN) {
-        if (!visited.test_set(in->_idx)) {
-          if (trace) {tty->print("Pushed cmovep:"); in->dump();}
-          phis.push(in, CMoveNode::IfTrue);
-          in = in->in(CMoveNode::IfFalse);
-          continue;
-        }
-        if (trace) {tty->print("Already seen cmovep:"); in->dump();}
-      } else if (in->Opcode() == Op_EncodeP || in->Opcode() == Op_DecodeN) {
-        in = in->in(1);
-        continue;
-      } else {
-        return false;
-      }
-    }
-    bool cont = false;
-    while (phis.is_nonempty()) {
-      uint idx = phis.index();
-      Node* phi = phis.node();
-      if (idx >= phi->req()) {
-        if (trace) {tty->print("Popped phi:"); phi->dump();}
-        phis.pop();
-        continue;
-      }
-      if (trace) {tty->print("Next entry(%d) for phi:", idx); phi->dump();}
-      in = phi->in(idx);
-      phis.set_index(idx+1);
-      cont = true;
-      break;
-    }
-    if (!cont) {
-      break;
-    }
-  }
-  return true;
-}
-
-void ShenandoahBarrierC2Support::report_verify_failure(const char* msg, Node* n1, Node* n2) {
-  if (n1 != nullptr) {
-    n1->dump(+10);
-  }
-  if (n2 != nullptr) {
-    n2->dump(+10);
-  }
-  fatal("%s", msg);
-}
-
-void ShenandoahBarrierC2Support::verify(RootNode* root) {
-  ResourceMark rm;
-  Unique_Node_List wq;
-  GrowableArray<Node*> barriers;
-  Unique_Node_List barriers_used;
-  Node_Stack phis(0);
-  VectorSet visited;
-  const bool trace = false;
-  const bool verify_no_useless_barrier = false;
-
-  wq.push(root);
-  for (uint next = 0; next < wq.size(); next++) {
-    Node *n = wq.at(next);
-    if (n->is_Load()) {
-      const bool trace = false;
-      if (trace) {tty->print("Verifying"); n->dump();}
-      if (n->Opcode() == Op_LoadRange || n->Opcode() == Op_LoadKlass || n->Opcode() == Op_LoadNKlass) {
-        if (trace) {tty->print_cr("Load range/klass");}
-      } else {
-        const TypePtr* adr_type = n->as_Load()->adr_type();
-
-        if (adr_type->isa_oopptr() && adr_type->is_oopptr()->offset() == oopDesc::mark_offset_in_bytes()) {
-          if (trace) {tty->print_cr("Mark load");}
-        } else if (adr_type->isa_instptr() &&
-                   adr_type->is_instptr()->instance_klass()->is_subtype_of(Compile::current()->env()->Reference_klass()) &&
-                   adr_type->is_instptr()->offset() == java_lang_ref_Reference::referent_offset()) {
-          if (trace) {tty->print_cr("Reference.get()");}
-        } else if (!verify_helper(n->in(MemNode::Address), phis, visited, ShenandoahLoad, trace, barriers_used)) {
-          report_verify_failure("Shenandoah verification: Load should have barriers", n);
-        }
-      }
-    } else if (n->is_Store()) {
-      const bool trace = false;
-
-      if (trace) {tty->print("Verifying"); n->dump();}
-      if (n->in(MemNode::ValueIn)->bottom_type()->make_oopptr()) {
-        Node* adr = n->in(MemNode::Address);
-        bool verify = true;
-
-        if (adr->is_AddP() && adr->in(AddPNode::Base)->is_top()) {
-          adr = adr->in(AddPNode::Address);
-          if (adr->is_AddP()) {
-            assert(adr->in(AddPNode::Base)->is_top(), "");
-            adr = adr->in(AddPNode::Address);
-            if (adr->Opcode() == Op_LoadP &&
-                adr->in(MemNode::Address)->in(AddPNode::Base)->is_top() &&
-                adr->in(MemNode::Address)->in(AddPNode::Address)->Opcode() == Op_ThreadLocal &&
-                adr->in(MemNode::Address)->in(AddPNode::Offset)->find_intptr_t_con(-1) == in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset())) {
-              if (trace) {tty->print_cr("SATB prebarrier");}
-              verify = false;
-            }
-          }
-        }
-
-        if (verify && !verify_helper(n->in(MemNode::ValueIn), phis, visited, ShenandoahValue, trace, barriers_used)) {
-          report_verify_failure("Shenandoah verification: Store should have barriers", n);
-        }
-      }
-      if (!verify_helper(n->in(MemNode::Address), phis, visited, ShenandoahStore, trace, barriers_used)) {
-        report_verify_failure("Shenandoah verification: Store (address) should have barriers", n);
-      }
-    } else if (n->Opcode() == Op_CmpP) {
-      const bool trace = false;
-
-      Node* in1 = n->in(1);
-      Node* in2 = n->in(2);
-      if (in1->bottom_type()->isa_oopptr()) {
-        if (trace) {tty->print("Verifying"); n->dump();}
-
-        bool mark_inputs = false;
-        if (in1->bottom_type() == TypePtr::NULL_PTR || in2->bottom_type() == TypePtr::NULL_PTR ||
-            (in1->is_Con() || in2->is_Con())) {
-          if (trace) {tty->print_cr("Comparison against a constant");}
-          mark_inputs = true;
-        } else if ((in1->is_CheckCastPP() && in1->in(1)->is_Proj() && in1->in(1)->in(0)->is_Allocate()) ||
-                   (in2->is_CheckCastPP() && in2->in(1)->is_Proj() && in2->in(1)->in(0)->is_Allocate())) {
-          if (trace) {tty->print_cr("Comparison with newly alloc'ed object");}
-          mark_inputs = true;
-        } else {
-          assert(in2->bottom_type()->isa_oopptr(), "");
-
-          if (!verify_helper(in1, phis, visited, ShenandoahStore, trace, barriers_used) ||
-              !verify_helper(in2, phis, visited, ShenandoahStore, trace, barriers_used)) {
-            report_verify_failure("Shenandoah verification: Cmp should have barriers", n);
-          }
-        }
-        if (verify_no_useless_barrier &&
-            mark_inputs &&
-            (!verify_helper(in1, phis, visited, ShenandoahValue, trace, barriers_used) ||
-             !verify_helper(in2, phis, visited, ShenandoahValue, trace, barriers_used))) {
-          phis.clear();
-          visited.reset();
-        }
-      }
-    } else if (n->is_LoadStore()) {
-      if (n->in(MemNode::ValueIn)->bottom_type()->make_ptr() &&
-          !verify_helper(n->in(MemNode::ValueIn), phis, visited, ShenandoahValue, trace, barriers_used)) {
-        report_verify_failure("Shenandoah verification: LoadStore (value) should have barriers", n);
-      }
-
-      if (n->in(MemNode::Address)->bottom_type()->make_oopptr() && !verify_helper(n->in(MemNode::Address), phis, visited, ShenandoahStore, trace, barriers_used)) {
-        report_verify_failure("Shenandoah verification: LoadStore (address) should have barriers", n);
-      }
-    } else if (n->Opcode() == Op_CallLeafNoFP || n->Opcode() == Op_CallLeaf) {
-      CallNode* call = n->as_Call();
-
-      static struct {
-        const char* name;
-        struct {
-          int pos;
-          verify_type t;
-        } args[6];
-      } calls[] = {
-        "array_partition_stub",
-        { { TypeFunc::Parms, ShenandoahStore }, { TypeFunc::Parms+4, ShenandoahStore },   { -1, ShenandoahNone },
-          { -1, ShenandoahNone },                { -1, ShenandoahNone },                  { -1, ShenandoahNone } },
-        "arraysort_stub",
-        { { TypeFunc::Parms, ShenandoahStore },  { -1, ShenandoahNone },                  { -1, ShenandoahNone },
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "aescrypt_encryptBlock",
-        { { TypeFunc::Parms, ShenandoahLoad },   { TypeFunc::Parms+1, ShenandoahStore },  { TypeFunc::Parms+2, ShenandoahLoad },
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "aescrypt_decryptBlock",
-        { { TypeFunc::Parms, ShenandoahLoad },   { TypeFunc::Parms+1, ShenandoahStore },  { TypeFunc::Parms+2, ShenandoahLoad },
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "multiplyToLen",
-        { { TypeFunc::Parms, ShenandoahLoad },   { TypeFunc::Parms+2, ShenandoahLoad },   { TypeFunc::Parms+4, ShenandoahStore },
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "squareToLen",
-        { { TypeFunc::Parms, ShenandoahLoad },   { TypeFunc::Parms+2, ShenandoahLoad },   { -1,  ShenandoahNone},
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "montgomery_multiply",
-        { { TypeFunc::Parms, ShenandoahLoad },   { TypeFunc::Parms+1, ShenandoahLoad },   { TypeFunc::Parms+2, ShenandoahLoad },
-          { TypeFunc::Parms+6, ShenandoahStore }, { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "montgomery_square",
-        { { TypeFunc::Parms, ShenandoahLoad },   { TypeFunc::Parms+1, ShenandoahLoad },   { TypeFunc::Parms+5, ShenandoahStore },
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "mulAdd",
-        { { TypeFunc::Parms, ShenandoahStore },  { TypeFunc::Parms+1, ShenandoahLoad },   { -1,  ShenandoahNone},
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "vectorizedMismatch",
-        { { TypeFunc::Parms, ShenandoahLoad },   { TypeFunc::Parms+1, ShenandoahLoad },   { -1,  ShenandoahNone},
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "updateBytesCRC32",
-        { { TypeFunc::Parms+1, ShenandoahLoad }, { -1,  ShenandoahNone},                  { -1,  ShenandoahNone},
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "updateBytesAdler32",
-        { { TypeFunc::Parms+1, ShenandoahLoad }, { -1,  ShenandoahNone},                  { -1,  ShenandoahNone},
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "updateBytesCRC32C",
-        { { TypeFunc::Parms+1, ShenandoahLoad }, { TypeFunc::Parms+3, ShenandoahLoad},    { -1,  ShenandoahNone},
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "counterMode_AESCrypt",
-        { { TypeFunc::Parms, ShenandoahLoad },   { TypeFunc::Parms+1, ShenandoahStore },  { TypeFunc::Parms+2, ShenandoahLoad },
-          { TypeFunc::Parms+3, ShenandoahStore }, { TypeFunc::Parms+5, ShenandoahStore }, { TypeFunc::Parms+6, ShenandoahStore } },
-        "cipherBlockChaining_encryptAESCrypt",
-        { { TypeFunc::Parms, ShenandoahLoad },   { TypeFunc::Parms+1, ShenandoahStore },  { TypeFunc::Parms+2, ShenandoahLoad },
-          { TypeFunc::Parms+3, ShenandoahLoad },  { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "cipherBlockChaining_decryptAESCrypt",
-        { { TypeFunc::Parms, ShenandoahLoad },   { TypeFunc::Parms+1, ShenandoahStore },  { TypeFunc::Parms+2, ShenandoahLoad },
-          { TypeFunc::Parms+3, ShenandoahLoad },  { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "shenandoah_clone",
-        { { TypeFunc::Parms, ShenandoahLoad },   { -1,  ShenandoahNone},                  { -1,  ShenandoahNone},
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "ghash_processBlocks",
-        { { TypeFunc::Parms, ShenandoahStore },  { TypeFunc::Parms+1, ShenandoahLoad },   { TypeFunc::Parms+2, ShenandoahLoad },
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "sha1_implCompress",
-        { { TypeFunc::Parms, ShenandoahLoad },  { TypeFunc::Parms+1, ShenandoahStore },   { -1, ShenandoahNone },
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "sha256_implCompress",
-        { { TypeFunc::Parms, ShenandoahLoad },  { TypeFunc::Parms+1, ShenandoahStore },   { -1, ShenandoahNone },
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "sha512_implCompress",
-        { { TypeFunc::Parms, ShenandoahLoad },  { TypeFunc::Parms+1, ShenandoahStore },   { -1, ShenandoahNone },
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "sha1_implCompressMB",
-        { { TypeFunc::Parms, ShenandoahLoad },  { TypeFunc::Parms+1, ShenandoahStore },   { -1, ShenandoahNone },
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "sha256_implCompressMB",
-        { { TypeFunc::Parms, ShenandoahLoad },  { TypeFunc::Parms+1, ShenandoahStore },   { -1, ShenandoahNone },
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "sha512_implCompressMB",
-        { { TypeFunc::Parms, ShenandoahLoad },  { TypeFunc::Parms+1, ShenandoahStore },   { -1, ShenandoahNone },
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "encodeBlock",
-        { { TypeFunc::Parms, ShenandoahLoad },  { TypeFunc::Parms+3, ShenandoahStore },   { -1, ShenandoahNone },
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "decodeBlock",
-        { { TypeFunc::Parms, ShenandoahLoad },  { TypeFunc::Parms+3, ShenandoahStore },   { -1, ShenandoahNone },
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "intpoly_montgomeryMult_P256",
-        { { TypeFunc::Parms, ShenandoahLoad },  { TypeFunc::Parms+1, ShenandoahLoad  },   { TypeFunc::Parms+2, ShenandoahStore },
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-        "intpoly_assign",
-        { { TypeFunc::Parms+1, ShenandoahStore }, { TypeFunc::Parms+2, ShenandoahLoad },  { -1, ShenandoahNone },
-          { -1,  ShenandoahNone},                 { -1,  ShenandoahNone},                 { -1,  ShenandoahNone} },
-      };
-
-      if (call->is_call_to_arraycopystub()) {
-        Node* dest = nullptr;
-        const TypeTuple* args = n->as_Call()->_tf->domain();
-        for (uint i = TypeFunc::Parms, j = 0; i < args->cnt(); i++) {
-          if (args->field_at(i)->isa_ptr()) {
-            j++;
-            if (j == 2) {
-              dest = n->in(i);
-              break;
-            }
-          }
-        }
-        if (!verify_helper(n->in(TypeFunc::Parms), phis, visited, ShenandoahLoad, trace, barriers_used) ||
-            !verify_helper(dest, phis, visited, ShenandoahStore, trace, barriers_used)) {
-          report_verify_failure("Shenandoah verification: ArrayCopy should have barriers", n);
-        }
-      } else if (strlen(call->_name) > 5 &&
-                 !strcmp(call->_name + strlen(call->_name) - 5, "_fill")) {
-        if (!verify_helper(n->in(TypeFunc::Parms), phis, visited, ShenandoahStore, trace, barriers_used)) {
-          report_verify_failure("Shenandoah verification: _fill should have barriers", n);
-        }
-      } else if (!strcmp(call->_name, "shenandoah_wb_pre")) {
-        // skip
-      } else {
-        const int calls_len = sizeof(calls) / sizeof(calls[0]);
-        int i = 0;
-        for (; i < calls_len; i++) {
-          if (!strcmp(calls[i].name, call->_name)) {
-            break;
-          }
-        }
-        if (i != calls_len) {
-          const uint args_len = sizeof(calls[0].args) / sizeof(calls[0].args[0]);
-          for (uint j = 0; j < args_len; j++) {
-            int pos = calls[i].args[j].pos;
-            if (pos == -1) {
-              break;
-            }
-            if (!verify_helper(call->in(pos), phis, visited, calls[i].args[j].t, trace, barriers_used)) {
-              report_verify_failure("Shenandoah verification: intrinsic calls should have barriers", n);
-            }
-          }
-          for (uint j = TypeFunc::Parms; j < call->req(); j++) {
-            if (call->in(j)->bottom_type()->make_ptr() &&
-                call->in(j)->bottom_type()->make_ptr()->isa_oopptr()) {
-              uint k = 0;
-              for (; k < args_len && calls[i].args[k].pos != (int)j; k++);
-              if (k == args_len) {
-                fatal("arg %d for call %s not covered", j, call->_name);
-              }
-            }
-          }
-        } else {
-          for (uint j = TypeFunc::Parms; j < call->req(); j++) {
-            if (call->in(j)->bottom_type()->make_ptr() &&
-                call->in(j)->bottom_type()->make_ptr()->isa_oopptr()) {
-              fatal("%s not covered", call->_name);
-            }
-          }
-        }
-      }
-    } else if (n->Opcode() == Op_ShenandoahLoadReferenceBarrier) {
-      // skip
-    } else if (n->is_AddP()
-               || n->is_Phi()
-               || n->is_ConstraintCast()
-               || n->Opcode() == Op_Return
-               || n->Opcode() == Op_CMoveP
-               || n->Opcode() == Op_CMoveN
-               || n->Opcode() == Op_Rethrow
-               || n->is_MemBar()
-               || n->Opcode() == Op_Conv2B
-               || n->Opcode() == Op_SafePoint
-               || n->is_CallJava()
-               || n->Opcode() == Op_Unlock
-               || n->Opcode() == Op_EncodeP
-               || n->Opcode() == Op_DecodeN) {
-      // nothing to do
-    } else {
-      static struct {
-        int opcode;
-        struct {
-          int pos;
-          verify_type t;
-        } inputs[2];
-      } others[] = {
-        Op_FastLock,
-        { { 1, ShenandoahLoad },                  { -1, ShenandoahNone} },
-        Op_Lock,
-        { { TypeFunc::Parms, ShenandoahLoad },    { -1, ShenandoahNone} },
-        Op_ArrayCopy,
-        { { ArrayCopyNode::Src, ShenandoahLoad }, { ArrayCopyNode::Dest, ShenandoahStore } },
-        Op_StrCompressedCopy,
-        { { 2, ShenandoahLoad },                  { 3, ShenandoahStore } },
-        Op_StrInflatedCopy,
-        { { 2, ShenandoahLoad },                  { 3, ShenandoahStore } },
-        Op_AryEq,
-        { { 2, ShenandoahLoad },                  { 3, ShenandoahLoad } },
-        Op_StrIndexOf,
-        { { 2, ShenandoahLoad },                  { 4, ShenandoahLoad } },
-        Op_StrComp,
-        { { 2, ShenandoahLoad },                  { 4, ShenandoahLoad } },
-        Op_StrEquals,
-        { { 2, ShenandoahLoad },                  { 3, ShenandoahLoad } },
-        Op_VectorizedHashCode,
-        { { 2, ShenandoahLoad },                  { -1, ShenandoahNone } },
-        Op_EncodeISOArray,
-        { { 2, ShenandoahLoad },                  { 3, ShenandoahStore } },
-        Op_CountPositives,
-        { { 2, ShenandoahLoad },                  { -1, ShenandoahNone} },
-        Op_CastP2X,
-        { { 1, ShenandoahLoad },                  { -1, ShenandoahNone} },
-        Op_StrIndexOfChar,
-        { { 2, ShenandoahLoad },                  { -1, ShenandoahNone } },
-      };
-
-      const int others_len = sizeof(others) / sizeof(others[0]);
-      int i = 0;
-      for (; i < others_len; i++) {
-        if (others[i].opcode == n->Opcode()) {
-          break;
-        }
-      }
-      uint stop = n->is_Call() ? n->as_Call()->tf()->domain()->cnt() : n->req();
-      if (i != others_len) {
-        const uint inputs_len = sizeof(others[0].inputs) / sizeof(others[0].inputs[0]);
-        for (uint j = 0; j < inputs_len; j++) {
-          int pos = others[i].inputs[j].pos;
-          if (pos == -1) {
-            break;
-          }
-          if (!verify_helper(n->in(pos), phis, visited, others[i].inputs[j].t, trace, barriers_used)) {
-            report_verify_failure("Shenandoah verification: intrinsic calls should have barriers", n);
-          }
-        }
-        for (uint j = 1; j < stop; j++) {
-          if (n->in(j) != nullptr && n->in(j)->bottom_type()->make_ptr() &&
-              n->in(j)->bottom_type()->make_ptr()->make_oopptr()) {
-            uint k = 0;
-            for (; k < inputs_len && others[i].inputs[k].pos != (int)j; k++);
-            if (k == inputs_len) {
-              fatal("arg %d for node %s not covered", j, n->Name());
-            }
-          }
-        }
-      } else {
-        for (uint j = 1; j < stop; j++) {
-          if (n->in(j) != nullptr && n->in(j)->bottom_type()->make_ptr() &&
-              n->in(j)->bottom_type()->make_ptr()->make_oopptr()) {
-            fatal("%s not covered", n->Name());
-          }
-        }
-      }
-    }
-
-    if (n->is_SafePoint()) {
-      SafePointNode* sfpt = n->as_SafePoint();
-      if (verify_no_useless_barrier && sfpt->jvms() != nullptr) {
-        for (uint i = sfpt->jvms()->scloff(); i < sfpt->jvms()->endoff(); i++) {
-          if (!verify_helper(sfpt->in(i), phis, visited, ShenandoahLoad, trace, barriers_used)) {
-            phis.clear();
-            visited.reset();
-          }
-        }
-      }
-    }
-  }
-
-  if (verify_no_useless_barrier) {
-    for (int i = 0; i < barriers.length(); i++) {
-      Node* n = barriers.at(i);
-      if (!barriers_used.member(n)) {
-        tty->print("XXX useless barrier"); n->dump(-2);
-        ShouldNotReachHere();
-      }
-    }
-  }
-}
-#endif
-
-bool ShenandoahBarrierC2Support::is_anti_dependent_load_at_control(PhaseIdealLoop* phase, Node* maybe_load, Node* store,
-                                                                   Node* control) {
-  return maybe_load->is_Load() && phase->C->can_alias(store->adr_type(), phase->C->get_alias_index(maybe_load->adr_type())) &&
-         phase->ctrl_or_self(maybe_load) == control;
-}
-
-void ShenandoahBarrierC2Support::maybe_push_anti_dependent_loads(PhaseIdealLoop* phase, Node* maybe_store, Node* control, Unique_Node_List &wq) {
-  if (!maybe_store->is_Store() && !maybe_store->is_LoadStore()) {
-    return;
-  }
-  Node* mem = maybe_store->in(MemNode::Memory);
-  for (DUIterator_Fast imax, i = mem->fast_outs(imax); i < imax; i++) {
-    Node* u = mem->fast_out(i);
-    if (is_anti_dependent_load_at_control(phase, u, maybe_store, control)) {
-      wq.push(u);
-    }
-  }
-}
-
-void ShenandoahBarrierC2Support::push_data_inputs_at_control(PhaseIdealLoop* phase, Node* n, Node* ctrl, Unique_Node_List &wq) {
-  for (uint i = 0; i < n->req(); i++) {
-    Node* in = n->in(i);
-    if (in != nullptr && phase->has_ctrl(in) && phase->get_ctrl(in) == ctrl) {
-      wq.push(in);
-    }
-  }
-}
-
-bool ShenandoahBarrierC2Support::is_dominator_same_ctrl(Node* c, Node* d, Node* n, PhaseIdealLoop* phase) {
-  // That both nodes have the same control is not sufficient to prove
-  // domination, verify that there's no path from d to n
-  ResourceMark rm;
-  Unique_Node_List wq;
-  wq.push(d);
-  for (uint next = 0; next < wq.size(); next++) {
-    Node *m = wq.at(next);
-    if (m == n) {
-      return false;
-    }
-    if (m->is_Phi() && m->in(0)->is_Loop()) {
-      assert(phase->ctrl_or_self(m->in(LoopNode::EntryControl)) != c, "following loop entry should lead to new control");
-    } else {
-      // Take anti-dependencies into account
-      maybe_push_anti_dependent_loads(phase, m, c, wq);
-      push_data_inputs_at_control(phase, m, c, wq);
-    }
-  }
-  return true;
-}
-
-bool ShenandoahBarrierC2Support::is_dominator(Node* d_c, Node* n_c, Node* d, Node* n, PhaseIdealLoop* phase) {
-  if (d_c != n_c) {
-    return phase->is_dominator(d_c, n_c);
-  }
-  return is_dominator_same_ctrl(d_c, d, n, phase);
-}
-
-Node* next_mem(Node* mem, int alias) {
-  Node* res = nullptr;
-  if (mem->is_Proj()) {
-    res = mem->in(0);
-  } else if (mem->is_SafePoint() || mem->is_MemBar()) {
-    res = mem->in(TypeFunc::Memory);
-  } else if (mem->is_Phi()) {
-    res = mem->in(1);
-  } else if (mem->is_MergeMem()) {
-    res = mem->as_MergeMem()->memory_at(alias);
-  } else if (mem->is_Store() || mem->is_LoadStore() || mem->is_ClearArray()) {
-    assert(alias == Compile::AliasIdxRaw, "following raw memory can't lead to a barrier");
-    res = mem->in(MemNode::Memory);
-  } else {
-#ifdef ASSERT
-    mem->dump();
-#endif
-    ShouldNotReachHere();
-  }
-  return res;
-}
-
-Node* ShenandoahBarrierC2Support::no_branches(Node* c, Node* dom, bool allow_one_proj, PhaseIdealLoop* phase) {
-  Node* iffproj = nullptr;
-  while (c != dom) {
-    Node* next = phase->idom(c);
-    assert(next->unique_ctrl_out_or_null() == c || c->is_Proj() || c->is_Region(), "multiple control flow out but no proj or region?");
-    if (c->is_Region()) {
-      ResourceMark rm;
-      Unique_Node_List wq;
-      wq.push(c);
-      for (uint i = 0; i < wq.size(); i++) {
-        Node *n = wq.at(i);
-        if (n == next) {
-          continue;
-        }
-        if (n->is_Region()) {
-          for (uint j = 1; j < n->req(); j++) {
-            wq.push(n->in(j));
-          }
-        } else {
-          wq.push(n->in(0));
-        }
-      }
-      for (uint i = 0; i < wq.size(); i++) {
-        Node *n = wq.at(i);
-        assert(n->is_CFG(), "");
-        if (n->is_Multi()) {
-          for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++) {
-            Node* u = n->fast_out(j);
-            if (u->is_CFG()) {
-              if (!wq.member(u) && !u->as_Proj()->is_uncommon_trap_proj()) {
-                return NodeSentinel;
-              }
-            }
-          }
-        }
-      }
-    } else  if (c->is_Proj()) {
-      if (c->is_IfProj()) {
-        if (c->as_Proj()->is_uncommon_trap_if_pattern() != nullptr) {
-          // continue;
-        } else {
-          if (!allow_one_proj) {
-            return NodeSentinel;
-          }
-          if (iffproj == nullptr) {
-            iffproj = c;
-          } else {
-            return NodeSentinel;
-          }
-        }
-      } else if (c->Opcode() == Op_JumpProj) {
-        return NodeSentinel; // unsupported
-      } else if (c->Opcode() == Op_CatchProj) {
-        return NodeSentinel; // unsupported
-      } else if (c->Opcode() == Op_CProj && next->is_NeverBranch()) {
-        return NodeSentinel; // unsupported
-      } else {
-        assert(next->unique_ctrl_out() == c, "unsupported branch pattern");
-      }
-    }
-    c = next;
-  }
-  return iffproj;
-}
-
-Node* ShenandoahBarrierC2Support::dom_mem(Node* mem, Node* ctrl, int alias, Node*& mem_ctrl, PhaseIdealLoop* phase) {
-  ResourceMark rm;
-  VectorSet wq;
-  wq.set(mem->_idx);
-  mem_ctrl = phase->ctrl_or_self(mem);
-  while (!phase->is_dominator(mem_ctrl, ctrl) || mem_ctrl == ctrl) {
-    mem = next_mem(mem, alias);
-    if (wq.test_set(mem->_idx)) {
-      return nullptr;
-    }
-    mem_ctrl = phase->ctrl_or_self(mem);
-  }
-  if (mem->is_MergeMem()) {
-    mem = mem->as_MergeMem()->memory_at(alias);
-    mem_ctrl = phase->ctrl_or_self(mem);
-  }
-  return mem;
-}
-
-Node* ShenandoahBarrierC2Support::find_bottom_mem(Node* ctrl, PhaseIdealLoop* phase) {
-  Node* mem = nullptr;
-  Node* c = ctrl;
-  do {
-    if (c->is_Region()) {
-      for (DUIterator_Fast imax, i = c->fast_outs(imax); i < imax && mem == nullptr; i++) {
-        Node* u = c->fast_out(i);
-        if (u->is_Phi() && u->bottom_type() == Type::MEMORY) {
-          if (u->adr_type() == TypePtr::BOTTOM) {
-            mem = u;
-          }
-        }
-      }
-    } else {
-      if (c->is_Call() && c->as_Call()->adr_type() != nullptr) {
-        CallProjections projs;
-        c->as_Call()->extract_projections(&projs, true, false);
-        if (projs.fallthrough_memproj != nullptr) {
-          if (projs.fallthrough_memproj->adr_type() == TypePtr::BOTTOM) {
-            if (projs.catchall_memproj == nullptr) {
-              mem = projs.fallthrough_memproj;
-            } else {
-              if (phase->is_dominator(projs.fallthrough_catchproj, ctrl)) {
-                mem = projs.fallthrough_memproj;
-              } else {
-                assert(phase->is_dominator(projs.catchall_catchproj, ctrl), "one proj must dominate barrier");
-                mem = projs.catchall_memproj;
-              }
-            }
-          }
-        } else {
-          Node* proj = c->as_Call()->proj_out(TypeFunc::Memory);
-          if (proj != nullptr &&
-              proj->adr_type() == TypePtr::BOTTOM) {
-            mem = proj;
-          }
-        }
-      } else {
-        for (DUIterator_Fast imax, i = c->fast_outs(imax); i < imax; i++) {
-          Node* u = c->fast_out(i);
-          if (u->is_Proj() &&
-              u->bottom_type() == Type::MEMORY &&
-              u->adr_type() == TypePtr::BOTTOM) {
-              assert(c->is_SafePoint() || c->is_MemBar() || c->is_Start(), "");
-              assert(mem == nullptr, "only one proj");
-              mem = u;
-          }
-        }
-        assert(!c->is_Call() || c->as_Call()->adr_type() != nullptr || mem == nullptr, "no mem projection expected");
-      }
-    }
-    c = phase->idom(c);
-  } while (mem == nullptr);
-  return mem;
-}
-
-void ShenandoahBarrierC2Support::follow_barrier_uses(Node* n, Node* ctrl, Unique_Node_List& uses, PhaseIdealLoop* phase) {
-  for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
-    Node* u = n->fast_out(i);
-    if (!u->is_CFG() && phase->get_ctrl(u) == ctrl && (!u->is_Phi() || !u->in(0)->is_Loop() || u->in(LoopNode::LoopBackControl) != n)) {
-      uses.push(u);
-    }
-  }
-}
-
-static void hide_strip_mined_loop(OuterStripMinedLoopNode* outer, CountedLoopNode* inner, PhaseIdealLoop* phase) {
-  OuterStripMinedLoopEndNode* le = inner->outer_loop_end();
-  Node* new_outer = new LoopNode(outer->in(LoopNode::EntryControl), outer->in(LoopNode::LoopBackControl));
-  phase->register_control(new_outer, phase->get_loop(outer), outer->in(LoopNode::EntryControl));
-  Node* new_le = new IfNode(le->in(0), le->in(1), le->_prob, le->_fcnt);
-  phase->register_control(new_le, phase->get_loop(le), le->in(0));
-  phase->replace_node_and_forward_ctrl(outer, new_outer);
-  phase->replace_node_and_forward_ctrl(le, new_le);
-  inner->clear_strip_mined();
-}
-
-void ShenandoahBarrierC2Support::test_gc_state(Node*& ctrl, Node* raw_mem, Node*& test_fail_ctrl,
-                                               PhaseIdealLoop* phase, int flags) {
-  PhaseIterGVN& igvn = phase->igvn();
-  Node* old_ctrl = ctrl;
-
-  Node* thread          = new ThreadLocalNode();
-  Node* gc_state_offset = igvn.MakeConX(in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
-  Node* gc_state_addr   = new AddPNode(phase->C->top(), thread, gc_state_offset);
-  Node* gc_state        = new LoadBNode(old_ctrl, raw_mem, gc_state_addr,
-                                        DEBUG_ONLY(phase->C->get_adr_type(Compile::AliasIdxRaw)) NOT_DEBUG(nullptr),
-                                        TypeInt::BYTE, MemNode::unordered);
-  Node* gc_state_and    = new AndINode(gc_state, igvn.intcon(flags));
-  Node* gc_state_cmp    = new CmpINode(gc_state_and, igvn.zerocon(T_INT));
-  Node* gc_state_bool   = new BoolNode(gc_state_cmp, BoolTest::ne);
-
-  IfNode* gc_state_iff  = new IfNode(old_ctrl, gc_state_bool, PROB_UNLIKELY(0.999), COUNT_UNKNOWN);
-  ctrl                  = new IfTrueNode(gc_state_iff);
-  test_fail_ctrl        = new IfFalseNode(gc_state_iff);
-
-  IdealLoopTree* loop = phase->get_loop(old_ctrl);
-  phase->register_control(gc_state_iff,   loop, old_ctrl);
-  phase->register_control(ctrl,           loop, gc_state_iff);
-  phase->register_control(test_fail_ctrl, loop, gc_state_iff);
-
-  phase->register_new_node(thread,        old_ctrl);
-  phase->register_new_node(gc_state_addr, old_ctrl);
-  phase->register_new_node(gc_state,      old_ctrl);
-  phase->register_new_node(gc_state_and,  old_ctrl);
-  phase->register_new_node(gc_state_cmp,  old_ctrl);
-  phase->register_new_node(gc_state_bool, old_ctrl);
-
-  phase->set_root_as_ctrl(gc_state_offset);
-
-  assert(is_gc_state_test(gc_state_iff, flags), "Should match the shape");
-}
-
-void ShenandoahBarrierC2Support::test_null(Node*& ctrl, Node* val, Node*& null_ctrl, PhaseIdealLoop* phase) {
-  Node* old_ctrl = ctrl;
-  PhaseIterGVN& igvn = phase->igvn();
-
-  const Type* val_t = igvn.type(val);
-  if (val_t->meet(TypePtr::NULL_PTR) == val_t) {
-    Node* null_cmp   = new CmpPNode(val, igvn.zerocon(T_OBJECT));
-    Node* null_test  = new BoolNode(null_cmp, BoolTest::ne);
-
-    IfNode* null_iff = new IfNode(old_ctrl, null_test, PROB_LIKELY(0.999), COUNT_UNKNOWN);
-    ctrl             = new IfTrueNode(null_iff);
-    null_ctrl        = new IfFalseNode(null_iff);
-
-    IdealLoopTree* loop = phase->get_loop(old_ctrl);
-    phase->register_control(null_iff,  loop, old_ctrl);
-    phase->register_control(ctrl,      loop, null_iff);
-    phase->register_control(null_ctrl, loop, null_iff);
-
-    phase->register_new_node(null_cmp,  old_ctrl);
-    phase->register_new_node(null_test, old_ctrl);
-  }
-}
-
-void ShenandoahBarrierC2Support::test_in_cset(Node*& ctrl, Node*& not_cset_ctrl, Node* val, Node* raw_mem, PhaseIdealLoop* phase) {
-  Node* old_ctrl = ctrl;
-  PhaseIterGVN& igvn = phase->igvn();
-
-  Node* raw_val        = new CastP2XNode(old_ctrl, val);
-  Node* cset_idx       = new URShiftXNode(raw_val, igvn.intcon(ShenandoahHeapRegion::region_size_bytes_shift_jint()));
-
-  // Figure out the target cset address with raw pointer math.
-  // This avoids matching AddP+LoadB that would emit inefficient code.
-  // See JDK-8245465.
-  Node* cset_addr_ptr  = igvn.makecon(TypeRawPtr::make(ShenandoahHeap::in_cset_fast_test_addr()));
-  Node* cset_addr      = new CastP2XNode(old_ctrl, cset_addr_ptr);
-  Node* cset_load_addr = new AddXNode(cset_addr, cset_idx);
-  Node* cset_load_ptr  = new CastX2PNode(cset_load_addr);
-
-  Node* cset_load      = new LoadBNode(old_ctrl, raw_mem, cset_load_ptr,
-                                       DEBUG_ONLY(phase->C->get_adr_type(Compile::AliasIdxRaw)) NOT_DEBUG(nullptr),
-                                       TypeInt::BYTE, MemNode::unordered);
-  Node* cset_cmp       = new CmpINode(cset_load, igvn.zerocon(T_INT));
-  Node* cset_bool      = new BoolNode(cset_cmp, BoolTest::ne);
-
-  IfNode* cset_iff     = new IfNode(old_ctrl, cset_bool, PROB_UNLIKELY(0.999), COUNT_UNKNOWN);
-  ctrl                 = new IfTrueNode(cset_iff);
-  not_cset_ctrl        = new IfFalseNode(cset_iff);
-
-  IdealLoopTree *loop = phase->get_loop(old_ctrl);
-  phase->register_control(cset_iff,      loop, old_ctrl);
-  phase->register_control(ctrl,          loop, cset_iff);
-  phase->register_control(not_cset_ctrl, loop, cset_iff);
-
-  phase->set_root_as_ctrl(cset_addr_ptr);
-
-  phase->register_new_node(raw_val,        old_ctrl);
-  phase->register_new_node(cset_idx,       old_ctrl);
-  phase->register_new_node(cset_addr,      old_ctrl);
-  phase->register_new_node(cset_load_addr, old_ctrl);
-  phase->register_new_node(cset_load_ptr,  old_ctrl);
-  phase->register_new_node(cset_load,      old_ctrl);
-  phase->register_new_node(cset_cmp,       old_ctrl);
-  phase->register_new_node(cset_bool,      old_ctrl);
-}
-
-void ShenandoahBarrierC2Support::call_lrb_stub(Node*& ctrl, Node*& val, Node* load_addr,
-                                               DecoratorSet decorators, PhaseIdealLoop* phase) {
-  IdealLoopTree*loop = phase->get_loop(ctrl);
-  const TypePtr* obj_type = phase->igvn().type(val)->is_oopptr();
-
-  address calladdr = nullptr;
-  const char* name = nullptr;
-  bool is_strong  = ShenandoahBarrierSet::is_strong_access(decorators);
-  bool is_weak    = ShenandoahBarrierSet::is_weak_access(decorators);
-  bool is_phantom = ShenandoahBarrierSet::is_phantom_access(decorators);
-  bool is_native  = ShenandoahBarrierSet::is_native_access(decorators);
-  bool is_narrow  = UseCompressedOops && !is_native;
-  if (is_strong) {
-    if (is_narrow) {
-      calladdr = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_strong_narrow);
-      name = "load_reference_barrier_strong_narrow";
-    } else {
-      calladdr = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_strong);
-      name = "load_reference_barrier_strong";
-    }
-  } else if (is_weak) {
-    if (is_narrow) {
-      calladdr = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_weak_narrow);
-      name = "load_reference_barrier_weak_narrow";
-    } else {
-      calladdr = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_weak);
-      name = "load_reference_barrier_weak";
-    }
-  } else {
-    assert(is_phantom, "only remaining strength");
-    if (is_narrow) {
-      calladdr = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_phantom_narrow);
-      name = "load_reference_barrier_phantom_narrow";
-    } else {
-      calladdr = CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_phantom);
-      name = "load_reference_barrier_phantom";
-    }
-  }
-  Node* call = new CallLeafNode(ShenandoahBarrierSetC2::load_reference_barrier_Type(), calladdr, name, TypeRawPtr::BOTTOM);
-
-  call->init_req(TypeFunc::Control, ctrl);
-  call->init_req(TypeFunc::I_O, phase->C->top());
-  call->init_req(TypeFunc::Memory, phase->C->top());
-  call->init_req(TypeFunc::FramePtr, phase->C->top());
-  call->init_req(TypeFunc::ReturnAdr, phase->C->top());
-  call->init_req(TypeFunc::Parms, val);
-  call->init_req(TypeFunc::Parms+1, load_addr);
-  phase->register_control(call, loop, ctrl);
-  ctrl = new ProjNode(call, TypeFunc::Control);
-  phase->register_control(ctrl, loop, call);
-  val = new ProjNode(call, TypeFunc::Parms);
-  phase->register_new_node(val, call);
-  val = new CheckCastPPNode(ctrl, val, obj_type);
-  phase->register_new_node(val, ctrl);
-}
-
-void ShenandoahBarrierC2Support::collect_nodes_above_barrier(Unique_Node_List &nodes_above_barrier, PhaseIdealLoop* phase, Node* ctrl, Node* init_raw_mem) {
-  nodes_above_barrier.clear();
-  if (phase->has_ctrl(init_raw_mem) && phase->get_ctrl(init_raw_mem) == ctrl && !init_raw_mem->is_Phi()) {
-    nodes_above_barrier.push(init_raw_mem);
-  }
-  for (uint next = 0; next < nodes_above_barrier.size(); next++) {
-    Node* n = nodes_above_barrier.at(next);
-    // Take anti-dependencies into account
-    maybe_push_anti_dependent_loads(phase, n, ctrl, nodes_above_barrier);
-    push_data_inputs_at_control(phase, n, ctrl, nodes_above_barrier);
-  }
-}
-
-void ShenandoahBarrierC2Support::fix_ctrl(Node* barrier, Node* region, const MemoryGraphFixer& fixer, Unique_Node_List& uses, Unique_Node_List& nodes_above_barrier, uint last, PhaseIdealLoop* phase) {
-  Node* ctrl = phase->get_ctrl(barrier);
-  Node* init_raw_mem = fixer.find_mem(ctrl, barrier);
-
-  // Update the control of all nodes that should be after the
-  // barrier control flow
-  uses.clear();
-  // Every node that is control dependent on the barrier's input
-  // control will be after the expanded barrier. The raw memory (if
-  // its memory is control dependent on the barrier's input control)
-  // must stay above the barrier.
-  collect_nodes_above_barrier(nodes_above_barrier, phase, ctrl, init_raw_mem);
-  for (DUIterator_Fast imax, i = ctrl->fast_outs(imax); i < imax; i++) {
-    Node* u = ctrl->fast_out(i);
-    if (u->_idx < last &&
-        u != barrier &&
-        !u->depends_only_on_test() && // preserve dependency on test
-        !nodes_above_barrier.member(u) &&
-        (u->in(0) != ctrl || (!u->is_Region() && !u->is_Phi())) &&
-        (ctrl->Opcode() != Op_CatchProj || u->Opcode() != Op_CreateEx)) {
-      Node* old_c = phase->ctrl_or_self(u);
-      if (old_c != ctrl ||
-          is_dominator_same_ctrl(old_c, barrier, u, phase) ||
-          ShenandoahBarrierSetC2::is_shenandoah_state_load(u)) {
-        phase->igvn().rehash_node_delayed(u);
-        int nb = u->replace_edge(ctrl, region, &phase->igvn());
-        if (u->is_CFG()) {
-          if (phase->idom(u) == ctrl) {
-            phase->set_idom(u, region, phase->dom_depth(region));
-          }
-        } else if (phase->get_ctrl(u) == ctrl) {
-          assert(u != init_raw_mem, "should leave input raw mem above the barrier");
-          uses.push(u);
-        }
-        assert(nb == 1, "more than 1 ctrl input?");
-        --i, imax -= nb;
-      }
-    }
-  }
-}
-
-static Node* create_phis_on_call_return(Node* ctrl, Node* c, Node* n, Node* n_clone, const CallProjections& projs, PhaseIdealLoop* phase) {
-  Node* region = nullptr;
-  while (c != ctrl) {
-    if (c->is_Region()) {
-      region = c;
-    }
-    c = phase->idom(c);
-  }
-  assert(region != nullptr, "");
-  Node* phi = new PhiNode(region, n->bottom_type());
-  for (uint j = 1; j < region->req(); j++) {
-    Node* in = region->in(j);
-    if (phase->is_dominator(projs.fallthrough_catchproj, in)) {
-      phi->init_req(j, n);
-    } else if (phase->is_dominator(projs.catchall_catchproj, in)) {
-      phi->init_req(j, n_clone);
-    } else {
-      phi->init_req(j, create_phis_on_call_return(ctrl, in, n, n_clone, projs, phase));
-    }
-  }
-  phase->register_new_node(phi, region);
-  return phi;
-}
-
-void ShenandoahBarrierC2Support::pin_and_expand(PhaseIdealLoop* phase) {
-  ShenandoahBarrierSetC2State* state = ShenandoahBarrierSetC2::bsc2()->state();
-
-  Unique_Node_List uses;
-  Node_Stack stack(0);
-  Node_List clones;
-  for (int i = state->load_reference_barriers_count() - 1; i >= 0; i--) {
-    ShenandoahLoadReferenceBarrierNode* lrb = state->load_reference_barrier(i);
-
-    Node* ctrl = phase->get_ctrl(lrb);
-    Node* val = lrb->in(ShenandoahLoadReferenceBarrierNode::ValueIn);
-
-    CallStaticJavaNode* unc = nullptr;
-    Node* unc_ctrl = nullptr;
-    Node* uncasted_val = val;
-
-    for (DUIterator_Fast imax, i = lrb->fast_outs(imax); i < imax; i++) {
-      Node* u = lrb->fast_out(i);
-      if (u->Opcode() == Op_CastPP &&
-          u->in(0) != nullptr &&
-          phase->is_dominator(u->in(0), ctrl)) {
-        const Type* u_t = phase->igvn().type(u);
-
-        if (u_t->meet(TypePtr::NULL_PTR) != u_t &&
-            u->in(0)->Opcode() == Op_IfTrue &&
-            u->in(0)->as_Proj()->is_uncommon_trap_if_pattern() &&
-            u->in(0)->in(0)->is_If() &&
-            u->in(0)->in(0)->in(1)->Opcode() == Op_Bool &&
-            u->in(0)->in(0)->in(1)->as_Bool()->_test._test == BoolTest::ne &&
-            u->in(0)->in(0)->in(1)->in(1)->Opcode() == Op_CmpP &&
-            u->in(0)->in(0)->in(1)->in(1)->in(1) == val &&
-            u->in(0)->in(0)->in(1)->in(1)->in(2)->bottom_type() == TypePtr::NULL_PTR) {
-          IdealLoopTree* loop = phase->get_loop(ctrl);
-          IdealLoopTree* unc_loop = phase->get_loop(u->in(0));
-
-          if (!unc_loop->is_member(loop)) {
-            continue;
-          }
-
-          Node* branch = no_branches(ctrl, u->in(0), false, phase);
-          assert(branch == nullptr || branch == NodeSentinel, "was not looking for a branch");
-          if (branch == NodeSentinel) {
-            continue;
-          }
-
-          Node* iff = u->in(0)->in(0);
-          Node* bol = iff->in(1)->clone();
-          Node* cmp = bol->in(1)->clone();
-          cmp->set_req(1, lrb);
-          bol->set_req(1, cmp);
-          phase->igvn().replace_input_of(iff, 1, bol);
-          phase->set_ctrl(lrb, iff->in(0));
-          phase->register_new_node(cmp, iff->in(0));
-          phase->register_new_node(bol, iff->in(0));
-          break;
-        }
-      }
-    }
-    // Load barrier on the control output of a call
-    if ((ctrl->is_Proj() && ctrl->in(0)->is_CallJava()) || ctrl->is_CallJava()) {
-      CallJavaNode* call = ctrl->is_Proj() ? ctrl->in(0)->as_CallJava() : ctrl->as_CallJava();
-      if (call->entry_point() == OptoRuntime::rethrow_stub()) {
-        // The rethrow call may have too many projections to be
-        // properly handled here. Given there's no reason for a
-        // barrier to depend on the call, move it above the call
-        stack.push(lrb, 0);
-        do {
-          Node* n = stack.node();
-          uint idx = stack.index();
-          if (idx < n->req()) {
-            Node* in = n->in(idx);
-            stack.set_index(idx+1);
-            if (in != nullptr) {
-              if (phase->has_ctrl(in)) {
-                if (phase->is_dominator(call, phase->get_ctrl(in))) {
-#ifdef ASSERT
-                  for (uint i = 0; i < stack.size(); i++) {
-                    assert(stack.node_at(i) != in, "node shouldn't have been seen yet");
-                  }
-#endif
-                  stack.push(in, 0);
-                }
-              } else {
-                assert(phase->is_dominator(in, call->in(0)), "no dependency on the call");
-              }
-            }
-          } else {
-            phase->set_ctrl(n, call->in(0));
-            stack.pop();
-          }
-        } while(stack.size() > 0);
-        continue;
-      }
-      CallProjections projs;
-      call->extract_projections(&projs, false, false);
-
-      // If this is a runtime call, it doesn't have an exception handling path
-      if (projs.fallthrough_catchproj == nullptr) {
-        assert(call->method() == nullptr, "should be runtime call");
-        assert(projs.catchall_catchproj == nullptr, "runtime call should not have catch all projection");
-        continue;
-      }
-
-      // Otherwise, clone the barrier so there's one for the fallthrough and one for the exception handling path
-#ifdef ASSERT
-      VectorSet cloned;
-#endif
-      Node* lrb_clone = lrb->clone();
-      phase->register_new_node(lrb_clone, projs.catchall_catchproj);
-      phase->set_ctrl(lrb, projs.fallthrough_catchproj);
-
-      stack.push(lrb, 0);
-      clones.push(lrb_clone);
-
-      do {
-        assert(stack.size() == clones.size(), "");
-        Node* n = stack.node();
-#ifdef ASSERT
-        if (n->is_Load()) {
-          Node* mem = n->in(MemNode::Memory);
-          for (DUIterator_Fast jmax, j = mem->fast_outs(jmax); j < jmax; j++) {
-            Node* u = mem->fast_out(j);
-            assert(!u->is_Store() || !u->is_LoadStore() || phase->get_ctrl(u) != ctrl, "anti dependent store?");
-          }
-        }
-#endif
-        uint idx = stack.index();
-        Node* n_clone = clones.at(clones.size()-1);
-        if (idx < n->outcnt()) {
-          Node* u = n->raw_out(idx);
-          Node* c = phase->ctrl_or_self(u);
-          if (phase->is_dominator(call, c) && phase->is_dominator(c, projs.fallthrough_proj)) {
-            stack.set_index(idx+1);
-            assert(!u->is_CFG(), "");
-            stack.push(u, 0);
-            assert(!cloned.test_set(u->_idx), "only one clone");
-            Node* u_clone = u->clone();
-            int nb = u_clone->replace_edge(n, n_clone, &phase->igvn());
-            assert(nb > 0, "should have replaced some uses");
-            phase->register_new_node(u_clone, projs.catchall_catchproj);
-            clones.push(u_clone);
-            phase->set_ctrl(u, projs.fallthrough_catchproj);
-          } else {
-            bool replaced = false;
-            if (u->is_Phi()) {
-              for (uint k = 1; k < u->req(); k++) {
-                if (u->in(k) == n) {
-                  if (phase->is_dominator(projs.catchall_catchproj, u->in(0)->in(k))) {
-                    phase->igvn().replace_input_of(u, k, n_clone);
-                    replaced = true;
-                  } else if (!phase->is_dominator(projs.fallthrough_catchproj, u->in(0)->in(k))) {
-                    phase->igvn().replace_input_of(u, k, create_phis_on_call_return(ctrl, u->in(0)->in(k), n, n_clone, projs, phase));
-                    replaced = true;
-                  }
-                }
-              }
-            } else {
-              if (phase->is_dominator(projs.catchall_catchproj, c)) {
-                phase->igvn().rehash_node_delayed(u);
-                int nb = u->replace_edge(n, n_clone, &phase->igvn());
-                assert(nb > 0, "should have replaced some uses");
-                replaced = true;
-              } else if (!phase->is_dominator(projs.fallthrough_catchproj, c)) {
-                if (u->is_If()) {
-                  // Can't break If/Bool/Cmp chain
-                  assert(n->is_Bool(), "unexpected If shape");
-                  assert(stack.node_at(stack.size()-2)->is_Cmp(), "unexpected If shape");
-                  assert(n_clone->is_Bool(), "unexpected clone");
-                  assert(clones.at(clones.size()-2)->is_Cmp(), "unexpected clone");
-                  Node* bol_clone = n->clone();
-                  Node* cmp_clone = stack.node_at(stack.size()-2)->clone();
-                  bol_clone->set_req(1, cmp_clone);
-
-                  Node* nn = stack.node_at(stack.size()-3);
-                  Node* nn_clone = clones.at(clones.size()-3);
-                  assert(nn->Opcode() == nn_clone->Opcode(), "mismatch");
-
-                  int nb = cmp_clone->replace_edge(nn, create_phis_on_call_return(ctrl, c, nn, nn_clone, projs, phase),
-                                                   &phase->igvn());
-                  assert(nb > 0, "should have replaced some uses");
-
-                  phase->register_new_node(bol_clone, u->in(0));
-                  phase->register_new_node(cmp_clone, u->in(0));
-
-                  phase->igvn().replace_input_of(u, 1, bol_clone);
-
-                } else {
-                  phase->igvn().rehash_node_delayed(u);
-                  int nb = u->replace_edge(n, create_phis_on_call_return(ctrl, c, n, n_clone, projs, phase), &phase->igvn());
-                  assert(nb > 0, "should have replaced some uses");
-                }
-                replaced = true;
-              }
-            }
-            if (!replaced) {
-              stack.set_index(idx+1);
-            }
-          }
-        } else {
-          stack.pop();
-          clones.pop();
-        }
-      } while (stack.size() > 0);
-      assert(stack.size() == 0 && clones.size() == 0, "");
-    }
-  }
-
-  for (int i = 0; i < state->load_reference_barriers_count(); i++) {
-    ShenandoahLoadReferenceBarrierNode* lrb = state->load_reference_barrier(i);
-    Node* ctrl = phase->get_ctrl(lrb);
-    IdealLoopTree* loop = phase->get_loop(ctrl);
-    Node* head = loop->head();
-    if (head->is_OuterStripMinedLoop()) {
-      // Expanding a barrier here will break loop strip mining
-      // verification. Transform the loop so the loop nest doesn't
-      // appear as strip mined.
-      OuterStripMinedLoopNode* outer = head->as_OuterStripMinedLoop();
-      hide_strip_mined_loop(outer, outer->unique_ctrl_out()->as_CountedLoop(), phase);
-    }
-    if (head->is_BaseCountedLoop() && ctrl->is_IfProj() && ctrl->in(0)->is_BaseCountedLoopEnd() &&
-        head->as_BaseCountedLoop()->loopexit() == ctrl->in(0)) {
-      Node* entry = head->in(LoopNode::EntryControl);
-      Node* backedge = head->in(LoopNode::LoopBackControl);
-      Node* new_head = new LoopNode(entry, backedge);
-      phase->register_control(new_head, phase->get_loop(entry), entry);
-      phase->replace_node_and_forward_ctrl(head, new_head);
-    }
-  }
-
-  // Expand load-reference-barriers
-  MemoryGraphFixer fixer(Compile::AliasIdxRaw, true, phase);
-  Unique_Node_List nodes_above_barriers;
-  for (int i = state->load_reference_barriers_count() - 1; i >= 0; i--) {
-    ShenandoahLoadReferenceBarrierNode* lrb = state->load_reference_barrier(i);
-    uint last = phase->C->unique();
-    Node* ctrl = phase->get_ctrl(lrb);
-    Node* val = lrb->in(ShenandoahLoadReferenceBarrierNode::ValueIn);
-
-    Node* orig_ctrl = ctrl;
-
-    Node* raw_mem = fixer.find_mem(ctrl, lrb);
-    Node* raw_mem_for_ctrl = fixer.find_mem(ctrl, nullptr);
-
-    IdealLoopTree *loop = phase->get_loop(ctrl);
-
-    Node* heap_stable_ctrl = nullptr;
-    Node* null_ctrl = nullptr;
-
-    assert(val->bottom_type()->make_oopptr(), "need oop");
-    assert(val->bottom_type()->make_oopptr()->const_oop() == nullptr, "expect non-constant");
-
-    enum { _heap_stable = 1, _evac_path, _not_cset, PATH_LIMIT };
-    Node* region = new RegionNode(PATH_LIMIT);
-    Node* val_phi = new PhiNode(region, val->bottom_type()->is_oopptr());
-
-    // Stable path.
-    int flags = ShenandoahHeap::HAS_FORWARDED;
-    if (!ShenandoahBarrierSet::is_strong_access(lrb->decorators())) {
-      flags |= ShenandoahHeap::WEAK_ROOTS;
-    }
-    test_gc_state(ctrl, raw_mem, heap_stable_ctrl, phase, flags);
-    IfNode* heap_stable_iff = heap_stable_ctrl->in(0)->as_If();
-
-    // Heap stable case
-    region->init_req(_heap_stable, heap_stable_ctrl);
-    val_phi->init_req(_heap_stable, val);
-
-    // Test for in-cset, unless it's a native-LRB. Native LRBs need to return null
-    // even for non-cset objects to prevent resurrection of such objects.
-    // Wires !in_cset(obj) to slot 2 of region and phis
-    Node* not_cset_ctrl = nullptr;
-    if (ShenandoahBarrierSet::is_strong_access(lrb->decorators())) {
-      test_in_cset(ctrl, not_cset_ctrl, val, raw_mem, phase);
-    }
-    if (not_cset_ctrl != nullptr) {
-      region->init_req(_not_cset, not_cset_ctrl);
-      val_phi->init_req(_not_cset, val);
-    } else {
-      region->del_req(_not_cset);
-      val_phi->del_req(_not_cset);
-    }
-
-    // Resolve object when orig-value is in cset.
-    // Make the unconditional resolve for fwdptr.
-
-    // Call lrb-stub and wire up that path in slots 4
-    Node* result_mem = nullptr;
-
-    Node* addr;
-    {
-      VectorSet visited;
-      addr = get_load_addr(phase, visited, lrb);
-    }
-    if (addr->Opcode() == Op_AddP) {
-      Node* orig_base = addr->in(AddPNode::Base);
-      Node* base = new CheckCastPPNode(ctrl, orig_base, orig_base->bottom_type(), ConstraintCastNode::StrongDependency);
-      phase->register_new_node(base, ctrl);
-      if (addr->in(AddPNode::Base) == addr->in((AddPNode::Address))) {
-        // Field access
-        addr = addr->clone();
-        addr->set_req(AddPNode::Base, base);
-        addr->set_req(AddPNode::Address, base);
-        phase->register_new_node(addr, ctrl);
-      } else {
-        Node* addr2 = addr->in(AddPNode::Address);
-        if (addr2->Opcode() == Op_AddP && addr2->in(AddPNode::Base) == addr2->in(AddPNode::Address) &&
-              addr2->in(AddPNode::Base) == orig_base) {
-          addr2 = addr2->clone();
-          addr2->set_req(AddPNode::Base, base);
-          addr2->set_req(AddPNode::Address, base);
-          phase->register_new_node(addr2, ctrl);
-          addr = addr->clone();
-          addr->set_req(AddPNode::Base, base);
-          addr->set_req(AddPNode::Address, addr2);
-          phase->register_new_node(addr, ctrl);
-        }
-      }
-    }
-    call_lrb_stub(ctrl, val, addr, lrb->decorators(), phase);
-    region->init_req(_evac_path, ctrl);
-    val_phi->init_req(_evac_path, val);
-
-    phase->register_control(region, loop, heap_stable_iff);
-    Node* out_val = val_phi;
-    phase->register_new_node(val_phi, region);
-
-    fix_ctrl(lrb, region, fixer, uses, nodes_above_barriers, last, phase);
-
-    ctrl = orig_ctrl;
-
-    phase->igvn().replace_node(lrb, out_val);
-
-    follow_barrier_uses(out_val, ctrl, uses, phase);
-
-    for(uint next = 0; next < uses.size(); next++ ) {
-      Node *n = uses.at(next);
-      assert(phase->get_ctrl(n) == ctrl, "bad control");
-      assert(n != raw_mem, "should leave input raw mem above the barrier");
-      phase->set_ctrl(n, region);
-      follow_barrier_uses(n, ctrl, uses, phase);
-    }
-    fixer.record_new_ctrl(ctrl, region, raw_mem, raw_mem_for_ctrl);
-  }
-  // Done expanding load-reference-barriers.
-  assert(ShenandoahBarrierSetC2::bsc2()->state()->load_reference_barriers_count() == 0, "all load reference barrier nodes should have been replaced");
-}
-
-Node* ShenandoahBarrierC2Support::get_load_addr(PhaseIdealLoop* phase, VectorSet& visited, Node* in) {
-  if (visited.test_set(in->_idx)) {
-    return nullptr;
-  }
-  switch (in->Opcode()) {
-    case Op_Proj:
-      return get_load_addr(phase, visited, in->in(0));
-    case Op_CastPP:
-    case Op_CheckCastPP:
-    case Op_DecodeN:
-    case Op_EncodeP:
-      return get_load_addr(phase, visited, in->in(1));
-    case Op_LoadN:
-    case Op_LoadP:
-      return in->in(MemNode::Address);
-    case Op_CompareAndExchangeN:
-    case Op_CompareAndExchangeP:
-    case Op_GetAndSetN:
-    case Op_GetAndSetP:
-    case Op_ShenandoahCompareAndExchangeP:
-    case Op_ShenandoahCompareAndExchangeN:
-      // Those instructions would just have stored a different
-      // value into the field. No use to attempt to fix it at this point.
-      return phase->igvn().zerocon(T_OBJECT);
-    case Op_CMoveP:
-    case Op_CMoveN: {
-      Node* t = get_load_addr(phase, visited, in->in(CMoveNode::IfTrue));
-      Node* f = get_load_addr(phase, visited, in->in(CMoveNode::IfFalse));
-      // Handle unambiguous cases: single address reported on both branches.
-      if (t != nullptr && f == nullptr) return t;
-      if (t == nullptr && f != nullptr) return f;
-      if (t != nullptr && t == f)    return t;
-      // Ambiguity.
-      return phase->igvn().zerocon(T_OBJECT);
-    }
-    case Op_Phi: {
-      Node* addr = nullptr;
-      for (uint i = 1; i < in->req(); i++) {
-        Node* addr1 = get_load_addr(phase, visited, in->in(i));
-        if (addr == nullptr) {
-          addr = addr1;
-        }
-        if (addr != addr1) {
-          return phase->igvn().zerocon(T_OBJECT);
-        }
-      }
-      return addr;
-    }
-    case Op_ShenandoahLoadReferenceBarrier:
-      return get_load_addr(phase, visited, in->in(ShenandoahLoadReferenceBarrierNode::ValueIn));
-    case Op_CallDynamicJava:
-    case Op_CallLeaf:
-    case Op_CallStaticJava:
-    case Op_ConN:
-    case Op_ConP:
-    case Op_Parm:
-    case Op_CreateEx:
-      return phase->igvn().zerocon(T_OBJECT);
-    default:
-#ifdef ASSERT
-      fatal("Unknown node in get_load_addr: %s", NodeClassNames[in->Opcode()]);
-#endif
-      return phase->igvn().zerocon(T_OBJECT);
-  }
-
-}
-
-#ifdef ASSERT
-static bool has_never_branch(Node* root) {
-  for (uint i = 1; i < root->req(); i++) {
-    Node* in = root->in(i);
-    if (in != nullptr && in->Opcode() == Op_Halt && in->in(0)->is_Proj() && in->in(0)->in(0)->is_NeverBranch()) {
-      return true;
-    }
-  }
-  return false;
-}
-#endif
-
-void MemoryGraphFixer::collect_memory_nodes() {
-  Node_Stack stack(0);
-  VectorSet visited;
-  Node_List regions;
-
-  // Walk the raw memory graph and create a mapping from CFG node to
-  // memory node. Exclude phis for now.
-  stack.push(_phase->C->root(), 1);
-  do {
-    Node* n = stack.node();
-    int opc = n->Opcode();
-    uint i = stack.index();
-    if (i < n->req()) {
-      Node* mem = nullptr;
-      if (opc == Op_Root) {
-        Node* in = n->in(i);
-        int in_opc = in->Opcode();
-        if (in_opc == Op_Return || in_opc == Op_Rethrow) {
-          mem = in->in(TypeFunc::Memory);
-        } else if (in_opc == Op_Halt) {
-          if (in->in(0)->is_Region()) {
-            Node* r = in->in(0);
-            for (uint j = 1; j < r->req(); j++) {
-              assert(!r->in(j)->is_NeverBranch(), "");
-            }
-          } else {
-            Node* proj = in->in(0);
-            assert(proj->is_Proj(), "");
-            Node* in = proj->in(0);
-            assert(in->is_CallStaticJava() || in->is_NeverBranch() || in->Opcode() == Op_Catch || proj->is_IfProj(), "");
-            if (in->is_CallStaticJava()) {
-              mem = in->in(TypeFunc::Memory);
-            } else if (in->Opcode() == Op_Catch) {
-              Node* call = in->in(0)->in(0);
-              assert(call->is_Call(), "");
-              mem = call->in(TypeFunc::Memory);
-            } else if (in->is_NeverBranch()) {
-              mem = collect_memory_for_infinite_loop(in);
-            }
-          }
-        } else {
-#ifdef ASSERT
-          n->dump();
-          in->dump();
-#endif
-          ShouldNotReachHere();
-        }
-      } else {
-        assert(n->is_Phi() && n->bottom_type() == Type::MEMORY, "");
-        assert(n->adr_type() == TypePtr::BOTTOM || _phase->C->get_alias_index(n->adr_type()) == _alias, "");
-        mem = n->in(i);
-      }
-      i++;
-      stack.set_index(i);
-      if (mem == nullptr) {
-        continue;
-      }
-      for (;;) {
-        if (visited.test_set(mem->_idx) || mem->is_Start()) {
-          break;
-        }
-        if (mem->is_Phi()) {
-          stack.push(mem, 2);
-          mem = mem->in(1);
-        } else if (mem->is_Proj()) {
-          stack.push(mem, mem->req());
-          mem = mem->in(0);
-        } else if (mem->is_SafePoint() || mem->is_MemBar()) {
-          mem = mem->in(TypeFunc::Memory);
-        } else if (mem->is_MergeMem()) {
-          MergeMemNode* mm = mem->as_MergeMem();
-          mem = mm->memory_at(_alias);
-        } else if (mem->is_Store() || mem->is_LoadStore() || mem->is_ClearArray()) {
-          assert(_alias == Compile::AliasIdxRaw, "");
-          stack.push(mem, mem->req());
-          mem = mem->in(MemNode::Memory);
-        } else {
-#ifdef ASSERT
-          mem->dump();
-#endif
-          ShouldNotReachHere();
-        }
-      }
-    } else {
-      if (n->is_Phi()) {
-        // Nothing
-      } else if (!n->is_Root()) {
-        Node* c = get_ctrl(n);
-        _memory_nodes.map(c->_idx, n);
-      }
-      stack.pop();
-    }
-  } while(stack.is_nonempty());
-
-  // Iterate over CFG nodes in rpo and propagate memory state to
-  // compute memory state at regions, creating new phis if needed.
-  Node_List rpo_list;
-  visited.clear();
-  _phase->rpo(_phase->C->root(), stack, visited, rpo_list);
-  Node* root = rpo_list.pop();
-  assert(root == _phase->C->root(), "");
-
-  const bool trace = false;
-#ifdef ASSERT
-  if (trace) {
-    for (int i = rpo_list.size() - 1; i >= 0; i--) {
-      Node* c = rpo_list.at(i);
-      if (_memory_nodes[c->_idx] != nullptr) {
-        tty->print("X %d", c->_idx);  _memory_nodes[c->_idx]->dump();
-      }
-    }
-  }
-#endif
-  uint last = _phase->C->unique();
-
-#ifdef ASSERT
-  uint16_t max_depth = 0;
-  for (LoopTreeIterator iter(_phase->ltree_root()); !iter.done(); iter.next()) {
-    IdealLoopTree* lpt = iter.current();
-    max_depth = MAX2(max_depth, lpt->_nest);
-  }
-#endif
-
-  bool progress = true;
-  int iteration = 0;
-  Node_List dead_phis;
-  while (progress) {
-    progress = false;
-    iteration++;
-    assert(iteration <= 2+max_depth || _phase->C->has_irreducible_loop() || has_never_branch(_phase->C->root()), "");
-    if (trace) { tty->print_cr("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); }
-
-    for (int i = rpo_list.size() - 1; i >= 0; i--) {
-      Node* c = rpo_list.at(i);
-
-      Node* prev_mem = _memory_nodes[c->_idx];
-      if (c->is_Region() && (_include_lsm || !c->is_OuterStripMinedLoop())) {
-        Node* prev_region = regions[c->_idx];
-        Node* unique = nullptr;
-        for (uint j = 1; j < c->req() && unique != NodeSentinel; j++) {
-          Node* m = _memory_nodes[c->in(j)->_idx];
-          assert(m != nullptr || (c->is_Loop() && j == LoopNode::LoopBackControl && iteration == 1) || _phase->C->has_irreducible_loop() || has_never_branch(_phase->C->root()), "expect memory state");
-          if (m != nullptr) {
-            if (m == prev_region && ((c->is_Loop() && j == LoopNode::LoopBackControl) || (prev_region->is_Phi() && prev_region->in(0) == c))) {
-              assert((c->is_Loop() && j == LoopNode::LoopBackControl) || _phase->C->has_irreducible_loop() || has_never_branch(_phase->C->root()), "");
-              // continue
-            } else if (unique == nullptr) {
-              unique = m;
-            } else if (m == unique) {
-              // continue
-            } else {
-              unique = NodeSentinel;
-            }
-          }
-        }
-        assert(unique != nullptr, "empty phi???");
-        if (unique != NodeSentinel) {
-          if (prev_region != nullptr && prev_region->is_Phi() && prev_region->in(0) == c) {
-            dead_phis.push(prev_region);
-          }
-          regions.map(c->_idx, unique);
-        } else {
-          Node* phi = nullptr;
-          if (prev_region != nullptr && prev_region->is_Phi() && prev_region->in(0) == c && prev_region->_idx >= last) {
-            phi = prev_region;
-            for (uint k = 1; k < c->req(); k++) {
-              Node* m = _memory_nodes[c->in(k)->_idx];
-              assert(m != nullptr, "expect memory state");
-              phi->set_req(k, m);
-            }
-          } else {
-            for (DUIterator_Fast jmax, j = c->fast_outs(jmax); j < jmax && phi == nullptr; j++) {
-              Node* u = c->fast_out(j);
-              if (u->is_Phi() && u->bottom_type() == Type::MEMORY &&
-                  (u->adr_type() == TypePtr::BOTTOM || _phase->C->get_alias_index(u->adr_type()) == _alias)) {
-                phi = u;
-                for (uint k = 1; k < c->req() && phi != nullptr; k++) {
-                  Node* m = _memory_nodes[c->in(k)->_idx];
-                  assert(m != nullptr, "expect memory state");
-                  if (u->in(k) != m) {
-                    phi = NodeSentinel;
-                  }
-                }
-              }
-            }
-            if (phi == NodeSentinel) {
-              phi = new PhiNode(c, Type::MEMORY, _phase->C->get_adr_type(_alias));
-              for (uint k = 1; k < c->req(); k++) {
-                Node* m = _memory_nodes[c->in(k)->_idx];
-                assert(m != nullptr, "expect memory state");
-                phi->init_req(k, m);
-              }
-            }
-          }
-          if (phi != nullptr) {
-            regions.map(c->_idx, phi);
-          } else {
-            assert(c->unique_ctrl_out()->Opcode() == Op_Halt, "expected memory state");
-          }
-        }
-        Node* current_region = regions[c->_idx];
-        if (current_region != prev_region) {
-          progress = true;
-          if (prev_region == prev_mem) {
-            _memory_nodes.map(c->_idx, current_region);
-          }
-        }
-      } else if (prev_mem == nullptr || prev_mem->is_Phi() || ctrl_or_self(prev_mem) != c) {
-        Node* m = _memory_nodes[_phase->idom(c)->_idx];
-        assert(m != nullptr || c->Opcode() == Op_Halt, "expect memory state");
-        if (m != prev_mem) {
-          _memory_nodes.map(c->_idx, m);
-          progress = true;
-        }
-      }
-#ifdef ASSERT
-      if (trace) { tty->print("X %d", c->_idx);  _memory_nodes[c->_idx]->dump(); }
-#endif
-    }
-  }
-
-  // Replace existing phi with computed memory state for that region
-  // if different (could be a new phi or a dominating memory node if
-  // that phi was found to be useless).
-  while (dead_phis.size() > 0) {
-    Node* n = dead_phis.pop();
-    n->replace_by(_phase->C->top());
-    n->destruct(&_phase->igvn());
-  }
-  for (int i = rpo_list.size() - 1; i >= 0; i--) {
-    Node* c = rpo_list.at(i);
-    if (c->is_Region() && (_include_lsm || !c->is_OuterStripMinedLoop())) {
-      Node* n = regions[c->_idx];
-      assert(n != nullptr || c->unique_ctrl_out()->Opcode() == Op_Halt, "expected memory state");
-      if (n != nullptr && n->is_Phi() && n->_idx >= last && n->in(0) == c) {
-        _phase->register_new_node(n, c);
-      }
-    }
-  }
-  for (int i = rpo_list.size() - 1; i >= 0; i--) {
-    Node* c = rpo_list.at(i);
-    if (c->is_Region() && (_include_lsm || !c->is_OuterStripMinedLoop())) {
-      Node* n = regions[c->_idx];
-      assert(n != nullptr || c->unique_ctrl_out()->Opcode() == Op_Halt, "expected memory state");
-      for (DUIterator_Fast imax, i = c->fast_outs(imax); i < imax; i++) {
-        Node* u = c->fast_out(i);
-        if (u->is_Phi() && u->bottom_type() == Type::MEMORY &&
-            u != n) {
-          assert(c->unique_ctrl_out()->Opcode() != Op_Halt, "expected memory state");
-          if (u->adr_type() == TypePtr::BOTTOM) {
-            fix_memory_uses(u, n, n, c);
-          } else if (_phase->C->get_alias_index(u->adr_type()) == _alias) {
-            _phase->igvn().replace_node(u, n);
-            --i; --imax;
-          }
-        }
-      }
-    }
-  }
-}
-
-Node* MemoryGraphFixer::collect_memory_for_infinite_loop(const Node* in) {
-  Node* mem = nullptr;
-  Node* head = in->in(0);
-  assert(head->is_Region(), "unexpected infinite loop graph shape");
-
-  Node* phi_mem = nullptr;
-  for (DUIterator_Fast jmax, j = head->fast_outs(jmax); j < jmax; j++) {
-    Node* u = head->fast_out(j);
-    if (u->is_Phi() && u->bottom_type() == Type::MEMORY) {
-      if (_phase->C->get_alias_index(u->adr_type()) == _alias) {
-        assert(phi_mem == nullptr || phi_mem->adr_type() == TypePtr::BOTTOM, "");
-        phi_mem = u;
-      } else if (u->adr_type() == TypePtr::BOTTOM) {
-        assert(phi_mem == nullptr || _phase->C->get_alias_index(phi_mem->adr_type()) == _alias, "");
-        if (phi_mem == nullptr) {
-          phi_mem = u;
-        }
-      }
-    }
-  }
-  if (phi_mem == nullptr) {
-    ResourceMark rm;
-    Node_Stack stack(0);
-    stack.push(head, 1);
-    do {
-      Node* n = stack.node();
-      uint i = stack.index();
-      if (i >= n->req()) {
-        stack.pop();
-      } else {
-        stack.set_index(i + 1);
-        Node* c = n->in(i);
-        assert(c != head, "should have found a safepoint on the way");
-        if (stack.size() != 1 || _phase->is_dominator(head, c)) {
-          for (;;) {
-            if (c->is_Region()) {
-              stack.push(c, 1);
-              break;
-            } else if (c->is_SafePoint() && !c->is_CallLeaf()) {
-              Node* m = c->in(TypeFunc::Memory);
-              if (m->is_MergeMem()) {
-                m = m->as_MergeMem()->memory_at(_alias);
-              }
-              assert(mem == nullptr || mem == m, "several memory states");
-              mem = m;
-              break;
-            } else {
-              assert(c != c->in(0), "");
-              c = c->in(0);
-            }
-          }
-        }
-      }
-    } while (stack.size() > 0);
-    assert(mem != nullptr, "should have found safepoint");
-  } else {
-    mem = phi_mem;
-  }
-  return mem;
-}
-
-Node* MemoryGraphFixer::get_ctrl(Node* n) const {
-  Node* c = _phase->get_ctrl(n);
-  if (n->is_Proj() && n->in(0) != nullptr && n->in(0)->is_Call()) {
-    assert(c == n->in(0), "");
-    CallNode* call = c->as_Call();
-    CallProjections projs;
-    call->extract_projections(&projs, true, false);
-    if (projs.catchall_memproj != nullptr) {
-      if (projs.fallthrough_memproj == n) {
-        c = projs.fallthrough_catchproj;
-      } else {
-        assert(projs.catchall_memproj == n, "");
-        c = projs.catchall_catchproj;
-      }
-    }
-  }
-  return c;
-}
-
-Node* MemoryGraphFixer::ctrl_or_self(Node* n) const {
-  if (_phase->has_ctrl(n))
-    return get_ctrl(n);
-  else {
-    assert (n->is_CFG(), "must be a CFG node");
-    return n;
-  }
-}
-
-bool MemoryGraphFixer::mem_is_valid(Node* m, Node* c) const {
-  return m != nullptr && get_ctrl(m) == c;
-}
-
-Node* MemoryGraphFixer::find_mem(Node* ctrl, Node* n) const {
-  assert(n == nullptr || _phase->ctrl_or_self(n) == ctrl, "");
-  assert(!ctrl->is_Call() || ctrl == n, "projection expected");
-#ifdef ASSERT
-  if ((ctrl->is_Proj() && ctrl->in(0)->is_Call()) ||
-      (ctrl->is_Catch() && ctrl->in(0)->in(0)->is_Call())) {
-    CallNode* call = ctrl->is_Proj() ? ctrl->in(0)->as_Call() : ctrl->in(0)->in(0)->as_Call();
-    int mems = 0;
-    for (DUIterator_Fast imax, i = call->fast_outs(imax); i < imax; i++) {
-      Node* u = call->fast_out(i);
-      if (u->bottom_type() == Type::MEMORY) {
-        mems++;
-      }
-    }
-    assert(mems <= 1, "No node right after call if multiple mem projections");
-  }
-#endif
-  Node* mem = _memory_nodes[ctrl->_idx];
-  Node* c = ctrl;
-  while (!mem_is_valid(mem, c) &&
-         (!c->is_CatchProj() || mem == nullptr || c->in(0)->in(0)->in(0) != get_ctrl(mem))) {
-    c = _phase->idom(c);
-    mem = _memory_nodes[c->_idx];
-  }
-  if (n != nullptr && mem_is_valid(mem, c)) {
-    while (!ShenandoahBarrierC2Support::is_dominator_same_ctrl(c, mem, n, _phase) && _phase->ctrl_or_self(mem) == ctrl) {
-      mem = next_mem(mem, _alias);
-    }
-    if (mem->is_MergeMem()) {
-      mem = mem->as_MergeMem()->memory_at(_alias);
-    }
-    if (!mem_is_valid(mem, c)) {
-      do {
-        c = _phase->idom(c);
-        mem = _memory_nodes[c->_idx];
-      } while (!mem_is_valid(mem, c) &&
-               (!c->is_CatchProj() || mem == nullptr || c->in(0)->in(0)->in(0) != get_ctrl(mem)));
-    }
-  }
-  assert(mem->bottom_type() == Type::MEMORY, "");
-  return mem;
-}
-
-bool MemoryGraphFixer::has_mem_phi(Node* region) const {
-  for (DUIterator_Fast imax, i = region->fast_outs(imax); i < imax; i++) {
-    Node* use = region->fast_out(i);
-    if (use->is_Phi() && use->bottom_type() == Type::MEMORY &&
-        (_phase->C->get_alias_index(use->adr_type()) == _alias)) {
-      return true;
-    }
-  }
-  return false;
-}
-
-void MemoryGraphFixer::fix_mem(Node* ctrl, Node* new_ctrl, Node* mem, Node* mem_for_ctrl, Node* new_mem, Unique_Node_List& uses) {
-  assert(_phase->ctrl_or_self(new_mem) == new_ctrl, "");
-  const bool trace = false;
-  DEBUG_ONLY(if (trace) { tty->print("ZZZ control is"); ctrl->dump(); });
-  DEBUG_ONLY(if (trace) { tty->print("ZZZ mem is"); mem->dump(); });
-  GrowableArray<Node*> phis;
-  if (mem_for_ctrl != mem) {
-    Node* old = mem_for_ctrl;
-    Node* prev = nullptr;
-    while (old != mem) {
-      prev = old;
-      if (old->is_Store() || old->is_ClearArray() || old->is_LoadStore()) {
-        assert(_alias == Compile::AliasIdxRaw, "");
-        old = old->in(MemNode::Memory);
-      } else if (old->Opcode() == Op_SCMemProj) {
-        assert(_alias == Compile::AliasIdxRaw, "");
-        old = old->in(0);
-      } else {
-        ShouldNotReachHere();
-      }
-    }
-    assert(prev != nullptr, "");
-    if (new_ctrl != ctrl) {
-      _memory_nodes.map(ctrl->_idx, mem);
-      _memory_nodes.map(new_ctrl->_idx, mem_for_ctrl);
-    }
-    uint input = (uint)MemNode::Memory;
-    _phase->igvn().replace_input_of(prev, input, new_mem);
-  } else {
-    uses.clear();
-    _memory_nodes.map(new_ctrl->_idx, new_mem);
-    uses.push(new_ctrl);
-    for(uint next = 0; next < uses.size(); next++ ) {
-      Node *n = uses.at(next);
-      assert(n->is_CFG(), "");
-      DEBUG_ONLY(if (trace) { tty->print("ZZZ ctrl"); n->dump(); });
-      for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
-        Node* u = n->fast_out(i);
-        if (!u->is_Root() && u->is_CFG() && u != n) {
-          Node* m = _memory_nodes[u->_idx];
-          if (u->is_Region() && (!u->is_OuterStripMinedLoop() || _include_lsm) &&
-              !has_mem_phi(u) &&
-              u->unique_ctrl_out()->Opcode() != Op_Halt) {
-            DEBUG_ONLY(if (trace) { tty->print("ZZZ region"); u->dump(); });
-            DEBUG_ONLY(if (trace && m != nullptr) { tty->print("ZZZ mem"); m->dump(); });
-
-            if (!mem_is_valid(m, u) || !m->is_Phi()) {
-              bool push = true;
-              bool create_phi = true;
-              if (_phase->is_dominator(new_ctrl, u)) {
-                create_phi = false;
-              }
-              if (create_phi) {
-                Node* phi = new PhiNode(u, Type::MEMORY, _phase->C->get_adr_type(_alias));
-                _phase->register_new_node(phi, u);
-                phis.push(phi);
-                DEBUG_ONLY(if (trace) { tty->print("ZZZ new phi"); phi->dump(); });
-                if (!mem_is_valid(m, u)) {
-                  DEBUG_ONLY(if (trace) { tty->print("ZZZ setting mem"); phi->dump(); });
-                  _memory_nodes.map(u->_idx, phi);
-                } else {
-                  DEBUG_ONLY(if (trace) { tty->print("ZZZ NOT setting mem"); m->dump(); });
-                  for (;;) {
-                    assert(m->is_Mem() || m->is_LoadStore() || m->is_Proj(), "");
-                    Node* next = nullptr;
-                    if (m->is_Proj()) {
-                      next = m->in(0);
-                    } else {
-                      assert(m->is_Mem() || m->is_LoadStore(), "");
-                      assert(_alias == Compile::AliasIdxRaw, "");
-                      next = m->in(MemNode::Memory);
-                    }
-                    if (_phase->get_ctrl(next) != u) {
-                      break;
-                    }
-                    if (next->is_MergeMem()) {
-                      assert(_phase->get_ctrl(next->as_MergeMem()->memory_at(_alias)) != u, "");
-                      break;
-                    }
-                    if (next->is_Phi()) {
-                      assert(next->adr_type() == TypePtr::BOTTOM && next->in(0) == u, "");
-                      break;
-                    }
-                    m = next;
-                  }
-
-                  DEBUG_ONLY(if (trace) { tty->print("ZZZ setting to phi"); m->dump(); });
-                  assert(m->is_Mem() || m->is_LoadStore(), "");
-                  uint input = (uint)MemNode::Memory;
-                  _phase->igvn().replace_input_of(m, input, phi);
-                  push = false;
-                }
-              } else {
-                DEBUG_ONLY(if (trace) { tty->print("ZZZ skipping region"); u->dump(); });
-              }
-              if (push) {
-                uses.push(u);
-              }
-            }
-          } else if (!mem_is_valid(m, u) &&
-                     !(u->Opcode() == Op_CProj && u->in(0)->is_NeverBranch() && u->as_Proj()->_con == 1)) {
-            uses.push(u);
-          }
-        }
-      }
-    }
-    for (int i = 0; i < phis.length(); i++) {
-      Node* n = phis.at(i);
-      Node* r = n->in(0);
-      DEBUG_ONLY(if (trace) { tty->print("ZZZ fixing new phi"); n->dump(); });
-      for (uint j = 1; j < n->req(); j++) {
-        Node* m = find_mem(r->in(j), nullptr);
-        _phase->igvn().replace_input_of(n, j, m);
-        DEBUG_ONLY(if (trace) { tty->print("ZZZ fixing new phi: %d", j); m->dump(); });
-      }
-    }
-  }
-  uint last = _phase->C->unique();
-  MergeMemNode* mm = nullptr;
-  int alias = _alias;
-  DEBUG_ONLY(if (trace) { tty->print("ZZZ raw mem is"); mem->dump(); });
-  // Process loads first to not miss an anti-dependency: if the memory
-  // edge of a store is updated before a load is processed then an
-  // anti-dependency may be missed.
-  for (DUIterator i = mem->outs(); mem->has_out(i); i++) {
-    Node* u = mem->out(i);
-    if (u->_idx < last && u->is_Load() && _phase->C->get_alias_index(u->adr_type()) == alias) {
-      Node* m = find_mem(_phase->get_ctrl(u), u);
-      if (m != mem) {
-        DEBUG_ONLY(if (trace) { tty->print("ZZZ setting memory of use"); u->dump(); });
-        _phase->igvn().replace_input_of(u, MemNode::Memory, m);
-        --i;
-      }
-    }
-  }
-  for (DUIterator i = mem->outs(); mem->has_out(i); i++) {
-    Node* u = mem->out(i);
-    if (u->_idx < last) {
-      if (u->is_Mem()) {
-        if (_phase->C->get_alias_index(u->adr_type()) == alias) {
-          Node* m = find_mem(_phase->get_ctrl(u), u);
-          if (m != mem) {
-            DEBUG_ONLY(if (trace) { tty->print("ZZZ setting memory of use"); u->dump(); });
-            _phase->igvn().replace_input_of(u, MemNode::Memory, m);
-            --i;
-          }
-        }
-      } else if (u->is_MergeMem()) {
-        MergeMemNode* u_mm = u->as_MergeMem();
-        if (u_mm->memory_at(alias) == mem) {
-          MergeMemNode* newmm = nullptr;
-          for (DUIterator_Fast jmax, j = u->fast_outs(jmax); j < jmax; j++) {
-            Node* uu = u->fast_out(j);
-            assert(!uu->is_MergeMem(), "chain of MergeMems?");
-            if (uu->is_Phi()) {
-              assert(uu->adr_type() == TypePtr::BOTTOM, "");
-              Node* region = uu->in(0);
-              int nb = 0;
-              for (uint k = 1; k < uu->req(); k++) {
-                if (uu->in(k) == u) {
-                  Node* m = find_mem(region->in(k), nullptr);
-                  if (m != mem) {
-                    DEBUG_ONLY(if (trace) { tty->print("ZZZ setting memory of phi %d", k); uu->dump(); });
-                    newmm = clone_merge_mem(u, mem, m, _phase->ctrl_or_self(m), i);
-                    if (newmm != u) {
-                      _phase->igvn().replace_input_of(uu, k, newmm);
-                      nb++;
-                      --jmax;
-                    }
-                  }
-                }
-              }
-              if (nb > 0) {
-                --j;
-              }
-            } else {
-              Node* m = find_mem(_phase->ctrl_or_self(uu), uu);
-              if (m != mem) {
-                DEBUG_ONLY(if (trace) { tty->print("ZZZ setting memory of use"); uu->dump(); });
-                newmm = clone_merge_mem(u, mem, m, _phase->ctrl_or_self(m), i);
-                if (newmm != u) {
-                  _phase->igvn().replace_input_of(uu, uu->find_edge(u), newmm);
-                  --j, --jmax;
-                }
-              }
-            }
-          }
-        }
-      } else if (u->is_Phi()) {
-        assert(u->bottom_type() == Type::MEMORY, "what else?");
-        if (_phase->C->get_alias_index(u->adr_type()) == alias || u->adr_type() == TypePtr::BOTTOM) {
-          Node* region = u->in(0);
-          bool replaced = false;
-          for (uint j = 1; j < u->req(); j++) {
-            if (u->in(j) == mem) {
-              Node* m = find_mem(region->in(j), nullptr);
-              Node* nnew = m;
-              if (m != mem) {
-                if (u->adr_type() == TypePtr::BOTTOM) {
-                  mm = allocate_merge_mem(mem, m, _phase->ctrl_or_self(m));
-                  nnew = mm;
-                }
-                DEBUG_ONLY(if (trace) { tty->print("ZZZ setting memory of phi %d", j); u->dump(); });
-                _phase->igvn().replace_input_of(u, j, nnew);
-                replaced = true;
-              }
-            }
-          }
-          if (replaced) {
-            --i;
-          }
-        }
-      } else if ((u->adr_type() == TypePtr::BOTTOM && u->Opcode() != Op_StrInflatedCopy) ||
-                 u->adr_type() == nullptr) {
-        assert(u->adr_type() != nullptr ||
-               u->Opcode() == Op_Rethrow ||
-               u->Opcode() == Op_Return ||
-               u->Opcode() == Op_SafePoint ||
-               (u->is_CallStaticJava() && u->as_CallStaticJava()->uncommon_trap_request() != 0) ||
-               (u->is_CallStaticJava() && u->as_CallStaticJava()->_entry_point == OptoRuntime::rethrow_stub()) ||
-               u->Opcode() == Op_CallLeaf, "");
-        Node* m = find_mem(_phase->ctrl_or_self(u), u);
-        if (m != mem) {
-          mm = allocate_merge_mem(mem, m, _phase->get_ctrl(m));
-          _phase->igvn().replace_input_of(u, u->find_edge(mem), mm);
-          --i;
-        }
-      } else if (_phase->C->get_alias_index(u->adr_type()) == alias) {
-        Node* m = find_mem(_phase->ctrl_or_self(u), u);
-        if (m != mem) {
-          DEBUG_ONLY(if (trace) { tty->print("ZZZ setting memory of use"); u->dump(); });
-          _phase->igvn().replace_input_of(u, u->find_edge(mem), m);
-          --i;
-        }
-      } else if (u->adr_type() != TypePtr::BOTTOM &&
-                 _memory_nodes[_phase->ctrl_or_self(u)->_idx] == u) {
-        Node* m = find_mem(_phase->ctrl_or_self(u), u);
-        assert(m != mem, "");
-        // u is on the wrong slice...
-        assert(u->is_ClearArray(), "");
-        DEBUG_ONLY(if (trace) { tty->print("ZZZ setting memory of use"); u->dump(); });
-        _phase->igvn().replace_input_of(u, u->find_edge(mem), m);
-        --i;
-      }
-    }
-  }
-#ifdef ASSERT
-  assert(new_mem->outcnt() > 0, "");
-  for (int i = 0; i < phis.length(); i++) {
-    Node* n = phis.at(i);
-    assert(n->outcnt() > 0, "new phi must have uses now");
-  }
-#endif
-}
-
-void MemoryGraphFixer::record_new_ctrl(Node* ctrl, Node* new_ctrl, Node* mem, Node* mem_for_ctrl) {
-  if (mem_for_ctrl != mem && new_ctrl != ctrl) {
-    _memory_nodes.map(ctrl->_idx, mem);
-    _memory_nodes.map(new_ctrl->_idx, mem_for_ctrl);
-  }
-}
-
-MergeMemNode* MemoryGraphFixer::allocate_merge_mem(Node* mem, Node* rep_proj, Node* rep_ctrl) const {
-  MergeMemNode* mm = MergeMemNode::make(mem);
-  mm->set_memory_at(_alias, rep_proj);
-  _phase->register_new_node(mm, rep_ctrl);
-  return mm;
-}
-
-MergeMemNode* MemoryGraphFixer::clone_merge_mem(Node* u, Node* mem, Node* rep_proj, Node* rep_ctrl, DUIterator& i) const {
-  MergeMemNode* newmm = nullptr;
-  MergeMemNode* u_mm = u->as_MergeMem();
-  Node* c = _phase->get_ctrl(u);
-  if (_phase->is_dominator(c, rep_ctrl)) {
-    c = rep_ctrl;
-  } else {
-    assert(_phase->is_dominator(rep_ctrl, c), "one must dominate the other");
-  }
-  if (u->outcnt() == 1) {
-    if (u->req() > (uint)_alias && u->in(_alias) == mem) {
-      _phase->igvn().replace_input_of(u, _alias, rep_proj);
-      --i;
-    } else {
-      _phase->igvn().rehash_node_delayed(u);
-      u_mm->set_memory_at(_alias, rep_proj);
-    }
-    newmm = u_mm;
-    _phase->set_ctrl_and_loop(u, c);
-  } else {
-    // can't simply clone u and then change one of its input because
-    // it adds and then removes an edge which messes with the
-    // DUIterator
-    newmm = MergeMemNode::make(u_mm->base_memory());
-    for (uint j = 0; j < u->req(); j++) {
-      if (j < newmm->req()) {
-        if (j == (uint)_alias) {
-          newmm->set_req(j, rep_proj);
-        } else if (newmm->in(j) != u->in(j)) {
-          newmm->set_req(j, u->in(j));
-        }
-      } else if (j == (uint)_alias) {
-        newmm->add_req(rep_proj);
-      } else {
-        newmm->add_req(u->in(j));
-      }
-    }
-    if ((uint)_alias >= u->req()) {
-      newmm->set_memory_at(_alias, rep_proj);
-    }
-    _phase->register_new_node(newmm, c);
-  }
-  return newmm;
-}
-
-bool MemoryGraphFixer::should_process_phi(Node* phi) const {
-  if (phi->adr_type() == TypePtr::BOTTOM) {
-    Node* region = phi->in(0);
-    for (DUIterator_Fast jmax, j = region->fast_outs(jmax); j < jmax; j++) {
-      Node* uu = region->fast_out(j);
-      if (uu->is_Phi() && uu != phi && uu->bottom_type() == Type::MEMORY && _phase->C->get_alias_index(uu->adr_type()) == _alias) {
-        return false;
-      }
-    }
-    return true;
-  }
-  return _phase->C->get_alias_index(phi->adr_type()) == _alias;
-}
-
-void MemoryGraphFixer::fix_memory_uses(Node* mem, Node* replacement, Node* rep_proj, Node* rep_ctrl) const {
-  uint last = _phase-> C->unique();
-  MergeMemNode* mm = nullptr;
-  assert(mem->bottom_type() == Type::MEMORY, "");
-  for (DUIterator i = mem->outs(); mem->has_out(i); i++) {
-    Node* u = mem->out(i);
-    if (u != replacement && u->_idx < last) {
-      if (u->is_MergeMem()) {
-        MergeMemNode* u_mm = u->as_MergeMem();
-        if (u_mm->memory_at(_alias) == mem) {
-          MergeMemNode* newmm = nullptr;
-          for (DUIterator_Fast jmax, j = u->fast_outs(jmax); j < jmax; j++) {
-            Node* uu = u->fast_out(j);
-            assert(!uu->is_MergeMem(), "chain of MergeMems?");
-            if (uu->is_Phi()) {
-              if (should_process_phi(uu)) {
-                Node* region = uu->in(0);
-                int nb = 0;
-                for (uint k = 1; k < uu->req(); k++) {
-                  if (uu->in(k) == u && _phase->is_dominator(rep_ctrl, region->in(k))) {
-                    if (newmm == nullptr) {
-                      newmm = clone_merge_mem(u, mem, rep_proj, rep_ctrl, i);
-                    }
-                    if (newmm != u) {
-                      _phase->igvn().replace_input_of(uu, k, newmm);
-                      nb++;
-                      --jmax;
-                    }
-                  }
-                }
-                if (nb > 0) {
-                  --j;
-                }
-              }
-            } else {
-              if (rep_ctrl != uu && ShenandoahBarrierC2Support::is_dominator(rep_ctrl, _phase->ctrl_or_self(uu), replacement, uu, _phase)) {
-                if (newmm == nullptr) {
-                  newmm = clone_merge_mem(u, mem, rep_proj, rep_ctrl, i);
-                }
-                if (newmm != u) {
-                  _phase->igvn().replace_input_of(uu, uu->find_edge(u), newmm);
-                  --j, --jmax;
-                }
-              }
-            }
-          }
-        }
-      } else if (u->is_Phi()) {
-        assert(u->bottom_type() == Type::MEMORY, "what else?");
-        Node* region = u->in(0);
-        if (should_process_phi(u)) {
-          bool replaced = false;
-          for (uint j = 1; j < u->req(); j++) {
-            if (u->in(j) == mem && _phase->is_dominator(rep_ctrl, region->in(j))) {
-              Node* nnew = rep_proj;
-              if (u->adr_type() == TypePtr::BOTTOM) {
-                if (mm == nullptr) {
-                  mm = allocate_merge_mem(mem, rep_proj, rep_ctrl);
-                }
-                nnew = mm;
-              }
-              _phase->igvn().replace_input_of(u, j, nnew);
-              replaced = true;
-            }
-          }
-          if (replaced) {
-            --i;
-          }
-
-        }
-      } else if ((u->adr_type() == TypePtr::BOTTOM && u->Opcode() != Op_StrInflatedCopy) ||
-                 u->adr_type() == nullptr) {
-        assert(u->adr_type() != nullptr ||
-               u->Opcode() == Op_Rethrow ||
-               u->Opcode() == Op_Return ||
-               u->Opcode() == Op_SafePoint ||
-               (u->is_CallStaticJava() && u->as_CallStaticJava()->uncommon_trap_request() != 0) ||
-               (u->is_CallStaticJava() && u->as_CallStaticJava()->_entry_point == OptoRuntime::rethrow_stub()) ||
-               u->Opcode() == Op_CallLeaf, "%s", u->Name());
-        if (ShenandoahBarrierC2Support::is_dominator(rep_ctrl, _phase->ctrl_or_self(u), replacement, u, _phase)) {
-          if (mm == nullptr) {
-            mm = allocate_merge_mem(mem, rep_proj, rep_ctrl);
-          }
-          _phase->igvn().replace_input_of(u, u->find_edge(mem), mm);
-          --i;
-        }
-      } else if (_phase->C->get_alias_index(u->adr_type()) == _alias) {
-        if (ShenandoahBarrierC2Support::is_dominator(rep_ctrl, _phase->ctrl_or_self(u), replacement, u, _phase)) {
-          _phase->igvn().replace_input_of(u, u->find_edge(mem), rep_proj);
-          --i;
-        }
-      }
-    }
-  }
-}
-
-ShenandoahLoadReferenceBarrierNode::ShenandoahLoadReferenceBarrierNode(Node* ctrl, Node* obj, DecoratorSet decorators)
-: Node(ctrl, obj), _decorators(decorators) {
-  ShenandoahBarrierSetC2::bsc2()->state()->add_load_reference_barrier(this);
-}
-
-DecoratorSet ShenandoahLoadReferenceBarrierNode::decorators() const {
-  return _decorators;
-}
-
-uint ShenandoahLoadReferenceBarrierNode::size_of() const {
-  return sizeof(*this);
-}
-
-static DecoratorSet mask_decorators(DecoratorSet decorators) {
-  return decorators & (ON_STRONG_OOP_REF | ON_WEAK_OOP_REF | ON_PHANTOM_OOP_REF | ON_UNKNOWN_OOP_REF | IN_NATIVE);
-}
-
-uint ShenandoahLoadReferenceBarrierNode::hash() const {
-  uint hash = Node::hash();
-  hash += mask_decorators(_decorators);
-  return hash;
-}
-
-bool ShenandoahLoadReferenceBarrierNode::cmp( const Node &n ) const {
-  return Node::cmp(n) && n.Opcode() == Op_ShenandoahLoadReferenceBarrier &&
-         mask_decorators(_decorators) == mask_decorators(((const ShenandoahLoadReferenceBarrierNode&)n)._decorators);
-}
-
-const Type* ShenandoahLoadReferenceBarrierNode::bottom_type() const {
-  if (in(ValueIn) == nullptr || in(ValueIn)->is_top()) {
-    return Type::TOP;
-  }
-  const Type* t = in(ValueIn)->bottom_type();
-  if (t == TypePtr::NULL_PTR) {
-    return t;
-  }
-
-  if (ShenandoahBarrierSet::is_strong_access(decorators())) {
-    return t;
-  }
-
-  return t->meet(TypePtr::NULL_PTR);
-}
-
-const Type* ShenandoahLoadReferenceBarrierNode::Value(PhaseGVN* phase) const {
-  // Either input is TOP ==> the result is TOP
-  const Type *t2 = phase->type(in(ValueIn));
-  if( t2 == Type::TOP ) return Type::TOP;
-
-  if (t2 == TypePtr::NULL_PTR) {
-    return t2;
-  }
-
-  if (ShenandoahBarrierSet::is_strong_access(decorators())) {
-    return t2;
-  }
-
-  return t2->meet(TypePtr::NULL_PTR);
-}
-
-Node* ShenandoahLoadReferenceBarrierNode::Identity(PhaseGVN* phase) {
-  Node* value = in(ValueIn);
-  if (!needs_barrier(phase, value)) {
-    return value;
-  }
-  return this;
-}
-
-bool ShenandoahLoadReferenceBarrierNode::needs_barrier(PhaseGVN* phase, Node* n) {
-  Unique_Node_List visited;
-  return needs_barrier_impl(phase, n, visited);
-}
-
-bool ShenandoahLoadReferenceBarrierNode::needs_barrier_impl(PhaseGVN* phase, Node* n, Unique_Node_List &visited) {
-  if (n == nullptr) return false;
-  if (visited.member(n)) {
-    return false; // Been there.
-  }
-  visited.push(n);
-
-  if (n->is_Allocate()) {
-    // tty->print_cr("optimize barrier on alloc");
-    return false;
-  }
-  if (n->is_Call()) {
-    // tty->print_cr("optimize barrier on call");
-    return false;
-  }
-
-  const Type* type = phase->type(n);
-  if (type == Type::TOP) {
-    return false;
-  }
-  if (type->make_ptr()->higher_equal(TypePtr::NULL_PTR)) {
-    // tty->print_cr("optimize barrier on null");
-    return false;
-  }
-  if (type->make_oopptr() && type->make_oopptr()->const_oop() != nullptr) {
-    // tty->print_cr("optimize barrier on constant");
-    return false;
-  }
-
-  switch (n->Opcode()) {
-    case Op_AddP:
-      return true; // TODO: Can refine?
-    case Op_LoadP:
-    case Op_ShenandoahCompareAndExchangeN:
-    case Op_ShenandoahCompareAndExchangeP:
-    case Op_CompareAndExchangeN:
-    case Op_CompareAndExchangeP:
-    case Op_GetAndSetN:
-    case Op_GetAndSetP:
-      return true;
-    case Op_Phi: {
-      for (uint i = 1; i < n->req(); i++) {
-        if (needs_barrier_impl(phase, n->in(i), visited)) return true;
-      }
-      return false;
-    }
-    case Op_CheckCastPP:
-    case Op_CastPP:
-      return needs_barrier_impl(phase, n->in(1), visited);
-    case Op_Proj:
-      return needs_barrier_impl(phase, n->in(0), visited);
-    case Op_ShenandoahLoadReferenceBarrier:
-      // tty->print_cr("optimize barrier on barrier");
-      return false;
-    case Op_Parm:
-      // tty->print_cr("optimize barrier on input arg");
-      return false;
-    case Op_DecodeN:
-    case Op_EncodeP:
-      return needs_barrier_impl(phase, n->in(1), visited);
-    case Op_LoadN:
-      return true;
-    case Op_CMoveN:
-    case Op_CMoveP:
-      return needs_barrier_impl(phase, n->in(2), visited) ||
-             needs_barrier_impl(phase, n->in(3), visited);
-    case Op_CreateEx:
-      return false;
-    default:
-      break;
-  }
-#ifdef ASSERT
-  tty->print("need barrier on?: ");
-  tty->print_cr("ins:");
-  n->dump(2);
-  tty->print_cr("outs:");
-  n->dump(-2);
-  ShouldNotReachHere();
-#endif
-  return true;
-}
diff a/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.hpp b/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.hpp
--- a/src/hotspot/share/gc/shenandoah/c2/shenandoahSupport.hpp
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * Copyright (c) 2015, 2021, Red Hat, Inc. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- *
- */
-
-#ifndef SHARE_GC_SHENANDOAH_C2_SHENANDOAHSUPPORT_HPP
-#define SHARE_GC_SHENANDOAH_C2_SHENANDOAHSUPPORT_HPP
-
-#include "gc/shenandoah/shenandoahBarrierSet.hpp"
-#include "memory/allocation.hpp"
-#include "opto/addnode.hpp"
-#include "opto/graphKit.hpp"
-#include "opto/machnode.hpp"
-#include "opto/memnode.hpp"
-#include "opto/multnode.hpp"
-#include "opto/node.hpp"
-
-class PhaseGVN;
-class MemoryGraphFixer;
-
-class ShenandoahBarrierC2Support : public AllStatic {
-private:
-#ifdef ASSERT
-  enum verify_type {
-    ShenandoahLoad,
-    ShenandoahStore,
-    ShenandoahValue,
-    ShenandoahOopStore,
-    ShenandoahNone
-  };
-
-  static bool verify_helper(Node* in, Node_Stack& phis, VectorSet& visited, verify_type t, bool trace, Unique_Node_List& barriers_used);
-  static void report_verify_failure(const char* msg, Node* n1 = nullptr, Node* n2 = nullptr);
-#endif
-  static Node* dom_mem(Node* mem, Node* ctrl, int alias, Node*& mem_ctrl, PhaseIdealLoop* phase);
-  static Node* no_branches(Node* c, Node* dom, bool allow_one_proj, PhaseIdealLoop* phase);
-  static bool is_gc_state_test(Node* iff, int mask);
-  static bool has_safepoint_between(Node* start, Node* stop, PhaseIdealLoop *phase);
-  static Node* find_bottom_mem(Node* ctrl, PhaseIdealLoop* phase);
-  static void follow_barrier_uses(Node* n, Node* ctrl, Unique_Node_List& uses, PhaseIdealLoop* phase);
-  static void test_null(Node*& ctrl, Node* val, Node*& null_ctrl, PhaseIdealLoop* phase);
-  static void test_gc_state(Node*& ctrl, Node* raw_mem, Node*& heap_stable_ctrl,
-                            PhaseIdealLoop* phase, int flags);
-  static void call_lrb_stub(Node*& ctrl, Node*& val, Node* load_addr,
-                            DecoratorSet decorators, PhaseIdealLoop* phase);
-
-  static void collect_nodes_above_barrier(Unique_Node_List &nodes_above_barrier, PhaseIdealLoop* phase, Node* ctrl,
-                                          Node* init_raw_mem);
-
-  static void test_in_cset(Node*& ctrl, Node*& not_cset_ctrl, Node* val, Node* raw_mem, PhaseIdealLoop* phase);
-  static void fix_ctrl(Node* barrier, Node* region, const MemoryGraphFixer& fixer, Unique_Node_List& uses, Unique_Node_List& nodes_above_barrier, uint last, PhaseIdealLoop* phase);
-
-  static Node* get_load_addr(PhaseIdealLoop* phase, VectorSet& visited, Node* lrb);
-public:
-  static bool is_dominator(Node* d_c, Node* n_c, Node* d, Node* n, PhaseIdealLoop* phase);
-  static bool is_dominator_same_ctrl(Node* c, Node* d, Node* n, PhaseIdealLoop* phase);
-
-  static bool is_gc_state_load(Node* n);
-  static bool is_heap_stable_test(Node* iff);
-
-  static bool expand(Compile* C, PhaseIterGVN& igvn);
-  static void pin_and_expand(PhaseIdealLoop* phase);
-
-  static void push_data_inputs_at_control(PhaseIdealLoop* phase, Node* n, Node* ctrl,
-                                          Unique_Node_List &wq);
-  static bool is_anti_dependent_load_at_control(PhaseIdealLoop* phase, Node* maybe_load, Node* store, Node* control);
-
-  static void maybe_push_anti_dependent_loads(PhaseIdealLoop* phase, Node* maybe_store, Node* control, Unique_Node_List &wq);
-#ifdef ASSERT
-  static void verify(RootNode* root);
-#endif
-};
-
-class MemoryGraphFixer : public ResourceObj {
-private:
-  Node_List _memory_nodes;
-  int _alias;
-  PhaseIdealLoop* _phase;
-  bool _include_lsm;
-
-  void collect_memory_nodes();
-  Node* get_ctrl(Node* n) const;
-  Node* ctrl_or_self(Node* n) const;
-  bool mem_is_valid(Node* m, Node* c) const;
-  MergeMemNode* allocate_merge_mem(Node* mem, Node* rep_proj, Node* rep_ctrl) const;
-  MergeMemNode* clone_merge_mem(Node* u, Node* mem, Node* rep_proj, Node* rep_ctrl, DUIterator& i) const;
-  void fix_memory_uses(Node* mem, Node* replacement, Node* rep_proj, Node* rep_ctrl) const;
-  bool should_process_phi(Node* phi) const;
-  bool has_mem_phi(Node* region) const;
-
-public:
-  MemoryGraphFixer(int alias, bool include_lsm, PhaseIdealLoop* phase) :
-    _alias(alias), _phase(phase), _include_lsm(include_lsm) {
-    assert(_alias != Compile::AliasIdxBot, "unsupported");
-    collect_memory_nodes();
-  }
-
-  Node* find_mem(Node* ctrl, Node* n) const;
-  void fix_mem(Node* ctrl, Node* region, Node* mem, Node* mem_for_ctrl, Node* mem_phi, Unique_Node_List& uses);
-  int alias() const { return _alias; }
-
-  Node* collect_memory_for_infinite_loop(const Node* in);
-
-  void record_new_ctrl(Node* ctrl, Node* region, Node* mem, Node* mem_for_ctrl);
-};
-
-class ShenandoahCompareAndSwapPNode : public CompareAndSwapPNode {
-public:
-  ShenandoahCompareAndSwapPNode(Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord)
-    : CompareAndSwapPNode(c, mem, adr, val, ex, mem_ord) { }
-
-  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape) {
-    if (in(ExpectedIn) != nullptr && phase->type(in(ExpectedIn)) == TypePtr::NULL_PTR) {
-      return new CompareAndSwapPNode(in(MemNode::Control), in(MemNode::Memory), in(MemNode::Address), in(MemNode::ValueIn), in(ExpectedIn), order());
-    }
-    return nullptr;
-  }
-
-  virtual int Opcode() const;
-};
-
-class ShenandoahCompareAndSwapNNode : public CompareAndSwapNNode {
-public:
-  ShenandoahCompareAndSwapNNode(Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord)
-    : CompareAndSwapNNode(c, mem, adr, val, ex, mem_ord) { }
-
-  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape) {
-    if (in(ExpectedIn) != nullptr && phase->type(in(ExpectedIn)) == TypeNarrowOop::NULL_PTR) {
-      return new CompareAndSwapNNode(in(MemNode::Control), in(MemNode::Memory), in(MemNode::Address), in(MemNode::ValueIn), in(ExpectedIn), order());
-    }
-    return nullptr;
-  }
-
-  virtual int Opcode() const;
-};
-
-class ShenandoahWeakCompareAndSwapPNode : public WeakCompareAndSwapPNode {
-public:
-  ShenandoahWeakCompareAndSwapPNode(Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord)
-    : WeakCompareAndSwapPNode(c, mem, adr, val, ex, mem_ord) { }
-
-  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape) {
-    if (in(ExpectedIn) != nullptr && phase->type(in(ExpectedIn)) == TypePtr::NULL_PTR) {
-      return new WeakCompareAndSwapPNode(in(MemNode::Control), in(MemNode::Memory), in(MemNode::Address), in(MemNode::ValueIn), in(ExpectedIn), order());
-    }
-    return nullptr;
-  }
-
-  virtual int Opcode() const;
-};
-
-class ShenandoahWeakCompareAndSwapNNode : public WeakCompareAndSwapNNode {
-public:
-  ShenandoahWeakCompareAndSwapNNode(Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord)
-    : WeakCompareAndSwapNNode(c, mem, adr, val, ex, mem_ord) { }
-
-  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape) {
-    if (in(ExpectedIn) != nullptr && phase->type(in(ExpectedIn)) == TypeNarrowOop::NULL_PTR) {
-      return new WeakCompareAndSwapNNode(in(MemNode::Control), in(MemNode::Memory), in(MemNode::Address), in(MemNode::ValueIn), in(ExpectedIn), order());
-    }
-    return nullptr;
-  }
-
-  virtual int Opcode() const;
-};
-
-class ShenandoahCompareAndExchangePNode : public CompareAndExchangePNode {
-public:
-  ShenandoahCompareAndExchangePNode(Node *c, Node *mem, Node *adr, Node *val, Node *ex, const TypePtr* at, const Type* t, MemNode::MemOrd mem_ord)
-    : CompareAndExchangePNode(c, mem, adr, val, ex, at, t, mem_ord) { }
-
-  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape) {
-    if (in(ExpectedIn) != nullptr && phase->type(in(ExpectedIn)) == TypePtr::NULL_PTR) {
-      return new CompareAndExchangePNode(in(MemNode::Control), in(MemNode::Memory), in(MemNode::Address), in(MemNode::ValueIn), in(ExpectedIn), adr_type(), bottom_type(), order());
-    }
-    return nullptr;
-  }
-
-  virtual int Opcode() const;
-};
-
-class ShenandoahCompareAndExchangeNNode : public CompareAndExchangeNNode {
-public:
-  ShenandoahCompareAndExchangeNNode(Node *c, Node *mem, Node *adr, Node *val, Node *ex, const TypePtr* at, const Type* t, MemNode::MemOrd mem_ord)
-    : CompareAndExchangeNNode(c, mem, adr, val, ex, at, t, mem_ord) { }
-
-  virtual Node *Ideal(PhaseGVN *phase, bool can_reshape) {
-    if (in(ExpectedIn) != nullptr && phase->type(in(ExpectedIn)) == TypeNarrowOop::NULL_PTR) {
-      return new CompareAndExchangeNNode(in(MemNode::Control), in(MemNode::Memory), in(MemNode::Address), in(MemNode::ValueIn), in(ExpectedIn), adr_type(), bottom_type(), order());
-    }
-    return nullptr;
-  }
-
-  virtual int Opcode() const;
-};
-
-class ShenandoahLoadReferenceBarrierNode : public Node {
-public:
-  enum {
-    Control,
-    ValueIn
-  };
-
-private:
-  DecoratorSet _decorators;
-
-public:
-  ShenandoahLoadReferenceBarrierNode(Node* ctrl, Node* val, DecoratorSet decorators);
-
-  DecoratorSet decorators() const;
-  virtual int Opcode() const;
-  virtual const Type* bottom_type() const;
-  virtual const Type* Value(PhaseGVN* phase) const;
-  virtual const class TypePtr *adr_type() const { return TypeOopPtr::BOTTOM; }
-  virtual uint match_edge(uint idx) const {
-    return idx >= ValueIn;
-  }
-  virtual uint ideal_reg() const { return Op_RegP; }
-
-  virtual Node* Identity(PhaseGVN* phase);
-
-  virtual uint size_of() const;
-  virtual uint hash() const;
-  virtual bool cmp( const Node &n ) const;
-
-private:
-  bool needs_barrier(PhaseGVN* phase, Node* n);
-  bool needs_barrier_impl(PhaseGVN* phase, Node* n, Unique_Node_List &visited);
-};
-
-
-#endif // SHARE_GC_SHENANDOAH_C2_SHENANDOAHSUPPORT_HPP
diff a/src/hotspot/share/gc/shenandoah/shenandoahRuntime.cpp b/src/hotspot/share/gc/shenandoah/shenandoahRuntime.cpp
--- a/src/hotspot/share/gc/shenandoah/shenandoahRuntime.cpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahRuntime.cpp
@@ -36,10 +36,15 @@
 
 JRT_LEAF(void, ShenandoahRuntime::arraycopy_barrier_narrow_oop(narrowOop* src, narrowOop* dst, size_t length))
   ShenandoahBarrierSet::barrier_set()->arraycopy_barrier(src, dst, length);
 JRT_END
 
+JRT_LEAF(void, ShenandoahRuntime::write_barrier_pre_c2(oopDesc* orig))
+//log_info(gc)("WB pre C2: " PTR_FORMAT, p2i(orig));
+  write_barrier_pre(orig);
+JRT_END
+
 JRT_LEAF(void, ShenandoahRuntime::write_barrier_pre(oopDesc* orig))
   assert(orig != nullptr, "should be optimized out");
   shenandoah_assert_correct(nullptr, orig);
   // Capture the original value that was in the field reference.
   JavaThread* thread = JavaThread::current();
@@ -47,14 +52,16 @@
   SATBMarkQueue& queue = ShenandoahThreadLocalData::satb_mark_queue(thread);
   ShenandoahBarrierSet::satb_mark_queue_set().enqueue_known_active(queue, orig);
 JRT_END
 
 JRT_LEAF(oopDesc*, ShenandoahRuntime::load_reference_barrier_strong(oopDesc* src, oop* load_addr))
+  //tty->print_cr("ShenandoahRuntime::load_reference_barrier_strong: " PTR_FORMAT " [" PTR_FORMAT "]", p2i(src), p2i(load_addr));
   return ShenandoahBarrierSet::barrier_set()->load_reference_barrier_mutator(src, load_addr);
 JRT_END
 
 JRT_LEAF(oopDesc*, ShenandoahRuntime::load_reference_barrier_strong_narrow(oopDesc* src, narrowOop* load_addr))
+  // tty->print_cr("ShenandoahRuntime::load_reference_barrier_strong_narrow: " PTR_FORMAT " [" PTR_FORMAT "]", p2i(src), p2i(load_addr));
   return ShenandoahBarrierSet::barrier_set()->load_reference_barrier_mutator(src, load_addr);
 JRT_END
 
 JRT_LEAF(oopDesc*, ShenandoahRuntime::load_reference_barrier_weak(oopDesc* src, oop* load_addr))
   return (oopDesc*) ShenandoahBarrierSet::barrier_set()->load_reference_barrier<oop>(ON_WEAK_OOP_REF, oop(src), load_addr);
diff a/src/hotspot/share/gc/shenandoah/shenandoahRuntime.hpp b/src/hotspot/share/gc/shenandoah/shenandoahRuntime.hpp
--- a/src/hotspot/share/gc/shenandoah/shenandoahRuntime.hpp
+++ b/src/hotspot/share/gc/shenandoah/shenandoahRuntime.hpp
@@ -35,10 +35,11 @@
 public:
   static void arraycopy_barrier_oop(oop* src, oop* dst, size_t length);
   static void arraycopy_barrier_narrow_oop(narrowOop* src, narrowOop* dst, size_t length);
 
   static void write_barrier_pre(oopDesc* orig);
+  static void write_barrier_pre_c2(oopDesc* orig);
 
   static oopDesc* load_reference_barrier_strong(oopDesc* src, oop* load_addr);
   static oopDesc* load_reference_barrier_strong_narrow(oopDesc* src, narrowOop* load_addr);
 
   static oopDesc* load_reference_barrier_weak(oopDesc* src, oop* load_addr);
diff a/src/hotspot/share/opto/arraycopynode.cpp b/src/hotspot/share/opto/arraycopynode.cpp
--- a/src/hotspot/share/opto/arraycopynode.cpp
+++ b/src/hotspot/share/opto/arraycopynode.cpp
@@ -697,12 +697,10 @@
   }
 
   Node* c = mb->in(0);
 
   BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
-  // step over g1 gc barrier if we're at e.g. a clone with ReduceInitialCardMarks off
-  c = bs->step_over_gc_barrier(c);
 
   CallNode* call = nullptr;
   guarantee(c != nullptr, "step_over_gc_barrier failed, there must be something to step to.");
   if (c->is_Region()) {
     for (uint i = 1; i < c->req(); i++) {
diff a/src/hotspot/share/opto/callnode.cpp b/src/hotspot/share/opto/callnode.cpp
--- a/src/hotspot/share/opto/callnode.cpp
+++ b/src/hotspot/share/opto/callnode.cpp
@@ -1947,12 +1947,12 @@
   if (ctrl_proj != nullptr && ctrl_proj->_con == TypeFunc::Control) {
     Node *n = ctrl_proj->in(0);
     if (n != nullptr && n->is_Unlock()) {
       UnlockNode *unlock = n->as_Unlock();
       BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
-      Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
-      Node* unlock_obj = bs->step_over_gc_barrier(unlock->obj_node());
+      Node* lock_obj = lock->obj_node();
+      Node* unlock_obj = unlock->obj_node();
       if (lock_obj->eqv_uncast(unlock_obj) &&
           BoxLockNode::same_slot(lock->box_node(), unlock->box_node()) &&
           !unlock->is_eliminated()) {
         lock_ops.append(unlock);
         return true;
@@ -1995,12 +1995,12 @@
     }
   }
   if (ctrl->is_Lock()) {
     LockNode *lock = ctrl->as_Lock();
     BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
-    Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
-    Node* unlock_obj = bs->step_over_gc_barrier(unlock->obj_node());
+    Node* lock_obj = lock->obj_node();
+    Node* unlock_obj = unlock->obj_node();
     if (lock_obj->eqv_uncast(unlock_obj) &&
         BoxLockNode::same_slot(lock->box_node(), unlock->box_node())) {
       lock_result = lock;
     }
   }
@@ -2029,12 +2029,12 @@
         }
       }
       if (lock1_node != nullptr && lock1_node->is_Lock()) {
         LockNode *lock1 = lock1_node->as_Lock();
         BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
-        Node* lock_obj = bs->step_over_gc_barrier(lock->obj_node());
-        Node* lock1_obj = bs->step_over_gc_barrier(lock1->obj_node());
+        Node* lock_obj = lock->obj_node();
+        Node* lock1_obj = lock1->obj_node();
         if (lock_obj->eqv_uncast(lock1_obj) &&
             BoxLockNode::same_slot(lock->box_node(), lock1->box_node()) &&
             !lock1->is_eliminated()) {
           lock_ops.append(lock1);
           return true;
@@ -2290,23 +2290,20 @@
     }
 #endif
     return false;
   }
 
-  BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
-  obj = bs->step_over_gc_barrier(obj);
   // Look for external lock for the same object.
   SafePointNode* sfn = this->as_SafePoint();
   JVMState* youngest_jvms = sfn->jvms();
   int max_depth = youngest_jvms->depth();
   for (int depth = 1; depth <= max_depth; depth++) {
     JVMState* jvms = youngest_jvms->of_depth(depth);
     int num_mon  = jvms->nof_monitors();
     // Loop over monitors
     for (int idx = 0; idx < num_mon; idx++) {
       Node* obj_node = sfn->monitor_obj(jvms, idx);
-      obj_node = bs->step_over_gc_barrier(obj_node);
       BoxLockNode* box_node = sfn->monitor_box(jvms, idx)->as_BoxLock();
       if ((box_node->stack_slot() < stk_slot) && obj_node->eqv_uncast(obj)) {
         box->set_nested();
         return true;
       }
diff a/src/hotspot/share/opto/classes.hpp b/src/hotspot/share/opto/classes.hpp
--- a/src/hotspot/share/opto/classes.hpp
+++ b/src/hotspot/share/opto/classes.hpp
@@ -321,22 +321,10 @@
 macro(RotateRight)
 macro(RotateRightV)
 macro(SafePoint)
 macro(SafePointScalarObject)
 macro(SafePointScalarMerge)
-#if INCLUDE_SHENANDOAHGC
-#define shmacro(x) macro(x)
-#else
-#define shmacro(x) optionalmacro(x)
-#endif
-shmacro(ShenandoahCompareAndExchangeP)
-shmacro(ShenandoahCompareAndExchangeN)
-shmacro(ShenandoahCompareAndSwapN)
-shmacro(ShenandoahCompareAndSwapP)
-shmacro(ShenandoahWeakCompareAndSwapN)
-shmacro(ShenandoahWeakCompareAndSwapP)
-shmacro(ShenandoahLoadReferenceBarrier)
 macro(SCMemProj)
 macro(CopySignD)
 macro(CopySignF)
 macro(SaturatingAddV)
 macro(SaturatingSubV)
diff a/src/hotspot/share/opto/compile.cpp b/src/hotspot/share/opto/compile.cpp
--- a/src/hotspot/share/opto/compile.cpp
+++ b/src/hotspot/share/opto/compile.cpp
@@ -416,12 +416,10 @@
 
     if (dead->is_CallStaticJava()) {
       remove_unstable_if_trap(dead->as_CallStaticJava(), false);
     }
   }
-  BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
-  bs->unregister_potential_barrier_node(dead);
 }
 
 // Disconnect all useless nodes by disconnecting those at the boundary.
 void Compile::disconnect_useless_nodes(Unique_Node_List& useful, Unique_Node_List& worklist, const Unique_Node_List* root_and_safepoints) {
   uint next = 0;
@@ -467,12 +465,10 @@
   if (_modified_nodes != nullptr) {
     _modified_nodes->remove_useless_nodes(useful.member_set());
   }
 #endif
 
-  BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
-  bs->eliminate_useless_gc_barriers(useful, this);
   // clean up the late inline lists
   remove_useless_late_inlines(                &_late_inlines, useful);
   remove_useless_late_inlines(         &_string_late_inlines, useful);
   remove_useless_late_inlines(         &_boxing_late_inlines, useful);
   remove_useless_late_inlines(&_vector_reboxing_late_inlines, useful);
@@ -3210,23 +3206,20 @@
   }
   if (n->is_MemBar()) {
     MemBarNode* mb = n->as_MemBar();
     if (mb->trailing_store() || mb->trailing_load_store()) {
       assert(mb->leading_membar()->trailing_membar() == mb, "bad membar pair");
-      Node* mem = BarrierSet::barrier_set()->barrier_set_c2()->step_over_gc_barrier(mb->in(MemBarNode::Precedent));
+      Node* mem = mb->in(MemBarNode::Precedent);
       assert((mb->trailing_store() && mem->is_Store() && mem->as_Store()->is_release()) ||
              (mb->trailing_load_store() && mem->is_LoadStore()), "missing mem op");
     } else if (mb->leading()) {
       assert(mb->trailing_membar()->leading_membar() == mb, "bad membar pair");
     }
   }
 #endif
   // Count FPU ops and common calls, implements item (3)
-  bool gc_handled = BarrierSet::barrier_set()->barrier_set_c2()->final_graph_reshaping(this, n, nop, dead_nodes);
-  if (!gc_handled) {
-    final_graph_reshaping_main_switch(n, frc, nop, dead_nodes);
-  }
+  final_graph_reshaping_main_switch(n, frc, nop, dead_nodes);
 
   // Collect CFG split points
   if (n->is_MultiBranch() && !n->is_RangeCheck()) {
     frc._tests.push(n);
   }
diff a/src/hotspot/share/opto/escape.cpp b/src/hotspot/share/opto/escape.cpp
--- a/src/hotspot/share/opto/escape.cpp
+++ b/src/hotspot/share/opto/escape.cpp
@@ -1504,15 +1504,10 @@
   PointsToNode* n_ptn = ptnode_adr(n_idx);
   if (n_ptn != nullptr) {
     return; // No need to redefine PointsTo node during first iteration.
   }
   int opcode = n->Opcode();
-  bool gc_handled = BarrierSet::barrier_set()->barrier_set_c2()->escape_add_to_con_graph(this, igvn, delayed_worklist, n, opcode);
-  if (gc_handled) {
-    return; // Ignore node if already handled by GC.
-  }
-
   if (n->is_Call()) {
     // Arguments to allocation and locking don't escape.
     if (n->is_AbstractLock()) {
       // Put Lock and Unlock nodes on IGVN worklist to process them during
       // first IGVN optimization when escape information is still available.
@@ -1726,14 +1721,10 @@
   }
   assert(n->is_Store() || n->is_LoadStore() ||
          ((n_ptn != nullptr) && (n_ptn->ideal_node() != nullptr)),
          "node should be registered already");
   int opcode = n->Opcode();
-  bool gc_handled = BarrierSet::barrier_set()->barrier_set_c2()->escape_add_final_edges(this, _igvn, n, opcode);
-  if (gc_handled) {
-    return; // Ignore node if already handled by GC.
-  }
   switch (opcode) {
     case Op_AddP: {
       Node* base = get_addp_base(n);
       PointsToNode* ptn_base = ptnode_adr(base->_idx);
       assert(ptn_base != nullptr, "field's base should be registered");
@@ -3454,12 +3445,11 @@
         bt = field->layout_type();
       } else {
         // Check for unsafe oop field access
         if (n->has_out_with(Op_StoreP, Op_LoadP, Op_StoreN, Op_LoadN) ||
             n->has_out_with(Op_GetAndSetP, Op_GetAndSetN, Op_CompareAndExchangeP, Op_CompareAndExchangeN) ||
-            n->has_out_with(Op_CompareAndSwapP, Op_CompareAndSwapN, Op_WeakCompareAndSwapP, Op_WeakCompareAndSwapN) ||
-            BarrierSet::barrier_set()->barrier_set_c2()->escape_has_out_with_unsafe_object(n)) {
+            n->has_out_with(Op_CompareAndSwapP, Op_CompareAndSwapN, Op_WeakCompareAndSwapP, Op_WeakCompareAndSwapN)) {
           bt = T_OBJECT;
           (*unsafe) = true;
         }
       }
     } else if (adr_type->isa_aryptr()) {
@@ -3473,12 +3463,11 @@
       }
     } else if (adr_type->isa_rawptr() || adr_type->isa_klassptr()) {
       // Allocation initialization, ThreadLocal field access, unsafe access
       if (n->has_out_with(Op_StoreP, Op_LoadP, Op_StoreN, Op_LoadN) ||
           n->has_out_with(Op_GetAndSetP, Op_GetAndSetN, Op_CompareAndExchangeP, Op_CompareAndExchangeN) ||
-          n->has_out_with(Op_CompareAndSwapP, Op_CompareAndSwapN, Op_WeakCompareAndSwapP, Op_WeakCompareAndSwapN) ||
-          BarrierSet::barrier_set()->barrier_set_c2()->escape_has_out_with_unsafe_object(n)) {
+          n->has_out_with(Op_CompareAndSwapP, Op_CompareAndSwapN, Op_WeakCompareAndSwapP, Op_WeakCompareAndSwapN)) {
         bt = T_OBJECT;
       }
     }
   }
   // Note: T_NARROWOOP is not classed as a real reference type
@@ -4153,13 +4142,11 @@
         if (alloc == nullptr || alloc->_idx != (uint)toop->instance_id()) {
           result = proj_in->in(TypeFunc::Memory);
         }
       } else if (proj_in->is_MemBar()) {
         // Check if there is an array copy for a clone
-        // Step over GC barrier when ReduceInitialCardMarks is disabled
-        BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
-        Node* control_proj_ac = bs->step_over_gc_barrier(proj_in->in(0));
+        Node* control_proj_ac = proj_in->in(0);
 
         if (control_proj_ac->is_Proj() && control_proj_ac->in(0)->is_ArrayCopy()) {
           // Stop if it is a clone
           ArrayCopyNode* ac = control_proj_ac->in(0)->as_ArrayCopy();
           if (ac->may_modify(toop, igvn)) {
diff a/src/hotspot/share/opto/graphKit.cpp b/src/hotspot/share/opto/graphKit.cpp
--- a/src/hotspot/share/opto/graphKit.cpp
+++ b/src/hotspot/share/opto/graphKit.cpp
@@ -3974,13 +3974,10 @@
 AllocateNode* AllocateNode::Ideal_allocation(Node* ptr) {
   if (ptr == nullptr) {     // reduce dumb test in callers
     return nullptr;
   }
 
-  BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
-  ptr = bs->step_over_gc_barrier(ptr);
-
   if (ptr->is_CheckCastPP()) { // strip only one raw-to-oop cast
     ptr = ptr->in(1);
     if (ptr == nullptr) return nullptr;
   }
   // Return null for allocations with several casts:
diff a/src/hotspot/share/opto/loopTransform.cpp b/src/hotspot/share/opto/loopTransform.cpp
--- a/src/hotspot/share/opto/loopTransform.cpp
+++ b/src/hotspot/share/opto/loopTransform.cpp
@@ -3051,17 +3051,11 @@
              (bol->in(1)->Opcode() == Op_CompareAndSwapB) ||
              (bol->in(1)->Opcode() == Op_CompareAndSwapS) ||
              (bol->in(1)->Opcode() == Op_CompareAndSwapI) ||
              (bol->in(1)->Opcode() == Op_CompareAndSwapL) ||
              (bol->in(1)->Opcode() == Op_CompareAndSwapP) ||
-             (bol->in(1)->Opcode() == Op_CompareAndSwapN) ||
-             (bol->in(1)->Opcode() == Op_ShenandoahCompareAndExchangeP) ||
-             (bol->in(1)->Opcode() == Op_ShenandoahCompareAndExchangeN) ||
-             (bol->in(1)->Opcode() == Op_ShenandoahWeakCompareAndSwapP) ||
-             (bol->in(1)->Opcode() == Op_ShenandoahWeakCompareAndSwapN) ||
-             (bol->in(1)->Opcode() == Op_ShenandoahCompareAndSwapP) ||
-             (bol->in(1)->Opcode() == Op_ShenandoahCompareAndSwapN)))
+             (bol->in(1)->Opcode() == Op_CompareAndSwapN)))
           return;               // Allocation loops RARELY take backedge
         // Find the OTHER exit path from the IF
         Node* ex = iff->proj_out(1-test_con);
         float p = iff->_prob;
         if (!phase->is_member(this, ex) && iff->_fcnt == COUNT_UNKNOWN) {
diff a/src/hotspot/share/opto/loopnode.cpp b/src/hotspot/share/opto/loopnode.cpp
--- a/src/hotspot/share/opto/loopnode.cpp
+++ b/src/hotspot/share/opto/loopnode.cpp
@@ -4995,16 +4995,14 @@
       C->record_method_not_compilable("empty program detected during loop optimization");
     }
     return;
   }
 
-  BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
   // Nothing to do, so get out
   bool stop_early = !C->has_loops() && !skip_loop_opts && !do_split_ifs && !do_max_unroll && !_verify_me &&
-          !_verify_only && !bs->is_gc_specific_loop_opts_pass(_mode);
+          !_verify_only;
   bool do_expensive_nodes = C->should_optimize_expensive_nodes(_igvn);
-  bool strip_mined_loops_expanded = bs->strip_mined_loops_expanded(_mode);
   if (stop_early && !do_expensive_nodes) {
     return;
   }
 
   // Set loop nesting depth
@@ -5077,11 +5075,11 @@
   visited.set(C->top()->_idx); // Set C->top() as visited now
   build_loop_early( visited, worklist, nstack );
 
   // Given early legal placement, try finding counted loops.  This placement
   // is good enough to discover most loop invariants.
-  if (!_verify_me && !_verify_only && !strip_mined_loops_expanded) {
+  if (!_verify_me && !_verify_only) {
     _ltree_root->counted_loop( this );
   }
 
   // Find latest loop placement.  Find ideal loop placement.
   visited.clear();
@@ -5162,14 +5160,10 @@
 
     C->restore_major_progress(old_progress);
     return;
   }
 
-  if (bs->optimize_loops(this, _mode, visited, nstack, worklist)) {
-    return;
-  }
-
   if (ReassociateInvariants && !C->major_progress()) {
     // Reassociate invariants and prep for split_thru_phi
     for (LoopTreeIterator iter(_ltree_root); !iter.done(); iter.next()) {
       IdealLoopTree* lpt = iter.current();
       if (!lpt->is_loop()) {
@@ -6852,11 +6846,11 @@
     predicate_iterator.for_each(dominated_predicates);
     least = dominated_predicates.earliest_dominated_predicate_entry();
   }
   // Try not to place code on a loop entry projection
   // which can inhibit range check elimination.
-  if (least != early && !BarrierSet::barrier_set()->barrier_set_c2()->is_gc_specific_loop_opts_pass(_mode)) {
+  if (least != early) {
     Node* ctrl_out = least->unique_ctrl_out_or_null();
     if (ctrl_out != nullptr && ctrl_out->is_Loop() &&
         least == ctrl_out->in(LoopNode::EntryControl) &&
         (ctrl_out->is_CountedLoop() || ctrl_out->is_OuterStripMinedLoop())) {
       Node* least_dom = idom(least);
diff a/src/hotspot/share/opto/macro.cpp b/src/hotspot/share/opto/macro.cpp
--- a/src/hotspot/share/opto/macro.cpp
+++ b/src/hotspot/share/opto/macro.cpp
@@ -390,12 +390,10 @@
       }
       if (val == mem) {
         values.at_put(j, mem);
       } else if (val->is_Store()) {
         Node* n = val->in(MemNode::ValueIn);
-        BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
-        n = bs->step_over_gc_barrier(n);
         if (is_subword_type(ft)) {
           n = Compile::narrow_value(ft, n, phi_type, &_igvn, true);
         }
         values.at_put(j, n);
       } else if(val->is_Proj() && val->in(0) == alloc) {
@@ -509,14 +507,11 @@
   if (mem != nullptr) {
     if (mem == start_mem || mem == alloc_mem) {
       // hit a sentinel, return appropriate 0 value
       return _igvn.zerocon(ft);
     } else if (mem->is_Store()) {
-      Node* n = mem->in(MemNode::ValueIn);
-      BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
-      n = bs->step_over_gc_barrier(n);
-      return n;
+      return mem->in(MemNode::ValueIn);
     } else if (mem->is_Phi()) {
       // attempt to produce a Phi reflecting the values on the input paths of the Phi
       Node_Stack value_phis(8);
       Node* phi = value_from_mem_phi(mem, ft, ftype, adr_t, alloc, &value_phis, ValueSearchLimit);
       if (phi != nullptr) {
@@ -593,11 +588,11 @@
           break;
         }
         for (DUIterator_Fast kmax, k = use->fast_outs(kmax);
                                    k < kmax && can_eliminate; k++) {
           Node* n = use->fast_out(k);
-          if (!n->is_Store() && n->Opcode() != Op_CastP2X && !bs->is_gc_pre_barrier_node(n) && !reduce_merge_precheck) {
+          if (!n->is_Store() && n->Opcode() != Op_CastP2X && !reduce_merge_precheck) {
             DEBUG_ONLY(disq_node = n;)
             if (n->is_Load() || n->is_LoadStore()) {
               NOT_PRODUCT(fail_eliminate = "Field load";)
             } else {
               NOT_PRODUCT(fail_eliminate = "Not store field reference";)
diff a/src/hotspot/share/opto/matcher.cpp b/src/hotspot/share/opto/matcher.cpp
--- a/src/hotspot/share/opto/matcher.cpp
+++ b/src/hotspot/share/opto/matcher.cpp
@@ -2090,15 +2090,11 @@
     }
     else if (nstate == Post_Visit) {
       mstack.pop(); // Remove node from stack
 
       // Now hack a few special opcodes
-      uint opcode = n->Opcode();
-      bool gc_handled = BarrierSet::barrier_set()->barrier_set_c2()->matcher_find_shared_post_visit(this, n, opcode);
-      if (!gc_handled) {
-        find_shared_post_visit(n, opcode);
-      }
+      find_shared_post_visit(n, n->Opcode());
     }
     else {
       ShouldNotReachHere();
     }
   } // end of while (mstack.is_nonempty())
@@ -2799,12 +2795,11 @@
         xop == Op_CompareAndSwapB ||
         xop == Op_CompareAndSwapS ||
         xop == Op_CompareAndSwapL ||
         xop == Op_CompareAndSwapP ||
         xop == Op_CompareAndSwapN ||
-        xop == Op_CompareAndSwapI ||
-        BarrierSet::barrier_set()->barrier_set_c2()->matcher_is_store_load_barrier(x, xop)) {
+        xop == Op_CompareAndSwapI) {
       return true;
     }
 
     // Op_FastLock previously appeared in the Op_* list above.
     if (xop == Op_FastLock) {
diff a/src/hotspot/share/opto/memnode.cpp b/src/hotspot/share/opto/memnode.cpp
--- a/src/hotspot/share/opto/memnode.cpp
+++ b/src/hotspot/share/opto/memnode.cpp
@@ -104,10 +104,11 @@
     st->print(" mismatched");
   }
   if (_unsafe_access) {
     st->print(" unsafe");
   }
+  st->print(" barrier: %u", _barrier_data);
 }
 
 void MemNode::dump_adr_type(const Node* mem, const TypePtr* adr_type, outputStream *st) {
   st->print(" @");
   if (adr_type == nullptr) {
@@ -648,14 +649,11 @@
       ArrayCopyNode* ac = nullptr;
       if (mb->in(0) != nullptr && mb->in(0)->is_Proj() &&
           mb->in(0)->in(0) != nullptr && mb->in(0)->in(0)->is_ArrayCopy()) {
         ac = mb->in(0)->in(0)->as_ArrayCopy();
       } else {
-        // Step over GC barrier when ReduceInitialCardMarks is disabled
-        BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
-        Node* control_proj_ac = bs->step_over_gc_barrier(mb->in(0));
-
+        Node* control_proj_ac = mb->in(0);
         if (control_proj_ac->is_Proj() && control_proj_ac->in(0)->is_ArrayCopy()) {
           ac = control_proj_ac->in(0)->as_ArrayCopy();
         }
       }
 
@@ -1056,13 +1054,12 @@
     LoadNode* ld = clone_pinned();
     Node* addp = in(MemNode::Address)->clone();
     if (ac->as_ArrayCopy()->is_clonebasic()) {
       assert(ld_alloc != nullptr, "need an alloc");
       assert(addp->is_AddP(), "address must be addp");
-      BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
-      assert(bs->step_over_gc_barrier(addp->in(AddPNode::Base)) == bs->step_over_gc_barrier(ac->in(ArrayCopyNode::Dest)), "strange pattern");
-      assert(bs->step_over_gc_barrier(addp->in(AddPNode::Address)) == bs->step_over_gc_barrier(ac->in(ArrayCopyNode::Dest)), "strange pattern");
+      assert(addp->in(AddPNode::Base) == ac->in(ArrayCopyNode::Dest), "strange pattern");
+      assert(addp->in(AddPNode::Address) == ac->in(ArrayCopyNode::Dest), "strange pattern");
       addp->set_req(AddPNode::Base, src);
       addp->set_req(AddPNode::Address, src);
     } else {
       assert(ac->as_ArrayCopy()->is_arraycopy_validated() ||
              ac->as_ArrayCopy()->is_copyof_validated() ||
@@ -1242,12 +1239,10 @@
     // Load boxed value from result of valueOf() call is input parameter.
     if (this->is_Load() && ld_adr->is_AddP() &&
         (tp != nullptr) && tp->is_ptr_to_boxed_value()) {
       intptr_t ignore = 0;
       Node* base = AddPNode::Ideal_base_and_offset(ld_adr, phase, ignore);
-      BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
-      base = bs->step_over_gc_barrier(base);
       if (base != nullptr && base->is_Proj() &&
           base->as_Proj()->_con == TypeFunc::Parms &&
           base->in(0)->is_CallStaticJava() &&
           base->in(0)->as_CallStaticJava()->is_boxing_method()) {
         return base->in(0)->in(TypeFunc::Parms);
@@ -2523,16 +2518,10 @@
   Node*    base   = AddPNode::Ideal_base_and_offset(adr, phase, offset);
   if (base == nullptr)     return this;
   const TypeOopPtr* toop = phase->type(adr)->isa_oopptr();
   if (toop == nullptr)     return this;
 
-  // Step over potential GC barrier for OopHandle resolve
-  BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
-  if (bs->is_gc_barrier_node(base)) {
-    base = bs->step_over_gc_barrier(base);
-  }
-
   // We can fetch the klass directly through an AllocateNode.
   // This works even if the klass is not constant (clone or newArray).
   if (offset == oopDesc::klass_offset_in_bytes()) {
     Node* allocated_klass = AllocateNode::Ideal_klass(base, phase);
     if (allocated_klass != nullptr) {
diff a/src/hotspot/share/opto/node.cpp b/src/hotspot/share/opto/node.cpp
--- a/src/hotspot/share/opto/node.cpp
+++ b/src/hotspot/share/opto/node.cpp
@@ -518,13 +518,10 @@
   }
   if (n->is_OpaqueTemplateAssertionPredicate()) {
     C->add_template_assertion_predicate_opaque(n->as_OpaqueTemplateAssertionPredicate());
   }
 
-  BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
-  bs->register_potential_barrier_node(n);
-
   n->set_idx(C->next_unique()); // Get new unique index as well
   NOT_PRODUCT(n->_igv_idx = C->next_igv_idx());
   DEBUG_ONLY( n->verify_construction() );
   NOT_PRODUCT(nodes_created++);
   // Do not patch over the debug_idx of a clone, because it makes it
@@ -640,12 +637,10 @@
 
     if (is_CallStaticJava()) {
       compile->remove_unstable_if_trap(as_CallStaticJava(), false);
     }
   }
-  BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
-  bs->unregister_potential_barrier_node(this);
 
   // See if the input array was allocated just prior to the object
   int edge_size = _max*sizeof(void*);
   int out_edge_size = _outmax*sizeof(void*);
   char *in_array = ((char*)_in);
@@ -1464,12 +1459,10 @@
             // The restriction (outcnt() <= 2) is the same as in set_req_X()
             // and remove_globally_dead_node().
             igvn->add_users_to_worklist( n );
           } else if (dead->is_data_proj_of_pure_function(n)) {
             igvn->_worklist.push(n);
-          } else {
-            BarrierSet::barrier_set()->barrier_set_c2()->enqueue_useful_gc_barrier(igvn, n);
           }
         }
       }
       igvn->C->remove_useless_node(dead);
     } // (dead->outcnt() == 0)
diff a/src/hotspot/share/opto/phaseX.cpp b/src/hotspot/share/opto/phaseX.cpp
--- a/src/hotspot/share/opto/phaseX.cpp
+++ b/src/hotspot/share/opto/phaseX.cpp
@@ -661,15 +661,11 @@
 
 
 
 //=============================================================================
 Node* PhaseGVN::apply_ideal(Node* k, bool can_reshape) {
-  Node* i = BarrierSet::barrier_set()->barrier_set_c2()->ideal_node(this, k, can_reshape);
-  if (i == nullptr) {
-    i = k->Ideal(this, can_reshape);
-  }
-  return i;
+  return k->Ideal(this, can_reshape);
 }
 
 //------------------------------transform--------------------------------------
 // Return a node which computes the same function as this node, but
 // in a faster or cheaper fashion.
@@ -2256,12 +2252,10 @@
                 }
                 assert(!(i < imax), "sanity");
               }
             } else if (dead->is_data_proj_of_pure_function(in)) {
               _worklist.push(in);
-            } else {
-              BarrierSet::barrier_set()->barrier_set_c2()->enqueue_useful_gc_barrier(this, in);
             }
             if (ReduceFieldZeroing && dead->is_Load() && i == MemNode::Memory &&
                 in->is_Proj() && in->in(0) != nullptr && in->in(0)->is_Initialize()) {
               // A Load that directly follows an InitializeNode is
               // going away. The Stores that follow are candidates
@@ -2614,28 +2608,16 @@
     Node* imem = use->as_Initialize()->proj_out_or_null(TypeFunc::Memory);
     if (imem != nullptr) add_users_to_worklist0(imem, worklist);
   }
   // Loading the java mirror from a Klass requires two loads and the type
   // of the mirror load depends on the type of 'n'. See LoadNode::Value().
-  //   LoadBarrier?(LoadP(LoadP(AddP(foo:Klass, #java_mirror))))
-  BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
-  bool has_load_barrier_nodes = bs->has_load_barrier_nodes();
-
+  //   LoadP(LoadP(AddP(foo:Klass, #java_mirror)))
   if (use_op == Op_LoadP && use->bottom_type()->isa_rawptr()) {
     for (DUIterator_Fast i2max, i2 = use->fast_outs(i2max); i2 < i2max; i2++) {
       Node* u = use->fast_out(i2);
       const Type* ut = u->bottom_type();
       if (u->Opcode() == Op_LoadP && ut->isa_instptr()) {
-        if (has_load_barrier_nodes) {
-          // Search for load barriers behind the load
-          for (DUIterator_Fast i3max, i3 = u->fast_outs(i3max); i3 < i3max; i3++) {
-            Node* b = u->fast_out(i3);
-            if (bs->is_gc_barrier_node(b)) {
-              worklist.push(b);
-            }
-          }
-        }
         worklist.push(u);
       }
     }
   }
   if (use->Opcode() == Op_OpaqueZeroTripGuard) {
@@ -2994,22 +2976,15 @@
 }
 
 // Loading the java mirror from a Klass requires two loads and the type of the mirror load depends on the type of 'n'.
 // See LoadNode::Value().
 void PhaseCCP::push_loadp(Unique_Node_List& worklist, const Node* use) const {
-  BarrierSetC2* barrier_set = BarrierSet::barrier_set()->barrier_set_c2();
-  bool has_load_barrier_nodes = barrier_set->has_load_barrier_nodes();
-
   if (use->Opcode() == Op_LoadP && use->bottom_type()->isa_rawptr()) {
     for (DUIterator_Fast imax, i = use->fast_outs(imax); i < imax; i++) {
       Node* loadp = use->fast_out(i);
       const Type* ut = loadp->bottom_type();
       if (loadp->Opcode() == Op_LoadP && ut->isa_instptr() && ut != type(loadp)) {
-        if (has_load_barrier_nodes) {
-          // Search for load barriers behind the load
-          push_load_barrier(worklist, barrier_set, loadp);
-        }
         worklist.push(loadp);
       }
     }
   }
 }
@@ -3381,12 +3356,10 @@
       }
       break;
     default:
       break;
     }
-
-    BarrierSet::barrier_set()->barrier_set_c2()->enqueue_useful_gc_barrier(igvn, old);
   }
 }
 
 void Node::set_req_X(uint i, Node *n, PhaseGVN *gvn) {
   PhaseIterGVN* igvn = gvn->is_IterGVN();
diff a/src/hotspot/share/opto/subnode.cpp b/src/hotspot/share/opto/subnode.cpp
--- a/src/hotspot/share/opto/subnode.cpp
+++ b/src/hotspot/share/opto/subnode.cpp
@@ -1096,13 +1096,10 @@
 
 static inline Node* isa_java_mirror_load(PhaseGVN* phase, Node* n) {
   // Return the klass node for (indirect load from OopHandle)
   //   LoadBarrier?(LoadP(LoadP(AddP(foo:Klass, #java_mirror))))
   //   or null if not matching.
-  BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
-    n = bs->step_over_gc_barrier(n);
-
   if (n->Opcode() != Op_LoadP) return nullptr;
 
   const TypeInstPtr* tp = phase->type(n)->isa_instptr();
   if (!tp || tp->instance_klass() != phase->C->env()->Class_klass()) return nullptr;
 
diff a/test/hotspot/jtreg/gc/shenandoah/compiler/TestShenandoahLoadRefBarrier.java b/test/hotspot/jtreg/gc/shenandoah/compiler/TestShenandoahLoadRefBarrier.java
--- /dev/null
+++ b/test/hotspot/jtreg/gc/shenandoah/compiler/TestShenandoahLoadRefBarrier.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2025, Red Hat, Inc. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test id=passive
+ * @summary Test Shenandoah Load Reference Barrier
+ * @requires vm.gc.Shenandoah
+ *
+ * @run main/othervm -XX:-IgnoreUnrecognizedVMOptions
+ *                  -XX:-BackgroundCompilation
+ *                  -XX:-UseOnStackReplacement
+ *                  -XX:-TieredCompilation
+ *                  -Xms512m -Xmx512m
+ *                  -XX:+UseShenandoahGC
+ *                  -XX:ShenandoahGCMode=passive
+ *                  -XX:+ShenandoahLoadRefBarrier
+ *                  -XX:CompileCommand=dontinline,TestShenandoahLoadRefBarrier::notInlined
+ *                  -XX:CompileCommand=dontinline,TestShenandoahLoadRefBarrier::lrb*
+ *                  -XX:CompileCommand=print,TestShenandoahLoadRefBarrier::lrb*
+ *                  -Xlog:gc+ergo,gc+barrier=debug
+ *                  TestShenandoahLoadRefBarrier
+ */
+
+public class TestShenandoahLoadRefBarrier {
+    private static final int LOOP_COUNT = 20_000;
+    private static A obj_a = new A();
+
+    public static void main(String[] args) {
+        for (int i = 0; i < LOOP_COUNT; i++) {
+            lrb_1();
+        }
+    }
+
+    private static boolean lrb_1() {
+        return TestShenandoahLoadRefBarrier.obj_a != null;
+    }
+
+    private static class A {
+        public float float_field;
+    }
+}
