Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8261455: Automatically generate the CDS archive if necessary #5997

Closed
wants to merge 8 commits into from
@@ -276,6 +276,28 @@ private static void testAutoCreateSharedArchive() throws Exception {
throw new RuntimeException("Shared archive " + modBaseName + " should not automatically be generated");
}

// 15 Create an archive with only dynamic magic (size of 4)
print("15 Create an archive with only dynamic magic (size of 4)");
String magicOnly = startNewArchive("magic-only");
copiedJsa = CDSArchiveUtils.createMagicOnlyFile(magicOnly, false/*dynamic*/);
ft1 = Files.getLastModifiedTime(Paths.get(magicOnly));
run(magicOnly,
"-Xshare:auto",
"-XX:+AutoCreateSharedArchive",
"-Xlog:cds",
"-Xlog:cds+dynamic=info",
"-cp", appJar,
mainAppClass)
.assertAbnormalExit(output -> {
output.shouldHaveExitValue(1);
output.shouldContain("Unable to read generic CDS file map header from shared archive");
output.shouldNotContain("Dumping shared data to file:");
});
ft2 = Files.getLastModifiedTime(Paths.get(magicOnly));
if (!ft1.equals(ft2)) {
throw new RuntimeException("Shared archive " + modBaseName + " should not automatically be generated");
}

// delete top archive
if (archiveFile.exists()) {
archiveFile.delete();
@@ -372,5 +394,25 @@ private static void testAutoCreateSharedArchive() throws Exception {
if (!ft1.equals(ft2)) {
throw new RuntimeException("Shared archive " + TOP_NAME + " should not be created at exit");
}

// 23 create an archive like in 15
print("23 create an archive with dynamic magic number only");
copiedJsa = CDSArchiveUtils.createMagicOnlyFile(magicOnly, false /*dynamic*/);
ft1 = Files.getLastModifiedTime(Paths.get(magicOnly));
run2(BASE_NAME, magicOnly,
"-Xshare:auto",
"-XX:+AutoCreateSharedArchive",
"-Xlog:cds",
"-Xlog:cds+dynamic=info",
"-cp", appJar,
mainAppClass)
.assertAbnormalExit(output -> {
output.shouldContain("Unable to read generic CDS file map header from shared archive")
.shouldNotContain("Dumping shared data to file:");
});
ft2 = Files.getLastModifiedTime(Paths.get(magicOnly));
if (!ft1.equals(ft2)) {
throw new RuntimeException("Shared archive " + magicOnly + " should not be created at exit");
}
}
}
@@ -331,6 +331,18 @@ public static File copyArchiveFile(File orgJsaFile, String newName) throws Excep
return newJsaFile;
}

public static File createMagicOnlyFile(String fileName, boolean createStatic) throws Exception {
File file = new File(fileName);
if (file.exists()) {
file.delete();
}
try (FileOutputStream out = new FileOutputStream(file)) {
ByteBuffer buffer = ByteBuffer.allocate(4).putInt(createStatic ? staticMagic: dynamicMagic);
out.write(buffer.array(), 0, 4);
}
return file;
}

private static FileChannel getFileChannel(File file, boolean write) throws Exception {
List<StandardOpenOption> arry = new ArrayList<StandardOpenOption>();
arry.add(READ);