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