author | iklam |
Fri, 22 Nov 2019 15:32:00 -0800 | |
changeset 59236 | e2ee246e44e3 |
parent 58990 | 7f1d2c3a99da |
permissions | -rw-r--r-- |
48138 | 1 |
/* |
53636
962ed57b29c9
8218029: [TESTBUG] Use -Djava.class.path= to specify empty -cp in CDS tests
iklam
parents:
52631
diff
changeset
|
2 |
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. |
48138 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
import jdk.test.lib.Utils; |
|
48516
7d286141598c
8193664: AppCDS tests should use -XX:+UnlockCommercialFeatures when running with commercial JDK
iklam
parents:
48155
diff
changeset
|
26 |
import jdk.test.lib.BuildHelper; |
48138 | 27 |
import jdk.test.lib.JDKToolFinder; |
28 |
import jdk.test.lib.Platform; |
|
29 |
import jdk.test.lib.cds.CDSOptions; |
|
30 |
import jdk.test.lib.cds.CDSTestUtils; |
|
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48516
diff
changeset
|
31 |
import jdk.test.lib.cds.CDSTestUtils.Result; |
48138 | 32 |
import jdk.test.lib.process.ProcessTools; |
33 |
import jdk.test.lib.process.OutputAnalyzer; |
|
34 |
import java.io.File; |
|
54927 | 35 |
import java.io.FileInputStream; |
36 |
import java.io.FileOutputStream; |
|
37 |
import java.io.InputStream; |
|
38 |
import java.net.URI; |
|
39 |
import java.nio.file.DirectoryStream; |
|
40 |
import java.nio.file.Files; |
|
41 |
import java.nio.file.FileSystem; |
|
42 |
import java.nio.file.FileSystems; |
|
43 |
import java.nio.file.Path; |
|
48138 | 44 |
import java.text.SimpleDateFormat; |
50951
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
49931
diff
changeset
|
45 |
import java.util.Arrays; |
48138 | 46 |
import java.util.ArrayList; |
47 |
import java.util.Date; |
|
54927 | 48 |
import java.util.Enumeration; |
49 |
import java.util.regex.Matcher; |
|
50 |
import java.util.regex.Pattern; |
|
51 |
import java.util.zip.ZipEntry; |
|
52 |
import java.util.zip.ZipFile; |
|
53 |
import java.util.zip.ZipOutputStream; |
|
54 |
import jtreg.SkippedException; |
|
55 |
import cdsutils.DynamicDumpHelper; |
|
56 |
||
48138 | 57 |
|
58 |
/** |
|
59 |
* This is a test utility class for common AppCDS test functionality. |
|
60 |
* |
|
61 |
* Various methods use (String ...) for passing VM options. Note that the order |
|
62 |
* of the VM options are important in certain cases. Many methods take arguments like |
|
63 |
* |
|
64 |
* (String prefix[], String suffix[], String... opts) |
|
65 |
* |
|
66 |
* Note that the order of the VM options is: |
|
67 |
* |
|
68 |
* prefix + opts + suffix |
|
69 |
*/ |
|
70 |
public class TestCommon extends CDSTestUtils { |
|
71 |
private static final String JSA_FILE_PREFIX = System.getProperty("user.dir") + |
|
54927 | 72 |
File.separator; |
48138 | 73 |
|
74 |
private static final SimpleDateFormat timeStampFormat = |
|
75 |
new SimpleDateFormat("HH'h'mm'm'ss's'SSS"); |
|
76 |
||
77 |
private static final String timeoutFactor = |
|
78 |
System.getProperty("test.timeout.factor", "1.0"); |
|
79 |
||
80 |
private static String currentArchiveName; |
|
81 |
||
82 |
// Call this method to start new archive with new unique name |
|
83 |
public static void startNewArchiveName() { |
|
84 |
deletePriorArchives(); |
|
54927 | 85 |
currentArchiveName = getNewArchiveName(); |
48138 | 86 |
} |
87 |
||
88 |
// Call this method to get current archive name |
|
89 |
public static String getCurrentArchiveName() { |
|
90 |
return currentArchiveName; |
|
91 |
} |
|
92 |
||
55694
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
54927
diff
changeset
|
93 |
public static void setCurrentArchiveName(String archiveName) { |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
54927
diff
changeset
|
94 |
currentArchiveName = archiveName; |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
54927
diff
changeset
|
95 |
} |
7b7df2be6219
8226406: JVM fails to detect mismatched or corrupt CDS archive
ccheung
parents:
54927
diff
changeset
|
96 |
|
54927 | 97 |
public static String getNewArchiveName() { |
98 |
return getNewArchiveName(null); |
|
99 |
} |
|
100 |
||
101 |
public static String getNewArchiveName(String stem) { |
|
102 |
if (stem == null) { |
|
103 |
stem = "appcds"; |
|
104 |
} |
|
105 |
return JSA_FILE_PREFIX + stem + "-" + |
|
106 |
timeStampFormat.format(new Date()) + ".jsa"; |
|
107 |
} |
|
108 |
||
48138 | 109 |
// Attempt to clean old archives to preserve space |
110 |
// Archives are large artifacts (20Mb or more), and much larger than |
|
111 |
// most other artifacts created in jtreg testing. |
|
112 |
// Therefore it is a good idea to clean the old archives when they are not needed. |
|
113 |
// In most cases the deletion attempt will succeed; on rare occasion the |
|
114 |
// delete operation will fail since the system or VM process still holds a handle |
|
115 |
// to the file; in such cases the File.delete() operation will silently fail, w/o |
|
116 |
// throwing an exception, thus allowing testing to continue. |
|
117 |
public static void deletePriorArchives() { |
|
118 |
File dir = new File(System.getProperty("user.dir")); |
|
119 |
String files[] = dir.list(); |
|
120 |
for (String name : files) { |
|
121 |
if (name.startsWith("appcds-") && name.endsWith(".jsa")) { |
|
122 |
if (!(new File(dir, name)).delete()) |
|
123 |
System.out.println("deletePriorArchives(): delete failed for file " + name); |
|
124 |
} |
|
125 |
} |
|
126 |
} |
|
127 |
||
128 |
// Create AppCDS archive using most common args - convenience method |
|
129 |
// Legacy name preserved for compatibility |
|
52631
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
51894
diff
changeset
|
130 |
public static OutputAnalyzer dump(String appJar, String classList[], |
48138 | 131 |
String... suffix) throws Exception { |
52631
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
51894
diff
changeset
|
132 |
return createArchive(appJar, classList, suffix); |
48138 | 133 |
} |
134 |
||
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
135 |
public static OutputAnalyzer dump(String appJarDir, String appJar, String classList[], |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
136 |
String... suffix) throws Exception { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
137 |
return createArchive(appJarDir, appJar, classList, suffix); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
138 |
} |
48138 | 139 |
|
140 |
// Create AppCDS archive using most common args - convenience method |
|
52631
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
51894
diff
changeset
|
141 |
public static OutputAnalyzer createArchive(String appJar, String classList[], |
48138 | 142 |
String... suffix) throws Exception { |
52631
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
51894
diff
changeset
|
143 |
AppCDSOptions opts = (new AppCDSOptions()).setAppJar(appJar); |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
51894
diff
changeset
|
144 |
opts.setClassList(classList); |
48138 | 145 |
opts.addSuffix(suffix); |
146 |
return createArchive(opts); |
|
147 |
} |
|
148 |
||
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
149 |
public static OutputAnalyzer createArchive(String appJarDir, String appJar, String classList[], |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
150 |
String... suffix) throws Exception { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
151 |
AppCDSOptions opts = (new AppCDSOptions()).setAppJar(appJar); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
152 |
opts.setAppJarDir(appJarDir); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
153 |
opts.setClassList(classList); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
154 |
opts.addSuffix(suffix); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
155 |
return createArchive(opts); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
156 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
157 |
|
54927 | 158 |
// Simulate -Xshare:dump with -XX:ArchiveClassesAtExit. See comments around patchJarForDynamicDump() |
159 |
private static final Class tmp = DynamicDumpHelper.class; |
|
160 |
||
48138 | 161 |
// Create AppCDS archive using appcds options |
162 |
public static OutputAnalyzer createArchive(AppCDSOptions opts) |
|
163 |
throws Exception { |
|
164 |
ArrayList<String> cmd = new ArrayList<String>(); |
|
165 |
startNewArchiveName(); |
|
166 |
||
167 |
for (String p : opts.prefix) cmd.add(p); |
|
168 |
||
169 |
if (opts.appJar != null) { |
|
170 |
cmd.add("-cp"); |
|
171 |
cmd.add(opts.appJar); |
|
54927 | 172 |
File jf = new File(opts.appJar); |
173 |
if (DYNAMIC_DUMP && !jf.isDirectory()) { |
|
174 |
patchJarForDynamicDump(opts.appJar); |
|
175 |
} |
|
48138 | 176 |
} else { |
53636
962ed57b29c9
8218029: [TESTBUG] Use -Djava.class.path= to specify empty -cp in CDS tests
iklam
parents:
52631
diff
changeset
|
177 |
cmd.add("-Djava.class.path="); |
48138 | 178 |
} |
179 |
||
54927 | 180 |
if (opts.archiveName == null) { |
48138 | 181 |
opts.archiveName = getCurrentArchiveName(); |
52631
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
51894
diff
changeset
|
182 |
} |
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
51894
diff
changeset
|
183 |
|
54927 | 184 |
if (DYNAMIC_DUMP) { |
185 |
cmd.add("-Xshare:on"); |
|
186 |
cmd.add("-XX:ArchiveClassesAtExit=" + opts.archiveName); |
|
187 |
||
188 |
cmd.add("-Xlog:cds"); |
|
189 |
cmd.add("-Xlog:cds+dynamic"); |
|
190 |
boolean mainModuleSpecified = false; |
|
191 |
boolean patchModuleSpecified = false; |
|
192 |
for (String s : opts.suffix) { |
|
193 |
if (s.length() == 0) { |
|
194 |
continue; |
|
195 |
} |
|
196 |
if (s.equals("-m")) { |
|
197 |
mainModuleSpecified = true; |
|
198 |
} |
|
199 |
if (s.startsWith("--patch-module=")) { |
|
200 |
patchModuleSpecified = true; |
|
201 |
} |
|
202 |
cmd.add(s); |
|
203 |
} |
|
204 |
||
205 |
if (opts.appJar != null) { |
|
206 |
// classlist is supported only when we have a Jar file to patch (to insert |
|
207 |
// cdsutils.DynamicDumpHelper) |
|
208 |
if (opts.classList == null) { |
|
209 |
throw new RuntimeException("test.dynamic.dump requires classList file"); |
|
210 |
} |
|
211 |
||
212 |
if (!mainModuleSpecified && !patchModuleSpecified) { |
|
213 |
cmd.add("cdsutils.DynamicDumpHelper"); |
|
214 |
File classListFile = makeClassList(opts.classList); |
|
215 |
cmd.add(classListFile.getPath()); |
|
216 |
} |
|
217 |
} else { |
|
218 |
if (!mainModuleSpecified && !patchModuleSpecified) { |
|
219 |
// If you have an empty classpath, you cannot specify a classlist! |
|
220 |
if (opts.classList != null && opts.classList.length > 0) { |
|
58300
c3b93d6603f5
8231367: [TESTBUG] ParallelLoadTest.java fails with "test.dynamic.dump not supported"
iklam
parents:
57567
diff
changeset
|
221 |
throw new RuntimeException("test.dynamic.dump is not supported with an empty classpath while the classlist is not empty"); |
54927 | 222 |
} |
223 |
cmd.add("-version"); |
|
224 |
} |
|
225 |
} |
|
226 |
} else { |
|
227 |
// static dump |
|
228 |
cmd.add("-Xshare:dump"); |
|
229 |
cmd.add("-XX:SharedArchiveFile=" + opts.archiveName); |
|
230 |
||
231 |
if (opts.classList != null) { |
|
232 |
File classListFile = makeClassList(opts.classList); |
|
233 |
cmd.add("-XX:ExtraSharedClassListFile=" + classListFile.getPath()); |
|
234 |
} |
|
235 |
for (String s : opts.suffix) { |
|
236 |
cmd.add(s); |
|
237 |
} |
|
238 |
} |
|
48138 | 239 |
|
240 |
String[] cmdLine = cmd.toArray(new String[cmd.size()]); |
|
51894
1e7353bd1499
8202282: [TESTBUG] appcds TestCommon.makeCommandLineForAppCDS() can be removed
ccheung
parents:
51370
diff
changeset
|
241 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine); |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
242 |
if (opts.appJarDir != null) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
243 |
pb.directory(new File(opts.appJarDir)); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
244 |
} |
58310
81134def991d
8231097: [TESTBUG] runtime/cds/appcds/DirClasspathTest.java can fail with a mapping error
ccheung
parents:
58300
diff
changeset
|
245 |
|
81134def991d
8231097: [TESTBUG] runtime/cds/appcds/DirClasspathTest.java can fail with a mapping error
ccheung
parents:
58300
diff
changeset
|
246 |
OutputAnalyzer output = executeAndLog(pb, "dump"); |
81134def991d
8231097: [TESTBUG] runtime/cds/appcds/DirClasspathTest.java can fail with a mapping error
ccheung
parents:
58300
diff
changeset
|
247 |
if (DYNAMIC_DUMP && isUnableToMap(output)) { |
81134def991d
8231097: [TESTBUG] runtime/cds/appcds/DirClasspathTest.java can fail with a mapping error
ccheung
parents:
58300
diff
changeset
|
248 |
throw new SkippedException(UnableToMapMsg); |
81134def991d
8231097: [TESTBUG] runtime/cds/appcds/DirClasspathTest.java can fail with a mapping error
ccheung
parents:
58300
diff
changeset
|
249 |
} |
81134def991d
8231097: [TESTBUG] runtime/cds/appcds/DirClasspathTest.java can fail with a mapping error
ccheung
parents:
58300
diff
changeset
|
250 |
return output; |
48138 | 251 |
} |
252 |
||
54340
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
253 |
// This allows you to run the AppCDS tests with JFR enabled at runtime (though not at |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
254 |
// dump time, as that's uncommon for typical AppCDS users). |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
255 |
// |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
256 |
// To run in this special mode, add the following to your jtreg command-line |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
257 |
// -Dtest.cds.run.with.jfr=true |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
258 |
// |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
259 |
// Some AppCDS tests are not compatible with this mode. See the group |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
260 |
// hotspot_appcds_with_jfr in ../../TEST.ROOT for details. |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
261 |
private static final boolean RUN_WITH_JFR = Boolean.getBoolean("test.cds.run.with.jfr"); |
54927 | 262 |
// This method simulates -Xshare:dump with -XX:ArchiveClassesAtExit. This way, we |
263 |
// can re-use many tests (outside of the ./dynamicArchive directory) for testing |
|
264 |
// general features of JDK-8215311 (JEP 350: Dynamic CDS Archives). |
|
265 |
// |
|
266 |
// We insert the cdsutils/DynamicDumpHelper.class into the first Jar file in |
|
267 |
// the classpath. We use this class to load all the classes specified in the classlist. |
|
268 |
// |
|
269 |
// There's no need to change the run-time command-line: in this special mode, two |
|
270 |
// archives are involved. The command-line specifies only the top archive. However, |
|
271 |
// the location of the base archive is recorded in the top archive, so it can be |
|
272 |
// determined by the JVM at runtime start-up. |
|
273 |
// |
|
274 |
// To run in this special mode, specify the following in your jtreg command-line |
|
275 |
// -Dtest.dynamic.cds.archive=true |
|
276 |
// |
|
277 |
// Note that some tests are not compatible with this special mode, including |
|
278 |
// + Tests in ./dynamicArchive: these tests are specifically written for |
|
279 |
// dynamic archive, and do not use TestCommon.createArchive(), which works |
|
280 |
// together with patchJarForDynamicDump(). |
|
281 |
// + Tests related to cached objects and shared strings: dynamic dumping |
|
282 |
// does not support these. |
|
283 |
// + Custom loader tests: DynamicDumpHelper doesn't support the required |
|
284 |
// classlist syntax. (FIXME). |
|
285 |
// + Extra symbols and extra strings. |
|
286 |
// See the hotspot_appcds_dynamic in ../../TEST.ROOT for details. |
|
287 |
// |
|
288 |
// To run all tests that are compatible with this mode: |
|
289 |
// cd test/hotspot/jtreg |
|
290 |
// jtreg -Dtest.dynamic.cds.archive=true :hotspot_appcds_dynamic |
|
291 |
// |
|
292 |
private static void patchJarForDynamicDump(String cp) throws Exception { |
|
293 |
System.out.println("patchJarForDynamicDump: classpath = " + cp); |
|
294 |
String firstJar = cp; |
|
295 |
int n = firstJar.indexOf(File.pathSeparator); |
|
296 |
if (n > 0) { |
|
297 |
firstJar = firstJar.substring(0, n); |
|
298 |
} |
|
299 |
String classDir = System.getProperty("test.classes"); |
|
300 |
String expected1 = classDir + File.separator; |
|
301 |
String expected2 = System.getProperty("user.dir") + File.separator; |
|
302 |
||
303 |
if (!firstJar.startsWith(expected1) && !firstJar.startsWith(expected2)) { |
|
304 |
throw new RuntimeException("FIXME: jar file not at a supported location ('" |
|
305 |
+ expected1 + "', or '" + expected2 + "'): " + firstJar); |
|
306 |
} |
|
307 |
||
308 |
String replaceJar = firstJar + ".tmp"; |
|
309 |
String patchClass = "cdsutils/DynamicDumpHelper.class"; |
|
310 |
ZipFile zipFile = new ZipFile(firstJar); |
|
311 |
byte[] buf = new byte[1024]; |
|
312 |
int len; |
|
313 |
if (zipFile.getEntry(patchClass) == null) { |
|
314 |
FileOutputStream fout = new FileOutputStream(replaceJar); |
|
315 |
final ZipOutputStream zos = new ZipOutputStream(fout); |
|
316 |
||
317 |
zos.putNextEntry(new ZipEntry(patchClass)); |
|
318 |
InputStream is = new FileInputStream(classDir + File.separator + patchClass); |
|
319 |
while ((len = (is.read(buf))) > 0) { |
|
320 |
zos.write(buf, 0, len); |
|
321 |
} |
|
322 |
zos.closeEntry(); |
|
323 |
is.close(); |
|
324 |
||
325 |
for (Enumeration e = zipFile.entries(); e.hasMoreElements(); ) { |
|
326 |
ZipEntry entryIn = (ZipEntry) e.nextElement(); |
|
327 |
zos.putNextEntry(entryIn); |
|
328 |
is = zipFile.getInputStream(entryIn); |
|
329 |
while ((len = is.read(buf)) > 0) { |
|
330 |
zos.write(buf, 0, len); |
|
331 |
} |
|
332 |
zos.closeEntry(); |
|
333 |
is.close(); |
|
334 |
} |
|
335 |
||
336 |
zos.close(); |
|
337 |
fout.close(); |
|
338 |
zipFile.close(); |
|
339 |
||
340 |
File oldFile = new File(firstJar); |
|
341 |
File newFile = new File(replaceJar); |
|
342 |
oldFile.delete(); |
|
343 |
newFile.renameTo(oldFile); |
|
344 |
System.out.println("firstJar = " + firstJar + " Modified"); |
|
345 |
} else { |
|
58990
7f1d2c3a99da
8233855: [TESTBUG] appcds/FieldLayoutFlags.java failed to clean up files after test
iklam
parents:
58528
diff
changeset
|
346 |
zipFile.close(); |
54927 | 347 |
System.out.println("firstJar = " + firstJar); |
348 |
} |
|
349 |
} |
|
48138 | 350 |
|
351 |
// Execute JVM using AppCDS archive with specified AppCDSOptions |
|
352 |
public static OutputAnalyzer runWithArchive(AppCDSOptions opts) |
|
353 |
throws Exception { |
|
354 |
||
355 |
ArrayList<String> cmd = new ArrayList<String>(); |
|
356 |
||
357 |
for (String p : opts.prefix) cmd.add(p); |
|
358 |
||
359 |
cmd.add("-Xshare:" + opts.xShareMode); |
|
360 |
cmd.add("-showversion"); |
|
361 |
cmd.add("-XX:SharedArchiveFile=" + getCurrentArchiveName()); |
|
362 |
cmd.add("-Dtest.timeout.factor=" + timeoutFactor); |
|
363 |
||
364 |
if (opts.appJar != null) { |
|
365 |
cmd.add("-cp"); |
|
366 |
cmd.add(opts.appJar); |
|
367 |
} |
|
368 |
||
369 |
for (String s : opts.suffix) cmd.add(s); |
|
370 |
||
54340
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
371 |
if (RUN_WITH_JFR) { |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
372 |
boolean usesJFR = false; |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
373 |
for (String s : cmd) { |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
374 |
if (s.startsWith("-XX:StartFlightRecording=") || s.startsWith("-XX:FlightRecorderOptions")) { |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
375 |
System.out.println("JFR option might have been specified. Don't interfere: " + s); |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
376 |
usesJFR = true; |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
377 |
break; |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
378 |
} |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
379 |
} |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
380 |
if (!usesJFR) { |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
381 |
System.out.println("JFR option not specified. Enabling JFR ..."); |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
382 |
cmd.add(0, "-XX:StartFlightRecording=dumponexit=true"); |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
383 |
System.out.println(cmd); |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
384 |
} |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
385 |
} |
2221f042556d
8221351: Crash in KlassFactory::check_shared_class_file_load_hook
iklam
parents:
53636
diff
changeset
|
386 |
|
48138 | 387 |
String[] cmdLine = cmd.toArray(new String[cmd.size()]); |
51894
1e7353bd1499
8202282: [TESTBUG] appcds TestCommon.makeCommandLineForAppCDS() can be removed
ccheung
parents:
51370
diff
changeset
|
388 |
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, cmdLine); |
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
389 |
if (opts.appJarDir != null) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
390 |
pb.directory(new File(opts.appJarDir)); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
391 |
} |
48138 | 392 |
return executeAndLog(pb, "exec"); |
393 |
} |
|
394 |
||
395 |
||
396 |
public static OutputAnalyzer execCommon(String... suffix) throws Exception { |
|
397 |
AppCDSOptions opts = (new AppCDSOptions()); |
|
398 |
opts.addSuffix(suffix); |
|
399 |
return runWithArchive(opts); |
|
400 |
} |
|
401 |
||
48979
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48516
diff
changeset
|
402 |
// This is the new API for running a Java process with CDS enabled. |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48516
diff
changeset
|
403 |
// See comments in the CDSTestUtils.Result class for how to use this method. |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48516
diff
changeset
|
404 |
public static Result run(String... suffix) throws Exception { |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48516
diff
changeset
|
405 |
AppCDSOptions opts = (new AppCDSOptions()); |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48516
diff
changeset
|
406 |
opts.addSuffix(suffix); |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48516
diff
changeset
|
407 |
return new Result(opts, runWithArchive(opts)); |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48516
diff
changeset
|
408 |
} |
514c73a1955b
8179249: Improve process output analysis in CDS tests
iklam
parents:
48516
diff
changeset
|
409 |
|
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
410 |
public static Result runWithRelativePath(String jarDir, String... suffix) throws Exception { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
411 |
AppCDSOptions opts = (new AppCDSOptions()); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
412 |
opts.setAppJarDir(jarDir); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
413 |
opts.addSuffix(suffix); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
414 |
return new Result(opts, runWithArchive(opts)); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
415 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
416 |
|
48138 | 417 |
public static OutputAnalyzer exec(String appJar, String... suffix) throws Exception { |
418 |
AppCDSOptions opts = (new AppCDSOptions()).setAppJar(appJar); |
|
419 |
opts.addSuffix(suffix); |
|
420 |
return runWithArchive(opts); |
|
421 |
} |
|
422 |
||
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
423 |
public static Result runWithModules(String prefix[], String upgrademodulepath, String modulepath, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
424 |
String mid, String... testClassArgs) throws Exception { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
425 |
AppCDSOptions opts = makeModuleOptions(prefix, upgrademodulepath, modulepath, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
426 |
mid, testClassArgs); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
427 |
return new Result(opts, runWithArchive(opts)); |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
428 |
} |
48138 | 429 |
|
430 |
public static OutputAnalyzer execAuto(String... suffix) throws Exception { |
|
431 |
AppCDSOptions opts = (new AppCDSOptions()); |
|
432 |
opts.addSuffix(suffix).setXShareMode("auto"); |
|
433 |
return runWithArchive(opts); |
|
434 |
} |
|
435 |
||
436 |
public static OutputAnalyzer execOff(String... suffix) throws Exception { |
|
437 |
AppCDSOptions opts = (new AppCDSOptions()); |
|
438 |
opts.addSuffix(suffix).setXShareMode("off"); |
|
439 |
return runWithArchive(opts); |
|
440 |
} |
|
441 |
||
442 |
||
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
443 |
private static AppCDSOptions makeModuleOptions(String prefix[], String upgrademodulepath, String modulepath, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
444 |
String mid, String testClassArgs[]) { |
48138 | 445 |
AppCDSOptions opts = (new AppCDSOptions()); |
446 |
||
447 |
opts.addPrefix(prefix); |
|
448 |
if (upgrademodulepath == null) { |
|
449 |
opts.addSuffix("-p", modulepath, "-m", mid); |
|
450 |
} else { |
|
451 |
opts.addSuffix("--upgrade-module-path", upgrademodulepath, |
|
452 |
"-p", modulepath, "-m", mid); |
|
453 |
} |
|
454 |
opts.addSuffix(testClassArgs); |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
455 |
return opts; |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
456 |
} |
48138 | 457 |
|
49739
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
458 |
public static OutputAnalyzer execModule(String prefix[], String upgrademodulepath, String modulepath, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
459 |
String mid, String... testClassArgs) |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
460 |
throws Exception { |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
461 |
AppCDSOptions opts = makeModuleOptions(prefix, upgrademodulepath, modulepath, |
00805b129186
8194812: Extend class-data sharing to support the module path
ccheung
parents:
48979
diff
changeset
|
462 |
mid, testClassArgs); |
48138 | 463 |
return runWithArchive(opts); |
464 |
} |
|
465 |
||
466 |
// A common operation: dump, then check results |
|
52631
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
51894
diff
changeset
|
467 |
public static OutputAnalyzer testDump(String appJar, String classList[], |
48138 | 468 |
String... suffix) throws Exception { |
52631
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
51894
diff
changeset
|
469 |
OutputAnalyzer output = dump(appJar, classList, suffix); |
54927 | 470 |
if (DYNAMIC_DUMP) { |
471 |
output.shouldContain("Written dynamic archive"); |
|
472 |
} else { |
|
473 |
output.shouldContain("Loading classes to share"); |
|
474 |
} |
|
48138 | 475 |
output.shouldHaveExitValue(0); |
476 |
return output; |
|
477 |
} |
|
478 |
||
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
479 |
public static OutputAnalyzer testDump(String appJarDir, String appJar, String classList[], |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
480 |
String... suffix) throws Exception { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
481 |
OutputAnalyzer output = dump(appJarDir, appJar, classList, suffix); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
482 |
if (DYNAMIC_DUMP) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
483 |
output.shouldContain("Written dynamic archive"); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
484 |
} else { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
485 |
output.shouldContain("Loading classes to share"); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
486 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
487 |
output.shouldHaveExitValue(0); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
488 |
return output; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
489 |
} |
48138 | 490 |
|
491 |
/** |
|
52631
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
51894
diff
changeset
|
492 |
* Simple test -- dump and execute appJar with the given classList in classlist. |
48138 | 493 |
*/ |
52631
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
51894
diff
changeset
|
494 |
public static OutputAnalyzer test(String appJar, String classList[], String... args) |
48138 | 495 |
throws Exception { |
52631
3009ca99de32
8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents:
51894
diff
changeset
|
496 |
testDump(appJar, classList); |
48138 | 497 |
|
498 |
OutputAnalyzer output = exec(appJar, args); |
|
499 |
return checkExec(output); |
|
500 |
} |
|
501 |
||
502 |
||
503 |
public static OutputAnalyzer checkExecReturn(OutputAnalyzer output, int ret, |
|
504 |
boolean checkContain, String... matches) throws Exception { |
|
505 |
try { |
|
506 |
for (String s : matches) { |
|
507 |
if (checkContain) { |
|
508 |
output.shouldContain(s); |
|
509 |
} else { |
|
510 |
output.shouldNotContain(s); |
|
511 |
} |
|
512 |
} |
|
513 |
output.shouldHaveExitValue(ret); |
|
514 |
} catch (Exception e) { |
|
515 |
checkCommonExecExceptions(output, e); |
|
516 |
} |
|
517 |
||
518 |
return output; |
|
519 |
} |
|
520 |
||
521 |
// Convenience concatenation utils |
|
522 |
public static String[] list(String ...args) { |
|
523 |
return args; |
|
524 |
} |
|
525 |
||
526 |
||
527 |
public static String[] list(String arg, int count) { |
|
528 |
ArrayList<String> stringList = new ArrayList<String>(); |
|
529 |
for (int i = 0; i < count; i++) { |
|
530 |
stringList.add(arg); |
|
531 |
} |
|
532 |
||
533 |
String outputArray[] = stringList.toArray(new String[stringList.size()]); |
|
534 |
return outputArray; |
|
535 |
} |
|
536 |
||
537 |
||
538 |
public static String[] concat(String... args) { |
|
539 |
return list(args); |
|
540 |
} |
|
541 |
||
542 |
||
543 |
public static String[] concat(String prefix[], String... extra) { |
|
544 |
ArrayList<String> list = new ArrayList<String>(); |
|
545 |
for (String s : prefix) { |
|
546 |
list.add(s); |
|
547 |
} |
|
548 |
for (String s : extra) { |
|
549 |
list.add(s); |
|
550 |
} |
|
551 |
||
552 |
return list.toArray(new String[list.size()]); |
|
553 |
} |
|
554 |
||
54927 | 555 |
public static String[] concat(String prefix, String[] extra) { |
556 |
ArrayList<String> list = new ArrayList<String>(); |
|
557 |
list.add(prefix); |
|
558 |
for (String s : extra) { |
|
559 |
list.add(s); |
|
560 |
} |
|
561 |
||
562 |
return list.toArray(new String[list.size()]); |
|
563 |
} |
|
48138 | 564 |
|
565 |
// ===================== Concatenate paths |
|
566 |
public static String concatPaths(String... paths) { |
|
567 |
String prefix = ""; |
|
568 |
String s = ""; |
|
569 |
for (String p : paths) { |
|
570 |
s += prefix; |
|
571 |
s += p; |
|
572 |
prefix = File.pathSeparator; |
|
573 |
} |
|
574 |
return s; |
|
575 |
} |
|
576 |
||
577 |
||
578 |
public static String getTestJar(String jar) { |
|
579 |
File jarFile = CDSTestUtils.getTestArtifact(jar, true); |
|
580 |
if (!jarFile.isFile()) { |
|
581 |
throw new RuntimeException("Not a regular file: " + jarFile.getPath()); |
|
582 |
} |
|
583 |
return jarFile.getPath(); |
|
584 |
} |
|
585 |
||
586 |
||
587 |
public static String getTestDir(String d) { |
|
588 |
File dirFile = CDSTestUtils.getTestArtifact(d, true); |
|
589 |
if (!dirFile.isDirectory()) { |
|
590 |
throw new RuntimeException("Not a directory: " + dirFile.getPath()); |
|
591 |
} |
|
592 |
return dirFile.getPath(); |
|
593 |
} |
|
50951
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
49931
diff
changeset
|
594 |
|
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
49931
diff
changeset
|
595 |
public static boolean checkOutputStrings(String outputString1, |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
49931
diff
changeset
|
596 |
String outputString2, |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
49931
diff
changeset
|
597 |
String split_regex) { |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
49931
diff
changeset
|
598 |
String[] sa1 = outputString1.split(split_regex); |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
49931
diff
changeset
|
599 |
String[] sa2 = outputString2.split(split_regex); |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
49931
diff
changeset
|
600 |
Arrays.sort(sa1); |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
49931
diff
changeset
|
601 |
Arrays.sort(sa2); |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
49931
diff
changeset
|
602 |
|
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
49931
diff
changeset
|
603 |
int i = 0; |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
49931
diff
changeset
|
604 |
for (String s : sa1) { |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
49931
diff
changeset
|
605 |
if (!s.equals(sa2[i])) { |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
49931
diff
changeset
|
606 |
throw new RuntimeException(s + " is different from " + sa2[i]); |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
49931
diff
changeset
|
607 |
} |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
49931
diff
changeset
|
608 |
i ++; |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
49931
diff
changeset
|
609 |
} |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
49931
diff
changeset
|
610 |
return true; |
b96466cdfc45
8202035: Archive the set of ModuleDescriptor and ModuleReference objects for observable system modules with unnamed initial module.
jiangli
parents:
49931
diff
changeset
|
611 |
} |
54927 | 612 |
|
613 |
static Pattern pattern; |
|
614 |
||
58528
d0519b8bd8d9
8231529: [TESTBUG] runtime/cds/appcds/dynamicArchive/DynamicLotsOfClasses.java shouldn't wrap SkippedException into Exception
ccheung
parents:
58310
diff
changeset
|
615 |
static void findAllClasses(ArrayList<String> list) throws Exception { |
54927 | 616 |
// Find all the classes in the jrt file system |
617 |
pattern = Pattern.compile("/modules/[a-z.]*[a-z]+/([^-]*)[.]class"); |
|
618 |
FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/")); |
|
619 |
Path base = fs.getPath("/modules/"); |
|
620 |
findAllClassesAtPath(base, list); |
|
621 |
} |
|
622 |
||
58528
d0519b8bd8d9
8231529: [TESTBUG] runtime/cds/appcds/dynamicArchive/DynamicLotsOfClasses.java shouldn't wrap SkippedException into Exception
ccheung
parents:
58310
diff
changeset
|
623 |
private static void findAllClassesAtPath(Path p, ArrayList<String> list) throws Exception { |
54927 | 624 |
try (DirectoryStream<Path> stream = Files.newDirectoryStream(p)) { |
625 |
for (Path entry: stream) { |
|
626 |
Matcher matcher = pattern.matcher(entry.toString()); |
|
627 |
if (matcher.find()) { |
|
628 |
String className = matcher.group(1); |
|
629 |
list.add(className); |
|
630 |
} |
|
631 |
try { |
|
632 |
findAllClassesAtPath(entry, list); |
|
58528
d0519b8bd8d9
8231529: [TESTBUG] runtime/cds/appcds/dynamicArchive/DynamicLotsOfClasses.java shouldn't wrap SkippedException into Exception
ccheung
parents:
58310
diff
changeset
|
633 |
} catch (Exception ex) {} |
54927 | 634 |
} |
635 |
} |
|
636 |
} |
|
55524
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
637 |
|
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
638 |
public static String composeRelPath(String appJar) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
639 |
int idx = appJar.lastIndexOf(File.separator); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
640 |
String jarName = appJar.substring(idx + 1); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
641 |
String jarDir = appJar.substring(0, idx); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
642 |
String lastDir = jarDir.substring(jarDir.lastIndexOf(File.separator)); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
643 |
String relPath = jarDir + File.separator + ".." + File.separator + lastDir; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
644 |
String newJar = relPath + File.separator + jarName; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
645 |
return newJar; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
646 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
647 |
|
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
648 |
|
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
649 |
public static File createSymLink(String appJar) throws Exception { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
650 |
int idx = appJar.lastIndexOf(File.separator); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
651 |
String jarName = appJar.substring(idx + 1); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
652 |
String jarDir = appJar.substring(0, idx); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
653 |
File origJar = new File(jarDir, jarName); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
654 |
String linkedJarName = "linked_" + jarName; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
655 |
File linkedJar = null; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
656 |
if (!Platform.isWindows()) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
657 |
linkedJar = new File(jarDir, linkedJarName); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
658 |
if (linkedJar.exists()) { |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
659 |
linkedJar.delete(); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
660 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
661 |
Files.createSymbolicLink(linkedJar.toPath(), origJar.toPath()); |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
662 |
} |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
663 |
return linkedJar; |
b279ae9843b8
8211723: AppCDS: referring to a jar file in any way other than exactly how it was done during dumping doesn't work
ccheung
parents:
54927
diff
changeset
|
664 |
} |
59236
e2ee246e44e3
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
iklam
parents:
58990
diff
changeset
|
665 |
|
e2ee246e44e3
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
iklam
parents:
58990
diff
changeset
|
666 |
// Remove all UL log messages from a JVM's STDOUT (such as those printed by -Xlog:cds) |
e2ee246e44e3
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
iklam
parents:
58990
diff
changeset
|
667 |
static Pattern logPattern = Pattern.compile("^\\[[0-9. ]*s\\].*"); |
e2ee246e44e3
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
iklam
parents:
58990
diff
changeset
|
668 |
public static String filterOutLogs(String stdout) { |
e2ee246e44e3
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
iklam
parents:
58990
diff
changeset
|
669 |
StringBuilder sb = new StringBuilder(); |
e2ee246e44e3
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
iklam
parents:
58990
diff
changeset
|
670 |
String prefix = ""; |
e2ee246e44e3
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
iklam
parents:
58990
diff
changeset
|
671 |
for (String line : stdout.split("\n")) { |
e2ee246e44e3
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
iklam
parents:
58990
diff
changeset
|
672 |
if (logPattern.matcher(line).matches()) { |
e2ee246e44e3
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
iklam
parents:
58990
diff
changeset
|
673 |
continue; |
e2ee246e44e3
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
iklam
parents:
58990
diff
changeset
|
674 |
} |
e2ee246e44e3
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
iklam
parents:
58990
diff
changeset
|
675 |
sb.append(prefix); |
e2ee246e44e3
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
iklam
parents:
58990
diff
changeset
|
676 |
sb.append(line); |
e2ee246e44e3
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
iklam
parents:
58990
diff
changeset
|
677 |
prefix = "\n"; |
e2ee246e44e3
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
iklam
parents:
58990
diff
changeset
|
678 |
} |
e2ee246e44e3
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
iklam
parents:
58990
diff
changeset
|
679 |
if (stdout.endsWith("\n")) { |
e2ee246e44e3
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
iklam
parents:
58990
diff
changeset
|
680 |
// String.split("A\n") returns {"A"}, not {"A", ""}. |
e2ee246e44e3
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
iklam
parents:
58990
diff
changeset
|
681 |
sb.append("\n"); |
e2ee246e44e3
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
iklam
parents:
58990
diff
changeset
|
682 |
} |
e2ee246e44e3
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
iklam
parents:
58990
diff
changeset
|
683 |
return sb.toString(); |
e2ee246e44e3
8234622: [TESTBUG] ArchivedModuleCompareTest.java fails with -vmoptions:-Xlog:cds
iklam
parents:
58990
diff
changeset
|
684 |
} |
48138 | 685 |
} |