Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit 30ff2ad

Browse files
committedJun 11, 2020
8246382: assert in MetaspaceShared::map_archives
Perform base archive header CRC check earlier. Reviewed-by: iklam, coleenp
1 parent 212ab17 commit 30ff2ad

File tree

4 files changed

+103
-18
lines changed

4 files changed

+103
-18
lines changed
 

‎src/hotspot/share/memory/dynamicArchive.cpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -1119,28 +1119,24 @@ DynamicArchiveBuilder* DynamicArchive::_builder = NULL;
11191119

11201120

11211121
bool DynamicArchive::validate(FileMapInfo* dynamic_info) {
1122+
assert(!dynamic_info->is_static(), "must be");
11221123
// Check if the recorded base archive matches with the current one
11231124
FileMapInfo* base_info = FileMapInfo::current_info();
11241125
DynamicArchiveHeader* dynamic_header = dynamic_info->dynamic_header();
11251126

11261127
// Check the header crc
11271128
if (dynamic_header->base_header_crc() != base_info->crc()) {
1128-
FileMapInfo::fail_continue("Archive header checksum verification failed.");
1129+
FileMapInfo::fail_continue("Dynamic archive cannot be used: static archive header checksum verification failed.");
11291130
return false;
11301131
}
11311132

11321133
// Check each space's crc
11331134
for (int i = 0; i < MetaspaceShared::n_regions; i++) {
11341135
if (dynamic_header->base_region_crc(i) != base_info->space_crc(i)) {
1135-
FileMapInfo::fail_continue("Archive region #%d checksum verification failed.", i);
1136+
FileMapInfo::fail_continue("Dynamic archive cannot be used: static archive region #%d checksum verification failed.", i);
11361137
return false;
11371138
}
11381139
}
11391140

1140-
// Validate the dynamic archived shared path table, and set the global
1141-
// _shared_path_table to that.
1142-
if (!dynamic_info->validate_shared_path_table()) {
1143-
return false;
1144-
}
11451141
return true;
11461142
}

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -2140,7 +2140,14 @@ bool FileMapHeader::validate() {
21402140
}
21412141

21422142
bool FileMapInfo::validate_header() {
2143-
return header()->validate();
2143+
if (!header()->validate()) {
2144+
return false;
2145+
}
2146+
if (_is_static) {
2147+
return true;
2148+
} else {
2149+
return DynamicArchive::validate(this);
2150+
}
21442151
}
21452152

21462153
// Check if a given address is within one of the shared regions

‎src/hotspot/share/memory/metaspaceShared.cpp

+3-10
Original file line numberDiff line numberDiff line change
@@ -2595,16 +2595,9 @@ MapArchiveResult MetaspaceShared::map_archive(FileMapInfo* mapinfo, char* mapped
25952595
return result;
25962596
}
25972597

2598-
if (mapinfo->is_static()) {
2599-
if (!mapinfo->validate_shared_path_table()) {
2600-
unmap_archive(mapinfo);
2601-
return MAP_ARCHIVE_OTHER_FAILURE;
2602-
}
2603-
} else {
2604-
if (!DynamicArchive::validate(mapinfo)) {
2605-
unmap_archive(mapinfo);
2606-
return MAP_ARCHIVE_OTHER_FAILURE;
2607-
}
2598+
if (!mapinfo->validate_shared_path_table()) {
2599+
unmap_archive(mapinfo);
2600+
return MAP_ARCHIVE_OTHER_FAILURE;
26082601
}
26092602

26102603
mapinfo->set_is_mapped(true);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
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+
/*
26+
* @test
27+
* @summary The base archive used for dynamic dump is not the same as the one
28+
* used during run time. With -Xshare:on, VM will exit with en error message.
29+
* @requires vm.cds
30+
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/test-classes
31+
* @build Hello
32+
* @build sun.hotspot.WhiteBox
33+
* @run driver ClassFileInstaller -jar hello.jar Hello
34+
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
35+
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. MismatchedBaseArchive
36+
*/
37+
38+
public class MismatchedBaseArchive extends DynamicArchiveTestBase {
39+
public static void main(String[] args) throws Exception {
40+
createBaseArchive();
41+
runTest(MismatchedBaseArchive::testDefaultBase);
42+
runTest(MismatchedBaseArchive::testCustomBase);
43+
}
44+
45+
static String helloBaseArchive = getNewArchiveName("base-with-hello");
46+
static String appJar = ClassFileInstaller.getJarPath("hello.jar");
47+
static String mainClass = "Hello";
48+
49+
static void createBaseArchive() throws Exception {
50+
TestCommon.dumpBaseArchive(helloBaseArchive,
51+
"-Xlog:cds",
52+
"-cp", appJar, mainClass);
53+
}
54+
55+
// (1) Test with default base archive + top archive
56+
static void testDefaultBase() throws Exception {
57+
String topArchiveName = getNewArchiveName("top");
58+
doTest(null, topArchiveName);
59+
}
60+
61+
// (2) Test with custom base archive + top archive
62+
static void testCustomBase() throws Exception {
63+
String topArchiveName = getNewArchiveName("top2");
64+
String baseArchiveName = getNewArchiveName("base");
65+
TestCommon.dumpBaseArchive(baseArchiveName);
66+
doTest(baseArchiveName, topArchiveName);
67+
}
68+
69+
private static void doTest(String baseArchiveName, String topArchiveName) throws Exception {
70+
dump2(baseArchiveName, topArchiveName,
71+
"-Xlog:cds",
72+
"-Xlog:cds+dynamic=debug",
73+
"-cp", appJar, mainClass)
74+
.assertNormalExit(output -> {
75+
output.shouldContain("Buffer-space to target-space delta")
76+
.shouldContain("Written dynamic archive 0x");
77+
});
78+
79+
run2(helloBaseArchive, topArchiveName,
80+
"-Xlog:class+load",
81+
"-Xlog:cds+dynamic=debug,cds=debug",
82+
"-cp", appJar, mainClass)
83+
.assertAbnormalExit(output -> {
84+
output.shouldContain("Dynamic archive cannot be used: static archive header checksum verification failed.")
85+
.shouldHaveExitValue(1);
86+
});
87+
88+
}
89+
}

0 commit comments

Comments
 (0)