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