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 // banging in compiler code needs 2 yellow page: it bangs page at 2073 // StackShadowPages+1 which may be second yellow page. 2074 status = status && verify_min_value(StackYellowPages, 2, "StackYellowPages"); 2075 status = status && verify_min_value(StackRedPages, 1, "StackRedPages"); 2076 // greater stack shadow pages can't generate instruction to bang stack 2077 status = status && verify_interval(StackShadowPages, 1, 50, "StackShadowPages"); 2078 return status; 2079 } 2080 2081 // Check the consistency of vm_init_args 2082 bool Arguments::check_vm_args_consistency() { 2083 // Method for adding checks for flag consistency. 2084 // The intent is to warn the user of all possible conflicts, 2085 // before returning an error. 2086 // Note: Needs platform-dependent factoring. 2087 bool status = true; 2088 2089 // Allow both -XX:-UseStackBanging and -XX:-UseBoundThreads in non-product 2090 // builds so the cost of stack banging can be measured. 2091 #if (defined(PRODUCT) && defined(SOLARIS)) 2092 if (!UseBoundThreads && !UseStackBanging) { 2093 jio_fprintf(defaultStream::error_stream(), 2094 "-UseStackBanging conflicts with -UseBoundThreads\n"); 2095 2096 status = false; 2097 } 2098 #endif 2099 2100 if (TLABRefillWasteFraction == 0) { 2101 jio_fprintf(defaultStream::error_stream(), 2102 "TLABRefillWasteFraction should be a denominator, " 2103 "not " SIZE_FORMAT "\n", 2104 TLABRefillWasteFraction); 2105 status = false; 2106 } 2107 2108 status = status && verify_interval(AdaptiveSizePolicyWeight, 0, 100, 2109 "AdaptiveSizePolicyWeight"); 2110 status = status && verify_percentage(ThresholdTolerance, "ThresholdTolerance"); 2111 2112 // Divide by bucket size to prevent a large size from causing rollover when 2113 // calculating amount of memory needed to be allocated for the String table. 2114 status = status && verify_interval(StringTableSize, minimumStringTableSize, 2115 (max_uintx / StringTable::bucket_size()), "StringTable size"); 2116 2117 status = status && verify_interval(SymbolTableSize, minimumSymbolTableSize, 2118 (max_uintx / SymbolTable::bucket_size()), "SymbolTable size"); 2119 2120 { 2121 // Using "else if" below to avoid printing two error messages if min > max. 2122 // This will also prevent us from reporting both min>100 and max>100 at the 2123 // same time, but that is less annoying than printing two identical errors IMHO. 2124 FormatBuffer<80> err_msg(""); 2125 if (!verify_MinHeapFreeRatio(err_msg, MinHeapFreeRatio)) { 2126 jio_fprintf(defaultStream::error_stream(), "%s\n", err_msg.buffer()); 2127 status = false; 2128 } else if (!verify_MaxHeapFreeRatio(err_msg, MaxHeapFreeRatio)) { 2129 jio_fprintf(defaultStream::error_stream(), "%s\n", err_msg.buffer()); 2130 status = false; 2131 } 2132 } 2133 2134 // Min/MaxMetaspaceFreeRatio 2135 status = status && verify_percentage(MinMetaspaceFreeRatio, "MinMetaspaceFreeRatio"); 2136 status = status && verify_percentage(MaxMetaspaceFreeRatio, "MaxMetaspaceFreeRatio"); 2137 2138 if (MinMetaspaceFreeRatio > MaxMetaspaceFreeRatio) { 2139 jio_fprintf(defaultStream::error_stream(), 2140 "MinMetaspaceFreeRatio (%s" UINTX_FORMAT ") must be less than or " 2141 "equal to MaxMetaspaceFreeRatio (%s" UINTX_FORMAT ")\n", 2142 FLAG_IS_DEFAULT(MinMetaspaceFreeRatio) ? "Default: " : "", 2143 MinMetaspaceFreeRatio, 2144 FLAG_IS_DEFAULT(MaxMetaspaceFreeRatio) ? "Default: " : "", 2145 MaxMetaspaceFreeRatio); 2146 status = false; 2147 } 2148 2149 // Trying to keep 100% free is not practical 2150 MinMetaspaceFreeRatio = MIN2(MinMetaspaceFreeRatio, (uintx) 99); 2151 2152 if (FullGCALot && FLAG_IS_DEFAULT(MarkSweepAlwaysCompactCount)) { 2153 MarkSweepAlwaysCompactCount = 1; // Move objects every gc. 2154 } 2155 2156 if (UseParallelOldGC && ParallelOldGCSplitALot) { 2157 // Settings to encourage splitting. 2158 if (!FLAG_IS_CMDLINE(NewRatio)) { 2159 FLAG_SET_CMDLINE(uintx, NewRatio, 2); 2160 } 2161 if (!FLAG_IS_CMDLINE(ScavengeBeforeFullGC)) { 2162 FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false); 2163 } 2164 } 2165 2166 status = status && verify_percentage(GCHeapFreeLimit, "GCHeapFreeLimit"); 2167 status = status && verify_percentage(GCTimeLimit, "GCTimeLimit"); 2168 if (GCTimeLimit == 100) { 2169 // Turn off gc-overhead-limit-exceeded checks 2170 FLAG_SET_DEFAULT(UseGCOverheadLimit, false); 2171 } 2172 2173 status = status && check_gc_consistency(); 2174 status = status && check_stack_pages(); 2175 2176 if (CMSIncrementalMode) { 2177 if (!UseConcMarkSweepGC) { 2178 jio_fprintf(defaultStream::error_stream(), 2179 "error: invalid argument combination.\n" 2180 "The CMS collector (-XX:+UseConcMarkSweepGC) must be " 2181 "selected in order\nto use CMSIncrementalMode.\n"); 2182 status = false; 2183 } else { 2184 status = status && verify_percentage(CMSIncrementalDutyCycle, 2185 "CMSIncrementalDutyCycle"); 2186 status = status && verify_percentage(CMSIncrementalDutyCycleMin, 2187 "CMSIncrementalDutyCycleMin"); 2188 status = status && verify_percentage(CMSIncrementalSafetyFactor, 2189 "CMSIncrementalSafetyFactor"); 2190 status = status && verify_percentage(CMSIncrementalOffset, 2191 "CMSIncrementalOffset"); 2192 status = status && verify_percentage(CMSExpAvgFactor, 2193 "CMSExpAvgFactor"); 2194 // If it was not set on the command line, set 2195 // CMSInitiatingOccupancyFraction to 1 so icms can initiate cycles early. 2196 if (CMSInitiatingOccupancyFraction < 0) { 2197 FLAG_SET_DEFAULT(CMSInitiatingOccupancyFraction, 1); 2198 } 2199 } 2200 } 2201 2202 // CMS space iteration, which FLSVerifyAllHeapreferences entails, 2203 // insists that we hold the requisite locks so that the iteration is 2204 // MT-safe. For the verification at start-up and shut-down, we don't 2205 // yet have a good way of acquiring and releasing these locks, 2206 // which are not visible at the CollectedHeap level. We want to 2207 // be able to acquire these locks and then do the iteration rather 2208 // than just disable the lock verification. This will be fixed under 2209 // bug 4788986. 2210 if (UseConcMarkSweepGC && FLSVerifyAllHeapReferences) { 2211 if (VerifyDuringStartup) { 2212 warning("Heap verification at start-up disabled " 2213 "(due to current incompatibility with FLSVerifyAllHeapReferences)"); 2214 VerifyDuringStartup = false; // Disable verification at start-up 2215 } 2216 2217 if (VerifyBeforeExit) { 2218 warning("Heap verification at shutdown disabled " 2219 "(due to current incompatibility with FLSVerifyAllHeapReferences)"); 2220 VerifyBeforeExit = false; // Disable verification at shutdown 2221 } 2222 } 2223 2224 // Note: only executed in non-PRODUCT mode 2225 if (!UseAsyncConcMarkSweepGC && 2226 (ExplicitGCInvokesConcurrent || 2227 ExplicitGCInvokesConcurrentAndUnloadsClasses)) { 2228 jio_fprintf(defaultStream::error_stream(), 2229 "error: +ExplicitGCInvokesConcurrent[AndUnloadsClasses] conflicts" 2230 " with -UseAsyncConcMarkSweepGC"); 2231 status = false; 2232 } 2233 2234 status = status && verify_min_value(ParGCArrayScanChunk, 1, "ParGCArrayScanChunk"); 2235 2236 #if INCLUDE_ALL_GCS 2237 if (UseG1GC) { 2238 status = status && verify_percentage(G1NewSizePercent, "G1NewSizePercent"); 2239 status = status && verify_percentage(G1MaxNewSizePercent, "G1MaxNewSizePercent"); 2240 status = status && verify_interval(G1NewSizePercent, 0, G1MaxNewSizePercent, "G1NewSizePercent"); 2241 2242 status = status && verify_percentage(InitiatingHeapOccupancyPercent, 2243 "InitiatingHeapOccupancyPercent"); 2244 status = status && verify_min_value(G1RefProcDrainInterval, 1, 2245 "G1RefProcDrainInterval"); 2246 status = status && verify_min_value((intx)G1ConcMarkStepDurationMillis, 1, 2247 "G1ConcMarkStepDurationMillis"); 2248 status = status && verify_interval(G1ConcRSHotCardLimit, 0, max_jubyte, 2249 "G1ConcRSHotCardLimit"); 2250 status = status && verify_interval(G1ConcRSLogCacheSize, 0, 31, 2251 "G1ConcRSLogCacheSize"); 2252 } 2253 if (UseConcMarkSweepGC) { 2254 status = status && verify_min_value(CMSOldPLABNumRefills, 1, "CMSOldPLABNumRefills"); 2255 status = status && verify_min_value(CMSOldPLABToleranceFactor, 1, "CMSOldPLABToleranceFactor"); 2256 status = status && verify_min_value(CMSOldPLABMax, 1, "CMSOldPLABMax"); 2257 status = status && verify_interval(CMSOldPLABMin, 1, CMSOldPLABMax, "CMSOldPLABMin"); 2258 2259 status = status && verify_min_value(CMSYoungGenPerWorker, 1, "CMSYoungGenPerWorker"); 2260 2261 status = status && verify_min_value(CMSSamplingGrain, 1, "CMSSamplingGrain"); 2262 status = status && verify_interval(CMS_SweepWeight, 0, 100, "CMS_SweepWeight"); 2263 status = status && verify_interval(CMS_FLSWeight, 0, 100, "CMS_FLSWeight"); 2264 2265 status = status && verify_interval(FLSCoalescePolicy, 0, 4, "FLSCoalescePolicy"); 2266 2267 status = status && verify_min_value(CMSRescanMultiple, 1, "CMSRescanMultiple"); 2268 status = status && verify_min_value(CMSConcMarkMultiple, 1, "CMSConcMarkMultiple"); 2269 2270 status = status && verify_interval(CMSPrecleanIter, 0, 9, "CMSPrecleanIter"); 2271 status = status && verify_min_value(CMSPrecleanDenominator, 1, "CMSPrecleanDenominator"); 2272 status = status && verify_interval(CMSPrecleanNumerator, 0, CMSPrecleanDenominator - 1, "CMSPrecleanNumerator"); 2273 2274 status = status && verify_percentage(CMSBootstrapOccupancy, "CMSBootstrapOccupancy"); 2275 2276 status = status && verify_min_value(CMSPrecleanThreshold, 100, "CMSPrecleanThreshold"); 2277 2278 status = status && verify_percentage(CMSScheduleRemarkEdenPenetration, "CMSScheduleRemarkEdenPenetration"); 2279 status = status && verify_min_value(CMSScheduleRemarkSamplingRatio, 1, "CMSScheduleRemarkSamplingRatio"); 2280 status = status && verify_min_value(CMSBitMapYieldQuantum, 1, "CMSBitMapYieldQuantum"); 2281 status = status && verify_percentage(CMSTriggerRatio, "CMSTriggerRatio"); 2282 status = status && verify_percentage(CMSIsTooFullPercentage, "CMSIsTooFullPercentage"); 2283 } 2284 2285 if (UseParallelGC || UseParallelOldGC) { 2286 status = status && verify_interval(ParallelOldDeadWoodLimiterMean, 0, 100, "ParallelOldDeadWoodLimiterMean"); 2287 status = status && verify_interval(ParallelOldDeadWoodLimiterStdDev, 0, 100, "ParallelOldDeadWoodLimiterStdDev"); 2288 2289 status = status && verify_percentage(YoungGenerationSizeIncrement, "YoungGenerationSizeIncrement"); 2290 status = status && verify_percentage(TenuredGenerationSizeIncrement, "TenuredGenerationSizeIncrement"); 2291 2292 status = status && verify_min_value(YoungGenerationSizeSupplementDecay, 1, "YoungGenerationSizeSupplementDecay"); 2293 status = status && verify_min_value(TenuredGenerationSizeSupplementDecay, 1, "TenuredGenerationSizeSupplementDecay"); 2294 2295 status = status && verify_min_value(ParGCCardsPerStrideChunk, 1, "ParGCCardsPerStrideChunk"); 2296 2297 status = status && verify_min_value(ParallelOldGCSplitInterval, 0, "ParallelOldGCSplitInterval"); 2298 } 2299 #endif // INCLUDE_ALL_GCS 2300 2301 status = status && verify_interval(RefDiscoveryPolicy, 2302 ReferenceProcessor::DiscoveryPolicyMin, 2303 ReferenceProcessor::DiscoveryPolicyMax, 2304 "RefDiscoveryPolicy"); 2305 2306 // Limit the lower bound of this flag to 1 as it is used in a division 2307 // expression. 2308 status = status && verify_interval(TLABWasteTargetPercent, 2309 1, 100, "TLABWasteTargetPercent"); 2310 2311 status = status && verify_object_alignment(); 2312 2313 status = status && verify_interval(CompressedClassSpaceSize, 1*M, 3*G, 2314 "CompressedClassSpaceSize"); 2315 2316 status = status && verify_interval(MarkStackSizeMax, 2317 1, (max_jint - 1), "MarkStackSizeMax"); 2318 status = status && verify_interval(NUMAChunkResizeWeight, 0, 100, "NUMAChunkResizeWeight"); 2319 2320 status = status && verify_min_value(LogEventsBufferEntries, 1, "LogEventsBufferEntries"); 2321 2322 status = status && verify_min_value(HeapSizePerGCThread, (uintx) os::vm_page_size(), "HeapSizePerGCThread"); 2323 2324 status = status && verify_min_value(GCTaskTimeStampEntries, 1, "GCTaskTimeStampEntries"); 2325 2326 status = status && verify_percentage(ParallelGCBufferWastePct, "ParallelGCBufferWastePct"); 2327 status = status && verify_interval(TargetPLABWastePct, 1, 100, "TargetPLABWastePct"); 2328 2329 status = status && verify_min_value(ParGCStridesPerThread, 1, "ParGCStridesPerThread"); 2330 2331 status = status && verify_min_value(MinRAMFraction, 1, "MinRAMFraction"); 2332 status = status && verify_min_value(InitialRAMFraction, 1, "InitialRAMFraction"); 2333 status = status && verify_min_value(MaxRAMFraction, 1, "MaxRAMFraction"); 2334 status = status && verify_min_value(DefaultMaxRAMFraction, 1, "DefaultMaxRAMFraction"); 2335 2336 status = status && verify_interval(AdaptiveTimeWeight, 0, 100, "AdaptiveTimeWeight"); 2337 status = status && verify_min_value(AdaptiveSizeDecrementScaleFactor, 1, "AdaptiveSizeDecrementScaleFactor"); 2338 2339 status = status && verify_interval(TLABAllocationWeight, 0, 100, "TLABAllocationWeight"); 2340 status = status && verify_min_value(MinTLABSize, 1, "MinTLABSize"); 2341 status = status && verify_min_value(TLABRefillWasteFraction, 1, "TLABRefillWasteFraction"); 2342 2343 status = status && verify_percentage(YoungGenerationSizeSupplement, "YoungGenerationSizeSupplement"); 2344 status = status && verify_percentage(TenuredGenerationSizeSupplement, "TenuredGenerationSizeSupplement"); 2345 2346 // the "age" field in the oop header is 4 bits; do not want to pull in markOop.hpp 2347 // just for that, so hardcode here. 2348 status = status && verify_interval(MaxTenuringThreshold, 0, 15, "MaxTenuringThreshold"); 2349 status = status && verify_interval(InitialTenuringThreshold, 0, MaxTenuringThreshold, "MaxTenuringThreshold"); 2350 status = status && verify_percentage(TargetSurvivorRatio, "TargetSurvivorRatio"); 2351 status = status && verify_percentage(MarkSweepDeadRatio, "MarkSweepDeadRatio"); 2352 2353 status = status && verify_min_value(MarkSweepAlwaysCompactCount, 1, "MarkSweepAlwaysCompactCount"); 2354 2355 if (PrintNMTStatistics) { 2356 #if INCLUDE_NMT 2357 if (MemTracker::tracking_level() == MemTracker::NMT_off) { 2358 #endif // INCLUDE_NMT 2359 warning("PrintNMTStatistics is disabled, because native memory tracking is not enabled"); 2360 PrintNMTStatistics = false; 2361 #if INCLUDE_NMT 2362 } 2363 #endif 2364 } 2365 2366 // Need to limit the extent of the padding to reasonable size. 2367 // 8K is well beyond the reasonable HW cache line size, even with the 2368 // aggressive prefetching, while still leaving the room for segregating 2369 // among the distinct pages. 2370 if (ContendedPaddingWidth < 0 || ContendedPaddingWidth > 8192) { 2371 jio_fprintf(defaultStream::error_stream(), 2372 "ContendedPaddingWidth=" INTX_FORMAT " must be in between %d and %d\n", 2373 ContendedPaddingWidth, 0, 8192); 2374 status = false; 2375 } 2376 2377 // Need to enforce the padding not to break the existing field alignments. 2378 // It is sufficient to check against the largest type size. 2379 if ((ContendedPaddingWidth % BytesPerLong) != 0) { 2380 jio_fprintf(defaultStream::error_stream(), 2381 "ContendedPaddingWidth=" INTX_FORMAT " must be a multiple of %d\n", 2382 ContendedPaddingWidth, BytesPerLong); 2383 status = false; 2384 } 2385 2386 // Check lower bounds of the code cache 2387 // Template Interpreter code is approximately 3X larger in debug builds. 2388 uint min_code_cache_size = (CodeCacheMinimumUseSpace DEBUG_ONLY(* 3)) + CodeCacheMinimumFreeSpace; 2389 if (InitialCodeCacheSize < (uintx)os::vm_page_size()) { 2390 jio_fprintf(defaultStream::error_stream(), 2391 "Invalid InitialCodeCacheSize=%dK. Must be at least %dK.\n", InitialCodeCacheSize/K, 2392 os::vm_page_size()/K); 2393 status = false; 2394 } else if (ReservedCodeCacheSize < InitialCodeCacheSize) { 2395 jio_fprintf(defaultStream::error_stream(), 2396 "Invalid ReservedCodeCacheSize: %dK. Must be at least InitialCodeCacheSize=%dK.\n", 2397 ReservedCodeCacheSize/K, InitialCodeCacheSize/K); 2398 status = false; 2399 } else if (ReservedCodeCacheSize < min_code_cache_size) { 2400 jio_fprintf(defaultStream::error_stream(), 2401 "Invalid ReservedCodeCacheSize=%dK. Must be at least %uK.\n", ReservedCodeCacheSize/K, 2402 min_code_cache_size/K); 2403 status = false; 2404 } else if (ReservedCodeCacheSize > 2*G) { 2405 // Code cache size larger than MAXINT is not supported. 2406 jio_fprintf(defaultStream::error_stream(), 2407 "Invalid ReservedCodeCacheSize=%dM. Must be at most %uM.\n", ReservedCodeCacheSize/M, 2408 (2*G)/M); 2409 status = false; 2410 } 2411 2412 status &= verify_interval(NmethodSweepFraction, 1, ReservedCodeCacheSize/K, "NmethodSweepFraction"); 2413 status &= verify_interval(NmethodSweepActivity, 0, 2000, "NmethodSweepActivity"); 2414 status &= verify_interval(CodeCacheMinBlockLength, 1, 100, "CodeCacheMinBlockLength"); 2415 status &= verify_interval(CodeCacheSegmentSize, 1, 1024, "CodeCacheSegmentSize"); 2416 2417 // TieredCompilation needs at least 2 compiler threads. 2418 const int num_min_compiler_threads = (TieredCompilation && (TieredStopAtLevel >= CompLevel_full_optimization)) ? 2 : 1; 2419 status &=verify_min_value(CICompilerCount, num_min_compiler_threads, "CICompilerCount"); 2420 2421 return status; 2422 } 2423 2424 bool Arguments::is_bad_option(const JavaVMOption* option, jboolean ignore, 2425 const char* option_type) { 2426 if (ignore) return false; 2427 2428 const char* spacer = " "; 2429 if (option_type == NULL) { 2430 option_type = ++spacer; // Set both to the empty string. 2431 } 2432 2433 if (os::obsolete_option(option)) { 2434 jio_fprintf(defaultStream::error_stream(), 2435 "Obsolete %s%soption: %s\n", option_type, spacer, 2436 option->optionString); 2437 return false; 2438 } else { 2439 jio_fprintf(defaultStream::error_stream(), 2440 "Unrecognized %s%soption: %s\n", option_type, spacer, 2441 option->optionString); 2442 return true; 2443 } 2444 } 2445 2446 static const char* user_assertion_options[] = { 2447 "-da", "-ea", "-disableassertions", "-enableassertions", 0 2448 }; 2449 2450 static const char* system_assertion_options[] = { 2451 "-dsa", "-esa", "-disablesystemassertions", "-enablesystemassertions", 0 2452 }; 2453 2454 // Return true if any of the strings in null-terminated array 'names' matches. 2455 // If tail_allowed is true, then the tail must begin with a colon; otherwise, 2456 // the option must match exactly. 2457 static bool match_option(const JavaVMOption* option, const char** names, const char** tail, 2458 bool tail_allowed) { 2459 for (/* empty */; *names != NULL; ++names) { 2460 if (match_option(option, *names, tail)) { 2461 if (**tail == '\0' || tail_allowed && **tail == ':') { 2462 return true; 2463 } 2464 } 2465 } 2466 return false; 2467 } 2468 2469 bool Arguments::parse_uintx(const char* value, 2470 uintx* uintx_arg, 2471 uintx min_size) { 2472 2473 // Check the sign first since atomull() parses only unsigned values. 2474 bool value_is_positive = !(*value == '-'); 2475 2476 if (value_is_positive) { 2477 julong n; 2478 bool good_return = atomull(value, &n); 2479 if (good_return) { 2480 bool above_minimum = n >= min_size; 2481 bool value_is_too_large = n > max_uintx; 2482 2483 if (above_minimum && !value_is_too_large) { 2484 *uintx_arg = n; 2485 return true; 2486 } 2487 } 2488 } 2489 return false; 2490 } 2491 2492 Arguments::ArgsRange Arguments::parse_memory_size(const char* s, 2493 julong* long_arg, 2494 julong min_size) { 2495 if (!atomull(s, long_arg)) return arg_unreadable; 2496 return check_memory_size(*long_arg, min_size); 2497 } 2498 2499 // Parse JavaVMInitArgs structure 2500 2501 jint Arguments::parse_vm_init_args(const JavaVMInitArgs* args) { 2502 // For components of the system classpath. 2503 SysClassPath scp(Arguments::get_sysclasspath()); 2504 bool scp_assembly_required = false; 2505 2506 // Save default settings for some mode flags 2507 Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods; 2508 Arguments::_UseOnStackReplacement = UseOnStackReplacement; 2509 Arguments::_ClipInlining = ClipInlining; 2510 Arguments::_BackgroundCompilation = BackgroundCompilation; 2511 2512 // Setup flags for mixed which is the default 2513 set_mode_flags(_mixed); 2514 2515 // Parse JAVA_TOOL_OPTIONS environment variable (if present) 2516 jint result = parse_java_tool_options_environment_variable(&scp, &scp_assembly_required); 2517 if (result != JNI_OK) { 2518 return result; 2519 } 2520 2521 // Parse JavaVMInitArgs structure passed in 2522 result = parse_each_vm_init_arg(args, &scp, &scp_assembly_required, Flag::COMMAND_LINE); 2523 if (result != JNI_OK) { 2524 return result; 2525 } 2526 2527 // Parse _JAVA_OPTIONS environment variable (if present) (mimics classic VM) 2528 result = parse_java_options_environment_variable(&scp, &scp_assembly_required); 2529 if (result != JNI_OK) { 2530 return result; 2531 } 2532 2533 // Do final processing now that all arguments have been parsed 2534 result = finalize_vm_init_args(&scp, scp_assembly_required); 2535 if (result != JNI_OK) { 2536 return result; 2537 } 2538 2539 return JNI_OK; 2540 } 2541 2542 // Checks if name in command-line argument -agent{lib,path}:name[=options] 2543 // represents a valid HPROF of JDWP agent. is_path==true denotes that we 2544 // are dealing with -agentpath (case where name is a path), otherwise with 2545 // -agentlib 2546 bool valid_hprof_or_jdwp_agent(char *name, bool is_path) { 2547 char *_name; 2548 const char *_hprof = "hprof", *_jdwp = "jdwp"; 2549 size_t _len_hprof, _len_jdwp, _len_prefix; 2550 2551 if (is_path) { 2552 if ((_name = strrchr(name, (int) *os::file_separator())) == NULL) { 2553 return false; 2554 } 2555 2556 _name++; // skip past last path separator 2557 _len_prefix = strlen(JNI_LIB_PREFIX); 2558 2559 if (strncmp(_name, JNI_LIB_PREFIX, _len_prefix) != 0) { 2560 return false; 2561 } 2562 2563 _name += _len_prefix; 2564 _len_hprof = strlen(_hprof); 2565 _len_jdwp = strlen(_jdwp); 2566 2567 if (strncmp(_name, _hprof, _len_hprof) == 0) { 2568 _name += _len_hprof; 2569 } 2570 else if (strncmp(_name, _jdwp, _len_jdwp) == 0) { 2571 _name += _len_jdwp; 2572 } 2573 else { 2574 return false; 2575 } 2576 2577 if (strcmp(_name, JNI_LIB_SUFFIX) != 0) { 2578 return false; 2579 } 2580 2581 return true; 2582 } 2583 2584 if (strcmp(name, _hprof) == 0 || strcmp(name, _jdwp) == 0) { 2585 return true; 2586 } 2587 2588 return false; 2589 } 2590 2591 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, 2592 SysClassPath* scp_p, 2593 bool* scp_assembly_required_p, 2594 Flag::Flags origin) { 2595 // Remaining part of option string 2596 const char* tail; 2597 2598 // iterate over arguments 2599 for (int index = 0; index < args->nOptions; index++) { 2600 bool is_absolute_path = false; // for -agentpath vs -agentlib 2601 2602 const JavaVMOption* option = args->options + index; 2603 2604 if (!match_option(option, "-Djava.class.path", &tail) && 2605 !match_option(option, "-Dsun.java.command", &tail) && 2606 !match_option(option, "-Dsun.java.launcher", &tail)) { 2607 2608 // add all jvm options to the jvm_args string. This string 2609 // is used later to set the java.vm.args PerfData string constant. 2610 // the -Djava.class.path and the -Dsun.java.command options are 2611 // omitted from jvm_args string as each have their own PerfData 2612 // string constant object. 2613 build_jvm_args(option->optionString); 2614 } 2615 2616 // -verbose:[class/gc/jni] 2617 if (match_option(option, "-verbose", &tail)) { 2618 if (!strcmp(tail, ":class") || !strcmp(tail, "")) { 2619 FLAG_SET_CMDLINE(bool, TraceClassLoading, true); 2620 FLAG_SET_CMDLINE(bool, TraceClassUnloading, true); 2621 } else if (!strcmp(tail, ":gc")) { 2622 FLAG_SET_CMDLINE(bool, PrintGC, true); 2623 } else if (!strcmp(tail, ":jni")) { 2624 FLAG_SET_CMDLINE(bool, PrintJNIResolving, true); 2625 } 2626 // -da / -ea / -disableassertions / -enableassertions 2627 // These accept an optional class/package name separated by a colon, e.g., 2628 // -da:java.lang.Thread. 2629 } else if (match_option(option, user_assertion_options, &tail, true)) { 2630 bool enable = option->optionString[1] == 'e'; // char after '-' is 'e' 2631 if (*tail == '\0') { 2632 JavaAssertions::setUserClassDefault(enable); 2633 } else { 2634 assert(*tail == ':', "bogus match by match_option()"); 2635 JavaAssertions::addOption(tail + 1, enable); 2636 } 2637 // -dsa / -esa / -disablesystemassertions / -enablesystemassertions 2638 } else if (match_option(option, system_assertion_options, &tail, false)) { 2639 bool enable = option->optionString[1] == 'e'; // char after '-' is 'e' 2640 JavaAssertions::setSystemClassDefault(enable); 2641 // -bootclasspath: 2642 } else if (match_option(option, "-Xbootclasspath:", &tail)) { 2643 scp_p->reset_path(tail); 2644 *scp_assembly_required_p = true; 2645 // -bootclasspath/a: 2646 } else if (match_option(option, "-Xbootclasspath/a:", &tail)) { 2647 scp_p->add_suffix(tail); 2648 *scp_assembly_required_p = true; 2649 // -bootclasspath/p: 2650 } else if (match_option(option, "-Xbootclasspath/p:", &tail)) { 2651 scp_p->add_prefix(tail); 2652 *scp_assembly_required_p = true; 2653 // -Xrun 2654 } else if (match_option(option, "-Xrun", &tail)) { 2655 if (tail != NULL) { 2656 const char* pos = strchr(tail, ':'); 2657 size_t len = (pos == NULL) ? strlen(tail) : pos - tail; 2658 char* name = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len + 1, mtInternal), tail, len); 2659 name[len] = '\0'; 2660 2661 char *options = NULL; 2662 if(pos != NULL) { 2663 size_t len2 = strlen(pos+1) + 1; // options start after ':'. Final zero must be copied. 2664 options = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len2, mtInternal), pos+1, len2); 2665 } 2666 #if !INCLUDE_JVMTI 2667 if ((strcmp(name, "hprof") == 0) || (strcmp(name, "jdwp") == 0)) { 2668 jio_fprintf(defaultStream::error_stream(), 2669 "Profiling and debugging agents are not supported in this VM\n"); 2670 return JNI_ERR; 2671 } 2672 #endif // !INCLUDE_JVMTI 2673 add_init_library(name, options); 2674 } 2675 // -agentlib and -agentpath 2676 } else if (match_option(option, "-agentlib:", &tail) || 2677 (is_absolute_path = match_option(option, "-agentpath:", &tail))) { 2678 if(tail != NULL) { 2679 const char* pos = strchr(tail, '='); 2680 size_t len = (pos == NULL) ? strlen(tail) : pos - tail; 2681 char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1, mtInternal), tail, len); 2682 name[len] = '\0'; 2683 2684 char *options = NULL; 2685 if(pos != NULL) { 2686 options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(pos + 1) + 1, mtInternal), pos + 1); 2687 } 2688 #if !INCLUDE_JVMTI 2689 if (valid_hprof_or_jdwp_agent(name, is_absolute_path)) { 2690 jio_fprintf(defaultStream::error_stream(), 2691 "Profiling and debugging agents are not supported in this VM\n"); 2692 return JNI_ERR; 2693 } 2694 #endif // !INCLUDE_JVMTI 2695 add_init_agent(name, options, is_absolute_path); 2696 } 2697 // -javaagent 2698 } else if (match_option(option, "-javaagent:", &tail)) { 2699 #if !INCLUDE_JVMTI 2700 jio_fprintf(defaultStream::error_stream(), 2701 "Instrumentation agents are not supported in this VM\n"); 2702 return JNI_ERR; 2703 #else 2704 if(tail != NULL) { 2705 char *options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(tail) + 1, mtInternal), tail); 2706 add_init_agent("instrument", options, false); 2707 } 2708 #endif // !INCLUDE_JVMTI 2709 // -Xnoclassgc 2710 } else if (match_option(option, "-Xnoclassgc", &tail)) { 2711 FLAG_SET_CMDLINE(bool, ClassUnloading, false); 2712 // -Xincgc: i-CMS 2713 } else if (match_option(option, "-Xincgc", &tail)) { 2714 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true); 2715 FLAG_SET_CMDLINE(bool, CMSIncrementalMode, true); 2716 // -Xnoincgc: no i-CMS 2717 } else if (match_option(option, "-Xnoincgc", &tail)) { 2718 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false); 2719 FLAG_SET_CMDLINE(bool, CMSIncrementalMode, false); 2720 // -Xconcgc 2721 } else if (match_option(option, "-Xconcgc", &tail)) { 2722 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true); 2723 // -Xnoconcgc 2724 } else if (match_option(option, "-Xnoconcgc", &tail)) { 2725 FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false); 2726 // -Xbatch 2727 } else if (match_option(option, "-Xbatch", &tail)) { 2728 FLAG_SET_CMDLINE(bool, BackgroundCompilation, false); 2729 // -Xmn for compatibility with other JVM vendors 2730 } else if (match_option(option, "-Xmn", &tail)) { 2731 julong long_initial_young_size = 0; 2732 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1); 2733 if (errcode != arg_in_range) { 2734 jio_fprintf(defaultStream::error_stream(), 2735 "Invalid initial young generation size: %s\n", option->optionString); 2736 describe_range_error(errcode); 2737 return JNI_EINVAL; 2738 } 2739 FLAG_SET_CMDLINE(uintx, MaxNewSize, (uintx)long_initial_young_size); 2740 FLAG_SET_CMDLINE(uintx, NewSize, (uintx)long_initial_young_size); 2741 // -Xms 2742 } else if (match_option(option, "-Xms", &tail)) { 2743 julong long_initial_heap_size = 0; 2744 // an initial heap size of 0 means automatically determine 2745 ArgsRange errcode = parse_memory_size(tail, &long_initial_heap_size, 0); 2746 if (errcode != arg_in_range) { 2747 jio_fprintf(defaultStream::error_stream(), 2748 "Invalid initial heap size: %s\n", option->optionString); 2749 describe_range_error(errcode); 2750 return JNI_EINVAL; 2751 } 2752 set_min_heap_size((uintx)long_initial_heap_size); 2753 // Currently the minimum size and the initial heap sizes are the same. 2754 // Can be overridden with -XX:InitialHeapSize. 2755 FLAG_SET_CMDLINE(uintx, InitialHeapSize, (uintx)long_initial_heap_size); 2756 // -Xmx 2757 } else if (match_option(option, "-Xmx", &tail) || match_option(option, "-XX:MaxHeapSize=", &tail)) { 2758 julong long_max_heap_size = 0; 2759 ArgsRange errcode = parse_memory_size(tail, &long_max_heap_size, 1); 2760 if (errcode != arg_in_range) { 2761 jio_fprintf(defaultStream::error_stream(), 2762 "Invalid maximum heap size: %s\n", option->optionString); 2763 describe_range_error(errcode); 2764 return JNI_EINVAL; 2765 } 2766 FLAG_SET_CMDLINE(uintx, MaxHeapSize, (uintx)long_max_heap_size); 2767 // Xmaxf 2768 } else if (match_option(option, "-Xmaxf", &tail)) { 2769 char* err; 2770 int maxf = (int)(strtod(tail, &err) * 100); 2771 if (*err != '\0' || *tail == '\0' || maxf < 0 || maxf > 100) { 2772 jio_fprintf(defaultStream::error_stream(), 2773 "Bad max heap free percentage size: %s\n", 2774 option->optionString); 2775 return JNI_EINVAL; 2776 } else { 2777 FLAG_SET_CMDLINE(uintx, MaxHeapFreeRatio, maxf); 2778 } 2779 // Xminf 2780 } else if (match_option(option, "-Xminf", &tail)) { 2781 char* err; 2782 int minf = (int)(strtod(tail, &err) * 100); 2783 if (*err != '\0' || *tail == '\0' || minf < 0 || minf > 100) { 2784 jio_fprintf(defaultStream::error_stream(), 2785 "Bad min heap free percentage size: %s\n", 2786 option->optionString); 2787 return JNI_EINVAL; 2788 } else { 2789 FLAG_SET_CMDLINE(uintx, MinHeapFreeRatio, minf); 2790 } 2791 // -Xss 2792 } else if (match_option(option, "-Xss", &tail)) { 2793 julong long_ThreadStackSize = 0; 2794 ArgsRange errcode = parse_memory_size(tail, &long_ThreadStackSize, 1000); 2795 if (errcode != arg_in_range) { 2796 jio_fprintf(defaultStream::error_stream(), 2797 "Invalid thread stack size: %s\n", option->optionString); 2798 describe_range_error(errcode); 2799 return JNI_EINVAL; 2800 } 2801 // Internally track ThreadStackSize in units of 1024 bytes. 2802 FLAG_SET_CMDLINE(intx, ThreadStackSize, 2803 round_to((int)long_ThreadStackSize, K) / K); 2804 // -Xoss 2805 } else if (match_option(option, "-Xoss", &tail)) { 2806 // HotSpot does not have separate native and Java stacks, ignore silently for compatibility 2807 } else if (match_option(option, "-XX:CodeCacheExpansionSize=", &tail)) { 2808 julong long_CodeCacheExpansionSize = 0; 2809 ArgsRange errcode = parse_memory_size(tail, &long_CodeCacheExpansionSize, os::vm_page_size()); 2810 if (errcode != arg_in_range) { 2811 jio_fprintf(defaultStream::error_stream(), 2812 "Invalid argument: %s. Must be at least %luK.\n", option->optionString, 2813 os::vm_page_size()/K); 2814 return JNI_EINVAL; 2815 } 2816 FLAG_SET_CMDLINE(uintx, CodeCacheExpansionSize, (uintx)long_CodeCacheExpansionSize); 2817 } else if (match_option(option, "-Xmaxjitcodesize", &tail) || 2818 match_option(option, "-XX:ReservedCodeCacheSize=", &tail)) { 2819 julong long_ReservedCodeCacheSize = 0; 2820 2821 ArgsRange errcode = parse_memory_size(tail, &long_ReservedCodeCacheSize, 1); 2822 if (errcode != arg_in_range) { 2823 jio_fprintf(defaultStream::error_stream(), 2824 "Invalid maximum code cache size: %s.\n", option->optionString); 2825 return JNI_EINVAL; 2826 } 2827 FLAG_SET_CMDLINE(uintx, ReservedCodeCacheSize, (uintx)long_ReservedCodeCacheSize); 2828 //-XX:IncreaseFirstTierCompileThresholdAt= 2829 } else if (match_option(option, "-XX:IncreaseFirstTierCompileThresholdAt=", &tail)) { 2830 uintx uint_IncreaseFirstTierCompileThresholdAt = 0; 2831 if (!parse_uintx(tail, &uint_IncreaseFirstTierCompileThresholdAt, 0) || uint_IncreaseFirstTierCompileThresholdAt > 99) { 2832 jio_fprintf(defaultStream::error_stream(), 2833 "Invalid value for IncreaseFirstTierCompileThresholdAt: %s. Should be between 0 and 99.\n", 2834 option->optionString); 2835 return JNI_EINVAL; 2836 } 2837 FLAG_SET_CMDLINE(uintx, IncreaseFirstTierCompileThresholdAt, (uintx)uint_IncreaseFirstTierCompileThresholdAt); 2838 // -green 2839 } else if (match_option(option, "-green", &tail)) { 2840 jio_fprintf(defaultStream::error_stream(), 2841 "Green threads support not available\n"); 2842 return JNI_EINVAL; 2843 // -native 2844 } else if (match_option(option, "-native", &tail)) { 2845 // HotSpot always uses native threads, ignore silently for compatibility 2846 // -Xsqnopause 2847 } else if (match_option(option, "-Xsqnopause", &tail)) { 2848 // EVM option, ignore silently for compatibility 2849 // -Xrs 2850 } else if (match_option(option, "-Xrs", &tail)) { 2851 // Classic/EVM option, new functionality 2852 FLAG_SET_CMDLINE(bool, ReduceSignalUsage, true); 2853 } else if (match_option(option, "-Xusealtsigs", &tail)) { 2854 // change default internal VM signals used - lower case for back compat 2855 FLAG_SET_CMDLINE(bool, UseAltSigs, true); 2856 // -Xoptimize 2857 } else if (match_option(option, "-Xoptimize", &tail)) { 2858 // EVM option, ignore silently for compatibility 2859 // -Xprof 2860 } else if (match_option(option, "-Xprof", &tail)) { 2861 #if INCLUDE_FPROF 2862 _has_profile = true; 2863 #else // INCLUDE_FPROF 2864 jio_fprintf(defaultStream::error_stream(), 2865 "Flat profiling is not supported in this VM.\n"); 2866 return JNI_ERR; 2867 #endif // INCLUDE_FPROF 2868 // -Xconcurrentio 2869 } else if (match_option(option, "-Xconcurrentio", &tail)) { 2870 FLAG_SET_CMDLINE(bool, UseLWPSynchronization, true); 2871 FLAG_SET_CMDLINE(bool, BackgroundCompilation, false); 2872 FLAG_SET_CMDLINE(intx, DeferThrSuspendLoopCount, 1); 2873 FLAG_SET_CMDLINE(bool, UseTLAB, false); 2874 FLAG_SET_CMDLINE(uintx, NewSizeThreadIncrease, 16 * K); // 20Kb per thread added to new generation 2875 2876 // -Xinternalversion 2877 } else if (match_option(option, "-Xinternalversion", &tail)) { 2878 jio_fprintf(defaultStream::output_stream(), "%s\n", 2879 VM_Version::internal_vm_info_string()); 2880 vm_exit(0); 2881 #ifndef PRODUCT 2882 // -Xprintflags 2883 } else if (match_option(option, "-Xprintflags", &tail)) { 2884 CommandLineFlags::printFlags(tty, false); 2885 vm_exit(0); 2886 #endif 2887 // -D 2888 } else if (match_option(option, "-D", &tail)) { 2889 if (!add_property(tail)) { 2890 return JNI_ENOMEM; 2891 } 2892 // Out of the box management support 2893 if (match_option(option, "-Dcom.sun.management", &tail)) { 2894 #if INCLUDE_MANAGEMENT 2895 FLAG_SET_CMDLINE(bool, ManagementServer, true); 2896 #else 2897 jio_fprintf(defaultStream::output_stream(), 2898 "-Dcom.sun.management is not supported in this VM.\n"); 2899 return JNI_ERR; 2900 #endif 2901 } 2902 // -Xint 2903 } else if (match_option(option, "-Xint", &tail)) { 2904 set_mode_flags(_int); 2905 // -Xmixed 2906 } else if (match_option(option, "-Xmixed", &tail)) { 2907 set_mode_flags(_mixed); 2908 // -Xcomp 2909 } else if (match_option(option, "-Xcomp", &tail)) { 2910 // for testing the compiler; turn off all flags that inhibit compilation 2911 set_mode_flags(_comp); 2912 // -Xshare:dump 2913 } else if (match_option(option, "-Xshare:dump", &tail)) { 2914 FLAG_SET_CMDLINE(bool, DumpSharedSpaces, true); 2915 set_mode_flags(_int); // Prevent compilation, which creates objects 2916 // -Xshare:on 2917 } else if (match_option(option, "-Xshare:on", &tail)) { 2918 FLAG_SET_CMDLINE(bool, UseSharedSpaces, true); 2919 FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true); 2920 // -Xshare:auto 2921 } else if (match_option(option, "-Xshare:auto", &tail)) { 2922 FLAG_SET_CMDLINE(bool, UseSharedSpaces, true); 2923 FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false); 2924 // -Xshare:off 2925 } else if (match_option(option, "-Xshare:off", &tail)) { 2926 FLAG_SET_CMDLINE(bool, UseSharedSpaces, false); 2927 FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false); 2928 // -Xverify 2929 } else if (match_option(option, "-Xverify", &tail)) { 2930 if (strcmp(tail, ":all") == 0 || strcmp(tail, "") == 0) { 2931 FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, true); 2932 FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true); 2933 } else if (strcmp(tail, ":remote") == 0) { 2934 FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false); 2935 FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true); 2936 } else if (strcmp(tail, ":none") == 0) { 2937 FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false); 2938 FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, false); 2939 } else if (is_bad_option(option, args->ignoreUnrecognized, "verification")) { 2940 return JNI_EINVAL; 2941 } 2942 // -Xdebug 2943 } else if (match_option(option, "-Xdebug", &tail)) { 2944 // note this flag has been used, then ignore 2945 set_xdebug_mode(true); 2946 // -Xnoagent 2947 } else if (match_option(option, "-Xnoagent", &tail)) { 2948 // For compatibility with classic. HotSpot refuses to load the old style agent.dll. 2949 } else if (match_option(option, "-Xboundthreads", &tail)) { 2950 // Bind user level threads to kernel threads (Solaris only) 2951 FLAG_SET_CMDLINE(bool, UseBoundThreads, true); 2952 } else if (match_option(option, "-Xloggc:", &tail)) { 2953 // Redirect GC output to the file. -Xloggc:<filename> 2954 // ostream_init_log(), when called will use this filename 2955 // to initialize a fileStream. 2956 _gc_log_filename = strdup(tail); 2957 if (!is_filename_valid(_gc_log_filename)) { 2958 jio_fprintf(defaultStream::output_stream(), 2959 "Invalid file name for use with -Xloggc: Filename can only contain the " 2960 "characters [A-Z][a-z][0-9]-_.%%[p|t] but it has been %s\n" 2961 "Note %%p or %%t can only be used once\n", _gc_log_filename); 2962 return JNI_EINVAL; 2963 } 2964 FLAG_SET_CMDLINE(bool, PrintGC, true); 2965 FLAG_SET_CMDLINE(bool, PrintGCTimeStamps, true); 2966 2967 // JNI hooks 2968 } else if (match_option(option, "-Xcheck", &tail)) { 2969 if (!strcmp(tail, ":jni")) { 2970 #if !INCLUDE_JNI_CHECK 2971 warning("JNI CHECKING is not supported in this VM"); 2972 #else 2973 CheckJNICalls = true; 2974 #endif // INCLUDE_JNI_CHECK 2975 } else if (is_bad_option(option, args->ignoreUnrecognized, 2976 "check")) { 2977 return JNI_EINVAL; 2978 } 2979 } else if (match_option(option, "vfprintf", &tail)) { 2980 _vfprintf_hook = CAST_TO_FN_PTR(vfprintf_hook_t, option->extraInfo); 2981 } else if (match_option(option, "exit", &tail)) { 2982 _exit_hook = CAST_TO_FN_PTR(exit_hook_t, option->extraInfo); 2983 } else if (match_option(option, "abort", &tail)) { 2984 _abort_hook = CAST_TO_FN_PTR(abort_hook_t, option->extraInfo); 2985 // -XX:+AggressiveHeap 2986 } else if (match_option(option, "-XX:+AggressiveHeap", &tail)) { 2987 2988 // This option inspects the machine and attempts to set various 2989 // parameters to be optimal for long-running, memory allocation 2990 // intensive jobs. It is intended for machines with large 2991 // amounts of cpu and memory. 2992 2993 // initHeapSize is needed since _initial_heap_size is 4 bytes on a 32 bit 2994 // VM, but we may not be able to represent the total physical memory 2995 // available (like having 8gb of memory on a box but using a 32bit VM). 2996 // Thus, we need to make sure we're using a julong for intermediate 2997 // calculations. 2998 julong initHeapSize; 2999 julong total_memory = os::physical_memory(); 3000 3001 if (total_memory < (julong)256*M) { 3002 jio_fprintf(defaultStream::error_stream(), 3003 "You need at least 256mb of memory to use -XX:+AggressiveHeap\n"); 3004 vm_exit(1); 3005 } 3006 3007 // The heap size is half of available memory, or (at most) 3008 // all of possible memory less 160mb (leaving room for the OS 3009 // when using ISM). This is the maximum; because adaptive sizing 3010 // is turned on below, the actual space used may be smaller. 3011 3012 initHeapSize = MIN2(total_memory / (julong)2, 3013 total_memory - (julong)160*M); 3014 3015 initHeapSize = limit_by_allocatable_memory(initHeapSize); 3016 3017 if (FLAG_IS_DEFAULT(MaxHeapSize)) { 3018 FLAG_SET_CMDLINE(uintx, MaxHeapSize, initHeapSize); 3019 FLAG_SET_CMDLINE(uintx, InitialHeapSize, initHeapSize); 3020 // Currently the minimum size and the initial heap sizes are the same. 3021 set_min_heap_size(initHeapSize); 3022 } 3023 if (FLAG_IS_DEFAULT(NewSize)) { 3024 // Make the young generation 3/8ths of the total heap. 3025 FLAG_SET_CMDLINE(uintx, NewSize, 3026 ((julong)MaxHeapSize / (julong)8) * (julong)3); 3027 FLAG_SET_CMDLINE(uintx, MaxNewSize, NewSize); 3028 } 3029 3030 #ifndef _ALLBSD_SOURCE // UseLargePages is not yet supported on BSD. 3031 FLAG_SET_DEFAULT(UseLargePages, true); 3032 #endif 3033 3034 // Increase some data structure sizes for efficiency 3035 FLAG_SET_CMDLINE(uintx, BaseFootPrintEstimate, MaxHeapSize); 3036 FLAG_SET_CMDLINE(bool, ResizeTLAB, false); 3037 FLAG_SET_CMDLINE(uintx, TLABSize, 256*K); 3038 3039 // See the OldPLABSize comment below, but replace 'after promotion' 3040 // with 'after copying'. YoungPLABSize is the size of the survivor 3041 // space per-gc-thread buffers. The default is 4kw. 3042 FLAG_SET_CMDLINE(uintx, YoungPLABSize, 256*K); // Note: this is in words 3043 3044 // OldPLABSize is the size of the buffers in the old gen that 3045 // UseParallelGC uses to promote live data that doesn't fit in the 3046 // survivor spaces. At any given time, there's one for each gc thread. 3047 // The default size is 1kw. These buffers are rarely used, since the 3048 // survivor spaces are usually big enough. For specjbb, however, there 3049 // are occasions when there's lots of live data in the young gen 3050 // and we end up promoting some of it. We don't have a definite 3051 // explanation for why bumping OldPLABSize helps, but the theory 3052 // is that a bigger PLAB results in retaining something like the 3053 // original allocation order after promotion, which improves mutator 3054 // locality. A minor effect may be that larger PLABs reduce the 3055 // number of PLAB allocation events during gc. The value of 8kw 3056 // was arrived at by experimenting with specjbb. 3057 FLAG_SET_CMDLINE(uintx, OldPLABSize, 8*K); // Note: this is in words 3058 3059 // Enable parallel GC and adaptive generation sizing 3060 FLAG_SET_CMDLINE(bool, UseParallelGC, true); 3061 FLAG_SET_DEFAULT(ParallelGCThreads, 3062 Abstract_VM_Version::parallel_worker_threads()); 3063 3064 // Encourage steady state memory management 3065 FLAG_SET_CMDLINE(uintx, ThresholdTolerance, 100); 3066 3067 // This appears to improve mutator locality 3068 FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false); 3069 3070 // Get around early Solaris scheduling bug 3071 // (affinity vs other jobs on system) 3072 // but disallow DR and offlining (5008695). 3073 FLAG_SET_CMDLINE(bool, BindGCTaskThreadsToCPUs, true); 3074 3075 } else if (match_option(option, "-XX:+NeverTenure", &tail)) { 3076 // The last option must always win. 3077 FLAG_SET_CMDLINE(bool, AlwaysTenure, false); 3078 FLAG_SET_CMDLINE(bool, NeverTenure, true); 3079 } else if (match_option(option, "-XX:+AlwaysTenure", &tail)) { 3080 // The last option must always win. 3081 FLAG_SET_CMDLINE(bool, NeverTenure, false); 3082 FLAG_SET_CMDLINE(bool, AlwaysTenure, true); 3083 } else if (match_option(option, "-XX:+CMSPermGenSweepingEnabled", &tail) || 3084 match_option(option, "-XX:-CMSPermGenSweepingEnabled", &tail)) { 3085 jio_fprintf(defaultStream::error_stream(), 3086 "Please use CMSClassUnloadingEnabled in place of " 3087 "CMSPermGenSweepingEnabled in the future\n"); 3088 } else if (match_option(option, "-XX:+UseGCTimeLimit", &tail)) { 3089 FLAG_SET_CMDLINE(bool, UseGCOverheadLimit, true); 3090 jio_fprintf(defaultStream::error_stream(), 3091 "Please use -XX:+UseGCOverheadLimit in place of " 3092 "-XX:+UseGCTimeLimit in the future\n"); 3093 } else if (match_option(option, "-XX:-UseGCTimeLimit", &tail)) { 3094 FLAG_SET_CMDLINE(bool, UseGCOverheadLimit, false); 3095 jio_fprintf(defaultStream::error_stream(), 3096 "Please use -XX:-UseGCOverheadLimit in place of " 3097 "-XX:-UseGCTimeLimit in the future\n"); 3098 // The TLE options are for compatibility with 1.3 and will be 3099 // removed without notice in a future release. These options 3100 // are not to be documented. 3101 } else if (match_option(option, "-XX:MaxTLERatio=", &tail)) { 3102 // No longer used. 3103 } else if (match_option(option, "-XX:+ResizeTLE", &tail)) { 3104 FLAG_SET_CMDLINE(bool, ResizeTLAB, true); 3105 } else if (match_option(option, "-XX:-ResizeTLE", &tail)) { 3106 FLAG_SET_CMDLINE(bool, ResizeTLAB, false); 3107 } else if (match_option(option, "-XX:+PrintTLE", &tail)) { 3108 FLAG_SET_CMDLINE(bool, PrintTLAB, true); 3109 } else if (match_option(option, "-XX:-PrintTLE", &tail)) { 3110 FLAG_SET_CMDLINE(bool, PrintTLAB, false); 3111 } else if (match_option(option, "-XX:TLEFragmentationRatio=", &tail)) { 3112 // No longer used. 3113 } else if (match_option(option, "-XX:TLESize=", &tail)) { 3114 julong long_tlab_size = 0; 3115 ArgsRange errcode = parse_memory_size(tail, &long_tlab_size, 1); 3116 if (errcode != arg_in_range) { 3117 jio_fprintf(defaultStream::error_stream(), 3118 "Invalid TLAB size: %s\n", option->optionString); 3119 describe_range_error(errcode); 3120 return JNI_EINVAL; 3121 } 3122 FLAG_SET_CMDLINE(uintx, TLABSize, long_tlab_size); 3123 } else if (match_option(option, "-XX:TLEThreadRatio=", &tail)) { 3124 // No longer used. 3125 } else if (match_option(option, "-XX:+UseTLE", &tail)) { 3126 FLAG_SET_CMDLINE(bool, UseTLAB, true); 3127 } else if (match_option(option, "-XX:-UseTLE", &tail)) { 3128 FLAG_SET_CMDLINE(bool, UseTLAB, false); 3129 } else if (match_option(option, "-XX:+DisplayVMOutputToStderr", &tail)) { 3130 FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, false); 3131 FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, true); 3132 } else if (match_option(option, "-XX:+DisplayVMOutputToStdout", &tail)) { 3133 FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, false); 3134 FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, true); 3135 } else if (match_option(option, "-XX:+ExtendedDTraceProbes", &tail)) { 3136 #if defined(DTRACE_ENABLED) 3137 FLAG_SET_CMDLINE(bool, ExtendedDTraceProbes, true); 3138 FLAG_SET_CMDLINE(bool, DTraceMethodProbes, true); 3139 FLAG_SET_CMDLINE(bool, DTraceAllocProbes, true); 3140 FLAG_SET_CMDLINE(bool, DTraceMonitorProbes, true); 3141 #else // defined(DTRACE_ENABLED) 3142 jio_fprintf(defaultStream::error_stream(), 3143 "ExtendedDTraceProbes flag is not applicable for this configuration\n"); 3144 return JNI_EINVAL; 3145 #endif // defined(DTRACE_ENABLED) 3146 #ifdef ASSERT 3147 } else if (match_option(option, "-XX:+FullGCALot", &tail)) { 3148 FLAG_SET_CMDLINE(bool, FullGCALot, true); 3149 // disable scavenge before parallel mark-compact 3150 FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false); 3151 #endif 3152 } else if (match_option(option, "-XX:CMSParPromoteBlocksToClaim=", &tail)) { 3153 julong cms_blocks_to_claim = (julong)atol(tail); 3154 FLAG_SET_CMDLINE(uintx, CMSParPromoteBlocksToClaim, cms_blocks_to_claim); 3155 jio_fprintf(defaultStream::error_stream(), 3156 "Please use -XX:OldPLABSize in place of " 3157 "-XX:CMSParPromoteBlocksToClaim in the future\n"); 3158 } else if (match_option(option, "-XX:ParCMSPromoteBlocksToClaim=", &tail)) { 3159 julong cms_blocks_to_claim = (julong)atol(tail); 3160 FLAG_SET_CMDLINE(uintx, CMSParPromoteBlocksToClaim, cms_blocks_to_claim); 3161 jio_fprintf(defaultStream::error_stream(), 3162 "Please use -XX:OldPLABSize in place of " 3163 "-XX:ParCMSPromoteBlocksToClaim in the future\n"); 3164 } else if (match_option(option, "-XX:ParallelGCOldGenAllocBufferSize=", &tail)) { 3165 julong old_plab_size = 0; 3166 ArgsRange errcode = parse_memory_size(tail, &old_plab_size, 1); 3167 if (errcode != arg_in_range) { 3168 jio_fprintf(defaultStream::error_stream(), 3169 "Invalid old PLAB size: %s\n", option->optionString); 3170 describe_range_error(errcode); 3171 return JNI_EINVAL; 3172 } 3173 FLAG_SET_CMDLINE(uintx, OldPLABSize, old_plab_size); 3174 jio_fprintf(defaultStream::error_stream(), 3175 "Please use -XX:OldPLABSize in place of " 3176 "-XX:ParallelGCOldGenAllocBufferSize in the future\n"); 3177 } else if (match_option(option, "-XX:ParallelGCToSpaceAllocBufferSize=", &tail)) { 3178 julong young_plab_size = 0; 3179 ArgsRange errcode = parse_memory_size(tail, &young_plab_size, 1); 3180 if (errcode != arg_in_range) { 3181 jio_fprintf(defaultStream::error_stream(), 3182 "Invalid young PLAB size: %s\n", option->optionString); 3183 describe_range_error(errcode); 3184 return JNI_EINVAL; 3185 } 3186 FLAG_SET_CMDLINE(uintx, YoungPLABSize, young_plab_size); 3187 jio_fprintf(defaultStream::error_stream(), 3188 "Please use -XX:YoungPLABSize in place of " 3189 "-XX:ParallelGCToSpaceAllocBufferSize in the future\n"); 3190 } else if (match_option(option, "-XX:CMSMarkStackSize=", &tail) || 3191 match_option(option, "-XX:G1MarkStackSize=", &tail)) { 3192 julong stack_size = 0; 3193 ArgsRange errcode = parse_memory_size(tail, &stack_size, 1); 3194 if (errcode != arg_in_range) { 3195 jio_fprintf(defaultStream::error_stream(), 3196 "Invalid mark stack size: %s\n", option->optionString); 3197 describe_range_error(errcode); 3198 return JNI_EINVAL; 3199 } 3200 FLAG_SET_CMDLINE(uintx, MarkStackSize, stack_size); 3201 } else if (match_option(option, "-XX:CMSMarkStackSizeMax=", &tail)) { 3202 julong max_stack_size = 0; 3203 ArgsRange errcode = parse_memory_size(tail, &max_stack_size, 1); 3204 if (errcode != arg_in_range) { 3205 jio_fprintf(defaultStream::error_stream(), 3206 "Invalid maximum mark stack size: %s\n", 3207 option->optionString); 3208 describe_range_error(errcode); 3209 return JNI_EINVAL; 3210 } 3211 FLAG_SET_CMDLINE(uintx, MarkStackSizeMax, max_stack_size); 3212 } else if (match_option(option, "-XX:ParallelMarkingThreads=", &tail) || 3213 match_option(option, "-XX:ParallelCMSThreads=", &tail)) { 3214 uintx conc_threads = 0; 3215 if (!parse_uintx(tail, &conc_threads, 1)) { 3216 jio_fprintf(defaultStream::error_stream(), 3217 "Invalid concurrent threads: %s\n", option->optionString); 3218 return JNI_EINVAL; 3219 } 3220 FLAG_SET_CMDLINE(uintx, ConcGCThreads, conc_threads); 3221 } else if (match_option(option, "-XX:MaxDirectMemorySize=", &tail)) { 3222 julong max_direct_memory_size = 0; 3223 ArgsRange errcode = parse_memory_size(tail, &max_direct_memory_size, 0); 3224 if (errcode != arg_in_range) { 3225 jio_fprintf(defaultStream::error_stream(), 3226 "Invalid maximum direct memory size: %s\n", 3227 option->optionString); 3228 describe_range_error(errcode); 3229 return JNI_EINVAL; 3230 } 3231 FLAG_SET_CMDLINE(uintx, MaxDirectMemorySize, max_direct_memory_size); 3232 } else if (match_option(option, "-XX:+UseVMInterruptibleIO", &tail)) { 3233 // NOTE! In JDK 9, the UseVMInterruptibleIO flag will completely go 3234 // away and will cause VM initialization failures! 3235 warning("-XX:+UseVMInterruptibleIO is obsolete and will be removed in a future release."); 3236 FLAG_SET_CMDLINE(bool, UseVMInterruptibleIO, true); 3237 #if !INCLUDE_MANAGEMENT 3238 } else if (match_option(option, "-XX:+ManagementServer", &tail)) { 3239 jio_fprintf(defaultStream::error_stream(), 3240 "ManagementServer is not supported in this VM.\n"); 3241 return JNI_ERR; 3242 #endif // INCLUDE_MANAGEMENT 3243 } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx 3244 // Skip -XX:Flags= since that case has already been handled 3245 if (strncmp(tail, "Flags=", strlen("Flags=")) != 0) { 3246 if (!process_argument(tail, args->ignoreUnrecognized, origin)) { 3247 return JNI_EINVAL; 3248 } 3249 } 3250 // Unknown option 3251 } else if (is_bad_option(option, args->ignoreUnrecognized)) { 3252 return JNI_ERR; 3253 } 3254 } 3255 3256 // Change the default value for flags which have different default values 3257 // when working with older JDKs. 3258 #ifdef LINUX 3259 if (JDK_Version::current().compare_major(6) <= 0 && 3260 FLAG_IS_DEFAULT(UseLinuxPosixThreadCPUClocks)) { 3261 FLAG_SET_DEFAULT(UseLinuxPosixThreadCPUClocks, false); 3262 } 3263 #endif // LINUX 3264 return JNI_OK; 3265 } 3266 3267 jint Arguments::finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required) { 3268 // This must be done after all -D arguments have been processed. 3269 scp_p->expand_endorsed(); 3270 3271 if (scp_assembly_required || scp_p->get_endorsed() != NULL) { 3272 // Assemble the bootclasspath elements into the final path. 3273 Arguments::set_sysclasspath(scp_p->combined_path()); 3274 } 3275 3276 // This must be done after all arguments have been processed. 3277 // java_compiler() true means set to "NONE" or empty. 3278 if (java_compiler() && !xdebug_mode()) { 3279 // For backwards compatibility, we switch to interpreted mode if 3280 // -Djava.compiler="NONE" or "" is specified AND "-Xdebug" was 3281 // not specified. 3282 set_mode_flags(_int); 3283 } 3284 if (CompileThreshold == 0) { 3285 set_mode_flags(_int); 3286 } 3287 3288 // eventually fix up InitialTenuringThreshold if only MaxTenuringThreshold is set 3289 if (FLAG_IS_DEFAULT(InitialTenuringThreshold) && (InitialTenuringThreshold > MaxTenuringThreshold)) { 3290 FLAG_SET_ERGO(uintx, InitialTenuringThreshold, MaxTenuringThreshold); 3291 } 3292 3293 #ifndef COMPILER2 3294 // Don't degrade server performance for footprint 3295 if (FLAG_IS_DEFAULT(UseLargePages) && 3296 MaxHeapSize < LargePageHeapSizeThreshold) { 3297 // No need for large granularity pages w/small heaps. 3298 // Note that large pages are enabled/disabled for both the 3299 // Java heap and the code cache. 3300 FLAG_SET_DEFAULT(UseLargePages, false); 3301 } 3302 3303 #else 3304 if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) { 3305 FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment-1); 3306 } 3307 #endif 3308 3309 #ifndef TIERED 3310 // Tiered compilation is undefined. 3311 UNSUPPORTED_OPTION(TieredCompilation, "TieredCompilation"); 3312 #endif 3313 3314 // If we are running in a headless jre, force java.awt.headless property 3315 // to be true unless the property has already been set. 3316 // Also allow the OS environment variable JAVA_AWT_HEADLESS to set headless state. 3317 if (os::is_headless_jre()) { 3318 const char* headless = Arguments::get_property("java.awt.headless"); 3319 if (headless == NULL) { 3320 char envbuffer[128]; 3321 if (!os::getenv("JAVA_AWT_HEADLESS", envbuffer, sizeof(envbuffer))) { 3322 if (!add_property("java.awt.headless=true")) { 3323 return JNI_ENOMEM; 3324 } 3325 } else { 3326 char buffer[256]; 3327 strcpy(buffer, "java.awt.headless="); 3328 strcat(buffer, envbuffer); 3329 if (!add_property(buffer)) { 3330 return JNI_ENOMEM; 3331 } 3332 } 3333 } 3334 } 3335 3336 if (!check_vm_args_consistency()) { 3337 return JNI_ERR; 3338 } 3339 3340 return JNI_OK; 3341 } 3342 3343 jint Arguments::parse_java_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) { 3344 return parse_options_environment_variable("_JAVA_OPTIONS", scp_p, 3345 scp_assembly_required_p); 3346 } 3347 3348 jint Arguments::parse_java_tool_options_environment_variable(SysClassPath* scp_p, bool* scp_assembly_required_p) { 3349 return parse_options_environment_variable("JAVA_TOOL_OPTIONS", scp_p, 3350 scp_assembly_required_p); 3351 } 3352 3353 jint Arguments::parse_options_environment_variable(const char* name, SysClassPath* scp_p, bool* scp_assembly_required_p) { 3354 const int N_MAX_OPTIONS = 64; 3355 const int OPTION_BUFFER_SIZE = 1024; 3356 char buffer[OPTION_BUFFER_SIZE]; 3357 3358 // The variable will be ignored if it exceeds the length of the buffer. 3359 // Don't check this variable if user has special privileges 3360 // (e.g. unix su command). 3361 if (os::getenv(name, buffer, sizeof(buffer)) && 3362 !os::have_special_privileges()) { 3363 JavaVMOption options[N_MAX_OPTIONS]; // Construct option array 3364 jio_fprintf(defaultStream::error_stream(), 3365 "Picked up %s: %s\n", name, buffer); 3366 char* rd = buffer; // pointer to the input string (rd) 3367 int i; 3368 for (i = 0; i < N_MAX_OPTIONS;) { // repeat for all options in the input string 3369 while (isspace(*rd)) rd++; // skip whitespace 3370 if (*rd == 0) break; // we re done when the input string is read completely 3371 3372 // The output, option string, overwrites the input string. 3373 // Because of quoting, the pointer to the option string (wrt) may lag the pointer to 3374 // input string (rd). 3375 char* wrt = rd; 3376 3377 options[i++].optionString = wrt; // Fill in option 3378 while (*rd != 0 && !isspace(*rd)) { // unquoted strings terminate with a space or NULL 3379 if (*rd == '\'' || *rd == '"') { // handle a quoted string 3380 int quote = *rd; // matching quote to look for 3381 rd++; // don't copy open quote 3382 while (*rd != quote) { // include everything (even spaces) up until quote 3383 if (*rd == 0) { // string termination means unmatched string 3384 jio_fprintf(defaultStream::error_stream(), 3385 "Unmatched quote in %s\n", name); 3386 return JNI_ERR; 3387 } 3388 *wrt++ = *rd++; // copy to option string 3389 } 3390 rd++; // don't copy close quote 3391 } else { 3392 *wrt++ = *rd++; // copy to option string 3393 } 3394 } 3395 // Need to check if we're done before writing a NULL, 3396 // because the write could be to the byte that rd is pointing to. 3397 if (*rd++ == 0) { 3398 *wrt = 0; 3399 break; 3400 } 3401 *wrt = 0; // Zero terminate option 3402 } 3403 // Construct JavaVMInitArgs structure and parse as if it was part of the command line 3404 JavaVMInitArgs vm_args; 3405 vm_args.version = JNI_VERSION_1_2; 3406 vm_args.options = options; 3407 vm_args.nOptions = i; 3408 vm_args.ignoreUnrecognized = IgnoreUnrecognizedVMOptions; 3409 3410 if (PrintVMOptions) { 3411 const char* tail; 3412 for (int i = 0; i < vm_args.nOptions; i++) { 3413 const JavaVMOption *option = vm_args.options + i; 3414 if (match_option(option, "-XX:", &tail)) { 3415 logOption(tail); 3416 } 3417 } 3418 } 3419 3420 return(parse_each_vm_init_arg(&vm_args, scp_p, scp_assembly_required_p, Flag::ENVIRON_VAR)); 3421 } 3422 return JNI_OK; 3423 } 3424 3425 void Arguments::set_shared_spaces_flags() { 3426 if (DumpSharedSpaces) { 3427 if (RequireSharedSpaces) { 3428 warning("cannot dump shared archive while using shared archive"); 3429 } 3430 UseSharedSpaces = false; 3431 #ifdef _LP64 3432 if (!UseCompressedOops || !UseCompressedClassPointers) { 3433 vm_exit_during_initialization( 3434 "Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off.", NULL); 3435 } 3436 } else { 3437 // UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces. 3438 if (!UseCompressedOops || !UseCompressedClassPointers) { 3439 no_shared_spaces(); 3440 } 3441 #endif 3442 } 3443 } 3444 3445 #if !INCLUDE_ALL_GCS 3446 static void force_serial_gc() { 3447 FLAG_SET_DEFAULT(UseSerialGC, true); 3448 FLAG_SET_DEFAULT(CMSIncrementalMode, false); // special CMS suboption 3449 UNSUPPORTED_GC_OPTION(UseG1GC); 3450 UNSUPPORTED_GC_OPTION(UseParallelGC); 3451 UNSUPPORTED_GC_OPTION(UseParallelOldGC); 3452 UNSUPPORTED_GC_OPTION(UseConcMarkSweepGC); 3453 UNSUPPORTED_GC_OPTION(UseParNewGC); 3454 } 3455 #endif // INCLUDE_ALL_GCS 3456 3457 // Sharing support 3458 // Construct the path to the archive 3459 static char* get_shared_archive_path() { 3460 char *shared_archive_path; 3461 if (SharedArchiveFile == NULL) { 3462 char jvm_path[JVM_MAXPATHLEN]; 3463 os::jvm_path(jvm_path, sizeof(jvm_path)); 3464 char *end = strrchr(jvm_path, *os::file_separator()); 3465 if (end != NULL) *end = '\0'; 3466 size_t jvm_path_len = strlen(jvm_path); 3467 size_t file_sep_len = strlen(os::file_separator()); 3468 shared_archive_path = NEW_C_HEAP_ARRAY(char, jvm_path_len + 3469 file_sep_len + 20, mtInternal); 3470 if (shared_archive_path != NULL) { 3471 strncpy(shared_archive_path, jvm_path, jvm_path_len + 1); 3472 strncat(shared_archive_path, os::file_separator(), file_sep_len); 3473 strncat(shared_archive_path, "classes.jsa", 11); 3474 } 3475 } else { 3476 shared_archive_path = NEW_C_HEAP_ARRAY(char, strlen(SharedArchiveFile) + 1, mtInternal); 3477 if (shared_archive_path != NULL) { 3478 strncpy(shared_archive_path, SharedArchiveFile, strlen(SharedArchiveFile) + 1); 3479 } 3480 } 3481 return shared_archive_path; 3482 } 3483 3484 #ifndef PRODUCT 3485 // Determine whether LogVMOutput should be implicitly turned on. 3486 static bool use_vm_log() { 3487 if (LogCompilation || !FLAG_IS_DEFAULT(LogFile) || 3488 PrintCompilation || PrintInlining || PrintDependencies || PrintNativeNMethods || 3489 PrintDebugInfo || PrintRelocations || PrintNMethods || PrintExceptionHandlers || 3490 PrintAssembly || TraceDeoptimization || TraceDependencies || 3491 (VerifyDependencies && FLAG_IS_CMDLINE(VerifyDependencies))) { 3492 return true; 3493 } 3494 3495 #ifdef COMPILER1 3496 if (PrintC1Statistics) { 3497 return true; 3498 } 3499 #endif // COMPILER1 3500 3501 #ifdef COMPILER2 3502 if (PrintOptoAssembly || PrintOptoStatistics) { 3503 return true; 3504 } 3505 #endif // COMPILER2 3506 3507 return false; 3508 } 3509 #endif // PRODUCT 3510 3511 // Parse entry point called from JNI_CreateJavaVM 3512 3513 jint Arguments::parse(const JavaVMInitArgs* args) { 3514 3515 // Remaining part of option string 3516 const char* tail; 3517 3518 // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed. 3519 const char* hotspotrc = ".hotspotrc"; 3520 bool settings_file_specified = false; 3521 bool needs_hotspotrc_warning = false; 3522 3523 const char* flags_file; 3524 int index; 3525 for (index = 0; index < args->nOptions; index++) { 3526 const JavaVMOption *option = args->options + index; 3527 if (match_option(option, "-XX:Flags=", &tail)) { 3528 flags_file = tail; 3529 settings_file_specified = true; 3530 } 3531 if (match_option(option, "-XX:+PrintVMOptions", &tail)) { 3532 PrintVMOptions = true; 3533 } 3534 if (match_option(option, "-XX:-PrintVMOptions", &tail)) { 3535 PrintVMOptions = false; 3536 } 3537 if (match_option(option, "-XX:+IgnoreUnrecognizedVMOptions", &tail)) { 3538 IgnoreUnrecognizedVMOptions = true; 3539 } 3540 if (match_option(option, "-XX:-IgnoreUnrecognizedVMOptions", &tail)) { 3541 IgnoreUnrecognizedVMOptions = false; 3542 } 3543 if (match_option(option, "-XX:+PrintFlagsInitial", &tail)) { 3544 CommandLineFlags::printFlags(tty, false); 3545 vm_exit(0); 3546 } 3547 if (match_option(option, "-XX:NativeMemoryTracking", &tail)) { 3548 #if INCLUDE_NMT 3549 MemTracker::init_tracking_options(tail); 3550 #else 3551 jio_fprintf(defaultStream::error_stream(), 3552 "Native Memory Tracking is not supported in this VM\n"); 3553 return JNI_ERR; 3554 #endif 3555 } 3556 3557 3558 #ifndef PRODUCT 3559 if (match_option(option, "-XX:+PrintFlagsWithComments", &tail)) { 3560 CommandLineFlags::printFlags(tty, true); 3561 vm_exit(0); 3562 } 3563 #endif 3564 } 3565 3566 if (IgnoreUnrecognizedVMOptions) { 3567 // uncast const to modify the flag args->ignoreUnrecognized 3568 *(jboolean*)(&args->ignoreUnrecognized) = true; 3569 } 3570 3571 // Parse specified settings file 3572 if (settings_file_specified) { 3573 if (!process_settings_file(flags_file, true, args->ignoreUnrecognized)) { 3574 return JNI_EINVAL; 3575 } 3576 } else { 3577 #ifdef ASSERT 3578 // Parse default .hotspotrc settings file 3579 if (!process_settings_file(".hotspotrc", false, args->ignoreUnrecognized)) { 3580 return JNI_EINVAL; 3581 } 3582 #else 3583 struct stat buf; 3584 if (os::stat(hotspotrc, &buf) == 0) { 3585 needs_hotspotrc_warning = true; 3586 } 3587 #endif 3588 } 3589 3590 if (PrintVMOptions) { 3591 for (index = 0; index < args->nOptions; index++) { 3592 const JavaVMOption *option = args->options + index; 3593 if (match_option(option, "-XX:", &tail)) { 3594 logOption(tail); 3595 } 3596 } 3597 } 3598 3599 // Parse JavaVMInitArgs structure passed in, as well as JAVA_TOOL_OPTIONS and _JAVA_OPTIONS 3600 jint result = parse_vm_init_args(args); 3601 if (result != JNI_OK) { 3602 return result; 3603 } 3604 3605 // Call get_shared_archive_path() here, after possible SharedArchiveFile option got parsed. 3606 SharedArchivePath = get_shared_archive_path(); 3607 if (SharedArchivePath == NULL) { 3608 return JNI_ENOMEM; 3609 } 3610 3611 // Delay warning until here so that we've had a chance to process 3612 // the -XX:-PrintWarnings flag 3613 if (needs_hotspotrc_warning) { 3614 warning("%s file is present but has been ignored. " 3615 "Run with -XX:Flags=%s to load the file.", 3616 hotspotrc, hotspotrc); 3617 } 3618 3619 #ifdef _ALLBSD_SOURCE // UseLargePages is not yet supported on BSD. 3620 UNSUPPORTED_OPTION(UseLargePages, "-XX:+UseLargePages"); 3621 #endif 3622 3623 #if INCLUDE_ALL_GCS 3624 #if (defined JAVASE_EMBEDDED || defined ARM) 3625 UNSUPPORTED_OPTION(UseG1GC, "G1 GC"); 3626 #endif 3627 #endif 3628 3629 #ifndef PRODUCT 3630 if (TraceBytecodesAt != 0) { 3631 TraceBytecodes = true; 3632 } 3633 if (CountCompiledCalls) { 3634 if (UseCounterDecay) { 3635 warning("UseCounterDecay disabled because CountCalls is set"); 3636 UseCounterDecay = false; 3637 } 3638 } 3639 #endif // PRODUCT 3640 3641 // JSR 292 is not supported before 1.7 3642 if (!JDK_Version::is_gte_jdk17x_version()) { 3643 if (EnableInvokeDynamic) { 3644 if (!FLAG_IS_DEFAULT(EnableInvokeDynamic)) { 3645 warning("JSR 292 is not supported before 1.7. Disabling support."); 3646 } 3647 EnableInvokeDynamic = false; 3648 } 3649 } 3650 3651 if (EnableInvokeDynamic && ScavengeRootsInCode == 0) { 3652 if (!FLAG_IS_DEFAULT(ScavengeRootsInCode)) { 3653 warning("forcing ScavengeRootsInCode non-zero because EnableInvokeDynamic is true"); 3654 } 3655 ScavengeRootsInCode = 1; 3656 } 3657 3658 if (PrintGCDetails) { 3659 // Turn on -verbose:gc options as well 3660 PrintGC = true; 3661 } 3662 3663 if (!JDK_Version::is_gte_jdk18x_version()) { 3664 // To avoid changing the log format for 7 updates this flag is only 3665 // true by default in JDK8 and above. 3666 if (FLAG_IS_DEFAULT(PrintGCCause)) { 3667 FLAG_SET_DEFAULT(PrintGCCause, false); 3668 } 3669 } 3670 3671 // Set object alignment values. 3672 set_object_alignment(); 3673 3674 #if !INCLUDE_ALL_GCS 3675 force_serial_gc(); 3676 #endif // INCLUDE_ALL_GCS 3677 #if !INCLUDE_CDS 3678 if (DumpSharedSpaces || RequireSharedSpaces) { 3679 jio_fprintf(defaultStream::error_stream(), 3680 "Shared spaces are not supported in this VM\n"); 3681 return JNI_ERR; 3682 } 3683 if ((UseSharedSpaces && FLAG_IS_CMDLINE(UseSharedSpaces)) || PrintSharedSpaces) { 3684 warning("Shared spaces are not supported in this VM"); 3685 FLAG_SET_DEFAULT(UseSharedSpaces, false); 3686 FLAG_SET_DEFAULT(PrintSharedSpaces, false); 3687 } 3688 no_shared_spaces(); 3689 #endif // INCLUDE_CDS 3690 3691 return JNI_OK; 3692 } 3693 3694 jint Arguments::apply_ergo() { 3695 3696 // Set flags based on ergonomics. 3697 set_ergonomics_flags(); 3698 3699 set_shared_spaces_flags(); 3700 3701 // Check the GC selections again. 3702 if (!check_gc_consistency()) { 3703 return JNI_EINVAL; 3704 } 3705 3706 if (TieredCompilation) { 3707 set_tiered_flags(); 3708 } else { 3709 // Check if the policy is valid. Policies 0 and 1 are valid for non-tiered setup. 3710 if (CompilationPolicyChoice >= 2) { 3711 vm_exit_during_initialization( 3712 "Incompatible compilation policy selected", NULL); 3713 } 3714 } 3715 // Set NmethodSweepFraction after the size of the code cache is adapted (in case of tiered) 3716 if (FLAG_IS_DEFAULT(NmethodSweepFraction)) { 3717 FLAG_SET_DEFAULT(NmethodSweepFraction, 1 + ReservedCodeCacheSize / (16 * M)); 3718 } 3719 3720 3721 // Set heap size based on available physical memory 3722 set_heap_size(); 3723 3724 #if INCLUDE_ALL_GCS 3725 // Set per-collector flags 3726 if (UseParallelGC || UseParallelOldGC) { 3727 set_parallel_gc_flags(); 3728 } else if (UseConcMarkSweepGC) { // Should be done before ParNew check below 3729 set_cms_and_parnew_gc_flags(); 3730 } else if (UseParNewGC) { // Skipped if CMS is set above 3731 set_parnew_gc_flags(); 3732 } else if (UseG1GC) { 3733 set_g1_gc_flags(); 3734 } 3735 check_deprecated_gcs(); 3736 check_deprecated_gc_flags(); 3737 if (AssumeMP && !UseSerialGC) { 3738 if (FLAG_IS_DEFAULT(ParallelGCThreads) && ParallelGCThreads == 1) { 3739 warning("If the number of processors is expected to increase from one, then" 3740 " you should configure the number of parallel GC threads appropriately" 3741 " using -XX:ParallelGCThreads=N"); 3742 } 3743 } 3744 if (MinHeapFreeRatio == 100) { 3745 // Keeping the heap 100% free is hard ;-) so limit it to 99%. 3746 FLAG_SET_ERGO(uintx, MinHeapFreeRatio, 99); 3747 } 3748 #else // INCLUDE_ALL_GCS 3749 assert(verify_serial_gc_flags(), "SerialGC unset"); 3750 #endif // INCLUDE_ALL_GCS 3751 3752 // Initialize Metaspace flags and alignments 3753 Metaspace::ergo_initialize(); 3754 3755 // Set bytecode rewriting flags 3756 set_bytecode_flags(); 3757 3758 // Set flags if Aggressive optimization flags (-XX:+AggressiveOpts) enabled 3759 set_aggressive_opts_flags(); 3760 3761 // Turn off biased locking for locking debug mode flags, 3762 // which are subtly different from each other but neither works with 3763 // biased locking 3764 if (UseHeavyMonitors 3765 #ifdef COMPILER1 3766 || !UseFastLocking 3767 #endif // COMPILER1 3768 ) { 3769 if (!FLAG_IS_DEFAULT(UseBiasedLocking) && UseBiasedLocking) { 3770 // flag set to true on command line; warn the user that they 3771 // can't enable biased locking here 3772 warning("Biased Locking is not supported with locking debug flags" 3773 "; ignoring UseBiasedLocking flag." ); 3774 } 3775 UseBiasedLocking = false; 3776 } 3777 3778 #ifdef ZERO 3779 // Clear flags not supported on zero. 3780 FLAG_SET_DEFAULT(ProfileInterpreter, false); 3781 FLAG_SET_DEFAULT(UseBiasedLocking, false); 3782 LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedOops, false)); 3783 LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedClassPointers, false)); 3784 #endif // CC_INTERP 3785 3786 #ifdef COMPILER2 3787 if (!UseBiasedLocking || EmitSync != 0) { 3788 UseOptoBiasInlining = false; 3789 } 3790 if (!EliminateLocks) { 3791 EliminateNestedLocks = false; 3792 } 3793 if (!Inline) { 3794 IncrementalInline = false; 3795 } 3796 #ifndef PRODUCT 3797 if (!IncrementalInline) { 3798 AlwaysIncrementalInline = false; 3799 } 3800 #endif 3801 if (IncrementalInline && FLAG_IS_DEFAULT(MaxNodeLimit)) { 3802 // incremental inlining: bump MaxNodeLimit 3803 FLAG_SET_DEFAULT(MaxNodeLimit, (intx)75000); 3804 } 3805 if (!UseTypeSpeculation && FLAG_IS_DEFAULT(TypeProfileLevel)) { 3806 // nothing to use the profiling, turn if off 3807 FLAG_SET_DEFAULT(TypeProfileLevel, 0); 3808 } 3809 if (UseTypeSpeculation && FLAG_IS_DEFAULT(ReplaceInParentMaps)) { 3810 // Doing the replace in parent maps helps speculation 3811 FLAG_SET_DEFAULT(ReplaceInParentMaps, true); 3812 } 3813 #endif 3814 3815 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) { 3816 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output"); 3817 DebugNonSafepoints = true; 3818 } 3819 3820 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) { 3821 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used"); 3822 } 3823 3824 #ifndef PRODUCT 3825 if (CompileTheWorld) { 3826 // Force NmethodSweeper to sweep whole CodeCache each time. 3827 if (FLAG_IS_DEFAULT(NmethodSweepFraction)) { 3828 NmethodSweepFraction = 1; 3829 } 3830 } 3831 3832 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) { 3833 if (use_vm_log()) { 3834 LogVMOutput = true; 3835 } 3836 } 3837 #endif // PRODUCT 3838 3839 if (PrintCommandLineFlags) { 3840 CommandLineFlags::printSetFlags(tty); 3841 } 3842 3843 // Apply CPU specific policy for the BiasedLocking 3844 if (UseBiasedLocking) { 3845 if (!VM_Version::use_biased_locking() && 3846 !(FLAG_IS_CMDLINE(UseBiasedLocking))) { 3847 UseBiasedLocking = false; 3848 } 3849 } 3850 3851 return JNI_OK; 3852 } 3853 3854 jint Arguments::adjust_after_os() { 3855 if (UseNUMA) { 3856 if (UseParallelGC || UseParallelOldGC) { 3857 if (FLAG_IS_DEFAULT(MinHeapDeltaBytes)) { 3858 FLAG_SET_DEFAULT(MinHeapDeltaBytes, 64*M); 3859 } 3860 } 3861 // UseNUMAInterleaving is set to ON for all collectors and 3862 // platforms when UseNUMA is set to ON. NUMA-aware collectors 3863 // such as the parallel collector for Linux and Solaris will 3864 // interleave old gen and survivor spaces on top of NUMA 3865 // allocation policy for the eden space. 3866 // Non NUMA-aware collectors such as CMS, G1 and Serial-GC on 3867 // all platforms and ParallelGC on Windows will interleave all 3868 // of the heap spaces across NUMA nodes. 3869 if (FLAG_IS_DEFAULT(UseNUMAInterleaving)) { 3870 FLAG_SET_ERGO(bool, UseNUMAInterleaving, true); 3871 } 3872 } 3873 return JNI_OK; 3874 } 3875 3876 int Arguments::PropertyList_count(SystemProperty* pl) { 3877 int count = 0; 3878 while(pl != NULL) { 3879 count++; 3880 pl = pl->next(); 3881 } 3882 return count; 3883 } 3884 3885 const char* Arguments::PropertyList_get_value(SystemProperty *pl, const char* key) { 3886 assert(key != NULL, "just checking"); 3887 SystemProperty* prop; 3888 for (prop = pl; prop != NULL; prop = prop->next()) { 3889 if (strcmp(key, prop->key()) == 0) return prop->value(); 3890 } 3891 return NULL; 3892 } 3893 3894 const char* Arguments::PropertyList_get_key_at(SystemProperty *pl, int index) { 3895 int count = 0; 3896 const char* ret_val = NULL; 3897 3898 while(pl != NULL) { 3899 if(count >= index) { 3900 ret_val = pl->key(); 3901 break; 3902 } 3903 count++; 3904 pl = pl->next(); 3905 } 3906 3907 return ret_val; 3908 } 3909 3910 char* Arguments::PropertyList_get_value_at(SystemProperty* pl, int index) { 3911 int count = 0; 3912 char* ret_val = NULL; 3913 3914 while(pl != NULL) { 3915 if(count >= index) { 3916 ret_val = pl->value(); 3917 break; 3918 } 3919 count++; 3920 pl = pl->next(); 3921 } 3922 3923 return ret_val; 3924 } 3925 3926 void Arguments::PropertyList_add(SystemProperty** plist, SystemProperty *new_p) { 3927 SystemProperty* p = *plist; 3928 if (p == NULL) { 3929 *plist = new_p; 3930 } else { 3931 while (p->next() != NULL) { 3932 p = p->next(); 3933 } 3934 p->set_next(new_p); 3935 } 3936 } 3937 3938 void Arguments::PropertyList_add(SystemProperty** plist, const char* k, char* v) { 3939 if (plist == NULL) 3940 return; 3941 3942 SystemProperty* new_p = new SystemProperty(k, v, true); 3943 PropertyList_add(plist, new_p); 3944 } 3945 3946 // This add maintains unique property key in the list. 3947 void Arguments::PropertyList_unique_add(SystemProperty** plist, const char* k, char* v, jboolean append) { 3948 if (plist == NULL) 3949 return; 3950 3951 // If property key exist then update with new value. 3952 SystemProperty* prop; 3953 for (prop = *plist; prop != NULL; prop = prop->next()) { 3954 if (strcmp(k, prop->key()) == 0) { 3955 if (append) { 3956 prop->append_value(v); 3957 } else { 3958 prop->set_value(v); 3959 } 3960 return; 3961 } 3962 } 3963 3964 PropertyList_add(plist, k, v); 3965 } 3966 3967 // Copies src into buf, replacing "%%" with "%" and "%p" with pid 3968 // Returns true if all of the source pointed by src has been copied over to 3969 // the destination buffer pointed by buf. Otherwise, returns false. 3970 // Notes: 3971 // 1. If the length (buflen) of the destination buffer excluding the 3972 // NULL terminator character is not long enough for holding the expanded 3973 // pid characters, it also returns false instead of returning the partially 3974 // expanded one. 3975 // 2. The passed in "buflen" should be large enough to hold the null terminator. 3976 bool Arguments::copy_expand_pid(const char* src, size_t srclen, 3977 char* buf, size_t buflen) { 3978 const char* p = src; 3979 char* b = buf; 3980 const char* src_end = &src[srclen]; 3981 char* buf_end = &buf[buflen - 1]; 3982 3983 while (p < src_end && b < buf_end) { 3984 if (*p == '%') { 3985 switch (*(++p)) { 3986 case '%': // "%%" ==> "%" 3987 *b++ = *p++; 3988 break; 3989 case 'p': { // "%p" ==> current process id 3990 // buf_end points to the character before the last character so 3991 // that we could write '\0' to the end of the buffer. 3992 size_t buf_sz = buf_end - b + 1; 3993 int ret = jio_snprintf(b, buf_sz, "%d", os::current_process_id()); 3994 3995 // if jio_snprintf fails or the buffer is not long enough to hold 3996 // the expanded pid, returns false. 3997 if (ret < 0 || ret >= (int)buf_sz) { 3998 return false; 3999 } else { 4000 b += ret; 4001 assert(*b == '\0', "fail in copy_expand_pid"); 4002 if (p == src_end && b == buf_end + 1) { 4003 // reach the end of the buffer. 4004 return true; 4005 } 4006 } 4007 p++; 4008 break; 4009 } 4010 default : 4011 *b++ = '%'; 4012 } 4013 } else { 4014 *b++ = *p++; 4015 } 4016 } 4017 *b = '\0'; 4018 return (p == src_end); // return false if not all of the source was copied 4019 }