Skip to content

Commit 1c215f3

Browse files
Vishal ChandThomas Schatzl
Vishal Chand
authored and
Thomas Schatzl
committedNov 20, 2021
8272773: Configurable card table card size
Reviewed-by: tschatzl, ayang
1 parent 1d7cef3 commit 1c215f3

13 files changed

+111
-24
lines changed
 

‎src/hotspot/share/gc/g1/g1Arguments.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ static size_t calculate_heap_alignment(size_t space_alignment) {
4545
}
4646

4747
void G1Arguments::initialize_alignments() {
48+
// Initialize card size before initializing alignments
49+
CardTable::initialize_card_size();
50+
4851
// Set up the region size and associated fields.
4952
//
5053
// There is a circular dependency here. We base the region size on the heap

‎src/hotspot/share/gc/g1/g1CollectedHeap.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,7 @@ jint G1CollectedHeap::initialize() {
16601660

16611661
// The G1FromCardCache reserves card with value 0 as "invalid", so the heap must not
16621662
// start within the first card.
1663-
guarantee(heap_rs.base() >= (char*)G1CardTable::card_size, "Java heap must not start within the first card.");
1663+
guarantee((uintptr_t)(heap_rs.base()) >= G1CardTable::card_size, "Java heap must not start within the first card.");
16641664
G1FromCardCache::initialize(max_reserved_regions());
16651665
// Also create a G1 rem set.
16661666
_rem_set = new G1RemSet(this, _card_table, _hot_card_cache);

‎src/hotspot/share/gc/parallel/objectStartArray.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,21 @@
3131
#include "services/memTracker.hpp"
3232
#include "utilities/align.hpp"
3333

34+
uint ObjectStartArray::block_shift = 0;
35+
uint ObjectStartArray::block_size = 0;
36+
uint ObjectStartArray::block_size_in_words = 0;
37+
38+
void ObjectStartArray::initialize_block_size(uint card_shift) {
39+
block_shift = card_shift;
40+
block_size = 1 << block_shift;
41+
block_size_in_words = block_size / sizeof(HeapWord);
42+
}
43+
3444
void ObjectStartArray::initialize(MemRegion reserved_region) {
3545
// We're based on the assumption that we use the same
3646
// size blocks as the card table.
3747
assert((int)block_size == (int)CardTable::card_size, "Sanity");
38-
assert((int)block_size <= 512, "block_size must be less than or equal to 512");
48+
assert(block_size <= MaxBlockSize, "block_size must be less than or equal to " UINT32_FORMAT, MaxBlockSize);
3949

4050
// Calculate how much space must be reserved
4151
_reserved_region = reserved_region;

‎src/hotspot/share/gc/parallel/objectStartArray.hpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,17 @@ class ObjectStartArray : public CHeapObj<mtGC> {
5252
clean_block = -1
5353
};
5454

55-
enum BlockSizeConstants {
56-
block_shift = 9,
57-
block_size = 1 << block_shift,
58-
block_size_in_words = block_size / sizeof(HeapWord)
59-
};
55+
static uint block_shift;
56+
static uint block_size;
57+
static uint block_size_in_words;
58+
59+
// Maximum size an offset table entry can cover. This maximum is derived from that
60+
// we need an extra bit for possible offsets in the byte for backskip values, leaving 2^7 possible offsets.
61+
// Minimum object alignment is 8 bytes (2^3), so we can at most represent 2^10 offsets within a BOT value.
62+
static const uint MaxBlockSize = 1024;
63+
64+
// Initialize block size based on card size
65+
static void initialize_block_size(uint card_shift);
6066

6167
protected:
6268

‎src/hotspot/share/gc/parallel/parallelArguments.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ static size_t default_gen_alignment() {
9797
}
9898

9999
void ParallelArguments::initialize_alignments() {
100+
// Initialize card size before initializing alignments
101+
CardTable::initialize_card_size();
100102
SpaceAlignment = GenAlignment = default_gen_alignment();
101103
HeapAlignment = compute_heap_alignment();
102104
}

‎src/hotspot/share/gc/shared/blockOffsetTable.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@
3333
#include "runtime/java.hpp"
3434
#include "services/memTracker.hpp"
3535

36+
uint BOTConstants::LogN = 0;
37+
uint BOTConstants::LogN_words = 0;
38+
uint BOTConstants::N_bytes = 0;
39+
uint BOTConstants::N_words = 0;
40+
41+
void BOTConstants::initialize_bot_size(uint card_shift) {
42+
LogN = card_shift;
43+
LogN_words = LogN - LogHeapWordSize;
44+
N_bytes = 1 << LogN;
45+
N_words = 1 << LogN_words;
46+
}
47+
3648
//////////////////////////////////////////////////////////////////////
3749
// BlockOffsetSharedArray
3850
//////////////////////////////////////////////////////////////////////

‎src/hotspot/share/gc/shared/blockOffsetTable.hpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "gc/shared/gc_globals.hpp"
2929
#include "gc/shared/memset_with_concurrent_readers.hpp"
30+
#include "gc/shared/cardTable.hpp"
3031
#include "memory/allocation.hpp"
3132
#include "memory/memRegion.hpp"
3233
#include "memory/virtualspace.hpp"
@@ -49,16 +50,20 @@ class ContiguousSpace;
4950

5051
class BOTConstants : public AllStatic {
5152
public:
52-
static const uint LogN = 9;
53-
static const uint LogN_words = LogN - LogHeapWordSize;
54-
static const uint N_bytes = 1 << LogN;
55-
static const uint N_words = 1 << LogN_words;
53+
static uint LogN;
54+
static uint LogN_words;
55+
static uint N_bytes;
56+
static uint N_words;
57+
5658
// entries "e" of at least N_words mean "go back by Base^(e-N_words)."
5759
// All entries are less than "N_words + N_powers".
5860
static const uint LogBase = 4;
5961
static const uint Base = (1 << LogBase);
6062
static const uint N_powers = 14;
6163

64+
// Initialize bot size based on card size
65+
static void initialize_bot_size(uint card_shift);
66+
6267
static size_t power_to_cards_back(uint i) {
6368
return (size_t)1 << (LogBase * i);
6469
}
@@ -93,6 +98,7 @@ class BlockOffsetTable {
9398
BlockOffsetTable(HeapWord* bottom, HeapWord* end):
9499
_bottom(bottom), _end(end) {
95100
assert(_bottom <= _end, "arguments out of order");
101+
assert(BOTConstants::N_bytes == CardTable::card_size, "sanity");
96102
}
97103

98104
// Note that the committed size of the covered space may have changed,

‎src/hotspot/share/gc/shared/cardTable.cpp

+30-3
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,41 @@
2525
#include "precompiled.hpp"
2626
#include "gc/shared/cardTable.hpp"
2727
#include "gc/shared/collectedHeap.hpp"
28+
#include "gc/shared/gcLogPrecious.hpp"
29+
#include "gc/shared/gc_globals.hpp"
2830
#include "gc/shared/space.inline.hpp"
2931
#include "logging/log.hpp"
3032
#include "memory/virtualspace.hpp"
3133
#include "runtime/java.hpp"
3234
#include "runtime/os.hpp"
3335
#include "services/memTracker.hpp"
3436
#include "utilities/align.hpp"
37+
#if INCLUDE_PARALLELGC
38+
#include "gc/parallel/objectStartArray.hpp"
39+
#endif
40+
41+
uint CardTable::card_shift = 0;
42+
uint CardTable::card_size = 0;
43+
uint CardTable::card_size_in_words = 0;
44+
45+
void CardTable::initialize_card_size() {
46+
assert(UseG1GC || UseParallelGC || UseSerialGC,
47+
"Initialize card size should only be called by card based collectors.");
48+
49+
card_size = GCCardSizeInBytes;
50+
card_shift = log2i_exact(card_size);
51+
card_size_in_words = card_size / sizeof(HeapWord);
52+
53+
// Set blockOffsetTable size based on card table entry size
54+
BOTConstants::initialize_bot_size(card_shift);
55+
56+
#if INCLUDE_PARALLELGC
57+
// Set ObjectStartArray block size based on card table entry size
58+
ObjectStartArray::initialize_block_size(card_shift);
59+
#endif
60+
61+
log_info_p(gc, init)("CardTable entry size: " UINT32_FORMAT, card_size);
62+
}
3563

3664
size_t CardTable::compute_byte_map_size() {
3765
assert(_guard_index == cards_required(_whole_heap.word_size()) - 1,
@@ -56,8 +84,6 @@ CardTable::CardTable(MemRegion whole_heap) :
5684
{
5785
assert((uintptr_t(_whole_heap.start()) & (card_size - 1)) == 0, "heap must start at card boundary");
5886
assert((uintptr_t(_whole_heap.end()) & (card_size - 1)) == 0, "heap must end at card boundary");
59-
60-
assert(card_size <= 512, "card_size must be less than 512"); // why?
6187
}
6288

6389
CardTable::~CardTable() {
@@ -428,7 +454,8 @@ MemRegion CardTable::dirty_card_range_after_reset(MemRegion mr,
428454
}
429455

430456
uintx CardTable::ct_max_alignment_constraint() {
431-
return card_size * os::vm_page_size();
457+
// Calculate maximum alignment using GCCardSizeInBytes as card_size hasn't been set yet
458+
return GCCardSizeInBytes * os::vm_page_size();
432459
}
433460

434461
void CardTable::verify_guard() {

‎src/hotspot/share/gc/shared/cardTable.hpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -228,17 +228,18 @@ class CardTable: public CHeapObj<mtGC> {
228228
MemRegion dirty_card_range_after_reset(MemRegion mr, bool reset,
229229
int reset_val);
230230

231-
// Constants
232-
enum SomePublicConstants {
233-
card_shift = 9,
234-
card_size = 1 << card_shift,
235-
card_size_in_words = card_size / sizeof(HeapWord)
236-
};
231+
// CardTable entry size
232+
static uint card_shift;
233+
static uint card_size;
234+
static uint card_size_in_words;
237235

238236
static constexpr CardValue clean_card_val() { return clean_card; }
239237
static constexpr CardValue dirty_card_val() { return dirty_card; }
240238
static intptr_t clean_card_row_val() { return clean_card_row; }
241239

240+
// Initialize card size
241+
static void initialize_card_size();
242+
242243
// Card marking array base (adjusted for heap low boundary)
243244
// This would be the 0th element of _byte_map, if the heap started at 0x0.
244245
// But since the heap starts at some higher address, this points to somewhere

‎src/hotspot/share/gc/shared/gc_globals.hpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,13 @@
692692
product(uintx, GCDrainStackTargetSize, 64, \
693693
"Number of entries we will try to leave on the stack " \
694694
"during parallel gc") \
695-
range(0, max_juint)
696-
697-
// end of GC_FLAGS
695+
range(0, max_juint) \
696+
\
697+
product(uint, GCCardSizeInBytes, 512, \
698+
"Card table entry size (in bytes) for card based collectors") \
699+
range(128, 1024) \
700+
constraint(GCCardSizeInBytesConstraintFunc,AtParse)
701+
// end of GC_FLAGS
698702

699703
DECLARE_FLAGS(GC_FLAGS)
700704

‎src/hotspot/share/gc/shared/genArguments.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424

2525
#include "precompiled.hpp"
26+
#include "gc/shared/cardTable.hpp"
2627
#include "gc/shared/genArguments.hpp"
2728
#include "gc/shared/generation.hpp"
2829
#include "logging/log.hpp"
@@ -61,6 +62,8 @@ static size_t bound_minus_alignment(size_t desired_size,
6162
}
6263

6364
void GenArguments::initialize_alignments() {
65+
// Initialize card size before initializing alignments
66+
CardTable::initialize_card_size();
6467
SpaceAlignment = GenAlignment = (size_t)Generation::GenGrain;
6568
HeapAlignment = compute_heap_alignment();
6669
}

‎src/hotspot/share/gc/shared/jvmFlagConstraintsGC.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -424,3 +424,15 @@ JVMFlag::Error MaxMetaspaceSizeConstraintFunc(size_t value, bool verbose) {
424424
}
425425
}
426426

427+
JVMFlag::Error GCCardSizeInBytesConstraintFunc(uint value, bool verbose) {
428+
if (!is_power_of_2(value)) {
429+
JVMFlag::printError(verbose,
430+
"GCCardSizeInBytes ( %u ) must be "
431+
"a power of 2\n",
432+
value);
433+
return JVMFlag::VIOLATES_CONSTRAINT;
434+
} else {
435+
return JVMFlag::SUCCESS;
436+
}
437+
}
438+

‎src/hotspot/share/gc/shared/jvmFlagConstraintsGC.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@
6666
f(uintx, TLABWasteIncrementConstraintFunc) \
6767
f(uintx, SurvivorRatioConstraintFunc) \
6868
f(size_t, MetaspaceSizeConstraintFunc) \
69-
f(size_t, MaxMetaspaceSizeConstraintFunc)
69+
f(size_t, MaxMetaspaceSizeConstraintFunc) \
70+
f(uint, GCCardSizeInBytesConstraintFunc)
7071

7172
SHARED_GC_CONSTRAINTS(DECLARE_CONSTRAINT)
7273

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Nov 20, 2021

@openjdk-notifier[bot]
Please sign in to comment.