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