Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8136552

Last argument wins does not work for special options with "-XX:VMOptionsFile" option

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 9
    • 9
    • hotspot
    • b89

    Backports

      Description

        If we have option file(name it "optionfile") with option which have special behavior("-XX:+PrintVMOptions") and ran java with following options:
        ./java -XX:VMOptionsFile=optionfile -XX:-PrintVMOptions -version

        We expect that special PrintVMOption will be disabled since "last argument wins", because "-XX:-PrintVMOptions" is specified after VM Options file. But in current implementation we see:
        java -XX:VMOptionsFile=optionfile -XX:-PrintVMOptions -version
        VM option '+PrintVMOptions'
        VM option '-PrintVMOptions'

        That means that special option got value from VM Options file. This applied to the all special options("-XX:Flags", "-XX:+IgnoreUnrecognizedVMOptions" etc.). The problem is that in Arguments::match_special_option_and_act function "match specail option and act" mechanism is applied to the VM Options file only after all options from command line are compared with special options:
        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;

          for (int index = 0; index < args->nOptions; index++) {
            const JavaVMOption* option = args->options + index;
            if (ArgumentsExt::process_options(option)) {
              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;
              }
              continue;
            }
            if (match_option(option, "-XX:VMOptionsFile=", &tail)) {
        ...
            }
            if (match_option(option, "-XX:+PrintVMOptions")) {
              PrintVMOptions = true;
              continue;
            }
        ...
          }

          // If there's a VMOptionsFile, parse that (also can set flags_file)
          if ((vm_options_file != NULL) && (*vm_options_file != NULL)) {
            return insert_vm_options_file(args, flags_file, vm_options_file,
                                          vm_options_file_pos, vm_options_file_args, args_out);
          }
          return JNI_OK;
        }

        Attachments

          Issue Links

            Activity

              People

                rdurbin Ron Durbin (Inactive)
                ddmitriev Dmitry Dmitriev
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: