< prev index next >

src/share/vm/runtime/arguments.cpp

Print this page
rev 8867 : imported patch 8066821.rev6
rev 8868 : imported patch 8066821.rev7
rev 8869 : [mq]: 8066821.v8


 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  *               "deprecated_jvm_flags" table. Often an option "deprecated" in one major release will
 259  *               be made "obsolete" in the next. In this case the entry should be removed from the
 260  *               "deprecated_jvm_flags" table and added to the "obsolete_jvm_flags" table (see below).
 261  *
 262  *     OBSOLETE: An option that has been removed (and deleted from globals.hpp), but is still accepted
 263  *               on the command line. A warning is printed to let the user know that option might not
 264  *               be accepted in the future.
 265  *
 266  *               Add an obsolete warning for an option by adding an entry in the "obsolete_jvm_flags"
 267  *               table.
 268  *
 269  *      EXPIRED: A deprecated or obsolete option that has an "accept_until" version less than or equal
 270  *               to the current JDK version. The system will flatly refuse to admit the existence of
 271  *               the flag. This allows a flag to die automatically over JDK releases.
 272  *
 273  *               Note that manual cleanup of expired options should be done at major JDK version upgrades:
 274  *                  - Expired options should be removed from the obsolete_jvm_flags, deprecated_jvm_flags,
 275  *                    and aliased_jvm_flags tables.
 276  *                  - Expired deprecated options should have their global variable definitions removed
 277  *                    (in globals.hpp, etc).
 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 // MAINTENANCE 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, push the entry below into the
 320 //   "Obsolete Flags" section.
 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:
 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):
 339   { "DefaultMaxRAMFraction",        JDK_Version::jdk(8), JDK_Version::undefined(), JDK_Version::undefined() },
 340   { "CMSMarkStackSizeMax",          JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
 341   { "CMSMarkStackSize",             JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
 342   { "G1MarkStackSize",              JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
 343   { "ParallelMarkingThreads",       JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
 344   { "ParallelCMSThreads",           JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(10) },
 345   { "CreateMinidumpOnCrash",        JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::undefined() },
 346 
 347   // -------------- Obsolete Flags --------------
 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 // Returns 1 if the flag is special and jdk version is in the range specified.
 413 //     In this case the 'version' buffer is filled in with the version number when
 414 //     the flag became special.
 415 // Returns -1 if the flag is the wrong kind of special - expired or (check_deprecated & obsolete).
 416 // Returns 0 if the flag is not special.
 417 // "flag_name" is a flag name stripped of '+', '-', and '='.
 418 static int is_special_flag(bool check_deprecated, const char *flag_name, JDK_Version* version) {
 419   assert(version != NULL, "Must provide a version buffer");
 420   SpecialFlag flag;
 421   if (lookup_special_flag(flag_name, flag)) {
 422     if (check_deprecated && !flag.deprecated_in.is_undefined()) {
 423       if (version_less_than(JDK_Version::current(), flag.obsolete_in) &&
 424           version_less_than(JDK_Version::current(), flag.expired_in)) {
 425         *version = flag.deprecated_in;
 426         return 1;
 427       } else {
 428         return -1;
 429       }
 430     } else if (!check_deprecated && !flag.obsolete_in.is_undefined()) {
 431        if (version_less_than(JDK_Version::current(), flag.expired_in)) {
 432         *version = flag.obsolete_in;
 433         return 1;
 434       } else {
 435         return -1;
 436       }
 437     }
 438   }
 439   return 0;
 440 }
 441 
 442 bool Arguments::is_obsolete_flag(const char *flag_name, JDK_Version* version) {
 443   return (is_special_flag(false, flag_name, version) == 1);
 444 }
 445 
 446 int Arguments::is_deprecated_flag(const char *flag_name, JDK_Version* version) {
 447   return is_special_flag(true, flag_name, version);
 448 }
 449 
 450 const char* Arguments::real_flag_name(const char *flag_name) {
 451   for (size_t i = 0; aliased_jvm_flags[i].alias_name != NULL; i++) {
 452     const AliasedFlag& flag_status = aliased_jvm_flags[i];
 453     if (strcmp(flag_status.alias_name, flag_name) == 0) {
 454         return flag_status.real_name;
 455     }
 456   }
 457   return flag_name;
 458 }
 459 
 460 #ifndef PRODUCT
 461 static bool lookup_special_flag(const char *flag_name, size_t skip_index) {
 462   for (size_t i = 0; special_jvm_flags[i].name != NULL; i++) {
 463     if ((i != skip_index) && (strcmp(special_jvm_flags[i].name, flag_name) == 0)) {
 464       return true;
 465     }
 466   }
 467   return false;
 468 }
 469 
 470 static bool verify_special_jvm_flags() {
 471   bool success = true;
 472   for (size_t i = 0; special_jvm_flags[i].name != NULL; i++) {
 473     const SpecialFlag& flag = special_jvm_flags[i];
 474     if (lookup_special_flag(flag.name, i)) {
 475       warning("Duplicate special flag declaration \"%s\"", flag.name);
 476       success = false;
 477     }
 478     if (flag.deprecated_in.is_undefined() &&
 479         flag.obsolete_in.is_undefined()) {
 480       warning("Special flag entry \"%s\" must declare version deprecated and/or obsoleted in.", flag.name);
 481       success = false;
 482     }
 483 
 484     if (!flag.deprecated_in.is_undefined()) {
 485       if (!version_less_than(flag.deprecated_in, flag.obsolete_in)) {
 486         warning("Special flag entry \"%s\" must be deprecated before obsoleted.", flag.name);
 487         success = false;
 488       }
 489 
 490       if (!version_less_than(flag.deprecated_in, flag.expired_in)) {
 491         warning("Special flag entry \"%s\" must be deprecated before expired.", flag.name);
 492         success = false;
 493       }
 494     }
 495 
 496     if (!flag.obsolete_in.is_undefined()) {
 497       if (!version_less_than(flag.obsolete_in, flag.expired_in)) {
 498         warning("Special flag entry \"%s\" must be obsoleted before expired.", flag.name);
 499         success = false;
 500       }
 501 
 502       // if flag has become obsolete it should not have a "globals" flag defined anymore.
 503       if (!version_less_than(JDK_Version::current(), flag.obsolete_in)) {
 504         if (Flag::find_flag(flag.name) != NULL) {
 505           warning("Global variable for obsolete special flag entry \"%s\" should be removed", flag.name);
 506           success = false;
 507         }
 508       }
 509     }
 510 
 511     if (!flag.expired_in.is_undefined()) {
 512       // if flag has become expired it should not have a "globals" flag defined anymore.
 513       if (!version_less_than(JDK_Version::current(), flag.expired_in)) {
 514         if (Flag::find_flag(flag.name) != NULL) {
 515           warning("Global variable for expired flag entry \"%s\" should be removed", flag.name);
 516           success = false;
 517         }
 518       }
 519     }
 520 
 521   }
 522   return success;
 523 }
 524 #endif
 525 
 526 // Constructs the system class path (aka boot class path) from the following
 527 // components, in order:
 528 //
 529 //     prefix           // from -Xbootclasspath/p:...
 530 //     base             // from os::get_system_properties() or -Xbootclasspath=
 531 //     suffix           // from -Xbootclasspath/a:...
 532 //
 533 // This could be AllStatic, but it isn't needed after argument processing is
 534 // complete.
 535 class SysClassPath: public StackObj {
 536 public:
 537   SysClassPath(const char* base);
 538   ~SysClassPath();
 539 
 540   inline void set_base(const char* base);
 541   inline void add_prefix(const char* prefix);
 542   inline void add_suffix_to_prefix(const char* suffix);
 543   inline void add_suffix(const char* suffix);
 544   inline void reset_path(const char* base);
 545 


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


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


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


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


1963 #if !INCLUDE_ALL_GCS
1964 #ifdef ASSERT
1965 static bool verify_serial_gc_flags() {
1966   return (UseSerialGC &&
1967         !(UseParNewGC || (UseConcMarkSweepGC) || UseG1GC ||
1968           UseParallelGC || UseParallelOldGC));
1969 }
1970 #endif // ASSERT
1971 #endif // INCLUDE_ALL_GCS
1972 
1973 void Arguments::set_gc_specific_flags() {
1974 #if INCLUDE_ALL_GCS
1975   // Set per-collector flags
1976   if (UseParallelGC || UseParallelOldGC) {
1977     set_parallel_gc_flags();
1978   } else if (UseConcMarkSweepGC) {
1979     set_cms_and_parnew_gc_flags();
1980   } else if (UseG1GC) {
1981     set_g1_gc_flags();
1982   }

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





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


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


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














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


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


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













































































































3224       }

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


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














































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













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


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


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


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


< prev index next >