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