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 (ReservedCodeCacheSize < InitialCodeCacheSize) { 2152 jio_fprintf(defaultStream::error_stream(), 2153 "Invalid ReservedCodeCacheSize: %dK. Must be at least InitialCodeCacheSize=%dK.\n", 2154 ReservedCodeCacheSize/K, InitialCodeCacheSize/K); 2155 status = false; 2156 } else if (ReservedCodeCacheSize < min_code_cache_size) { 2157 jio_fprintf(defaultStream::error_stream(), 2158 "Invalid ReservedCodeCacheSize=%dK. Must be at least %uK.\n", ReservedCodeCacheSize/K, 2159 min_code_cache_size/K); 2160 status = false; 2161 } else if (ReservedCodeCacheSize > CODE_CACHE_SIZE_LIMIT) { 2162 // Code cache size larger than CODE_CACHE_SIZE_LIMIT is not supported. 2163 jio_fprintf(defaultStream::error_stream(), 2164 "Invalid ReservedCodeCacheSize=%dM. Must be at most %uM.\n", ReservedCodeCacheSize/M, 2165 CODE_CACHE_SIZE_LIMIT/M); 2166 status = false; 2167 } else if (NonNMethodCodeHeapSize < min_code_cache_size) { 2168 jio_fprintf(defaultStream::error_stream(), 2169 "Invalid NonNMethodCodeHeapSize=%dK. Must be at least %uK.\n", NonNMethodCodeHeapSize/K, 2170 min_code_cache_size/K); 2171 status = false; 2172 } 2173 2174 #ifdef _LP64 2175 if (!FLAG_IS_DEFAULT(CICompilerCount) && !FLAG_IS_DEFAULT(CICompilerCountPerCPU) && CICompilerCountPerCPU) { 2176 warning("The VM option CICompilerCountPerCPU overrides CICompilerCount."); 2177 } 2178 #endif 2179 2180 #ifndef SUPPORT_RESERVED_STACK_AREA 2181 if (StackReservedPages != 0) { 2182 FLAG_SET_CMDLINE(intx, StackReservedPages, 0); 2183 warning("Reserved Stack Area not supported on this platform"); 2184 } 2185 #endif 2186 2187 if (BackgroundCompilation && (CompileTheWorld || ReplayCompiles)) { 2188 if (!FLAG_IS_DEFAULT(BackgroundCompilation)) { 2189 warning("BackgroundCompilation disabled due to CompileTheWorld or ReplayCompiles options."); 2190 } 2191 FLAG_SET_CMDLINE(bool, BackgroundCompilation, false); 2192 } 2193 if (UseCompiler && is_interpreter_only()) { 2194 if (!FLAG_IS_DEFAULT(UseCompiler)) { 2195 warning("UseCompiler disabled due to -Xint."); 2196 } 2197 FLAG_SET_CMDLINE(bool, UseCompiler, false); 2198 } 2199 #ifdef COMPILER2 2200 if (PostLoopMultiversioning && !RangeCheckElimination) { 2201 if (!FLAG_IS_DEFAULT(PostLoopMultiversioning)) { 2202 warning("PostLoopMultiversioning disabled because RangeCheckElimination is disabled."); 2203 } 2204 FLAG_SET_CMDLINE(bool, PostLoopMultiversioning, false); 2205 } 2206 #endif 2207 return status; 2208 } 2209 2210 bool Arguments::is_bad_option(const JavaVMOption* option, jboolean ignore, 2211 const char* option_type) { 2212 if (ignore) return false; 2213 2214 const char* spacer = " "; 2215 if (option_type == NULL) { 2216 option_type = ++spacer; // Set both to the empty string. 2217 } 2218 2219 if (os::obsolete_option(option)) { 2220 jio_fprintf(defaultStream::error_stream(), 2221 "Obsolete %s%soption: %s\n", option_type, spacer, 2222 option->optionString); 2223 return false; 2224 } else { 2225 jio_fprintf(defaultStream::error_stream(), 2226 "Unrecognized %s%soption: %s\n", option_type, spacer, 2227 option->optionString); 2228 return true; 2229 } 2230 } 2231 2232 static const char* user_assertion_options[] = { 2233 "-da", "-ea", "-disableassertions", "-enableassertions", 0 2234 }; 2235 2236 static const char* system_assertion_options[] = { 2237 "-dsa", "-esa", "-disablesystemassertions", "-enablesystemassertions", 0 2238 }; 2239 2240 bool Arguments::parse_uintx(const char* value, 2241 uintx* uintx_arg, 2242 uintx min_size) { 2243 2244 // Check the sign first since atojulong() parses only unsigned values. 2245 bool value_is_positive = !(*value == '-'); 2246 2247 if (value_is_positive) { 2248 julong n; 2249 bool good_return = atojulong(value, &n); 2250 if (good_return) { 2251 bool above_minimum = n >= min_size; 2252 bool value_is_too_large = n > max_uintx; 2253 2254 if (above_minimum && !value_is_too_large) { 2255 *uintx_arg = n; 2256 return true; 2257 } 2258 } 2259 } 2260 return false; 2261 } 2262 2263 unsigned int addreads_count = 0; 2264 unsigned int addexports_count = 0; 2265 unsigned int addopens_count = 0; 2266 unsigned int addmods_count = 0; 2267 unsigned int patch_mod_count = 0; 2268 2269 bool Arguments::create_property(const char* prop_name, const char* prop_value, PropertyInternal internal) { 2270 size_t prop_len = strlen(prop_name) + strlen(prop_value) + 2; 2271 char* property = AllocateHeap(prop_len, mtArguments); 2272 int ret = jio_snprintf(property, prop_len, "%s=%s", prop_name, prop_value); 2273 if (ret < 0 || ret >= (int)prop_len) { 2274 FreeHeap(property); 2275 return false; 2276 } 2277 bool added = add_property(property, UnwriteableProperty, internal); 2278 FreeHeap(property); 2279 return added; 2280 } 2281 2282 bool Arguments::create_numbered_property(const char* prop_base_name, const char* prop_value, unsigned int count) { 2283 const unsigned int props_count_limit = 1000; 2284 const int max_digits = 3; 2285 const int extra_symbols_count = 3; // includes '.', '=', '\0' 2286 2287 // Make sure count is < props_count_limit. Otherwise, memory allocation will be too small. 2288 if (count < props_count_limit) { 2289 size_t prop_len = strlen(prop_base_name) + strlen(prop_value) + max_digits + extra_symbols_count; 2290 char* property = AllocateHeap(prop_len, mtArguments); 2291 int ret = jio_snprintf(property, prop_len, "%s.%d=%s", prop_base_name, count, prop_value); 2292 if (ret < 0 || ret >= (int)prop_len) { 2293 FreeHeap(property); 2294 jio_fprintf(defaultStream::error_stream(), "Failed to create property %s.%d=%s\n", prop_base_name, count, prop_value); 2295 return false; 2296 } 2297 bool added = add_property(property, UnwriteableProperty, InternalProperty); 2298 FreeHeap(property); 2299 return added; 2300 } 2301 2302 jio_fprintf(defaultStream::error_stream(), "Property count limit exceeded: %s, limit=%d\n", prop_base_name, props_count_limit); 2303 return false; 2304 } 2305 2306 Arguments::ArgsRange Arguments::parse_memory_size(const char* s, 2307 julong* long_arg, 2308 julong min_size, 2309 julong max_size) { 2310 if (!atojulong(s, long_arg)) return arg_unreadable; 2311 return check_memory_size(*long_arg, min_size, max_size); 2312 } 2313 2314 // Parse JavaVMInitArgs structure 2315 2316 jint Arguments::parse_vm_init_args(const JavaVMInitArgs *java_tool_options_args, 2317 const JavaVMInitArgs *java_options_args, 2318 const JavaVMInitArgs *cmd_line_args) { 2319 bool patch_mod_javabase = false; 2320 2321 // Save default settings for some mode flags 2322 Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods; 2323 Arguments::_UseOnStackReplacement = UseOnStackReplacement; 2324 Arguments::_ClipInlining = ClipInlining; 2325 Arguments::_BackgroundCompilation = BackgroundCompilation; 2326 if (TieredCompilation) { 2327 Arguments::_Tier3InvokeNotifyFreqLog = Tier3InvokeNotifyFreqLog; 2328 Arguments::_Tier4InvocationThreshold = Tier4InvocationThreshold; 2329 } 2330 2331 // Setup flags for mixed which is the default 2332 set_mode_flags(_mixed); 2333 2334 // Parse args structure generated from JAVA_TOOL_OPTIONS environment 2335 // variable (if present). 2336 jint result = parse_each_vm_init_arg(java_tool_options_args, &patch_mod_javabase, Flag::ENVIRON_VAR); 2337 if (result != JNI_OK) { 2338 return result; 2339 } 2340 2341 // Parse args structure generated from the command line flags. 2342 result = parse_each_vm_init_arg(cmd_line_args, &patch_mod_javabase, Flag::COMMAND_LINE); 2343 if (result != JNI_OK) { 2344 return result; 2345 } 2346 2347 // Parse args structure generated from the _JAVA_OPTIONS environment 2348 // variable (if present) (mimics classic VM) 2349 result = parse_each_vm_init_arg(java_options_args, &patch_mod_javabase, Flag::ENVIRON_VAR); 2350 if (result != JNI_OK) { 2351 return result; 2352 } 2353 2354 // We need to ensure processor and memory resources have been properly 2355 // configured - which may rely on arguments we just processed - before 2356 // doing the final argument processing. Any argument processing that 2357 // needs to know about processor and memory resources must occur after 2358 // this point. 2359 2360 os::init_container_support(); 2361 2362 // Do final processing now that all arguments have been parsed 2363 result = finalize_vm_init_args(patch_mod_javabase); 2364 if (result != JNI_OK) { 2365 return result; 2366 } 2367 2368 return JNI_OK; 2369 } 2370 2371 // Checks if name in command-line argument -agent{lib,path}:name[=options] 2372 // represents a valid JDWP agent. is_path==true denotes that we 2373 // are dealing with -agentpath (case where name is a path), otherwise with 2374 // -agentlib 2375 bool valid_jdwp_agent(char *name, bool is_path) { 2376 char *_name; 2377 const char *_jdwp = "jdwp"; 2378 size_t _len_jdwp, _len_prefix; 2379 2380 if (is_path) { 2381 if ((_name = strrchr(name, (int) *os::file_separator())) == NULL) { 2382 return false; 2383 } 2384 2385 _name++; // skip past last path separator 2386 _len_prefix = strlen(JNI_LIB_PREFIX); 2387 2388 if (strncmp(_name, JNI_LIB_PREFIX, _len_prefix) != 0) { 2389 return false; 2390 } 2391 2392 _name += _len_prefix; 2393 _len_jdwp = strlen(_jdwp); 2394 2395 if (strncmp(_name, _jdwp, _len_jdwp) == 0) { 2396 _name += _len_jdwp; 2397 } 2398 else { 2399 return false; 2400 } 2401 2402 if (strcmp(_name, JNI_LIB_SUFFIX) != 0) { 2403 return false; 2404 } 2405 2406 return true; 2407 } 2408 2409 if (strcmp(name, _jdwp) == 0) { 2410 return true; 2411 } 2412 2413 return false; 2414 } 2415 2416 int Arguments::process_patch_mod_option(const char* patch_mod_tail, bool* patch_mod_javabase) { 2417 // --patch-module=<module>=<file>(<pathsep><file>)* 2418 assert(patch_mod_tail != NULL, "Unexpected NULL patch-module value"); 2419 // Find the equal sign between the module name and the path specification 2420 const char* module_equal = strchr(patch_mod_tail, '='); 2421 if (module_equal == NULL) { 2422 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n"); 2423 return JNI_ERR; 2424 } else { 2425 // Pick out the module name 2426 size_t module_len = module_equal - patch_mod_tail; 2427 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments); 2428 if (module_name != NULL) { 2429 memcpy(module_name, patch_mod_tail, module_len); 2430 *(module_name + module_len) = '\0'; 2431 // The path piece begins one past the module_equal sign 2432 add_patch_mod_prefix(module_name, module_equal + 1, patch_mod_javabase); 2433 FREE_C_HEAP_ARRAY(char, module_name); 2434 if (!create_numbered_property("jdk.module.patch", patch_mod_tail, patch_mod_count++)) { 2435 return JNI_ENOMEM; 2436 } 2437 } else { 2438 return JNI_ENOMEM; 2439 } 2440 } 2441 return JNI_OK; 2442 } 2443 2444 // Parse -Xss memory string parameter and convert to ThreadStackSize in K. 2445 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) { 2446 // The min and max sizes match the values in globals.hpp, but scaled 2447 // with K. The values have been chosen so that alignment with page 2448 // size doesn't change the max value, which makes the conversions 2449 // back and forth between Xss value and ThreadStackSize value easier. 2450 // The values have also been chosen to fit inside a 32-bit signed type. 2451 const julong min_ThreadStackSize = 0; 2452 const julong max_ThreadStackSize = 1 * M; 2453 2454 const julong min_size = min_ThreadStackSize * K; 2455 const julong max_size = max_ThreadStackSize * K; 2456 2457 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption"); 2458 2459 julong size = 0; 2460 ArgsRange errcode = parse_memory_size(tail, &size, min_size, max_size); 2461 if (errcode != arg_in_range) { 2462 bool silent = (option == NULL); // Allow testing to silence error messages 2463 if (!silent) { 2464 jio_fprintf(defaultStream::error_stream(), 2465 "Invalid thread stack size: %s\n", option->optionString); 2466 describe_range_error(errcode); 2467 } 2468 return JNI_EINVAL; 2469 } 2470 2471 // Internally track ThreadStackSize in units of 1024 bytes. 2472 const julong size_aligned = align_up(size, K); 2473 assert(size <= size_aligned, 2474 "Overflow: " JULONG_FORMAT " " JULONG_FORMAT, 2475 size, size_aligned); 2476 2477 const julong size_in_K = size_aligned / K; 2478 assert(size_in_K < (julong)max_intx, 2479 "size_in_K doesn't fit in the type of ThreadStackSize: " JULONG_FORMAT, 2480 size_in_K); 2481 2482 // Check that code expanding ThreadStackSize to a page aligned number of bytes won't overflow. 2483 const julong max_expanded = align_up(size_in_K * K, os::vm_page_size()); 2484 assert(max_expanded < max_uintx && max_expanded >= size_in_K, 2485 "Expansion overflowed: " JULONG_FORMAT " " JULONG_FORMAT, 2486 max_expanded, size_in_K); 2487 2488 *out_ThreadStackSize = (intx)size_in_K; 2489 2490 return JNI_OK; 2491 } 2492 2493 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_mod_javabase, Flag::Flags origin) { 2494 // For match_option to return remaining or value part of option string 2495 const char* tail; 2496 2497 // iterate over arguments 2498 for (int index = 0; index < args->nOptions; index++) { 2499 bool is_absolute_path = false; // for -agentpath vs -agentlib 2500 2501 const JavaVMOption* option = args->options + index; 2502 2503 if (!match_option(option, "-Djava.class.path", &tail) && 2504 !match_option(option, "-Dsun.java.command", &tail) && 2505 !match_option(option, "-Dsun.java.launcher", &tail)) { 2506 2507 // add all jvm options to the jvm_args string. This string 2508 // is used later to set the java.vm.args PerfData string constant. 2509 // the -Djava.class.path and the -Dsun.java.command options are 2510 // omitted from jvm_args string as each have their own PerfData 2511 // string constant object. 2512 build_jvm_args(option->optionString); 2513 } 2514 2515 // -verbose:[class/module/gc/jni] 2516 if (match_option(option, "-verbose", &tail)) { 2517 if (!strcmp(tail, ":class") || !strcmp(tail, "")) { 2518 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, load)); 2519 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, unload)); 2520 } else if (!strcmp(tail, ":module")) { 2521 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(module, load)); 2522 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(module, unload)); 2523 } else if (!strcmp(tail, ":gc")) { 2524 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(gc)); 2525 } else if (!strcmp(tail, ":jni")) { 2526 if (FLAG_SET_CMDLINE(bool, PrintJNIResolving, true) != Flag::SUCCESS) { 2527 return JNI_EINVAL; 2528 } 2529 } 2530 // -da / -ea / -disableassertions / -enableassertions 2531 // These accept an optional class/package name separated by a colon, e.g., 2532 // -da:java.lang.Thread. 2533 } else if (match_option(option, user_assertion_options, &tail, true)) { 2534 bool enable = option->optionString[1] == 'e'; // char after '-' is 'e' 2535 if (*tail == '\0') { 2536 JavaAssertions::setUserClassDefault(enable); 2537 } else { 2538 assert(*tail == ':', "bogus match by match_option()"); 2539 JavaAssertions::addOption(tail + 1, enable); 2540 } 2541 // -dsa / -esa / -disablesystemassertions / -enablesystemassertions 2542 } else if (match_option(option, system_assertion_options, &tail, false)) { 2543 bool enable = option->optionString[1] == 'e'; // char after '-' is 'e' 2544 JavaAssertions::setSystemClassDefault(enable); 2545 // -bootclasspath: 2546 } else if (match_option(option, "-Xbootclasspath:", &tail)) { 2547 jio_fprintf(defaultStream::output_stream(), 2548 "-Xbootclasspath is no longer a supported option.\n"); 2549 return JNI_EINVAL; 2550 // -bootclasspath/a: 2551 } else if (match_option(option, "-Xbootclasspath/a:", &tail)) { 2552 Arguments::append_sysclasspath(tail); 2553 // -bootclasspath/p: 2554 } else if (match_option(option, "-Xbootclasspath/p:", &tail)) { 2555 jio_fprintf(defaultStream::output_stream(), 2556 "-Xbootclasspath/p is no longer a supported option.\n"); 2557 return JNI_EINVAL; 2558 // -Xrun 2559 } else if (match_option(option, "-Xrun", &tail)) { 2560 if (tail != NULL) { 2561 const char* pos = strchr(tail, ':'); 2562 size_t len = (pos == NULL) ? strlen(tail) : pos - tail; 2563 char* name = NEW_C_HEAP_ARRAY(char, len + 1, mtArguments); 2564 jio_snprintf(name, len + 1, "%s", tail); 2565 2566 char *options = NULL; 2567 if(pos != NULL) { 2568 size_t len2 = strlen(pos+1) + 1; // options start after ':'. Final zero must be copied. 2569 options = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len2, mtArguments), pos+1, len2); 2570 } 2571 #if !INCLUDE_JVMTI 2572 if (strcmp(name, "jdwp") == 0) { 2573 jio_fprintf(defaultStream::error_stream(), 2574 "Debugging agents are not supported in this VM\n"); 2575 return JNI_ERR; 2576 } 2577 #endif // !INCLUDE_JVMTI 2578 add_init_library(name, options); 2579 } 2580 } else if (match_option(option, "--add-reads=", &tail)) { 2581 if (!create_numbered_property("jdk.module.addreads", tail, addreads_count++)) { 2582 return JNI_ENOMEM; 2583 } 2584 } else if (match_option(option, "--add-exports=", &tail)) { 2585 if (!create_numbered_property("jdk.module.addexports", tail, addexports_count++)) { 2586 return JNI_ENOMEM; 2587 } 2588 } else if (match_option(option, "--add-opens=", &tail)) { 2589 if (!create_numbered_property("jdk.module.addopens", tail, addopens_count++)) { 2590 return JNI_ENOMEM; 2591 } 2592 } else if (match_option(option, "--add-modules=", &tail)) { 2593 if (!create_numbered_property("jdk.module.addmods", tail, addmods_count++)) { 2594 return JNI_ENOMEM; 2595 } 2596 } else if (match_option(option, "--limit-modules=", &tail)) { 2597 if (!create_property("jdk.module.limitmods", tail, InternalProperty)) { 2598 return JNI_ENOMEM; 2599 } 2600 } else if (match_option(option, "--module-path=", &tail)) { 2601 if (!create_property("jdk.module.path", tail, ExternalProperty)) { 2602 return JNI_ENOMEM; 2603 } 2604 } else if (match_option(option, "--upgrade-module-path=", &tail)) { 2605 if (!create_property("jdk.module.upgrade.path", tail, ExternalProperty)) { 2606 return JNI_ENOMEM; 2607 } 2608 } else if (match_option(option, "--patch-module=", &tail)) { 2609 // --patch-module=<module>=<file>(<pathsep><file>)* 2610 int res = process_patch_mod_option(tail, patch_mod_javabase); 2611 if (res != JNI_OK) { 2612 return res; 2613 } 2614 } else if (match_option(option, "--illegal-access=", &tail)) { 2615 if (!create_property("jdk.module.illegalAccess", tail, ExternalProperty)) { 2616 return JNI_ENOMEM; 2617 } 2618 // -agentlib and -agentpath 2619 } else if (match_option(option, "-agentlib:", &tail) || 2620 (is_absolute_path = match_option(option, "-agentpath:", &tail))) { 2621 if(tail != NULL) { 2622 const char* pos = strchr(tail, '='); 2623 size_t len = (pos == NULL) ? strlen(tail) : pos - tail; 2624 char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1, mtArguments), tail, len); 2625 name[len] = '\0'; 2626 2627 char *options = NULL; 2628 if(pos != NULL) { 2629 options = os::strdup_check_oom(pos + 1, mtArguments); 2630 } 2631 #if !INCLUDE_JVMTI 2632 if (valid_jdwp_agent(name, is_absolute_path)) { 2633 jio_fprintf(defaultStream::error_stream(), 2634 "Debugging agents are not supported in this VM\n"); 2635 return JNI_ERR; 2636 } 2637 #endif // !INCLUDE_JVMTI 2638 add_init_agent(name, options, is_absolute_path); 2639 } 2640 // -javaagent 2641 } else if (match_option(option, "-javaagent:", &tail)) { 2642 #if !INCLUDE_JVMTI 2643 jio_fprintf(defaultStream::error_stream(), 2644 "Instrumentation agents are not supported in this VM\n"); 2645 return JNI_ERR; 2646 #else 2647 if (tail != NULL) { 2648 size_t length = strlen(tail) + 1; 2649 char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments); 2650 jio_snprintf(options, length, "%s", tail); 2651 add_init_agent("instrument", options, false); 2652 // java agents need module java.instrument 2653 if (!create_numbered_property("jdk.module.addmods", "java.instrument", addmods_count++)) { 2654 return JNI_ENOMEM; 2655 } 2656 } 2657 #endif // !INCLUDE_JVMTI 2658 // -Xnoclassgc 2659 } else if (match_option(option, "-Xnoclassgc")) { 2660 if (FLAG_SET_CMDLINE(bool, ClassUnloading, false) != Flag::SUCCESS) { 2661 return JNI_EINVAL; 2662 } 2663 // -Xconcgc 2664 } else if (match_option(option, "-Xconcgc")) { 2665 if (FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true) != Flag::SUCCESS) { 2666 return JNI_EINVAL; 2667 } 2668 handle_extra_cms_flags("-Xconcgc uses UseConcMarkSweepGC"); 2669 // -Xnoconcgc 2670 } else if (match_option(option, "-Xnoconcgc")) { 2671 if (FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false) != Flag::SUCCESS) { 2672 return JNI_EINVAL; 2673 } 2674 handle_extra_cms_flags("-Xnoconcgc uses UseConcMarkSweepGC"); 2675 // -Xbatch 2676 } else if (match_option(option, "-Xbatch")) { 2677 if (FLAG_SET_CMDLINE(bool, BackgroundCompilation, false) != Flag::SUCCESS) { 2678 return JNI_EINVAL; 2679 } 2680 // -Xmn for compatibility with other JVM vendors 2681 } else if (match_option(option, "-Xmn", &tail)) { 2682 julong long_initial_young_size = 0; 2683 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1); 2684 if (errcode != arg_in_range) { 2685 jio_fprintf(defaultStream::error_stream(), 2686 "Invalid initial young generation size: %s\n", option->optionString); 2687 describe_range_error(errcode); 2688 return JNI_EINVAL; 2689 } 2690 if (FLAG_SET_CMDLINE(size_t, MaxNewSize, (size_t)long_initial_young_size) != Flag::SUCCESS) { 2691 return JNI_EINVAL; 2692 } 2693 if (FLAG_SET_CMDLINE(size_t, NewSize, (size_t)long_initial_young_size) != Flag::SUCCESS) { 2694 return JNI_EINVAL; 2695 } 2696 // -Xms 2697 } else if (match_option(option, "-Xms", &tail)) { 2698 julong long_initial_heap_size = 0; 2699 // an initial heap size of 0 means automatically determine 2700 ArgsRange errcode = parse_memory_size(tail, &long_initial_heap_size, 0); 2701 if (errcode != arg_in_range) { 2702 jio_fprintf(defaultStream::error_stream(), 2703 "Invalid initial heap size: %s\n", option->optionString); 2704 describe_range_error(errcode); 2705 return JNI_EINVAL; 2706 } 2707 set_min_heap_size((size_t)long_initial_heap_size); 2708 // Currently the minimum size and the initial heap sizes are the same. 2709 // Can be overridden with -XX:InitialHeapSize. 2710 if (FLAG_SET_CMDLINE(size_t, InitialHeapSize, (size_t)long_initial_heap_size) != Flag::SUCCESS) { 2711 return JNI_EINVAL; 2712 } 2713 // -Xmx 2714 } else if (match_option(option, "-Xmx", &tail) || match_option(option, "-XX:MaxHeapSize=", &tail)) { 2715 julong long_max_heap_size = 0; 2716 ArgsRange errcode = parse_memory_size(tail, &long_max_heap_size, 1); 2717 if (errcode != arg_in_range) { 2718 jio_fprintf(defaultStream::error_stream(), 2719 "Invalid maximum heap size: %s\n", option->optionString); 2720 describe_range_error(errcode); 2721 return JNI_EINVAL; 2722 } 2723 if (FLAG_SET_CMDLINE(size_t, MaxHeapSize, (size_t)long_max_heap_size) != Flag::SUCCESS) { 2724 return JNI_EINVAL; 2725 } 2726 // Xmaxf 2727 } else if (match_option(option, "-Xmaxf", &tail)) { 2728 char* err; 2729 int maxf = (int)(strtod(tail, &err) * 100); 2730 if (*err != '\0' || *tail == '\0') { 2731 jio_fprintf(defaultStream::error_stream(), 2732 "Bad max heap free percentage size: %s\n", 2733 option->optionString); 2734 return JNI_EINVAL; 2735 } else { 2736 if (FLAG_SET_CMDLINE(uintx, MaxHeapFreeRatio, maxf) != Flag::SUCCESS) { 2737 return JNI_EINVAL; 2738 } 2739 } 2740 // Xminf 2741 } else if (match_option(option, "-Xminf", &tail)) { 2742 char* err; 2743 int minf = (int)(strtod(tail, &err) * 100); 2744 if (*err != '\0' || *tail == '\0') { 2745 jio_fprintf(defaultStream::error_stream(), 2746 "Bad min heap free percentage size: %s\n", 2747 option->optionString); 2748 return JNI_EINVAL; 2749 } else { 2750 if (FLAG_SET_CMDLINE(uintx, MinHeapFreeRatio, minf) != Flag::SUCCESS) { 2751 return JNI_EINVAL; 2752 } 2753 } 2754 // -Xss 2755 } else if (match_option(option, "-Xss", &tail)) { 2756 intx value = 0; 2757 jint err = parse_xss(option, tail, &value); 2758 if (err != JNI_OK) { 2759 return err; 2760 } 2761 if (FLAG_SET_CMDLINE(intx, ThreadStackSize, value) != Flag::SUCCESS) { 2762 return JNI_EINVAL; 2763 } 2764 } else if (match_option(option, "-Xmaxjitcodesize", &tail) || 2765 match_option(option, "-XX:ReservedCodeCacheSize=", &tail)) { 2766 julong long_ReservedCodeCacheSize = 0; 2767 2768 ArgsRange errcode = parse_memory_size(tail, &long_ReservedCodeCacheSize, 1); 2769 if (errcode != arg_in_range) { 2770 jio_fprintf(defaultStream::error_stream(), 2771 "Invalid maximum code cache size: %s.\n", option->optionString); 2772 return JNI_EINVAL; 2773 } 2774 if (FLAG_SET_CMDLINE(uintx, ReservedCodeCacheSize, (uintx)long_ReservedCodeCacheSize) != Flag::SUCCESS) { 2775 return JNI_EINVAL; 2776 } 2777 // -green 2778 } else if (match_option(option, "-green")) { 2779 jio_fprintf(defaultStream::error_stream(), 2780 "Green threads support not available\n"); 2781 return JNI_EINVAL; 2782 // -native 2783 } else if (match_option(option, "-native")) { 2784 // HotSpot always uses native threads, ignore silently for compatibility 2785 // -Xrs 2786 } else if (match_option(option, "-Xrs")) { 2787 // Classic/EVM option, new functionality 2788 if (FLAG_SET_CMDLINE(bool, ReduceSignalUsage, true) != Flag::SUCCESS) { 2789 return JNI_EINVAL; 2790 } 2791 // -Xprof 2792 } else if (match_option(option, "-Xprof")) { 2793 char version[256]; 2794 // Obsolete in JDK 10 2795 JDK_Version::jdk(10).to_string(version, sizeof(version)); 2796 warning("Ignoring option %s; support was removed in %s", option->optionString, version); 2797 // -Xconcurrentio 2798 } else if (match_option(option, "-Xconcurrentio")) { 2799 if (FLAG_SET_CMDLINE(bool, UseLWPSynchronization, true) != Flag::SUCCESS) { 2800 return JNI_EINVAL; 2801 } 2802 if (FLAG_SET_CMDLINE(bool, BackgroundCompilation, false) != Flag::SUCCESS) { 2803 return JNI_EINVAL; 2804 } 2805 if (FLAG_SET_CMDLINE(intx, DeferThrSuspendLoopCount, 1) != Flag::SUCCESS) { 2806 return JNI_EINVAL; 2807 } 2808 if (FLAG_SET_CMDLINE(bool, UseTLAB, false) != Flag::SUCCESS) { 2809 return JNI_EINVAL; 2810 } 2811 if (FLAG_SET_CMDLINE(size_t, NewSizeThreadIncrease, 16 * K) != Flag::SUCCESS) { // 20Kb per thread added to new generation 2812 return JNI_EINVAL; 2813 } 2814 2815 // -Xinternalversion 2816 } else if (match_option(option, "-Xinternalversion")) { 2817 jio_fprintf(defaultStream::output_stream(), "%s\n", 2818 VM_Version::internal_vm_info_string()); 2819 vm_exit(0); 2820 #ifndef PRODUCT 2821 // -Xprintflags 2822 } else if (match_option(option, "-Xprintflags")) { 2823 CommandLineFlags::printFlags(tty, false); 2824 vm_exit(0); 2825 #endif 2826 // -D 2827 } else if (match_option(option, "-D", &tail)) { 2828 const char* value; 2829 if (match_option(option, "-Djava.endorsed.dirs=", &value) && 2830 *value!= '\0' && strcmp(value, "\"\"") != 0) { 2831 // abort if -Djava.endorsed.dirs is set 2832 jio_fprintf(defaultStream::output_stream(), 2833 "-Djava.endorsed.dirs=%s is not supported. Endorsed standards and standalone APIs\n" 2834 "in modular form will be supported via the concept of upgradeable modules.\n", value); 2835 return JNI_EINVAL; 2836 } 2837 if (match_option(option, "-Djava.ext.dirs=", &value) && 2838 *value != '\0' && strcmp(value, "\"\"") != 0) { 2839 // abort if -Djava.ext.dirs is set 2840 jio_fprintf(defaultStream::output_stream(), 2841 "-Djava.ext.dirs=%s is not supported. Use -classpath instead.\n", value); 2842 return JNI_EINVAL; 2843 } 2844 // Check for module related properties. They must be set using the modules 2845 // options. For example: use "--add-modules=java.sql", not 2846 // "-Djdk.module.addmods=java.sql" 2847 if (is_internal_module_property(option->optionString + 2)) { 2848 needs_module_property_warning = true; 2849 continue; 2850 } 2851 2852 if (!add_property(tail)) { 2853 return JNI_ENOMEM; 2854 } 2855 // Out of the box management support 2856 if (match_option(option, "-Dcom.sun.management", &tail)) { 2857 #if INCLUDE_MANAGEMENT 2858 if (FLAG_SET_CMDLINE(bool, ManagementServer, true) != Flag::SUCCESS) { 2859 return JNI_EINVAL; 2860 } 2861 // management agent in module jdk.management.agent 2862 if (!create_numbered_property("jdk.module.addmods", "jdk.management.agent", addmods_count++)) { 2863 return JNI_ENOMEM; 2864 } 2865 #else 2866 jio_fprintf(defaultStream::output_stream(), 2867 "-Dcom.sun.management is not supported in this VM.\n"); 2868 return JNI_ERR; 2869 #endif 2870 } 2871 // -Xint 2872 } else if (match_option(option, "-Xint")) { 2873 set_mode_flags(_int); 2874 // -Xmixed 2875 } else if (match_option(option, "-Xmixed")) { 2876 set_mode_flags(_mixed); 2877 // -Xcomp 2878 } else if (match_option(option, "-Xcomp")) { 2879 // for testing the compiler; turn off all flags that inhibit compilation 2880 set_mode_flags(_comp); 2881 // -Xshare:dump 2882 } else if (match_option(option, "-Xshare:dump")) { 2883 if (FLAG_SET_CMDLINE(bool, DumpSharedSpaces, true) != Flag::SUCCESS) { 2884 return JNI_EINVAL; 2885 } 2886 set_mode_flags(_int); // Prevent compilation, which creates objects 2887 // -Xshare:on 2888 } else if (match_option(option, "-Xshare:on")) { 2889 if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, true) != Flag::SUCCESS) { 2890 return JNI_EINVAL; 2891 } 2892 if (FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true) != Flag::SUCCESS) { 2893 return JNI_EINVAL; 2894 } 2895 // -Xshare:auto 2896 } else if (match_option(option, "-Xshare:auto")) { 2897 if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, true) != Flag::SUCCESS) { 2898 return JNI_EINVAL; 2899 } 2900 if (FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false) != Flag::SUCCESS) { 2901 return JNI_EINVAL; 2902 } 2903 // -Xshare:off 2904 } else if (match_option(option, "-Xshare:off")) { 2905 if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, false) != Flag::SUCCESS) { 2906 return JNI_EINVAL; 2907 } 2908 if (FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false) != Flag::SUCCESS) { 2909 return JNI_EINVAL; 2910 } 2911 // -Xverify 2912 } else if (match_option(option, "-Xverify", &tail)) { 2913 if (strcmp(tail, ":all") == 0 || strcmp(tail, "") == 0) { 2914 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, true) != Flag::SUCCESS) { 2915 return JNI_EINVAL; 2916 } 2917 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true) != Flag::SUCCESS) { 2918 return JNI_EINVAL; 2919 } 2920 } else if (strcmp(tail, ":remote") == 0) { 2921 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false) != Flag::SUCCESS) { 2922 return JNI_EINVAL; 2923 } 2924 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true) != Flag::SUCCESS) { 2925 return JNI_EINVAL; 2926 } 2927 } else if (strcmp(tail, ":none") == 0) { 2928 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false) != Flag::SUCCESS) { 2929 return JNI_EINVAL; 2930 } 2931 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, false) != Flag::SUCCESS) { 2932 return JNI_EINVAL; 2933 } 2934 } else if (is_bad_option(option, args->ignoreUnrecognized, "verification")) { 2935 return JNI_EINVAL; 2936 } 2937 // -Xdebug 2938 } else if (match_option(option, "-Xdebug")) { 2939 // note this flag has been used, then ignore 2940 set_xdebug_mode(true); 2941 // -Xnoagent 2942 } else if (match_option(option, "-Xnoagent")) { 2943 // For compatibility with classic. HotSpot refuses to load the old style agent.dll. 2944 } else if (match_option(option, "-Xloggc:", &tail)) { 2945 // Deprecated flag to redirect GC output to a file. -Xloggc:<filename> 2946 log_warning(gc)("-Xloggc is deprecated. Will use -Xlog:gc:%s instead.", tail); 2947 _gc_log_filename = os::strdup_check_oom(tail); 2948 } else if (match_option(option, "-Xlog", &tail)) { 2949 bool ret = false; 2950 if (strcmp(tail, ":help") == 0) { 2951 LogConfiguration::print_command_line_help(defaultStream::output_stream()); 2952 vm_exit(0); 2953 } else if (strcmp(tail, ":disable") == 0) { 2954 LogConfiguration::disable_logging(); 2955 ret = true; 2956 } else if (*tail == '\0') { 2957 ret = LogConfiguration::parse_command_line_arguments(); 2958 assert(ret, "-Xlog without arguments should never fail to parse"); 2959 } else if (*tail == ':') { 2960 ret = LogConfiguration::parse_command_line_arguments(tail + 1); 2961 } 2962 if (ret == false) { 2963 jio_fprintf(defaultStream::error_stream(), 2964 "Invalid -Xlog option '-Xlog%s'\n", 2965 tail); 2966 return JNI_EINVAL; 2967 } 2968 // JNI hooks 2969 } else if (match_option(option, "-Xcheck", &tail)) { 2970 if (!strcmp(tail, ":jni")) { 2971 #if !INCLUDE_JNI_CHECK 2972 warning("JNI CHECKING is not supported in this VM"); 2973 #else 2974 CheckJNICalls = true; 2975 #endif // INCLUDE_JNI_CHECK 2976 } else if (is_bad_option(option, args->ignoreUnrecognized, 2977 "check")) { 2978 return JNI_EINVAL; 2979 } 2980 } else if (match_option(option, "vfprintf")) { 2981 _vfprintf_hook = CAST_TO_FN_PTR(vfprintf_hook_t, option->extraInfo); 2982 } else if (match_option(option, "exit")) { 2983 _exit_hook = CAST_TO_FN_PTR(exit_hook_t, option->extraInfo); 2984 } else if (match_option(option, "abort")) { 2985 _abort_hook = CAST_TO_FN_PTR(abort_hook_t, option->extraInfo); 2986 // Need to keep consistency of MaxTenuringThreshold and AlwaysTenure/NeverTenure; 2987 // and the last option wins. 2988 } else if (match_option(option, "-XX:+NeverTenure")) { 2989 if (FLAG_SET_CMDLINE(bool, NeverTenure, true) != Flag::SUCCESS) { 2990 return JNI_EINVAL; 2991 } 2992 if (FLAG_SET_CMDLINE(bool, AlwaysTenure, false) != Flag::SUCCESS) { 2993 return JNI_EINVAL; 2994 } 2995 if (FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, markOopDesc::max_age + 1) != Flag::SUCCESS) { 2996 return JNI_EINVAL; 2997 } 2998 } else if (match_option(option, "-XX:+AlwaysTenure")) { 2999 if (FLAG_SET_CMDLINE(bool, NeverTenure, false) != Flag::SUCCESS) { 3000 return JNI_EINVAL; 3001 } 3002 if (FLAG_SET_CMDLINE(bool, AlwaysTenure, true) != Flag::SUCCESS) { 3003 return JNI_EINVAL; 3004 } 3005 if (FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, 0) != Flag::SUCCESS) { 3006 return JNI_EINVAL; 3007 } 3008 } else if (match_option(option, "-XX:MaxTenuringThreshold=", &tail)) { 3009 uintx max_tenuring_thresh = 0; 3010 if (!parse_uintx(tail, &max_tenuring_thresh, 0)) { 3011 jio_fprintf(defaultStream::error_stream(), 3012 "Improperly specified VM option \'MaxTenuringThreshold=%s\'\n", tail); 3013 return JNI_EINVAL; 3014 } 3015 3016 if (FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, max_tenuring_thresh) != Flag::SUCCESS) { 3017 return JNI_EINVAL; 3018 } 3019 3020 if (MaxTenuringThreshold == 0) { 3021 if (FLAG_SET_CMDLINE(bool, NeverTenure, false) != Flag::SUCCESS) { 3022 return JNI_EINVAL; 3023 } 3024 if (FLAG_SET_CMDLINE(bool, AlwaysTenure, true) != Flag::SUCCESS) { 3025 return JNI_EINVAL; 3026 } 3027 } else { 3028 if (FLAG_SET_CMDLINE(bool, NeverTenure, false) != Flag::SUCCESS) { 3029 return JNI_EINVAL; 3030 } 3031 if (FLAG_SET_CMDLINE(bool, AlwaysTenure, false) != Flag::SUCCESS) { 3032 return JNI_EINVAL; 3033 } 3034 } 3035 } else if (match_option(option, "-XX:+DisplayVMOutputToStderr")) { 3036 if (FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, false) != Flag::SUCCESS) { 3037 return JNI_EINVAL; 3038 } 3039 if (FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, true) != Flag::SUCCESS) { 3040 return JNI_EINVAL; 3041 } 3042 } else if (match_option(option, "-XX:+DisplayVMOutputToStdout")) { 3043 if (FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, false) != Flag::SUCCESS) { 3044 return JNI_EINVAL; 3045 } 3046 if (FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, true) != Flag::SUCCESS) { 3047 return JNI_EINVAL; 3048 } 3049 } else if (match_option(option, "-XX:+ExtendedDTraceProbes")) { 3050 #if defined(DTRACE_ENABLED) 3051 if (FLAG_SET_CMDLINE(bool, ExtendedDTraceProbes, true) != Flag::SUCCESS) { 3052 return JNI_EINVAL; 3053 } 3054 if (FLAG_SET_CMDLINE(bool, DTraceMethodProbes, true) != Flag::SUCCESS) { 3055 return JNI_EINVAL; 3056 } 3057 if (FLAG_SET_CMDLINE(bool, DTraceAllocProbes, true) != Flag::SUCCESS) { 3058 return JNI_EINVAL; 3059 } 3060 if (FLAG_SET_CMDLINE(bool, DTraceMonitorProbes, true) != Flag::SUCCESS) { 3061 return JNI_EINVAL; 3062 } 3063 #else // defined(DTRACE_ENABLED) 3064 jio_fprintf(defaultStream::error_stream(), 3065 "ExtendedDTraceProbes flag is not applicable for this configuration\n"); 3066 return JNI_EINVAL; 3067 #endif // defined(DTRACE_ENABLED) 3068 #ifdef ASSERT 3069 } else if (match_option(option, "-XX:+FullGCALot")) { 3070 if (FLAG_SET_CMDLINE(bool, FullGCALot, true) != Flag::SUCCESS) { 3071 return JNI_EINVAL; 3072 } 3073 // disable scavenge before parallel mark-compact 3074 if (FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false) != Flag::SUCCESS) { 3075 return JNI_EINVAL; 3076 } 3077 #endif 3078 #if !INCLUDE_MANAGEMENT 3079 } else if (match_option(option, "-XX:+ManagementServer")) { 3080 jio_fprintf(defaultStream::error_stream(), 3081 "ManagementServer is not supported in this VM.\n"); 3082 return JNI_ERR; 3083 #endif // INCLUDE_MANAGEMENT 3084 } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx 3085 // Skip -XX:Flags= and -XX:VMOptionsFile= since those cases have 3086 // already been handled 3087 if ((strncmp(tail, "Flags=", strlen("Flags=")) != 0) && 3088 (strncmp(tail, "VMOptionsFile=", strlen("VMOptionsFile=")) != 0)) { 3089 if (!process_argument(tail, args->ignoreUnrecognized, origin)) { 3090 return JNI_EINVAL; 3091 } 3092 } 3093 // Unknown option 3094 } else if (is_bad_option(option, args->ignoreUnrecognized)) { 3095 return JNI_ERR; 3096 } 3097 } 3098 3099 // PrintSharedArchiveAndExit will turn on 3100 // -Xshare:on 3101 // -Xlog:class+path=info 3102 if (PrintSharedArchiveAndExit) { 3103 if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, true) != Flag::SUCCESS) { 3104 return JNI_EINVAL; 3105 } 3106 if (FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true) != Flag::SUCCESS) { 3107 return JNI_EINVAL; 3108 } 3109 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path)); 3110 } 3111 3112 // Change the default value for flags which have different default values 3113 // when working with older JDKs. 3114 #ifdef LINUX 3115 if (JDK_Version::current().compare_major(6) <= 0 && 3116 FLAG_IS_DEFAULT(UseLinuxPosixThreadCPUClocks)) { 3117 FLAG_SET_DEFAULT(UseLinuxPosixThreadCPUClocks, false); 3118 } 3119 #endif // LINUX 3120 fix_appclasspath(); 3121 return JNI_OK; 3122 } 3123 3124 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool* patch_mod_javabase) { 3125 // For java.base check for duplicate --patch-module options being specified on the command line. 3126 // This check is only required for java.base, all other duplicate module specifications 3127 // will be checked during module system initialization. The module system initialization 3128 // will throw an ExceptionInInitializerError if this situation occurs. 3129 if (strcmp(module_name, JAVA_BASE_NAME) == 0) { 3130 if (*patch_mod_javabase) { 3131 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module"); 3132 } else { 3133 *patch_mod_javabase = true; 3134 } 3135 } 3136 3137 // Create GrowableArray lazily, only if --patch-module has been specified 3138 if (_patch_mod_prefix == NULL) { 3139 _patch_mod_prefix = new (ResourceObj::C_HEAP, mtArguments) GrowableArray<ModulePatchPath*>(10, true); 3140 } 3141 3142 _patch_mod_prefix->push(new ModulePatchPath(module_name, path)); 3143 } 3144 3145 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled) 3146 // 3147 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar 3148 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar". 3149 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty 3150 // path is treated as the current directory. 3151 // 3152 // This causes problems with CDS, which requires that all directories specified in the classpath 3153 // must be empty. In most cases, applications do NOT want to load classes from the current 3154 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up 3155 // scripts compatible with CDS. 3156 void Arguments::fix_appclasspath() { 3157 if (IgnoreEmptyClassPaths) { 3158 const char separator = *os::path_separator(); 3159 const char* src = _java_class_path->value(); 3160 3161 // skip over all the leading empty paths 3162 while (*src == separator) { 3163 src ++; 3164 } 3165 3166 char* copy = os::strdup_check_oom(src, mtArguments); 3167 3168 // trim all trailing empty paths 3169 for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) { 3170 *tail = '\0'; 3171 } 3172 3173 char from[3] = {separator, separator, '\0'}; 3174 char to [2] = {separator, '\0'}; 3175 while (StringUtils::replace_no_expand(copy, from, to) > 0) { 3176 // Keep replacing "::" -> ":" until we have no more "::" (non-windows) 3177 // Keep replacing ";;" -> ";" until we have no more ";;" (windows) 3178 } 3179 3180 _java_class_path->set_writeable_value(copy); 3181 FreeHeap(copy); // a copy was made by set_value, so don't need this anymore 3182 } 3183 } 3184 3185 static bool has_jar_files(const char* directory) { 3186 DIR* dir = os::opendir(directory); 3187 if (dir == NULL) return false; 3188 3189 struct dirent *entry; 3190 char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory), mtArguments); 3191 bool hasJarFile = false; 3192 while (!hasJarFile && (entry = os::readdir(dir, (dirent *) dbuf)) != NULL) { 3193 const char* name = entry->d_name; 3194 const char* ext = name + strlen(name) - 4; 3195 hasJarFile = ext > name && (os::file_name_strcmp(ext, ".jar") == 0); 3196 } 3197 FREE_C_HEAP_ARRAY(char, dbuf); 3198 os::closedir(dir); 3199 return hasJarFile ; 3200 } 3201 3202 static int check_non_empty_dirs(const char* path) { 3203 const char separator = *os::path_separator(); 3204 const char* const end = path + strlen(path); 3205 int nonEmptyDirs = 0; 3206 while (path < end) { 3207 const char* tmp_end = strchr(path, separator); 3208 if (tmp_end == NULL) { 3209 if (has_jar_files(path)) { 3210 nonEmptyDirs++; 3211 jio_fprintf(defaultStream::output_stream(), 3212 "Non-empty directory: %s\n", path); 3213 } 3214 path = end; 3215 } else { 3216 char* dirpath = NEW_C_HEAP_ARRAY(char, tmp_end - path + 1, mtArguments); 3217 memcpy(dirpath, path, tmp_end - path); 3218 dirpath[tmp_end - path] = '\0'; 3219 if (has_jar_files(dirpath)) { 3220 nonEmptyDirs++; 3221 jio_fprintf(defaultStream::output_stream(), 3222 "Non-empty directory: %s\n", dirpath); 3223 } 3224 FREE_C_HEAP_ARRAY(char, dirpath); 3225 path = tmp_end + 1; 3226 } 3227 } 3228 return nonEmptyDirs; 3229 } 3230 3231 jint Arguments::finalize_vm_init_args(bool patch_mod_javabase) { 3232 // check if the default lib/endorsed directory exists; if so, error 3233 char path[JVM_MAXPATHLEN]; 3234 const char* fileSep = os::file_separator(); 3235 jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep); 3236 3237 if (CheckEndorsedAndExtDirs) { 3238 int nonEmptyDirs = 0; 3239 // check endorsed directory 3240 nonEmptyDirs += check_non_empty_dirs(path); 3241 // check the extension directories 3242 nonEmptyDirs += check_non_empty_dirs(Arguments::get_ext_dirs()); 3243 if (nonEmptyDirs > 0) { 3244 return JNI_ERR; 3245 } 3246 } 3247 3248 DIR* dir = os::opendir(path); 3249 if (dir != NULL) { 3250 jio_fprintf(defaultStream::output_stream(), 3251 "<JAVA_HOME>/lib/endorsed is not supported. Endorsed standards and standalone APIs\n" 3252 "in modular form will be supported via the concept of upgradeable modules.\n"); 3253 os::closedir(dir); 3254 return JNI_ERR; 3255 } 3256 3257 jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep); 3258 dir = os::opendir(path); 3259 if (dir != NULL) { 3260 jio_fprintf(defaultStream::output_stream(), 3261 "<JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; " 3262 "Use -classpath instead.\n."); 3263 os::closedir(dir); 3264 return JNI_ERR; 3265 } 3266 3267 // This must be done after all arguments have been processed 3268 // and the container support has been initialized since AggressiveHeap 3269 // relies on the amount of total memory available. 3270 if (AggressiveHeap) { 3271 jint result = set_aggressive_heap_flags(); 3272 if (result != JNI_OK) { 3273 return result; 3274 } 3275 } 3276 3277 // This must be done after all arguments have been processed. 3278 // java_compiler() true means set to "NONE" or empty. 3279 if (java_compiler() && !xdebug_mode()) { 3280 // For backwards compatibility, we switch to interpreted mode if 3281 // -Djava.compiler="NONE" or "" is specified AND "-Xdebug" was 3282 // not specified. 3283 set_mode_flags(_int); 3284 } 3285 3286 // CompileThresholdScaling == 0.0 is same as -Xint: Disable compilation (enable interpreter-only mode), 3287 // but like -Xint, leave compilation thresholds unaffected. 3288 // With tiered compilation disabled, setting CompileThreshold to 0 disables compilation as well. 3289 if ((CompileThresholdScaling == 0.0) || (!TieredCompilation && CompileThreshold == 0)) { 3290 set_mode_flags(_int); 3291 } 3292 3293 // eventually fix up InitialTenuringThreshold if only MaxTenuringThreshold is set 3294 if (FLAG_IS_DEFAULT(InitialTenuringThreshold) && (InitialTenuringThreshold > MaxTenuringThreshold)) { 3295 FLAG_SET_ERGO(uintx, InitialTenuringThreshold, MaxTenuringThreshold); 3296 } 3297 3298 #if !defined(COMPILER2) && !INCLUDE_JVMCI 3299 // Don't degrade server performance for footprint 3300 if (FLAG_IS_DEFAULT(UseLargePages) && 3301 MaxHeapSize < LargePageHeapSizeThreshold) { 3302 // No need for large granularity pages w/small heaps. 3303 // Note that large pages are enabled/disabled for both the 3304 // Java heap and the code cache. 3305 FLAG_SET_DEFAULT(UseLargePages, false); 3306 } 3307 3308 #elif defined(COMPILER2) 3309 if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) { 3310 FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment-1); 3311 } 3312 #endif 3313 3314 #if !defined(COMPILER2) && !INCLUDE_JVMCI 3315 UNSUPPORTED_OPTION(ProfileInterpreter); 3316 NOT_PRODUCT(UNSUPPORTED_OPTION(TraceProfileInterpreter)); 3317 #endif 3318 3319 #ifndef TIERED 3320 // Tiered compilation is undefined. 3321 UNSUPPORTED_OPTION(TieredCompilation); 3322 #endif 3323 3324 #if INCLUDE_JVMCI 3325 if (EnableJVMCI && 3326 !create_numbered_property("jdk.module.addmods", "jdk.internal.vm.ci", addmods_count++)) { 3327 return JNI_ENOMEM; 3328 } 3329 #endif 3330 3331 // If we are running in a headless jre, force java.awt.headless property 3332 // to be true unless the property has already been set. 3333 // Also allow the OS environment variable JAVA_AWT_HEADLESS to set headless state. 3334 if (os::is_headless_jre()) { 3335 const char* headless = Arguments::get_property("java.awt.headless"); 3336 if (headless == NULL) { 3337 const char *headless_env = ::getenv("JAVA_AWT_HEADLESS"); 3338 if (headless_env == NULL) { 3339 if (!add_property("java.awt.headless=true")) { 3340 return JNI_ENOMEM; 3341 } 3342 } else { 3343 char buffer[256]; 3344 jio_snprintf(buffer, sizeof(buffer), "java.awt.headless=%s", headless_env); 3345 if (!add_property(buffer)) { 3346 return JNI_ENOMEM; 3347 } 3348 } 3349 } 3350 } 3351 3352 if (!check_vm_args_consistency()) { 3353 return JNI_ERR; 3354 } 3355 3356 #if INCLUDE_JVMCI 3357 if (UseJVMCICompiler) { 3358 Compilation_mode = CompMode_server; 3359 } 3360 #endif 3361 3362 #if INCLUDE_CDS 3363 if (DumpSharedSpaces) { 3364 // Disable biased locking now as it interferes with the clean up of 3365 // the archived Klasses and Java string objects (at dump time only). 3366 UseBiasedLocking = false; 3367 } 3368 if (UseSharedSpaces && patch_mod_javabase) { 3369 no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched."); 3370 } 3371 #endif 3372 3373 return JNI_OK; 3374 } 3375 3376 // Helper class for controlling the lifetime of JavaVMInitArgs 3377 // objects. The contents of the JavaVMInitArgs are guaranteed to be 3378 // deleted on the destruction of the ScopedVMInitArgs object. 3379 class ScopedVMInitArgs : public StackObj { 3380 private: 3381 JavaVMInitArgs _args; 3382 char* _container_name; 3383 bool _is_set; 3384 char* _vm_options_file_arg; 3385 3386 public: 3387 ScopedVMInitArgs(const char *container_name) { 3388 _args.version = JNI_VERSION_1_2; 3389 _args.nOptions = 0; 3390 _args.options = NULL; 3391 _args.ignoreUnrecognized = false; 3392 _container_name = (char *)container_name; 3393 _is_set = false; 3394 _vm_options_file_arg = NULL; 3395 } 3396 3397 // Populates the JavaVMInitArgs object represented by this 3398 // ScopedVMInitArgs object with the arguments in options. The 3399 // allocated memory is deleted by the destructor. If this method 3400 // returns anything other than JNI_OK, then this object is in a 3401 // partially constructed state, and should be abandoned. 3402 jint set_args(GrowableArray<JavaVMOption>* options) { 3403 _is_set = true; 3404 JavaVMOption* options_arr = NEW_C_HEAP_ARRAY_RETURN_NULL( 3405 JavaVMOption, options->length(), mtArguments); 3406 if (options_arr == NULL) { 3407 return JNI_ENOMEM; 3408 } 3409 _args.options = options_arr; 3410 3411 for (int i = 0; i < options->length(); i++) { 3412 options_arr[i] = options->at(i); 3413 options_arr[i].optionString = os::strdup(options_arr[i].optionString); 3414 if (options_arr[i].optionString == NULL) { 3415 // Rely on the destructor to do cleanup. 3416 _args.nOptions = i; 3417 return JNI_ENOMEM; 3418 } 3419 } 3420 3421 _args.nOptions = options->length(); 3422 _args.ignoreUnrecognized = IgnoreUnrecognizedVMOptions; 3423 return JNI_OK; 3424 } 3425 3426 JavaVMInitArgs* get() { return &_args; } 3427 char* container_name() { return _container_name; } 3428 bool is_set() { return _is_set; } 3429 bool found_vm_options_file_arg() { return _vm_options_file_arg != NULL; } 3430 char* vm_options_file_arg() { return _vm_options_file_arg; } 3431 3432 void set_vm_options_file_arg(const char *vm_options_file_arg) { 3433 if (_vm_options_file_arg != NULL) { 3434 os::free(_vm_options_file_arg); 3435 } 3436 _vm_options_file_arg = os::strdup_check_oom(vm_options_file_arg); 3437 } 3438 3439 ~ScopedVMInitArgs() { 3440 if (_vm_options_file_arg != NULL) { 3441 os::free(_vm_options_file_arg); 3442 } 3443 if (_args.options == NULL) return; 3444 for (int i = 0; i < _args.nOptions; i++) { 3445 os::free(_args.options[i].optionString); 3446 } 3447 FREE_C_HEAP_ARRAY(JavaVMOption, _args.options); 3448 } 3449 3450 // Insert options into this option list, to replace option at 3451 // vm_options_file_pos (-XX:VMOptionsFile) 3452 jint insert(const JavaVMInitArgs* args, 3453 const JavaVMInitArgs* args_to_insert, 3454 const int vm_options_file_pos) { 3455 assert(_args.options == NULL, "shouldn't be set yet"); 3456 assert(args_to_insert->nOptions != 0, "there should be args to insert"); 3457 assert(vm_options_file_pos != -1, "vm_options_file_pos should be set"); 3458 3459 int length = args->nOptions + args_to_insert->nOptions - 1; 3460 GrowableArray<JavaVMOption> *options = new (ResourceObj::C_HEAP, mtArguments) 3461 GrowableArray<JavaVMOption>(length, true); // Construct new option array 3462 for (int i = 0; i < args->nOptions; i++) { 3463 if (i == vm_options_file_pos) { 3464 // insert the new options starting at the same place as the 3465 // -XX:VMOptionsFile option 3466 for (int j = 0; j < args_to_insert->nOptions; j++) { 3467 options->push(args_to_insert->options[j]); 3468 } 3469 } else { 3470 options->push(args->options[i]); 3471 } 3472 } 3473 // make into options array 3474 jint result = set_args(options); 3475 delete options; 3476 return result; 3477 } 3478 }; 3479 3480 jint Arguments::parse_java_options_environment_variable(ScopedVMInitArgs* args) { 3481 return parse_options_environment_variable("_JAVA_OPTIONS", args); 3482 } 3483 3484 jint Arguments::parse_java_tool_options_environment_variable(ScopedVMInitArgs* args) { 3485 return parse_options_environment_variable("JAVA_TOOL_OPTIONS", args); 3486 } 3487 3488 jint Arguments::parse_options_environment_variable(const char* name, 3489 ScopedVMInitArgs* vm_args) { 3490 char *buffer = ::getenv(name); 3491 3492 // Don't check this environment variable if user has special privileges 3493 // (e.g. unix su command). 3494 if (buffer == NULL || os::have_special_privileges()) { 3495 return JNI_OK; 3496 } 3497 3498 if ((buffer = os::strdup(buffer)) == NULL) { 3499 return JNI_ENOMEM; 3500 } 3501 3502 jio_fprintf(defaultStream::error_stream(), 3503 "Picked up %s: %s\n", name, buffer); 3504 3505 int retcode = parse_options_buffer(name, buffer, strlen(buffer), vm_args); 3506 3507 os::free(buffer); 3508 return retcode; 3509 } 3510 3511 jint Arguments::parse_vm_options_file(const char* file_name, ScopedVMInitArgs* vm_args) { 3512 // read file into buffer 3513 int fd = ::open(file_name, O_RDONLY); 3514 if (fd < 0) { 3515 jio_fprintf(defaultStream::error_stream(), 3516 "Could not open options file '%s'\n", 3517 file_name); 3518 return JNI_ERR; 3519 } 3520 3521 struct stat stbuf; 3522 int retcode = os::stat(file_name, &stbuf); 3523 if (retcode != 0) { 3524 jio_fprintf(defaultStream::error_stream(), 3525 "Could not stat options file '%s'\n", 3526 file_name); 3527 os::close(fd); 3528 return JNI_ERR; 3529 } 3530 3531 if (stbuf.st_size == 0) { 3532 // tell caller there is no option data and that is ok 3533 os::close(fd); 3534 return JNI_OK; 3535 } 3536 3537 // '+ 1' for NULL termination even with max bytes 3538 size_t bytes_alloc = stbuf.st_size + 1; 3539 3540 char *buf = NEW_C_HEAP_ARRAY_RETURN_NULL(char, bytes_alloc, mtArguments); 3541 if (NULL == buf) { 3542 jio_fprintf(defaultStream::error_stream(), 3543 "Could not allocate read buffer for options file parse\n"); 3544 os::close(fd); 3545 return JNI_ENOMEM; 3546 } 3547 3548 memset(buf, 0, bytes_alloc); 3549 3550 // Fill buffer 3551 // Use ::read() instead of os::read because os::read() 3552 // might do a thread state transition 3553 // and it is too early for that here 3554 3555 ssize_t bytes_read = ::read(fd, (void *)buf, (unsigned)bytes_alloc); 3556 os::close(fd); 3557 if (bytes_read < 0) { 3558 FREE_C_HEAP_ARRAY(char, buf); 3559 jio_fprintf(defaultStream::error_stream(), 3560 "Could not read options file '%s'\n", file_name); 3561 return JNI_ERR; 3562 } 3563 3564 if (bytes_read == 0) { 3565 // tell caller there is no option data and that is ok 3566 FREE_C_HEAP_ARRAY(char, buf); 3567 return JNI_OK; 3568 } 3569 3570 retcode = parse_options_buffer(file_name, buf, bytes_read, vm_args); 3571 3572 FREE_C_HEAP_ARRAY(char, buf); 3573 return retcode; 3574 } 3575 3576 jint Arguments::parse_options_buffer(const char* name, char* buffer, const size_t buf_len, ScopedVMInitArgs* vm_args) { 3577 GrowableArray<JavaVMOption> *options = new (ResourceObj::C_HEAP, mtArguments) GrowableArray<JavaVMOption>(2, true); // Construct option array 3578 3579 // some pointers to help with parsing 3580 char *buffer_end = buffer + buf_len; 3581 char *opt_hd = buffer; 3582 char *wrt = buffer; 3583 char *rd = buffer; 3584 3585 // parse all options 3586 while (rd < buffer_end) { 3587 // skip leading white space from the input string 3588 while (rd < buffer_end && isspace(*rd)) { 3589 rd++; 3590 } 3591 3592 if (rd >= buffer_end) { 3593 break; 3594 } 3595 3596 // Remember this is where we found the head of the token. 3597 opt_hd = wrt; 3598 3599 // Tokens are strings of non white space characters separated 3600 // by one or more white spaces. 3601 while (rd < buffer_end && !isspace(*rd)) { 3602 if (*rd == '\'' || *rd == '"') { // handle a quoted string 3603 int quote = *rd; // matching quote to look for 3604 rd++; // don't copy open quote 3605 while (rd < buffer_end && *rd != quote) { 3606 // include everything (even spaces) 3607 // up until the close quote 3608 *wrt++ = *rd++; // copy to option string 3609 } 3610 3611 if (rd < buffer_end) { 3612 rd++; // don't copy close quote 3613 } else { 3614 // did not see closing quote 3615 jio_fprintf(defaultStream::error_stream(), 3616 "Unmatched quote in %s\n", name); 3617 delete options; 3618 return JNI_ERR; 3619 } 3620 } else { 3621 *wrt++ = *rd++; // copy to option string 3622 } 3623 } 3624 3625 // steal a white space character and set it to NULL 3626 *wrt++ = '\0'; 3627 // We now have a complete token 3628 3629 JavaVMOption option; 3630 option.optionString = opt_hd; 3631 option.extraInfo = NULL; 3632 3633 options->append(option); // Fill in option 3634 3635 rd++; // Advance to next character 3636 } 3637 3638 // Fill out JavaVMInitArgs structure. 3639 jint status = vm_args->set_args(options); 3640 3641 delete options; 3642 return status; 3643 } 3644 3645 void Arguments::set_shared_spaces_flags() { 3646 if (DumpSharedSpaces) { 3647 if (FailOverToOldVerifier) { 3648 // Don't fall back to the old verifier on verification failure. If a 3649 // class fails verification with the split verifier, it might fail the 3650 // CDS runtime verifier constraint check. In that case, we don't want 3651 // to share the class. We only archive classes that pass the split verifier. 3652 FLAG_SET_DEFAULT(FailOverToOldVerifier, false); 3653 } 3654 3655 if (RequireSharedSpaces) { 3656 warning("Cannot dump shared archive while using shared archive"); 3657 } 3658 UseSharedSpaces = false; 3659 #ifdef _LP64 3660 if (!UseCompressedOops || !UseCompressedClassPointers) { 3661 vm_exit_during_initialization( 3662 "Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off.", NULL); 3663 } 3664 } else { 3665 if (!UseCompressedOops || !UseCompressedClassPointers) { 3666 no_shared_spaces("UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces."); 3667 } 3668 #endif 3669 } 3670 } 3671 3672 // Sharing support 3673 // Construct the path to the archive 3674 static char* get_shared_archive_path() { 3675 char *shared_archive_path; 3676 if (SharedArchiveFile == NULL) { 3677 char jvm_path[JVM_MAXPATHLEN]; 3678 os::jvm_path(jvm_path, sizeof(jvm_path)); 3679 char *end = strrchr(jvm_path, *os::file_separator()); 3680 if (end != NULL) *end = '\0'; 3681 size_t jvm_path_len = strlen(jvm_path); 3682 size_t file_sep_len = strlen(os::file_separator()); 3683 const size_t len = jvm_path_len + file_sep_len + 20; 3684 shared_archive_path = NEW_C_HEAP_ARRAY(char, len, mtArguments); 3685 if (shared_archive_path != NULL) { 3686 jio_snprintf(shared_archive_path, len, "%s%sclasses.jsa", 3687 jvm_path, os::file_separator()); 3688 } 3689 } else { 3690 shared_archive_path = os::strdup_check_oom(SharedArchiveFile, mtArguments); 3691 } 3692 return shared_archive_path; 3693 } 3694 3695 #ifndef PRODUCT 3696 // Determine whether LogVMOutput should be implicitly turned on. 3697 static bool use_vm_log() { 3698 if (LogCompilation || !FLAG_IS_DEFAULT(LogFile) || 3699 PrintCompilation || PrintInlining || PrintDependencies || PrintNativeNMethods || 3700 PrintDebugInfo || PrintRelocations || PrintNMethods || PrintExceptionHandlers || 3701 PrintAssembly || TraceDeoptimization || TraceDependencies || 3702 (VerifyDependencies && FLAG_IS_CMDLINE(VerifyDependencies))) { 3703 return true; 3704 } 3705 3706 #ifdef COMPILER1 3707 if (PrintC1Statistics) { 3708 return true; 3709 } 3710 #endif // COMPILER1 3711 3712 #ifdef COMPILER2 3713 if (PrintOptoAssembly || PrintOptoStatistics) { 3714 return true; 3715 } 3716 #endif // COMPILER2 3717 3718 return false; 3719 } 3720 3721 #endif // PRODUCT 3722 3723 bool Arguments::args_contains_vm_options_file_arg(const JavaVMInitArgs* args) { 3724 for (int index = 0; index < args->nOptions; index++) { 3725 const JavaVMOption* option = args->options + index; 3726 const char* tail; 3727 if (match_option(option, "-XX:VMOptionsFile=", &tail)) { 3728 return true; 3729 } 3730 } 3731 return false; 3732 } 3733 3734 jint Arguments::insert_vm_options_file(const JavaVMInitArgs* args, 3735 const char* vm_options_file, 3736 const int vm_options_file_pos, 3737 ScopedVMInitArgs* vm_options_file_args, 3738 ScopedVMInitArgs* args_out) { 3739 jint code = parse_vm_options_file(vm_options_file, vm_options_file_args); 3740 if (code != JNI_OK) { 3741 return code; 3742 } 3743 3744 if (vm_options_file_args->get()->nOptions < 1) { 3745 return JNI_OK; 3746 } 3747 3748 if (args_contains_vm_options_file_arg(vm_options_file_args->get())) { 3749 jio_fprintf(defaultStream::error_stream(), 3750 "A VM options file may not refer to a VM options file. " 3751 "Specification of '-XX:VMOptionsFile=<file-name>' in the " 3752 "options file '%s' in options container '%s' is an error.\n", 3753 vm_options_file_args->vm_options_file_arg(), 3754 vm_options_file_args->container_name()); 3755 return JNI_EINVAL; 3756 } 3757 3758 return args_out->insert(args, vm_options_file_args->get(), 3759 vm_options_file_pos); 3760 } 3761 3762 // Expand -XX:VMOptionsFile found in args_in as needed. 3763 // mod_args and args_out parameters may return values as needed. 3764 jint Arguments::expand_vm_options_as_needed(const JavaVMInitArgs* args_in, 3765 ScopedVMInitArgs* mod_args, 3766 JavaVMInitArgs** args_out) { 3767 jint code = match_special_option_and_act(args_in, mod_args); 3768 if (code != JNI_OK) { 3769 return code; 3770 } 3771 3772 if (mod_args->is_set()) { 3773 // args_in contains -XX:VMOptionsFile and mod_args contains the 3774 // original options from args_in along with the options expanded 3775 // from the VMOptionsFile. Return a short-hand to the caller. 3776 *args_out = mod_args->get(); 3777 } else { 3778 *args_out = (JavaVMInitArgs *)args_in; // no changes so use args_in 3779 } 3780 return JNI_OK; 3781 } 3782 3783 jint Arguments::match_special_option_and_act(const JavaVMInitArgs* args, 3784 ScopedVMInitArgs* args_out) { 3785 // Remaining part of option string 3786 const char* tail; 3787 ScopedVMInitArgs vm_options_file_args(args_out->container_name()); 3788 3789 for (int index = 0; index < args->nOptions; index++) { 3790 const JavaVMOption* option = args->options + index; 3791 if (ArgumentsExt::process_options(option)) { 3792 continue; 3793 } 3794 if (match_option(option, "-XX:Flags=", &tail)) { 3795 Arguments::set_jvm_flags_file(tail); 3796 continue; 3797 } 3798 if (match_option(option, "-XX:VMOptionsFile=", &tail)) { 3799 if (vm_options_file_args.found_vm_options_file_arg()) { 3800 jio_fprintf(defaultStream::error_stream(), 3801 "The option '%s' is already specified in the options " 3802 "container '%s' so the specification of '%s' in the " 3803 "same options container is an error.\n", 3804 vm_options_file_args.vm_options_file_arg(), 3805 vm_options_file_args.container_name(), 3806 option->optionString); 3807 return JNI_EINVAL; 3808 } 3809 vm_options_file_args.set_vm_options_file_arg(option->optionString); 3810 // If there's a VMOptionsFile, parse that 3811 jint code = insert_vm_options_file(args, tail, index, 3812 &vm_options_file_args, args_out); 3813 if (code != JNI_OK) { 3814 return code; 3815 } 3816 args_out->set_vm_options_file_arg(vm_options_file_args.vm_options_file_arg()); 3817 if (args_out->is_set()) { 3818 // The VMOptions file inserted some options so switch 'args' 3819 // to the new set of options, and continue processing which 3820 // preserves "last option wins" semantics. 3821 args = args_out->get(); 3822 // The first option from the VMOptionsFile replaces the 3823 // current option. So we back track to process the 3824 // replacement option. 3825 index--; 3826 } 3827 continue; 3828 } 3829 if (match_option(option, "-XX:+PrintVMOptions")) { 3830 PrintVMOptions = true; 3831 continue; 3832 } 3833 if (match_option(option, "-XX:-PrintVMOptions")) { 3834 PrintVMOptions = false; 3835 continue; 3836 } 3837 if (match_option(option, "-XX:+IgnoreUnrecognizedVMOptions")) { 3838 IgnoreUnrecognizedVMOptions = true; 3839 continue; 3840 } 3841 if (match_option(option, "-XX:-IgnoreUnrecognizedVMOptions")) { 3842 IgnoreUnrecognizedVMOptions = false; 3843 continue; 3844 } 3845 if (match_option(option, "-XX:+PrintFlagsInitial")) { 3846 CommandLineFlags::printFlags(tty, false); 3847 vm_exit(0); 3848 } 3849 if (match_option(option, "-XX:NativeMemoryTracking", &tail)) { 3850 #if INCLUDE_NMT 3851 // The launcher did not setup nmt environment variable properly. 3852 if (!MemTracker::check_launcher_nmt_support(tail)) { 3853 warning("Native Memory Tracking did not setup properly, using wrong launcher?"); 3854 } 3855 3856 // Verify if nmt option is valid. 3857 if (MemTracker::verify_nmt_option()) { 3858 // Late initialization, still in single-threaded mode. 3859 if (MemTracker::tracking_level() >= NMT_summary) { 3860 MemTracker::init(); 3861 } 3862 } else { 3863 vm_exit_during_initialization("Syntax error, expecting -XX:NativeMemoryTracking=[off|summary|detail]", NULL); 3864 } 3865 continue; 3866 #else 3867 jio_fprintf(defaultStream::error_stream(), 3868 "Native Memory Tracking is not supported in this VM\n"); 3869 return JNI_ERR; 3870 #endif 3871 } 3872 3873 #ifndef PRODUCT 3874 if (match_option(option, "-XX:+PrintFlagsWithComments")) { 3875 CommandLineFlags::printFlags(tty, true); 3876 vm_exit(0); 3877 } 3878 #endif 3879 } 3880 return JNI_OK; 3881 } 3882 3883 static void print_options(const JavaVMInitArgs *args) { 3884 const char* tail; 3885 for (int index = 0; index < args->nOptions; index++) { 3886 const JavaVMOption *option = args->options + index; 3887 if (match_option(option, "-XX:", &tail)) { 3888 logOption(tail); 3889 } 3890 } 3891 } 3892 3893 bool Arguments::handle_deprecated_print_gc_flags() { 3894 if (PrintGC) { 3895 log_warning(gc)("-XX:+PrintGC is deprecated. Will use -Xlog:gc instead."); 3896 } 3897 if (PrintGCDetails) { 3898 log_warning(gc)("-XX:+PrintGCDetails is deprecated. Will use -Xlog:gc* instead."); 3899 } 3900 3901 if (_gc_log_filename != NULL) { 3902 // -Xloggc was used to specify a filename 3903 const char* gc_conf = PrintGCDetails ? "gc*" : "gc"; 3904 3905 LogTarget(Error, logging) target; 3906 LogStream errstream(target); 3907 return LogConfiguration::parse_log_arguments(_gc_log_filename, gc_conf, NULL, NULL, &errstream); 3908 } else if (PrintGC || PrintGCDetails) { 3909 LogConfiguration::configure_stdout(LogLevel::Info, !PrintGCDetails, LOG_TAGS(gc)); 3910 } 3911 return true; 3912 } 3913 3914 void Arguments::handle_extra_cms_flags(const char* msg) { 3915 SpecialFlag flag; 3916 const char *flag_name = "UseConcMarkSweepGC"; 3917 if (lookup_special_flag(flag_name, flag)) { 3918 handle_aliases_and_deprecation(flag_name, /* print warning */ true); 3919 warning("%s", msg); 3920 } 3921 } 3922 3923 // Parse entry point called from JNI_CreateJavaVM 3924 3925 jint Arguments::parse(const JavaVMInitArgs* initial_cmd_args) { 3926 assert(verify_special_jvm_flags(), "deprecated and obsolete flag table inconsistent"); 3927 3928 // Initialize ranges, constraints and writeables 3929 CommandLineFlagRangeList::init(); 3930 CommandLineFlagConstraintList::init(); 3931 CommandLineFlagWriteableList::init(); 3932 3933 // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed. 3934 const char* hotspotrc = ".hotspotrc"; 3935 bool settings_file_specified = false; 3936 bool needs_hotspotrc_warning = false; 3937 ScopedVMInitArgs initial_java_tool_options_args("env_var='JAVA_TOOL_OPTIONS'"); 3938 ScopedVMInitArgs initial_java_options_args("env_var='_JAVA_OPTIONS'"); 3939 3940 // Pointers to current working set of containers 3941 JavaVMInitArgs* cur_cmd_args; 3942 JavaVMInitArgs* cur_java_options_args; 3943 JavaVMInitArgs* cur_java_tool_options_args; 3944 3945 // Containers for modified/expanded options 3946 ScopedVMInitArgs mod_cmd_args("cmd_line_args"); 3947 ScopedVMInitArgs mod_java_tool_options_args("env_var='JAVA_TOOL_OPTIONS'"); 3948 ScopedVMInitArgs mod_java_options_args("env_var='_JAVA_OPTIONS'"); 3949 3950 3951 jint code = 3952 parse_java_tool_options_environment_variable(&initial_java_tool_options_args); 3953 if (code != JNI_OK) { 3954 return code; 3955 } 3956 3957 code = parse_java_options_environment_variable(&initial_java_options_args); 3958 if (code != JNI_OK) { 3959 return code; 3960 } 3961 3962 code = expand_vm_options_as_needed(initial_java_tool_options_args.get(), 3963 &mod_java_tool_options_args, 3964 &cur_java_tool_options_args); 3965 if (code != JNI_OK) { 3966 return code; 3967 } 3968 3969 code = expand_vm_options_as_needed(initial_cmd_args, 3970 &mod_cmd_args, 3971 &cur_cmd_args); 3972 if (code != JNI_OK) { 3973 return code; 3974 } 3975 3976 code = expand_vm_options_as_needed(initial_java_options_args.get(), 3977 &mod_java_options_args, 3978 &cur_java_options_args); 3979 if (code != JNI_OK) { 3980 return code; 3981 } 3982 3983 const char* flags_file = Arguments::get_jvm_flags_file(); 3984 settings_file_specified = (flags_file != NULL); 3985 3986 if (IgnoreUnrecognizedVMOptions) { 3987 cur_cmd_args->ignoreUnrecognized = true; 3988 cur_java_tool_options_args->ignoreUnrecognized = true; 3989 cur_java_options_args->ignoreUnrecognized = true; 3990 } 3991 3992 // Parse specified settings file 3993 if (settings_file_specified) { 3994 if (!process_settings_file(flags_file, true, 3995 cur_cmd_args->ignoreUnrecognized)) { 3996 return JNI_EINVAL; 3997 } 3998 } else { 3999 #ifdef ASSERT 4000 // Parse default .hotspotrc settings file 4001 if (!process_settings_file(".hotspotrc", false, 4002 cur_cmd_args->ignoreUnrecognized)) { 4003 return JNI_EINVAL; 4004 } 4005 #else 4006 struct stat buf; 4007 if (os::stat(hotspotrc, &buf) == 0) { 4008 needs_hotspotrc_warning = true; 4009 } 4010 #endif 4011 } 4012 4013 if (PrintVMOptions) { 4014 print_options(cur_java_tool_options_args); 4015 print_options(cur_cmd_args); 4016 print_options(cur_java_options_args); 4017 } 4018 4019 // Parse JavaVMInitArgs structure passed in, as well as JAVA_TOOL_OPTIONS and _JAVA_OPTIONS 4020 jint result = parse_vm_init_args(cur_java_tool_options_args, 4021 cur_java_options_args, 4022 cur_cmd_args); 4023 4024 if (result != JNI_OK) { 4025 return result; 4026 } 4027 4028 // Call get_shared_archive_path() here, after possible SharedArchiveFile option got parsed. 4029 SharedArchivePath = get_shared_archive_path(); 4030 if (SharedArchivePath == NULL) { 4031 return JNI_ENOMEM; 4032 } 4033 4034 // Set up VerifySharedSpaces 4035 if (FLAG_IS_DEFAULT(VerifySharedSpaces) && SharedArchiveFile != NULL) { 4036 VerifySharedSpaces = true; 4037 } 4038 4039 // Delay warning until here so that we've had a chance to process 4040 // the -XX:-PrintWarnings flag 4041 if (needs_hotspotrc_warning) { 4042 warning("%s file is present but has been ignored. " 4043 "Run with -XX:Flags=%s to load the file.", 4044 hotspotrc, hotspotrc); 4045 } 4046 4047 if (needs_module_property_warning) { 4048 warning("Ignoring system property options whose names match the '-Djdk.module.*'." 4049 " names that are reserved for internal use."); 4050 } 4051 4052 #if defined(_ALLBSD_SOURCE) || defined(AIX) // UseLargePages is not yet supported on BSD and AIX. 4053 UNSUPPORTED_OPTION(UseLargePages); 4054 #endif 4055 4056 ArgumentsExt::report_unsupported_options(); 4057 4058 #ifndef PRODUCT 4059 if (TraceBytecodesAt != 0) { 4060 TraceBytecodes = true; 4061 } 4062 if (CountCompiledCalls) { 4063 if (UseCounterDecay) { 4064 warning("UseCounterDecay disabled because CountCalls is set"); 4065 UseCounterDecay = false; 4066 } 4067 } 4068 #endif // PRODUCT 4069 4070 if (ScavengeRootsInCode == 0) { 4071 if (!FLAG_IS_DEFAULT(ScavengeRootsInCode)) { 4072 warning("Forcing ScavengeRootsInCode non-zero"); 4073 } 4074 ScavengeRootsInCode = 1; 4075 } 4076 4077 if (!handle_deprecated_print_gc_flags()) { 4078 return JNI_EINVAL; 4079 } 4080 4081 // Set object alignment values. 4082 set_object_alignment(); 4083 4084 #if !INCLUDE_CDS 4085 if (DumpSharedSpaces || RequireSharedSpaces) { 4086 jio_fprintf(defaultStream::error_stream(), 4087 "Shared spaces are not supported in this VM\n"); 4088 return JNI_ERR; 4089 } 4090 if ((UseSharedSpaces && FLAG_IS_CMDLINE(UseSharedSpaces)) || 4091 log_is_enabled(Info, cds)) { 4092 warning("Shared spaces are not supported in this VM"); 4093 FLAG_SET_DEFAULT(UseSharedSpaces, false); 4094 LogConfiguration::configure_stdout(LogLevel::Off, true, LOG_TAGS(cds)); 4095 } 4096 no_shared_spaces("CDS Disabled"); 4097 #endif // INCLUDE_CDS 4098 4099 return JNI_OK; 4100 } 4101 4102 jint Arguments::apply_ergo() { 4103 // Set flags based on ergonomics. 4104 jint result = set_ergonomics_flags(); 4105 if (result != JNI_OK) return result; 4106 4107 #if INCLUDE_JVMCI 4108 set_jvmci_specific_flags(); 4109 #endif 4110 4111 set_shared_spaces_flags(); 4112 4113 // Check the GC selections again. 4114 if (!check_gc_consistency()) { 4115 return JNI_EINVAL; 4116 } 4117 4118 if (TieredCompilation) { 4119 set_tiered_flags(); 4120 } else { 4121 int max_compilation_policy_choice = 1; 4122 #ifdef COMPILER2 4123 if (is_server_compilation_mode_vm()) { 4124 max_compilation_policy_choice = 2; 4125 } 4126 #endif 4127 // Check if the policy is valid. 4128 if (CompilationPolicyChoice >= max_compilation_policy_choice) { 4129 vm_exit_during_initialization( 4130 "Incompatible compilation policy selected", NULL); 4131 } 4132 // Scale CompileThreshold 4133 // CompileThresholdScaling == 0.0 is equivalent to -Xint and leaves CompileThreshold unchanged. 4134 if (!FLAG_IS_DEFAULT(CompileThresholdScaling) && CompileThresholdScaling > 0.0) { 4135 FLAG_SET_ERGO(intx, CompileThreshold, scaled_compile_threshold(CompileThreshold)); 4136 } 4137 } 4138 4139 #ifdef COMPILER2 4140 #ifndef PRODUCT 4141 if (PrintIdealGraphLevel > 0) { 4142 FLAG_SET_ERGO(bool, PrintIdealGraph, true); 4143 } 4144 #endif 4145 #endif 4146 4147 // Set heap size based on available physical memory 4148 set_heap_size(); 4149 4150 ArgumentsExt::set_gc_specific_flags(); 4151 4152 // Initialize Metaspace flags and alignments 4153 Metaspace::ergo_initialize(); 4154 4155 // Set bytecode rewriting flags 4156 set_bytecode_flags(); 4157 4158 // Set flags if Aggressive optimization flags (-XX:+AggressiveOpts) enabled 4159 jint code = set_aggressive_opts_flags(); 4160 if (code != JNI_OK) { 4161 return code; 4162 } 4163 4164 // Turn off biased locking for locking debug mode flags, 4165 // which are subtly different from each other but neither works with 4166 // biased locking 4167 if (UseHeavyMonitors 4168 #ifdef COMPILER1 4169 || !UseFastLocking 4170 #endif // COMPILER1 4171 #if INCLUDE_JVMCI 4172 || !JVMCIUseFastLocking 4173 #endif 4174 ) { 4175 if (!FLAG_IS_DEFAULT(UseBiasedLocking) && UseBiasedLocking) { 4176 // flag set to true on command line; warn the user that they 4177 // can't enable biased locking here 4178 warning("Biased Locking is not supported with locking debug flags" 4179 "; ignoring UseBiasedLocking flag." ); 4180 } 4181 UseBiasedLocking = false; 4182 } 4183 4184 #ifdef CC_INTERP 4185 // Clear flags not supported on zero. 4186 FLAG_SET_DEFAULT(ProfileInterpreter, false); 4187 FLAG_SET_DEFAULT(UseBiasedLocking, false); 4188 LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedOops, false)); 4189 LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedClassPointers, false)); 4190 #endif // CC_INTERP 4191 4192 #ifdef COMPILER2 4193 if (!EliminateLocks) { 4194 EliminateNestedLocks = false; 4195 } 4196 if (!Inline) { 4197 IncrementalInline = false; 4198 } 4199 #ifndef PRODUCT 4200 if (!IncrementalInline) { 4201 AlwaysIncrementalInline = false; 4202 } 4203 #endif 4204 if (!UseTypeSpeculation && FLAG_IS_DEFAULT(TypeProfileLevel)) { 4205 // nothing to use the profiling, turn if off 4206 FLAG_SET_DEFAULT(TypeProfileLevel, 0); 4207 } 4208 #endif 4209 4210 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) { 4211 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output"); 4212 DebugNonSafepoints = true; 4213 } 4214 4215 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) { 4216 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used"); 4217 } 4218 4219 if (UseOnStackReplacement && !UseLoopCounter) { 4220 warning("On-stack-replacement requires loop counters; enabling loop counters"); 4221 FLAG_SET_DEFAULT(UseLoopCounter, true); 4222 } 4223 4224 #ifndef PRODUCT 4225 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) { 4226 if (use_vm_log()) { 4227 LogVMOutput = true; 4228 } 4229 } 4230 #endif // PRODUCT 4231 4232 if (PrintCommandLineFlags) { 4233 CommandLineFlags::printSetFlags(tty); 4234 } 4235 4236 // Apply CPU specific policy for the BiasedLocking 4237 if (UseBiasedLocking) { 4238 if (!VM_Version::use_biased_locking() && 4239 !(FLAG_IS_CMDLINE(UseBiasedLocking))) { 4240 UseBiasedLocking = false; 4241 } 4242 } 4243 #ifdef COMPILER2 4244 if (!UseBiasedLocking || EmitSync != 0) { 4245 UseOptoBiasInlining = false; 4246 } 4247 #endif 4248 4249 bool aot_enabled = UseAOT && AOTLibrary != NULL; 4250 bool jvmci_enabled = NOT_JVMCI(false) JVMCI_ONLY(EnableJVMCI || UseJVMCICompiler); 4251 bool handshakes_supported = SafepointMechanism::supports_thread_local_poll() && !aot_enabled && !jvmci_enabled && ThreadLocalHandshakes; 4252 // ThreadLocalHandshakesConstraintFunc handles the constraints. 4253 // Here we try to figure out if a mutual exclusive option have been set that conflict with a default. 4254 if (handshakes_supported) { 4255 FLAG_SET_DEFAULT(UseAOT, false); // Clear the AOT flag to make sure it doesn't try to initialize. 4256 } else { 4257 if (FLAG_IS_DEFAULT(ThreadLocalHandshakes) && ThreadLocalHandshakes) { 4258 if (aot_enabled) { 4259 // If user enabled AOT but ThreadLocalHandshakes is at default set it to false. 4260 log_debug(ergo)("Disabling ThreadLocalHandshakes for UseAOT."); 4261 FLAG_SET_DEFAULT(ThreadLocalHandshakes, false); 4262 } else if (jvmci_enabled){ 4263 // If user enabled JVMCI but ThreadLocalHandshakes is at default set it to false. 4264 log_debug(ergo)("Disabling ThreadLocalHandshakes for EnableJVMCI/UseJVMCICompiler."); 4265 FLAG_SET_DEFAULT(ThreadLocalHandshakes, false); 4266 } 4267 } 4268 } 4269 if (FLAG_IS_DEFAULT(ThreadLocalHandshakes) || !SafepointMechanism::supports_thread_local_poll()) { 4270 log_debug(ergo)("ThreadLocalHandshakes %s", ThreadLocalHandshakes ? "enabled." : "disabled."); 4271 } else { 4272 log_info(ergo)("ThreadLocalHandshakes %s", ThreadLocalHandshakes ? "enabled." : "disabled."); 4273 } 4274 4275 return JNI_OK; 4276 } 4277 4278 jint Arguments::adjust_after_os() { 4279 if (UseNUMA) { 4280 if (UseParallelGC || UseParallelOldGC) { 4281 if (FLAG_IS_DEFAULT(MinHeapDeltaBytes)) { 4282 FLAG_SET_DEFAULT(MinHeapDeltaBytes, 64*M); 4283 } 4284 } 4285 // UseNUMAInterleaving is set to ON for all collectors and 4286 // platforms when UseNUMA is set to ON. NUMA-aware collectors 4287 // such as the parallel collector for Linux and Solaris will 4288 // interleave old gen and survivor spaces on top of NUMA 4289 // allocation policy for the eden space. 4290 // Non NUMA-aware collectors such as CMS, G1 and Serial-GC on 4291 // all platforms and ParallelGC on Windows will interleave all 4292 // of the heap spaces across NUMA nodes. 4293 if (FLAG_IS_DEFAULT(UseNUMAInterleaving)) { 4294 FLAG_SET_ERGO(bool, UseNUMAInterleaving, true); 4295 } 4296 } 4297 return JNI_OK; 4298 } 4299 4300 int Arguments::PropertyList_count(SystemProperty* pl) { 4301 int count = 0; 4302 while(pl != NULL) { 4303 count++; 4304 pl = pl->next(); 4305 } 4306 return count; 4307 } 4308 4309 // Return the number of readable properties. 4310 int Arguments::PropertyList_readable_count(SystemProperty* pl) { 4311 int count = 0; 4312 while(pl != NULL) { 4313 if (pl->is_readable()) { 4314 count++; 4315 } 4316 pl = pl->next(); 4317 } 4318 return count; 4319 } 4320 4321 const char* Arguments::PropertyList_get_value(SystemProperty *pl, const char* key) { 4322 assert(key != NULL, "just checking"); 4323 SystemProperty* prop; 4324 for (prop = pl; prop != NULL; prop = prop->next()) { 4325 if (strcmp(key, prop->key()) == 0) return prop->value(); 4326 } 4327 return NULL; 4328 } 4329 4330 // Return the value of the requested property provided that it is a readable property. 4331 const char* Arguments::PropertyList_get_readable_value(SystemProperty *pl, const char* key) { 4332 assert(key != NULL, "just checking"); 4333 SystemProperty* prop; 4334 // Return the property value if the keys match and the property is not internal or 4335 // it's the special internal property "jdk.boot.class.path.append". 4336 for (prop = pl; prop != NULL; prop = prop->next()) { 4337 if (strcmp(key, prop->key()) == 0) { 4338 if (!prop->internal()) { 4339 return prop->value(); 4340 } else if (strcmp(key, "jdk.boot.class.path.append") == 0) { 4341 return prop->value(); 4342 } else { 4343 // Property is internal and not jdk.boot.class.path.append so return NULL. 4344 return NULL; 4345 } 4346 } 4347 } 4348 return NULL; 4349 } 4350 4351 const char* Arguments::PropertyList_get_key_at(SystemProperty *pl, int index) { 4352 int count = 0; 4353 const char* ret_val = NULL; 4354 4355 while(pl != NULL) { 4356 if(count >= index) { 4357 ret_val = pl->key(); 4358 break; 4359 } 4360 count++; 4361 pl = pl->next(); 4362 } 4363 4364 return ret_val; 4365 } 4366 4367 char* Arguments::PropertyList_get_value_at(SystemProperty* pl, int index) { 4368 int count = 0; 4369 char* ret_val = NULL; 4370 4371 while(pl != NULL) { 4372 if(count >= index) { 4373 ret_val = pl->value(); 4374 break; 4375 } 4376 count++; 4377 pl = pl->next(); 4378 } 4379 4380 return ret_val; 4381 } 4382 4383 void Arguments::PropertyList_add(SystemProperty** plist, SystemProperty *new_p) { 4384 SystemProperty* p = *plist; 4385 if (p == NULL) { 4386 *plist = new_p; 4387 } else { 4388 while (p->next() != NULL) { 4389 p = p->next(); 4390 } 4391 p->set_next(new_p); 4392 } 4393 } 4394 4395 void Arguments::PropertyList_add(SystemProperty** plist, const char* k, const char* v, 4396 bool writeable, bool internal) { 4397 if (plist == NULL) 4398 return; 4399 4400 SystemProperty* new_p = new SystemProperty(k, v, writeable, internal); 4401 PropertyList_add(plist, new_p); 4402 } 4403 4404 void Arguments::PropertyList_add(SystemProperty *element) { 4405 PropertyList_add(&_system_properties, element); 4406 } 4407 4408 // This add maintains unique property key in the list. 4409 void Arguments::PropertyList_unique_add(SystemProperty** plist, const char* k, const char* v, 4410 PropertyAppendable append, PropertyWriteable writeable, 4411 PropertyInternal internal) { 4412 if (plist == NULL) 4413 return; 4414 4415 // If property key exist then update with new value. 4416 SystemProperty* prop; 4417 for (prop = *plist; prop != NULL; prop = prop->next()) { 4418 if (strcmp(k, prop->key()) == 0) { 4419 if (append == AppendProperty) { 4420 prop->append_value(v); 4421 } else { 4422 prop->set_value(v); 4423 } 4424 return; 4425 } 4426 } 4427 4428 PropertyList_add(plist, k, v, writeable == WriteableProperty, internal == InternalProperty); 4429 } 4430 4431 // Copies src into buf, replacing "%%" with "%" and "%p" with pid 4432 // Returns true if all of the source pointed by src has been copied over to 4433 // the destination buffer pointed by buf. Otherwise, returns false. 4434 // Notes: 4435 // 1. If the length (buflen) of the destination buffer excluding the 4436 // NULL terminator character is not long enough for holding the expanded 4437 // pid characters, it also returns false instead of returning the partially 4438 // expanded one. 4439 // 2. The passed in "buflen" should be large enough to hold the null terminator. 4440 bool Arguments::copy_expand_pid(const char* src, size_t srclen, 4441 char* buf, size_t buflen) { 4442 const char* p = src; 4443 char* b = buf; 4444 const char* src_end = &src[srclen]; 4445 char* buf_end = &buf[buflen - 1]; 4446 4447 while (p < src_end && b < buf_end) { 4448 if (*p == '%') { 4449 switch (*(++p)) { 4450 case '%': // "%%" ==> "%" 4451 *b++ = *p++; 4452 break; 4453 case 'p': { // "%p" ==> current process id 4454 // buf_end points to the character before the last character so 4455 // that we could write '\0' to the end of the buffer. 4456 size_t buf_sz = buf_end - b + 1; 4457 int ret = jio_snprintf(b, buf_sz, "%d", os::current_process_id()); 4458 4459 // if jio_snprintf fails or the buffer is not long enough to hold 4460 // the expanded pid, returns false. 4461 if (ret < 0 || ret >= (int)buf_sz) { 4462 return false; 4463 } else { 4464 b += ret; 4465 assert(*b == '\0', "fail in copy_expand_pid"); 4466 if (p == src_end && b == buf_end + 1) { 4467 // reach the end of the buffer. 4468 return true; 4469 } 4470 } 4471 p++; 4472 break; 4473 } 4474 default : 4475 *b++ = '%'; 4476 } 4477 } else { 4478 *b++ = *p++; 4479 } 4480 } 4481 *b = '\0'; 4482 return (p == src_end); // return false if not all of the source was copied 4483 }