src/share/vm/runtime/arguments.cpp

Wed, 03 Jul 2013 17:26:59 -0400

author
jiangli
date
Wed, 03 Jul 2013 17:26:59 -0400
changeset 5369
71180a6e5080
parent 5292
b88209cf98c0
child 5370
fa6929d0b0a9
permissions
-rw-r--r--

7133260: AllocationProfiler uses space in metadata and doesn't seem to do anything useful.
Summary: Remove -Xaprof and Klass::_alloc_count & ArrayKlass::_alloc_size.
Reviewed-by: stefank, coleenp

     1 /*
     2  * Copyright (c) 1997, 2013, 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 "precompiled.hpp"
    26 #include "classfile/javaAssertions.hpp"
    27 #include "classfile/symbolTable.hpp"
    28 #include "compiler/compilerOracle.hpp"
    29 #include "memory/allocation.inline.hpp"
    30 #include "memory/cardTableRS.hpp"
    31 #include "memory/referenceProcessor.hpp"
    32 #include "memory/universe.inline.hpp"
    33 #include "oops/oop.inline.hpp"
    34 #include "prims/jvmtiExport.hpp"
    35 #include "runtime/arguments.hpp"
    36 #include "runtime/globals_extension.hpp"
    37 #include "runtime/java.hpp"
    38 #include "services/management.hpp"
    39 #include "services/memTracker.hpp"
    40 #include "utilities/defaultStream.hpp"
    41 #include "utilities/macros.hpp"
    42 #include "utilities/taskqueue.hpp"
    43 #ifdef TARGET_OS_FAMILY_linux
    44 # include "os_linux.inline.hpp"
    45 #endif
    46 #ifdef TARGET_OS_FAMILY_solaris
    47 # include "os_solaris.inline.hpp"
    48 #endif
    49 #ifdef TARGET_OS_FAMILY_windows
    50 # include "os_windows.inline.hpp"
    51 #endif
    52 #ifdef TARGET_OS_FAMILY_bsd
    53 # include "os_bsd.inline.hpp"
    54 #endif
    55 #if INCLUDE_ALL_GCS
    56 #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp"
    57 #endif // INCLUDE_ALL_GCS
    59 // Note: This is a special bug reporting site for the JVM
    60 #define DEFAULT_VENDOR_URL_BUG "http://bugreport.sun.com/bugreport/crash.jsp"
    61 #define DEFAULT_JAVA_LAUNCHER  "generic"
    63 char**  Arguments::_jvm_flags_array             = NULL;
    64 int     Arguments::_num_jvm_flags               = 0;
    65 char**  Arguments::_jvm_args_array              = NULL;
    66 int     Arguments::_num_jvm_args                = 0;
    67 char*  Arguments::_java_command                 = NULL;
    68 SystemProperty* Arguments::_system_properties   = NULL;
    69 const char*  Arguments::_gc_log_filename        = NULL;
    70 bool   Arguments::_has_profile                  = false;
    71 uintx  Arguments::_min_heap_size                = 0;
    72 Arguments::Mode Arguments::_mode                = _mixed;
    73 bool   Arguments::_java_compiler                = false;
    74 bool   Arguments::_xdebug_mode                  = false;
    75 const char*  Arguments::_java_vendor_url_bug    = DEFAULT_VENDOR_URL_BUG;
    76 const char*  Arguments::_sun_java_launcher      = DEFAULT_JAVA_LAUNCHER;
    77 int    Arguments::_sun_java_launcher_pid        = -1;
    78 bool   Arguments::_created_by_gamma_launcher    = false;
    80 // These parameters are reset in method parse_vm_init_args(JavaVMInitArgs*)
    81 bool   Arguments::_AlwaysCompileLoopMethods     = AlwaysCompileLoopMethods;
    82 bool   Arguments::_UseOnStackReplacement        = UseOnStackReplacement;
    83 bool   Arguments::_BackgroundCompilation        = BackgroundCompilation;
    84 bool   Arguments::_ClipInlining                 = ClipInlining;
    86 char*  Arguments::SharedArchivePath             = NULL;
    88 AgentLibraryList Arguments::_libraryList;
    89 AgentLibraryList Arguments::_agentList;
    91 abort_hook_t     Arguments::_abort_hook         = NULL;
    92 exit_hook_t      Arguments::_exit_hook          = NULL;
    93 vfprintf_hook_t  Arguments::_vfprintf_hook      = NULL;
    96 SystemProperty *Arguments::_java_ext_dirs = NULL;
    97 SystemProperty *Arguments::_java_endorsed_dirs = NULL;
    98 SystemProperty *Arguments::_sun_boot_library_path = NULL;
    99 SystemProperty *Arguments::_java_library_path = NULL;
   100 SystemProperty *Arguments::_java_home = NULL;
   101 SystemProperty *Arguments::_java_class_path = NULL;
   102 SystemProperty *Arguments::_sun_boot_class_path = NULL;
   104 char* Arguments::_meta_index_path = NULL;
   105 char* Arguments::_meta_index_dir = NULL;
   107 // Check if head of 'option' matches 'name', and sets 'tail' remaining part of option string
   109 static bool match_option(const JavaVMOption *option, const char* name,
   110                          const char** tail) {
   111   int len = (int)strlen(name);
   112   if (strncmp(option->optionString, name, len) == 0) {
   113     *tail = option->optionString + len;
   114     return true;
   115   } else {
   116     return false;
   117   }
   118 }
   120 static void logOption(const char* opt) {
   121   if (PrintVMOptions) {
   122     jio_fprintf(defaultStream::output_stream(), "VM option '%s'\n", opt);
   123   }
   124 }
   126 // Process java launcher properties.
   127 void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
   128   // See if sun.java.launcher or sun.java.launcher.pid is defined.
   129   // Must do this before setting up other system properties,
   130   // as some of them may depend on launcher type.
   131   for (int index = 0; index < args->nOptions; index++) {
   132     const JavaVMOption* option = args->options + index;
   133     const char* tail;
   135     if (match_option(option, "-Dsun.java.launcher=", &tail)) {
   136       process_java_launcher_argument(tail, option->extraInfo);
   137       continue;
   138     }
   139     if (match_option(option, "-Dsun.java.launcher.pid=", &tail)) {
   140       _sun_java_launcher_pid = atoi(tail);
   141       continue;
   142     }
   143   }
   144 }
   146 // Initialize system properties key and value.
   147 void Arguments::init_system_properties() {
   149   PropertyList_add(&_system_properties, new SystemProperty("java.vm.specification.name",
   150                                                                  "Java Virtual Machine Specification",  false));
   151   PropertyList_add(&_system_properties, new SystemProperty("java.vm.version", VM_Version::vm_release(),  false));
   152   PropertyList_add(&_system_properties, new SystemProperty("java.vm.name", VM_Version::vm_name(),  false));
   153   PropertyList_add(&_system_properties, new SystemProperty("java.vm.info", VM_Version::vm_info_string(),  true));
   155   // following are JVMTI agent writeable properties.
   156   // Properties values are set to NULL and they are
   157   // os specific they are initialized in os::init_system_properties_values().
   158   _java_ext_dirs = new SystemProperty("java.ext.dirs", NULL,  true);
   159   _java_endorsed_dirs = new SystemProperty("java.endorsed.dirs", NULL,  true);
   160   _sun_boot_library_path = new SystemProperty("sun.boot.library.path", NULL,  true);
   161   _java_library_path = new SystemProperty("java.library.path", NULL,  true);
   162   _java_home =  new SystemProperty("java.home", NULL,  true);
   163   _sun_boot_class_path = new SystemProperty("sun.boot.class.path", NULL,  true);
   165   _java_class_path = new SystemProperty("java.class.path", "",  true);
   167   // Add to System Property list.
   168   PropertyList_add(&_system_properties, _java_ext_dirs);
   169   PropertyList_add(&_system_properties, _java_endorsed_dirs);
   170   PropertyList_add(&_system_properties, _sun_boot_library_path);
   171   PropertyList_add(&_system_properties, _java_library_path);
   172   PropertyList_add(&_system_properties, _java_home);
   173   PropertyList_add(&_system_properties, _java_class_path);
   174   PropertyList_add(&_system_properties, _sun_boot_class_path);
   176   // Set OS specific system properties values
   177   os::init_system_properties_values();
   178 }
   181   // Update/Initialize System properties after JDK version number is known
   182 void Arguments::init_version_specific_system_properties() {
   183   enum { bufsz = 16 };
   184   char buffer[bufsz];
   185   const char* spec_vendor = "Sun Microsystems Inc.";
   186   uint32_t spec_version = 0;
   188   if (JDK_Version::is_gte_jdk17x_version()) {
   189     spec_vendor = "Oracle Corporation";
   190     spec_version = JDK_Version::current().major_version();
   191   }
   192   jio_snprintf(buffer, bufsz, "1." UINT32_FORMAT, spec_version);
   194   PropertyList_add(&_system_properties,
   195       new SystemProperty("java.vm.specification.vendor",  spec_vendor, false));
   196   PropertyList_add(&_system_properties,
   197       new SystemProperty("java.vm.specification.version", buffer, false));
   198   PropertyList_add(&_system_properties,
   199       new SystemProperty("java.vm.vendor", VM_Version::vm_vendor(),  false));
   200 }
   202 /**
   203  * Provide a slightly more user-friendly way of eliminating -XX flags.
   204  * When a flag is eliminated, it can be added to this list in order to
   205  * continue accepting this flag on the command-line, while issuing a warning
   206  * and ignoring the value.  Once the JDK version reaches the 'accept_until'
   207  * limit, we flatly refuse to admit the existence of the flag.  This allows
   208  * a flag to die correctly over JDK releases using HSX.
   209  */
   210 typedef struct {
   211   const char* name;
   212   JDK_Version obsoleted_in; // when the flag went away
   213   JDK_Version accept_until; // which version to start denying the existence
   214 } ObsoleteFlag;
   216 static ObsoleteFlag obsolete_jvm_flags[] = {
   217   { "UseTrainGC",                    JDK_Version::jdk(5), JDK_Version::jdk(7) },
   218   { "UseSpecialLargeObjectHandling", JDK_Version::jdk(5), JDK_Version::jdk(7) },
   219   { "UseOversizedCarHandling",       JDK_Version::jdk(5), JDK_Version::jdk(7) },
   220   { "TraceCarAllocation",            JDK_Version::jdk(5), JDK_Version::jdk(7) },
   221   { "PrintTrainGCProcessingStats",   JDK_Version::jdk(5), JDK_Version::jdk(7) },
   222   { "LogOfCarSpaceSize",             JDK_Version::jdk(5), JDK_Version::jdk(7) },
   223   { "OversizedCarThreshold",         JDK_Version::jdk(5), JDK_Version::jdk(7) },
   224   { "MinTickInterval",               JDK_Version::jdk(5), JDK_Version::jdk(7) },
   225   { "DefaultTickInterval",           JDK_Version::jdk(5), JDK_Version::jdk(7) },
   226   { "MaxTickInterval",               JDK_Version::jdk(5), JDK_Version::jdk(7) },
   227   { "DelayTickAdjustment",           JDK_Version::jdk(5), JDK_Version::jdk(7) },
   228   { "ProcessingToTenuringRatio",     JDK_Version::jdk(5), JDK_Version::jdk(7) },
   229   { "MinTrainLength",                JDK_Version::jdk(5), JDK_Version::jdk(7) },
   230   { "AppendRatio",         JDK_Version::jdk_update(6,10), JDK_Version::jdk(7) },
   231   { "DefaultMaxRAM",       JDK_Version::jdk_update(6,18), JDK_Version::jdk(7) },
   232   { "DefaultInitialRAMFraction",
   233                            JDK_Version::jdk_update(6,18), JDK_Version::jdk(7) },
   234   { "UseDepthFirstScavengeOrder",
   235                            JDK_Version::jdk_update(6,22), JDK_Version::jdk(7) },
   236   { "HandlePromotionFailure",
   237                            JDK_Version::jdk_update(6,24), JDK_Version::jdk(8) },
   238   { "MaxLiveObjectEvacuationRatio",
   239                            JDK_Version::jdk_update(6,24), JDK_Version::jdk(8) },
   240   { "ForceSharedSpaces",   JDK_Version::jdk_update(6,25), JDK_Version::jdk(8) },
   241   { "UseParallelOldGCCompacting",
   242                            JDK_Version::jdk_update(6,27), JDK_Version::jdk(8) },
   243   { "UseParallelDensePrefixUpdate",
   244                            JDK_Version::jdk_update(6,27), JDK_Version::jdk(8) },
   245   { "UseParallelOldGCDensePrefix",
   246                            JDK_Version::jdk_update(6,27), JDK_Version::jdk(8) },
   247   { "AllowTransitionalJSR292",       JDK_Version::jdk(7), JDK_Version::jdk(8) },
   248   { "UseCompressedStrings",          JDK_Version::jdk(7), JDK_Version::jdk(8) },
   249   { "CMSPermGenPrecleaningEnabled", JDK_Version::jdk(8),  JDK_Version::jdk(9) },
   250   { "CMSTriggerPermRatio", JDK_Version::jdk(8),  JDK_Version::jdk(9) },
   251   { "CMSInitiatingPermOccupancyFraction", JDK_Version::jdk(8),  JDK_Version::jdk(9) },
   252   { "AdaptivePermSizeWeight", JDK_Version::jdk(8),  JDK_Version::jdk(9) },
   253   { "PermGenPadding", JDK_Version::jdk(8),  JDK_Version::jdk(9) },
   254   { "PermMarkSweepDeadRatio", JDK_Version::jdk(8),  JDK_Version::jdk(9) },
   255   { "PermSize", JDK_Version::jdk(8),  JDK_Version::jdk(9) },
   256   { "MaxPermSize", JDK_Version::jdk(8),  JDK_Version::jdk(9) },
   257   { "MinPermHeapExpansion", JDK_Version::jdk(8),  JDK_Version::jdk(9) },
   258   { "MaxPermHeapExpansion", JDK_Version::jdk(8),  JDK_Version::jdk(9) },
   259   { "CMSRevisitStackSize",           JDK_Version::jdk(8), JDK_Version::jdk(9) },
   260   { "PrintRevisitStats",             JDK_Version::jdk(8), JDK_Version::jdk(9) },
   261   { "UseVectoredExceptions",         JDK_Version::jdk(8), JDK_Version::jdk(9) },
   262   { "UseSplitVerifier",              JDK_Version::jdk(8), JDK_Version::jdk(9) },
   263 #ifdef PRODUCT
   264   { "DesiredMethodLimit",
   265                            JDK_Version::jdk_update(7, 2), JDK_Version::jdk(8) },
   266 #endif // PRODUCT
   267   { NULL, JDK_Version(0), JDK_Version(0) }
   268 };
   270 // Returns true if the flag is obsolete and fits into the range specified
   271 // for being ignored.  In the case that the flag is ignored, the 'version'
   272 // value is filled in with the version number when the flag became
   273 // obsolete so that that value can be displayed to the user.
   274 bool Arguments::is_newly_obsolete(const char *s, JDK_Version* version) {
   275   int i = 0;
   276   assert(version != NULL, "Must provide a version buffer");
   277   while (obsolete_jvm_flags[i].name != NULL) {
   278     const ObsoleteFlag& flag_status = obsolete_jvm_flags[i];
   279     // <flag>=xxx form
   280     // [-|+]<flag> form
   281     if ((strncmp(flag_status.name, s, strlen(flag_status.name)) == 0) ||
   282         ((s[0] == '+' || s[0] == '-') &&
   283         (strncmp(flag_status.name, &s[1], strlen(flag_status.name)) == 0))) {
   284       if (JDK_Version::current().compare(flag_status.accept_until) == -1) {
   285           *version = flag_status.obsoleted_in;
   286           return true;
   287       }
   288     }
   289     i++;
   290   }
   291   return false;
   292 }
   294 // Constructs the system class path (aka boot class path) from the following
   295 // components, in order:
   296 //
   297 //     prefix           // from -Xbootclasspath/p:...
   298 //     endorsed         // the expansion of -Djava.endorsed.dirs=...
   299 //     base             // from os::get_system_properties() or -Xbootclasspath=
   300 //     suffix           // from -Xbootclasspath/a:...
   301 //
   302 // java.endorsed.dirs is a list of directories; any jar or zip files in the
   303 // directories are added to the sysclasspath just before the base.
   304 //
   305 // This could be AllStatic, but it isn't needed after argument processing is
   306 // complete.
   307 class SysClassPath: public StackObj {
   308 public:
   309   SysClassPath(const char* base);
   310   ~SysClassPath();
   312   inline void set_base(const char* base);
   313   inline void add_prefix(const char* prefix);
   314   inline void add_suffix_to_prefix(const char* suffix);
   315   inline void add_suffix(const char* suffix);
   316   inline void reset_path(const char* base);
   318   // Expand the jar/zip files in each directory listed by the java.endorsed.dirs
   319   // property.  Must be called after all command-line arguments have been
   320   // processed (in particular, -Djava.endorsed.dirs=...) and before calling
   321   // combined_path().
   322   void expand_endorsed();
   324   inline const char* get_base()     const { return _items[_scp_base]; }
   325   inline const char* get_prefix()   const { return _items[_scp_prefix]; }
   326   inline const char* get_suffix()   const { return _items[_scp_suffix]; }
   327   inline const char* get_endorsed() const { return _items[_scp_endorsed]; }
   329   // Combine all the components into a single c-heap-allocated string; caller
   330   // must free the string if/when no longer needed.
   331   char* combined_path();
   333 private:
   334   // Utility routines.
   335   static char* add_to_path(const char* path, const char* str, bool prepend);
   336   static char* add_jars_to_path(char* path, const char* directory);
   338   inline void reset_item_at(int index);
   340   // Array indices for the items that make up the sysclasspath.  All except the
   341   // base are allocated in the C heap and freed by this class.
   342   enum {
   343     _scp_prefix,        // from -Xbootclasspath/p:...
   344     _scp_endorsed,      // the expansion of -Djava.endorsed.dirs=...
   345     _scp_base,          // the default sysclasspath
   346     _scp_suffix,        // from -Xbootclasspath/a:...
   347     _scp_nitems         // the number of items, must be last.
   348   };
   350   const char* _items[_scp_nitems];
   351   DEBUG_ONLY(bool _expansion_done;)
   352 };
   354 SysClassPath::SysClassPath(const char* base) {
   355   memset(_items, 0, sizeof(_items));
   356   _items[_scp_base] = base;
   357   DEBUG_ONLY(_expansion_done = false;)
   358 }
   360 SysClassPath::~SysClassPath() {
   361   // Free everything except the base.
   362   for (int i = 0; i < _scp_nitems; ++i) {
   363     if (i != _scp_base) reset_item_at(i);
   364   }
   365   DEBUG_ONLY(_expansion_done = false;)
   366 }
   368 inline void SysClassPath::set_base(const char* base) {
   369   _items[_scp_base] = base;
   370 }
   372 inline void SysClassPath::add_prefix(const char* prefix) {
   373   _items[_scp_prefix] = add_to_path(_items[_scp_prefix], prefix, true);
   374 }
   376 inline void SysClassPath::add_suffix_to_prefix(const char* suffix) {
   377   _items[_scp_prefix] = add_to_path(_items[_scp_prefix], suffix, false);
   378 }
   380 inline void SysClassPath::add_suffix(const char* suffix) {
   381   _items[_scp_suffix] = add_to_path(_items[_scp_suffix], suffix, false);
   382 }
   384 inline void SysClassPath::reset_item_at(int index) {
   385   assert(index < _scp_nitems && index != _scp_base, "just checking");
   386   if (_items[index] != NULL) {
   387     FREE_C_HEAP_ARRAY(char, _items[index], mtInternal);
   388     _items[index] = NULL;
   389   }
   390 }
   392 inline void SysClassPath::reset_path(const char* base) {
   393   // Clear the prefix and suffix.
   394   reset_item_at(_scp_prefix);
   395   reset_item_at(_scp_suffix);
   396   set_base(base);
   397 }
   399 //------------------------------------------------------------------------------
   401 void SysClassPath::expand_endorsed() {
   402   assert(_items[_scp_endorsed] == NULL, "can only be called once.");
   404   const char* path = Arguments::get_property("java.endorsed.dirs");
   405   if (path == NULL) {
   406     path = Arguments::get_endorsed_dir();
   407     assert(path != NULL, "no default for java.endorsed.dirs");
   408   }
   410   char* expanded_path = NULL;
   411   const char separator = *os::path_separator();
   412   const char* const end = path + strlen(path);
   413   while (path < end) {
   414     const char* tmp_end = strchr(path, separator);
   415     if (tmp_end == NULL) {
   416       expanded_path = add_jars_to_path(expanded_path, path);
   417       path = end;
   418     } else {
   419       char* dirpath = NEW_C_HEAP_ARRAY(char, tmp_end - path + 1, mtInternal);
   420       memcpy(dirpath, path, tmp_end - path);
   421       dirpath[tmp_end - path] = '\0';
   422       expanded_path = add_jars_to_path(expanded_path, dirpath);
   423       FREE_C_HEAP_ARRAY(char, dirpath, mtInternal);
   424       path = tmp_end + 1;
   425     }
   426   }
   427   _items[_scp_endorsed] = expanded_path;
   428   DEBUG_ONLY(_expansion_done = true;)
   429 }
   431 // Combine the bootclasspath elements, some of which may be null, into a single
   432 // c-heap-allocated string.
   433 char* SysClassPath::combined_path() {
   434   assert(_items[_scp_base] != NULL, "empty default sysclasspath");
   435   assert(_expansion_done, "must call expand_endorsed() first.");
   437   size_t lengths[_scp_nitems];
   438   size_t total_len = 0;
   440   const char separator = *os::path_separator();
   442   // Get the lengths.
   443   int i;
   444   for (i = 0; i < _scp_nitems; ++i) {
   445     if (_items[i] != NULL) {
   446       lengths[i] = strlen(_items[i]);
   447       // Include space for the separator char (or a NULL for the last item).
   448       total_len += lengths[i] + 1;
   449     }
   450   }
   451   assert(total_len > 0, "empty sysclasspath not allowed");
   453   // Copy the _items to a single string.
   454   char* cp = NEW_C_HEAP_ARRAY(char, total_len, mtInternal);
   455   char* cp_tmp = cp;
   456   for (i = 0; i < _scp_nitems; ++i) {
   457     if (_items[i] != NULL) {
   458       memcpy(cp_tmp, _items[i], lengths[i]);
   459       cp_tmp += lengths[i];
   460       *cp_tmp++ = separator;
   461     }
   462   }
   463   *--cp_tmp = '\0';     // Replace the extra separator.
   464   return cp;
   465 }
   467 // Note:  path must be c-heap-allocated (or NULL); it is freed if non-null.
   468 char*
   469 SysClassPath::add_to_path(const char* path, const char* str, bool prepend) {
   470   char *cp;
   472   assert(str != NULL, "just checking");
   473   if (path == NULL) {
   474     size_t len = strlen(str) + 1;
   475     cp = NEW_C_HEAP_ARRAY(char, len, mtInternal);
   476     memcpy(cp, str, len);                       // copy the trailing null
   477   } else {
   478     const char separator = *os::path_separator();
   479     size_t old_len = strlen(path);
   480     size_t str_len = strlen(str);
   481     size_t len = old_len + str_len + 2;
   483     if (prepend) {
   484       cp = NEW_C_HEAP_ARRAY(char, len, mtInternal);
   485       char* cp_tmp = cp;
   486       memcpy(cp_tmp, str, str_len);
   487       cp_tmp += str_len;
   488       *cp_tmp = separator;
   489       memcpy(++cp_tmp, path, old_len + 1);      // copy the trailing null
   490       FREE_C_HEAP_ARRAY(char, path, mtInternal);
   491     } else {
   492       cp = REALLOC_C_HEAP_ARRAY(char, path, len, mtInternal);
   493       char* cp_tmp = cp + old_len;
   494       *cp_tmp = separator;
   495       memcpy(++cp_tmp, str, str_len + 1);       // copy the trailing null
   496     }
   497   }
   498   return cp;
   499 }
   501 // Scan the directory and append any jar or zip files found to path.
   502 // Note:  path must be c-heap-allocated (or NULL); it is freed if non-null.
   503 char* SysClassPath::add_jars_to_path(char* path, const char* directory) {
   504   DIR* dir = os::opendir(directory);
   505   if (dir == NULL) return path;
   507   char dir_sep[2] = { '\0', '\0' };
   508   size_t directory_len = strlen(directory);
   509   const char fileSep = *os::file_separator();
   510   if (directory[directory_len - 1] != fileSep) dir_sep[0] = fileSep;
   512   /* Scan the directory for jars/zips, appending them to path. */
   513   struct dirent *entry;
   514   char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory), mtInternal);
   515   while ((entry = os::readdir(dir, (dirent *) dbuf)) != NULL) {
   516     const char* name = entry->d_name;
   517     const char* ext = name + strlen(name) - 4;
   518     bool isJarOrZip = ext > name &&
   519       (os::file_name_strcmp(ext, ".jar") == 0 ||
   520        os::file_name_strcmp(ext, ".zip") == 0);
   521     if (isJarOrZip) {
   522       char* jarpath = NEW_C_HEAP_ARRAY(char, directory_len + 2 + strlen(name), mtInternal);
   523       sprintf(jarpath, "%s%s%s", directory, dir_sep, name);
   524       path = add_to_path(path, jarpath, false);
   525       FREE_C_HEAP_ARRAY(char, jarpath, mtInternal);
   526     }
   527   }
   528   FREE_C_HEAP_ARRAY(char, dbuf, mtInternal);
   529   os::closedir(dir);
   530   return path;
   531 }
   533 // Parses a memory size specification string.
   534 static bool atomull(const char *s, julong* result) {
   535   julong n = 0;
   536   int args_read = sscanf(s, JULONG_FORMAT, &n);
   537   if (args_read != 1) {
   538     return false;
   539   }
   540   while (*s != '\0' && isdigit(*s)) {
   541     s++;
   542   }
   543   // 4705540: illegal if more characters are found after the first non-digit
   544   if (strlen(s) > 1) {
   545     return false;
   546   }
   547   switch (*s) {
   548     case 'T': case 't':
   549       *result = n * G * K;
   550       // Check for overflow.
   551       if (*result/((julong)G * K) != n) return false;
   552       return true;
   553     case 'G': case 'g':
   554       *result = n * G;
   555       if (*result/G != n) return false;
   556       return true;
   557     case 'M': case 'm':
   558       *result = n * M;
   559       if (*result/M != n) return false;
   560       return true;
   561     case 'K': case 'k':
   562       *result = n * K;
   563       if (*result/K != n) return false;
   564       return true;
   565     case '\0':
   566       *result = n;
   567       return true;
   568     default:
   569       return false;
   570   }
   571 }
   573 Arguments::ArgsRange Arguments::check_memory_size(julong size, julong min_size) {
   574   if (size < min_size) return arg_too_small;
   575   // Check that size will fit in a size_t (only relevant on 32-bit)
   576   if (size > max_uintx) return arg_too_big;
   577   return arg_in_range;
   578 }
   580 // Describe an argument out of range error
   581 void Arguments::describe_range_error(ArgsRange errcode) {
   582   switch(errcode) {
   583   case arg_too_big:
   584     jio_fprintf(defaultStream::error_stream(),
   585                 "The specified size exceeds the maximum "
   586                 "representable size.\n");
   587     break;
   588   case arg_too_small:
   589   case arg_unreadable:
   590   case arg_in_range:
   591     // do nothing for now
   592     break;
   593   default:
   594     ShouldNotReachHere();
   595   }
   596 }
   598 static bool set_bool_flag(char* name, bool value, FlagValueOrigin origin) {
   599   return CommandLineFlags::boolAtPut(name, &value, origin);
   600 }
   602 static bool set_fp_numeric_flag(char* name, char* value, FlagValueOrigin origin) {
   603   double v;
   604   if (sscanf(value, "%lf", &v) != 1) {
   605     return false;
   606   }
   608   if (CommandLineFlags::doubleAtPut(name, &v, origin)) {
   609     return true;
   610   }
   611   return false;
   612 }
   614 static bool set_numeric_flag(char* name, char* value, FlagValueOrigin origin) {
   615   julong v;
   616   intx intx_v;
   617   bool is_neg = false;
   618   // Check the sign first since atomull() parses only unsigned values.
   619   if (*value == '-') {
   620     if (!CommandLineFlags::intxAt(name, &intx_v)) {
   621       return false;
   622     }
   623     value++;
   624     is_neg = true;
   625   }
   626   if (!atomull(value, &v)) {
   627     return false;
   628   }
   629   intx_v = (intx) v;
   630   if (is_neg) {
   631     intx_v = -intx_v;
   632   }
   633   if (CommandLineFlags::intxAtPut(name, &intx_v, origin)) {
   634     return true;
   635   }
   636   uintx uintx_v = (uintx) v;
   637   if (!is_neg && CommandLineFlags::uintxAtPut(name, &uintx_v, origin)) {
   638     return true;
   639   }
   640   uint64_t uint64_t_v = (uint64_t) v;
   641   if (!is_neg && CommandLineFlags::uint64_tAtPut(name, &uint64_t_v, origin)) {
   642     return true;
   643   }
   644   return false;
   645 }
   647 static bool set_string_flag(char* name, const char* value, FlagValueOrigin origin) {
   648   if (!CommandLineFlags::ccstrAtPut(name, &value, origin))  return false;
   649   // Contract:  CommandLineFlags always returns a pointer that needs freeing.
   650   FREE_C_HEAP_ARRAY(char, value, mtInternal);
   651   return true;
   652 }
   654 static bool append_to_string_flag(char* name, const char* new_value, FlagValueOrigin origin) {
   655   const char* old_value = "";
   656   if (!CommandLineFlags::ccstrAt(name, &old_value))  return false;
   657   size_t old_len = old_value != NULL ? strlen(old_value) : 0;
   658   size_t new_len = strlen(new_value);
   659   const char* value;
   660   char* free_this_too = NULL;
   661   if (old_len == 0) {
   662     value = new_value;
   663   } else if (new_len == 0) {
   664     value = old_value;
   665   } else {
   666     char* buf = NEW_C_HEAP_ARRAY(char, old_len + 1 + new_len + 1, mtInternal);
   667     // each new setting adds another LINE to the switch:
   668     sprintf(buf, "%s\n%s", old_value, new_value);
   669     value = buf;
   670     free_this_too = buf;
   671   }
   672   (void) CommandLineFlags::ccstrAtPut(name, &value, origin);
   673   // CommandLineFlags always returns a pointer that needs freeing.
   674   FREE_C_HEAP_ARRAY(char, value, mtInternal);
   675   if (free_this_too != NULL) {
   676     // CommandLineFlags made its own copy, so I must delete my own temp. buffer.
   677     FREE_C_HEAP_ARRAY(char, free_this_too, mtInternal);
   678   }
   679   return true;
   680 }
   682 bool Arguments::parse_argument(const char* arg, FlagValueOrigin origin) {
   684   // range of acceptable characters spelled out for portability reasons
   685 #define NAME_RANGE  "[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]"
   686 #define BUFLEN 255
   687   char name[BUFLEN+1];
   688   char dummy;
   690   if (sscanf(arg, "-%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
   691     return set_bool_flag(name, false, origin);
   692   }
   693   if (sscanf(arg, "+%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
   694     return set_bool_flag(name, true, origin);
   695   }
   697   char punct;
   698   if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "%c", name, &punct) == 2 && punct == '=') {
   699     const char* value = strchr(arg, '=') + 1;
   700     Flag* flag = Flag::find_flag(name, strlen(name));
   701     if (flag != NULL && flag->is_ccstr()) {
   702       if (flag->ccstr_accumulates()) {
   703         return append_to_string_flag(name, value, origin);
   704       } else {
   705         if (value[0] == '\0') {
   706           value = NULL;
   707         }
   708         return set_string_flag(name, value, origin);
   709       }
   710     }
   711   }
   713   if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE ":%c", name, &punct) == 2 && punct == '=') {
   714     const char* value = strchr(arg, '=') + 1;
   715     // -XX:Foo:=xxx will reset the string flag to the given value.
   716     if (value[0] == '\0') {
   717       value = NULL;
   718     }
   719     return set_string_flag(name, value, origin);
   720   }
   722 #define SIGNED_FP_NUMBER_RANGE "[-0123456789.]"
   723 #define SIGNED_NUMBER_RANGE    "[-0123456789]"
   724 #define        NUMBER_RANGE    "[0123456789]"
   725   char value[BUFLEN + 1];
   726   char value2[BUFLEN + 1];
   727   if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_NUMBER_RANGE "." "%" XSTR(BUFLEN) NUMBER_RANGE "%c", name, value, value2, &dummy) == 3) {
   728     // Looks like a floating-point number -- try again with more lenient format string
   729     if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_FP_NUMBER_RANGE "%c", name, value, &dummy) == 2) {
   730       return set_fp_numeric_flag(name, value, origin);
   731     }
   732   }
   734 #define VALUE_RANGE "[-kmgtKMGT0123456789]"
   735   if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) VALUE_RANGE "%c", name, value, &dummy) == 2) {
   736     return set_numeric_flag(name, value, origin);
   737   }
   739   return false;
   740 }
   742 void Arguments::add_string(char*** bldarray, int* count, const char* arg) {
   743   assert(bldarray != NULL, "illegal argument");
   745   if (arg == NULL) {
   746     return;
   747   }
   749   int new_count = *count + 1;
   751   // expand the array and add arg to the last element
   752   if (*bldarray == NULL) {
   753     *bldarray = NEW_C_HEAP_ARRAY(char*, new_count, mtInternal);
   754   } else {
   755     *bldarray = REALLOC_C_HEAP_ARRAY(char*, *bldarray, new_count, mtInternal);
   756   }
   757   (*bldarray)[*count] = strdup(arg);
   758   *count = new_count;
   759 }
   761 void Arguments::build_jvm_args(const char* arg) {
   762   add_string(&_jvm_args_array, &_num_jvm_args, arg);
   763 }
   765 void Arguments::build_jvm_flags(const char* arg) {
   766   add_string(&_jvm_flags_array, &_num_jvm_flags, arg);
   767 }
   769 // utility function to return a string that concatenates all
   770 // strings in a given char** array
   771 const char* Arguments::build_resource_string(char** args, int count) {
   772   if (args == NULL || count == 0) {
   773     return NULL;
   774   }
   775   size_t length = strlen(args[0]) + 1; // add 1 for the null terminator
   776   for (int i = 1; i < count; i++) {
   777     length += strlen(args[i]) + 1; // add 1 for a space
   778   }
   779   char* s = NEW_RESOURCE_ARRAY(char, length);
   780   strcpy(s, args[0]);
   781   for (int j = 1; j < count; j++) {
   782     strcat(s, " ");
   783     strcat(s, args[j]);
   784   }
   785   return (const char*) s;
   786 }
   788 void Arguments::print_on(outputStream* st) {
   789   st->print_cr("VM Arguments:");
   790   if (num_jvm_flags() > 0) {
   791     st->print("jvm_flags: "); print_jvm_flags_on(st);
   792   }
   793   if (num_jvm_args() > 0) {
   794     st->print("jvm_args: "); print_jvm_args_on(st);
   795   }
   796   st->print_cr("java_command: %s", java_command() ? java_command() : "<unknown>");
   797   if (_java_class_path != NULL) {
   798     char* path = _java_class_path->value();
   799     st->print_cr("java_class_path (initial): %s", strlen(path) == 0 ? "<not set>" : path );
   800   }
   801   st->print_cr("Launcher Type: %s", _sun_java_launcher);
   802 }
   804 void Arguments::print_jvm_flags_on(outputStream* st) {
   805   if (_num_jvm_flags > 0) {
   806     for (int i=0; i < _num_jvm_flags; i++) {
   807       st->print("%s ", _jvm_flags_array[i]);
   808     }
   809     st->print_cr("");
   810   }
   811 }
   813 void Arguments::print_jvm_args_on(outputStream* st) {
   814   if (_num_jvm_args > 0) {
   815     for (int i=0; i < _num_jvm_args; i++) {
   816       st->print("%s ", _jvm_args_array[i]);
   817     }
   818     st->print_cr("");
   819   }
   820 }
   822 bool Arguments::process_argument(const char* arg,
   823     jboolean ignore_unrecognized, FlagValueOrigin origin) {
   825   JDK_Version since = JDK_Version();
   827   if (parse_argument(arg, origin) || ignore_unrecognized) {
   828     return true;
   829   }
   831   bool has_plus_minus = (*arg == '+' || *arg == '-');
   832   const char* const argname = has_plus_minus ? arg + 1 : arg;
   833   if (is_newly_obsolete(arg, &since)) {
   834     char version[256];
   835     since.to_string(version, sizeof(version));
   836     warning("ignoring option %s; support was removed in %s", argname, version);
   837     return true;
   838   }
   840   // For locked flags, report a custom error message if available.
   841   // Otherwise, report the standard unrecognized VM option.
   843   size_t arg_len;
   844   const char* equal_sign = strchr(argname, '=');
   845   if (equal_sign == NULL) {
   846     arg_len = strlen(argname);
   847   } else {
   848     arg_len = equal_sign - argname;
   849   }
   851   Flag* found_flag = Flag::find_flag((char*)argname, arg_len, true);
   852   if (found_flag != NULL) {
   853     char locked_message_buf[BUFLEN];
   854     found_flag->get_locked_message(locked_message_buf, BUFLEN);
   855     if (strlen(locked_message_buf) == 0) {
   856       if (found_flag->is_bool() && !has_plus_minus) {
   857         jio_fprintf(defaultStream::error_stream(),
   858           "Missing +/- setting for VM option '%s'\n", argname);
   859       } else if (!found_flag->is_bool() && has_plus_minus) {
   860         jio_fprintf(defaultStream::error_stream(),
   861           "Unexpected +/- setting in VM option '%s'\n", argname);
   862       } else {
   863         jio_fprintf(defaultStream::error_stream(),
   864           "Improperly specified VM option '%s'\n", argname);
   865       }
   866     } else {
   867       jio_fprintf(defaultStream::error_stream(), "%s", locked_message_buf);
   868     }
   869   } else {
   870     jio_fprintf(defaultStream::error_stream(),
   871                 "Unrecognized VM option '%s'\n", argname);
   872   }
   874   // allow for commandline "commenting out" options like -XX:#+Verbose
   875   return arg[0] == '#';
   876 }
   878 bool Arguments::process_settings_file(const char* file_name, bool should_exist, jboolean ignore_unrecognized) {
   879   FILE* stream = fopen(file_name, "rb");
   880   if (stream == NULL) {
   881     if (should_exist) {
   882       jio_fprintf(defaultStream::error_stream(),
   883                   "Could not open settings file %s\n", file_name);
   884       return false;
   885     } else {
   886       return true;
   887     }
   888   }
   890   char token[1024];
   891   int  pos = 0;
   893   bool in_white_space = true;
   894   bool in_comment     = false;
   895   bool in_quote       = false;
   896   char quote_c        = 0;
   897   bool result         = true;
   899   int c = getc(stream);
   900   while(c != EOF && pos < (int)(sizeof(token)-1)) {
   901     if (in_white_space) {
   902       if (in_comment) {
   903         if (c == '\n') in_comment = false;
   904       } else {
   905         if (c == '#') in_comment = true;
   906         else if (!isspace(c)) {
   907           in_white_space = false;
   908           token[pos++] = c;
   909         }
   910       }
   911     } else {
   912       if (c == '\n' || (!in_quote && isspace(c))) {
   913         // token ends at newline, or at unquoted whitespace
   914         // this allows a way to include spaces in string-valued options
   915         token[pos] = '\0';
   916         logOption(token);
   917         result &= process_argument(token, ignore_unrecognized, CONFIG_FILE);
   918         build_jvm_flags(token);
   919         pos = 0;
   920         in_white_space = true;
   921         in_quote = false;
   922       } else if (!in_quote && (c == '\'' || c == '"')) {
   923         in_quote = true;
   924         quote_c = c;
   925       } else if (in_quote && (c == quote_c)) {
   926         in_quote = false;
   927       } else {
   928         token[pos++] = c;
   929       }
   930     }
   931     c = getc(stream);
   932   }
   933   if (pos > 0) {
   934     token[pos] = '\0';
   935     result &= process_argument(token, ignore_unrecognized, CONFIG_FILE);
   936     build_jvm_flags(token);
   937   }
   938   fclose(stream);
   939   return result;
   940 }
   942 //=============================================================================================================
   943 // Parsing of properties (-D)
   945 const char* Arguments::get_property(const char* key) {
   946   return PropertyList_get_value(system_properties(), key);
   947 }
   949 bool Arguments::add_property(const char* prop) {
   950   const char* eq = strchr(prop, '=');
   951   char* key;
   952   // ns must be static--its address may be stored in a SystemProperty object.
   953   const static char ns[1] = {0};
   954   char* value = (char *)ns;
   956   size_t key_len = (eq == NULL) ? strlen(prop) : (eq - prop);
   957   key = AllocateHeap(key_len + 1, mtInternal);
   958   strncpy(key, prop, key_len);
   959   key[key_len] = '\0';
   961   if (eq != NULL) {
   962     size_t value_len = strlen(prop) - key_len - 1;
   963     value = AllocateHeap(value_len + 1, mtInternal);
   964     strncpy(value, &prop[key_len + 1], value_len + 1);
   965   }
   967   if (strcmp(key, "java.compiler") == 0) {
   968     process_java_compiler_argument(value);
   969     FreeHeap(key);
   970     if (eq != NULL) {
   971       FreeHeap(value);
   972     }
   973     return true;
   974   } else if (strcmp(key, "sun.java.command") == 0) {
   975     _java_command = value;
   977     // Record value in Arguments, but let it get passed to Java.
   978   } else if (strcmp(key, "sun.java.launcher.pid") == 0) {
   979     // launcher.pid property is private and is processed
   980     // in process_sun_java_launcher_properties();
   981     // the sun.java.launcher property is passed on to the java application
   982     FreeHeap(key);
   983     if (eq != NULL) {
   984       FreeHeap(value);
   985     }
   986     return true;
   987   } else if (strcmp(key, "java.vendor.url.bug") == 0) {
   988     // save it in _java_vendor_url_bug, so JVM fatal error handler can access
   989     // its value without going through the property list or making a Java call.
   990     _java_vendor_url_bug = value;
   991   } else if (strcmp(key, "sun.boot.library.path") == 0) {
   992     PropertyList_unique_add(&_system_properties, key, value, true);
   993     return true;
   994   }
   995   // Create new property and add at the end of the list
   996   PropertyList_unique_add(&_system_properties, key, value);
   997   return true;
   998 }
  1000 //===========================================================================================================
  1001 // Setting int/mixed/comp mode flags
  1003 void Arguments::set_mode_flags(Mode mode) {
  1004   // Set up default values for all flags.
  1005   // If you add a flag to any of the branches below,
  1006   // add a default value for it here.
  1007   set_java_compiler(false);
  1008   _mode                      = mode;
  1010   // Ensure Agent_OnLoad has the correct initial values.
  1011   // This may not be the final mode; mode may change later in onload phase.
  1012   PropertyList_unique_add(&_system_properties, "java.vm.info",
  1013                           (char*)VM_Version::vm_info_string(), false);
  1015   UseInterpreter             = true;
  1016   UseCompiler                = true;
  1017   UseLoopCounter             = true;
  1019 #ifndef ZERO
  1020   // Turn these off for mixed and comp.  Leave them on for Zero.
  1021   if (FLAG_IS_DEFAULT(UseFastAccessorMethods)) {
  1022     UseFastAccessorMethods = (mode == _int);
  1024   if (FLAG_IS_DEFAULT(UseFastEmptyMethods)) {
  1025     UseFastEmptyMethods = (mode == _int);
  1027 #endif
  1029   // Default values may be platform/compiler dependent -
  1030   // use the saved values
  1031   ClipInlining               = Arguments::_ClipInlining;
  1032   AlwaysCompileLoopMethods   = Arguments::_AlwaysCompileLoopMethods;
  1033   UseOnStackReplacement      = Arguments::_UseOnStackReplacement;
  1034   BackgroundCompilation      = Arguments::_BackgroundCompilation;
  1036   // Change from defaults based on mode
  1037   switch (mode) {
  1038   default:
  1039     ShouldNotReachHere();
  1040     break;
  1041   case _int:
  1042     UseCompiler              = false;
  1043     UseLoopCounter           = false;
  1044     AlwaysCompileLoopMethods = false;
  1045     UseOnStackReplacement    = false;
  1046     break;
  1047   case _mixed:
  1048     // same as default
  1049     break;
  1050   case _comp:
  1051     UseInterpreter           = false;
  1052     BackgroundCompilation    = false;
  1053     ClipInlining             = false;
  1054     // Be much more aggressive in tiered mode with -Xcomp and exercise C2 more.
  1055     // We will first compile a level 3 version (C1 with full profiling), then do one invocation of it and
  1056     // compile a level 4 (C2) and then continue executing it.
  1057     if (TieredCompilation) {
  1058       Tier3InvokeNotifyFreqLog = 0;
  1059       Tier4InvocationThreshold = 0;
  1061     break;
  1065 // Conflict: required to use shared spaces (-Xshare:on), but
  1066 // incompatible command line options were chosen.
  1068 static void no_shared_spaces() {
  1069   if (RequireSharedSpaces) {
  1070     jio_fprintf(defaultStream::error_stream(),
  1071       "Class data sharing is inconsistent with other specified options.\n");
  1072     vm_exit_during_initialization("Unable to use shared archive.", NULL);
  1073   } else {
  1074     FLAG_SET_DEFAULT(UseSharedSpaces, false);
  1078 void Arguments::set_tiered_flags() {
  1079   // With tiered, set default policy to AdvancedThresholdPolicy, which is 3.
  1080   if (FLAG_IS_DEFAULT(CompilationPolicyChoice)) {
  1081     FLAG_SET_DEFAULT(CompilationPolicyChoice, 3);
  1083   if (CompilationPolicyChoice < 2) {
  1084     vm_exit_during_initialization(
  1085       "Incompatible compilation policy selected", NULL);
  1087   // Increase the code cache size - tiered compiles a lot more.
  1088   if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) {
  1089     FLAG_SET_DEFAULT(ReservedCodeCacheSize, ReservedCodeCacheSize * 5);
  1091   if (!UseInterpreter) { // -Xcomp
  1092     Tier3InvokeNotifyFreqLog = 0;
  1093     Tier4InvocationThreshold = 0;
  1097 #if INCLUDE_ALL_GCS
  1098 static void disable_adaptive_size_policy(const char* collector_name) {
  1099   if (UseAdaptiveSizePolicy) {
  1100     if (FLAG_IS_CMDLINE(UseAdaptiveSizePolicy)) {
  1101       warning("disabling UseAdaptiveSizePolicy; it is incompatible with %s.",
  1102               collector_name);
  1104     FLAG_SET_DEFAULT(UseAdaptiveSizePolicy, false);
  1108 void Arguments::set_parnew_gc_flags() {
  1109   assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC && !UseG1GC,
  1110          "control point invariant");
  1111   assert(UseParNewGC, "Error");
  1113   // Turn off AdaptiveSizePolicy for parnew until it is complete.
  1114   disable_adaptive_size_policy("UseParNewGC");
  1116   if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
  1117     FLAG_SET_DEFAULT(ParallelGCThreads, Abstract_VM_Version::parallel_worker_threads());
  1118     assert(ParallelGCThreads > 0, "We should always have at least one thread by default");
  1119   } else if (ParallelGCThreads == 0) {
  1120     jio_fprintf(defaultStream::error_stream(),
  1121         "The ParNew GC can not be combined with -XX:ParallelGCThreads=0\n");
  1122     vm_exit(1);
  1125   // By default YoungPLABSize and OldPLABSize are set to 4096 and 1024 respectively,
  1126   // these settings are default for Parallel Scavenger. For ParNew+Tenured configuration
  1127   // we set them to 1024 and 1024.
  1128   // See CR 6362902.
  1129   if (FLAG_IS_DEFAULT(YoungPLABSize)) {
  1130     FLAG_SET_DEFAULT(YoungPLABSize, (intx)1024);
  1132   if (FLAG_IS_DEFAULT(OldPLABSize)) {
  1133     FLAG_SET_DEFAULT(OldPLABSize, (intx)1024);
  1136   // AlwaysTenure flag should make ParNew promote all at first collection.
  1137   // See CR 6362902.
  1138   if (AlwaysTenure) {
  1139     FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, 0);
  1141   // When using compressed oops, we use local overflow stacks,
  1142   // rather than using a global overflow list chained through
  1143   // the klass word of the object's pre-image.
  1144   if (UseCompressedOops && !ParGCUseLocalOverflow) {
  1145     if (!FLAG_IS_DEFAULT(ParGCUseLocalOverflow)) {
  1146       warning("Forcing +ParGCUseLocalOverflow: needed if using compressed references");
  1148     FLAG_SET_DEFAULT(ParGCUseLocalOverflow, true);
  1150   assert(ParGCUseLocalOverflow || !UseCompressedOops, "Error");
  1153 // Adjust some sizes to suit CMS and/or ParNew needs; these work well on
  1154 // sparc/solaris for certain applications, but would gain from
  1155 // further optimization and tuning efforts, and would almost
  1156 // certainly gain from analysis of platform and environment.
  1157 void Arguments::set_cms_and_parnew_gc_flags() {
  1158   assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC, "Error");
  1159   assert(UseConcMarkSweepGC, "CMS is expected to be on here");
  1161   // If we are using CMS, we prefer to UseParNewGC,
  1162   // unless explicitly forbidden.
  1163   if (FLAG_IS_DEFAULT(UseParNewGC)) {
  1164     FLAG_SET_ERGO(bool, UseParNewGC, true);
  1167   // Turn off AdaptiveSizePolicy by default for cms until it is complete.
  1168   disable_adaptive_size_policy("UseConcMarkSweepGC");
  1170   // In either case, adjust ParallelGCThreads and/or UseParNewGC
  1171   // as needed.
  1172   if (UseParNewGC) {
  1173     set_parnew_gc_flags();
  1176   size_t max_heap = align_size_down(MaxHeapSize,
  1177                                     CardTableRS::ct_max_alignment_constraint());
  1179   // Now make adjustments for CMS
  1180   intx   tenuring_default = (intx)6;
  1181   size_t young_gen_per_worker = CMSYoungGenPerWorker;
  1183   // Preferred young gen size for "short" pauses:
  1184   // upper bound depends on # of threads and NewRatio.
  1185   const uintx parallel_gc_threads =
  1186     (ParallelGCThreads == 0 ? 1 : ParallelGCThreads);
  1187   const size_t preferred_max_new_size_unaligned =
  1188     MIN2(max_heap/(NewRatio+1), ScaleForWordSize(young_gen_per_worker * parallel_gc_threads));
  1189   size_t preferred_max_new_size =
  1190     align_size_up(preferred_max_new_size_unaligned, os::vm_page_size());
  1192   // Unless explicitly requested otherwise, size young gen
  1193   // for "short" pauses ~ CMSYoungGenPerWorker*ParallelGCThreads
  1195   // If either MaxNewSize or NewRatio is set on the command line,
  1196   // assume the user is trying to set the size of the young gen.
  1197   if (FLAG_IS_DEFAULT(MaxNewSize) && FLAG_IS_DEFAULT(NewRatio)) {
  1199     // Set MaxNewSize to our calculated preferred_max_new_size unless
  1200     // NewSize was set on the command line and it is larger than
  1201     // preferred_max_new_size.
  1202     if (!FLAG_IS_DEFAULT(NewSize)) {   // NewSize explicitly set at command-line
  1203       FLAG_SET_ERGO(uintx, MaxNewSize, MAX2(NewSize, preferred_max_new_size));
  1204     } else {
  1205       FLAG_SET_ERGO(uintx, MaxNewSize, preferred_max_new_size);
  1207     if (PrintGCDetails && Verbose) {
  1208       // Too early to use gclog_or_tty
  1209       tty->print_cr("CMS ergo set MaxNewSize: " SIZE_FORMAT, MaxNewSize);
  1212     // Code along this path potentially sets NewSize and OldSize
  1213     if (PrintGCDetails && Verbose) {
  1214       // Too early to use gclog_or_tty
  1215       tty->print_cr("CMS set min_heap_size: " SIZE_FORMAT
  1216            " initial_heap_size:  " SIZE_FORMAT
  1217            " max_heap: " SIZE_FORMAT,
  1218            min_heap_size(), InitialHeapSize, max_heap);
  1220     size_t min_new = preferred_max_new_size;
  1221     if (FLAG_IS_CMDLINE(NewSize)) {
  1222       min_new = NewSize;
  1224     if (max_heap > min_new && min_heap_size() > min_new) {
  1225       // Unless explicitly requested otherwise, make young gen
  1226       // at least min_new, and at most preferred_max_new_size.
  1227       if (FLAG_IS_DEFAULT(NewSize)) {
  1228         FLAG_SET_ERGO(uintx, NewSize, MAX2(NewSize, min_new));
  1229         FLAG_SET_ERGO(uintx, NewSize, MIN2(preferred_max_new_size, NewSize));
  1230         if (PrintGCDetails && Verbose) {
  1231           // Too early to use gclog_or_tty
  1232           tty->print_cr("CMS ergo set NewSize: " SIZE_FORMAT, NewSize);
  1235       // Unless explicitly requested otherwise, size old gen
  1236       // so it's NewRatio x of NewSize.
  1237       if (FLAG_IS_DEFAULT(OldSize)) {
  1238         if (max_heap > NewSize) {
  1239           FLAG_SET_ERGO(uintx, OldSize, MIN2(NewRatio*NewSize, max_heap - NewSize));
  1240           if (PrintGCDetails && Verbose) {
  1241             // Too early to use gclog_or_tty
  1242             tty->print_cr("CMS ergo set OldSize: " SIZE_FORMAT, OldSize);
  1248   // Unless explicitly requested otherwise, definitely
  1249   // promote all objects surviving "tenuring_default" scavenges.
  1250   if (FLAG_IS_DEFAULT(MaxTenuringThreshold) &&
  1251       FLAG_IS_DEFAULT(SurvivorRatio)) {
  1252     FLAG_SET_ERGO(uintx, MaxTenuringThreshold, tenuring_default);
  1254   // If we decided above (or user explicitly requested)
  1255   // `promote all' (via MaxTenuringThreshold := 0),
  1256   // prefer minuscule survivor spaces so as not to waste
  1257   // space for (non-existent) survivors
  1258   if (FLAG_IS_DEFAULT(SurvivorRatio) && MaxTenuringThreshold == 0) {
  1259     FLAG_SET_ERGO(uintx, SurvivorRatio, MAX2((uintx)1024, SurvivorRatio));
  1261   // If OldPLABSize is set and CMSParPromoteBlocksToClaim is not,
  1262   // set CMSParPromoteBlocksToClaim equal to OldPLABSize.
  1263   // This is done in order to make ParNew+CMS configuration to work
  1264   // with YoungPLABSize and OldPLABSize options.
  1265   // See CR 6362902.
  1266   if (!FLAG_IS_DEFAULT(OldPLABSize)) {
  1267     if (FLAG_IS_DEFAULT(CMSParPromoteBlocksToClaim)) {
  1268       // OldPLABSize is not the default value but CMSParPromoteBlocksToClaim
  1269       // is.  In this situtation let CMSParPromoteBlocksToClaim follow
  1270       // the value (either from the command line or ergonomics) of
  1271       // OldPLABSize.  Following OldPLABSize is an ergonomics decision.
  1272       FLAG_SET_ERGO(uintx, CMSParPromoteBlocksToClaim, OldPLABSize);
  1273     } else {
  1274       // OldPLABSize and CMSParPromoteBlocksToClaim are both set.
  1275       // CMSParPromoteBlocksToClaim is a collector-specific flag, so
  1276       // we'll let it to take precedence.
  1277       jio_fprintf(defaultStream::error_stream(),
  1278                   "Both OldPLABSize and CMSParPromoteBlocksToClaim"
  1279                   " options are specified for the CMS collector."
  1280                   " CMSParPromoteBlocksToClaim will take precedence.\n");
  1283   if (!FLAG_IS_DEFAULT(ResizeOldPLAB) && !ResizeOldPLAB) {
  1284     // OldPLAB sizing manually turned off: Use a larger default setting,
  1285     // unless it was manually specified. This is because a too-low value
  1286     // will slow down scavenges.
  1287     if (FLAG_IS_DEFAULT(CMSParPromoteBlocksToClaim)) {
  1288       FLAG_SET_ERGO(uintx, CMSParPromoteBlocksToClaim, 50); // default value before 6631166
  1291   // Overwrite OldPLABSize which is the variable we will internally use everywhere.
  1292   FLAG_SET_ERGO(uintx, OldPLABSize, CMSParPromoteBlocksToClaim);
  1293   // If either of the static initialization defaults have changed, note this
  1294   // modification.
  1295   if (!FLAG_IS_DEFAULT(CMSParPromoteBlocksToClaim) || !FLAG_IS_DEFAULT(OldPLABWeight)) {
  1296     CFLS_LAB::modify_initialization(OldPLABSize, OldPLABWeight);
  1298   if (PrintGCDetails && Verbose) {
  1299     tty->print_cr("MarkStackSize: %uk  MarkStackSizeMax: %uk",
  1300       MarkStackSize / K, MarkStackSizeMax / K);
  1301     tty->print_cr("ConcGCThreads: %u", ConcGCThreads);
  1304 #endif // INCLUDE_ALL_GCS
  1306 void set_object_alignment() {
  1307   // Object alignment.
  1308   assert(is_power_of_2(ObjectAlignmentInBytes), "ObjectAlignmentInBytes must be power of 2");
  1309   MinObjAlignmentInBytes     = ObjectAlignmentInBytes;
  1310   assert(MinObjAlignmentInBytes >= HeapWordsPerLong * HeapWordSize, "ObjectAlignmentInBytes value is too small");
  1311   MinObjAlignment            = MinObjAlignmentInBytes / HeapWordSize;
  1312   assert(MinObjAlignmentInBytes == MinObjAlignment * HeapWordSize, "ObjectAlignmentInBytes value is incorrect");
  1313   MinObjAlignmentInBytesMask = MinObjAlignmentInBytes - 1;
  1315   LogMinObjAlignmentInBytes  = exact_log2(ObjectAlignmentInBytes);
  1316   LogMinObjAlignment         = LogMinObjAlignmentInBytes - LogHeapWordSize;
  1318   // Oop encoding heap max
  1319   OopEncodingHeapMax = (uint64_t(max_juint) + 1) << LogMinObjAlignmentInBytes;
  1321 #if INCLUDE_ALL_GCS
  1322   // Set CMS global values
  1323   CompactibleFreeListSpace::set_cms_values();
  1324 #endif // INCLUDE_ALL_GCS
  1327 bool verify_object_alignment() {
  1328   // Object alignment.
  1329   if (!is_power_of_2(ObjectAlignmentInBytes)) {
  1330     jio_fprintf(defaultStream::error_stream(),
  1331                 "error: ObjectAlignmentInBytes=%d must be power of 2\n",
  1332                 (int)ObjectAlignmentInBytes);
  1333     return false;
  1335   if ((int)ObjectAlignmentInBytes < BytesPerLong) {
  1336     jio_fprintf(defaultStream::error_stream(),
  1337                 "error: ObjectAlignmentInBytes=%d must be greater or equal %d\n",
  1338                 (int)ObjectAlignmentInBytes, BytesPerLong);
  1339     return false;
  1341   // It does not make sense to have big object alignment
  1342   // since a space lost due to alignment will be greater
  1343   // then a saved space from compressed oops.
  1344   if ((int)ObjectAlignmentInBytes > 256) {
  1345     jio_fprintf(defaultStream::error_stream(),
  1346                 "error: ObjectAlignmentInBytes=%d must not be greater than 256\n",
  1347                 (int)ObjectAlignmentInBytes);
  1348     return false;
  1350   // In case page size is very small.
  1351   if ((int)ObjectAlignmentInBytes >= os::vm_page_size()) {
  1352     jio_fprintf(defaultStream::error_stream(),
  1353                 "error: ObjectAlignmentInBytes=%d must be less than page size %d\n",
  1354                 (int)ObjectAlignmentInBytes, os::vm_page_size());
  1355     return false;
  1357   return true;
  1360 inline uintx max_heap_for_compressed_oops() {
  1361   // Avoid sign flip.
  1362   if (OopEncodingHeapMax < ClassMetaspaceSize + os::vm_page_size()) {
  1363     return 0;
  1365   LP64_ONLY(return OopEncodingHeapMax - ClassMetaspaceSize - os::vm_page_size());
  1366   NOT_LP64(ShouldNotReachHere(); return 0);
  1369 bool Arguments::should_auto_select_low_pause_collector() {
  1370   if (UseAutoGCSelectPolicy &&
  1371       !FLAG_IS_DEFAULT(MaxGCPauseMillis) &&
  1372       (MaxGCPauseMillis <= AutoGCSelectPauseMillis)) {
  1373     if (PrintGCDetails) {
  1374       // Cannot use gclog_or_tty yet.
  1375       tty->print_cr("Automatic selection of the low pause collector"
  1376        " based on pause goal of %d (ms)", MaxGCPauseMillis);
  1378     return true;
  1380   return false;
  1383 void Arguments::set_use_compressed_oops() {
  1384 #ifndef ZERO
  1385 #ifdef _LP64
  1386   // MaxHeapSize is not set up properly at this point, but
  1387   // the only value that can override MaxHeapSize if we are
  1388   // to use UseCompressedOops is InitialHeapSize.
  1389   size_t max_heap_size = MAX2(MaxHeapSize, InitialHeapSize);
  1391   if (max_heap_size <= max_heap_for_compressed_oops()) {
  1392 #if !defined(COMPILER1) || defined(TIERED)
  1393     if (FLAG_IS_DEFAULT(UseCompressedOops)) {
  1394       FLAG_SET_ERGO(bool, UseCompressedOops, true);
  1396 #endif
  1397 #ifdef _WIN64
  1398     if (UseLargePages && UseCompressedOops) {
  1399       // Cannot allocate guard pages for implicit checks in indexed addressing
  1400       // mode, when large pages are specified on windows.
  1401       // This flag could be switched ON if narrow oop base address is set to 0,
  1402       // see code in Universe::initialize_heap().
  1403       Universe::set_narrow_oop_use_implicit_null_checks(false);
  1405 #endif //  _WIN64
  1406   } else {
  1407     if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) {
  1408       warning("Max heap size too large for Compressed Oops");
  1409       FLAG_SET_DEFAULT(UseCompressedOops, false);
  1410       FLAG_SET_DEFAULT(UseCompressedKlassPointers, false);
  1413 #endif // _LP64
  1414 #endif // ZERO
  1417 void Arguments::set_ergonomics_flags() {
  1419   if (os::is_server_class_machine()) {
  1420     // If no other collector is requested explicitly,
  1421     // let the VM select the collector based on
  1422     // machine class and automatic selection policy.
  1423     if (!UseSerialGC &&
  1424         !UseConcMarkSweepGC &&
  1425         !UseG1GC &&
  1426         !UseParNewGC &&
  1427         FLAG_IS_DEFAULT(UseParallelGC)) {
  1428       if (should_auto_select_low_pause_collector()) {
  1429         FLAG_SET_ERGO(bool, UseConcMarkSweepGC, true);
  1430       } else {
  1431         FLAG_SET_ERGO(bool, UseParallelGC, true);
  1434     // Shared spaces work fine with other GCs but causes bytecode rewriting
  1435     // to be disabled, which hurts interpreter performance and decreases
  1436     // server performance.   On server class machines, keep the default
  1437     // off unless it is asked for.  Future work: either add bytecode rewriting
  1438     // at link time, or rewrite bytecodes in non-shared methods.
  1439     if (!DumpSharedSpaces && !RequireSharedSpaces) {
  1440       no_shared_spaces();
  1444 #ifndef ZERO
  1445 #ifdef _LP64
  1446   set_use_compressed_oops();
  1447   // UseCompressedOops must be on for UseCompressedKlassPointers to be on.
  1448   if (!UseCompressedOops) {
  1449     if (UseCompressedKlassPointers) {
  1450       warning("UseCompressedKlassPointers requires UseCompressedOops");
  1452     FLAG_SET_DEFAULT(UseCompressedKlassPointers, false);
  1453   } else {
  1454     // Turn on UseCompressedKlassPointers too
  1455     if (FLAG_IS_DEFAULT(UseCompressedKlassPointers)) {
  1456       FLAG_SET_ERGO(bool, UseCompressedKlassPointers, true);
  1458     // Set the ClassMetaspaceSize to something that will not need to be
  1459     // expanded, since it cannot be expanded.
  1460     if (UseCompressedKlassPointers) {
  1461       if (ClassMetaspaceSize > KlassEncodingMetaspaceMax) {
  1462         warning("Class metaspace size is too large for UseCompressedKlassPointers");
  1463         FLAG_SET_DEFAULT(UseCompressedKlassPointers, false);
  1464       } else if (FLAG_IS_DEFAULT(ClassMetaspaceSize)) {
  1465         // 100,000 classes seems like a good size, so 100M assumes around 1K
  1466         // per klass.   The vtable and oopMap is embedded so we don't have a fixed
  1467         // size per klass.   Eventually, this will be parameterized because it
  1468         // would also be useful to determine the optimal size of the
  1469         // systemDictionary.
  1470         FLAG_SET_ERGO(uintx, ClassMetaspaceSize, 100*M);
  1474   // Also checks that certain machines are slower with compressed oops
  1475   // in vm_version initialization code.
  1476 #endif // _LP64
  1477 #endif // !ZERO
  1480 void Arguments::set_parallel_gc_flags() {
  1481   assert(UseParallelGC || UseParallelOldGC, "Error");
  1482   // Enable ParallelOld unless it was explicitly disabled (cmd line or rc file).
  1483   if (FLAG_IS_DEFAULT(UseParallelOldGC)) {
  1484     FLAG_SET_DEFAULT(UseParallelOldGC, true);
  1486   FLAG_SET_DEFAULT(UseParallelGC, true);
  1488   // If no heap maximum was requested explicitly, use some reasonable fraction
  1489   // of the physical memory, up to a maximum of 1GB.
  1490   FLAG_SET_DEFAULT(ParallelGCThreads,
  1491                    Abstract_VM_Version::parallel_worker_threads());
  1492   if (ParallelGCThreads == 0) {
  1493     jio_fprintf(defaultStream::error_stream(),
  1494         "The Parallel GC can not be combined with -XX:ParallelGCThreads=0\n");
  1495     vm_exit(1);
  1499   // If InitialSurvivorRatio or MinSurvivorRatio were not specified, but the
  1500   // SurvivorRatio has been set, reset their default values to SurvivorRatio +
  1501   // 2.  By doing this we make SurvivorRatio also work for Parallel Scavenger.
  1502   // See CR 6362902 for details.
  1503   if (!FLAG_IS_DEFAULT(SurvivorRatio)) {
  1504     if (FLAG_IS_DEFAULT(InitialSurvivorRatio)) {
  1505        FLAG_SET_DEFAULT(InitialSurvivorRatio, SurvivorRatio + 2);
  1507     if (FLAG_IS_DEFAULT(MinSurvivorRatio)) {
  1508       FLAG_SET_DEFAULT(MinSurvivorRatio, SurvivorRatio + 2);
  1512   if (UseParallelOldGC) {
  1513     // Par compact uses lower default values since they are treated as
  1514     // minimums.  These are different defaults because of the different
  1515     // interpretation and are not ergonomically set.
  1516     if (FLAG_IS_DEFAULT(MarkSweepDeadRatio)) {
  1517       FLAG_SET_DEFAULT(MarkSweepDeadRatio, 1);
  1522 void Arguments::set_g1_gc_flags() {
  1523   assert(UseG1GC, "Error");
  1524 #ifdef COMPILER1
  1525   FastTLABRefill = false;
  1526 #endif
  1527   FLAG_SET_DEFAULT(ParallelGCThreads,
  1528                      Abstract_VM_Version::parallel_worker_threads());
  1529   if (ParallelGCThreads == 0) {
  1530     FLAG_SET_DEFAULT(ParallelGCThreads,
  1531                      Abstract_VM_Version::parallel_worker_threads());
  1534   // MarkStackSize will be set (if it hasn't been set by the user)
  1535   // when concurrent marking is initialized.
  1536   // Its value will be based upon the number of parallel marking threads.
  1537   // But we do set the maximum mark stack size here.
  1538   if (FLAG_IS_DEFAULT(MarkStackSizeMax)) {
  1539     FLAG_SET_DEFAULT(MarkStackSizeMax, 128 * TASKQUEUE_SIZE);
  1542   if (FLAG_IS_DEFAULT(GCTimeRatio) || GCTimeRatio == 0) {
  1543     // In G1, we want the default GC overhead goal to be higher than
  1544     // say in PS. So we set it here to 10%. Otherwise the heap might
  1545     // be expanded more aggressively than we would like it to. In
  1546     // fact, even 10% seems to not be high enough in some cases
  1547     // (especially small GC stress tests that the main thing they do
  1548     // is allocation). We might consider increase it further.
  1549     FLAG_SET_DEFAULT(GCTimeRatio, 9);
  1552   if (PrintGCDetails && Verbose) {
  1553     tty->print_cr("MarkStackSize: %uk  MarkStackSizeMax: %uk",
  1554       MarkStackSize / K, MarkStackSizeMax / K);
  1555     tty->print_cr("ConcGCThreads: %u", ConcGCThreads);
  1559 julong Arguments::limit_by_allocatable_memory(julong limit) {
  1560   julong max_allocatable;
  1561   julong result = limit;
  1562   if (os::has_allocatable_memory_limit(&max_allocatable)) {
  1563     result = MIN2(result, max_allocatable / MaxVirtMemFraction);
  1565   return result;
  1568 void Arguments::set_heap_base_min_address() {
  1569   if (FLAG_IS_DEFAULT(HeapBaseMinAddress) && UseG1GC && HeapBaseMinAddress < 1*G) {
  1570     // By default HeapBaseMinAddress is 2G on all platforms except Solaris x86.
  1571     // G1 currently needs a lot of C-heap, so on Solaris we have to give G1
  1572     // some extra space for the C-heap compared to other collectors.
  1573     FLAG_SET_ERGO(uintx, HeapBaseMinAddress, 1*G);
  1577 void Arguments::set_heap_size() {
  1578   if (!FLAG_IS_DEFAULT(DefaultMaxRAMFraction)) {
  1579     // Deprecated flag
  1580     FLAG_SET_CMDLINE(uintx, MaxRAMFraction, DefaultMaxRAMFraction);
  1583   const julong phys_mem =
  1584     FLAG_IS_DEFAULT(MaxRAM) ? MIN2(os::physical_memory(), (julong)MaxRAM)
  1585                             : (julong)MaxRAM;
  1587   // If the maximum heap size has not been set with -Xmx,
  1588   // then set it as fraction of the size of physical memory,
  1589   // respecting the maximum and minimum sizes of the heap.
  1590   if (FLAG_IS_DEFAULT(MaxHeapSize)) {
  1591     julong reasonable_max = phys_mem / MaxRAMFraction;
  1593     if (phys_mem <= MaxHeapSize * MinRAMFraction) {
  1594       // Small physical memory, so use a minimum fraction of it for the heap
  1595       reasonable_max = phys_mem / MinRAMFraction;
  1596     } else {
  1597       // Not-small physical memory, so require a heap at least
  1598       // as large as MaxHeapSize
  1599       reasonable_max = MAX2(reasonable_max, (julong)MaxHeapSize);
  1601     if (!FLAG_IS_DEFAULT(ErgoHeapSizeLimit) && ErgoHeapSizeLimit != 0) {
  1602       // Limit the heap size to ErgoHeapSizeLimit
  1603       reasonable_max = MIN2(reasonable_max, (julong)ErgoHeapSizeLimit);
  1605     if (UseCompressedOops) {
  1606       // Limit the heap size to the maximum possible when using compressed oops
  1607       julong max_coop_heap = (julong)max_heap_for_compressed_oops();
  1608       if (HeapBaseMinAddress + MaxHeapSize < max_coop_heap) {
  1609         // Heap should be above HeapBaseMinAddress to get zero based compressed oops
  1610         // but it should be not less than default MaxHeapSize.
  1611         max_coop_heap -= HeapBaseMinAddress;
  1613       reasonable_max = MIN2(reasonable_max, max_coop_heap);
  1615     reasonable_max = limit_by_allocatable_memory(reasonable_max);
  1617     if (!FLAG_IS_DEFAULT(InitialHeapSize)) {
  1618       // An initial heap size was specified on the command line,
  1619       // so be sure that the maximum size is consistent.  Done
  1620       // after call to limit_by_allocatable_memory because that
  1621       // method might reduce the allocation size.
  1622       reasonable_max = MAX2(reasonable_max, (julong)InitialHeapSize);
  1625     if (PrintGCDetails && Verbose) {
  1626       // Cannot use gclog_or_tty yet.
  1627       tty->print_cr("  Maximum heap size " SIZE_FORMAT, reasonable_max);
  1629     FLAG_SET_ERGO(uintx, MaxHeapSize, (uintx)reasonable_max);
  1632   // If the minimum or initial heap_size have not been set or requested to be set
  1633   // ergonomically, set them accordingly.
  1634   if (InitialHeapSize == 0 || min_heap_size() == 0) {
  1635     julong reasonable_minimum = (julong)(OldSize + NewSize);
  1637     reasonable_minimum = MIN2(reasonable_minimum, (julong)MaxHeapSize);
  1639     reasonable_minimum = limit_by_allocatable_memory(reasonable_minimum);
  1641     if (InitialHeapSize == 0) {
  1642       julong reasonable_initial = phys_mem / InitialRAMFraction;
  1644       reasonable_initial = MAX3(reasonable_initial, reasonable_minimum, (julong)min_heap_size());
  1645       reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize);
  1647       reasonable_initial = limit_by_allocatable_memory(reasonable_initial);
  1649       if (PrintGCDetails && Verbose) {
  1650         // Cannot use gclog_or_tty yet.
  1651         tty->print_cr("  Initial heap size " SIZE_FORMAT, (uintx)reasonable_initial);
  1653       FLAG_SET_ERGO(uintx, InitialHeapSize, (uintx)reasonable_initial);
  1655     // If the minimum heap size has not been set (via -Xms),
  1656     // synchronize with InitialHeapSize to avoid errors with the default value.
  1657     if (min_heap_size() == 0) {
  1658       set_min_heap_size(MIN2((uintx)reasonable_minimum, InitialHeapSize));
  1659       if (PrintGCDetails && Verbose) {
  1660         // Cannot use gclog_or_tty yet.
  1661         tty->print_cr("  Minimum heap size " SIZE_FORMAT, min_heap_size());
  1667 // This must be called after ergonomics because we want bytecode rewriting
  1668 // if the server compiler is used, or if UseSharedSpaces is disabled.
  1669 void Arguments::set_bytecode_flags() {
  1670   // Better not attempt to store into a read-only space.
  1671   if (UseSharedSpaces) {
  1672     FLAG_SET_DEFAULT(RewriteBytecodes, false);
  1673     FLAG_SET_DEFAULT(RewriteFrequentPairs, false);
  1676   if (!RewriteBytecodes) {
  1677     FLAG_SET_DEFAULT(RewriteFrequentPairs, false);
  1681 // Aggressive optimization flags  -XX:+AggressiveOpts
  1682 void Arguments::set_aggressive_opts_flags() {
  1683 #ifdef COMPILER2
  1684   if (AggressiveUnboxing) {
  1685     if (FLAG_IS_DEFAULT(EliminateAutoBox)) {
  1686       FLAG_SET_DEFAULT(EliminateAutoBox, true);
  1687     } else if (!EliminateAutoBox) {
  1688       // warning("AggressiveUnboxing is disabled because EliminateAutoBox is disabled");
  1689       AggressiveUnboxing = false;
  1691     if (FLAG_IS_DEFAULT(DoEscapeAnalysis)) {
  1692       FLAG_SET_DEFAULT(DoEscapeAnalysis, true);
  1693     } else if (!DoEscapeAnalysis) {
  1694       // warning("AggressiveUnboxing is disabled because DoEscapeAnalysis is disabled");
  1695       AggressiveUnboxing = false;
  1698   if (AggressiveOpts || !FLAG_IS_DEFAULT(AutoBoxCacheMax)) {
  1699     if (FLAG_IS_DEFAULT(EliminateAutoBox)) {
  1700       FLAG_SET_DEFAULT(EliminateAutoBox, true);
  1702     if (FLAG_IS_DEFAULT(AutoBoxCacheMax)) {
  1703       FLAG_SET_DEFAULT(AutoBoxCacheMax, 20000);
  1706     // Feed the cache size setting into the JDK
  1707     char buffer[1024];
  1708     sprintf(buffer, "java.lang.Integer.IntegerCache.high=" INTX_FORMAT, AutoBoxCacheMax);
  1709     add_property(buffer);
  1711   if (AggressiveOpts && FLAG_IS_DEFAULT(BiasedLockingStartupDelay)) {
  1712     FLAG_SET_DEFAULT(BiasedLockingStartupDelay, 500);
  1714 #endif
  1716   if (AggressiveOpts) {
  1717 // Sample flag setting code
  1718 //    if (FLAG_IS_DEFAULT(EliminateZeroing)) {
  1719 //      FLAG_SET_DEFAULT(EliminateZeroing, true);
  1720 //    }
  1724 //===========================================================================================================
  1725 // Parsing of java.compiler property
  1727 void Arguments::process_java_compiler_argument(char* arg) {
  1728   // For backwards compatibility, Djava.compiler=NONE or ""
  1729   // causes us to switch to -Xint mode UNLESS -Xdebug
  1730   // is also specified.
  1731   if (strlen(arg) == 0 || strcasecmp(arg, "NONE") == 0) {
  1732     set_java_compiler(true);    // "-Djava.compiler[=...]" most recently seen.
  1736 void Arguments::process_java_launcher_argument(const char* launcher, void* extra_info) {
  1737   _sun_java_launcher = strdup(launcher);
  1738   if (strcmp("gamma", _sun_java_launcher) == 0) {
  1739     _created_by_gamma_launcher = true;
  1743 bool Arguments::created_by_java_launcher() {
  1744   assert(_sun_java_launcher != NULL, "property must have value");
  1745   return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0;
  1748 bool Arguments::created_by_gamma_launcher() {
  1749   return _created_by_gamma_launcher;
  1752 //===========================================================================================================
  1753 // Parsing of main arguments
  1755 bool Arguments::verify_interval(uintx val, uintx min,
  1756                                 uintx max, const char* name) {
  1757   // Returns true iff value is in the inclusive interval [min..max]
  1758   // false, otherwise.
  1759   if (val >= min && val <= max) {
  1760     return true;
  1762   jio_fprintf(defaultStream::error_stream(),
  1763               "%s of " UINTX_FORMAT " is invalid; must be between " UINTX_FORMAT
  1764               " and " UINTX_FORMAT "\n",
  1765               name, val, min, max);
  1766   return false;
  1769 bool Arguments::verify_min_value(intx val, intx min, const char* name) {
  1770   // Returns true if given value is at least specified min threshold
  1771   // false, otherwise.
  1772   if (val >= min ) {
  1773       return true;
  1775   jio_fprintf(defaultStream::error_stream(),
  1776               "%s of " INTX_FORMAT " is invalid; must be at least " INTX_FORMAT "\n",
  1777               name, val, min);
  1778   return false;
  1781 bool Arguments::verify_percentage(uintx value, const char* name) {
  1782   if (value <= 100) {
  1783     return true;
  1785   jio_fprintf(defaultStream::error_stream(),
  1786               "%s of " UINTX_FORMAT " is invalid; must be between 0 and 100\n",
  1787               name, value);
  1788   return false;
  1791 #if !INCLUDE_ALL_GCS
  1792 #ifdef ASSERT
  1793 static bool verify_serial_gc_flags() {
  1794   return (UseSerialGC &&
  1795         !(UseParNewGC || (UseConcMarkSweepGC || CMSIncrementalMode) || UseG1GC ||
  1796           UseParallelGC || UseParallelOldGC));
  1798 #endif // ASSERT
  1799 #endif // INCLUDE_ALL_GCS
  1801 // check if do gclog rotation
  1802 // +UseGCLogFileRotation is a must,
  1803 // no gc log rotation when log file not supplied or
  1804 // NumberOfGCLogFiles is 0, or GCLogFileSize is 0
  1805 void check_gclog_consistency() {
  1806   if (UseGCLogFileRotation) {
  1807     if ((Arguments::gc_log_filename() == NULL) ||
  1808         (NumberOfGCLogFiles == 0)  ||
  1809         (GCLogFileSize == 0)) {
  1810       jio_fprintf(defaultStream::output_stream(),
  1811                   "To enable GC log rotation, use -Xloggc:<filename> -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=<num_of_files> -XX:GCLogFileSize=<num_of_size>\n"
  1812                   "where num_of_file > 0 and num_of_size > 0\n"
  1813                   "GC log rotation is turned off\n");
  1814       UseGCLogFileRotation = false;
  1818   if (UseGCLogFileRotation && GCLogFileSize < 8*K) {
  1819         FLAG_SET_CMDLINE(uintx, GCLogFileSize, 8*K);
  1820         jio_fprintf(defaultStream::output_stream(),
  1821                     "GCLogFileSize changed to minimum 8K\n");
  1825 // Check consistency of GC selection
  1826 bool Arguments::check_gc_consistency() {
  1827   check_gclog_consistency();
  1828   bool status = true;
  1829   // Ensure that the user has not selected conflicting sets
  1830   // of collectors. [Note: this check is merely a user convenience;
  1831   // collectors over-ride each other so that only a non-conflicting
  1832   // set is selected; however what the user gets is not what they
  1833   // may have expected from the combination they asked for. It's
  1834   // better to reduce user confusion by not allowing them to
  1835   // select conflicting combinations.
  1836   uint i = 0;
  1837   if (UseSerialGC)                       i++;
  1838   if (UseConcMarkSweepGC || UseParNewGC) i++;
  1839   if (UseParallelGC || UseParallelOldGC) i++;
  1840   if (UseG1GC)                           i++;
  1841   if (i > 1) {
  1842     jio_fprintf(defaultStream::error_stream(),
  1843                 "Conflicting collector combinations in option list; "
  1844                 "please refer to the release notes for the combinations "
  1845                 "allowed\n");
  1846     status = false;
  1849   return status;
  1852 void Arguments::check_deprecated_gcs() {
  1853   if (UseConcMarkSweepGC && !UseParNewGC) {
  1854     warning("Using the DefNew young collector with the CMS collector is deprecated "
  1855         "and will likely be removed in a future release");
  1858   if (UseParNewGC && !UseConcMarkSweepGC) {
  1859     // !UseConcMarkSweepGC means that we are using serial old gc. Unfortunately we don't
  1860     // set up UseSerialGC properly, so that can't be used in the check here.
  1861     warning("Using the ParNew young collector with the Serial old collector is deprecated "
  1862         "and will likely be removed in a future release");
  1865   if (CMSIncrementalMode) {
  1866     warning("Using incremental CMS is deprecated and will likely be removed in a future release");
  1870 void Arguments::check_deprecated_gc_flags() {
  1871   if (FLAG_IS_CMDLINE(MaxGCMinorPauseMillis)) {
  1872     warning("Using MaxGCMinorPauseMillis as minor pause goal is deprecated"
  1873             "and will likely be removed in future release");
  1877 // Check stack pages settings
  1878 bool Arguments::check_stack_pages()
  1880   bool status = true;
  1881   status = status && verify_min_value(StackYellowPages, 1, "StackYellowPages");
  1882   status = status && verify_min_value(StackRedPages, 1, "StackRedPages");
  1883   // greater stack shadow pages can't generate instruction to bang stack
  1884   status = status && verify_interval(StackShadowPages, 1, 50, "StackShadowPages");
  1885   return status;
  1888 // Check the consistency of vm_init_args
  1889 bool Arguments::check_vm_args_consistency() {
  1890   // Method for adding checks for flag consistency.
  1891   // The intent is to warn the user of all possible conflicts,
  1892   // before returning an error.
  1893   // Note: Needs platform-dependent factoring.
  1894   bool status = true;
  1896   // Allow both -XX:-UseStackBanging and -XX:-UseBoundThreads in non-product
  1897   // builds so the cost of stack banging can be measured.
  1898 #if (defined(PRODUCT) && defined(SOLARIS))
  1899   if (!UseBoundThreads && !UseStackBanging) {
  1900     jio_fprintf(defaultStream::error_stream(),
  1901                 "-UseStackBanging conflicts with -UseBoundThreads\n");
  1903      status = false;
  1905 #endif
  1907   if (TLABRefillWasteFraction == 0) {
  1908     jio_fprintf(defaultStream::error_stream(),
  1909                 "TLABRefillWasteFraction should be a denominator, "
  1910                 "not " SIZE_FORMAT "\n",
  1911                 TLABRefillWasteFraction);
  1912     status = false;
  1915   status = status && verify_interval(AdaptiveSizePolicyWeight, 0, 100,
  1916                               "AdaptiveSizePolicyWeight");
  1917   status = status && verify_percentage(ThresholdTolerance, "ThresholdTolerance");
  1918   status = status && verify_percentage(MinHeapFreeRatio, "MinHeapFreeRatio");
  1919   status = status && verify_percentage(MaxHeapFreeRatio, "MaxHeapFreeRatio");
  1921   // Divide by bucket size to prevent a large size from causing rollover when
  1922   // calculating amount of memory needed to be allocated for the String table.
  1923   status = status && verify_interval(StringTableSize, minimumStringTableSize,
  1924     (max_uintx / StringTable::bucket_size()), "StringTable size");
  1926   if (MinHeapFreeRatio > MaxHeapFreeRatio) {
  1927     jio_fprintf(defaultStream::error_stream(),
  1928                 "MinHeapFreeRatio (" UINTX_FORMAT ") must be less than or "
  1929                 "equal to MaxHeapFreeRatio (" UINTX_FORMAT ")\n",
  1930                 MinHeapFreeRatio, MaxHeapFreeRatio);
  1931     status = false;
  1933   // Keeping the heap 100% free is hard ;-) so limit it to 99%.
  1934   MinHeapFreeRatio = MIN2(MinHeapFreeRatio, (uintx) 99);
  1936   // Min/MaxMetaspaceFreeRatio
  1937   status = status && verify_percentage(MinMetaspaceFreeRatio, "MinMetaspaceFreeRatio");
  1938   status = status && verify_percentage(MaxMetaspaceFreeRatio, "MaxMetaspaceFreeRatio");
  1940   if (MinMetaspaceFreeRatio > MaxMetaspaceFreeRatio) {
  1941     jio_fprintf(defaultStream::error_stream(),
  1942                 "MinMetaspaceFreeRatio (%s" UINTX_FORMAT ") must be less than or "
  1943                 "equal to MaxMetaspaceFreeRatio (%s" UINTX_FORMAT ")\n",
  1944                 FLAG_IS_DEFAULT(MinMetaspaceFreeRatio) ? "Default: " : "",
  1945                 MinMetaspaceFreeRatio,
  1946                 FLAG_IS_DEFAULT(MaxMetaspaceFreeRatio) ? "Default: " : "",
  1947                 MaxMetaspaceFreeRatio);
  1948     status = false;
  1951   // Trying to keep 100% free is not practical
  1952   MinMetaspaceFreeRatio = MIN2(MinMetaspaceFreeRatio, (uintx) 99);
  1954   if (FullGCALot && FLAG_IS_DEFAULT(MarkSweepAlwaysCompactCount)) {
  1955     MarkSweepAlwaysCompactCount = 1;  // Move objects every gc.
  1958   if (UseParallelOldGC && ParallelOldGCSplitALot) {
  1959     // Settings to encourage splitting.
  1960     if (!FLAG_IS_CMDLINE(NewRatio)) {
  1961       FLAG_SET_CMDLINE(uintx, NewRatio, 2);
  1963     if (!FLAG_IS_CMDLINE(ScavengeBeforeFullGC)) {
  1964       FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
  1968   status = status && verify_percentage(GCHeapFreeLimit, "GCHeapFreeLimit");
  1969   status = status && verify_percentage(GCTimeLimit, "GCTimeLimit");
  1970   if (GCTimeLimit == 100) {
  1971     // Turn off gc-overhead-limit-exceeded checks
  1972     FLAG_SET_DEFAULT(UseGCOverheadLimit, false);
  1975   status = status && check_gc_consistency();
  1976   status = status && check_stack_pages();
  1978   if (CMSIncrementalMode) {
  1979     if (!UseConcMarkSweepGC) {
  1980       jio_fprintf(defaultStream::error_stream(),
  1981                   "error:  invalid argument combination.\n"
  1982                   "The CMS collector (-XX:+UseConcMarkSweepGC) must be "
  1983                   "selected in order\nto use CMSIncrementalMode.\n");
  1984       status = false;
  1985     } else {
  1986       status = status && verify_percentage(CMSIncrementalDutyCycle,
  1987                                   "CMSIncrementalDutyCycle");
  1988       status = status && verify_percentage(CMSIncrementalDutyCycleMin,
  1989                                   "CMSIncrementalDutyCycleMin");
  1990       status = status && verify_percentage(CMSIncrementalSafetyFactor,
  1991                                   "CMSIncrementalSafetyFactor");
  1992       status = status && verify_percentage(CMSIncrementalOffset,
  1993                                   "CMSIncrementalOffset");
  1994       status = status && verify_percentage(CMSExpAvgFactor,
  1995                                   "CMSExpAvgFactor");
  1996       // If it was not set on the command line, set
  1997       // CMSInitiatingOccupancyFraction to 1 so icms can initiate cycles early.
  1998       if (CMSInitiatingOccupancyFraction < 0) {
  1999         FLAG_SET_DEFAULT(CMSInitiatingOccupancyFraction, 1);
  2004   // CMS space iteration, which FLSVerifyAllHeapreferences entails,
  2005   // insists that we hold the requisite locks so that the iteration is
  2006   // MT-safe. For the verification at start-up and shut-down, we don't
  2007   // yet have a good way of acquiring and releasing these locks,
  2008   // which are not visible at the CollectedHeap level. We want to
  2009   // be able to acquire these locks and then do the iteration rather
  2010   // than just disable the lock verification. This will be fixed under
  2011   // bug 4788986.
  2012   if (UseConcMarkSweepGC && FLSVerifyAllHeapReferences) {
  2013     if (VerifyDuringStartup) {
  2014       warning("Heap verification at start-up disabled "
  2015               "(due to current incompatibility with FLSVerifyAllHeapReferences)");
  2016       VerifyDuringStartup = false; // Disable verification at start-up
  2019     if (VerifyBeforeExit) {
  2020       warning("Heap verification at shutdown disabled "
  2021               "(due to current incompatibility with FLSVerifyAllHeapReferences)");
  2022       VerifyBeforeExit = false; // Disable verification at shutdown
  2026   // Note: only executed in non-PRODUCT mode
  2027   if (!UseAsyncConcMarkSweepGC &&
  2028       (ExplicitGCInvokesConcurrent ||
  2029        ExplicitGCInvokesConcurrentAndUnloadsClasses)) {
  2030     jio_fprintf(defaultStream::error_stream(),
  2031                 "error: +ExplicitGCInvokesConcurrent[AndUnloadsClasses] conflicts"
  2032                 " with -UseAsyncConcMarkSweepGC");
  2033     status = false;
  2036   status = status && verify_min_value(ParGCArrayScanChunk, 1, "ParGCArrayScanChunk");
  2038 #if INCLUDE_ALL_GCS
  2039   if (UseG1GC) {
  2040     status = status && verify_percentage(InitiatingHeapOccupancyPercent,
  2041                                          "InitiatingHeapOccupancyPercent");
  2042     status = status && verify_min_value(G1RefProcDrainInterval, 1,
  2043                                         "G1RefProcDrainInterval");
  2044     status = status && verify_min_value((intx)G1ConcMarkStepDurationMillis, 1,
  2045                                         "G1ConcMarkStepDurationMillis");
  2046     status = status && verify_interval(G1ConcRSHotCardLimit, 0, max_jubyte,
  2047                                        "G1ConcRSHotCardLimit");
  2048     status = status && verify_interval(G1ConcRSLogCacheSize, 0, 31,
  2049                                        "G1ConcRSLogCacheSize");
  2051   if (UseConcMarkSweepGC) {
  2052     status = status && verify_min_value(CMSOldPLABNumRefills, 1, "CMSOldPLABNumRefills");
  2053     status = status && verify_min_value(CMSOldPLABToleranceFactor, 1, "CMSOldPLABToleranceFactor");
  2054     status = status && verify_min_value(CMSOldPLABMax, 1, "CMSOldPLABMax");
  2055     status = status && verify_interval(CMSOldPLABMin, 1, CMSOldPLABMax, "CMSOldPLABMin");
  2057     status = status && verify_min_value(CMSYoungGenPerWorker, 1, "CMSYoungGenPerWorker");
  2059     status = status && verify_min_value(CMSSamplingGrain, 1, "CMSSamplingGrain");
  2060     status = status && verify_interval(CMS_SweepWeight, 0, 100, "CMS_SweepWeight");
  2061     status = status && verify_interval(CMS_FLSWeight, 0, 100, "CMS_FLSWeight");
  2063     status = status && verify_interval(FLSCoalescePolicy, 0, 4, "FLSCoalescePolicy");
  2065     status = status && verify_min_value(CMSRescanMultiple, 1, "CMSRescanMultiple");
  2066     status = status && verify_min_value(CMSConcMarkMultiple, 1, "CMSConcMarkMultiple");
  2068     status = status && verify_interval(CMSPrecleanIter, 0, 9, "CMSPrecleanIter");
  2069     status = status && verify_min_value(CMSPrecleanDenominator, 1, "CMSPrecleanDenominator");
  2070     status = status && verify_interval(CMSPrecleanNumerator, 0, CMSPrecleanDenominator - 1, "CMSPrecleanNumerator");
  2072     status = status && verify_percentage(CMSBootstrapOccupancy, "CMSBootstrapOccupancy");
  2074     status = status && verify_min_value(CMSPrecleanThreshold, 100, "CMSPrecleanThreshold");
  2076     status = status && verify_percentage(CMSScheduleRemarkEdenPenetration, "CMSScheduleRemarkEdenPenetration");
  2077     status = status && verify_min_value(CMSScheduleRemarkSamplingRatio, 1, "CMSScheduleRemarkSamplingRatio");
  2078     status = status && verify_min_value(CMSBitMapYieldQuantum, 1, "CMSBitMapYieldQuantum");
  2079     status = status && verify_percentage(CMSTriggerRatio, "CMSTriggerRatio");
  2080     status = status && verify_percentage(CMSIsTooFullPercentage, "CMSIsTooFullPercentage");
  2083   if (UseParallelGC || UseParallelOldGC) {
  2084     status = status && verify_interval(ParallelOldDeadWoodLimiterMean, 0, 100, "ParallelOldDeadWoodLimiterMean");
  2085     status = status && verify_interval(ParallelOldDeadWoodLimiterStdDev, 0, 100, "ParallelOldDeadWoodLimiterStdDev");
  2087     status = status && verify_percentage(YoungGenerationSizeIncrement, "YoungGenerationSizeIncrement");
  2088     status = status && verify_percentage(TenuredGenerationSizeIncrement, "TenuredGenerationSizeIncrement");
  2090     status = status && verify_min_value(YoungGenerationSizeSupplementDecay, 1, "YoungGenerationSizeSupplementDecay");
  2091     status = status && verify_min_value(TenuredGenerationSizeSupplementDecay, 1, "TenuredGenerationSizeSupplementDecay");
  2093     status = status && verify_min_value(ParGCCardsPerStrideChunk, 1, "ParGCCardsPerStrideChunk");
  2095     status = status && verify_min_value(ParallelOldGCSplitInterval, 0, "ParallelOldGCSplitInterval");
  2097 #endif // INCLUDE_ALL_GCS
  2099   status = status && verify_interval(RefDiscoveryPolicy,
  2100                                      ReferenceProcessor::DiscoveryPolicyMin,
  2101                                      ReferenceProcessor::DiscoveryPolicyMax,
  2102                                      "RefDiscoveryPolicy");
  2104   // Limit the lower bound of this flag to 1 as it is used in a division
  2105   // expression.
  2106   status = status && verify_interval(TLABWasteTargetPercent,
  2107                                      1, 100, "TLABWasteTargetPercent");
  2109   status = status && verify_object_alignment();
  2111   status = status && verify_min_value(ClassMetaspaceSize, 1*M,
  2112                                       "ClassMetaspaceSize");
  2114   status = status && verify_interval(MarkStackSizeMax,
  2115                                   1, (max_jint - 1), "MarkStackSizeMax");
  2116   status = status && verify_interval(NUMAChunkResizeWeight, 0, 100, "NUMAChunkResizeWeight");
  2118   status = status && verify_min_value(LogEventsBufferEntries, 1, "LogEventsBufferEntries");
  2120   status = status && verify_min_value(HeapSizePerGCThread, (uintx) os::vm_page_size(), "HeapSizePerGCThread");
  2122   status = status && verify_min_value(GCTaskTimeStampEntries, 1, "GCTaskTimeStampEntries");
  2124   status = status && verify_percentage(ParallelGCBufferWastePct, "ParallelGCBufferWastePct");
  2125   status = status && verify_interval(TargetPLABWastePct, 1, 100, "TargetPLABWastePct");
  2127   status = status && verify_min_value(ParGCStridesPerThread, 1, "ParGCStridesPerThread");
  2129   status = status && verify_min_value(MinRAMFraction, 1, "MinRAMFraction");
  2130   status = status && verify_min_value(InitialRAMFraction, 1, "InitialRAMFraction");
  2131   status = status && verify_min_value(MaxRAMFraction, 1, "MaxRAMFraction");
  2132   status = status && verify_min_value(DefaultMaxRAMFraction, 1, "DefaultMaxRAMFraction");
  2134   status = status && verify_interval(AdaptiveTimeWeight, 0, 100, "AdaptiveTimeWeight");
  2135   status = status && verify_min_value(AdaptiveSizeDecrementScaleFactor, 1, "AdaptiveSizeDecrementScaleFactor");
  2137   status = status && verify_interval(TLABAllocationWeight, 0, 100, "TLABAllocationWeight");
  2138   status = status && verify_min_value(MinTLABSize, 1, "MinTLABSize");
  2139   status = status && verify_min_value(TLABRefillWasteFraction, 1, "TLABRefillWasteFraction");
  2141   status = status && verify_percentage(YoungGenerationSizeSupplement, "YoungGenerationSizeSupplement");
  2142   status = status && verify_percentage(TenuredGenerationSizeSupplement, "TenuredGenerationSizeSupplement");
  2144   // the "age" field in the oop header is 4 bits; do not want to pull in markOop.hpp
  2145   // just for that, so hardcode here.
  2146   status = status && verify_interval(MaxTenuringThreshold, 0, 15, "MaxTenuringThreshold");
  2147   status = status && verify_interval(InitialTenuringThreshold, 0, MaxTenuringThreshold, "MaxTenuringThreshold");
  2148   status = status && verify_percentage(TargetSurvivorRatio, "TargetSurvivorRatio");
  2149   status = status && verify_percentage(MarkSweepDeadRatio, "MarkSweepDeadRatio");
  2151   status = status && verify_min_value(MarkSweepAlwaysCompactCount, 1, "MarkSweepAlwaysCompactCount");
  2152 #ifdef SPARC
  2153   if (UseConcMarkSweepGC || UseG1GC) {
  2154     // Issue a stern warning if the user has explicitly set
  2155     // UseMemSetInBOT (it is known to cause issues), but allow
  2156     // use for experimentation and debugging.
  2157     if (VM_Version::is_sun4v() && UseMemSetInBOT) {
  2158       assert(!FLAG_IS_DEFAULT(UseMemSetInBOT), "Error");
  2159       warning("Experimental flag -XX:+UseMemSetInBOT is known to cause instability"
  2160           " on sun4v; please understand that you are using at your own risk!");
  2163 #endif // SPARC
  2165   if (PrintNMTStatistics) {
  2166 #if INCLUDE_NMT
  2167     if (MemTracker::tracking_level() == MemTracker::NMT_off) {
  2168 #endif // INCLUDE_NMT
  2169       warning("PrintNMTStatistics is disabled, because native memory tracking is not enabled");
  2170       PrintNMTStatistics = false;
  2171 #if INCLUDE_NMT
  2173 #endif
  2176   // Need to limit the extent of the padding to reasonable size.
  2177   // 8K is well beyond the reasonable HW cache line size, even with the
  2178   // aggressive prefetching, while still leaving the room for segregating
  2179   // among the distinct pages.
  2180   if (ContendedPaddingWidth < 0 || ContendedPaddingWidth > 8192) {
  2181     jio_fprintf(defaultStream::error_stream(),
  2182                 "ContendedPaddingWidth=" INTX_FORMAT " must be the between %d and %d\n",
  2183                 ContendedPaddingWidth, 0, 8192);
  2184     status = false;
  2187   // Need to enforce the padding not to break the existing field alignments.
  2188   // It is sufficient to check against the largest type size.
  2189   if ((ContendedPaddingWidth % BytesPerLong) != 0) {
  2190     jio_fprintf(defaultStream::error_stream(),
  2191                 "ContendedPaddingWidth=" INTX_FORMAT " must be the multiple of %d\n",
  2192                 ContendedPaddingWidth, BytesPerLong);
  2193     status = false;
  2196   if (ReservedCodeCacheSize < InitialCodeCacheSize) {
  2197     jio_fprintf(defaultStream::error_stream(),
  2198                 "Invalid ReservedCodeCacheSize: %dK. Should be greater than InitialCodeCacheSize=%dK\n",
  2199                 ReservedCodeCacheSize/K, InitialCodeCacheSize/K);
  2200     status = false;
  2203   return status;
  2206 bool Arguments::is_bad_option(const JavaVMOption* option, jboolean ignore,
  2207   const char* option_type) {
  2208   if (ignore) return false;
  2210   const char* spacer = " ";
  2211   if (option_type == NULL) {
  2212     option_type = ++spacer; // Set both to the empty string.
  2215   if (os::obsolete_option(option)) {
  2216     jio_fprintf(defaultStream::error_stream(),
  2217                 "Obsolete %s%soption: %s\n", option_type, spacer,
  2218       option->optionString);
  2219     return false;
  2220   } else {
  2221     jio_fprintf(defaultStream::error_stream(),
  2222                 "Unrecognized %s%soption: %s\n", option_type, spacer,
  2223       option->optionString);
  2224     return true;
  2228 static const char* user_assertion_options[] = {
  2229   "-da", "-ea", "-disableassertions", "-enableassertions", 0
  2230 };
  2232 static const char* system_assertion_options[] = {
  2233   "-dsa", "-esa", "-disablesystemassertions", "-enablesystemassertions", 0
  2234 };
  2236 // Return true if any of the strings in null-terminated array 'names' matches.
  2237 // If tail_allowed is true, then the tail must begin with a colon; otherwise,
  2238 // the option must match exactly.
  2239 static bool match_option(const JavaVMOption* option, const char** names, const char** tail,
  2240   bool tail_allowed) {
  2241   for (/* empty */; *names != NULL; ++names) {
  2242     if (match_option(option, *names, tail)) {
  2243       if (**tail == '\0' || tail_allowed && **tail == ':') {
  2244         return true;
  2248   return false;
  2251 bool Arguments::parse_uintx(const char* value,
  2252                             uintx* uintx_arg,
  2253                             uintx min_size) {
  2255   // Check the sign first since atomull() parses only unsigned values.
  2256   bool value_is_positive = !(*value == '-');
  2258   if (value_is_positive) {
  2259     julong n;
  2260     bool good_return = atomull(value, &n);
  2261     if (good_return) {
  2262       bool above_minimum = n >= min_size;
  2263       bool value_is_too_large = n > max_uintx;
  2265       if (above_minimum && !value_is_too_large) {
  2266         *uintx_arg = n;
  2267         return true;
  2271   return false;
  2274 Arguments::ArgsRange Arguments::parse_memory_size(const char* s,
  2275                                                   julong* long_arg,
  2276                                                   julong min_size) {
  2277   if (!atomull(s, long_arg)) return arg_unreadable;
  2278   return check_memory_size(*long_arg, min_size);
  2281 // Parse JavaVMInitArgs structure
  2283 jint Arguments::parse_vm_init_args(const JavaVMInitArgs* args) {
  2284   // For components of the system classpath.
  2285   SysClassPath scp(Arguments::get_sysclasspath());
  2286   bool scp_assembly_required = false;
  2288   // Save default settings for some mode flags
  2289   Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
  2290   Arguments::_UseOnStackReplacement    = UseOnStackReplacement;
  2291   Arguments::_ClipInlining             = ClipInlining;
  2292   Arguments::_BackgroundCompilation    = BackgroundCompilation;
  2294   // Setup flags for mixed which is the default
  2295   set_mode_flags(_mixed);
  2297   // Parse JAVA_TOOL_OPTIONS environment variable (if present)
  2298   jint result = parse_java_tool_options_environment_variable(&scp, &scp_assembly_required);
  2299   if (result != JNI_OK) {
  2300     return result;
  2303   // Parse JavaVMInitArgs structure passed in
  2304   result = parse_each_vm_init_arg(args, &scp, &scp_assembly_required, COMMAND_LINE);
  2305   if (result != JNI_OK) {
  2306     return result;
  2309   if (AggressiveOpts) {
  2310     // Insert alt-rt.jar between user-specified bootclasspath
  2311     // prefix and the default bootclasspath.  os::set_boot_path()
  2312     // uses meta_index_dir as the default bootclasspath directory.
  2313     const char* altclasses_jar = "alt-rt.jar";
  2314     size_t altclasses_path_len = strlen(get_meta_index_dir()) + 1 +
  2315                                  strlen(altclasses_jar);
  2316     char* altclasses_path = NEW_C_HEAP_ARRAY(char, altclasses_path_len, mtInternal);
  2317     strcpy(altclasses_path, get_meta_index_dir());
  2318     strcat(altclasses_path, altclasses_jar);
  2319     scp.add_suffix_to_prefix(altclasses_path);
  2320     scp_assembly_required = true;
  2321     FREE_C_HEAP_ARRAY(char, altclasses_path, mtInternal);
  2324   // Parse _JAVA_OPTIONS environment variable (if present) (mimics classic VM)
  2325   result = parse_java_options_environment_variable(&scp, &scp_assembly_required);
  2326   if (result != JNI_OK) {
  2327     return result;
  2330   // Do final processing now that all arguments have been parsed
  2331   result = finalize_vm_init_args(&scp, scp_assembly_required);
  2332   if (result != JNI_OK) {
  2333     return result;
  2336   return JNI_OK;
  2339 // Checks if name in command-line argument -agent{lib,path}:name[=options]
  2340 // represents a valid HPROF of JDWP agent.  is_path==true denotes that we
  2341 // are dealing with -agentpath (case where name is a path), otherwise with
  2342 // -agentlib
  2343 bool valid_hprof_or_jdwp_agent(char *name, bool is_path) {
  2344   char *_name;
  2345   const char *_hprof = "hprof", *_jdwp = "jdwp";
  2346   size_t _len_hprof, _len_jdwp, _len_prefix;
  2348   if (is_path) {
  2349     if ((_name = strrchr(name, (int) *os::file_separator())) == NULL) {
  2350       return false;
  2353     _name++;  // skip past last path separator
  2354     _len_prefix = strlen(JNI_LIB_PREFIX);
  2356     if (strncmp(_name, JNI_LIB_PREFIX, _len_prefix) != 0) {
  2357       return false;
  2360     _name += _len_prefix;
  2361     _len_hprof = strlen(_hprof);
  2362     _len_jdwp = strlen(_jdwp);
  2364     if (strncmp(_name, _hprof, _len_hprof) == 0) {
  2365       _name += _len_hprof;
  2367     else if (strncmp(_name, _jdwp, _len_jdwp) == 0) {
  2368       _name += _len_jdwp;
  2370     else {
  2371       return false;
  2374     if (strcmp(_name, JNI_LIB_SUFFIX) != 0) {
  2375       return false;
  2378     return true;
  2381   if (strcmp(name, _hprof) == 0 || strcmp(name, _jdwp) == 0) {
  2382     return true;
  2385   return false;
  2388 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
  2389                                        SysClassPath* scp_p,
  2390                                        bool* scp_assembly_required_p,
  2391                                        FlagValueOrigin origin) {
  2392   // Remaining part of option string
  2393   const char* tail;
  2395   // iterate over arguments
  2396   for (int index = 0; index < args->nOptions; index++) {
  2397     bool is_absolute_path = false;  // for -agentpath vs -agentlib
  2399     const JavaVMOption* option = args->options + index;
  2401     if (!match_option(option, "-Djava.class.path", &tail) &&
  2402         !match_option(option, "-Dsun.java.command", &tail) &&
  2403         !match_option(option, "-Dsun.java.launcher", &tail)) {
  2405         // add all jvm options to the jvm_args string. This string
  2406         // is used later to set the java.vm.args PerfData string constant.
  2407         // the -Djava.class.path and the -Dsun.java.command options are
  2408         // omitted from jvm_args string as each have their own PerfData
  2409         // string constant object.
  2410         build_jvm_args(option->optionString);
  2413     // -verbose:[class/gc/jni]
  2414     if (match_option(option, "-verbose", &tail)) {
  2415       if (!strcmp(tail, ":class") || !strcmp(tail, "")) {
  2416         FLAG_SET_CMDLINE(bool, TraceClassLoading, true);
  2417         FLAG_SET_CMDLINE(bool, TraceClassUnloading, true);
  2418       } else if (!strcmp(tail, ":gc")) {
  2419         FLAG_SET_CMDLINE(bool, PrintGC, true);
  2420       } else if (!strcmp(tail, ":jni")) {
  2421         FLAG_SET_CMDLINE(bool, PrintJNIResolving, true);
  2423     // -da / -ea / -disableassertions / -enableassertions
  2424     // These accept an optional class/package name separated by a colon, e.g.,
  2425     // -da:java.lang.Thread.
  2426     } else if (match_option(option, user_assertion_options, &tail, true)) {
  2427       bool enable = option->optionString[1] == 'e';     // char after '-' is 'e'
  2428       if (*tail == '\0') {
  2429         JavaAssertions::setUserClassDefault(enable);
  2430       } else {
  2431         assert(*tail == ':', "bogus match by match_option()");
  2432         JavaAssertions::addOption(tail + 1, enable);
  2434     // -dsa / -esa / -disablesystemassertions / -enablesystemassertions
  2435     } else if (match_option(option, system_assertion_options, &tail, false)) {
  2436       bool enable = option->optionString[1] == 'e';     // char after '-' is 'e'
  2437       JavaAssertions::setSystemClassDefault(enable);
  2438     // -bootclasspath:
  2439     } else if (match_option(option, "-Xbootclasspath:", &tail)) {
  2440       scp_p->reset_path(tail);
  2441       *scp_assembly_required_p = true;
  2442     // -bootclasspath/a:
  2443     } else if (match_option(option, "-Xbootclasspath/a:", &tail)) {
  2444       scp_p->add_suffix(tail);
  2445       *scp_assembly_required_p = true;
  2446     // -bootclasspath/p:
  2447     } else if (match_option(option, "-Xbootclasspath/p:", &tail)) {
  2448       scp_p->add_prefix(tail);
  2449       *scp_assembly_required_p = true;
  2450     // -Xrun
  2451     } else if (match_option(option, "-Xrun", &tail)) {
  2452       if (tail != NULL) {
  2453         const char* pos = strchr(tail, ':');
  2454         size_t len = (pos == NULL) ? strlen(tail) : pos - tail;
  2455         char* name = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len + 1, mtInternal), tail, len);
  2456         name[len] = '\0';
  2458         char *options = NULL;
  2459         if(pos != NULL) {
  2460           size_t len2 = strlen(pos+1) + 1; // options start after ':'.  Final zero must be copied.
  2461           options = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len2, mtInternal), pos+1, len2);
  2463 #if !INCLUDE_JVMTI
  2464         if ((strcmp(name, "hprof") == 0) || (strcmp(name, "jdwp") == 0)) {
  2465           jio_fprintf(defaultStream::error_stream(),
  2466             "Profiling and debugging agents are not supported in this VM\n");
  2467           return JNI_ERR;
  2469 #endif // !INCLUDE_JVMTI
  2470         add_init_library(name, options);
  2472     // -agentlib and -agentpath
  2473     } else if (match_option(option, "-agentlib:", &tail) ||
  2474           (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
  2475       if(tail != NULL) {
  2476         const char* pos = strchr(tail, '=');
  2477         size_t len = (pos == NULL) ? strlen(tail) : pos - tail;
  2478         char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1, mtInternal), tail, len);
  2479         name[len] = '\0';
  2481         char *options = NULL;
  2482         if(pos != NULL) {
  2483           options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(pos + 1) + 1, mtInternal), pos + 1);
  2485 #if !INCLUDE_JVMTI
  2486         if (valid_hprof_or_jdwp_agent(name, is_absolute_path)) {
  2487           jio_fprintf(defaultStream::error_stream(),
  2488             "Profiling and debugging agents are not supported in this VM\n");
  2489           return JNI_ERR;
  2491 #endif // !INCLUDE_JVMTI
  2492         add_init_agent(name, options, is_absolute_path);
  2494     // -javaagent
  2495     } else if (match_option(option, "-javaagent:", &tail)) {
  2496 #if !INCLUDE_JVMTI
  2497       jio_fprintf(defaultStream::error_stream(),
  2498         "Instrumentation agents are not supported in this VM\n");
  2499       return JNI_ERR;
  2500 #else
  2501       if(tail != NULL) {
  2502         char *options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(tail) + 1, mtInternal), tail);
  2503         add_init_agent("instrument", options, false);
  2505 #endif // !INCLUDE_JVMTI
  2506     // -Xnoclassgc
  2507     } else if (match_option(option, "-Xnoclassgc", &tail)) {
  2508       FLAG_SET_CMDLINE(bool, ClassUnloading, false);
  2509     // -Xincgc: i-CMS
  2510     } else if (match_option(option, "-Xincgc", &tail)) {
  2511       FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true);
  2512       FLAG_SET_CMDLINE(bool, CMSIncrementalMode, true);
  2513     // -Xnoincgc: no i-CMS
  2514     } else if (match_option(option, "-Xnoincgc", &tail)) {
  2515       FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false);
  2516       FLAG_SET_CMDLINE(bool, CMSIncrementalMode, false);
  2517     // -Xconcgc
  2518     } else if (match_option(option, "-Xconcgc", &tail)) {
  2519       FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true);
  2520     // -Xnoconcgc
  2521     } else if (match_option(option, "-Xnoconcgc", &tail)) {
  2522       FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false);
  2523     // -Xbatch
  2524     } else if (match_option(option, "-Xbatch", &tail)) {
  2525       FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
  2526     // -Xmn for compatibility with other JVM vendors
  2527     } else if (match_option(option, "-Xmn", &tail)) {
  2528       julong long_initial_eden_size = 0;
  2529       ArgsRange errcode = parse_memory_size(tail, &long_initial_eden_size, 1);
  2530       if (errcode != arg_in_range) {
  2531         jio_fprintf(defaultStream::error_stream(),
  2532                     "Invalid initial eden size: %s\n", option->optionString);
  2533         describe_range_error(errcode);
  2534         return JNI_EINVAL;
  2536       FLAG_SET_CMDLINE(uintx, MaxNewSize, (uintx)long_initial_eden_size);
  2537       FLAG_SET_CMDLINE(uintx, NewSize, (uintx)long_initial_eden_size);
  2538     // -Xms
  2539     } else if (match_option(option, "-Xms", &tail)) {
  2540       julong long_initial_heap_size = 0;
  2541       // an initial heap size of 0 means automatically determine
  2542       ArgsRange errcode = parse_memory_size(tail, &long_initial_heap_size, 0);
  2543       if (errcode != arg_in_range) {
  2544         jio_fprintf(defaultStream::error_stream(),
  2545                     "Invalid initial heap size: %s\n", option->optionString);
  2546         describe_range_error(errcode);
  2547         return JNI_EINVAL;
  2549       FLAG_SET_CMDLINE(uintx, InitialHeapSize, (uintx)long_initial_heap_size);
  2550       // Currently the minimum size and the initial heap sizes are the same.
  2551       set_min_heap_size(InitialHeapSize);
  2552     // -Xmx
  2553     } else if (match_option(option, "-Xmx", &tail) || match_option(option, "-XX:MaxHeapSize=", &tail)) {
  2554       julong long_max_heap_size = 0;
  2555       ArgsRange errcode = parse_memory_size(tail, &long_max_heap_size, 1);
  2556       if (errcode != arg_in_range) {
  2557         jio_fprintf(defaultStream::error_stream(),
  2558                     "Invalid maximum heap size: %s\n", option->optionString);
  2559         describe_range_error(errcode);
  2560         return JNI_EINVAL;
  2562       FLAG_SET_CMDLINE(uintx, MaxHeapSize, (uintx)long_max_heap_size);
  2563     // Xmaxf
  2564     } else if (match_option(option, "-Xmaxf", &tail)) {
  2565       int maxf = (int)(atof(tail) * 100);
  2566       if (maxf < 0 || maxf > 100) {
  2567         jio_fprintf(defaultStream::error_stream(),
  2568                     "Bad max heap free percentage size: %s\n",
  2569                     option->optionString);
  2570         return JNI_EINVAL;
  2571       } else {
  2572         FLAG_SET_CMDLINE(uintx, MaxHeapFreeRatio, maxf);
  2574     // Xminf
  2575     } else if (match_option(option, "-Xminf", &tail)) {
  2576       int minf = (int)(atof(tail) * 100);
  2577       if (minf < 0 || minf > 100) {
  2578         jio_fprintf(defaultStream::error_stream(),
  2579                     "Bad min heap free percentage size: %s\n",
  2580                     option->optionString);
  2581         return JNI_EINVAL;
  2582       } else {
  2583         FLAG_SET_CMDLINE(uintx, MinHeapFreeRatio, minf);
  2585     // -Xss
  2586     } else if (match_option(option, "-Xss", &tail)) {
  2587       julong long_ThreadStackSize = 0;
  2588       ArgsRange errcode = parse_memory_size(tail, &long_ThreadStackSize, 1000);
  2589       if (errcode != arg_in_range) {
  2590         jio_fprintf(defaultStream::error_stream(),
  2591                     "Invalid thread stack size: %s\n", option->optionString);
  2592         describe_range_error(errcode);
  2593         return JNI_EINVAL;
  2595       // Internally track ThreadStackSize in units of 1024 bytes.
  2596       FLAG_SET_CMDLINE(intx, ThreadStackSize,
  2597                               round_to((int)long_ThreadStackSize, K) / K);
  2598     // -Xoss
  2599     } else if (match_option(option, "-Xoss", &tail)) {
  2600           // HotSpot does not have separate native and Java stacks, ignore silently for compatibility
  2601     // -Xmaxjitcodesize
  2602     } else if (match_option(option, "-Xmaxjitcodesize", &tail) ||
  2603                match_option(option, "-XX:ReservedCodeCacheSize=", &tail)) {
  2604       julong long_ReservedCodeCacheSize = 0;
  2605       ArgsRange errcode = parse_memory_size(tail, &long_ReservedCodeCacheSize, 1);
  2606       if (errcode != arg_in_range) {
  2607         jio_fprintf(defaultStream::error_stream(),
  2608                     "Invalid maximum code cache size: %s.\n", option->optionString);
  2609         return JNI_EINVAL;
  2611       FLAG_SET_CMDLINE(uintx, ReservedCodeCacheSize, (uintx)long_ReservedCodeCacheSize);
  2612       //-XX:IncreaseFirstTierCompileThresholdAt=
  2613       } else if (match_option(option, "-XX:IncreaseFirstTierCompileThresholdAt=", &tail)) {
  2614         uintx uint_IncreaseFirstTierCompileThresholdAt = 0;
  2615         if (!parse_uintx(tail, &uint_IncreaseFirstTierCompileThresholdAt, 0) || uint_IncreaseFirstTierCompileThresholdAt > 99) {
  2616           jio_fprintf(defaultStream::error_stream(),
  2617                       "Invalid value for IncreaseFirstTierCompileThresholdAt: %s. Should be between 0 and 99.\n",
  2618                       option->optionString);
  2619           return JNI_EINVAL;
  2621         FLAG_SET_CMDLINE(uintx, IncreaseFirstTierCompileThresholdAt, (uintx)uint_IncreaseFirstTierCompileThresholdAt);
  2622     // -green
  2623     } else if (match_option(option, "-green", &tail)) {
  2624       jio_fprintf(defaultStream::error_stream(),
  2625                   "Green threads support not available\n");
  2626           return JNI_EINVAL;
  2627     // -native
  2628     } else if (match_option(option, "-native", &tail)) {
  2629           // HotSpot always uses native threads, ignore silently for compatibility
  2630     // -Xsqnopause
  2631     } else if (match_option(option, "-Xsqnopause", &tail)) {
  2632           // EVM option, ignore silently for compatibility
  2633     // -Xrs
  2634     } else if (match_option(option, "-Xrs", &tail)) {
  2635           // Classic/EVM option, new functionality
  2636       FLAG_SET_CMDLINE(bool, ReduceSignalUsage, true);
  2637     } else if (match_option(option, "-Xusealtsigs", &tail)) {
  2638           // change default internal VM signals used - lower case for back compat
  2639       FLAG_SET_CMDLINE(bool, UseAltSigs, true);
  2640     // -Xoptimize
  2641     } else if (match_option(option, "-Xoptimize", &tail)) {
  2642           // EVM option, ignore silently for compatibility
  2643     // -Xprof
  2644     } else if (match_option(option, "-Xprof", &tail)) {
  2645 #if INCLUDE_FPROF
  2646       _has_profile = true;
  2647 #else // INCLUDE_FPROF
  2648       jio_fprintf(defaultStream::error_stream(),
  2649         "Flat profiling is not supported in this VM.\n");
  2650       return JNI_ERR;
  2651 #endif // INCLUDE_FPROF
  2652     // -Xconcurrentio
  2653     } else if (match_option(option, "-Xconcurrentio", &tail)) {
  2654       FLAG_SET_CMDLINE(bool, UseLWPSynchronization, true);
  2655       FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
  2656       FLAG_SET_CMDLINE(intx, DeferThrSuspendLoopCount, 1);
  2657       FLAG_SET_CMDLINE(bool, UseTLAB, false);
  2658       FLAG_SET_CMDLINE(uintx, NewSizeThreadIncrease, 16 * K);  // 20Kb per thread added to new generation
  2660       // -Xinternalversion
  2661     } else if (match_option(option, "-Xinternalversion", &tail)) {
  2662       jio_fprintf(defaultStream::output_stream(), "%s\n",
  2663                   VM_Version::internal_vm_info_string());
  2664       vm_exit(0);
  2665 #ifndef PRODUCT
  2666     // -Xprintflags
  2667     } else if (match_option(option, "-Xprintflags", &tail)) {
  2668       CommandLineFlags::printFlags(tty, false);
  2669       vm_exit(0);
  2670 #endif
  2671     // -D
  2672     } else if (match_option(option, "-D", &tail)) {
  2673       if (!add_property(tail)) {
  2674         return JNI_ENOMEM;
  2676       // Out of the box management support
  2677       if (match_option(option, "-Dcom.sun.management", &tail)) {
  2678 #if INCLUDE_MANAGEMENT
  2679         FLAG_SET_CMDLINE(bool, ManagementServer, true);
  2680 #else
  2681         jio_fprintf(defaultStream::output_stream(),
  2682           "-Dcom.sun.management is not supported in this VM.\n");
  2683         return JNI_ERR;
  2684 #endif
  2686     // -Xint
  2687     } else if (match_option(option, "-Xint", &tail)) {
  2688           set_mode_flags(_int);
  2689     // -Xmixed
  2690     } else if (match_option(option, "-Xmixed", &tail)) {
  2691           set_mode_flags(_mixed);
  2692     // -Xcomp
  2693     } else if (match_option(option, "-Xcomp", &tail)) {
  2694       // for testing the compiler; turn off all flags that inhibit compilation
  2695           set_mode_flags(_comp);
  2696     // -Xshare:dump
  2697     } else if (match_option(option, "-Xshare:dump", &tail)) {
  2698       FLAG_SET_CMDLINE(bool, DumpSharedSpaces, true);
  2699       set_mode_flags(_int);     // Prevent compilation, which creates objects
  2700     // -Xshare:on
  2701     } else if (match_option(option, "-Xshare:on", &tail)) {
  2702       FLAG_SET_CMDLINE(bool, UseSharedSpaces, true);
  2703       FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true);
  2704     // -Xshare:auto
  2705     } else if (match_option(option, "-Xshare:auto", &tail)) {
  2706       FLAG_SET_CMDLINE(bool, UseSharedSpaces, true);
  2707       FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false);
  2708     // -Xshare:off
  2709     } else if (match_option(option, "-Xshare:off", &tail)) {
  2710       FLAG_SET_CMDLINE(bool, UseSharedSpaces, false);
  2711       FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false);
  2712     // -Xverify
  2713     } else if (match_option(option, "-Xverify", &tail)) {
  2714       if (strcmp(tail, ":all") == 0 || strcmp(tail, "") == 0) {
  2715         FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, true);
  2716         FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true);
  2717       } else if (strcmp(tail, ":remote") == 0) {
  2718         FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false);
  2719         FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true);
  2720       } else if (strcmp(tail, ":none") == 0) {
  2721         FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false);
  2722         FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, false);
  2723       } else if (is_bad_option(option, args->ignoreUnrecognized, "verification")) {
  2724         return JNI_EINVAL;
  2726     // -Xdebug
  2727     } else if (match_option(option, "-Xdebug", &tail)) {
  2728       // note this flag has been used, then ignore
  2729       set_xdebug_mode(true);
  2730     // -Xnoagent
  2731     } else if (match_option(option, "-Xnoagent", &tail)) {
  2732       // For compatibility with classic. HotSpot refuses to load the old style agent.dll.
  2733     } else if (match_option(option, "-Xboundthreads", &tail)) {
  2734       // Bind user level threads to kernel threads (Solaris only)
  2735       FLAG_SET_CMDLINE(bool, UseBoundThreads, true);
  2736     } else if (match_option(option, "-Xloggc:", &tail)) {
  2737       // Redirect GC output to the file. -Xloggc:<filename>
  2738       // ostream_init_log(), when called will use this filename
  2739       // to initialize a fileStream.
  2740       _gc_log_filename = strdup(tail);
  2741       FLAG_SET_CMDLINE(bool, PrintGC, true);
  2742       FLAG_SET_CMDLINE(bool, PrintGCTimeStamps, true);
  2744     // JNI hooks
  2745     } else if (match_option(option, "-Xcheck", &tail)) {
  2746       if (!strcmp(tail, ":jni")) {
  2747 #if !INCLUDE_JNI_CHECK
  2748         warning("JNI CHECKING is not supported in this VM");
  2749 #else
  2750         CheckJNICalls = true;
  2751 #endif // INCLUDE_JNI_CHECK
  2752       } else if (is_bad_option(option, args->ignoreUnrecognized,
  2753                                      "check")) {
  2754         return JNI_EINVAL;
  2756     } else if (match_option(option, "vfprintf", &tail)) {
  2757       _vfprintf_hook = CAST_TO_FN_PTR(vfprintf_hook_t, option->extraInfo);
  2758     } else if (match_option(option, "exit", &tail)) {
  2759       _exit_hook = CAST_TO_FN_PTR(exit_hook_t, option->extraInfo);
  2760     } else if (match_option(option, "abort", &tail)) {
  2761       _abort_hook = CAST_TO_FN_PTR(abort_hook_t, option->extraInfo);
  2762     // -XX:+AggressiveHeap
  2763     } else if (match_option(option, "-XX:+AggressiveHeap", &tail)) {
  2765       // This option inspects the machine and attempts to set various
  2766       // parameters to be optimal for long-running, memory allocation
  2767       // intensive jobs.  It is intended for machines with large
  2768       // amounts of cpu and memory.
  2770       // initHeapSize is needed since _initial_heap_size is 4 bytes on a 32 bit
  2771       // VM, but we may not be able to represent the total physical memory
  2772       // available (like having 8gb of memory on a box but using a 32bit VM).
  2773       // Thus, we need to make sure we're using a julong for intermediate
  2774       // calculations.
  2775       julong initHeapSize;
  2776       julong total_memory = os::physical_memory();
  2778       if (total_memory < (julong)256*M) {
  2779         jio_fprintf(defaultStream::error_stream(),
  2780                     "You need at least 256mb of memory to use -XX:+AggressiveHeap\n");
  2781         vm_exit(1);
  2784       // The heap size is half of available memory, or (at most)
  2785       // all of possible memory less 160mb (leaving room for the OS
  2786       // when using ISM).  This is the maximum; because adaptive sizing
  2787       // is turned on below, the actual space used may be smaller.
  2789       initHeapSize = MIN2(total_memory / (julong)2,
  2790                           total_memory - (julong)160*M);
  2792       initHeapSize = limit_by_allocatable_memory(initHeapSize);
  2794       if (FLAG_IS_DEFAULT(MaxHeapSize)) {
  2795          FLAG_SET_CMDLINE(uintx, MaxHeapSize, initHeapSize);
  2796          FLAG_SET_CMDLINE(uintx, InitialHeapSize, initHeapSize);
  2797          // Currently the minimum size and the initial heap sizes are the same.
  2798          set_min_heap_size(initHeapSize);
  2800       if (FLAG_IS_DEFAULT(NewSize)) {
  2801          // Make the young generation 3/8ths of the total heap.
  2802          FLAG_SET_CMDLINE(uintx, NewSize,
  2803                                 ((julong)MaxHeapSize / (julong)8) * (julong)3);
  2804          FLAG_SET_CMDLINE(uintx, MaxNewSize, NewSize);
  2807 #ifndef _ALLBSD_SOURCE  // UseLargePages is not yet supported on BSD.
  2808       FLAG_SET_DEFAULT(UseLargePages, true);
  2809 #endif
  2811       // Increase some data structure sizes for efficiency
  2812       FLAG_SET_CMDLINE(uintx, BaseFootPrintEstimate, MaxHeapSize);
  2813       FLAG_SET_CMDLINE(bool, ResizeTLAB, false);
  2814       FLAG_SET_CMDLINE(uintx, TLABSize, 256*K);
  2816       // See the OldPLABSize comment below, but replace 'after promotion'
  2817       // with 'after copying'.  YoungPLABSize is the size of the survivor
  2818       // space per-gc-thread buffers.  The default is 4kw.
  2819       FLAG_SET_CMDLINE(uintx, YoungPLABSize, 256*K);      // Note: this is in words
  2821       // OldPLABSize is the size of the buffers in the old gen that
  2822       // UseParallelGC uses to promote live data that doesn't fit in the
  2823       // survivor spaces.  At any given time, there's one for each gc thread.
  2824       // The default size is 1kw. These buffers are rarely used, since the
  2825       // survivor spaces are usually big enough.  For specjbb, however, there
  2826       // are occasions when there's lots of live data in the young gen
  2827       // and we end up promoting some of it.  We don't have a definite
  2828       // explanation for why bumping OldPLABSize helps, but the theory
  2829       // is that a bigger PLAB results in retaining something like the
  2830       // original allocation order after promotion, which improves mutator
  2831       // locality.  A minor effect may be that larger PLABs reduce the
  2832       // number of PLAB allocation events during gc.  The value of 8kw
  2833       // was arrived at by experimenting with specjbb.
  2834       FLAG_SET_CMDLINE(uintx, OldPLABSize, 8*K);  // Note: this is in words
  2836       // Enable parallel GC and adaptive generation sizing
  2837       FLAG_SET_CMDLINE(bool, UseParallelGC, true);
  2838       FLAG_SET_DEFAULT(ParallelGCThreads,
  2839                        Abstract_VM_Version::parallel_worker_threads());
  2841       // Encourage steady state memory management
  2842       FLAG_SET_CMDLINE(uintx, ThresholdTolerance, 100);
  2844       // This appears to improve mutator locality
  2845       FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
  2847       // Get around early Solaris scheduling bug
  2848       // (affinity vs other jobs on system)
  2849       // but disallow DR and offlining (5008695).
  2850       FLAG_SET_CMDLINE(bool, BindGCTaskThreadsToCPUs, true);
  2852     } else if (match_option(option, "-XX:+NeverTenure", &tail)) {
  2853       // The last option must always win.
  2854       FLAG_SET_CMDLINE(bool, AlwaysTenure, false);
  2855       FLAG_SET_CMDLINE(bool, NeverTenure, true);
  2856     } else if (match_option(option, "-XX:+AlwaysTenure", &tail)) {
  2857       // The last option must always win.
  2858       FLAG_SET_CMDLINE(bool, NeverTenure, false);
  2859       FLAG_SET_CMDLINE(bool, AlwaysTenure, true);
  2860     } else if (match_option(option, "-XX:+CMSPermGenSweepingEnabled", &tail) ||
  2861                match_option(option, "-XX:-CMSPermGenSweepingEnabled", &tail)) {
  2862       jio_fprintf(defaultStream::error_stream(),
  2863         "Please use CMSClassUnloadingEnabled in place of "
  2864         "CMSPermGenSweepingEnabled in the future\n");
  2865     } else if (match_option(option, "-XX:+UseGCTimeLimit", &tail)) {
  2866       FLAG_SET_CMDLINE(bool, UseGCOverheadLimit, true);
  2867       jio_fprintf(defaultStream::error_stream(),
  2868         "Please use -XX:+UseGCOverheadLimit in place of "
  2869         "-XX:+UseGCTimeLimit in the future\n");
  2870     } else if (match_option(option, "-XX:-UseGCTimeLimit", &tail)) {
  2871       FLAG_SET_CMDLINE(bool, UseGCOverheadLimit, false);
  2872       jio_fprintf(defaultStream::error_stream(),
  2873         "Please use -XX:-UseGCOverheadLimit in place of "
  2874         "-XX:-UseGCTimeLimit in the future\n");
  2875     // The TLE options are for compatibility with 1.3 and will be
  2876     // removed without notice in a future release.  These options
  2877     // are not to be documented.
  2878     } else if (match_option(option, "-XX:MaxTLERatio=", &tail)) {
  2879       // No longer used.
  2880     } else if (match_option(option, "-XX:+ResizeTLE", &tail)) {
  2881       FLAG_SET_CMDLINE(bool, ResizeTLAB, true);
  2882     } else if (match_option(option, "-XX:-ResizeTLE", &tail)) {
  2883       FLAG_SET_CMDLINE(bool, ResizeTLAB, false);
  2884     } else if (match_option(option, "-XX:+PrintTLE", &tail)) {
  2885       FLAG_SET_CMDLINE(bool, PrintTLAB, true);
  2886     } else if (match_option(option, "-XX:-PrintTLE", &tail)) {
  2887       FLAG_SET_CMDLINE(bool, PrintTLAB, false);
  2888     } else if (match_option(option, "-XX:TLEFragmentationRatio=", &tail)) {
  2889       // No longer used.
  2890     } else if (match_option(option, "-XX:TLESize=", &tail)) {
  2891       julong long_tlab_size = 0;
  2892       ArgsRange errcode = parse_memory_size(tail, &long_tlab_size, 1);
  2893       if (errcode != arg_in_range) {
  2894         jio_fprintf(defaultStream::error_stream(),
  2895                     "Invalid TLAB size: %s\n", option->optionString);
  2896         describe_range_error(errcode);
  2897         return JNI_EINVAL;
  2899       FLAG_SET_CMDLINE(uintx, TLABSize, long_tlab_size);
  2900     } else if (match_option(option, "-XX:TLEThreadRatio=", &tail)) {
  2901       // No longer used.
  2902     } else if (match_option(option, "-XX:+UseTLE", &tail)) {
  2903       FLAG_SET_CMDLINE(bool, UseTLAB, true);
  2904     } else if (match_option(option, "-XX:-UseTLE", &tail)) {
  2905       FLAG_SET_CMDLINE(bool, UseTLAB, false);
  2906 SOLARIS_ONLY(
  2907     } else if (match_option(option, "-XX:+UsePermISM", &tail)) {
  2908       warning("-XX:+UsePermISM is obsolete.");
  2909       FLAG_SET_CMDLINE(bool, UseISM, true);
  2910     } else if (match_option(option, "-XX:-UsePermISM", &tail)) {
  2911       FLAG_SET_CMDLINE(bool, UseISM, false);
  2913     } else if (match_option(option, "-XX:+DisplayVMOutputToStderr", &tail)) {
  2914       FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, false);
  2915       FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, true);
  2916     } else if (match_option(option, "-XX:+DisplayVMOutputToStdout", &tail)) {
  2917       FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, false);
  2918       FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, true);
  2919     } else if (match_option(option, "-XX:+ExtendedDTraceProbes", &tail)) {
  2920 #if defined(DTRACE_ENABLED)
  2921       FLAG_SET_CMDLINE(bool, ExtendedDTraceProbes, true);
  2922       FLAG_SET_CMDLINE(bool, DTraceMethodProbes, true);
  2923       FLAG_SET_CMDLINE(bool, DTraceAllocProbes, true);
  2924       FLAG_SET_CMDLINE(bool, DTraceMonitorProbes, true);
  2925 #else // defined(DTRACE_ENABLED)
  2926       jio_fprintf(defaultStream::error_stream(),
  2927                   "ExtendedDTraceProbes flag is not applicable for this configuration\n");
  2928       return JNI_EINVAL;
  2929 #endif // defined(DTRACE_ENABLED)
  2930 #ifdef ASSERT
  2931     } else if (match_option(option, "-XX:+FullGCALot", &tail)) {
  2932       FLAG_SET_CMDLINE(bool, FullGCALot, true);
  2933       // disable scavenge before parallel mark-compact
  2934       FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
  2935 #endif
  2936     } else if (match_option(option, "-XX:CMSParPromoteBlocksToClaim=", &tail)) {
  2937       julong cms_blocks_to_claim = (julong)atol(tail);
  2938       FLAG_SET_CMDLINE(uintx, CMSParPromoteBlocksToClaim, cms_blocks_to_claim);
  2939       jio_fprintf(defaultStream::error_stream(),
  2940         "Please use -XX:OldPLABSize in place of "
  2941         "-XX:CMSParPromoteBlocksToClaim in the future\n");
  2942     } else if (match_option(option, "-XX:ParCMSPromoteBlocksToClaim=", &tail)) {
  2943       julong cms_blocks_to_claim = (julong)atol(tail);
  2944       FLAG_SET_CMDLINE(uintx, CMSParPromoteBlocksToClaim, cms_blocks_to_claim);
  2945       jio_fprintf(defaultStream::error_stream(),
  2946         "Please use -XX:OldPLABSize in place of "
  2947         "-XX:ParCMSPromoteBlocksToClaim in the future\n");
  2948     } else if (match_option(option, "-XX:ParallelGCOldGenAllocBufferSize=", &tail)) {
  2949       julong old_plab_size = 0;
  2950       ArgsRange errcode = parse_memory_size(tail, &old_plab_size, 1);
  2951       if (errcode != arg_in_range) {
  2952         jio_fprintf(defaultStream::error_stream(),
  2953                     "Invalid old PLAB size: %s\n", option->optionString);
  2954         describe_range_error(errcode);
  2955         return JNI_EINVAL;
  2957       FLAG_SET_CMDLINE(uintx, OldPLABSize, old_plab_size);
  2958       jio_fprintf(defaultStream::error_stream(),
  2959                   "Please use -XX:OldPLABSize in place of "
  2960                   "-XX:ParallelGCOldGenAllocBufferSize in the future\n");
  2961     } else if (match_option(option, "-XX:ParallelGCToSpaceAllocBufferSize=", &tail)) {
  2962       julong young_plab_size = 0;
  2963       ArgsRange errcode = parse_memory_size(tail, &young_plab_size, 1);
  2964       if (errcode != arg_in_range) {
  2965         jio_fprintf(defaultStream::error_stream(),
  2966                     "Invalid young PLAB size: %s\n", option->optionString);
  2967         describe_range_error(errcode);
  2968         return JNI_EINVAL;
  2970       FLAG_SET_CMDLINE(uintx, YoungPLABSize, young_plab_size);
  2971       jio_fprintf(defaultStream::error_stream(),
  2972                   "Please use -XX:YoungPLABSize in place of "
  2973                   "-XX:ParallelGCToSpaceAllocBufferSize in the future\n");
  2974     } else if (match_option(option, "-XX:CMSMarkStackSize=", &tail) ||
  2975                match_option(option, "-XX:G1MarkStackSize=", &tail)) {
  2976       julong stack_size = 0;
  2977       ArgsRange errcode = parse_memory_size(tail, &stack_size, 1);
  2978       if (errcode != arg_in_range) {
  2979         jio_fprintf(defaultStream::error_stream(),
  2980                     "Invalid mark stack size: %s\n", option->optionString);
  2981         describe_range_error(errcode);
  2982         return JNI_EINVAL;
  2984       FLAG_SET_CMDLINE(uintx, MarkStackSize, stack_size);
  2985     } else if (match_option(option, "-XX:CMSMarkStackSizeMax=", &tail)) {
  2986       julong max_stack_size = 0;
  2987       ArgsRange errcode = parse_memory_size(tail, &max_stack_size, 1);
  2988       if (errcode != arg_in_range) {
  2989         jio_fprintf(defaultStream::error_stream(),
  2990                     "Invalid maximum mark stack size: %s\n",
  2991                     option->optionString);
  2992         describe_range_error(errcode);
  2993         return JNI_EINVAL;
  2995       FLAG_SET_CMDLINE(uintx, MarkStackSizeMax, max_stack_size);
  2996     } else if (match_option(option, "-XX:ParallelMarkingThreads=", &tail) ||
  2997                match_option(option, "-XX:ParallelCMSThreads=", &tail)) {
  2998       uintx conc_threads = 0;
  2999       if (!parse_uintx(tail, &conc_threads, 1)) {
  3000         jio_fprintf(defaultStream::error_stream(),
  3001                     "Invalid concurrent threads: %s\n", option->optionString);
  3002         return JNI_EINVAL;
  3004       FLAG_SET_CMDLINE(uintx, ConcGCThreads, conc_threads);
  3005     } else if (match_option(option, "-XX:MaxDirectMemorySize=", &tail)) {
  3006       julong max_direct_memory_size = 0;
  3007       ArgsRange errcode = parse_memory_size(tail, &max_direct_memory_size, 0);
  3008       if (errcode != arg_in_range) {
  3009         jio_fprintf(defaultStream::error_stream(),
  3010                     "Invalid maximum direct memory size: %s\n",
  3011                     option->optionString);
  3012         describe_range_error(errcode);
  3013         return JNI_EINVAL;
  3015       FLAG_SET_CMDLINE(uintx, MaxDirectMemorySize, max_direct_memory_size);
  3016     } else if (match_option(option, "-XX:+UseVMInterruptibleIO", &tail)) {
  3017       // NOTE! In JDK 9, the UseVMInterruptibleIO flag will completely go
  3018       //       away and will cause VM initialization failures!
  3019       warning("-XX:+UseVMInterruptibleIO is obsolete and will be removed in a future release.");
  3020       FLAG_SET_CMDLINE(bool, UseVMInterruptibleIO, true);
  3021 #if !INCLUDE_MANAGEMENT
  3022     } else if (match_option(option, "-XX:+ManagementServer", &tail)) {
  3023         jio_fprintf(defaultStream::error_stream(),
  3024           "ManagementServer is not supported in this VM.\n");
  3025         return JNI_ERR;
  3026 #endif // INCLUDE_MANAGEMENT
  3027     } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx
  3028       // Skip -XX:Flags= since that case has already been handled
  3029       if (strncmp(tail, "Flags=", strlen("Flags=")) != 0) {
  3030         if (!process_argument(tail, args->ignoreUnrecognized, origin)) {
  3031           return JNI_EINVAL;
  3034     // Unknown option
  3035     } else if (is_bad_option(option, args->ignoreUnrecognized)) {
  3036       return JNI_ERR;
  3040   // Change the default value for flags  which have different default values
  3041   // when working with older JDKs.
  3042 #ifdef LINUX
  3043  if (JDK_Version::current().compare_major(6) <= 0 &&
  3044       FLAG_IS_DEFAULT(UseLinuxPosixThreadCPUClocks)) {
  3045     FLAG_SET_DEFAULT(UseLinuxPosixThreadCPUClocks, false);
  3047 #endif // LINUX
  3048   return JNI_OK;
  3051 jint Arguments::finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required) {
  3052   // This must be done after all -D arguments have been processed.
  3053   scp_p->expand_endorsed();
  3055   if (scp_assembly_required || scp_p->get_endorsed() != NULL) {
  3056     // Assemble the bootclasspath elements into the final path.
  3057     Arguments::set_sysclasspath(scp_p->combined_path());
  3060   // This must be done after all arguments have been processed.
  3061   // java_compiler() true means set to "NONE" or empty.
  3062   if (java_compiler() && !xdebug_mode()) {
  3063     // For backwards compatibility, we switch to interpreted mode if
  3064     // -Djava.compiler="NONE" or "" is specified AND "-Xdebug" was
  3065     // not specified.
  3066     set_mode_flags(_int);
  3068   if (CompileThreshold == 0) {
  3069     set_mode_flags(_int);
  3072   // eventually fix up InitialTenuringThreshold if only MaxTenuringThreshold is set
  3073   if (FLAG_IS_DEFAULT(InitialTenuringThreshold) && (InitialTenuringThreshold > MaxTenuringThreshold)) {
  3074     FLAG_SET_ERGO(uintx, InitialTenuringThreshold, MaxTenuringThreshold);
  3077 #ifndef COMPILER2
  3078   // Don't degrade server performance for footprint
  3079   if (FLAG_IS_DEFAULT(UseLargePages) &&
  3080       MaxHeapSize < LargePageHeapSizeThreshold) {
  3081     // No need for large granularity pages w/small heaps.
  3082     // Note that large pages are enabled/disabled for both the
  3083     // Java heap and the code cache.
  3084     FLAG_SET_DEFAULT(UseLargePages, false);
  3085     SOLARIS_ONLY(FLAG_SET_DEFAULT(UseMPSS, false));
  3086     SOLARIS_ONLY(FLAG_SET_DEFAULT(UseISM, false));
  3089   // Tiered compilation is undefined with C1.
  3090   TieredCompilation = false;
  3091 #else
  3092   if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) {
  3093     FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment-1);
  3095 #endif
  3097   // If we are running in a headless jre, force java.awt.headless property
  3098   // to be true unless the property has already been set.
  3099   // Also allow the OS environment variable JAVA_AWT_HEADLESS to set headless state.
  3100   if (os::is_headless_jre()) {
  3101     const char* headless = Arguments::get_property("java.awt.headless");
  3102     if (headless == NULL) {
  3103       char envbuffer[128];
  3104       if (!os::getenv("JAVA_AWT_HEADLESS", envbuffer, sizeof(envbuffer))) {
  3105         if (!add_property("java.awt.headless=true")) {
  3106           return JNI_ENOMEM;
  3108       } else {
  3109         char buffer[256];
  3110         strcpy(buffer, "java.awt.headless=");
  3111         strcat(buffer, envbuffer);
  3112         if (!add_property(buffer)) {
  3113           return JNI_ENOMEM;
  3119   if (!check_vm_args_consistency()) {
  3120     return JNI_ERR;
  3123   return JNI_OK;
  3126 jint Arguments::parse_java_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
  3127   return parse_options_environment_variable("_JAVA_OPTIONS", scp_p,
  3128                                             scp_assembly_required_p);
  3131 jint Arguments::parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) {
  3132   return parse_options_environment_variable("JAVA_TOOL_OPTIONS", scp_p,
  3133                                             scp_assembly_required_p);
  3136 jint Arguments::parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p) {
  3137   const int N_MAX_OPTIONS = 64;
  3138   const int OPTION_BUFFER_SIZE = 1024;
  3139   char buffer[OPTION_BUFFER_SIZE];
  3141   // The variable will be ignored if it exceeds the length of the buffer.
  3142   // Don't check this variable if user has special privileges
  3143   // (e.g. unix su command).
  3144   if (os::getenv(name, buffer, sizeof(buffer)) &&
  3145       !os::have_special_privileges()) {
  3146     JavaVMOption options[N_MAX_OPTIONS];      // Construct option array
  3147     jio_fprintf(defaultStream::error_stream(),
  3148                 "Picked up %s: %s\n", name, buffer);
  3149     char* rd = buffer;                        // pointer to the input string (rd)
  3150     int i;
  3151     for (i = 0; i < N_MAX_OPTIONS;) {         // repeat for all options in the input string
  3152       while (isspace(*rd)) rd++;              // skip whitespace
  3153       if (*rd == 0) break;                    // we re done when the input string is read completely
  3155       // The output, option string, overwrites the input string.
  3156       // Because of quoting, the pointer to the option string (wrt) may lag the pointer to
  3157       // input string (rd).
  3158       char* wrt = rd;
  3160       options[i++].optionString = wrt;        // Fill in option
  3161       while (*rd != 0 && !isspace(*rd)) {     // unquoted strings terminate with a space or NULL
  3162         if (*rd == '\'' || *rd == '"') {      // handle a quoted string
  3163           int quote = *rd;                    // matching quote to look for
  3164           rd++;                               // don't copy open quote
  3165           while (*rd != quote) {              // include everything (even spaces) up until quote
  3166             if (*rd == 0) {                   // string termination means unmatched string
  3167               jio_fprintf(defaultStream::error_stream(),
  3168                           "Unmatched quote in %s\n", name);
  3169               return JNI_ERR;
  3171             *wrt++ = *rd++;                   // copy to option string
  3173           rd++;                               // don't copy close quote
  3174         } else {
  3175           *wrt++ = *rd++;                     // copy to option string
  3178       // Need to check if we're done before writing a NULL,
  3179       // because the write could be to the byte that rd is pointing to.
  3180       if (*rd++ == 0) {
  3181         *wrt = 0;
  3182         break;
  3184       *wrt = 0;                               // Zero terminate option
  3186     // Construct JavaVMInitArgs structure and parse as if it was part of the command line
  3187     JavaVMInitArgs vm_args;
  3188     vm_args.version = JNI_VERSION_1_2;
  3189     vm_args.options = options;
  3190     vm_args.nOptions = i;
  3191     vm_args.ignoreUnrecognized = IgnoreUnrecognizedVMOptions;
  3193     if (PrintVMOptions) {
  3194       const char* tail;
  3195       for (int i = 0; i < vm_args.nOptions; i++) {
  3196         const JavaVMOption *option = vm_args.options + i;
  3197         if (match_option(option, "-XX:", &tail)) {
  3198           logOption(tail);
  3203     return(parse_each_vm_init_arg(&vm_args, scp_p, scp_assembly_required_p, ENVIRON_VAR));
  3205   return JNI_OK;
  3208 void Arguments::set_shared_spaces_flags() {
  3209 #ifdef _LP64
  3210     const bool must_share = DumpSharedSpaces || RequireSharedSpaces;
  3212     // CompressedOops cannot be used with CDS.  The offsets of oopmaps and
  3213     // static fields are incorrect in the archive.  With some more clever
  3214     // initialization, this restriction can probably be lifted.
  3215     if (UseCompressedOops) {
  3216       if (must_share) {
  3217           warning("disabling compressed oops because of %s",
  3218                   DumpSharedSpaces ? "-Xshare:dump" : "-Xshare:on");
  3219           FLAG_SET_CMDLINE(bool, UseCompressedOops, false);
  3220           FLAG_SET_CMDLINE(bool, UseCompressedKlassPointers, false);
  3221       } else {
  3222         // Prefer compressed oops to class data sharing
  3223         if (UseSharedSpaces && Verbose) {
  3224           warning("turning off use of shared archive because of compressed oops");
  3226         no_shared_spaces();
  3229 #endif
  3231   if (DumpSharedSpaces) {
  3232     if (RequireSharedSpaces) {
  3233       warning("cannot dump shared archive while using shared archive");
  3235     UseSharedSpaces = false;
  3239 // Disable options not supported in this release, with a warning if they
  3240 // were explicitly requested on the command-line
  3241 #define UNSUPPORTED_OPTION(opt, description)                    \
  3242 do {                                                            \
  3243   if (opt) {                                                    \
  3244     if (FLAG_IS_CMDLINE(opt)) {                                 \
  3245       warning(description " is disabled in this release.");     \
  3246     }                                                           \
  3247     FLAG_SET_DEFAULT(opt, false);                               \
  3248   }                                                             \
  3249 } while(0)
  3252 #define UNSUPPORTED_GC_OPTION(gc)                                     \
  3253 do {                                                                  \
  3254   if (gc) {                                                           \
  3255     if (FLAG_IS_CMDLINE(gc)) {                                        \
  3256       warning(#gc " is not supported in this VM.  Using Serial GC."); \
  3257     }                                                                 \
  3258     FLAG_SET_DEFAULT(gc, false);                                      \
  3259   }                                                                   \
  3260 } while(0)
  3262 #if !INCLUDE_ALL_GCS
  3263 static void force_serial_gc() {
  3264   FLAG_SET_DEFAULT(UseSerialGC, true);
  3265   FLAG_SET_DEFAULT(CMSIncrementalMode, false);  // special CMS suboption
  3266   UNSUPPORTED_GC_OPTION(UseG1GC);
  3267   UNSUPPORTED_GC_OPTION(UseParallelGC);
  3268   UNSUPPORTED_GC_OPTION(UseParallelOldGC);
  3269   UNSUPPORTED_GC_OPTION(UseConcMarkSweepGC);
  3270   UNSUPPORTED_GC_OPTION(UseParNewGC);
  3272 #endif // INCLUDE_ALL_GCS
  3274 // Sharing support
  3275 // Construct the path to the archive
  3276 static char* get_shared_archive_path() {
  3277   char *shared_archive_path;
  3278   if (SharedArchiveFile == NULL) {
  3279     char jvm_path[JVM_MAXPATHLEN];
  3280     os::jvm_path(jvm_path, sizeof(jvm_path));
  3281     char *end = strrchr(jvm_path, *os::file_separator());
  3282     if (end != NULL) *end = '\0';
  3283     size_t jvm_path_len = strlen(jvm_path);
  3284     size_t file_sep_len = strlen(os::file_separator());
  3285     shared_archive_path = NEW_C_HEAP_ARRAY(char, jvm_path_len +
  3286         file_sep_len + 20, mtInternal);
  3287     if (shared_archive_path != NULL) {
  3288       strncpy(shared_archive_path, jvm_path, jvm_path_len + 1);
  3289       strncat(shared_archive_path, os::file_separator(), file_sep_len);
  3290       strncat(shared_archive_path, "classes.jsa", 11);
  3292   } else {
  3293     shared_archive_path = NEW_C_HEAP_ARRAY(char, strlen(SharedArchiveFile) + 1, mtInternal);
  3294     if (shared_archive_path != NULL) {
  3295       strncpy(shared_archive_path, SharedArchiveFile, strlen(SharedArchiveFile) + 1);
  3298   return shared_archive_path;
  3301 // Parse entry point called from JNI_CreateJavaVM
  3303 jint Arguments::parse(const JavaVMInitArgs* args) {
  3305   // Remaining part of option string
  3306   const char* tail;
  3308   // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed.
  3309   const char* hotspotrc = ".hotspotrc";
  3310   bool settings_file_specified = false;
  3311   bool needs_hotspotrc_warning = false;
  3313   const char* flags_file;
  3314   int index;
  3315   for (index = 0; index < args->nOptions; index++) {
  3316     const JavaVMOption *option = args->options + index;
  3317     if (match_option(option, "-XX:Flags=", &tail)) {
  3318       flags_file = tail;
  3319       settings_file_specified = true;
  3321     if (match_option(option, "-XX:+PrintVMOptions", &tail)) {
  3322       PrintVMOptions = true;
  3324     if (match_option(option, "-XX:-PrintVMOptions", &tail)) {
  3325       PrintVMOptions = false;
  3327     if (match_option(option, "-XX:+IgnoreUnrecognizedVMOptions", &tail)) {
  3328       IgnoreUnrecognizedVMOptions = true;
  3330     if (match_option(option, "-XX:-IgnoreUnrecognizedVMOptions", &tail)) {
  3331       IgnoreUnrecognizedVMOptions = false;
  3333     if (match_option(option, "-XX:+PrintFlagsInitial", &tail)) {
  3334       CommandLineFlags::printFlags(tty, false);
  3335       vm_exit(0);
  3337     if (match_option(option, "-XX:NativeMemoryTracking", &tail)) {
  3338 #if INCLUDE_NMT
  3339       MemTracker::init_tracking_options(tail);
  3340 #else
  3341       jio_fprintf(defaultStream::error_stream(),
  3342         "Native Memory Tracking is not supported in this VM\n");
  3343       return JNI_ERR;
  3344 #endif
  3348 #ifndef PRODUCT
  3349     if (match_option(option, "-XX:+PrintFlagsWithComments", &tail)) {
  3350       CommandLineFlags::printFlags(tty, true);
  3351       vm_exit(0);
  3353 #endif
  3356   if (IgnoreUnrecognizedVMOptions) {
  3357     // uncast const to modify the flag args->ignoreUnrecognized
  3358     *(jboolean*)(&args->ignoreUnrecognized) = true;
  3361   // Parse specified settings file
  3362   if (settings_file_specified) {
  3363     if (!process_settings_file(flags_file, true, args->ignoreUnrecognized)) {
  3364       return JNI_EINVAL;
  3366   } else {
  3367 #ifdef ASSERT
  3368     // Parse default .hotspotrc settings file
  3369     if (!process_settings_file(".hotspotrc", false, args->ignoreUnrecognized)) {
  3370       return JNI_EINVAL;
  3372 #else
  3373     struct stat buf;
  3374     if (os::stat(hotspotrc, &buf) == 0) {
  3375       needs_hotspotrc_warning = true;
  3377 #endif
  3380   if (PrintVMOptions) {
  3381     for (index = 0; index < args->nOptions; index++) {
  3382       const JavaVMOption *option = args->options + index;
  3383       if (match_option(option, "-XX:", &tail)) {
  3384         logOption(tail);
  3389   // Parse JavaVMInitArgs structure passed in, as well as JAVA_TOOL_OPTIONS and _JAVA_OPTIONS
  3390   jint result = parse_vm_init_args(args);
  3391   if (result != JNI_OK) {
  3392     return result;
  3395   // Call get_shared_archive_path() here, after possible SharedArchiveFile option got parsed.
  3396   SharedArchivePath = get_shared_archive_path();
  3397   if (SharedArchivePath == NULL) {
  3398     return JNI_ENOMEM;
  3401   // Delay warning until here so that we've had a chance to process
  3402   // the -XX:-PrintWarnings flag
  3403   if (needs_hotspotrc_warning) {
  3404     warning("%s file is present but has been ignored.  "
  3405             "Run with -XX:Flags=%s to load the file.",
  3406             hotspotrc, hotspotrc);
  3409 #ifdef _ALLBSD_SOURCE  // UseLargePages is not yet supported on BSD.
  3410   UNSUPPORTED_OPTION(UseLargePages, "-XX:+UseLargePages");
  3411 #endif
  3413 #if INCLUDE_ALL_GCS
  3414   #if (defined JAVASE_EMBEDDED || defined ARM)
  3415     UNSUPPORTED_OPTION(UseG1GC, "G1 GC");
  3416   #endif
  3417 #endif
  3419 #ifndef PRODUCT
  3420   if (TraceBytecodesAt != 0) {
  3421     TraceBytecodes = true;
  3423   if (CountCompiledCalls) {
  3424     if (UseCounterDecay) {
  3425       warning("UseCounterDecay disabled because CountCalls is set");
  3426       UseCounterDecay = false;
  3429 #endif // PRODUCT
  3431   // JSR 292 is not supported before 1.7
  3432   if (!JDK_Version::is_gte_jdk17x_version()) {
  3433     if (EnableInvokeDynamic) {
  3434       if (!FLAG_IS_DEFAULT(EnableInvokeDynamic)) {
  3435         warning("JSR 292 is not supported before 1.7.  Disabling support.");
  3437       EnableInvokeDynamic = false;
  3441   if (EnableInvokeDynamic && ScavengeRootsInCode == 0) {
  3442     if (!FLAG_IS_DEFAULT(ScavengeRootsInCode)) {
  3443       warning("forcing ScavengeRootsInCode non-zero because EnableInvokeDynamic is true");
  3445     ScavengeRootsInCode = 1;
  3448   if (PrintGCDetails) {
  3449     // Turn on -verbose:gc options as well
  3450     PrintGC = true;
  3453   if (!JDK_Version::is_gte_jdk18x_version()) {
  3454     // To avoid changing the log format for 7 updates this flag is only
  3455     // true by default in JDK8 and above.
  3456     if (FLAG_IS_DEFAULT(PrintGCCause)) {
  3457       FLAG_SET_DEFAULT(PrintGCCause, false);
  3461   // Set object alignment values.
  3462   set_object_alignment();
  3464 #if !INCLUDE_ALL_GCS
  3465   force_serial_gc();
  3466 #endif // INCLUDE_ALL_GCS
  3467 #if !INCLUDE_CDS
  3468   if (DumpSharedSpaces || RequireSharedSpaces) {
  3469     jio_fprintf(defaultStream::error_stream(),
  3470       "Shared spaces are not supported in this VM\n");
  3471     return JNI_ERR;
  3473   if ((UseSharedSpaces && FLAG_IS_CMDLINE(UseSharedSpaces)) || PrintSharedSpaces) {
  3474     warning("Shared spaces are not supported in this VM");
  3475     FLAG_SET_DEFAULT(UseSharedSpaces, false);
  3476     FLAG_SET_DEFAULT(PrintSharedSpaces, false);
  3478   no_shared_spaces();
  3479 #endif // INCLUDE_CDS
  3481   // Set flags based on ergonomics.
  3482   set_ergonomics_flags();
  3484   set_shared_spaces_flags();
  3486   // Check the GC selections again.
  3487   if (!check_gc_consistency()) {
  3488     return JNI_EINVAL;
  3491   if (TieredCompilation) {
  3492     set_tiered_flags();
  3493   } else {
  3494     // Check if the policy is valid. Policies 0 and 1 are valid for non-tiered setup.
  3495     if (CompilationPolicyChoice >= 2) {
  3496       vm_exit_during_initialization(
  3497         "Incompatible compilation policy selected", NULL);
  3501   set_heap_base_min_address();
  3503   // Set heap size based on available physical memory
  3504   set_heap_size();
  3506 #if INCLUDE_ALL_GCS
  3507   // Set per-collector flags
  3508   if (UseParallelGC || UseParallelOldGC) {
  3509     set_parallel_gc_flags();
  3510   } else if (UseConcMarkSweepGC) { // should be done before ParNew check below
  3511     set_cms_and_parnew_gc_flags();
  3512   } else if (UseParNewGC) {  // skipped if CMS is set above
  3513     set_parnew_gc_flags();
  3514   } else if (UseG1GC) {
  3515     set_g1_gc_flags();
  3517   check_deprecated_gcs();
  3518   check_deprecated_gc_flags();
  3519   if (AssumeMP && !UseSerialGC) {
  3520     if (FLAG_IS_DEFAULT(ParallelGCThreads) && ParallelGCThreads == 1) {
  3521       warning("If the number of processors is expected to increase from one, then"
  3522               " you should configure the number of parallel GC threads appropriately"
  3523               " using -XX:ParallelGCThreads=N");
  3526 #else // INCLUDE_ALL_GCS
  3527   assert(verify_serial_gc_flags(), "SerialGC unset");
  3528 #endif // INCLUDE_ALL_GCS
  3530   // Set bytecode rewriting flags
  3531   set_bytecode_flags();
  3533   // Set flags if Aggressive optimization flags (-XX:+AggressiveOpts) enabled.
  3534   set_aggressive_opts_flags();
  3536   // Turn off biased locking for locking debug mode flags,
  3537   // which are subtlely different from each other but neither works with
  3538   // biased locking.
  3539   if (UseHeavyMonitors
  3540 #ifdef COMPILER1
  3541       || !UseFastLocking
  3542 #endif // COMPILER1
  3543     ) {
  3544     if (!FLAG_IS_DEFAULT(UseBiasedLocking) && UseBiasedLocking) {
  3545       // flag set to true on command line; warn the user that they
  3546       // can't enable biased locking here
  3547       warning("Biased Locking is not supported with locking debug flags"
  3548               "; ignoring UseBiasedLocking flag." );
  3550     UseBiasedLocking = false;
  3553 #ifdef CC_INTERP
  3554   // Clear flags not supported by the C++ interpreter
  3555   FLAG_SET_DEFAULT(ProfileInterpreter, false);
  3556   FLAG_SET_DEFAULT(UseBiasedLocking, false);
  3557   LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedOops, false));
  3558   LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedKlassPointers, false));
  3559 #endif // CC_INTERP
  3561 #ifdef COMPILER2
  3562   if (!UseBiasedLocking || EmitSync != 0) {
  3563     UseOptoBiasInlining = false;
  3565   if (!EliminateLocks) {
  3566     EliminateNestedLocks = false;
  3568   if (!Inline) {
  3569     IncrementalInline = false;
  3571 #ifndef PRODUCT
  3572   if (!IncrementalInline) {
  3573     AlwaysIncrementalInline = false;
  3575 #endif
  3576   if (IncrementalInline && FLAG_IS_DEFAULT(MaxNodeLimit)) {
  3577     // incremental inlining: bump MaxNodeLimit
  3578     FLAG_SET_DEFAULT(MaxNodeLimit, (intx)75000);
  3580 #endif
  3582   if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
  3583     warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
  3584     DebugNonSafepoints = true;
  3587 #ifndef PRODUCT
  3588   if (CompileTheWorld) {
  3589     // Force NmethodSweeper to sweep whole CodeCache each time.
  3590     if (FLAG_IS_DEFAULT(NmethodSweepFraction)) {
  3591       NmethodSweepFraction = 1;
  3594 #endif
  3596   if (PrintCommandLineFlags) {
  3597     CommandLineFlags::printSetFlags(tty);
  3600   // Apply CPU specific policy for the BiasedLocking
  3601   if (UseBiasedLocking) {
  3602     if (!VM_Version::use_biased_locking() &&
  3603         !(FLAG_IS_CMDLINE(UseBiasedLocking))) {
  3604       UseBiasedLocking = false;
  3608   // set PauseAtExit if the gamma launcher was used and a debugger is attached
  3609   // but only if not already set on the commandline
  3610   if (Arguments::created_by_gamma_launcher() && os::is_debugger_attached()) {
  3611     bool set = false;
  3612     CommandLineFlags::wasSetOnCmdline("PauseAtExit", &set);
  3613     if (!set) {
  3614       FLAG_SET_DEFAULT(PauseAtExit, true);
  3618   return JNI_OK;
  3621 jint Arguments::adjust_after_os() {
  3622 #if INCLUDE_ALL_GCS
  3623   if (UseParallelGC || UseParallelOldGC) {
  3624     if (UseNUMA) {
  3625       if (FLAG_IS_DEFAULT(MinHeapDeltaBytes)) {
  3626         FLAG_SET_DEFAULT(MinHeapDeltaBytes, 64*M);
  3628       // For those collectors or operating systems (eg, Windows) that do
  3629       // not support full UseNUMA, we will map to UseNUMAInterleaving for now
  3630       UseNUMAInterleaving = true;
  3633 #endif // INCLUDE_ALL_GCS
  3634   return JNI_OK;
  3637 int Arguments::PropertyList_count(SystemProperty* pl) {
  3638   int count = 0;
  3639   while(pl != NULL) {
  3640     count++;
  3641     pl = pl->next();
  3643   return count;
  3646 const char* Arguments::PropertyList_get_value(SystemProperty *pl, const char* key) {
  3647   assert(key != NULL, "just checking");
  3648   SystemProperty* prop;
  3649   for (prop = pl; prop != NULL; prop = prop->next()) {
  3650     if (strcmp(key, prop->key()) == 0) return prop->value();
  3652   return NULL;
  3655 const char* Arguments::PropertyList_get_key_at(SystemProperty *pl, int index) {
  3656   int count = 0;
  3657   const char* ret_val = NULL;
  3659   while(pl != NULL) {
  3660     if(count >= index) {
  3661       ret_val = pl->key();
  3662       break;
  3664     count++;
  3665     pl = pl->next();
  3668   return ret_val;
  3671 char* Arguments::PropertyList_get_value_at(SystemProperty* pl, int index) {
  3672   int count = 0;
  3673   char* ret_val = NULL;
  3675   while(pl != NULL) {
  3676     if(count >= index) {
  3677       ret_val = pl->value();
  3678       break;
  3680     count++;
  3681     pl = pl->next();
  3684   return ret_val;
  3687 void Arguments::PropertyList_add(SystemProperty** plist, SystemProperty *new_p) {
  3688   SystemProperty* p = *plist;
  3689   if (p == NULL) {
  3690     *plist = new_p;
  3691   } else {
  3692     while (p->next() != NULL) {
  3693       p = p->next();
  3695     p->set_next(new_p);
  3699 void Arguments::PropertyList_add(SystemProperty** plist, const char* k, char* v) {
  3700   if (plist == NULL)
  3701     return;
  3703   SystemProperty* new_p = new SystemProperty(k, v, true);
  3704   PropertyList_add(plist, new_p);
  3707 // This add maintains unique property key in the list.
  3708 void Arguments::PropertyList_unique_add(SystemProperty** plist, const char* k, char* v, jboolean append) {
  3709   if (plist == NULL)
  3710     return;
  3712   // If property key exist then update with new value.
  3713   SystemProperty* prop;
  3714   for (prop = *plist; prop != NULL; prop = prop->next()) {
  3715     if (strcmp(k, prop->key()) == 0) {
  3716       if (append) {
  3717         prop->append_value(v);
  3718       } else {
  3719         prop->set_value(v);
  3721       return;
  3725   PropertyList_add(plist, k, v);
  3728 // Copies src into buf, replacing "%%" with "%" and "%p" with pid
  3729 // Returns true if all of the source pointed by src has been copied over to
  3730 // the destination buffer pointed by buf. Otherwise, returns false.
  3731 // Notes:
  3732 // 1. If the length (buflen) of the destination buffer excluding the
  3733 // NULL terminator character is not long enough for holding the expanded
  3734 // pid characters, it also returns false instead of returning the partially
  3735 // expanded one.
  3736 // 2. The passed in "buflen" should be large enough to hold the null terminator.
  3737 bool Arguments::copy_expand_pid(const char* src, size_t srclen,
  3738                                 char* buf, size_t buflen) {
  3739   const char* p = src;
  3740   char* b = buf;
  3741   const char* src_end = &src[srclen];
  3742   char* buf_end = &buf[buflen - 1];
  3744   while (p < src_end && b < buf_end) {
  3745     if (*p == '%') {
  3746       switch (*(++p)) {
  3747       case '%':         // "%%" ==> "%"
  3748         *b++ = *p++;
  3749         break;
  3750       case 'p':  {       //  "%p" ==> current process id
  3751         // buf_end points to the character before the last character so
  3752         // that we could write '\0' to the end of the buffer.
  3753         size_t buf_sz = buf_end - b + 1;
  3754         int ret = jio_snprintf(b, buf_sz, "%d", os::current_process_id());
  3756         // if jio_snprintf fails or the buffer is not long enough to hold
  3757         // the expanded pid, returns false.
  3758         if (ret < 0 || ret >= (int)buf_sz) {
  3759           return false;
  3760         } else {
  3761           b += ret;
  3762           assert(*b == '\0', "fail in copy_expand_pid");
  3763           if (p == src_end && b == buf_end + 1) {
  3764             // reach the end of the buffer.
  3765             return true;
  3768         p++;
  3769         break;
  3771       default :
  3772         *b++ = '%';
  3774     } else {
  3775       *b++ = *p++;
  3778   *b = '\0';
  3779   return (p == src_end); // return false if not all of the source was copied

mercurial