42
42
import java .util .List ;
43
43
44
44
public class ClassLoadUnloadTest {
45
- private static OutputAnalyzer out ;
46
- private static ProcessBuilder pb ;
47
45
private static class ClassUnloadTestMain {
48
46
public static void main (String ... args ) throws Exception {
49
47
String className = "test.Empty" ;
@@ -54,79 +52,78 @@ public static void main(String... args) throws Exception {
54
52
}
55
53
}
56
54
57
- static void checkFor (String ... outputStrings ) throws Exception {
58
- out = new OutputAnalyzer (pb .start ());
55
+ static void checkFor (OutputAnalyzer output , String ... outputStrings ) throws Exception {
59
56
for (String s : outputStrings ) {
60
- out .shouldContain (s );
57
+ output .shouldContain (s );
61
58
}
62
- out .shouldHaveExitValue (0 );
63
59
}
64
60
65
- static void checkAbsent (String ... outputStrings ) throws Exception {
66
- out = new OutputAnalyzer (pb .start ());
61
+ static void checkAbsent (OutputAnalyzer output , String ... outputStrings ) throws Exception {
67
62
for (String s : outputStrings ) {
68
- out .shouldNotContain (s );
63
+ output .shouldNotContain (s );
69
64
}
70
- out .shouldHaveExitValue (0 );
71
65
}
72
66
73
67
// 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 {
75
69
List <String > argsList = new ArrayList <>();
76
70
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 ;
82
77
}
83
78
84
79
public static void main (String ... args ) throws Exception {
85
80
81
+ OutputAnalyzer output ;
82
+
86
83
// -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" );
89
86
90
87
// -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]" );
93
90
94
91
// -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" );
97
94
98
95
// -XX:-TraceClassUnloading
99
- pb = exec ("-XX:-TraceClassUnloading" );
100
- checkAbsent ("[class,unload]" );
96
+ output = exec ("-XX:-TraceClassUnloading" );
97
+ checkAbsent (output , "[class,unload]" );
101
98
102
99
// -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:" );
105
102
106
103
// -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:" );
109
106
110
107
// -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]" );
113
110
114
111
// -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:" );
117
114
118
115
// -XX:-TraceClassLoading
119
- pb = exec ("-XX:-TraceClassLoading" );
120
- checkAbsent ("[class,load]" );
116
+ output = exec ("-XX:-TraceClassLoading" );
117
+ checkAbsent (output , "[class,load]" );
121
118
122
119
// -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" );
126
123
127
124
// -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" );
130
127
131
128
}
132
129
}
0 commit comments