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