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