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