Skip to content

Commit fe52048

Browse files
author
duke
committed
Backport 5aae80304c0b1b49341777b9da103638183877d5
1 parent d383ba5 commit fe52048

File tree

4 files changed

+72
-13
lines changed

4 files changed

+72
-13
lines changed

test/hotspot/jtreg/testlibrary/jittester/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -80,6 +80,7 @@ TESTLIBRARY_SRC_FILES = $(TESTLIBRARY_SRC_DIR)/Asserts.java \
8080
$(TESTLIBRARY_SRC_DIR)/process/OutputBuffer.java \
8181
$(TESTLIBRARY_SRC_DIR)/process/ProcessTools.java \
8282
$(TESTLIBRARY_SRC_DIR)/process/StreamPumper.java \
83+
$(TESTLIBRARY_SRC_DIR)/util/FileUtils.java \
8384
$(TESTLIBRARY_SRC_DIR)/util/Pair.java
8485

8586
.PHONY: cleantmp

test/hotspot/jtreg/testlibrary/jittester/src/jdk/test/lib/jittester/JavaCodeGenerator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -64,13 +64,13 @@ private void generateSources(IRNode mainClass, IRNode privateClasses) {
6464
}
6565

6666
private void compileJavaFile(String mainClassName) {
67-
String classPath = tmpDir.toString();
67+
String classPath = tmpDir.path.toString();
6868
ProcessBuilder pb = new ProcessBuilder(JAVAC,
6969
"-d", classPath,
7070
"-cp", classPath,
7171
generatorDir.resolve(mainClassName + ".java").toString());
7272
try {
73-
int r = runProcess(pb, tmpDir.resolve(mainClassName + ".javac").toString());
73+
int r = runProcess(pb, tmpDir.path.resolve(mainClassName + ".javac").toString());
7474
if (r != 0) {
7575
throw new Error("Can't compile sources, exit code = " + r);
7676
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 jdk.test.lib.jittester;
25+
26+
import java.io.IOException;
27+
import java.nio.file.Files;
28+
import java.nio.file.Path;
29+
30+
import jdk.test.lib.util.FileUtils;
31+
32+
/**
33+
* A temporary directory wrapper.
34+
* Makes sure that the directory gets deleted after usage.
35+
*/
36+
public class TempDir {
37+
public final Path path;
38+
39+
/**
40+
* Creates a temporary directory with a given suffix.
41+
* The directory is deep deleted on VM shutdown using a ShutdownHook.
42+
*/
43+
public TempDir(String suffix) {
44+
try {
45+
path = Files.createTempDirectory(suffix).toAbsolutePath();
46+
Runtime.getRuntime().addShutdownHook(new Thread(this::delete));
47+
} catch (IOException e) {
48+
throw new Error("Can't create a tmp dir for " + suffix, e);
49+
}
50+
51+
System.out.println("DBG: Temp folder created: '" + path + "'");
52+
}
53+
54+
private void delete() {
55+
try {
56+
FileUtils.deleteFileTreeWithRetry(path);
57+
System.out.println("DBG: Temp folder deleted: '" + path + "'");
58+
} catch (IOException exc) {
59+
throw new Error("Could not deep delete '" + path + "'", exc);
60+
}
61+
}
62+
}

test/hotspot/jtreg/testlibrary/jittester/src/jdk/test/lib/jittester/TestsGenerator.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -42,7 +42,7 @@ public abstract class TestsGenerator implements BiConsumer<IRNode, IRNode> {
4242
protected static final String JAVAC = Paths.get(JAVA_BIN, "javac").toString();
4343
protected static final String JAVA = Paths.get(JAVA_BIN, "java").toString();
4444
protected final Path generatorDir;
45-
protected final Path tmpDir;
45+
protected final TempDir tmpDir;
4646
protected final Function<String, String[]> preRunActions;
4747
protected final String jtDriverOptions;
4848
private static final String DISABLE_WARNINGS = "-XX:-PrintWarnings";
@@ -54,17 +54,13 @@ protected TestsGenerator(String suffix) {
5454
protected TestsGenerator(String suffix, Function<String, String[]> preRunActions,
5555
String jtDriverOptions) {
5656
generatorDir = getRoot().resolve(suffix).toAbsolutePath();
57-
try {
58-
tmpDir = Files.createTempDirectory(suffix).toAbsolutePath();
59-
} catch (IOException e) {
60-
throw new Error("Can't get a tmp dir for " + suffix, e);
61-
}
57+
tmpDir = new TempDir(suffix);
6258
this.preRunActions = preRunActions;
6359
this.jtDriverOptions = jtDriverOptions;
6460
}
6561

6662
protected void generateGoldenOut(String mainClassName) {
67-
String classPath = tmpDir.toString() + File.pathSeparator
63+
String classPath = tmpDir.path.toString() + File.pathSeparator
6864
+ generatorDir.toString();
6965
ProcessBuilder pb = new ProcessBuilder(JAVA, "-Xint", DISABLE_WARNINGS, "-Xverify",
7066
"-cp", classPath, mainClassName);
@@ -97,7 +93,7 @@ protected static int runProcess(ProcessBuilder pb, String name)
9793
protected void compilePrinter() {
9894
Path root = getRoot();
9995
ProcessBuilder pbPrinter = new ProcessBuilder(JAVAC,
100-
"-d", tmpDir.toString(),
96+
"-d", tmpDir.path.toString(),
10197
root.resolve("jdk")
10298
.resolve("test")
10399
.resolve("lib")

0 commit comments

Comments
 (0)