8073989: Deprecated integer options are considered as invalid instead of deprecated in Java 9
authormockner
Thu, 16 Apr 2015 11:00:10 -0400
changeset 30242 5b15a65d4373
parent 30240 a7ba42fa1df6
child 30243 f71a6f74bbcb
8073989: Deprecated integer options are considered as invalid instead of deprecated in Java 9 Summary: Deprecated integer options are now recognized as being deprecated. Reviewed-by: dholmes, hseigel, ddmitriev
hotspot/src/share/vm/runtime/arguments.cpp
hotspot/test/runtime/CommandLine/ObsoleteFlagErrorMessage.java
--- a/hotspot/src/share/vm/runtime/arguments.cpp	Wed Apr 15 17:34:28 2015 -0700
+++ b/hotspot/src/share/vm/runtime/arguments.cpp	Thu Apr 16 11:00:10 2015 -0400
@@ -286,11 +286,8 @@
     // <flag>=xxx form
     // [-|+]<flag> form
     size_t len = strlen(flag_status.name);
-    if (((strncmp(flag_status.name, s, len) == 0) &&
-         (strlen(s) == len)) ||
-        ((s[0] == '+' || s[0] == '-') &&
-         (strncmp(flag_status.name, &s[1], len) == 0) &&
-         (strlen(&s[1]) == len))) {
+    if ((strncmp(flag_status.name, s, len) == 0) &&
+        (strlen(s) == len)){
       if (JDK_Version::current().compare(flag_status.accept_until) == -1) {
           *version = flag_status.obsoleted_in;
           return true;
@@ -806,17 +803,9 @@
     return true;
   }
 
+  // Determine if the flag has '+', '-', or '=' characters.
   bool has_plus_minus = (*arg == '+' || *arg == '-');
   const char* const argname = has_plus_minus ? arg + 1 : arg;
-  if (is_newly_obsolete(arg, &since)) {
-    char version[256];
-    since.to_string(version, sizeof(version));
-    warning("ignoring option %s; support was removed in %s", argname, version);
-    return true;
-  }
-
-  // For locked flags, report a custom error message if available.
-  // Otherwise, report the standard unrecognized VM option.
 
   size_t arg_len;
   const char* equal_sign = strchr(argname, '=');
@@ -826,6 +815,20 @@
     arg_len = equal_sign - argname;
   }
 
+  // Construct a string which consists only of the argument name without '+', '-', or '='.
+  char stripped_argname[256];
+  strncpy(stripped_argname, argname, arg_len);
+  stripped_argname[arg_len] = '\0'; //strncpy doesn't null terminate.
+
+  if (is_newly_obsolete(stripped_argname, &since)) {
+    char version[256];
+    since.to_string(version, sizeof(version));
+    warning("ignoring option %s; support was removed in %s", stripped_argname, version);
+    return true;
+  }
+
+  // For locked flags, report a custom error message if available.
+  // Otherwise, report the standard unrecognized VM option.
   Flag* found_flag = Flag::find_flag((const char*)argname, arg_len, true, true);
   if (found_flag != NULL) {
     char locked_message_buf[BUFLEN];
@@ -854,16 +857,8 @@
                   (fuzzy_matched->is_bool()) ? "(+/-)" : "",
                   fuzzy_matched->_name,
                   (fuzzy_matched->is_bool()) ? "" : "=<value>");
-      if (is_newly_obsolete(fuzzy_matched->_name, &since)) {
-        char version[256];
-        since.to_string(version, sizeof(version));
-        jio_fprintf(defaultStream::error_stream(),
-                    "Warning: support for %s was removed in %s\n",
-                    fuzzy_matched->_name,
-                    version);
     }
   }
-  }
 
   // allow for commandline "commenting out" options like -XX:#+Verbose
   return arg[0] == '#';
--- a/hotspot/test/runtime/CommandLine/ObsoleteFlagErrorMessage.java	Wed Apr 15 17:34:28 2015 -0700
+++ b/hotspot/test/runtime/CommandLine/ObsoleteFlagErrorMessage.java	Thu Apr 16 11:00:10 2015 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2015 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
@@ -23,24 +23,30 @@
 
 /*
  * @test
- * @bug 8060449
+ * @bug 8060449 8073989
  * @summary Newly obsolete command line options should still give useful error messages when used improperly.
  * @library /testlibrary
- * @modules java.base/sun.misc
- *          java.management
  */
 
 import com.oracle.java.testlibrary.*;
 
 public class ObsoleteFlagErrorMessage {
   public static void main(String[] args) throws Exception {
+
+    // Case 1: Newly obsolete flags with extra junk appended should not be treated as newly obsolete (8060449)
     ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
-        "-XX:UseBoundThreadsPlusJunk", "-version");
+        "-XX:UseOldInliningPlusJunk", "-version");
 
     OutputAnalyzer output = new OutputAnalyzer(pb.start());
-    output.shouldContain("Unrecognized VM option 'UseBoundThreadsPlusJunk'"); // Must identify bad option.
-    output.shouldContain("UseBoundThreads"); // Should apply fuzzy matching to find correct option.
-    output.shouldContain("support").shouldContain("removed"); // Should warn user that the option they are trying to use is no longer supported.
+    output.shouldContain("Unrecognized VM option 'UseOldInliningPlusJunk'"); // Must identify bad option.
     output.shouldHaveExitValue(1);
+
+    // Case 2: Newly obsolete integer-valued flags should be recognized as newly obsolete (8073989)
+    ProcessBuilder pb2 = ProcessTools.createJavaProcessBuilder(
+        "-XX:NmethodSweepFraction=10", "-version");
+
+    OutputAnalyzer output2 = new OutputAnalyzer(pb2.start());
+    output2.shouldContain("ignoring option").shouldContain("support was removed");
+    output2.shouldContain("NmethodSweepFraction");
   }
 }