--- a/src/hotspot/share/memory/filemap.cpp Tue May 14 11:06:23 2019 +0800
+++ b/src/hotspot/share/memory/filemap.cpp Tue May 14 12:00:49 2019 +0200
@@ -877,7 +877,7 @@
MemTracker::record_virtual_memory_type((address)base, mtClassShared);
#endif
- if (!verify_region_checksum(i)) {
+ if (VerifySharedSpaces && !verify_region_checksum(i)) {
return NULL;
}
@@ -1143,9 +1143,11 @@
bool FileMapInfo::verify_mapped_heap_regions(int first, int num) {
assert(num > 0, "sanity");
- for (int i = first; i < first + num; i++) {
- if (!verify_region_checksum(i)) {
- return false;
+ if (VerifySharedSpaces) {
+ for (int i = first; i < first + num; i++) {
+ if (!verify_region_checksum(i)) {
+ return false;
+ }
}
}
return true;
@@ -1204,9 +1206,7 @@
#endif // INCLUDE_CDS_JAVA_HEAP
bool FileMapInfo::verify_region_checksum(int i) {
- if (!VerifySharedSpaces) {
- return true;
- }
+ assert(VerifySharedSpaces, "sanity");
size_t sz = space_at(i)->_used;
--- a/src/hotspot/share/runtime/arguments.cpp Tue May 14 11:06:23 2019 +0800
+++ b/src/hotspot/share/runtime/arguments.cpp Tue May 14 12:00:49 2019 +0200
@@ -3792,11 +3792,6 @@
return JNI_ENOMEM;
}
- // Set up VerifySharedSpaces
- if (FLAG_IS_DEFAULT(VerifySharedSpaces) && SharedArchiveFile != NULL) {
- VerifySharedSpaces = true;
- }
-
// Delay warning until here so that we've had a chance to process
// the -XX:-PrintWarnings flag
if (needs_hotspotrc_warning) {
--- a/src/hotspot/share/runtime/globals.hpp Tue May 14 11:06:23 2019 +0800
+++ b/src/hotspot/share/runtime/globals.hpp Tue May 14 12:00:49 2019 +0200
@@ -2349,8 +2349,7 @@
"Use shared spaces for metadata") \
\
product(bool, VerifySharedSpaces, false, \
- "Verify shared spaces (false for default archive, true for " \
- "archive specified by -XX:SharedArchiveFile)") \
+ "Verify integrity of shared spaces") \
\
product(bool, RequireSharedSpaces, false, \
"Require shared spaces for metadata") \
--- a/test/hotspot/jtreg/runtime/appcds/SharedArchiveConsistency.java Tue May 14 11:06:23 2019 +0800
+++ b/test/hotspot/jtreg/runtime/appcds/SharedArchiveConsistency.java Tue May 14 12:00:49 2019 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -318,7 +318,11 @@
// test, should pass
System.out.println("1. Normal, should pass but may fail\n");
+
String[] execArgs = {"-cp", jarFile, "Hello"};
+ // tests that corrupt contents of the archive need to run with
+ // VerifySharedSpaces enabled to detect inconsistencies
+ String[] verifyExecArgs = {"-XX:+VerifySharedSpaces", "-cp", jarFile, "Hello"};
OutputAnalyzer output = TestCommon.execCommon(execArgs);
@@ -350,9 +354,10 @@
// modify content
System.out.println("\n3. Corrupt Content, should fail\n");
+
copyFile(orgJsaFile, jsa);
modifyJsaContent();
- testAndCheck(execArgs);
+ testAndCheck(verifyExecArgs);
// modify both header and content, test should fail
System.out.println("\n4. Corrupt Header and Content, should fail\n");
@@ -363,19 +368,19 @@
output.shouldContain("The shared archive file has the wrong version");
output.shouldNotContain("Checksum verification failed");
- // delete bytes in data sectoin
- System.out.println("\n5. Delete bytes at begining of data section, should fail\n");
+ // delete bytes in data section
+ System.out.println("\n5. Delete bytes at beginning of data section, should fail\n");
copyFile(orgJsaFile, jsa, true);
- testAndCheck(execArgs);
+ testAndCheck(verifyExecArgs);
- // insert bytes in data sectoin forward
- System.out.println("\n6. Insert bytes at begining of data section, should fail\n");
+ // insert bytes in data section forward
+ System.out.println("\n6. Insert bytes at beginning of data section, should fail\n");
copyFile(orgJsaFile, jsa, false);
- testAndCheck(execArgs);
+ testAndCheck(verifyExecArgs);
System.out.println("\n7. modify Content in random areas, should fail\n");
copyFile(orgJsaFile, jsa);
modifyJsaContentRandomly();
- testAndCheck(execArgs);
+ testAndCheck(verifyExecArgs);
}
}