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