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