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