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