Skip to content

Commit 6514aef

Browse files
committed
8340419: ZGC: Create an UseLargePages adaptation of TestAllocateHeapAt.java
Reviewed-by: stefank, sjohanss, jsikstro
1 parent ae4d2f1 commit 6514aef

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (c) 2024, 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+
package gc.z;
25+
26+
/*
27+
* @test TestAllocateHeapAtWithHugeTLBFS
28+
* @requires vm.gc.ZGenerational & os.family == "linux"
29+
* @summary Test ZGC with -XX:AllocateHeapAt and -XX:+UseLargePages
30+
* @library /test/lib
31+
* @run driver gc.z.TestAllocateHeapAtWithHugeTLBFS true
32+
* @run driver gc.z.TestAllocateHeapAtWithHugeTLBFS false
33+
*/
34+
35+
import jdk.test.lib.process.ProcessTools;
36+
import jtreg.SkippedException;
37+
38+
import java.io.File;
39+
import java.io.FileNotFoundException;
40+
import java.nio.file.Files;
41+
import java.nio.file.Paths;
42+
import java.nio.file.Path;
43+
import java.util.regex.Matcher;
44+
import java.util.regex.Pattern;
45+
import java.util.Scanner;
46+
47+
public class TestAllocateHeapAtWithHugeTLBFS {
48+
static String find_hugetlbfs_mountpoint() {
49+
Pattern pat = Pattern.compile("\\d+ \\d+ \\d+:\\d+ \\S+ (\\S+) [^-]*- hugetlbfs (.+)");
50+
try (Scanner scanner = new Scanner(new File("/proc/self/mountinfo"))) {
51+
while (scanner.hasNextLine()) {
52+
final Matcher mat = pat.matcher(scanner.nextLine());
53+
if (mat.matches() && mat.group(2).contains("pagesize=2M")) {
54+
final Path path = Paths.get(mat.group(1));
55+
if (Files.isReadable(path) &&
56+
Files.isWritable(path) &&
57+
Files.isExecutable(path)) {
58+
// Found a usable mount point.
59+
return path.toString();
60+
}
61+
}
62+
}
63+
} catch (FileNotFoundException e) {
64+
System.out.println("Could not open /proc/self/mountinfo");
65+
}
66+
return null;
67+
}
68+
public static void main(String[] args) throws Exception {
69+
final boolean exists = Boolean.parseBoolean(args[0]);
70+
final String directory = exists ? find_hugetlbfs_mountpoint()
71+
: "non-existing-directory";
72+
if (directory == null) {
73+
throw new SkippedException("No valid hugetlbfs mount point found");
74+
}
75+
final String heapBackingFile = "Heap Backing File: " + directory;
76+
final String failedToCreateFile = "Failed to create file " + directory;
77+
78+
ProcessTools.executeTestJava(
79+
"-XX:+UseZGC",
80+
"-XX:+ZGenerational",
81+
"-Xlog:gc*",
82+
"-Xms32M",
83+
"-Xmx32M",
84+
"-XX:+UseLargePages",
85+
"-XX:AllocateHeapAt=" + directory,
86+
"-version")
87+
.shouldContain(exists ? heapBackingFile : failedToCreateFile)
88+
.shouldNotContain(exists ? failedToCreateFile : heapBackingFile)
89+
.shouldHaveExitValue(exists ? 0 : 1);
90+
}
91+
}

0 commit comments

Comments
 (0)