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