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