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