< prev index next >

src/hotspot/share/runtime/arguments.cpp

Print this page


  24 
  25 #include "precompiled.hpp"
  26 #include "jvm.h"
  27 #include "classfile/classLoader.hpp"
  28 #include "classfile/javaAssertions.hpp"
  29 #include "classfile/moduleEntry.hpp"
  30 #include "classfile/stringTable.hpp"
  31 #include "classfile/symbolTable.hpp"
  32 #include "gc/shared/gcArguments.hpp"
  33 #include "gc/shared/gcConfig.hpp"
  34 #include "logging/log.hpp"
  35 #include "logging/logConfiguration.hpp"
  36 #include "logging/logStream.hpp"
  37 #include "logging/logTag.hpp"
  38 #include "memory/allocation.inline.hpp"
  39 #include "memory/filemap.hpp"
  40 #include "oops/oop.inline.hpp"
  41 #include "prims/jvmtiExport.hpp"
  42 #include "runtime/arguments.hpp"
  43 #include "runtime/flags/jvmFlag.hpp"
  44 #include "runtime/flags/jvmFlagConstraintList.hpp"
  45 #include "runtime/flags/jvmFlagRangeList.hpp"
  46 #include "runtime/globals_extension.hpp"
  47 #include "runtime/java.hpp"
  48 #include "runtime/os.inline.hpp"
  49 #include "runtime/safepoint.hpp"
  50 #include "runtime/safepointMechanism.hpp"
  51 #include "runtime/vm_version.hpp"
  52 #include "services/management.hpp"
  53 #include "services/memTracker.hpp"
  54 #include "utilities/align.hpp"
  55 #include "utilities/defaultStream.hpp"
  56 #include "utilities/macros.hpp"
  57 #include "utilities/powerOfTwo.hpp"
  58 #include "utilities/stringUtils.hpp"
  59 #if INCLUDE_JFR
  60 #include "jfr/jfr.hpp"
  61 #endif
  62 
  63 #define DEFAULT_JAVA_LAUNCHER  "generic"
  64 
  65 char*  Arguments::_jvm_flags_file               = NULL;
  66 char** Arguments::_jvm_flags_array              = NULL;


 843 
 844 // Describe an argument out of range error
 845 void Arguments::describe_range_error(ArgsRange errcode) {
 846   switch(errcode) {
 847   case arg_too_big:
 848     jio_fprintf(defaultStream::error_stream(),
 849                 "The specified size exceeds the maximum "
 850                 "representable size.\n");
 851     break;
 852   case arg_too_small:
 853   case arg_unreadable:
 854   case arg_in_range:
 855     // do nothing for now
 856     break;
 857   default:
 858     ShouldNotReachHere();
 859   }
 860 }
 861 
 862 static bool set_bool_flag(JVMFlag* flag, bool value, JVMFlag::Flags origin) {
 863   if (JVMFlag::boolAtPut(flag, &value, origin) == JVMFlag::SUCCESS) {
 864     return true;
 865   } else {
 866     return false;
 867   }
 868 }
 869 
 870 static bool set_fp_numeric_flag(JVMFlag* flag, char* value, JVMFlag::Flags origin) {
 871   char* end;
 872   errno = 0;
 873   double v = strtod(value, &end);
 874   if ((errno != 0) || (*end != 0)) {
 875     return false;
 876   }
 877 
 878   if (JVMFlag::doubleAtPut(flag, &v, origin) == JVMFlag::SUCCESS) {
 879     return true;
 880   }
 881   return false;
 882 }
 883 
 884 static bool set_numeric_flag(JVMFlag* flag, char* value, JVMFlag::Flags origin) {
 885   julong v;
 886   int int_v;
 887   intx intx_v;
 888   bool is_neg = false;
 889 
 890   if (flag == NULL) {
 891     return false;
 892   }
 893 
 894   // Check the sign first since atojulong() parses only unsigned values.
 895   if (*value == '-') {
 896     if (!flag->is_intx() && !flag->is_int()) {
 897       return false;
 898     }
 899     value++;
 900     is_neg = true;
 901   }
 902   if (!Arguments::atojulong(value, &v)) {
 903     return false;
 904   }
 905   if (flag->is_int()) {
 906     int_v = (int) v;
 907     if (is_neg) {
 908       int_v = -int_v;
 909     }
 910     return JVMFlag::intAtPut(flag, &int_v, origin) == JVMFlag::SUCCESS;
 911   } else if (flag->is_uint()) {
 912     uint uint_v = (uint) v;
 913     return JVMFlag::uintAtPut(flag, &uint_v, origin) == JVMFlag::SUCCESS;
 914   } else if (flag->is_intx()) {
 915     intx_v = (intx) v;
 916     if (is_neg) {
 917       intx_v = -intx_v;
 918     }
 919     return JVMFlag::intxAtPut(flag, &intx_v, origin) == JVMFlag::SUCCESS;
 920   } else if (flag->is_uintx()) {
 921     uintx uintx_v = (uintx) v;
 922     return JVMFlag::uintxAtPut(flag, &uintx_v, origin) == JVMFlag::SUCCESS;
 923   } else if (flag->is_uint64_t()) {
 924     uint64_t uint64_t_v = (uint64_t) v;
 925     return JVMFlag::uint64_tAtPut(flag, &uint64_t_v, origin) == JVMFlag::SUCCESS;
 926   } else if (flag->is_size_t()) {
 927     size_t size_t_v = (size_t) v;
 928     return JVMFlag::size_tAtPut(flag, &size_t_v, origin) == JVMFlag::SUCCESS;
 929   } else if (flag->is_double()) {
 930     double double_v = (double) v;
 931     return JVMFlag::doubleAtPut(flag, &double_v, origin) == JVMFlag::SUCCESS;
 932   } else {
 933     return false;
 934   }
 935 }
 936 
 937 static bool set_string_flag(JVMFlag* flag, const char* value, JVMFlag::Flags origin) {
 938   if (JVMFlag::ccstrAtPut(flag, &value, origin) != JVMFlag::SUCCESS) return false;
 939   // Contract:  JVMFlag always returns a pointer that needs freeing.
 940   FREE_C_HEAP_ARRAY(char, value);
 941   return true;
 942 }
 943 
 944 static bool append_to_string_flag(JVMFlag* flag, const char* new_value, JVMFlag::Flags origin) {
 945   const char* old_value = "";
 946   if (JVMFlag::ccstrAt(flag, &old_value) != JVMFlag::SUCCESS) return false;
 947   size_t old_len = old_value != NULL ? strlen(old_value) : 0;
 948   size_t new_len = strlen(new_value);
 949   const char* value;
 950   char* free_this_too = NULL;
 951   if (old_len == 0) {


1321 #ifdef PRODUCT
1322       bool mismatched = ((msg_type == JVMFlag::NOTPRODUCT_FLAG_BUT_PRODUCT_BUILD) ||
1323                          (msg_type == JVMFlag::DEVELOPER_FLAG_BUT_PRODUCT_BUILD));
1324       if (ignore_unrecognized && mismatched) {
1325         return true;
1326       }
1327 #endif
1328       jio_fprintf(defaultStream::error_stream(), "%s", locked_message_buf);
1329     }
1330   } else {
1331     if (ignore_unrecognized) {
1332       return true;
1333     }
1334     jio_fprintf(defaultStream::error_stream(),
1335                 "Unrecognized VM option '%s'\n", argname);
1336     JVMFlag* fuzzy_matched = JVMFlag::fuzzy_match((const char*)argname, arg_len, true);
1337     if (fuzzy_matched != NULL) {
1338       jio_fprintf(defaultStream::error_stream(),
1339                   "Did you mean '%s%s%s'? ",
1340                   (fuzzy_matched->is_bool()) ? "(+/-)" : "",
1341                   fuzzy_matched->_name,
1342                   (fuzzy_matched->is_bool()) ? "" : "=<value>");
1343     }
1344   }
1345 
1346   // allow for commandline "commenting out" options like -XX:#+Verbose
1347   return arg[0] == '#';
1348 }
1349 
1350 bool Arguments::process_settings_file(const char* file_name, bool should_exist, jboolean ignore_unrecognized) {
1351   FILE* stream = fopen(file_name, "rb");
1352   if (stream == NULL) {
1353     if (should_exist) {
1354       jio_fprintf(defaultStream::error_stream(),
1355                   "Could not open settings file %s\n", file_name);
1356       return false;
1357     } else {
1358       return true;
1359     }
1360   }
1361 


3826   }
3827 
3828   if (_gc_log_filename != NULL) {
3829     // -Xloggc was used to specify a filename
3830     const char* gc_conf = PrintGCDetails ? "gc*" : "gc";
3831 
3832     LogTarget(Error, logging) target;
3833     LogStream errstream(target);
3834     return LogConfiguration::parse_log_arguments(_gc_log_filename, gc_conf, NULL, NULL, &errstream);
3835   } else if (PrintGC || PrintGCDetails) {
3836     LogConfiguration::configure_stdout(LogLevel::Info, !PrintGCDetails, LOG_TAGS(gc));
3837   }
3838   return true;
3839 }
3840 
3841 // Parse entry point called from JNI_CreateJavaVM
3842 
3843 jint Arguments::parse(const JavaVMInitArgs* initial_cmd_args) {
3844   assert(verify_special_jvm_flags(false), "deprecated and obsolete flag table inconsistent");
3845 
3846   // Initialize ranges and constraints
3847   JVMFlagRangeList::init();
3848   JVMFlagConstraintList::init();
3849 
3850   // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed.
3851   const char* hotspotrc = ".hotspotrc";
3852   bool settings_file_specified = false;
3853   bool needs_hotspotrc_warning = false;
3854   ScopedVMInitArgs initial_vm_options_args("");
3855   ScopedVMInitArgs initial_java_tool_options_args("env_var='JAVA_TOOL_OPTIONS'");
3856   ScopedVMInitArgs initial_java_options_args("env_var='_JAVA_OPTIONS'");
3857 
3858   // Pointers to current working set of containers
3859   JavaVMInitArgs* cur_cmd_args;
3860   JavaVMInitArgs* cur_vm_options_args;
3861   JavaVMInitArgs* cur_java_options_args;
3862   JavaVMInitArgs* cur_java_tool_options_args;
3863 
3864   // Containers for modified/expanded options
3865   ScopedVMInitArgs mod_cmd_args("cmd_line_args");
3866   ScopedVMInitArgs mod_vm_options_args("vm_options_args");
3867   ScopedVMInitArgs mod_java_tool_options_args("env_var='JAVA_TOOL_OPTIONS'");
3868   ScopedVMInitArgs mod_java_options_args("env_var='_JAVA_OPTIONS'");




  24 
  25 #include "precompiled.hpp"
  26 #include "jvm.h"
  27 #include "classfile/classLoader.hpp"
  28 #include "classfile/javaAssertions.hpp"
  29 #include "classfile/moduleEntry.hpp"
  30 #include "classfile/stringTable.hpp"
  31 #include "classfile/symbolTable.hpp"
  32 #include "gc/shared/gcArguments.hpp"
  33 #include "gc/shared/gcConfig.hpp"
  34 #include "logging/log.hpp"
  35 #include "logging/logConfiguration.hpp"
  36 #include "logging/logStream.hpp"
  37 #include "logging/logTag.hpp"
  38 #include "memory/allocation.inline.hpp"
  39 #include "memory/filemap.hpp"
  40 #include "oops/oop.inline.hpp"
  41 #include "prims/jvmtiExport.hpp"
  42 #include "runtime/arguments.hpp"
  43 #include "runtime/flags/jvmFlag.hpp"



  44 #include "runtime/java.hpp"
  45 #include "runtime/os.inline.hpp"
  46 #include "runtime/safepoint.hpp"
  47 #include "runtime/safepointMechanism.hpp"
  48 #include "runtime/vm_version.hpp"
  49 #include "services/management.hpp"
  50 #include "services/memTracker.hpp"
  51 #include "utilities/align.hpp"
  52 #include "utilities/defaultStream.hpp"
  53 #include "utilities/macros.hpp"
  54 #include "utilities/powerOfTwo.hpp"
  55 #include "utilities/stringUtils.hpp"
  56 #if INCLUDE_JFR
  57 #include "jfr/jfr.hpp"
  58 #endif
  59 
  60 #define DEFAULT_JAVA_LAUNCHER  "generic"
  61 
  62 char*  Arguments::_jvm_flags_file               = NULL;
  63 char** Arguments::_jvm_flags_array              = NULL;


 840 
 841 // Describe an argument out of range error
 842 void Arguments::describe_range_error(ArgsRange errcode) {
 843   switch(errcode) {
 844   case arg_too_big:
 845     jio_fprintf(defaultStream::error_stream(),
 846                 "The specified size exceeds the maximum "
 847                 "representable size.\n");
 848     break;
 849   case arg_too_small:
 850   case arg_unreadable:
 851   case arg_in_range:
 852     // do nothing for now
 853     break;
 854   default:
 855     ShouldNotReachHere();
 856   }
 857 }
 858 
 859 static bool set_bool_flag(JVMFlag* flag, bool value, JVMFlag::Flags origin) {
 860   if (JVMFlag::boolAtPut(flag, value, origin) == JVMFlag::SUCCESS) {
 861     return true;
 862   } else {
 863     return false;
 864   }
 865 }
 866 
 867 static bool set_fp_numeric_flag(JVMFlag* flag, char* value, JVMFlag::Flags origin) {
 868   char* end;
 869   errno = 0;
 870   double v = strtod(value, &end);
 871   if ((errno != 0) || (*end != 0)) {
 872     return false;
 873   }
 874 
 875   if (JVMFlag::doubleAtPut(flag, v, origin) == JVMFlag::SUCCESS) {
 876     return true;
 877   }
 878   return false;
 879 }
 880 
 881 static bool set_numeric_flag(JVMFlag* flag, char* value, JVMFlag::Flags origin) {
 882   julong v;
 883   int int_v;
 884   intx intx_v;
 885   bool is_neg = false;
 886 
 887   if (flag == NULL) {
 888     return false;
 889   }
 890 
 891   // Check the sign first since atojulong() parses only unsigned values.
 892   if (*value == '-') {
 893     if (!flag->is_intx() && !flag->is_int()) {
 894       return false;
 895     }
 896     value++;
 897     is_neg = true;
 898   }
 899   if (!Arguments::atojulong(value, &v)) {
 900     return false;
 901   }
 902   if (flag->is_int()) {
 903     int_v = (int) v;
 904     if (is_neg) {
 905       int_v = -int_v;
 906     }
 907     return JVMFlag::intAtPut(flag, int_v, origin) == JVMFlag::SUCCESS;
 908   } else if (flag->is_uint()) {
 909     uint uint_v = (uint) v;
 910     return JVMFlag::uintAtPut(flag, uint_v, origin) == JVMFlag::SUCCESS;
 911   } else if (flag->is_intx()) {
 912     intx_v = (intx) v;
 913     if (is_neg) {
 914       intx_v = -intx_v;
 915     }
 916     return JVMFlag::intxAtPut(flag, intx_v, origin) == JVMFlag::SUCCESS;
 917   } else if (flag->is_uintx()) {
 918     uintx uintx_v = (uintx) v;
 919     return JVMFlag::uintxAtPut(flag, uintx_v, origin) == JVMFlag::SUCCESS;
 920   } else if (flag->is_uint64_t()) {
 921     uint64_t uint64_t_v = (uint64_t) v;
 922     return JVMFlag::uint64_tAtPut(flag, uint64_t_v, origin) == JVMFlag::SUCCESS;
 923   } else if (flag->is_size_t()) {
 924     size_t size_t_v = (size_t) v;
 925     return JVMFlag::size_tAtPut(flag, size_t_v, origin) == JVMFlag::SUCCESS;
 926   } else if (flag->is_double()) {
 927     double double_v = (double) v;
 928     return JVMFlag::doubleAtPut(flag, double_v, origin) == JVMFlag::SUCCESS;
 929   } else {
 930     return false;
 931   }
 932 }
 933 
 934 static bool set_string_flag(JVMFlag* flag, const char* value, JVMFlag::Flags origin) {
 935   if (JVMFlag::ccstrAtPut(flag, &value, origin) != JVMFlag::SUCCESS) return false;
 936   // Contract:  JVMFlag always returns a pointer that needs freeing.
 937   FREE_C_HEAP_ARRAY(char, value);
 938   return true;
 939 }
 940 
 941 static bool append_to_string_flag(JVMFlag* flag, const char* new_value, JVMFlag::Flags origin) {
 942   const char* old_value = "";
 943   if (JVMFlag::ccstrAt(flag, &old_value) != JVMFlag::SUCCESS) return false;
 944   size_t old_len = old_value != NULL ? strlen(old_value) : 0;
 945   size_t new_len = strlen(new_value);
 946   const char* value;
 947   char* free_this_too = NULL;
 948   if (old_len == 0) {


1318 #ifdef PRODUCT
1319       bool mismatched = ((msg_type == JVMFlag::NOTPRODUCT_FLAG_BUT_PRODUCT_BUILD) ||
1320                          (msg_type == JVMFlag::DEVELOPER_FLAG_BUT_PRODUCT_BUILD));
1321       if (ignore_unrecognized && mismatched) {
1322         return true;
1323       }
1324 #endif
1325       jio_fprintf(defaultStream::error_stream(), "%s", locked_message_buf);
1326     }
1327   } else {
1328     if (ignore_unrecognized) {
1329       return true;
1330     }
1331     jio_fprintf(defaultStream::error_stream(),
1332                 "Unrecognized VM option '%s'\n", argname);
1333     JVMFlag* fuzzy_matched = JVMFlag::fuzzy_match((const char*)argname, arg_len, true);
1334     if (fuzzy_matched != NULL) {
1335       jio_fprintf(defaultStream::error_stream(),
1336                   "Did you mean '%s%s%s'? ",
1337                   (fuzzy_matched->is_bool()) ? "(+/-)" : "",
1338                   fuzzy_matched->name(),
1339                   (fuzzy_matched->is_bool()) ? "" : "=<value>");
1340     }
1341   }
1342 
1343   // allow for commandline "commenting out" options like -XX:#+Verbose
1344   return arg[0] == '#';
1345 }
1346 
1347 bool Arguments::process_settings_file(const char* file_name, bool should_exist, jboolean ignore_unrecognized) {
1348   FILE* stream = fopen(file_name, "rb");
1349   if (stream == NULL) {
1350     if (should_exist) {
1351       jio_fprintf(defaultStream::error_stream(),
1352                   "Could not open settings file %s\n", file_name);
1353       return false;
1354     } else {
1355       return true;
1356     }
1357   }
1358 


3823   }
3824 
3825   if (_gc_log_filename != NULL) {
3826     // -Xloggc was used to specify a filename
3827     const char* gc_conf = PrintGCDetails ? "gc*" : "gc";
3828 
3829     LogTarget(Error, logging) target;
3830     LogStream errstream(target);
3831     return LogConfiguration::parse_log_arguments(_gc_log_filename, gc_conf, NULL, NULL, &errstream);
3832   } else if (PrintGC || PrintGCDetails) {
3833     LogConfiguration::configure_stdout(LogLevel::Info, !PrintGCDetails, LOG_TAGS(gc));
3834   }
3835   return true;
3836 }
3837 
3838 // Parse entry point called from JNI_CreateJavaVM
3839 
3840 jint Arguments::parse(const JavaVMInitArgs* initial_cmd_args) {
3841   assert(verify_special_jvm_flags(false), "deprecated and obsolete flag table inconsistent");
3842 
3843   // Initialize custom ranges
3844   JVMFlagCustomRange::init_all();
3845   JVMFlag::validate_flags();
3846 
3847   // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed.
3848   const char* hotspotrc = ".hotspotrc";
3849   bool settings_file_specified = false;
3850   bool needs_hotspotrc_warning = false;
3851   ScopedVMInitArgs initial_vm_options_args("");
3852   ScopedVMInitArgs initial_java_tool_options_args("env_var='JAVA_TOOL_OPTIONS'");
3853   ScopedVMInitArgs initial_java_options_args("env_var='_JAVA_OPTIONS'");
3854 
3855   // Pointers to current working set of containers
3856   JavaVMInitArgs* cur_cmd_args;
3857   JavaVMInitArgs* cur_vm_options_args;
3858   JavaVMInitArgs* cur_java_options_args;
3859   JavaVMInitArgs* cur_java_tool_options_args;
3860 
3861   // Containers for modified/expanded options
3862   ScopedVMInitArgs mod_cmd_args("cmd_line_args");
3863   ScopedVMInitArgs mod_vm_options_args("vm_options_args");
3864   ScopedVMInitArgs mod_java_tool_options_args("env_var='JAVA_TOOL_OPTIONS'");
3865   ScopedVMInitArgs mod_java_options_args("env_var='_JAVA_OPTIONS'");


< prev index next >