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