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