< prev index next >

src/share/vm/runtime/arguments.cpp

Print this page




3494     FLAG_SET_DEFAULT(UseLargePages, false);
3495   }
3496 
3497 #else
3498   if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) {
3499     FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment-1);
3500   }
3501 #endif
3502 
3503 #ifndef TIERED
3504   // Tiered compilation is undefined.
3505   UNSUPPORTED_OPTION(TieredCompilation, "TieredCompilation");
3506 #endif
3507 
3508   // If we are running in a headless jre, force java.awt.headless property
3509   // to be true unless the property has already been set.
3510   // Also allow the OS environment variable JAVA_AWT_HEADLESS to set headless state.
3511   if (os::is_headless_jre()) {
3512     const char* headless = Arguments::get_property("java.awt.headless");
3513     if (headless == NULL) {
3514       char envbuffer[128];
3515       if (!os::getenv("JAVA_AWT_HEADLESS", envbuffer, sizeof(envbuffer))) {
3516         if (!add_property("java.awt.headless=true")) {
3517           return JNI_ENOMEM;
3518         }
3519       } else {
3520         char buffer[256];
3521         strcpy(buffer, "java.awt.headless=");
3522         strcat(buffer, envbuffer);
3523         if (!add_property(buffer)) {





3524           return JNI_ENOMEM;
3525         }
3526       }
3527     }
3528   }
3529 
3530   if (UseConcMarkSweepGC && FLAG_IS_DEFAULT(UseParNewGC) && !UseParNewGC) {
3531     // CMS can only be used with ParNew
3532     FLAG_SET_ERGO(bool, UseParNewGC, true);
3533   }
3534 
3535   if (!check_vm_args_consistency()) {
3536     return JNI_ERR;
3537   }
3538 
3539   return JNI_OK;
3540 }
3541 
3542 jint Arguments::parse_java_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
3543   return parse_options_environment_variable("_JAVA_OPTIONS", scp_p,
3544                                             scp_assembly_required_p);
3545 }
3546 
3547 jint Arguments::parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
3548   return parse_options_environment_variable("JAVA_TOOL_OPTIONS", scp_p,
3549                                             scp_assembly_required_p);
3550 }
3551 
3552 jint Arguments::parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p) {
3553   const int N_MAX_OPTIONS = 64;
3554   const int OPTION_BUFFER_SIZE = 1024;
3555   char buffer[OPTION_BUFFER_SIZE];
3556 
3557   // The variable will be ignored if it exceeds the length of the buffer.
3558   // Don't check this variable if user has special privileges
3559   // (e.g. unix su command).
3560   if (os::getenv(name, buffer, sizeof(buffer)) &&
3561       !os::have_special_privileges()) {
3562     JavaVMOption options[N_MAX_OPTIONS];      // Construct option array





3563     jio_fprintf(defaultStream::error_stream(),
3564                 "Picked up %s: %s\n", name, buffer);
3565     char* rd = buffer;                        // pointer to the input string (rd)
3566     int i;
3567     for (i = 0; i < N_MAX_OPTIONS;) {         // repeat for all options in the input string
3568       while (isspace(*rd)) rd++;              // skip whitespace
3569       if (*rd == 0) break;                    // we re done when the input string is read completely
3570 
3571       // The output, option string, overwrites the input string.
3572       // Because of quoting, the pointer to the option string (wrt) may lag the pointer to
3573       // input string (rd).
3574       char* wrt = rd;
3575 
3576       options[i++].optionString = wrt;        // Fill in option


3577       while (*rd != 0 && !isspace(*rd)) {     // unquoted strings terminate with a space or NULL
3578         if (*rd == '\'' || *rd == '"') {      // handle a quoted string
3579           int quote = *rd;                    // matching quote to look for
3580           rd++;                               // don't copy open quote
3581           while (*rd != quote) {              // include everything (even spaces) up until quote
3582             if (*rd == 0) {                   // string termination means unmatched string
3583               jio_fprintf(defaultStream::error_stream(),
3584                           "Unmatched quote in %s\n", name);

3585               return JNI_ERR;
3586             }
3587             *wrt++ = *rd++;                   // copy to option string
3588           }
3589           rd++;                               // don't copy close quote
3590         } else {
3591           *wrt++ = *rd++;                     // copy to option string
3592         }
3593       }
3594       // Need to check if we're done before writing a NULL,
3595       // because the write could be to the byte that rd is pointing to.
3596       if (*rd++ == 0) {
3597         *wrt = 0;
3598         break;
3599       }
3600       *wrt = 0;                               // Zero terminate option
3601     }






3602     // Construct JavaVMInitArgs structure and parse as if it was part of the command line
3603     JavaVMInitArgs vm_args;
3604     vm_args.version = JNI_VERSION_1_2;
3605     vm_args.options = options;
3606     vm_args.nOptions = i;
3607     vm_args.ignoreUnrecognized = IgnoreUnrecognizedVMOptions;
3608 
3609     if (PrintVMOptions) {
3610       const char* tail;
3611       for (int i = 0; i < vm_args.nOptions; i++) {
3612         const JavaVMOption *option = vm_args.options + i;
3613         if (match_option(option, "-XX:", &tail)) {
3614           logOption(tail);
3615         }
3616       }
3617     }
3618 
3619     return(parse_each_vm_init_arg(&vm_args, scp_p, scp_assembly_required_p, Flag::ENVIRON_VAR));
3620   }
3621   return JNI_OK;


3622 }
3623 
3624 void Arguments::set_shared_spaces_flags() {
3625   if (DumpSharedSpaces) {
3626     if (RequireSharedSpaces) {
3627       warning("cannot dump shared archive while using shared archive");
3628     }
3629     UseSharedSpaces = false;
3630 #ifdef _LP64
3631     if (!UseCompressedOops || !UseCompressedClassPointers) {
3632       vm_exit_during_initialization(
3633         "Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off.", NULL);
3634     }
3635   } else {
3636     if (!UseCompressedOops || !UseCompressedClassPointers) {
3637       no_shared_spaces("UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces.");
3638     }
3639 #endif
3640   }
3641 }




3494     FLAG_SET_DEFAULT(UseLargePages, false);
3495   }
3496 
3497 #else
3498   if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) {
3499     FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment-1);
3500   }
3501 #endif
3502 
3503 #ifndef TIERED
3504   // Tiered compilation is undefined.
3505   UNSUPPORTED_OPTION(TieredCompilation, "TieredCompilation");
3506 #endif
3507 
3508   // If we are running in a headless jre, force java.awt.headless property
3509   // to be true unless the property has already been set.
3510   // Also allow the OS environment variable JAVA_AWT_HEADLESS to set headless state.
3511   if (os::is_headless_jre()) {
3512     const char* headless = Arguments::get_property("java.awt.headless");
3513     if (headless == NULL) {
3514       const char *headless_env = ::getenv("JAVA_AWT_HEADLESS");
3515       if (headless_env == NULL) {
3516         if (!add_property("java.awt.headless=true")) {
3517           return JNI_ENOMEM;
3518         }
3519       } else {
3520         const char* key = "java.awt.headless=";
3521         char* buffer = NEW_C_HEAP_ARRAY(
3522             char, strlen(key) + strlen(headless_env) + 1, mtInternal);
3523 
3524         strcpy(buffer, key);
3525         strcat(buffer, headless_env);
3526         bool success = add_property(buffer);
3527         FREE_C_HEAP_ARRAY(char, buffer);
3528         if (!success) {
3529           return JNI_ENOMEM;
3530         }
3531       }
3532     }
3533   }
3534 
3535   if (UseConcMarkSweepGC && FLAG_IS_DEFAULT(UseParNewGC) && !UseParNewGC) {
3536     // CMS can only be used with ParNew
3537     FLAG_SET_ERGO(bool, UseParNewGC, true);
3538   }
3539 
3540   if (!check_vm_args_consistency()) {
3541     return JNI_ERR;
3542   }
3543 
3544   return JNI_OK;
3545 }
3546 
3547 jint Arguments::parse_java_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
3548   return parse_options_environment_variable("_JAVA_OPTIONS", scp_p,
3549                                             scp_assembly_required_p);
3550 }
3551 
3552 jint Arguments::parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
3553   return parse_options_environment_variable("JAVA_TOOL_OPTIONS", scp_p,
3554                                             scp_assembly_required_p);
3555 }
3556 
3557 jint Arguments::parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p) {
3558   char *buffer = ::getenv(name);


3559 

3560   // Don't check this variable if user has special privileges
3561   // (e.g. unix su command).
3562   if (buffer == NULL || os::have_special_privileges()) {
3563     return JNI_OK;
3564   }
3565 
3566   if ((buffer = os::strdup(buffer)) == NULL) {
3567     return JNI_OK;
3568   }
3569   GrowableArray<JavaVMOption> options(2, true);    // Construct option array
3570   jio_fprintf(defaultStream::error_stream(),
3571               "Picked up %s: %s\n", name, buffer);
3572   char* rd = buffer;                        // pointer to the input string (rd)
3573   while (true) {                            // repeat for all options in the input string

3574     while (isspace(*rd)) rd++;              // skip whitespace
3575     if (*rd == 0) break;                    // we re done when the input string is read completely
3576 
3577     // The output, option string, overwrites the input string.
3578     // Because of quoting, the pointer to the option string (wrt) may lag the pointer to
3579     // input string (rd).
3580     char* wrt = rd;
3581 
3582     JavaVMOption option;
3583     option.optionString = wrt;
3584     options.append(option);                 // Fill in option
3585     while (*rd != 0 && !isspace(*rd)) {     // unquoted strings terminate with a space or NULL
3586       if (*rd == '\'' || *rd == '"') {      // handle a quoted string
3587         int quote = *rd;                    // matching quote to look for
3588         rd++;                               // don't copy open quote
3589         while (*rd != quote) {              // include everything (even spaces) up until quote
3590           if (*rd == 0) {                   // string termination means unmatched string
3591             jio_fprintf(defaultStream::error_stream(),
3592                         "Unmatched quote in %s\n", name);
3593             os::free(buffer);
3594             return JNI_ERR;
3595           }
3596           *wrt++ = *rd++;                   // copy to option string
3597         }
3598         rd++;                               // don't copy close quote
3599       } else {
3600         *wrt++ = *rd++;                     // copy to option string
3601       }
3602     }
3603     // Need to check if we're done before writing a NULL,
3604     // because the write could be to the byte that rd is pointing to.
3605     if (*rd++ == 0) {
3606       *wrt = 0;
3607       break;
3608     }
3609     *wrt = 0;                               // Zero terminate option
3610   }
3611   JavaVMOption* options_arr =
3612       NEW_C_HEAP_ARRAY(JavaVMOption, options.length(), mtInternal);
3613   for (int i = 0; i < options.length(); i++) {
3614     options_arr[i] = options.at(i);
3615   }
3616 
3617   // Construct JavaVMInitArgs structure and parse as if it was part of the command line
3618   JavaVMInitArgs vm_args;
3619   vm_args.version = JNI_VERSION_1_2;
3620   vm_args.options = options_arr;
3621   vm_args.nOptions = options.length();
3622   vm_args.ignoreUnrecognized = IgnoreUnrecognizedVMOptions;
3623 
3624   if (PrintVMOptions) {
3625     const char* tail;
3626     for (int i = 0; i < vm_args.nOptions; i++) {
3627       const JavaVMOption *option = vm_args.options + i;
3628       if (match_option(option, "-XX:", &tail)) {
3629         logOption(tail);
3630       }
3631     }
3632   }
3633 
3634   jint result = parse_each_vm_init_arg(&vm_args, scp_p, scp_assembly_required_p,
3635                                        Flag::ENVIRON_VAR);
3636   FREE_C_HEAP_ARRAY(JavaVMOption, options_arr);
3637   os::free(buffer);
3638   return result;
3639 }
3640 
3641 void Arguments::set_shared_spaces_flags() {
3642   if (DumpSharedSpaces) {
3643     if (RequireSharedSpaces) {
3644       warning("cannot dump shared archive while using shared archive");
3645     }
3646     UseSharedSpaces = false;
3647 #ifdef _LP64
3648     if (!UseCompressedOops || !UseCompressedClassPointers) {
3649       vm_exit_during_initialization(
3650         "Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off.", NULL);
3651     }
3652   } else {
3653     if (!UseCompressedOops || !UseCompressedClassPointers) {
3654       no_shared_spaces("UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces.");
3655     }
3656 #endif
3657   }
3658 }


< prev index next >