44
44
import jdk .test .lib .classloader .ClassUnloadCommon ;
45
45
46
46
public class ClassLoadUnloadTest {
47
- private static OutputAnalyzer out ;
48
- private static ProcessBuilder pb ;
49
47
private static class ClassUnloadTestMain {
50
48
public static void main (String ... args ) throws Exception {
51
49
String className = "test.Empty" ;
@@ -56,63 +54,62 @@ public static void main(String... args) throws Exception {
56
54
}
57
55
}
58
56
59
- static void checkFor (String ... outputStrings ) throws Exception {
60
- out = new OutputAnalyzer (pb .start ());
57
+ static void checkFor (OutputAnalyzer output , String ... outputStrings ) throws Exception {
61
58
for (String s : outputStrings ) {
62
- out .shouldContain (s );
59
+ output .shouldContain (s );
63
60
}
64
- out .shouldHaveExitValue (0 );
65
61
}
66
62
67
- static void checkAbsent (String ... outputStrings ) throws Exception {
68
- out = new OutputAnalyzer (pb .start ());
63
+ static void checkAbsent (OutputAnalyzer output , String ... outputStrings ) throws Exception {
69
64
for (String s : outputStrings ) {
70
- out .shouldNotContain (s );
65
+ output .shouldNotContain (s );
71
66
}
72
- out .shouldHaveExitValue (0 );
73
67
}
74
68
75
69
// 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 {
77
71
List <String > argsList = new ArrayList <>();
78
72
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 ;
84
79
}
85
80
86
81
public static void main (String ... args ) throws Exception {
87
82
83
+ OutputAnalyzer output ;
84
+
88
85
// -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" );
91
88
92
89
// -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]" );
95
92
96
93
// -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:" );
99
96
100
97
// -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:" );
103
100
104
101
// -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]" );
107
104
108
105
// -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" );
112
109
113
110
// -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" );
116
113
117
114
}
118
115
}
0 commit comments