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