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