src/share/vm/runtime/arguments.cpp

Sat, 23 Oct 2010 23:03:49 -0700

author
ysr
date
Sat, 23 Oct 2010 23:03:49 -0700
changeset 2243
a7214d79fcf1
parent 2187
22e4420d19f7
child 2245
f5c8d6e5bfee
permissions
-rw-r--r--

6896603: CMS/GCH: collection_attempt_is_safe() ergo should use more recent data
Summary: Deprecated HandlePromotionFailure, removing the ability to turn off that feature, did away with one epoch look-ahead when deciding if a scavenge is likely to fail, relying on current data.
Reviewed-by: jmasa, johnc, poonam

     1 /*
     2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #include "incls/_precompiled.incl"
    26 #include "incls/_arguments.cpp.incl"
    28 #define DEFAULT_VENDOR_URL_BUG "http://java.sun.com/webapps/bugreport/crash.jsp"
    29 #define DEFAULT_JAVA_LAUNCHER  "generic"
    31 char**  Arguments::_jvm_flags_array             = NULL;
    32 int     Arguments::_num_jvm_flags               = 0;
    33 char**  Arguments::_jvm_args_array              = NULL;
    34 int     Arguments::_num_jvm_args                = 0;
    35 char*  Arguments::_java_command                 = NULL;
    36 SystemProperty* Arguments::_system_properties   = NULL;
    37 const char*  Arguments::_gc_log_filename        = NULL;
    38 bool   Arguments::_has_profile                  = false;
    39 bool   Arguments::_has_alloc_profile            = false;
    40 uintx  Arguments::_min_heap_size                = 0;
    41 Arguments::Mode Arguments::_mode                = _mixed;
    42 bool   Arguments::_java_compiler                = false;
    43 bool   Arguments::_xdebug_mode                  = false;
    44 const char*  Arguments::_java_vendor_url_bug    = DEFAULT_VENDOR_URL_BUG;
    45 const char*  Arguments::_sun_java_launcher      = DEFAULT_JAVA_LAUNCHER;
    46 int    Arguments::_sun_java_launcher_pid        = -1;
    48 // These parameters are reset in method parse_vm_init_args(JavaVMInitArgs*)
    49 bool   Arguments::_AlwaysCompileLoopMethods     = AlwaysCompileLoopMethods;
    50 bool   Arguments::_UseOnStackReplacement        = UseOnStackReplacement;
    51 bool   Arguments::_BackgroundCompilation        = BackgroundCompilation;
    52 bool   Arguments::_ClipInlining                 = ClipInlining;
    54 char*  Arguments::SharedArchivePath             = NULL;
    56 AgentLibraryList Arguments::_libraryList;
    57 AgentLibraryList Arguments::_agentList;
    59 abort_hook_t     Arguments::_abort_hook         = NULL;
    60 exit_hook_t      Arguments::_exit_hook          = NULL;
    61 vfprintf_hook_t  Arguments::_vfprintf_hook      = NULL;
    64 SystemProperty *Arguments::_java_ext_dirs = NULL;
    65 SystemProperty *Arguments::_java_endorsed_dirs = NULL;
    66 SystemProperty *Arguments::_sun_boot_library_path = NULL;
    67 SystemProperty *Arguments::_java_library_path = NULL;
    68 SystemProperty *Arguments::_java_home = NULL;
    69 SystemProperty *Arguments::_java_class_path = NULL;
    70 SystemProperty *Arguments::_sun_boot_class_path = NULL;
    72 char* Arguments::_meta_index_path = NULL;
    73 char* Arguments::_meta_index_dir = NULL;
    75 static bool force_client_mode = false;
    77 // Check if head of 'option' matches 'name', and sets 'tail' remaining part of option string
    79 static bool match_option(const JavaVMOption *option, const char* name,
    80                          const char** tail) {
    81   int len = (int)strlen(name);
    82   if (strncmp(option->optionString, name, len) == 0) {
    83     *tail = option->optionString + len;
    84     return true;
    85   } else {
    86     return false;
    87   }
    88 }
    90 static void logOption(const char* opt) {
    91   if (PrintVMOptions) {
    92     jio_fprintf(defaultStream::output_stream(), "VM option '%s'\n", opt);
    93   }
    94 }
    96 // Process java launcher properties.
    97 void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
    98   // See if sun.java.launcher or sun.java.launcher.pid is defined.
    99   // Must do this before setting up other system properties,
   100   // as some of them may depend on launcher type.
   101   for (int index = 0; index < args->nOptions; index++) {
   102     const JavaVMOption* option = args->options + index;
   103     const char* tail;
   105     if (match_option(option, "-Dsun.java.launcher=", &tail)) {
   106       process_java_launcher_argument(tail, option->extraInfo);
   107       continue;
   108     }
   109     if (match_option(option, "-Dsun.java.launcher.pid=", &tail)) {
   110       _sun_java_launcher_pid = atoi(tail);
   111       continue;
   112     }
   113   }
   114 }
   116 // Initialize system properties key and value.
   117 void Arguments::init_system_properties() {
   119   PropertyList_add(&_system_properties, new SystemProperty("java.vm.specification.version", "1.0", false));
   120   PropertyList_add(&_system_properties, new SystemProperty("java.vm.specification.name",
   121                                                                  "Java Virtual Machine Specification",  false));
   122   PropertyList_add(&_system_properties, new SystemProperty("java.vm.specification.vendor",
   123         JDK_Version::is_gte_jdk17x_version() ? "Oracle Corporation" : "Sun Microsystems Inc.", false));
   124   PropertyList_add(&_system_properties, new SystemProperty("java.vm.version", VM_Version::vm_release(),  false));
   125   PropertyList_add(&_system_properties, new SystemProperty("java.vm.name", VM_Version::vm_name(),  false));
   126   PropertyList_add(&_system_properties, new SystemProperty("java.vm.vendor", VM_Version::vm_vendor(),  false));
   127   PropertyList_add(&_system_properties, new SystemProperty("java.vm.info", VM_Version::vm_info_string(),  true));
   129   // following are JVMTI agent writeable properties.
   130   // Properties values are set to NULL and they are
   131   // os specific they are initialized in os::init_system_properties_values().
   132   _java_ext_dirs = new SystemProperty("java.ext.dirs", NULL,  true);
   133   _java_endorsed_dirs = new SystemProperty("java.endorsed.dirs", NULL,  true);
   134   _sun_boot_library_path = new SystemProperty("sun.boot.library.path", NULL,  true);
   135   _java_library_path = new SystemProperty("java.library.path", NULL,  true);
   136   _java_home =  new SystemProperty("java.home", NULL,  true);
   137   _sun_boot_class_path = new SystemProperty("sun.boot.class.path", NULL,  true);
   139   _java_class_path = new SystemProperty("java.class.path", "",  true);
   141   // Add to System Property list.
   142   PropertyList_add(&_system_properties, _java_ext_dirs);
   143   PropertyList_add(&_system_properties, _java_endorsed_dirs);
   144   PropertyList_add(&_system_properties, _sun_boot_library_path);
   145   PropertyList_add(&_system_properties, _java_library_path);
   146   PropertyList_add(&_system_properties, _java_home);
   147   PropertyList_add(&_system_properties, _java_class_path);
   148   PropertyList_add(&_system_properties, _sun_boot_class_path);
   150   // Set OS specific system properties values
   151   os::init_system_properties_values();
   152 }
   154 /**
   155  * Provide a slightly more user-friendly way of eliminating -XX flags.
   156  * When a flag is eliminated, it can be added to this list in order to
   157  * continue accepting this flag on the command-line, while issuing a warning
   158  * and ignoring the value.  Once the JDK version reaches the 'accept_until'
   159  * limit, we flatly refuse to admit the existence of the flag.  This allows
   160  * a flag to die correctly over JDK releases using HSX.
   161  */
   162 typedef struct {
   163   const char* name;
   164   JDK_Version obsoleted_in; // when the flag went away
   165   JDK_Version accept_until; // which version to start denying the existence
   166 } ObsoleteFlag;
   168 static ObsoleteFlag obsolete_jvm_flags[] = {
   169   { "UseTrainGC",                    JDK_Version::jdk(5), JDK_Version::jdk(7) },
   170   { "UseSpecialLargeObjectHandling", JDK_Version::jdk(5), JDK_Version::jdk(7) },
   171   { "UseOversizedCarHandling",       JDK_Version::jdk(5), JDK_Version::jdk(7) },
   172   { "TraceCarAllocation",            JDK_Version::jdk(5), JDK_Version::jdk(7) },
   173   { "PrintTrainGCProcessingStats",   JDK_Version::jdk(5), JDK_Version::jdk(7) },
   174   { "LogOfCarSpaceSize",             JDK_Version::jdk(5), JDK_Version::jdk(7) },
   175   { "OversizedCarThreshold",         JDK_Version::jdk(5), JDK_Version::jdk(7) },
   176   { "MinTickInterval",               JDK_Version::jdk(5), JDK_Version::jdk(7) },
   177   { "DefaultTickInterval",           JDK_Version::jdk(5), JDK_Version::jdk(7) },
   178   { "MaxTickInterval",               JDK_Version::jdk(5), JDK_Version::jdk(7) },
   179   { "DelayTickAdjustment",           JDK_Version::jdk(5), JDK_Version::jdk(7) },
   180   { "ProcessingToTenuringRatio",     JDK_Version::jdk(5), JDK_Version::jdk(7) },
   181   { "MinTrainLength",                JDK_Version::jdk(5), JDK_Version::jdk(7) },
   182   { "AppendRatio",         JDK_Version::jdk_update(6,10), JDK_Version::jdk(7) },
   183   { "DefaultMaxRAM",       JDK_Version::jdk_update(6,18), JDK_Version::jdk(7) },
   184   { "DefaultInitialRAMFraction",
   185                            JDK_Version::jdk_update(6,18), JDK_Version::jdk(7) },
   186   { "UseDepthFirstScavengeOrder",
   187                            JDK_Version::jdk_update(6,22), JDK_Version::jdk(7) },
   188   { "HandlePromotionFailure",
   189                            JDK_Version::jdk_update(6,24), JDK_Version::jdk(8) },
   190   { "MaxLiveObjectEvacuationRatio",
   191                            JDK_Version::jdk_update(6,24), JDK_Version::jdk(8) },
   192   { NULL, JDK_Version(0), JDK_Version(0) }
   193 };
   195 // Returns true if the flag is obsolete and fits into the range specified
   196 // for being ignored.  In the case that the flag is ignored, the 'version'
   197 // value is filled in with the version number when the flag became
   198 // obsolete so that that value can be displayed to the user.
   199 bool Arguments::is_newly_obsolete(const char *s, JDK_Version* version) {
   200   int i = 0;
   201   assert(version != NULL, "Must provide a version buffer");
   202   while (obsolete_jvm_flags[i].name != NULL) {
   203     const ObsoleteFlag& flag_status = obsolete_jvm_flags[i];
   204     // <flag>=xxx form
   205     // [-|+]<flag> form
   206     if ((strncmp(flag_status.name, s, strlen(flag_status.name)) == 0) ||
   207         ((s[0] == '+' || s[0] == '-') &&
   208         (strncmp(flag_status.name, &s[1], strlen(flag_status.name)) == 0))) {
   209       if (JDK_Version::current().compare(flag_status.accept_until) == -1) {
   210           *version = flag_status.obsoleted_in;
   211           return true;
   212       }
   213     }
   214     i++;
   215   }
   216   return false;
   217 }
   219 // Constructs the system class path (aka boot class path) from the following
   220 // components, in order:
   221 //
   222 //     prefix           // from -Xbootclasspath/p:...
   223 //     endorsed         // the expansion of -Djava.endorsed.dirs=...
   224 //     base             // from os::get_system_properties() or -Xbootclasspath=
   225 //     suffix           // from -Xbootclasspath/a:...
   226 //
   227 // java.endorsed.dirs is a list of directories; any jar or zip files in the
   228 // directories are added to the sysclasspath just before the base.
   229 //
   230 // This could be AllStatic, but it isn't needed after argument processing is
   231 // complete.
   232 class SysClassPath: public StackObj {
   233 public:
   234   SysClassPath(const char* base);
   235   ~SysClassPath();
   237   inline void set_base(const char* base);
   238   inline void add_prefix(const char* prefix);
   239   inline void add_suffix_to_prefix(const char* suffix);
   240   inline void add_suffix(const char* suffix);
   241   inline void reset_path(const char* base);
   243   // Expand the jar/zip files in each directory listed by the java.endorsed.dirs
   244   // property.  Must be called after all command-line arguments have been
   245   // processed (in particular, -Djava.endorsed.dirs=...) and before calling
   246   // combined_path().
   247   void expand_endorsed();
   249   inline const char* get_base()     const { return _items[_scp_base]; }
   250   inline const char* get_prefix()   const { return _items[_scp_prefix]; }
   251   inline const char* get_suffix()   const { return _items[_scp_suffix]; }
   252   inline const char* get_endorsed() const { return _items[_scp_endorsed]; }
   254   // Combine all the components into a single c-heap-allocated string; caller
   255   // must free the string if/when no longer needed.
   256   char* combined_path();
   258 private:
   259   // Utility routines.
   260   static char* add_to_path(const char* path, const char* str, bool prepend);
   261   static char* add_jars_to_path(char* path, const char* directory);
   263   inline void reset_item_at(int index);
   265   // Array indices for the items that make up the sysclasspath.  All except the
   266   // base are allocated in the C heap and freed by this class.
   267   enum {
   268     _scp_prefix,        // from -Xbootclasspath/p:...
   269     _scp_endorsed,      // the expansion of -Djava.endorsed.dirs=...
   270     _scp_base,          // the default sysclasspath
   271     _scp_suffix,        // from -Xbootclasspath/a:...
   272     _scp_nitems         // the number of items, must be last.
   273   };
   275   const char* _items[_scp_nitems];
   276   DEBUG_ONLY(bool _expansion_done;)
   277 };
   279 SysClassPath::SysClassPath(const char* base) {
   280   memset(_items, 0, sizeof(_items));
   281   _items[_scp_base] = base;
   282   DEBUG_ONLY(_expansion_done = false;)
   283 }
   285 SysClassPath::~SysClassPath() {
   286   // Free everything except the base.
   287   for (int i = 0; i < _scp_nitems; ++i) {
   288     if (i != _scp_base) reset_item_at(i);
   289   }
   290   DEBUG_ONLY(_expansion_done = false;)
   291 }
   293 inline void SysClassPath::set_base(const char* base) {
   294   _items[_scp_base] = base;
   295 }
   297 inline void SysClassPath::add_prefix(const char* prefix) {
   298   _items[_scp_prefix] = add_to_path(_items[_scp_prefix], prefix, true);
   299 }
   301 inline void SysClassPath::add_suffix_to_prefix(const char* suffix) {
   302   _items[_scp_prefix] = add_to_path(_items[_scp_prefix], suffix, false);
   303 }
   305 inline void SysClassPath::add_suffix(const char* suffix) {
   306   _items[_scp_suffix] = add_to_path(_items[_scp_suffix], suffix, false);
   307 }
   309 inline void SysClassPath::reset_item_at(int index) {
   310   assert(index < _scp_nitems && index != _scp_base, "just checking");
   311   if (_items[index] != NULL) {
   312     FREE_C_HEAP_ARRAY(char, _items[index]);
   313     _items[index] = NULL;
   314   }
   315 }
   317 inline void SysClassPath::reset_path(const char* base) {
   318   // Clear the prefix and suffix.
   319   reset_item_at(_scp_prefix);
   320   reset_item_at(_scp_suffix);
   321   set_base(base);
   322 }
   324 //------------------------------------------------------------------------------
   326 void SysClassPath::expand_endorsed() {
   327   assert(_items[_scp_endorsed] == NULL, "can only be called once.");
   329   const char* path = Arguments::get_property("java.endorsed.dirs");
   330   if (path == NULL) {
   331     path = Arguments::get_endorsed_dir();
   332     assert(path != NULL, "no default for java.endorsed.dirs");
   333   }
   335   char* expanded_path = NULL;
   336   const char separator = *os::path_separator();
   337   const char* const end = path + strlen(path);
   338   while (path < end) {
   339     const char* tmp_end = strchr(path, separator);
   340     if (tmp_end == NULL) {
   341       expanded_path = add_jars_to_path(expanded_path, path);
   342       path = end;
   343     } else {
   344       char* dirpath = NEW_C_HEAP_ARRAY(char, tmp_end - path + 1);
   345       memcpy(dirpath, path, tmp_end - path);
   346       dirpath[tmp_end - path] = '\0';
   347       expanded_path = add_jars_to_path(expanded_path, dirpath);
   348       FREE_C_HEAP_ARRAY(char, dirpath);
   349       path = tmp_end + 1;
   350     }
   351   }
   352   _items[_scp_endorsed] = expanded_path;
   353   DEBUG_ONLY(_expansion_done = true;)
   354 }
   356 // Combine the bootclasspath elements, some of which may be null, into a single
   357 // c-heap-allocated string.
   358 char* SysClassPath::combined_path() {
   359   assert(_items[_scp_base] != NULL, "empty default sysclasspath");
   360   assert(_expansion_done, "must call expand_endorsed() first.");
   362   size_t lengths[_scp_nitems];
   363   size_t total_len = 0;
   365   const char separator = *os::path_separator();
   367   // Get the lengths.
   368   int i;
   369   for (i = 0; i < _scp_nitems; ++i) {
   370     if (_items[i] != NULL) {
   371       lengths[i] = strlen(_items[i]);
   372       // Include space for the separator char (or a NULL for the last item).
   373       total_len += lengths[i] + 1;
   374     }
   375   }
   376   assert(total_len > 0, "empty sysclasspath not allowed");
   378   // Copy the _items to a single string.
   379   char* cp = NEW_C_HEAP_ARRAY(char, total_len);
   380   char* cp_tmp = cp;
   381   for (i = 0; i < _scp_nitems; ++i) {
   382     if (_items[i] != NULL) {
   383       memcpy(cp_tmp, _items[i], lengths[i]);
   384       cp_tmp += lengths[i];
   385       *cp_tmp++ = separator;
   386     }
   387   }
   388   *--cp_tmp = '\0';     // Replace the extra separator.
   389   return cp;
   390 }
   392 // Note:  path must be c-heap-allocated (or NULL); it is freed if non-null.
   393 char*
   394 SysClassPath::add_to_path(const char* path, const char* str, bool prepend) {
   395   char *cp;
   397   assert(str != NULL, "just checking");
   398   if (path == NULL) {
   399     size_t len = strlen(str) + 1;
   400     cp = NEW_C_HEAP_ARRAY(char, len);
   401     memcpy(cp, str, len);                       // copy the trailing null
   402   } else {
   403     const char separator = *os::path_separator();
   404     size_t old_len = strlen(path);
   405     size_t str_len = strlen(str);
   406     size_t len = old_len + str_len + 2;
   408     if (prepend) {
   409       cp = NEW_C_HEAP_ARRAY(char, len);
   410       char* cp_tmp = cp;
   411       memcpy(cp_tmp, str, str_len);
   412       cp_tmp += str_len;
   413       *cp_tmp = separator;
   414       memcpy(++cp_tmp, path, old_len + 1);      // copy the trailing null
   415       FREE_C_HEAP_ARRAY(char, path);
   416     } else {
   417       cp = REALLOC_C_HEAP_ARRAY(char, path, len);
   418       char* cp_tmp = cp + old_len;
   419       *cp_tmp = separator;
   420       memcpy(++cp_tmp, str, str_len + 1);       // copy the trailing null
   421     }
   422   }
   423   return cp;
   424 }
   426 // Scan the directory and append any jar or zip files found to path.
   427 // Note:  path must be c-heap-allocated (or NULL); it is freed if non-null.
   428 char* SysClassPath::add_jars_to_path(char* path, const char* directory) {
   429   DIR* dir = os::opendir(directory);
   430   if (dir == NULL) return path;
   432   char dir_sep[2] = { '\0', '\0' };
   433   size_t directory_len = strlen(directory);
   434   const char fileSep = *os::file_separator();
   435   if (directory[directory_len - 1] != fileSep) dir_sep[0] = fileSep;
   437   /* Scan the directory for jars/zips, appending them to path. */
   438   struct dirent *entry;
   439   char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory));
   440   while ((entry = os::readdir(dir, (dirent *) dbuf)) != NULL) {
   441     const char* name = entry->d_name;
   442     const char* ext = name + strlen(name) - 4;
   443     bool isJarOrZip = ext > name &&
   444       (os::file_name_strcmp(ext, ".jar") == 0 ||
   445        os::file_name_strcmp(ext, ".zip") == 0);
   446     if (isJarOrZip) {
   447       char* jarpath = NEW_C_HEAP_ARRAY(char, directory_len + 2 + strlen(name));
   448       sprintf(jarpath, "%s%s%s", directory, dir_sep, name);
   449       path = add_to_path(path, jarpath, false);
   450       FREE_C_HEAP_ARRAY(char, jarpath);
   451     }
   452   }
   453   FREE_C_HEAP_ARRAY(char, dbuf);
   454   os::closedir(dir);
   455   return path;
   456 }
   458 // Parses a memory size specification string.
   459 static bool atomull(const char *s, julong* result) {
   460   julong n = 0;
   461   int args_read = sscanf(s, os::julong_format_specifier(), &n);
   462   if (args_read != 1) {
   463     return false;
   464   }
   465   while (*s != '\0' && isdigit(*s)) {
   466     s++;
   467   }
   468   // 4705540: illegal if more characters are found after the first non-digit
   469   if (strlen(s) > 1) {
   470     return false;
   471   }
   472   switch (*s) {
   473     case 'T': case 't':
   474       *result = n * G * K;
   475       // Check for overflow.
   476       if (*result/((julong)G * K) != n) return false;
   477       return true;
   478     case 'G': case 'g':
   479       *result = n * G;
   480       if (*result/G != n) return false;
   481       return true;
   482     case 'M': case 'm':
   483       *result = n * M;
   484       if (*result/M != n) return false;
   485       return true;
   486     case 'K': case 'k':
   487       *result = n * K;
   488       if (*result/K != n) return false;
   489       return true;
   490     case '\0':
   491       *result = n;
   492       return true;
   493     default:
   494       return false;
   495   }
   496 }
   498 Arguments::ArgsRange Arguments::check_memory_size(julong size, julong min_size) {
   499   if (size < min_size) return arg_too_small;
   500   // Check that size will fit in a size_t (only relevant on 32-bit)
   501   if (size > max_uintx) return arg_too_big;
   502   return arg_in_range;
   503 }
   505 // Describe an argument out of range error
   506 void Arguments::describe_range_error(ArgsRange errcode) {
   507   switch(errcode) {
   508   case arg_too_big:
   509     jio_fprintf(defaultStream::error_stream(),
   510                 "The specified size exceeds the maximum "
   511                 "representable size.\n");
   512     break;
   513   case arg_too_small:
   514   case arg_unreadable:
   515   case arg_in_range:
   516     // do nothing for now
   517     break;
   518   default:
   519     ShouldNotReachHere();
   520   }
   521 }
   523 static bool set_bool_flag(char* name, bool value, FlagValueOrigin origin) {
   524   return CommandLineFlags::boolAtPut(name, &value, origin);
   525 }
   527 static bool set_fp_numeric_flag(char* name, char* value, FlagValueOrigin origin) {
   528   double v;
   529   if (sscanf(value, "%lf", &v) != 1) {
   530     return false;
   531   }
   533   if (CommandLineFlags::doubleAtPut(name, &v, origin)) {
   534     return true;
   535   }
   536   return false;
   537 }
   539 static bool set_numeric_flag(char* name, char* value, FlagValueOrigin origin) {
   540   julong v;
   541   intx intx_v;
   542   bool is_neg = false;
   543   // Check the sign first since atomull() parses only unsigned values.
   544   if (*value == '-') {
   545     if (!CommandLineFlags::intxAt(name, &intx_v)) {
   546       return false;
   547     }
   548     value++;
   549     is_neg = true;
   550   }
   551   if (!atomull(value, &v)) {
   552     return false;
   553   }
   554   intx_v = (intx) v;
   555   if (is_neg) {
   556     intx_v = -intx_v;
   557   }
   558   if (CommandLineFlags::intxAtPut(name, &intx_v, origin)) {
   559     return true;
   560   }
   561   uintx uintx_v = (uintx) v;
   562   if (!is_neg && CommandLineFlags::uintxAtPut(name, &uintx_v, origin)) {
   563     return true;
   564   }
   565   uint64_t uint64_t_v = (uint64_t) v;
   566   if (!is_neg && CommandLineFlags::uint64_tAtPut(name, &uint64_t_v, origin)) {
   567     return true;
   568   }
   569   return false;
   570 }
   572 static bool set_string_flag(char* name, const char* value, FlagValueOrigin origin) {
   573   if (!CommandLineFlags::ccstrAtPut(name, &value, origin))  return false;
   574   // Contract:  CommandLineFlags always returns a pointer that needs freeing.
   575   FREE_C_HEAP_ARRAY(char, value);
   576   return true;
   577 }
   579 static bool append_to_string_flag(char* name, const char* new_value, FlagValueOrigin origin) {
   580   const char* old_value = "";
   581   if (!CommandLineFlags::ccstrAt(name, &old_value))  return false;
   582   size_t old_len = old_value != NULL ? strlen(old_value) : 0;
   583   size_t new_len = strlen(new_value);
   584   const char* value;
   585   char* free_this_too = NULL;
   586   if (old_len == 0) {
   587     value = new_value;
   588   } else if (new_len == 0) {
   589     value = old_value;
   590   } else {
   591     char* buf = NEW_C_HEAP_ARRAY(char, old_len + 1 + new_len + 1);
   592     // each new setting adds another LINE to the switch:
   593     sprintf(buf, "%s\n%s", old_value, new_value);
   594     value = buf;
   595     free_this_too = buf;
   596   }
   597   (void) CommandLineFlags::ccstrAtPut(name, &value, origin);
   598   // CommandLineFlags always returns a pointer that needs freeing.
   599   FREE_C_HEAP_ARRAY(char, value);
   600   if (free_this_too != NULL) {
   601     // CommandLineFlags made its own copy, so I must delete my own temp. buffer.
   602     FREE_C_HEAP_ARRAY(char, free_this_too);
   603   }
   604   return true;
   605 }
   607 bool Arguments::parse_argument(const char* arg, FlagValueOrigin origin) {
   609   // range of acceptable characters spelled out for portability reasons
   610 #define NAME_RANGE  "[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]"
   611 #define BUFLEN 255
   612   char name[BUFLEN+1];
   613   char dummy;
   615   if (sscanf(arg, "-%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
   616     return set_bool_flag(name, false, origin);
   617   }
   618   if (sscanf(arg, "+%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
   619     return set_bool_flag(name, true, origin);
   620   }
   622   char punct;
   623   if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "%c", name, &punct) == 2 && punct == '=') {
   624     const char* value = strchr(arg, '=') + 1;
   625     Flag* flag = Flag::find_flag(name, strlen(name));
   626     if (flag != NULL && flag->is_ccstr()) {
   627       if (flag->ccstr_accumulates()) {
   628         return append_to_string_flag(name, value, origin);
   629       } else {
   630         if (value[0] == '\0') {
   631           value = NULL;
   632         }
   633         return set_string_flag(name, value, origin);
   634       }
   635     }
   636   }
   638   if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE ":%c", name, &punct) == 2 && punct == '=') {
   639     const char* value = strchr(arg, '=') + 1;
   640     // -XX:Foo:=xxx will reset the string flag to the given value.
   641     if (value[0] == '\0') {
   642       value = NULL;
   643     }
   644     return set_string_flag(name, value, origin);
   645   }
   647 #define SIGNED_FP_NUMBER_RANGE "[-0123456789.]"
   648 #define SIGNED_NUMBER_RANGE    "[-0123456789]"
   649 #define        NUMBER_RANGE    "[0123456789]"
   650   char value[BUFLEN + 1];
   651   char value2[BUFLEN + 1];
   652   if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_NUMBER_RANGE "." "%" XSTR(BUFLEN) NUMBER_RANGE "%c", name, value, value2, &dummy) == 3) {
   653     // Looks like a floating-point number -- try again with more lenient format string
   654     if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_FP_NUMBER_RANGE "%c", name, value, &dummy) == 2) {
   655       return set_fp_numeric_flag(name, value, origin);
   656     }
   657   }
   659 #define VALUE_RANGE "[-kmgtKMGT0123456789]"
   660   if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) VALUE_RANGE "%c", name, value, &dummy) == 2) {
   661     return set_numeric_flag(name, value, origin);
   662   }
   664   return false;
   665 }
   667 void Arguments::add_string(char*** bldarray, int* count, const char* arg) {
   668   assert(bldarray != NULL, "illegal argument");
   670   if (arg == NULL) {
   671     return;
   672   }
   674   int index = *count;
   676   // expand the array and add arg to the last element
   677   (*count)++;
   678   if (*bldarray == NULL) {
   679     *bldarray = NEW_C_HEAP_ARRAY(char*, *count);
   680   } else {
   681     *bldarray = REALLOC_C_HEAP_ARRAY(char*, *bldarray, *count);
   682   }
   683   (*bldarray)[index] = strdup(arg);
   684 }
   686 void Arguments::build_jvm_args(const char* arg) {
   687   add_string(&_jvm_args_array, &_num_jvm_args, arg);
   688 }
   690 void Arguments::build_jvm_flags(const char* arg) {
   691   add_string(&_jvm_flags_array, &_num_jvm_flags, arg);
   692 }
   694 // utility function to return a string that concatenates all
   695 // strings in a given char** array
   696 const char* Arguments::build_resource_string(char** args, int count) {
   697   if (args == NULL || count == 0) {
   698     return NULL;
   699   }
   700   size_t length = strlen(args[0]) + 1; // add 1 for the null terminator
   701   for (int i = 1; i < count; i++) {
   702     length += strlen(args[i]) + 1; // add 1 for a space
   703   }
   704   char* s = NEW_RESOURCE_ARRAY(char, length);
   705   strcpy(s, args[0]);
   706   for (int j = 1; j < count; j++) {
   707     strcat(s, " ");
   708     strcat(s, args[j]);
   709   }
   710   return (const char*) s;
   711 }
   713 void Arguments::print_on(outputStream* st) {
   714   st->print_cr("VM Arguments:");
   715   if (num_jvm_flags() > 0) {
   716     st->print("jvm_flags: "); print_jvm_flags_on(st);
   717   }
   718   if (num_jvm_args() > 0) {
   719     st->print("jvm_args: "); print_jvm_args_on(st);
   720   }
   721   st->print_cr("java_command: %s", java_command() ? java_command() : "<unknown>");
   722   st->print_cr("Launcher Type: %s", _sun_java_launcher);
   723 }
   725 void Arguments::print_jvm_flags_on(outputStream* st) {
   726   if (_num_jvm_flags > 0) {
   727     for (int i=0; i < _num_jvm_flags; i++) {
   728       st->print("%s ", _jvm_flags_array[i]);
   729     }
   730     st->print_cr("");
   731   }
   732 }
   734 void Arguments::print_jvm_args_on(outputStream* st) {
   735   if (_num_jvm_args > 0) {
   736     for (int i=0; i < _num_jvm_args; i++) {
   737       st->print("%s ", _jvm_args_array[i]);
   738     }
   739     st->print_cr("");
   740   }
   741 }
   743 bool Arguments::process_argument(const char* arg,
   744     jboolean ignore_unrecognized, FlagValueOrigin origin) {
   746   JDK_Version since = JDK_Version();
   748   if (parse_argument(arg, origin)) {
   749     // do nothing
   750   } else if (is_newly_obsolete(arg, &since)) {
   751     enum { bufsize = 256 };
   752     char buffer[bufsize];
   753     since.to_string(buffer, bufsize);
   754     jio_fprintf(defaultStream::error_stream(),
   755       "Warning: The flag %s has been EOL'd as of %s and will"
   756       " be ignored\n", arg, buffer);
   757   } else {
   758     if (!ignore_unrecognized) {
   759       jio_fprintf(defaultStream::error_stream(),
   760                   "Unrecognized VM option '%s'\n", arg);
   761       // allow for commandline "commenting out" options like -XX:#+Verbose
   762       if (strlen(arg) == 0 || arg[0] != '#') {
   763         return false;
   764       }
   765     }
   766   }
   767   return true;
   768 }
   770 bool Arguments::process_settings_file(const char* file_name, bool should_exist, jboolean ignore_unrecognized) {
   771   FILE* stream = fopen(file_name, "rb");
   772   if (stream == NULL) {
   773     if (should_exist) {
   774       jio_fprintf(defaultStream::error_stream(),
   775                   "Could not open settings file %s\n", file_name);
   776       return false;
   777     } else {
   778       return true;
   779     }
   780   }
   782   char token[1024];
   783   int  pos = 0;
   785   bool in_white_space = true;
   786   bool in_comment     = false;
   787   bool in_quote       = false;
   788   char quote_c        = 0;
   789   bool result         = true;
   791   int c = getc(stream);
   792   while(c != EOF) {
   793     if (in_white_space) {
   794       if (in_comment) {
   795         if (c == '\n') in_comment = false;
   796       } else {
   797         if (c == '#') in_comment = true;
   798         else if (!isspace(c)) {
   799           in_white_space = false;
   800           token[pos++] = c;
   801         }
   802       }
   803     } else {
   804       if (c == '\n' || (!in_quote && isspace(c))) {
   805         // token ends at newline, or at unquoted whitespace
   806         // this allows a way to include spaces in string-valued options
   807         token[pos] = '\0';
   808         logOption(token);
   809         result &= process_argument(token, ignore_unrecognized, CONFIG_FILE);
   810         build_jvm_flags(token);
   811         pos = 0;
   812         in_white_space = true;
   813         in_quote = false;
   814       } else if (!in_quote && (c == '\'' || c == '"')) {
   815         in_quote = true;
   816         quote_c = c;
   817       } else if (in_quote && (c == quote_c)) {
   818         in_quote = false;
   819       } else {
   820         token[pos++] = c;
   821       }
   822     }
   823     c = getc(stream);
   824   }
   825   if (pos > 0) {
   826     token[pos] = '\0';
   827     result &= process_argument(token, ignore_unrecognized, CONFIG_FILE);
   828     build_jvm_flags(token);
   829   }
   830   fclose(stream);
   831   return result;
   832 }
   834 //=============================================================================================================
   835 // Parsing of properties (-D)
   837 const char* Arguments::get_property(const char* key) {
   838   return PropertyList_get_value(system_properties(), key);
   839 }
   841 bool Arguments::add_property(const char* prop) {
   842   const char* eq = strchr(prop, '=');
   843   char* key;
   844   // ns must be static--its address may be stored in a SystemProperty object.
   845   const static char ns[1] = {0};
   846   char* value = (char *)ns;
   848   size_t key_len = (eq == NULL) ? strlen(prop) : (eq - prop);
   849   key = AllocateHeap(key_len + 1, "add_property");
   850   strncpy(key, prop, key_len);
   851   key[key_len] = '\0';
   853   if (eq != NULL) {
   854     size_t value_len = strlen(prop) - key_len - 1;
   855     value = AllocateHeap(value_len + 1, "add_property");
   856     strncpy(value, &prop[key_len + 1], value_len + 1);
   857   }
   859   if (strcmp(key, "java.compiler") == 0) {
   860     process_java_compiler_argument(value);
   861     FreeHeap(key);
   862     if (eq != NULL) {
   863       FreeHeap(value);
   864     }
   865     return true;
   866   } else if (strcmp(key, "sun.java.command") == 0) {
   867     _java_command = value;
   869     // don't add this property to the properties exposed to the java application
   870     FreeHeap(key);
   871     return true;
   872   } else if (strcmp(key, "sun.java.launcher.pid") == 0) {
   873     // launcher.pid property is private and is processed
   874     // in process_sun_java_launcher_properties();
   875     // the sun.java.launcher property is passed on to the java application
   876     FreeHeap(key);
   877     if (eq != NULL) {
   878       FreeHeap(value);
   879     }
   880     return true;
   881   } else if (strcmp(key, "java.vendor.url.bug") == 0) {
   882     // save it in _java_vendor_url_bug, so JVM fatal error handler can access
   883     // its value without going through the property list or making a Java call.
   884     _java_vendor_url_bug = value;
   885   } else if (strcmp(key, "sun.boot.library.path") == 0) {
   886     PropertyList_unique_add(&_system_properties, key, value, true);
   887     return true;
   888   }
   889   // Create new property and add at the end of the list
   890   PropertyList_unique_add(&_system_properties, key, value);
   891   return true;
   892 }
   894 //===========================================================================================================
   895 // Setting int/mixed/comp mode flags
   897 void Arguments::set_mode_flags(Mode mode) {
   898   // Set up default values for all flags.
   899   // If you add a flag to any of the branches below,
   900   // add a default value for it here.
   901   set_java_compiler(false);
   902   _mode                      = mode;
   904   // Ensure Agent_OnLoad has the correct initial values.
   905   // This may not be the final mode; mode may change later in onload phase.
   906   PropertyList_unique_add(&_system_properties, "java.vm.info",
   907                           (char*)Abstract_VM_Version::vm_info_string(), false);
   909   UseInterpreter             = true;
   910   UseCompiler                = true;
   911   UseLoopCounter             = true;
   913   // Default values may be platform/compiler dependent -
   914   // use the saved values
   915   ClipInlining               = Arguments::_ClipInlining;
   916   AlwaysCompileLoopMethods   = Arguments::_AlwaysCompileLoopMethods;
   917   UseOnStackReplacement      = Arguments::_UseOnStackReplacement;
   918   BackgroundCompilation      = Arguments::_BackgroundCompilation;
   920   // Change from defaults based on mode
   921   switch (mode) {
   922   default:
   923     ShouldNotReachHere();
   924     break;
   925   case _int:
   926     UseCompiler              = false;
   927     UseLoopCounter           = false;
   928     AlwaysCompileLoopMethods = false;
   929     UseOnStackReplacement    = false;
   930     break;
   931   case _mixed:
   932     // same as default
   933     break;
   934   case _comp:
   935     UseInterpreter           = false;
   936     BackgroundCompilation    = false;
   937     ClipInlining             = false;
   938     break;
   939   }
   940 }
   942 // Conflict: required to use shared spaces (-Xshare:on), but
   943 // incompatible command line options were chosen.
   945 static void no_shared_spaces() {
   946   if (RequireSharedSpaces) {
   947     jio_fprintf(defaultStream::error_stream(),
   948       "Class data sharing is inconsistent with other specified options.\n");
   949     vm_exit_during_initialization("Unable to use shared archive.", NULL);
   950   } else {
   951     FLAG_SET_DEFAULT(UseSharedSpaces, false);
   952   }
   953 }
   955 void Arguments::set_tiered_flags() {
   956   if (FLAG_IS_DEFAULT(CompilationPolicyChoice)) {
   957     FLAG_SET_DEFAULT(CompilationPolicyChoice, 2);
   958   }
   960   if (CompilationPolicyChoice < 2) {
   961     vm_exit_during_initialization(
   962       "Incompatible compilation policy selected", NULL);
   963   }
   965 #ifdef _LP64
   966   if (FLAG_IS_DEFAULT(UseCompressedOops) || FLAG_IS_ERGO(UseCompressedOops)) {
   967     UseCompressedOops = false;
   968   }
   969   if (UseCompressedOops) {
   970     vm_exit_during_initialization(
   971       "Tiered compilation is not supported with compressed oops yet", NULL);
   972   }
   973 #endif
   974  // Increase the code cache size - tiered compiles a lot more.
   975   if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) {
   976     FLAG_SET_DEFAULT(ReservedCodeCacheSize, ReservedCodeCacheSize * 2);
   977   }
   978 }
   980 #ifndef KERNEL
   981 // If the user has chosen ParallelGCThreads > 0, we set UseParNewGC
   982 // if it's not explictly set or unset. If the user has chosen
   983 // UseParNewGC and not explicitly set ParallelGCThreads we
   984 // set it, unless this is a single cpu machine.
   985 void Arguments::set_parnew_gc_flags() {
   986   assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC && !UseG1GC,
   987          "control point invariant");
   988   assert(UseParNewGC, "Error");
   990   // Turn off AdaptiveSizePolicy by default for parnew until it is
   991   // complete.
   992   if (FLAG_IS_DEFAULT(UseAdaptiveSizePolicy)) {
   993     FLAG_SET_DEFAULT(UseAdaptiveSizePolicy, false);
   994   }
   996   if (ParallelGCThreads == 0) {
   997     FLAG_SET_DEFAULT(ParallelGCThreads,
   998                      Abstract_VM_Version::parallel_worker_threads());
   999     if (ParallelGCThreads == 1) {
  1000       FLAG_SET_DEFAULT(UseParNewGC, false);
  1001       FLAG_SET_DEFAULT(ParallelGCThreads, 0);
  1004   if (UseParNewGC) {
  1005     // CDS doesn't work with ParNew yet
  1006     no_shared_spaces();
  1008     // By default YoungPLABSize and OldPLABSize are set to 4096 and 1024 respectively,
  1009     // these settings are default for Parallel Scavenger. For ParNew+Tenured configuration
  1010     // we set them to 1024 and 1024.
  1011     // See CR 6362902.
  1012     if (FLAG_IS_DEFAULT(YoungPLABSize)) {
  1013       FLAG_SET_DEFAULT(YoungPLABSize, (intx)1024);
  1015     if (FLAG_IS_DEFAULT(OldPLABSize)) {
  1016       FLAG_SET_DEFAULT(OldPLABSize, (intx)1024);
  1019     // AlwaysTenure flag should make ParNew promote all at first collection.
  1020     // See CR 6362902.
  1021     if (AlwaysTenure) {
  1022       FLAG_SET_CMDLINE(intx, MaxTenuringThreshold, 0);
  1024     // When using compressed oops, we use local overflow stacks,
  1025     // rather than using a global overflow list chained through
  1026     // the klass word of the object's pre-image.
  1027     if (UseCompressedOops && !ParGCUseLocalOverflow) {
  1028       if (!FLAG_IS_DEFAULT(ParGCUseLocalOverflow)) {
  1029         warning("Forcing +ParGCUseLocalOverflow: needed if using compressed references");
  1031       FLAG_SET_DEFAULT(ParGCUseLocalOverflow, true);
  1033     assert(ParGCUseLocalOverflow || !UseCompressedOops, "Error");
  1037 // Adjust some sizes to suit CMS and/or ParNew needs; these work well on
  1038 // sparc/solaris for certain applications, but would gain from
  1039 // further optimization and tuning efforts, and would almost
  1040 // certainly gain from analysis of platform and environment.
  1041 void Arguments::set_cms_and_parnew_gc_flags() {
  1042   assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC, "Error");
  1043   assert(UseConcMarkSweepGC, "CMS is expected to be on here");
  1045   // If we are using CMS, we prefer to UseParNewGC,
  1046   // unless explicitly forbidden.
  1047   if (FLAG_IS_DEFAULT(UseParNewGC)) {
  1048     FLAG_SET_ERGO(bool, UseParNewGC, true);
  1051   // Turn off AdaptiveSizePolicy by default for cms until it is
  1052   // complete.
  1053   if (FLAG_IS_DEFAULT(UseAdaptiveSizePolicy)) {
  1054     FLAG_SET_DEFAULT(UseAdaptiveSizePolicy, false);
  1057   // In either case, adjust ParallelGCThreads and/or UseParNewGC
  1058   // as needed.
  1059   if (UseParNewGC) {
  1060     set_parnew_gc_flags();
  1063   // Now make adjustments for CMS
  1064   size_t young_gen_per_worker;
  1065   intx new_ratio;
  1066   size_t min_new_default;
  1067   intx tenuring_default;
  1068   if (CMSUseOldDefaults) {  // old defaults: "old" as of 6.0
  1069     if FLAG_IS_DEFAULT(CMSYoungGenPerWorker) {
  1070       FLAG_SET_ERGO(intx, CMSYoungGenPerWorker, 4*M);
  1072     young_gen_per_worker = 4*M;
  1073     new_ratio = (intx)15;
  1074     min_new_default = 4*M;
  1075     tenuring_default = (intx)0;
  1076   } else { // new defaults: "new" as of 6.0
  1077     young_gen_per_worker = CMSYoungGenPerWorker;
  1078     new_ratio = (intx)7;
  1079     min_new_default = 16*M;
  1080     tenuring_default = (intx)4;
  1083   // Preferred young gen size for "short" pauses
  1084   const uintx parallel_gc_threads =
  1085     (ParallelGCThreads == 0 ? 1 : ParallelGCThreads);
  1086   const size_t preferred_max_new_size_unaligned =
  1087     ScaleForWordSize(young_gen_per_worker * parallel_gc_threads);
  1088   const size_t preferred_max_new_size =
  1089     align_size_up(preferred_max_new_size_unaligned, os::vm_page_size());
  1091   // Unless explicitly requested otherwise, size young gen
  1092   // for "short" pauses ~ 4M*ParallelGCThreads
  1094   // If either MaxNewSize or NewRatio is set on the command line,
  1095   // assume the user is trying to set the size of the young gen.
  1097   if (FLAG_IS_DEFAULT(MaxNewSize) && FLAG_IS_DEFAULT(NewRatio)) {
  1099     // Set MaxNewSize to our calculated preferred_max_new_size unless
  1100     // NewSize was set on the command line and it is larger than
  1101     // preferred_max_new_size.
  1102     if (!FLAG_IS_DEFAULT(NewSize)) {   // NewSize explicitly set at command-line
  1103       FLAG_SET_ERGO(uintx, MaxNewSize, MAX2(NewSize, preferred_max_new_size));
  1104     } else {
  1105       FLAG_SET_ERGO(uintx, MaxNewSize, preferred_max_new_size);
  1107     if (PrintGCDetails && Verbose) {
  1108       // Too early to use gclog_or_tty
  1109       tty->print_cr("Ergo set MaxNewSize: " SIZE_FORMAT, MaxNewSize);
  1112     // Unless explicitly requested otherwise, prefer a large
  1113     // Old to Young gen size so as to shift the collection load
  1114     // to the old generation concurrent collector
  1116     // If this is only guarded by FLAG_IS_DEFAULT(NewRatio)
  1117     // then NewSize and OldSize may be calculated.  That would
  1118     // generally lead to some differences with ParNewGC for which
  1119     // there was no obvious reason.  Also limit to the case where
  1120     // MaxNewSize has not been set.
  1122     FLAG_SET_ERGO(intx, NewRatio, MAX2(NewRatio, new_ratio));
  1124     // Code along this path potentially sets NewSize and OldSize
  1126     // Calculate the desired minimum size of the young gen but if
  1127     // NewSize has been set on the command line, use it here since
  1128     // it should be the final value.
  1129     size_t min_new;
  1130     if (FLAG_IS_DEFAULT(NewSize)) {
  1131       min_new = align_size_up(ScaleForWordSize(min_new_default),
  1132                               os::vm_page_size());
  1133     } else {
  1134       min_new = NewSize;
  1136     size_t prev_initial_size = InitialHeapSize;
  1137     if (prev_initial_size != 0 && prev_initial_size < min_new + OldSize) {
  1138       FLAG_SET_ERGO(uintx, InitialHeapSize, min_new + OldSize);
  1139       // Currently minimum size and the initial heap sizes are the same.
  1140       set_min_heap_size(InitialHeapSize);
  1141       if (PrintGCDetails && Verbose) {
  1142         warning("Initial heap size increased to " SIZE_FORMAT " M from "
  1143                 SIZE_FORMAT " M; use -XX:NewSize=... for finer control.",
  1144                 InitialHeapSize/M, prev_initial_size/M);
  1148     // MaxHeapSize is aligned down in collectorPolicy
  1149     size_t max_heap =
  1150       align_size_down(MaxHeapSize,
  1151                       CardTableRS::ct_max_alignment_constraint());
  1153     if (PrintGCDetails && Verbose) {
  1154       // Too early to use gclog_or_tty
  1155       tty->print_cr("CMS set min_heap_size: " SIZE_FORMAT
  1156            " initial_heap_size:  " SIZE_FORMAT
  1157            " max_heap: " SIZE_FORMAT,
  1158            min_heap_size(), InitialHeapSize, max_heap);
  1160     if (max_heap > min_new) {
  1161       // Unless explicitly requested otherwise, make young gen
  1162       // at least min_new, and at most preferred_max_new_size.
  1163       if (FLAG_IS_DEFAULT(NewSize)) {
  1164         FLAG_SET_ERGO(uintx, NewSize, MAX2(NewSize, min_new));
  1165         FLAG_SET_ERGO(uintx, NewSize, MIN2(preferred_max_new_size, NewSize));
  1166         if (PrintGCDetails && Verbose) {
  1167           // Too early to use gclog_or_tty
  1168           tty->print_cr("Ergo set NewSize: " SIZE_FORMAT, NewSize);
  1171       // Unless explicitly requested otherwise, size old gen
  1172       // so that it's at least 3X of NewSize to begin with;
  1173       // later NewRatio will decide how it grows; see above.
  1174       if (FLAG_IS_DEFAULT(OldSize)) {
  1175         if (max_heap > NewSize) {
  1176           FLAG_SET_ERGO(uintx, OldSize, MIN2(3*NewSize, max_heap - NewSize));
  1177           if (PrintGCDetails && Verbose) {
  1178             // Too early to use gclog_or_tty
  1179             tty->print_cr("Ergo set OldSize: " SIZE_FORMAT, OldSize);
  1185   // Unless explicitly requested otherwise, definitely
  1186   // promote all objects surviving "tenuring_default" scavenges.
  1187   if (FLAG_IS_DEFAULT(MaxTenuringThreshold) &&
  1188       FLAG_IS_DEFAULT(SurvivorRatio)) {
  1189     FLAG_SET_ERGO(intx, MaxTenuringThreshold, tenuring_default);
  1191   // If we decided above (or user explicitly requested)
  1192   // `promote all' (via MaxTenuringThreshold := 0),
  1193   // prefer minuscule survivor spaces so as not to waste
  1194   // space for (non-existent) survivors
  1195   if (FLAG_IS_DEFAULT(SurvivorRatio) && MaxTenuringThreshold == 0) {
  1196     FLAG_SET_ERGO(intx, SurvivorRatio, MAX2((intx)1024, SurvivorRatio));
  1198   // If OldPLABSize is set and CMSParPromoteBlocksToClaim is not,
  1199   // set CMSParPromoteBlocksToClaim equal to OldPLABSize.
  1200   // This is done in order to make ParNew+CMS configuration to work
  1201   // with YoungPLABSize and OldPLABSize options.
  1202   // See CR 6362902.
  1203   if (!FLAG_IS_DEFAULT(OldPLABSize)) {
  1204     if (FLAG_IS_DEFAULT(CMSParPromoteBlocksToClaim)) {
  1205       // OldPLABSize is not the default value but CMSParPromoteBlocksToClaim
  1206       // is.  In this situtation let CMSParPromoteBlocksToClaim follow
  1207       // the value (either from the command line or ergonomics) of
  1208       // OldPLABSize.  Following OldPLABSize is an ergonomics decision.
  1209       FLAG_SET_ERGO(uintx, CMSParPromoteBlocksToClaim, OldPLABSize);
  1210     } else {
  1211       // OldPLABSize and CMSParPromoteBlocksToClaim are both set.
  1212       // CMSParPromoteBlocksToClaim is a collector-specific flag, so
  1213       // we'll let it to take precedence.
  1214       jio_fprintf(defaultStream::error_stream(),
  1215                   "Both OldPLABSize and CMSParPromoteBlocksToClaim"
  1216                   " options are specified for the CMS collector."
  1217                   " CMSParPromoteBlocksToClaim will take precedence.\n");
  1220   if (!FLAG_IS_DEFAULT(ResizeOldPLAB) && !ResizeOldPLAB) {
  1221     // OldPLAB sizing manually turned off: Use a larger default setting,
  1222     // unless it was manually specified. This is because a too-low value
  1223     // will slow down scavenges.
  1224     if (FLAG_IS_DEFAULT(CMSParPromoteBlocksToClaim)) {
  1225       FLAG_SET_ERGO(uintx, CMSParPromoteBlocksToClaim, 50); // default value before 6631166
  1228   // Overwrite OldPLABSize which is the variable we will internally use everywhere.
  1229   FLAG_SET_ERGO(uintx, OldPLABSize, CMSParPromoteBlocksToClaim);
  1230   // If either of the static initialization defaults have changed, note this
  1231   // modification.
  1232   if (!FLAG_IS_DEFAULT(CMSParPromoteBlocksToClaim) || !FLAG_IS_DEFAULT(OldPLABWeight)) {
  1233     CFLS_LAB::modify_initialization(OldPLABSize, OldPLABWeight);
  1235   if (PrintGCDetails && Verbose) {
  1236     tty->print_cr("MarkStackSize: %uk  MarkStackSizeMax: %uk",
  1237       MarkStackSize / K, MarkStackSizeMax / K);
  1238     tty->print_cr("ConcGCThreads: %u", ConcGCThreads);
  1241 #endif // KERNEL
  1243 void set_object_alignment() {
  1244   // Object alignment.
  1245   assert(is_power_of_2(ObjectAlignmentInBytes), "ObjectAlignmentInBytes must be power of 2");
  1246   MinObjAlignmentInBytes     = ObjectAlignmentInBytes;
  1247   assert(MinObjAlignmentInBytes >= HeapWordsPerLong * HeapWordSize, "ObjectAlignmentInBytes value is too small");
  1248   MinObjAlignment            = MinObjAlignmentInBytes / HeapWordSize;
  1249   assert(MinObjAlignmentInBytes == MinObjAlignment * HeapWordSize, "ObjectAlignmentInBytes value is incorrect");
  1250   MinObjAlignmentInBytesMask = MinObjAlignmentInBytes - 1;
  1252   LogMinObjAlignmentInBytes  = exact_log2(ObjectAlignmentInBytes);
  1253   LogMinObjAlignment         = LogMinObjAlignmentInBytes - LogHeapWordSize;
  1255   // Oop encoding heap max
  1256   OopEncodingHeapMax = (uint64_t(max_juint) + 1) << LogMinObjAlignmentInBytes;
  1258 #ifndef KERNEL
  1259   // Set CMS global values
  1260   CompactibleFreeListSpace::set_cms_values();
  1261 #endif // KERNEL
  1264 bool verify_object_alignment() {
  1265   // Object alignment.
  1266   if (!is_power_of_2(ObjectAlignmentInBytes)) {
  1267     jio_fprintf(defaultStream::error_stream(),
  1268                 "error: ObjectAlignmentInBytes=%d must be power of 2\n",
  1269                 (int)ObjectAlignmentInBytes);
  1270     return false;
  1272   if ((int)ObjectAlignmentInBytes < BytesPerLong) {
  1273     jio_fprintf(defaultStream::error_stream(),
  1274                 "error: ObjectAlignmentInBytes=%d must be greater or equal %d\n",
  1275                 (int)ObjectAlignmentInBytes, BytesPerLong);
  1276     return false;
  1278   // It does not make sense to have big object alignment
  1279   // since a space lost due to alignment will be greater
  1280   // then a saved space from compressed oops.
  1281   if ((int)ObjectAlignmentInBytes > 256) {
  1282     jio_fprintf(defaultStream::error_stream(),
  1283                 "error: ObjectAlignmentInBytes=%d must not be greater then 256\n",
  1284                 (int)ObjectAlignmentInBytes);
  1285     return false;
  1287   // In case page size is very small.
  1288   if ((int)ObjectAlignmentInBytes >= os::vm_page_size()) {
  1289     jio_fprintf(defaultStream::error_stream(),
  1290                 "error: ObjectAlignmentInBytes=%d must be less then page size %d\n",
  1291                 (int)ObjectAlignmentInBytes, os::vm_page_size());
  1292     return false;
  1294   return true;
  1297 inline uintx max_heap_for_compressed_oops() {
  1298   // Heap should be above HeapBaseMinAddress to get zero based compressed oops.
  1299   LP64_ONLY(return OopEncodingHeapMax - MaxPermSize - os::vm_page_size() - HeapBaseMinAddress);
  1300   NOT_LP64(ShouldNotReachHere(); return 0);
  1303 bool Arguments::should_auto_select_low_pause_collector() {
  1304   if (UseAutoGCSelectPolicy &&
  1305       !FLAG_IS_DEFAULT(MaxGCPauseMillis) &&
  1306       (MaxGCPauseMillis <= AutoGCSelectPauseMillis)) {
  1307     if (PrintGCDetails) {
  1308       // Cannot use gclog_or_tty yet.
  1309       tty->print_cr("Automatic selection of the low pause collector"
  1310        " based on pause goal of %d (ms)", MaxGCPauseMillis);
  1312     return true;
  1314   return false;
  1317 void Arguments::set_ergonomics_flags() {
  1318   // Parallel GC is not compatible with sharing. If one specifies
  1319   // that they want sharing explicitly, do not set ergonomics flags.
  1320   if (DumpSharedSpaces || ForceSharedSpaces) {
  1321     return;
  1324   if (os::is_server_class_machine() && !force_client_mode ) {
  1325     // If no other collector is requested explicitly,
  1326     // let the VM select the collector based on
  1327     // machine class and automatic selection policy.
  1328     if (!UseSerialGC &&
  1329         !UseConcMarkSweepGC &&
  1330         !UseG1GC &&
  1331         !UseParNewGC &&
  1332         !DumpSharedSpaces &&
  1333         FLAG_IS_DEFAULT(UseParallelGC)) {
  1334       if (should_auto_select_low_pause_collector()) {
  1335         FLAG_SET_ERGO(bool, UseConcMarkSweepGC, true);
  1336       } else {
  1337         FLAG_SET_ERGO(bool, UseParallelGC, true);
  1339       no_shared_spaces();
  1343 #ifndef ZERO
  1344 #ifdef _LP64
  1345   // Check that UseCompressedOops can be set with the max heap size allocated
  1346   // by ergonomics.
  1347   if (MaxHeapSize <= max_heap_for_compressed_oops()) {
  1348 #if !defined(COMPILER1) || defined(TIERED)
  1349     if (FLAG_IS_DEFAULT(UseCompressedOops) && !UseG1GC) {
  1350       FLAG_SET_ERGO(bool, UseCompressedOops, true);
  1352 #endif
  1353 #ifdef _WIN64
  1354     if (UseLargePages && UseCompressedOops) {
  1355       // Cannot allocate guard pages for implicit checks in indexed addressing
  1356       // mode, when large pages are specified on windows.
  1357       // This flag could be switched ON if narrow oop base address is set to 0,
  1358       // see code in Universe::initialize_heap().
  1359       Universe::set_narrow_oop_use_implicit_null_checks(false);
  1361 #endif //  _WIN64
  1362   } else {
  1363     if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) {
  1364       warning("Max heap size too large for Compressed Oops");
  1365       FLAG_SET_DEFAULT(UseCompressedOops, false);
  1368   // Also checks that certain machines are slower with compressed oops
  1369   // in vm_version initialization code.
  1370 #endif // _LP64
  1371 #endif // !ZERO
  1374 void Arguments::set_parallel_gc_flags() {
  1375   assert(UseParallelGC || UseParallelOldGC, "Error");
  1376   // If parallel old was requested, automatically enable parallel scavenge.
  1377   if (UseParallelOldGC && !UseParallelGC && FLAG_IS_DEFAULT(UseParallelGC)) {
  1378     FLAG_SET_DEFAULT(UseParallelGC, true);
  1381   // If no heap maximum was requested explicitly, use some reasonable fraction
  1382   // of the physical memory, up to a maximum of 1GB.
  1383   if (UseParallelGC) {
  1384     FLAG_SET_ERGO(uintx, ParallelGCThreads,
  1385                   Abstract_VM_Version::parallel_worker_threads());
  1387     // If InitialSurvivorRatio or MinSurvivorRatio were not specified, but the
  1388     // SurvivorRatio has been set, reset their default values to SurvivorRatio +
  1389     // 2.  By doing this we make SurvivorRatio also work for Parallel Scavenger.
  1390     // See CR 6362902 for details.
  1391     if (!FLAG_IS_DEFAULT(SurvivorRatio)) {
  1392       if (FLAG_IS_DEFAULT(InitialSurvivorRatio)) {
  1393          FLAG_SET_DEFAULT(InitialSurvivorRatio, SurvivorRatio + 2);
  1395       if (FLAG_IS_DEFAULT(MinSurvivorRatio)) {
  1396         FLAG_SET_DEFAULT(MinSurvivorRatio, SurvivorRatio + 2);
  1400     if (UseParallelOldGC) {
  1401       // Par compact uses lower default values since they are treated as
  1402       // minimums.  These are different defaults because of the different
  1403       // interpretation and are not ergonomically set.
  1404       if (FLAG_IS_DEFAULT(MarkSweepDeadRatio)) {
  1405         FLAG_SET_DEFAULT(MarkSweepDeadRatio, 1);
  1407       if (FLAG_IS_DEFAULT(PermMarkSweepDeadRatio)) {
  1408         FLAG_SET_DEFAULT(PermMarkSweepDeadRatio, 5);
  1414 void Arguments::set_g1_gc_flags() {
  1415   assert(UseG1GC, "Error");
  1416 #ifdef COMPILER1
  1417   FastTLABRefill = false;
  1418 #endif
  1419   FLAG_SET_DEFAULT(ParallelGCThreads,
  1420                      Abstract_VM_Version::parallel_worker_threads());
  1421   if (ParallelGCThreads == 0) {
  1422     FLAG_SET_DEFAULT(ParallelGCThreads,
  1423                      Abstract_VM_Version::parallel_worker_threads());
  1425   no_shared_spaces();
  1427   if (FLAG_IS_DEFAULT(MarkStackSize)) {
  1428     FLAG_SET_DEFAULT(MarkStackSize, 128 * TASKQUEUE_SIZE);
  1430   if (PrintGCDetails && Verbose) {
  1431     tty->print_cr("MarkStackSize: %uk  MarkStackSizeMax: %uk",
  1432       MarkStackSize / K, MarkStackSizeMax / K);
  1433     tty->print_cr("ConcGCThreads: %u", ConcGCThreads);
  1436   if (FLAG_IS_DEFAULT(GCTimeRatio) || GCTimeRatio == 0) {
  1437     // In G1, we want the default GC overhead goal to be higher than
  1438     // say in PS. So we set it here to 10%. Otherwise the heap might
  1439     // be expanded more aggressively than we would like it to. In
  1440     // fact, even 10% seems to not be high enough in some cases
  1441     // (especially small GC stress tests that the main thing they do
  1442     // is allocation). We might consider increase it further.
  1443     FLAG_SET_DEFAULT(GCTimeRatio, 9);
  1447 void Arguments::set_heap_size() {
  1448   if (!FLAG_IS_DEFAULT(DefaultMaxRAMFraction)) {
  1449     // Deprecated flag
  1450     FLAG_SET_CMDLINE(uintx, MaxRAMFraction, DefaultMaxRAMFraction);
  1453   const julong phys_mem =
  1454     FLAG_IS_DEFAULT(MaxRAM) ? MIN2(os::physical_memory(), (julong)MaxRAM)
  1455                             : (julong)MaxRAM;
  1457   // If the maximum heap size has not been set with -Xmx,
  1458   // then set it as fraction of the size of physical memory,
  1459   // respecting the maximum and minimum sizes of the heap.
  1460   if (FLAG_IS_DEFAULT(MaxHeapSize)) {
  1461     julong reasonable_max = phys_mem / MaxRAMFraction;
  1463     if (phys_mem <= MaxHeapSize * MinRAMFraction) {
  1464       // Small physical memory, so use a minimum fraction of it for the heap
  1465       reasonable_max = phys_mem / MinRAMFraction;
  1466     } else {
  1467       // Not-small physical memory, so require a heap at least
  1468       // as large as MaxHeapSize
  1469       reasonable_max = MAX2(reasonable_max, (julong)MaxHeapSize);
  1471     if (!FLAG_IS_DEFAULT(ErgoHeapSizeLimit) && ErgoHeapSizeLimit != 0) {
  1472       // Limit the heap size to ErgoHeapSizeLimit
  1473       reasonable_max = MIN2(reasonable_max, (julong)ErgoHeapSizeLimit);
  1475     if (UseCompressedOops) {
  1476       // Limit the heap size to the maximum possible when using compressed oops
  1477       reasonable_max = MIN2(reasonable_max, (julong)max_heap_for_compressed_oops());
  1479     reasonable_max = os::allocatable_physical_memory(reasonable_max);
  1481     if (!FLAG_IS_DEFAULT(InitialHeapSize)) {
  1482       // An initial heap size was specified on the command line,
  1483       // so be sure that the maximum size is consistent.  Done
  1484       // after call to allocatable_physical_memory because that
  1485       // method might reduce the allocation size.
  1486       reasonable_max = MAX2(reasonable_max, (julong)InitialHeapSize);
  1489     if (PrintGCDetails && Verbose) {
  1490       // Cannot use gclog_or_tty yet.
  1491       tty->print_cr("  Maximum heap size " SIZE_FORMAT, reasonable_max);
  1493     FLAG_SET_ERGO(uintx, MaxHeapSize, (uintx)reasonable_max);
  1496   // If the initial_heap_size has not been set with InitialHeapSize
  1497   // or -Xms, then set it as fraction of the size of physical memory,
  1498   // respecting the maximum and minimum sizes of the heap.
  1499   if (FLAG_IS_DEFAULT(InitialHeapSize)) {
  1500     julong reasonable_minimum = (julong)(OldSize + NewSize);
  1502     reasonable_minimum = MIN2(reasonable_minimum, (julong)MaxHeapSize);
  1504     reasonable_minimum = os::allocatable_physical_memory(reasonable_minimum);
  1506     julong reasonable_initial = phys_mem / InitialRAMFraction;
  1508     reasonable_initial = MAX2(reasonable_initial, reasonable_minimum);
  1509     reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize);
  1511     reasonable_initial = os::allocatable_physical_memory(reasonable_initial);
  1513     if (PrintGCDetails && Verbose) {
  1514       // Cannot use gclog_or_tty yet.
  1515       tty->print_cr("  Initial heap size " SIZE_FORMAT, (uintx)reasonable_initial);
  1516       tty->print_cr("  Minimum heap size " SIZE_FORMAT, (uintx)reasonable_minimum);
  1518     FLAG_SET_ERGO(uintx, InitialHeapSize, (uintx)reasonable_initial);
  1519     set_min_heap_size((uintx)reasonable_minimum);
  1523 // This must be called after ergonomics because we want bytecode rewriting
  1524 // if the server compiler is used, or if UseSharedSpaces is disabled.
  1525 void Arguments::set_bytecode_flags() {
  1526   // Better not attempt to store into a read-only space.
  1527   if (UseSharedSpaces) {
  1528     FLAG_SET_DEFAULT(RewriteBytecodes, false);
  1529     FLAG_SET_DEFAULT(RewriteFrequentPairs, false);
  1532   if (!RewriteBytecodes) {
  1533     FLAG_SET_DEFAULT(RewriteFrequentPairs, false);
  1537 // Aggressive optimization flags  -XX:+AggressiveOpts
  1538 void Arguments::set_aggressive_opts_flags() {
  1539 #ifdef COMPILER2
  1540   if (AggressiveOpts || !FLAG_IS_DEFAULT(AutoBoxCacheMax)) {
  1541     if (FLAG_IS_DEFAULT(EliminateAutoBox)) {
  1542       FLAG_SET_DEFAULT(EliminateAutoBox, true);
  1544     if (FLAG_IS_DEFAULT(AutoBoxCacheMax)) {
  1545       FLAG_SET_DEFAULT(AutoBoxCacheMax, 20000);
  1548     // Feed the cache size setting into the JDK
  1549     char buffer[1024];
  1550     sprintf(buffer, "java.lang.Integer.IntegerCache.high=" INTX_FORMAT, AutoBoxCacheMax);
  1551     add_property(buffer);
  1553   if (AggressiveOpts && FLAG_IS_DEFAULT(DoEscapeAnalysis)) {
  1554     FLAG_SET_DEFAULT(DoEscapeAnalysis, true);
  1556   if (AggressiveOpts && FLAG_IS_DEFAULT(BiasedLockingStartupDelay)) {
  1557     FLAG_SET_DEFAULT(BiasedLockingStartupDelay, 500);
  1559   if (AggressiveOpts && FLAG_IS_DEFAULT(OptimizeStringConcat)) {
  1560     FLAG_SET_DEFAULT(OptimizeStringConcat, true);
  1562   if (AggressiveOpts && FLAG_IS_DEFAULT(OptimizeFill)) {
  1563     FLAG_SET_DEFAULT(OptimizeFill, true);
  1565 #endif
  1567   if (AggressiveOpts) {
  1568 // Sample flag setting code
  1569 //    if (FLAG_IS_DEFAULT(EliminateZeroing)) {
  1570 //      FLAG_SET_DEFAULT(EliminateZeroing, true);
  1571 //    }
  1575 //===========================================================================================================
  1576 // Parsing of java.compiler property
  1578 void Arguments::process_java_compiler_argument(char* arg) {
  1579   // For backwards compatibility, Djava.compiler=NONE or ""
  1580   // causes us to switch to -Xint mode UNLESS -Xdebug
  1581   // is also specified.
  1582   if (strlen(arg) == 0 || strcasecmp(arg, "NONE") == 0) {
  1583     set_java_compiler(true);    // "-Djava.compiler[=...]" most recently seen.
  1587 void Arguments::process_java_launcher_argument(const char* launcher, void* extra_info) {
  1588   _sun_java_launcher = strdup(launcher);
  1591 bool Arguments::created_by_java_launcher() {
  1592   assert(_sun_java_launcher != NULL, "property must have value");
  1593   return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
  1596 //===========================================================================================================
  1597 // Parsing of main arguments
  1599 bool Arguments::verify_interval(uintx val, uintx min,
  1600                                 uintx max, const char* name) {
  1601   // Returns true iff value is in the inclusive interval [min..max]
  1602   // false, otherwise.
  1603   if (val >= min && val <= max) {
  1604     return true;
  1606   jio_fprintf(defaultStream::error_stream(),
  1607               "%s of " UINTX_FORMAT " is invalid; must be between " UINTX_FORMAT
  1608               " and " UINTX_FORMAT "\n",
  1609               name, val, min, max);
  1610   return false;
  1613 bool Arguments::verify_min_value(intx val, intx min, const char* name) {
  1614   // Returns true if given value is greater than specified min threshold
  1615   // false, otherwise.
  1616   if (val >= min ) {
  1617       return true;
  1619   jio_fprintf(defaultStream::error_stream(),
  1620               "%s of " INTX_FORMAT " is invalid; must be greater than " INTX_FORMAT "\n",
  1621               name, val, min);
  1622   return false;
  1625 bool Arguments::verify_percentage(uintx value, const char* name) {
  1626   if (value <= 100) {
  1627     return true;
  1629   jio_fprintf(defaultStream::error_stream(),
  1630               "%s of " UINTX_FORMAT " is invalid; must be between 0 and 100\n",
  1631               name, value);
  1632   return false;
  1635 static void force_serial_gc() {
  1636   FLAG_SET_DEFAULT(UseSerialGC, true);
  1637   FLAG_SET_DEFAULT(UseParNewGC, false);
  1638   FLAG_SET_DEFAULT(UseConcMarkSweepGC, false);
  1639   FLAG_SET_DEFAULT(CMSIncrementalMode, false);  // special CMS suboption
  1640   FLAG_SET_DEFAULT(UseParallelGC, false);
  1641   FLAG_SET_DEFAULT(UseParallelOldGC, false);
  1642   FLAG_SET_DEFAULT(UseG1GC, false);
  1645 static bool verify_serial_gc_flags() {
  1646   return (UseSerialGC &&
  1647         !(UseParNewGC || (UseConcMarkSweepGC || CMSIncrementalMode) || UseG1GC ||
  1648           UseParallelGC || UseParallelOldGC));
  1651 // Check consistency of GC selection
  1652 bool Arguments::check_gc_consistency() {
  1653   bool status = true;
  1654   // Ensure that the user has not selected conflicting sets
  1655   // of collectors. [Note: this check is merely a user convenience;
  1656   // collectors over-ride each other so that only a non-conflicting
  1657   // set is selected; however what the user gets is not what they
  1658   // may have expected from the combination they asked for. It's
  1659   // better to reduce user confusion by not allowing them to
  1660   // select conflicting combinations.
  1661   uint i = 0;
  1662   if (UseSerialGC)                       i++;
  1663   if (UseConcMarkSweepGC || UseParNewGC) i++;
  1664   if (UseParallelGC || UseParallelOldGC) i++;
  1665   if (UseG1GC)                           i++;
  1666   if (i > 1) {
  1667     jio_fprintf(defaultStream::error_stream(),
  1668                 "Conflicting collector combinations in option list; "
  1669                 "please refer to the release notes for the combinations "
  1670                 "allowed\n");
  1671     status = false;
  1674   return status;
  1677 // Check stack pages settings
  1678 bool Arguments::check_stack_pages()
  1680   bool status = true;
  1681   status = status && verify_min_value(StackYellowPages, 1, "StackYellowPages");
  1682   status = status && verify_min_value(StackRedPages, 1, "StackRedPages");
  1683   status = status && verify_min_value(StackShadowPages, 1, "StackShadowPages");
  1684   return status;
  1687 // Check the consistency of vm_init_args
  1688 bool Arguments::check_vm_args_consistency() {
  1689   // Method for adding checks for flag consistency.
  1690   // The intent is to warn the user of all possible conflicts,
  1691   // before returning an error.
  1692   // Note: Needs platform-dependent factoring.
  1693   bool status = true;
  1695 #if ( (defined(COMPILER2) && defined(SPARC)))
  1696   // NOTE: The call to VM_Version_init depends on the fact that VM_Version_init
  1697   // on sparc doesn't require generation of a stub as is the case on, e.g.,
  1698   // x86.  Normally, VM_Version_init must be called from init_globals in
  1699   // init.cpp, which is called by the initial java thread *after* arguments
  1700   // have been parsed.  VM_Version_init gets called twice on sparc.
  1701   extern void VM_Version_init();
  1702   VM_Version_init();
  1703   if (!VM_Version::has_v9()) {
  1704     jio_fprintf(defaultStream::error_stream(),
  1705                 "V8 Machine detected, Server requires V9\n");
  1706     status = false;
  1708 #endif /* COMPILER2 && SPARC */
  1710   // Allow both -XX:-UseStackBanging and -XX:-UseBoundThreads in non-product
  1711   // builds so the cost of stack banging can be measured.
  1712 #if (defined(PRODUCT) && defined(SOLARIS))
  1713   if (!UseBoundThreads && !UseStackBanging) {
  1714     jio_fprintf(defaultStream::error_stream(),
  1715                 "-UseStackBanging conflicts with -UseBoundThreads\n");
  1717      status = false;
  1719 #endif
  1721   if (TLABRefillWasteFraction == 0) {
  1722     jio_fprintf(defaultStream::error_stream(),
  1723                 "TLABRefillWasteFraction should be a denominator, "
  1724                 "not " SIZE_FORMAT "\n",
  1725                 TLABRefillWasteFraction);
  1726     status = false;
  1729   status = status && verify_percentage(AdaptiveSizePolicyWeight,
  1730                               "AdaptiveSizePolicyWeight");
  1731   status = status && verify_percentage(AdaptivePermSizeWeight, "AdaptivePermSizeWeight");
  1732   status = status && verify_percentage(ThresholdTolerance, "ThresholdTolerance");
  1733   status = status && verify_percentage(MinHeapFreeRatio, "MinHeapFreeRatio");
  1734   status = status && verify_percentage(MaxHeapFreeRatio, "MaxHeapFreeRatio");
  1736   if (MinHeapFreeRatio > MaxHeapFreeRatio) {
  1737     jio_fprintf(defaultStream::error_stream(),
  1738                 "MinHeapFreeRatio (" UINTX_FORMAT ") must be less than or "
  1739                 "equal to MaxHeapFreeRatio (" UINTX_FORMAT ")\n",
  1740                 MinHeapFreeRatio, MaxHeapFreeRatio);
  1741     status = false;
  1743   // Keeping the heap 100% free is hard ;-) so limit it to 99%.
  1744   MinHeapFreeRatio = MIN2(MinHeapFreeRatio, (uintx) 99);
  1746   if (FullGCALot && FLAG_IS_DEFAULT(MarkSweepAlwaysCompactCount)) {
  1747     MarkSweepAlwaysCompactCount = 1;  // Move objects every gc.
  1750   if (UseParallelOldGC && ParallelOldGCSplitALot) {
  1751     // Settings to encourage splitting.
  1752     if (!FLAG_IS_CMDLINE(NewRatio)) {
  1753       FLAG_SET_CMDLINE(intx, NewRatio, 2);
  1755     if (!FLAG_IS_CMDLINE(ScavengeBeforeFullGC)) {
  1756       FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
  1760   status = status && verify_percentage(GCHeapFreeLimit, "GCHeapFreeLimit");
  1761   status = status && verify_percentage(GCTimeLimit, "GCTimeLimit");
  1762   if (GCTimeLimit == 100) {
  1763     // Turn off gc-overhead-limit-exceeded checks
  1764     FLAG_SET_DEFAULT(UseGCOverheadLimit, false);
  1767   status = status && verify_percentage(GCHeapFreeLimit, "GCHeapFreeLimit");
  1769   // Check whether user-specified sharing option conflicts with GC or page size.
  1770   // Both sharing and large pages are enabled by default on some platforms;
  1771   // large pages override sharing only if explicitly set on the command line.
  1772   const bool cannot_share = UseConcMarkSweepGC || CMSIncrementalMode ||
  1773           UseG1GC || UseParNewGC || UseParallelGC || UseParallelOldGC ||
  1774           UseLargePages && FLAG_IS_CMDLINE(UseLargePages);
  1775   if (cannot_share) {
  1776     // Either force sharing on by forcing the other options off, or
  1777     // force sharing off.
  1778     if (DumpSharedSpaces || ForceSharedSpaces) {
  1779       jio_fprintf(defaultStream::error_stream(),
  1780                   "Using Serial GC and default page size because of %s\n",
  1781                   ForceSharedSpaces ? "-Xshare:on" : "-Xshare:dump");
  1782       force_serial_gc();
  1783       FLAG_SET_DEFAULT(UseLargePages, false);
  1784     } else {
  1785       if (UseSharedSpaces && Verbose) {
  1786         jio_fprintf(defaultStream::error_stream(),
  1787                     "Turning off use of shared archive because of "
  1788                     "choice of garbage collector or large pages\n");
  1790       no_shared_spaces();
  1792   } else if (UseLargePages && (UseSharedSpaces || DumpSharedSpaces)) {
  1793     FLAG_SET_DEFAULT(UseLargePages, false);
  1796   status = status && check_gc_consistency();
  1797   status = status && check_stack_pages();
  1799   if (_has_alloc_profile) {
  1800     if (UseParallelGC || UseParallelOldGC) {
  1801       jio_fprintf(defaultStream::error_stream(),
  1802                   "error:  invalid argument combination.\n"
  1803                   "Allocation profiling (-Xaprof) cannot be used together with "
  1804                   "Parallel GC (-XX:+UseParallelGC or -XX:+UseParallelOldGC).\n");
  1805       status = false;
  1807     if (UseConcMarkSweepGC) {
  1808       jio_fprintf(defaultStream::error_stream(),
  1809                   "error:  invalid argument combination.\n"
  1810                   "Allocation profiling (-Xaprof) cannot be used together with "
  1811                   "the CMS collector (-XX:+UseConcMarkSweepGC).\n");
  1812       status = false;
  1816   if (CMSIncrementalMode) {
  1817     if (!UseConcMarkSweepGC) {
  1818       jio_fprintf(defaultStream::error_stream(),
  1819                   "error:  invalid argument combination.\n"
  1820                   "The CMS collector (-XX:+UseConcMarkSweepGC) must be "
  1821                   "selected in order\nto use CMSIncrementalMode.\n");
  1822       status = false;
  1823     } else {
  1824       status = status && verify_percentage(CMSIncrementalDutyCycle,
  1825                                   "CMSIncrementalDutyCycle");
  1826       status = status && verify_percentage(CMSIncrementalDutyCycleMin,
  1827                                   "CMSIncrementalDutyCycleMin");
  1828       status = status && verify_percentage(CMSIncrementalSafetyFactor,
  1829                                   "CMSIncrementalSafetyFactor");
  1830       status = status && verify_percentage(CMSIncrementalOffset,
  1831                                   "CMSIncrementalOffset");
  1832       status = status && verify_percentage(CMSExpAvgFactor,
  1833                                   "CMSExpAvgFactor");
  1834       // If it was not set on the command line, set
  1835       // CMSInitiatingOccupancyFraction to 1 so icms can initiate cycles early.
  1836       if (CMSInitiatingOccupancyFraction < 0) {
  1837         FLAG_SET_DEFAULT(CMSInitiatingOccupancyFraction, 1);
  1842   // CMS space iteration, which FLSVerifyAllHeapreferences entails,
  1843   // insists that we hold the requisite locks so that the iteration is
  1844   // MT-safe. For the verification at start-up and shut-down, we don't
  1845   // yet have a good way of acquiring and releasing these locks,
  1846   // which are not visible at the CollectedHeap level. We want to
  1847   // be able to acquire these locks and then do the iteration rather
  1848   // than just disable the lock verification. This will be fixed under
  1849   // bug 4788986.
  1850   if (UseConcMarkSweepGC && FLSVerifyAllHeapReferences) {
  1851     if (VerifyGCStartAt == 0) {
  1852       warning("Heap verification at start-up disabled "
  1853               "(due to current incompatibility with FLSVerifyAllHeapReferences)");
  1854       VerifyGCStartAt = 1;      // Disable verification at start-up
  1856     if (VerifyBeforeExit) {
  1857       warning("Heap verification at shutdown disabled "
  1858               "(due to current incompatibility with FLSVerifyAllHeapReferences)");
  1859       VerifyBeforeExit = false; // Disable verification at shutdown
  1863   // Note: only executed in non-PRODUCT mode
  1864   if (!UseAsyncConcMarkSweepGC &&
  1865       (ExplicitGCInvokesConcurrent ||
  1866        ExplicitGCInvokesConcurrentAndUnloadsClasses)) {
  1867     jio_fprintf(defaultStream::error_stream(),
  1868                 "error: +ExplictGCInvokesConcurrent[AndUnloadsClasses] conflicts"
  1869                 " with -UseAsyncConcMarkSweepGC");
  1870     status = false;
  1873   if (UseG1GC) {
  1874     status = status && verify_percentage(InitiatingHeapOccupancyPercent,
  1875                                          "InitiatingHeapOccupancyPercent");
  1878   status = status && verify_interval(RefDiscoveryPolicy,
  1879                                      ReferenceProcessor::DiscoveryPolicyMin,
  1880                                      ReferenceProcessor::DiscoveryPolicyMax,
  1881                                      "RefDiscoveryPolicy");
  1883   // Limit the lower bound of this flag to 1 as it is used in a division
  1884   // expression.
  1885   status = status && verify_interval(TLABWasteTargetPercent,
  1886                                      1, 100, "TLABWasteTargetPercent");
  1888   status = status && verify_object_alignment();
  1890   return status;
  1893 bool Arguments::is_bad_option(const JavaVMOption* option, jboolean ignore,
  1894   const char* option_type) {
  1895   if (ignore) return false;
  1897   const char* spacer = " ";
  1898   if (option_type == NULL) {
  1899     option_type = ++spacer; // Set both to the empty string.
  1902   if (os::obsolete_option(option)) {
  1903     jio_fprintf(defaultStream::error_stream(),
  1904                 "Obsolete %s%soption: %s\n", option_type, spacer,
  1905       option->optionString);
  1906     return false;
  1907   } else {
  1908     jio_fprintf(defaultStream::error_stream(),
  1909                 "Unrecognized %s%soption: %s\n", option_type, spacer,
  1910       option->optionString);
  1911     return true;
  1915 static const char* user_assertion_options[] = {
  1916   "-da", "-ea", "-disableassertions", "-enableassertions", 0
  1917 };
  1919 static const char* system_assertion_options[] = {
  1920   "-dsa", "-esa", "-disablesystemassertions", "-enablesystemassertions", 0
  1921 };
  1923 // Return true if any of the strings in null-terminated array 'names' matches.
  1924 // If tail_allowed is true, then the tail must begin with a colon; otherwise,
  1925 // the option must match exactly.
  1926 static bool match_option(const JavaVMOption* option, const char** names, const char** tail,
  1927   bool tail_allowed) {
  1928   for (/* empty */; *names != NULL; ++names) {
  1929     if (match_option(option, *names, tail)) {
  1930       if (**tail == '\0' || tail_allowed && **tail == ':') {
  1931         return true;
  1935   return false;
  1938 bool Arguments::parse_uintx(const char* value,
  1939                             uintx* uintx_arg,
  1940                             uintx min_size) {
  1942   // Check the sign first since atomull() parses only unsigned values.
  1943   bool value_is_positive = !(*value == '-');
  1945   if (value_is_positive) {
  1946     julong n;
  1947     bool good_return = atomull(value, &n);
  1948     if (good_return) {
  1949       bool above_minimum = n >= min_size;
  1950       bool value_is_too_large = n > max_uintx;
  1952       if (above_minimum && !value_is_too_large) {
  1953         *uintx_arg = n;
  1954         return true;
  1958   return false;
  1961 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
  1962                                                   julong* long_arg,
  1963                                                   julong min_size) {
  1964   if (!atomull(s, long_arg)) return arg_unreadable;
  1965   return check_memory_size(*long_arg, min_size);
  1968 // Parse JavaVMInitArgs structure
  1970 jint Arguments::parse_vm_init_args(const JavaVMInitArgs* args) {
  1971   // For components of the system classpath.
  1972   SysClassPath scp(Arguments::get_sysclasspath());
  1973   bool scp_assembly_required = false;
  1975   // Save default settings for some mode flags
  1976   Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
  1977   Arguments::_UseOnStackReplacement    = UseOnStackReplacement;
  1978   Arguments::_ClipInlining             = ClipInlining;
  1979   Arguments::_BackgroundCompilation    = BackgroundCompilation;
  1981   // Parse JAVA_TOOL_OPTIONS environment variable (if present)
  1982   jint result = parse_java_tool_options_environment_variable(&scp, &scp_assembly_required);
  1983   if (result != JNI_OK) {
  1984     return result;
  1987   // Parse JavaVMInitArgs structure passed in
  1988   result = parse_each_vm_init_arg(args, &scp, &scp_assembly_required, COMMAND_LINE);
  1989   if (result != JNI_OK) {
  1990     return result;
  1993   if (AggressiveOpts) {
  1994     // Insert alt-rt.jar between user-specified bootclasspath
  1995     // prefix and the default bootclasspath.  os::set_boot_path()
  1996     // uses meta_index_dir as the default bootclasspath directory.
  1997     const char* altclasses_jar = "alt-rt.jar";
  1998     size_t altclasses_path_len = strlen(get_meta_index_dir()) + 1 +
  1999                                  strlen(altclasses_jar);
  2000     char* altclasses_path = NEW_C_HEAP_ARRAY(char, altclasses_path_len);
  2001     strcpy(altclasses_path, get_meta_index_dir());
  2002     strcat(altclasses_path, altclasses_jar);
  2003     scp.add_suffix_to_prefix(altclasses_path);
  2004     scp_assembly_required = true;
  2005     FREE_C_HEAP_ARRAY(char, altclasses_path);
  2008   // Parse _JAVA_OPTIONS environment variable (if present) (mimics classic VM)
  2009   result = parse_java_options_environment_variable(&scp, &scp_assembly_required);
  2010   if (result != JNI_OK) {
  2011     return result;
  2014   // Do final processing now that all arguments have been parsed
  2015   result = finalize_vm_init_args(&scp, scp_assembly_required);
  2016   if (result != JNI_OK) {
  2017     return result;
  2020   return JNI_OK;
  2023 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
  2024                                        SysClassPath* scp_p,
  2025                                        bool* scp_assembly_required_p,
  2026                                        FlagValueOrigin origin) {
  2027   // Remaining part of option string
  2028   const char* tail;
  2030   // iterate over arguments
  2031   for (int index = 0; index < args->nOptions; index++) {
  2032     bool is_absolute_path = false;  // for -agentpath vs -agentlib
  2034     const JavaVMOption* option = args->options + index;
  2036     if (!match_option(option, "-Djava.class.path", &tail) &&
  2037         !match_option(option, "-Dsun.java.command", &tail) &&
  2038         !match_option(option, "-Dsun.java.launcher", &tail)) {
  2040         // add all jvm options to the jvm_args string. This string
  2041         // is used later to set the java.vm.args PerfData string constant.
  2042         // the -Djava.class.path and the -Dsun.java.command options are
  2043         // omitted from jvm_args string as each have their own PerfData
  2044         // string constant object.
  2045         build_jvm_args(option->optionString);
  2048     // -verbose:[class/gc/jni]
  2049     if (match_option(option, "-verbose", &tail)) {
  2050       if (!strcmp(tail, ":class") || !strcmp(tail, "")) {
  2051         FLAG_SET_CMDLINE(bool, TraceClassLoading, true);
  2052         FLAG_SET_CMDLINE(bool, TraceClassUnloading, true);
  2053       } else if (!strcmp(tail, ":gc")) {
  2054         FLAG_SET_CMDLINE(bool, PrintGC, true);
  2055       } else if (!strcmp(tail, ":jni")) {
  2056         FLAG_SET_CMDLINE(bool, PrintJNIResolving, true);
  2058     // -da / -ea / -disableassertions / -enableassertions
  2059     // These accept an optional class/package name separated by a colon, e.g.,
  2060     // -da:java.lang.Thread.
  2061     } else if (match_option(option, user_assertion_options, &tail, true)) {
  2062       bool enable = option->optionString[1] == 'e';     // char after '-' is 'e'
  2063       if (*tail == '\0') {
  2064         JavaAssertions::setUserClassDefault(enable);
  2065       } else {
  2066         assert(*tail == ':', "bogus match by match_option()");
  2067         JavaAssertions::addOption(tail + 1, enable);
  2069     // -dsa / -esa / -disablesystemassertions / -enablesystemassertions
  2070     } else if (match_option(option, system_assertion_options, &tail, false)) {
  2071       bool enable = option->optionString[1] == 'e';     // char after '-' is 'e'
  2072       JavaAssertions::setSystemClassDefault(enable);
  2073     // -bootclasspath:
  2074     } else if (match_option(option, "-Xbootclasspath:", &tail)) {
  2075       scp_p->reset_path(tail);
  2076       *scp_assembly_required_p = true;
  2077     // -bootclasspath/a:
  2078     } else if (match_option(option, "-Xbootclasspath/a:", &tail)) {
  2079       scp_p->add_suffix(tail);
  2080       *scp_assembly_required_p = true;
  2081     // -bootclasspath/p:
  2082     } else if (match_option(option, "-Xbootclasspath/p:", &tail)) {
  2083       scp_p->add_prefix(tail);
  2084       *scp_assembly_required_p = true;
  2085     // -Xrun
  2086     } else if (match_option(option, "-Xrun", &tail)) {
  2087       if (tail != NULL) {
  2088         const char* pos = strchr(tail, ':');
  2089         size_t len = (pos == NULL) ? strlen(tail) : pos - tail;
  2090         char* name = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len + 1), tail, len);
  2091         name[len] = '\0';
  2093         char *options = NULL;
  2094         if(pos != NULL) {
  2095           size_t len2 = strlen(pos+1) + 1; // options start after ':'.  Final zero must be copied.
  2096           options = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len2), pos+1, len2);
  2098 #ifdef JVMTI_KERNEL
  2099         if ((strcmp(name, "hprof") == 0) || (strcmp(name, "jdwp") == 0)) {
  2100           warning("profiling and debugging agents are not supported with Kernel VM");
  2101         } else
  2102 #endif // JVMTI_KERNEL
  2103         add_init_library(name, options);
  2105     // -agentlib and -agentpath
  2106     } else if (match_option(option, "-agentlib:", &tail) ||
  2107           (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
  2108       if(tail != NULL) {
  2109         const char* pos = strchr(tail, '=');
  2110         size_t len = (pos == NULL) ? strlen(tail) : pos - tail;
  2111         char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1), tail, len);
  2112         name[len] = '\0';
  2114         char *options = NULL;
  2115         if(pos != NULL) {
  2116           options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(pos + 1) + 1), pos + 1);
  2118 #ifdef JVMTI_KERNEL
  2119         if ((strcmp(name, "hprof") == 0) || (strcmp(name, "jdwp") == 0)) {
  2120           warning("profiling and debugging agents are not supported with Kernel VM");
  2121         } else
  2122 #endif // JVMTI_KERNEL
  2123         add_init_agent(name, options, is_absolute_path);
  2126     // -javaagent
  2127     } else if (match_option(option, "-javaagent:", &tail)) {
  2128       if(tail != NULL) {
  2129         char *options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(tail) + 1), tail);
  2130         add_init_agent("instrument", options, false);
  2132     // -Xnoclassgc
  2133     } else if (match_option(option, "-Xnoclassgc", &tail)) {
  2134       FLAG_SET_CMDLINE(bool, ClassUnloading, false);
  2135     // -Xincgc: i-CMS
  2136     } else if (match_option(option, "-Xincgc", &tail)) {
  2137       FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true);
  2138       FLAG_SET_CMDLINE(bool, CMSIncrementalMode, true);
  2139     // -Xnoincgc: no i-CMS
  2140     } else if (match_option(option, "-Xnoincgc", &tail)) {
  2141       FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false);
  2142       FLAG_SET_CMDLINE(bool, CMSIncrementalMode, false);
  2143     // -Xconcgc
  2144     } else if (match_option(option, "-Xconcgc", &tail)) {
  2145       FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true);
  2146     // -Xnoconcgc
  2147     } else if (match_option(option, "-Xnoconcgc", &tail)) {
  2148       FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false);
  2149     // -Xbatch
  2150     } else if (match_option(option, "-Xbatch", &tail)) {
  2151       FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
  2152     // -Xmn for compatibility with other JVM vendors
  2153     } else if (match_option(option, "-Xmn", &tail)) {
  2154       julong long_initial_eden_size = 0;
  2155       ArgsRange errcode = parse_memory_size(tail, &long_initial_eden_size, 1);
  2156       if (errcode != arg_in_range) {
  2157         jio_fprintf(defaultStream::error_stream(),
  2158                     "Invalid initial eden size: %s\n", option->optionString);
  2159         describe_range_error(errcode);
  2160         return JNI_EINVAL;
  2162       FLAG_SET_CMDLINE(uintx, MaxNewSize, (uintx)long_initial_eden_size);
  2163       FLAG_SET_CMDLINE(uintx, NewSize, (uintx)long_initial_eden_size);
  2164     // -Xms
  2165     } else if (match_option(option, "-Xms", &tail)) {
  2166       julong long_initial_heap_size = 0;
  2167       ArgsRange errcode = parse_memory_size(tail, &long_initial_heap_size, 1);
  2168       if (errcode != arg_in_range) {
  2169         jio_fprintf(defaultStream::error_stream(),
  2170                     "Invalid initial heap size: %s\n", option->optionString);
  2171         describe_range_error(errcode);
  2172         return JNI_EINVAL;
  2174       FLAG_SET_CMDLINE(uintx, InitialHeapSize, (uintx)long_initial_heap_size);
  2175       // Currently the minimum size and the initial heap sizes are the same.
  2176       set_min_heap_size(InitialHeapSize);
  2177     // -Xmx
  2178     } else if (match_option(option, "-Xmx", &tail)) {
  2179       julong long_max_heap_size = 0;
  2180       ArgsRange errcode = parse_memory_size(tail, &long_max_heap_size, 1);
  2181       if (errcode != arg_in_range) {
  2182         jio_fprintf(defaultStream::error_stream(),
  2183                     "Invalid maximum heap size: %s\n", option->optionString);
  2184         describe_range_error(errcode);
  2185         return JNI_EINVAL;
  2187       FLAG_SET_CMDLINE(uintx, MaxHeapSize, (uintx)long_max_heap_size);
  2188     // Xmaxf
  2189     } else if (match_option(option, "-Xmaxf", &tail)) {
  2190       int maxf = (int)(atof(tail) * 100);
  2191       if (maxf < 0 || maxf > 100) {
  2192         jio_fprintf(defaultStream::error_stream(),
  2193                     "Bad max heap free percentage size: %s\n",
  2194                     option->optionString);
  2195         return JNI_EINVAL;
  2196       } else {
  2197         FLAG_SET_CMDLINE(uintx, MaxHeapFreeRatio, maxf);
  2199     // Xminf
  2200     } else if (match_option(option, "-Xminf", &tail)) {
  2201       int minf = (int)(atof(tail) * 100);
  2202       if (minf < 0 || minf > 100) {
  2203         jio_fprintf(defaultStream::error_stream(),
  2204                     "Bad min heap free percentage size: %s\n",
  2205                     option->optionString);
  2206         return JNI_EINVAL;
  2207       } else {
  2208         FLAG_SET_CMDLINE(uintx, MinHeapFreeRatio, minf);
  2210     // -Xss
  2211     } else if (match_option(option, "-Xss", &tail)) {
  2212       julong long_ThreadStackSize = 0;
  2213       ArgsRange errcode = parse_memory_size(tail, &long_ThreadStackSize, 1000);
  2214       if (errcode != arg_in_range) {
  2215         jio_fprintf(defaultStream::error_stream(),
  2216                     "Invalid thread stack size: %s\n", option->optionString);
  2217         describe_range_error(errcode);
  2218         return JNI_EINVAL;
  2220       // Internally track ThreadStackSize in units of 1024 bytes.
  2221       FLAG_SET_CMDLINE(intx, ThreadStackSize,
  2222                               round_to((int)long_ThreadStackSize, K) / K);
  2223     // -Xoss
  2224     } else if (match_option(option, "-Xoss", &tail)) {
  2225           // HotSpot does not have separate native and Java stacks, ignore silently for compatibility
  2226     // -Xmaxjitcodesize
  2227     } else if (match_option(option, "-Xmaxjitcodesize", &tail)) {
  2228       julong long_ReservedCodeCacheSize = 0;
  2229       ArgsRange errcode = parse_memory_size(tail, &long_ReservedCodeCacheSize,
  2230                                             (size_t)InitialCodeCacheSize);
  2231       if (errcode != arg_in_range) {
  2232         jio_fprintf(defaultStream::error_stream(),
  2233                     "Invalid maximum code cache size: %s\n",
  2234                     option->optionString);
  2235         describe_range_error(errcode);
  2236         return JNI_EINVAL;
  2238       FLAG_SET_CMDLINE(uintx, ReservedCodeCacheSize, (uintx)long_ReservedCodeCacheSize);
  2239     // -green
  2240     } else if (match_option(option, "-green", &tail)) {
  2241       jio_fprintf(defaultStream::error_stream(),
  2242                   "Green threads support not available\n");
  2243           return JNI_EINVAL;
  2244     // -native
  2245     } else if (match_option(option, "-native", &tail)) {
  2246           // HotSpot always uses native threads, ignore silently for compatibility
  2247     // -Xsqnopause
  2248     } else if (match_option(option, "-Xsqnopause", &tail)) {
  2249           // EVM option, ignore silently for compatibility
  2250     // -Xrs
  2251     } else if (match_option(option, "-Xrs", &tail)) {
  2252           // Classic/EVM option, new functionality
  2253       FLAG_SET_CMDLINE(bool, ReduceSignalUsage, true);
  2254     } else if (match_option(option, "-Xusealtsigs", &tail)) {
  2255           // change default internal VM signals used - lower case for back compat
  2256       FLAG_SET_CMDLINE(bool, UseAltSigs, true);
  2257     // -Xoptimize
  2258     } else if (match_option(option, "-Xoptimize", &tail)) {
  2259           // EVM option, ignore silently for compatibility
  2260     // -Xprof
  2261     } else if (match_option(option, "-Xprof", &tail)) {
  2262 #ifndef FPROF_KERNEL
  2263       _has_profile = true;
  2264 #else // FPROF_KERNEL
  2265       // do we have to exit?
  2266       warning("Kernel VM does not support flat profiling.");
  2267 #endif // FPROF_KERNEL
  2268     // -Xaprof
  2269     } else if (match_option(option, "-Xaprof", &tail)) {
  2270       _has_alloc_profile = true;
  2271     // -Xconcurrentio
  2272     } else if (match_option(option, "-Xconcurrentio", &tail)) {
  2273       FLAG_SET_CMDLINE(bool, UseLWPSynchronization, true);
  2274       FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
  2275       FLAG_SET_CMDLINE(intx, DeferThrSuspendLoopCount, 1);
  2276       FLAG_SET_CMDLINE(bool, UseTLAB, false);
  2277       FLAG_SET_CMDLINE(uintx, NewSizeThreadIncrease, 16 * K);  // 20Kb per thread added to new generation
  2279       // -Xinternalversion
  2280     } else if (match_option(option, "-Xinternalversion", &tail)) {
  2281       jio_fprintf(defaultStream::output_stream(), "%s\n",
  2282                   VM_Version::internal_vm_info_string());
  2283       vm_exit(0);
  2284 #ifndef PRODUCT
  2285     // -Xprintflags
  2286     } else if (match_option(option, "-Xprintflags", &tail)) {
  2287       CommandLineFlags::printFlags();
  2288       vm_exit(0);
  2289 #endif
  2290     // -D
  2291     } else if (match_option(option, "-D", &tail)) {
  2292       if (!add_property(tail)) {
  2293         return JNI_ENOMEM;
  2295       // Out of the box management support
  2296       if (match_option(option, "-Dcom.sun.management", &tail)) {
  2297         FLAG_SET_CMDLINE(bool, ManagementServer, true);
  2299     // -Xint
  2300     } else if (match_option(option, "-Xint", &tail)) {
  2301           set_mode_flags(_int);
  2302     // -Xmixed
  2303     } else if (match_option(option, "-Xmixed", &tail)) {
  2304           set_mode_flags(_mixed);
  2305     // -Xcomp
  2306     } else if (match_option(option, "-Xcomp", &tail)) {
  2307       // for testing the compiler; turn off all flags that inhibit compilation
  2308           set_mode_flags(_comp);
  2310     // -Xshare:dump
  2311     } else if (match_option(option, "-Xshare:dump", &tail)) {
  2312 #ifdef TIERED
  2313       FLAG_SET_CMDLINE(bool, DumpSharedSpaces, true);
  2314       set_mode_flags(_int);     // Prevent compilation, which creates objects
  2315 #elif defined(COMPILER2)
  2316       vm_exit_during_initialization(
  2317           "Dumping a shared archive is not supported on the Server JVM.", NULL);
  2318 #elif defined(KERNEL)
  2319       vm_exit_during_initialization(
  2320           "Dumping a shared archive is not supported on the Kernel JVM.", NULL);
  2321 #else
  2322       FLAG_SET_CMDLINE(bool, DumpSharedSpaces, true);
  2323       set_mode_flags(_int);     // Prevent compilation, which creates objects
  2324 #endif
  2325     // -Xshare:on
  2326     } else if (match_option(option, "-Xshare:on", &tail)) {
  2327       FLAG_SET_CMDLINE(bool, UseSharedSpaces, true);
  2328       FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true);
  2329 #ifdef TIERED
  2330       FLAG_SET_CMDLINE(bool, ForceSharedSpaces, true);
  2331 #endif // TIERED
  2332     // -Xshare:auto
  2333     } else if (match_option(option, "-Xshare:auto", &tail)) {
  2334       FLAG_SET_CMDLINE(bool, UseSharedSpaces, true);
  2335       FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false);
  2336     // -Xshare:off
  2337     } else if (match_option(option, "-Xshare:off", &tail)) {
  2338       FLAG_SET_CMDLINE(bool, UseSharedSpaces, false);
  2339       FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false);
  2341     // -Xverify
  2342     } else if (match_option(option, "-Xverify", &tail)) {
  2343       if (strcmp(tail, ":all") == 0 || strcmp(tail, "") == 0) {
  2344         FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, true);
  2345         FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true);
  2346       } else if (strcmp(tail, ":remote") == 0) {
  2347         FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false);
  2348         FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true);
  2349       } else if (strcmp(tail, ":none") == 0) {
  2350         FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false);
  2351         FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, false);
  2352       } else if (is_bad_option(option, args->ignoreUnrecognized, "verification")) {
  2353         return JNI_EINVAL;
  2355     // -Xdebug
  2356     } else if (match_option(option, "-Xdebug", &tail)) {
  2357       // note this flag has been used, then ignore
  2358       set_xdebug_mode(true);
  2359     // -Xnoagent
  2360     } else if (match_option(option, "-Xnoagent", &tail)) {
  2361       // For compatibility with classic. HotSpot refuses to load the old style agent.dll.
  2362     } else if (match_option(option, "-Xboundthreads", &tail)) {
  2363       // Bind user level threads to kernel threads (Solaris only)
  2364       FLAG_SET_CMDLINE(bool, UseBoundThreads, true);
  2365     } else if (match_option(option, "-Xloggc:", &tail)) {
  2366       // Redirect GC output to the file. -Xloggc:<filename>
  2367       // ostream_init_log(), when called will use this filename
  2368       // to initialize a fileStream.
  2369       _gc_log_filename = strdup(tail);
  2370       FLAG_SET_CMDLINE(bool, PrintGC, true);
  2371       FLAG_SET_CMDLINE(bool, PrintGCTimeStamps, true);
  2372       FLAG_SET_CMDLINE(bool, TraceClassUnloading, true);
  2374     // JNI hooks
  2375     } else if (match_option(option, "-Xcheck", &tail)) {
  2376       if (!strcmp(tail, ":jni")) {
  2377         CheckJNICalls = true;
  2378       } else if (is_bad_option(option, args->ignoreUnrecognized,
  2379                                      "check")) {
  2380         return JNI_EINVAL;
  2382     } else if (match_option(option, "vfprintf", &tail)) {
  2383       _vfprintf_hook = CAST_TO_FN_PTR(vfprintf_hook_t, option->extraInfo);
  2384     } else if (match_option(option, "exit", &tail)) {
  2385       _exit_hook = CAST_TO_FN_PTR(exit_hook_t, option->extraInfo);
  2386     } else if (match_option(option, "abort", &tail)) {
  2387       _abort_hook = CAST_TO_FN_PTR(abort_hook_t, option->extraInfo);
  2388     // -XX:+AggressiveHeap
  2389     } else if (match_option(option, "-XX:+AggressiveHeap", &tail)) {
  2391       // This option inspects the machine and attempts to set various
  2392       // parameters to be optimal for long-running, memory allocation
  2393       // intensive jobs.  It is intended for machines with large
  2394       // amounts of cpu and memory.
  2396       // initHeapSize is needed since _initial_heap_size is 4 bytes on a 32 bit
  2397       // VM, but we may not be able to represent the total physical memory
  2398       // available (like having 8gb of memory on a box but using a 32bit VM).
  2399       // Thus, we need to make sure we're using a julong for intermediate
  2400       // calculations.
  2401       julong initHeapSize;
  2402       julong total_memory = os::physical_memory();
  2404       if (total_memory < (julong)256*M) {
  2405         jio_fprintf(defaultStream::error_stream(),
  2406                     "You need at least 256mb of memory to use -XX:+AggressiveHeap\n");
  2407         vm_exit(1);
  2410       // The heap size is half of available memory, or (at most)
  2411       // all of possible memory less 160mb (leaving room for the OS
  2412       // when using ISM).  This is the maximum; because adaptive sizing
  2413       // is turned on below, the actual space used may be smaller.
  2415       initHeapSize = MIN2(total_memory / (julong)2,
  2416                           total_memory - (julong)160*M);
  2418       // Make sure that if we have a lot of memory we cap the 32 bit
  2419       // process space.  The 64bit VM version of this function is a nop.
  2420       initHeapSize = os::allocatable_physical_memory(initHeapSize);
  2422       // The perm gen is separate but contiguous with the
  2423       // object heap (and is reserved with it) so subtract it
  2424       // from the heap size.
  2425       if (initHeapSize > MaxPermSize) {
  2426         initHeapSize = initHeapSize - MaxPermSize;
  2427       } else {
  2428         warning("AggressiveHeap and MaxPermSize values may conflict");
  2431       if (FLAG_IS_DEFAULT(MaxHeapSize)) {
  2432          FLAG_SET_CMDLINE(uintx, MaxHeapSize, initHeapSize);
  2433          FLAG_SET_CMDLINE(uintx, InitialHeapSize, initHeapSize);
  2434          // Currently the minimum size and the initial heap sizes are the same.
  2435          set_min_heap_size(initHeapSize);
  2437       if (FLAG_IS_DEFAULT(NewSize)) {
  2438          // Make the young generation 3/8ths of the total heap.
  2439          FLAG_SET_CMDLINE(uintx, NewSize,
  2440                                 ((julong)MaxHeapSize / (julong)8) * (julong)3);
  2441          FLAG_SET_CMDLINE(uintx, MaxNewSize, NewSize);
  2444       FLAG_SET_DEFAULT(UseLargePages, true);
  2446       // Increase some data structure sizes for efficiency
  2447       FLAG_SET_CMDLINE(uintx, BaseFootPrintEstimate, MaxHeapSize);
  2448       FLAG_SET_CMDLINE(bool, ResizeTLAB, false);
  2449       FLAG_SET_CMDLINE(uintx, TLABSize, 256*K);
  2451       // See the OldPLABSize comment below, but replace 'after promotion'
  2452       // with 'after copying'.  YoungPLABSize is the size of the survivor
  2453       // space per-gc-thread buffers.  The default is 4kw.
  2454       FLAG_SET_CMDLINE(uintx, YoungPLABSize, 256*K);      // Note: this is in words
  2456       // OldPLABSize is the size of the buffers in the old gen that
  2457       // UseParallelGC uses to promote live data that doesn't fit in the
  2458       // survivor spaces.  At any given time, there's one for each gc thread.
  2459       // The default size is 1kw. These buffers are rarely used, since the
  2460       // survivor spaces are usually big enough.  For specjbb, however, there
  2461       // are occasions when there's lots of live data in the young gen
  2462       // and we end up promoting some of it.  We don't have a definite
  2463       // explanation for why bumping OldPLABSize helps, but the theory
  2464       // is that a bigger PLAB results in retaining something like the
  2465       // original allocation order after promotion, which improves mutator
  2466       // locality.  A minor effect may be that larger PLABs reduce the
  2467       // number of PLAB allocation events during gc.  The value of 8kw
  2468       // was arrived at by experimenting with specjbb.
  2469       FLAG_SET_CMDLINE(uintx, OldPLABSize, 8*K);  // Note: this is in words
  2471       // CompilationPolicyChoice=0 causes the server compiler to adopt
  2472       // a more conservative which-method-do-I-compile policy when one
  2473       // of the counters maintained by the interpreter trips.  The
  2474       // result is reduced startup time and improved specjbb and
  2475       // alacrity performance.  Zero is the default, but we set it
  2476       // explicitly here in case the default changes.
  2477       // See runtime/compilationPolicy.*.
  2478       FLAG_SET_CMDLINE(intx, CompilationPolicyChoice, 0);
  2480       // Enable parallel GC and adaptive generation sizing
  2481       FLAG_SET_CMDLINE(bool, UseParallelGC, true);
  2482       FLAG_SET_DEFAULT(ParallelGCThreads,
  2483                        Abstract_VM_Version::parallel_worker_threads());
  2485       // Encourage steady state memory management
  2486       FLAG_SET_CMDLINE(uintx, ThresholdTolerance, 100);
  2488       // This appears to improve mutator locality
  2489       FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
  2491       // Get around early Solaris scheduling bug
  2492       // (affinity vs other jobs on system)
  2493       // but disallow DR and offlining (5008695).
  2494       FLAG_SET_CMDLINE(bool, BindGCTaskThreadsToCPUs, true);
  2496     } else if (match_option(option, "-XX:+NeverTenure", &tail)) {
  2497       // The last option must always win.
  2498       FLAG_SET_CMDLINE(bool, AlwaysTenure, false);
  2499       FLAG_SET_CMDLINE(bool, NeverTenure, true);
  2500     } else if (match_option(option, "-XX:+AlwaysTenure", &tail)) {
  2501       // The last option must always win.
  2502       FLAG_SET_CMDLINE(bool, NeverTenure, false);
  2503       FLAG_SET_CMDLINE(bool, AlwaysTenure, true);
  2504     } else if (match_option(option, "-XX:+CMSPermGenSweepingEnabled", &tail) ||
  2505                match_option(option, "-XX:-CMSPermGenSweepingEnabled", &tail)) {
  2506       jio_fprintf(defaultStream::error_stream(),
  2507         "Please use CMSClassUnloadingEnabled in place of "
  2508         "CMSPermGenSweepingEnabled in the future\n");
  2509     } else if (match_option(option, "-XX:+UseGCTimeLimit", &tail)) {
  2510       FLAG_SET_CMDLINE(bool, UseGCOverheadLimit, true);
  2511       jio_fprintf(defaultStream::error_stream(),
  2512         "Please use -XX:+UseGCOverheadLimit in place of "
  2513         "-XX:+UseGCTimeLimit in the future\n");
  2514     } else if (match_option(option, "-XX:-UseGCTimeLimit", &tail)) {
  2515       FLAG_SET_CMDLINE(bool, UseGCOverheadLimit, false);
  2516       jio_fprintf(defaultStream::error_stream(),
  2517         "Please use -XX:-UseGCOverheadLimit in place of "
  2518         "-XX:-UseGCTimeLimit in the future\n");
  2519     // The TLE options are for compatibility with 1.3 and will be
  2520     // removed without notice in a future release.  These options
  2521     // are not to be documented.
  2522     } else if (match_option(option, "-XX:MaxTLERatio=", &tail)) {
  2523       // No longer used.
  2524     } else if (match_option(option, "-XX:+ResizeTLE", &tail)) {
  2525       FLAG_SET_CMDLINE(bool, ResizeTLAB, true);
  2526     } else if (match_option(option, "-XX:-ResizeTLE", &tail)) {
  2527       FLAG_SET_CMDLINE(bool, ResizeTLAB, false);
  2528     } else if (match_option(option, "-XX:+PrintTLE", &tail)) {
  2529       FLAG_SET_CMDLINE(bool, PrintTLAB, true);
  2530     } else if (match_option(option, "-XX:-PrintTLE", &tail)) {
  2531       FLAG_SET_CMDLINE(bool, PrintTLAB, false);
  2532     } else if (match_option(option, "-XX:TLEFragmentationRatio=", &tail)) {
  2533       // No longer used.
  2534     } else if (match_option(option, "-XX:TLESize=", &tail)) {
  2535       julong long_tlab_size = 0;
  2536       ArgsRange errcode = parse_memory_size(tail, &long_tlab_size, 1);
  2537       if (errcode != arg_in_range) {
  2538         jio_fprintf(defaultStream::error_stream(),
  2539                     "Invalid TLAB size: %s\n", option->optionString);
  2540         describe_range_error(errcode);
  2541         return JNI_EINVAL;
  2543       FLAG_SET_CMDLINE(uintx, TLABSize, long_tlab_size);
  2544     } else if (match_option(option, "-XX:TLEThreadRatio=", &tail)) {
  2545       // No longer used.
  2546     } else if (match_option(option, "-XX:+UseTLE", &tail)) {
  2547       FLAG_SET_CMDLINE(bool, UseTLAB, true);
  2548     } else if (match_option(option, "-XX:-UseTLE", &tail)) {
  2549       FLAG_SET_CMDLINE(bool, UseTLAB, false);
  2550 SOLARIS_ONLY(
  2551     } else if (match_option(option, "-XX:+UsePermISM", &tail)) {
  2552       warning("-XX:+UsePermISM is obsolete.");
  2553       FLAG_SET_CMDLINE(bool, UseISM, true);
  2554     } else if (match_option(option, "-XX:-UsePermISM", &tail)) {
  2555       FLAG_SET_CMDLINE(bool, UseISM, false);
  2557     } else if (match_option(option, "-XX:+DisplayVMOutputToStderr", &tail)) {
  2558       FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, false);
  2559       FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, true);
  2560     } else if (match_option(option, "-XX:+DisplayVMOutputToStdout", &tail)) {
  2561       FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, false);
  2562       FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, true);
  2563     } else if (match_option(option, "-XX:+ExtendedDTraceProbes", &tail)) {
  2564 #ifdef SOLARIS
  2565       FLAG_SET_CMDLINE(bool, ExtendedDTraceProbes, true);
  2566       FLAG_SET_CMDLINE(bool, DTraceMethodProbes, true);
  2567       FLAG_SET_CMDLINE(bool, DTraceAllocProbes, true);
  2568       FLAG_SET_CMDLINE(bool, DTraceMonitorProbes, true);
  2569 #else // ndef SOLARIS
  2570       jio_fprintf(defaultStream::error_stream(),
  2571                   "ExtendedDTraceProbes flag is only applicable on Solaris\n");
  2572       return JNI_EINVAL;
  2573 #endif // ndef SOLARIS
  2574 #ifdef ASSERT
  2575     } else if (match_option(option, "-XX:+FullGCALot", &tail)) {
  2576       FLAG_SET_CMDLINE(bool, FullGCALot, true);
  2577       // disable scavenge before parallel mark-compact
  2578       FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
  2579 #endif
  2580     } else if (match_option(option, "-XX:CMSParPromoteBlocksToClaim=", &tail)) {
  2581       julong cms_blocks_to_claim = (julong)atol(tail);
  2582       FLAG_SET_CMDLINE(uintx, CMSParPromoteBlocksToClaim, cms_blocks_to_claim);
  2583       jio_fprintf(defaultStream::error_stream(),
  2584         "Please use -XX:OldPLABSize in place of "
  2585         "-XX:CMSParPromoteBlocksToClaim in the future\n");
  2586     } else if (match_option(option, "-XX:ParCMSPromoteBlocksToClaim=", &tail)) {
  2587       julong cms_blocks_to_claim = (julong)atol(tail);
  2588       FLAG_SET_CMDLINE(uintx, CMSParPromoteBlocksToClaim, cms_blocks_to_claim);
  2589       jio_fprintf(defaultStream::error_stream(),
  2590         "Please use -XX:OldPLABSize in place of "
  2591         "-XX:ParCMSPromoteBlocksToClaim in the future\n");
  2592     } else if (match_option(option, "-XX:ParallelGCOldGenAllocBufferSize=", &tail)) {
  2593       julong old_plab_size = 0;
  2594       ArgsRange errcode = parse_memory_size(tail, &old_plab_size, 1);
  2595       if (errcode != arg_in_range) {
  2596         jio_fprintf(defaultStream::error_stream(),
  2597                     "Invalid old PLAB size: %s\n", option->optionString);
  2598         describe_range_error(errcode);
  2599         return JNI_EINVAL;
  2601       FLAG_SET_CMDLINE(uintx, OldPLABSize, old_plab_size);
  2602       jio_fprintf(defaultStream::error_stream(),
  2603                   "Please use -XX:OldPLABSize in place of "
  2604                   "-XX:ParallelGCOldGenAllocBufferSize in the future\n");
  2605     } else if (match_option(option, "-XX:ParallelGCToSpaceAllocBufferSize=", &tail)) {
  2606       julong young_plab_size = 0;
  2607       ArgsRange errcode = parse_memory_size(tail, &young_plab_size, 1);
  2608       if (errcode != arg_in_range) {
  2609         jio_fprintf(defaultStream::error_stream(),
  2610                     "Invalid young PLAB size: %s\n", option->optionString);
  2611         describe_range_error(errcode);
  2612         return JNI_EINVAL;
  2614       FLAG_SET_CMDLINE(uintx, YoungPLABSize, young_plab_size);
  2615       jio_fprintf(defaultStream::error_stream(),
  2616                   "Please use -XX:YoungPLABSize in place of "
  2617                   "-XX:ParallelGCToSpaceAllocBufferSize in the future\n");
  2618     } else if (match_option(option, "-XX:CMSMarkStackSize=", &tail) ||
  2619                match_option(option, "-XX:G1MarkStackSize=", &tail)) {
  2620       julong stack_size = 0;
  2621       ArgsRange errcode = parse_memory_size(tail, &stack_size, 1);
  2622       if (errcode != arg_in_range) {
  2623         jio_fprintf(defaultStream::error_stream(),
  2624                     "Invalid mark stack size: %s\n", option->optionString);
  2625         describe_range_error(errcode);
  2626         return JNI_EINVAL;
  2628       FLAG_SET_CMDLINE(uintx, MarkStackSize, stack_size);
  2629     } else if (match_option(option, "-XX:CMSMarkStackSizeMax=", &tail)) {
  2630       julong max_stack_size = 0;
  2631       ArgsRange errcode = parse_memory_size(tail, &max_stack_size, 1);
  2632       if (errcode != arg_in_range) {
  2633         jio_fprintf(defaultStream::error_stream(),
  2634                     "Invalid maximum mark stack size: %s\n",
  2635                     option->optionString);
  2636         describe_range_error(errcode);
  2637         return JNI_EINVAL;
  2639       FLAG_SET_CMDLINE(uintx, MarkStackSizeMax, max_stack_size);
  2640     } else if (match_option(option, "-XX:ParallelMarkingThreads=", &tail) ||
  2641                match_option(option, "-XX:ParallelCMSThreads=", &tail)) {
  2642       uintx conc_threads = 0;
  2643       if (!parse_uintx(tail, &conc_threads, 1)) {
  2644         jio_fprintf(defaultStream::error_stream(),
  2645                     "Invalid concurrent threads: %s\n", option->optionString);
  2646         return JNI_EINVAL;
  2648       FLAG_SET_CMDLINE(uintx, ConcGCThreads, conc_threads);
  2649     } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx
  2650       // Skip -XX:Flags= since that case has already been handled
  2651       if (strncmp(tail, "Flags=", strlen("Flags=")) != 0) {
  2652         if (!process_argument(tail, args->ignoreUnrecognized, origin)) {
  2653           return JNI_EINVAL;
  2656     // Unknown option
  2657     } else if (is_bad_option(option, args->ignoreUnrecognized)) {
  2658       return JNI_ERR;
  2661   // Change the default value for flags  which have different default values
  2662   // when working with older JDKs.
  2663   if (JDK_Version::current().compare_major(6) <= 0 &&
  2664       FLAG_IS_DEFAULT(UseVMInterruptibleIO)) {
  2665     FLAG_SET_DEFAULT(UseVMInterruptibleIO, true);
  2667 #ifdef LINUX
  2668  if (JDK_Version::current().compare_major(6) <= 0 &&
  2669       FLAG_IS_DEFAULT(UseLinuxPosixThreadCPUClocks)) {
  2670     FLAG_SET_DEFAULT(UseLinuxPosixThreadCPUClocks, false);
  2672 #endif // LINUX
  2673   return JNI_OK;
  2676 jint Arguments::finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required) {
  2677   // This must be done after all -D arguments have been processed.
  2678   scp_p->expand_endorsed();
  2680   if (scp_assembly_required || scp_p->get_endorsed() != NULL) {
  2681     // Assemble the bootclasspath elements into the final path.
  2682     Arguments::set_sysclasspath(scp_p->combined_path());
  2685   // This must be done after all arguments have been processed.
  2686   // java_compiler() true means set to "NONE" or empty.
  2687   if (java_compiler() && !xdebug_mode()) {
  2688     // For backwards compatibility, we switch to interpreted mode if
  2689     // -Djava.compiler="NONE" or "" is specified AND "-Xdebug" was
  2690     // not specified.
  2691     set_mode_flags(_int);
  2693   if (CompileThreshold == 0) {
  2694     set_mode_flags(_int);
  2697 #ifndef COMPILER2
  2698   // Don't degrade server performance for footprint
  2699   if (FLAG_IS_DEFAULT(UseLargePages) &&
  2700       MaxHeapSize < LargePageHeapSizeThreshold) {
  2701     // No need for large granularity pages w/small heaps.
  2702     // Note that large pages are enabled/disabled for both the
  2703     // Java heap and the code cache.
  2704     FLAG_SET_DEFAULT(UseLargePages, false);
  2705     SOLARIS_ONLY(FLAG_SET_DEFAULT(UseMPSS, false));
  2706     SOLARIS_ONLY(FLAG_SET_DEFAULT(UseISM, false));
  2709   // Tiered compilation is undefined with C1.
  2710   TieredCompilation = false;
  2711 #else
  2712   if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) {
  2713     FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment-1);
  2715   // Temporary disable bulk zeroing reduction with G1. See CR 6627983.
  2716   if (UseG1GC) {
  2717     FLAG_SET_DEFAULT(ReduceBulkZeroing, false);
  2719 #endif
  2721   // If we are running in a headless jre, force java.awt.headless property
  2722   // to be true unless the property has already been set.
  2723   // Also allow the OS environment variable JAVA_AWT_HEADLESS to set headless state.
  2724   if (os::is_headless_jre()) {
  2725     const char* headless = Arguments::get_property("java.awt.headless");
  2726     if (headless == NULL) {
  2727       char envbuffer[128];
  2728       if (!os::getenv("JAVA_AWT_HEADLESS", envbuffer, sizeof(envbuffer))) {
  2729         if (!add_property("java.awt.headless=true")) {
  2730           return JNI_ENOMEM;
  2732       } else {
  2733         char buffer[256];
  2734         strcpy(buffer, "java.awt.headless=");
  2735         strcat(buffer, envbuffer);
  2736         if (!add_property(buffer)) {
  2737           return JNI_ENOMEM;
  2743   if (!check_vm_args_consistency()) {
  2744     return JNI_ERR;
  2747   return JNI_OK;
  2750 jint Arguments::parse_java_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
  2751   return parse_options_environment_variable("_JAVA_OPTIONS", scp_p,
  2752                                             scp_assembly_required_p);
  2755 jint Arguments::parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
  2756   return parse_options_environment_variable("JAVA_TOOL_OPTIONS", scp_p,
  2757                                             scp_assembly_required_p);
  2760 jint Arguments::parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p) {
  2761   const int N_MAX_OPTIONS = 64;
  2762   const int OPTION_BUFFER_SIZE = 1024;
  2763   char buffer[OPTION_BUFFER_SIZE];
  2765   // The variable will be ignored if it exceeds the length of the buffer.
  2766   // Don't check this variable if user has special privileges
  2767   // (e.g. unix su command).
  2768   if (os::getenv(name, buffer, sizeof(buffer)) &&
  2769       !os::have_special_privileges()) {
  2770     JavaVMOption options[N_MAX_OPTIONS];      // Construct option array
  2771     jio_fprintf(defaultStream::error_stream(),
  2772                 "Picked up %s: %s\n", name, buffer);
  2773     char* rd = buffer;                        // pointer to the input string (rd)
  2774     int i;
  2775     for (i = 0; i < N_MAX_OPTIONS;) {         // repeat for all options in the input string
  2776       while (isspace(*rd)) rd++;              // skip whitespace
  2777       if (*rd == 0) break;                    // we re done when the input string is read completely
  2779       // The output, option string, overwrites the input string.
  2780       // Because of quoting, the pointer to the option string (wrt) may lag the pointer to
  2781       // input string (rd).
  2782       char* wrt = rd;
  2784       options[i++].optionString = wrt;        // Fill in option
  2785       while (*rd != 0 && !isspace(*rd)) {     // unquoted strings terminate with a space or NULL
  2786         if (*rd == '\'' || *rd == '"') {      // handle a quoted string
  2787           int quote = *rd;                    // matching quote to look for
  2788           rd++;                               // don't copy open quote
  2789           while (*rd != quote) {              // include everything (even spaces) up until quote
  2790             if (*rd == 0) {                   // string termination means unmatched string
  2791               jio_fprintf(defaultStream::error_stream(),
  2792                           "Unmatched quote in %s\n", name);
  2793               return JNI_ERR;
  2795             *wrt++ = *rd++;                   // copy to option string
  2797           rd++;                               // don't copy close quote
  2798         } else {
  2799           *wrt++ = *rd++;                     // copy to option string
  2802       // Need to check if we're done before writing a NULL,
  2803       // because the write could be to the byte that rd is pointing to.
  2804       if (*rd++ == 0) {
  2805         *wrt = 0;
  2806         break;
  2808       *wrt = 0;                               // Zero terminate option
  2810     // Construct JavaVMInitArgs structure and parse as if it was part of the command line
  2811     JavaVMInitArgs vm_args;
  2812     vm_args.version = JNI_VERSION_1_2;
  2813     vm_args.options = options;
  2814     vm_args.nOptions = i;
  2815     vm_args.ignoreUnrecognized = IgnoreUnrecognizedVMOptions;
  2817     if (PrintVMOptions) {
  2818       const char* tail;
  2819       for (int i = 0; i < vm_args.nOptions; i++) {
  2820         const JavaVMOption *option = vm_args.options + i;
  2821         if (match_option(option, "-XX:", &tail)) {
  2822           logOption(tail);
  2827     return(parse_each_vm_init_arg(&vm_args, scp_p, scp_assembly_required_p, ENVIRON_VAR));
  2829   return JNI_OK;
  2832 // Parse entry point called from JNI_CreateJavaVM
  2834 jint Arguments::parse(const JavaVMInitArgs* args) {
  2836   // Sharing support
  2837   // Construct the path to the archive
  2838   char jvm_path[JVM_MAXPATHLEN];
  2839   os::jvm_path(jvm_path, sizeof(jvm_path));
  2840 #ifdef TIERED
  2841   if (strstr(jvm_path, "client") != NULL) {
  2842     force_client_mode = true;
  2844 #endif // TIERED
  2845   char *end = strrchr(jvm_path, *os::file_separator());
  2846   if (end != NULL) *end = '\0';
  2847   char *shared_archive_path = NEW_C_HEAP_ARRAY(char, strlen(jvm_path) +
  2848                                         strlen(os::file_separator()) + 20);
  2849   if (shared_archive_path == NULL) return JNI_ENOMEM;
  2850   strcpy(shared_archive_path, jvm_path);
  2851   strcat(shared_archive_path, os::file_separator());
  2852   strcat(shared_archive_path, "classes");
  2853   DEBUG_ONLY(strcat(shared_archive_path, "_g");)
  2854   strcat(shared_archive_path, ".jsa");
  2855   SharedArchivePath = shared_archive_path;
  2857   // Remaining part of option string
  2858   const char* tail;
  2860   // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed.
  2861   bool settings_file_specified = false;
  2862   const char* flags_file;
  2863   int index;
  2864   for (index = 0; index < args->nOptions; index++) {
  2865     const JavaVMOption *option = args->options + index;
  2866     if (match_option(option, "-XX:Flags=", &tail)) {
  2867       flags_file = tail;
  2868       settings_file_specified = true;
  2870     if (match_option(option, "-XX:+PrintVMOptions", &tail)) {
  2871       PrintVMOptions = true;
  2873     if (match_option(option, "-XX:-PrintVMOptions", &tail)) {
  2874       PrintVMOptions = false;
  2876     if (match_option(option, "-XX:+IgnoreUnrecognizedVMOptions", &tail)) {
  2877       IgnoreUnrecognizedVMOptions = true;
  2879     if (match_option(option, "-XX:-IgnoreUnrecognizedVMOptions", &tail)) {
  2880       IgnoreUnrecognizedVMOptions = false;
  2882     if (match_option(option, "-XX:+PrintFlagsInitial", &tail)) {
  2883       CommandLineFlags::printFlags();
  2884       vm_exit(0);
  2887 #ifndef PRODUCT
  2888     if (match_option(option, "-XX:+PrintFlagsWithComments", &tail)) {
  2889       CommandLineFlags::printFlags(true);
  2890       vm_exit(0);
  2892 #endif
  2895   if (IgnoreUnrecognizedVMOptions) {
  2896     // uncast const to modify the flag args->ignoreUnrecognized
  2897     *(jboolean*)(&args->ignoreUnrecognized) = true;
  2900   // Parse specified settings file
  2901   if (settings_file_specified) {
  2902     if (!process_settings_file(flags_file, true, args->ignoreUnrecognized)) {
  2903       return JNI_EINVAL;
  2907   // Parse default .hotspotrc settings file
  2908   if (!settings_file_specified) {
  2909     if (!process_settings_file(".hotspotrc", false, args->ignoreUnrecognized)) {
  2910       return JNI_EINVAL;
  2914   if (PrintVMOptions) {
  2915     for (index = 0; index < args->nOptions; index++) {
  2916       const JavaVMOption *option = args->options + index;
  2917       if (match_option(option, "-XX:", &tail)) {
  2918         logOption(tail);
  2923   // Parse JavaVMInitArgs structure passed in, as well as JAVA_TOOL_OPTIONS and _JAVA_OPTIONS
  2924   jint result = parse_vm_init_args(args);
  2925   if (result != JNI_OK) {
  2926     return result;
  2929 #ifndef PRODUCT
  2930   if (TraceBytecodesAt != 0) {
  2931     TraceBytecodes = true;
  2933   if (CountCompiledCalls) {
  2934     if (UseCounterDecay) {
  2935       warning("UseCounterDecay disabled because CountCalls is set");
  2936       UseCounterDecay = false;
  2939 #endif // PRODUCT
  2941   if (EnableInvokeDynamic && !EnableMethodHandles) {
  2942     if (!FLAG_IS_DEFAULT(EnableMethodHandles)) {
  2943       warning("forcing EnableMethodHandles true because EnableInvokeDynamic is true");
  2945     EnableMethodHandles = true;
  2947   if (EnableMethodHandles && !AnonymousClasses) {
  2948     if (!FLAG_IS_DEFAULT(AnonymousClasses)) {
  2949       warning("forcing AnonymousClasses true because EnableMethodHandles is true");
  2951     AnonymousClasses = true;
  2953   if ((EnableMethodHandles || AnonymousClasses) && ScavengeRootsInCode == 0) {
  2954     if (!FLAG_IS_DEFAULT(ScavengeRootsInCode)) {
  2955       warning("forcing ScavengeRootsInCode non-zero because EnableMethodHandles or AnonymousClasses is true");
  2957     ScavengeRootsInCode = 1;
  2959 #ifdef COMPILER2
  2960   if (EnableInvokeDynamic && DoEscapeAnalysis) {
  2961     // TODO: We need to find rules for invokedynamic and EA.  For now,
  2962     // simply disable EA by default.
  2963     if (FLAG_IS_DEFAULT(DoEscapeAnalysis)) {
  2964       DoEscapeAnalysis = false;
  2967 #endif
  2969   if (PrintGCDetails) {
  2970     // Turn on -verbose:gc options as well
  2971     PrintGC = true;
  2974 #if defined(_LP64) && defined(COMPILER1) && !defined(TIERED)
  2975   UseCompressedOops = false;
  2976 #endif
  2978   // Set object alignment values.
  2979   set_object_alignment();
  2981 #ifdef SERIALGC
  2982   force_serial_gc();
  2983 #endif // SERIALGC
  2984 #ifdef KERNEL
  2985   no_shared_spaces();
  2986 #endif // KERNEL
  2988   // Set flags based on ergonomics.
  2989   set_ergonomics_flags();
  2991 #ifdef _LP64
  2992   // XXX JSR 292 currently does not support compressed oops.
  2993   if (EnableMethodHandles && UseCompressedOops) {
  2994     if (FLAG_IS_DEFAULT(UseCompressedOops) || FLAG_IS_ERGO(UseCompressedOops)) {
  2995       UseCompressedOops = false;
  2998 #endif // _LP64
  3000   // Check the GC selections again.
  3001   if (!check_gc_consistency()) {
  3002     return JNI_EINVAL;
  3005   if (TieredCompilation) {
  3006     set_tiered_flags();
  3007   } else {
  3008     // Check if the policy is valid. Policies 0 and 1 are valid for non-tiered setup.
  3009     if (CompilationPolicyChoice >= 2) {
  3010       vm_exit_during_initialization(
  3011         "Incompatible compilation policy selected", NULL);
  3015 #ifndef KERNEL
  3016   if (UseConcMarkSweepGC) {
  3017     // Set flags for CMS and ParNew.  Check UseConcMarkSweep first
  3018     // to ensure that when both UseConcMarkSweepGC and UseParNewGC
  3019     // are true, we don't call set_parnew_gc_flags() as well.
  3020     set_cms_and_parnew_gc_flags();
  3021   } else {
  3022     // Set heap size based on available physical memory
  3023     set_heap_size();
  3024     // Set per-collector flags
  3025     if (UseParallelGC || UseParallelOldGC) {
  3026       set_parallel_gc_flags();
  3027     } else if (UseParNewGC) {
  3028       set_parnew_gc_flags();
  3029     } else if (UseG1GC) {
  3030       set_g1_gc_flags();
  3033 #endif // KERNEL
  3035 #ifdef SERIALGC
  3036   assert(verify_serial_gc_flags(), "SerialGC unset");
  3037 #endif // SERIALGC
  3039   // Set bytecode rewriting flags
  3040   set_bytecode_flags();
  3042   // Set flags if Aggressive optimization flags (-XX:+AggressiveOpts) enabled.
  3043   set_aggressive_opts_flags();
  3045 #ifdef CC_INTERP
  3046   // Clear flags not supported by the C++ interpreter
  3047   FLAG_SET_DEFAULT(ProfileInterpreter, false);
  3048   FLAG_SET_DEFAULT(UseBiasedLocking, false);
  3049   LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedOops, false));
  3050 #endif // CC_INTERP
  3052 #ifdef COMPILER2
  3053   if (!UseBiasedLocking || EmitSync != 0) {
  3054     UseOptoBiasInlining = false;
  3056 #endif
  3058   if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
  3059     warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
  3060     DebugNonSafepoints = true;
  3063 #ifndef PRODUCT
  3064   if (CompileTheWorld) {
  3065     // Force NmethodSweeper to sweep whole CodeCache each time.
  3066     if (FLAG_IS_DEFAULT(NmethodSweepFraction)) {
  3067       NmethodSweepFraction = 1;
  3070 #endif
  3072   if (PrintCommandLineFlags) {
  3073     CommandLineFlags::printSetFlags();
  3076   // Apply CPU specific policy for the BiasedLocking
  3077   if (UseBiasedLocking) {
  3078     if (!VM_Version::use_biased_locking() &&
  3079         !(FLAG_IS_CMDLINE(UseBiasedLocking))) {
  3080       UseBiasedLocking = false;
  3084   return JNI_OK;
  3087 int Arguments::PropertyList_count(SystemProperty* pl) {
  3088   int count = 0;
  3089   while(pl != NULL) {
  3090     count++;
  3091     pl = pl->next();
  3093   return count;
  3096 const char* Arguments::PropertyList_get_value(SystemProperty *pl, const char* key) {
  3097   assert(key != NULL, "just checking");
  3098   SystemProperty* prop;
  3099   for (prop = pl; prop != NULL; prop = prop->next()) {
  3100     if (strcmp(key, prop->key()) == 0) return prop->value();
  3102   return NULL;
  3105 const char* Arguments::PropertyList_get_key_at(SystemProperty *pl, int index) {
  3106   int count = 0;
  3107   const char* ret_val = NULL;
  3109   while(pl != NULL) {
  3110     if(count >= index) {
  3111       ret_val = pl->key();
  3112       break;
  3114     count++;
  3115     pl = pl->next();
  3118   return ret_val;
  3121 char* Arguments::PropertyList_get_value_at(SystemProperty* pl, int index) {
  3122   int count = 0;
  3123   char* ret_val = NULL;
  3125   while(pl != NULL) {
  3126     if(count >= index) {
  3127       ret_val = pl->value();
  3128       break;
  3130     count++;
  3131     pl = pl->next();
  3134   return ret_val;
  3137 void Arguments::PropertyList_add(SystemProperty** plist, SystemProperty *new_p) {
  3138   SystemProperty* p = *plist;
  3139   if (p == NULL) {
  3140     *plist = new_p;
  3141   } else {
  3142     while (p->next() != NULL) {
  3143       p = p->next();
  3145     p->set_next(new_p);
  3149 void Arguments::PropertyList_add(SystemProperty** plist, const char* k, char* v) {
  3150   if (plist == NULL)
  3151     return;
  3153   SystemProperty* new_p = new SystemProperty(k, v, true);
  3154   PropertyList_add(plist, new_p);
  3157 // This add maintains unique property key in the list.
  3158 void Arguments::PropertyList_unique_add(SystemProperty** plist, const char* k, char* v, jboolean append) {
  3159   if (plist == NULL)
  3160     return;
  3162   // If property key exist then update with new value.
  3163   SystemProperty* prop;
  3164   for (prop = *plist; prop != NULL; prop = prop->next()) {
  3165     if (strcmp(k, prop->key()) == 0) {
  3166       if (append) {
  3167         prop->append_value(v);
  3168       } else {
  3169         prop->set_value(v);
  3171       return;
  3175   PropertyList_add(plist, k, v);
  3178 #ifdef KERNEL
  3179 char *Arguments::get_kernel_properties() {
  3180   // Find properties starting with kernel and append them to string
  3181   // We need to find out how long they are first because the URL's that they
  3182   // might point to could get long.
  3183   int length = 0;
  3184   SystemProperty* prop;
  3185   for (prop = _system_properties; prop != NULL; prop = prop->next()) {
  3186     if (strncmp(prop->key(), "kernel.", 7 ) == 0) {
  3187       length += (strlen(prop->key()) + strlen(prop->value()) + 5);  // "-D ="
  3190   // Add one for null terminator.
  3191   char *props = AllocateHeap(length + 1, "get_kernel_properties");
  3192   if (length != 0) {
  3193     int pos = 0;
  3194     for (prop = _system_properties; prop != NULL; prop = prop->next()) {
  3195       if (strncmp(prop->key(), "kernel.", 7 ) == 0) {
  3196         jio_snprintf(&props[pos], length-pos,
  3197                      "-D%s=%s ", prop->key(), prop->value());
  3198         pos = strlen(props);
  3202   // null terminate props in case of null
  3203   props[length] = '\0';
  3204   return props;
  3206 #endif // KERNEL
  3208 // Copies src into buf, replacing "%%" with "%" and "%p" with pid
  3209 // Returns true if all of the source pointed by src has been copied over to
  3210 // the destination buffer pointed by buf. Otherwise, returns false.
  3211 // Notes:
  3212 // 1. If the length (buflen) of the destination buffer excluding the
  3213 // NULL terminator character is not long enough for holding the expanded
  3214 // pid characters, it also returns false instead of returning the partially
  3215 // expanded one.
  3216 // 2. The passed in "buflen" should be large enough to hold the null terminator.
  3217 bool Arguments::copy_expand_pid(const char* src, size_t srclen,
  3218                                 char* buf, size_t buflen) {
  3219   const char* p = src;
  3220   char* b = buf;
  3221   const char* src_end = &src[srclen];
  3222   char* buf_end = &buf[buflen - 1];
  3224   while (p < src_end && b < buf_end) {
  3225     if (*p == '%') {
  3226       switch (*(++p)) {
  3227       case '%':         // "%%" ==> "%"
  3228         *b++ = *p++;
  3229         break;
  3230       case 'p':  {       //  "%p" ==> current process id
  3231         // buf_end points to the character before the last character so
  3232         // that we could write '\0' to the end of the buffer.
  3233         size_t buf_sz = buf_end - b + 1;
  3234         int ret = jio_snprintf(b, buf_sz, "%d", os::current_process_id());
  3236         // if jio_snprintf fails or the buffer is not long enough to hold
  3237         // the expanded pid, returns false.
  3238         if (ret < 0 || ret >= (int)buf_sz) {
  3239           return false;
  3240         } else {
  3241           b += ret;
  3242           assert(*b == '\0', "fail in copy_expand_pid");
  3243           if (p == src_end && b == buf_end + 1) {
  3244             // reach the end of the buffer.
  3245             return true;
  3248         p++;
  3249         break;
  3251       default :
  3252         *b++ = '%';
  3254     } else {
  3255       *b++ = *p++;
  3258   *b = '\0';
  3259   return (p == src_end); // return false if not all of the source was copied

mercurial