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