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