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