Skip to content
Permalink
Browse files
8261918: two runtime/cds/appcds/VerifierTest failed with "Unable to u…
…se shared archive"

Reviewed-by: iklam, minqi
  • Loading branch information
calvinccheung committed Mar 10, 2021
1 parent 7e52a6e commit 9399e1b71091627e5cb23f636b7cd1fd03a1e893
@@ -2219,14 +2219,26 @@ bool FileMapHeader::validate() {
_has_platform_or_app_classes = false;
}

// For backwards compatibility, we don't check the verification setting

if (!_verify_local && BytecodeVerificationLocal) {
// we cannot load boot classes, so there's no point of using the CDS archive
FileMapInfo::fail_continue("The shared archive file's BytecodeVerificationLocal setting (%s)"
" does not equal the current BytecodeVerificationLocal setting (%s).",
_verify_local ? "enabled" : "disabled",
BytecodeVerificationLocal ? "enabled" : "disabled");
return false;
}

// For backwards compatibility, we don't check the BytecodeVerificationRemote setting
// if the archive only contains system classes.
if (_has_platform_or_app_classes &&
((!_verify_local && BytecodeVerificationLocal) ||
(!_verify_remote && BytecodeVerificationRemote))) {
if (_has_platform_or_app_classes
&& !_verify_remote // we didn't verify the archived platform/app classes
&& BytecodeVerificationRemote) { // but we want to verify all loaded platform/app classes
FileMapInfo::fail_continue("The shared archive file was created with less restrictive "
"verification setting than the current setting.");
return false;
"verification setting than the current setting.");
// Pretend that we didn't have any archived platform/app classes, so they won't be loaded
// by SystemDictionaryShared.
_has_platform_or_app_classes = false;
}

// Java agents are allowed during run time. Therefore, the following condition is not
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, 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
@@ -177,10 +177,27 @@ public static OutputAnalyzer createArchive(String appJarDir, String appJar, Stri
// name of the base archive to be used for dynamic dump
private static String tempBaseArchive = null;

private static void captureVerifyOpts(ArrayList<String> opts, ArrayList<String> verifyOpts) {
boolean addedDiagnosticOpt = false;
for (String s : opts) {
if (s.startsWith("-XX:-BytecodeVerification")) {
if (!addedDiagnosticOpt) {
verifyOpts.add("-XX:+UnlockDiagnosticVMOptions");
addedDiagnosticOpt = true;
}
verifyOpts.add(s);
}
if (s.startsWith("-Xverify")) {
verifyOpts.add(s);
}
}
}

// Create AppCDS archive using appcds options
public static OutputAnalyzer createArchive(AppCDSOptions opts)
throws Exception {
ArrayList<String> cmd = new ArrayList<String>();
ArrayList<String> verifyOpts = new ArrayList<String>();
startNewArchiveName();

for (String p : opts.prefix) cmd.add(p);
@@ -202,9 +219,15 @@ public static OutputAnalyzer createArchive(AppCDSOptions opts)

if (DYNAMIC_DUMP) {
File baseArchive = null;
if (tempBaseArchive == null || !(new File(tempBaseArchive)).isFile()) {
captureVerifyOpts(opts.suffix, verifyOpts);
int size = verifyOpts.size();
if (tempBaseArchive == null || !(new File(tempBaseArchive)).isFile() || size > 0) {
tempBaseArchive = getNewArchiveName("tempBaseArchive");
dumpBaseArchive(tempBaseArchive);
if (size == 0) {
dumpBaseArchive(tempBaseArchive);
} else {
dumpBaseArchive(tempBaseArchive, verifyOpts.toArray(new String[size]));
}
}
cmd.add("-Xshare:on");
cmd.add("-XX:SharedArchiveFile=" + tempBaseArchive);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, 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
@@ -42,8 +42,8 @@

static final String ERR =
"ERROR: class VerifierTestC was loaded unexpectedly";
static final String MAP_FAIL =
"shared archive file was created with less restrictive verification setting";
static final String MAP_FAIL_VFY_LOCAL =
"shared archive file's BytecodeVerificationLocal setting";
static final String VFY_ERR = "java.lang.VerifyError";
static final String PASS_RESULT = "Hi, how are you?";
static final String VFY_INFO_MESSAGE =
@@ -132,27 +132,27 @@ static void testset_1(String jar, String[] noAppClasses, String[] appClasses, Te

// Dump app/ext with -Xverify:remote
{"app", VFY_REMOTE, VFY_REMOTE, VFY_ERR},
{"app", VFY_REMOTE, VFY_ALL, MAP_FAIL},
{"app", VFY_REMOTE, VFY_ALL, MAP_FAIL_VFY_LOCAL},
{"app", VFY_REMOTE, VFY_NONE, ERR },
// Dump app/ext with -Xverify:all
{"app", VFY_ALL, VFY_REMOTE, VFY_ERR },
{"app", VFY_ALL, VFY_ALL, VFY_ERR },
{"app", VFY_ALL, VFY_NONE, ERR },
// Dump app/ext with verifier turned off
{"app", VFY_NONE, VFY_REMOTE, VFY_ERR},
{"app", VFY_NONE, VFY_ALL, MAP_FAIL},
{"app", VFY_NONE, VFY_ALL, MAP_FAIL_VFY_LOCAL},
{"app", VFY_NONE, VFY_NONE, ERR },
// Dump sys only with -Xverify:remote
{"noApp", VFY_REMOTE, VFY_REMOTE, VFY_ERR},
{"noApp", VFY_REMOTE, VFY_ALL, VFY_ERR},
{"noApp", VFY_REMOTE, VFY_ALL, MAP_FAIL_VFY_LOCAL},
{"noApp", VFY_REMOTE, VFY_NONE, ERR},
// Dump sys only with -Xverify:all
{"noApp", VFY_ALL, VFY_REMOTE, VFY_ERR},
{"noApp", VFY_ALL, VFY_ALL, VFY_ERR},
{"noApp", VFY_ALL, VFY_NONE, ERR},
// Dump sys only with verifier turned off
{"noApp", VFY_NONE, VFY_REMOTE, VFY_ERR},
{"noApp", VFY_NONE, VFY_ALL, VFY_ERR},
{"noApp", VFY_NONE, VFY_ALL, MAP_FAIL_VFY_LOCAL},
{"noApp", VFY_NONE, VFY_NONE, ERR},
};

@@ -245,15 +245,15 @@ static void testset_2(String jarName_greet, String jarName_hi) throws Exception

// Dump app/ext with -Xverify:remote
{"app", VFY_REMOTE, VFY_REMOTE, PASS_RESULT},
{"app", VFY_REMOTE, VFY_ALL, MAP_FAIL},
{"app", VFY_REMOTE, VFY_ALL, MAP_FAIL_VFY_LOCAL},
{"app", VFY_REMOTE, VFY_NONE, PASS_RESULT },
// Dump app/ext with -Xverify:all
{"app", VFY_ALL, VFY_REMOTE, PASS_RESULT },
{"app", VFY_ALL, VFY_ALL, PASS_RESULT },
{"app", VFY_ALL, VFY_NONE, PASS_RESULT },
// Dump app/ext with verifier turned off
{"app", VFY_NONE, VFY_REMOTE, PASS_RESULT},
{"app", VFY_NONE, VFY_ALL, MAP_FAIL},
{"app", VFY_NONE, VFY_ALL, MAP_FAIL_VFY_LOCAL},
{"app", VFY_NONE, VFY_NONE, PASS_RESULT },
};
String prev_dump_setting = "";

1 comment on commit 9399e1b

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 9399e1b Mar 10, 2021

Please sign in to comment.