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