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