Skip to content

Commit 68c5957

Browse files
committedJun 7, 2022
8287869: -XX:+AutoCreateSharedArchive doesn't work when JDK build is switched
Reviewed-by: ccheung, dholmes
1 parent bf439f8 commit 68c5957

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed
 

‎src/hotspot/share/cds/filemap.cpp

+12-8
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,15 @@ void FileMapInfo::populate_header(size_t core_region_alignment) {
209209
// dynamic header including base archive name for non-default base archive
210210
c_header_size = sizeof(DynamicArchiveHeader);
211211
header_size = c_header_size;
212-
if (!FLAG_IS_DEFAULT(SharedArchiveFile)) {
213-
base_archive_name_size = strlen(Arguments::GetSharedArchivePath()) + 1;
212+
213+
const char* default_base_archive_name = Arguments::get_default_shared_archive_path();
214+
const char* current_base_archive_name = Arguments::GetSharedArchivePath();
215+
if (!os::same_files(current_base_archive_name, default_base_archive_name)) {
216+
base_archive_name_size = strlen(current_base_archive_name) + 1;
214217
header_size += base_archive_name_size;
215218
base_archive_name_offset = c_header_size;
216219
}
220+
FREE_C_HEAP_ARRAY(const char, default_base_archive_name);
217221
}
218222
_header = (FileMapHeader*)os::malloc(header_size, mtInternal);
219223
memset((void*)_header, 0, header_size);
@@ -301,7 +305,7 @@ void FileMapHeader::print(outputStream* st) {
301305

302306
st->print_cr("- magic: 0x%08x", magic());
303307
st->print_cr("- crc: 0x%08x", crc());
304-
st->print_cr("- version: %d", version());
308+
st->print_cr("- version: 0x%x", version());
305309
st->print_cr("- header_size: " UINT32_FORMAT, header_size());
306310
st->print_cr("- base_archive_name_offset: " UINT32_FORMAT, base_archive_name_offset());
307311
st->print_cr("- base_archive_name_size: " UINT32_FORMAT, base_archive_name_size());
@@ -1151,14 +1155,14 @@ class FileHeaderHelper {
11511155
}
11521156

11531157
if (gen_header._version < CDS_GENERIC_HEADER_SUPPORTED_MIN_VERSION) {
1154-
FileMapInfo::fail_continue("Cannot handle shared archive file version %d. Must be at least %d",
1158+
FileMapInfo::fail_continue("Cannot handle shared archive file version 0x%x. Must be at least 0x%x.",
11551159
gen_header._version, CDS_GENERIC_HEADER_SUPPORTED_MIN_VERSION);
11561160
return false;
11571161
}
11581162

11591163
if (gen_header._version != CURRENT_CDS_ARCHIVE_VERSION) {
1160-
FileMapInfo::fail_continue("The shared archive file version %d does not match the required version %d",
1161-
gen_header._version, CURRENT_CDS_ARCHIVE_VERSION);
1164+
FileMapInfo::fail_continue("The shared archive file version 0x%x does not match the required version 0x%x.",
1165+
gen_header._version, CURRENT_CDS_ARCHIVE_VERSION);
11621166
}
11631167

11641168
size_t filelen = os::lseek(fd, 0, SEEK_END);
@@ -1332,8 +1336,8 @@ bool FileMapInfo::init_from_file(int fd) {
13321336
}
13331337

13341338
if (header()->version() != CURRENT_CDS_ARCHIVE_VERSION) {
1335-
log_info(cds)("_version expected: %d", CURRENT_CDS_ARCHIVE_VERSION);
1336-
log_info(cds)(" actual: %d", header()->version());
1339+
log_info(cds)("_version expected: 0x%x", CURRENT_CDS_ARCHIVE_VERSION);
1340+
log_info(cds)(" actual: 0x%x", header()->version());
13371341
fail_continue("The shared archive file has the wrong version.");
13381342
return false;
13391343
}

‎src/hotspot/share/include/cds.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ typedef struct CDSFileMapRegion {
6161
} CDSFileMapRegion;
6262

6363
// This portion of the archive file header must remain unchanged for
64-
// _version >= CDS_GENERIC_HEADER_SUPPORTED_MIN_VERSION (12).
64+
// _version >= CDS_GENERIC_HEADER_SUPPORTED_MIN_VERSION (13).
6565
// This makes it possible to read important information from a CDS archive created by
6666
// a different version of HotSpot, so that we can automatically regenerate the archive as necessary.
6767
typedef struct GenericCDSFileMapHeader {

‎test/hotspot/jtreg/runtime/cds/appcds/SharedArchiveConsistency.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ public static void testAndCheck(String[] execArgs, String... expectedMessages) t
100100
TestCommon.checkExec(output);
101101
}
102102

103+
private static String hex(int version) {
104+
return String.format("0x%x", version);
105+
}
106+
103107
// dump with hello.jsa, then
104108
// read the jsa file
105109
// 1) run normal
@@ -192,7 +196,7 @@ public static void main(String... args) throws Exception {
192196
copiedJsa = CDSArchiveUtils.copyArchiveFile(orgJsaFile, modVersion);
193197
CDSArchiveUtils.modifyHeaderIntField(copiedJsa, CDSArchiveUtils.offsetVersion(), version);
194198
output = shareAuto ? TestCommon.execAuto(execArgs) : TestCommon.execCommon(execArgs);
195-
output.shouldContain("The shared archive file version " + version + " does not match the required version " + currentCDSArchiveVersion);
199+
output.shouldContain("The shared archive file version " + hex(version) + " does not match the required version " + hex(currentCDSArchiveVersion));
196200
if (shareAuto) {
197201
output.shouldContain(HELLO_WORLD);
198202
}
@@ -203,7 +207,7 @@ public static void main(String... args) throws Exception {
203207
version = genericHeaderMinVersion - 1;
204208
CDSArchiveUtils.modifyHeaderIntField(copiedJsa, CDSArchiveUtils.offsetVersion(), version);
205209
output = shareAuto ? TestCommon.execAuto(execArgs) : TestCommon.execCommon(execArgs);
206-
output.shouldContain("Cannot handle shared archive file version " + version + ". Must be at least " + genericHeaderMinVersion);
210+
output.shouldContain("Cannot handle shared archive file version " + hex(version) + ". Must be at least " + hex(genericHeaderMinVersion));
207211
output.shouldNotContain("Checksum verification failed");
208212
if (shareAuto) {
209213
output.shouldContain(HELLO_WORLD);

‎test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/TestAutoCreateSharedArchive.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ public static void print(String message) {
151151
System.out.println(message);
152152
}
153153

154+
private static String hex(int version) {
155+
return String.format("0x%x", version);
156+
}
157+
154158
private static void testAutoCreateSharedArchive() throws Exception {
155159
String appJar = ClassFileInstaller.getJarPath("hello.jar");
156160
boolean fileModified = false;
@@ -303,7 +307,7 @@ private static void testAutoCreateSharedArchive() throws Exception {
303307
.assertNormalExit(output -> {
304308
output.shouldHaveExitValue(0)
305309
.shouldContain(HELLO_WORLD)
306-
.shouldContain("Cannot handle shared archive file version " + version1 + ". Must be at least " + genericHeaderMinVersion)
310+
.shouldContain("Cannot handle shared archive file version " + hex(version1) + ". Must be at least " + hex(genericHeaderMinVersion))
307311
.shouldContain("Unable to use shared archive: invalid archive")
308312
.shouldNotContain("Dumping shared data to file");
309313
});
@@ -331,7 +335,7 @@ private static void testAutoCreateSharedArchive() throws Exception {
331335
.assertNormalExit(output -> {
332336
output.shouldHaveExitValue(0)
333337
.shouldContain(HELLO_WORLD)
334-
.shouldContain("The shared archive file version " + version2 + " does not match the required version " + currentCDSVersion)
338+
.shouldContain("The shared archive file version " + hex(version2) + " does not match the required version " + hex(currentCDSVersion))
335339
.shouldContain("UseSharedSpaces: The shared archive file has the wrong version")
336340
.shouldContain("UseSharedSpaces: Initialize dynamic archive failed")
337341
.shouldContain("Dumping shared data to file");
@@ -523,7 +527,7 @@ private static void testAutoCreateSharedArchive() throws Exception {
523527
.assertNormalExit(output -> {
524528
output.shouldHaveExitValue(0)
525529
.shouldContain(HELLO_WORLD)
526-
.shouldContain("Cannot handle shared archive file version " + version1)
530+
.shouldContain("Cannot handle shared archive file version " + hex(version1))
527531
.shouldContain(versionB)
528532
.shouldContain("Dumping shared data to file:");
529533
});
@@ -548,7 +552,7 @@ private static void testAutoCreateSharedArchive() throws Exception {
548552
"-cp", appJar,
549553
mainAppClass)
550554
.assertNormalExit(output -> {
551-
output.shouldContain("The shared archive file version " + version2 + " does not match the required version " + currentCDSVersion)
555+
output.shouldContain("The shared archive file version " + hex(version2) + " does not match the required version " + hex(currentCDSVersion))
552556
.shouldContain(HELLO_WORLD)
553557
.shouldContain("Dumping shared data to file:");
554558
});

0 commit comments

Comments
 (0)
Please sign in to comment.