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