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