1 /* 2 * Copyright (c) 1997, 2024, 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 "cds/cds_globals.hpp" 27 #include "cds/cdsConfig.hpp" 28 #include "cds/filemap.hpp" 29 #include "classfile/classLoader.hpp" 30 #include "classfile/javaAssertions.hpp" 31 #include "classfile/moduleEntry.hpp" 32 #include "classfile/stringTable.hpp" 33 #include "classfile/symbolTable.hpp" 34 #include "compiler/compilerDefinitions.hpp" 35 #include "gc/shared/gcArguments.hpp" 36 #include "gc/shared/gcConfig.hpp" 37 #include "gc/shared/genArguments.hpp" 38 #include "gc/shared/stringdedup/stringDedup.hpp" 39 #include "gc/shared/tlab_globals.hpp" 40 #include "jvm.h" 41 #include "logging/log.hpp" 42 #include "logging/logConfiguration.hpp" 43 #include "logging/logStream.hpp" 44 #include "logging/logTag.hpp" 45 #include "memory/allocation.inline.hpp" 46 #include "nmt/nmtCommon.hpp" 47 #include "oops/compressedKlass.hpp" 48 #include "oops/instanceKlass.hpp" 49 #include "oops/oop.inline.hpp" 50 #include "prims/jvmtiAgentList.hpp" 51 #include "prims/jvmtiExport.hpp" 52 #include "runtime/arguments.hpp" 53 #include "runtime/flags/jvmFlag.hpp" 54 #include "runtime/flags/jvmFlagAccess.hpp" 55 #include "runtime/flags/jvmFlagLimit.hpp" 56 #include "runtime/globals_extension.hpp" 57 #include "runtime/java.hpp" 58 #include "runtime/os.hpp" 59 #include "runtime/safepoint.hpp" 60 #include "runtime/safepointMechanism.hpp" 61 #include "runtime/synchronizer.hpp" 62 #include "runtime/vm_version.hpp" 63 #include "services/management.hpp" 64 #include "utilities/align.hpp" 65 #include "utilities/checkedCast.hpp" 66 #include "utilities/debug.hpp" 67 #include "utilities/defaultStream.hpp" 68 #include "utilities/macros.hpp" 69 #include "utilities/parseInteger.hpp" 70 #include "utilities/powerOfTwo.hpp" 71 #include "utilities/stringUtils.hpp" 72 #include "utilities/systemMemoryBarrier.hpp" 73 #if INCLUDE_JFR 74 #include "jfr/jfr.hpp" 75 #endif 76 77 #include <limits> 78 #include <string.h> 79 80 static const char _default_java_launcher[] = "generic"; 81 82 #define DEFAULT_JAVA_LAUNCHER _default_java_launcher 83 84 char* Arguments::_jvm_flags_file = nullptr; 85 char** Arguments::_jvm_flags_array = nullptr; 86 int Arguments::_num_jvm_flags = 0; 87 char** Arguments::_jvm_args_array = nullptr; 88 int Arguments::_num_jvm_args = 0; 89 unsigned int Arguments::_addmods_count = 0; 90 char* Arguments::_java_command = nullptr; 91 SystemProperty* Arguments::_system_properties = nullptr; 92 size_t Arguments::_conservative_max_heap_alignment = 0; 93 Arguments::Mode Arguments::_mode = _mixed; 94 const char* Arguments::_java_vendor_url_bug = nullptr; 95 const char* Arguments::_sun_java_launcher = DEFAULT_JAVA_LAUNCHER; 96 bool Arguments::_sun_java_launcher_is_altjvm = false; 97 98 // These parameters are reset in method parse_vm_init_args() 99 bool Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods; 100 bool Arguments::_UseOnStackReplacement = UseOnStackReplacement; 101 bool Arguments::_BackgroundCompilation = BackgroundCompilation; 102 bool Arguments::_ClipInlining = ClipInlining; 103 size_t Arguments::_default_SharedBaseAddress = SharedBaseAddress; 104 105 bool Arguments::_enable_preview = false; 106 107 LegacyGCLogging Arguments::_legacyGCLogging = { nullptr, 0 }; 108 109 // These are not set by the JDK's built-in launchers, but they can be set by 110 // programs that embed the JVM using JNI_CreateJavaVM. See comments around 111 // JavaVMOption in jni.h. 112 abort_hook_t Arguments::_abort_hook = nullptr; 113 exit_hook_t Arguments::_exit_hook = nullptr; 114 vfprintf_hook_t Arguments::_vfprintf_hook = nullptr; 115 116 117 SystemProperty *Arguments::_sun_boot_library_path = nullptr; 118 SystemProperty *Arguments::_java_library_path = nullptr; 119 SystemProperty *Arguments::_java_home = nullptr; 120 SystemProperty *Arguments::_java_class_path = nullptr; 121 SystemProperty *Arguments::_jdk_boot_class_path_append = nullptr; 122 SystemProperty *Arguments::_vm_info = nullptr; 123 124 GrowableArray<ModulePatchPath*> *Arguments::_patch_mod_prefix = nullptr; 125 PathString *Arguments::_boot_class_path = nullptr; 126 bool Arguments::_has_jimage = false; 127 128 char* Arguments::_ext_dirs = nullptr; 129 130 // True if -Xshare:auto option was specified. 131 static bool xshare_auto_cmd_line = false; 132 133 // True if -Xint/-Xmixed/-Xcomp were specified 134 static bool mode_flag_cmd_line = false; 135 136 bool PathString::set_value(const char *value, AllocFailType alloc_failmode) { 137 char* new_value = AllocateHeap(strlen(value)+1, mtArguments, alloc_failmode); 138 if (new_value == nullptr) { 139 assert(alloc_failmode == AllocFailStrategy::RETURN_NULL, "must be"); 140 return false; 141 } 142 if (_value != nullptr) { 143 FreeHeap(_value); 144 } 145 _value = new_value; 146 strcpy(_value, value); 147 return true; 148 } 149 150 void PathString::append_value(const char *value) { 151 char *sp; 152 size_t len = 0; 153 if (value != nullptr) { 154 len = strlen(value); 155 if (_value != nullptr) { 156 len += strlen(_value); 157 } 158 sp = AllocateHeap(len+2, mtArguments); 159 assert(sp != nullptr, "Unable to allocate space for new append path value"); 160 if (sp != nullptr) { 161 if (_value != nullptr) { 162 strcpy(sp, _value); 163 strcat(sp, os::path_separator()); 164 strcat(sp, value); 165 FreeHeap(_value); 166 } else { 167 strcpy(sp, value); 168 } 169 _value = sp; 170 } 171 } 172 } 173 174 PathString::PathString(const char* value) { 175 if (value == nullptr) { 176 _value = nullptr; 177 } else { 178 _value = AllocateHeap(strlen(value)+1, mtArguments); 179 strcpy(_value, value); 180 } 181 } 182 183 PathString::~PathString() { 184 if (_value != nullptr) { 185 FreeHeap(_value); 186 _value = nullptr; 187 } 188 } 189 190 ModulePatchPath::ModulePatchPath(const char* module_name, const char* path) { 191 assert(module_name != nullptr && path != nullptr, "Invalid module name or path value"); 192 size_t len = strlen(module_name) + 1; 193 _module_name = AllocateHeap(len, mtInternal); 194 strncpy(_module_name, module_name, len); // copy the trailing null 195 _path = new PathString(path); 196 } 197 198 ModulePatchPath::~ModulePatchPath() { 199 if (_module_name != nullptr) { 200 FreeHeap(_module_name); 201 _module_name = nullptr; 202 } 203 if (_path != nullptr) { 204 delete _path; 205 _path = nullptr; 206 } 207 } 208 209 SystemProperty::SystemProperty(const char* key, const char* value, bool writeable, bool internal) : PathString(value) { 210 if (key == nullptr) { 211 _key = nullptr; 212 } else { 213 _key = AllocateHeap(strlen(key)+1, mtArguments); 214 strcpy(_key, key); 215 } 216 _next = nullptr; 217 _internal = internal; 218 _writeable = writeable; 219 } 220 221 // Check if head of 'option' matches 'name', and sets 'tail' to the remaining 222 // part of the option string. 223 static bool match_option(const JavaVMOption *option, const char* name, 224 const char** tail) { 225 size_t len = strlen(name); 226 if (strncmp(option->optionString, name, len) == 0) { 227 *tail = option->optionString + len; 228 return true; 229 } else { 230 return false; 231 } 232 } 233 234 // Check if 'option' matches 'name'. No "tail" is allowed. 235 static bool match_option(const JavaVMOption *option, const char* name) { 236 const char* tail = nullptr; 237 bool result = match_option(option, name, &tail); 238 if (tail != nullptr && *tail == '\0') { 239 return result; 240 } else { 241 return false; 242 } 243 } 244 245 // Return true if any of the strings in null-terminated array 'names' matches. 246 // If tail_allowed is true, then the tail must begin with a colon; otherwise, 247 // the option must match exactly. 248 static bool match_option(const JavaVMOption* option, const char** names, const char** tail, 249 bool tail_allowed) { 250 for (/* empty */; *names != nullptr; ++names) { 251 if (match_option(option, *names, tail)) { 252 if (**tail == '\0' || (tail_allowed && **tail == ':')) { 253 return true; 254 } 255 } 256 } 257 return false; 258 } 259 260 #if INCLUDE_JFR 261 static bool _has_jfr_option = false; // is using JFR 262 263 // return true on failure 264 static bool match_jfr_option(const JavaVMOption** option) { 265 assert((*option)->optionString != nullptr, "invariant"); 266 char* tail = nullptr; 267 if (match_option(*option, "-XX:StartFlightRecording", (const char**)&tail)) { 268 _has_jfr_option = true; 269 return Jfr::on_start_flight_recording_option(option, tail); 270 } else if (match_option(*option, "-XX:FlightRecorderOptions", (const char**)&tail)) { 271 _has_jfr_option = true; 272 return Jfr::on_flight_recorder_option(option, tail); 273 } 274 return false; 275 } 276 277 bool Arguments::has_jfr_option() { 278 return _has_jfr_option; 279 } 280 #endif 281 282 static void logOption(const char* opt) { 283 if (PrintVMOptions) { 284 jio_fprintf(defaultStream::output_stream(), "VM option '%s'\n", opt); 285 } 286 } 287 288 bool needs_module_property_warning = false; 289 290 #define MODULE_PROPERTY_PREFIX "jdk.module." 291 #define MODULE_PROPERTY_PREFIX_LEN 11 292 #define ADDEXPORTS "addexports" 293 #define ADDEXPORTS_LEN 10 294 #define ADDREADS "addreads" 295 #define ADDREADS_LEN 8 296 #define ADDOPENS "addopens" 297 #define ADDOPENS_LEN 8 298 #define PATCH "patch" 299 #define PATCH_LEN 5 300 #define ADDMODS "addmods" 301 #define ADDMODS_LEN 7 302 #define LIMITMODS "limitmods" 303 #define LIMITMODS_LEN 9 304 #define PATH "path" 305 #define PATH_LEN 4 306 #define UPGRADE_PATH "upgrade.path" 307 #define UPGRADE_PATH_LEN 12 308 #define ENABLE_NATIVE_ACCESS "enable.native.access" 309 #define ENABLE_NATIVE_ACCESS_LEN 20 310 #define ILLEGAL_NATIVE_ACCESS "illegal.native.access" 311 #define ILLEGAL_NATIVE_ACCESS_LEN 21 312 313 // Return TRUE if option matches 'property', or 'property=', or 'property.'. 314 static bool matches_property_suffix(const char* option, const char* property, size_t len) { 315 return ((strncmp(option, property, len) == 0) && 316 (option[len] == '=' || option[len] == '.' || option[len] == '\0')); 317 } 318 319 // Return true if property starts with "jdk.module." and its ensuing chars match 320 // any of the reserved module properties. 321 // property should be passed without the leading "-D". 322 bool Arguments::is_internal_module_property(const char* property) { 323 if (strncmp(property, MODULE_PROPERTY_PREFIX, MODULE_PROPERTY_PREFIX_LEN) == 0) { 324 const char* property_suffix = property + MODULE_PROPERTY_PREFIX_LEN; 325 if (matches_property_suffix(property_suffix, ADDEXPORTS, ADDEXPORTS_LEN) || 326 matches_property_suffix(property_suffix, ADDREADS, ADDREADS_LEN) || 327 matches_property_suffix(property_suffix, ADDOPENS, ADDOPENS_LEN) || 328 matches_property_suffix(property_suffix, PATCH, PATCH_LEN) || 329 matches_property_suffix(property_suffix, ADDMODS, ADDMODS_LEN) || 330 matches_property_suffix(property_suffix, LIMITMODS, LIMITMODS_LEN) || 331 matches_property_suffix(property_suffix, PATH, PATH_LEN) || 332 matches_property_suffix(property_suffix, UPGRADE_PATH, UPGRADE_PATH_LEN) || 333 matches_property_suffix(property_suffix, ILLEGAL_NATIVE_ACCESS, ILLEGAL_NATIVE_ACCESS_LEN) || 334 matches_property_suffix(property_suffix, ENABLE_NATIVE_ACCESS, ENABLE_NATIVE_ACCESS_LEN)) { 335 return true; 336 } 337 } 338 return false; 339 } 340 341 bool Arguments::is_add_modules_property(const char* key) { 342 return (strcmp(key, MODULE_PROPERTY_PREFIX ADDMODS) == 0); 343 } 344 345 // Return true if the key matches the --module-path property name ("jdk.module.path"). 346 bool Arguments::is_module_path_property(const char* key) { 347 return (strcmp(key, MODULE_PROPERTY_PREFIX PATH) == 0); 348 } 349 350 // Process java launcher properties. 351 void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) { 352 // See if sun.java.launcher or sun.java.launcher.is_altjvm is defined. 353 // Must do this before setting up other system properties, 354 // as some of them may depend on launcher type. 355 for (int index = 0; index < args->nOptions; index++) { 356 const JavaVMOption* option = args->options + index; 357 const char* tail; 358 359 if (match_option(option, "-Dsun.java.launcher=", &tail)) { 360 process_java_launcher_argument(tail, option->extraInfo); 361 continue; 362 } 363 if (match_option(option, "-Dsun.java.launcher.is_altjvm=", &tail)) { 364 if (strcmp(tail, "true") == 0) { 365 _sun_java_launcher_is_altjvm = true; 366 } 367 continue; 368 } 369 } 370 } 371 372 // Initialize system properties key and value. 373 void Arguments::init_system_properties() { 374 375 // Set up _boot_class_path which is not a property but 376 // relies heavily on argument processing and the jdk.boot.class.path.append 377 // property. It is used to store the underlying boot class path. 378 _boot_class_path = new PathString(nullptr); 379 380 PropertyList_add(&_system_properties, new SystemProperty("java.vm.specification.name", 381 "Java Virtual Machine Specification", false)); 382 PropertyList_add(&_system_properties, new SystemProperty("java.vm.version", VM_Version::vm_release(), false)); 383 PropertyList_add(&_system_properties, new SystemProperty("java.vm.name", VM_Version::vm_name(), false)); 384 PropertyList_add(&_system_properties, new SystemProperty("jdk.debug", VM_Version::jdk_debug_level(), false)); 385 386 // Initialize the vm.info now, but it will need updating after argument parsing. 387 _vm_info = new SystemProperty("java.vm.info", VM_Version::vm_info_string(), true); 388 389 // Following are JVMTI agent writable properties. 390 // Properties values are set to nullptr and they are 391 // os specific they are initialized in os::init_system_properties_values(). 392 _sun_boot_library_path = new SystemProperty("sun.boot.library.path", nullptr, true); 393 _java_library_path = new SystemProperty("java.library.path", nullptr, true); 394 _java_home = new SystemProperty("java.home", nullptr, true); 395 _java_class_path = new SystemProperty("java.class.path", "", true); 396 // jdk.boot.class.path.append is a non-writeable, internal property. 397 // It can only be set by either: 398 // - -Xbootclasspath/a: 399 // - AddToBootstrapClassLoaderSearch during JVMTI OnLoad phase 400 _jdk_boot_class_path_append = new SystemProperty("jdk.boot.class.path.append", nullptr, false, true); 401 402 // Add to System Property list. 403 PropertyList_add(&_system_properties, _sun_boot_library_path); 404 PropertyList_add(&_system_properties, _java_library_path); 405 PropertyList_add(&_system_properties, _java_home); 406 PropertyList_add(&_system_properties, _java_class_path); 407 PropertyList_add(&_system_properties, _jdk_boot_class_path_append); 408 PropertyList_add(&_system_properties, _vm_info); 409 410 // Set OS specific system properties values 411 os::init_system_properties_values(); 412 } 413 414 // Update/Initialize System properties after JDK version number is known 415 void Arguments::init_version_specific_system_properties() { 416 enum { bufsz = 16 }; 417 char buffer[bufsz]; 418 const char* spec_vendor = "Oracle Corporation"; 419 uint32_t spec_version = JDK_Version::current().major_version(); 420 421 jio_snprintf(buffer, bufsz, UINT32_FORMAT, spec_version); 422 423 PropertyList_add(&_system_properties, 424 new SystemProperty("java.vm.specification.vendor", spec_vendor, false)); 425 PropertyList_add(&_system_properties, 426 new SystemProperty("java.vm.specification.version", buffer, false)); 427 PropertyList_add(&_system_properties, 428 new SystemProperty("java.vm.vendor", VM_Version::vm_vendor(), false)); 429 } 430 431 /* 432 * -XX argument processing: 433 * 434 * -XX arguments are defined in several places, such as: 435 * globals.hpp, globals_<cpu>.hpp, globals_<os>.hpp, <compiler>_globals.hpp, or <gc>_globals.hpp. 436 * -XX arguments are parsed in parse_argument(). 437 * -XX argument bounds checking is done in check_vm_args_consistency(). 438 * 439 * Over time -XX arguments may change. There are mechanisms to handle common cases: 440 * 441 * ALIASED: An option that is simply another name for another option. This is often 442 * part of the process of deprecating a flag, but not all aliases need 443 * to be deprecated. 444 * 445 * Create an alias for an option by adding the old and new option names to the 446 * "aliased_jvm_flags" table. Delete the old variable from globals.hpp (etc). 447 * 448 * DEPRECATED: An option that is supported, but a warning is printed to let the user know that 449 * support may be removed in the future. Both regular and aliased options may be 450 * deprecated. 451 * 452 * Add a deprecation warning for an option (or alias) by adding an entry in the 453 * "special_jvm_flags" table and setting the "deprecated_in" field. 454 * Often an option "deprecated" in one major release will 455 * be made "obsolete" in the next. In this case the entry should also have its 456 * "obsolete_in" field set. 457 * 458 * OBSOLETE: An option that has been removed (and deleted from globals.hpp), but is still accepted 459 * on the command line. A warning is printed to let the user know that option might not 460 * be accepted in the future. 461 * 462 * Add an obsolete warning for an option by adding an entry in the "special_jvm_flags" 463 * table and setting the "obsolete_in" field. 464 * 465 * EXPIRED: A deprecated or obsolete option that has an "accept_until" version less than or equal 466 * to the current JDK version. The system will flatly refuse to admit the existence of 467 * the flag. This allows a flag to die automatically over JDK releases. 468 * 469 * Note that manual cleanup of expired options should be done at major JDK version upgrades: 470 * - Newly expired options should be removed from the special_jvm_flags and aliased_jvm_flags tables. 471 * - Newly obsolete or expired deprecated options should have their global variable 472 * definitions removed (from globals.hpp, etc) and related implementations removed. 473 * 474 * Recommended approach for removing options: 475 * 476 * To remove options commonly used by customers (e.g. product -XX options), use 477 * the 3-step model adding major release numbers to the deprecate, obsolete and expire columns. 478 * 479 * To remove internal options (e.g. diagnostic, experimental, develop options), use 480 * a 2-step model adding major release numbers to the obsolete and expire columns. 481 * 482 * To change the name of an option, use the alias table as well as a 2-step 483 * model adding major release numbers to the deprecate and expire columns. 484 * Think twice about aliasing commonly used customer options. 485 * 486 * There are times when it is appropriate to leave a future release number as undefined. 487 * 488 * Tests: Aliases should be tested in VMAliasOptions.java. 489 * Deprecated options should be tested in VMDeprecatedOptions.java. 490 */ 491 492 // The special_jvm_flags table declares options that are being deprecated and/or obsoleted. The 493 // "deprecated_in" or "obsolete_in" fields may be set to "undefined", but not both. 494 // When the JDK version reaches 'deprecated_in' limit, the JVM will process this flag on 495 // the command-line as usual, but will issue a warning. 496 // When the JDK version reaches 'obsolete_in' limit, the JVM will continue accepting this flag on 497 // the command-line, while issuing a warning and ignoring the flag value. 498 // Once the JDK version reaches 'expired_in' limit, the JVM will flatly refuse to admit the 499 // existence of the flag. 500 // 501 // MANUAL CLEANUP ON JDK VERSION UPDATES: 502 // This table ensures that the handling of options will update automatically when the JDK 503 // version is incremented, but the source code needs to be cleanup up manually: 504 // - As "deprecated" options age into "obsolete" or "expired" options, the associated "globals" 505 // variable should be removed, as well as users of the variable. 506 // - As "deprecated" options age into "obsolete" options, move the entry into the 507 // "Obsolete Flags" section of the table. 508 // - All expired options should be removed from the table. 509 static SpecialFlag const special_jvm_flags[] = { 510 // -------------- Deprecated Flags -------------- 511 // --- Non-alias flags - sorted by obsolete_in then expired_in: 512 { "AllowRedefinitionToAddDeleteMethods", JDK_Version::jdk(13), JDK_Version::undefined(), JDK_Version::undefined() }, 513 { "FlightRecorder", JDK_Version::jdk(13), JDK_Version::undefined(), JDK_Version::undefined() }, 514 { "DumpSharedSpaces", JDK_Version::jdk(18), JDK_Version::jdk(19), JDK_Version::undefined() }, 515 { "DynamicDumpSharedSpaces", JDK_Version::jdk(18), JDK_Version::jdk(19), JDK_Version::undefined() }, 516 { "RequireSharedSpaces", JDK_Version::jdk(18), JDK_Version::jdk(19), JDK_Version::undefined() }, 517 { "UseSharedSpaces", JDK_Version::jdk(18), JDK_Version::jdk(19), JDK_Version::undefined() }, 518 { "DontYieldALot", JDK_Version::jdk(23), JDK_Version::jdk(24), JDK_Version::jdk(25) }, 519 #ifdef LINUX 520 { "UseLinuxPosixThreadCPUClocks", JDK_Version::jdk(24), JDK_Version::jdk(25), JDK_Version::jdk(26) }, 521 #endif 522 { "LockingMode", JDK_Version::jdk(24), JDK_Version::jdk(26), JDK_Version::jdk(27) }, 523 // --- Deprecated alias flags (see also aliased_jvm_flags) - sorted by obsolete_in then expired_in: 524 { "CreateMinidumpOnCrash", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::undefined() }, 525 526 // -------------- Obsolete Flags - sorted by expired_in -------------- 527 528 { "MetaspaceReclaimPolicy", JDK_Version::undefined(), JDK_Version::jdk(21), JDK_Version::undefined() }, 529 { "ZGenerational", JDK_Version::jdk(23), JDK_Version::jdk(24), JDK_Version::undefined() }, 530 { "UseNotificationThread", JDK_Version::jdk(23), JDK_Version::jdk(24), JDK_Version::jdk(25) }, 531 { "PreserveAllAnnotations", JDK_Version::jdk(23), JDK_Version::jdk(24), JDK_Version::jdk(25) }, 532 { "UseEmptySlotsInSupers", JDK_Version::jdk(23), JDK_Version::jdk(24), JDK_Version::jdk(25) }, 533 { "OldSize", JDK_Version::jdk(23), JDK_Version::jdk(24), JDK_Version::jdk(25) }, 534 #if defined(X86) 535 { "UseRTMLocking", JDK_Version::jdk(23), JDK_Version::jdk(24), JDK_Version::jdk(25) }, 536 { "UseRTMDeopt", JDK_Version::jdk(23), JDK_Version::jdk(24), JDK_Version::jdk(25) }, 537 { "RTMRetryCount", JDK_Version::jdk(23), JDK_Version::jdk(24), JDK_Version::jdk(25) }, 538 #endif // X86 539 540 541 { "BaseFootPrintEstimate", JDK_Version::undefined(), JDK_Version::jdk(24), JDK_Version::jdk(25) }, 542 { "HeapFirstMaximumCompactionCount", JDK_Version::undefined(), JDK_Version::jdk(24), JDK_Version::jdk(25) }, 543 { "UseVtableBasedCHA", JDK_Version::undefined(), JDK_Version::jdk(24), JDK_Version::jdk(25) }, 544 #ifdef ASSERT 545 { "DummyObsoleteTestFlag", JDK_Version::undefined(), JDK_Version::jdk(18), JDK_Version::undefined() }, 546 #endif 547 548 #ifdef TEST_VERIFY_SPECIAL_JVM_FLAGS 549 // These entries will generate build errors. Their purpose is to test the macros. 550 { "dep > obs", JDK_Version::jdk(9), JDK_Version::jdk(8), JDK_Version::undefined() }, 551 { "dep > exp ", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(8) }, 552 { "obs > exp ", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(8) }, 553 { "obs > exp", JDK_Version::jdk(8), JDK_Version::undefined(), JDK_Version::jdk(10) }, 554 { "not deprecated or obsolete", JDK_Version::undefined(), JDK_Version::undefined(), JDK_Version::jdk(9) }, 555 { "dup option", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::undefined() }, 556 { "dup option", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::undefined() }, 557 #endif 558 559 { nullptr, JDK_Version(0), JDK_Version(0) } 560 }; 561 562 // Flags that are aliases for other flags. 563 typedef struct { 564 const char* alias_name; 565 const char* real_name; 566 } AliasedFlag; 567 568 static AliasedFlag const aliased_jvm_flags[] = { 569 { "CreateMinidumpOnCrash", "CreateCoredumpOnCrash" }, 570 { nullptr, nullptr} 571 }; 572 573 // Return true if "v" is less than "other", where "other" may be "undefined". 574 static bool version_less_than(JDK_Version v, JDK_Version other) { 575 assert(!v.is_undefined(), "must be defined"); 576 if (!other.is_undefined() && v.compare(other) >= 0) { 577 return false; 578 } else { 579 return true; 580 } 581 } 582 583 static bool lookup_special_flag(const char *flag_name, SpecialFlag& flag) { 584 for (size_t i = 0; special_jvm_flags[i].name != nullptr; i++) { 585 if ((strcmp(special_jvm_flags[i].name, flag_name) == 0)) { 586 flag = special_jvm_flags[i]; 587 return true; 588 } 589 } 590 return false; 591 } 592 593 bool Arguments::is_obsolete_flag(const char *flag_name, JDK_Version* version) { 594 assert(version != nullptr, "Must provide a version buffer"); 595 SpecialFlag flag; 596 if (lookup_special_flag(flag_name, flag)) { 597 if (!flag.obsolete_in.is_undefined()) { 598 if (!version_less_than(JDK_Version::current(), flag.obsolete_in)) { 599 *version = flag.obsolete_in; 600 // This flag may have been marked for obsoletion in this version, but we may not 601 // have actually removed it yet. Rather than ignoring it as soon as we reach 602 // this version we allow some time for the removal to happen. So if the flag 603 // still actually exists we process it as normal, but issue an adjusted warning. 604 const JVMFlag *real_flag = JVMFlag::find_declared_flag(flag_name); 605 if (real_flag != nullptr) { 606 char version_str[256]; 607 version->to_string(version_str, sizeof(version_str)); 608 warning("Temporarily processing option %s; support is scheduled for removal in %s", 609 flag_name, version_str); 610 return false; 611 } 612 return true; 613 } 614 } 615 } 616 return false; 617 } 618 619 int Arguments::is_deprecated_flag(const char *flag_name, JDK_Version* version) { 620 assert(version != nullptr, "Must provide a version buffer"); 621 SpecialFlag flag; 622 if (lookup_special_flag(flag_name, flag)) { 623 if (!flag.deprecated_in.is_undefined()) { 624 if (version_less_than(JDK_Version::current(), flag.obsolete_in) && 625 version_less_than(JDK_Version::current(), flag.expired_in)) { 626 *version = flag.deprecated_in; 627 return 1; 628 } else { 629 return -1; 630 } 631 } 632 } 633 return 0; 634 } 635 636 const char* Arguments::real_flag_name(const char *flag_name) { 637 for (size_t i = 0; aliased_jvm_flags[i].alias_name != nullptr; i++) { 638 const AliasedFlag& flag_status = aliased_jvm_flags[i]; 639 if (strcmp(flag_status.alias_name, flag_name) == 0) { 640 return flag_status.real_name; 641 } 642 } 643 return flag_name; 644 } 645 646 #ifdef ASSERT 647 static bool lookup_special_flag(const char *flag_name, size_t skip_index) { 648 for (size_t i = 0; special_jvm_flags[i].name != nullptr; i++) { 649 if ((i != skip_index) && (strcmp(special_jvm_flags[i].name, flag_name) == 0)) { 650 return true; 651 } 652 } 653 return false; 654 } 655 656 // Verifies the correctness of the entries in the special_jvm_flags table. 657 // If there is a semantic error (i.e. a bug in the table) such as the obsoletion 658 // version being earlier than the deprecation version, then a warning is issued 659 // and verification fails - by returning false. If it is detected that the table 660 // is out of date, with respect to the current version, then ideally a warning is 661 // issued but verification does not fail. This allows the VM to operate when the 662 // version is first updated, without needing to update all the impacted flags at 663 // the same time. In practice we can't issue the warning immediately when the version 664 // is updated as it occurs for every test and some tests are not prepared to handle 665 // unexpected output - see 8196739. Instead we only check if the table is up-to-date 666 // if the check_globals flag is true, and in addition allow a grace period and only 667 // check for stale flags when we hit build 25 (which is far enough into the 6 month 668 // release cycle that all flag updates should have been processed, whilst still 669 // leaving time to make the change before RDP2). 670 // We use a gtest to call this, passing true, so that we can detect stale flags before 671 // the end of the release cycle. 672 673 static const int SPECIAL_FLAG_VALIDATION_BUILD = 25; 674 675 bool Arguments::verify_special_jvm_flags(bool check_globals) { 676 bool success = true; 677 for (size_t i = 0; special_jvm_flags[i].name != nullptr; i++) { 678 const SpecialFlag& flag = special_jvm_flags[i]; 679 if (lookup_special_flag(flag.name, i)) { 680 warning("Duplicate special flag declaration \"%s\"", flag.name); 681 success = false; 682 } 683 if (flag.deprecated_in.is_undefined() && 684 flag.obsolete_in.is_undefined()) { 685 warning("Special flag entry \"%s\" must declare version deprecated and/or obsoleted in.", flag.name); 686 success = false; 687 } 688 689 if (!flag.deprecated_in.is_undefined()) { 690 if (!version_less_than(flag.deprecated_in, flag.obsolete_in)) { 691 warning("Special flag entry \"%s\" must be deprecated before obsoleted.", flag.name); 692 success = false; 693 } 694 695 if (!version_less_than(flag.deprecated_in, flag.expired_in)) { 696 warning("Special flag entry \"%s\" must be deprecated before expired.", flag.name); 697 success = false; 698 } 699 } 700 701 if (!flag.obsolete_in.is_undefined()) { 702 if (!version_less_than(flag.obsolete_in, flag.expired_in)) { 703 warning("Special flag entry \"%s\" must be obsoleted before expired.", flag.name); 704 success = false; 705 } 706 707 // if flag has become obsolete it should not have a "globals" flag defined anymore. 708 if (check_globals && VM_Version::vm_build_number() >= SPECIAL_FLAG_VALIDATION_BUILD && 709 !version_less_than(JDK_Version::current(), flag.obsolete_in)) { 710 if (JVMFlag::find_declared_flag(flag.name) != nullptr) { 711 warning("Global variable for obsolete special flag entry \"%s\" should be removed", flag.name); 712 success = false; 713 } 714 } 715 716 } else if (!flag.expired_in.is_undefined()) { 717 warning("Special flag entry \"%s\" must be explicitly obsoleted before expired.", flag.name); 718 success = false; 719 } 720 721 if (!flag.expired_in.is_undefined()) { 722 // if flag has become expired it should not have a "globals" flag defined anymore. 723 if (check_globals && VM_Version::vm_build_number() >= SPECIAL_FLAG_VALIDATION_BUILD && 724 !version_less_than(JDK_Version::current(), flag.expired_in)) { 725 if (JVMFlag::find_declared_flag(flag.name) != nullptr) { 726 warning("Global variable for expired flag entry \"%s\" should be removed", flag.name); 727 success = false; 728 } 729 } 730 } 731 } 732 return success; 733 } 734 #endif 735 736 bool Arguments::atojulong(const char *s, julong* result) { 737 return parse_integer(s, result); 738 } 739 740 Arguments::ArgsRange Arguments::check_memory_size(julong size, julong min_size, julong max_size) { 741 if (size < min_size) return arg_too_small; 742 if (size > max_size) return arg_too_big; 743 return arg_in_range; 744 } 745 746 // Describe an argument out of range error 747 void Arguments::describe_range_error(ArgsRange errcode) { 748 switch(errcode) { 749 case arg_too_big: 750 jio_fprintf(defaultStream::error_stream(), 751 "The specified size exceeds the maximum " 752 "representable size.\n"); 753 break; 754 case arg_too_small: 755 case arg_unreadable: 756 case arg_in_range: 757 // do nothing for now 758 break; 759 default: 760 ShouldNotReachHere(); 761 } 762 } 763 764 static bool set_bool_flag(JVMFlag* flag, bool value, JVMFlagOrigin origin) { 765 if (JVMFlagAccess::set_bool(flag, &value, origin) == JVMFlag::SUCCESS) { 766 return true; 767 } else { 768 return false; 769 } 770 } 771 772 static bool set_fp_numeric_flag(JVMFlag* flag, const char* value, JVMFlagOrigin origin) { 773 // strtod allows leading whitespace, but our flag format does not. 774 if (*value == '\0' || isspace((unsigned char) *value)) { 775 return false; 776 } 777 char* end; 778 errno = 0; 779 double v = strtod(value, &end); 780 if ((errno != 0) || (*end != 0)) { 781 return false; 782 } 783 if (g_isnan(v) || !g_isfinite(v)) { 784 // Currently we cannot handle these special values. 785 return false; 786 } 787 788 if (JVMFlagAccess::set_double(flag, &v, origin) == JVMFlag::SUCCESS) { 789 return true; 790 } 791 return false; 792 } 793 794 static bool set_numeric_flag(JVMFlag* flag, const char* value, JVMFlagOrigin origin) { 795 JVMFlag::Error result = JVMFlag::WRONG_FORMAT; 796 797 if (flag->is_int()) { 798 int v; 799 if (parse_integer(value, &v)) { 800 result = JVMFlagAccess::set_int(flag, &v, origin); 801 } 802 } else if (flag->is_uint()) { 803 uint v; 804 if (parse_integer(value, &v)) { 805 result = JVMFlagAccess::set_uint(flag, &v, origin); 806 } 807 } else if (flag->is_intx()) { 808 intx v; 809 if (parse_integer(value, &v)) { 810 result = JVMFlagAccess::set_intx(flag, &v, origin); 811 } 812 } else if (flag->is_uintx()) { 813 uintx v; 814 if (parse_integer(value, &v)) { 815 result = JVMFlagAccess::set_uintx(flag, &v, origin); 816 } 817 } else if (flag->is_uint64_t()) { 818 uint64_t v; 819 if (parse_integer(value, &v)) { 820 result = JVMFlagAccess::set_uint64_t(flag, &v, origin); 821 } 822 } else if (flag->is_size_t()) { 823 size_t v; 824 if (parse_integer(value, &v)) { 825 result = JVMFlagAccess::set_size_t(flag, &v, origin); 826 } 827 } 828 829 return result == JVMFlag::SUCCESS; 830 } 831 832 static bool set_string_flag(JVMFlag* flag, const char* value, JVMFlagOrigin origin) { 833 if (value[0] == '\0') { 834 value = nullptr; 835 } 836 if (JVMFlagAccess::set_ccstr(flag, &value, origin) != JVMFlag::SUCCESS) return false; 837 // Contract: JVMFlag always returns a pointer that needs freeing. 838 FREE_C_HEAP_ARRAY(char, value); 839 return true; 840 } 841 842 static bool append_to_string_flag(JVMFlag* flag, const char* new_value, JVMFlagOrigin origin) { 843 const char* old_value = ""; 844 if (JVMFlagAccess::get_ccstr(flag, &old_value) != JVMFlag::SUCCESS) return false; 845 size_t old_len = old_value != nullptr ? strlen(old_value) : 0; 846 size_t new_len = strlen(new_value); 847 const char* value; 848 char* free_this_too = nullptr; 849 if (old_len == 0) { 850 value = new_value; 851 } else if (new_len == 0) { 852 value = old_value; 853 } else { 854 size_t length = old_len + 1 + new_len + 1; 855 char* buf = NEW_C_HEAP_ARRAY(char, length, mtArguments); 856 // each new setting adds another LINE to the switch: 857 jio_snprintf(buf, length, "%s\n%s", old_value, new_value); 858 value = buf; 859 free_this_too = buf; 860 } 861 (void) JVMFlagAccess::set_ccstr(flag, &value, origin); 862 // JVMFlag always returns a pointer that needs freeing. 863 FREE_C_HEAP_ARRAY(char, value); 864 // JVMFlag made its own copy, so I must delete my own temp. buffer. 865 FREE_C_HEAP_ARRAY(char, free_this_too); 866 return true; 867 } 868 869 const char* Arguments::handle_aliases_and_deprecation(const char* arg) { 870 const char* real_name = real_flag_name(arg); 871 JDK_Version since = JDK_Version(); 872 switch (is_deprecated_flag(arg, &since)) { 873 case -1: { 874 // Obsolete or expired, so don't process normally, 875 // but allow for an obsolete flag we're still 876 // temporarily allowing. 877 if (!is_obsolete_flag(arg, &since)) { 878 return real_name; 879 } 880 // Note if we're not considered obsolete then we can't be expired either 881 // as obsoletion must come first. 882 return nullptr; 883 } 884 case 0: 885 return real_name; 886 case 1: { 887 char version[256]; 888 since.to_string(version, sizeof(version)); 889 if (real_name != arg) { 890 warning("Option %s was deprecated in version %s and will likely be removed in a future release. Use option %s instead.", 891 arg, version, real_name); 892 } else { 893 warning("Option %s was deprecated in version %s and will likely be removed in a future release.", 894 arg, version); 895 } 896 return real_name; 897 } 898 } 899 ShouldNotReachHere(); 900 return nullptr; 901 } 902 903 #define BUFLEN 255 904 905 JVMFlag* Arguments::find_jvm_flag(const char* name, size_t name_length) { 906 char name_copied[BUFLEN+1]; 907 if (name[name_length] != 0) { 908 if (name_length > BUFLEN) { 909 return nullptr; 910 } else { 911 strncpy(name_copied, name, name_length); 912 name_copied[name_length] = '\0'; 913 name = name_copied; 914 } 915 } 916 917 const char* real_name = Arguments::handle_aliases_and_deprecation(name); 918 if (real_name == nullptr) { 919 return nullptr; 920 } 921 JVMFlag* flag = JVMFlag::find_flag(real_name); 922 return flag; 923 } 924 925 bool Arguments::parse_argument(const char* arg, JVMFlagOrigin origin) { 926 bool is_bool = false; 927 bool bool_val = false; 928 char c = *arg; 929 if (c == '+' || c == '-') { 930 is_bool = true; 931 bool_val = (c == '+'); 932 arg++; 933 } 934 935 const char* name = arg; 936 while (true) { 937 c = *arg; 938 if (isalnum(c) || (c == '_')) { 939 ++arg; 940 } else { 941 break; 942 } 943 } 944 945 size_t name_len = size_t(arg - name); 946 if (name_len == 0) { 947 return false; 948 } 949 950 JVMFlag* flag = find_jvm_flag(name, name_len); 951 if (flag == nullptr) { 952 return false; 953 } 954 955 if (is_bool) { 956 if (*arg != 0) { 957 // Error -- extra characters such as -XX:+BoolFlag=123 958 return false; 959 } 960 return set_bool_flag(flag, bool_val, origin); 961 } 962 963 if (arg[0] == '=') { 964 const char* value = arg + 1; 965 if (flag->is_ccstr()) { 966 if (flag->ccstr_accumulates()) { 967 return append_to_string_flag(flag, value, origin); 968 } else { 969 return set_string_flag(flag, value, origin); 970 } 971 } else if (flag->is_double()) { 972 return set_fp_numeric_flag(flag, value, origin); 973 } else { 974 return set_numeric_flag(flag, value, origin); 975 } 976 } 977 978 if (arg[0] == ':' && arg[1] == '=') { 979 // -XX:Foo:=xxx will reset the string flag to the given value. 980 const char* value = arg + 2; 981 return set_string_flag(flag, value, origin); 982 } 983 984 return false; 985 } 986 987 void Arguments::add_string(char*** bldarray, int* count, const char* arg) { 988 assert(bldarray != nullptr, "illegal argument"); 989 990 if (arg == nullptr) { 991 return; 992 } 993 994 int new_count = *count + 1; 995 996 // expand the array and add arg to the last element 997 if (*bldarray == nullptr) { 998 *bldarray = NEW_C_HEAP_ARRAY(char*, new_count, mtArguments); 999 } else { 1000 *bldarray = REALLOC_C_HEAP_ARRAY(char*, *bldarray, new_count, mtArguments); 1001 } 1002 (*bldarray)[*count] = os::strdup_check_oom(arg); 1003 *count = new_count; 1004 } 1005 1006 void Arguments::build_jvm_args(const char* arg) { 1007 add_string(&_jvm_args_array, &_num_jvm_args, arg); 1008 } 1009 1010 void Arguments::build_jvm_flags(const char* arg) { 1011 add_string(&_jvm_flags_array, &_num_jvm_flags, arg); 1012 } 1013 1014 // utility function to return a string that concatenates all 1015 // strings in a given char** array 1016 const char* Arguments::build_resource_string(char** args, int count) { 1017 if (args == nullptr || count == 0) { 1018 return nullptr; 1019 } 1020 size_t length = 0; 1021 for (int i = 0; i < count; i++) { 1022 length += strlen(args[i]) + 1; // add 1 for a space or null terminating character 1023 } 1024 char* s = NEW_RESOURCE_ARRAY(char, length); 1025 char* dst = s; 1026 for (int j = 0; j < count; j++) { 1027 size_t offset = strlen(args[j]) + 1; // add 1 for a space or null terminating character 1028 jio_snprintf(dst, length, "%s ", args[j]); // jio_snprintf will replace the last space character with null character 1029 dst += offset; 1030 length -= offset; 1031 } 1032 return (const char*) s; 1033 } 1034 1035 void Arguments::print_on(outputStream* st) { 1036 st->print_cr("VM Arguments:"); 1037 if (num_jvm_flags() > 0) { 1038 st->print("jvm_flags: "); print_jvm_flags_on(st); 1039 st->cr(); 1040 } 1041 if (num_jvm_args() > 0) { 1042 st->print("jvm_args: "); print_jvm_args_on(st); 1043 st->cr(); 1044 } 1045 st->print_cr("java_command: %s", java_command() ? java_command() : "<unknown>"); 1046 if (_java_class_path != nullptr) { 1047 char* path = _java_class_path->value(); 1048 size_t len = strlen(path); 1049 st->print("java_class_path (initial): "); 1050 // Avoid using st->print_cr() because path length maybe longer than O_BUFLEN. 1051 if (len == 0) { 1052 st->print_raw_cr("<not set>"); 1053 } else { 1054 st->print_raw_cr(path, len); 1055 } 1056 } 1057 st->print_cr("Launcher Type: %s", _sun_java_launcher); 1058 } 1059 1060 void Arguments::print_summary_on(outputStream* st) { 1061 // Print the command line. Environment variables that are helpful for 1062 // reproducing the problem are written later in the hs_err file. 1063 // flags are from setting file 1064 if (num_jvm_flags() > 0) { 1065 st->print_raw("Settings File: "); 1066 print_jvm_flags_on(st); 1067 st->cr(); 1068 } 1069 // args are the command line and environment variable arguments. 1070 st->print_raw("Command Line: "); 1071 if (num_jvm_args() > 0) { 1072 print_jvm_args_on(st); 1073 } 1074 // this is the classfile and any arguments to the java program 1075 if (java_command() != nullptr) { 1076 st->print("%s", java_command()); 1077 } 1078 st->cr(); 1079 } 1080 1081 void Arguments::print_jvm_flags_on(outputStream* st) { 1082 if (_num_jvm_flags > 0) { 1083 for (int i=0; i < _num_jvm_flags; i++) { 1084 st->print("%s ", _jvm_flags_array[i]); 1085 } 1086 } 1087 } 1088 1089 void Arguments::print_jvm_args_on(outputStream* st) { 1090 if (_num_jvm_args > 0) { 1091 for (int i=0; i < _num_jvm_args; i++) { 1092 st->print("%s ", _jvm_args_array[i]); 1093 } 1094 } 1095 } 1096 1097 bool Arguments::process_argument(const char* arg, 1098 jboolean ignore_unrecognized, 1099 JVMFlagOrigin origin) { 1100 JDK_Version since = JDK_Version(); 1101 1102 if (parse_argument(arg, origin)) { 1103 return true; 1104 } 1105 1106 // Determine if the flag has '+', '-', or '=' characters. 1107 bool has_plus_minus = (*arg == '+' || *arg == '-'); 1108 const char* const argname = has_plus_minus ? arg + 1 : arg; 1109 1110 size_t arg_len; 1111 const char* equal_sign = strchr(argname, '='); 1112 if (equal_sign == nullptr) { 1113 arg_len = strlen(argname); 1114 } else { 1115 arg_len = equal_sign - argname; 1116 } 1117 1118 // Only make the obsolete check for valid arguments. 1119 if (arg_len <= BUFLEN) { 1120 // Construct a string which consists only of the argument name without '+', '-', or '='. 1121 char stripped_argname[BUFLEN+1]; // +1 for '\0' 1122 jio_snprintf(stripped_argname, arg_len+1, "%s", argname); // +1 for '\0' 1123 if (is_obsolete_flag(stripped_argname, &since)) { 1124 char version[256]; 1125 since.to_string(version, sizeof(version)); 1126 warning("Ignoring option %s; support was removed in %s", stripped_argname, version); 1127 return true; 1128 } 1129 } 1130 1131 // For locked flags, report a custom error message if available. 1132 // Otherwise, report the standard unrecognized VM option. 1133 const JVMFlag* found_flag = JVMFlag::find_declared_flag((const char*)argname, arg_len); 1134 if (found_flag != nullptr) { 1135 char locked_message_buf[BUFLEN]; 1136 JVMFlag::MsgType msg_type = found_flag->get_locked_message(locked_message_buf, BUFLEN); 1137 if (strlen(locked_message_buf) != 0) { 1138 #ifdef PRODUCT 1139 bool mismatched = msg_type == JVMFlag::DEVELOPER_FLAG_BUT_PRODUCT_BUILD; 1140 if (ignore_unrecognized && mismatched) { 1141 return true; 1142 } 1143 #endif 1144 jio_fprintf(defaultStream::error_stream(), "%s", locked_message_buf); 1145 } 1146 if (found_flag->is_bool() && !has_plus_minus) { 1147 jio_fprintf(defaultStream::error_stream(), 1148 "Missing +/- setting for VM option '%s'\n", argname); 1149 } else if (!found_flag->is_bool() && has_plus_minus) { 1150 jio_fprintf(defaultStream::error_stream(), 1151 "Unexpected +/- setting in VM option '%s'\n", argname); 1152 } else { 1153 jio_fprintf(defaultStream::error_stream(), 1154 "Improperly specified VM option '%s'\n", argname); 1155 } 1156 } else { 1157 if (ignore_unrecognized) { 1158 return true; 1159 } 1160 jio_fprintf(defaultStream::error_stream(), 1161 "Unrecognized VM option '%s'\n", argname); 1162 JVMFlag* fuzzy_matched = JVMFlag::fuzzy_match((const char*)argname, arg_len, true); 1163 if (fuzzy_matched != nullptr) { 1164 jio_fprintf(defaultStream::error_stream(), 1165 "Did you mean '%s%s%s'?\n", 1166 (fuzzy_matched->is_bool()) ? "(+/-)" : "", 1167 fuzzy_matched->name(), 1168 (fuzzy_matched->is_bool()) ? "" : "=<value>"); 1169 } 1170 } 1171 1172 // allow for commandline "commenting out" options like -XX:#+Verbose 1173 return arg[0] == '#'; 1174 } 1175 1176 bool Arguments::process_settings_file(const char* file_name, bool should_exist, jboolean ignore_unrecognized) { 1177 FILE* stream = os::fopen(file_name, "rb"); 1178 if (stream == nullptr) { 1179 if (should_exist) { 1180 jio_fprintf(defaultStream::error_stream(), 1181 "Could not open settings file %s\n", file_name); 1182 return false; 1183 } else { 1184 return true; 1185 } 1186 } 1187 1188 char token[1024]; 1189 int pos = 0; 1190 1191 bool in_white_space = true; 1192 bool in_comment = false; 1193 bool in_quote = false; 1194 int quote_c = 0; 1195 bool result = true; 1196 1197 int c = getc(stream); 1198 while(c != EOF && pos < (int)(sizeof(token)-1)) { 1199 if (in_white_space) { 1200 if (in_comment) { 1201 if (c == '\n') in_comment = false; 1202 } else { 1203 if (c == '#') in_comment = true; 1204 else if (!isspace((unsigned char) c)) { 1205 in_white_space = false; 1206 token[pos++] = checked_cast<char>(c); 1207 } 1208 } 1209 } else { 1210 if (c == '\n' || (!in_quote && isspace((unsigned char) c))) { 1211 // token ends at newline, or at unquoted whitespace 1212 // this allows a way to include spaces in string-valued options 1213 token[pos] = '\0'; 1214 logOption(token); 1215 result &= process_argument(token, ignore_unrecognized, JVMFlagOrigin::CONFIG_FILE); 1216 build_jvm_flags(token); 1217 pos = 0; 1218 in_white_space = true; 1219 in_quote = false; 1220 } else if (!in_quote && (c == '\'' || c == '"')) { 1221 in_quote = true; 1222 quote_c = c; 1223 } else if (in_quote && (c == quote_c)) { 1224 in_quote = false; 1225 } else { 1226 token[pos++] = checked_cast<char>(c); 1227 } 1228 } 1229 c = getc(stream); 1230 } 1231 if (pos > 0) { 1232 token[pos] = '\0'; 1233 result &= process_argument(token, ignore_unrecognized, JVMFlagOrigin::CONFIG_FILE); 1234 build_jvm_flags(token); 1235 } 1236 fclose(stream); 1237 return result; 1238 } 1239 1240 //============================================================================================================= 1241 // Parsing of properties (-D) 1242 1243 const char* Arguments::get_property(const char* key) { 1244 return PropertyList_get_value(system_properties(), key); 1245 } 1246 1247 bool Arguments::add_property(const char* prop, PropertyWriteable writeable, PropertyInternal internal) { 1248 const char* eq = strchr(prop, '='); 1249 const char* key; 1250 const char* value = ""; 1251 1252 if (eq == nullptr) { 1253 // property doesn't have a value, thus use passed string 1254 key = prop; 1255 } else { 1256 // property have a value, thus extract it and save to the 1257 // allocated string 1258 size_t key_len = eq - prop; 1259 char* tmp_key = AllocateHeap(key_len + 1, mtArguments); 1260 1261 jio_snprintf(tmp_key, key_len + 1, "%s", prop); 1262 key = tmp_key; 1263 1264 value = &prop[key_len + 1]; 1265 } 1266 1267 if (internal == ExternalProperty) { 1268 CDSConfig::check_incompatible_property(key, value); 1269 } 1270 1271 if (strcmp(key, "java.compiler") == 0) { 1272 // we no longer support java.compiler system property, log a warning and let it get 1273 // passed to Java, like any other system property 1274 if (strlen(value) == 0 || strcasecmp(value, "NONE") == 0) { 1275 // for applications using NONE or empty value, log a more informative message 1276 warning("The java.compiler system property is obsolete and no longer supported, use -Xint"); 1277 } else { 1278 warning("The java.compiler system property is obsolete and no longer supported."); 1279 } 1280 } else if (strcmp(key, "sun.java.launcher.is_altjvm") == 0) { 1281 // sun.java.launcher.is_altjvm property is 1282 // private and is processed in process_sun_java_launcher_properties(); 1283 // the sun.java.launcher property is passed on to the java application 1284 } else if (strcmp(key, "sun.boot.library.path") == 0) { 1285 // append is true, writable is true, internal is false 1286 PropertyList_unique_add(&_system_properties, key, value, AppendProperty, 1287 WriteableProperty, ExternalProperty); 1288 } else { 1289 if (strcmp(key, "sun.java.command") == 0) { 1290 char *old_java_command = _java_command; 1291 _java_command = os::strdup_check_oom(value, mtArguments); 1292 if (old_java_command != nullptr) { 1293 os::free(old_java_command); 1294 } 1295 } else if (strcmp(key, "java.vendor.url.bug") == 0) { 1296 // If this property is set on the command line then its value will be 1297 // displayed in VM error logs as the URL at which to submit such logs. 1298 // Normally the URL displayed in error logs is different from the value 1299 // of this system property, so a different property should have been 1300 // used here, but we leave this as-is in case someone depends upon it. 1301 const char* old_java_vendor_url_bug = _java_vendor_url_bug; 1302 // save it in _java_vendor_url_bug, so JVM fatal error handler can access 1303 // its value without going through the property list or making a Java call. 1304 _java_vendor_url_bug = os::strdup_check_oom(value, mtArguments); 1305 if (old_java_vendor_url_bug != nullptr) { 1306 os::free((void *)old_java_vendor_url_bug); 1307 } 1308 } 1309 1310 // Create new property and add at the end of the list 1311 PropertyList_unique_add(&_system_properties, key, value, AddProperty, writeable, internal); 1312 } 1313 1314 if (key != prop) { 1315 // SystemProperty copy passed value, thus free previously allocated 1316 // memory 1317 FreeHeap((void *)key); 1318 } 1319 1320 return true; 1321 } 1322 1323 //=========================================================================================================== 1324 // Setting int/mixed/comp mode flags 1325 1326 void Arguments::set_mode_flags(Mode mode) { 1327 // Set up default values for all flags. 1328 // If you add a flag to any of the branches below, 1329 // add a default value for it here. 1330 _mode = mode; 1331 1332 // Ensure Agent_OnLoad has the correct initial values. 1333 // This may not be the final mode; mode may change later in onload phase. 1334 PropertyList_unique_add(&_system_properties, "java.vm.info", 1335 VM_Version::vm_info_string(), AddProperty, UnwriteableProperty, ExternalProperty); 1336 1337 UseInterpreter = true; 1338 UseCompiler = true; 1339 UseLoopCounter = true; 1340 1341 // Default values may be platform/compiler dependent - 1342 // use the saved values 1343 ClipInlining = Arguments::_ClipInlining; 1344 AlwaysCompileLoopMethods = Arguments::_AlwaysCompileLoopMethods; 1345 UseOnStackReplacement = Arguments::_UseOnStackReplacement; 1346 BackgroundCompilation = Arguments::_BackgroundCompilation; 1347 1348 // Change from defaults based on mode 1349 switch (mode) { 1350 default: 1351 ShouldNotReachHere(); 1352 break; 1353 case _int: 1354 UseCompiler = false; 1355 UseLoopCounter = false; 1356 AlwaysCompileLoopMethods = false; 1357 UseOnStackReplacement = false; 1358 break; 1359 case _mixed: 1360 // same as default 1361 break; 1362 case _comp: 1363 UseInterpreter = false; 1364 BackgroundCompilation = false; 1365 ClipInlining = false; 1366 break; 1367 } 1368 } 1369 1370 // Conflict: required to use shared spaces (-Xshare:on), but 1371 // incompatible command line options were chosen. 1372 void Arguments::no_shared_spaces(const char* message) { 1373 if (RequireSharedSpaces) { 1374 jio_fprintf(defaultStream::error_stream(), 1375 "Class data sharing is inconsistent with other specified options.\n"); 1376 vm_exit_during_initialization("Unable to use shared archive", message); 1377 } else { 1378 log_info(cds)("Unable to use shared archive: %s", message); 1379 UseSharedSpaces = false; 1380 } 1381 } 1382 1383 static void set_object_alignment() { 1384 // Object alignment. 1385 assert(is_power_of_2(ObjectAlignmentInBytes), "ObjectAlignmentInBytes must be power of 2"); 1386 MinObjAlignmentInBytes = ObjectAlignmentInBytes; 1387 assert(MinObjAlignmentInBytes >= HeapWordsPerLong * HeapWordSize, "ObjectAlignmentInBytes value is too small"); 1388 MinObjAlignment = MinObjAlignmentInBytes / HeapWordSize; 1389 assert(MinObjAlignmentInBytes == MinObjAlignment * HeapWordSize, "ObjectAlignmentInBytes value is incorrect"); 1390 MinObjAlignmentInBytesMask = MinObjAlignmentInBytes - 1; 1391 1392 LogMinObjAlignmentInBytes = exact_log2(ObjectAlignmentInBytes); 1393 LogMinObjAlignment = LogMinObjAlignmentInBytes - LogHeapWordSize; 1394 1395 // Oop encoding heap max 1396 OopEncodingHeapMax = (uint64_t(max_juint) + 1) << LogMinObjAlignmentInBytes; 1397 } 1398 1399 size_t Arguments::max_heap_for_compressed_oops() { 1400 // Avoid sign flip. 1401 assert(OopEncodingHeapMax > (uint64_t)os::vm_page_size(), "Unusual page size"); 1402 // We need to fit both the null page and the heap into the memory budget, while 1403 // keeping alignment constraints of the heap. To guarantee the latter, as the 1404 // null page is located before the heap, we pad the null page to the conservative 1405 // maximum alignment that the GC may ever impose upon the heap. 1406 size_t displacement_due_to_null_page = align_up(os::vm_page_size(), 1407 _conservative_max_heap_alignment); 1408 1409 LP64_ONLY(return OopEncodingHeapMax - displacement_due_to_null_page); 1410 NOT_LP64(ShouldNotReachHere(); return 0); 1411 } 1412 1413 void Arguments::set_use_compressed_oops() { 1414 #ifdef _LP64 1415 // MaxHeapSize is not set up properly at this point, but 1416 // the only value that can override MaxHeapSize if we are 1417 // to use UseCompressedOops are InitialHeapSize and MinHeapSize. 1418 size_t max_heap_size = MAX3(MaxHeapSize, InitialHeapSize, MinHeapSize); 1419 1420 if (max_heap_size <= max_heap_for_compressed_oops()) { 1421 if (FLAG_IS_DEFAULT(UseCompressedOops)) { 1422 FLAG_SET_ERGO(UseCompressedOops, true); 1423 } 1424 } else { 1425 if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) { 1426 warning("Max heap size too large for Compressed Oops"); 1427 FLAG_SET_DEFAULT(UseCompressedOops, false); 1428 } 1429 } 1430 #endif // _LP64 1431 } 1432 1433 void Arguments::set_use_compressed_klass_ptrs() { 1434 #ifdef _LP64 1435 assert(!UseCompressedClassPointers || CompressedClassSpaceSize <= KlassEncodingMetaspaceMax, 1436 "CompressedClassSpaceSize is too large for UseCompressedClassPointers"); 1437 #endif // _LP64 1438 } 1439 1440 void Arguments::set_conservative_max_heap_alignment() { 1441 // The conservative maximum required alignment for the heap is the maximum of 1442 // the alignments imposed by several sources: any requirements from the heap 1443 // itself and the maximum page size we may run the VM with. 1444 size_t heap_alignment = GCConfig::arguments()->conservative_max_heap_alignment(); 1445 _conservative_max_heap_alignment = MAX4(heap_alignment, 1446 os::vm_allocation_granularity(), 1447 os::max_page_size(), 1448 GCArguments::compute_heap_alignment()); 1449 } 1450 1451 jint Arguments::set_ergonomics_flags() { 1452 GCConfig::initialize(); 1453 1454 set_conservative_max_heap_alignment(); 1455 1456 #ifdef _LP64 1457 set_use_compressed_oops(); 1458 set_use_compressed_klass_ptrs(); 1459 1460 // Also checks that certain machines are slower with compressed oops 1461 // in vm_version initialization code. 1462 #endif // _LP64 1463 1464 return JNI_OK; 1465 } 1466 1467 size_t Arguments::limit_heap_by_allocatable_memory(size_t limit) { 1468 size_t max_allocatable; 1469 size_t result = limit; 1470 if (os::has_allocatable_memory_limit(&max_allocatable)) { 1471 // The AggressiveHeap check is a temporary workaround to avoid calling 1472 // GCarguments::heap_virtual_to_physical_ratio() before a GC has been 1473 // selected. This works because AggressiveHeap implies UseParallelGC 1474 // where we know the ratio will be 1. Once the AggressiveHeap option is 1475 // removed, this can be cleaned up. 1476 size_t heap_virtual_to_physical_ratio = (AggressiveHeap ? 1 : GCConfig::arguments()->heap_virtual_to_physical_ratio()); 1477 size_t fraction = MaxVirtMemFraction * heap_virtual_to_physical_ratio; 1478 result = MIN2(result, max_allocatable / fraction); 1479 } 1480 return result; 1481 } 1482 1483 // Use static initialization to get the default before parsing 1484 static const size_t DefaultHeapBaseMinAddress = HeapBaseMinAddress; 1485 1486 void Arguments::set_heap_size() { 1487 julong phys_mem; 1488 1489 // If the user specified one of these options, they 1490 // want specific memory sizing so do not limit memory 1491 // based on compressed oops addressability. 1492 // Also, memory limits will be calculated based on 1493 // available os physical memory, not our MaxRAM limit, 1494 // unless MaxRAM is also specified. 1495 bool override_coop_limit = (!FLAG_IS_DEFAULT(MaxRAMPercentage) || 1496 !FLAG_IS_DEFAULT(MinRAMPercentage) || 1497 !FLAG_IS_DEFAULT(InitialRAMPercentage) || 1498 !FLAG_IS_DEFAULT(MaxRAM)); 1499 if (override_coop_limit) { 1500 if (FLAG_IS_DEFAULT(MaxRAM)) { 1501 phys_mem = os::physical_memory(); 1502 FLAG_SET_ERGO(MaxRAM, (uint64_t)phys_mem); 1503 } else { 1504 phys_mem = (julong)MaxRAM; 1505 } 1506 } else { 1507 phys_mem = FLAG_IS_DEFAULT(MaxRAM) ? MIN2(os::physical_memory(), (julong)MaxRAM) 1508 : (julong)MaxRAM; 1509 } 1510 1511 // If the maximum heap size has not been set with -Xmx, 1512 // then set it as fraction of the size of physical memory, 1513 // respecting the maximum and minimum sizes of the heap. 1514 if (FLAG_IS_DEFAULT(MaxHeapSize)) { 1515 julong reasonable_max = (julong)(((double)phys_mem * MaxRAMPercentage) / 100); 1516 const julong reasonable_min = (julong)(((double)phys_mem * MinRAMPercentage) / 100); 1517 if (reasonable_min < MaxHeapSize) { 1518 // Small physical memory, so use a minimum fraction of it for the heap 1519 reasonable_max = reasonable_min; 1520 } else { 1521 // Not-small physical memory, so require a heap at least 1522 // as large as MaxHeapSize 1523 reasonable_max = MAX2(reasonable_max, (julong)MaxHeapSize); 1524 } 1525 1526 if (!FLAG_IS_DEFAULT(ErgoHeapSizeLimit) && ErgoHeapSizeLimit != 0) { 1527 // Limit the heap size to ErgoHeapSizeLimit 1528 reasonable_max = MIN2(reasonable_max, (julong)ErgoHeapSizeLimit); 1529 } 1530 1531 reasonable_max = limit_heap_by_allocatable_memory(reasonable_max); 1532 1533 if (!FLAG_IS_DEFAULT(InitialHeapSize)) { 1534 // An initial heap size was specified on the command line, 1535 // so be sure that the maximum size is consistent. Done 1536 // after call to limit_heap_by_allocatable_memory because that 1537 // method might reduce the allocation size. 1538 reasonable_max = MAX2(reasonable_max, (julong)InitialHeapSize); 1539 } else if (!FLAG_IS_DEFAULT(MinHeapSize)) { 1540 reasonable_max = MAX2(reasonable_max, (julong)MinHeapSize); 1541 } 1542 1543 #ifdef _LP64 1544 if (UseCompressedOops || UseCompressedClassPointers) { 1545 // HeapBaseMinAddress can be greater than default but not less than. 1546 if (!FLAG_IS_DEFAULT(HeapBaseMinAddress)) { 1547 if (HeapBaseMinAddress < DefaultHeapBaseMinAddress) { 1548 // matches compressed oops printing flags 1549 log_debug(gc, heap, coops)("HeapBaseMinAddress must be at least " SIZE_FORMAT 1550 " (" SIZE_FORMAT "G) which is greater than value given " SIZE_FORMAT, 1551 DefaultHeapBaseMinAddress, 1552 DefaultHeapBaseMinAddress/G, 1553 HeapBaseMinAddress); 1554 FLAG_SET_ERGO(HeapBaseMinAddress, DefaultHeapBaseMinAddress); 1555 } 1556 } 1557 } 1558 if (UseCompressedOops) { 1559 // Limit the heap size to the maximum possible when using compressed oops 1560 julong max_coop_heap = (julong)max_heap_for_compressed_oops(); 1561 1562 if (HeapBaseMinAddress + MaxHeapSize < max_coop_heap) { 1563 // Heap should be above HeapBaseMinAddress to get zero based compressed oops 1564 // but it should be not less than default MaxHeapSize. 1565 max_coop_heap -= HeapBaseMinAddress; 1566 } 1567 1568 // If user specified flags prioritizing os physical 1569 // memory limits, then disable compressed oops if 1570 // limits exceed max_coop_heap and UseCompressedOops 1571 // was not specified. 1572 if (reasonable_max > max_coop_heap) { 1573 if (FLAG_IS_ERGO(UseCompressedOops) && override_coop_limit) { 1574 log_info(cds)("UseCompressedOops and UseCompressedClassPointers have been disabled due to" 1575 " max heap " SIZE_FORMAT " > compressed oop heap " SIZE_FORMAT ". " 1576 "Please check the setting of MaxRAMPercentage %5.2f." 1577 ,(size_t)reasonable_max, (size_t)max_coop_heap, MaxRAMPercentage); 1578 FLAG_SET_ERGO(UseCompressedOops, false); 1579 } else { 1580 reasonable_max = MIN2(reasonable_max, max_coop_heap); 1581 } 1582 } 1583 } 1584 #endif // _LP64 1585 1586 log_trace(gc, heap)(" Maximum heap size " SIZE_FORMAT, (size_t) reasonable_max); 1587 FLAG_SET_ERGO(MaxHeapSize, (size_t)reasonable_max); 1588 } 1589 1590 // If the minimum or initial heap_size have not been set or requested to be set 1591 // ergonomically, set them accordingly. 1592 if (InitialHeapSize == 0 || MinHeapSize == 0) { 1593 julong reasonable_minimum = (julong)(OldSize + NewSize); 1594 1595 reasonable_minimum = MIN2(reasonable_minimum, (julong)MaxHeapSize); 1596 1597 reasonable_minimum = limit_heap_by_allocatable_memory(reasonable_minimum); 1598 1599 if (InitialHeapSize == 0) { 1600 julong reasonable_initial = (julong)(((double)phys_mem * InitialRAMPercentage) / 100); 1601 reasonable_initial = limit_heap_by_allocatable_memory(reasonable_initial); 1602 1603 reasonable_initial = MAX3(reasonable_initial, reasonable_minimum, (julong)MinHeapSize); 1604 reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize); 1605 1606 FLAG_SET_ERGO(InitialHeapSize, (size_t)reasonable_initial); 1607 log_trace(gc, heap)(" Initial heap size " SIZE_FORMAT, InitialHeapSize); 1608 } 1609 // If the minimum heap size has not been set (via -Xms or -XX:MinHeapSize), 1610 // synchronize with InitialHeapSize to avoid errors with the default value. 1611 if (MinHeapSize == 0) { 1612 FLAG_SET_ERGO(MinHeapSize, MIN2((size_t)reasonable_minimum, InitialHeapSize)); 1613 log_trace(gc, heap)(" Minimum heap size " SIZE_FORMAT, MinHeapSize); 1614 } 1615 } 1616 } 1617 1618 // This option inspects the machine and attempts to set various 1619 // parameters to be optimal for long-running, memory allocation 1620 // intensive jobs. It is intended for machines with large 1621 // amounts of cpu and memory. 1622 jint Arguments::set_aggressive_heap_flags() { 1623 // initHeapSize is needed since _initial_heap_size is 4 bytes on a 32 bit 1624 // VM, but we may not be able to represent the total physical memory 1625 // available (like having 8gb of memory on a box but using a 32bit VM). 1626 // Thus, we need to make sure we're using a julong for intermediate 1627 // calculations. 1628 julong initHeapSize; 1629 julong total_memory = os::physical_memory(); 1630 1631 if (total_memory < (julong) 256 * M) { 1632 jio_fprintf(defaultStream::error_stream(), 1633 "You need at least 256mb of memory to use -XX:+AggressiveHeap\n"); 1634 vm_exit(1); 1635 } 1636 1637 // The heap size is half of available memory, or (at most) 1638 // all of possible memory less 160mb (leaving room for the OS 1639 // when using ISM). This is the maximum; because adaptive sizing 1640 // is turned on below, the actual space used may be smaller. 1641 1642 initHeapSize = MIN2(total_memory / (julong) 2, 1643 total_memory - (julong) 160 * M); 1644 1645 initHeapSize = limit_heap_by_allocatable_memory(initHeapSize); 1646 1647 if (FLAG_IS_DEFAULT(MaxHeapSize)) { 1648 if (FLAG_SET_CMDLINE(MaxHeapSize, initHeapSize) != JVMFlag::SUCCESS) { 1649 return JNI_EINVAL; 1650 } 1651 if (FLAG_SET_CMDLINE(InitialHeapSize, initHeapSize) != JVMFlag::SUCCESS) { 1652 return JNI_EINVAL; 1653 } 1654 if (FLAG_SET_CMDLINE(MinHeapSize, initHeapSize) != JVMFlag::SUCCESS) { 1655 return JNI_EINVAL; 1656 } 1657 } 1658 if (FLAG_IS_DEFAULT(NewSize)) { 1659 // Make the young generation 3/8ths of the total heap. 1660 if (FLAG_SET_CMDLINE(NewSize, 1661 ((julong) MaxHeapSize / (julong) 8) * (julong) 3) != JVMFlag::SUCCESS) { 1662 return JNI_EINVAL; 1663 } 1664 if (FLAG_SET_CMDLINE(MaxNewSize, NewSize) != JVMFlag::SUCCESS) { 1665 return JNI_EINVAL; 1666 } 1667 } 1668 1669 #if !defined(_ALLBSD_SOURCE) && !defined(AIX) // UseLargePages is not yet supported on BSD and AIX. 1670 FLAG_SET_DEFAULT(UseLargePages, true); 1671 #endif 1672 1673 // Increase some data structure sizes for efficiency 1674 if (FLAG_SET_CMDLINE(ResizeTLAB, false) != JVMFlag::SUCCESS) { 1675 return JNI_EINVAL; 1676 } 1677 if (FLAG_SET_CMDLINE(TLABSize, 256 * K) != JVMFlag::SUCCESS) { 1678 return JNI_EINVAL; 1679 } 1680 1681 // See the OldPLABSize comment below, but replace 'after promotion' 1682 // with 'after copying'. YoungPLABSize is the size of the survivor 1683 // space per-gc-thread buffers. The default is 4kw. 1684 if (FLAG_SET_CMDLINE(YoungPLABSize, 256 * K) != JVMFlag::SUCCESS) { // Note: this is in words 1685 return JNI_EINVAL; 1686 } 1687 1688 // OldPLABSize is the size of the buffers in the old gen that 1689 // UseParallelGC uses to promote live data that doesn't fit in the 1690 // survivor spaces. At any given time, there's one for each gc thread. 1691 // The default size is 1kw. These buffers are rarely used, since the 1692 // survivor spaces are usually big enough. For specjbb, however, there 1693 // are occasions when there's lots of live data in the young gen 1694 // and we end up promoting some of it. We don't have a definite 1695 // explanation for why bumping OldPLABSize helps, but the theory 1696 // is that a bigger PLAB results in retaining something like the 1697 // original allocation order after promotion, which improves mutator 1698 // locality. A minor effect may be that larger PLABs reduce the 1699 // number of PLAB allocation events during gc. The value of 8kw 1700 // was arrived at by experimenting with specjbb. 1701 if (FLAG_SET_CMDLINE(OldPLABSize, 8 * K) != JVMFlag::SUCCESS) { // Note: this is in words 1702 return JNI_EINVAL; 1703 } 1704 1705 // Enable parallel GC and adaptive generation sizing 1706 if (FLAG_SET_CMDLINE(UseParallelGC, true) != JVMFlag::SUCCESS) { 1707 return JNI_EINVAL; 1708 } 1709 1710 // Encourage steady state memory management 1711 if (FLAG_SET_CMDLINE(ThresholdTolerance, 100) != JVMFlag::SUCCESS) { 1712 return JNI_EINVAL; 1713 } 1714 1715 return JNI_OK; 1716 } 1717 1718 // This must be called after ergonomics. 1719 void Arguments::set_bytecode_flags() { 1720 if (!RewriteBytecodes) { 1721 FLAG_SET_DEFAULT(RewriteFrequentPairs, false); 1722 } 1723 } 1724 1725 // Aggressive optimization flags 1726 jint Arguments::set_aggressive_opts_flags() { 1727 #ifdef COMPILER2 1728 if (AggressiveUnboxing) { 1729 if (FLAG_IS_DEFAULT(EliminateAutoBox)) { 1730 FLAG_SET_DEFAULT(EliminateAutoBox, true); 1731 } else if (!EliminateAutoBox) { 1732 // warning("AggressiveUnboxing is disabled because EliminateAutoBox is disabled"); 1733 AggressiveUnboxing = false; 1734 } 1735 if (FLAG_IS_DEFAULT(DoEscapeAnalysis)) { 1736 FLAG_SET_DEFAULT(DoEscapeAnalysis, true); 1737 } else if (!DoEscapeAnalysis) { 1738 // warning("AggressiveUnboxing is disabled because DoEscapeAnalysis is disabled"); 1739 AggressiveUnboxing = false; 1740 } 1741 } 1742 if (!FLAG_IS_DEFAULT(AutoBoxCacheMax)) { 1743 if (FLAG_IS_DEFAULT(EliminateAutoBox)) { 1744 FLAG_SET_DEFAULT(EliminateAutoBox, true); 1745 } 1746 // Feed the cache size setting into the JDK 1747 char buffer[1024]; 1748 jio_snprintf(buffer, 1024, "java.lang.Integer.IntegerCache.high=" INTX_FORMAT, AutoBoxCacheMax); 1749 if (!add_property(buffer)) { 1750 return JNI_ENOMEM; 1751 } 1752 } 1753 #endif 1754 1755 return JNI_OK; 1756 } 1757 1758 //=========================================================================================================== 1759 1760 void Arguments::process_java_launcher_argument(const char* launcher, void* extra_info) { 1761 if (_sun_java_launcher != _default_java_launcher) { 1762 os::free(const_cast<char*>(_sun_java_launcher)); 1763 } 1764 _sun_java_launcher = os::strdup_check_oom(launcher); 1765 } 1766 1767 bool Arguments::created_by_java_launcher() { 1768 assert(_sun_java_launcher != nullptr, "property must have value"); 1769 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0; 1770 } 1771 1772 bool Arguments::sun_java_launcher_is_altjvm() { 1773 return _sun_java_launcher_is_altjvm; 1774 } 1775 1776 //=========================================================================================================== 1777 // Parsing of main arguments 1778 1779 unsigned int addreads_count = 0; 1780 unsigned int addexports_count = 0; 1781 unsigned int addopens_count = 0; 1782 unsigned int enable_native_access_count = 0; 1783 1784 // Check the consistency of vm_init_args 1785 bool Arguments::check_vm_args_consistency() { 1786 // Method for adding checks for flag consistency. 1787 // The intent is to warn the user of all possible conflicts, 1788 // before returning an error. 1789 // Note: Needs platform-dependent factoring. 1790 bool status = true; 1791 1792 if (TLABRefillWasteFraction == 0) { 1793 jio_fprintf(defaultStream::error_stream(), 1794 "TLABRefillWasteFraction should be a denominator, " 1795 "not " SIZE_FORMAT "\n", 1796 TLABRefillWasteFraction); 1797 status = false; 1798 } 1799 1800 status = CompilerConfig::check_args_consistency(status); 1801 #if INCLUDE_JVMCI 1802 if (status && EnableJVMCI) { 1803 PropertyList_unique_add(&_system_properties, "jdk.internal.vm.ci.enabled", "true", 1804 AddProperty, UnwriteableProperty, InternalProperty); 1805 if (ClassLoader::is_module_observable("jdk.internal.vm.ci")) { 1806 if (!create_numbered_module_property("jdk.module.addmods", "jdk.internal.vm.ci", _addmods_count++)) { 1807 return false; 1808 } 1809 } 1810 } 1811 #endif 1812 1813 #if INCLUDE_JFR 1814 if (status && (FlightRecorderOptions || StartFlightRecording)) { 1815 if (!create_numbered_module_property("jdk.module.addmods", "jdk.jfr", _addmods_count++)) { 1816 return false; 1817 } 1818 } 1819 #endif 1820 1821 #ifndef SUPPORT_RESERVED_STACK_AREA 1822 if (StackReservedPages != 0) { 1823 FLAG_SET_CMDLINE(StackReservedPages, 0); 1824 warning("Reserved Stack Area not supported on this platform"); 1825 } 1826 #endif 1827 1828 if (UseObjectMonitorTable && LockingMode != LM_LIGHTWEIGHT) { 1829 // ObjectMonitorTable requires lightweight locking. 1830 FLAG_SET_CMDLINE(UseObjectMonitorTable, false); 1831 warning("UseObjectMonitorTable requires LM_LIGHTWEIGHT"); 1832 } 1833 1834 #if !defined(X86) && !defined(AARCH64) && !defined(PPC64) && !defined(RISCV64) && !defined(S390) 1835 if (LockingMode == LM_MONITOR) { 1836 jio_fprintf(defaultStream::error_stream(), 1837 "LockingMode == 0 (LM_MONITOR) is not fully implemented on this architecture\n"); 1838 return false; 1839 } 1840 #endif 1841 if (VerifyHeavyMonitors && LockingMode != LM_MONITOR) { 1842 jio_fprintf(defaultStream::error_stream(), 1843 "-XX:+VerifyHeavyMonitors requires LockingMode == 0 (LM_MONITOR)\n"); 1844 return false; 1845 } 1846 return status; 1847 } 1848 1849 bool Arguments::is_bad_option(const JavaVMOption* option, jboolean ignore, 1850 const char* option_type) { 1851 if (ignore) return false; 1852 1853 const char* spacer = " "; 1854 if (option_type == nullptr) { 1855 option_type = ++spacer; // Set both to the empty string. 1856 } 1857 1858 jio_fprintf(defaultStream::error_stream(), 1859 "Unrecognized %s%soption: %s\n", option_type, spacer, 1860 option->optionString); 1861 return true; 1862 } 1863 1864 static const char* user_assertion_options[] = { 1865 "-da", "-ea", "-disableassertions", "-enableassertions", nullptr 1866 }; 1867 1868 static const char* system_assertion_options[] = { 1869 "-dsa", "-esa", "-disablesystemassertions", "-enablesystemassertions", nullptr 1870 }; 1871 1872 bool Arguments::parse_uint(const char* value, 1873 uint* uint_arg, 1874 uint min_size) { 1875 uint n; 1876 if (!parse_integer(value, &n)) { 1877 return false; 1878 } 1879 if (n >= min_size) { 1880 *uint_arg = n; 1881 return true; 1882 } else { 1883 return false; 1884 } 1885 } 1886 1887 bool Arguments::create_module_property(const char* prop_name, const char* prop_value, PropertyInternal internal) { 1888 assert(is_internal_module_property(prop_name), "unknown module property: '%s'", prop_name); 1889 CDSConfig::check_internal_module_property(prop_name, prop_value); 1890 size_t prop_len = strlen(prop_name) + strlen(prop_value) + 2; 1891 char* property = AllocateHeap(prop_len, mtArguments); 1892 int ret = jio_snprintf(property, prop_len, "%s=%s", prop_name, prop_value); 1893 if (ret < 0 || ret >= (int)prop_len) { 1894 FreeHeap(property); 1895 return false; 1896 } 1897 // These are not strictly writeable properties as they cannot be set via -Dprop=val. But that 1898 // is enforced by checking is_internal_module_property(). We need the property to be writeable so 1899 // that multiple occurrences of the associated flag just causes the existing property value to be 1900 // replaced ("last option wins"). Otherwise we would need to keep track of the flags and only convert 1901 // to a property after we have finished flag processing. 1902 bool added = add_property(property, WriteableProperty, internal); 1903 FreeHeap(property); 1904 return added; 1905 } 1906 1907 bool Arguments::create_numbered_module_property(const char* prop_base_name, const char* prop_value, unsigned int count) { 1908 assert(is_internal_module_property(prop_base_name), "unknown module property: '%s'", prop_base_name); 1909 CDSConfig::check_internal_module_property(prop_base_name, prop_value); 1910 const unsigned int props_count_limit = 1000; 1911 const int max_digits = 3; 1912 const int extra_symbols_count = 3; // includes '.', '=', '\0' 1913 1914 // Make sure count is < props_count_limit. Otherwise, memory allocation will be too small. 1915 if (count < props_count_limit) { 1916 size_t prop_len = strlen(prop_base_name) + strlen(prop_value) + max_digits + extra_symbols_count; 1917 char* property = AllocateHeap(prop_len, mtArguments); 1918 int ret = jio_snprintf(property, prop_len, "%s.%d=%s", prop_base_name, count, prop_value); 1919 if (ret < 0 || ret >= (int)prop_len) { 1920 FreeHeap(property); 1921 jio_fprintf(defaultStream::error_stream(), "Failed to create property %s.%d=%s\n", prop_base_name, count, prop_value); 1922 return false; 1923 } 1924 bool added = add_property(property, UnwriteableProperty, InternalProperty); 1925 FreeHeap(property); 1926 return added; 1927 } 1928 1929 jio_fprintf(defaultStream::error_stream(), "Property count limit exceeded: %s, limit=%d\n", prop_base_name, props_count_limit); 1930 return false; 1931 } 1932 1933 Arguments::ArgsRange Arguments::parse_memory_size(const char* s, 1934 julong* long_arg, 1935 julong min_size, 1936 julong max_size) { 1937 if (!parse_integer(s, long_arg)) return arg_unreadable; 1938 return check_memory_size(*long_arg, min_size, max_size); 1939 } 1940 1941 // Parse JavaVMInitArgs structure 1942 1943 jint Arguments::parse_vm_init_args(const JavaVMInitArgs *vm_options_args, 1944 const JavaVMInitArgs *java_tool_options_args, 1945 const JavaVMInitArgs *java_options_args, 1946 const JavaVMInitArgs *cmd_line_args) { 1947 // Save default settings for some mode flags 1948 Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods; 1949 Arguments::_UseOnStackReplacement = UseOnStackReplacement; 1950 Arguments::_ClipInlining = ClipInlining; 1951 Arguments::_BackgroundCompilation = BackgroundCompilation; 1952 1953 // Remember the default value of SharedBaseAddress. 1954 Arguments::_default_SharedBaseAddress = SharedBaseAddress; 1955 1956 // Setup flags for mixed which is the default 1957 set_mode_flags(_mixed); 1958 1959 // Parse args structure generated from java.base vm options resource 1960 jint result = parse_each_vm_init_arg(vm_options_args, JVMFlagOrigin::JIMAGE_RESOURCE); 1961 if (result != JNI_OK) { 1962 return result; 1963 } 1964 1965 // Parse args structure generated from JAVA_TOOL_OPTIONS environment 1966 // variable (if present). 1967 result = parse_each_vm_init_arg(java_tool_options_args, JVMFlagOrigin::ENVIRON_VAR); 1968 if (result != JNI_OK) { 1969 return result; 1970 } 1971 1972 // Parse args structure generated from the command line flags. 1973 result = parse_each_vm_init_arg(cmd_line_args, JVMFlagOrigin::COMMAND_LINE); 1974 if (result != JNI_OK) { 1975 return result; 1976 } 1977 1978 // Parse args structure generated from the _JAVA_OPTIONS environment 1979 // variable (if present) (mimics classic VM) 1980 result = parse_each_vm_init_arg(java_options_args, JVMFlagOrigin::ENVIRON_VAR); 1981 if (result != JNI_OK) { 1982 return result; 1983 } 1984 1985 // Disable CDS for exploded image 1986 if (!has_jimage()) { 1987 no_shared_spaces("CDS disabled on exploded JDK"); 1988 } 1989 1990 // We need to ensure processor and memory resources have been properly 1991 // configured - which may rely on arguments we just processed - before 1992 // doing the final argument processing. Any argument processing that 1993 // needs to know about processor and memory resources must occur after 1994 // this point. 1995 1996 os::init_container_support(); 1997 1998 SystemMemoryBarrier::initialize(); 1999 2000 // Do final processing now that all arguments have been parsed 2001 result = finalize_vm_init_args(); 2002 if (result != JNI_OK) { 2003 return result; 2004 } 2005 2006 return JNI_OK; 2007 } 2008 2009 #if !INCLUDE_JVMTI 2010 // Checks if name in command-line argument -agent{lib,path}:name[=options] 2011 // represents a valid JDWP agent. is_path==true denotes that we 2012 // are dealing with -agentpath (case where name is a path), otherwise with 2013 // -agentlib 2014 static bool valid_jdwp_agent(char *name, bool is_path) { 2015 char *_name; 2016 const char *_jdwp = "jdwp"; 2017 size_t _len_jdwp, _len_prefix; 2018 2019 if (is_path) { 2020 if ((_name = strrchr(name, (int) *os::file_separator())) == nullptr) { 2021 return false; 2022 } 2023 2024 _name++; // skip past last path separator 2025 _len_prefix = strlen(JNI_LIB_PREFIX); 2026 2027 if (strncmp(_name, JNI_LIB_PREFIX, _len_prefix) != 0) { 2028 return false; 2029 } 2030 2031 _name += _len_prefix; 2032 _len_jdwp = strlen(_jdwp); 2033 2034 if (strncmp(_name, _jdwp, _len_jdwp) == 0) { 2035 _name += _len_jdwp; 2036 } 2037 else { 2038 return false; 2039 } 2040 2041 if (strcmp(_name, JNI_LIB_SUFFIX) != 0) { 2042 return false; 2043 } 2044 2045 return true; 2046 } 2047 2048 if (strcmp(name, _jdwp) == 0) { 2049 return true; 2050 } 2051 2052 return false; 2053 } 2054 #endif 2055 2056 int Arguments::process_patch_mod_option(const char* patch_mod_tail) { 2057 // --patch-module=<module>=<file>(<pathsep><file>)* 2058 assert(patch_mod_tail != nullptr, "Unexpected null patch-module value"); 2059 // Find the equal sign between the module name and the path specification 2060 const char* module_equal = strchr(patch_mod_tail, '='); 2061 if (module_equal == nullptr) { 2062 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n"); 2063 return JNI_ERR; 2064 } else { 2065 // Pick out the module name 2066 size_t module_len = module_equal - patch_mod_tail; 2067 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments); 2068 if (module_name != nullptr) { 2069 memcpy(module_name, patch_mod_tail, module_len); 2070 *(module_name + module_len) = '\0'; 2071 // The path piece begins one past the module_equal sign 2072 add_patch_mod_prefix(module_name, module_equal + 1, false /* no append */, false /* no cds */); 2073 FREE_C_HEAP_ARRAY(char, module_name); 2074 } else { 2075 return JNI_ENOMEM; 2076 } 2077 } 2078 return JNI_OK; 2079 } 2080 2081 // VALUECLASS_STR must match string used in the build 2082 #define VALUECLASS_STR "valueclasses" 2083 #define VALUECLASS_JAR "-" VALUECLASS_STR ".jar" 2084 2085 // Finalize --patch-module args and --enable-preview related to value class module patches. 2086 // Create all numbered properties passing module patches. 2087 int Arguments::finalize_patch_module() { 2088 // If --enable-preview and EnableValhalla is true, each module may have value classes that 2089 // are to be patched into the module. 2090 // For each <module>-valueclasses.jar in <JAVA_HOME>/lib/valueclasses/ 2091 // appends the equivalent of --patch-module <module>=<JAVA_HOME>/lib/valueclasses/<module>-valueclasses.jar 2092 if (enable_preview() && EnableValhalla) { 2093 char * valueclasses_dir = AllocateHeap(JVM_MAXPATHLEN, mtArguments); 2094 const char * fileSep = os::file_separator(); 2095 2096 jio_snprintf(valueclasses_dir, JVM_MAXPATHLEN, "%s%slib%s" VALUECLASS_STR "%s", 2097 Arguments::get_java_home(), fileSep, fileSep, fileSep); 2098 DIR* dir = os::opendir(valueclasses_dir); 2099 if (dir != nullptr) { 2100 char * module_name = AllocateHeap(JVM_MAXPATHLEN, mtArguments); 2101 char * path = AllocateHeap(JVM_MAXPATHLEN, mtArguments); 2102 2103 for (dirent * entry = os::readdir(dir); entry != nullptr; entry = os::readdir(dir)) { 2104 // Test if file ends-with "-valueclasses.jar" 2105 int len = (int)strlen(entry->d_name) - (sizeof(VALUECLASS_JAR) - 1); 2106 if (len <= 0 || strcmp(&entry->d_name[len], VALUECLASS_JAR) != 0) { 2107 continue; // too short or not the expected suffix 2108 } 2109 2110 strcpy(module_name, entry->d_name); 2111 module_name[len] = '\0'; // truncate to just module-name 2112 2113 jio_snprintf(path, JVM_MAXPATHLEN, "%s%s", valueclasses_dir, &entry->d_name); 2114 add_patch_mod_prefix(module_name, path, true /* append */, true /* cds OK*/); 2115 log_info(class)("--enable-preview appending value classes for module %s: %s", module_name, entry->d_name); 2116 } 2117 FreeHeap(module_name); 2118 FreeHeap(path); 2119 os::closedir(dir); 2120 } 2121 FreeHeap(valueclasses_dir); 2122 } 2123 2124 // Create numbered properties for each module that has been patched either 2125 // by --patch-module or --enable-preview 2126 // Format is "jdk.module.patch.<n>=<module_name>=<path>" 2127 if (_patch_mod_prefix != nullptr) { 2128 char * prop_value = AllocateHeap(JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, mtArguments); 2129 unsigned int patch_mod_count = 0; 2130 2131 for (GrowableArrayIterator<ModulePatchPath *> it = _patch_mod_prefix->begin(); 2132 it != _patch_mod_prefix->end(); ++it) { 2133 jio_snprintf(prop_value, JVM_MAXPATHLEN + JVM_MAXPATHLEN + 1, "%s=%s", 2134 (*it)->module_name(), (*it)->path_string()); 2135 if (!create_numbered_module_property("jdk.module.patch", prop_value, patch_mod_count++)) { 2136 FreeHeap(prop_value); 2137 return JNI_ENOMEM; 2138 } 2139 } 2140 FreeHeap(prop_value); 2141 } 2142 return JNI_OK; 2143 } 2144 2145 // Parse -Xss memory string parameter and convert to ThreadStackSize in K. 2146 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) { 2147 // The min and max sizes match the values in globals.hpp, but scaled 2148 // with K. The values have been chosen so that alignment with page 2149 // size doesn't change the max value, which makes the conversions 2150 // back and forth between Xss value and ThreadStackSize value easier. 2151 // The values have also been chosen to fit inside a 32-bit signed type. 2152 const julong min_ThreadStackSize = 0; 2153 const julong max_ThreadStackSize = 1 * M; 2154 2155 // Make sure the above values match the range set in globals.hpp 2156 const JVMTypedFlagLimit<intx>* limit = JVMFlagLimit::get_range_at(FLAG_MEMBER_ENUM(ThreadStackSize))->cast<intx>(); 2157 assert(min_ThreadStackSize == static_cast<julong>(limit->min()), "must be"); 2158 assert(max_ThreadStackSize == static_cast<julong>(limit->max()), "must be"); 2159 2160 const julong min_size = min_ThreadStackSize * K; 2161 const julong max_size = max_ThreadStackSize * K; 2162 2163 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption"); 2164 2165 julong size = 0; 2166 ArgsRange errcode = parse_memory_size(tail, &size, min_size, max_size); 2167 if (errcode != arg_in_range) { 2168 bool silent = (option == nullptr); // Allow testing to silence error messages 2169 if (!silent) { 2170 jio_fprintf(defaultStream::error_stream(), 2171 "Invalid thread stack size: %s\n", option->optionString); 2172 describe_range_error(errcode); 2173 } 2174 return JNI_EINVAL; 2175 } 2176 2177 // Internally track ThreadStackSize in units of 1024 bytes. 2178 const julong size_aligned = align_up(size, K); 2179 assert(size <= size_aligned, 2180 "Overflow: " JULONG_FORMAT " " JULONG_FORMAT, 2181 size, size_aligned); 2182 2183 const julong size_in_K = size_aligned / K; 2184 assert(size_in_K < (julong)max_intx, 2185 "size_in_K doesn't fit in the type of ThreadStackSize: " JULONG_FORMAT, 2186 size_in_K); 2187 2188 // Check that code expanding ThreadStackSize to a page aligned number of bytes won't overflow. 2189 const julong max_expanded = align_up(size_in_K * K, os::vm_page_size()); 2190 assert(max_expanded < max_uintx && max_expanded >= size_in_K, 2191 "Expansion overflowed: " JULONG_FORMAT " " JULONG_FORMAT, 2192 max_expanded, size_in_K); 2193 2194 *out_ThreadStackSize = (intx)size_in_K; 2195 2196 return JNI_OK; 2197 } 2198 2199 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, JVMFlagOrigin origin) { 2200 // For match_option to return remaining or value part of option string 2201 const char* tail; 2202 2203 // iterate over arguments 2204 for (int index = 0; index < args->nOptions; index++) { 2205 bool is_absolute_path = false; // for -agentpath vs -agentlib 2206 2207 const JavaVMOption* option = args->options + index; 2208 2209 if (!match_option(option, "-Djava.class.path", &tail) && 2210 !match_option(option, "-Dsun.java.command", &tail) && 2211 !match_option(option, "-Dsun.java.launcher", &tail)) { 2212 2213 // add all jvm options to the jvm_args string. This string 2214 // is used later to set the java.vm.args PerfData string constant. 2215 // the -Djava.class.path and the -Dsun.java.command options are 2216 // omitted from jvm_args string as each have their own PerfData 2217 // string constant object. 2218 build_jvm_args(option->optionString); 2219 } 2220 2221 // -verbose:[class/module/gc/jni] 2222 if (match_option(option, "-verbose", &tail)) { 2223 if (!strcmp(tail, ":class") || !strcmp(tail, "")) { 2224 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, load)); 2225 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, unload)); 2226 } else if (!strcmp(tail, ":module")) { 2227 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(module, load)); 2228 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(module, unload)); 2229 } else if (!strcmp(tail, ":gc")) { 2230 if (_legacyGCLogging.lastFlag == 0) { 2231 _legacyGCLogging.lastFlag = 1; 2232 } 2233 } else if (!strcmp(tail, ":jni")) { 2234 LogConfiguration::configure_stdout(LogLevel::Debug, true, LOG_TAGS(jni, resolve)); 2235 } 2236 // -da / -ea / -disableassertions / -enableassertions 2237 // These accept an optional class/package name separated by a colon, e.g., 2238 // -da:java.lang.Thread. 2239 } else if (match_option(option, user_assertion_options, &tail, true)) { 2240 bool enable = option->optionString[1] == 'e'; // char after '-' is 'e' 2241 if (*tail == '\0') { 2242 JavaAssertions::setUserClassDefault(enable); 2243 } else { 2244 assert(*tail == ':', "bogus match by match_option()"); 2245 JavaAssertions::addOption(tail + 1, enable); 2246 } 2247 // -dsa / -esa / -disablesystemassertions / -enablesystemassertions 2248 } else if (match_option(option, system_assertion_options, &tail, false)) { 2249 bool enable = option->optionString[1] == 'e'; // char after '-' is 'e' 2250 JavaAssertions::setSystemClassDefault(enable); 2251 // -bootclasspath: 2252 } else if (match_option(option, "-Xbootclasspath:", &tail)) { 2253 jio_fprintf(defaultStream::output_stream(), 2254 "-Xbootclasspath is no longer a supported option.\n"); 2255 return JNI_EINVAL; 2256 // -bootclasspath/a: 2257 } else if (match_option(option, "-Xbootclasspath/a:", &tail)) { 2258 Arguments::append_sysclasspath(tail); 2259 // -bootclasspath/p: 2260 } else if (match_option(option, "-Xbootclasspath/p:", &tail)) { 2261 jio_fprintf(defaultStream::output_stream(), 2262 "-Xbootclasspath/p is no longer a supported option.\n"); 2263 return JNI_EINVAL; 2264 // -Xrun 2265 } else if (match_option(option, "-Xrun", &tail)) { 2266 if (tail != nullptr) { 2267 const char* pos = strchr(tail, ':'); 2268 size_t len = (pos == nullptr) ? strlen(tail) : pos - tail; 2269 char* name = NEW_C_HEAP_ARRAY(char, len + 1, mtArguments); 2270 jio_snprintf(name, len + 1, "%s", tail); 2271 2272 char *options = nullptr; 2273 if(pos != nullptr) { 2274 size_t len2 = strlen(pos+1) + 1; // options start after ':'. Final zero must be copied. 2275 options = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len2, mtArguments), pos+1, len2); 2276 } 2277 #if !INCLUDE_JVMTI 2278 if (strcmp(name, "jdwp") == 0) { 2279 jio_fprintf(defaultStream::error_stream(), 2280 "Debugging agents are not supported in this VM\n"); 2281 return JNI_ERR; 2282 } 2283 #endif // !INCLUDE_JVMTI 2284 JvmtiAgentList::add_xrun(name, options, false); 2285 FREE_C_HEAP_ARRAY(char, name); 2286 FREE_C_HEAP_ARRAY(char, options); 2287 } 2288 } else if (match_option(option, "--add-reads=", &tail)) { 2289 if (!create_numbered_module_property("jdk.module.addreads", tail, addreads_count++)) { 2290 return JNI_ENOMEM; 2291 } 2292 } else if (match_option(option, "--add-exports=", &tail)) { 2293 if (!create_numbered_module_property("jdk.module.addexports", tail, addexports_count++)) { 2294 return JNI_ENOMEM; 2295 } 2296 } else if (match_option(option, "--add-opens=", &tail)) { 2297 if (!create_numbered_module_property("jdk.module.addopens", tail, addopens_count++)) { 2298 return JNI_ENOMEM; 2299 } 2300 } else if (match_option(option, "--add-modules=", &tail)) { 2301 if (!create_numbered_module_property("jdk.module.addmods", tail, _addmods_count++)) { 2302 return JNI_ENOMEM; 2303 } 2304 } else if (match_option(option, "--enable-native-access=", &tail)) { 2305 if (!create_numbered_module_property("jdk.module.enable.native.access", tail, enable_native_access_count++)) { 2306 return JNI_ENOMEM; 2307 } 2308 } else if (match_option(option, "--illegal-native-access=", &tail)) { 2309 if (!create_module_property("jdk.module.illegal.native.access", tail, InternalProperty)) { 2310 return JNI_ENOMEM; 2311 } 2312 } else if (match_option(option, "--limit-modules=", &tail)) { 2313 if (!create_module_property("jdk.module.limitmods", tail, InternalProperty)) { 2314 return JNI_ENOMEM; 2315 } 2316 } else if (match_option(option, "--module-path=", &tail)) { 2317 if (!create_module_property("jdk.module.path", tail, ExternalProperty)) { 2318 return JNI_ENOMEM; 2319 } 2320 } else if (match_option(option, "--upgrade-module-path=", &tail)) { 2321 if (!create_module_property("jdk.module.upgrade.path", tail, ExternalProperty)) { 2322 return JNI_ENOMEM; 2323 } 2324 } else if (match_option(option, "--patch-module=", &tail)) { 2325 // --patch-module=<module>=<file>(<pathsep><file>)* 2326 int res = process_patch_mod_option(tail); 2327 if (res != JNI_OK) { 2328 return res; 2329 } 2330 } else if (match_option(option, "--sun-misc-unsafe-memory-access=", &tail)) { 2331 if (strcmp(tail, "allow") == 0 || strcmp(tail, "warn") == 0 || strcmp(tail, "debug") == 0 || strcmp(tail, "deny") == 0) { 2332 PropertyList_unique_add(&_system_properties, "sun.misc.unsafe.memory.access", tail, 2333 AddProperty, WriteableProperty, InternalProperty); 2334 } else { 2335 jio_fprintf(defaultStream::error_stream(), 2336 "Value specified to --sun-misc-unsafe-memory-access not recognized: '%s'\n", tail); 2337 return JNI_ERR; 2338 } 2339 } else if (match_option(option, "--illegal-access=", &tail)) { 2340 char version[256]; 2341 JDK_Version::jdk(17).to_string(version, sizeof(version)); 2342 warning("Ignoring option %s; support was removed in %s", option->optionString, version); 2343 // -agentlib and -agentpath 2344 } else if (match_option(option, "-agentlib:", &tail) || 2345 (is_absolute_path = match_option(option, "-agentpath:", &tail))) { 2346 if(tail != nullptr) { 2347 const char* pos = strchr(tail, '='); 2348 char* name; 2349 if (pos == nullptr) { 2350 name = os::strdup_check_oom(tail, mtArguments); 2351 } else { 2352 size_t len = pos - tail; 2353 name = NEW_C_HEAP_ARRAY(char, len + 1, mtArguments); 2354 memcpy(name, tail, len); 2355 name[len] = '\0'; 2356 } 2357 2358 char *options = nullptr; 2359 if(pos != nullptr) { 2360 options = os::strdup_check_oom(pos + 1, mtArguments); 2361 } 2362 #if !INCLUDE_JVMTI 2363 if (valid_jdwp_agent(name, is_absolute_path)) { 2364 jio_fprintf(defaultStream::error_stream(), 2365 "Debugging agents are not supported in this VM\n"); 2366 return JNI_ERR; 2367 } 2368 #endif // !INCLUDE_JVMTI 2369 JvmtiAgentList::add(name, options, is_absolute_path); 2370 os::free(name); 2371 os::free(options); 2372 } 2373 // -javaagent 2374 } else if (match_option(option, "-javaagent:", &tail)) { 2375 #if !INCLUDE_JVMTI 2376 jio_fprintf(defaultStream::error_stream(), 2377 "Instrumentation agents are not supported in this VM\n"); 2378 return JNI_ERR; 2379 #else 2380 if (tail != nullptr) { 2381 size_t length = strlen(tail) + 1; 2382 char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments); 2383 jio_snprintf(options, length, "%s", tail); 2384 JvmtiAgentList::add("instrument", options, false); 2385 FREE_C_HEAP_ARRAY(char, options); 2386 2387 // java agents need module java.instrument 2388 if (!create_numbered_module_property("jdk.module.addmods", "java.instrument", _addmods_count++)) { 2389 return JNI_ENOMEM; 2390 } 2391 } 2392 #endif // !INCLUDE_JVMTI 2393 // --enable_preview 2394 } else if (match_option(option, "--enable-preview")) { 2395 set_enable_preview(); 2396 // --enable-preview enables Valhalla, EnableValhalla VM option will eventually be removed before integration 2397 if (FLAG_SET_CMDLINE(EnableValhalla, true) != JVMFlag::SUCCESS) { 2398 return JNI_EINVAL; 2399 } 2400 // -Xnoclassgc 2401 } else if (match_option(option, "-Xnoclassgc")) { 2402 if (FLAG_SET_CMDLINE(ClassUnloading, false) != JVMFlag::SUCCESS) { 2403 return JNI_EINVAL; 2404 } 2405 // -Xbatch 2406 } else if (match_option(option, "-Xbatch")) { 2407 if (FLAG_SET_CMDLINE(BackgroundCompilation, false) != JVMFlag::SUCCESS) { 2408 return JNI_EINVAL; 2409 } 2410 // -Xmn for compatibility with other JVM vendors 2411 } else if (match_option(option, "-Xmn", &tail)) { 2412 julong long_initial_young_size = 0; 2413 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1); 2414 if (errcode != arg_in_range) { 2415 jio_fprintf(defaultStream::error_stream(), 2416 "Invalid initial young generation size: %s\n", option->optionString); 2417 describe_range_error(errcode); 2418 return JNI_EINVAL; 2419 } 2420 if (FLAG_SET_CMDLINE(MaxNewSize, (size_t)long_initial_young_size) != JVMFlag::SUCCESS) { 2421 return JNI_EINVAL; 2422 } 2423 if (FLAG_SET_CMDLINE(NewSize, (size_t)long_initial_young_size) != JVMFlag::SUCCESS) { 2424 return JNI_EINVAL; 2425 } 2426 // -Xms 2427 } else if (match_option(option, "-Xms", &tail)) { 2428 julong size = 0; 2429 // an initial heap size of 0 means automatically determine 2430 ArgsRange errcode = parse_memory_size(tail, &size, 0); 2431 if (errcode != arg_in_range) { 2432 jio_fprintf(defaultStream::error_stream(), 2433 "Invalid initial heap size: %s\n", option->optionString); 2434 describe_range_error(errcode); 2435 return JNI_EINVAL; 2436 } 2437 if (FLAG_SET_CMDLINE(MinHeapSize, (size_t)size) != JVMFlag::SUCCESS) { 2438 return JNI_EINVAL; 2439 } 2440 if (FLAG_SET_CMDLINE(InitialHeapSize, (size_t)size) != JVMFlag::SUCCESS) { 2441 return JNI_EINVAL; 2442 } 2443 // -Xmx 2444 } else if (match_option(option, "-Xmx", &tail) || match_option(option, "-XX:MaxHeapSize=", &tail)) { 2445 julong long_max_heap_size = 0; 2446 ArgsRange errcode = parse_memory_size(tail, &long_max_heap_size, 1); 2447 if (errcode != arg_in_range) { 2448 jio_fprintf(defaultStream::error_stream(), 2449 "Invalid maximum heap size: %s\n", option->optionString); 2450 describe_range_error(errcode); 2451 return JNI_EINVAL; 2452 } 2453 if (FLAG_SET_CMDLINE(MaxHeapSize, (size_t)long_max_heap_size) != JVMFlag::SUCCESS) { 2454 return JNI_EINVAL; 2455 } 2456 // Xmaxf 2457 } else if (match_option(option, "-Xmaxf", &tail)) { 2458 char* err; 2459 int maxf = (int)(strtod(tail, &err) * 100); 2460 if (*err != '\0' || *tail == '\0') { 2461 jio_fprintf(defaultStream::error_stream(), 2462 "Bad max heap free percentage size: %s\n", 2463 option->optionString); 2464 return JNI_EINVAL; 2465 } else { 2466 if (FLAG_SET_CMDLINE(MaxHeapFreeRatio, maxf) != JVMFlag::SUCCESS) { 2467 return JNI_EINVAL; 2468 } 2469 } 2470 // Xminf 2471 } else if (match_option(option, "-Xminf", &tail)) { 2472 char* err; 2473 int minf = (int)(strtod(tail, &err) * 100); 2474 if (*err != '\0' || *tail == '\0') { 2475 jio_fprintf(defaultStream::error_stream(), 2476 "Bad min heap free percentage size: %s\n", 2477 option->optionString); 2478 return JNI_EINVAL; 2479 } else { 2480 if (FLAG_SET_CMDLINE(MinHeapFreeRatio, minf) != JVMFlag::SUCCESS) { 2481 return JNI_EINVAL; 2482 } 2483 } 2484 // -Xss 2485 } else if (match_option(option, "-Xss", &tail)) { 2486 intx value = 0; 2487 jint err = parse_xss(option, tail, &value); 2488 if (err != JNI_OK) { 2489 return err; 2490 } 2491 if (FLAG_SET_CMDLINE(ThreadStackSize, value) != JVMFlag::SUCCESS) { 2492 return JNI_EINVAL; 2493 } 2494 } else if (match_option(option, "-Xmaxjitcodesize", &tail) || 2495 match_option(option, "-XX:ReservedCodeCacheSize=", &tail)) { 2496 julong long_ReservedCodeCacheSize = 0; 2497 2498 ArgsRange errcode = parse_memory_size(tail, &long_ReservedCodeCacheSize, 1); 2499 if (errcode != arg_in_range) { 2500 jio_fprintf(defaultStream::error_stream(), 2501 "Invalid maximum code cache size: %s.\n", option->optionString); 2502 return JNI_EINVAL; 2503 } 2504 if (FLAG_SET_CMDLINE(ReservedCodeCacheSize, (uintx)long_ReservedCodeCacheSize) != JVMFlag::SUCCESS) { 2505 return JNI_EINVAL; 2506 } 2507 // -green 2508 } else if (match_option(option, "-green")) { 2509 jio_fprintf(defaultStream::error_stream(), 2510 "Green threads support not available\n"); 2511 return JNI_EINVAL; 2512 // -native 2513 } else if (match_option(option, "-native")) { 2514 // HotSpot always uses native threads, ignore silently for compatibility 2515 // -Xrs 2516 } else if (match_option(option, "-Xrs")) { 2517 // Classic/EVM option, new functionality 2518 if (FLAG_SET_CMDLINE(ReduceSignalUsage, true) != JVMFlag::SUCCESS) { 2519 return JNI_EINVAL; 2520 } 2521 // -Xprof 2522 } else if (match_option(option, "-Xprof")) { 2523 char version[256]; 2524 // Obsolete in JDK 10 2525 JDK_Version::jdk(10).to_string(version, sizeof(version)); 2526 warning("Ignoring option %s; support was removed in %s", option->optionString, version); 2527 // -Xinternalversion 2528 } else if (match_option(option, "-Xinternalversion")) { 2529 jio_fprintf(defaultStream::output_stream(), "%s\n", 2530 VM_Version::internal_vm_info_string()); 2531 vm_exit(0); 2532 #ifndef PRODUCT 2533 // -Xprintflags 2534 } else if (match_option(option, "-Xprintflags")) { 2535 JVMFlag::printFlags(tty, false); 2536 vm_exit(0); 2537 #endif 2538 // -D 2539 } else if (match_option(option, "-D", &tail)) { 2540 const char* value; 2541 if (match_option(option, "-Djava.endorsed.dirs=", &value) && 2542 *value!= '\0' && strcmp(value, "\"\"") != 0) { 2543 // abort if -Djava.endorsed.dirs is set 2544 jio_fprintf(defaultStream::output_stream(), 2545 "-Djava.endorsed.dirs=%s is not supported. Endorsed standards and standalone APIs\n" 2546 "in modular form will be supported via the concept of upgradeable modules.\n", value); 2547 return JNI_EINVAL; 2548 } 2549 if (match_option(option, "-Djava.ext.dirs=", &value) && 2550 *value != '\0' && strcmp(value, "\"\"") != 0) { 2551 // abort if -Djava.ext.dirs is set 2552 jio_fprintf(defaultStream::output_stream(), 2553 "-Djava.ext.dirs=%s is not supported. Use -classpath instead.\n", value); 2554 return JNI_EINVAL; 2555 } 2556 // Check for module related properties. They must be set using the modules 2557 // options. For example: use "--add-modules=java.sql", not 2558 // "-Djdk.module.addmods=java.sql" 2559 if (is_internal_module_property(option->optionString + 2)) { 2560 needs_module_property_warning = true; 2561 continue; 2562 } 2563 if (!add_property(tail)) { 2564 return JNI_ENOMEM; 2565 } 2566 // Out of the box management support 2567 if (match_option(option, "-Dcom.sun.management", &tail)) { 2568 #if INCLUDE_MANAGEMENT 2569 if (FLAG_SET_CMDLINE(ManagementServer, true) != JVMFlag::SUCCESS) { 2570 return JNI_EINVAL; 2571 } 2572 // management agent in module jdk.management.agent 2573 if (!create_numbered_module_property("jdk.module.addmods", "jdk.management.agent", _addmods_count++)) { 2574 return JNI_ENOMEM; 2575 } 2576 #else 2577 jio_fprintf(defaultStream::output_stream(), 2578 "-Dcom.sun.management is not supported in this VM.\n"); 2579 return JNI_ERR; 2580 #endif 2581 } 2582 // -Xint 2583 } else if (match_option(option, "-Xint")) { 2584 set_mode_flags(_int); 2585 mode_flag_cmd_line = true; 2586 // -Xmixed 2587 } else if (match_option(option, "-Xmixed")) { 2588 set_mode_flags(_mixed); 2589 mode_flag_cmd_line = true; 2590 // -Xcomp 2591 } else if (match_option(option, "-Xcomp")) { 2592 // for testing the compiler; turn off all flags that inhibit compilation 2593 set_mode_flags(_comp); 2594 mode_flag_cmd_line = true; 2595 // -Xshare:dump 2596 } else if (match_option(option, "-Xshare:dump")) { 2597 CDSConfig::enable_dumping_static_archive(); 2598 // -Xshare:on 2599 } else if (match_option(option, "-Xshare:on")) { 2600 UseSharedSpaces = true; 2601 RequireSharedSpaces = true; 2602 // -Xshare:auto || -XX:ArchiveClassesAtExit=<archive file> 2603 } else if (match_option(option, "-Xshare:auto")) { 2604 UseSharedSpaces = true; 2605 RequireSharedSpaces = false; 2606 xshare_auto_cmd_line = true; 2607 // -Xshare:off 2608 } else if (match_option(option, "-Xshare:off")) { 2609 UseSharedSpaces = false; 2610 RequireSharedSpaces = false; 2611 // -Xverify 2612 } else if (match_option(option, "-Xverify", &tail)) { 2613 if (strcmp(tail, ":all") == 0 || strcmp(tail, "") == 0) { 2614 if (FLAG_SET_CMDLINE(BytecodeVerificationLocal, true) != JVMFlag::SUCCESS) { 2615 return JNI_EINVAL; 2616 } 2617 if (FLAG_SET_CMDLINE(BytecodeVerificationRemote, true) != JVMFlag::SUCCESS) { 2618 return JNI_EINVAL; 2619 } 2620 } else if (strcmp(tail, ":remote") == 0) { 2621 if (FLAG_SET_CMDLINE(BytecodeVerificationLocal, false) != JVMFlag::SUCCESS) { 2622 return JNI_EINVAL; 2623 } 2624 if (FLAG_SET_CMDLINE(BytecodeVerificationRemote, true) != JVMFlag::SUCCESS) { 2625 return JNI_EINVAL; 2626 } 2627 } else if (strcmp(tail, ":none") == 0) { 2628 if (FLAG_SET_CMDLINE(BytecodeVerificationLocal, false) != JVMFlag::SUCCESS) { 2629 return JNI_EINVAL; 2630 } 2631 if (FLAG_SET_CMDLINE(BytecodeVerificationRemote, false) != JVMFlag::SUCCESS) { 2632 return JNI_EINVAL; 2633 } 2634 warning("Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release."); 2635 } else if (is_bad_option(option, args->ignoreUnrecognized, "verification")) { 2636 return JNI_EINVAL; 2637 } 2638 // -Xdebug 2639 } else if (match_option(option, "-Xdebug")) { 2640 warning("Option -Xdebug was deprecated in JDK 22 and will likely be removed in a future release."); 2641 } else if (match_option(option, "-Xloggc:", &tail)) { 2642 // Deprecated flag to redirect GC output to a file. -Xloggc:<filename> 2643 log_warning(gc)("-Xloggc is deprecated. Will use -Xlog:gc:%s instead.", tail); 2644 _legacyGCLogging.lastFlag = 2; 2645 _legacyGCLogging.file = os::strdup_check_oom(tail); 2646 } else if (match_option(option, "-Xlog", &tail)) { 2647 bool ret = false; 2648 if (strcmp(tail, ":help") == 0) { 2649 fileStream stream(defaultStream::output_stream()); 2650 LogConfiguration::print_command_line_help(&stream); 2651 vm_exit(0); 2652 } else if (strcmp(tail, ":disable") == 0) { 2653 LogConfiguration::disable_logging(); 2654 ret = true; 2655 } else if (strcmp(tail, ":async") == 0) { 2656 LogConfiguration::set_async_mode(true); 2657 ret = true; 2658 } else if (*tail == '\0') { 2659 ret = LogConfiguration::parse_command_line_arguments(); 2660 assert(ret, "-Xlog without arguments should never fail to parse"); 2661 } else if (*tail == ':') { 2662 ret = LogConfiguration::parse_command_line_arguments(tail + 1); 2663 } 2664 if (ret == false) { 2665 jio_fprintf(defaultStream::error_stream(), 2666 "Invalid -Xlog option '-Xlog%s', see error log for details.\n", 2667 tail); 2668 return JNI_EINVAL; 2669 } 2670 // JNI hooks 2671 } else if (match_option(option, "-Xcheck", &tail)) { 2672 if (!strcmp(tail, ":jni")) { 2673 #if !INCLUDE_JNI_CHECK 2674 warning("JNI CHECKING is not supported in this VM"); 2675 #else 2676 CheckJNICalls = true; 2677 #endif // INCLUDE_JNI_CHECK 2678 } else if (is_bad_option(option, args->ignoreUnrecognized, 2679 "check")) { 2680 return JNI_EINVAL; 2681 } 2682 } else if (match_option(option, "vfprintf")) { 2683 _vfprintf_hook = CAST_TO_FN_PTR(vfprintf_hook_t, option->extraInfo); 2684 } else if (match_option(option, "exit")) { 2685 _exit_hook = CAST_TO_FN_PTR(exit_hook_t, option->extraInfo); 2686 } else if (match_option(option, "abort")) { 2687 _abort_hook = CAST_TO_FN_PTR(abort_hook_t, option->extraInfo); 2688 // Need to keep consistency of MaxTenuringThreshold and AlwaysTenure/NeverTenure; 2689 // and the last option wins. 2690 } else if (match_option(option, "-XX:+NeverTenure")) { 2691 if (FLAG_SET_CMDLINE(NeverTenure, true) != JVMFlag::SUCCESS) { 2692 return JNI_EINVAL; 2693 } 2694 if (FLAG_SET_CMDLINE(AlwaysTenure, false) != JVMFlag::SUCCESS) { 2695 return JNI_EINVAL; 2696 } 2697 if (FLAG_SET_CMDLINE(MaxTenuringThreshold, markWord::max_age + 1) != JVMFlag::SUCCESS) { 2698 return JNI_EINVAL; 2699 } 2700 } else if (match_option(option, "-XX:+AlwaysTenure")) { 2701 if (FLAG_SET_CMDLINE(NeverTenure, false) != JVMFlag::SUCCESS) { 2702 return JNI_EINVAL; 2703 } 2704 if (FLAG_SET_CMDLINE(AlwaysTenure, true) != JVMFlag::SUCCESS) { 2705 return JNI_EINVAL; 2706 } 2707 if (FLAG_SET_CMDLINE(MaxTenuringThreshold, 0) != JVMFlag::SUCCESS) { 2708 return JNI_EINVAL; 2709 } 2710 } else if (match_option(option, "-XX:MaxTenuringThreshold=", &tail)) { 2711 uint max_tenuring_thresh = 0; 2712 if (!parse_uint(tail, &max_tenuring_thresh, 0)) { 2713 jio_fprintf(defaultStream::error_stream(), 2714 "Improperly specified VM option \'MaxTenuringThreshold=%s\'\n", tail); 2715 return JNI_EINVAL; 2716 } 2717 2718 if (FLAG_SET_CMDLINE(MaxTenuringThreshold, max_tenuring_thresh) != JVMFlag::SUCCESS) { 2719 return JNI_EINVAL; 2720 } 2721 2722 if (MaxTenuringThreshold == 0) { 2723 if (FLAG_SET_CMDLINE(NeverTenure, false) != JVMFlag::SUCCESS) { 2724 return JNI_EINVAL; 2725 } 2726 if (FLAG_SET_CMDLINE(AlwaysTenure, true) != JVMFlag::SUCCESS) { 2727 return JNI_EINVAL; 2728 } 2729 } else { 2730 if (FLAG_SET_CMDLINE(NeverTenure, false) != JVMFlag::SUCCESS) { 2731 return JNI_EINVAL; 2732 } 2733 if (FLAG_SET_CMDLINE(AlwaysTenure, false) != JVMFlag::SUCCESS) { 2734 return JNI_EINVAL; 2735 } 2736 } 2737 } else if (match_option(option, "-XX:+DisplayVMOutputToStderr")) { 2738 if (FLAG_SET_CMDLINE(DisplayVMOutputToStdout, false) != JVMFlag::SUCCESS) { 2739 return JNI_EINVAL; 2740 } 2741 if (FLAG_SET_CMDLINE(DisplayVMOutputToStderr, true) != JVMFlag::SUCCESS) { 2742 return JNI_EINVAL; 2743 } 2744 } else if (match_option(option, "-XX:+DisplayVMOutputToStdout")) { 2745 if (FLAG_SET_CMDLINE(DisplayVMOutputToStderr, false) != JVMFlag::SUCCESS) { 2746 return JNI_EINVAL; 2747 } 2748 if (FLAG_SET_CMDLINE(DisplayVMOutputToStdout, true) != JVMFlag::SUCCESS) { 2749 return JNI_EINVAL; 2750 } 2751 } else if (match_option(option, "-XX:+ErrorFileToStderr")) { 2752 if (FLAG_SET_CMDLINE(ErrorFileToStdout, false) != JVMFlag::SUCCESS) { 2753 return JNI_EINVAL; 2754 } 2755 if (FLAG_SET_CMDLINE(ErrorFileToStderr, true) != JVMFlag::SUCCESS) { 2756 return JNI_EINVAL; 2757 } 2758 } else if (match_option(option, "-XX:+ErrorFileToStdout")) { 2759 if (FLAG_SET_CMDLINE(ErrorFileToStderr, false) != JVMFlag::SUCCESS) { 2760 return JNI_EINVAL; 2761 } 2762 if (FLAG_SET_CMDLINE(ErrorFileToStdout, true) != JVMFlag::SUCCESS) { 2763 return JNI_EINVAL; 2764 } 2765 } else if (match_option(option, "--finalization=", &tail)) { 2766 if (strcmp(tail, "enabled") == 0) { 2767 InstanceKlass::set_finalization_enabled(true); 2768 } else if (strcmp(tail, "disabled") == 0) { 2769 InstanceKlass::set_finalization_enabled(false); 2770 } else { 2771 jio_fprintf(defaultStream::error_stream(), 2772 "Invalid finalization value '%s', must be 'disabled' or 'enabled'.\n", 2773 tail); 2774 return JNI_EINVAL; 2775 } 2776 #if !defined(DTRACE_ENABLED) 2777 } else if (match_option(option, "-XX:+DTraceMethodProbes")) { 2778 jio_fprintf(defaultStream::error_stream(), 2779 "DTraceMethodProbes flag is not applicable for this configuration\n"); 2780 return JNI_EINVAL; 2781 } else if (match_option(option, "-XX:+DTraceAllocProbes")) { 2782 jio_fprintf(defaultStream::error_stream(), 2783 "DTraceAllocProbes flag is not applicable for this configuration\n"); 2784 return JNI_EINVAL; 2785 } else if (match_option(option, "-XX:+DTraceMonitorProbes")) { 2786 jio_fprintf(defaultStream::error_stream(), 2787 "DTraceMonitorProbes flag is not applicable for this configuration\n"); 2788 return JNI_EINVAL; 2789 #endif // !defined(DTRACE_ENABLED) 2790 #ifdef ASSERT 2791 } else if (match_option(option, "-XX:+FullGCALot")) { 2792 if (FLAG_SET_CMDLINE(FullGCALot, true) != JVMFlag::SUCCESS) { 2793 return JNI_EINVAL; 2794 } 2795 #endif 2796 #if !INCLUDE_MANAGEMENT 2797 } else if (match_option(option, "-XX:+ManagementServer")) { 2798 jio_fprintf(defaultStream::error_stream(), 2799 "ManagementServer is not supported in this VM.\n"); 2800 return JNI_ERR; 2801 #endif // INCLUDE_MANAGEMENT 2802 #if INCLUDE_JVMCI 2803 } else if (match_option(option, "-XX:-EnableJVMCIProduct") || match_option(option, "-XX:-UseGraalJIT")) { 2804 if (EnableJVMCIProduct) { 2805 jio_fprintf(defaultStream::error_stream(), 2806 "-XX:-EnableJVMCIProduct or -XX:-UseGraalJIT cannot come after -XX:+EnableJVMCIProduct or -XX:+UseGraalJIT\n"); 2807 return JNI_EINVAL; 2808 } 2809 } else if (match_option(option, "-XX:+EnableJVMCIProduct") || match_option(option, "-XX:+UseGraalJIT")) { 2810 bool use_graal_jit = match_option(option, "-XX:+UseGraalJIT"); 2811 if (use_graal_jit) { 2812 const char* jvmci_compiler = get_property("jvmci.Compiler"); 2813 if (jvmci_compiler != nullptr) { 2814 if (strncmp(jvmci_compiler, "graal", strlen("graal")) != 0) { 2815 jio_fprintf(defaultStream::error_stream(), 2816 "Value of jvmci.Compiler incompatible with +UseGraalJIT: %s\n", jvmci_compiler); 2817 return JNI_ERR; 2818 } 2819 } else if (!add_property("jvmci.Compiler=graal")) { 2820 return JNI_ENOMEM; 2821 } 2822 } 2823 2824 // Just continue, since "-XX:+EnableJVMCIProduct" or "-XX:+UseGraalJIT" has been specified before 2825 if (EnableJVMCIProduct) { 2826 continue; 2827 } 2828 JVMFlag *jvmciFlag = JVMFlag::find_flag("EnableJVMCIProduct"); 2829 // Allow this flag if it has been unlocked. 2830 if (jvmciFlag != nullptr && jvmciFlag->is_unlocked()) { 2831 if (!JVMCIGlobals::enable_jvmci_product_mode(origin, use_graal_jit)) { 2832 jio_fprintf(defaultStream::error_stream(), 2833 "Unable to enable JVMCI in product mode\n"); 2834 return JNI_ERR; 2835 } 2836 } 2837 // The flag was locked so process normally to report that error 2838 else if (!process_argument(use_graal_jit ? "UseGraalJIT" : "EnableJVMCIProduct", args->ignoreUnrecognized, origin)) { 2839 return JNI_EINVAL; 2840 } 2841 #endif // INCLUDE_JVMCI 2842 #if INCLUDE_JFR 2843 } else if (match_jfr_option(&option)) { 2844 return JNI_EINVAL; 2845 #endif 2846 } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx 2847 // Skip -XX:Flags= and -XX:VMOptionsFile= since those cases have 2848 // already been handled 2849 if ((strncmp(tail, "Flags=", strlen("Flags=")) != 0) && 2850 (strncmp(tail, "VMOptionsFile=", strlen("VMOptionsFile=")) != 0)) { 2851 if (!process_argument(tail, args->ignoreUnrecognized, origin)) { 2852 return JNI_EINVAL; 2853 } 2854 } 2855 // Unknown option 2856 } else if (is_bad_option(option, args->ignoreUnrecognized)) { 2857 return JNI_ERR; 2858 } 2859 } 2860 2861 // PrintSharedArchiveAndExit will turn on 2862 // -Xshare:on 2863 // -Xlog:class+path=info 2864 if (PrintSharedArchiveAndExit) { 2865 UseSharedSpaces = true; 2866 RequireSharedSpaces = true; 2867 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path)); 2868 } 2869 2870 fix_appclasspath(); 2871 2872 return JNI_OK; 2873 } 2874 2875 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool allow_append, bool allow_cds) { 2876 if (!allow_cds) { 2877 CDSConfig::set_module_patching_disables_cds(); 2878 if (strcmp(module_name, JAVA_BASE_NAME) == 0) { 2879 CDSConfig::set_java_base_module_patching_disables_cds(); 2880 } 2881 } 2882 2883 // Create GrowableArray lazily, only if --patch-module has been specified 2884 if (_patch_mod_prefix == nullptr) { 2885 _patch_mod_prefix = new (mtArguments) GrowableArray<ModulePatchPath*>(10, mtArguments); 2886 } 2887 2888 // Scan patches for matching module 2889 int i = _patch_mod_prefix->find_if([&](ModulePatchPath* patch) { 2890 return (strcmp(module_name, patch->module_name()) == 0); 2891 }); 2892 if (i == -1) { 2893 _patch_mod_prefix->push(new ModulePatchPath(module_name, path)); 2894 } else { 2895 if (allow_append) { 2896 // append path to existing module entry 2897 _patch_mod_prefix->at(i)->append_path(path); 2898 } else { 2899 if (strcmp(module_name, JAVA_BASE_NAME) == 0) { 2900 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module"); 2901 } else { 2902 vm_exit_during_initialization("Cannot specify a module more than once to --patch-module", module_name); 2903 } 2904 } 2905 } 2906 } 2907 2908 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled) 2909 // 2910 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar 2911 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar". 2912 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty 2913 // path is treated as the current directory. 2914 // 2915 // This causes problems with CDS, which requires that all directories specified in the classpath 2916 // must be empty. In most cases, applications do NOT want to load classes from the current 2917 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up 2918 // scripts compatible with CDS. 2919 void Arguments::fix_appclasspath() { 2920 if (IgnoreEmptyClassPaths) { 2921 const char separator = *os::path_separator(); 2922 const char* src = _java_class_path->value(); 2923 2924 // skip over all the leading empty paths 2925 while (*src == separator) { 2926 src ++; 2927 } 2928 2929 char* copy = os::strdup_check_oom(src, mtArguments); 2930 2931 // trim all trailing empty paths 2932 for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) { 2933 *tail = '\0'; 2934 } 2935 2936 char from[3] = {separator, separator, '\0'}; 2937 char to [2] = {separator, '\0'}; 2938 while (StringUtils::replace_no_expand(copy, from, to) > 0) { 2939 // Keep replacing "::" -> ":" until we have no more "::" (non-windows) 2940 // Keep replacing ";;" -> ";" until we have no more ";;" (windows) 2941 } 2942 2943 _java_class_path->set_writeable_value(copy); 2944 FreeHeap(copy); // a copy was made by set_value, so don't need this anymore 2945 } 2946 } 2947 2948 jint Arguments::finalize_vm_init_args() { 2949 // check if the default lib/endorsed directory exists; if so, error 2950 char path[JVM_MAXPATHLEN]; 2951 const char* fileSep = os::file_separator(); 2952 jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep); 2953 2954 DIR* dir = os::opendir(path); 2955 if (dir != nullptr) { 2956 jio_fprintf(defaultStream::output_stream(), 2957 "<JAVA_HOME>/lib/endorsed is not supported. Endorsed standards and standalone APIs\n" 2958 "in modular form will be supported via the concept of upgradeable modules.\n"); 2959 os::closedir(dir); 2960 return JNI_ERR; 2961 } 2962 2963 jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep); 2964 dir = os::opendir(path); 2965 if (dir != nullptr) { 2966 jio_fprintf(defaultStream::output_stream(), 2967 "<JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; " 2968 "Use -classpath instead.\n."); 2969 os::closedir(dir); 2970 return JNI_ERR; 2971 } 2972 2973 // This must be done after all arguments have been processed 2974 // and the container support has been initialized since AggressiveHeap 2975 // relies on the amount of total memory available. 2976 if (AggressiveHeap) { 2977 jint result = set_aggressive_heap_flags(); 2978 if (result != JNI_OK) { 2979 return result; 2980 } 2981 } 2982 2983 // CompileThresholdScaling == 0.0 is same as -Xint: Disable compilation (enable interpreter-only mode), 2984 // but like -Xint, leave compilation thresholds unaffected. 2985 // With tiered compilation disabled, setting CompileThreshold to 0 disables compilation as well. 2986 if ((CompileThresholdScaling == 0.0) || (!TieredCompilation && CompileThreshold == 0)) { 2987 set_mode_flags(_int); 2988 } 2989 2990 #ifdef ZERO 2991 // Zero always runs in interpreted mode 2992 set_mode_flags(_int); 2993 #endif 2994 2995 // eventually fix up InitialTenuringThreshold if only MaxTenuringThreshold is set 2996 if (FLAG_IS_DEFAULT(InitialTenuringThreshold) && (InitialTenuringThreshold > MaxTenuringThreshold)) { 2997 FLAG_SET_ERGO(InitialTenuringThreshold, MaxTenuringThreshold); 2998 } 2999 3000 #if !COMPILER2_OR_JVMCI 3001 // Don't degrade server performance for footprint 3002 if (FLAG_IS_DEFAULT(UseLargePages) && 3003 MaxHeapSize < LargePageHeapSizeThreshold) { 3004 // No need for large granularity pages w/small heaps. 3005 // Note that large pages are enabled/disabled for both the 3006 // Java heap and the code cache. 3007 FLAG_SET_DEFAULT(UseLargePages, false); 3008 } 3009 3010 UNSUPPORTED_OPTION(ProfileInterpreter); 3011 #endif 3012 3013 // Parse the CompilationMode flag 3014 if (!CompilationModeFlag::initialize()) { 3015 return JNI_ERR; 3016 } 3017 3018 if (!check_vm_args_consistency()) { 3019 return JNI_ERR; 3020 } 3021 3022 // finalize --module-patch and related --enable-preview 3023 if (finalize_patch_module() != JNI_OK) { 3024 return JNI_ERR; 3025 } 3026 3027 if (!CDSConfig::check_vm_args_consistency(mode_flag_cmd_line)) { 3028 return JNI_ERR; 3029 } 3030 3031 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT 3032 UNSUPPORTED_OPTION(ShowRegistersOnAssert); 3033 #endif // CAN_SHOW_REGISTERS_ON_ASSERT 3034 3035 return JNI_OK; 3036 } 3037 3038 // Helper class for controlling the lifetime of JavaVMInitArgs 3039 // objects. The contents of the JavaVMInitArgs are guaranteed to be 3040 // deleted on the destruction of the ScopedVMInitArgs object. 3041 class ScopedVMInitArgs : public StackObj { 3042 private: 3043 JavaVMInitArgs _args; 3044 char* _container_name; 3045 bool _is_set; 3046 char* _vm_options_file_arg; 3047 3048 public: 3049 ScopedVMInitArgs(const char *container_name) { 3050 _args.version = JNI_VERSION_1_2; 3051 _args.nOptions = 0; 3052 _args.options = nullptr; 3053 _args.ignoreUnrecognized = false; 3054 _container_name = (char *)container_name; 3055 _is_set = false; 3056 _vm_options_file_arg = nullptr; 3057 } 3058 3059 // Populates the JavaVMInitArgs object represented by this 3060 // ScopedVMInitArgs object with the arguments in options. The 3061 // allocated memory is deleted by the destructor. If this method 3062 // returns anything other than JNI_OK, then this object is in a 3063 // partially constructed state, and should be abandoned. 3064 jint set_args(const GrowableArrayView<JavaVMOption>* options) { 3065 _is_set = true; 3066 JavaVMOption* options_arr = NEW_C_HEAP_ARRAY_RETURN_NULL( 3067 JavaVMOption, options->length(), mtArguments); 3068 if (options_arr == nullptr) { 3069 return JNI_ENOMEM; 3070 } 3071 _args.options = options_arr; 3072 3073 for (int i = 0; i < options->length(); i++) { 3074 options_arr[i] = options->at(i); 3075 options_arr[i].optionString = os::strdup(options_arr[i].optionString); 3076 if (options_arr[i].optionString == nullptr) { 3077 // Rely on the destructor to do cleanup. 3078 _args.nOptions = i; 3079 return JNI_ENOMEM; 3080 } 3081 } 3082 3083 _args.nOptions = options->length(); 3084 _args.ignoreUnrecognized = IgnoreUnrecognizedVMOptions; 3085 return JNI_OK; 3086 } 3087 3088 JavaVMInitArgs* get() { return &_args; } 3089 char* container_name() { return _container_name; } 3090 bool is_set() { return _is_set; } 3091 bool found_vm_options_file_arg() { return _vm_options_file_arg != nullptr; } 3092 char* vm_options_file_arg() { return _vm_options_file_arg; } 3093 3094 void set_vm_options_file_arg(const char *vm_options_file_arg) { 3095 if (_vm_options_file_arg != nullptr) { 3096 os::free(_vm_options_file_arg); 3097 } 3098 _vm_options_file_arg = os::strdup_check_oom(vm_options_file_arg); 3099 } 3100 3101 ~ScopedVMInitArgs() { 3102 if (_vm_options_file_arg != nullptr) { 3103 os::free(_vm_options_file_arg); 3104 } 3105 if (_args.options == nullptr) return; 3106 for (int i = 0; i < _args.nOptions; i++) { 3107 os::free(_args.options[i].optionString); 3108 } 3109 FREE_C_HEAP_ARRAY(JavaVMOption, _args.options); 3110 } 3111 3112 // Insert options into this option list, to replace option at 3113 // vm_options_file_pos (-XX:VMOptionsFile) 3114 jint insert(const JavaVMInitArgs* args, 3115 const JavaVMInitArgs* args_to_insert, 3116 const int vm_options_file_pos) { 3117 assert(_args.options == nullptr, "shouldn't be set yet"); 3118 assert(args_to_insert->nOptions != 0, "there should be args to insert"); 3119 assert(vm_options_file_pos != -1, "vm_options_file_pos should be set"); 3120 3121 int length = args->nOptions + args_to_insert->nOptions - 1; 3122 // Construct new option array 3123 GrowableArrayCHeap<JavaVMOption, mtArguments> options(length); 3124 for (int i = 0; i < args->nOptions; i++) { 3125 if (i == vm_options_file_pos) { 3126 // insert the new options starting at the same place as the 3127 // -XX:VMOptionsFile option 3128 for (int j = 0; j < args_to_insert->nOptions; j++) { 3129 options.push(args_to_insert->options[j]); 3130 } 3131 } else { 3132 options.push(args->options[i]); 3133 } 3134 } 3135 // make into options array 3136 return set_args(&options); 3137 } 3138 }; 3139 3140 jint Arguments::parse_java_options_environment_variable(ScopedVMInitArgs* args) { 3141 return parse_options_environment_variable("_JAVA_OPTIONS", args); 3142 } 3143 3144 jint Arguments::parse_java_tool_options_environment_variable(ScopedVMInitArgs* args) { 3145 return parse_options_environment_variable("JAVA_TOOL_OPTIONS", args); 3146 } 3147 3148 jint Arguments::parse_options_environment_variable(const char* name, 3149 ScopedVMInitArgs* vm_args) { 3150 char *buffer = ::getenv(name); 3151 3152 // Don't check this environment variable if user has special privileges 3153 // (e.g. unix su command). 3154 if (buffer == nullptr || os::have_special_privileges()) { 3155 return JNI_OK; 3156 } 3157 3158 if ((buffer = os::strdup(buffer)) == nullptr) { 3159 return JNI_ENOMEM; 3160 } 3161 3162 jio_fprintf(defaultStream::error_stream(), 3163 "Picked up %s: %s\n", name, buffer); 3164 3165 int retcode = parse_options_buffer(name, buffer, strlen(buffer), vm_args); 3166 3167 os::free(buffer); 3168 return retcode; 3169 } 3170 3171 jint Arguments::parse_vm_options_file(const char* file_name, ScopedVMInitArgs* vm_args) { 3172 // read file into buffer 3173 int fd = ::open(file_name, O_RDONLY); 3174 if (fd < 0) { 3175 jio_fprintf(defaultStream::error_stream(), 3176 "Could not open options file '%s'\n", 3177 file_name); 3178 return JNI_ERR; 3179 } 3180 3181 struct stat stbuf; 3182 int retcode = os::stat(file_name, &stbuf); 3183 if (retcode != 0) { 3184 jio_fprintf(defaultStream::error_stream(), 3185 "Could not stat options file '%s'\n", 3186 file_name); 3187 ::close(fd); 3188 return JNI_ERR; 3189 } 3190 3191 if (stbuf.st_size == 0) { 3192 // tell caller there is no option data and that is ok 3193 ::close(fd); 3194 return JNI_OK; 3195 } 3196 3197 // '+ 1' for null termination even with max bytes 3198 size_t bytes_alloc = stbuf.st_size + 1; 3199 3200 char *buf = NEW_C_HEAP_ARRAY_RETURN_NULL(char, bytes_alloc, mtArguments); 3201 if (nullptr == buf) { 3202 jio_fprintf(defaultStream::error_stream(), 3203 "Could not allocate read buffer for options file parse\n"); 3204 ::close(fd); 3205 return JNI_ENOMEM; 3206 } 3207 3208 memset(buf, 0, bytes_alloc); 3209 3210 // Fill buffer 3211 ssize_t bytes_read = ::read(fd, (void *)buf, (unsigned)bytes_alloc); 3212 ::close(fd); 3213 if (bytes_read < 0) { 3214 FREE_C_HEAP_ARRAY(char, buf); 3215 jio_fprintf(defaultStream::error_stream(), 3216 "Could not read options file '%s'\n", file_name); 3217 return JNI_ERR; 3218 } 3219 3220 if (bytes_read == 0) { 3221 // tell caller there is no option data and that is ok 3222 FREE_C_HEAP_ARRAY(char, buf); 3223 return JNI_OK; 3224 } 3225 3226 retcode = parse_options_buffer(file_name, buf, bytes_read, vm_args); 3227 3228 FREE_C_HEAP_ARRAY(char, buf); 3229 return retcode; 3230 } 3231 3232 jint Arguments::parse_options_buffer(const char* name, char* buffer, const size_t buf_len, ScopedVMInitArgs* vm_args) { 3233 // Construct option array 3234 GrowableArrayCHeap<JavaVMOption, mtArguments> options(2); 3235 3236 // some pointers to help with parsing 3237 char *buffer_end = buffer + buf_len; 3238 char *opt_hd = buffer; 3239 char *wrt = buffer; 3240 char *rd = buffer; 3241 3242 // parse all options 3243 while (rd < buffer_end) { 3244 // skip leading white space from the input string 3245 while (rd < buffer_end && isspace((unsigned char) *rd)) { 3246 rd++; 3247 } 3248 3249 if (rd >= buffer_end) { 3250 break; 3251 } 3252 3253 // Remember this is where we found the head of the token. 3254 opt_hd = wrt; 3255 3256 // Tokens are strings of non white space characters separated 3257 // by one or more white spaces. 3258 while (rd < buffer_end && !isspace((unsigned char) *rd)) { 3259 if (*rd == '\'' || *rd == '"') { // handle a quoted string 3260 int quote = *rd; // matching quote to look for 3261 rd++; // don't copy open quote 3262 while (rd < buffer_end && *rd != quote) { 3263 // include everything (even spaces) 3264 // up until the close quote 3265 *wrt++ = *rd++; // copy to option string 3266 } 3267 3268 if (rd < buffer_end) { 3269 rd++; // don't copy close quote 3270 } else { 3271 // did not see closing quote 3272 jio_fprintf(defaultStream::error_stream(), 3273 "Unmatched quote in %s\n", name); 3274 return JNI_ERR; 3275 } 3276 } else { 3277 *wrt++ = *rd++; // copy to option string 3278 } 3279 } 3280 3281 // steal a white space character and set it to null 3282 *wrt++ = '\0'; 3283 // We now have a complete token 3284 3285 JavaVMOption option; 3286 option.optionString = opt_hd; 3287 option.extraInfo = nullptr; 3288 3289 options.append(option); // Fill in option 3290 3291 rd++; // Advance to next character 3292 } 3293 3294 // Fill out JavaVMInitArgs structure. 3295 return vm_args->set_args(&options); 3296 } 3297 3298 #ifndef PRODUCT 3299 // Determine whether LogVMOutput should be implicitly turned on. 3300 static bool use_vm_log() { 3301 if (LogCompilation || !FLAG_IS_DEFAULT(LogFile) || 3302 PrintCompilation || PrintInlining || PrintDependencies || PrintNativeNMethods || 3303 PrintDebugInfo || PrintRelocations || PrintNMethods || PrintExceptionHandlers || 3304 PrintAssembly || TraceDeoptimization || 3305 (VerifyDependencies && FLAG_IS_CMDLINE(VerifyDependencies))) { 3306 return true; 3307 } 3308 3309 #ifdef COMPILER1 3310 if (PrintC1Statistics) { 3311 return true; 3312 } 3313 #endif // COMPILER1 3314 3315 #ifdef COMPILER2 3316 if (PrintOptoAssembly || PrintOptoStatistics) { 3317 return true; 3318 } 3319 #endif // COMPILER2 3320 3321 return false; 3322 } 3323 3324 #endif // PRODUCT 3325 3326 bool Arguments::args_contains_vm_options_file_arg(const JavaVMInitArgs* args) { 3327 for (int index = 0; index < args->nOptions; index++) { 3328 const JavaVMOption* option = args->options + index; 3329 const char* tail; 3330 if (match_option(option, "-XX:VMOptionsFile=", &tail)) { 3331 return true; 3332 } 3333 } 3334 return false; 3335 } 3336 3337 jint Arguments::insert_vm_options_file(const JavaVMInitArgs* args, 3338 const char* vm_options_file, 3339 const int vm_options_file_pos, 3340 ScopedVMInitArgs* vm_options_file_args, 3341 ScopedVMInitArgs* args_out) { 3342 jint code = parse_vm_options_file(vm_options_file, vm_options_file_args); 3343 if (code != JNI_OK) { 3344 return code; 3345 } 3346 3347 if (vm_options_file_args->get()->nOptions < 1) { 3348 return JNI_OK; 3349 } 3350 3351 if (args_contains_vm_options_file_arg(vm_options_file_args->get())) { 3352 jio_fprintf(defaultStream::error_stream(), 3353 "A VM options file may not refer to a VM options file. " 3354 "Specification of '-XX:VMOptionsFile=<file-name>' in the " 3355 "options file '%s' in options container '%s' is an error.\n", 3356 vm_options_file_args->vm_options_file_arg(), 3357 vm_options_file_args->container_name()); 3358 return JNI_EINVAL; 3359 } 3360 3361 return args_out->insert(args, vm_options_file_args->get(), 3362 vm_options_file_pos); 3363 } 3364 3365 // Expand -XX:VMOptionsFile found in args_in as needed. 3366 // mod_args and args_out parameters may return values as needed. 3367 jint Arguments::expand_vm_options_as_needed(const JavaVMInitArgs* args_in, 3368 ScopedVMInitArgs* mod_args, 3369 JavaVMInitArgs** args_out) { 3370 jint code = match_special_option_and_act(args_in, mod_args); 3371 if (code != JNI_OK) { 3372 return code; 3373 } 3374 3375 if (mod_args->is_set()) { 3376 // args_in contains -XX:VMOptionsFile and mod_args contains the 3377 // original options from args_in along with the options expanded 3378 // from the VMOptionsFile. Return a short-hand to the caller. 3379 *args_out = mod_args->get(); 3380 } else { 3381 *args_out = (JavaVMInitArgs *)args_in; // no changes so use args_in 3382 } 3383 return JNI_OK; 3384 } 3385 3386 jint Arguments::match_special_option_and_act(const JavaVMInitArgs* args, 3387 ScopedVMInitArgs* args_out) { 3388 // Remaining part of option string 3389 const char* tail; 3390 ScopedVMInitArgs vm_options_file_args(args_out->container_name()); 3391 3392 for (int index = 0; index < args->nOptions; index++) { 3393 const JavaVMOption* option = args->options + index; 3394 if (match_option(option, "-XX:Flags=", &tail)) { 3395 Arguments::set_jvm_flags_file(tail); 3396 continue; 3397 } 3398 if (match_option(option, "-XX:VMOptionsFile=", &tail)) { 3399 if (vm_options_file_args.found_vm_options_file_arg()) { 3400 jio_fprintf(defaultStream::error_stream(), 3401 "The option '%s' is already specified in the options " 3402 "container '%s' so the specification of '%s' in the " 3403 "same options container is an error.\n", 3404 vm_options_file_args.vm_options_file_arg(), 3405 vm_options_file_args.container_name(), 3406 option->optionString); 3407 return JNI_EINVAL; 3408 } 3409 vm_options_file_args.set_vm_options_file_arg(option->optionString); 3410 // If there's a VMOptionsFile, parse that 3411 jint code = insert_vm_options_file(args, tail, index, 3412 &vm_options_file_args, args_out); 3413 if (code != JNI_OK) { 3414 return code; 3415 } 3416 args_out->set_vm_options_file_arg(vm_options_file_args.vm_options_file_arg()); 3417 if (args_out->is_set()) { 3418 // The VMOptions file inserted some options so switch 'args' 3419 // to the new set of options, and continue processing which 3420 // preserves "last option wins" semantics. 3421 args = args_out->get(); 3422 // The first option from the VMOptionsFile replaces the 3423 // current option. So we back track to process the 3424 // replacement option. 3425 index--; 3426 } 3427 continue; 3428 } 3429 if (match_option(option, "-XX:+PrintVMOptions")) { 3430 PrintVMOptions = true; 3431 continue; 3432 } 3433 if (match_option(option, "-XX:-PrintVMOptions")) { 3434 PrintVMOptions = false; 3435 continue; 3436 } 3437 if (match_option(option, "-XX:+IgnoreUnrecognizedVMOptions")) { 3438 IgnoreUnrecognizedVMOptions = true; 3439 continue; 3440 } 3441 if (match_option(option, "-XX:-IgnoreUnrecognizedVMOptions")) { 3442 IgnoreUnrecognizedVMOptions = false; 3443 continue; 3444 } 3445 if (match_option(option, "-XX:+PrintFlagsInitial")) { 3446 JVMFlag::printFlags(tty, false); 3447 vm_exit(0); 3448 } 3449 3450 #ifndef PRODUCT 3451 if (match_option(option, "-XX:+PrintFlagsWithComments")) { 3452 JVMFlag::printFlags(tty, true); 3453 vm_exit(0); 3454 } 3455 #endif 3456 } 3457 return JNI_OK; 3458 } 3459 3460 static void print_options(const JavaVMInitArgs *args) { 3461 const char* tail; 3462 for (int index = 0; index < args->nOptions; index++) { 3463 const JavaVMOption *option = args->options + index; 3464 if (match_option(option, "-XX:", &tail)) { 3465 logOption(tail); 3466 } 3467 } 3468 } 3469 3470 bool Arguments::handle_deprecated_print_gc_flags() { 3471 if (PrintGC) { 3472 log_warning(gc)("-XX:+PrintGC is deprecated. Will use -Xlog:gc instead."); 3473 } 3474 if (PrintGCDetails) { 3475 log_warning(gc)("-XX:+PrintGCDetails is deprecated. Will use -Xlog:gc* instead."); 3476 } 3477 3478 if (_legacyGCLogging.lastFlag == 2) { 3479 // -Xloggc was used to specify a filename 3480 const char* gc_conf = PrintGCDetails ? "gc*" : "gc"; 3481 3482 LogTarget(Error, logging) target; 3483 LogStream errstream(target); 3484 return LogConfiguration::parse_log_arguments(_legacyGCLogging.file, gc_conf, nullptr, nullptr, &errstream); 3485 } else if (PrintGC || PrintGCDetails || (_legacyGCLogging.lastFlag == 1)) { 3486 LogConfiguration::configure_stdout(LogLevel::Info, !PrintGCDetails, LOG_TAGS(gc)); 3487 } 3488 return true; 3489 } 3490 3491 static void apply_debugger_ergo() { 3492 #ifdef ASSERT 3493 if (ReplayCompiles) { 3494 FLAG_SET_ERGO_IF_DEFAULT(UseDebuggerErgo, true); 3495 } 3496 3497 if (UseDebuggerErgo) { 3498 // Turn on sub-flags 3499 FLAG_SET_ERGO_IF_DEFAULT(UseDebuggerErgo1, true); 3500 FLAG_SET_ERGO_IF_DEFAULT(UseDebuggerErgo2, true); 3501 } 3502 3503 if (UseDebuggerErgo2) { 3504 // Debugging with limited number of CPUs 3505 FLAG_SET_ERGO_IF_DEFAULT(UseNUMA, false); 3506 FLAG_SET_ERGO_IF_DEFAULT(ConcGCThreads, 1); 3507 FLAG_SET_ERGO_IF_DEFAULT(ParallelGCThreads, 1); 3508 FLAG_SET_ERGO_IF_DEFAULT(CICompilerCount, 2); 3509 } 3510 #endif // ASSERT 3511 } 3512 3513 // Parse entry point called from JNI_CreateJavaVM 3514 3515 jint Arguments::parse(const JavaVMInitArgs* initial_cmd_args) { 3516 assert(verify_special_jvm_flags(false), "deprecated and obsolete flag table inconsistent"); 3517 JVMFlag::check_all_flag_declarations(); 3518 3519 // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed. 3520 const char* hotspotrc = ".hotspotrc"; 3521 bool settings_file_specified = false; 3522 bool needs_hotspotrc_warning = false; 3523 ScopedVMInitArgs initial_vm_options_args(""); 3524 ScopedVMInitArgs initial_java_tool_options_args("env_var='JAVA_TOOL_OPTIONS'"); 3525 ScopedVMInitArgs initial_java_options_args("env_var='_JAVA_OPTIONS'"); 3526 3527 // Pointers to current working set of containers 3528 JavaVMInitArgs* cur_cmd_args; 3529 JavaVMInitArgs* cur_vm_options_args; 3530 JavaVMInitArgs* cur_java_options_args; 3531 JavaVMInitArgs* cur_java_tool_options_args; 3532 3533 // Containers for modified/expanded options 3534 ScopedVMInitArgs mod_cmd_args("cmd_line_args"); 3535 ScopedVMInitArgs mod_vm_options_args("vm_options_args"); 3536 ScopedVMInitArgs mod_java_tool_options_args("env_var='JAVA_TOOL_OPTIONS'"); 3537 ScopedVMInitArgs mod_java_options_args("env_var='_JAVA_OPTIONS'"); 3538 3539 3540 jint code = 3541 parse_java_tool_options_environment_variable(&initial_java_tool_options_args); 3542 if (code != JNI_OK) { 3543 return code; 3544 } 3545 3546 code = parse_java_options_environment_variable(&initial_java_options_args); 3547 if (code != JNI_OK) { 3548 return code; 3549 } 3550 3551 // Parse the options in the /java.base/jdk/internal/vm/options resource, if present 3552 char *vmoptions = ClassLoader::lookup_vm_options(); 3553 if (vmoptions != nullptr) { 3554 code = parse_options_buffer("vm options resource", vmoptions, strlen(vmoptions), &initial_vm_options_args); 3555 FREE_C_HEAP_ARRAY(char, vmoptions); 3556 if (code != JNI_OK) { 3557 return code; 3558 } 3559 } 3560 3561 code = expand_vm_options_as_needed(initial_java_tool_options_args.get(), 3562 &mod_java_tool_options_args, 3563 &cur_java_tool_options_args); 3564 if (code != JNI_OK) { 3565 return code; 3566 } 3567 3568 code = expand_vm_options_as_needed(initial_cmd_args, 3569 &mod_cmd_args, 3570 &cur_cmd_args); 3571 if (code != JNI_OK) { 3572 return code; 3573 } 3574 3575 code = expand_vm_options_as_needed(initial_java_options_args.get(), 3576 &mod_java_options_args, 3577 &cur_java_options_args); 3578 if (code != JNI_OK) { 3579 return code; 3580 } 3581 3582 code = expand_vm_options_as_needed(initial_vm_options_args.get(), 3583 &mod_vm_options_args, 3584 &cur_vm_options_args); 3585 if (code != JNI_OK) { 3586 return code; 3587 } 3588 3589 const char* flags_file = Arguments::get_jvm_flags_file(); 3590 settings_file_specified = (flags_file != nullptr); 3591 3592 if (IgnoreUnrecognizedVMOptions) { 3593 cur_cmd_args->ignoreUnrecognized = true; 3594 cur_java_tool_options_args->ignoreUnrecognized = true; 3595 cur_java_options_args->ignoreUnrecognized = true; 3596 } 3597 3598 // Parse specified settings file 3599 if (settings_file_specified) { 3600 if (!process_settings_file(flags_file, true, 3601 cur_cmd_args->ignoreUnrecognized)) { 3602 return JNI_EINVAL; 3603 } 3604 } else { 3605 #ifdef ASSERT 3606 // Parse default .hotspotrc settings file 3607 if (!process_settings_file(".hotspotrc", false, 3608 cur_cmd_args->ignoreUnrecognized)) { 3609 return JNI_EINVAL; 3610 } 3611 #else 3612 struct stat buf; 3613 if (os::stat(hotspotrc, &buf) == 0) { 3614 needs_hotspotrc_warning = true; 3615 } 3616 #endif 3617 } 3618 3619 if (PrintVMOptions) { 3620 print_options(cur_java_tool_options_args); 3621 print_options(cur_cmd_args); 3622 print_options(cur_java_options_args); 3623 } 3624 3625 // Parse JavaVMInitArgs structure passed in, as well as JAVA_TOOL_OPTIONS and _JAVA_OPTIONS 3626 jint result = parse_vm_init_args(cur_vm_options_args, 3627 cur_java_tool_options_args, 3628 cur_java_options_args, 3629 cur_cmd_args); 3630 3631 if (result != JNI_OK) { 3632 return result; 3633 } 3634 3635 // Delay warning until here so that we've had a chance to process 3636 // the -XX:-PrintWarnings flag 3637 if (needs_hotspotrc_warning) { 3638 warning("%s file is present but has been ignored. " 3639 "Run with -XX:Flags=%s to load the file.", 3640 hotspotrc, hotspotrc); 3641 } 3642 3643 if (needs_module_property_warning) { 3644 warning("Ignoring system property options whose names match the '-Djdk.module.*'." 3645 " names that are reserved for internal use."); 3646 } 3647 3648 #if defined(_ALLBSD_SOURCE) || defined(AIX) // UseLargePages is not yet supported on BSD and AIX. 3649 UNSUPPORTED_OPTION(UseLargePages); 3650 #endif 3651 3652 #if defined(AIX) 3653 UNSUPPORTED_OPTION_NULL(AllocateHeapAt); 3654 #endif 3655 3656 #ifndef PRODUCT 3657 if (TraceBytecodesAt != 0) { 3658 TraceBytecodes = true; 3659 } 3660 #endif // PRODUCT 3661 3662 if (ScavengeRootsInCode == 0) { 3663 if (!FLAG_IS_DEFAULT(ScavengeRootsInCode)) { 3664 warning("Forcing ScavengeRootsInCode non-zero"); 3665 } 3666 ScavengeRootsInCode = 1; 3667 } 3668 3669 if (!handle_deprecated_print_gc_flags()) { 3670 return JNI_EINVAL; 3671 } 3672 3673 // Set object alignment values. 3674 set_object_alignment(); 3675 3676 #if !INCLUDE_CDS 3677 if (CDSConfig::is_dumping_static_archive() || RequireSharedSpaces) { 3678 jio_fprintf(defaultStream::error_stream(), 3679 "Shared spaces are not supported in this VM\n"); 3680 return JNI_ERR; 3681 } 3682 if (DumpLoadedClassList != nullptr) { 3683 jio_fprintf(defaultStream::error_stream(), 3684 "DumpLoadedClassList is not supported in this VM\n"); 3685 return JNI_ERR; 3686 } 3687 if ((CDSConfig::is_using_archive() && xshare_auto_cmd_line) || 3688 log_is_enabled(Info, cds)) { 3689 warning("Shared spaces are not supported in this VM"); 3690 UseSharedSpaces = false; 3691 LogConfiguration::configure_stdout(LogLevel::Off, true, LOG_TAGS(cds)); 3692 } 3693 no_shared_spaces("CDS Disabled"); 3694 #endif // INCLUDE_CDS 3695 3696 // Verify NMT arguments 3697 const NMT_TrackingLevel lvl = NMTUtil::parse_tracking_level(NativeMemoryTracking); 3698 if (lvl == NMT_unknown) { 3699 jio_fprintf(defaultStream::error_stream(), 3700 "Syntax error, expecting -XX:NativeMemoryTracking=[off|summary|detail]\n"); 3701 return JNI_ERR; 3702 } 3703 if (PrintNMTStatistics && lvl == NMT_off) { 3704 warning("PrintNMTStatistics is disabled, because native memory tracking is not enabled"); 3705 FLAG_SET_DEFAULT(PrintNMTStatistics, false); 3706 } 3707 3708 bool trace_dependencies = log_is_enabled(Debug, dependencies); 3709 if (trace_dependencies && VerifyDependencies) { 3710 warning("dependency logging results may be inflated by VerifyDependencies"); 3711 } 3712 3713 bool log_class_load_cause = log_is_enabled(Info, class, load, cause, native) || 3714 log_is_enabled(Info, class, load, cause); 3715 if (log_class_load_cause && LogClassLoadingCauseFor == nullptr) { 3716 warning("class load cause logging will not produce output without LogClassLoadingCauseFor"); 3717 } 3718 3719 apply_debugger_ergo(); 3720 3721 // The VMThread needs to stop now and then to execute these debug options. 3722 if ((HandshakeALot || SafepointALot) && FLAG_IS_DEFAULT(GuaranteedSafepointInterval)) { 3723 FLAG_SET_DEFAULT(GuaranteedSafepointInterval, 1000); 3724 } 3725 3726 if (log_is_enabled(Info, arguments)) { 3727 LogStream st(Log(arguments)::info()); 3728 Arguments::print_on(&st); 3729 } 3730 3731 return JNI_OK; 3732 } 3733 3734 jint Arguments::apply_ergo() { 3735 // Set flags based on ergonomics. 3736 jint result = set_ergonomics_flags(); 3737 if (result != JNI_OK) return result; 3738 3739 // Set heap size based on available physical memory 3740 set_heap_size(); 3741 3742 GCConfig::arguments()->initialize(); 3743 3744 CDSConfig::initialize(); 3745 3746 // Initialize Metaspace flags and alignments 3747 Metaspace::ergo_initialize(); 3748 3749 if (!StringDedup::ergo_initialize()) { 3750 return JNI_EINVAL; 3751 } 3752 3753 // Set compiler flags after GC is selected and GC specific 3754 // flags (LoopStripMiningIter) are set. 3755 CompilerConfig::ergo_initialize(); 3756 3757 // Set bytecode rewriting flags 3758 set_bytecode_flags(); 3759 3760 // Set flags if aggressive optimization flags are enabled 3761 jint code = set_aggressive_opts_flags(); 3762 if (code != JNI_OK) { 3763 return code; 3764 } 3765 3766 if (FLAG_IS_DEFAULT(UseSecondarySupersTable)) { 3767 FLAG_SET_DEFAULT(UseSecondarySupersTable, VM_Version::supports_secondary_supers_table()); 3768 } else if (UseSecondarySupersTable && !VM_Version::supports_secondary_supers_table()) { 3769 warning("UseSecondarySupersTable is not supported"); 3770 FLAG_SET_DEFAULT(UseSecondarySupersTable, false); 3771 } 3772 if (!UseSecondarySupersTable) { 3773 FLAG_SET_DEFAULT(StressSecondarySupers, false); 3774 FLAG_SET_DEFAULT(VerifySecondarySupers, false); 3775 } 3776 3777 #ifdef ZERO 3778 // Clear flags not supported on zero. 3779 FLAG_SET_DEFAULT(ProfileInterpreter, false); 3780 #endif // ZERO 3781 3782 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) { 3783 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output"); 3784 DebugNonSafepoints = true; 3785 } 3786 3787 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) { 3788 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used"); 3789 } 3790 3791 // Treat the odd case where local verification is enabled but remote 3792 // verification is not as if both were enabled. 3793 if (BytecodeVerificationLocal && !BytecodeVerificationRemote) { 3794 log_info(verification)("Turning on remote verification because local verification is on"); 3795 FLAG_SET_DEFAULT(BytecodeVerificationRemote, true); 3796 } 3797 if (!EnableValhalla || (is_interpreter_only() && !CDSConfig::is_dumping_archive() && !UseSharedSpaces)) { 3798 // Disable calling convention optimizations if inline types are not supported. 3799 // Also these aren't useful in -Xint. However, don't disable them when dumping or using 3800 // the CDS archive, as the values must match between dumptime and runtime. 3801 InlineTypePassFieldsAsArgs = false; 3802 InlineTypeReturnedAsFields = false; 3803 } 3804 3805 #ifndef PRODUCT 3806 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) { 3807 if (use_vm_log()) { 3808 LogVMOutput = true; 3809 } 3810 } 3811 #endif // PRODUCT 3812 3813 if (PrintCommandLineFlags) { 3814 JVMFlag::printSetFlags(tty); 3815 } 3816 3817 #if COMPILER2_OR_JVMCI 3818 if (!FLAG_IS_DEFAULT(EnableVectorSupport) && !EnableVectorSupport) { 3819 if (!FLAG_IS_DEFAULT(EnableVectorReboxing) && EnableVectorReboxing) { 3820 warning("Disabling EnableVectorReboxing since EnableVectorSupport is turned off."); 3821 } 3822 FLAG_SET_DEFAULT(EnableVectorReboxing, false); 3823 3824 if (!FLAG_IS_DEFAULT(EnableVectorAggressiveReboxing) && EnableVectorAggressiveReboxing) { 3825 if (!EnableVectorReboxing) { 3826 warning("Disabling EnableVectorAggressiveReboxing since EnableVectorReboxing is turned off."); 3827 } else { 3828 warning("Disabling EnableVectorAggressiveReboxing since EnableVectorSupport is turned off."); 3829 } 3830 } 3831 FLAG_SET_DEFAULT(EnableVectorAggressiveReboxing, false); 3832 3833 if (!FLAG_IS_DEFAULT(UseVectorStubs) && UseVectorStubs) { 3834 warning("Disabling UseVectorStubs since EnableVectorSupport is turned off."); 3835 } 3836 FLAG_SET_DEFAULT(UseVectorStubs, false); 3837 } 3838 #endif // COMPILER2_OR_JVMCI 3839 3840 if (log_is_enabled(Info, perf, class, link)) { 3841 if (!UsePerfData) { 3842 warning("Disabling -Xlog:perf+class+link since UsePerfData is turned off."); 3843 LogConfiguration::configure_stdout(LogLevel::Off, false, LOG_TAGS(perf, class, link)); 3844 } 3845 } 3846 3847 if (FLAG_IS_CMDLINE(DiagnoseSyncOnValueBasedClasses)) { 3848 if (DiagnoseSyncOnValueBasedClasses == ObjectSynchronizer::LOG_WARNING && !log_is_enabled(Info, valuebasedclasses)) { 3849 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(valuebasedclasses)); 3850 } 3851 } 3852 return JNI_OK; 3853 } 3854 3855 jint Arguments::adjust_after_os() { 3856 if (UseNUMA) { 3857 if (UseParallelGC) { 3858 if (FLAG_IS_DEFAULT(MinHeapDeltaBytes)) { 3859 FLAG_SET_DEFAULT(MinHeapDeltaBytes, 64*M); 3860 } 3861 } 3862 } 3863 return JNI_OK; 3864 } 3865 3866 int Arguments::PropertyList_count(SystemProperty* pl) { 3867 int count = 0; 3868 while(pl != nullptr) { 3869 count++; 3870 pl = pl->next(); 3871 } 3872 return count; 3873 } 3874 3875 // Return the number of readable properties. 3876 int Arguments::PropertyList_readable_count(SystemProperty* pl) { 3877 int count = 0; 3878 while(pl != nullptr) { 3879 if (pl->readable()) { 3880 count++; 3881 } 3882 pl = pl->next(); 3883 } 3884 return count; 3885 } 3886 3887 const char* Arguments::PropertyList_get_value(SystemProperty *pl, const char* key) { 3888 assert(key != nullptr, "just checking"); 3889 SystemProperty* prop; 3890 for (prop = pl; prop != nullptr; prop = prop->next()) { 3891 if (strcmp(key, prop->key()) == 0) return prop->value(); 3892 } 3893 return nullptr; 3894 } 3895 3896 // Return the value of the requested property provided that it is a readable property. 3897 const char* Arguments::PropertyList_get_readable_value(SystemProperty *pl, const char* key) { 3898 assert(key != nullptr, "just checking"); 3899 SystemProperty* prop; 3900 // Return the property value if the keys match and the property is not internal or 3901 // it's the special internal property "jdk.boot.class.path.append". 3902 for (prop = pl; prop != nullptr; prop = prop->next()) { 3903 if (strcmp(key, prop->key()) == 0) { 3904 if (!prop->internal()) { 3905 return prop->value(); 3906 } else if (strcmp(key, "jdk.boot.class.path.append") == 0) { 3907 return prop->value(); 3908 } else { 3909 // Property is internal and not jdk.boot.class.path.append so return null. 3910 return nullptr; 3911 } 3912 } 3913 } 3914 return nullptr; 3915 } 3916 3917 void Arguments::PropertyList_add(SystemProperty** plist, SystemProperty *new_p) { 3918 SystemProperty* p = *plist; 3919 if (p == nullptr) { 3920 *plist = new_p; 3921 } else { 3922 while (p->next() != nullptr) { 3923 p = p->next(); 3924 } 3925 p->set_next(new_p); 3926 } 3927 } 3928 3929 void Arguments::PropertyList_add(SystemProperty** plist, const char* k, const char* v, 3930 bool writeable, bool internal) { 3931 if (plist == nullptr) 3932 return; 3933 3934 SystemProperty* new_p = new SystemProperty(k, v, writeable, internal); 3935 PropertyList_add(plist, new_p); 3936 } 3937 3938 void Arguments::PropertyList_add(SystemProperty *element) { 3939 PropertyList_add(&_system_properties, element); 3940 } 3941 3942 // This add maintains unique property key in the list. 3943 void Arguments::PropertyList_unique_add(SystemProperty** plist, const char* k, const char* v, 3944 PropertyAppendable append, PropertyWriteable writeable, 3945 PropertyInternal internal) { 3946 if (plist == nullptr) 3947 return; 3948 3949 // If property key exists and is writeable, then update with new value. 3950 // Trying to update a non-writeable property is silently ignored. 3951 SystemProperty* prop; 3952 for (prop = *plist; prop != nullptr; prop = prop->next()) { 3953 if (strcmp(k, prop->key()) == 0) { 3954 if (append == AppendProperty) { 3955 prop->append_writeable_value(v); 3956 } else { 3957 prop->set_writeable_value(v); 3958 } 3959 return; 3960 } 3961 } 3962 3963 PropertyList_add(plist, k, v, writeable == WriteableProperty, internal == InternalProperty); 3964 } 3965 3966 // Copies src into buf, replacing "%%" with "%" and "%p" with pid 3967 // Returns true if all of the source pointed by src has been copied over to 3968 // the destination buffer pointed by buf. Otherwise, returns false. 3969 // Notes: 3970 // 1. If the length (buflen) of the destination buffer excluding the 3971 // null terminator character is not long enough for holding the expanded 3972 // pid characters, it also returns false instead of returning the partially 3973 // expanded one. 3974 // 2. The passed in "buflen" should be large enough to hold the null terminator. 3975 bool Arguments::copy_expand_pid(const char* src, size_t srclen, 3976 char* buf, size_t buflen) { 3977 const char* p = src; 3978 char* b = buf; 3979 const char* src_end = &src[srclen]; 3980 char* buf_end = &buf[buflen - 1]; 3981 3982 while (p < src_end && b < buf_end) { 3983 if (*p == '%') { 3984 switch (*(++p)) { 3985 case '%': // "%%" ==> "%" 3986 *b++ = *p++; 3987 break; 3988 case 'p': { // "%p" ==> current process id 3989 // buf_end points to the character before the last character so 3990 // that we could write '\0' to the end of the buffer. 3991 size_t buf_sz = buf_end - b + 1; 3992 int ret = jio_snprintf(b, buf_sz, "%d", os::current_process_id()); 3993 3994 // if jio_snprintf fails or the buffer is not long enough to hold 3995 // the expanded pid, returns false. 3996 if (ret < 0 || ret >= (int)buf_sz) { 3997 return false; 3998 } else { 3999 b += ret; 4000 assert(*b == '\0', "fail in copy_expand_pid"); 4001 if (p == src_end && b == buf_end + 1) { 4002 // reach the end of the buffer. 4003 return true; 4004 } 4005 } 4006 p++; 4007 break; 4008 } 4009 default : 4010 *b++ = '%'; 4011 } 4012 } else { 4013 *b++ = *p++; 4014 } 4015 } 4016 *b = '\0'; 4017 return (p == src_end); // return false if not all of the source was copied 4018 }