8201483: Make it possible to disable JVM features
authorihse
Thu, 12 Apr 2018 20:20:27 +0200
changeset 49582 f29aeb8bb44f
parent 49581 bd45ce23b1ac
child 49584 3852547060c8
8201483: Make it possible to disable JVM features Reviewed-by: erikj, stuefe
make/autoconf/basics.m4
make/autoconf/configure.ac
make/autoconf/help.m4
make/autoconf/hotspot.m4
--- a/make/autoconf/basics.m4	Thu Apr 12 17:23:32 2018 +0200
+++ b/make/autoconf/basics.m4	Thu Apr 12 20:20:27 2018 +0200
@@ -23,6 +23,7 @@
 # questions.
 #
 
+###############################################################################
 # Create a function/macro that takes a series of named arguments. The call is
 # similar to AC_DEFUN, but the setup of the function looks like this:
 # BASIC_DEFUN_NAMED([MYFUNC], [FOO *BAR], [$@], [
@@ -91,6 +92,42 @@
   ])
 ])
 
+###############################################################################
+# Check if a list of space-separated words are selected only from a list of
+# space-separated legal words. Typical use is to see if a user-specified
+# set of words is selected from a set of legal words.
+#
+# Sets the specified variable to list of non-matching (offending) words, or to
+# the empty string if all words are matching the legal set.
+#
+# $1: result variable name
+# $2: list of values to check
+# $3: list of legal values
+AC_DEFUN([BASIC_GET_NON_MATCHING_VALUES],
+[
+  # grep filter function inspired by a comment to http://stackoverflow.com/a/1617326
+  # Notice that the original variant fails on SLES 10 and 11
+  values_to_check=`$ECHO $2 | $TR ' ' '\n'`
+  legal_values=`$ECHO $3 | $TR ' ' '\n'`
+  result=`$GREP -Fvx "$legal_values" <<< "$values_to_check" | $GREP -v '^$'`
+  $1=${result//$'\n'/ }
+])
+
+###############################################################################
+# Sort a space-separated list, and remove duplicates.
+#
+# Sets the specified variable to the resulting list.
+#
+# $1: result variable name
+# $2: list of values to sort
+AC_DEFUN([BASIC_SORT_LIST],
+[
+  values_to_sort=`$ECHO $2 | $TR ' ' '\n'`
+  result=`$SORT -u <<< "$values_to_sort" | $GREP -v '^$'`
+  $1=${result//$'\n'/ }
+])
+
+###############################################################################
 # Test if $1 is a valid argument to $3 (often is $JAVA passed as $3)
 # If so, then append $1 to $2 \
 # Also set JVM_ARG_OK to true/false depending on outcome.
@@ -135,6 +172,7 @@
   fi
 ])
 
+###############################################################################
 # This will make sure the given variable points to a full and proper
 # path. This means:
 # 1) There will be no spaces in the path. On unix platforms,
@@ -178,6 +216,7 @@
   fi
 ])
 
+###############################################################################
 # This will make sure the given variable points to a executable
 # with a full and proper path. This means:
 # 1) There will be no spaces in the path. On unix platforms,
@@ -249,6 +288,7 @@
   fi
 ])
 
+###############################################################################
 AC_DEFUN([BASIC_REMOVE_SYMBOLIC_LINKS],
 [
   if test "x$OPENJDK_BUILD_OS" != xwindows; then
@@ -295,6 +335,7 @@
   fi
 ])
 
+###############################################################################
 # Register a --with argument but mark it as deprecated
 # $1: The name of the with argument to deprecate, not including --with-
 AC_DEFUN([BASIC_DEPRECATED_ARG_WITH],
@@ -304,6 +345,7 @@
       [AC_MSG_WARN([Option --with-$1 is deprecated and will be ignored.])])
 ])
 
+###############################################################################
 # Register a --enable argument but mark it as deprecated
 # $1: The name of the with argument to deprecate, not including --enable-
 # $2: The name of the argument to deprecate, in shell variable style (i.e. with _ instead of -)
@@ -322,6 +364,7 @@
   fi
 ])
 
+###############################################################################
 AC_DEFUN_ONCE([BASIC_INIT],
 [
   # Save the original command line. This is passed to us by the wrapper configure script.
@@ -334,6 +377,7 @@
   AC_MSG_NOTICE([Configuration created at $DATE_WHEN_CONFIGURED.])
 ])
 
+###############################################################################
 # Test that variable $1 denoting a program is not empty. If empty, exit with an error.
 # $1: variable to check
 AC_DEFUN([BASIC_CHECK_NONEMPTY],
@@ -343,6 +387,7 @@
   fi
 ])
 
+###############################################################################
 # Check that there are no unprocessed overridden variables left.
 # If so, they are an incorrect argument and we will exit with an error.
 AC_DEFUN([BASIC_CHECK_LEFTOVER_OVERRIDDEN],
@@ -354,6 +399,7 @@
   fi
 ])
 
+###############################################################################
 # Setup a tool for the given variable. If correctly specified by the user,
 # use that value, otherwise search for the tool using the supplied code snippet.
 # $1: variable to set
@@ -420,6 +466,7 @@
   fi
 ])
 
+###############################################################################
 # Call BASIC_SETUP_TOOL with AC_PATH_PROGS to locate the tool
 # $1: variable to set
 # $2: executable name (or list of names) to look for
@@ -429,6 +476,7 @@
   BASIC_SETUP_TOOL($1, [AC_PATH_PROGS($1, $2, , $3)])
 ])
 
+###############################################################################
 # Call BASIC_SETUP_TOOL with AC_CHECK_TOOLS to locate the tool
 # $1: variable to set
 # $2: executable name (or list of names) to look for
@@ -437,6 +485,7 @@
   BASIC_SETUP_TOOL($1, [AC_CHECK_TOOLS($1, $2)])
 ])
 
+###############################################################################
 # Like BASIC_PATH_PROGS but fails if no tool was found.
 # $1: variable to set
 # $2: executable name (or list of names) to look for
@@ -447,6 +496,7 @@
   BASIC_CHECK_NONEMPTY($1)
 ])
 
+###############################################################################
 # Like BASIC_SETUP_TOOL but fails if no tool was found.
 # $1: variable to set
 # $2: autoconf macro to call to look for the special tool
@@ -456,6 +506,7 @@
   BASIC_CHECK_NONEMPTY($1)
 ])
 
+###############################################################################
 # Setup the most fundamental tools that relies on not much else to set up,
 # but is used by much of the early bootstrap code.
 AC_DEFUN_ONCE([BASIC_SETUP_FUNDAMENTAL_TOOLS],
@@ -528,6 +579,7 @@
   BASIC_PATH_PROGS(PANDOC, pandoc)
 ])
 
+###############################################################################
 # Setup basic configuration paths, and platform-specific stuff related to PATHs.
 AC_DEFUN_ONCE([BASIC_SETUP_PATHS],
 [
@@ -569,6 +621,7 @@
   AC_SUBST(USERNAME)
 ])
 
+###############################################################################
 # Evaluates platform specific overrides for devkit variables.
 # $1: Name of variable
 AC_DEFUN([BASIC_EVAL_DEVKIT_VARIABLE],
@@ -578,6 +631,7 @@
   fi
 ])
 
+###############################################################################
 AC_DEFUN_ONCE([BASIC_SETUP_DEVKIT],
 [
   AC_ARG_WITH([devkit], [AS_HELP_STRING([--with-devkit],
@@ -756,6 +810,7 @@
   AC_MSG_RESULT([$EXTRA_PATH])
 ])
 
+###############################################################################
 AC_DEFUN_ONCE([BASIC_SETUP_OUTPUT_DIR],
 [
 
@@ -855,6 +910,7 @@
 
 #%%% Simple tools %%%
 
+###############################################################################
 # Check if we have found a usable version of make
 # $1: the path to a potential make binary (or empty)
 # $2: the description on how we found this
@@ -908,6 +964,7 @@
   fi
 ])
 
+###############################################################################
 AC_DEFUN([BASIC_CHECK_MAKE_OUTPUT_SYNC],
 [
   # Check if make supports the output sync option and if so, setup using it.
@@ -934,6 +991,7 @@
   AC_SUBST(OUTPUT_SYNC)
 ])
 
+###############################################################################
 # Goes looking for a usable version of GNU make.
 AC_DEFUN([BASIC_CHECK_GNU_MAKE],
 [
@@ -981,6 +1039,7 @@
   BASIC_CHECK_MAKE_OUTPUT_SYNC
 ])
 
+###############################################################################
 AC_DEFUN([BASIC_CHECK_FIND_DELETE],
 [
   # Test if find supports -delete
@@ -1009,6 +1068,7 @@
   AC_SUBST(FIND_DELETE)
 ])
 
+###############################################################################
 AC_DEFUN([BASIC_CHECK_TAR],
 [
   # Test which kind of tar was found
@@ -1043,6 +1103,7 @@
   AC_SUBST(TAR_SUPPORTS_TRANSFORM)
 ])
 
+###############################################################################
 AC_DEFUN([BASIC_CHECK_GREP],
 [
   # Test that grep supports -Fx with a list of pattern which includes null pattern.
@@ -1066,6 +1127,7 @@
   fi
 ])
 
+###############################################################################
 AC_DEFUN_ONCE([BASIC_SETUP_COMPLEX_TOOLS],
 [
   BASIC_CHECK_GNU_MAKE
@@ -1132,6 +1194,7 @@
   fi
 ])
 
+###############################################################################
 # Check if build directory is on local disk. If not possible to determine,
 # we prefer to claim it's local.
 # Argument 1: directory to test
@@ -1171,6 +1234,7 @@
   fi
 ])
 
+###############################################################################
 # Check that source files have basic read permissions set. This might
 # not be the case in cygwin in certain conditions.
 AC_DEFUN_ONCE([BASIC_CHECK_SRC_PERMS],
@@ -1183,6 +1247,7 @@
   fi
 ])
 
+###############################################################################
 AC_DEFUN_ONCE([BASIC_TEST_USABILITY_ISSUES],
 [
   AC_MSG_CHECKING([if build directory is on local disk])
@@ -1205,6 +1270,7 @@
   fi
 ])
 
+###############################################################################
 # Check for support for specific options in bash
 AC_DEFUN_ONCE([BASIC_CHECK_BASH_OPTIONS],
 [
@@ -1260,6 +1326,7 @@
   AC_SUBST(DEFAULT_MAKE_TARGET)
 ])
 
+###############################################################################
 # Setup the default value for LOG=
 #
 AC_DEFUN_ONCE([BASIC_SETUP_DEFAULT_LOG],
@@ -1278,6 +1345,7 @@
   AC_SUBST(DEFAULT_LOG)
 ])
 
+###############################################################################
 # Code to run after AC_OUTPUT
 AC_DEFUN_ONCE([BASIC_POST_CONFIG_OUTPUT],
 [
--- a/make/autoconf/configure.ac	Thu Apr 12 17:23:32 2018 +0200
+++ b/make/autoconf/configure.ac	Thu Apr 12 20:20:27 2018 +0200
@@ -273,7 +273,7 @@
 CUSTOM_LATE_HOOK
 
 # This needs to be done after CUSTOM_LATE_HOOK since we can setup custom features.
-HOTSPOT_VALIDATE_JVM_FEATURES
+HOTSPOT_FINALIZE_JVM_FEATURES
 
 # Did user specify any unknown variables?
 BASIC_CHECK_LEFTOVER_OVERRIDDEN
--- a/make/autoconf/help.m4	Thu Apr 12 17:23:32 2018 +0200
+++ b/make/autoconf/help.m4	Thu Apr 12 20:20:27 2018 +0200
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 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
@@ -213,8 +213,16 @@
   printf "Configuration summary:\n"
   printf "* Debug level:    $DEBUG_LEVEL\n"
   printf "* HS debug level: $HOTSPOT_DEBUG_LEVEL\n"
-  printf "* JDK variant:    $JDK_VARIANT\n"
   printf "* JVM variants:   $JVM_VARIANTS\n"
+  printf "* JVM features:   "
+
+  for variant in $JVM_VARIANTS; do
+    features_var_name=JVM_FEATURES_$variant
+    JVM_FEATURES_FOR_VARIANT=${!features_var_name}
+    printf "$variant: \'$JVM_FEATURES_FOR_VARIANT\' "
+  done
+  printf "\n"
+
   printf "* OpenJDK target: OS: $OPENJDK_TARGET_OS, CPU architecture: $OPENJDK_TARGET_CPU_ARCH, address length: $OPENJDK_TARGET_CPU_BITS\n"
   printf "* Version string: $VERSION_STRING ($VERSION_SHORT)\n"
 
--- a/make/autoconf/hotspot.m4	Thu Apr 12 17:23:32 2018 +0200
+++ b/make/autoconf/hotspot.m4	Thu Apr 12 20:20:27 2018 +0200
@@ -93,22 +93,16 @@
   AC_MSG_RESULT([$JVM_VARIANTS])
 
   # Check that the selected variants are valid
-
-  # grep filter function inspired by a comment to http://stackoverflow.com/a/1617326
-  # Notice that the original variant failes on SLES 10 and 11
-  NEEDLE=${VALID_JVM_VARIANTS// /$'\n'}
-  STACK=${JVM_VARIANTS// /$'\n'}
-  INVALID_VARIANTS=`$GREP -Fvx "${NEEDLE}" <<< "${STACK}"`
+  BASIC_GET_NON_MATCHING_VALUES(INVALID_VARIANTS, $JVM_VARIANTS, $VALID_JVM_VARIANTS)
   if test "x$INVALID_VARIANTS" != x; then
-    AC_MSG_NOTICE([Unknown variant(s) specified: $INVALID_VARIANTS])
-    AC_MSG_ERROR([The available JVM variants are: $VALID_JVM_VARIANTS])
+    AC_MSG_NOTICE([Unknown variant(s) specified: "$INVALID_VARIANTS"])
+    AC_MSG_NOTICE([The available JVM variants are: "$VALID_JVM_VARIANTS"])
+    AC_MSG_ERROR([Cannot continue])
   fi
 
   # All "special" variants share the same output directory ("server")
   VALID_MULTIPLE_JVM_VARIANTS="server client minimal"
-  NEEDLE=${VALID_MULTIPLE_JVM_VARIANTS// /$'\n'}
-  STACK=${JVM_VARIANTS// /$'\n'}
-  INVALID_MULTIPLE_VARIANTS=`$GREP -Fvx "${NEEDLE}" <<< "${STACK}"`
+  BASIC_GET_NON_MATCHING_VALUES(INVALID_MULTIPLE_VARIANTS, $JVM_VARIANTS, $VALID_MULTIPLE_JVM_VARIANTS)
   if  test "x$INVALID_MULTIPLE_VARIANTS" != x && test "x$BUILDING_MULTIPLE_JVM_VARIANTS" = xtrue; then
     AC_MSG_ERROR([You cannot build multiple variants with anything else than $VALID_MULTIPLE_JVM_VARIANTS.])
   fi
@@ -263,14 +257,30 @@
 #
 AC_DEFUN_ONCE([HOTSPOT_SETUP_JVM_FEATURES],
 [
+  # Prettify the VALID_JVM_FEATURES string
+  BASIC_SORT_LIST(VALID_JVM_FEATURES, $VALID_JVM_FEATURES)
+
   # The user can in some cases supply additional jvm features. For the custom
   # variant, this defines the entire variant.
   AC_ARG_WITH([jvm-features], [AS_HELP_STRING([--with-jvm-features],
-      [additional JVM features to enable (separated by comma),  use '--help' to show possible values @<:@none@:>@])])
+      [JVM features to enable (foo) or disable (-foo), separated by comma. Use '--help' to show possible values @<:@none@:>@])])
   if test "x$with_jvm_features" != x; then
-    AC_MSG_CHECKING([additional JVM features])
-    JVM_FEATURES=`$ECHO $with_jvm_features | $SED -e 's/,/ /g'`
-    AC_MSG_RESULT([$JVM_FEATURES])
+    AC_MSG_CHECKING([user specified JVM feature list])
+    USER_JVM_FEATURE_LIST=`$ECHO $with_jvm_features | $SED -e 's/,/ /g'`
+    AC_MSG_RESULT([$user_jvm_feature_list])
+    # These features will be added to all variant defaults
+    JVM_FEATURES=`$ECHO $USER_JVM_FEATURE_LIST | $AWK '{ for (i=1; i<=NF; i++) if (!match($i, /-.*/)) print $i }'`
+    # These features will be removed from all variant defaults
+    DISABLED_JVM_FEATURES=`$ECHO $USER_JVM_FEATURE_LIST | $AWK '{ for (i=1; i<=NF; i++) if (match($i, /-.*/)) print substr($i, 2) }'`
+
+    # Verify that the user has provided valid features
+    BASIC_GET_NON_MATCHING_VALUES(INVALID_FEATURES, $JVM_FEATURES $DISABLED_JVM_FEATURES, $VALID_JVM_FEATURES)
+    if test "x$INVALID_FEATURES" != x; then
+      AC_MSG_NOTICE([Unknown JVM features specified: "$INVALID_FEATURES"])
+      AC_MSG_NOTICE([The available JVM features are: "$VALID_JVM_FEATURES"])
+      AC_MSG_ERROR([Cannot continue])
+    fi
+
   fi
 
   # Override hotspot cpu definitions for ARM platforms
@@ -390,7 +400,7 @@
     NON_MINIMAL_FEATURES="$NON_MINIMAL_FEATURES cds"
   fi
 
-  # Enable features depending on variant.
+  # Enable default features depending on variant.
   JVM_FEATURES_server="compiler1 compiler2 $NON_MINIMAL_FEATURES $JVM_FEATURES $JVM_FEATURES_jvmci $JVM_FEATURES_aot $JVM_FEATURES_graal"
   JVM_FEATURES_client="compiler1 $NON_MINIMAL_FEATURES $JVM_FEATURES $JVM_FEATURES_jvmci"
   JVM_FEATURES_core="$NON_MINIMAL_FEATURES $JVM_FEATURES"
@@ -413,29 +423,29 @@
 ])
 
 ###############################################################################
-# Validate JVM features once all setup is complete, including custom setup.
+# Finalize JVM features once all setup is complete, including custom setup.
 #
-AC_DEFUN_ONCE([HOTSPOT_VALIDATE_JVM_FEATURES],
+AC_DEFUN_ONCE([HOTSPOT_FINALIZE_JVM_FEATURES],
 [
-  # Keep feature lists sorted and free of duplicates
-  JVM_FEATURES_server="$($ECHO $($PRINTF '%s\n' $JVM_FEATURES_server | $SORT -u))"
-  JVM_FEATURES_client="$($ECHO $($PRINTF '%s\n' $JVM_FEATURES_client | $SORT -u))"
-  JVM_FEATURES_core="$($ECHO $($PRINTF '%s\n' $JVM_FEATURES_core | $SORT -u))"
-  JVM_FEATURES_minimal="$($ECHO $($PRINTF '%s\n' $JVM_FEATURES_minimal | $SORT -u))"
-  JVM_FEATURES_zero="$($ECHO $($PRINTF '%s\n' $JVM_FEATURES_zero | $SORT -u))"
-  JVM_FEATURES_custom="$($ECHO $($PRINTF '%s\n' $JVM_FEATURES_custom | $SORT -u))"
-
-  # Validate features
   for variant in $JVM_VARIANTS; do
     AC_MSG_CHECKING([JVM features for JVM variant '$variant'])
     features_var_name=JVM_FEATURES_$variant
-    JVM_FEATURES_TO_TEST=${!features_var_name}
-    AC_MSG_RESULT([$JVM_FEATURES_TO_TEST])
-    NEEDLE=${VALID_JVM_FEATURES// /$'\n'}
-    STACK=${JVM_FEATURES_TO_TEST// /$'\n'}
-    INVALID_FEATURES=`$GREP -Fvx "${NEEDLE}" <<< "${STACK}"`
+    JVM_FEATURES_FOR_VARIANT=${!features_var_name}
+
+    # Filter out user-requested disabled features
+    BASIC_GET_NON_MATCHING_VALUES(JVM_FEATURES_FOR_VARIANT, $JVM_FEATURES_FOR_VARIANT, $DISABLED_JVM_FEATURES)
+
+    # Keep feature lists sorted and free of duplicates
+    BASIC_SORT_LIST(JVM_FEATURES_FOR_VARIANT, $JVM_FEATURES_FOR_VARIANT)
+
+    # Update real feature set variable
+    eval $features_var_name='"'$JVM_FEATURES_FOR_VARIANT'"'
+    AC_MSG_RESULT(["$JVM_FEATURES_FOR_VARIANT"])
+
+    # Validate features (for configure script errors, not user errors)
+    INVALID_FEATURES=`$GREP -Fvx "${VALID_JVM_FEATURES// /$'\n'}" <<< "${JVM_FEATURES_FOR_VARIANT// /$'\n'}"`
     if test "x$INVALID_FEATURES" != x; then
-      AC_MSG_ERROR([Invalid JVM feature(s): $INVALID_FEATURES])
+      AC_MSG_ERROR([Internal configure script error. Invalid JVM feature(s): $INVALID_FEATURES])
     fi
   done
 ])