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