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