< prev index next >

src/hotspot/cpu/riscv/gc/shenandoah/shenandoahBarrierSetAssembler_riscv.cpp

Print this page
@@ -40,10 +40,14 @@
  #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"
+ #include "opto/output.hpp"
+ #endif
  
  #define __ masm->
  
  void ShenandoahBarrierSetAssembler::arraycopy_prologue(MacroAssembler* masm, DecoratorSet decorators, bool is_oop,
                                                         Register src, Register dst, Register count, RegSet saved_regs) {

@@ -766,5 +770,321 @@
  }
  
  #undef __
  
  #endif // COMPILER1
+ 
+ #ifdef COMPILER2
+ 
+ #undef __
+ #define __ masm->
+ 
+ void ShenandoahBarrierSetAssembler::load_c2(const MachNode* node, MacroAssembler* masm, Register dst, Address src, Register tmp1, Register tmp2, bool is_narrow) {
+   // Do the actual load. This load is the candidate for implicit null check, and MUST come first.
+   if (is_narrow) {
+     __ lwu(dst, src);
+   } else {
+     __ ld(dst, src);
+   }
+ 
+   ShenandoahBarrierStubC2::load_post(masm, node, dst, src, tmp1, tmp2, is_narrow);
+ }
+ 
+ void ShenandoahBarrierSetAssembler::store_c2(const MachNode* node, MacroAssembler* masm, Address dst, bool dst_narrow,
+     Register src, bool src_narrow, Register tmp1, Register tmp2, Register tmp3) {
+ 
+   ShenandoahBarrierStubC2::store_pre(masm, node, tmp1, dst, tmp2, tmp3, dst_narrow);
+ 
+   // Do the actual store
+   if (dst_narrow) {
+     if (!src_narrow) {
+       // Need to encode into tmp, because we cannot clobber src.
+       assert(tmp1 != noreg, "need temp register");
+       if ((node->barrier_data() & ShenandoahBitNotNull) == 0) {
+         __ encode_heap_oop(tmp1, src);
+       } else {
+         __ encode_heap_oop_not_null(tmp1, src);
+       }
+       src = tmp1;
+     }
+     __ sw(src, dst);
+   } else {
+     __ sd(src, dst);
+   }
+ 
+   ShenandoahBarrierStubC2::store_post(masm, node, dst, tmp2, tmp3);
+ }
+ 
+ void ShenandoahBarrierSetAssembler::compare_and_set_c2(const MachNode* node, MacroAssembler* masm, Register res, Register addr,
+     Register oldval, Register newval, Register tmp1, Register tmp2, Register tmp3, bool exchange, bool narrow, bool is_acquire) {
+   const Assembler::Aqrl acquire = is_acquire ? Assembler::aq : Assembler::relaxed;
+   const Assembler::Aqrl release = Assembler::rl;
+   const Assembler::operand_size size = narrow ? Assembler::uint32 : Assembler::int64;
+ 
+   ShenandoahBarrierStubC2::load_store_pre(masm, node, tmp1, Address(addr), tmp2, tmp3, narrow);
+ 
+   // CAS!
+   __ cmpxchg(addr, oldval, newval, size, acquire, release, /* result */ res, !exchange /* result_as_bool */);
+ 
+   ShenandoahBarrierStubC2::load_store_post(masm, node, Address(addr, 0), tmp2, tmp3);
+ }
+ 
+ void ShenandoahBarrierSetAssembler::get_and_set_c2(const MachNode* node, MacroAssembler* masm, Register preval,
+     Register newval, Register addr, Register tmp1, Register tmp2, Register tmp3, bool is_acquire) {
+   const bool is_narrow = node->bottom_type()->isa_narrowoop();
+ 
+   ShenandoahBarrierStubC2::load_store_pre(masm, node, tmp1, Address(addr, 0), tmp2, tmp3, is_narrow);
+ 
+   if (is_narrow) {
+     if (is_acquire) {
+       __ atomic_xchgalwu(preval, newval, addr);
+     } else {
+       __ atomic_xchgwu(preval, newval, addr);
+     }
+   } else {
+     if (is_acquire) {
+       __ atomic_xchgal(preval, newval, addr);
+     } else {
+       __ atomic_xchg(preval, newval, addr);
+     }
+   }
+ 
+   ShenandoahBarrierStubC2::load_store_post(masm, node, Address(addr, 0), tmp2, tmp3);
+ }
+ 
+ #undef __
+ #define __ masm.
+ 
+ void ShenandoahBarrierStubC2::cardtable(MacroAssembler& masm, Address address, Register tmp1, Register tmp2) {
+   assert(CardTable::dirty_card_val() == 0, "must be");
+   Assembler::InlineSkippedInstructionsCounter skip_counter(&masm);
+ 
+   // tmp1 = card table base (holder)
+   Address curr_ct_holder_addr(xthread, in_bytes(ShenandoahThreadLocalData::card_table_offset()));
+   __ ld(tmp1, curr_ct_holder_addr);
+ 
+   // tmp1 = effective address
+   __ la(tmp2, address);
+ 
+   // tmp2 = &card_table[ addr >> CardTable::card_shift() ] ; card index
+   __ srli(tmp2, tmp2, CardTable::card_shift());
+   __ add(tmp2, tmp2, tmp1);
+ 
+   if (UseCondCardMark) {
+     Label L_already_dirty;
+     __ lbu(tmp1, Address(tmp2));
+     __ beqz(tmp1, L_already_dirty);
+     __ sb(zr, Address(tmp2));
+     __ bind(L_already_dirty);
+   } else {
+     __ sb(zr, Address(tmp2));
+   }
+ }
+ 
+ void ShenandoahBarrierStubC2::enter_if_gc_state(MacroAssembler& masm, const char test_state, Register tmp) {
+   Assembler::InlineSkippedInstructionsCounter skip_counter(&masm);
+ 
+   Address gc_state_fast(xthread, in_bytes(ShenandoahThreadLocalData::gc_state_fast_array_offset(test_state)));
+   __ lbu(tmp, gc_state_fast);
+   __ beqz(tmp, *continuation());
+   __ j(*entry());
+ 
+   // This is were the slowpath stub will return to or the code above will
+   // jump to if the checks are false
+   __ bind(*continuation());
+ }
+ 
+ void ShenandoahBarrierStubC2::emit_code(MacroAssembler& masm) {
+   Assembler::InlineSkippedInstructionsCounter skip_counter(&masm);
+   assert(_needs_keep_alive_barrier || _needs_load_ref_barrier, "Why are you here?");
+ 
+   __ bind(*entry());
+ 
+   // If we need to load ourselves, do it here.
+   if (_do_load) {
+     if (_narrow) {
+       __ lwu(_obj, _addr);
+     } else {
+       __ ld(_obj, _addr);
+     }
+   }
+ 
+   // If the object is null, there is no point in applying barriers.
+   maybe_far_jump_if_zero(masm, _obj);
+ 
+   // We need to make sure that loads done by callers survive across slow-path calls.
+   // For self-loads, we need to care about the case when both KA and LRB are enabled (rare).
+   bool needs_both_barriers = _needs_keep_alive_barrier && _needs_load_ref_barrier;
+   if (!_do_load || needs_both_barriers) {
+     preserve(_obj);
+   }
+ 
+   // Go for barriers. Barriers can return straight to continuation, as long
+   // as another barrier is not needed and we can reach the fastpath.
+   if (needs_both_barriers) {
+     keepalive(masm, nullptr);
+     lrb(masm);
+   } else if (_needs_keep_alive_barrier) {
+     keepalive(masm, continuation());
+   } else if (_needs_load_ref_barrier) {
+     lrb(masm);
+   } else {
+     ShouldNotReachHere();
+   }
+ }
+ 
+ void ShenandoahBarrierStubC2::maybe_far_jump_if_zero(MacroAssembler& masm, Register reg) {
+   Label L_short_jump;
+   __ bnez(reg, L_short_jump);
+   __ j(*continuation());
+   __ bind(L_short_jump);
+ }
+ 
+ void ShenandoahBarrierStubC2::keepalive(MacroAssembler& masm, Label* L_done) {
+   Address index(xthread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_index_offset()));
+   Address buffer(xthread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset()));
+   Label L_through, L_slowpath;
+ 
+   // If another barrier is enabled as well, do a runtime check for a specific barrier.
+   if (_needs_load_ref_barrier) {
+     assert(L_done == nullptr, "L_done is always null when _needs_load_ref_barrier is true");
+     Address gc_state_fast(xthread, in_bytes(ShenandoahThreadLocalData::gc_state_fast_array_offset(ShenandoahHeap::MARKING)));
+     __ lbu(_tmp1, gc_state_fast);
+     __ beqz(_tmp1, L_through);
+   }
+ 
+   // Fast-path: put object into buffer.
+   // If buffer is already full, go slow.
+   __ ld(_tmp1, index);
+   __ beqz(_tmp1, L_slowpath);
+   __ subi(_tmp1, _tmp1, wordSize);
+   __ sd(_tmp1, index);
+   __ ld(_tmp2, buffer);
+ 
+   // Store the object in queue.
+   // If object is narrow, we need to decode it before inserting.
+   __ add(_tmp1, _tmp1, _tmp2);
+   if (_narrow) {
+     __ decode_heap_oop_not_null(_tmp2, _obj);
+     __ sd(_tmp2, Address(_tmp1));
+   } else {
+     __ sd(_obj, Address(_tmp1));
+   }
+ 
+   // Fast-path exits here.
+   if (L_done != nullptr) {
+     __ j(*L_done);
+   } else {
+     __ j(L_through);
+   }
+ 
+   // Slow-path: call runtime to handle.
+   __ bind(L_slowpath);
+ 
+   {
+     SaveLiveRegisters slr(&masm, this);
+ 
+     // Go to runtime and handle the rest there.
+     __ mv(c_rarg0, _obj);
+     __ rt_call(keepalive_runtime_entry_addr());
+   }
+   if (L_done != nullptr) {
+     __ j(*L_done);
+   } else {
+     __ bind(L_through);
+   }
+ }
+ 
+ void ShenandoahBarrierStubC2::lrb(MacroAssembler& masm) {
+   Label L_slow;
+ 
+   // If another barrier is enabled as well, do a runtime check for a specific barrier.
+   if (_needs_keep_alive_barrier) {
+     char state_to_check = ShenandoahHeap::HAS_FORWARDED | (_needs_load_ref_weak_barrier ? ShenandoahHeap::WEAK_ROOTS : 0);
+     Address gc_state_fast(xthread, in_bytes(ShenandoahThreadLocalData::gc_state_fast_array_offset(state_to_check)));
+     __ lbu(_tmp1, gc_state_fast);
+     maybe_far_jump_if_zero(masm, _tmp1);
+   }
+ 
+   // If weak references are being processed, weak/phantom loads need to go slow,
+   // regardless of their cset status.
+   if (_needs_load_ref_weak_barrier) {
+     Address gc_state_fast(xthread, in_bytes(ShenandoahThreadLocalData::gc_state_fast_array_offset(ShenandoahHeap::WEAK_ROOTS)));
+     __ lbu(_tmp1, gc_state_fast);
+     __ bnez(_tmp1, L_slow);
+   }
+ 
+   // Cset-check. Fall-through to slow if in collection set.
+   if (_narrow) {
+     __ decode_heap_oop_not_null(_tmp2, _obj);
+   } else {
+     __ mv(_tmp2, _obj);
+   }
+ 
+   __ mv(_tmp1, ShenandoahHeap::in_cset_fast_test_addr());
+   __ srli(_tmp2, _tmp2, ShenandoahHeapRegion::region_size_bytes_shift_jint());
+   __ add(_tmp1, _tmp1, _tmp2);
+   __ lbu(_tmp1, Address(_tmp1, 0));
+   maybe_far_jump_if_zero(masm, _tmp1);
+ 
+   // Slow path
+   __ bind(L_slow);
+ 
+   // Obj is the result, need to temporarily stop preserving it.
+   bool is_obj_preserved = is_preserved(_obj);
+   if (is_obj_preserved) {
+     dont_preserve(_obj);
+   }
+   {
+     SaveLiveRegisters slr(&masm, this);
+ 
+     // Shuffle in the arguments. The end result should be:
+     //   c_rarg0 <- obj
+     //   c_rarg1 <- lea(addr)
+     if (c_rarg0 == _obj) {
+       __ la(c_rarg1, _addr);
+     } else if (c_rarg1 == _obj) {
+       // Set up arguments in reverse, and then flip them
+       __ la(c_rarg0, _addr);
+       // flip them
+       __ mv(_tmp1, c_rarg0);
+       __ mv(c_rarg0, c_rarg1);
+       __ mv(c_rarg1, _tmp1);
+     } else {
+       assert_different_registers(c_rarg1, _obj);
+       __ la(c_rarg1, _addr);
+       __ mv(c_rarg0, _obj);
+     }
+ 
+     // Go to runtime and handle the rest there.
+     __ rt_call(lrb_runtime_entry_addr());
+ 
+     // Save the result where needed. Narrow entries return narrowOop (32 bits)
+     // we need to zero the upper 32 bits of x10.
+     if (_narrow) {
+       __ zext_w(_obj, x10);
+     } else {
+       __ mv(_obj, x10);
+     }
+   }
+   if (is_obj_preserved) {
+     preserve(_obj);
+   }
+ 
+   __ j(*continuation());
+ }
+ 
+ int ShenandoahBarrierStubC2::available_gp_registers() {
+   Unimplemented(); // Not used
+   return 0;
+ }
+ 
+ bool ShenandoahBarrierStubC2::is_special_register(Register r) {
+   Unimplemented(); // Not used
+   return true;
+ }
+ 
+ void ShenandoahBarrierStubC2::post_init() {
+   // Do nothing.
+ }
+ 
+ #endif // COMPILER2
< prev index next >