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