changeset 9413:f090597d24df

8141068: refactor -XXFlags= code in preparation for removal Reviewed-by: dcubed, gthornbr, coleenp
author rdurbin
date Wed, 11 Nov 2015 14:57:27 -0800
parents aabefa3ef38d
children e1a7a5dbdf59 a7ffcce47ffb
files src/share/vm/runtime/arguments.cpp src/share/vm/runtime/arguments.hpp
diffstat 2 files changed, 20 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/runtime/arguments.cpp	Wed Nov 11 11:47:20 2015 -0800
+++ b/src/share/vm/runtime/arguments.cpp	Wed Nov 11 14:57:27 2015 -0800
@@ -74,6 +74,7 @@
   }                                                                   \
 } while(0)
 
+char*  Arguments::_jvm_flags_file               = NULL;
 char** Arguments::_jvm_flags_array              = NULL;
 int    Arguments::_num_jvm_flags                = 0;
 char** Arguments::_jvm_args_array               = NULL;
@@ -3957,7 +3958,6 @@
 #endif // PRODUCT
 
 jint Arguments::insert_vm_options_file(const JavaVMInitArgs* args,
-                                       char** flags_file,
                                        char** vm_options_file,
                                        const int vm_options_file_pos,
                                        ScopedVMInitArgs *vm_options_file_args,
@@ -3976,13 +3976,12 @@
 }
 
 jint Arguments::match_special_option_and_act(const JavaVMInitArgs* args,
-                                             char ** flags_file,
                                              char ** vm_options_file,
-                                             ScopedVMInitArgs* vm_options_file_args,
                                              ScopedVMInitArgs* args_out) {
   // Remaining part of option string
   const char* tail;
   int   vm_options_file_pos = -1;
+  ScopedVMInitArgs vm_options_file_args;
 
   for (int index = 0; index < args->nOptions; index++) {
     const JavaVMOption* option = args->options + index;
@@ -3990,12 +3989,7 @@
       continue;
     }
     if (match_option(option, "-XX:Flags=", &tail)) {
-      *flags_file = (char *) tail;
-      if (*flags_file == NULL) {
-        jio_fprintf(defaultStream::error_stream(),
-                    "Cannot copy flags_file name.\n");
-        return JNI_ENOMEM;
-      }
+      Arguments::set_jvm_flags_file(tail);
       continue;
     }
     if (match_option(option, "-XX:VMOptionsFile=", &tail)) {
@@ -4011,9 +4005,9 @@
         *vm_options_file = (char *) tail;
         vm_options_file_pos = index;  // save position of -XX:VMOptionsFile
         // If there's a VMOptionsFile, parse that (also can set flags_file)
-        jint code = insert_vm_options_file(args, flags_file, vm_options_file,
+        jint code = insert_vm_options_file(args, vm_options_file,
                                            vm_options_file_pos,
-                                           vm_options_file_args, args_out);
+                                           &vm_options_file_args, args_out);
         if (code != JNI_OK) {
           return code;
         }
@@ -4109,16 +4103,12 @@
 
   // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed.
   const char* hotspotrc = ".hotspotrc";
-  char* flags_file = NULL;
   char* vm_options_file = NULL;
   bool settings_file_specified = false;
   bool needs_hotspotrc_warning = false;
   ScopedVMInitArgs java_tool_options_args;
   ScopedVMInitArgs java_options_args;
   ScopedVMInitArgs modified_cmd_line_args;
-  // Pass in vm_options_file_args to keep memory for flags_file from being
-  // deallocated if found in the vm options file.
-  ScopedVMInitArgs vm_options_file_args;
 
   jint code =
       parse_java_tool_options_environment_variable(&java_tool_options_args);
@@ -4132,13 +4122,12 @@
   }
 
   code = match_special_option_and_act(java_tool_options_args.get(),
-                                      &flags_file, NULL, NULL, NULL);
+                                      NULL, NULL);
   if (code != JNI_OK) {
     return code;
   }
 
-  code = match_special_option_and_act(args, &flags_file, &vm_options_file,
-                                      &vm_options_file_args,
+  code = match_special_option_and_act(args, &vm_options_file,
                                       &modified_cmd_line_args);
   if (code != JNI_OK) {
     return code;
@@ -4150,12 +4139,13 @@
     args = modified_cmd_line_args.get();
   }
 
-  code = match_special_option_and_act(java_options_args.get(), &flags_file,
-                                      NULL, NULL, NULL);
+  code = match_special_option_and_act(java_options_args.get(),
+                                      NULL, NULL);
   if (code != JNI_OK) {
     return code;
   }
 
+  const char * flags_file = Arguments::get_jvm_flags_file();
   settings_file_specified = (flags_file != NULL);
 
   if (IgnoreUnrecognizedVMOptions) {
--- a/src/share/vm/runtime/arguments.hpp	Wed Nov 11 11:47:20 2015 -0800
+++ b/src/share/vm/runtime/arguments.hpp	Wed Nov 11 14:57:27 2015 -0800
@@ -244,6 +244,8 @@
 
  private:
 
+  // a pointer to the flags file name if it is specified
+  static char*  _jvm_flags_file;
   // an array containing all flags specified in the .hotspotrc file
   static char** _jvm_flags_array;
   static int    _num_jvm_flags;
@@ -378,15 +380,12 @@
   static jint parse_vm_options_file(const char* file_name, ScopedVMInitArgs* vm_args);
   static jint parse_options_buffer(const char* name, char* buffer, const size_t buf_len, ScopedVMInitArgs* vm_args);
   static jint insert_vm_options_file(const JavaVMInitArgs* args,
-                                     char** flags_file,
                                      char** vm_options_file,
                                      const int vm_options_file_pos,
                                      ScopedVMInitArgs* vm_options_file_args,
                                      ScopedVMInitArgs* args_out);
   static jint match_special_option_and_act(const JavaVMInitArgs* args,
-                                           char** flags_file,
                                            char** vm_options_file,
-                                           ScopedVMInitArgs* vm_options_file_args,
                                            ScopedVMInitArgs* args_out);
 
   static jint parse_vm_init_args(const JavaVMInitArgs *java_tool_options_args,
@@ -514,6 +513,14 @@
   static void print_on(outputStream* st);
   static void print_summary_on(outputStream* st);
 
+  // convenient methods to get and set jvm_flags_file
+  static const char* get_jvm_flags_file()  { return _jvm_flags_file; }
+  static void set_jvm_flags_file(const char *value) {
+    if (_jvm_flags_file != NULL) {
+      os::free(_jvm_flags_file);
+    }
+    _jvm_flags_file = os::strdup_check_oom(value);
+  }
   // convenient methods to obtain / print jvm_flags and jvm_args
   static const char* jvm_flags()           { return build_resource_string(_jvm_flags_array, _num_jvm_flags); }
   static const char* jvm_args()            { return build_resource_string(_jvm_args_array, _num_jvm_args); }