# HG changeset patch # User hseigel # Date 1472661661 0 # Node ID 79489d5bfe1f29c5bd6dc50dbc1f46adeebaabd9 # Parent 791a3458971d6ba9a192a19d661a5d19720b6c2c# Parent cff45787a061f713ff9bd3836455668375765105 Merge diff -r 791a3458971d -r 79489d5bfe1f hotspot/src/share/vm/runtime/arguments.cpp --- a/hotspot/src/share/vm/runtime/arguments.cpp Wed Aug 31 16:48:26 2016 +0200 +++ b/hotspot/src/share/vm/runtime/arguments.cpp Wed Aug 31 16:41:01 2016 +0000 @@ -163,26 +163,47 @@ bool needs_module_property_warning = false; -#define MODULE_PROPERTY_PREFIX "jdk.module" -#define MODULE_PROPERTY_PREFIX_LEN 10 -#define MODULE_MAIN_PROPERTY "jdk.module.main" -#define MODULE_MAIN_PROPERTY_LEN 15 - -// Return TRUE if option matches property, or property=, or property.. -static bool matches_property_prefix(const char* option, const char* property, size_t len) { - return (strncmp(option, property, len) == 0) && - (option[len] == '=' || option[len] == '.' || option[len] == '\0'); +#define MODULE_PROPERTY_PREFIX "jdk.module." +#define MODULE_PROPERTY_PREFIX_LEN 11 +#define ADDEXPORTS "addexports" +#define ADDEXPORTS_LEN 10 +#define ADDREADS "addreads" +#define ADDREADS_LEN 8 +#define PATCH "patch" +#define PATCH_LEN 5 +#define ADDMODS "addmods" +#define ADDMODS_LEN 7 +#define LIMITMODS "limitmods" +#define LIMITMODS_LEN 9 +#define PATH "path" +#define PATH_LEN 4 +#define UPGRADE_PATH "upgrade.path" +#define UPGRADE_PATH_LEN 12 + +// Return TRUE if option matches 'property', or 'property=', or 'property.'. +static bool matches_property_suffix(const char* option, const char* property, size_t len) { + return ((strncmp(option, property, len) == 0) && + (option[len] == '=' || option[len] == '.' || option[len] == '\0')); } -// Return true if the property is either "jdk.module" or starts with "jdk.module.", -// but does not start with "jdk.module.main". -// Return false if jdk.module.main because jdk.module.main and jdk.module.main.class -// are valid non-internal system properties. -// "property" should be passed without the leading "-D". +// Return true if property starts with "jdk.module." and its ensuing chars match +// any of the reserved module properties. +// property should be passed without the leading "-D". bool Arguments::is_internal_module_property(const char* property) { assert((strncmp(property, "-D", 2) != 0), "Unexpected leading -D"); - return (matches_property_prefix(property, MODULE_PROPERTY_PREFIX, MODULE_PROPERTY_PREFIX_LEN) && - !matches_property_prefix(property, MODULE_MAIN_PROPERTY, MODULE_MAIN_PROPERTY_LEN)); + if (strncmp(property, MODULE_PROPERTY_PREFIX, MODULE_PROPERTY_PREFIX_LEN) == 0) { + const char* property_suffix = property + MODULE_PROPERTY_PREFIX_LEN; + if (matches_property_suffix(property_suffix, ADDEXPORTS, ADDEXPORTS_LEN) || + matches_property_suffix(property_suffix, ADDREADS, ADDREADS_LEN) || + matches_property_suffix(property_suffix, PATCH, PATCH_LEN) || + matches_property_suffix(property_suffix, ADDMODS, ADDMODS_LEN) || + matches_property_suffix(property_suffix, LIMITMODS, LIMITMODS_LEN) || + matches_property_suffix(property_suffix, PATH, PATH_LEN) || + matches_property_suffix(property_suffix, UPGRADE_PATH, UPGRADE_PATH_LEN)) { + return true; + } + } + return false; } // Process java launcher properties. @@ -4287,8 +4308,8 @@ } if (needs_module_property_warning) { - warning("Ignoring system property options whose names start with '-Djdk.module'." - " They are reserved for internal use."); + warning("Ignoring system property options whose names match the '-Djdk.module.*'." + " names that are reserved for internal use."); } #if defined(_ALLBSD_SOURCE) || defined(AIX) // UseLargePages is not yet supported on BSD and AIX. diff -r 791a3458971d -r 79489d5bfe1f hotspot/test/runtime/modules/ModuleOptionsWarn.java --- a/hotspot/test/runtime/modules/ModuleOptionsWarn.java Wed Aug 31 16:48:26 2016 +0200 +++ b/hotspot/test/runtime/modules/ModuleOptionsWarn.java Wed Aug 31 16:41:01 2016 +0000 @@ -29,6 +29,7 @@ * @library /test/lib */ +import java.util.Map; import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.process.ProcessTools; @@ -37,16 +38,65 @@ public static void main(String[] args) throws Exception { - // Test that a warning is issued for module related properties that get ignored. + // Test that a warning is not issued for extraneous jdk.module properties. ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( "-XX:+PrintWarnings", "-Djdk.module.ignored", "-version"); OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldNotContain("Ignoring system property option"); + output.shouldHaveExitValue(0); + + // Test that a warning is issued for a reserved jdk.module property. + pb = ProcessTools.createJavaProcessBuilder( + "-XX:+PrintWarnings", "-Djdk.module.addmods", "-version"); + output = new OutputAnalyzer(pb.start()); + output.shouldContain("Ignoring system property option"); + output.shouldHaveExitValue(0); + + // Test that a warning is issued for a reserved jdk.module property ending in '.'. + pb = ProcessTools.createJavaProcessBuilder( + "-XX:+PrintWarnings", "-Djdk.module.limitmods.", "-version"); + output = new OutputAnalyzer(pb.start()); + output.shouldContain("Ignoring system property option"); + output.shouldHaveExitValue(0); + + // Test that a warning is issued for a reserved jdk.module property ending in '='. + pb = ProcessTools.createJavaProcessBuilder( + "-XX:+PrintWarnings", "-Djdk.module.addexports=", "-version"); + output = new OutputAnalyzer(pb.start()); + output.shouldContain("Ignoring system property option"); + output.shouldHaveExitValue(0); + + // Test that a warning is issued for a reserved jdk.module property ending in ".stuff" + pb = ProcessTools.createJavaProcessBuilder( + "-XX:+PrintWarnings", "-Djdk.module.addreads.stuff", "-version"); + output = new OutputAnalyzer(pb.start()); + output.shouldContain("Ignoring system property option"); + output.shouldHaveExitValue(0); + + // Test that a warning is issued for a reserved jdk.module property ending in "=stuff" + pb = ProcessTools.createJavaProcessBuilder( + "-XX:+PrintWarnings", "-Djdk.module.path=stuff", "-version"); + output = new OutputAnalyzer(pb.start()); + output.shouldContain("Ignoring system property option"); + output.shouldHaveExitValue(0); + + // Test that a warning is issued for a reserved jdk.module property ending in ".=" + pb = ProcessTools.createJavaProcessBuilder( + "-XX:+PrintWarnings", "-Djdk.module.upgrade.path.=xx", "-version"); + output = new OutputAnalyzer(pb.start()); + output.shouldContain("Ignoring system property option"); + output.shouldHaveExitValue(0); + + // Test that a warning is issued for a reserved jdk.module property ending in "." + pb = ProcessTools.createJavaProcessBuilder( + "-XX:+PrintWarnings", "-Djdk.module.patch.3=xx", "-version"); + output = new OutputAnalyzer(pb.start()); output.shouldContain("Ignoring system property option"); output.shouldHaveExitValue(0); // Test that a warning can be suppressed for module related properties that get ignored. pb = ProcessTools.createJavaProcessBuilder( - "-Djdk.module.ignored", "-XX:-PrintWarnings", "-version"); + "-Djdk.module.addmods", "-XX:-PrintWarnings", "-version"); output = new OutputAnalyzer(pb.start()); output.shouldNotContain("Ignoring system property option"); output.shouldHaveExitValue(0); @@ -57,5 +107,13 @@ output = new OutputAnalyzer(pb.start()); output.shouldNotContain("Ignoring system property option"); output.shouldHaveExitValue(0); + + // Test that a warning is issued for module related properties specified using _JAVA_OPTIONS. + pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintWarnings", "-version"); + Map env = pb.environment(); + env.put("_JAVA_OPTIONS", "-Djdk.module.addreads"); + output = new OutputAnalyzer(pb.start()); + output.shouldContain("Ignoring system property option"); + output.shouldHaveExitValue(0); } }