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 src, Register dst, Register count, RegSet saved_regs) {
  48   if (is_oop) {
  49     bool dest_uninitialized = (decorators & IS_DEST_UNINITIALIZED) != 0;
  50     if ((ShenandoahSATBBarrier && !dest_uninitialized) || ShenandoahLoadRefBarrier) {
  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       if (dest_uninitialized) {
  61         __ tbz(rscratch1, ShenandoahHeap::HAS_FORWARDED_BITPOS, done);
  62       } else {
  63         __ mov(rscratch2, ShenandoahHeap::HAS_FORWARDED | ShenandoahHeap::MARKING);
  64         __ tst(rscratch1, rscratch2);
  65         __ br(Assembler::EQ, done);
  66       }
  67 
  68       __ push(saved_regs, sp);
  69       if (UseCompressedOops) {
  70         if (dest_uninitialized) {
  71           __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_array_pre_duinit_narrow_oop_entry), src, dst, count);
  72         } else {
  73           __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_array_pre_narrow_oop_entry), src, dst, count);
  74         }
  75       } else {
  76         if (dest_uninitialized) {
  77           __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_array_pre_duinit_oop_entry), src, dst, count);
  78         } else {
  79           __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_array_pre_oop_entry), src, dst, count);
  80         }
  81       }
  82       __ pop(saved_regs, sp);
  83       __ bind(done);
  84     }
  85   }
  86 }
  87 
  88 void ShenandoahBarrierSetAssembler::shenandoah_write_barrier_pre(MacroAssembler* masm,
  89                                                                  Register obj,
  90                                                                  Register pre_val,
  91                                                                  Register thread,
  92                                                                  Register tmp,
  93                                                                  bool tosca_live,
  94                                                                  bool expand_call) {
  95   if (ShenandoahSATBBarrier) {
  96     satb_write_barrier_pre(masm, obj, pre_val, thread, tmp, tosca_live, expand_call);
  97   }
  98 }
  99 
 100 void ShenandoahBarrierSetAssembler::satb_write_barrier_pre(MacroAssembler* masm,
 101                                                            Register obj,
 102                                                            Register pre_val,
 103                                                            Register thread,
 104                                                            Register tmp,
 105                                                            bool tosca_live,
 106                                                            bool expand_call) {
 107   // If expand_call is true then we expand the call_VM_leaf macro
 108   // directly to skip generating the check by
 109   // InterpreterMacroAssembler::call_VM_leaf_base that checks _last_sp.
 110 
 111   assert(thread == rthread, "must be");
 112 
 113   Label done;
 114   Label runtime;
 115 
 116   assert_different_registers(obj, pre_val, tmp, rscratch1);
 117   assert(pre_val != noreg &&  tmp != noreg, "expecting a register");
 118 
 119   Address in_progress(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_active_offset()));
 120   Address index(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_index_offset()));
 121   Address buffer(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset()));
 122 
 123   // Is marking active?
 124   if (in_bytes(ShenandoahSATBMarkQueue::byte_width_of_active()) == 4) {
 125     __ ldrw(tmp, in_progress);
 126   } else {
 127     assert(in_bytes(ShenandoahSATBMarkQueue::byte_width_of_active()) == 1, "Assumption");
 128     __ ldrb(tmp, in_progress);
 129   }
 130   __ cbzw(tmp, done);
 131 
 132   // Do we need to load the previous value?
 133   if (obj != noreg) {
 134     __ load_heap_oop(pre_val, Address(obj, 0), noreg, noreg, AS_RAW);
 135   }
 136 
 137   // Is the previous value null?
 138   __ cbz(pre_val, done);
 139 
 140   // Can we store original value in the thread's buffer?
 141   // Is index == 0?
 142   // (The index field is typed as size_t.)
 143 
 144   __ ldr(tmp, index);                      // tmp := *index_adr
 145   __ cbz(tmp, runtime);                    // tmp == 0?
 146                                         // If yes, goto runtime
 147 
 148   __ sub(tmp, tmp, wordSize);              // tmp := tmp - wordSize
 149   __ str(tmp, index);                      // *index_adr := tmp
 150   __ ldr(rscratch1, buffer);
 151   __ add(tmp, tmp, rscratch1);             // tmp := tmp + *buffer_adr
 152 
 153   // Record the previous value
 154   __ str(pre_val, Address(tmp, 0));
 155   __ b(done);
 156 
 157   __ bind(runtime);
 158   // save the live input values
 159   RegSet saved = RegSet::of(pre_val);
 160   if (tosca_live) saved += RegSet::of(r0);
 161   if (obj != noreg) saved += RegSet::of(obj);
 162 
 163   __ push(saved, sp);
 164 
 165   // Calling the runtime using the regular call_VM_leaf mechanism generates
 166   // code (generated by InterpreterMacroAssember::call_VM_leaf_base)
 167   // that checks that the *(rfp+frame::interpreter_frame_last_sp) == NULL.
 168   //
 169   // If we care generating the pre-barrier without a frame (e.g. in the
 170   // intrinsified Reference.get() routine) then ebp might be pointing to
 171   // the caller frame and so this check will most likely fail at runtime.
 172   //
 173   // Expanding the call directly bypasses the generation of the check.
 174   // So when we do not have have a full interpreter frame on the stack
 175   // expand_call should be passed true.
 176 
 177   if (expand_call) {
 178     assert(pre_val != c_rarg1, "smashed arg");
 179     __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), pre_val, thread);
 180   } else {
 181     __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), pre_val, thread);
 182   }
 183 
 184   __ pop(saved, sp);
 185 
 186   __ bind(done);
 187 }
 188 
 189 void ShenandoahBarrierSetAssembler::resolve_forward_pointer(MacroAssembler* masm, Register dst, Register tmp) {
 190   assert(ShenandoahLoadRefBarrier || ShenandoahCASBarrier, "Should be enabled");
 191   Label is_null;
 192   __ cbz(dst, is_null);
 193   resolve_forward_pointer_not_null(masm, dst, tmp);
 194   __ bind(is_null);
 195 }
 196 
 197 // IMPORTANT: This must preserve all registers, even rscratch1 and rscratch2, except those explicitely
 198 // passed in.
 199 void ShenandoahBarrierSetAssembler::resolve_forward_pointer_not_null(MacroAssembler* masm, Register dst, Register tmp) {
 200   assert(ShenandoahLoadRefBarrier || ShenandoahCASBarrier, "Should be enabled");
 201   // The below loads the mark word, checks if the lowest two bits are
 202   // set, and if so, clear the lowest two bits and copy the result
 203   // to dst. Otherwise it leaves dst alone.
 204   // Implementing this is surprisingly awkward. I do it here by:
 205   // - Inverting the mark word
 206   // - Test lowest two bits == 0
 207   // - If so, set the lowest two bits
 208   // - Invert the result back, and copy to dst
 209 
 210   bool borrow_reg = (tmp == noreg);
 211   if (borrow_reg) {
 212     // No free registers available. Make one useful.
 213     tmp = rscratch1;
 214     if (tmp == dst) {
 215       tmp = rscratch2;
 216     }
 217     __ push(RegSet::of(tmp), sp);
 218   }
 219 
 220   assert_different_registers(tmp, dst);
 221 
 222   Label done;
 223   __ ldr(tmp, Address(dst, oopDesc::mark_offset_in_bytes()));
 224   __ eon(tmp, tmp, zr);
 225   __ ands(zr, tmp, markOopDesc::lock_mask_in_place);
 226   __ br(Assembler::NE, done);
 227   __ orr(tmp, tmp, markOopDesc::marked_value);
 228   __ eon(dst, tmp, zr);
 229   __ bind(done);
 230 
 231   if (borrow_reg) {
 232     __ pop(RegSet::of(tmp), sp);
 233   }
 234 }
 235 
 236 void ShenandoahBarrierSetAssembler::load_reference_barrier_not_null(MacroAssembler* masm, Register dst, Address load_addr) {
 237   assert(ShenandoahLoadRefBarrier, "Should be enabled");
 238   assert(dst != rscratch2, "need rscratch2");
 239   assert_different_registers(load_addr.base(), load_addr.index(), rscratch1, rscratch2);
 240 
 241   Label done;
 242   __ enter();
 243   Address gc_state(rthread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
 244   __ ldrb(rscratch2, gc_state);
 245 
 246   // Check for heap stability
 247   __ tbz(rscratch2, ShenandoahHeap::HAS_FORWARDED_BITPOS, done);
 248 
 249   // use r1 for load address
 250   Register result_dst = dst;
 251   if (dst == r1) {
 252     __ mov(rscratch1, dst);
 253     dst = rscratch1;
 254   }
 255 
 256   // Save r0 and r1, unless it is an output register
 257   RegSet to_save = RegSet::of(r0, r1) - result_dst;
 258   __ push(to_save, sp);
 259   __ lea(r1, load_addr);
 260   __ mov(r0, dst);
 261 
 262   __ far_call(RuntimeAddress(CAST_FROM_FN_PTR(address, ShenandoahBarrierSetAssembler::shenandoah_lrb())));
 263 
 264   __ mov(result_dst, r0);
 265   __ pop(to_save, sp);
 266 
 267   __ bind(done);
 268   __ leave();
 269 }
 270 
 271 void ShenandoahBarrierSetAssembler::storeval_barrier(MacroAssembler* masm, Register dst, Register tmp) {
 272   if (ShenandoahStoreValEnqueueBarrier) {
 273     // Save possibly live regs.
 274     RegSet live_regs = RegSet::range(r0, r4) - dst;
 275     __ push(live_regs, sp);
 276     __ strd(v0, __ pre(sp, 2 * -wordSize));
 277 
 278     satb_write_barrier_pre(masm, noreg, dst, rthread, tmp, true, false);
 279 
 280     // Restore possibly live regs.
 281     __ ldrd(v0, __ post(sp, 2 * wordSize));
 282     __ pop(live_regs, sp);
 283   }
 284 }
 285 
 286 void ShenandoahBarrierSetAssembler::load_reference_barrier(MacroAssembler* masm, Register dst, Address load_addr) {
 287   if (ShenandoahLoadRefBarrier) {
 288     Label is_null;
 289     __ cbz(dst, is_null);
 290     load_reference_barrier_not_null(masm, dst, load_addr);
 291     __ bind(is_null);
 292   }
 293 }
 294 
 295 void ShenandoahBarrierSetAssembler::load_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
 296                                             Register dst, Address src, Register tmp1, Register tmp_thread) {
 297   // 1: non-reference load, no additional barrier is needed
 298   if (!is_reference_type(type)) {
 299     BarrierSetAssembler::load_at(masm, decorators, type, dst, src, tmp1, tmp_thread);
 300     return;
 301   }
 302 
 303   // 2: load a reference from src location and apply LRB if needed
 304   if (ShenandoahBarrierSet::need_load_reference_barrier(decorators, type)) {
 305     Register result_dst = dst;
 306 
 307     // Preserve src location for LRB
 308     if (dst == src.base() || dst == src.index()) {
 309       dst = rscratch1;
 310     }
 311     assert_different_registers(dst, src.base(), src.index());
 312 
 313     BarrierSetAssembler::load_at(masm, decorators, type, dst, src, tmp1, tmp_thread);
 314 
 315     load_reference_barrier(masm, dst, src);
 316 
 317     if (dst != result_dst) {
 318       __ mov(result_dst, dst);
 319       dst = result_dst;
 320     }
 321   } else {
 322     BarrierSetAssembler::load_at(masm, decorators, type, dst, src, tmp1, tmp_thread);
 323   }
 324 
 325   // 3: apply keep-alive barrier if needed
 326   if (ShenandoahBarrierSet::need_keep_alive_barrier(decorators, type)) {
 327     __ enter();
 328     satb_write_barrier_pre(masm /* masm */,
 329                            noreg /* obj */,
 330                            dst /* pre_val */,
 331                            rthread /* thread */,
 332                            tmp1 /* tmp */,
 333                            true /* tosca_live */,
 334                            true /* expand_call */);
 335     __ leave();
 336   }
 337 }
 338 
 339 void ShenandoahBarrierSetAssembler::store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
 340                                              Address dst, Register val, Register tmp1, Register tmp2) {
 341   bool on_oop = type == T_OBJECT || type == T_ARRAY;
 342   if (!on_oop) {
 343     BarrierSetAssembler::store_at(masm, decorators, type, dst, val, tmp1, tmp2);
 344     return;
 345   }
 346 
 347   // flatten object address if needed
 348   if (dst.index() == noreg && dst.offset() == 0) {
 349     if (dst.base() != r3) {
 350       __ mov(r3, dst.base());
 351     }
 352   } else {
 353     __ lea(r3, dst);
 354   }
 355 
 356   shenandoah_write_barrier_pre(masm,
 357                                r3 /* obj */,
 358                                tmp2 /* pre_val */,
 359                                rthread /* thread */,
 360                                tmp1  /* tmp */,
 361                                val != noreg /* tosca_live */,
 362                                false /* expand_call */);
 363 
 364   if (val == noreg) {
 365     BarrierSetAssembler::store_at(masm, decorators, type, Address(r3, 0), noreg, noreg, noreg);
 366   } else {
 367     storeval_barrier(masm, val, tmp1);
 368     // G1 barrier needs uncompressed oop for region cross check.
 369     Register new_val = val;
 370     if (UseCompressedOops) {
 371       new_val = rscratch2;
 372       __ mov(new_val, val);
 373     }
 374     BarrierSetAssembler::store_at(masm, decorators, type, Address(r3, 0), val, noreg, noreg);
 375   }
 376 
 377 }
 378 
 379 void ShenandoahBarrierSetAssembler::try_resolve_jobject_in_native(MacroAssembler* masm, Register jni_env,
 380                                                                   Register obj, Register tmp, Label& slowpath) {
 381   Label done;
 382   // Resolve jobject
 383   BarrierSetAssembler::try_resolve_jobject_in_native(masm, jni_env, obj, tmp, slowpath);
 384 
 385   // Check for null.
 386   __ cbz(obj, done);
 387 
 388   assert(obj != rscratch2, "need rscratch2");
 389   Address gc_state(jni_env, ShenandoahThreadLocalData::gc_state_offset() - JavaThread::jni_environment_offset());
 390   __ lea(rscratch2, gc_state);
 391   __ ldrb(rscratch2, Address(rscratch2));
 392 
 393   // Check for heap in evacuation phase
 394   __ tbnz(rscratch2, ShenandoahHeap::EVACUATION_BITPOS, slowpath);
 395 
 396   __ bind(done);
 397 }
 398 
 399 
 400 void ShenandoahBarrierSetAssembler::cmpxchg_oop(MacroAssembler* masm, Register addr, Register expected, Register new_val,
 401                                                 bool acquire, bool release, bool weak, bool is_cae,
 402                                                 Register result) {
 403   Register tmp1 = rscratch1;
 404   Register tmp2 = rscratch2;
 405   bool is_narrow = UseCompressedOops;
 406   Assembler::operand_size size = is_narrow ? Assembler::word : Assembler::xword;
 407 
 408   assert_different_registers(addr, expected, new_val, tmp1, tmp2);
 409 
 410   Label retry, done, fail;
 411 
 412   // CAS, using LL/SC pair.
 413   __ bind(retry);
 414   __ load_exclusive(tmp1, addr, size, acquire);
 415   if (is_narrow) {
 416     __ cmpw(tmp1, expected);
 417   } else {
 418     __ cmp(tmp1, expected);
 419   }
 420   __ br(Assembler::NE, fail);
 421   __ store_exclusive(tmp2, new_val, addr, size, release);
 422   if (weak) {
 423     __ cmpw(tmp2, 0u); // If the store fails, return NE to our caller
 424   } else {
 425     __ cbnzw(tmp2, retry);
 426   }
 427   __ b(done);
 428 
 429  __  bind(fail);
 430   // Check if rb(expected)==rb(tmp1)
 431   // Shuffle registers so that we have memory value ready for next expected.
 432   __ mov(tmp2, expected);
 433   __ mov(expected, tmp1);
 434   if (is_narrow) {
 435     __ decode_heap_oop(tmp1, tmp1);
 436     __ decode_heap_oop(tmp2, tmp2);
 437   }
 438   resolve_forward_pointer(masm, tmp1);
 439   resolve_forward_pointer(masm, tmp2);
 440   __ cmp(tmp1, tmp2);
 441   // Retry with expected now being the value we just loaded from addr.
 442   __ br(Assembler::EQ, retry);
 443   if (is_cae && is_narrow) {
 444     // For cmp-and-exchange and narrow oops, we need to restore
 445     // the compressed old-value. We moved it to 'expected' a few lines up.
 446     __ mov(tmp1, expected);
 447   }
 448   __ bind(done);
 449 
 450   if (is_cae) {
 451     __ mov(result, tmp1);
 452   } else {
 453     __ cset(result, Assembler::EQ);
 454   }
 455 }
 456 
 457 #undef __
 458 
 459 #ifdef COMPILER1
 460 
 461 #define __ ce->masm()->
 462 
 463 void ShenandoahBarrierSetAssembler::gen_pre_barrier_stub(LIR_Assembler* ce, ShenandoahPreBarrierStub* stub) {
 464   ShenandoahBarrierSetC1* bs = (ShenandoahBarrierSetC1*)BarrierSet::barrier_set()->barrier_set_c1();
 465   // At this point we know that marking is in progress.
 466   // If do_load() is true then we have to emit the
 467   // load of the previous value; otherwise it has already
 468   // been loaded into _pre_val.
 469 
 470   __ bind(*stub->entry());
 471 
 472   assert(stub->pre_val()->is_register(), "Precondition.");
 473 
 474   Register pre_val_reg = stub->pre_val()->as_register();
 475 
 476   if (stub->do_load()) {
 477     ce->mem2reg(stub->addr(), stub->pre_val(), T_OBJECT, stub->patch_code(), stub->info(), false /*wide*/, false /*unaligned*/);
 478   }
 479   __ cbz(pre_val_reg, *stub->continuation());
 480   ce->store_parameter(stub->pre_val()->as_register(), 0);
 481   __ far_call(RuntimeAddress(bs->pre_barrier_c1_runtime_code_blob()->code_begin()));
 482   __ b(*stub->continuation());
 483 }
 484 
 485 void ShenandoahBarrierSetAssembler::gen_load_reference_barrier_stub(LIR_Assembler* ce, ShenandoahLoadReferenceBarrierStub* stub) {
 486   ShenandoahBarrierSetC1* bs = (ShenandoahBarrierSetC1*)BarrierSet::barrier_set()->barrier_set_c1();
 487   __ bind(*stub->entry());
 488 
 489   Register obj = stub->obj()->as_register();
 490   Register res = stub->result()->as_register();
 491   Register addr = stub->addr()->as_pointer_register();
 492   Register tmp1 = stub->tmp1()->as_register();
 493   Register tmp2 = stub->tmp2()->as_register();
 494 
 495   assert(res == r0, "result must arrive in r0");
 496 
 497   if (res != obj) {
 498     __ mov(res, obj);
 499   }
 500 
 501   // Check for null.
 502   __ cbz(res, *stub->continuation());
 503 
 504   // Check for object in cset.
 505   __ mov(tmp2, ShenandoahHeap::in_cset_fast_test_addr());
 506   __ lsr(tmp1, res, ShenandoahHeapRegion::region_size_bytes_shift_jint());
 507   __ ldrb(tmp2, Address(tmp2, tmp1));
 508   __ cbz(tmp2, *stub->continuation());
 509 
 510   // Check if object is already forwarded.
 511   Label slow_path;
 512   __ ldr(tmp1, Address(res, oopDesc::mark_offset_in_bytes()));
 513   __ eon(tmp1, tmp1, zr);
 514   __ ands(zr, tmp1, markOopDesc::lock_mask_in_place);
 515   __ br(Assembler::NE, slow_path);
 516 
 517   // Decode forwarded object.
 518   __ orr(tmp1, tmp1, markOopDesc::marked_value);
 519   __ eon(res, tmp1, zr);
 520   __ b(*stub->continuation());
 521 
 522   __ bind(slow_path);
 523   ce->store_parameter(res, 0);
 524   ce->store_parameter(addr, 1);
 525   __ far_call(RuntimeAddress(bs->load_reference_barrier_rt_code_blob()->code_begin()));
 526 
 527   __ b(*stub->continuation());
 528 }
 529 
 530 #undef __
 531 
 532 #define __ sasm->
 533 
 534 void ShenandoahBarrierSetAssembler::generate_c1_pre_barrier_runtime_stub(StubAssembler* sasm) {
 535   __ prologue("shenandoah_pre_barrier", false);
 536 
 537   // arg0 : previous value of memory
 538 
 539   BarrierSet* bs = BarrierSet::barrier_set();
 540 
 541   const Register pre_val = r0;
 542   const Register thread = rthread;
 543   const Register tmp = rscratch1;
 544 
 545   Address queue_index(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_index_offset()));
 546   Address buffer(thread, in_bytes(ShenandoahThreadLocalData::satb_mark_queue_buffer_offset()));
 547 
 548   Label done;
 549   Label runtime;
 550 
 551   // Is marking still active?
 552   Address gc_state(thread, in_bytes(ShenandoahThreadLocalData::gc_state_offset()));
 553   __ ldrb(tmp, gc_state);
 554   __ mov(rscratch2, ShenandoahHeap::MARKING | ShenandoahHeap::TRAVERSAL);
 555   __ tst(tmp, rscratch2);
 556   __ br(Assembler::EQ, done);
 557 
 558   // Can we store original value in the thread's buffer?
 559   __ ldr(tmp, queue_index);
 560   __ cbz(tmp, runtime);
 561 
 562   __ sub(tmp, tmp, wordSize);
 563   __ str(tmp, queue_index);
 564   __ ldr(rscratch2, buffer);
 565   __ add(tmp, tmp, rscratch2);
 566   __ load_parameter(0, rscratch2);
 567   __ str(rscratch2, Address(tmp, 0));
 568   __ b(done);
 569 
 570   __ bind(runtime);
 571   __ push_call_clobbered_registers();
 572   __ load_parameter(0, pre_val);
 573   __ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), pre_val, thread);
 574   __ pop_call_clobbered_registers();
 575   __ bind(done);
 576 
 577   __ epilogue();
 578 }
 579 
 580 void ShenandoahBarrierSetAssembler::generate_c1_load_reference_barrier_runtime_stub(StubAssembler* sasm) {
 581   __ prologue("shenandoah_load_reference_barrier", false);
 582   // arg0 : object to be resolved
 583 
 584   __ push_call_clobbered_registers();
 585   __ load_parameter(0, r0);
 586   __ load_parameter(1, r1);
 587   if (UseCompressedOops) {
 588     __ mov(lr, CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_narrow));
 589   } else {
 590     __ mov(lr, CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier));
 591   }
 592   __ blr(lr);
 593   __ mov(rscratch1, r0);
 594   __ pop_call_clobbered_registers();
 595   __ mov(r0, rscratch1);
 596 
 597   __ epilogue();
 598 }
 599 
 600 #undef __
 601 
 602 #endif // COMPILER1
 603 
 604 address ShenandoahBarrierSetAssembler::shenandoah_lrb() {
 605   assert(_shenandoah_lrb != NULL, "need load reference barrier stub");
 606   return _shenandoah_lrb;
 607 }
 608 
 609 #define __ cgen->assembler()->
 610 
 611 // Shenandoah load reference barrier.
 612 //
 613 // Input:
 614 //   r0: OOP to evacuate.  Not null.
 615 //   r1: load address
 616 //
 617 // Output:
 618 //   r0: Pointer to evacuated OOP.
 619 //
 620 // Trash rscratch1, rscratch2.  Preserve everything else.
 621 address ShenandoahBarrierSetAssembler::generate_shenandoah_lrb(StubCodeGenerator* cgen) {
 622 
 623   __ align(6);
 624   StubCodeMark mark(cgen, "StubRoutines", "shenandoah_lrb");
 625   address start = __ pc();
 626 
 627   Label work, done;
 628   __ mov(rscratch2, ShenandoahHeap::in_cset_fast_test_addr());
 629   __ lsr(rscratch1, r0, ShenandoahHeapRegion::region_size_bytes_shift_jint());
 630   __ ldrb(rscratch2, Address(rscratch2, rscratch1));
 631   __ tbnz(rscratch2, 0, work);
 632   __ ret(lr);
 633   __ bind(work);
 634 
 635   Label slow_path;
 636   __ ldr(rscratch1, Address(r0, oopDesc::mark_offset_in_bytes()));
 637   __ eon(rscratch1, rscratch1, zr);
 638   __ ands(zr, rscratch1, markOopDesc::lock_mask_in_place);
 639   __ br(Assembler::NE, slow_path);
 640 
 641   // Decode forwarded object.
 642   __ orr(rscratch1, rscratch1, markOopDesc::marked_value);
 643   __ eon(r0, rscratch1, zr);
 644   __ ret(lr);
 645 
 646   __ bind(slow_path);
 647   __ enter(); // required for proper stackwalking of RuntimeStub frame
 648 
 649   __ push_call_clobbered_registers();
 650 
 651   if (UseCompressedOops) {
 652     __ mov(lr, CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier_narrow));
 653   } else {
 654     __ mov(lr, CAST_FROM_FN_PTR(address, ShenandoahRuntime::load_reference_barrier));
 655   }
 656   __ blr(lr);
 657   __ mov(rscratch1, r0);
 658   __ pop_call_clobbered_registers();
 659   __ mov(r0, rscratch1);
 660 
 661   __ leave(); // required for proper stackwalking of RuntimeStub frame
 662   __ bind(done);
 663   __ ret(lr);
 664 
 665   return start;
 666 }
 667 
 668 #undef __
 669 
 670 void ShenandoahBarrierSetAssembler::barrier_stubs_init() {
 671   if (ShenandoahLoadRefBarrier) {
 672     int stub_code_size = 2048;
 673     ResourceMark rm;
 674     BufferBlob* bb = BufferBlob::create("shenandoah_barrier_stubs", stub_code_size);
 675     CodeBuffer buf(bb);
 676     StubCodeGenerator cgen(&buf);
 677     _shenandoah_lrb = generate_shenandoah_lrb(&cgen);
 678   }
 679 }