void G1UnsafeGetObjSATBBarrierStub::emit_code(LIR_Assembler* ce) {
    // At this point we know that offset == referent_offset.
    //
    // So we might have to emit:
    //   if (src == null) goto continuation.
    //
    // and we definitely have to emit:
    //   if (klass(src).reference_type == REF_NONE) goto continuation
    //   if (!marking_active) goto continuation
    //   if (pre_val == null) goto continuation
    //   call pre_barrier(pre_val)
    //   goto continuation
    //
    __ bind(_entry);

    assert(src()->is_register(), "sanity");
    Register src_reg = src()->as_register();

    if (gen_src_check()) {
        // The original src operand was not a constant.
        // Generate src == null?
        if (__ is_in_wdisp16_range(_continuation)) {
            __ br_null(src_reg, /*annul*/false, Assembler::pt, _continuation);
        } else {
            __ cmp(src_reg, G0);
            __ brx(Assembler::equal, false, Assembler::pt, _continuation);
        }
        __ delayed()->nop();
    }

    // Generate src->_klass->_reference_type() == REF_NONE)?
    assert(tmp()->is_register(), "sanity");
    Register tmp_reg = tmp()->as_register();

    __ load_klass(src_reg, tmp_reg);

    Address ref_type_adr(tmp_reg, instanceKlass::reference_type_offset());
    __ ldub(ref_type_adr, tmp_reg);

    // _reference_type field is of type ReferenceType (enum)
    assert(REF_NONE == 0, "check this code");
    __ cmp_zero_and_br(Assembler::equal, tmp_reg, _continuation, /*annul*/false, Assembler::pt);
    __ delayed()->nop();

    // Is marking active?
    assert(thread()->is_register(), "precondition");
    Register thread_reg = thread()->as_pointer_register();

    Address in_progress(thread_reg, in_bytes(JavaThread::satb_mark_queue_offset() +
                        PtrQueue::byte_offset_of_active()));

    if (in_bytes(PtrQueue::byte_width_of_active()) == 4) {
        __ ld(in_progress, tmp_reg);
    } else {
        assert(in_bytes(PtrQueue::byte_width_of_active()) == 1, "Assumption");
        __ ldsb(in_progress, tmp_reg);
    }

    __ cmp_zero_and_br(Assembler::equal, tmp_reg, _continuation, /*annul*/false, Assembler::pt);
    __ delayed()->nop();

    // val == null?
    assert(val()->is_register(), "Precondition.");
    Register val_reg = val()->as_register();

    if (__ is_in_wdisp16_range(_continuation)) {
        __ br_null(val_reg, /*annul*/false, Assembler::pt, _continuation);
    } else {
        __ cmp(val_reg, G0);
        __ brx(Assembler::equal, false, Assembler::pt, _continuation);
    }
    __ delayed()->nop();

    __ call(Runtime1::entry_for(Runtime1::Runtime1::g1_pre_barrier_slow_id));
    __ delayed()->mov(val_reg, G4);
    __ br(Assembler::always, false, Assembler::pt, _continuation);
    __ delayed()->nop();
}
inline void MacroAssembler::ldsb(Register s1, RegisterOrConstant s2, Register d) { ldsb(Address(s1, s2), d); }
address JNI_FastGetField::generate_fast_get_int_field0(BasicType type) {
  const char *name;
  switch (type) {
    case T_BOOLEAN: name = "jni_fast_GetBooleanField"; break;
    case T_BYTE:    name = "jni_fast_GetByteField";    break;
    case T_CHAR:    name = "jni_fast_GetCharField";    break;
    case T_SHORT:   name = "jni_fast_GetShortField";   break;
    case T_INT:     name = "jni_fast_GetIntField";     break;
    default:        ShouldNotReachHere();
  }
  ResourceMark rm;
  BufferBlob* blob = BufferBlob::create(name, BUFFER_SIZE*wordSize);
  CodeBuffer cbuf(blob);
  MacroAssembler* masm = new MacroAssembler(&cbuf);
  address fast_entry = __ pc();

  Label label1, label2;

  AddressLiteral cnt_addrlit(SafepointSynchronize::safepoint_counter_addr());
  __ sethi (cnt_addrlit, O3);
  Address cnt_addr(O3, cnt_addrlit.low10());
  __ ld (cnt_addr, G4);
  __ andcc (G4, 1, G0);
  __ br (Assembler::notZero, false, Assembler::pn, label1);
  __ delayed()->srl (O2, 2, O4);
  __ ld_ptr (O1, 0, O5);

  assert(count < LIST_CAPACITY, "LIST_CAPACITY too small");
  speculative_load_pclist[count] = __ pc();
  switch (type) {
    case T_BOOLEAN: __ ldub (O5, O4, G3);  break;
    case T_BYTE:    __ ldsb (O5, O4, G3);  break;
    case T_CHAR:    __ lduh (O5, O4, G3);  break;
    case T_SHORT:   __ ldsh (O5, O4, G3);  break;
    case T_INT:     __ ld (O5, O4, G3);    break;
    default:        ShouldNotReachHere();
  }

  __ ld (cnt_addr, O5);
  __ cmp (O5, G4);
  __ br (Assembler::notEqual, false, Assembler::pn, label2);
  __ delayed()->mov (O7, G1);
  __ retl ();
  __ delayed()->mov (G3, O0);

  slowcase_entry_pclist[count++] = __ pc();
  __ bind (label1);
  __ mov (O7, G1);

  address slow_case_addr;
  switch (type) {
    case T_BOOLEAN: slow_case_addr = jni_GetBooleanField_addr(); break;
    case T_BYTE:    slow_case_addr = jni_GetByteField_addr();    break;
    case T_CHAR:    slow_case_addr = jni_GetCharField_addr();    break;
    case T_SHORT:   slow_case_addr = jni_GetShortField_addr();   break;
    case T_INT:     slow_case_addr = jni_GetIntField_addr();     break;
    default:        ShouldNotReachHere();
  }
  __ bind (label2);
  __ call (slow_case_addr, relocInfo::none);
  __ delayed()->mov (G1, O7);

  __ flush ();

  return fast_entry;
}
inline void MacroAssembler::ldsb(const Address& a, Register d, int offset) {
  if (a.has_index()) { assert(offset == 0, ""); ldsb(a.base(), a.index(),         d); }
  else               {                          ldsb(a.base(), a.disp() + offset, d); }
}