Skip to content

Commit d158b8b

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

File tree

1 file changed

+36
-39
lines changed

1 file changed

+36
-39
lines changed

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

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
import java.util.List;
4343

4444
public class ClassLoadUnloadTest {
45-
private static OutputAnalyzer out;
46-
private static ProcessBuilder pb;
4745
private static class ClassUnloadTestMain {
4846
public static void main(String... args) throws Exception {
4947
String className = "test.Empty";
@@ -54,79 +52,78 @@ public static void main(String... args) throws Exception {
5452
}
5553
}
5654

57-
static void checkFor(String... outputStrings) throws Exception {
58-
out = new OutputAnalyzer(pb.start());
55+
static void checkFor(OutputAnalyzer output, String... outputStrings) throws Exception {
5956
for (String s: outputStrings) {
60-
out.shouldContain(s);
57+
output.shouldContain(s);
6158
}
62-
out.shouldHaveExitValue(0);
6359
}
6460

65-
static void checkAbsent(String... outputStrings) throws Exception {
66-
out = new OutputAnalyzer(pb.start());
61+
static void checkAbsent(OutputAnalyzer output, String... outputStrings) throws Exception {
6762
for (String s: outputStrings) {
68-
out.shouldNotContain(s);
63+
output.shouldNotContain(s);
6964
}
70-
out.shouldHaveExitValue(0);
7165
}
7266

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

8479
public static void main(String... args) throws Exception {
8580

81+
OutputAnalyzer output;
82+
8683
// -Xlog:class+unload=info
87-
pb = exec("-Xlog:class+unload=info");
88-
checkFor("[class,unload]", "unloading class");
84+
output = exec("-Xlog:class+unload=info");
85+
checkFor(output, "[class,unload]", "unloading class");
8986

9087
// -Xlog:class+unload=off
91-
pb = exec("-Xlog:class+unload=off");
92-
checkAbsent("[class,unload]");
88+
output = exec("-Xlog:class+unload=off");
89+
checkAbsent(output,"[class,unload]");
9390

9491
// -XX:+TraceClassUnloading
95-
pb = exec("-XX:+TraceClassUnloading");
96-
checkFor("[class,unload]", "unloading class");
92+
output = exec("-XX:+TraceClassUnloading");
93+
checkFor(output, "[class,unload]", "unloading class");
9794

9895
// -XX:-TraceClassUnloading
99-
pb = exec("-XX:-TraceClassUnloading");
100-
checkAbsent("[class,unload]");
96+
output = exec("-XX:-TraceClassUnloading");
97+
checkAbsent(output, "[class,unload]");
10198

10299
// -Xlog:class+load=info
103-
pb = exec("-Xlog:class+load=info");
104-
checkFor("[class,load]", "java.lang.Object", "source:");
100+
output = exec("-Xlog:class+load=info");
101+
checkFor(output,"[class,load]", "java.lang.Object", "source:");
105102

106103
// -Xlog:class+load=debug
107-
pb = exec("-Xlog:class+load=debug");
108-
checkFor("[class,load]", "java.lang.Object", "source:", "klass:", "super:", "loader:", "bytes:");
104+
output = exec("-Xlog:class+load=debug");
105+
checkFor(output,"[class,load]", "java.lang.Object", "source:", "klass:", "super:", "loader:", "bytes:");
109106

110107
// -Xlog:class+load=off
111-
pb = exec("-Xlog:class+load=off");
112-
checkAbsent("[class,load]");
108+
output = exec("-Xlog:class+load=off");
109+
checkAbsent(output,"[class,load]");
113110

114111
// -XX:+TraceClassLoading
115-
pb = exec("-XX:+TraceClassLoading");
116-
checkFor("[class,load]", "java.lang.Object", "source:");
112+
output = exec("-XX:+TraceClassLoading");
113+
checkFor(output, "[class,load]", "java.lang.Object", "source:");
117114

118115
// -XX:-TraceClassLoading
119-
pb = exec("-XX:-TraceClassLoading");
120-
checkAbsent("[class,load]");
116+
output = exec("-XX:-TraceClassLoading");
117+
checkAbsent(output, "[class,load]");
121118

122119
// -verbose:class
123-
pb = exec("-verbose:class");
124-
checkFor("[class,load]", "java.lang.Object", "source:");
125-
checkFor("[class,unload]", "unloading class");
120+
output = exec("-verbose:class");
121+
checkFor(output,"[class,load]", "java.lang.Object", "source:");
122+
checkFor(output,"[class,unload]", "unloading class");
126123

127124
// -Xlog:class+loader+data=trace
128-
pb = exec("-Xlog:class+loader+data=trace");
129-
checkFor("[class,loader,data]", "create loader data");
125+
output = exec("-Xlog:class+loader+data=trace");
126+
checkFor(output, "[class,loader,data]", "create loader data");
130127

131128
}
132129
}

0 commit comments

Comments
 (0)