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