< prev index next >

src/share/vm/runtime/arguments.cpp

Print this page




  74 char** Arguments::_jvm_flags_array              = NULL;
  75 int    Arguments::_num_jvm_flags                = 0;
  76 char** Arguments::_jvm_args_array               = NULL;
  77 int    Arguments::_num_jvm_args                 = 0;
  78 char*  Arguments::_java_command                 = NULL;
  79 SystemProperty* Arguments::_system_properties   = NULL;
  80 const char*  Arguments::_gc_log_filename        = NULL;
  81 bool   Arguments::_has_profile                  = false;
  82 size_t Arguments::_conservative_max_heap_alignment = 0;
  83 size_t Arguments::_min_heap_size                = 0;
  84 uintx  Arguments::_min_heap_free_ratio          = 0;
  85 uintx  Arguments::_max_heap_free_ratio          = 0;
  86 Arguments::Mode Arguments::_mode                = _mixed;
  87 bool   Arguments::_java_compiler                = false;
  88 bool   Arguments::_xdebug_mode                  = false;
  89 const char*  Arguments::_java_vendor_url_bug    = DEFAULT_VENDOR_URL_BUG;
  90 const char*  Arguments::_sun_java_launcher      = DEFAULT_JAVA_LAUNCHER;
  91 int    Arguments::_sun_java_launcher_pid        = -1;
  92 bool   Arguments::_sun_java_launcher_is_altjvm  = false;
  93 
  94 // These parameters are reset in method parse_vm_init_args(JavaVMInitArgs*)
  95 bool   Arguments::_AlwaysCompileLoopMethods     = AlwaysCompileLoopMethods;
  96 bool   Arguments::_UseOnStackReplacement        = UseOnStackReplacement;
  97 bool   Arguments::_BackgroundCompilation        = BackgroundCompilation;
  98 bool   Arguments::_ClipInlining                 = ClipInlining;
  99 intx   Arguments::_Tier3InvokeNotifyFreqLog     = Tier3InvokeNotifyFreqLog;
 100 intx   Arguments::_Tier4InvocationThreshold     = Tier4InvocationThreshold;
 101 
 102 char*  Arguments::SharedArchivePath             = NULL;
 103 
 104 AgentLibraryList Arguments::_libraryList;
 105 AgentLibraryList Arguments::_agentList;
 106 
 107 abort_hook_t     Arguments::_abort_hook         = NULL;
 108 exit_hook_t      Arguments::_exit_hook          = NULL;
 109 vfprintf_hook_t  Arguments::_vfprintf_hook      = NULL;
 110 
 111 
 112 SystemProperty *Arguments::_sun_boot_library_path = NULL;
 113 SystemProperty *Arguments::_java_library_path = NULL;
 114 SystemProperty *Arguments::_java_home = NULL;


2232       bool value_is_too_large = n > max_uintx;
2233 
2234       if (above_minimum && !value_is_too_large) {
2235         *uintx_arg = n;
2236         return true;
2237       }
2238     }
2239   }
2240   return false;
2241 }
2242 
2243 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
2244                                                   julong* long_arg,
2245                                                   julong min_size) {
2246   if (!atomull(s, long_arg)) return arg_unreadable;
2247   return check_memory_size(*long_arg, min_size);
2248 }
2249 
2250 // Parse JavaVMInitArgs structure
2251 
2252 jint Arguments::parse_vm_init_args(const JavaVMInitArgs* args) {


2253   // For components of the system classpath.
2254   SysClassPath scp(Arguments::get_sysclasspath());
2255   bool scp_assembly_required = false;
2256 
2257   // Save default settings for some mode flags
2258   Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
2259   Arguments::_UseOnStackReplacement    = UseOnStackReplacement;
2260   Arguments::_ClipInlining             = ClipInlining;
2261   Arguments::_BackgroundCompilation    = BackgroundCompilation;
2262   if (TieredCompilation) {
2263     Arguments::_Tier3InvokeNotifyFreqLog = Tier3InvokeNotifyFreqLog;
2264     Arguments::_Tier4InvocationThreshold = Tier4InvocationThreshold;
2265   }
2266 
2267   // Setup flags for mixed which is the default
2268   set_mode_flags(_mixed);
2269 
2270   // Parse JAVA_TOOL_OPTIONS environment variable (if present)
2271   jint result = parse_java_tool_options_environment_variable(&scp, &scp_assembly_required);


2272   if (result != JNI_OK) {
2273     return result;
2274   }
2275 
2276   // Parse JavaVMInitArgs structure passed in
2277   result = parse_each_vm_init_arg(args, &scp, &scp_assembly_required, Flag::COMMAND_LINE);

2278   if (result != JNI_OK) {
2279     return result;
2280   }
2281 
2282   // Parse _JAVA_OPTIONS environment variable (if present) (mimics classic VM)
2283   result = parse_java_options_environment_variable(&scp, &scp_assembly_required);


2284   if (result != JNI_OK) {
2285     return result;
2286   }
2287 
2288   // Do final processing now that all arguments have been parsed
2289   result = finalize_vm_init_args(&scp, scp_assembly_required);
2290   if (result != JNI_OK) {
2291     return result;
2292   }
2293 
2294   return JNI_OK;
2295 }
2296 
2297 // Checks if name in command-line argument -agent{lib,path}:name[=options]
2298 // represents a valid HPROF of JDWP agent.  is_path==true denotes that we
2299 // are dealing with -agentpath (case where name is a path), otherwise with
2300 // -agentlib
2301 bool valid_hprof_or_jdwp_agent(char *name, bool is_path) {
2302   char *_name;
2303   const char *_hprof = "hprof", *_jdwp = "jdwp";


3366         jio_snprintf(buffer, sizeof(buffer), "java.awt.headless=%s", headless_env);
3367         if (!add_property(buffer)) {
3368           return JNI_ENOMEM;
3369         }
3370       }
3371     }
3372   }
3373 
3374   if (UseConcMarkSweepGC && FLAG_IS_DEFAULT(UseParNewGC) && !UseParNewGC) {
3375     // CMS can only be used with ParNew
3376     FLAG_SET_ERGO(bool, UseParNewGC, true);
3377   }
3378 
3379   if (!check_vm_args_consistency()) {
3380     return JNI_ERR;
3381   }
3382 
3383   return JNI_OK;
3384 }
3385 
3386 jint Arguments::parse_java_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
3387   return parse_options_environment_variable("_JAVA_OPTIONS", scp_p,
3388                                             scp_assembly_required_p);
3389 }
3390 
3391 jint Arguments::parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
3392   return parse_options_environment_variable("JAVA_TOOL_OPTIONS", scp_p,
3393                                             scp_assembly_required_p);
3394 }
3395 
3396 jint Arguments::parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p) {
3397   char *buffer = ::getenv(name);
3398 
3399   // Don't check this variable if user has special privileges





3400   // (e.g. unix su command).
3401   if (buffer == NULL || os::have_special_privileges()) {
3402     return JNI_OK;
3403   }
3404 
3405   if ((buffer = os::strdup(buffer)) == NULL) {
3406     return JNI_ENOMEM;
3407   }
3408 
3409   GrowableArray<JavaVMOption> *options = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<JavaVMOption>(2, true);    // Construct option array
3410   jio_fprintf(defaultStream::error_stream(),
3411               "Picked up %s: %s\n", name, buffer);
3412   char* rd = buffer;                        // pointer to the input string (rd)
3413   while (true) {                            // repeat for all options in the input string
3414     while (isspace(*rd)) rd++;              // skip whitespace
3415     if (*rd == 0) break;                    // we re done when the input string is read completely
3416 
3417     // The output, option string, overwrites the input string.
3418     // Because of quoting, the pointer to the option string (wrt) may lag the pointer to
3419     // input string (rd).
3420     char* wrt = rd;

3421 
3422     JavaVMOption option;
3423     option.optionString = wrt;
3424     options->append(option);                // Fill in option
3425     while (*rd != 0 && !isspace(*rd)) {     // unquoted strings terminate with a space or NULL
3426       if (*rd == '\'' || *rd == '"') {      // handle a quoted string
3427         int quote = *rd;                    // matching quote to look for
3428         rd++;                               // don't copy open quote
3429         while (*rd != quote) {              // include everything (even spaces) up until quote
3430           if (*rd == 0) {                   // string termination means unmatched string
3431             jio_fprintf(defaultStream::error_stream(),
3432                         "Unmatched quote in %s\n", name);
3433             delete options;
3434             os::free(buffer);
3435             return JNI_ERR;
3436           }
3437           *wrt++ = *rd++;                   // copy to option string
3438         }
3439         rd++;                               // don't copy close quote
3440       } else {
3441         *wrt++ = *rd++;                     // copy to option string
3442       }
3443     }
3444     // Need to check if we're done before writing a NULL,
3445     // because the write could be to the byte that rd is pointing to.
3446     if (*rd++ == 0) {
3447       *wrt = 0;
3448       break;
3449     }
3450     *wrt = 0;                               // Zero terminate option




3451   }


3452   JavaVMOption* options_arr =
3453       NEW_C_HEAP_ARRAY_RETURN_NULL(JavaVMOption, options->length(), mtInternal);
3454   if (options_arr == NULL) {
3455     delete options;
3456     os::free(buffer);
3457     return JNI_ENOMEM;
3458   }
3459   for (int i = 0; i < options->length(); i++) {
3460     options_arr[i] = options->at(i);
3461   }
3462 
3463   // Construct JavaVMInitArgs structure and parse as if it was part of the command line
3464   JavaVMInitArgs vm_args;
3465   vm_args.version = JNI_VERSION_1_2;
3466   vm_args.options = options_arr;
3467   vm_args.nOptions = options->length();
3468   vm_args.ignoreUnrecognized = IgnoreUnrecognizedVMOptions;
3469 
3470   if (PrintVMOptions) {
3471     const char* tail;
3472     for (int i = 0; i < vm_args.nOptions; i++) {
3473       const JavaVMOption *option = vm_args.options + i;
3474       if (match_option(option, "-XX:", &tail)) {
3475         logOption(tail);
3476       }
3477     }
3478   }
3479 
3480   jint result = parse_each_vm_init_arg(&vm_args, scp_p, scp_assembly_required_p,
3481                                        Flag::ENVIRON_VAR);
3482   FREE_C_HEAP_ARRAY(JavaVMOption, options_arr);
3483   delete options;
3484   os::free(buffer);
3485   return result;
3486 }
3487 
3488 void Arguments::set_shared_spaces_flags() {
3489   if (DumpSharedSpaces) {
3490     if (RequireSharedSpaces) {
3491       warning("cannot dump shared archive while using shared archive");
3492     }
3493     UseSharedSpaces = false;
3494 #ifdef _LP64
3495     if (!UseCompressedOops || !UseCompressedClassPointers) {
3496       vm_exit_during_initialization(
3497         "Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off.", NULL);
3498     }
3499   } else {
3500     if (!UseCompressedOops || !UseCompressedClassPointers) {
3501       no_shared_spaces("UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces.");
3502     }
3503 #endif
3504   }
3505 }


3548       (VerifyDependencies && FLAG_IS_CMDLINE(VerifyDependencies))) {
3549     return true;
3550   }
3551 
3552 #ifdef COMPILER1
3553   if (PrintC1Statistics) {
3554     return true;
3555   }
3556 #endif // COMPILER1
3557 
3558 #ifdef COMPILER2
3559   if (PrintOptoAssembly || PrintOptoStatistics) {
3560     return true;
3561   }
3562 #endif // COMPILER2
3563 
3564   return false;
3565 }
3566 #endif // PRODUCT
3567 
3568 // Parse entry point called from JNI_CreateJavaVM
3569 
3570 jint Arguments::parse(const JavaVMInitArgs* args) {
3571 
3572   // Initialize ranges and constraints
3573   CommandLineFlagRangeList::init();
3574   CommandLineFlagConstraintList::init();
3575 
3576   // Remaining part of option string
3577   const char* tail;
3578 
3579   // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed.
3580   const char* hotspotrc = ".hotspotrc";
3581   bool settings_file_specified = false;
3582   bool needs_hotspotrc_warning = false;
3583 
3584   const char* flags_file;
3585   int index;
3586   for (index = 0; index < args->nOptions; index++) {
3587     const JavaVMOption *option = args->options + index;
3588     if (ArgumentsExt::process_options(option)) {
3589       continue;
3590     }
3591     if (match_option(option, "-XX:Flags=", &tail)) {
3592       flags_file = tail;
3593       settings_file_specified = true;
3594       continue;
3595     }
3596     if (match_option(option, "-XX:+PrintVMOptions")) {
3597       PrintVMOptions = true;
3598       continue;
3599     }
3600     if (match_option(option, "-XX:-PrintVMOptions")) {
3601       PrintVMOptions = false;
3602       continue;
3603     }
3604     if (match_option(option, "-XX:+IgnoreUnrecognizedVMOptions")) {
3605       IgnoreUnrecognizedVMOptions = true;
3606       continue;
3607     }
3608     if (match_option(option, "-XX:-IgnoreUnrecognizedVMOptions")) {
3609       IgnoreUnrecognizedVMOptions = false;
3610       continue;
3611     }
3612     if (match_option(option, "-XX:+PrintFlagsInitial")) {
3613       CommandLineFlags::printFlags(tty, false);


3627           MemTracker::init();
3628         }
3629       } else {
3630         vm_exit_during_initialization("Syntax error, expecting -XX:NativeMemoryTracking=[off|summary|detail]", NULL);
3631       }
3632       continue;
3633 #else
3634       jio_fprintf(defaultStream::error_stream(),
3635         "Native Memory Tracking is not supported in this VM\n");
3636       return JNI_ERR;
3637 #endif
3638     }
3639 
3640 #ifndef PRODUCT
3641     if (match_option(option, "-XX:+PrintFlagsWithComments")) {
3642       CommandLineFlags::printFlags(tty, true);
3643       vm_exit(0);
3644     }
3645 #endif
3646   }







































3647 
3648   if (IgnoreUnrecognizedVMOptions) {
3649     // uncast const to modify the flag args->ignoreUnrecognized
3650     *(jboolean*)(&args->ignoreUnrecognized) = true;


3651   }
3652 
3653   // Parse specified settings file
3654   if (settings_file_specified) {
3655     if (!process_settings_file(flags_file, true, args->ignoreUnrecognized)) {
3656       return JNI_EINVAL;
3657     }
3658   } else {
3659 #ifdef ASSERT
3660     // Parse default .hotspotrc settings file
3661     if (!process_settings_file(".hotspotrc", false, args->ignoreUnrecognized)) {
3662       return JNI_EINVAL;
3663     }
3664 #else
3665     struct stat buf;
3666     if (os::stat(hotspotrc, &buf) == 0) {
3667       needs_hotspotrc_warning = true;
3668     }
3669 #endif
3670   }
3671 
3672   if (PrintVMOptions) {
3673     for (index = 0; index < args->nOptions; index++) {
3674       const JavaVMOption *option = args->options + index;
3675       if (match_option(option, "-XX:", &tail)) {
3676         logOption(tail);
3677       }
3678     }
3679   }
3680 
3681   // Parse JavaVMInitArgs structure passed in, as well as JAVA_TOOL_OPTIONS and _JAVA_OPTIONS
3682   jint result = parse_vm_init_args(args);












3683   if (result != JNI_OK) {
3684     return result;
3685   }
3686 
3687   // Call get_shared_archive_path() here, after possible SharedArchiveFile option got parsed.
3688   SharedArchivePath = get_shared_archive_path();
3689   if (SharedArchivePath == NULL) {
3690     return JNI_ENOMEM;
3691   }
3692 
3693   // Set up VerifySharedSpaces
3694   if (FLAG_IS_DEFAULT(VerifySharedSpaces) && SharedArchiveFile != NULL) {
3695     VerifySharedSpaces = true;
3696   }
3697 
3698   // Delay warning until here so that we've had a chance to process
3699   // the -XX:-PrintWarnings flag
3700   if (needs_hotspotrc_warning) {
3701     warning("%s file is present but has been ignored.  "
3702             "Run with -XX:Flags=%s to load the file.",




  74 char** Arguments::_jvm_flags_array              = NULL;
  75 int    Arguments::_num_jvm_flags                = 0;
  76 char** Arguments::_jvm_args_array               = NULL;
  77 int    Arguments::_num_jvm_args                 = 0;
  78 char*  Arguments::_java_command                 = NULL;
  79 SystemProperty* Arguments::_system_properties   = NULL;
  80 const char*  Arguments::_gc_log_filename        = NULL;
  81 bool   Arguments::_has_profile                  = false;
  82 size_t Arguments::_conservative_max_heap_alignment = 0;
  83 size_t Arguments::_min_heap_size                = 0;
  84 uintx  Arguments::_min_heap_free_ratio          = 0;
  85 uintx  Arguments::_max_heap_free_ratio          = 0;
  86 Arguments::Mode Arguments::_mode                = _mixed;
  87 bool   Arguments::_java_compiler                = false;
  88 bool   Arguments::_xdebug_mode                  = false;
  89 const char*  Arguments::_java_vendor_url_bug    = DEFAULT_VENDOR_URL_BUG;
  90 const char*  Arguments::_sun_java_launcher      = DEFAULT_JAVA_LAUNCHER;
  91 int    Arguments::_sun_java_launcher_pid        = -1;
  92 bool   Arguments::_sun_java_launcher_is_altjvm  = false;
  93 
  94 // These parameters are reset in method parse_vm_init_args()
  95 bool   Arguments::_AlwaysCompileLoopMethods     = AlwaysCompileLoopMethods;
  96 bool   Arguments::_UseOnStackReplacement        = UseOnStackReplacement;
  97 bool   Arguments::_BackgroundCompilation        = BackgroundCompilation;
  98 bool   Arguments::_ClipInlining                 = ClipInlining;
  99 intx   Arguments::_Tier3InvokeNotifyFreqLog     = Tier3InvokeNotifyFreqLog;
 100 intx   Arguments::_Tier4InvocationThreshold     = Tier4InvocationThreshold;
 101 
 102 char*  Arguments::SharedArchivePath             = NULL;
 103 
 104 AgentLibraryList Arguments::_libraryList;
 105 AgentLibraryList Arguments::_agentList;
 106 
 107 abort_hook_t     Arguments::_abort_hook         = NULL;
 108 exit_hook_t      Arguments::_exit_hook          = NULL;
 109 vfprintf_hook_t  Arguments::_vfprintf_hook      = NULL;
 110 
 111 
 112 SystemProperty *Arguments::_sun_boot_library_path = NULL;
 113 SystemProperty *Arguments::_java_library_path = NULL;
 114 SystemProperty *Arguments::_java_home = NULL;


2232       bool value_is_too_large = n > max_uintx;
2233 
2234       if (above_minimum && !value_is_too_large) {
2235         *uintx_arg = n;
2236         return true;
2237       }
2238     }
2239   }
2240   return false;
2241 }
2242 
2243 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
2244                                                   julong* long_arg,
2245                                                   julong min_size) {
2246   if (!atomull(s, long_arg)) return arg_unreadable;
2247   return check_memory_size(*long_arg, min_size);
2248 }
2249 
2250 // Parse JavaVMInitArgs structure
2251 
2252 jint Arguments::parse_vm_init_args(const JavaVMInitArgs *java_tool_options_args,
2253                                    const JavaVMInitArgs *java_options_args,
2254                                    const JavaVMInitArgs *cmd_line_args) {
2255   // For components of the system classpath.
2256   SysClassPath scp(Arguments::get_sysclasspath());
2257   bool scp_assembly_required = false;
2258 
2259   // Save default settings for some mode flags
2260   Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
2261   Arguments::_UseOnStackReplacement    = UseOnStackReplacement;
2262   Arguments::_ClipInlining             = ClipInlining;
2263   Arguments::_BackgroundCompilation    = BackgroundCompilation;
2264   if (TieredCompilation) {
2265     Arguments::_Tier3InvokeNotifyFreqLog = Tier3InvokeNotifyFreqLog;
2266     Arguments::_Tier4InvocationThreshold = Tier4InvocationThreshold;
2267   }
2268 
2269   // Setup flags for mixed which is the default
2270   set_mode_flags(_mixed);
2271 
2272   // Parse args structure generated from JAVA_TOOL_OPTIONS environment
2273   // variable (if present).
2274   jint result = parse_each_vm_init_arg(
2275       java_tool_options_args, &scp, &scp_assembly_required, Flag::ENVIRON_VAR);
2276   if (result != JNI_OK) {
2277     return result;
2278   }
2279 
2280   // Parse args structure generated from the command line flags.
2281   result = parse_each_vm_init_arg(cmd_line_args, &scp, &scp_assembly_required,
2282                                   Flag::COMMAND_LINE);
2283   if (result != JNI_OK) {
2284     return result;
2285   }
2286 
2287   // Parse args structure generated from the _JAVA_OPTIONS environment
2288   // variable (if present) (mimics classic VM)
2289   result = parse_each_vm_init_arg(
2290       java_options_args, &scp, &scp_assembly_required, Flag::ENVIRON_VAR);
2291   if (result != JNI_OK) {
2292     return result;
2293   }
2294 
2295   // Do final processing now that all arguments have been parsed
2296   result = finalize_vm_init_args(&scp, scp_assembly_required);
2297   if (result != JNI_OK) {
2298     return result;
2299   }
2300 
2301   return JNI_OK;
2302 }
2303 
2304 // Checks if name in command-line argument -agent{lib,path}:name[=options]
2305 // represents a valid HPROF of JDWP agent.  is_path==true denotes that we
2306 // are dealing with -agentpath (case where name is a path), otherwise with
2307 // -agentlib
2308 bool valid_hprof_or_jdwp_agent(char *name, bool is_path) {
2309   char *_name;
2310   const char *_hprof = "hprof", *_jdwp = "jdwp";


3373         jio_snprintf(buffer, sizeof(buffer), "java.awt.headless=%s", headless_env);
3374         if (!add_property(buffer)) {
3375           return JNI_ENOMEM;
3376         }
3377       }
3378     }
3379   }
3380 
3381   if (UseConcMarkSweepGC && FLAG_IS_DEFAULT(UseParNewGC) && !UseParNewGC) {
3382     // CMS can only be used with ParNew
3383     FLAG_SET_ERGO(bool, UseParNewGC, true);
3384   }
3385 
3386   if (!check_vm_args_consistency()) {
3387     return JNI_ERR;
3388   }
3389 
3390   return JNI_OK;
3391 }
3392 
3393 jint Arguments::parse_java_options_environment_variable(JavaVMInitArgs* args) {
3394   return parse_options_environment_variable("_JAVA_OPTIONS", args);

3395 }
3396 
3397 jint Arguments::parse_java_tool_options_environment_variable(JavaVMInitArgs* args) {
3398   return parse_options_environment_variable("JAVA_TOOL_OPTIONS", args);

3399 }
3400 
3401 jint Arguments::parse_options_environment_variable(const char* name, JavaVMInitArgs* vm_args) {
3402   char *buffer = ::getenv(name);
3403 
3404   vm_args->version = JNI_VERSION_1_2;
3405   vm_args->options = NULL;
3406   vm_args->nOptions = 0;
3407   vm_args->ignoreUnrecognized = false;
3408 
3409   // Don't check this environment variable if user has special privileges
3410   // (e.g. unix su command).
3411   if (buffer == NULL || os::have_special_privileges()) {
3412     return JNI_OK;
3413   }
3414 
3415   if ((buffer = os::strdup(buffer)) == NULL) {
3416     return JNI_ENOMEM;
3417   }
3418 
3419   GrowableArray<JavaVMOption> *options = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<JavaVMOption>(2, true);    // Construct option array
3420   jio_fprintf(defaultStream::error_stream(),
3421               "Picked up %s: %s\n", name, buffer);
3422   char* rd = buffer;                        // pointer to the input string (rd)
3423   while (true) {                            // repeat for all options in the input string
3424     while (isspace(*rd)) rd++;              // skip whitespace
3425     if (*rd == 0) break;                    // we re done when the input string is read completely
3426 
3427     // The output, option string, overwrites the input string.
3428     // Because of quoting, the pointer to the option string (wrt) may lag the pointer to
3429     // input string (rd).
3430     char* wrt = rd;
3431     char* start = wrt;
3432 



3433     while (*rd != 0 && !isspace(*rd)) {     // unquoted strings terminate with a space or NULL
3434       if (*rd == '\'' || *rd == '"') {      // handle a quoted string
3435         int quote = *rd;                    // matching quote to look for
3436         rd++;                               // don't copy open quote
3437         while (*rd != quote) {              // include everything (even spaces) up until quote
3438           if (*rd == 0) {                   // string termination means unmatched string
3439             jio_fprintf(defaultStream::error_stream(),
3440                         "Unmatched quote in %s\n", name);
3441             delete options;
3442             os::free(buffer);
3443             return JNI_ERR;
3444           }
3445           *wrt++ = *rd++;                   // copy to option string
3446         }
3447         rd++;                               // don't copy close quote
3448       } else {
3449         *wrt++ = *rd++;                     // copy to option string
3450       }
3451     }
3452     if (*rd != 0) {
3453       // In this case, the assignment to wrt below will make *rd nul,
3454       // which will interfere with the next loop iteration.
3455       rd++;

3456     }
3457     *wrt = 0;                               // Zero terminate option
3458 
3459     JavaVMOption option;
3460     option.optionString = os::strdup(start);
3461     options->append(option);                // Fill in option
3462   }
3463 
3464   // Fill out JavaVMInitArgs structure.
3465   JavaVMOption* options_arr =
3466       NEW_C_HEAP_ARRAY_RETURN_NULL(JavaVMOption, options->length(), mtInternal);
3467   if (options_arr == NULL) {
3468     delete options;
3469     os::free(buffer);
3470     return JNI_ENOMEM;
3471   }
3472   for (int i = 0; i < options->length(); i++) {
3473     options_arr[i] = options->at(i);
3474   }
3475 
3476   vm_args->options = options_arr;
3477   vm_args->nOptions = options->length();
3478   vm_args->ignoreUnrecognized = IgnoreUnrecognizedVMOptions;













3479 



3480   delete options;
3481   os::free(buffer);
3482   return JNI_OK;
3483 }
3484 
3485 void Arguments::set_shared_spaces_flags() {
3486   if (DumpSharedSpaces) {
3487     if (RequireSharedSpaces) {
3488       warning("cannot dump shared archive while using shared archive");
3489     }
3490     UseSharedSpaces = false;
3491 #ifdef _LP64
3492     if (!UseCompressedOops || !UseCompressedClassPointers) {
3493       vm_exit_during_initialization(
3494         "Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off.", NULL);
3495     }
3496   } else {
3497     if (!UseCompressedOops || !UseCompressedClassPointers) {
3498       no_shared_spaces("UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces.");
3499     }
3500 #endif
3501   }
3502 }


3545       (VerifyDependencies && FLAG_IS_CMDLINE(VerifyDependencies))) {
3546     return true;
3547   }
3548 
3549 #ifdef COMPILER1
3550   if (PrintC1Statistics) {
3551     return true;
3552   }
3553 #endif // COMPILER1
3554 
3555 #ifdef COMPILER2
3556   if (PrintOptoAssembly || PrintOptoStatistics) {
3557     return true;
3558   }
3559 #endif // COMPILER2
3560 
3561   return false;
3562 }
3563 #endif // PRODUCT
3564 
3565 static int match_special_option_and_act(const JavaVMInitArgs* args,
3566                                         char** flags_file) {






3567   // Remaining part of option string
3568   const char* tail;
3569 
3570   for (int index = 0; index < args->nOptions; index++) {
3571     const JavaVMOption* option = args->options + index;







3572     if (ArgumentsExt::process_options(option)) {
3573       continue;
3574     }
3575     if (match_option(option, "-XX:Flags=", &tail)) {
3576       *flags_file = (char *) tail;

3577       continue;
3578     }
3579     if (match_option(option, "-XX:+PrintVMOptions")) {
3580       PrintVMOptions = true;
3581       continue;
3582     }
3583     if (match_option(option, "-XX:-PrintVMOptions")) {
3584       PrintVMOptions = false;
3585       continue;
3586     }
3587     if (match_option(option, "-XX:+IgnoreUnrecognizedVMOptions")) {
3588       IgnoreUnrecognizedVMOptions = true;
3589       continue;
3590     }
3591     if (match_option(option, "-XX:-IgnoreUnrecognizedVMOptions")) {
3592       IgnoreUnrecognizedVMOptions = false;
3593       continue;
3594     }
3595     if (match_option(option, "-XX:+PrintFlagsInitial")) {
3596       CommandLineFlags::printFlags(tty, false);


3610           MemTracker::init();
3611         }
3612       } else {
3613         vm_exit_during_initialization("Syntax error, expecting -XX:NativeMemoryTracking=[off|summary|detail]", NULL);
3614       }
3615       continue;
3616 #else
3617       jio_fprintf(defaultStream::error_stream(),
3618         "Native Memory Tracking is not supported in this VM\n");
3619       return JNI_ERR;
3620 #endif
3621     }
3622 
3623 #ifndef PRODUCT
3624     if (match_option(option, "-XX:+PrintFlagsWithComments")) {
3625       CommandLineFlags::printFlags(tty, true);
3626       vm_exit(0);
3627     }
3628 #endif
3629   }
3630   return JNI_OK;
3631 }
3632 
3633 static void print_options(const JavaVMInitArgs *args) {
3634   const char* tail;
3635   for (int index = 0; index < args->nOptions; index++) {
3636     const JavaVMOption *option = args->options + index;
3637     if (match_option(option, "-XX:", &tail)) {
3638       logOption(tail);
3639     }
3640   }
3641 }
3642 
3643 // Parse entry point called from JNI_CreateJavaVM
3644 
3645 jint Arguments::parse(const JavaVMInitArgs* args) {
3646   // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed.
3647   const char* hotspotrc = ".hotspotrc";
3648   char* flags_file = NULL;
3649   bool settings_file_specified = false;
3650   bool needs_hotspotrc_warning = false;
3651   JavaVMInitArgs java_tool_options_args;
3652   JavaVMInitArgs java_options_args;
3653 
3654   int code =
3655       parse_java_tool_options_environment_variable(&java_tool_options_args);
3656   if (code != JNI_OK) {
3657     return code;
3658   }
3659 
3660   code = parse_java_options_environment_variable(&java_options_args);
3661   if (code != JNI_OK) {
3662     return code;
3663   }
3664 
3665   match_special_option_and_act(args, &flags_file);
3666   match_special_option_and_act(&java_tool_options_args, &flags_file);
3667   match_special_option_and_act(&java_options_args, &flags_file);
3668   settings_file_specified = (flags_file != NULL);
3669 
3670   if (IgnoreUnrecognizedVMOptions) {
3671     // uncast const to modify the flag args->ignoreUnrecognized
3672     *(jboolean*)(&args->ignoreUnrecognized) = true;
3673     java_tool_options_args.ignoreUnrecognized = true;
3674     java_options_args.ignoreUnrecognized = true;
3675   }
3676 
3677   // Parse specified settings file
3678   if (settings_file_specified) {
3679     if (!process_settings_file(flags_file, true, args->ignoreUnrecognized)) {
3680       return JNI_EINVAL;
3681     }
3682   } else {
3683 #ifdef ASSERT
3684     // Parse default .hotspotrc settings file
3685     if (!process_settings_file(".hotspotrc", false, args->ignoreUnrecognized)) {
3686       return JNI_EINVAL;
3687     }
3688 #else
3689     struct stat buf;
3690     if (os::stat(hotspotrc, &buf) == 0) {
3691       needs_hotspotrc_warning = true;
3692     }
3693 #endif
3694   }
3695 
3696   if (PrintVMOptions) {
3697     print_options(args);
3698     print_options(&java_tool_options_args);
3699     print_options(&java_options_args);



3700   }
3701 
3702   // Parse JavaVMInitArgs structure passed in, as well as JAVA_TOOL_OPTIONS and _JAVA_OPTIONS
3703   jint result =
3704       parse_vm_init_args(&java_tool_options_args, &java_options_args, args);
3705 
3706   // Done with the envvars
3707   for (int i = 0; i < java_tool_options_args.nOptions; i++) {
3708     os::free(java_tool_options_args.options[i].optionString);
3709   }
3710   FREE_C_HEAP_ARRAY(JavaVMOption, java_tool_options_args.options);
3711 
3712   for (int i = 0; i < java_options_args.nOptions; i++) {
3713     os::free(java_options_args.options[i].optionString);
3714   }
3715   FREE_C_HEAP_ARRAY(JavaVMOption, java_options_args.options);
3716   if (result != JNI_OK) {
3717     return result;
3718   }
3719 
3720   // Call get_shared_archive_path() here, after possible SharedArchiveFile option got parsed.
3721   SharedArchivePath = get_shared_archive_path();
3722   if (SharedArchivePath == NULL) {
3723     return JNI_ENOMEM;
3724   }
3725 
3726   // Set up VerifySharedSpaces
3727   if (FLAG_IS_DEFAULT(VerifySharedSpaces) && SharedArchiveFile != NULL) {
3728     VerifySharedSpaces = true;
3729   }
3730 
3731   // Delay warning until here so that we've had a chance to process
3732   // the -XX:-PrintWarnings flag
3733   if (needs_hotspotrc_warning) {
3734     warning("%s file is present but has been ignored.  "
3735             "Run with -XX:Flags=%s to load the file.",


< prev index next >