31
31
import java .util .regex .Matcher ;
32
32
33
33
import jdk .test .lib .Asserts ;
34
+ import jdk .test .lib .ByteCodeLoader ;
35
+ import jdk .test .lib .compiler .InMemoryJavaCompiler ;
34
36
import jdk .test .lib .process .OutputAnalyzer ;
35
37
import jdk .test .lib .process .ProcessTools ;
36
38
import jdk .test .whitebox .WhiteBox ;
@@ -91,9 +93,6 @@ private static boolean check(String line) {
91
93
}
92
94
93
95
private static void testMetaSpaceUpdate () throws Exception {
94
- // Propagate test.src for the jar file.
95
- String testSrc = "-Dtest.src=" + System .getProperty ("test.src" , "." );
96
-
97
96
ProcessBuilder pb =
98
97
ProcessTools .createTestJvm (
99
98
"-Xlog:gc*" ,
@@ -102,7 +101,7 @@ private static void testMetaSpaceUpdate() throws Exception {
102
101
"-XX:+WhiteBoxAPI" ,
103
102
"-Xmx1000M" ,
104
103
"-Xms1000M" ,
105
- testSrc , StressMetaSpace .class .getName ());
104
+ StressMetaSpace .class .getName ());
106
105
107
106
OutputAnalyzer output = null ;
108
107
try {
@@ -117,29 +116,20 @@ private static void testMetaSpaceUpdate() throws Exception {
117
116
}
118
117
119
118
static class StressMetaSpace {
120
- private static URL [] urls = new URL [1 ];
121
-
122
- static {
123
- try {
124
- File jarFile = new File (System .getProperty ("test.src" ) + "/testcases.jar" );
125
- urls [0 ] = jarFile .toURI ().toURL ();
126
- } catch (Exception e ) {
127
- e .printStackTrace ();
128
- }
129
- }
130
119
131
120
public static void main (String args []) {
132
- WhiteBox wb = WhiteBox .getWhiteBox ();
133
- for (int i = 0 ; i < 10000 ; i ++) {
134
- loadClass (wb );
135
- }
136
- wb .fullGC ();
121
+ loadManyClasses ();
122
+ WhiteBox .getWhiteBox ().fullGC ();
137
123
}
138
124
139
- public static void loadClass (WhiteBox wb ) {
125
+ public static void loadManyClasses () {
126
+ String className = "Tmp" ;
127
+ String sourceCode = "public class Tmp {}" ;
128
+ byte [] byteCode = InMemoryJavaCompiler .compile (className , sourceCode );
140
129
try {
141
- URLClassLoader ucl = new URLClassLoader (urls );
142
- Class .forName ("case00" , false , ucl );
130
+ for (int i = 0 ; i < 10000 ; i ++) {
131
+ ByteCodeLoader .load (className , byteCode );
132
+ }
143
133
} catch (Exception e ) {
144
134
e .printStackTrace ();
145
135
}
0 commit comments