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

8287873: Add test for using -XX:+AutoCreateSharedArchive with different JDK versions #11852

Closed
wants to merge 17 commits into from
Closed
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 197 additions & 0 deletions bin/jib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
#!/bin/bash
#
# Copyright (c) 2015, 2022, 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
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#

# This script installs the JIB tool into it's own local repository and
# puts a wrapper scripts into <source-root>/.jib

mydir="$(dirname "${BASH_SOURCE[0]}")"
myname="$(basename "${BASH_SOURCE[0]}")"

installed_jib_script=${mydir}/../.jib/jib
install_data=${mydir}/../.jib/.data

setup_url() {
if [ -f ~/.config/jib/jib.conf ]; then
source ~/.config/jib/jib.conf
fi

jib_repository="jdk-virtual"
jib_organization="jpg/infra/builddeps"
jib_module="jib"
jib_revision="3.0-SNAPSHOT"
jib_ext="jib.sh.gz"

closed_script="${mydir}/../../closed/make/conf/jib-install.conf"
if [ -f "${closed_script}" ]; then
source "${closed_script}"
fi

if [ -n "${JIB_SERVER}" ]; then
jib_server="${JIB_SERVER}"
fi
if [ -n "${JIB_SERVER_MIRRORS}" ]; then
jib_server_mirrors="${JIB_SERVER_MIRRORS}"
fi
if [ -n "${JIB_REPOSITORY}" ]; then
jib_repository="${JIB_REPOSITORY}"
fi
if [ -n "${JIB_ORGANIZATION}" ]; then
jib_organization="${JIB_ORGANIZATION}"
fi
if [ -n "${JIB_MODULE}" ]; then
jib_module="${JIB_MODULE}"
fi
if [ -n "${JIB_REVISION}" ]; then
jib_revision="${JIB_REVISION}"
fi
if [ -n "${JIB_EXTENSION}" ]; then
jib_extension="${JIB_EXTENSION}"
fi

if [ -n "${JIB_URL}" ]; then
jib_url="${JIB_URL}"
data_string="${jib_url}"
else
jib_path="${jib_repository}/${jib_organization}/${jib_module}/${jib_revision}/${jib_module}-${jib_revision}.${jib_ext}"
data_string="${jib_path}"
jib_url="${jib_server}/${jib_path}"
fi
}

install_jib() {
if [ -z "${jib_server}" -a -z "${JIB_URL}" ]; then
echo "No jib server or URL provided, set either"
echo "JIB_SERVER=<base server address>"
echo "or"
echo "JIB_URL=<full path to install script>"
exit 1
fi

if command -v curl > /dev/null; then
getcmd="curl -s -L --retry 3 --retry-delay 5"
elif command -v wget > /dev/null; then
getcmd="wget --quiet -O -"
else
echo "Could not find either curl or wget"
exit 1
fi

if ! command -v gunzip > /dev/null; then
echo "Could not find gunzip"
exit 1
fi

echo "Downloading JIB bootstrap script"
mkdir -p "${installed_jib_script%/*}"
rm -f "${installed_jib_script}.gz"
${getcmd} ${jib_url} > "${installed_jib_script}.gz"
if [ ! -s "${installed_jib_script}.gz" ]; then
echo "Failed to download ${jib_url}"
if [ -n "${jib_path}" -a -n "${jib_server_mirrors}" ]; then
OLD_IFS="${IFS}"
IFS=" ,"
for mirror in ${jib_server_mirrors}; do
echo "Trying mirror ${mirror}"
jib_url="${mirror}/${jib_path}"
${getcmd} ${jib_url} > "${installed_jib_script}.gz"
if [ -s "${installed_jib_script}.gz" ]; then
echo "Download from mirror successful"
break
else
echo "Failed to download ${jib_url}"
fi
done
IFS="${OLD_IFS}"
fi
if [ ! -s "${installed_jib_script}.gz" ]; then
exit 1
fi
fi
# Want to check the filetype using file, to see if we got served a HTML error page.
# This is sensitive to the filename containing a specific string, but good enough.
file ${installed_jib_script}.gz | grep "gzip compressed data" > /dev/null
if [ $? -ne 0 ]; then
echo "Warning: ${installed_jib_script}.gz is not a gzip file."
echo "If you are behind a proxy you may need to configure exceptions using no_proxy."
echo "The download URL was: ${jib_url}"
exit 1
fi
echo "Extracting JIB bootstrap script"
rm -f "${installed_jib_script}"
gunzip "${installed_jib_script}.gz"
chmod +x "${installed_jib_script}"
echo "${data_string}" > "${install_data}"
}

# Returns a shell-escaped version of the argument given.
shell_quote() {
if [[ -n "$1" ]]; then
# Uses only shell-safe characters? No quoting needed.
# '=' is a zsh meta-character, but only in word-initial position.
if echo "$1" | grep '^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\.:,%/+=_-]\{1,\}$' > /dev/null \
&& ! echo "$1" | grep '^=' > /dev/null; then
quoted="$1"
else
if echo "$1" | grep "[\'!]" > /dev/null; then
# csh does history expansion within single quotes, but not
# when backslash-escaped!
local quoted_quote="'\\''" quoted_exclam="'\\!'"
word="${1//\'/${quoted_quote}}"
word="${1//\!/${quoted_exclam}}"
fi
quoted="'$1'"
fi
echo "$quoted"
fi
}

# Main body starts here

setup_url

if [ ! -x "${installed_jib_script}" ]; then
install_jib
elif [ ! -e "${install_data}" ] || [ "${data_string}" != "$(cat "${install_data}")" ]; then
echo "Install url changed since last time, reinstalling"
install_jib
fi

# Provide a reasonable default for the --src-dir parameter if run out of tree
if [ -z "${JIB_SRC_DIR}" ]; then
export JIB_SRC_DIR="${mydir}/../"
fi


# Save the original command line
conf_quoted_arguments=()
for conf_option; do
conf_quoted_arguments=("${conf_quoted_arguments[@]}" "$(shell_quote "$conf_option")")
done
export REAL_CONFIGURE_COMMAND_LINE="${conf_quoted_arguments[@]}"

myfulldir="$(cd "${mydir}" > /dev/null && pwd)"
export REAL_CONFIGURE_COMMAND_EXEC_FULL="$BASH $myfulldir/$myname"
export REAL_CONFIGURE_COMMAND_EXEC_SHORT="$myname"

${installed_jib_script} "$@"
Original file line number Diff line number Diff line change
@@ -34,15 +34,16 @@
*/

import java.io.File;
import java.util.HashMap;
import java.util.Properties;
import jdk.test.lib.artifacts.Artifact;
import jdk.test.lib.artifacts.ArtifactResolver;
import jdk.test.lib.artifacts.ArtifactResolverException;

This comment was marked as resolved.

import jdk.test.lib.helpers.ClassFileInstaller;
import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;

import java.util.HashMap;
import jtreg.SkippedException;

public class TestAutoCreateSharedArchiveUpgrade {

@@ -58,7 +59,6 @@ public class TestAutoCreateSharedArchiveUpgrade {
// If you're unning this test using something like
// "make test TEST=test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/TestAutoCreateSharedArchiveUpgrade.java",
// the test.boot.jdk property is normally passed by make/RunTests.gmk
// now it is pulled by the artifactory
private static String BOOT_JDK;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we please call this something else? The concept of the BOOT_JDK is a rather specific thing in the JDK build process. This test is using the build's BOOT_JDK as a default for "a JDK of some older version than the current". Calling that "BOOT_JDK" in this test is confusing at least to me.

Perhaps something like OLD_JDK would be more suitable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually OLD_JDK would be confusing because we also have PREV_JDK. This is the original code before this PR:

// If you're running this test manually, specify the location of a previous version of
// the JDK using "jtreg -vmoption:-Dtest.previous.jdk=${JDK19_HOME} ..."
private static final String PREV_JDK = System.getProperty("test.previous.jdk", null);

// If you're unning this test using something like
// "make test TEST=test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/TestAutoCreateSharedArchiveUpgrade.java",
// the test.boot.jdk property is passed by make/RunTests.gmk
private static final String BOOT_JDK = System.getProperty("test.boot.jdk", null);

So the problem with this PR is it overloads the meaning of BOOT_JDK. I think it's better to do something like this:

static void setupJVMs(int fetchVersion) throws Throwable {
    ....
    if (fetchVersion> 0) {
        oldJVM = fetchJDK(fetchVersion) + FS + "bin" + FS + "java";
    } else if (PREV_JDK != null) {
        oldJVM = PREV_JDK + FS + "bin" + FS + "java";
    } else if (BOOT_JDK != null) {
        oldJVM = BOOT_JDK + FS + "bin" + FS + "java";
    } else {

private static String DEFAULT_BOOT_JDK = System.getProperty("test.boot.jdk", null);

@@ -72,20 +72,27 @@ public class TestAutoCreateSharedArchiveUpgrade {
private static String newJVM;

public static void main(String[] args) throws Throwable {
// Get OS and CPU type
String arch = props.getProperty("os.arch");
String os = getOsId();

// Earliest testable version is 19
int n = java.lang.Runtime.version().major() - 1;
for (int i = 19; i < n; i++) {
BOOT_JDK = fetchBootJDK(os, arch, i);
setupJVMs(os);
doTest();
// Only run once if using the default boot jdk
int n = java.lang.Runtime.version().major();

// Test only previous version unless specified in gmk
if (System.getProperty("test.autocreatesharedarchive.all.jdk.versions") == null) {
testJDK(n - 1);
return;
}
for (int i = n - 1; i >= 19 && BOOT_JDK != DEFAULT_BOOT_JDK; i--) {
testJDK(i);
}

This comment was marked as outdated.

}

static void setupJVMs(String os) throws Throwable {
static void testJDK(int version) throws Throwable {
BOOT_JDK = fetchBootJDK(version);
setupJVMs();
doTest();
}

static void setupJVMs() throws Throwable {
if (TEST_JDK == null) {
throw new RuntimeException("-Dtest.jdk should point to the JDK being tested");
}
@@ -96,11 +103,11 @@ static void setupJVMs(String os) throws Throwable {
if (PREV_JDK != null) {
oldJVM = PREV_JDK + FS + "bin" + FS + "java";
} else if (BOOT_JDK != null) {
oldJVM = (os == "MacOSX") ?
oldJVM = (Platform.isOSX()) ?
BOOT_JDK + ".jdk" + FS + "Contents" + FS + "Home" + FS + "bin" + FS + "java" :
BOOT_JDK + FS + "bin" + FS + "java";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in a comment in JDK-8296754, we should change the RuntimeException in the next block to a SkippedException.

} else {
throw new RuntimeException("Use -Dtest.previous.jdk or -Dtest.boot.jdk to specify a " +
throw new SkippedException("Use -Dtest.previous.jdk or -Dtest.boot.jdk to specify a " +
"previous version of the JDK that supports " +
"-XX:+AutoCreateSharedArchive");
}
@@ -124,15 +131,13 @@ static void doTest() throws Throwable {

// OLD JDK -- should reject the JSA created by NEW JDK, and create its own
output = run(oldJVM);
assertJSAVersionMismatch(output);
assertCreatedJSA(output);

output = run(oldJVM);
assertUsedJSA(output);

// NEW JDK -- should reject the JSA created by OLD JDK, and create its own
output = run(newJVM);
assertJSAVersionMismatch(output);
assertCreatedJSA(output);

output = run(newJVM);
@@ -157,17 +162,13 @@ static void assertCreatedJSA(OutputAnalyzer output) {
output.shouldContain("Dumping shared data to file");
}

static void assertJSAVersionMismatch(OutputAnalyzer output) {
output.shouldContain("does not match the required version");
}

static void assertUsedJSA(OutputAnalyzer output) {
output.shouldContain("Mapped dynamic region #0");
}

// Fetch JDK artifact depending on platform
// If the artifact cannot be found, default to the test.boot.jdk property
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment about test.boot.jdk is no longer valid. If the artifact cannot be found, RuntimeException is thrown.

private static String fetchBootJDK(String osID, String arch, int version) {
private static String fetchBootJDK(int version) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with the method names here, please don't call it BootJDK.

int build;
String architecture;
HashMap<String, Object> jdkArtifactMap = new HashMap<>();
@@ -187,8 +188,18 @@ private static String fetchBootJDK(String osID, String arch, int version) {
build = 0;
break;
}
jdkArtifactMap.put("version", version);
jdkArtifactMap.put("build_number", build);

// Get correct file name for architecture
switch(arch) {
if (Platform.isX64()) {
architecture = "x";
} else if (Platform.isAArch64()) {
architecture = "aarch";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use "x64" and "aarch64" here. The comments below should be fixed, too.

} else {
return DEFAULT_BOOT_JDK;
}
/*switch(arch) {
case("x86"):
case("x86_64"):
case("amd64"):
@@ -200,33 +211,40 @@ private static String fetchBootJDK(String osID, String arch, int version) {
default:
architecture = "";
break;
}
}*/

// File name is bundles/<os>-<architecture>64/jdk-<version>_<os>-<architecture>64_bin.<extension>
// Ex: bundles/linux-x64/jdk-19_linux-x64_bin.tar.gz
switch (osID) {
if (Platform.isWindows()) {
jdkArtifactMap.put("file", "bundles/windows-x64/jdk-" + version + "_windows-x64_bin.zip");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of hard-coding "x64", architecture should be used.

return fetchBootJDK(jdkArtifactMap, version);
} else if (Platform.isOSX()) {
jdkArtifactMap.put("file", "bundles/macos-" + architecture + "64/jdk-" + version + "_macos-" + architecture + "64_bin.tar.gz");
return fetchBootJDK(jdkArtifactMap, version);
} else if (Platform.isLinux()) {
jdkArtifactMap.put("file", "bundles/linux-" + architecture + "64/jdk-" + version + "_linux-" + architecture + "64_bin.tar.gz");
return fetchBootJDK(jdkArtifactMap, version);
} else {
return DEFAULT_BOOT_JDK;
}
/*switch (osID) {
case "Windows":
jdkArtifactMap.put("version", version);
jdkArtifactMap.put("build_number", build);
jdkArtifactMap.put("file", "bundles/windows-x64/jdk-" + version + "_windows-x64_bin.zip");
return fetchBootJDK(jdkArtifactMap, version);
case "MacOSX":
jdkArtifactMap.put("version", version);
jdkArtifactMap.put("build_number", build);
jdkArtifactMap.put("file", "bundles/macos-" + architecture + "64/jdk-" + version + "_macos-" + architecture + "64_bin.tar.gz");
return fetchBootJDK(jdkArtifactMap, version);
case "Linux":
jdkArtifactMap.put("version", version);
jdkArtifactMap.put("build_number", build);
jdkArtifactMap.put("file", "bundles/linux-" + architecture + "64/jdk-" + version + "_linux-" + architecture + "64_bin.tar.gz");
return fetchBootJDK(jdkArtifactMap, version);
default:
return DEFAULT_BOOT_JDK;
}
}*/
}

// Fetch JDK version from artifactory
// Fetch JDK artifact
private static String fetchBootJDK(HashMap<String, Object> jdkArtifactMap, int version) {
String path = DEFAULT_BOOT_JDK;
try {
@@ -244,14 +262,4 @@ private static String fetchBootJDK(HashMap<String, Object> jdkArtifactMap, int v
}
return path;
}

private static String getOsId() {
String osName = props.getProperty("os.name");
if (osName.startsWith("Win")) {
osName = "Windows";
} else if (osName.equals("Mac OS X")) {
osName = "MacOSX";
}
return osName;
}
}
15 changes: 4 additions & 11 deletions test/lib/jdk/test/lib/artifacts/Artifact.java
Original file line number Diff line number Diff line change
@@ -29,18 +29,11 @@
@Repeatable(ArtifactContainer.class)
@Retention(RetentionPolicy.RUNTIME)
public @interface Artifact {
String organization() default "";
String name() default "";
String revision() default "";
String extension() default "";
String organization();
String name();
String revision();
String extension();
String classifier() default "";
boolean unpack() default true;

// For getting jdk versions
String server() default "";
String product() default "";
int version() default 0;
int build_number() default 0;
String file() default "";
}

17 changes: 4 additions & 13 deletions test/lib/jdk/test/lib/artifacts/JibArtifactManager.java
Original file line number Diff line number Diff line change
@@ -114,19 +114,10 @@ private Path invokeInstallerMethod(String methodName, String jibVersion,
@Override
public Path resolve(Artifact artifact) throws ArtifactResolverException {
HashMap<String, Object> artifactDescription = new HashMap<>();
if (artifact.server().equals("jpg")) {
artifactDescription.put("server", artifact.server());
artifactDescription.put("product", artifact.product());
artifactDescription.put("version", artifact.version());
artifactDescription.put("build_number", artifact.build_number());
artifactDescription.put("file", artifact.file());
} else {
artifactDescription.put("module", artifact.name());
artifactDescription.put("organization", artifact.organization());
artifactDescription.put("ext", artifact.extension());
artifactDescription.put("revision", artifact.revision());
}

artifactDescription.put("module", artifact.name());
artifactDescription.put("organization", artifact.organization());
artifactDescription.put("ext", artifact.extension());
artifactDescription.put("revision", artifact.revision());
if (artifact.classifier().length() > 0) {
artifactDescription.put("classifier", artifact.classifier());
}