Skip to content

Commit 4e1367e

Browse files
author
Cesar Soares Lucas
committed
8343468: GenShen: Enable relocation of remembered set card tables
Reviewed-by: shade, kdnilsen, wkemper
1 parent a90f323 commit 4e1367e

25 files changed

+184
-139
lines changed

src/hotspot/cpu/aarch64/aarch64.ad

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4541,6 +4541,7 @@ operand immByteMapBase()
45414541
%{
45424542
// Get base of card map
45434543
predicate(BarrierSet::barrier_set()->is_a(BarrierSet::CardTableBarrierSet) &&
4544+
!BarrierSet::barrier_set()->is_a(BarrierSet::ShenandoahBarrierSet) &&
45444545
(CardTable::CardValue*)n->get_ptr() == ((CardTableBarrierSet*)(BarrierSet::barrier_set()))->card_table()->byte_map_base());
45454546
match(ConP);
45464547

src/hotspot/cpu/aarch64/gc/shenandoah/shenandoahBarrierSetAssembler_aarch64.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ void ShenandoahBarrierSetAssembler::store_check(MacroAssembler* masm, Register o
377377

378378
assert(CardTable::dirty_card_val() == 0, "must be");
379379

380-
__ load_byte_map_base(rscratch1);
380+
Address curr_ct_holder_addr(rthread, in_bytes(ShenandoahThreadLocalData::card_table_offset()));
381+
__ ldr(rscratch1, curr_ct_holder_addr);
381382

382383
if (UseCondCardMark) {
383384
Label L_already_dirty;
@@ -624,7 +625,8 @@ void ShenandoahBarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssemb
624625
// number of bytes to copy
625626
__ sub(count, end, start);
626627

627-
__ load_byte_map_base(scratch);
628+
Address curr_ct_holder_addr(rthread, in_bytes(ShenandoahThreadLocalData::card_table_offset()));
629+
__ ldr(scratch, curr_ct_holder_addr);
628630
__ add(start, start, scratch);
629631
__ bind(L_loop);
630632
__ strb(zr, Address(start, count));

src/hotspot/cpu/ppc/gc/shenandoah/shenandoahBarrierSetAssembler_ppc.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -587,9 +587,6 @@ void ShenandoahBarrierSetAssembler::load_at(
587587

588588
void ShenandoahBarrierSetAssembler::store_check(MacroAssembler* masm, Register base, RegisterOrConstant ind_or_offs, Register tmp) {
589589
assert(ShenandoahCardBarrier, "Should have been checked by caller");
590-
591-
ShenandoahBarrierSet* ctbs = ShenandoahBarrierSet::barrier_set();
592-
CardTable* ct = ctbs->card_table();
593590
assert_different_registers(base, tmp, R0);
594591

595592
if (ind_or_offs.is_constant()) {
@@ -598,7 +595,7 @@ void ShenandoahBarrierSetAssembler::store_check(MacroAssembler* masm, Register b
598595
__ add(base, ind_or_offs.as_register(), base);
599596
}
600597

601-
__ load_const_optimized(tmp, (address)ct->byte_map_base(), R0);
598+
__ ld(tmp, in_bytes(ShenandoahThreadLocalData::card_table_offset()), R16_thread); /* tmp = *[R16_thread + card_table_offset] */
602599
__ srdi(base, base, CardTable::card_shift());
603600
__ li(R0, CardTable::dirty_card_val());
604601
__ stbx(R0, tmp, base);
@@ -797,7 +794,8 @@ void ShenandoahBarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssemb
797794
__ srdi(addr, addr, CardTable::card_shift());
798795
__ srdi(count, count, CardTable::card_shift());
799796
__ subf(count, addr, count);
800-
__ add_const_optimized(addr, addr, (address)ct->byte_map_base(), R0);
797+
__ ld(R0, in_bytes(ShenandoahThreadLocalData::card_table_offset()), R16_thread);
798+
__ add(addr, addr, R0);
801799
__ addi(count, count, 1);
802800
__ li(R0, 0);
803801
__ mtctr(count);

src/hotspot/cpu/riscv/gc/shenandoah/shenandoahBarrierSetAssembler_riscv.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,8 @@ void ShenandoahBarrierSetAssembler::store_check(MacroAssembler* masm, Register o
396396

397397
assert(CardTable::dirty_card_val() == 0, "must be");
398398

399-
__ load_byte_map_base(t1);
399+
Address curr_ct_holder_addr(xthread, in_bytes(ShenandoahThreadLocalData::card_table_offset()));
400+
__ ld(t1, curr_ct_holder_addr);
400401
__ add(t1, obj, t1);
401402

402403
if (UseCondCardMark) {
@@ -568,7 +569,8 @@ void ShenandoahBarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssemb
568569
// number of bytes to copy
569570
__ sub(count, end, start);
570571

571-
__ load_byte_map_base(tmp);
572+
Address curr_ct_holder_addr(xthread, in_bytes(ShenandoahThreadLocalData::card_table_offset()));
573+
__ ld(tmp, curr_ct_holder_addr);
572574
__ add(start, start, tmp);
573575

574576
__ bind(L_loop);

src/hotspot/cpu/riscv/riscv.ad

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2916,6 +2916,7 @@ operand immByteMapBase()
29162916
%{
29172917
// Get base of card map
29182918
predicate(BarrierSet::barrier_set()->is_a(BarrierSet::CardTableBarrierSet) &&
2919+
!BarrierSet::barrier_set()->is_a(BarrierSet::ShenandoahBarrierSet) &&
29192920
(CardTable::CardValue*)n->get_ptr() ==
29202921
((CardTableBarrierSet*)(BarrierSet::barrier_set()))->card_table()->byte_map_base());
29212922
match(ConP);

src/hotspot/cpu/x86/gc/shared/cardTableBarrierSetAssembler_x86.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void CardTableBarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssembl
4747
CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(bs);
4848
CardTable* ct = ctbs->card_table();
4949
intptr_t disp = (intptr_t) ct->byte_map_base();
50+
SHENANDOAHGC_ONLY(assert(!UseShenandoahGC, "Shenandoah byte_map_base is not constant.");)
5051

5152
Label L_loop, L_done;
5253
const Register end = count;

src/hotspot/cpu/x86/gc/shenandoah/shenandoahBarrierSetAssembler_x86.cpp

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -614,32 +614,32 @@ void ShenandoahBarrierSetAssembler::store_check(MacroAssembler* masm, Register o
614614

615615
// Does a store check for the oop in register obj. The content of
616616
// register obj is destroyed afterwards.
617-
618-
ShenandoahBarrierSet* ctbs = ShenandoahBarrierSet::barrier_set();
619-
CardTable* ct = ctbs->card_table();
620-
621617
__ shrptr(obj, CardTable::card_shift());
622618

623-
Address card_addr;
619+
// We'll use this register as the TLS base address and also later on
620+
// to hold the byte_map_base.
621+
Register thread = LP64_ONLY(r15_thread) NOT_LP64(rcx);
622+
Register tmp = LP64_ONLY(rscratch1) NOT_LP64(rdx);
624623

625-
// The calculation for byte_map_base is as follows:
626-
// byte_map_base = _byte_map - (uintptr_t(low_bound) >> card_shift);
627-
// So this essentially converts an address to a displacement and it will
628-
// never need to be relocated. On 64-bit however the value may be too
629-
// large for a 32-bit displacement.
630-
intptr_t byte_map_base = (intptr_t)ct->byte_map_base();
631-
if (__ is_simm32(byte_map_base)) {
632-
card_addr = Address(noreg, obj, Address::times_1, byte_map_base);
633-
} else {
634-
// By doing it as an ExternalAddress 'byte_map_base' could be converted to a rip-relative
635-
// displacement and done in a single instruction given favorable mapping and a
636-
// smarter version of as_Address. However, 'ExternalAddress' generates a relocation
637-
// entry and that entry is not properly handled by the relocation code.
638-
AddressLiteral cardtable((address)byte_map_base, relocInfo::none);
639-
Address index(noreg, obj, Address::times_1);
640-
card_addr = __ as_Address(ArrayAddress(cardtable, index), rscratch1);
624+
#ifndef _LP64
625+
// The next two ifs are just to get temporary registers to use for TLS and card table base.
626+
if (thread == obj) {
627+
thread = rdx;
628+
tmp = rsi;
629+
}
630+
if (tmp == obj) {
631+
tmp = rsi;
641632
}
642633

634+
__ push(thread);
635+
__ push(tmp);
636+
__ get_thread(thread);
637+
#endif
638+
639+
Address curr_ct_holder_addr(thread, in_bytes(ShenandoahThreadLocalData::card_table_offset()));
640+
__ movptr(tmp, curr_ct_holder_addr);
641+
Address card_addr(tmp, obj, Address::times_1);
642+
643643
int dirty = CardTable::dirty_card_val();
644644
if (UseCondCardMark) {
645645
Label L_already_dirty;
@@ -650,6 +650,11 @@ void ShenandoahBarrierSetAssembler::store_check(MacroAssembler* masm, Register o
650650
} else {
651651
__ movb(card_addr, dirty);
652652
}
653+
654+
#ifndef _LP64
655+
__ pop(tmp);
656+
__ pop(thread);
657+
#endif
653658
}
654659

655660
void ShenandoahBarrierSetAssembler::store_at(MacroAssembler* masm, DecoratorSet decorators, BasicType type,
@@ -905,10 +910,6 @@ void ShenandoahBarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssemb
905910
Register tmp) {
906911
assert(ShenandoahCardBarrier, "Should have been checked by caller");
907912

908-
ShenandoahBarrierSet* bs = ShenandoahBarrierSet::barrier_set();
909-
CardTable* ct = bs->card_table();
910-
intptr_t disp = (intptr_t) ct->byte_map_base();
911-
912913
Label L_loop, L_done;
913914
const Register end = count;
914915
assert_different_registers(addr, end);
@@ -918,27 +919,38 @@ void ShenandoahBarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssemb
918919
__ jccb(Assembler::zero, L_done);
919920

920921
#ifdef _LP64
922+
const Register thread = r15_thread;
923+
Address curr_ct_holder_addr(thread, in_bytes(ShenandoahThreadLocalData::card_table_offset()));
924+
__ movptr(tmp, curr_ct_holder_addr);
925+
921926
__ leaq(end, Address(addr, count, TIMES_OOP, 0)); // end == addr+count*oop_size
922927
__ subptr(end, BytesPerHeapOop); // end - 1 to make inclusive
923928
__ shrptr(addr, CardTable::card_shift());
924929
__ shrptr(end, CardTable::card_shift());
925930
__ subptr(end, addr); // end --> cards count
926931

927-
__ mov64(tmp, disp);
928932
__ addptr(addr, tmp);
929933

930934
__ BIND(L_loop);
931935
__ movb(Address(addr, count, Address::times_1), 0);
932936
__ decrement(count);
933937
__ jccb(Assembler::greaterEqual, L_loop);
934938
#else
939+
const Register thread = tmp;
940+
__ get_thread(thread);
941+
942+
Address curr_ct_holder_addr(thread, in_bytes(ShenandoahThreadLocalData::byte_map_base_offset()));
943+
__ movptr(tmp, curr_ct_holder_addr);
944+
935945
__ lea(end, Address(addr, count, Address::times_ptr, -wordSize));
936946
__ shrptr(addr, CardTable::card_shift());
937947
__ shrptr(end, CardTable::card_shift());
938948
__ subptr(end, addr); // end --> count
939949

950+
__ addptr(addr, tmp);
951+
940952
__ BIND(L_loop);
941-
Address cardtable(addr, count, Address::times_1, disp);
953+
Address cardtable(addr, count, Address::times_1, 0);
942954
__ movb(cardtable, 0);
943955
__ decrement(count);
944956
__ jccb(Assembler::greaterEqual, L_loop);

src/hotspot/share/ci/ciUtilities.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "gc/shared/cardTableBarrierSet.hpp"
2727
#include "gc/shared/cardTable.hpp"
2828
#include "gc/shared/collectedHeap.hpp"
29+
#include "gc/shared/gc_globals.hpp"
2930

3031
// ciUtilities
3132
//
@@ -45,5 +46,6 @@ CardTable::CardValue* ci_card_table_address() {
4546
BarrierSet* bs = BarrierSet::barrier_set();
4647
CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(bs);
4748
CardTable* ct = ctbs->card_table();
49+
assert(!UseShenandoahGC, "Shenandoah byte_map_base is not constant.");
4850
return ct->byte_map_base();
4951
}

src/hotspot/share/gc/shared/c1/cardTableBarrierSetC1.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ void CardTableBarrierSetC1::post_barrier(LIRAccess& access, LIR_Opr addr, LIR_Op
4646
CardTableBarrierSet* ctbs = barrier_set_cast<CardTableBarrierSet>(bs);
4747
CardTable* ct = ctbs->card_table();
4848
LIR_Const* card_table_base = new LIR_Const(ct->byte_map_base());
49+
SHENANDOAHGC_ONLY(assert(!UseShenandoahGC, "Shenandoah byte_map_base is not constant.");)
50+
4951
if (addr->is_address()) {
5052
LIR_Address* address = addr->as_address_ptr();
5153
// ptr cannot be an object because we use this barrier for array card marks

src/hotspot/share/gc/shenandoah/c1/shenandoahBarrierSetC1.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,12 @@ void ShenandoahBarrierSetC1::post_barrier(LIRAccess& access, LIR_Opr addr, LIR_O
309309
return;
310310
}
311311

312-
BarrierSet* bs = BarrierSet::barrier_set();
313-
ShenandoahBarrierSet* ctbs = barrier_set_cast<ShenandoahBarrierSet>(bs);
314-
CardTable* ct = ctbs->card_table();
315-
LIR_Const* card_table_base = new LIR_Const(ct->byte_map_base());
312+
LIR_Opr thrd = gen->getThreadPointer();
313+
const int curr_ct_holder_offset = in_bytes(ShenandoahThreadLocalData::card_table_offset());
314+
LIR_Address* curr_ct_holder_addr = new LIR_Address(thrd, curr_ct_holder_offset, T_ADDRESS);
315+
LIR_Opr curr_ct_holder_ptr_reg = gen->new_register(T_ADDRESS);
316+
__ move(curr_ct_holder_addr, curr_ct_holder_ptr_reg);
317+
316318
if (addr->is_address()) {
317319
LIR_Address* address = addr->as_address_ptr();
318320
// ptr cannot be an object because we use this barrier for array card marks
@@ -336,13 +338,7 @@ void ShenandoahBarrierSetC1::post_barrier(LIRAccess& access, LIR_Opr addr, LIR_O
336338
__ unsigned_shift_right(addr, CardTable::card_shift(), tmp);
337339
}
338340

339-
LIR_Address* card_addr;
340-
if (gen->can_inline_as_constant(card_table_base)) {
341-
card_addr = new LIR_Address(tmp, card_table_base->as_jint(), T_BYTE);
342-
} else {
343-
card_addr = new LIR_Address(tmp, gen->load_constant(card_table_base), T_BYTE);
344-
}
345-
341+
LIR_Address* card_addr = new LIR_Address(curr_ct_holder_ptr_reg, tmp, T_BYTE);
346342
LIR_Opr dirty = LIR_OprFact::intConst(CardTable::dirty_card_val());
347343
if (UseCondCardMark) {
348344
LIR_Opr cur_value = gen->new_register(T_INT);

0 commit comments

Comments
 (0)