Skip to content

Commit 234c17e

Browse files
committed
8274788: Support archived heap objects in ParallelGC
Reviewed-by: iklam, ayang, tschatzl
1 parent fc918a7 commit 234c17e

File tree

7 files changed

+156
-1
lines changed

7 files changed

+156
-1
lines changed

src/hotspot/share/cds/filemap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,7 @@ void FileMapInfo::map_or_load_heap_regions() {
19941994
} else if (HeapShared::can_load()) {
19951995
success = HeapShared::load_heap_regions(this);
19961996
} else {
1997-
log_info(cds)("Cannot use CDS heap data. UseEpsilonGC, UseG1GC or UseSerialGC are required.");
1997+
log_info(cds)("Cannot use CDS heap data. UseEpsilonGC, UseG1GC, UseSerialGC or UseParallelGC are required.");
19981998
}
19991999
}
20002000

src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,16 @@ void ParallelScavengeHeap::resize_old_gen(size_t desired_free_space) {
798798
_old_gen->resize(desired_free_space);
799799
}
800800

801+
HeapWord* ParallelScavengeHeap::allocate_loaded_archive_space(size_t size) {
802+
return _old_gen->allocate(size);
803+
}
804+
805+
void ParallelScavengeHeap::complete_loaded_archive_space(MemRegion archive_space) {
806+
assert(_old_gen->object_space()->used_region().contains(archive_space),
807+
"Archive space not contained in old gen");
808+
_old_gen->complete_loaded_archive_space(archive_space);
809+
}
810+
801811
#ifndef PRODUCT
802812
void ParallelScavengeHeap::record_gen_tops_before_GC() {
803813
if (ZapUnusedHeapArea) {

src/hotspot/share/gc/parallel/parallelScavengeHeap.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,11 @@ class ParallelScavengeHeap : public CollectedHeap {
273273
WorkerThreads& workers() {
274274
return _workers;
275275
}
276+
277+
// Support for loading objects from CDS archive into the heap
278+
bool can_load_archived_objects() const { return UseCompressedOops; }
279+
HeapWord* allocate_loaded_archive_space(size_t size);
280+
void complete_loaded_archive_space(MemRegion archive_space);
276281
};
277282

278283
// Class that can be used to print information about the

src/hotspot/share/gc/parallel/psOldGen.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,15 @@ void PSOldGen::shrink(size_t bytes) {
283283
}
284284
}
285285

286+
void PSOldGen::complete_loaded_archive_space(MemRegion archive_space) {
287+
HeapWord* cur = archive_space.start();
288+
while (cur < archive_space.end()) {
289+
_start_array.allocate_block(cur);
290+
size_t word_size = cast_to_oop(cur)->size();
291+
cur += word_size;
292+
}
293+
}
294+
286295
void PSOldGen::resize(size_t desired_free_space) {
287296
const size_t alignment = virtual_space()->alignment();
288297
const size_t size_before = virtual_space()->committed_size();

src/hotspot/share/gc/parallel/psOldGen.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ class PSOldGen : public CHeapObj<mtGC> {
133133
return virtual_space()->uncommitted_size() == 0;
134134
}
135135

136+
void complete_loaded_archive_space(MemRegion archive_space);
137+
136138
// Calculating new sizes
137139
void resize(size_t desired_free_space);
138140

test/hotspot/jtreg/TEST.groups

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ hotspot_appcds_dynamic = \
428428
-runtime/cds/appcds/StaticArchiveWithLambda.java \
429429
-runtime/cds/appcds/TestCombinedCompressedFlags.java \
430430
-runtime/cds/appcds/TestEpsilonGCWithCDS.java \
431+
-runtime/cds/appcds/TestParallelGCWithCDS.java \
431432
-runtime/cds/appcds/TestSerialGCWithCDS.java \
432433
-runtime/cds/appcds/TestZGCWithCDS.java \
433434
-runtime/cds/appcds/UnusedCPDuringDump.java \
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/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+
* @test Loading CDS archived heap objects into ParallelGC
26+
* @bug 8274788
27+
* @requires vm.cds
28+
* @requires vm.gc.Parallel
29+
* @requires vm.gc.G1
30+
*
31+
* @comment don't run this test if any -XX::+Use???GC options are specified, since they will
32+
* interfere with the the test.
33+
* @requires vm.gc == null
34+
*
35+
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds
36+
* @compile test-classes/Hello.java
37+
* @run driver TestParallelGCWithCDS
38+
*/
39+
40+
import jdk.test.lib.Platform;
41+
import jdk.test.lib.process.OutputAnalyzer;
42+
43+
public class TestParallelGCWithCDS {
44+
public final static String HELLO = "Hello World";
45+
static String helloJar;
46+
47+
public static void main(String... args) throws Exception {
48+
helloJar = JarBuilder.build("hello", "Hello");
49+
50+
// Check if we can use ParallelGC during dump time, or run time, or both.
51+
test(false, true);
52+
test(true, false);
53+
test(true, true);
54+
55+
// With G1 we usually have 2 heap regions. To increase test coverage, we can have 3 heap regions
56+
// by using "-Xmx256m -XX:ObjectAlignmentInBytes=64"
57+
if (Platform.is64bit()) test(false, true, true);
58+
}
59+
60+
final static String G1 = "-XX:+UseG1GC";
61+
final static String Parallel = "-XX:+UseParallelGC";
62+
63+
static void test(boolean dumpWithParallel, boolean execWithParallel) throws Exception {
64+
test(dumpWithParallel, execWithParallel, false);
65+
}
66+
67+
static void test(boolean dumpWithParallel, boolean execWithParallel, boolean useSmallRegions) throws Exception {
68+
String dumpGC = dumpWithParallel ? Parallel : G1;
69+
String execGC = execWithParallel ? Parallel : G1;
70+
String small1 = useSmallRegions ? "-Xmx256m" : "-showversion";
71+
String small2 = useSmallRegions ? "-XX:ObjectAlignmentInBytes=64" : "-showversion";
72+
OutputAnalyzer out;
73+
74+
System.out.println("0. Dump with " + dumpGC);
75+
out = TestCommon.dump(helloJar,
76+
new String[] {"Hello"},
77+
dumpGC,
78+
small1,
79+
small2,
80+
"-Xlog:cds");
81+
out.shouldContain("Dumping shared data to file:");
82+
out.shouldHaveExitValue(0);
83+
84+
System.out.println("1. Exec with " + execGC);
85+
out = TestCommon.exec(helloJar,
86+
execGC,
87+
small1,
88+
small2,
89+
"-Xlog:cds",
90+
"Hello");
91+
out.shouldContain(HELLO);
92+
out.shouldHaveExitValue(0);
93+
94+
int n = 2;
95+
if (!dumpWithParallel && execWithParallel) {
96+
// We dumped with G1, so we have an archived heap. At exec time, try to load them into
97+
// a small ParallelGC heap that may be too small.
98+
String[] sizes = {
99+
"4m", // usually this will success load the archived heap
100+
"2m", // usually this will fail to load the archived heap, but app can launch
101+
// or fail with "GC triggered before VM initialization completed"
102+
"1m" // usually this will cause VM launch to fail with "Too small maximum heap"
103+
};
104+
for (String sz : sizes) {
105+
String xmx = "-Xmx" + sz;
106+
System.out.println("=======\n" + n + ". Exec with " + execGC + " " + xmx);
107+
out = TestCommon.exec(helloJar,
108+
execGC,
109+
small1,
110+
small2,
111+
xmx,
112+
"-Xlog:cds",
113+
"Hello");
114+
if (out.getExitValue() == 0) {
115+
out.shouldContain(HELLO);
116+
} else {
117+
String output = out.getStdout() + out.getStderr();
118+
String exp1 = "Too small maximum heap";
119+
String exp2 = "GC triggered before VM initialization completed";
120+
if (!output.contains(exp1) && !output.contains(exp2)) {
121+
throw new RuntimeException("Either '" + exp1 + "' or '" + exp2 + "' must be in stdout/stderr \n");
122+
}
123+
}
124+
n++;
125+
}
126+
}
127+
}
128+
}

0 commit comments

Comments
 (0)