1 /*
   2  * Copyright (c) 2018, 2019, Red Hat, Inc. All rights reserved.
   3  *
   4  * This code is free software; you can redistribute it and/or modify it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.
   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #include "precompiled.hpp"
  25 #include "gc/shenandoah/shenandoahBarrierSetAssembler.hpp"
  26 #include "gc/shenandoah/shenandoahForwarding.hpp"
  27 #include "gc/shenandoah/shenandoahHeap.hpp"
  28 #include "gc/shenandoah/shenandoahHeapRegion.hpp"
  29 #include "gc/shenandoah/shenandoahHeuristics.hpp"
  30 #include "gc/shenandoah/shenandoahRuntime.hpp"
  31 #include "gc/shenandoah/shenandoahThreadLocalData.hpp"
  32 #include "interpreter/interpreter.hpp"
  33 #include "interpreter/interp_masm.hpp"
  34 #include "runtime/sharedRuntime.hpp"
  35 #include "runtime/thread.hpp"
  36 #ifdef COMPILER1
  37 #include "c1/c1_LIRAssembler.hpp"
  38 #include "c1/c1_MacroAssembler.hpp"
  39 #include "gc/shenandoah/c1/shenandoahBarrierSetC1.hpp"
  40 #endif
  41 
  42 #define __ masm->
  43 
  44 address ShenandoahBarrierSetAssembler::_shenandoah_lrb = NULL;
  45 
  46 void ShenandoahBarrierSetAssembler::arraycopy_prologue(MacroAssembler* masm, DecoratorSet decorators, bool is_oop,
  47                                                        Register addr, Register count, RegSet saved_regs) {
  48   if (is_oop) {
  49     bool dest_uninitialized = (decorators & IS_DEST_UNINITIALIZED) != 0;
  50     if (ShenandoahSATBBarrier && !dest_uninitialized) {
  51 
  52       Label done;
  53 
  54       // Avoid calling runtime if count == 0
  55       __ cbz(count, done);
  56 
  57       // Is marking active?
  58       Address gc_state(rthread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
  59       __ ldrb(rscratch1, gc_state);
  60       __ tbz(rscratch1, ShenandoahHeap::MARKING_BITPOS, done);
  61 
  62       __ push(saved_regs, sp);
  63       if (count == c_rarg0) {
  64         if (addr == c_rarg1) {
  65           // exactly backwards!!
  66           __ mov(rscratch1, c_rarg0);
  67           __ mov(c_rarg0, c_rarg1);
  68           __ mov(c_rarg1, rscratch1);
  69         } else {
  70           __ mov(c_rarg1, count);
  71           __ mov(c_rarg0, addr);
  72         }
  73       } else {
  74         __ mov(c_rarg0, addr);
  75         __ mov(c_rarg1, count);
  76       }
  77       if (UseCompressedOops) {
  78         __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_array_pre_narrow_oop_entry), 2);
  79       } else {
  80         __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_array_pre_oop_entry), 2);
  81       }
  82       __ pop(saved_regs, sp);
  83       __ bind(done);
  84     }
  85   }
  86 }
  87 
  88 void ShenandoahBarrierSetAssembler::arraycopy_epilogue(MacroAssembler* masm, DecoratorSet decorators, bool is_oop,
  89                                                        Register start, Register count, Register scratch, RegSet saved_regs) {
  90   if (is_oop) {
  91       Label done;
  92 
  93       // Is updating references?
  94       Address gc_state(rthread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
  95       __ ldrb(rscratch1, gc_state);
  96       __ tbz(rscratch1, ShenandoahHeap::UPDATEREFS_BITPOS, done);
  97 
  98     assert_different_registers(start, count, scratch);
  99     assert_different_registers(c_rarg0, count);
 100 
 101     // Avoid calling runtime if count == 0
 102     __ cbz(count, done);
 103 
 104     __ push(saved_regs, sp);
 105     __ mov(c_rarg0, start);
 106     __ mov(c_rarg1, count);
 107     __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_array_post_entry), 2);
 108     __ pop(saved_regs, sp);
 109 
 110     __ bind(done);
 111   }
 112 }
 113 
 114 void ShenandoahBarrierSetAssembler::shenandoah_write_barrier_pre(MacroAssembler* masm,
 115                                                                  Register obj,
 116                                                                  Register pre_val,
 117                                                                  Register thread,
 118                                                                  Register tmp,
 119                                                                  bool tosca_live,
 120                                                                  bool expand_call) {
 121   if (ShenandoahSATBBarrier) {
 122     satb_write_barrier_pre(masm, obj, pre_val, thread, tmp, tosca_live, expand_call);
 123   }
 124 }
 125 
 126 void ShenandoahBarrierSetAssembler::satb_write_barrier_pre(MacroAssembler* masm,
 127                                                            Register obj,
 128                                                            Register pre_val,
 129                                                            Register thread,
 130                                                            Register tmp,
 131                                                            bool tosca_live,
 132                                                            bool expand_call) {
 133   // If expand_call is true then we expand the call_VM_leaf macro
 134   // directly to skip generating the check by
 135   // InterpreterMacroAssembler::call_VM_leaf_base that checks _last_sp.
 136 
 137   assert(thread == rthread, "must be");
 138 
 139   Label done;
 140   Label runtime;
 141 
 142   assert_different_registers(obj, pre_val, tmp, rscratch1);
 143   assert(pre_val != noreg &&  tmp != noreg, "expecting a register");
 144 
 145   Address in_progress(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_active_offset()));
 146   Address index(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_index_offset()));
 147   Address buffer(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset()));
 148 
 149   // Is marking active?
 150   if (in_bytes(SATBMarkQueue::byte_width_of_active()) == 4) {
 151     __ ldrw(tmp, in_progress);
 152   } else {
 153     assert(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "Assumption");
 154     __ ldrb(tmp, in_progress);
 155   }
 156   __ cbzw(tmp, done);
 157 
 158   // Do we need to load the previous value?
 159   if (obj != noreg) {
 160     __ load_heap_oop(pre_val, Address(obj, 0), noreg, noreg, AS_RAW);
 161   }
 162 
 163   // Is the previous value null?
 164   __ cbz(pre_val, done);
 165 
 166   // Can we store original value in the thread's buffer?
 167   // Is index == 0?
 168   // (The index field is typed as size_t.)
 169 
 170   __ ldr(tmp, index);                      // tmp := *index_adr
 171   __ cbz(tmp, runtime);                    // tmp == 0?
 172                                         // If yes, goto runtime
 173 
 174   __ sub(tmp, tmp, wordSize);              // tmp := tmp - wordSize
 175   __ str(tmp, index);                      // *index_adr := tmp
 176   __ ldr(rscratch1, buffer);
 177   __ add(tmp, tmp, rscratch1);             // tmp := tmp + *buffer_adr
 178 
 179   // Record the previous value
 180   __ str(pre_val, Address(tmp, 0));
 181   __ b(done);
 182 
 183   __ bind(runtime);
 184   // save the live input values
 185   RegSet saved = RegSet::of(pre_val);
 186   if (tosca_live) saved += RegSet::of(r0);
 187   if (obj != noreg) saved += RegSet::of(obj);
 188 
 189   __ push(saved, sp);
 190 
 191   // Calling the runtime using the regular call_VM_leaf mechanism generates
 192   // code (generated by InterpreterMacroAssember::call_VM_leaf_base)
 193   // that checks that the *(rfp+frame::interpreter_frame_last_sp) == NULL.
 194   //
 195   // If we care generating the pre-barrier without a frame (e.g. in the
 196   // intrinsified Reference.get() routine) then ebp might be pointing to
 197   // the caller frame and so this check will most likely fail at runtime.
 198   //
 199   // Expanding the call directly bypasses the generation of the check.
 200   // So when we do not have have a full interpreter frame on the stack
 201   // expand_call should be passed true.
 202 
 203   if (expand_call) {
 204     assert(pre_val != c_rarg1, "smashed arg");
 205     __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), pre_val, thread);
 206   } else {
 207     __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), pre_val, thread);
 208   }
 209 
 210   __ pop(saved, sp);
 211 
 212   __ bind(done);
 213 }
 214 
 215 void ShenandoahBarrierSetAssembler::resolve_forward_pointer(MacroAssembler* masm, Register dst, Register tmp) {
 216   assert(ShenandoahLoadRefBarrier || ShenandoahCASBarrier, "Should be enabled");
 217   Label is_null;
 218   __ cbz(dst, is_null);
 219   resolve_forward_pointer_not_null(masm, dst, tmp);
 220   __ bind(is_null);
 221 }
 222 
 223 // IMPORTANT: This must preserve all registers, even rscratch1 and rscratch2, except those explicitely
 224 // passed in.
 225 void ShenandoahBarrierSetAssembler::resolve_forward_pointer_not_null(MacroAssembler* masm, Register dst, Register tmp) {
 226   assert(ShenandoahLoadRefBarrier || ShenandoahCASBarrier, "Should be enabled");
 227   // The below loads the mark word, checks if the lowest two bits are
 228   // set, and if so, clear the lowest two bits and copy the result
 229   // to dst. Otherwise it leaves dst alone.
 230   // Implementing this is surprisingly awkward. I do it here by:
 231   // - Inverting the mark word
 232   // - Test lowest two bits == 0
 233   // - If so, set the lowest two bits
 234   // - Invert the result back, and copy to dst
 235 
 236   bool borrow_reg = (tmp == noreg);
 237   if (borrow_reg) {
 238     // No free registers available. Make one useful.
 239     tmp = rscratch1;
 240     __ push(RegSet::of(tmp), sp);
 241   }
 242 
 243   Label done;
 244   __ ldr(tmp, Address(dst, oopDesc::mark_offset_in_bytes()));
 245   __ eon(tmp, tmp, zr);
 246   __ ands(zr, tmp, markOopDesc::lock_mask_in_place);
 247   __ br(Assembler::NE, done);
 248   __ orr(tmp, tmp, markOopDesc::marked_value);
 249   __ eon(dst, tmp, zr);
 250   __ bind(done);
 251 
 252   if (borrow_reg) {
 253     __ pop(RegSet::of(tmp), sp);
 254   }
 255 }
 256 
 257 void ShenandoahBarrierSetAssembler::load_reference_barrier_not_null(MacroAssembler* masm, Register dst, Register tmp) {
 258   assert(ShenandoahLoadRefBarrier, "Should be enabled");
 259   assert(dst != rscratch2, "need rscratch2");
 260 
 261   Label done;
 262   __ enter();
 263   Address gc_state(rthread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
 264   __ ldrb(rscratch2, gc_state);
 265 
 266   // Check for heap stability
 267   __ tbz(rscratch2, ShenandoahHeap::HAS_FORWARDED_BITPOS, done);
 268 
 269   RegSet to_save = RegSet::of(r0);
 270   if (dst != r0) {
 271     __ push(to_save, sp);
 272     __ mov(r0, dst);
 273   }
 274 
 275   __ far_call(RuntimeAddress(CAST_FROM_FN_PTR(address, ShenandoahBarrierSetAssembler::shenandoah_lrb())));
 276 
 277   if (dst != r0) {
 278     __ mov(dst, r0);
 279     __ pop(to_save, sp);
 280   }
 281 
 282   __ bind(done);
 283   __ leave();
 284 }
 285 
 286 void ShenandoahBarrierSetAssembler::storeval_barrier(MacroAssembler* masm, Register dst, Register tmp) {
 287   if (ShenandoahStoreValEnqueueBarrier) {
 288     // Save possibly live regs.
 289     RegSet live_regs = RegSet::range(r0, r4) - dst;
 290     __ push(live_regs, sp);
 291     __ strd(v0, __ pre(sp, 2 * -wordSize));
 292 
 293     satb_write_barrier_pre(masm, noreg, dst, rthread, tmp, true, false);
 294 
 295     // Restore possibly live regs.
 296     __ ldrd(v0, __ post(sp, 2 * wordSize));
 297     __ pop(live_regs, sp);
 298   }
 299 }
 300 
 301 void ShenandoahBarrierSetAssembler::load_reference_barrier(MacroAssembler* masm, Register dst, Register tmp) {
 302   if (ShenandoahLoadRefBarrier) {
 303     Label is_null;
 304     __ cbz(dst, is_null);
 305     load_reference_barrier_not_null(masm, dst, tmp);
 306     __ bind(is_null);
 307   }
 308 }
 309 
 310 void ShenandoahBarrierSetAssembler::load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
 311                                             Register dst, Address src, Register tmp1, Register tmp_thread) {
 312   bool on_oop = type == T_OBJECT || type == T_ARRAY;
 313   bool on_weak = (decorators & ON_WEAK_OOP_REF) != 0;
 314   bool on_phantom = (decorators & ON_PHANTOM_OOP_REF) != 0;
 315   bool on_reference = on_weak || on_phantom;
 316 
 317   BarrierSetAssembler::load_at(masm, decorators, type, dst, src, tmp1, tmp_thread);
 318   if (on_oop) {
 319     load_reference_barrier(masm, dst, tmp1);
 320 
 321     if (ShenandoahKeepAliveBarrier && on_reference) {
 322       __ enter();
 323       satb_write_barrier_pre(masm /* masm */,
 324                              noreg /* obj */,
 325                              dst /* pre_val */,
 326                              rthread /* thread */,
 327                              tmp1 /* tmp */,
 328                              true /* tosca_live */,
 329                              true /* expand_call */);
 330       __ leave();
 331     }
 332   }
 333 }
 334 
 335 void ShenandoahBarrierSetAssembler::store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
 336                                              Address dst, Register val, Register tmp1, Register tmp2) {
 337   bool on_oop = type == T_OBJECT || type == T_ARRAY;
 338   if (!on_oop) {
 339     BarrierSetAssembler::store_at(masm, decorators, type, dst, val, tmp1, tmp2);
 340     return;
 341   }
 342 
 343   // flatten object address if needed
 344   if (dst.index() == noreg && dst.offset() == 0) {
 345     if (dst.base() != r3) {
 346       __ mov(r3, dst.base());
 347     }
 348   } else {
 349     __ lea(r3, dst);
 350   }
 351 
 352   shenandoah_write_barrier_pre(masm,
 353                                r3 /* obj */,
 354                                tmp2 /* pre_val */,
 355                                rthread /* thread */,
 356                                tmp1  /* tmp */,
 357                                val != noreg /* tosca_live */,
 358                                false /* expand_call */);
 359 
 360   if (val == noreg) {
 361     BarrierSetAssembler::store_at(masm, decorators, type, Address(r3, 0), noreg, noreg, noreg);
 362   } else {
 363     storeval_barrier(masm, val, tmp1);
 364     // G1 barrier needs uncompressed oop for region cross check.
 365     Register new_val = val;
 366     if (UseCompressedOops) {
 367       new_val = rscratch2;
 368       __ mov(new_val, val);
 369     }
 370     BarrierSetAssembler::store_at(masm, decorators, type, Address(r3, 0), val, noreg, noreg);
 371   }
 372 
 373 }
 374 
 375 void ShenandoahBarrierSetAssembler::cmpxchg_oop(MacroAssembler* masm, Register addr, Register expected, Register new_val,
 376                                                 bool acquire, bool release, bool weak, bool is_cae,
 377                                                 Register result) {
 378   Register tmp1 = rscratch1;
 379   Register tmp2 = rscratch2;
 380   bool is_narrow = UseCompressedOops;
 381   Assembler::operand_size size = is_narrow ? Assembler::word : Assembler::xword;
 382 
 383   assert_different_registers(addr, expected, new_val, tmp1, tmp2);
 384 
 385   Label retry, done, fail;
 386 
 387   // CAS, using LL/SC pair.
 388   __ bind(retry);
 389   __ load_exclusive(tmp1, addr, size, acquire);
 390   if (is_narrow) {
 391     __ cmpw(tmp1, expected);
 392   } else {
 393     __ cmp(tmp1, expected);
 394   }
 395   __ br(Assembler::NE, fail);
 396   __ store_exclusive(tmp2, new_val, addr, size, release);
 397   if (weak) {
 398     __ cmpw(tmp2, 0u); // If the store fails, return NE to our caller
 399   } else {
 400     __ cbnzw(tmp2, retry);
 401   }
 402   __ b(done);
 403 
 404  __  bind(fail);
 405   // Check if rb(expected)==rb(tmp1)
 406   // Shuffle registers so that we have memory value ready for next expected.
 407   __ mov(tmp2, expected);
 408   __ mov(expected, tmp1);
 409   if (is_narrow) {
 410     __ decode_heap_oop(tmp1, tmp1);
 411     __ decode_heap_oop(tmp2, tmp2);
 412   }
 413   resolve_forward_pointer(masm, tmp1);
 414   resolve_forward_pointer(masm, tmp2);
 415   __ cmp(tmp1, tmp2);
 416   // Retry with expected now being the value we just loaded from addr.
 417   __ br(Assembler::EQ, retry);
 418   if (is_cae && is_narrow) {
 419     // For cmp-and-exchange and narrow oops, we need to restore
 420     // the compressed old-value. We moved it to 'expected' a few lines up.
 421     __ mov(tmp1, expected);
 422   }
 423   __ bind(done);
 424 
 425   if (is_cae) {
 426     __ mov(result, tmp1);
 427   } else {
 428     __ cset(result, Assembler::EQ);
 429   }
 430 }
 431 
 432 #undef __
 433 
 434 #ifdef COMPILER1
 435 
 436 #define __ ce->masm()->
 437 
 438 void ShenandoahBarrierSetAssembler::gen_pre_barrier_stub(LIR_Assembler* ce, ShenandoahPreBarrierStub* stub) {
 439   ShenandoahBarrierSetC1* bs = (ShenandoahBarrierSetC1*)BarrierSet::barrier_set()->barrier_set_c1();
 440   // At this point we know that marking is in progress.
 441   // If do_load() is true then we have to emit the
 442   // load of the previous value; otherwise it has already
 443   // been loaded into _pre_val.
 444 
 445   __ bind(*stub->entry());
 446 
 447   assert(stub->pre_val()->is_register(), "Precondition.");
 448 
 449   Register pre_val_reg = stub->pre_val()->as_register();
 450 
 451   if (stub->do_load()) {
 452     ce->mem2reg(stub->addr(), stub->pre_val(), T_OBJECT, stub->patch_code(), stub->info(), false /*wide*/, false /*unaligned*/);
 453   }
 454   __ cbz(pre_val_reg, *stub->continuation());
 455   ce->store_parameter(stub->pre_val()->as_register(), 0);
 456   __ far_call(RuntimeAddress(bs->pre_barrier_c1_runtime_code_blob()->code_begin()));
 457   __ b(*stub->continuation());
 458 }
 459 
 460 void ShenandoahBarrierSetAssembler::gen_load_reference_barrier_stub(LIR_Assembler* ce, ShenandoahLoadReferenceBarrierStub* stub) {
 461 
 462   Register obj = stub->obj()->as_register();
 463   Register res = stub->result()->as_register();
 464 
 465   Label done;
 466 
 467   __ bind(*stub->entry());
 468 
 469   if (res != obj) {
 470     __ mov(res, obj);
 471   }
 472   // Check for null.
 473   __ cbz(res, done);
 474 
 475   load_reference_barrier_not_null(ce->masm(), res, rscratch1);
 476 
 477   __ bind(done);
 478   __ b(*stub->continuation());
 479 }
 480 
 481 #undef __
 482 
 483 #define __ sasm->
 484 
 485 void ShenandoahBarrierSetAssembler::generate_c1_pre_barrier_runtime_stub(StubAssembler* sasm) {
 486   __ prologue("shenandoah_pre_barrier", false);
 487 
 488   // arg0 : previous value of memory
 489 
 490   BarrierSet* bs = BarrierSet::barrier_set();
 491 
 492   const Register pre_val = r0;
 493   const Register thread = rthread;
 494   const Register tmp = rscratch1;
 495 
 496   Address queue_index(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_index_offset()));
 497   Address buffer(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset()));
 498 
 499   Label done;
 500   Label runtime;
 501 
 502   // Is marking still active?
 503   Address gc_state(thread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
 504   __ ldrb(tmp, gc_state);
 505   __ mov(rscratch2, ShenandoahHeap::MARKING | ShenandoahHeap::TRAVERSAL);
 506   __ tst(tmp, rscratch2);
 507   __ br(Assembler::EQ, done);
 508 
 509   // Can we store original value in the thread's buffer?
 510   __ ldr(tmp, queue_index);
 511   __ cbz(tmp, runtime);
 512 
 513   __ sub(tmp, tmp, wordSize);
 514   __ str(tmp, queue_index);
 515   __ ldr(rscratch2, buffer);
 516   __ add(tmp, tmp, rscratch2);
 517   __ load_parameter(0, rscratch2);
 518   __ str(rscratch2, Address(tmp, 0));
 519   __ b(done);
 520 
 521   __ bind(runtime);
 522   __ push_call_clobbered_registers();
 523   __ load_parameter(0, pre_val);
 524   __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), pre_val, thread);
 525   __ pop_call_clobbered_registers();
 526   __ bind(done);
 527 
 528   __ epilogue();
 529 }
 530 
 531 #undef __
 532 
 533 #endif // COMPILER1
 534 
 535 address ShenandoahBarrierSetAssembler::shenandoah_lrb() {
 536   assert(_shenandoah_lrb != NULL, "need load reference barrier stub");
 537   return _shenandoah_lrb;
 538 }
 539 
 540 #define __ cgen->assembler()->
 541 
 542 // Shenandoah load reference barrier.
 543 //
 544 // Input:
 545 //   r0: OOP to evacuate.  Not null.
 546 //
 547 // Output:
 548 //   r0: Pointer to evacuated OOP.
 549 //
 550 // Trash rscratch1, rscratch2.  Preserve everything else.
 551 address ShenandoahBarrierSetAssembler::generate_shenandoah_lrb(StubCodeGenerator* cgen) {
 552 
 553   __ align(6);
 554   StubCodeMark mark(cgen, "StubRoutines", "shenandoah_lrb");
 555   address start = __ pc();
 556 
 557   Label work, done;
 558   __ mov(rscratch2, ShenandoahHeap::in_cset_fast_test_addr());
 559   __ lsr(rscratch1, r0, ShenandoahHeapRegion::region_size_bytes_shift_jint());
 560   __ ldrb(rscratch2, Address(rscratch2, rscratch1));
 561   __ tbnz(rscratch2, 0, work);
 562   __ ret(lr);
 563   __ bind(work);
 564 
 565   __ mov(rscratch2, r0);
 566   resolve_forward_pointer_not_null(cgen->assembler(), r0, rscratch1);
 567   __ cmp(rscratch2, r0);
 568   __ br(Assembler::NE, done);
 569 
 570   __ enter(); // required for proper stackwalking of RuntimeStub frame
 571 
 572   __ push_call_clobbered_registers();
 573 
 574   __ mov(lr, CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier));
 575   __ blr(lr);
 576   __ mov(rscratch1, r0);
 577   __ pop_call_clobbered_registers();
 578   __ mov(r0, rscratch1);
 579 
 580   __ leave(); // required for proper stackwalking of RuntimeStub frame
 581   __ bind(done);
 582   __ ret(lr);
 583 
 584   return start;
 585 }
 586 
 587 #undef __
 588 
 589 void ShenandoahBarrierSetAssembler::barrier_stubs_init() {
 590   if (ShenandoahLoadRefBarrier) {
 591     int stub_code_size = 2048;
 592     ResourceMark rm;
 593     BufferBlob* bb = BufferBlob::create("shenandoah_barrier_stubs", stub_code_size);
 594     CodeBuffer buf(bb);
 595     StubCodeGenerator cgen(&buf);
 596     _shenandoah_lrb = generate_shenandoah_lrb(&cgen);
 597   }
 598 }