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