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