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