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