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
3432 JavaVMOption option;
3433 option.optionString = wrt;
3434 options->append(option); // Fill in option
3435
3436 while (*rd != 0 && !isspace(*rd)) { // unquoted strings terminate with a space or NULL
3437 if (*rd == '\'' || *rd == '"') { // handle a quoted string
3438 int quote = *rd; // matching quote to look for
3439 rd++; // don't copy open quote
3440 while (*rd != quote) { // include everything (even spaces) up until quote
3441 if (*rd == 0) { // string termination means unmatched string
3442 jio_fprintf(defaultStream::error_stream(),
3443 "Unmatched quote in %s\n", name);
3444 delete options;
3445 os::free(buffer);
3446 return JNI_ERR;
3447 }
3448 *wrt++ = *rd++; // copy to option string
3449 }
3450 rd++; // don't copy close quote
3451 } else {
3452 *wrt++ = *rd++; // copy to option string
3453 }
3454 }
3455 if (*rd != 0) {
3456 // In this case, the assignment to wrt below will make *rd nul,
3457 // which will interfere with the next loop iteration.
3458 rd++;
3459 }
3460 *wrt = 0; // Zero terminate option
3461 }
3462
3463 // Fill out JavaVMInitArgs structure.
3464 JavaVMOption* options_arr =
3465 NEW_C_HEAP_ARRAY_RETURN_NULL(JavaVMOption, options->length(), mtInternal);
3466 if (options_arr == NULL) {
3467 delete options;
3468 os::free(buffer);
3469 return JNI_ENOMEM;
3470 }
3471 for (int i = 0; i < options->length(); i++) {
3472 options_arr[i] = options->at(i);
3473 options_arr[i].optionString = os::strdup(options_arr[i].optionString);
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 static void free_memory_for_vm_init_args(JavaVMInitArgs* args) {
3486 for (int i = 0; i < args->nOptions; i++) {
3487 os::free(args->options[i].optionString);
3488 }
3489 FREE_C_HEAP_ARRAY(JavaVMOption, args->options);
3490 }
3491
3492 void Arguments::set_shared_spaces_flags() {
3493 if (DumpSharedSpaces) {
3494 if (RequireSharedSpaces) {
3495 warning("cannot dump shared archive while using shared archive");
3496 }
3497 UseSharedSpaces = false;
3498 #ifdef _LP64
3499 if (!UseCompressedOops || !UseCompressedClassPointers) {
3500 vm_exit_during_initialization(
3501 "Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off.", NULL);
3502 }
3503 } else {
3504 if (!UseCompressedOops || !UseCompressedClassPointers) {
3505 no_shared_spaces("UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces.");
3506 }
3507 #endif
3508 }
3509 }
3552 (VerifyDependencies && FLAG_IS_CMDLINE(VerifyDependencies))) {
3553 return true;
3554 }
3555
3556 #ifdef COMPILER1
3557 if (PrintC1Statistics) {
3558 return true;
3559 }
3560 #endif // COMPILER1
3561
3562 #ifdef COMPILER2
3563 if (PrintOptoAssembly || PrintOptoStatistics) {
3564 return true;
3565 }
3566 #endif // COMPILER2
3567
3568 return false;
3569 }
3570 #endif // PRODUCT
3571
3572 static int match_special_option_and_act(const JavaVMInitArgs* args,
3573 char** flags_file) {
3574 // Remaining part of option string
3575 const char* tail;
3576
3577 for (int index = 0; index < args->nOptions; index++) {
3578 const JavaVMOption* option = args->options + index;
3579 if (ArgumentsExt::process_options(option)) {
3580 continue;
3581 }
3582 if (match_option(option, "-XX:Flags=", &tail)) {
3583 *flags_file = (char *) tail;
3584 continue;
3585 }
3586 if (match_option(option, "-XX:+PrintVMOptions")) {
3587 PrintVMOptions = true;
3588 continue;
3589 }
3590 if (match_option(option, "-XX:-PrintVMOptions")) {
3591 PrintVMOptions = false;
3592 continue;
3593 }
3594 if (match_option(option, "-XX:+IgnoreUnrecognizedVMOptions")) {
3595 IgnoreUnrecognizedVMOptions = true;
3596 continue;
3597 }
3598 if (match_option(option, "-XX:-IgnoreUnrecognizedVMOptions")) {
3599 IgnoreUnrecognizedVMOptions = false;
3600 continue;
3601 }
3602 if (match_option(option, "-XX:+PrintFlagsInitial")) {
3603 CommandLineFlags::printFlags(tty, false);
3617 MemTracker::init();
3618 }
3619 } else {
3620 vm_exit_during_initialization("Syntax error, expecting -XX:NativeMemoryTracking=[off|summary|detail]", NULL);
3621 }
3622 continue;
3623 #else
3624 jio_fprintf(defaultStream::error_stream(),
3625 "Native Memory Tracking is not supported in this VM\n");
3626 return JNI_ERR;
3627 #endif
3628 }
3629
3630 #ifndef PRODUCT
3631 if (match_option(option, "-XX:+PrintFlagsWithComments")) {
3632 CommandLineFlags::printFlags(tty, true);
3633 vm_exit(0);
3634 }
3635 #endif
3636 }
3637 return JNI_OK;
3638 }
3639
3640 static void print_options(const JavaVMInitArgs *args) {
3641 const char* tail;
3642 for (int index = 0; index < args->nOptions; index++) {
3643 const JavaVMOption *option = args->options + index;
3644 if (match_option(option, "-XX:", &tail)) {
3645 logOption(tail);
3646 }
3647 }
3648 }
3649
3650 // Parse entry point called from JNI_CreateJavaVM
3651
3652 jint Arguments::parse(const JavaVMInitArgs* args) {
3653 // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed.
3654 const char* hotspotrc = ".hotspotrc";
3655 char* flags_file = NULL;
3656 bool settings_file_specified = false;
3657 bool needs_hotspotrc_warning = false;
3658 JavaVMInitArgs java_tool_options_args;
3659 JavaVMInitArgs java_options_args;
3660
3661 int code =
3662 parse_java_tool_options_environment_variable(&java_tool_options_args);
3663 if (code != JNI_OK) {
3664 return code;
3665 }
3666
3667 code = parse_java_options_environment_variable(&java_options_args);
3668 if (code != JNI_OK) {
3669 free_memory_for_vm_init_args(&java_tool_options_args);
3670 return code;
3671 }
3672
3673 match_special_option_and_act(&java_tool_options_args, &flags_file);
3674 match_special_option_and_act(args, &flags_file);
3675 match_special_option_and_act(&java_options_args, &flags_file);
3676 settings_file_specified = (flags_file != NULL);
3677
3678 if (IgnoreUnrecognizedVMOptions) {
3679 // uncast const to modify the flag args->ignoreUnrecognized
3680 *(jboolean*)(&args->ignoreUnrecognized) = true;
3681 java_tool_options_args.ignoreUnrecognized = true;
3682 java_options_args.ignoreUnrecognized = true;
3683 }
3684
3685 // Parse specified settings file
3686 if (settings_file_specified) {
3687 if (!process_settings_file(flags_file, true, args->ignoreUnrecognized)) {
3688 free_memory_for_vm_init_args(&java_tool_options_args);
3689 free_memory_for_vm_init_args(&java_options_args);
3690 return JNI_EINVAL;
3691 }
3692 } else {
3693 #ifdef ASSERT
3694 // Parse default .hotspotrc settings file
3695 if (!process_settings_file(".hotspotrc", false, args->ignoreUnrecognized)) {
3696 return JNI_EINVAL;
3697 }
3698 #else
3699 struct stat buf;
3700 if (os::stat(hotspotrc, &buf) == 0) {
3701 needs_hotspotrc_warning = true;
3702 }
3703 #endif
3704 }
3705
3706 if (PrintVMOptions) {
3707 print_options(&java_tool_options_args);
3708 print_options(args);
3709 print_options(&java_options_args);
3710 }
3711
3712 // Parse JavaVMInitArgs structure passed in, as well as JAVA_TOOL_OPTIONS and _JAVA_OPTIONS
3713 jint result =
3714 parse_vm_init_args(&java_tool_options_args, &java_options_args, args);
3715
3716 // Done with the envvars
3717 free_memory_for_vm_init_args(&java_tool_options_args);
3718 free_memory_for_vm_init_args(&java_options_args);
3719
3720 if (result != JNI_OK) {
3721 return result;
3722 }
3723
3724 // Call get_shared_archive_path() here, after possible SharedArchiveFile option got parsed.
3725 SharedArchivePath = get_shared_archive_path();
3726 if (SharedArchivePath == NULL) {
3727 return JNI_ENOMEM;
3728 }
3729
3730 // Set up VerifySharedSpaces
3731 if (FLAG_IS_DEFAULT(VerifySharedSpaces) && SharedArchiveFile != NULL) {
3732 VerifySharedSpaces = true;
3733 }
3734
3735 // Delay warning until here so that we've had a chance to process
3736 // the -XX:-PrintWarnings flag
3737 if (needs_hotspotrc_warning) {
3738 warning("%s file is present but has been ignored. "
3739 "Run with -XX:Flags=%s to load the file.",
|