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