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