diff --git a/make/Images.gmk b/make/Images.gmk index 10e3dc2d827..a12970dd8e8 100644 --- a/make/Images.gmk +++ b/make/Images.gmk @@ -90,24 +90,32 @@ endif $(JDK_IMAGE_DIR)/$(JIMAGE_TARGET_FILE): $(JMODS) \ $(call DependOnVariable, JDK_MODULES_LIST) $(BASE_RELEASE_FILE) - $(ECHO) Creating jdk image + $(call LogWarn, Creating jdk image) $(RM) -r $(JDK_IMAGE_DIR) $(call ExecuteWithLog, $(SUPPORT_OUTPUTDIR)/images/jdk, \ $(JLINK_TOOL) --add-modules $(JDK_MODULES_LIST) \ $(JLINK_JDK_EXTRA_OPTS) \ --output $(JDK_IMAGE_DIR) \ ) + ifeq ($(BUILD_CDS_ARCHIVE), true) + $(call LogWarn, Creating CDS archive for jdk image) + $(JDK_IMAGE_DIR)/bin/java -Xshare:dump -Xmx128M -Xms128M $(LOG_INFO) + endif $(TOUCH) $@ $(JRE_IMAGE_DIR)/$(JIMAGE_TARGET_FILE): $(JMODS) \ $(call DependOnVariable, JRE_MODULES_LIST) $(BASE_RELEASE_FILE) - $(ECHO) Creating legacy jre image + $(call LogWarn, Creating legacy jre image) $(RM) -r $(JRE_IMAGE_DIR) $(call ExecuteWithLog, $(SUPPORT_OUTPUTDIR)/images/jre, \ $(JLINK_TOOL) --add-modules $(JRE_MODULES_LIST) \ $(JLINK_JRE_EXTRA_OPTS) \ --output $(JRE_IMAGE_DIR) \ ) + ifeq ($(BUILD_CDS_ARCHIVE), true) + $(call LogWarn, Creating CDS archive for jre image) + $(JRE_IMAGE_DIR)/bin/java -Xshare:dump -Xmx128M -Xms128M $(LOG_INFO) + endif $(TOUCH) $@ TOOL_JRE_TARGETS := $(JRE_IMAGE_DIR)/$(JIMAGE_TARGET_FILE) diff --git a/make/autoconf/configure.ac b/make/autoconf/configure.ac index a9edea8c2c1..b579af3e697 100644 --- a/make/autoconf/configure.ac +++ b/make/autoconf/configure.ac @@ -233,6 +233,7 @@ JDKOPT_ENABLE_DISABLE_FAILURE_HANDLER JDKOPT_ENABLE_DISABLE_GENERATE_CLASSLIST JDKOPT_EXCLUDE_TRANSLATIONS JDKOPT_ENABLE_DISABLE_MANPAGES +JDKOPT_ENABLE_DISABLE_CDS_ARCHIVE ############################################################################### # diff --git a/make/autoconf/jdk-options.m4 b/make/autoconf/jdk-options.m4 index e958eba27ad..4dcd3b86718 100644 --- a/make/autoconf/jdk-options.m4 +++ b/make/autoconf/jdk-options.m4 @@ -605,3 +605,38 @@ AC_DEFUN([JDKOPT_ENABLE_DISABLE_MANPAGES], AC_SUBST(BUILD_MANPAGES) ]) + +################################################################################ +# +# Disable the default CDS archive generation +# cross compilation - disabled +# zero - off by default (not a tested configuration) +# +AC_DEFUN([JDKOPT_ENABLE_DISABLE_CDS_ARCHIVE], +[ + AC_ARG_ENABLE([cds-archive], [AS_HELP_STRING([--disable-cds-archive], + [Set to disable generation of a default CDS archive in the product image @<:@enabled@:>@])]) + + AC_MSG_CHECKING([if a default CDS archive should be generated]) + if test "x$COMPILE_TYPE" = "xcross"; then + AC_MSG_RESULT([no, not possible with cross compilation]) + BUILD_CDS_ARCHIVE="false" + elif test "x$enable_cds_archive" = "xyes"; then + AC_MSG_RESULT([yes, forced]) + BUILD_CDS_ARCHIVE="true" + elif HOTSPOT_CHECK_JVM_VARIANT(zero); then + AC_MSG_RESULT([no]) + BUILD_CDS_ARCHIVE="false" + elif test "x$enable_cds_archive" = "x"; then + AC_MSG_RESULT([yes]) + BUILD_CDS_ARCHIVE="true" + elif test "x$enable_cds_archive" = "xno"; then + AC_MSG_RESULT([no, forced]) + BUILD_CDS_ARCHIVE="false" + else + AC_MSG_RESULT([no]) + AC_MSG_ERROR([--enable-cds_archive can only be yes/no or empty]) + fi + + AC_SUBST(BUILD_CDS_ARCHIVE) +]) diff --git a/make/autoconf/spec.gmk.in b/make/autoconf/spec.gmk.in index f95bd921391..aec35664ac9 100644 --- a/make/autoconf/spec.gmk.in +++ b/make/autoconf/spec.gmk.in @@ -309,6 +309,8 @@ EXCLUDE_TRANSLATIONS := @EXCLUDE_TRANSLATIONS@ BUILD_MANPAGES := @BUILD_MANPAGES@ +BUILD_CDS_ARCHIVE := @BUILD_CDS_ARCHIVE@ + # The boot jdk to use. This is overridden in bootcycle-spec.gmk. Make sure to keep # it in sync. BOOT_JDK:=@BOOT_JDK@ diff --git a/make/scripts/compare.sh b/make/scripts/compare.sh index 8a99e4bb4a6..2cfc820b0b1 100644 --- a/make/scripts/compare.sh +++ b/make/scripts/compare.sh @@ -385,6 +385,7 @@ compare_general_files() { ! -name "JavaUpdater" ! -name "JavaWSApplicationStub" \ ! -name "jspawnhelper" ! -name "JavawsLauncher" ! -name "*.a" \ ! -name "finish_installation" ! -name "Sparkle" ! -name "*.tar.gz" \ + ! -name "classes.jsa" \ | $GREP -v "./bin/" | $SORT | $FILTER) echo Other files with binary differences... diff --git a/src/hotspot/share/prims/whitebox.cpp b/src/hotspot/share/prims/whitebox.cpp index 984ce83dd3f..5aea49e0ea0 100644 --- a/src/hotspot/share/prims/whitebox.cpp +++ b/src/hotspot/share/prims/whitebox.cpp @@ -1749,6 +1749,20 @@ WB_ENTRY(jobject, WB_GetMethodStringOption(JNIEnv* env, jobject wb, jobject meth return NULL; WB_END +WB_ENTRY(jobject, WB_GetDefaultArchivePath(JNIEnv* env, jobject wb)) + const char* p = Arguments::get_default_shared_archive_path(); + ThreadToNativeFromVM ttn(thread); + jstring path_string = env->NewStringUTF(p); + + CHECK_JNI_EXCEPTION_(env, NULL); + + return path_string; +WB_END + +WB_ENTRY(jboolean, WB_IsSharingEnabled(JNIEnv* env, jobject wb)) + return UseSharedSpaces; +WB_END + WB_ENTRY(jboolean, WB_IsShared(JNIEnv* env, jobject wb, jobject obj)) oop obj_oop = JNIHandles::resolve(obj); return MetaspaceShared::is_archive_object(obj_oop); @@ -2185,6 +2199,9 @@ static JNINativeMethod methods[] = { {CC"getMethodStringOption", CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;", (void*)&WB_GetMethodStringOption}, + {CC"getDefaultArchivePath", CC"()Ljava/lang/String;", + (void*)&WB_GetDefaultArchivePath}, + {CC"isSharingEnabled", CC"()Z", (void*)&WB_IsSharingEnabled}, {CC"isShared", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsShared }, {CC"isSharedClass", CC"(Ljava/lang/Class;)Z", (void*)&WB_IsSharedClass }, {CC"areSharedStringsIgnored", CC"()Z", (void*)&WB_AreSharedStringsIgnored }, diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp index cd7761e9044..6347b287358 100644 --- a/src/hotspot/share/runtime/arguments.cpp +++ b/src/hotspot/share/runtime/arguments.cpp @@ -3450,21 +3450,27 @@ void Arguments::set_shared_spaces_flags() { // Sharing support // Construct the path to the archive +char* Arguments::get_default_shared_archive_path() { + char *default_archive_path; + char jvm_path[JVM_MAXPATHLEN]; + os::jvm_path(jvm_path, sizeof(jvm_path)); + char *end = strrchr(jvm_path, *os::file_separator()); + if (end != NULL) *end = '\0'; + size_t jvm_path_len = strlen(jvm_path); + size_t file_sep_len = strlen(os::file_separator()); + const size_t len = jvm_path_len + file_sep_len + 20; + default_archive_path = NEW_C_HEAP_ARRAY(char, len, mtArguments); + if (default_archive_path != NULL) { + jio_snprintf(default_archive_path, len, "%s%sclasses.jsa", + jvm_path, os::file_separator()); + } + return default_archive_path; +} + static char* get_shared_archive_path() { char *shared_archive_path; if (SharedArchiveFile == NULL) { - char jvm_path[JVM_MAXPATHLEN]; - os::jvm_path(jvm_path, sizeof(jvm_path)); - char *end = strrchr(jvm_path, *os::file_separator()); - if (end != NULL) *end = '\0'; - size_t jvm_path_len = strlen(jvm_path); - size_t file_sep_len = strlen(os::file_separator()); - const size_t len = jvm_path_len + file_sep_len + 20; - shared_archive_path = NEW_C_HEAP_ARRAY(char, len, mtArguments); - if (shared_archive_path != NULL) { - jio_snprintf(shared_archive_path, len, "%s%sclasses.jsa", - jvm_path, os::file_separator()); - } + shared_archive_path = Arguments::get_default_shared_archive_path(); } else { shared_archive_path = os::strdup_check_oom(SharedArchiveFile, mtArguments); } diff --git a/src/hotspot/share/runtime/arguments.hpp b/src/hotspot/share/runtime/arguments.hpp index 72bfd2bf9e3..3bb983e6cd0 100644 --- a/src/hotspot/share/runtime/arguments.hpp +++ b/src/hotspot/share/runtime/arguments.hpp @@ -633,6 +633,7 @@ class Arguments : AllStatic { static char* get_appclasspath() { return _java_class_path->value(); } static void fix_appclasspath(); + static char* get_default_shared_archive_path(); // Operation modi static Mode mode() { return _mode; } diff --git a/test/TestCommon.gmk b/test/TestCommon.gmk index a51ce82c7b5..79c9f30f0a4 100644 --- a/test/TestCommon.gmk +++ b/test/TestCommon.gmk @@ -178,20 +178,6 @@ ifeq ($(USE_FAILURE_HANDLER), true) endif endif - -# Optionally create a CDS archive before running tests -ifeq ($(GENERATE_CDS_ARCHIVE), true) - CDS_ARCHIVE_FILE := $(ABS_TEST_OUTPUT_DIR)/cds_archive.jsa - - $(CDS_ARCHIVE_FILE): $(PRODUCT_HOME) - $(PRODUCT_HOME)/bin/java -XX:+UnlockDiagnosticVMOptions \ - -XX:SharedArchiveFile=$(shell $(GETMIXEDPATH) "$(CDS_ARCHIVE_FILE)") -Xshare:dump - - CDS_VM_ARGS := -XX:+UnlockDiagnosticVMOptions -XX:SharedArchiveFile=$(shell $(GETMIXEDPATH) "$(CDS_ARCHIVE_FILE)") - JTREG_TEST_OPTIONS += $(addprefix -vmoption:, $(CDS_VM_ARGS)) - TEST_PREREQS += $(CDS_ARCHIVE_FILE) -endif - # How to create the test bundle (pass or fail, we want to create this) # Follow command with ";$(BUNDLE_UP_AND_EXIT)", so it always gets executed. ifneq ($(ARCHIVE_BUNDLE), ) diff --git a/test/hotspot/jtreg/ProblemList-cds-mode.txt b/test/hotspot/jtreg/ProblemList-non-cds-mode.txt similarity index 94% rename from test/hotspot/jtreg/ProblemList-cds-mode.txt rename to test/hotspot/jtreg/ProblemList-non-cds-mode.txt index 8fbc756f0b5..912f4c05cd1 100644 --- a/test/hotspot/jtreg/ProblemList-cds-mode.txt +++ b/test/hotspot/jtreg/ProblemList-non-cds-mode.txt @@ -23,7 +23,7 @@ ############################################################################# # -# Additional list of quarantined tests when CDS mode enabled. +# Additional list of quarantined tests when non-CDS mode enabled. # ############################################################################# diff --git a/test/hotspot/jtreg/runtime/SharedArchiveFile/CheckDefaultArchiveFile.java b/test/hotspot/jtreg/runtime/SharedArchiveFile/CheckDefaultArchiveFile.java new file mode 100644 index 00000000000..191471255f9 --- /dev/null +++ b/test/hotspot/jtreg/runtime/SharedArchiveFile/CheckDefaultArchiveFile.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2018, 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. + */ + +/** + * @test Default CDS archive file + * @summary JDK platforms/binaries do not support default CDS archive should + * not contain classes.jsa in the default location. + * @library /test/lib + * @modules java.base/jdk.internal.misc + * java.management + * @build sun.hotspot.WhiteBox + * @run driver ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions + * -XX:+WhiteBoxAPI CheckDefaultArchiveFile + */ +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import jdk.test.lib.Platform; +import jdk.test.lib.cds.CDSTestUtils; +import jtreg.SkippedException; +import sun.hotspot.WhiteBox; + +public class CheckDefaultArchiveFile { + public static void main(String[] args) throws Exception { + WhiteBox wb = WhiteBox.getWhiteBox(); + String osArch = Platform.getOsArch(); + String vmName = System.getProperty("java.vm.name"); + String vmString = vmName + "(" + osArch + ")"; + String jsaString = wb.getDefaultArchivePath(); + Path jsa = Paths.get(jsaString); + if (Platform.isDefaultCDSArchiveSupported()) { + if (Files.exists(jsa)) { + System.out.println("Passed. " + vmString + + ": has default classes.jsa file"); + } else { + throw new RuntimeException(vmString + "has no " + jsaString); + } + } else { + throw new SkippedException("Default CDS archive is not supported"); + } + } +} diff --git a/test/hotspot/jtreg/runtime/SharedArchiveFile/CheckSharingWithDefaultArchive.java b/test/hotspot/jtreg/runtime/SharedArchiveFile/CheckSharingWithDefaultArchive.java new file mode 100644 index 00000000000..d25331c11a4 --- /dev/null +++ b/test/hotspot/jtreg/runtime/SharedArchiveFile/CheckSharingWithDefaultArchive.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2018, 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. + */ + +/** + * @test Default CDS archive + * @summary Sharing should be enabled by default on supported platform/binaries. + * No -Xshare:dump is needed. No -Xshare:auto or -Xshare:on in needed. + * Verify a set of well-known shared classes. + * @requires vm.cds + * @library /test/lib + * @modules java.base/jdk.internal.misc + * java.management + * @build sun.hotspot.WhiteBox + * @run driver ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions + * -XX:+WhiteBoxAPI CheckSharingWithDefaultArchive -showversion + */ +import jdk.test.lib.Platform; +import jtreg.SkippedException; +import sun.hotspot.WhiteBox; + +public class CheckSharingWithDefaultArchive { + public static void main(String[] args) throws Exception { + if (!Platform.isDefaultCDSArchiveSupported()) { + throw new SkippedException("Supported platform"); + } + + WhiteBox wb = WhiteBox.getWhiteBox(); + String classes[] = {"java.lang.Object", + "java.lang.String", + "java.lang.Class"}; + // If maping fails, sharing is disabled + if (wb.isSharingEnabled()) { + for (int i = 0; i < classes.length; i++) { + Class c = Class.forName(classes[i]); + if (wb.isSharedClass(c)) { + System.out.println(classes[i] + " is shared."); + } else { + throw new RuntimeException(classes[i] + " is not shared"); + } + } + } else { + throw new SkippedException("Sharing is not enabled."); + } + } +} diff --git a/test/hotspot/jtreg/testlibrary_tests/TestMutuallyExclusivePlatformPredicates.java b/test/hotspot/jtreg/testlibrary_tests/TestMutuallyExclusivePlatformPredicates.java index a016f233e7d..211b0b3384b 100644 --- a/test/hotspot/jtreg/testlibrary_tests/TestMutuallyExclusivePlatformPredicates.java +++ b/test/hotspot/jtreg/testlibrary_tests/TestMutuallyExclusivePlatformPredicates.java @@ -50,8 +50,9 @@ public class TestMutuallyExclusivePlatformPredicates { OS("isAix", "isLinux", "isOSX", "isSolaris", "isWindows"), VM_TYPE("isClient", "isServer", "isGraal", "isMinimal", "isZero", "isEmbedded"), MODE("isInt", "isMixed", "isComp"), - IGNORED("isEmulatedClient", "isDebugBuild", "isFastDebugBuild", "isSlowDebugBuild", - "hasSA", "shouldSAAttach", "isTieredSupported", "areCustomLoadersSupportedForCDS"); + IGNORED("isEmulatedClient", "isDebugBuild", "isFastDebugBuild", + "isSlowDebugBuild", "hasSA", "shouldSAAttach", "isTieredSupported", + "areCustomLoadersSupportedForCDS", "isDefaultCDSArchiveSupported"); public final List methodNames; diff --git a/test/jdk/javax/imageio/plugins/png/ItxtUtf8Test.java b/test/jdk/javax/imageio/plugins/png/ItxtUtf8Test.java index 74938bcda18..6f2dbb247c5 100644 --- a/test/jdk/javax/imageio/plugins/png/ItxtUtf8Test.java +++ b/test/jdk/javax/imageio/plugins/png/ItxtUtf8Test.java @@ -30,7 +30,7 @@ * * @run main ItxtUtf8Test * - * @run main/othervm/timeout=10 -Xmx4m ItxtUtf8Test truncate + * @run main/othervm/timeout=10 -Xmx6m ItxtUtf8Test truncate */ import java.awt.image.BufferedImage; diff --git a/test/lib/jdk/test/lib/Platform.java b/test/lib/jdk/test/lib/Platform.java index 3b68d0d2868..a658fa0b720 100644 --- a/test/lib/jdk/test/lib/Platform.java +++ b/test/lib/jdk/test/lib/Platform.java @@ -325,6 +325,19 @@ public class Platform { } } + public static boolean isDefaultCDSArchiveSupported() { + return (is64bit() && + isServer() && + (isLinux() || + isOSX() || + isSolaris() || + isWindows()) && + !isZero() && + !isMinimal() && + !isAArch64() && + !isARM()); + } + /* * This should match the #if condition in ClassListParser::load_class_from_source(). */ diff --git a/test/lib/sun/hotspot/WhiteBox.java b/test/lib/sun/hotspot/WhiteBox.java index d3ce3b7b80d..1a8101304a5 100644 --- a/test/lib/sun/hotspot/WhiteBox.java +++ b/test/lib/sun/hotspot/WhiteBox.java @@ -512,6 +512,8 @@ public class WhiteBox { public native void assertMatchingSafepointCalls(boolean mutexSafepointValue, boolean attemptedNoSafepointValue); // Sharing & archiving + public native String getDefaultArchivePath(); + public native boolean isSharingEnabled(); public native boolean isShared(Object o); public native boolean isSharedClass(Class c); public native boolean areSharedStringsIgnored();