< 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).


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).


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

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



3477 













3478   delete options;
3479   return JNI_OK;

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


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






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







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

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


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



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


< prev index next >