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