Skip to content

Commit eaf9556

Browse files
cost0muchPaul Hohensee
authored andcommitted
8312049: runtime/logging/ClassLoadUnloadTest can be improved
Reviewed-by: phh Backport-of: 4676b40f17dd18941f5883cb9b989ad639992a50
1 parent 533d873 commit eaf9556

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

test/hotspot/jtreg/runtime/logging/ClassLoadUnloadTest.java

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
import jdk.test.lib.classloader.ClassUnloadCommon;
4545

4646
public class ClassLoadUnloadTest {
47-
private static OutputAnalyzer out;
48-
private static ProcessBuilder pb;
4947
private static class ClassUnloadTestMain {
5048
public static void main(String... args) throws Exception {
5149
String className = "test.Empty";
@@ -56,63 +54,62 @@ public static void main(String... args) throws Exception {
5654
}
5755
}
5856

59-
static void checkFor(String... outputStrings) throws Exception {
60-
out = new OutputAnalyzer(pb.start());
57+
static void checkFor(OutputAnalyzer output, String... outputStrings) throws Exception {
6158
for (String s: outputStrings) {
62-
out.shouldContain(s);
59+
output.shouldContain(s);
6360
}
64-
out.shouldHaveExitValue(0);
6561
}
6662

67-
static void checkAbsent(String... outputStrings) throws Exception {
68-
out = new OutputAnalyzer(pb.start());
63+
static void checkAbsent(OutputAnalyzer output, String... outputStrings) throws Exception {
6964
for (String s: outputStrings) {
70-
out.shouldNotContain(s);
65+
output.shouldNotContain(s);
7166
}
72-
out.shouldHaveExitValue(0);
7367
}
7468

7569
// Use the same command-line heap size setting as ../ClassUnload/UnloadTest.java
76-
static ProcessBuilder exec(String... args) throws Exception {
70+
static OutputAnalyzer exec(String... args) throws Exception {
7771
List<String> argsList = new ArrayList<>();
7872
Collections.addAll(argsList, args);
79-
Collections.addAll(argsList, "-Xmn8m");
80-
Collections.addAll(argsList, "-Dtest.class.path=" + System.getProperty("test.class.path", "."));
81-
Collections.addAll(argsList, "-XX:+ClassUnloading");
82-
Collections.addAll(argsList, ClassUnloadTestMain.class.getName());
83-
return ProcessTools.createJavaProcessBuilder(argsList);
73+
Collections.addAll(argsList, "-Xmn8m", "-Dtest.class.path=" + System.getProperty("test.class.path", "."),
74+
"-XX:+ClassUnloading", ClassUnloadTestMain.class.getName());
75+
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(argsList);
76+
OutputAnalyzer output = new OutputAnalyzer(pb.start());
77+
output.shouldHaveExitValue(0);
78+
return output;
8479
}
8580

8681
public static void main(String... args) throws Exception {
8782

83+
OutputAnalyzer output;
84+
8885
// -Xlog:class+unload=info
89-
pb = exec("-Xlog:class+unload=info");
90-
checkFor("[class,unload]", "unloading class");
86+
output = exec("-Xlog:class+unload=info");
87+
checkFor(output, "[class,unload]", "unloading class");
9188

9289
// -Xlog:class+unload=off
93-
pb = exec("-Xlog:class+unload=off");
94-
checkAbsent("[class,unload]");
90+
output = exec("-Xlog:class+unload=off");
91+
checkAbsent(output,"[class,unload]");
9592

9693
// -Xlog:class+load=info
97-
pb = exec("-Xlog:class+load=info");
98-
checkFor("[class,load]", "java.lang.Object", "source:");
94+
output = exec("-Xlog:class+load=info");
95+
checkFor(output,"[class,load]", "java.lang.Object", "source:");
9996

10097
// -Xlog:class+load=debug
101-
pb = exec("-Xlog:class+load=debug");
102-
checkFor("[class,load]", "java.lang.Object", "source:", "klass:", "super:", "loader:", "bytes:");
98+
output = exec("-Xlog:class+load=debug");
99+
checkFor(output,"[class,load]", "java.lang.Object", "source:", "klass:", "super:", "loader:", "bytes:");
103100

104101
// -Xlog:class+load=off
105-
pb = exec("-Xlog:class+load=off");
106-
checkAbsent("[class,load]");
102+
output = exec("-Xlog:class+load=off");
103+
checkAbsent(output,"[class,load]");
107104

108105
// -verbose:class
109-
pb = exec("-verbose:class");
110-
checkFor("[class,load]", "java.lang.Object", "source:");
111-
checkFor("[class,unload]", "unloading class");
106+
output = exec("-verbose:class");
107+
checkFor(output,"[class,load]", "java.lang.Object", "source:");
108+
checkFor(output,"[class,unload]", "unloading class");
112109

113110
// -Xlog:class+loader+data=trace
114-
pb = exec("-Xlog:class+loader+data=trace");
115-
checkFor("[class,loader,data]", "create loader data");
111+
output = exec("-Xlog:class+loader+data=trace");
112+
checkFor(output, "[class,loader,data]", "create loader data");
116113

117114
}
118115
}

0 commit comments

Comments
 (0)