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