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