Skip to content

Commit f3dfdfa

Browse files
rgithubliXiaolong Peng
authored andcommitted
8369013: Shenandoah: passive mode should support enabling ShenandoahCardBarrier
Reviewed-by: wkemper
1 parent d62553d commit f3dfdfa

File tree

9 files changed

+111
-13
lines changed

9 files changed

+111
-13
lines changed

src/hotspot/share/gc/shenandoah/mode/shenandoahPassiveMode.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ void ShenandoahPassiveMode::initialize_flags() const {
4848
SHENANDOAH_ERGO_DISABLE_FLAG(ShenandoahCloneBarrier);
4949
SHENANDOAH_ERGO_DISABLE_FLAG(ShenandoahStackWatermarkBarrier);
5050
SHENANDOAH_ERGO_DISABLE_FLAG(ShenandoahCardBarrier);
51-
52-
// Final configuration checks
53-
// Passive mode does not instantiate the machinery to support the card table.
54-
// Exit if the flag has been explicitly set.
55-
SHENANDOAH_CHECK_FLAG_UNSET(ShenandoahCardBarrier);
5651
}
5752

5853
ShenandoahHeuristics* ShenandoahPassiveMode::initialize_heuristics(ShenandoahSpaceInfo* space_info) const {

src/hotspot/share/gc/shenandoah/shenandoahDegeneratedGC.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ void ShenandoahDegenGC::op_degenerated() {
9595
// some phase, we have to upgrade the Degenerate GC to Full GC.
9696
heap->clear_cancelled_gc();
9797

98+
// If it's passive mode with ShenandoahCardBarrier turned on: clean the write table
99+
// without swapping the tables since no scan happens in passive mode anyway
100+
if (ShenandoahCardBarrier && !heap->mode()->is_generational()) {
101+
heap->old_generation()->card_scan()->mark_write_table_as_clean();
102+
}
103+
98104
#ifdef ASSERT
99105
if (heap->mode()->is_generational()) {
100106
ShenandoahOldGeneration* old_generation = heap->old_generation();

src/hotspot/share/gc/shenandoah/shenandoahGenerationalHeap.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#ifndef SHARE_GC_SHENANDOAH_SHENANDOAHGENERATIONALHEAP
2626
#define SHARE_GC_SHENANDOAH_SHENANDOAHGENERATIONALHEAP
2727

28-
#include "gc/shenandoah/shenandoahAsserts.hpp"
2928
#include "gc/shenandoah/shenandoahHeap.hpp"
3029
#include "memory/universe.hpp"
3130
#include "utilities/checkedCast.hpp"
@@ -44,13 +43,13 @@ class ShenandoahGenerationalHeap : public ShenandoahHeap {
4443
void initialize_heuristics() override;
4544

4645
static ShenandoahGenerationalHeap* heap() {
47-
shenandoah_assert_generational();
46+
assert(ShenandoahCardBarrier, "Should have card barrier to use genenrational heap");
4847
CollectedHeap* heap = Universe::heap();
4948
return cast(heap);
5049
}
5150

5251
static ShenandoahGenerationalHeap* cast(CollectedHeap* heap) {
53-
shenandoah_assert_generational();
52+
assert(ShenandoahCardBarrier, "Should have card barrier to use genenrational heap");
5453
return checked_cast<ShenandoahGenerationalHeap*>(heap);
5554
}
5655

src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,13 @@ jint ShenandoahHeap::initialize() {
248248
// Now we know the number of regions and heap sizes, initialize the heuristics.
249249
initialize_heuristics();
250250

251+
// If ShenandoahCardBarrier is enabled but it's not generational mode
252+
// it means we're under passive mode and we have to initialize old gen
253+
// for the purpose of having card table.
254+
if (ShenandoahCardBarrier && !(mode()->is_generational())) {
255+
_old_generation = new ShenandoahOldGeneration(max_workers(), max_capacity());
256+
}
257+
251258
assert(_heap_region.byte_size() == heap_rs.size(), "Need to know reserved size for card table");
252259

253260
//

src/hotspot/share/gc/shenandoah/shenandoahHeap.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ class ShenandoahHeap : public CollectedHeap {
530530
}
531531

532532
ShenandoahOldGeneration* old_generation() const {
533-
assert(mode()->is_generational(), "Old generation requires generational mode");
533+
assert(ShenandoahCardBarrier, "Card mark barrier should be on");
534534
return _old_generation;
535535
}
536536

src/hotspot/share/gc/shenandoah/shenandoahScanRemembered.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ void ShenandoahDirectCardMarkRememberedSet::mark_read_table_as_clean() {
123123
log_develop_debug(gc, barrier)("Cleaned read_table from " PTR_FORMAT " to " PTR_FORMAT, p2i(&(read_table[0])), p2i(end_bp));
124124
}
125125

126+
void ShenandoahDirectCardMarkRememberedSet::mark_write_table_as_clean() {
127+
CardValue* write_table = _card_table->write_byte_map();
128+
CardValue* bp = &(write_table)[0];
129+
CardValue* end_bp = &(write_table)[_card_table->last_valid_index()];
130+
131+
while (bp <= end_bp) {
132+
*bp++ = CardTable::clean_card_val();
133+
}
134+
135+
log_develop_debug(gc, barrier)("Cleaned write_table from " PTR_FORMAT " to " PTR_FORMAT, p2i(&(write_table[0])), p2i(end_bp));
136+
}
137+
126138
// No lock required because arguments align with card boundaries.
127139
void ShenandoahCardCluster::reset_object_range(HeapWord* from, HeapWord* to) {
128140
assert(((((unsigned long long) from) & (CardTable::card_size() - 1)) == 0) &&
@@ -330,6 +342,10 @@ void ShenandoahScanRemembered::mark_read_table_as_clean() {
330342
_rs->mark_read_table_as_clean();
331343
}
332344

345+
void ShenandoahScanRemembered::mark_write_table_as_clean() {
346+
_rs->mark_write_table_as_clean();
347+
}
348+
333349
void ShenandoahScanRemembered::reset_object_range(HeapWord* from, HeapWord* to) {
334350
_scc->reset_object_range(from, to);
335351
}

src/hotspot/share/gc/shenandoah/shenandoahScanRemembered.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ class ShenandoahDirectCardMarkRememberedSet: public CHeapObj<mtGC> {
244244
// See comment in ShenandoahScanRemembered
245245
inline void mark_read_table_as_clean();
246246

247+
inline void mark_write_table_as_clean();
248+
247249
// Merge any dirty values from write table into the read table, while leaving
248250
// the write table unchanged.
249251
void merge_write_table(HeapWord* start, size_t word_count);
@@ -769,6 +771,8 @@ class ShenandoahScanRemembered: public CHeapObj<mtGC> {
769771
// the "write" table.
770772
void mark_read_table_as_clean();
771773

774+
void mark_write_table_as_clean();
775+
772776
// Swaps read and write card tables pointers in effect setting a clean card
773777
// table for the next GC cycle.
774778
void swap_card_tables() { _rs->swap_card_tables(); }
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*
23+
*/
24+
25+
/*
26+
* @test
27+
* @summary Test passive mode with card barrier with a gc heavy app. A simple hello world in TestSelectiveBarrierFlags
28+
* does not always surface crashes
29+
* @requires vm.gc.Shenandoah
30+
* @library /test/lib
31+
*
32+
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+UseShenandoahGC -Xmx128m -XX:ShenandoahGCMode=passive -XX:+ShenandoahCardBarrier TestPassiveModeWithCardBarrier
33+
*/
34+
35+
import java.util.*;
36+
import java.util.concurrent.*;
37+
38+
import jdk.test.lib.process.ProcessTools;
39+
import jdk.test.lib.process.OutputAnalyzer;
40+
41+
public class TestPassiveModeWithCardBarrier {
42+
public static void main(String[] args) throws Exception {
43+
List<byte[]> junk = new ArrayList<>();
44+
int junkLength = 1000;
45+
int totalRounds = 10;
46+
int round = 0;
47+
48+
while (round++ < totalRounds) {
49+
for (int i = 0; i < junkLength; i++) {
50+
junk.add(new byte[1024]);
51+
}
52+
53+
System.out.println(junk.hashCode());
54+
}
55+
56+
// trigger a full gc in case it was all degen
57+
System.gc();
58+
}
59+
}

test/hotspot/jtreg/gc/shenandoah/options/TestWrongBarrierEnable.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,30 @@
3737
public class TestWrongBarrierEnable {
3838

3939
public static void main(String[] args) throws Exception {
40-
String[] concurrent = { "ShenandoahSATBBarrier" };
40+
String[] concurrent = {
41+
"ShenandoahLoadRefBarrier",
42+
"ShenandoahSATBBarrier",
43+
"ShenandoahCASBarrier",
44+
"ShenandoahCloneBarrier",
45+
"ShenandoahStackWatermarkBarrier",
46+
};
4147
String[] generational = { "ShenandoahCardBarrier" };
42-
String[] all = { "ShenandoahSATBBarrier", "ShenandoahCardBarrier" };
48+
String[] all = {
49+
"ShenandoahLoadRefBarrier",
50+
"ShenandoahSATBBarrier",
51+
"ShenandoahCASBarrier",
52+
"ShenandoahCloneBarrier",
53+
"ShenandoahStackWatermarkBarrier",
54+
"ShenandoahCardBarrier"
55+
};
4356

4457
shouldPassAll("-XX:ShenandoahGCHeuristics=adaptive", concurrent);
4558
shouldPassAll("-XX:ShenandoahGCHeuristics=static", concurrent);
4659
shouldPassAll("-XX:ShenandoahGCHeuristics=compact", concurrent);
4760
shouldPassAll("-XX:ShenandoahGCHeuristics=aggressive", concurrent);
48-
shouldPassAll("-XX:ShenandoahGCMode=passive", concurrent);
61+
shouldPassAll("-XX:ShenandoahGCMode=passive", all);
4962
shouldPassAll("-XX:ShenandoahGCMode=generational", all);
5063
shouldFailAll("-XX:ShenandoahGCMode=satb", generational);
51-
shouldFailAll("-XX:ShenandoahGCMode=passive", generational);
5264
}
5365

5466
private static void shouldFailAll(String h, String[] barriers) throws Exception {

0 commit comments

Comments
 (0)