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