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