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