< prev index next >

src/hotspot/cpu/aarch64/gc/shenandoah/shenandoahBarrierSetAssembler_aarch64.cpp

Print this page
*** 39,13 ***
--- 39,22 ---
  #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->
  
+ #ifdef PRODUCT
+ #define BLOCK_COMMENT(str) /* nothing */
+ #else
+ #define BLOCK_COMMENT(str) __ block_comment(str)
+ #endif
+ 
  void ShenandoahBarrierSetAssembler::arraycopy_prologue(MacroAssembler* masm, DecoratorSet decorators, bool is_oop,
                                                         Register src, Register dst, Register count, RegSet saved_regs) {
    if (is_oop) {
      bool dest_uninitialized = (decorators & IS_DEST_UNINITIALIZED) != 0;
      if ((ShenandoahSATBBarrier && !dest_uninitialized) || ShenandoahLoadRefBarrier) {

*** 604,10 ***
--- 613,363 ---
    } 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) {
+   assert_different_registers(obj, addr, tmp);
+   BLOCK_COMMENT("load_ref_barrier_c2 {");
+   if (!ShenandoahLoadRefBarrierStubC2::needs_barrier(node)) {
+     return;
+   }
+   Assembler::InlineSkippedInstructionsCounter skip_counter(masm);
+   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);
+   if (tmp != noreg) {
+     stub->dont_preserve(tmp); // temp, no need to save
+   }
+ 
+   Address gc_state(rthread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
+   __ ldrb(rscratch1, gc_state);
+ 
+   // Check if GC marking is in progress or we are handling a weak reference, otherwise we don't have to do anything.
+   bool is_strong = (node->barrier_data() & ShenandoahBarrierStrong) != 0;
+   if (is_strong) {
+     __ tbz(rscratch1, ShenandoahHeap::HAS_FORWARDED_BITPOS, *stub->continuation());
+     __ b(*stub->entry());
+   } else {
+     static_assert(ShenandoahHeap::HAS_FORWARDED_BITPOS == 0, "Relied on in LRB check below.");
+     __ orr(tmp, rscratch1, rscratch1, Assembler::LSR, ShenandoahHeap::WEAK_ROOTS_BITPOS);
+     __ tbz(tmp, ShenandoahHeap::HAS_FORWARDED_BITPOS, *stub->continuation());
+     __ b(*stub->entry());
+   }
+ 
+   __ bind(*stub->continuation());
+   BLOCK_COMMENT("} load_ref_barrier_c2");
+ }
+ 
+ void ShenandoahBarrierSetAssembler::load_ref_barrier_c3(const MachNode* node, MacroAssembler* masm, Register obj, Register addr, Register tmp, bool narrow, bool maybe_null, Register gc_state) {
+   BLOCK_COMMENT("load_ref_barrier_c3 {");
+   if (!ShenandoahLoadRefBarrierStubC2::needs_barrier(node)) {
+     return;
+   }
+   Assembler::InlineSkippedInstructionsCounter skip_counter(masm);
+   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 or we are handling a weak reference,
+   // otherwise we don't have to do anything. The code below was optimized to
+   // use less registers and instructions as possible at the expense of always
+   // having a branch instruction. The reason why we use this particular branch
+   // scheme is because the stub entry may be too far for the tbnz to jump to.
+   bool is_strong = (node->barrier_data() & ShenandoahBarrierStrong) != 0;
+   if (is_strong) {
+     __ tbz(gc_state, ShenandoahHeap::HAS_FORWARDED_BITPOS, *stub->continuation());
+     __ b(*stub->entry());
+   } else {
+     static_assert(ShenandoahHeap::HAS_FORWARDED_BITPOS == 0, "Relied on in LRB check below.");
+     __ orr(tmp, gc_state, gc_state, Assembler::LSR, ShenandoahHeap::WEAK_ROOTS_BITPOS);
+     __ tbz(tmp, ShenandoahHeap::HAS_FORWARDED_BITPOS, *stub->continuation());
+     __ b(*stub->entry());
+   }
+ 
+   __ bind(*stub->continuation());
+   BLOCK_COMMENT("} load_ref_barrier_c3");
+ }
+ 
+ void ShenandoahBarrierSetAssembler::satb_barrier_c3(const MachNode* node, MacroAssembler* masm, Register addr, Register pre_val, Register gc_state) {
+   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.
+   __ tstw(gc_state, ShenandoahHeap::MARKING);
+   __ br(Assembler::NE, *stub->entry());
+   __ bind(*stub->continuation());
+ }
+ 
+ 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 oldval,
+                                                    Register newval, Register res,
+                                                    Register tmp1, Register tmp2,
+                                                    bool acquire, bool release, bool weak, bool exchange) {
+   BLOCK_COMMENT("cmpxchg_oop_c2 {");
+   assert(res != noreg, "need result register");
+   assert_different_registers(oldval, addr, res, tmp1, tmp2);
+   assert_different_registers(newval, addr, res, tmp1, tmp2);
+ 
+   // Fast-path: Try to CAS optimistically. If successful, then we are done.
+   // EQ flag set iff success. 'tmp2' holds value fetched.
+   Assembler::operand_size size = UseCompressedOops ? Assembler::word : Assembler::xword;
+   __ cmpxchg(addr, oldval, newval, size, acquire, release, weak, tmp2);
+ 
+   // If we need a boolean result out of CAS, set the flag appropriately.  This
+   // would be the final result if we do not go slow.
+   if (!exchange) {
+     __ cset(res, Assembler::EQ);
+   } else {
+     __ mov(res, tmp2);
+   }
+ 
+   if (ShenandoahCASBarrier) {
+     ShenandoahCASBarrierSlowStubC2* const slow_stub =
+       ShenandoahCASBarrierSlowStubC2::create(node, addr, oldval, newval, res, tmp1, tmp2, exchange, acquire, release, weak);
+ 
+     slow_stub->dont_preserve(res);    // set at the end, no need to save
+     slow_stub->dont_preserve(oldval); // saved explicitly
+     slow_stub->dont_preserve(tmp1);   // temp, no need to save
+     slow_stub->dont_preserve(tmp2);   // temp, no need to save
+ 
+     // On success, we do not need any additional handling.
+     __ br(Assembler::EQ, *slow_stub->continuation());
+ 
+     // If GC is in progress, it is likely we need additional handling for false negatives.
+     Address gc_state(rthread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
+     __ ldrb(tmp1, gc_state);
+     __ tbz(tmp1, ShenandoahHeap::HAS_FORWARDED_BITPOS, *slow_stub->continuation());
+     __ b(*slow_stub->entry());
+ 
+     // Slow stub re-enters with result set correctly.
+     __ bind(*slow_stub->continuation());
+   }
+ 
+   BLOCK_COMMENT("} cmpxchg_oop_c2");
+ }
+ 
+ #undef __
+ #define __ masm.
+ 
+ void ShenandoahLoadRefBarrierStubC2::emit_code(MacroAssembler& masm) {
+   BLOCK_COMMENT("ShenandoahLoadRefBarrierStubC2::emit_code {");
+   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());
+   BLOCK_COMMENT("} ShenandoahLoadRefBarrierStubC2::emit_code");
+ }
+ 
+ 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);
+   }
+ 
+   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) {
+   __ bind(*entry());
+ 
+   // CAS has failed because the value held at addr does not match expected.
+   // This may be a false negative because the version in memory might be
+   // the from-space version of the same object we currently hold to-space
+   // reference for.
+   //
+   // To resolve this, we need to pass the location through the LRB fixup,
+   // this will make sure that the location has only to-space pointers.
+   // To avoid calling into runtime often, we cset-check the object first.
+   // We can inline most of the work here, but there is little point,
+   // as CAS failures over cset locations must be rare. This fast-slow split
+   // matches what we do for normal LRB.
+ 
+   // Non-strong references should always go to runtime. We do not expect
+   // CASes over non-strong locations.
+   assert((_node->barrier_data() & ShenandoahBarrierStrong) != 0, "Only strong references for CASes");
+ 
+   Label L_final;
+ 
+   // (Compressed) failure witness is in _tmp2.
+   // Unpack it and check if it is in collection set.
+   // We need to backup the compressed version to use in the LRB.
+   __ mov(_result, _tmp2);
+   if (UseCompressedOops) {
+     __ decode_heap_oop(_tmp2);
+   }
+ 
+   __ mov(_tmp1, ShenandoahHeap::in_cset_fast_test_addr());
+   __ lsr(_tmp2, _tmp2, ShenandoahHeapRegion::region_size_bytes_shift_jint());
+   __ ldrb(_tmp1, Address(_tmp1, _tmp2));
+   __ cbz(_tmp1, L_final);
+ 
+   {
+     SaveLiveRegisters save_registers(&masm, this);
+     // Load up failure witness again.
+     __ mov(c_rarg0, _result);
+     if (UseCompressedOops) {
+       __ decode_heap_oop(c_rarg0);
+     }
+     __ mov(c_rarg1, _addr_reg);
+ 
+     if (UseCompressedOops) {
+       __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_strong_narrow), 2);
+     } else {
+       __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_strong), 2);
+     }
+     // We have called LRB to fix up the heap location. We do not care about its
+     // result, as we will just try to CAS the location again.
+   }
+ 
+   __ bind(L_final);
+ 
+   Assembler::operand_size size = UseCompressedOops ? Assembler::word : Assembler::xword;
+   __ cmpxchg(_addr_reg, _expected, _new_val, size, _acquire, _release, _weak, _result);
+ 
+   if (!_cae) {
+     __ cset(_result, Assembler::EQ);
+   }
+   __ 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) {
    assert(ShenandoahCardBarrier, "Should have been checked by caller");
  
    Label L_loop, L_done;
< prev index next >