< prev index next >

src/share/vm/runtime/arguments.cpp

Print this page




 102 AgentLibraryList Arguments::_libraryList;
 103 AgentLibraryList Arguments::_agentList;
 104 
 105 abort_hook_t     Arguments::_abort_hook         = NULL;
 106 exit_hook_t      Arguments::_exit_hook          = NULL;
 107 vfprintf_hook_t  Arguments::_vfprintf_hook      = NULL;
 108 
 109 
 110 SystemProperty *Arguments::_sun_boot_library_path = NULL;
 111 SystemProperty *Arguments::_java_library_path = NULL;
 112 SystemProperty *Arguments::_java_home = NULL;
 113 SystemProperty *Arguments::_java_class_path = NULL;
 114 SystemProperty *Arguments::_sun_boot_class_path = NULL;
 115 
 116 char* Arguments::_ext_dirs = NULL;
 117 
 118 // Check if head of 'option' matches 'name', and sets 'tail' to the remaining
 119 // part of the option string.
 120 static bool match_option(const JavaVMOption *option, const char* name,
 121                          const char** tail) {
 122   int len = (int)strlen(name);
 123   if (strncmp(option->optionString, name, len) == 0) {
 124     *tail = option->optionString + len;
 125     return true;
 126   } else {
 127     return false;
 128   }
 129 }
 130 
 131 // Check if 'option' matches 'name'. No "tail" is allowed.
 132 static bool match_option(const JavaVMOption *option, const char* name) {
 133   const char* tail = NULL;
 134   bool result = match_option(option, name, &tail);
 135   if (tail != NULL && *tail == '\0') {
 136     return result;
 137   } else {
 138     return false;
 139   }
 140 }
 141 
 142 // Return true if any of the strings in null-terminated array 'names' matches.


 203   _java_home =  new SystemProperty("java.home", NULL,  true);
 204   _sun_boot_class_path = new SystemProperty("sun.boot.class.path", NULL,  true);
 205 
 206   _java_class_path = new SystemProperty("java.class.path", "",  true);
 207 
 208   // Add to System Property list.
 209   PropertyList_add(&_system_properties, _sun_boot_library_path);
 210   PropertyList_add(&_system_properties, _java_library_path);
 211   PropertyList_add(&_system_properties, _java_home);
 212   PropertyList_add(&_system_properties, _java_class_path);
 213   PropertyList_add(&_system_properties, _sun_boot_class_path);
 214 
 215   // Set OS specific system properties values
 216   os::init_system_properties_values();
 217 }
 218 
 219 // Update/Initialize System properties after JDK version number is known
 220 void Arguments::init_version_specific_system_properties() {
 221   enum { bufsz = 16 };
 222   char buffer[bufsz];
 223   const char* spec_vendor = "Sun Microsystems Inc.";
 224   uint32_t spec_version = 0;
 225 
 226   spec_vendor = "Oracle Corporation";
 227   spec_version = JDK_Version::current().major_version();
 228   jio_snprintf(buffer, bufsz, "1." UINT32_FORMAT, spec_version);
 229 
 230   PropertyList_add(&_system_properties,
 231       new SystemProperty("java.vm.specification.vendor",  spec_vendor, false));
 232   PropertyList_add(&_system_properties,
 233       new SystemProperty("java.vm.specification.version", buffer, false));
 234   PropertyList_add(&_system_properties,
 235       new SystemProperty("java.vm.vendor", VM_Version::vm_vendor(),  false));
 236 }
 237 
 238 /**
 239  * Provide a slightly more user-friendly way of eliminating -XX flags.
 240  * When a flag is eliminated, it can be added to this list in order to
 241  * continue accepting this flag on the command-line, while issuing a warning
 242  * and ignoring the value.  Once the JDK version reaches the 'accept_until'
 243  * limit, we flatly refuse to admit the existence of the flag.  This allows
 244  * a flag to die correctly over JDK releases using HSX.
 245  * But now that HSX is no longer supported only options with a future
 246  * accept_until value need to be listed, and the list can be pruned
 247  * on each major release.

















































 248  */


 249 typedef struct {
 250   const char* name;
 251   JDK_Version obsoleted_in; // when the flag went away
 252   JDK_Version accept_until; // which version to start denying the existence
 253 } ObsoleteFlag;
 254 
 255 static ObsoleteFlag obsolete_jvm_flags[] = {
 256   { "UseOldInlining",                JDK_Version::jdk(9), JDK_Version::jdk(10) },
 257   { "SafepointPollOffset",           JDK_Version::jdk(9), JDK_Version::jdk(10) },
 258   { "UseBoundThreads",               JDK_Version::jdk(9), JDK_Version::jdk(10) },
 259   { "DefaultThreadPriority",         JDK_Version::jdk(9), JDK_Version::jdk(10) },
 260   { "NoYieldsInMicrolock",           JDK_Version::jdk(9), JDK_Version::jdk(10) },
 261   { "BackEdgeThreshold",             JDK_Version::jdk(9), JDK_Version::jdk(10) },
 262   { "UseNewReflection",              JDK_Version::jdk(9), JDK_Version::jdk(10) },
 263   { "ReflectionWrapResolutionErrors",JDK_Version::jdk(9), JDK_Version::jdk(10) },
 264   { "VerifyReflectionBytecodes",     JDK_Version::jdk(9), JDK_Version::jdk(10) },
 265   { "AutoShutdownNMT",               JDK_Version::jdk(9), JDK_Version::jdk(10) },
 266   { "NmethodSweepFraction",          JDK_Version::jdk(9), JDK_Version::jdk(10) },
 267   { "NmethodSweepCheckInterval",     JDK_Version::jdk(9), JDK_Version::jdk(10) },
 268   { "CodeCacheMinimumFreeSpace",     JDK_Version::jdk(9), JDK_Version::jdk(10) },











































 269 #ifndef ZERO
 270   { "UseFastAccessorMethods",        JDK_Version::jdk(9), JDK_Version::jdk(10) },
 271   { "UseFastEmptyMethods",           JDK_Version::jdk(9), JDK_Version::jdk(10) },
 272 #endif // ZERO
 273   { "UseCompilerSafepoints",         JDK_Version::jdk(9), JDK_Version::jdk(10) },
 274   { "AdaptiveSizePausePolicy",       JDK_Version::jdk(9), JDK_Version::jdk(10) },
 275   { "ParallelGCRetainPLAB",          JDK_Version::jdk(9), JDK_Version::jdk(10) },
 276   { "ThreadSafetyMargin",            JDK_Version::jdk(9), JDK_Version::jdk(10) },
 277   { "LazyBootClassLoader",           JDK_Version::jdk(9), JDK_Version::jdk(10) },
 278   { "StarvationMonitorInterval",     JDK_Version::jdk(9), JDK_Version::jdk(10) },
 279   { "PreInflateSpin",                JDK_Version::jdk(9), JDK_Version::jdk(10) },
 280   { NULL, JDK_Version(0), JDK_Version(0) }
 281 };
 282 
 283 // Returns true if the flag is obsolete and fits into the range specified
 284 // for being ignored.  In the case that the flag is ignored, the 'version'
 285 // value is filled in with the version number when the flag became
 286 // obsolete so that that value can be displayed to the user.
 287 bool Arguments::is_newly_obsolete(const char *s, JDK_Version* version) {
 288   int i = 0;
































 289   assert(version != NULL, "Must provide a version buffer");
 290   while (obsolete_jvm_flags[i].name != NULL) {
 291     const ObsoleteFlag& flag_status = obsolete_jvm_flags[i];
 292     // <flag>=xxx form
 293     // [-|+]<flag> form
 294     size_t len = strlen(flag_status.name);
 295     if ((strncmp(flag_status.name, s, len) == 0) &&
 296         (strlen(s) == len)){
 297       if (JDK_Version::current().compare(flag_status.accept_until) == -1) {
 298           *version = flag_status.obsoleted_in;
 299           return true;
 300       }
 301     }
 302     i++;
 303   }
 304   return false;
 305 }
 306 





























































































 307 // Constructs the system class path (aka boot class path) from the following
 308 // components, in order:
 309 //
 310 //     prefix           // from -Xbootclasspath/p:...
 311 //     base             // from os::get_system_properties() or -Xbootclasspath=
 312 //     suffix           // from -Xbootclasspath/a:...
 313 //
 314 // This could be AllStatic, but it isn't needed after argument processing is
 315 // complete.
 316 class SysClassPath: public StackObj {
 317 public:
 318   SysClassPath(const char* base);
 319   ~SysClassPath();
 320 
 321   inline void set_base(const char* base);
 322   inline void add_prefix(const char* prefix);
 323   inline void add_suffix_to_prefix(const char* suffix);
 324   inline void add_suffix(const char* suffix);
 325   inline void reset_path(const char* base);
 326 


 555 }
 556 
 557 // Describe an argument out of range error
 558 void Arguments::describe_range_error(ArgsRange errcode) {
 559   switch(errcode) {
 560   case arg_too_big:
 561     jio_fprintf(defaultStream::error_stream(),
 562                 "The specified size exceeds the maximum "
 563                 "representable size.\n");
 564     break;
 565   case arg_too_small:
 566   case arg_unreadable:
 567   case arg_in_range:
 568     // do nothing for now
 569     break;
 570   default:
 571     ShouldNotReachHere();
 572   }
 573 }
 574 
 575 static bool set_bool_flag(char* name, bool value, Flag::Flags origin) {
 576   if (CommandLineFlags::boolAtPut(name, &value, origin) == Flag::SUCCESS) {
 577     return true;
 578   } else {
 579     return false;
 580   }
 581 }
 582 
 583 static bool set_fp_numeric_flag(char* name, char* value, Flag::Flags origin) {
 584   double v;
 585   if (sscanf(value, "%lf", &v) != 1) {
 586     return false;
 587   }
 588 
 589   if (CommandLineFlags::doubleAtPut(name, &v, origin) == Flag::SUCCESS) {
 590     return true;
 591   }
 592   return false;
 593 }
 594 
 595 static bool set_numeric_flag(char* name, char* value, Flag::Flags origin) {
 596   julong v;
 597   int int_v;
 598   intx intx_v;
 599   bool is_neg = false;
 600   // Check the sign first since atomull() parses only unsigned values.
 601   if (*value == '-') {
 602     if ((CommandLineFlags::intxAt(name, &intx_v) != Flag::SUCCESS) && (CommandLineFlags::intAt(name, &int_v) != Flag::SUCCESS)) {
 603       return false;
 604     }
 605     value++;
 606     is_neg = true;
 607   }
 608   if (!atomull(value, &v)) {
 609     return false;
 610   }
 611   int_v = (int) v;
 612   if (is_neg) {
 613     int_v = -int_v;
 614   }
 615   if (CommandLineFlags::intAtPut(name, &int_v, origin) == Flag::SUCCESS) {


 624     intx_v = -intx_v;
 625   }
 626   if (CommandLineFlags::intxAtPut(name, &intx_v, origin) == Flag::SUCCESS) {
 627     return true;
 628   }
 629   uintx uintx_v = (uintx) v;
 630   if (!is_neg && (CommandLineFlags::uintxAtPut(name, &uintx_v, origin) == Flag::SUCCESS)) {
 631     return true;
 632   }
 633   uint64_t uint64_t_v = (uint64_t) v;
 634   if (!is_neg && (CommandLineFlags::uint64_tAtPut(name, &uint64_t_v, origin) == Flag::SUCCESS)) {
 635     return true;
 636   }
 637   size_t size_t_v = (size_t) v;
 638   if (!is_neg && (CommandLineFlags::size_tAtPut(name, &size_t_v, origin) == Flag::SUCCESS)) {
 639     return true;
 640   }
 641   return false;
 642 }
 643 
 644 static bool set_string_flag(char* name, const char* value, Flag::Flags origin) {
 645   if (CommandLineFlags::ccstrAtPut(name, &value, origin) != Flag::SUCCESS) return false;
 646   // Contract:  CommandLineFlags always returns a pointer that needs freeing.
 647   FREE_C_HEAP_ARRAY(char, value);
 648   return true;
 649 }
 650 
 651 static bool append_to_string_flag(char* name, const char* new_value, Flag::Flags origin) {
 652   const char* old_value = "";
 653   if (CommandLineFlags::ccstrAt(name, &old_value) != Flag::SUCCESS) return false;
 654   size_t old_len = old_value != NULL ? strlen(old_value) : 0;
 655   size_t new_len = strlen(new_value);
 656   const char* value;
 657   char* free_this_too = NULL;
 658   if (old_len == 0) {
 659     value = new_value;
 660   } else if (new_len == 0) {
 661     value = old_value;
 662   } else {
 663     char* buf = NEW_C_HEAP_ARRAY(char, old_len + 1 + new_len + 1, mtInternal);
 664     // each new setting adds another LINE to the switch:
 665     sprintf(buf, "%s\n%s", old_value, new_value);
 666     value = buf;
 667     free_this_too = buf;
 668   }
 669   (void) CommandLineFlags::ccstrAtPut(name, &value, origin);
 670   // CommandLineFlags always returns a pointer that needs freeing.
 671   FREE_C_HEAP_ARRAY(char, value);
 672   if (free_this_too != NULL) {
 673     // CommandLineFlags made its own copy, so I must delete my own temp. buffer.
 674     FREE_C_HEAP_ARRAY(char, free_this_too);
 675   }
 676   return true;
 677 }
 678 



























 679 bool Arguments::parse_argument(const char* arg, Flag::Flags origin) {
 680 
 681   // range of acceptable characters spelled out for portability reasons
 682 #define NAME_RANGE  "[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]"
 683 #define BUFLEN 255
 684   char name[BUFLEN+1];
 685   char dummy;


 686 
 687   if (sscanf(arg, "-%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
 688     return set_bool_flag(name, false, origin);




 689   }
 690   if (sscanf(arg, "+%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
 691     return set_bool_flag(name, true, origin);




 692   }
 693 
 694   char punct;
 695   if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "%c", name, &punct) == 2 && punct == '=') {
 696     const char* value = strchr(arg, '=') + 1;
 697     Flag* flag = Flag::find_flag(name, strlen(name));







 698     if (flag != NULL && flag->is_ccstr()) {
 699       if (flag->ccstr_accumulates()) {
 700         return append_to_string_flag(name, value, origin);
 701       } else {
 702         if (value[0] == '\0') {
 703           value = NULL;
 704         }
 705         return set_string_flag(name, value, origin);
 706       }


 707     }
 708   }
 709 
 710   if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE ":%c", name, &punct) == 2 && punct == '=') {
 711     const char* value = strchr(arg, '=') + 1;
 712     // -XX:Foo:=xxx will reset the string flag to the given value.
 713     if (value[0] == '\0') {
 714       value = NULL;
 715     }
 716     return set_string_flag(name, value, origin);




 717   }
 718 
 719 #define SIGNED_FP_NUMBER_RANGE "[-0123456789.]"
 720 #define SIGNED_NUMBER_RANGE    "[-0123456789]"
 721 #define        NUMBER_RANGE    "[0123456789]"
 722   char value[BUFLEN + 1];
 723   char value2[BUFLEN + 1];
 724   if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_NUMBER_RANGE "." "%" XSTR(BUFLEN) NUMBER_RANGE "%c", name, value, value2, &dummy) == 3) {
 725     // Looks like a floating-point number -- try again with more lenient format string
 726     if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_FP_NUMBER_RANGE "%c", name, value, &dummy) == 2) {
 727       return set_fp_numeric_flag(name, value, origin);




 728     }
 729   }
 730 
 731 #define VALUE_RANGE "[-kmgtxKMGTX0123456789abcdefABCDEF]"
 732   if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) VALUE_RANGE "%c", name, value, &dummy) == 2) {
 733     return set_numeric_flag(name, value, origin);




 734   }
 735 
 736   return false;
 737 }
 738 
 739 void Arguments::add_string(char*** bldarray, int* count, const char* arg) {
 740   assert(bldarray != NULL, "illegal argument");
 741 
 742   if (arg == NULL) {
 743     return;
 744   }
 745 
 746   int new_count = *count + 1;
 747 
 748   // expand the array and add arg to the last element
 749   if (*bldarray == NULL) {
 750     *bldarray = NEW_C_HEAP_ARRAY(char*, new_count, mtInternal);
 751   } else {
 752     *bldarray = REALLOC_C_HEAP_ARRAY(char*, *bldarray, new_count, mtInternal);
 753   }


 821   st->cr();
 822 }
 823 
 824 void Arguments::print_jvm_flags_on(outputStream* st) {
 825   if (_num_jvm_flags > 0) {
 826     for (int i=0; i < _num_jvm_flags; i++) {
 827       st->print("%s ", _jvm_flags_array[i]);
 828     }
 829   }
 830 }
 831 
 832 void Arguments::print_jvm_args_on(outputStream* st) {
 833   if (_num_jvm_args > 0) {
 834     for (int i=0; i < _num_jvm_args; i++) {
 835       st->print("%s ", _jvm_args_array[i]);
 836     }
 837   }
 838 }
 839 
 840 bool Arguments::process_argument(const char* arg,
 841     jboolean ignore_unrecognized, Flag::Flags origin) {
 842 
 843   JDK_Version since = JDK_Version();
 844 
 845   if (parse_argument(arg, origin) || ignore_unrecognized) {
 846     return true;
 847   }
 848 
 849   // Determine if the flag has '+', '-', or '=' characters.
 850   bool has_plus_minus = (*arg == '+' || *arg == '-');
 851   const char* const argname = has_plus_minus ? arg + 1 : arg;
 852 
 853   size_t arg_len;
 854   const char* equal_sign = strchr(argname, '=');
 855   if (equal_sign == NULL) {
 856     arg_len = strlen(argname);
 857   } else {
 858     arg_len = equal_sign - argname;
 859   }
 860 
 861   // Only make the obsolete check for valid arguments.
 862   if (arg_len <= BUFLEN) {
 863     // Construct a string which consists only of the argument name without '+', '-', or '='.
 864     char stripped_argname[BUFLEN+1];
 865     strncpy(stripped_argname, argname, arg_len);
 866     stripped_argname[arg_len] = '\0';  // strncpy may not null terminate.
 867 
 868     if (is_newly_obsolete(stripped_argname, &since)) {
 869       char version[256];
 870       since.to_string(version, sizeof(version));
 871       warning("ignoring option %s; support was removed in %s", stripped_argname, version);
 872       return true;
 873     }
 874   }
 875 
 876   // For locked flags, report a custom error message if available.
 877   // Otherwise, report the standard unrecognized VM option.
 878   Flag* found_flag = Flag::find_flag((const char*)argname, arg_len, true, true);
 879   if (found_flag != NULL) {
 880     char locked_message_buf[BUFLEN];
 881     found_flag->get_locked_message(locked_message_buf, BUFLEN);
 882     if (strlen(locked_message_buf) == 0) {
 883       if (found_flag->is_bool() && !has_plus_minus) {
 884         jio_fprintf(defaultStream::error_stream(),
 885           "Missing +/- setting for VM option '%s'\n", argname);
 886       } else if (!found_flag->is_bool() && has_plus_minus) {
 887         jio_fprintf(defaultStream::error_stream(),
 888           "Unexpected +/- setting in VM option '%s'\n", argname);
 889       } else {
 890         jio_fprintf(defaultStream::error_stream(),
 891           "Improperly specified VM option '%s'\n", argname);


1211 
1212     FLAG_SET_ERGO(intx, Tier2InvokeNotifyFreqLog, scaled_freq_log(Tier2InvokeNotifyFreqLog));
1213     FLAG_SET_ERGO(intx, Tier2BackedgeNotifyFreqLog, scaled_freq_log(Tier2BackedgeNotifyFreqLog));
1214 
1215     FLAG_SET_ERGO(intx, Tier3InvokeNotifyFreqLog, scaled_freq_log(Tier3InvokeNotifyFreqLog));
1216     FLAG_SET_ERGO(intx, Tier3BackedgeNotifyFreqLog, scaled_freq_log(Tier3BackedgeNotifyFreqLog));
1217 
1218     FLAG_SET_ERGO(intx, Tier23InlineeNotifyFreqLog, scaled_freq_log(Tier23InlineeNotifyFreqLog));
1219 
1220     FLAG_SET_ERGO(intx, Tier4InvocationThreshold, scaled_compile_threshold(Tier4InvocationThreshold));
1221     FLAG_SET_ERGO(intx, Tier4MinInvocationThreshold, scaled_compile_threshold(Tier4MinInvocationThreshold));
1222     FLAG_SET_ERGO(intx, Tier4CompileThreshold, scaled_compile_threshold(Tier4CompileThreshold));
1223     FLAG_SET_ERGO(intx, Tier4BackEdgeThreshold, scaled_compile_threshold(Tier4BackEdgeThreshold));
1224   }
1225 }
1226 
1227 #if INCLUDE_ALL_GCS
1228 static void disable_adaptive_size_policy(const char* collector_name) {
1229   if (UseAdaptiveSizePolicy) {
1230     if (FLAG_IS_CMDLINE(UseAdaptiveSizePolicy)) {
1231       warning("disabling UseAdaptiveSizePolicy; it is incompatible with %s.",
1232               collector_name);
1233     }
1234     FLAG_SET_DEFAULT(UseAdaptiveSizePolicy, false);
1235   }
1236 }
1237 
1238 void Arguments::set_parnew_gc_flags() {
1239   assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC && !UseG1GC,
1240          "control point invariant");
1241   assert(UseConcMarkSweepGC, "CMS is expected to be on here");
1242   assert(UseParNewGC, "ParNew should always be used with CMS");
1243 
1244   if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
1245     FLAG_SET_DEFAULT(ParallelGCThreads, Abstract_VM_Version::parallel_worker_threads());
1246     assert(ParallelGCThreads > 0, "We should always have at least one thread by default");
1247   } else if (ParallelGCThreads == 0) {
1248     jio_fprintf(defaultStream::error_stream(),
1249         "The ParNew GC can not be combined with -XX:ParallelGCThreads=0\n");
1250     vm_exit(1);
1251   }


1686 #if !INCLUDE_ALL_GCS
1687 #ifdef ASSERT
1688 static bool verify_serial_gc_flags() {
1689   return (UseSerialGC &&
1690         !(UseParNewGC || (UseConcMarkSweepGC) || UseG1GC ||
1691           UseParallelGC || UseParallelOldGC));
1692 }
1693 #endif // ASSERT
1694 #endif // INCLUDE_ALL_GCS
1695 
1696 void Arguments::set_gc_specific_flags() {
1697 #if INCLUDE_ALL_GCS
1698   // Set per-collector flags
1699   if (UseParallelGC || UseParallelOldGC) {
1700     set_parallel_gc_flags();
1701   } else if (UseConcMarkSweepGC) {
1702     set_cms_and_parnew_gc_flags();
1703   } else if (UseG1GC) {
1704     set_g1_gc_flags();
1705   }
1706   check_deprecated_gc_flags();
1707   if (AssumeMP && !UseSerialGC) {
1708     if (FLAG_IS_DEFAULT(ParallelGCThreads) && ParallelGCThreads == 1) {
1709       warning("If the number of processors is expected to increase from one, then"
1710               " you should configure the number of parallel GC threads appropriately"
1711               " using -XX:ParallelGCThreads=N");
1712     }
1713   }
1714   if (MinHeapFreeRatio == 100) {
1715     // Keeping the heap 100% free is hard ;-) so limit it to 99%.
1716     FLAG_SET_ERGO(uintx, MinHeapFreeRatio, 99);
1717   }
1718 #else // INCLUDE_ALL_GCS
1719   assert(verify_serial_gc_flags(), "SerialGC unset");
1720 #endif // INCLUDE_ALL_GCS
1721 }
1722 
1723 julong Arguments::limit_by_allocatable_memory(julong limit) {
1724   julong max_allocatable;
1725   julong result = limit;
1726   if (os::has_allocatable_memory_limit(&max_allocatable)) {
1727     result = MIN2(result, max_allocatable / MaxVirtMemFraction);
1728   }
1729   return result;
1730 }
1731 
1732 // Use static initialization to get the default before parsing
1733 static const size_t DefaultHeapBaseMinAddress = HeapBaseMinAddress;
1734 
1735 void Arguments::set_heap_size() {
1736   if (!FLAG_IS_DEFAULT(DefaultMaxRAMFraction)) {
1737     // Deprecated flag
1738     FLAG_SET_CMDLINE(uintx, MaxRAMFraction, DefaultMaxRAMFraction);
1739   }
1740 
1741   const julong phys_mem =
1742     FLAG_IS_DEFAULT(MaxRAM) ? MIN2(os::physical_memory(), (julong)MaxRAM)
1743                             : (julong)MaxRAM;
1744 
1745   // If the maximum heap size has not been set with -Xmx,
1746   // then set it as fraction of the size of physical memory,
1747   // respecting the maximum and minimum sizes of the heap.
1748   if (FLAG_IS_DEFAULT(MaxHeapSize)) {
1749     julong reasonable_max = phys_mem / MaxRAMFraction;
1750 
1751     if (phys_mem <= MaxHeapSize * MinRAMFraction) {
1752       // Small physical memory, so use a minimum fraction of it for the heap
1753       reasonable_max = phys_mem / MinRAMFraction;
1754     } else {
1755       // Not-small physical memory, so require a heap at least
1756       // as large as MaxHeapSize
1757       reasonable_max = MAX2(reasonable_max, (julong)MaxHeapSize);
1758     }
1759     if (!FLAG_IS_DEFAULT(ErgoHeapSizeLimit) && ErgoHeapSizeLimit != 0) {
1760       // Limit the heap size to ErgoHeapSizeLimit


1823       reasonable_initial = limit_by_allocatable_memory(reasonable_initial);
1824 
1825       if (PrintGCDetails && Verbose) {
1826         // Cannot use gclog_or_tty yet.
1827         tty->print_cr("  Initial heap size " SIZE_FORMAT, (size_t)reasonable_initial);
1828       }
1829       FLAG_SET_ERGO(size_t, InitialHeapSize, (size_t)reasonable_initial);
1830     }
1831     // If the minimum heap size has not been set (via -Xms),
1832     // synchronize with InitialHeapSize to avoid errors with the default value.
1833     if (min_heap_size() == 0) {
1834       set_min_heap_size(MIN2((size_t)reasonable_minimum, InitialHeapSize));
1835       if (PrintGCDetails && Verbose) {
1836         // Cannot use gclog_or_tty yet.
1837         tty->print_cr("  Minimum heap size " SIZE_FORMAT, min_heap_size());
1838       }
1839     }
1840   }
1841 }
1842 
1843   // Set up runtime image flags




















































































































1844 void Arguments::set_runtime_image_flags() {
1845 #ifdef _LP64
1846   // Memory map image file by default on 64 bit machines.
1847   if (FLAG_IS_DEFAULT(MemoryMapImage)) {
1848     FLAG_SET_ERGO(bool, MemoryMapImage, true);
1849   }
1850 #endif
1851 }
1852 
1853 // This must be called after ergonomics.
1854 void Arguments::set_bytecode_flags() {
1855   if (!RewriteBytecodes) {
1856     FLAG_SET_DEFAULT(RewriteFrequentPairs, false);
1857   }
1858 }
1859 
1860 // Aggressive optimization flags  -XX:+AggressiveOpts
1861 void Arguments::set_aggressive_opts_flags() {
1862 #ifdef COMPILER2
1863   if (AggressiveUnboxing) {


2012                 "please refer to the release notes for the combinations "
2013                 "allowed\n");
2014     return false;
2015   }
2016 
2017   if (UseConcMarkSweepGC && !UseParNewGC) {
2018     jio_fprintf(defaultStream::error_stream(),
2019         "It is not possible to combine the DefNew young collector with the CMS collector.\n");
2020     return false;
2021   }
2022 
2023   if (UseParNewGC && !UseConcMarkSweepGC) {
2024     jio_fprintf(defaultStream::error_stream(),
2025         "It is not possible to combine the ParNew young collector with any collector other than CMS.\n");
2026     return false;
2027   }
2028 
2029   return true;
2030 }
2031 
2032 void Arguments::check_deprecated_gc_flags() {
2033   if (FLAG_IS_CMDLINE(UseParNewGC)) {
2034     warning("The UseParNewGC flag is deprecated and will likely be removed in a future release");
2035   }
2036   if (FLAG_IS_CMDLINE(MaxGCMinorPauseMillis)) {
2037     warning("Using MaxGCMinorPauseMillis as minor pause goal is deprecated"
2038             "and will likely be removed in future release");
2039   }
2040   if (FLAG_IS_CMDLINE(DefaultMaxRAMFraction)) {
2041     warning("DefaultMaxRAMFraction is deprecated and will likely be removed in a future release. "
2042         "Use MaxRAMFraction instead.");
2043   }
2044 }
2045 
2046 // Check the consistency of vm_init_args
2047 bool Arguments::check_vm_args_consistency() {
2048   // Method for adding checks for flag consistency.
2049   // The intent is to warn the user of all possible conflicts,
2050   // before returning an error.
2051   // Note: Needs platform-dependent factoring.
2052   bool status = true;
2053 
2054   if (TLABRefillWasteFraction == 0) {
2055     jio_fprintf(defaultStream::error_stream(),
2056                 "TLABRefillWasteFraction should be a denominator, "
2057                 "not " SIZE_FORMAT "\n",
2058                 TLABRefillWasteFraction);
2059     status = false;
2060   }
2061 
2062   if (FullGCALot && FLAG_IS_DEFAULT(MarkSweepAlwaysCompactCount)) {
2063     MarkSweepAlwaysCompactCount = 1;  // Move objects every gc.
2064   }
2065 


2561       ArgsRange errcode = parse_memory_size(tail, &long_ThreadStackSize, 1000);
2562       if (errcode != arg_in_range) {
2563         jio_fprintf(defaultStream::error_stream(),
2564                     "Invalid thread stack size: %s\n", option->optionString);
2565         describe_range_error(errcode);
2566         return JNI_EINVAL;
2567       }
2568       // Internally track ThreadStackSize in units of 1024 bytes.
2569       if (FLAG_SET_CMDLINE(intx, ThreadStackSize,
2570                        round_to((int)long_ThreadStackSize, K) / K) != Flag::SUCCESS) {
2571         return JNI_EINVAL;
2572       }
2573     // -Xoss, -Xsqnopause, -Xoptimize, -Xboundthreads
2574     } else if (match_option(option, "-Xoss", &tail) ||
2575                match_option(option, "-Xsqnopause") ||
2576                match_option(option, "-Xoptimize") ||
2577                match_option(option, "-Xboundthreads")) {
2578       // All these options are deprecated in JDK 9 and will be removed in a future release
2579       char version[256];
2580       JDK_Version::jdk(9).to_string(version, sizeof(version));
2581       warning("ignoring option %s; support was removed in %s", option->optionString, version);
2582     } else if (match_option(option, "-XX:CodeCacheExpansionSize=", &tail)) {
2583       julong long_CodeCacheExpansionSize = 0;
2584       ArgsRange errcode = parse_memory_size(tail, &long_CodeCacheExpansionSize, os::vm_page_size());
2585       if (errcode != arg_in_range) {
2586         jio_fprintf(defaultStream::error_stream(),
2587                    "Invalid argument: %s. Must be at least %luK.\n", option->optionString,
2588                    os::vm_page_size()/K);
2589         return JNI_EINVAL;
2590       }
2591       if (FLAG_SET_CMDLINE(uintx, CodeCacheExpansionSize, (uintx)long_CodeCacheExpansionSize) != Flag::SUCCESS) {
2592         return JNI_EINVAL;
2593       }
2594     } else if (match_option(option, "-Xmaxjitcodesize", &tail) ||
2595                match_option(option, "-XX:ReservedCodeCacheSize=", &tail)) {
2596       julong long_ReservedCodeCacheSize = 0;
2597 
2598       ArgsRange errcode = parse_memory_size(tail, &long_ReservedCodeCacheSize, 1);
2599       if (errcode != arg_in_range) {
2600         jio_fprintf(defaultStream::error_stream(),
2601                     "Invalid maximum code cache size: %s.\n", option->optionString);


2828     // JNI hooks
2829     } else if (match_option(option, "-Xcheck", &tail)) {
2830       if (!strcmp(tail, ":jni")) {
2831 #if !INCLUDE_JNI_CHECK
2832         warning("JNI CHECKING is not supported in this VM");
2833 #else
2834         CheckJNICalls = true;
2835 #endif // INCLUDE_JNI_CHECK
2836       } else if (is_bad_option(option, args->ignoreUnrecognized,
2837                                      "check")) {
2838         return JNI_EINVAL;
2839       }
2840     } else if (match_option(option, "vfprintf")) {
2841       _vfprintf_hook = CAST_TO_FN_PTR(vfprintf_hook_t, option->extraInfo);
2842     } else if (match_option(option, "exit")) {
2843       _exit_hook = CAST_TO_FN_PTR(exit_hook_t, option->extraInfo);
2844     } else if (match_option(option, "abort")) {
2845       _abort_hook = CAST_TO_FN_PTR(abort_hook_t, option->extraInfo);
2846     // -XX:+AggressiveHeap
2847     } else if (match_option(option, "-XX:+AggressiveHeap")) {
2848 
2849       // This option inspects the machine and attempts to set various
2850       // parameters to be optimal for long-running, memory allocation
2851       // intensive jobs.  It is intended for machines with large
2852       // amounts of cpu and memory.
2853 
2854       // initHeapSize is needed since _initial_heap_size is 4 bytes on a 32 bit
2855       // VM, but we may not be able to represent the total physical memory
2856       // available (like having 8gb of memory on a box but using a 32bit VM).
2857       // Thus, we need to make sure we're using a julong for intermediate
2858       // calculations.
2859       julong initHeapSize;
2860       julong total_memory = os::physical_memory();
2861 
2862       if (total_memory < (julong)256*M) {
2863         jio_fprintf(defaultStream::error_stream(),
2864                     "You need at least 256mb of memory to use -XX:+AggressiveHeap\n");
2865         vm_exit(1);
2866       }
2867 
2868       // The heap size is half of available memory, or (at most)
2869       // all of possible memory less 160mb (leaving room for the OS
2870       // when using ISM).  This is the maximum; because adaptive sizing
2871       // is turned on below, the actual space used may be smaller.
2872 
2873       initHeapSize = MIN2(total_memory / (julong)2,
2874                           total_memory - (julong)160*M);
2875 
2876       initHeapSize = limit_by_allocatable_memory(initHeapSize);
2877 
2878       if (FLAG_IS_DEFAULT(MaxHeapSize)) {
2879          if (FLAG_SET_CMDLINE(size_t, MaxHeapSize, initHeapSize) != Flag::SUCCESS) {
2880            return JNI_EINVAL;
2881          }
2882          if (FLAG_SET_CMDLINE(size_t, InitialHeapSize, initHeapSize) != Flag::SUCCESS) {
2883            return JNI_EINVAL;
2884          }
2885          // Currently the minimum size and the initial heap sizes are the same.
2886          set_min_heap_size(initHeapSize);
2887       }
2888       if (FLAG_IS_DEFAULT(NewSize)) {
2889          // Make the young generation 3/8ths of the total heap.
2890          if (FLAG_SET_CMDLINE(size_t, NewSize,
2891                                 ((julong)MaxHeapSize / (julong)8) * (julong)3) != Flag::SUCCESS) {
2892            return JNI_EINVAL;
2893          }
2894          if (FLAG_SET_CMDLINE(size_t, MaxNewSize, NewSize) != Flag::SUCCESS) {
2895            return JNI_EINVAL;
2896          }
2897       }
2898 
2899 #if !defined(_ALLBSD_SOURCE) && !defined(AIX)  // UseLargePages is not yet supported on BSD and AIX.
2900       FLAG_SET_DEFAULT(UseLargePages, true);
2901 #endif
2902 
2903       // Increase some data structure sizes for efficiency
2904       if (FLAG_SET_CMDLINE(size_t, BaseFootPrintEstimate, MaxHeapSize) != Flag::SUCCESS) {
2905         return JNI_EINVAL;
2906       }
2907       if (FLAG_SET_CMDLINE(bool, ResizeTLAB, false) != Flag::SUCCESS) {
2908         return JNI_EINVAL;
2909       }
2910       if (FLAG_SET_CMDLINE(size_t, TLABSize, 256*K) != Flag::SUCCESS) {
2911         return JNI_EINVAL;
2912       }
2913 
2914       // See the OldPLABSize comment below, but replace 'after promotion'
2915       // with 'after copying'.  YoungPLABSize is the size of the survivor
2916       // space per-gc-thread buffers.  The default is 4kw.
2917       if (FLAG_SET_CMDLINE(size_t, YoungPLABSize, 256*K) != Flag::SUCCESS) {      // Note: this is in words
2918         return JNI_EINVAL;
2919       }
2920 
2921       // OldPLABSize is the size of the buffers in the old gen that
2922       // UseParallelGC uses to promote live data that doesn't fit in the
2923       // survivor spaces.  At any given time, there's one for each gc thread.
2924       // The default size is 1kw. These buffers are rarely used, since the
2925       // survivor spaces are usually big enough.  For specjbb, however, there
2926       // are occasions when there's lots of live data in the young gen
2927       // and we end up promoting some of it.  We don't have a definite
2928       // explanation for why bumping OldPLABSize helps, but the theory
2929       // is that a bigger PLAB results in retaining something like the
2930       // original allocation order after promotion, which improves mutator
2931       // locality.  A minor effect may be that larger PLABs reduce the
2932       // number of PLAB allocation events during gc.  The value of 8kw
2933       // was arrived at by experimenting with specjbb.
2934       if (FLAG_SET_CMDLINE(size_t, OldPLABSize, 8*K) != Flag::SUCCESS) {  // Note: this is in words
2935         return JNI_EINVAL;
2936       }
2937 
2938       // Enable parallel GC and adaptive generation sizing
2939       if (FLAG_SET_CMDLINE(bool, UseParallelGC, true) != Flag::SUCCESS) {
2940         return JNI_EINVAL;
2941       }
2942       FLAG_SET_DEFAULT(ParallelGCThreads,
2943                        Abstract_VM_Version::parallel_worker_threads());
2944 
2945       // Encourage steady state memory management
2946       if (FLAG_SET_CMDLINE(uintx, ThresholdTolerance, 100) != Flag::SUCCESS) {
2947         return JNI_EINVAL;
2948       }
2949 
2950       // This appears to improve mutator locality
2951       if (FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false) != Flag::SUCCESS) {
2952         return JNI_EINVAL;
2953       }
2954 
2955       // Get around early Solaris scheduling bug
2956       // (affinity vs other jobs on system)
2957       // but disallow DR and offlining (5008695).
2958       if (FLAG_SET_CMDLINE(bool, BindGCTaskThreadsToCPUs, true) != Flag::SUCCESS) {
2959         return JNI_EINVAL;
2960       }
2961 
2962     // Need to keep consistency of MaxTenuringThreshold and AlwaysTenure/NeverTenure;
2963     // and the last option wins.
2964     } else if (match_option(option, "-XX:+NeverTenure")) {
2965       if (FLAG_SET_CMDLINE(bool, NeverTenure, true) != Flag::SUCCESS) {
2966         return JNI_EINVAL;
2967       }
2968       if (FLAG_SET_CMDLINE(bool, AlwaysTenure, false) != Flag::SUCCESS) {
2969         return JNI_EINVAL;
2970       }
2971       if (FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, markOopDesc::max_age + 1) != Flag::SUCCESS) {
2972         return JNI_EINVAL;
2973       }
2974     } else if (match_option(option, "-XX:+AlwaysTenure")) {
2975       if (FLAG_SET_CMDLINE(bool, NeverTenure, false) != Flag::SUCCESS) {
2976         return JNI_EINVAL;
2977       }
2978       if (FLAG_SET_CMDLINE(bool, AlwaysTenure, true) != Flag::SUCCESS) {
2979         return JNI_EINVAL;
2980       }
2981       if (FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, 0) != Flag::SUCCESS) {


3034         return JNI_EINVAL;
3035       }
3036       if (FLAG_SET_CMDLINE(bool, DTraceMonitorProbes, true) != Flag::SUCCESS) {
3037         return JNI_EINVAL;
3038       }
3039 #else // defined(DTRACE_ENABLED)
3040       jio_fprintf(defaultStream::error_stream(),
3041                   "ExtendedDTraceProbes flag is not applicable for this configuration\n");
3042       return JNI_EINVAL;
3043 #endif // defined(DTRACE_ENABLED)
3044 #ifdef ASSERT
3045     } else if (match_option(option, "-XX:+FullGCALot")) {
3046       if (FLAG_SET_CMDLINE(bool, FullGCALot, true) != Flag::SUCCESS) {
3047         return JNI_EINVAL;
3048       }
3049       // disable scavenge before parallel mark-compact
3050       if (FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false) != Flag::SUCCESS) {
3051         return JNI_EINVAL;
3052       }
3053 #endif
3054     } else if (match_option(option, "-XX:CMSMarkStackSize=", &tail) ||
3055                match_option(option, "-XX:G1MarkStackSize=", &tail)) {
3056       julong stack_size = 0;
3057       ArgsRange errcode = parse_memory_size(tail, &stack_size, 1);
3058       if (errcode != arg_in_range) {
3059         jio_fprintf(defaultStream::error_stream(),
3060                     "Invalid mark stack size: %s\n", option->optionString);
3061         describe_range_error(errcode);
3062         return JNI_EINVAL;
3063       }
3064       jio_fprintf(defaultStream::error_stream(),
3065         "Please use -XX:MarkStackSize in place of "
3066         "-XX:CMSMarkStackSize or -XX:G1MarkStackSize in the future\n");
3067       if (FLAG_SET_CMDLINE(size_t, MarkStackSize, stack_size) != Flag::SUCCESS) {
3068         return JNI_EINVAL;
3069       }
3070     } else if (match_option(option, "-XX:CMSMarkStackSizeMax=", &tail)) {
3071       julong max_stack_size = 0;
3072       ArgsRange errcode = parse_memory_size(tail, &max_stack_size, 1);
3073       if (errcode != arg_in_range) {
3074         jio_fprintf(defaultStream::error_stream(),
3075                     "Invalid maximum mark stack size: %s\n",
3076                     option->optionString);
3077         describe_range_error(errcode);
3078         return JNI_EINVAL;
3079       }
3080       jio_fprintf(defaultStream::error_stream(),
3081          "Please use -XX:MarkStackSizeMax in place of "
3082          "-XX:CMSMarkStackSizeMax in the future\n");
3083       if (FLAG_SET_CMDLINE(size_t, MarkStackSizeMax, max_stack_size) != Flag::SUCCESS) {
3084         return JNI_EINVAL;
3085       }
3086     } else if (match_option(option, "-XX:ParallelMarkingThreads=", &tail) ||
3087                match_option(option, "-XX:ParallelCMSThreads=", &tail)) {
3088       uintx conc_threads = 0;
3089       if (!parse_uintx(tail, &conc_threads, 1)) {
3090         jio_fprintf(defaultStream::error_stream(),
3091                     "Invalid concurrent threads: %s\n", option->optionString);
3092         return JNI_EINVAL;
3093       }
3094       jio_fprintf(defaultStream::error_stream(),
3095         "Please use -XX:ConcGCThreads in place of "
3096         "-XX:ParallelMarkingThreads or -XX:ParallelCMSThreads in the future\n");
3097       if (FLAG_SET_CMDLINE(uint, ConcGCThreads, conc_threads) != Flag::SUCCESS) {
3098         return JNI_EINVAL;
3099       }
3100     } else if (match_option(option, "-XX:MaxDirectMemorySize=", &tail)) {
3101       julong max_direct_memory_size = 0;
3102       ArgsRange errcode = parse_memory_size(tail, &max_direct_memory_size, 0);
3103       if (errcode != arg_in_range) {
3104         jio_fprintf(defaultStream::error_stream(),
3105                     "Invalid maximum direct memory size: %s\n",
3106                     option->optionString);
3107         describe_range_error(errcode);
3108         return JNI_EINVAL;
3109       }
3110       if (FLAG_SET_CMDLINE(size_t, MaxDirectMemorySize, max_direct_memory_size) != Flag::SUCCESS) {
3111         return JNI_EINVAL;
3112       }
3113 #if !INCLUDE_MANAGEMENT
3114     } else if (match_option(option, "-XX:+ManagementServer")) {
3115         jio_fprintf(defaultStream::error_stream(),
3116           "ManagementServer is not supported in this VM.\n");
3117         return JNI_ERR;
3118 #endif // INCLUDE_MANAGEMENT
3119     // CreateMinidumpOnCrash is removed, and replaced by CreateCoredumpOnCrash
3120     } else if (match_option(option, "-XX:+CreateMinidumpOnCrash")) {
3121       if (FLAG_SET_CMDLINE(bool, CreateCoredumpOnCrash, true) != Flag::SUCCESS) {
3122         return JNI_EINVAL;
3123       }
3124       jio_fprintf(defaultStream::output_stream(),
3125           "CreateMinidumpOnCrash is replaced by CreateCoredumpOnCrash: CreateCoredumpOnCrash is on\n");
3126     } else if (match_option(option, "-XX:-CreateMinidumpOnCrash")) {
3127       if (FLAG_SET_CMDLINE(bool, CreateCoredumpOnCrash, false) != Flag::SUCCESS) {
3128         return JNI_EINVAL;
3129       }
3130       jio_fprintf(defaultStream::output_stream(),
3131           "CreateMinidumpOnCrash is replaced by CreateCoredumpOnCrash: CreateCoredumpOnCrash is off\n");
3132     } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx
3133       // Skip -XX:Flags= since that case has already been handled
3134       if (strncmp(tail, "Flags=", strlen("Flags=")) != 0) {
3135         if (!process_argument(tail, args->ignoreUnrecognized, origin)) {
3136           return JNI_EINVAL;
3137         }
3138       }
3139     // Unknown option
3140     } else if (is_bad_option(option, args->ignoreUnrecognized)) {
3141       return JNI_ERR;
3142     }
3143   }
3144 
3145   // PrintSharedArchiveAndExit will turn on
3146   //   -Xshare:on
3147   //   -XX:+TraceClassPaths
3148   if (PrintSharedArchiveAndExit) {
3149     if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, true) != Flag::SUCCESS) {
3150       return JNI_EINVAL;
3151     }


3490     }
3491     if (*rd != 0) {
3492       // In this case, the assignment to wrt below will make *rd nul,
3493       // which will interfere with the next loop iteration.
3494       rd++;
3495     }
3496     *wrt = 0;                               // Zero terminate option
3497   }
3498 
3499   // Fill out JavaVMInitArgs structure.
3500   jint status = vm_args->set_args(options);
3501 
3502   delete options;
3503   os::free(buffer);
3504   return status;
3505 }
3506 
3507 void Arguments::set_shared_spaces_flags() {
3508   if (DumpSharedSpaces) {
3509     if (RequireSharedSpaces) {
3510       warning("cannot dump shared archive while using shared archive");
3511     }
3512     UseSharedSpaces = false;
3513 #ifdef _LP64
3514     if (!UseCompressedOops || !UseCompressedClassPointers) {
3515       vm_exit_during_initialization(
3516         "Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off.", NULL);
3517     }
3518   } else {
3519     if (!UseCompressedOops || !UseCompressedClassPointers) {
3520       no_shared_spaces("UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces.");
3521     }
3522 #endif
3523   }
3524 }
3525 
3526 #if !INCLUDE_ALL_GCS
3527 static void force_serial_gc() {
3528   FLAG_SET_DEFAULT(UseSerialGC, true);
3529   UNSUPPORTED_GC_OPTION(UseG1GC);
3530   UNSUPPORTED_GC_OPTION(UseParallelGC);


3648       vm_exit(0);
3649     }
3650 #endif
3651   }
3652   return JNI_OK;
3653 }
3654 
3655 static void print_options(const JavaVMInitArgs *args) {
3656   const char* tail;
3657   for (int index = 0; index < args->nOptions; index++) {
3658     const JavaVMOption *option = args->options + index;
3659     if (match_option(option, "-XX:", &tail)) {
3660       logOption(tail);
3661     }
3662   }
3663 }
3664 
3665 // Parse entry point called from JNI_CreateJavaVM
3666 
3667 jint Arguments::parse(const JavaVMInitArgs* args) {

3668 
3669   // Initialize ranges and constraints
3670   CommandLineFlagRangeList::init();
3671   CommandLineFlagConstraintList::init();
3672 
3673   // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed.
3674   const char* hotspotrc = ".hotspotrc";
3675   char* flags_file = NULL;
3676   bool settings_file_specified = false;
3677   bool needs_hotspotrc_warning = false;
3678   ScopedVMInitArgs java_tool_options_args;
3679   ScopedVMInitArgs java_options_args;
3680 
3681   jint code =
3682       parse_java_tool_options_environment_variable(&java_tool_options_args);
3683   if (code != JNI_OK) {
3684     return code;
3685   }
3686 
3687   code = parse_java_options_environment_variable(&java_options_args);


3769 #if defined(_ALLBSD_SOURCE) || defined(AIX)  // UseLargePages is not yet supported on BSD and AIX.
3770   UNSUPPORTED_OPTION(UseLargePages, "-XX:+UseLargePages");
3771 #endif
3772 
3773   ArgumentsExt::report_unsupported_options();
3774 
3775 #ifndef PRODUCT
3776   if (TraceBytecodesAt != 0) {
3777     TraceBytecodes = true;
3778   }
3779   if (CountCompiledCalls) {
3780     if (UseCounterDecay) {
3781       warning("UseCounterDecay disabled because CountCalls is set");
3782       UseCounterDecay = false;
3783     }
3784   }
3785 #endif // PRODUCT
3786 
3787   if (ScavengeRootsInCode == 0) {
3788     if (!FLAG_IS_DEFAULT(ScavengeRootsInCode)) {
3789       warning("forcing ScavengeRootsInCode non-zero");
3790     }
3791     ScavengeRootsInCode = 1;
3792   }
3793 
3794   if (PrintGCDetails) {
3795     // Turn on -verbose:gc options as well
3796     PrintGC = true;
3797   }
3798 
3799   // Set object alignment values.
3800   set_object_alignment();
3801 
3802 #if !INCLUDE_ALL_GCS
3803   force_serial_gc();
3804 #endif // INCLUDE_ALL_GCS
3805 #if !INCLUDE_CDS
3806   if (DumpSharedSpaces || RequireSharedSpaces) {
3807     jio_fprintf(defaultStream::error_stream(),
3808       "Shared spaces are not supported in this VM\n");
3809     return JNI_ERR;




 102 AgentLibraryList Arguments::_libraryList;
 103 AgentLibraryList Arguments::_agentList;
 104 
 105 abort_hook_t     Arguments::_abort_hook         = NULL;
 106 exit_hook_t      Arguments::_exit_hook          = NULL;
 107 vfprintf_hook_t  Arguments::_vfprintf_hook      = NULL;
 108 
 109 
 110 SystemProperty *Arguments::_sun_boot_library_path = NULL;
 111 SystemProperty *Arguments::_java_library_path = NULL;
 112 SystemProperty *Arguments::_java_home = NULL;
 113 SystemProperty *Arguments::_java_class_path = NULL;
 114 SystemProperty *Arguments::_sun_boot_class_path = NULL;
 115 
 116 char* Arguments::_ext_dirs = NULL;
 117 
 118 // Check if head of 'option' matches 'name', and sets 'tail' to the remaining
 119 // part of the option string.
 120 static bool match_option(const JavaVMOption *option, const char* name,
 121                          const char** tail) {
 122   size_t len = strlen(name);
 123   if (strncmp(option->optionString, name, len) == 0) {
 124     *tail = option->optionString + len;
 125     return true;
 126   } else {
 127     return false;
 128   }
 129 }
 130 
 131 // Check if 'option' matches 'name'. No "tail" is allowed.
 132 static bool match_option(const JavaVMOption *option, const char* name) {
 133   const char* tail = NULL;
 134   bool result = match_option(option, name, &tail);
 135   if (tail != NULL && *tail == '\0') {
 136     return result;
 137   } else {
 138     return false;
 139   }
 140 }
 141 
 142 // Return true if any of the strings in null-terminated array 'names' matches.


 203   _java_home =  new SystemProperty("java.home", NULL,  true);
 204   _sun_boot_class_path = new SystemProperty("sun.boot.class.path", NULL,  true);
 205 
 206   _java_class_path = new SystemProperty("java.class.path", "",  true);
 207 
 208   // Add to System Property list.
 209   PropertyList_add(&_system_properties, _sun_boot_library_path);
 210   PropertyList_add(&_system_properties, _java_library_path);
 211   PropertyList_add(&_system_properties, _java_home);
 212   PropertyList_add(&_system_properties, _java_class_path);
 213   PropertyList_add(&_system_properties, _sun_boot_class_path);
 214 
 215   // Set OS specific system properties values
 216   os::init_system_properties_values();
 217 }
 218 
 219 // Update/Initialize System properties after JDK version number is known
 220 void Arguments::init_version_specific_system_properties() {
 221   enum { bufsz = 16 };
 222   char buffer[bufsz];
 223   const char* spec_vendor = "Oracle Corporation";
 224   uint32_t spec_version = JDK_Version::current().major_version();
 225 


 226   jio_snprintf(buffer, bufsz, "1." UINT32_FORMAT, spec_version);
 227 
 228   PropertyList_add(&_system_properties,
 229       new SystemProperty("java.vm.specification.vendor",  spec_vendor, false));
 230   PropertyList_add(&_system_properties,
 231       new SystemProperty("java.vm.specification.version", buffer, false));
 232   PropertyList_add(&_system_properties,
 233       new SystemProperty("java.vm.vendor", VM_Version::vm_vendor(),  false));
 234 }
 235 
 236 /*
 237  *  -XX argument processing:
 238  *
 239  *  -XX arguments are defined in several places, such as:
 240  *      globals.hpp, globals_<cpu>.hpp, globals_<os>.hpp, <compiler>_globals.hpp, or <gc>_globals.hpp.
 241  *  -XX arguments are parsed in parse_argument().
 242  *  -XX argument bounds checking is done in check_vm_args_consistency().
 243  *
 244  * Over time -XX arguments may change. There are mechanisms to handle common cases:
 245  *
 246  *      ALIASED: An option that is simply another name for another option. This is often
 247  *               part of the process of deprecating a flag, but not all aliases need
 248  *               to be deprecated.
 249  *
 250  *               Create an alias for an option by adding the old and new option names to the
 251  *               "aliased_jvm_flags" table. Delete the old variable from globals.hpp (etc).
 252  *
 253  *   DEPRECATED: An option that is supported, but a warning is printed to let the user know that
 254  *               support may be removed in the future. Both regular and aliased options may be
 255  *               deprecated.
 256  *
 257  *               Add a deprecation warning for an option (or alias) by adding an entry in the
 258  *               "special_jvm_flags" table and setting the "deprecated_in" field.
 259  *               Often an option "deprecated" in one major release will
 260  *               be made "obsolete" in the next. In this case the entry should also have it's
 261  *               "obsolete_in" field set.
 262  *
 263  *     OBSOLETE: An option that has been removed (and deleted from globals.hpp), but is still accepted
 264  *               on the command line. A warning is printed to let the user know that option might not
 265  *               be accepted in the future.
 266  *
 267  *               Add an obsolete warning for an option by adding an entry in the "special_jvm_flags"
 268  *               table and setting the "obsolete_in" field.
 269  *
 270  *      EXPIRED: A deprecated or obsolete option that has an "accept_until" version less than or equal
 271  *               to the current JDK version. The system will flatly refuse to admit the existence of
 272  *               the flag. This allows a flag to die automatically over JDK releases.
 273  *
 274  *               Note that manual cleanup of expired options should be done at major JDK version upgrades:
 275  *                  - Newly expired options should be removed from the special_jvm_flags and aliased_jvm_flags tables.
 276  *                  - Newly obsolete or expired deprecated options should have their global variable
 277  *                    definitions removed (from globals.hpp, etc) and related implementations removed.
 278  *
 279  * Recommended approach for removing options:
 280  *
 281  * To remove options commonly used by customers (e.g. product, commercial -XX options), use
 282  * the 3-step model adding major release numbers to the deprecate, obsolete and expire columns.
 283  *
 284  * To remove internal options (e.g. diagnostic, experimental, develop options), use
 285  * a 2-step model adding major release numbers to the obsolete and expire columns.
 286  *
 287  * To change the name of an option, use the alias table as well as a 2-step
 288  * model adding major release numbers to the deprecate and expire columns.
 289  * Think twice about aliasing commonly used customer options.
 290  *
 291  * There are times when it is appropriate to leave a future release number as undefined.
 292  *
 293  * Tests:  Aliases should be tested in VMAliasOptions.java.
 294  *         Deprecated options should be tested in VMDeprecatedOptions.java.
 295  */
 296 
 297 // Obsolete or deprecated -XX flag.
 298 typedef struct {
 299   const char* name;
 300   JDK_Version deprecated_in; // When the deprecation warning started (or "undefined").
 301   JDK_Version obsolete_in;   // When the obsolete warning started (or "undefined").
 302   JDK_Version expired_in;    // When the option expires (or "undefined").
 303 } SpecialFlag;
 304 
 305 // The special_jvm_flags table declares options that are being deprecated and/or obsoleted. The
 306 // "deprecated_in" or "obsolete_in" fields may be set to "undefined", but not both.
 307 // When the JDK version reaches 'deprecated_in' limit, the JVM will process this flag on
 308 // the command-line as usual, but will issue a warning.
 309 // When the JDK version reaches 'obsolete_in' limit, the JVM will continue accepting this flag on
 310 // the command-line, while issuing a warning and ignoring the flag value.
 311 // Once the JDK version reaches 'expired_in' limit, the JVM will flatly refuse to admit the
 312 // existence of the flag.
 313 //
 314 // MANUAL CLEANUP ON JDK VERSION UPDATES:
 315 // This table ensures that the handling of options will update automatically when the JDK
 316 // version is incremented, but the source code needs to be cleanup up manually:
 317 // - As "deprecated" options age into "obsolete" or "expired" options, the associated "globals"
 318 //   variable should be removed, as well as users of the variable.
 319 // - As "deprecated" options age into "obsolete" options, move the entry into the
 320 //   "Obsolete Flags" section of the table.
 321 // - All expired options should be removed from the table.
 322 static SpecialFlag const special_jvm_flags[] = {
 323 #ifdef TEST_VERIFY_SPECIAL_JVM_FLAGS
 324   { "dep > obs",                    JDK_Version::jdk(9), JDK_Version::jdk(8), JDK_Version::undefined() },
 325   { "dep > exp ",                   JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(8) },
 326   { "obs > exp ",                   JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(8) },
 327   { "not deprecated or obsolete",   JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::undefined() },
 328   { "dup option",                   JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::undefined() },
 329   { "dup option",                   JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::undefined() },
 330   { "BytecodeVerificationRemote",   JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::undefined() },
 331 #endif
 332 
 333   // -------------- Deprecated Flags --------------
 334   // --- Non-alias flags - sorted by obsolete_in then expired_in:
 335   { "MaxGCMinorPauseMillis",        JDK_Version::jdk(8), JDK_Version::undefined(), JDK_Version::undefined() },
 336   { "UseParNewGC",                  JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
 337 
 338   // --- Deprecated alias flags (see also aliased_jvm_flags) - sorted by obsolete_in then expired_in:
 339   { "DefaultMaxRAMFraction",        JDK_Version::jdk(8), JDK_Version::undefined(), JDK_Version::undefined() },
 340   { "CreateMinidumpOnCrash",        JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::undefined() },
 341   { "CMSMarkStackSizeMax",          JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
 342   { "CMSMarkStackSize",             JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
 343   { "G1MarkStackSize",              JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
 344   { "ParallelMarkingThreads",       JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
 345   { "ParallelCMSThreads",           JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
 346 
 347   // -------------- Obsolete Flags - sorted by expired_in --------------
 348   { "UseOldInlining",                JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 349   { "SafepointPollOffset",           JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 350   { "UseBoundThreads",               JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 351   { "DefaultThreadPriority",         JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 352   { "NoYieldsInMicrolock",           JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 353   { "BackEdgeThreshold",             JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 354   { "UseNewReflection",              JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 355   { "ReflectionWrapResolutionErrors",JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 356   { "VerifyReflectionBytecodes",     JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 357   { "AutoShutdownNMT",               JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 358   { "NmethodSweepFraction",          JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 359   { "NmethodSweepCheckInterval",     JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 360   { "CodeCacheMinimumFreeSpace",     JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 361 #ifndef ZERO
 362   { "UseFastAccessorMethods",        JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 363   { "UseFastEmptyMethods",           JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 364 #endif // ZERO
 365   { "UseCompilerSafepoints",         JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 366   { "AdaptiveSizePausePolicy",       JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 367   { "ParallelGCRetainPLAB",          JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 368   { "ThreadSafetyMargin",            JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 369   { "LazyBootClassLoader",           JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 370   { "StarvationMonitorInterval",     JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 371   { "PreInflateSpin",                JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(10) },
 372   { NULL, JDK_Version(0), JDK_Version(0) }
 373 };
 374 
 375 // Flags that are aliases for other flags.
 376 typedef struct {
 377   const char* alias_name;
 378   const char* real_name;
 379 } AliasedFlag;
 380 
 381 static AliasedFlag const aliased_jvm_flags[] = {
 382   { "DefaultMaxRAMFraction",    "MaxRAMFraction"    },
 383   { "CMSMarkStackSizeMax",      "MarkStackSizeMax"  },
 384   { "CMSMarkStackSize",         "MarkStackSize"     },
 385   { "G1MarkStackSize",          "MarkStackSize"     },
 386   { "ParallelMarkingThreads",   "ConcGCThreads"     },
 387   { "ParallelCMSThreads",       "ConcGCThreads"     },
 388   { "CreateMinidumpOnCrash",    "CreateCoredumpOnCrash" },
 389   { NULL, NULL}
 390 };
 391 
 392 // Return true if "v" is less than "other", where "other" may be "undefined".
 393 static bool version_less_than(JDK_Version v, JDK_Version other) {
 394   assert(!v.is_undefined(), "must be defined");
 395   if (!other.is_undefined() && v.compare(other) >= 0) {
 396     return false;
 397   } else {
 398     return true;
 399   }
 400 }
 401 
 402 static bool lookup_special_flag(const char *flag_name, SpecialFlag& flag) {
 403   for (size_t i = 0; special_jvm_flags[i].name != NULL; i++) {
 404     if ((strcmp(special_jvm_flags[i].name, flag_name) == 0)) {
 405       flag = special_jvm_flags[i];
 406       return true;
 407     }
 408   }
 409   return false;
 410 }
 411 
 412 bool Arguments::is_obsolete_flag(const char *flag_name, JDK_Version* version) {
 413   assert(version != NULL, "Must provide a version buffer");
 414   SpecialFlag flag;
 415   if (lookup_special_flag(flag_name, flag)) {
 416     if (!flag.obsolete_in.is_undefined()) {
 417       if (version_less_than(JDK_Version::current(), flag.expired_in)) {
 418         *version = flag.obsolete_in;




 419         return true;
 420       }
 421     }

 422   }
 423   return false;
 424 }
 425 
 426 int Arguments::is_deprecated_flag(const char *flag_name, JDK_Version* version) {
 427   assert(version != NULL, "Must provide a version buffer");
 428   SpecialFlag flag;
 429   if (lookup_special_flag(flag_name, flag)) {
 430     if (!flag.deprecated_in.is_undefined()) {
 431       if (version_less_than(JDK_Version::current(), flag.obsolete_in) &&
 432           version_less_than(JDK_Version::current(), flag.expired_in)) {
 433         *version = flag.deprecated_in;
 434         return 1;
 435       } else {
 436         return -1;
 437       }
 438     }
 439   }
 440   return 0;
 441 }
 442 
 443 const char* Arguments::real_flag_name(const char *flag_name) {
 444   for (size_t i = 0; aliased_jvm_flags[i].alias_name != NULL; i++) {
 445     const AliasedFlag& flag_status = aliased_jvm_flags[i];
 446     if (strcmp(flag_status.alias_name, flag_name) == 0) {
 447         return flag_status.real_name;
 448     }
 449   }
 450   return flag_name;
 451 }
 452 
 453 #ifndef PRODUCT
 454 static bool lookup_special_flag(const char *flag_name, size_t skip_index) {
 455   for (size_t i = 0; special_jvm_flags[i].name != NULL; i++) {
 456     if ((i != skip_index) && (strcmp(special_jvm_flags[i].name, flag_name) == 0)) {
 457       return true;
 458     }
 459   }
 460   return false;
 461 }
 462 
 463 static bool verify_special_jvm_flags() {
 464   bool success = true;
 465   for (size_t i = 0; special_jvm_flags[i].name != NULL; i++) {
 466     const SpecialFlag& flag = special_jvm_flags[i];
 467     if (lookup_special_flag(flag.name, i)) {
 468       warning("Duplicate special flag declaration \"%s\"", flag.name);
 469       success = false;
 470     }
 471     if (flag.deprecated_in.is_undefined() &&
 472         flag.obsolete_in.is_undefined()) {
 473       warning("Special flag entry \"%s\" must declare version deprecated and/or obsoleted in.", flag.name);
 474       success = false;
 475     }
 476 
 477     if (!flag.deprecated_in.is_undefined()) {
 478       if (!version_less_than(flag.deprecated_in, flag.obsolete_in)) {
 479         warning("Special flag entry \"%s\" must be deprecated before obsoleted.", flag.name);
 480         success = false;
 481       }
 482 
 483       if (!version_less_than(flag.deprecated_in, flag.expired_in)) {
 484         warning("Special flag entry \"%s\" must be deprecated before expired.", flag.name);
 485         success = false;
 486       }
 487     }
 488 
 489     if (!flag.obsolete_in.is_undefined()) {
 490       if (!version_less_than(flag.obsolete_in, flag.expired_in)) {
 491         warning("Special flag entry \"%s\" must be obsoleted before expired.", flag.name);
 492         success = false;
 493       }
 494 
 495       // if flag has become obsolete it should not have a "globals" flag defined anymore.
 496       if (!version_less_than(JDK_Version::current(), flag.obsolete_in)) {
 497         if (Flag::find_flag(flag.name) != NULL) {
 498           warning("Global variable for obsolete special flag entry \"%s\" should be removed", flag.name);
 499           success = false;
 500         }
 501       }
 502     }
 503 
 504     if (!flag.expired_in.is_undefined()) {
 505       // if flag has become expired it should not have a "globals" flag defined anymore.
 506       if (!version_less_than(JDK_Version::current(), flag.expired_in)) {
 507         if (Flag::find_flag(flag.name) != NULL) {
 508           warning("Global variable for expired flag entry \"%s\" should be removed", flag.name);
 509           success = false;
 510         }
 511       }
 512     }
 513 
 514   }
 515   return success;
 516 }
 517 #endif
 518 
 519 // Constructs the system class path (aka boot class path) from the following
 520 // components, in order:
 521 //
 522 //     prefix           // from -Xbootclasspath/p:...
 523 //     base             // from os::get_system_properties() or -Xbootclasspath=
 524 //     suffix           // from -Xbootclasspath/a:...
 525 //
 526 // This could be AllStatic, but it isn't needed after argument processing is
 527 // complete.
 528 class SysClassPath: public StackObj {
 529 public:
 530   SysClassPath(const char* base);
 531   ~SysClassPath();
 532 
 533   inline void set_base(const char* base);
 534   inline void add_prefix(const char* prefix);
 535   inline void add_suffix_to_prefix(const char* suffix);
 536   inline void add_suffix(const char* suffix);
 537   inline void reset_path(const char* base);
 538 


 767 }
 768 
 769 // Describe an argument out of range error
 770 void Arguments::describe_range_error(ArgsRange errcode) {
 771   switch(errcode) {
 772   case arg_too_big:
 773     jio_fprintf(defaultStream::error_stream(),
 774                 "The specified size exceeds the maximum "
 775                 "representable size.\n");
 776     break;
 777   case arg_too_small:
 778   case arg_unreadable:
 779   case arg_in_range:
 780     // do nothing for now
 781     break;
 782   default:
 783     ShouldNotReachHere();
 784   }
 785 }
 786 
 787 static bool set_bool_flag(const char* name, bool value, Flag::Flags origin) {
 788   if (CommandLineFlags::boolAtPut(name, &value, origin) == Flag::SUCCESS) {
 789     return true;
 790   } else {
 791     return false;
 792   }
 793 }
 794 
 795 static bool set_fp_numeric_flag(const char* name, char* value, Flag::Flags origin) {
 796   double v;
 797   if (sscanf(value, "%lf", &v) != 1) {
 798     return false;
 799   }
 800 
 801   if (CommandLineFlags::doubleAtPut(name, &v, origin) == Flag::SUCCESS) {
 802     return true;
 803   }
 804   return false;
 805 }
 806 
 807 static bool set_numeric_flag(const char* name, char* value, Flag::Flags origin) {
 808   julong v;
 809   int int_v;
 810   intx intx_v;
 811   bool is_neg = false;
 812   // Check the sign first since atomull() parses only unsigned values.
 813   if (*value == '-') {
 814     if ((CommandLineFlags::intxAt(name, &intx_v) != Flag::SUCCESS) && (CommandLineFlags::intAt(name, &int_v) != Flag::SUCCESS)) {
 815       return false;
 816     }
 817     value++;
 818     is_neg = true;
 819   }
 820   if (!atomull(value, &v)) {
 821     return false;
 822   }
 823   int_v = (int) v;
 824   if (is_neg) {
 825     int_v = -int_v;
 826   }
 827   if (CommandLineFlags::intAtPut(name, &int_v, origin) == Flag::SUCCESS) {


 836     intx_v = -intx_v;
 837   }
 838   if (CommandLineFlags::intxAtPut(name, &intx_v, origin) == Flag::SUCCESS) {
 839     return true;
 840   }
 841   uintx uintx_v = (uintx) v;
 842   if (!is_neg && (CommandLineFlags::uintxAtPut(name, &uintx_v, origin) == Flag::SUCCESS)) {
 843     return true;
 844   }
 845   uint64_t uint64_t_v = (uint64_t) v;
 846   if (!is_neg && (CommandLineFlags::uint64_tAtPut(name, &uint64_t_v, origin) == Flag::SUCCESS)) {
 847     return true;
 848   }
 849   size_t size_t_v = (size_t) v;
 850   if (!is_neg && (CommandLineFlags::size_tAtPut(name, &size_t_v, origin) == Flag::SUCCESS)) {
 851     return true;
 852   }
 853   return false;
 854 }
 855 
 856 static bool set_string_flag(const char* name, const char* value, Flag::Flags origin) {
 857   if (CommandLineFlags::ccstrAtPut(name, &value, origin) != Flag::SUCCESS) return false;
 858   // Contract:  CommandLineFlags always returns a pointer that needs freeing.
 859   FREE_C_HEAP_ARRAY(char, value);
 860   return true;
 861 }
 862 
 863 static bool append_to_string_flag(const char* name, const char* new_value, Flag::Flags origin) {
 864   const char* old_value = "";
 865   if (CommandLineFlags::ccstrAt(name, &old_value) != Flag::SUCCESS) return false;
 866   size_t old_len = old_value != NULL ? strlen(old_value) : 0;
 867   size_t new_len = strlen(new_value);
 868   const char* value;
 869   char* free_this_too = NULL;
 870   if (old_len == 0) {
 871     value = new_value;
 872   } else if (new_len == 0) {
 873     value = old_value;
 874   } else {
 875     char* buf = NEW_C_HEAP_ARRAY(char, old_len + 1 + new_len + 1, mtInternal);
 876     // each new setting adds another LINE to the switch:
 877     sprintf(buf, "%s\n%s", old_value, new_value);
 878     value = buf;
 879     free_this_too = buf;
 880   }
 881   (void) CommandLineFlags::ccstrAtPut(name, &value, origin);
 882   // CommandLineFlags always returns a pointer that needs freeing.
 883   FREE_C_HEAP_ARRAY(char, value);
 884   if (free_this_too != NULL) {
 885     // CommandLineFlags made its own copy, so I must delete my own temp. buffer.
 886     FREE_C_HEAP_ARRAY(char, free_this_too);
 887   }
 888   return true;
 889 }
 890 
 891 const char* Arguments::handle_aliases_and_deprecation(const char* arg, bool warn) {
 892   const char* real_name = real_flag_name(arg);
 893   JDK_Version since = JDK_Version();
 894   switch (is_deprecated_flag(arg, &since)) {
 895     case -1:
 896       return NULL; // obsolete or expired, don't process normally
 897     case 0:
 898       return real_name;
 899     case 1: {
 900       if (warn) {
 901         char version[256];
 902         since.to_string(version, sizeof(version));
 903         if (real_name != arg) {
 904           warning("Option %s was deprecated in version %s and will likely be removed in a future release. Use option %s instead.",
 905                   arg, version, real_name);
 906         } else {
 907           warning("Option %s was deprecated in version %s and will likely be removed in a future release.",
 908                   arg, version);
 909         }
 910       }
 911       return real_name;
 912     }
 913   }
 914   ShouldNotReachHere();
 915   return NULL;
 916 }
 917 
 918 bool Arguments::parse_argument(const char* arg, Flag::Flags origin) {
 919 
 920   // range of acceptable characters spelled out for portability reasons
 921 #define NAME_RANGE  "[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]"
 922 #define BUFLEN 255
 923   char name[BUFLEN+1];
 924   char dummy;
 925   const char* real_name;
 926   bool warn_if_deprecated = true;
 927 
 928   if (sscanf(arg, "-%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
 929     real_name = handle_aliases_and_deprecation(name, warn_if_deprecated);
 930     if (real_name == NULL) {
 931       return false;
 932     }
 933     return set_bool_flag(real_name, false, origin);
 934   }
 935   if (sscanf(arg, "+%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
 936     real_name = handle_aliases_and_deprecation(name, warn_if_deprecated);
 937     if (real_name == NULL) {
 938       return false;
 939     }
 940     return set_bool_flag(real_name, true, origin);
 941   }
 942 
 943   char punct;
 944   if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "%c", name, &punct) == 2 && punct == '=') {
 945     const char* value = strchr(arg, '=') + 1;
 946     Flag* flag;
 947 
 948     // this scanf pattern matches both strings (handled here) and numbers (handled later))
 949     real_name = handle_aliases_and_deprecation(name, warn_if_deprecated);
 950     if (real_name == NULL) {
 951       return false;
 952     }
 953     flag = Flag::find_flag(real_name);
 954     if (flag != NULL && flag->is_ccstr()) {
 955       if (flag->ccstr_accumulates()) {
 956         return append_to_string_flag(real_name, value, origin);
 957       } else {
 958         if (value[0] == '\0') {
 959           value = NULL;
 960         }
 961         return set_string_flag(real_name, value, origin);
 962       }
 963     } else {
 964       warn_if_deprecated = false; // if arg is deprecated, we've already done warning...
 965     }
 966   }
 967 
 968   if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE ":%c", name, &punct) == 2 && punct == '=') {
 969     const char* value = strchr(arg, '=') + 1;
 970     // -XX:Foo:=xxx will reset the string flag to the given value.
 971     if (value[0] == '\0') {
 972       value = NULL;
 973     }
 974     real_name = handle_aliases_and_deprecation(name, warn_if_deprecated);
 975     if (real_name == NULL) {
 976       return false;
 977     }
 978     return set_string_flag(real_name, value, origin);
 979   }
 980 
 981 #define SIGNED_FP_NUMBER_RANGE "[-0123456789.]"
 982 #define SIGNED_NUMBER_RANGE    "[-0123456789]"
 983 #define        NUMBER_RANGE    "[0123456789]"
 984   char value[BUFLEN + 1];
 985   char value2[BUFLEN + 1];
 986   if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_NUMBER_RANGE "." "%" XSTR(BUFLEN) NUMBER_RANGE "%c", name, value, value2, &dummy) == 3) {
 987     // Looks like a floating-point number -- try again with more lenient format string
 988     if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_FP_NUMBER_RANGE "%c", name, value, &dummy) == 2) {
 989       real_name = handle_aliases_and_deprecation(name, warn_if_deprecated);
 990       if (real_name == NULL) {
 991         return false;
 992       }
 993       return set_fp_numeric_flag(real_name, value, origin);
 994     }
 995   }
 996 
 997 #define VALUE_RANGE "[-kmgtxKMGTX0123456789abcdefABCDEF]"
 998   if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) VALUE_RANGE "%c", name, value, &dummy) == 2) {
 999     real_name = handle_aliases_and_deprecation(name, warn_if_deprecated);
1000     if (real_name == NULL) {
1001       return false;
1002     }
1003     return set_numeric_flag(real_name, value, origin);
1004   }
1005 
1006   return false;
1007 }
1008 
1009 void Arguments::add_string(char*** bldarray, int* count, const char* arg) {
1010   assert(bldarray != NULL, "illegal argument");
1011 
1012   if (arg == NULL) {
1013     return;
1014   }
1015 
1016   int new_count = *count + 1;
1017 
1018   // expand the array and add arg to the last element
1019   if (*bldarray == NULL) {
1020     *bldarray = NEW_C_HEAP_ARRAY(char*, new_count, mtInternal);
1021   } else {
1022     *bldarray = REALLOC_C_HEAP_ARRAY(char*, *bldarray, new_count, mtInternal);
1023   }


1091   st->cr();
1092 }
1093 
1094 void Arguments::print_jvm_flags_on(outputStream* st) {
1095   if (_num_jvm_flags > 0) {
1096     for (int i=0; i < _num_jvm_flags; i++) {
1097       st->print("%s ", _jvm_flags_array[i]);
1098     }
1099   }
1100 }
1101 
1102 void Arguments::print_jvm_args_on(outputStream* st) {
1103   if (_num_jvm_args > 0) {
1104     for (int i=0; i < _num_jvm_args; i++) {
1105       st->print("%s ", _jvm_args_array[i]);
1106     }
1107   }
1108 }
1109 
1110 bool Arguments::process_argument(const char* arg,
1111                                  jboolean ignore_unrecognized,
1112                                  Flag::Flags origin) {
1113   JDK_Version since = JDK_Version();
1114 
1115   if (parse_argument(arg, origin) || ignore_unrecognized) {
1116     return true;
1117   }
1118 
1119   // Determine if the flag has '+', '-', or '=' characters.
1120   bool has_plus_minus = (*arg == '+' || *arg == '-');
1121   const char* const argname = has_plus_minus ? arg + 1 : arg;
1122 
1123   size_t arg_len;
1124   const char* equal_sign = strchr(argname, '=');
1125   if (equal_sign == NULL) {
1126     arg_len = strlen(argname);
1127   } else {
1128     arg_len = equal_sign - argname;
1129   }
1130 
1131   // Only make the obsolete check for valid arguments.
1132   if (arg_len <= BUFLEN) {
1133     // Construct a string which consists only of the argument name without '+', '-', or '='.
1134     char stripped_argname[BUFLEN+1];
1135     strncpy(stripped_argname, argname, arg_len);
1136     stripped_argname[arg_len] = '\0';  // strncpy may not null terminate.
1137 
1138     if (is_obsolete_flag(stripped_argname, &since)) {
1139       char version[256];
1140       since.to_string(version, sizeof(version));
1141       warning("Ignoring option %s; support was removed in %s", stripped_argname, version);
1142       return true;
1143     }
1144   }
1145 
1146   // For locked flags, report a custom error message if available.
1147   // Otherwise, report the standard unrecognized VM option.
1148   Flag* found_flag = Flag::find_flag((const char*)argname, arg_len, true, true);
1149   if (found_flag != NULL) {
1150     char locked_message_buf[BUFLEN];
1151     found_flag->get_locked_message(locked_message_buf, BUFLEN);
1152     if (strlen(locked_message_buf) == 0) {
1153       if (found_flag->is_bool() && !has_plus_minus) {
1154         jio_fprintf(defaultStream::error_stream(),
1155           "Missing +/- setting for VM option '%s'\n", argname);
1156       } else if (!found_flag->is_bool() && has_plus_minus) {
1157         jio_fprintf(defaultStream::error_stream(),
1158           "Unexpected +/- setting in VM option '%s'\n", argname);
1159       } else {
1160         jio_fprintf(defaultStream::error_stream(),
1161           "Improperly specified VM option '%s'\n", argname);


1481 
1482     FLAG_SET_ERGO(intx, Tier2InvokeNotifyFreqLog, scaled_freq_log(Tier2InvokeNotifyFreqLog));
1483     FLAG_SET_ERGO(intx, Tier2BackedgeNotifyFreqLog, scaled_freq_log(Tier2BackedgeNotifyFreqLog));
1484 
1485     FLAG_SET_ERGO(intx, Tier3InvokeNotifyFreqLog, scaled_freq_log(Tier3InvokeNotifyFreqLog));
1486     FLAG_SET_ERGO(intx, Tier3BackedgeNotifyFreqLog, scaled_freq_log(Tier3BackedgeNotifyFreqLog));
1487 
1488     FLAG_SET_ERGO(intx, Tier23InlineeNotifyFreqLog, scaled_freq_log(Tier23InlineeNotifyFreqLog));
1489 
1490     FLAG_SET_ERGO(intx, Tier4InvocationThreshold, scaled_compile_threshold(Tier4InvocationThreshold));
1491     FLAG_SET_ERGO(intx, Tier4MinInvocationThreshold, scaled_compile_threshold(Tier4MinInvocationThreshold));
1492     FLAG_SET_ERGO(intx, Tier4CompileThreshold, scaled_compile_threshold(Tier4CompileThreshold));
1493     FLAG_SET_ERGO(intx, Tier4BackEdgeThreshold, scaled_compile_threshold(Tier4BackEdgeThreshold));
1494   }
1495 }
1496 
1497 #if INCLUDE_ALL_GCS
1498 static void disable_adaptive_size_policy(const char* collector_name) {
1499   if (UseAdaptiveSizePolicy) {
1500     if (FLAG_IS_CMDLINE(UseAdaptiveSizePolicy)) {
1501       warning("Disabling UseAdaptiveSizePolicy; it is incompatible with %s.",
1502               collector_name);
1503     }
1504     FLAG_SET_DEFAULT(UseAdaptiveSizePolicy, false);
1505   }
1506 }
1507 
1508 void Arguments::set_parnew_gc_flags() {
1509   assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC && !UseG1GC,
1510          "control point invariant");
1511   assert(UseConcMarkSweepGC, "CMS is expected to be on here");
1512   assert(UseParNewGC, "ParNew should always be used with CMS");
1513 
1514   if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
1515     FLAG_SET_DEFAULT(ParallelGCThreads, Abstract_VM_Version::parallel_worker_threads());
1516     assert(ParallelGCThreads > 0, "We should always have at least one thread by default");
1517   } else if (ParallelGCThreads == 0) {
1518     jio_fprintf(defaultStream::error_stream(),
1519         "The ParNew GC can not be combined with -XX:ParallelGCThreads=0\n");
1520     vm_exit(1);
1521   }


1956 #if !INCLUDE_ALL_GCS
1957 #ifdef ASSERT
1958 static bool verify_serial_gc_flags() {
1959   return (UseSerialGC &&
1960         !(UseParNewGC || (UseConcMarkSweepGC) || UseG1GC ||
1961           UseParallelGC || UseParallelOldGC));
1962 }
1963 #endif // ASSERT
1964 #endif // INCLUDE_ALL_GCS
1965 
1966 void Arguments::set_gc_specific_flags() {
1967 #if INCLUDE_ALL_GCS
1968   // Set per-collector flags
1969   if (UseParallelGC || UseParallelOldGC) {
1970     set_parallel_gc_flags();
1971   } else if (UseConcMarkSweepGC) {
1972     set_cms_and_parnew_gc_flags();
1973   } else if (UseG1GC) {
1974     set_g1_gc_flags();
1975   }

1976   if (AssumeMP && !UseSerialGC) {
1977     if (FLAG_IS_DEFAULT(ParallelGCThreads) && ParallelGCThreads == 1) {
1978       warning("If the number of processors is expected to increase from one, then"
1979               " you should configure the number of parallel GC threads appropriately"
1980               " using -XX:ParallelGCThreads=N");
1981     }
1982   }
1983   if (MinHeapFreeRatio == 100) {
1984     // Keeping the heap 100% free is hard ;-) so limit it to 99%.
1985     FLAG_SET_ERGO(uintx, MinHeapFreeRatio, 99);
1986   }
1987 #else // INCLUDE_ALL_GCS
1988   assert(verify_serial_gc_flags(), "SerialGC unset");
1989 #endif // INCLUDE_ALL_GCS
1990 }
1991 
1992 julong Arguments::limit_by_allocatable_memory(julong limit) {
1993   julong max_allocatable;
1994   julong result = limit;
1995   if (os::has_allocatable_memory_limit(&max_allocatable)) {
1996     result = MIN2(result, max_allocatable / MaxVirtMemFraction);
1997   }
1998   return result;
1999 }
2000 
2001 // Use static initialization to get the default before parsing
2002 static const size_t DefaultHeapBaseMinAddress = HeapBaseMinAddress;
2003 
2004 void Arguments::set_heap_size() {





2005   const julong phys_mem =
2006     FLAG_IS_DEFAULT(MaxRAM) ? MIN2(os::physical_memory(), (julong)MaxRAM)
2007                             : (julong)MaxRAM;
2008 
2009   // If the maximum heap size has not been set with -Xmx,
2010   // then set it as fraction of the size of physical memory,
2011   // respecting the maximum and minimum sizes of the heap.
2012   if (FLAG_IS_DEFAULT(MaxHeapSize)) {
2013     julong reasonable_max = phys_mem / MaxRAMFraction;
2014 
2015     if (phys_mem <= MaxHeapSize * MinRAMFraction) {
2016       // Small physical memory, so use a minimum fraction of it for the heap
2017       reasonable_max = phys_mem / MinRAMFraction;
2018     } else {
2019       // Not-small physical memory, so require a heap at least
2020       // as large as MaxHeapSize
2021       reasonable_max = MAX2(reasonable_max, (julong)MaxHeapSize);
2022     }
2023     if (!FLAG_IS_DEFAULT(ErgoHeapSizeLimit) && ErgoHeapSizeLimit != 0) {
2024       // Limit the heap size to ErgoHeapSizeLimit


2087       reasonable_initial = limit_by_allocatable_memory(reasonable_initial);
2088 
2089       if (PrintGCDetails && Verbose) {
2090         // Cannot use gclog_or_tty yet.
2091         tty->print_cr("  Initial heap size " SIZE_FORMAT, (size_t)reasonable_initial);
2092       }
2093       FLAG_SET_ERGO(size_t, InitialHeapSize, (size_t)reasonable_initial);
2094     }
2095     // If the minimum heap size has not been set (via -Xms),
2096     // synchronize with InitialHeapSize to avoid errors with the default value.
2097     if (min_heap_size() == 0) {
2098       set_min_heap_size(MIN2((size_t)reasonable_minimum, InitialHeapSize));
2099       if (PrintGCDetails && Verbose) {
2100         // Cannot use gclog_or_tty yet.
2101         tty->print_cr("  Minimum heap size " SIZE_FORMAT, min_heap_size());
2102       }
2103     }
2104   }
2105 }
2106 
2107 // This option inspects the machine and attempts to set various
2108 // parameters to be optimal for long-running, memory allocation
2109 // intensive jobs.  It is intended for machines with large
2110 // amounts of cpu and memory.
2111 jint Arguments::set_aggressive_heap_flags() {
2112   // initHeapSize is needed since _initial_heap_size is 4 bytes on a 32 bit
2113   // VM, but we may not be able to represent the total physical memory
2114   // available (like having 8gb of memory on a box but using a 32bit VM).
2115   // Thus, we need to make sure we're using a julong for intermediate
2116   // calculations.
2117   julong initHeapSize;
2118   julong total_memory = os::physical_memory();
2119 
2120   if (total_memory < (julong) 256 * M) {
2121     jio_fprintf(defaultStream::error_stream(),
2122             "You need at least 256mb of memory to use -XX:+AggressiveHeap\n");
2123     vm_exit(1);
2124   }
2125 
2126   // The heap size is half of available memory, or (at most)
2127   // all of possible memory less 160mb (leaving room for the OS
2128   // when using ISM).  This is the maximum; because adaptive sizing
2129   // is turned on below, the actual space used may be smaller.
2130 
2131   initHeapSize = MIN2(total_memory / (julong) 2,
2132           total_memory - (julong) 160 * M);
2133 
2134   initHeapSize = limit_by_allocatable_memory(initHeapSize);
2135 
2136   if (FLAG_IS_DEFAULT(MaxHeapSize)) {
2137     if (FLAG_SET_CMDLINE(size_t, MaxHeapSize, initHeapSize) != Flag::SUCCESS) {
2138       return JNI_EINVAL;
2139     }
2140     if (FLAG_SET_CMDLINE(size_t, InitialHeapSize, initHeapSize) != Flag::SUCCESS) {
2141       return JNI_EINVAL;
2142     }
2143     // Currently the minimum size and the initial heap sizes are the same.
2144     set_min_heap_size(initHeapSize);
2145   }
2146   if (FLAG_IS_DEFAULT(NewSize)) {
2147     // Make the young generation 3/8ths of the total heap.
2148     if (FLAG_SET_CMDLINE(size_t, NewSize,
2149             ((julong) MaxHeapSize / (julong) 8) * (julong) 3) != Flag::SUCCESS) {
2150       return JNI_EINVAL;
2151     }
2152     if (FLAG_SET_CMDLINE(size_t, MaxNewSize, NewSize) != Flag::SUCCESS) {
2153       return JNI_EINVAL;
2154     }
2155   }
2156 
2157 #if !defined(_ALLBSD_SOURCE) && !defined(AIX)  // UseLargePages is not yet supported on BSD and AIX.
2158   FLAG_SET_DEFAULT(UseLargePages, true);
2159 #endif
2160 
2161   // Increase some data structure sizes for efficiency
2162   if (FLAG_SET_CMDLINE(size_t, BaseFootPrintEstimate, MaxHeapSize) != Flag::SUCCESS) {
2163     return JNI_EINVAL;
2164   }
2165   if (FLAG_SET_CMDLINE(bool, ResizeTLAB, false) != Flag::SUCCESS) {
2166     return JNI_EINVAL;
2167   }
2168   if (FLAG_SET_CMDLINE(size_t, TLABSize, 256 * K) != Flag::SUCCESS) {
2169     return JNI_EINVAL;
2170   }
2171 
2172   // See the OldPLABSize comment below, but replace 'after promotion'
2173   // with 'after copying'.  YoungPLABSize is the size of the survivor
2174   // space per-gc-thread buffers.  The default is 4kw.
2175   if (FLAG_SET_CMDLINE(size_t, YoungPLABSize, 256 * K) != Flag::SUCCESS) { // Note: this is in words
2176     return JNI_EINVAL;
2177   }
2178 
2179   // OldPLABSize is the size of the buffers in the old gen that
2180   // UseParallelGC uses to promote live data that doesn't fit in the
2181   // survivor spaces.  At any given time, there's one for each gc thread.
2182   // The default size is 1kw. These buffers are rarely used, since the
2183   // survivor spaces are usually big enough.  For specjbb, however, there
2184   // are occasions when there's lots of live data in the young gen
2185   // and we end up promoting some of it.  We don't have a definite
2186   // explanation for why bumping OldPLABSize helps, but the theory
2187   // is that a bigger PLAB results in retaining something like the
2188   // original allocation order after promotion, which improves mutator
2189   // locality.  A minor effect may be that larger PLABs reduce the
2190   // number of PLAB allocation events during gc.  The value of 8kw
2191   // was arrived at by experimenting with specjbb.
2192   if (FLAG_SET_CMDLINE(size_t, OldPLABSize, 8 * K) != Flag::SUCCESS) { // Note: this is in words
2193     return JNI_EINVAL;
2194   }
2195 
2196   // Enable parallel GC and adaptive generation sizing
2197   if (FLAG_SET_CMDLINE(bool, UseParallelGC, true) != Flag::SUCCESS) {
2198     return JNI_EINVAL;
2199   }
2200   FLAG_SET_DEFAULT(ParallelGCThreads,
2201           Abstract_VM_Version::parallel_worker_threads());
2202 
2203   // Encourage steady state memory management
2204   if (FLAG_SET_CMDLINE(uintx, ThresholdTolerance, 100) != Flag::SUCCESS) {
2205     return JNI_EINVAL;
2206   }
2207 
2208   // This appears to improve mutator locality
2209   if (FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false) != Flag::SUCCESS) {
2210     return JNI_EINVAL;
2211   }
2212 
2213   // Get around early Solaris scheduling bug
2214   // (affinity vs other jobs on system)
2215   // but disallow DR and offlining (5008695).
2216   if (FLAG_SET_CMDLINE(bool, BindGCTaskThreadsToCPUs, true) != Flag::SUCCESS) {
2217     return JNI_EINVAL;
2218   }
2219 
2220   return JNI_OK;
2221 }
2222 
2223 // Set up runtime image flags
2224 void Arguments::set_runtime_image_flags() {
2225 #ifdef _LP64
2226   // Memory map image file by default on 64 bit machines.
2227   if (FLAG_IS_DEFAULT(MemoryMapImage)) {
2228     FLAG_SET_ERGO(bool, MemoryMapImage, true);
2229   }
2230 #endif
2231 }
2232 
2233 // This must be called after ergonomics.
2234 void Arguments::set_bytecode_flags() {
2235   if (!RewriteBytecodes) {
2236     FLAG_SET_DEFAULT(RewriteFrequentPairs, false);
2237   }
2238 }
2239 
2240 // Aggressive optimization flags  -XX:+AggressiveOpts
2241 void Arguments::set_aggressive_opts_flags() {
2242 #ifdef COMPILER2
2243   if (AggressiveUnboxing) {


2392                 "please refer to the release notes for the combinations "
2393                 "allowed\n");
2394     return false;
2395   }
2396 
2397   if (UseConcMarkSweepGC && !UseParNewGC) {
2398     jio_fprintf(defaultStream::error_stream(),
2399         "It is not possible to combine the DefNew young collector with the CMS collector.\n");
2400     return false;
2401   }
2402 
2403   if (UseParNewGC && !UseConcMarkSweepGC) {
2404     jio_fprintf(defaultStream::error_stream(),
2405         "It is not possible to combine the ParNew young collector with any collector other than CMS.\n");
2406     return false;
2407   }
2408 
2409   return true;
2410 }
2411 














2412 // Check the consistency of vm_init_args
2413 bool Arguments::check_vm_args_consistency() {
2414   // Method for adding checks for flag consistency.
2415   // The intent is to warn the user of all possible conflicts,
2416   // before returning an error.
2417   // Note: Needs platform-dependent factoring.
2418   bool status = true;
2419 
2420   if (TLABRefillWasteFraction == 0) {
2421     jio_fprintf(defaultStream::error_stream(),
2422                 "TLABRefillWasteFraction should be a denominator, "
2423                 "not " SIZE_FORMAT "\n",
2424                 TLABRefillWasteFraction);
2425     status = false;
2426   }
2427 
2428   if (FullGCALot && FLAG_IS_DEFAULT(MarkSweepAlwaysCompactCount)) {
2429     MarkSweepAlwaysCompactCount = 1;  // Move objects every gc.
2430   }
2431 


2927       ArgsRange errcode = parse_memory_size(tail, &long_ThreadStackSize, 1000);
2928       if (errcode != arg_in_range) {
2929         jio_fprintf(defaultStream::error_stream(),
2930                     "Invalid thread stack size: %s\n", option->optionString);
2931         describe_range_error(errcode);
2932         return JNI_EINVAL;
2933       }
2934       // Internally track ThreadStackSize in units of 1024 bytes.
2935       if (FLAG_SET_CMDLINE(intx, ThreadStackSize,
2936                        round_to((int)long_ThreadStackSize, K) / K) != Flag::SUCCESS) {
2937         return JNI_EINVAL;
2938       }
2939     // -Xoss, -Xsqnopause, -Xoptimize, -Xboundthreads
2940     } else if (match_option(option, "-Xoss", &tail) ||
2941                match_option(option, "-Xsqnopause") ||
2942                match_option(option, "-Xoptimize") ||
2943                match_option(option, "-Xboundthreads")) {
2944       // All these options are deprecated in JDK 9 and will be removed in a future release
2945       char version[256];
2946       JDK_Version::jdk(9).to_string(version, sizeof(version));
2947       warning("Ignoring option %s; support was removed in %s", option->optionString, version);
2948     } else if (match_option(option, "-XX:CodeCacheExpansionSize=", &tail)) {
2949       julong long_CodeCacheExpansionSize = 0;
2950       ArgsRange errcode = parse_memory_size(tail, &long_CodeCacheExpansionSize, os::vm_page_size());
2951       if (errcode != arg_in_range) {
2952         jio_fprintf(defaultStream::error_stream(),
2953                    "Invalid argument: %s. Must be at least %luK.\n", option->optionString,
2954                    os::vm_page_size()/K);
2955         return JNI_EINVAL;
2956       }
2957       if (FLAG_SET_CMDLINE(uintx, CodeCacheExpansionSize, (uintx)long_CodeCacheExpansionSize) != Flag::SUCCESS) {
2958         return JNI_EINVAL;
2959       }
2960     } else if (match_option(option, "-Xmaxjitcodesize", &tail) ||
2961                match_option(option, "-XX:ReservedCodeCacheSize=", &tail)) {
2962       julong long_ReservedCodeCacheSize = 0;
2963 
2964       ArgsRange errcode = parse_memory_size(tail, &long_ReservedCodeCacheSize, 1);
2965       if (errcode != arg_in_range) {
2966         jio_fprintf(defaultStream::error_stream(),
2967                     "Invalid maximum code cache size: %s.\n", option->optionString);


3194     // JNI hooks
3195     } else if (match_option(option, "-Xcheck", &tail)) {
3196       if (!strcmp(tail, ":jni")) {
3197 #if !INCLUDE_JNI_CHECK
3198         warning("JNI CHECKING is not supported in this VM");
3199 #else
3200         CheckJNICalls = true;
3201 #endif // INCLUDE_JNI_CHECK
3202       } else if (is_bad_option(option, args->ignoreUnrecognized,
3203                                      "check")) {
3204         return JNI_EINVAL;
3205       }
3206     } else if (match_option(option, "vfprintf")) {
3207       _vfprintf_hook = CAST_TO_FN_PTR(vfprintf_hook_t, option->extraInfo);
3208     } else if (match_option(option, "exit")) {
3209       _exit_hook = CAST_TO_FN_PTR(exit_hook_t, option->extraInfo);
3210     } else if (match_option(option, "abort")) {
3211       _abort_hook = CAST_TO_FN_PTR(abort_hook_t, option->extraInfo);
3212     // -XX:+AggressiveHeap
3213     } else if (match_option(option, "-XX:+AggressiveHeap")) {
3214       jint result = set_aggressive_heap_flags();
3215       if (result != JNI_OK) {
3216           return result;













































































































3217       }

3218     // Need to keep consistency of MaxTenuringThreshold and AlwaysTenure/NeverTenure;
3219     // and the last option wins.
3220     } else if (match_option(option, "-XX:+NeverTenure")) {
3221       if (FLAG_SET_CMDLINE(bool, NeverTenure, true) != Flag::SUCCESS) {
3222         return JNI_EINVAL;
3223       }
3224       if (FLAG_SET_CMDLINE(bool, AlwaysTenure, false) != Flag::SUCCESS) {
3225         return JNI_EINVAL;
3226       }
3227       if (FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, markOopDesc::max_age + 1) != Flag::SUCCESS) {
3228         return JNI_EINVAL;
3229       }
3230     } else if (match_option(option, "-XX:+AlwaysTenure")) {
3231       if (FLAG_SET_CMDLINE(bool, NeverTenure, false) != Flag::SUCCESS) {
3232         return JNI_EINVAL;
3233       }
3234       if (FLAG_SET_CMDLINE(bool, AlwaysTenure, true) != Flag::SUCCESS) {
3235         return JNI_EINVAL;
3236       }
3237       if (FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, 0) != Flag::SUCCESS) {


3290         return JNI_EINVAL;
3291       }
3292       if (FLAG_SET_CMDLINE(bool, DTraceMonitorProbes, true) != Flag::SUCCESS) {
3293         return JNI_EINVAL;
3294       }
3295 #else // defined(DTRACE_ENABLED)
3296       jio_fprintf(defaultStream::error_stream(),
3297                   "ExtendedDTraceProbes flag is not applicable for this configuration\n");
3298       return JNI_EINVAL;
3299 #endif // defined(DTRACE_ENABLED)
3300 #ifdef ASSERT
3301     } else if (match_option(option, "-XX:+FullGCALot")) {
3302       if (FLAG_SET_CMDLINE(bool, FullGCALot, true) != Flag::SUCCESS) {
3303         return JNI_EINVAL;
3304       }
3305       // disable scavenge before parallel mark-compact
3306       if (FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false) != Flag::SUCCESS) {
3307         return JNI_EINVAL;
3308       }
3309 #endif














































3310     } else if (match_option(option, "-XX:MaxDirectMemorySize=", &tail)) {
3311       julong max_direct_memory_size = 0;
3312       ArgsRange errcode = parse_memory_size(tail, &max_direct_memory_size, 0);
3313       if (errcode != arg_in_range) {
3314         jio_fprintf(defaultStream::error_stream(),
3315                     "Invalid maximum direct memory size: %s\n",
3316                     option->optionString);
3317         describe_range_error(errcode);
3318         return JNI_EINVAL;
3319       }
3320       if (FLAG_SET_CMDLINE(size_t, MaxDirectMemorySize, max_direct_memory_size) != Flag::SUCCESS) {
3321         return JNI_EINVAL;
3322       }
3323 #if !INCLUDE_MANAGEMENT
3324     } else if (match_option(option, "-XX:+ManagementServer")) {
3325         jio_fprintf(defaultStream::error_stream(),
3326           "ManagementServer is not supported in this VM.\n");
3327         return JNI_ERR;
3328 #endif // INCLUDE_MANAGEMENT













3329     } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx
3330       // Skip -XX:Flags= since that case has already been handled
3331       if (strncmp(tail, "Flags=", strlen("Flags=")) != 0) {
3332         if (!process_argument(tail, args->ignoreUnrecognized, origin)) {
3333           return JNI_EINVAL;
3334         }
3335       }
3336     // Unknown option
3337     } else if (is_bad_option(option, args->ignoreUnrecognized)) {
3338       return JNI_ERR;
3339     }
3340   }
3341 
3342   // PrintSharedArchiveAndExit will turn on
3343   //   -Xshare:on
3344   //   -XX:+TraceClassPaths
3345   if (PrintSharedArchiveAndExit) {
3346     if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, true) != Flag::SUCCESS) {
3347       return JNI_EINVAL;
3348     }


3687     }
3688     if (*rd != 0) {
3689       // In this case, the assignment to wrt below will make *rd nul,
3690       // which will interfere with the next loop iteration.
3691       rd++;
3692     }
3693     *wrt = 0;                               // Zero terminate option
3694   }
3695 
3696   // Fill out JavaVMInitArgs structure.
3697   jint status = vm_args->set_args(options);
3698 
3699   delete options;
3700   os::free(buffer);
3701   return status;
3702 }
3703 
3704 void Arguments::set_shared_spaces_flags() {
3705   if (DumpSharedSpaces) {
3706     if (RequireSharedSpaces) {
3707       warning("Cannot dump shared archive while using shared archive");
3708     }
3709     UseSharedSpaces = false;
3710 #ifdef _LP64
3711     if (!UseCompressedOops || !UseCompressedClassPointers) {
3712       vm_exit_during_initialization(
3713         "Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off.", NULL);
3714     }
3715   } else {
3716     if (!UseCompressedOops || !UseCompressedClassPointers) {
3717       no_shared_spaces("UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces.");
3718     }
3719 #endif
3720   }
3721 }
3722 
3723 #if !INCLUDE_ALL_GCS
3724 static void force_serial_gc() {
3725   FLAG_SET_DEFAULT(UseSerialGC, true);
3726   UNSUPPORTED_GC_OPTION(UseG1GC);
3727   UNSUPPORTED_GC_OPTION(UseParallelGC);


3845       vm_exit(0);
3846     }
3847 #endif
3848   }
3849   return JNI_OK;
3850 }
3851 
3852 static void print_options(const JavaVMInitArgs *args) {
3853   const char* tail;
3854   for (int index = 0; index < args->nOptions; index++) {
3855     const JavaVMOption *option = args->options + index;
3856     if (match_option(option, "-XX:", &tail)) {
3857       logOption(tail);
3858     }
3859   }
3860 }
3861 
3862 // Parse entry point called from JNI_CreateJavaVM
3863 
3864 jint Arguments::parse(const JavaVMInitArgs* args) {
3865   assert(verify_special_jvm_flags(), "deprecated and obsolete flag table inconsistent");
3866 
3867   // Initialize ranges and constraints
3868   CommandLineFlagRangeList::init();
3869   CommandLineFlagConstraintList::init();
3870 
3871   // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed.
3872   const char* hotspotrc = ".hotspotrc";
3873   char* flags_file = NULL;
3874   bool settings_file_specified = false;
3875   bool needs_hotspotrc_warning = false;
3876   ScopedVMInitArgs java_tool_options_args;
3877   ScopedVMInitArgs java_options_args;
3878 
3879   jint code =
3880       parse_java_tool_options_environment_variable(&java_tool_options_args);
3881   if (code != JNI_OK) {
3882     return code;
3883   }
3884 
3885   code = parse_java_options_environment_variable(&java_options_args);


3967 #if defined(_ALLBSD_SOURCE) || defined(AIX)  // UseLargePages is not yet supported on BSD and AIX.
3968   UNSUPPORTED_OPTION(UseLargePages, "-XX:+UseLargePages");
3969 #endif
3970 
3971   ArgumentsExt::report_unsupported_options();
3972 
3973 #ifndef PRODUCT
3974   if (TraceBytecodesAt != 0) {
3975     TraceBytecodes = true;
3976   }
3977   if (CountCompiledCalls) {
3978     if (UseCounterDecay) {
3979       warning("UseCounterDecay disabled because CountCalls is set");
3980       UseCounterDecay = false;
3981     }
3982   }
3983 #endif // PRODUCT
3984 
3985   if (ScavengeRootsInCode == 0) {
3986     if (!FLAG_IS_DEFAULT(ScavengeRootsInCode)) {
3987       warning("Forcing ScavengeRootsInCode non-zero");
3988     }
3989     ScavengeRootsInCode = 1;
3990   }
3991 
3992   if (PrintGCDetails) {
3993     // Turn on -verbose:gc options as well
3994     PrintGC = true;
3995   }
3996 
3997   // Set object alignment values.
3998   set_object_alignment();
3999 
4000 #if !INCLUDE_ALL_GCS
4001   force_serial_gc();
4002 #endif // INCLUDE_ALL_GCS
4003 #if !INCLUDE_CDS
4004   if (DumpSharedSpaces || RequireSharedSpaces) {
4005     jio_fprintf(defaultStream::error_stream(),
4006       "Shared spaces are not supported in this VM\n");
4007     return JNI_ERR;


< prev index next >