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