1 /*
   2  * Copyright (c) 2018, 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 && !ShenandoahHeap::heap()->heuristics()->can_do_traversal_gc()) {
  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       // Avoid calling runtime if count == 0
  94       __ cbz(count, done);
  95 
  96       // Is updating references?
  97       Address gc_state(rthread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
  98       __ ldrb(rscratch1, gc_state);
  99       __ tbz(rscratch1, ShenandoahHeap::UPDATEREFS_BITPOS, done);
 100 
 101     __ push(saved_regs, sp);
 102     assert_different_registers(start, count, scratch);
 103     assert_different_registers(c_rarg0, count);
 104     __ mov(c_rarg0, start);
 105     __ mov(c_rarg1, count);
 106     __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_array_post_entry), 2);
 107     __ pop(saved_regs, sp);
 108 
 109     __ bind(done);
 110   }
 111 }
 112 
 113 void ShenandoahBarrierSetAssembler::shenandoah_write_barrier_pre(MacroAssembler* masm,
 114                                                                  Register obj,
 115                                                                  Register pre_val,
 116                                                                  Register thread,
 117                                                                  Register tmp,
 118                                                                  bool tosca_live,
 119                                                                  bool expand_call) {
 120   if (ShenandoahSATBBarrier) {
 121     satb_write_barrier_pre(masm, obj, pre_val, thread, tmp, tosca_live, expand_call);
 122   }
 123 }
 124 
 125 void ShenandoahBarrierSetAssembler::satb_write_barrier_pre(MacroAssembler* masm,
 126                                                            Register obj,
 127                                                            Register pre_val,
 128                                                            Register thread,
 129                                                            Register tmp,
 130                                                            bool tosca_live,
 131                                                            bool expand_call) {
 132   // If expand_call is true then we expand the call_VM_leaf macro
 133   // directly to skip generating the check by
 134   // InterpreterMacroAssembler::call_VM_leaf_base that checks _last_sp.
 135 
 136   assert(thread == rthread, "must be");
 137 
 138   Label done;
 139   Label runtime;
 140 
 141   assert_different_registers(obj, pre_val, tmp, rscratch1);
 142   assert(pre_val != noreg &&  tmp != noreg, "expecting a register");
 143 
 144   Address in_progress(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_active_offset()));
 145   Address index(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_index_offset()));
 146   Address buffer(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset()));
 147 
 148   // Is marking active?
 149   if (in_bytes(SATBMarkQueue::byte_width_of_active()) == 4) {
 150     __ ldrw(tmp, in_progress);
 151   } else {
 152     assert(in_bytes(SATBMarkQueue::byte_width_of_active()) == 1, "Assumption");
 153     __ ldrb(tmp, in_progress);
 154   }
 155   __ cbzw(tmp, done);
 156 
 157   // Do we need to load the previous value?
 158   if (obj != noreg) {
 159     __ load_heap_oop(pre_val, Address(obj, 0), noreg, noreg, AS_RAW);
 160   }
 161 
 162   // Is the previous value null?
 163   __ cbz(pre_val, done);
 164 
 165   // Can we store original value in the thread's buffer?
 166   // Is index == 0?
 167   // (The index field is typed as size_t.)
 168 
 169   __ ldr(tmp, index);                      // tmp := *index_adr
 170   __ cbz(tmp, runtime);                    // tmp == 0?
 171                                         // If yes, goto runtime
 172 
 173   __ sub(tmp, tmp, wordSize);              // tmp := tmp - wordSize
 174   __ str(tmp, index);                      // *index_adr := tmp
 175   __ ldr(rscratch1, buffer);
 176   __ add(tmp, tmp, rscratch1);             // tmp := tmp + *buffer_adr
 177 
 178   // Record the previous value
 179   __ str(pre_val, Address(tmp, 0));
 180   __ b(done);
 181 
 182   __ bind(runtime);
 183   // save the live input values
 184   RegSet saved = RegSet::of(pre_val);
 185   if (tosca_live) saved += RegSet::of(r0);
 186   if (obj != noreg) saved += RegSet::of(obj);
 187 
 188   __ push(saved, sp);
 189 
 190   // Calling the runtime using the regular call_VM_leaf mechanism generates
 191   // code (generated by InterpreterMacroAssember::call_VM_leaf_base)
 192   // that checks that the *(rfp+frame::interpreter_frame_last_sp) == NULL.
 193   //
 194   // If we care generating the pre-barrier without a frame (e.g. in the
 195   // intrinsified Reference.get() routine) then ebp might be pointing to
 196   // the caller frame and so this check will most likely fail at runtime.
 197   //
 198   // Expanding the call directly bypasses the generation of the check.
 199   // So when we do not have have a full interpreter frame on the stack
 200   // expand_call should be passed true.
 201 
 202   if (expand_call) {
 203     assert(pre_val != c_rarg1, "smashed arg");
 204     __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), pre_val, thread);
 205   } else {
 206     __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), pre_val, thread);
 207   }
 208 
 209   __ pop(saved, sp);
 210 
 211   __ bind(done);
 212 }
 213 
 214 void ShenandoahBarrierSetAssembler::resolve_forward_pointer(MacroAssembler* masm, Register dst) {
 215   assert(ShenandoahLoadRefBarrier || ShenandoahCASBarrier, "Should be enabled");
 216   Label is_null;
 217   __ cbz(dst, is_null);
 218   resolve_forward_pointer_not_null(masm, dst);
 219   __ bind(is_null);
 220 }
 221 
 222 // IMPORTANT: This must preserve all registers, even rscratch1 and rscratch2.
 223 void ShenandoahBarrierSetAssembler::resolve_forward_pointer_not_null(MacroAssembler* masm, Register dst) {
 224   assert(ShenandoahLoadRefBarrier || ShenandoahCASBarrier, "Should be enabled");
 225   __ ldr(dst, Address(dst, ShenandoahForwarding::byte_offset()));
 226 }
 227 
 228 void ShenandoahBarrierSetAssembler::load_reference_barrier_not_null(MacroAssembler* masm, Register dst, Register tmp) {
 229   assert(ShenandoahLoadRefBarrier, "Should be enabled");
 230   assert(dst != rscratch2, "need rscratch2");
 231 
 232   Label done;
 233   __ enter();
 234   Address gc_state(rthread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
 235   __ ldrb(rscratch2, gc_state);
 236 
 237   // Check for heap stability
 238   __ tbz(rscratch2, ShenandoahHeap::HAS_FORWARDED_BITPOS, done);
 239 
 240   RegSet to_save = RegSet::of(r0);
 241   if (dst != r0) {
 242     __ push(to_save, sp);
 243     __ mov(r0, dst);
 244   }
 245 
 246   __ far_call(RuntimeAddress(CAST_FROM_FN_PTR(address, ShenandoahBarrierSetAssembler::shenandoah_lrb())));
 247 
 248   if (dst != r0) {
 249     __ mov(dst, r0);
 250     __ pop(to_save, sp);
 251   }
 252 
 253   __ bind(done);
 254   __ leave();
 255 }
 256 
 257 void ShenandoahBarrierSetAssembler::storeval_barrier(MacroAssembler* masm, Register dst, Register tmp) {
 258   if (ShenandoahStoreValEnqueueBarrier) {
 259     // Save possibly live regs.
 260     RegSet live_regs = RegSet::range(r0, r4) - dst;
 261     __ push(live_regs, sp);
 262     __ strd(v0, __ pre(sp, 2 * -wordSize));
 263 
 264     satb_write_barrier_pre(masm, noreg, dst, rthread, tmp, true, false);
 265 
 266     // Restore possibly live regs.
 267     __ ldrd(v0, __ post(sp, 2 * wordSize));
 268     __ pop(live_regs, sp);
 269   }
 270 }
 271 
 272 void ShenandoahBarrierSetAssembler::load_reference_barrier(MacroAssembler* masm, Register dst, Register tmp) {
 273   if (ShenandoahLoadRefBarrier) {
 274     Label is_null;
 275     __ cbz(dst, is_null);
 276     load_reference_barrier_not_null(masm, dst, tmp);
 277     __ bind(is_null);
 278   }
 279 }
 280 
 281 void ShenandoahBarrierSetAssembler::load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
 282                                             Register dst, Address src, Register tmp1, Register tmp_thread) {
 283   bool on_oop = type == T_OBJECT || type == T_ARRAY;
 284   bool on_weak = (decorators & ON_WEAK_OOP_REF) != 0;
 285   bool on_phantom = (decorators & ON_PHANTOM_OOP_REF) != 0;
 286   bool on_reference = on_weak || on_phantom;
 287 
 288   BarrierSetAssembler::load_at(masm, decorators, type, dst, src, tmp1, tmp_thread);
 289   if (on_oop) {
 290     load_reference_barrier(masm, dst, tmp1);
 291 
 292     if (ShenandoahKeepAliveBarrier && on_reference) {
 293       __ enter();
 294       satb_write_barrier_pre(masm /* masm */,
 295                              noreg /* obj */,
 296                              dst /* pre_val */,
 297                              rthread /* thread */,
 298                              tmp1 /* tmp */,
 299                              true /* tosca_live */,
 300                              true /* expand_call */);
 301       __ leave();
 302     }
 303   }
 304 }
 305 
 306 void ShenandoahBarrierSetAssembler::store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
 307                                              Address dst, Register val, Register tmp1, Register tmp2) {
 308   bool on_oop = type == T_OBJECT || type == T_ARRAY;
 309   if (!on_oop) {
 310     BarrierSetAssembler::store_at(masm, decorators, type, dst, val, tmp1, tmp2);
 311     return;
 312   }
 313 
 314   // flatten object address if needed
 315   if (dst.index() == noreg && dst.offset() == 0) {
 316     if (dst.base() != r3) {
 317       __ mov(r3, dst.base());
 318     }
 319   } else {
 320     __ lea(r3, dst);
 321   }
 322 
 323   shenandoah_write_barrier_pre(masm,
 324                                r3 /* obj */,
 325                                tmp2 /* pre_val */,
 326                                rthread /* thread */,
 327                                tmp1  /* tmp */,
 328                                val != noreg /* tosca_live */,
 329                                false /* expand_call */);
 330 
 331   if (val == noreg) {
 332     BarrierSetAssembler::store_at(masm, decorators, type, Address(r3, 0), noreg, noreg, noreg);
 333   } else {
 334     storeval_barrier(masm, val, tmp1);
 335     // G1 barrier needs uncompressed oop for region cross check.
 336     Register new_val = val;
 337     if (UseCompressedOops) {
 338       new_val = rscratch2;
 339       __ mov(new_val, val);
 340     }
 341     BarrierSetAssembler::store_at(masm, decorators, type, Address(r3, 0), val, noreg, noreg);
 342   }
 343 
 344 }
 345 
 346 void ShenandoahBarrierSetAssembler::tlab_allocate(MacroAssembler* masm, Register obj,
 347                                                   Register var_size_in_bytes,
 348                                                   int con_size_in_bytes,
 349                                                   Register t1,
 350                                                   Register t2,
 351                                                   Label& slow_case) {
 352 
 353   assert_different_registers(obj, t2);
 354   assert_different_registers(obj, var_size_in_bytes);
 355   Register end = t2;
 356 
 357   __ ldr(obj, Address(rthread, JavaThread::tlab_top_offset()));
 358   if (var_size_in_bytes == noreg) {
 359     __ lea(end, Address(obj, (int) (con_size_in_bytes + ShenandoahForwarding::byte_size())));
 360   } else {
 361     __ add(var_size_in_bytes, var_size_in_bytes, ShenandoahForwarding::byte_size());
 362     __ lea(end, Address(obj, var_size_in_bytes));
 363   }
 364   __ ldr(rscratch1, Address(rthread, JavaThread::tlab_end_offset()));
 365   __ cmp(end, rscratch1);
 366   __ br(Assembler::HI, slow_case);
 367 
 368   // update the tlab top pointer
 369   __ str(end, Address(rthread, JavaThread::tlab_top_offset()));
 370 
 371   __ add(obj, obj, ShenandoahForwarding::byte_size());
 372   __ str(obj, Address(obj, ShenandoahForwarding::byte_offset()));
 373 
 374   // recover var_size_in_bytes if necessary
 375   if (var_size_in_bytes == end) {
 376     __ sub(var_size_in_bytes, var_size_in_bytes, obj);
 377   }
 378 }
 379 
 380 void ShenandoahBarrierSetAssembler::cmpxchg_oop(MacroAssembler* masm, Register addr, Register expected, Register new_val,
 381                                                 bool acquire, bool release, bool weak, bool is_cae,
 382                                                 Register result) {
 383   Register tmp1 = rscratch1;
 384   Register tmp2 = rscratch2;
 385   bool is_narrow = UseCompressedOops;
 386   Assembler::operand_size size = is_narrow ? Assembler::word : Assembler::xword;
 387 
 388   assert_different_registers(addr, expected, new_val, tmp1, tmp2);
 389 
 390   Label retry, done, fail;
 391 
 392   // CAS, using LL/SC pair.
 393   __ bind(retry);
 394   __ load_exclusive(tmp1, addr, size, acquire);
 395   if (is_narrow) {
 396     __ cmpw(tmp1, expected);
 397   } else {
 398     __ cmp(tmp1, expected);
 399   }
 400   __ br(Assembler::NE, fail);
 401   __ store_exclusive(tmp2, new_val, addr, size, release);
 402   if (weak) {
 403     __ cmpw(tmp2, 0u); // If the store fails, return NE to our caller
 404   } else {
 405     __ cbnzw(tmp2, retry);
 406   }
 407   __ b(done);
 408 
 409  __  bind(fail);
 410   // Check if rb(expected)==rb(tmp1)
 411   // Shuffle registers so that we have memory value ready for next expected.
 412   __ mov(tmp2, expected);
 413   __ mov(expected, tmp1);
 414   if (is_narrow) {
 415     __ decode_heap_oop(tmp1, tmp1);
 416     __ decode_heap_oop(tmp2, tmp2);
 417   }
 418   resolve_forward_pointer(masm, tmp1);
 419   resolve_forward_pointer(masm, tmp2);
 420   __ cmp(tmp1, tmp2);
 421   // Retry with expected now being the value we just loaded from addr.
 422   __ br(Assembler::EQ, retry);
 423   if (is_cae && is_narrow) {
 424     // For cmp-and-exchange and narrow oops, we need to restore
 425     // the compressed old-value. We moved it to 'expected' a few lines up.
 426     __ mov(tmp1, expected);
 427   }
 428   __ bind(done);
 429 
 430   if (is_cae) {
 431     __ mov(result, tmp1);
 432   } else {
 433     __ cset(result, Assembler::EQ);
 434   }
 435 }
 436 
 437 #ifdef COMPILER1
 438 
 439 #undef __
 440 #define __ ce->masm()->
 441 
 442 void ShenandoahBarrierSetAssembler::gen_pre_barrier_stub(LIR_Assembler* ce, ShenandoahPreBarrierStub* stub) {
 443   ShenandoahBarrierSetC1* bs = (ShenandoahBarrierSetC1*)BarrierSet::barrier_set()->barrier_set_c1();
 444   // At this point we know that marking is in progress.
 445   // If do_load() is true then we have to emit the
 446   // load of the previous value; otherwise it has already
 447   // been loaded into _pre_val.
 448 
 449   __ bind(*stub->entry());
 450 
 451   assert(stub->pre_val()->is_register(), "Precondition.");
 452 
 453   Register pre_val_reg = stub->pre_val()->as_register();
 454 
 455   if (stub->do_load()) {
 456     ce->mem2reg(stub->addr(), stub->pre_val(), T_OBJECT, stub->patch_code(), stub->info(), false /*wide*/, false /*unaligned*/);
 457   }
 458   __ cbz(pre_val_reg, *stub->continuation());
 459   ce->store_parameter(stub->pre_val()->as_register(), 0);
 460   __ far_call(RuntimeAddress(bs->pre_barrier_c1_runtime_code_blob()->code_begin()));
 461   __ b(*stub->continuation());
 462 }
 463 
 464 void ShenandoahBarrierSetAssembler::gen_load_reference_barrier_stub(LIR_Assembler* ce, ShenandoahLoadReferenceBarrierStub* stub) {
 465 
 466   Register obj = stub->obj()->as_register();
 467   Register res = stub->result()->as_register();
 468 
 469   Label done;
 470 
 471   __ bind(*stub->entry());
 472 
 473   if (res != obj) {
 474     __ mov(res, obj);
 475   }
 476   // Check for null.
 477   if (stub->needs_null_check()) {
 478     __ cbz(res, done);
 479   }
 480 
 481   load_reference_barrier_not_null(ce->masm(), res, rscratch1);
 482 
 483   __ bind(done);
 484   __ b(*stub->continuation());
 485 }
 486 
 487 #undef __
 488 
 489 #define __ sasm->
 490 
 491 void ShenandoahBarrierSetAssembler::generate_c1_pre_barrier_runtime_stub(StubAssembler* sasm) {
 492   __ prologue("shenandoah_pre_barrier", false);
 493 
 494   // arg0 : previous value of memory
 495 
 496   BarrierSet* bs = BarrierSet::barrier_set();
 497 
 498   const Register pre_val = r0;
 499   const Register thread = rthread;
 500   const Register tmp = rscratch1;
 501 
 502   Address queue_index(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_index_offset()));
 503   Address buffer(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset()));
 504 
 505   Label done;
 506   Label runtime;
 507 
 508   // Is marking still active?
 509   Address gc_state(thread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
 510   __ ldrb(tmp, gc_state);
 511   __ mov(rscratch2, ShenandoahHeap::MARKING | ShenandoahHeap::TRAVERSAL);
 512   __ tst(tmp, rscratch2);
 513   __ br(Assembler::EQ, done);
 514 
 515   // Can we store original value in the thread's buffer?
 516   __ ldr(tmp, queue_index);
 517   __ cbz(tmp, runtime);
 518 
 519   __ sub(tmp, tmp, wordSize);
 520   __ str(tmp, queue_index);
 521   __ ldr(rscratch2, buffer);
 522   __ add(tmp, tmp, rscratch2);
 523   __ load_parameter(0, rscratch2);
 524   __ str(rscratch2, Address(tmp, 0));
 525   __ b(done);
 526 
 527   __ bind(runtime);
 528   __ push_call_clobbered_registers();
 529   __ load_parameter(0, pre_val);
 530   __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), pre_val, thread);
 531   __ pop_call_clobbered_registers();
 532   __ bind(done);
 533 
 534   __ epilogue();
 535 }
 536 
 537 #undef __
 538 
 539 #endif // COMPILER1
 540 
 541 address ShenandoahBarrierSetAssembler::shenandoah_lrb() {
 542   assert(_shenandoah_lrb != NULL, "need load reference barrier stub");
 543   return _shenandoah_lrb;
 544 }
 545 
 546 #define __ cgen->assembler()->
 547 
 548 // Shenandoah load reference barrier.
 549 //
 550 // Input:
 551 //   r0: OOP to evacuate.  Not null.
 552 //
 553 // Output:
 554 //   r0: Pointer to evacuated OOP.
 555 //
 556 // Trash rscratch1, rscratch2.  Preserve everything else.
 557 address ShenandoahBarrierSetAssembler::generate_shenandoah_lrb(StubCodeGenerator* cgen) {
 558 
 559   __ align(6);
 560   StubCodeMark mark(cgen, "StubRoutines", "shenandoah_lrb");
 561   address start = __ pc();
 562 
 563   Label work, done;
 564   __ mov(rscratch2, ShenandoahHeap::in_cset_fast_test_addr());
 565   __ lsr(rscratch1, r0, ShenandoahHeapRegion::region_size_bytes_shift_jint());
 566   __ ldrb(rscratch2, Address(rscratch2, rscratch1));
 567   __ tbnz(rscratch2, 0, work);
 568   __ ret(lr);
 569   __ bind(work);
 570 
 571   __ mov(rscratch2, r0);
 572   resolve_forward_pointer_not_null(cgen->assembler(), r0);
 573   __ cmp(rscratch2, r0);
 574   __ br(Assembler::NE, done);
 575 
 576   __ enter(); // required for proper stackwalking of RuntimeStub frame
 577 
 578   __ push_call_clobbered_registers();
 579 
 580   __ mov(lr, CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_JRT));
 581   __ blrt(lr, 1, 0, MacroAssembler::ret_type_integral);
 582   __ mov(rscratch1, r0);
 583   __ pop_call_clobbered_registers();
 584   __ mov(r0, rscratch1);
 585 
 586   __ leave(); // required for proper stackwalking of RuntimeStub frame
 587   __ bind(done);
 588   __ ret(lr);
 589 
 590   return start;
 591 }
 592 
 593 #undef __
 594 
 595 void ShenandoahBarrierSetAssembler::barrier_stubs_init() {
 596   if (ShenandoahLoadRefBarrier) {
 597     int stub_code_size = 2048;
 598     ResourceMark rm;
 599     BufferBlob* bb = BufferBlob::create("shenandoah_barrier_stubs", stub_code_size);
 600     CodeBuffer buf(bb);
 601     StubCodeGenerator cgen(&buf);
 602     _shenandoah_lrb = generate_shenandoah_lrb(&cgen);
 603   }
 604 }