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