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 void Arguments::check_unsupported_dumping_properties() { 1450 assert(DumpSharedSpaces, "this function is only used with -Xshare:dump"); 1451 const char* unsupported_properties[] = { "jdk.module.main", 1452 "jdk.module.limitmods", 1453 "jdk.module.path", 1454 "jdk.module.upgrade.path", 1455 "jdk.module.patch.0" }; 1456 const char* unsupported_options[] = { "-m", // cannot use at dump time 1457 "--limit-modules", // ignored at dump time 1458 "--module-path", // ignored at dump time 1459 "--upgrade-module-path", // ignored at dump time 1460 "--patch-module" // ignored at dump time 1461 }; 1462 assert(ARRAY_SIZE(unsupported_properties) == ARRAY_SIZE(unsupported_options), "must be"); 1463 // If a vm option is found in the unsupported_options array with index less than the info_idx, 1464 // vm will exit with an error message. Otherwise, it will print an informational message if 1465 // -Xlog:cds is enabled. 1466 uint info_idx = 1; 1467 SystemProperty* sp = system_properties(); 1468 while (sp != NULL) { 1469 for (uint i = 0; i < ARRAY_SIZE(unsupported_properties); i++) { 1470 if (strcmp(sp->key(), unsupported_properties[i]) == 0) { 1471 if (i < info_idx) { 1472 vm_exit_during_initialization( 1473 "Cannot use the following option when dumping the shared archive", unsupported_options[i]); 1474 } else { 1475 log_info(cds)("Info: the %s option is ignored when dumping the shared archive", 1476 unsupported_options[i]); 1477 } 1478 } 1479 } 1480 sp = sp->next(); 1481 } 1482 1483 // Check for an exploded module build in use with -Xshare:dump. 1484 if (!has_jimage()) { 1485 vm_exit_during_initialization("Dumping the shared archive is not supported with an exploded module build"); 1486 } 1487 } 1488 #endif 1489 1490 //=========================================================================================================== 1491 // Setting int/mixed/comp mode flags 1492 1493 void Arguments::set_mode_flags(Mode mode) { 1494 // Set up default values for all flags. 1495 // If you add a flag to any of the branches below, 1496 // add a default value for it here. 1497 set_java_compiler(false); 1498 _mode = mode; 1499 1500 // Ensure Agent_OnLoad has the correct initial values. 1501 // This may not be the final mode; mode may change later in onload phase. 1502 PropertyList_unique_add(&_system_properties, "java.vm.info", 1503 VM_Version::vm_info_string(), AddProperty, UnwriteableProperty, ExternalProperty); 1504 1505 UseInterpreter = true; 1506 UseCompiler = true; 1507 UseLoopCounter = true; 1508 1509 // Default values may be platform/compiler dependent - 1510 // use the saved values 1511 ClipInlining = Arguments::_ClipInlining; 1512 AlwaysCompileLoopMethods = Arguments::_AlwaysCompileLoopMethods; 1513 UseOnStackReplacement = Arguments::_UseOnStackReplacement; 1514 BackgroundCompilation = Arguments::_BackgroundCompilation; 1515 if (TieredCompilation) { 1516 if (FLAG_IS_DEFAULT(Tier3InvokeNotifyFreqLog)) { 1517 Tier3InvokeNotifyFreqLog = Arguments::_Tier3InvokeNotifyFreqLog; 1518 } 1519 if (FLAG_IS_DEFAULT(Tier4InvocationThreshold)) { 1520 Tier4InvocationThreshold = Arguments::_Tier4InvocationThreshold; 1521 } 1522 } 1523 1524 // Change from defaults based on mode 1525 switch (mode) { 1526 default: 1527 ShouldNotReachHere(); 1528 break; 1529 case _int: 1530 UseCompiler = false; 1531 UseLoopCounter = false; 1532 AlwaysCompileLoopMethods = false; 1533 UseOnStackReplacement = false; 1534 break; 1535 case _mixed: 1536 // same as default 1537 break; 1538 case _comp: 1539 UseInterpreter = false; 1540 BackgroundCompilation = false; 1541 ClipInlining = false; 1542 // Be much more aggressive in tiered mode with -Xcomp and exercise C2 more. 1543 // We will first compile a level 3 version (C1 with full profiling), then do one invocation of it and 1544 // compile a level 4 (C2) and then continue executing it. 1545 if (TieredCompilation) { 1546 Tier3InvokeNotifyFreqLog = 0; 1547 Tier4InvocationThreshold = 0; 1548 } 1549 break; 1550 } 1551 } 1552 1553 // Conflict: required to use shared spaces (-Xshare:on), but 1554 // incompatible command line options were chosen. 1555 static void no_shared_spaces(const char* message) { 1556 if (RequireSharedSpaces) { 1557 jio_fprintf(defaultStream::error_stream(), 1558 "Class data sharing is inconsistent with other specified options.\n"); 1559 vm_exit_during_initialization("Unable to use shared archive.", message); 1560 } else { 1561 FLAG_SET_DEFAULT(UseSharedSpaces, false); 1562 } 1563 } 1564 1565 // Returns threshold scaled with the value of scale. 1566 // If scale < 0.0, threshold is returned without scaling. 1567 intx Arguments::scaled_compile_threshold(intx threshold, double scale) { 1568 if (scale == 1.0 || scale < 0.0) { 1569 return threshold; 1570 } else { 1571 return (intx)(threshold * scale); 1572 } 1573 } 1574 1575 // Returns freq_log scaled with the value of scale. 1576 // Returned values are in the range of [0, InvocationCounter::number_of_count_bits + 1]. 1577 // If scale < 0.0, freq_log is returned without scaling. 1578 intx Arguments::scaled_freq_log(intx freq_log, double scale) { 1579 // Check if scaling is necessary or if negative value was specified. 1580 if (scale == 1.0 || scale < 0.0) { 1581 return freq_log; 1582 } 1583 // Check values to avoid calculating log2 of 0. 1584 if (scale == 0.0 || freq_log == 0) { 1585 return 0; 1586 } 1587 // Determine the maximum notification frequency value currently supported. 1588 // The largest mask value that the interpreter/C1 can handle is 1589 // of length InvocationCounter::number_of_count_bits. Mask values are always 1590 // one bit shorter then the value of the notification frequency. Set 1591 // max_freq_bits accordingly. 1592 intx max_freq_bits = InvocationCounter::number_of_count_bits + 1; 1593 intx scaled_freq = scaled_compile_threshold((intx)1 << freq_log, scale); 1594 if (scaled_freq == 0) { 1595 // Return 0 right away to avoid calculating log2 of 0. 1596 return 0; 1597 } else if (scaled_freq > nth_bit(max_freq_bits)) { 1598 return max_freq_bits; 1599 } else { 1600 return log2_intptr(scaled_freq); 1601 } 1602 } 1603 1604 void Arguments::set_tiered_flags() { 1605 // With tiered, set default policy to AdvancedThresholdPolicy, which is 3. 1606 if (FLAG_IS_DEFAULT(CompilationPolicyChoice)) { 1607 FLAG_SET_DEFAULT(CompilationPolicyChoice, 3); 1608 } 1609 if (CompilationPolicyChoice < 2) { 1610 vm_exit_during_initialization( 1611 "Incompatible compilation policy selected", NULL); 1612 } 1613 // Increase the code cache size - tiered compiles a lot more. 1614 if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) { 1615 FLAG_SET_ERGO(uintx, ReservedCodeCacheSize, 1616 MIN2(CODE_CACHE_DEFAULT_LIMIT, ReservedCodeCacheSize * 5)); 1617 } 1618 // Enable SegmentedCodeCache if TieredCompilation is enabled and ReservedCodeCacheSize >= 240M 1619 if (FLAG_IS_DEFAULT(SegmentedCodeCache) && ReservedCodeCacheSize >= 240*M) { 1620 FLAG_SET_ERGO(bool, SegmentedCodeCache, true); 1621 } 1622 if (!UseInterpreter) { // -Xcomp 1623 Tier3InvokeNotifyFreqLog = 0; 1624 Tier4InvocationThreshold = 0; 1625 } 1626 1627 if (CompileThresholdScaling < 0) { 1628 vm_exit_during_initialization("Negative value specified for CompileThresholdScaling", NULL); 1629 } 1630 1631 // Scale tiered compilation thresholds. 1632 // CompileThresholdScaling == 0.0 is equivalent to -Xint and leaves compilation thresholds unchanged. 1633 if (!FLAG_IS_DEFAULT(CompileThresholdScaling) && CompileThresholdScaling > 0.0) { 1634 FLAG_SET_ERGO(intx, Tier0InvokeNotifyFreqLog, scaled_freq_log(Tier0InvokeNotifyFreqLog)); 1635 FLAG_SET_ERGO(intx, Tier0BackedgeNotifyFreqLog, scaled_freq_log(Tier0BackedgeNotifyFreqLog)); 1636 1637 FLAG_SET_ERGO(intx, Tier3InvocationThreshold, scaled_compile_threshold(Tier3InvocationThreshold)); 1638 FLAG_SET_ERGO(intx, Tier3MinInvocationThreshold, scaled_compile_threshold(Tier3MinInvocationThreshold)); 1639 FLAG_SET_ERGO(intx, Tier3CompileThreshold, scaled_compile_threshold(Tier3CompileThreshold)); 1640 FLAG_SET_ERGO(intx, Tier3BackEdgeThreshold, scaled_compile_threshold(Tier3BackEdgeThreshold)); 1641 1642 // Tier2{Invocation,MinInvocation,Compile,Backedge}Threshold should be scaled here 1643 // once these thresholds become supported. 1644 1645 FLAG_SET_ERGO(intx, Tier2InvokeNotifyFreqLog, scaled_freq_log(Tier2InvokeNotifyFreqLog)); 1646 FLAG_SET_ERGO(intx, Tier2BackedgeNotifyFreqLog, scaled_freq_log(Tier2BackedgeNotifyFreqLog)); 1647 1648 FLAG_SET_ERGO(intx, Tier3InvokeNotifyFreqLog, scaled_freq_log(Tier3InvokeNotifyFreqLog)); 1649 FLAG_SET_ERGO(intx, Tier3BackedgeNotifyFreqLog, scaled_freq_log(Tier3BackedgeNotifyFreqLog)); 1650 1651 FLAG_SET_ERGO(intx, Tier23InlineeNotifyFreqLog, scaled_freq_log(Tier23InlineeNotifyFreqLog)); 1652 1653 FLAG_SET_ERGO(intx, Tier4InvocationThreshold, scaled_compile_threshold(Tier4InvocationThreshold)); 1654 FLAG_SET_ERGO(intx, Tier4MinInvocationThreshold, scaled_compile_threshold(Tier4MinInvocationThreshold)); 1655 FLAG_SET_ERGO(intx, Tier4CompileThreshold, scaled_compile_threshold(Tier4CompileThreshold)); 1656 FLAG_SET_ERGO(intx, Tier4BackEdgeThreshold, scaled_compile_threshold(Tier4BackEdgeThreshold)); 1657 } 1658 } 1659 1660 void set_object_alignment() { 1661 // Object alignment. 1662 assert(is_power_of_2(ObjectAlignmentInBytes), "ObjectAlignmentInBytes must be power of 2"); 1663 MinObjAlignmentInBytes = ObjectAlignmentInBytes; 1664 assert(MinObjAlignmentInBytes >= HeapWordsPerLong * HeapWordSize, "ObjectAlignmentInBytes value is too small"); 1665 MinObjAlignment = MinObjAlignmentInBytes / HeapWordSize; 1666 assert(MinObjAlignmentInBytes == MinObjAlignment * HeapWordSize, "ObjectAlignmentInBytes value is incorrect"); 1667 MinObjAlignmentInBytesMask = MinObjAlignmentInBytes - 1; 1668 1669 LogMinObjAlignmentInBytes = exact_log2(ObjectAlignmentInBytes); 1670 LogMinObjAlignment = LogMinObjAlignmentInBytes - LogHeapWordSize; 1671 1672 // Oop encoding heap max 1673 OopEncodingHeapMax = (uint64_t(max_juint) + 1) << LogMinObjAlignmentInBytes; 1674 1675 if (SurvivorAlignmentInBytes == 0) { 1676 SurvivorAlignmentInBytes = ObjectAlignmentInBytes; 1677 } 1678 } 1679 1680 size_t Arguments::max_heap_for_compressed_oops() { 1681 // Avoid sign flip. 1682 assert(OopEncodingHeapMax > (uint64_t)os::vm_page_size(), "Unusual page size"); 1683 // We need to fit both the NULL page and the heap into the memory budget, while 1684 // keeping alignment constraints of the heap. To guarantee the latter, as the 1685 // NULL page is located before the heap, we pad the NULL page to the conservative 1686 // maximum alignment that the GC may ever impose upon the heap. 1687 size_t displacement_due_to_null_page = align_up((size_t)os::vm_page_size(), 1688 _conservative_max_heap_alignment); 1689 1690 LP64_ONLY(return OopEncodingHeapMax - displacement_due_to_null_page); 1691 NOT_LP64(ShouldNotReachHere(); return 0); 1692 } 1693 1694 void Arguments::set_use_compressed_oops() { 1695 #ifndef ZERO 1696 #ifdef _LP64 1697 // MaxHeapSize is not set up properly at this point, but 1698 // the only value that can override MaxHeapSize if we are 1699 // to use UseCompressedOops is InitialHeapSize. 1700 size_t max_heap_size = MAX2(MaxHeapSize, InitialHeapSize); 1701 1702 if (max_heap_size <= max_heap_for_compressed_oops()) { 1703 #if !defined(COMPILER1) || defined(TIERED) 1704 if (FLAG_IS_DEFAULT(UseCompressedOops)) { 1705 FLAG_SET_ERGO(bool, UseCompressedOops, true); 1706 } 1707 #endif 1708 } else { 1709 if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) { 1710 warning("Max heap size too large for Compressed Oops"); 1711 FLAG_SET_DEFAULT(UseCompressedOops, false); 1712 FLAG_SET_DEFAULT(UseCompressedClassPointers, false); 1713 } 1714 } 1715 #endif // _LP64 1716 #endif // ZERO 1717 } 1718 1719 1720 // NOTE: set_use_compressed_klass_ptrs() must be called after calling 1721 // set_use_compressed_oops(). 1722 void Arguments::set_use_compressed_klass_ptrs() { 1723 #ifndef ZERO 1724 #ifdef _LP64 1725 // UseCompressedOops must be on for UseCompressedClassPointers to be on. 1726 if (!UseCompressedOops) { 1727 if (UseCompressedClassPointers) { 1728 warning("UseCompressedClassPointers requires UseCompressedOops"); 1729 } 1730 FLAG_SET_DEFAULT(UseCompressedClassPointers, false); 1731 } else { 1732 // Turn on UseCompressedClassPointers too 1733 if (FLAG_IS_DEFAULT(UseCompressedClassPointers)) { 1734 FLAG_SET_ERGO(bool, UseCompressedClassPointers, true); 1735 } 1736 // Check the CompressedClassSpaceSize to make sure we use compressed klass ptrs. 1737 if (UseCompressedClassPointers) { 1738 if (CompressedClassSpaceSize > KlassEncodingMetaspaceMax) { 1739 warning("CompressedClassSpaceSize is too large for UseCompressedClassPointers"); 1740 FLAG_SET_DEFAULT(UseCompressedClassPointers, false); 1741 } 1742 } 1743 } 1744 #endif // _LP64 1745 #endif // !ZERO 1746 } 1747 1748 void Arguments::set_conservative_max_heap_alignment() { 1749 // The conservative maximum required alignment for the heap is the maximum of 1750 // the alignments imposed by several sources: any requirements from the heap 1751 // itself, the collector policy and the maximum page size we may run the VM 1752 // with. 1753 size_t heap_alignment = GCConfig::arguments()->conservative_max_heap_alignment(); 1754 _conservative_max_heap_alignment = MAX4(heap_alignment, 1755 (size_t)os::vm_allocation_granularity(), 1756 os::max_page_size(), 1757 CollectorPolicy::compute_heap_alignment()); 1758 } 1759 1760 #ifdef TIERED 1761 bool Arguments::compilation_mode_selected() { 1762 return !FLAG_IS_DEFAULT(TieredCompilation) || !FLAG_IS_DEFAULT(TieredStopAtLevel) || 1763 !FLAG_IS_DEFAULT(UseAOT) JVMCI_ONLY(|| !FLAG_IS_DEFAULT(EnableJVMCI) || !FLAG_IS_DEFAULT(UseJVMCICompiler)); 1764 1765 } 1766 1767 void Arguments::select_compilation_mode_ergonomically() { 1768 #if defined(_WINDOWS) && !defined(_LP64) 1769 if (FLAG_IS_DEFAULT(NeverActAsServerClassMachine)) { 1770 FLAG_SET_ERGO(bool, NeverActAsServerClassMachine, true); 1771 } 1772 #endif 1773 if (NeverActAsServerClassMachine) { 1774 set_client_compilation_mode(); 1775 } 1776 } 1777 #endif //TIERED 1778 1779 #if INCLUDE_JVMCI 1780 void Arguments::set_jvmci_specific_flags() { 1781 if (UseJVMCICompiler) { 1782 if (FLAG_IS_DEFAULT(TypeProfileWidth)) { 1783 FLAG_SET_DEFAULT(TypeProfileWidth, 8); 1784 } 1785 if (FLAG_IS_DEFAULT(OnStackReplacePercentage)) { 1786 FLAG_SET_DEFAULT(OnStackReplacePercentage, 933); 1787 } 1788 if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) { 1789 FLAG_SET_DEFAULT(ReservedCodeCacheSize, 64*M); 1790 } 1791 if (FLAG_IS_DEFAULT(InitialCodeCacheSize)) { 1792 FLAG_SET_DEFAULT(InitialCodeCacheSize, 16*M); 1793 } 1794 if (FLAG_IS_DEFAULT(MetaspaceSize)) { 1795 FLAG_SET_DEFAULT(MetaspaceSize, 12*M); 1796 } 1797 if (FLAG_IS_DEFAULT(NewSizeThreadIncrease)) { 1798 FLAG_SET_DEFAULT(NewSizeThreadIncrease, 4*K); 1799 } 1800 if (TieredStopAtLevel != CompLevel_full_optimization) { 1801 // Currently JVMCI compiler can only work at the full optimization level 1802 warning("forcing TieredStopAtLevel to full optimization because JVMCI is enabled"); 1803 TieredStopAtLevel = CompLevel_full_optimization; 1804 } 1805 if (FLAG_IS_DEFAULT(TypeProfileLevel)) { 1806 FLAG_SET_DEFAULT(TypeProfileLevel, 0); 1807 } 1808 } 1809 } 1810 #endif 1811 1812 jint Arguments::set_ergonomics_flags() { 1813 #ifdef TIERED 1814 if (!compilation_mode_selected()) { 1815 select_compilation_mode_ergonomically(); 1816 } 1817 #endif 1818 1819 GCConfig::initialize(); 1820 1821 #if COMPILER2_OR_JVMCI 1822 // Shared spaces work fine with other GCs but causes bytecode rewriting 1823 // to be disabled, which hurts interpreter performance and decreases 1824 // server performance. When -server is specified, keep the default off 1825 // unless it is asked for. Future work: either add bytecode rewriting 1826 // at link time, or rewrite bytecodes in non-shared methods. 1827 if (is_server_compilation_mode_vm() && !DumpSharedSpaces && !RequireSharedSpaces && 1828 (FLAG_IS_DEFAULT(UseSharedSpaces) || !UseSharedSpaces)) { 1829 no_shared_spaces("COMPILER2 default: -Xshare:auto | off, have to manually setup to on."); 1830 } 1831 #endif 1832 1833 #if defined(IA32) 1834 // Only server compiler can optimize safepoints well enough. 1835 if (!is_server_compilation_mode_vm()) { 1836 FLAG_SET_ERGO_IF_DEFAULT(bool, ThreadLocalHandshakes, false); 1837 } 1838 #endif 1839 1840 set_conservative_max_heap_alignment(); 1841 1842 #ifndef ZERO 1843 #ifdef _LP64 1844 set_use_compressed_oops(); 1845 1846 // set_use_compressed_klass_ptrs() must be called after calling 1847 // set_use_compressed_oops(). 1848 set_use_compressed_klass_ptrs(); 1849 1850 // Also checks that certain machines are slower with compressed oops 1851 // in vm_version initialization code. 1852 #endif // _LP64 1853 #endif // !ZERO 1854 1855 return JNI_OK; 1856 } 1857 1858 julong Arguments::limit_by_allocatable_memory(julong limit) { 1859 julong max_allocatable; 1860 julong result = limit; 1861 if (os::has_allocatable_memory_limit(&max_allocatable)) { 1862 result = MIN2(result, max_allocatable / MaxVirtMemFraction); 1863 } 1864 return result; 1865 } 1866 1867 // Use static initialization to get the default before parsing 1868 static const size_t DefaultHeapBaseMinAddress = HeapBaseMinAddress; 1869 1870 void Arguments::set_heap_size() { 1871 julong phys_mem = 1872 FLAG_IS_DEFAULT(MaxRAM) ? MIN2(os::physical_memory(), (julong)MaxRAM) 1873 : (julong)MaxRAM; 1874 1875 // Convert deprecated flags 1876 if (FLAG_IS_DEFAULT(MaxRAMPercentage) && 1877 !FLAG_IS_DEFAULT(MaxRAMFraction)) 1878 MaxRAMPercentage = 100.0 / MaxRAMFraction; 1879 1880 if (FLAG_IS_DEFAULT(MinRAMPercentage) && 1881 !FLAG_IS_DEFAULT(MinRAMFraction)) 1882 MinRAMPercentage = 100.0 / MinRAMFraction; 1883 1884 if (FLAG_IS_DEFAULT(InitialRAMPercentage) && 1885 !FLAG_IS_DEFAULT(InitialRAMFraction)) 1886 InitialRAMPercentage = 100.0 / InitialRAMFraction; 1887 1888 // If the maximum heap size has not been set with -Xmx, 1889 // then set it as fraction of the size of physical memory, 1890 // respecting the maximum and minimum sizes of the heap. 1891 if (FLAG_IS_DEFAULT(MaxHeapSize)) { 1892 julong reasonable_max = (julong)((phys_mem * MaxRAMPercentage) / 100); 1893 const julong reasonable_min = (julong)((phys_mem * MinRAMPercentage) / 100); 1894 if (reasonable_min < MaxHeapSize) { 1895 // Small physical memory, so use a minimum fraction of it for the heap 1896 reasonable_max = reasonable_min; 1897 } else { 1898 // Not-small physical memory, so require a heap at least 1899 // as large as MaxHeapSize 1900 reasonable_max = MAX2(reasonable_max, (julong)MaxHeapSize); 1901 } 1902 1903 if (!FLAG_IS_DEFAULT(ErgoHeapSizeLimit) && ErgoHeapSizeLimit != 0) { 1904 // Limit the heap size to ErgoHeapSizeLimit 1905 reasonable_max = MIN2(reasonable_max, (julong)ErgoHeapSizeLimit); 1906 } 1907 if (UseCompressedOops) { 1908 // Limit the heap size to the maximum possible when using compressed oops 1909 julong max_coop_heap = (julong)max_heap_for_compressed_oops(); 1910 1911 // HeapBaseMinAddress can be greater than default but not less than. 1912 if (!FLAG_IS_DEFAULT(HeapBaseMinAddress)) { 1913 if (HeapBaseMinAddress < DefaultHeapBaseMinAddress) { 1914 // matches compressed oops printing flags 1915 log_debug(gc, heap, coops)("HeapBaseMinAddress must be at least " SIZE_FORMAT 1916 " (" SIZE_FORMAT "G) which is greater than value given " SIZE_FORMAT, 1917 DefaultHeapBaseMinAddress, 1918 DefaultHeapBaseMinAddress/G, 1919 HeapBaseMinAddress); 1920 FLAG_SET_ERGO(size_t, HeapBaseMinAddress, DefaultHeapBaseMinAddress); 1921 } 1922 } 1923 1924 if (HeapBaseMinAddress + MaxHeapSize < max_coop_heap) { 1925 // Heap should be above HeapBaseMinAddress to get zero based compressed oops 1926 // but it should be not less than default MaxHeapSize. 1927 max_coop_heap -= HeapBaseMinAddress; 1928 } 1929 reasonable_max = MIN2(reasonable_max, max_coop_heap); 1930 } 1931 reasonable_max = limit_by_allocatable_memory(reasonable_max); 1932 1933 if (!FLAG_IS_DEFAULT(InitialHeapSize)) { 1934 // An initial heap size was specified on the command line, 1935 // so be sure that the maximum size is consistent. Done 1936 // after call to limit_by_allocatable_memory because that 1937 // method might reduce the allocation size. 1938 reasonable_max = MAX2(reasonable_max, (julong)InitialHeapSize); 1939 } 1940 1941 log_trace(gc, heap)(" Maximum heap size " SIZE_FORMAT, (size_t) reasonable_max); 1942 FLAG_SET_ERGO(size_t, MaxHeapSize, (size_t)reasonable_max); 1943 } 1944 1945 // If the minimum or initial heap_size have not been set or requested to be set 1946 // ergonomically, set them accordingly. 1947 if (InitialHeapSize == 0 || min_heap_size() == 0) { 1948 julong reasonable_minimum = (julong)(OldSize + NewSize); 1949 1950 reasonable_minimum = MIN2(reasonable_minimum, (julong)MaxHeapSize); 1951 1952 reasonable_minimum = limit_by_allocatable_memory(reasonable_minimum); 1953 1954 if (InitialHeapSize == 0) { 1955 julong reasonable_initial = (julong)((phys_mem * InitialRAMPercentage) / 100); 1956 1957 reasonable_initial = MAX3(reasonable_initial, reasonable_minimum, (julong)min_heap_size()); 1958 reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize); 1959 1960 reasonable_initial = limit_by_allocatable_memory(reasonable_initial); 1961 1962 log_trace(gc, heap)(" Initial heap size " SIZE_FORMAT, (size_t)reasonable_initial); 1963 FLAG_SET_ERGO(size_t, InitialHeapSize, (size_t)reasonable_initial); 1964 } 1965 // If the minimum heap size has not been set (via -Xms), 1966 // synchronize with InitialHeapSize to avoid errors with the default value. 1967 if (min_heap_size() == 0) { 1968 set_min_heap_size(MIN2((size_t)reasonable_minimum, InitialHeapSize)); 1969 log_trace(gc, heap)(" Minimum heap size " SIZE_FORMAT, min_heap_size()); 1970 } 1971 } 1972 } 1973 1974 // This option inspects the machine and attempts to set various 1975 // parameters to be optimal for long-running, memory allocation 1976 // intensive jobs. It is intended for machines with large 1977 // amounts of cpu and memory. 1978 jint Arguments::set_aggressive_heap_flags() { 1979 // initHeapSize is needed since _initial_heap_size is 4 bytes on a 32 bit 1980 // VM, but we may not be able to represent the total physical memory 1981 // available (like having 8gb of memory on a box but using a 32bit VM). 1982 // Thus, we need to make sure we're using a julong for intermediate 1983 // calculations. 1984 julong initHeapSize; 1985 julong total_memory = os::physical_memory(); 1986 1987 if (total_memory < (julong) 256 * M) { 1988 jio_fprintf(defaultStream::error_stream(), 1989 "You need at least 256mb of memory to use -XX:+AggressiveHeap\n"); 1990 vm_exit(1); 1991 } 1992 1993 // The heap size is half of available memory, or (at most) 1994 // all of possible memory less 160mb (leaving room for the OS 1995 // when using ISM). This is the maximum; because adaptive sizing 1996 // is turned on below, the actual space used may be smaller. 1997 1998 initHeapSize = MIN2(total_memory / (julong) 2, 1999 total_memory - (julong) 160 * M); 2000 2001 initHeapSize = limit_by_allocatable_memory(initHeapSize); 2002 2003 if (FLAG_IS_DEFAULT(MaxHeapSize)) { 2004 if (FLAG_SET_CMDLINE(size_t, MaxHeapSize, initHeapSize) != Flag::SUCCESS) { 2005 return JNI_EINVAL; 2006 } 2007 if (FLAG_SET_CMDLINE(size_t, InitialHeapSize, initHeapSize) != Flag::SUCCESS) { 2008 return JNI_EINVAL; 2009 } 2010 // Currently the minimum size and the initial heap sizes are the same. 2011 set_min_heap_size(initHeapSize); 2012 } 2013 if (FLAG_IS_DEFAULT(NewSize)) { 2014 // Make the young generation 3/8ths of the total heap. 2015 if (FLAG_SET_CMDLINE(size_t, NewSize, 2016 ((julong) MaxHeapSize / (julong) 8) * (julong) 3) != Flag::SUCCESS) { 2017 return JNI_EINVAL; 2018 } 2019 if (FLAG_SET_CMDLINE(size_t, MaxNewSize, NewSize) != Flag::SUCCESS) { 2020 return JNI_EINVAL; 2021 } 2022 } 2023 2024 #if !defined(_ALLBSD_SOURCE) && !defined(AIX) // UseLargePages is not yet supported on BSD and AIX. 2025 FLAG_SET_DEFAULT(UseLargePages, true); 2026 #endif 2027 2028 // Increase some data structure sizes for efficiency 2029 if (FLAG_SET_CMDLINE(size_t, BaseFootPrintEstimate, MaxHeapSize) != Flag::SUCCESS) { 2030 return JNI_EINVAL; 2031 } 2032 if (FLAG_SET_CMDLINE(bool, ResizeTLAB, false) != Flag::SUCCESS) { 2033 return JNI_EINVAL; 2034 } 2035 if (FLAG_SET_CMDLINE(size_t, TLABSize, 256 * K) != Flag::SUCCESS) { 2036 return JNI_EINVAL; 2037 } 2038 2039 // See the OldPLABSize comment below, but replace 'after promotion' 2040 // with 'after copying'. YoungPLABSize is the size of the survivor 2041 // space per-gc-thread buffers. The default is 4kw. 2042 if (FLAG_SET_CMDLINE(size_t, YoungPLABSize, 256 * K) != Flag::SUCCESS) { // Note: this is in words 2043 return JNI_EINVAL; 2044 } 2045 2046 // OldPLABSize is the size of the buffers in the old gen that 2047 // UseParallelGC uses to promote live data that doesn't fit in the 2048 // survivor spaces. At any given time, there's one for each gc thread. 2049 // The default size is 1kw. These buffers are rarely used, since the 2050 // survivor spaces are usually big enough. For specjbb, however, there 2051 // are occasions when there's lots of live data in the young gen 2052 // and we end up promoting some of it. We don't have a definite 2053 // explanation for why bumping OldPLABSize helps, but the theory 2054 // is that a bigger PLAB results in retaining something like the 2055 // original allocation order after promotion, which improves mutator 2056 // locality. A minor effect may be that larger PLABs reduce the 2057 // number of PLAB allocation events during gc. The value of 8kw 2058 // was arrived at by experimenting with specjbb. 2059 if (FLAG_SET_CMDLINE(size_t, OldPLABSize, 8 * K) != Flag::SUCCESS) { // Note: this is in words 2060 return JNI_EINVAL; 2061 } 2062 2063 // Enable parallel GC and adaptive generation sizing 2064 if (FLAG_SET_CMDLINE(bool, UseParallelGC, true) != Flag::SUCCESS) { 2065 return JNI_EINVAL; 2066 } 2067 2068 // Encourage steady state memory management 2069 if (FLAG_SET_CMDLINE(uintx, ThresholdTolerance, 100) != Flag::SUCCESS) { 2070 return JNI_EINVAL; 2071 } 2072 2073 // This appears to improve mutator locality 2074 if (FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false) != Flag::SUCCESS) { 2075 return JNI_EINVAL; 2076 } 2077 2078 // Get around early Solaris scheduling bug 2079 // (affinity vs other jobs on system) 2080 // but disallow DR and offlining (5008695). 2081 if (FLAG_SET_CMDLINE(bool, BindGCTaskThreadsToCPUs, true) != Flag::SUCCESS) { 2082 return JNI_EINVAL; 2083 } 2084 2085 return JNI_OK; 2086 } 2087 2088 // This must be called after ergonomics. 2089 void Arguments::set_bytecode_flags() { 2090 if (!RewriteBytecodes) { 2091 FLAG_SET_DEFAULT(RewriteFrequentPairs, false); 2092 } 2093 } 2094 2095 // Aggressive optimization flags -XX:+AggressiveOpts 2096 jint Arguments::set_aggressive_opts_flags() { 2097 #ifdef COMPILER2 2098 if (AggressiveUnboxing) { 2099 if (FLAG_IS_DEFAULT(EliminateAutoBox)) { 2100 FLAG_SET_DEFAULT(EliminateAutoBox, true); 2101 } else if (!EliminateAutoBox) { 2102 // warning("AggressiveUnboxing is disabled because EliminateAutoBox is disabled"); 2103 AggressiveUnboxing = false; 2104 } 2105 if (FLAG_IS_DEFAULT(DoEscapeAnalysis)) { 2106 FLAG_SET_DEFAULT(DoEscapeAnalysis, true); 2107 } else if (!DoEscapeAnalysis) { 2108 // warning("AggressiveUnboxing is disabled because DoEscapeAnalysis is disabled"); 2109 AggressiveUnboxing = false; 2110 } 2111 } 2112 if (AggressiveOpts || !FLAG_IS_DEFAULT(AutoBoxCacheMax)) { 2113 if (FLAG_IS_DEFAULT(EliminateAutoBox)) { 2114 FLAG_SET_DEFAULT(EliminateAutoBox, true); 2115 } 2116 if (FLAG_IS_DEFAULT(AutoBoxCacheMax)) { 2117 FLAG_SET_DEFAULT(AutoBoxCacheMax, 20000); 2118 } 2119 2120 // Feed the cache size setting into the JDK 2121 char buffer[1024]; 2122 jio_snprintf(buffer, 1024, "java.lang.Integer.IntegerCache.high=" INTX_FORMAT, AutoBoxCacheMax); 2123 if (!add_property(buffer)) { 2124 return JNI_ENOMEM; 2125 } 2126 } 2127 if (AggressiveOpts && FLAG_IS_DEFAULT(BiasedLockingStartupDelay)) { 2128 FLAG_SET_DEFAULT(BiasedLockingStartupDelay, 500); 2129 } 2130 #endif 2131 2132 if (AggressiveOpts) { 2133 // Sample flag setting code 2134 // if (FLAG_IS_DEFAULT(EliminateZeroing)) { 2135 // FLAG_SET_DEFAULT(EliminateZeroing, true); 2136 // } 2137 } 2138 2139 return JNI_OK; 2140 } 2141 2142 //=========================================================================================================== 2143 // Parsing of java.compiler property 2144 2145 void Arguments::process_java_compiler_argument(const char* arg) { 2146 // For backwards compatibility, Djava.compiler=NONE or "" 2147 // causes us to switch to -Xint mode UNLESS -Xdebug 2148 // is also specified. 2149 if (strlen(arg) == 0 || strcasecmp(arg, "NONE") == 0) { 2150 set_java_compiler(true); // "-Djava.compiler[=...]" most recently seen. 2151 } 2152 } 2153 2154 void Arguments::process_java_launcher_argument(const char* launcher, void* extra_info) { 2155 _sun_java_launcher = os::strdup_check_oom(launcher); 2156 } 2157 2158 bool Arguments::created_by_java_launcher() { 2159 assert(_sun_java_launcher != NULL, "property must have value"); 2160 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0; 2161 } 2162 2163 bool Arguments::sun_java_launcher_is_altjvm() { 2164 return _sun_java_launcher_is_altjvm; 2165 } 2166 2167 //=========================================================================================================== 2168 // Parsing of main arguments 2169 2170 #if INCLUDE_JVMCI 2171 // Check consistency of jvmci vm argument settings. 2172 bool Arguments::check_jvmci_args_consistency() { 2173 return JVMCIGlobals::check_jvmci_flags_are_consistent(); 2174 } 2175 #endif //INCLUDE_JVMCI 2176 2177 // Check the consistency of vm_init_args 2178 bool Arguments::check_vm_args_consistency() { 2179 // Method for adding checks for flag consistency. 2180 // The intent is to warn the user of all possible conflicts, 2181 // before returning an error. 2182 // Note: Needs platform-dependent factoring. 2183 bool status = true; 2184 2185 if (TLABRefillWasteFraction == 0) { 2186 jio_fprintf(defaultStream::error_stream(), 2187 "TLABRefillWasteFraction should be a denominator, " 2188 "not " SIZE_FORMAT "\n", 2189 TLABRefillWasteFraction); 2190 status = false; 2191 } 2192 2193 if (FullGCALot && FLAG_IS_DEFAULT(MarkSweepAlwaysCompactCount)) { 2194 MarkSweepAlwaysCompactCount = 1; // Move objects every gc. 2195 } 2196 2197 if (!(UseParallelGC || UseParallelOldGC) && FLAG_IS_DEFAULT(ScavengeBeforeFullGC)) { 2198 FLAG_SET_DEFAULT(ScavengeBeforeFullGC, false); 2199 } 2200 2201 if (GCTimeLimit == 100) { 2202 // Turn off gc-overhead-limit-exceeded checks 2203 FLAG_SET_DEFAULT(UseGCOverheadLimit, false); 2204 } 2205 2206 // CMS space iteration, which FLSVerifyAllHeapreferences entails, 2207 // insists that we hold the requisite locks so that the iteration is 2208 // MT-safe. For the verification at start-up and shut-down, we don't 2209 // yet have a good way of acquiring and releasing these locks, 2210 // which are not visible at the CollectedHeap level. We want to 2211 // be able to acquire these locks and then do the iteration rather 2212 // than just disable the lock verification. This will be fixed under 2213 // bug 4788986. 2214 if (UseConcMarkSweepGC && FLSVerifyAllHeapReferences) { 2215 if (VerifyDuringStartup) { 2216 warning("Heap verification at start-up disabled " 2217 "(due to current incompatibility with FLSVerifyAllHeapReferences)"); 2218 VerifyDuringStartup = false; // Disable verification at start-up 2219 } 2220 2221 if (VerifyBeforeExit) { 2222 warning("Heap verification at shutdown disabled " 2223 "(due to current incompatibility with FLSVerifyAllHeapReferences)"); 2224 VerifyBeforeExit = false; // Disable verification at shutdown 2225 } 2226 } 2227 2228 if (PrintNMTStatistics) { 2229 #if INCLUDE_NMT 2230 if (MemTracker::tracking_level() == NMT_off) { 2231 #endif // INCLUDE_NMT 2232 warning("PrintNMTStatistics is disabled, because native memory tracking is not enabled"); 2233 PrintNMTStatistics = false; 2234 #if INCLUDE_NMT 2235 } 2236 #endif 2237 } 2238 2239 #if INCLUDE_JVMCI 2240 status = status && check_jvmci_args_consistency(); 2241 2242 if (EnableJVMCI) { 2243 PropertyList_unique_add(&_system_properties, "jdk.internal.vm.ci.enabled", "true", 2244 AddProperty, UnwriteableProperty, InternalProperty); 2245 2246 if (!ScavengeRootsInCode) { 2247 warning("forcing ScavengeRootsInCode non-zero because JVMCI is enabled"); 2248 ScavengeRootsInCode = 1; 2249 } 2250 } 2251 #endif 2252 2253 // Check lower bounds of the code cache 2254 // Template Interpreter code is approximately 3X larger in debug builds. 2255 uint min_code_cache_size = CodeCacheMinimumUseSpace DEBUG_ONLY(* 3); 2256 if (ReservedCodeCacheSize < InitialCodeCacheSize) { 2257 jio_fprintf(defaultStream::error_stream(), 2258 "Invalid ReservedCodeCacheSize: %dK. Must be at least InitialCodeCacheSize=%dK.\n", 2259 ReservedCodeCacheSize/K, InitialCodeCacheSize/K); 2260 status = false; 2261 } else if (ReservedCodeCacheSize < min_code_cache_size) { 2262 jio_fprintf(defaultStream::error_stream(), 2263 "Invalid ReservedCodeCacheSize=%dK. Must be at least %uK.\n", ReservedCodeCacheSize/K, 2264 min_code_cache_size/K); 2265 status = false; 2266 } else if (ReservedCodeCacheSize > CODE_CACHE_SIZE_LIMIT) { 2267 // Code cache size larger than CODE_CACHE_SIZE_LIMIT is not supported. 2268 jio_fprintf(defaultStream::error_stream(), 2269 "Invalid ReservedCodeCacheSize=%dM. Must be at most %uM.\n", ReservedCodeCacheSize/M, 2270 CODE_CACHE_SIZE_LIMIT/M); 2271 status = false; 2272 } else if (NonNMethodCodeHeapSize < min_code_cache_size) { 2273 jio_fprintf(defaultStream::error_stream(), 2274 "Invalid NonNMethodCodeHeapSize=%dK. Must be at least %uK.\n", NonNMethodCodeHeapSize/K, 2275 min_code_cache_size/K); 2276 status = false; 2277 } 2278 2279 #ifdef _LP64 2280 if (!FLAG_IS_DEFAULT(CICompilerCount) && !FLAG_IS_DEFAULT(CICompilerCountPerCPU) && CICompilerCountPerCPU) { 2281 warning("The VM option CICompilerCountPerCPU overrides CICompilerCount."); 2282 } 2283 #endif 2284 2285 #ifndef SUPPORT_RESERVED_STACK_AREA 2286 if (StackReservedPages != 0) { 2287 FLAG_SET_CMDLINE(intx, StackReservedPages, 0); 2288 warning("Reserved Stack Area not supported on this platform"); 2289 } 2290 #endif 2291 2292 if (BackgroundCompilation && (CompileTheWorld || ReplayCompiles)) { 2293 if (!FLAG_IS_DEFAULT(BackgroundCompilation)) { 2294 warning("BackgroundCompilation disabled due to CompileTheWorld or ReplayCompiles options."); 2295 } 2296 FLAG_SET_CMDLINE(bool, BackgroundCompilation, false); 2297 } 2298 if (UseCompiler && is_interpreter_only()) { 2299 if (!FLAG_IS_DEFAULT(UseCompiler)) { 2300 warning("UseCompiler disabled due to -Xint."); 2301 } 2302 FLAG_SET_CMDLINE(bool, UseCompiler, false); 2303 } 2304 #ifdef COMPILER2 2305 if (PostLoopMultiversioning && !RangeCheckElimination) { 2306 if (!FLAG_IS_DEFAULT(PostLoopMultiversioning)) { 2307 warning("PostLoopMultiversioning disabled because RangeCheckElimination is disabled."); 2308 } 2309 FLAG_SET_CMDLINE(bool, PostLoopMultiversioning, false); 2310 } 2311 if (UseCountedLoopSafepoints && LoopStripMiningIter == 0) { 2312 if (!FLAG_IS_DEFAULT(UseCountedLoopSafepoints) || !FLAG_IS_DEFAULT(LoopStripMiningIter)) { 2313 warning("When counted loop safepoints are enabled, LoopStripMiningIter must be at least 1 (a safepoint every 1 iteration): setting it to 1"); 2314 } 2315 LoopStripMiningIter = 1; 2316 } else if (!UseCountedLoopSafepoints && LoopStripMiningIter > 0) { 2317 if (!FLAG_IS_DEFAULT(UseCountedLoopSafepoints) || !FLAG_IS_DEFAULT(LoopStripMiningIter)) { 2318 warning("Disabling counted safepoints implies no loop strip mining: setting LoopStripMiningIter to 0"); 2319 } 2320 LoopStripMiningIter = 0; 2321 } 2322 #endif 2323 if (!FLAG_IS_DEFAULT(AllocateHeapAt)) { 2324 if ((UseNUMAInterleaving && !FLAG_IS_DEFAULT(UseNUMAInterleaving)) || (UseNUMA && !FLAG_IS_DEFAULT(UseNUMA))) { 2325 log_warning(arguments) ("NUMA support for Heap depends on the file system when AllocateHeapAt option is used.\n"); 2326 } 2327 } 2328 return status; 2329 } 2330 2331 bool Arguments::is_bad_option(const JavaVMOption* option, jboolean ignore, 2332 const char* option_type) { 2333 if (ignore) return false; 2334 2335 const char* spacer = " "; 2336 if (option_type == NULL) { 2337 option_type = ++spacer; // Set both to the empty string. 2338 } 2339 2340 if (os::obsolete_option(option)) { 2341 jio_fprintf(defaultStream::error_stream(), 2342 "Obsolete %s%soption: %s\n", option_type, spacer, 2343 option->optionString); 2344 return false; 2345 } else { 2346 jio_fprintf(defaultStream::error_stream(), 2347 "Unrecognized %s%soption: %s\n", option_type, spacer, 2348 option->optionString); 2349 return true; 2350 } 2351 } 2352 2353 static const char* user_assertion_options[] = { 2354 "-da", "-ea", "-disableassertions", "-enableassertions", 0 2355 }; 2356 2357 static const char* system_assertion_options[] = { 2358 "-dsa", "-esa", "-disablesystemassertions", "-enablesystemassertions", 0 2359 }; 2360 2361 bool Arguments::parse_uintx(const char* value, 2362 uintx* uintx_arg, 2363 uintx min_size) { 2364 2365 // Check the sign first since atojulong() parses only unsigned values. 2366 bool value_is_positive = !(*value == '-'); 2367 2368 if (value_is_positive) { 2369 julong n; 2370 bool good_return = atojulong(value, &n); 2371 if (good_return) { 2372 bool above_minimum = n >= min_size; 2373 bool value_is_too_large = n > max_uintx; 2374 2375 if (above_minimum && !value_is_too_large) { 2376 *uintx_arg = n; 2377 return true; 2378 } 2379 } 2380 } 2381 return false; 2382 } 2383 2384 unsigned int addreads_count = 0; 2385 unsigned int addexports_count = 0; 2386 unsigned int addopens_count = 0; 2387 unsigned int addmods_count = 0; 2388 unsigned int patch_mod_count = 0; 2389 2390 bool Arguments::create_property(const char* prop_name, const char* prop_value, PropertyInternal internal) { 2391 size_t prop_len = strlen(prop_name) + strlen(prop_value) + 2; 2392 char* property = AllocateHeap(prop_len, mtArguments); 2393 int ret = jio_snprintf(property, prop_len, "%s=%s", prop_name, prop_value); 2394 if (ret < 0 || ret >= (int)prop_len) { 2395 FreeHeap(property); 2396 return false; 2397 } 2398 bool added = add_property(property, UnwriteableProperty, internal); 2399 FreeHeap(property); 2400 return added; 2401 } 2402 2403 bool Arguments::create_numbered_property(const char* prop_base_name, const char* prop_value, unsigned int count) { 2404 const unsigned int props_count_limit = 1000; 2405 const int max_digits = 3; 2406 const int extra_symbols_count = 3; // includes '.', '=', '\0' 2407 2408 // Make sure count is < props_count_limit. Otherwise, memory allocation will be too small. 2409 if (count < props_count_limit) { 2410 size_t prop_len = strlen(prop_base_name) + strlen(prop_value) + max_digits + extra_symbols_count; 2411 char* property = AllocateHeap(prop_len, mtArguments); 2412 int ret = jio_snprintf(property, prop_len, "%s.%d=%s", prop_base_name, count, prop_value); 2413 if (ret < 0 || ret >= (int)prop_len) { 2414 FreeHeap(property); 2415 jio_fprintf(defaultStream::error_stream(), "Failed to create property %s.%d=%s\n", prop_base_name, count, prop_value); 2416 return false; 2417 } 2418 bool added = add_property(property, UnwriteableProperty, InternalProperty); 2419 FreeHeap(property); 2420 return added; 2421 } 2422 2423 jio_fprintf(defaultStream::error_stream(), "Property count limit exceeded: %s, limit=%d\n", prop_base_name, props_count_limit); 2424 return false; 2425 } 2426 2427 Arguments::ArgsRange Arguments::parse_memory_size(const char* s, 2428 julong* long_arg, 2429 julong min_size, 2430 julong max_size) { 2431 if (!atojulong(s, long_arg)) return arg_unreadable; 2432 return check_memory_size(*long_arg, min_size, max_size); 2433 } 2434 2435 // Parse JavaVMInitArgs structure 2436 2437 jint Arguments::parse_vm_init_args(const JavaVMInitArgs *java_tool_options_args, 2438 const JavaVMInitArgs *java_options_args, 2439 const JavaVMInitArgs *cmd_line_args) { 2440 bool patch_mod_javabase = false; 2441 2442 // Save default settings for some mode flags 2443 Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods; 2444 Arguments::_UseOnStackReplacement = UseOnStackReplacement; 2445 Arguments::_ClipInlining = ClipInlining; 2446 Arguments::_BackgroundCompilation = BackgroundCompilation; 2447 if (TieredCompilation) { 2448 Arguments::_Tier3InvokeNotifyFreqLog = Tier3InvokeNotifyFreqLog; 2449 Arguments::_Tier4InvocationThreshold = Tier4InvocationThreshold; 2450 } 2451 2452 // Setup flags for mixed which is the default 2453 set_mode_flags(_mixed); 2454 2455 // Parse args structure generated from JAVA_TOOL_OPTIONS environment 2456 // variable (if present). 2457 jint result = parse_each_vm_init_arg(java_tool_options_args, &patch_mod_javabase, Flag::ENVIRON_VAR); 2458 if (result != JNI_OK) { 2459 return result; 2460 } 2461 2462 // Parse args structure generated from the command line flags. 2463 result = parse_each_vm_init_arg(cmd_line_args, &patch_mod_javabase, Flag::COMMAND_LINE); 2464 if (result != JNI_OK) { 2465 return result; 2466 } 2467 2468 // Parse args structure generated from the _JAVA_OPTIONS environment 2469 // variable (if present) (mimics classic VM) 2470 result = parse_each_vm_init_arg(java_options_args, &patch_mod_javabase, Flag::ENVIRON_VAR); 2471 if (result != JNI_OK) { 2472 return result; 2473 } 2474 2475 // We need to ensure processor and memory resources have been properly 2476 // configured - which may rely on arguments we just processed - before 2477 // doing the final argument processing. Any argument processing that 2478 // needs to know about processor and memory resources must occur after 2479 // this point. 2480 2481 os::init_container_support(); 2482 2483 // Do final processing now that all arguments have been parsed 2484 result = finalize_vm_init_args(patch_mod_javabase); 2485 if (result != JNI_OK) { 2486 return result; 2487 } 2488 2489 return JNI_OK; 2490 } 2491 2492 // Checks if name in command-line argument -agent{lib,path}:name[=options] 2493 // represents a valid JDWP agent. is_path==true denotes that we 2494 // are dealing with -agentpath (case where name is a path), otherwise with 2495 // -agentlib 2496 bool valid_jdwp_agent(char *name, bool is_path) { 2497 char *_name; 2498 const char *_jdwp = "jdwp"; 2499 size_t _len_jdwp, _len_prefix; 2500 2501 if (is_path) { 2502 if ((_name = strrchr(name, (int) *os::file_separator())) == NULL) { 2503 return false; 2504 } 2505 2506 _name++; // skip past last path separator 2507 _len_prefix = strlen(JNI_LIB_PREFIX); 2508 2509 if (strncmp(_name, JNI_LIB_PREFIX, _len_prefix) != 0) { 2510 return false; 2511 } 2512 2513 _name += _len_prefix; 2514 _len_jdwp = strlen(_jdwp); 2515 2516 if (strncmp(_name, _jdwp, _len_jdwp) == 0) { 2517 _name += _len_jdwp; 2518 } 2519 else { 2520 return false; 2521 } 2522 2523 if (strcmp(_name, JNI_LIB_SUFFIX) != 0) { 2524 return false; 2525 } 2526 2527 return true; 2528 } 2529 2530 if (strcmp(name, _jdwp) == 0) { 2531 return true; 2532 } 2533 2534 return false; 2535 } 2536 2537 int Arguments::process_patch_mod_option(const char* patch_mod_tail, bool* patch_mod_javabase) { 2538 // --patch-module=<module>=<file>(<pathsep><file>)* 2539 assert(patch_mod_tail != NULL, "Unexpected NULL patch-module value"); 2540 // Find the equal sign between the module name and the path specification 2541 const char* module_equal = strchr(patch_mod_tail, '='); 2542 if (module_equal == NULL) { 2543 jio_fprintf(defaultStream::output_stream(), "Missing '=' in --patch-module specification\n"); 2544 return JNI_ERR; 2545 } else { 2546 // Pick out the module name 2547 size_t module_len = module_equal - patch_mod_tail; 2548 char* module_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, module_len+1, mtArguments); 2549 if (module_name != NULL) { 2550 memcpy(module_name, patch_mod_tail, module_len); 2551 *(module_name + module_len) = '\0'; 2552 // The path piece begins one past the module_equal sign 2553 add_patch_mod_prefix(module_name, module_equal + 1, patch_mod_javabase); 2554 FREE_C_HEAP_ARRAY(char, module_name); 2555 if (!create_numbered_property("jdk.module.patch", patch_mod_tail, patch_mod_count++)) { 2556 return JNI_ENOMEM; 2557 } 2558 } else { 2559 return JNI_ENOMEM; 2560 } 2561 } 2562 return JNI_OK; 2563 } 2564 2565 // Parse -Xss memory string parameter and convert to ThreadStackSize in K. 2566 jint Arguments::parse_xss(const JavaVMOption* option, const char* tail, intx* out_ThreadStackSize) { 2567 // The min and max sizes match the values in globals.hpp, but scaled 2568 // with K. The values have been chosen so that alignment with page 2569 // size doesn't change the max value, which makes the conversions 2570 // back and forth between Xss value and ThreadStackSize value easier. 2571 // The values have also been chosen to fit inside a 32-bit signed type. 2572 const julong min_ThreadStackSize = 0; 2573 const julong max_ThreadStackSize = 1 * M; 2574 2575 const julong min_size = min_ThreadStackSize * K; 2576 const julong max_size = max_ThreadStackSize * K; 2577 2578 assert(is_aligned(max_size, os::vm_page_size()), "Implementation assumption"); 2579 2580 julong size = 0; 2581 ArgsRange errcode = parse_memory_size(tail, &size, min_size, max_size); 2582 if (errcode != arg_in_range) { 2583 bool silent = (option == NULL); // Allow testing to silence error messages 2584 if (!silent) { 2585 jio_fprintf(defaultStream::error_stream(), 2586 "Invalid thread stack size: %s\n", option->optionString); 2587 describe_range_error(errcode); 2588 } 2589 return JNI_EINVAL; 2590 } 2591 2592 // Internally track ThreadStackSize in units of 1024 bytes. 2593 const julong size_aligned = align_up(size, K); 2594 assert(size <= size_aligned, 2595 "Overflow: " JULONG_FORMAT " " JULONG_FORMAT, 2596 size, size_aligned); 2597 2598 const julong size_in_K = size_aligned / K; 2599 assert(size_in_K < (julong)max_intx, 2600 "size_in_K doesn't fit in the type of ThreadStackSize: " JULONG_FORMAT, 2601 size_in_K); 2602 2603 // Check that code expanding ThreadStackSize to a page aligned number of bytes won't overflow. 2604 const julong max_expanded = align_up(size_in_K * K, os::vm_page_size()); 2605 assert(max_expanded < max_uintx && max_expanded >= size_in_K, 2606 "Expansion overflowed: " JULONG_FORMAT " " JULONG_FORMAT, 2607 max_expanded, size_in_K); 2608 2609 *out_ThreadStackSize = (intx)size_in_K; 2610 2611 return JNI_OK; 2612 } 2613 2614 jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_mod_javabase, Flag::Flags origin) { 2615 // For match_option to return remaining or value part of option string 2616 const char* tail; 2617 2618 // iterate over arguments 2619 for (int index = 0; index < args->nOptions; index++) { 2620 bool is_absolute_path = false; // for -agentpath vs -agentlib 2621 2622 const JavaVMOption* option = args->options + index; 2623 2624 if (!match_option(option, "-Djava.class.path", &tail) && 2625 !match_option(option, "-Dsun.java.command", &tail) && 2626 !match_option(option, "-Dsun.java.launcher", &tail)) { 2627 2628 // add all jvm options to the jvm_args string. This string 2629 // is used later to set the java.vm.args PerfData string constant. 2630 // the -Djava.class.path and the -Dsun.java.command options are 2631 // omitted from jvm_args string as each have their own PerfData 2632 // string constant object. 2633 build_jvm_args(option->optionString); 2634 } 2635 2636 // -verbose:[class/module/gc/jni] 2637 if (match_option(option, "-verbose", &tail)) { 2638 if (!strcmp(tail, ":class") || !strcmp(tail, "")) { 2639 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, load)); 2640 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, unload)); 2641 } else if (!strcmp(tail, ":module")) { 2642 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(module, load)); 2643 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(module, unload)); 2644 } else if (!strcmp(tail, ":gc")) { 2645 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(gc)); 2646 } else if (!strcmp(tail, ":jni")) { 2647 if (FLAG_SET_CMDLINE(bool, PrintJNIResolving, true) != Flag::SUCCESS) { 2648 return JNI_EINVAL; 2649 } 2650 } 2651 // -da / -ea / -disableassertions / -enableassertions 2652 // These accept an optional class/package name separated by a colon, e.g., 2653 // -da:java.lang.Thread. 2654 } else if (match_option(option, user_assertion_options, &tail, true)) { 2655 bool enable = option->optionString[1] == 'e'; // char after '-' is 'e' 2656 if (*tail == '\0') { 2657 JavaAssertions::setUserClassDefault(enable); 2658 } else { 2659 assert(*tail == ':', "bogus match by match_option()"); 2660 JavaAssertions::addOption(tail + 1, enable); 2661 } 2662 // -dsa / -esa / -disablesystemassertions / -enablesystemassertions 2663 } else if (match_option(option, system_assertion_options, &tail, false)) { 2664 bool enable = option->optionString[1] == 'e'; // char after '-' is 'e' 2665 JavaAssertions::setSystemClassDefault(enable); 2666 // -bootclasspath: 2667 } else if (match_option(option, "-Xbootclasspath:", &tail)) { 2668 jio_fprintf(defaultStream::output_stream(), 2669 "-Xbootclasspath is no longer a supported option.\n"); 2670 return JNI_EINVAL; 2671 // -bootclasspath/a: 2672 } else if (match_option(option, "-Xbootclasspath/a:", &tail)) { 2673 Arguments::append_sysclasspath(tail); 2674 // -bootclasspath/p: 2675 } else if (match_option(option, "-Xbootclasspath/p:", &tail)) { 2676 jio_fprintf(defaultStream::output_stream(), 2677 "-Xbootclasspath/p is no longer a supported option.\n"); 2678 return JNI_EINVAL; 2679 // -Xrun 2680 } else if (match_option(option, "-Xrun", &tail)) { 2681 if (tail != NULL) { 2682 const char* pos = strchr(tail, ':'); 2683 size_t len = (pos == NULL) ? strlen(tail) : pos - tail; 2684 char* name = NEW_C_HEAP_ARRAY(char, len + 1, mtArguments); 2685 jio_snprintf(name, len + 1, "%s", tail); 2686 2687 char *options = NULL; 2688 if(pos != NULL) { 2689 size_t len2 = strlen(pos+1) + 1; // options start after ':'. Final zero must be copied. 2690 options = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len2, mtArguments), pos+1, len2); 2691 } 2692 #if !INCLUDE_JVMTI 2693 if (strcmp(name, "jdwp") == 0) { 2694 jio_fprintf(defaultStream::error_stream(), 2695 "Debugging agents are not supported in this VM\n"); 2696 return JNI_ERR; 2697 } 2698 #endif // !INCLUDE_JVMTI 2699 add_init_library(name, options); 2700 } 2701 } else if (match_option(option, "--add-reads=", &tail)) { 2702 if (!create_numbered_property("jdk.module.addreads", tail, addreads_count++)) { 2703 return JNI_ENOMEM; 2704 } 2705 } else if (match_option(option, "--add-exports=", &tail)) { 2706 if (!create_numbered_property("jdk.module.addexports", tail, addexports_count++)) { 2707 return JNI_ENOMEM; 2708 } 2709 } else if (match_option(option, "--add-opens=", &tail)) { 2710 if (!create_numbered_property("jdk.module.addopens", tail, addopens_count++)) { 2711 return JNI_ENOMEM; 2712 } 2713 } else if (match_option(option, "--add-modules=", &tail)) { 2714 if (!create_numbered_property("jdk.module.addmods", tail, addmods_count++)) { 2715 return JNI_ENOMEM; 2716 } 2717 } else if (match_option(option, "--limit-modules=", &tail)) { 2718 if (!create_property("jdk.module.limitmods", tail, InternalProperty)) { 2719 return JNI_ENOMEM; 2720 } 2721 } else if (match_option(option, "--module-path=", &tail)) { 2722 if (!create_property("jdk.module.path", tail, ExternalProperty)) { 2723 return JNI_ENOMEM; 2724 } 2725 } else if (match_option(option, "--upgrade-module-path=", &tail)) { 2726 if (!create_property("jdk.module.upgrade.path", tail, ExternalProperty)) { 2727 return JNI_ENOMEM; 2728 } 2729 } else if (match_option(option, "--patch-module=", &tail)) { 2730 // --patch-module=<module>=<file>(<pathsep><file>)* 2731 int res = process_patch_mod_option(tail, patch_mod_javabase); 2732 if (res != JNI_OK) { 2733 return res; 2734 } 2735 } else if (match_option(option, "--illegal-access=", &tail)) { 2736 if (!create_property("jdk.module.illegalAccess", tail, ExternalProperty)) { 2737 return JNI_ENOMEM; 2738 } 2739 // -agentlib and -agentpath 2740 } else if (match_option(option, "-agentlib:", &tail) || 2741 (is_absolute_path = match_option(option, "-agentpath:", &tail))) { 2742 if(tail != NULL) { 2743 const char* pos = strchr(tail, '='); 2744 size_t len = (pos == NULL) ? strlen(tail) : pos - tail; 2745 char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1, mtArguments), tail, len); 2746 name[len] = '\0'; 2747 2748 char *options = NULL; 2749 if(pos != NULL) { 2750 options = os::strdup_check_oom(pos + 1, mtArguments); 2751 } 2752 #if !INCLUDE_JVMTI 2753 if (valid_jdwp_agent(name, is_absolute_path)) { 2754 jio_fprintf(defaultStream::error_stream(), 2755 "Debugging agents are not supported in this VM\n"); 2756 return JNI_ERR; 2757 } 2758 #endif // !INCLUDE_JVMTI 2759 add_init_agent(name, options, is_absolute_path); 2760 } 2761 // -javaagent 2762 } else if (match_option(option, "-javaagent:", &tail)) { 2763 #if !INCLUDE_JVMTI 2764 jio_fprintf(defaultStream::error_stream(), 2765 "Instrumentation agents are not supported in this VM\n"); 2766 return JNI_ERR; 2767 #else 2768 if (tail != NULL) { 2769 size_t length = strlen(tail) + 1; 2770 char *options = NEW_C_HEAP_ARRAY(char, length, mtArguments); 2771 jio_snprintf(options, length, "%s", tail); 2772 add_instrument_agent("instrument", options, false); 2773 // java agents need module java.instrument 2774 if (!create_numbered_property("jdk.module.addmods", "java.instrument", addmods_count++)) { 2775 return JNI_ENOMEM; 2776 } 2777 } 2778 #endif // !INCLUDE_JVMTI 2779 // -Xnoclassgc 2780 } else if (match_option(option, "-Xnoclassgc")) { 2781 if (FLAG_SET_CMDLINE(bool, ClassUnloading, false) != Flag::SUCCESS) { 2782 return JNI_EINVAL; 2783 } 2784 // -Xconcgc 2785 } else if (match_option(option, "-Xconcgc")) { 2786 if (FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true) != Flag::SUCCESS) { 2787 return JNI_EINVAL; 2788 } 2789 handle_extra_cms_flags("-Xconcgc uses UseConcMarkSweepGC"); 2790 // -Xnoconcgc 2791 } else if (match_option(option, "-Xnoconcgc")) { 2792 if (FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false) != Flag::SUCCESS) { 2793 return JNI_EINVAL; 2794 } 2795 handle_extra_cms_flags("-Xnoconcgc uses UseConcMarkSweepGC"); 2796 // -Xbatch 2797 } else if (match_option(option, "-Xbatch")) { 2798 if (FLAG_SET_CMDLINE(bool, BackgroundCompilation, false) != Flag::SUCCESS) { 2799 return JNI_EINVAL; 2800 } 2801 // -Xmn for compatibility with other JVM vendors 2802 } else if (match_option(option, "-Xmn", &tail)) { 2803 julong long_initial_young_size = 0; 2804 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1); 2805 if (errcode != arg_in_range) { 2806 jio_fprintf(defaultStream::error_stream(), 2807 "Invalid initial young generation size: %s\n", option->optionString); 2808 describe_range_error(errcode); 2809 return JNI_EINVAL; 2810 } 2811 if (FLAG_SET_CMDLINE(size_t, MaxNewSize, (size_t)long_initial_young_size) != Flag::SUCCESS) { 2812 return JNI_EINVAL; 2813 } 2814 if (FLAG_SET_CMDLINE(size_t, NewSize, (size_t)long_initial_young_size) != Flag::SUCCESS) { 2815 return JNI_EINVAL; 2816 } 2817 // -Xms 2818 } else if (match_option(option, "-Xms", &tail)) { 2819 julong long_initial_heap_size = 0; 2820 // an initial heap size of 0 means automatically determine 2821 ArgsRange errcode = parse_memory_size(tail, &long_initial_heap_size, 0); 2822 if (errcode != arg_in_range) { 2823 jio_fprintf(defaultStream::error_stream(), 2824 "Invalid initial heap size: %s\n", option->optionString); 2825 describe_range_error(errcode); 2826 return JNI_EINVAL; 2827 } 2828 set_min_heap_size((size_t)long_initial_heap_size); 2829 // Currently the minimum size and the initial heap sizes are the same. 2830 // Can be overridden with -XX:InitialHeapSize. 2831 if (FLAG_SET_CMDLINE(size_t, InitialHeapSize, (size_t)long_initial_heap_size) != Flag::SUCCESS) { 2832 return JNI_EINVAL; 2833 } 2834 // -Xmx 2835 } else if (match_option(option, "-Xmx", &tail) || match_option(option, "-XX:MaxHeapSize=", &tail)) { 2836 julong long_max_heap_size = 0; 2837 ArgsRange errcode = parse_memory_size(tail, &long_max_heap_size, 1); 2838 if (errcode != arg_in_range) { 2839 jio_fprintf(defaultStream::error_stream(), 2840 "Invalid maximum heap size: %s\n", option->optionString); 2841 describe_range_error(errcode); 2842 return JNI_EINVAL; 2843 } 2844 if (FLAG_SET_CMDLINE(size_t, MaxHeapSize, (size_t)long_max_heap_size) != Flag::SUCCESS) { 2845 return JNI_EINVAL; 2846 } 2847 // Xmaxf 2848 } else if (match_option(option, "-Xmaxf", &tail)) { 2849 char* err; 2850 int maxf = (int)(strtod(tail, &err) * 100); 2851 if (*err != '\0' || *tail == '\0') { 2852 jio_fprintf(defaultStream::error_stream(), 2853 "Bad max heap free percentage size: %s\n", 2854 option->optionString); 2855 return JNI_EINVAL; 2856 } else { 2857 if (FLAG_SET_CMDLINE(uintx, MaxHeapFreeRatio, maxf) != Flag::SUCCESS) { 2858 return JNI_EINVAL; 2859 } 2860 } 2861 // Xminf 2862 } else if (match_option(option, "-Xminf", &tail)) { 2863 char* err; 2864 int minf = (int)(strtod(tail, &err) * 100); 2865 if (*err != '\0' || *tail == '\0') { 2866 jio_fprintf(defaultStream::error_stream(), 2867 "Bad min heap free percentage size: %s\n", 2868 option->optionString); 2869 return JNI_EINVAL; 2870 } else { 2871 if (FLAG_SET_CMDLINE(uintx, MinHeapFreeRatio, minf) != Flag::SUCCESS) { 2872 return JNI_EINVAL; 2873 } 2874 } 2875 // -Xss 2876 } else if (match_option(option, "-Xss", &tail)) { 2877 intx value = 0; 2878 jint err = parse_xss(option, tail, &value); 2879 if (err != JNI_OK) { 2880 return err; 2881 } 2882 if (FLAG_SET_CMDLINE(intx, ThreadStackSize, value) != Flag::SUCCESS) { 2883 return JNI_EINVAL; 2884 } 2885 } else if (match_option(option, "-Xmaxjitcodesize", &tail) || 2886 match_option(option, "-XX:ReservedCodeCacheSize=", &tail)) { 2887 julong long_ReservedCodeCacheSize = 0; 2888 2889 ArgsRange errcode = parse_memory_size(tail, &long_ReservedCodeCacheSize, 1); 2890 if (errcode != arg_in_range) { 2891 jio_fprintf(defaultStream::error_stream(), 2892 "Invalid maximum code cache size: %s.\n", option->optionString); 2893 return JNI_EINVAL; 2894 } 2895 if (FLAG_SET_CMDLINE(uintx, ReservedCodeCacheSize, (uintx)long_ReservedCodeCacheSize) != Flag::SUCCESS) { 2896 return JNI_EINVAL; 2897 } 2898 // -green 2899 } else if (match_option(option, "-green")) { 2900 jio_fprintf(defaultStream::error_stream(), 2901 "Green threads support not available\n"); 2902 return JNI_EINVAL; 2903 // -native 2904 } else if (match_option(option, "-native")) { 2905 // HotSpot always uses native threads, ignore silently for compatibility 2906 // -Xrs 2907 } else if (match_option(option, "-Xrs")) { 2908 // Classic/EVM option, new functionality 2909 if (FLAG_SET_CMDLINE(bool, ReduceSignalUsage, true) != Flag::SUCCESS) { 2910 return JNI_EINVAL; 2911 } 2912 // -Xprof 2913 } else if (match_option(option, "-Xprof")) { 2914 char version[256]; 2915 // Obsolete in JDK 10 2916 JDK_Version::jdk(10).to_string(version, sizeof(version)); 2917 warning("Ignoring option %s; support was removed in %s", option->optionString, version); 2918 // -Xconcurrentio 2919 } else if (match_option(option, "-Xconcurrentio")) { 2920 if (FLAG_SET_CMDLINE(bool, UseLWPSynchronization, true) != Flag::SUCCESS) { 2921 return JNI_EINVAL; 2922 } 2923 if (FLAG_SET_CMDLINE(bool, BackgroundCompilation, false) != Flag::SUCCESS) { 2924 return JNI_EINVAL; 2925 } 2926 SafepointSynchronize::set_defer_thr_suspend_loop_count(); 2927 if (FLAG_SET_CMDLINE(bool, UseTLAB, false) != Flag::SUCCESS) { 2928 return JNI_EINVAL; 2929 } 2930 if (FLAG_SET_CMDLINE(size_t, NewSizeThreadIncrease, 16 * K) != Flag::SUCCESS) { // 20Kb per thread added to new generation 2931 return JNI_EINVAL; 2932 } 2933 2934 // -Xinternalversion 2935 } else if (match_option(option, "-Xinternalversion")) { 2936 jio_fprintf(defaultStream::output_stream(), "%s\n", 2937 VM_Version::internal_vm_info_string()); 2938 vm_exit(0); 2939 #ifndef PRODUCT 2940 // -Xprintflags 2941 } else if (match_option(option, "-Xprintflags")) { 2942 CommandLineFlags::printFlags(tty, false); 2943 vm_exit(0); 2944 #endif 2945 // -D 2946 } else if (match_option(option, "-D", &tail)) { 2947 const char* value; 2948 if (match_option(option, "-Djava.endorsed.dirs=", &value) && 2949 *value!= '\0' && strcmp(value, "\"\"") != 0) { 2950 // abort if -Djava.endorsed.dirs is set 2951 jio_fprintf(defaultStream::output_stream(), 2952 "-Djava.endorsed.dirs=%s is not supported. Endorsed standards and standalone APIs\n" 2953 "in modular form will be supported via the concept of upgradeable modules.\n", value); 2954 return JNI_EINVAL; 2955 } 2956 if (match_option(option, "-Djava.ext.dirs=", &value) && 2957 *value != '\0' && strcmp(value, "\"\"") != 0) { 2958 // abort if -Djava.ext.dirs is set 2959 jio_fprintf(defaultStream::output_stream(), 2960 "-Djava.ext.dirs=%s is not supported. Use -classpath instead.\n", value); 2961 return JNI_EINVAL; 2962 } 2963 // Check for module related properties. They must be set using the modules 2964 // options. For example: use "--add-modules=java.sql", not 2965 // "-Djdk.module.addmods=java.sql" 2966 if (is_internal_module_property(option->optionString + 2)) { 2967 needs_module_property_warning = true; 2968 continue; 2969 } 2970 2971 if (!add_property(tail)) { 2972 return JNI_ENOMEM; 2973 } 2974 // Out of the box management support 2975 if (match_option(option, "-Dcom.sun.management", &tail)) { 2976 #if INCLUDE_MANAGEMENT 2977 if (FLAG_SET_CMDLINE(bool, ManagementServer, true) != Flag::SUCCESS) { 2978 return JNI_EINVAL; 2979 } 2980 // management agent in module jdk.management.agent 2981 if (!create_numbered_property("jdk.module.addmods", "jdk.management.agent", addmods_count++)) { 2982 return JNI_ENOMEM; 2983 } 2984 #else 2985 jio_fprintf(defaultStream::output_stream(), 2986 "-Dcom.sun.management is not supported in this VM.\n"); 2987 return JNI_ERR; 2988 #endif 2989 } 2990 // -Xint 2991 } else if (match_option(option, "-Xint")) { 2992 set_mode_flags(_int); 2993 // -Xmixed 2994 } else if (match_option(option, "-Xmixed")) { 2995 set_mode_flags(_mixed); 2996 // -Xcomp 2997 } else if (match_option(option, "-Xcomp")) { 2998 // for testing the compiler; turn off all flags that inhibit compilation 2999 set_mode_flags(_comp); 3000 // -Xshare:dump 3001 } else if (match_option(option, "-Xshare:dump")) { 3002 if (FLAG_SET_CMDLINE(bool, DumpSharedSpaces, true) != Flag::SUCCESS) { 3003 return JNI_EINVAL; 3004 } 3005 set_mode_flags(_int); // Prevent compilation, which creates objects 3006 // -Xshare:on 3007 } else if (match_option(option, "-Xshare:on")) { 3008 if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, true) != Flag::SUCCESS) { 3009 return JNI_EINVAL; 3010 } 3011 if (FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true) != Flag::SUCCESS) { 3012 return JNI_EINVAL; 3013 } 3014 // -Xshare:auto 3015 } else if (match_option(option, "-Xshare:auto")) { 3016 if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, true) != Flag::SUCCESS) { 3017 return JNI_EINVAL; 3018 } 3019 if (FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false) != Flag::SUCCESS) { 3020 return JNI_EINVAL; 3021 } 3022 // -Xshare:off 3023 } else if (match_option(option, "-Xshare:off")) { 3024 if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, false) != Flag::SUCCESS) { 3025 return JNI_EINVAL; 3026 } 3027 if (FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false) != Flag::SUCCESS) { 3028 return JNI_EINVAL; 3029 } 3030 // -Xverify 3031 } else if (match_option(option, "-Xverify", &tail)) { 3032 if (strcmp(tail, ":all") == 0 || strcmp(tail, "") == 0) { 3033 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, true) != Flag::SUCCESS) { 3034 return JNI_EINVAL; 3035 } 3036 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true) != Flag::SUCCESS) { 3037 return JNI_EINVAL; 3038 } 3039 } else if (strcmp(tail, ":remote") == 0) { 3040 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false) != Flag::SUCCESS) { 3041 return JNI_EINVAL; 3042 } 3043 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true) != Flag::SUCCESS) { 3044 return JNI_EINVAL; 3045 } 3046 } else if (strcmp(tail, ":none") == 0) { 3047 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false) != Flag::SUCCESS) { 3048 return JNI_EINVAL; 3049 } 3050 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, false) != Flag::SUCCESS) { 3051 return JNI_EINVAL; 3052 } 3053 } else if (is_bad_option(option, args->ignoreUnrecognized, "verification")) { 3054 return JNI_EINVAL; 3055 } 3056 // -Xdebug 3057 } else if (match_option(option, "-Xdebug")) { 3058 // note this flag has been used, then ignore 3059 set_xdebug_mode(true); 3060 // -Xnoagent 3061 } else if (match_option(option, "-Xnoagent")) { 3062 // For compatibility with classic. HotSpot refuses to load the old style agent.dll. 3063 } else if (match_option(option, "-Xloggc:", &tail)) { 3064 // Deprecated flag to redirect GC output to a file. -Xloggc:<filename> 3065 log_warning(gc)("-Xloggc is deprecated. Will use -Xlog:gc:%s instead.", tail); 3066 _gc_log_filename = os::strdup_check_oom(tail); 3067 } else if (match_option(option, "-Xlog", &tail)) { 3068 bool ret = false; 3069 if (strcmp(tail, ":help") == 0) { 3070 fileStream stream(defaultStream::output_stream()); 3071 LogConfiguration::print_command_line_help(&stream); 3072 vm_exit(0); 3073 } else if (strcmp(tail, ":disable") == 0) { 3074 LogConfiguration::disable_logging(); 3075 ret = true; 3076 } else if (*tail == '\0') { 3077 ret = LogConfiguration::parse_command_line_arguments(); 3078 assert(ret, "-Xlog without arguments should never fail to parse"); 3079 } else if (*tail == ':') { 3080 ret = LogConfiguration::parse_command_line_arguments(tail + 1); 3081 } 3082 if (ret == false) { 3083 jio_fprintf(defaultStream::error_stream(), 3084 "Invalid -Xlog option '-Xlog%s', see error log for details.\n", 3085 tail); 3086 return JNI_EINVAL; 3087 } 3088 // JNI hooks 3089 } else if (match_option(option, "-Xcheck", &tail)) { 3090 if (!strcmp(tail, ":jni")) { 3091 #if !INCLUDE_JNI_CHECK 3092 warning("JNI CHECKING is not supported in this VM"); 3093 #else 3094 CheckJNICalls = true; 3095 #endif // INCLUDE_JNI_CHECK 3096 } else if (is_bad_option(option, args->ignoreUnrecognized, 3097 "check")) { 3098 return JNI_EINVAL; 3099 } 3100 } else if (match_option(option, "vfprintf")) { 3101 _vfprintf_hook = CAST_TO_FN_PTR(vfprintf_hook_t, option->extraInfo); 3102 } else if (match_option(option, "exit")) { 3103 _exit_hook = CAST_TO_FN_PTR(exit_hook_t, option->extraInfo); 3104 } else if (match_option(option, "abort")) { 3105 _abort_hook = CAST_TO_FN_PTR(abort_hook_t, option->extraInfo); 3106 // Need to keep consistency of MaxTenuringThreshold and AlwaysTenure/NeverTenure; 3107 // and the last option wins. 3108 } else if (match_option(option, "-XX:+NeverTenure")) { 3109 if (FLAG_SET_CMDLINE(bool, NeverTenure, true) != Flag::SUCCESS) { 3110 return JNI_EINVAL; 3111 } 3112 if (FLAG_SET_CMDLINE(bool, AlwaysTenure, false) != Flag::SUCCESS) { 3113 return JNI_EINVAL; 3114 } 3115 if (FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, markOopDesc::max_age + 1) != Flag::SUCCESS) { 3116 return JNI_EINVAL; 3117 } 3118 } else if (match_option(option, "-XX:+AlwaysTenure")) { 3119 if (FLAG_SET_CMDLINE(bool, NeverTenure, false) != Flag::SUCCESS) { 3120 return JNI_EINVAL; 3121 } 3122 if (FLAG_SET_CMDLINE(bool, AlwaysTenure, true) != Flag::SUCCESS) { 3123 return JNI_EINVAL; 3124 } 3125 if (FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, 0) != Flag::SUCCESS) { 3126 return JNI_EINVAL; 3127 } 3128 } else if (match_option(option, "-XX:MaxTenuringThreshold=", &tail)) { 3129 uintx max_tenuring_thresh = 0; 3130 if (!parse_uintx(tail, &max_tenuring_thresh, 0)) { 3131 jio_fprintf(defaultStream::error_stream(), 3132 "Improperly specified VM option \'MaxTenuringThreshold=%s\'\n", tail); 3133 return JNI_EINVAL; 3134 } 3135 3136 if (FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, max_tenuring_thresh) != Flag::SUCCESS) { 3137 return JNI_EINVAL; 3138 } 3139 3140 if (MaxTenuringThreshold == 0) { 3141 if (FLAG_SET_CMDLINE(bool, NeverTenure, false) != Flag::SUCCESS) { 3142 return JNI_EINVAL; 3143 } 3144 if (FLAG_SET_CMDLINE(bool, AlwaysTenure, true) != Flag::SUCCESS) { 3145 return JNI_EINVAL; 3146 } 3147 } else { 3148 if (FLAG_SET_CMDLINE(bool, NeverTenure, false) != Flag::SUCCESS) { 3149 return JNI_EINVAL; 3150 } 3151 if (FLAG_SET_CMDLINE(bool, AlwaysTenure, false) != Flag::SUCCESS) { 3152 return JNI_EINVAL; 3153 } 3154 } 3155 } else if (match_option(option, "-XX:+DisplayVMOutputToStderr")) { 3156 if (FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, false) != Flag::SUCCESS) { 3157 return JNI_EINVAL; 3158 } 3159 if (FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, true) != Flag::SUCCESS) { 3160 return JNI_EINVAL; 3161 } 3162 } else if (match_option(option, "-XX:+DisplayVMOutputToStdout")) { 3163 if (FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, false) != Flag::SUCCESS) { 3164 return JNI_EINVAL; 3165 } 3166 if (FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, true) != Flag::SUCCESS) { 3167 return JNI_EINVAL; 3168 } 3169 } else if (match_option(option, "-XX:+ExtendedDTraceProbes")) { 3170 #if defined(DTRACE_ENABLED) 3171 if (FLAG_SET_CMDLINE(bool, ExtendedDTraceProbes, true) != Flag::SUCCESS) { 3172 return JNI_EINVAL; 3173 } 3174 if (FLAG_SET_CMDLINE(bool, DTraceMethodProbes, true) != Flag::SUCCESS) { 3175 return JNI_EINVAL; 3176 } 3177 if (FLAG_SET_CMDLINE(bool, DTraceAllocProbes, true) != Flag::SUCCESS) { 3178 return JNI_EINVAL; 3179 } 3180 if (FLAG_SET_CMDLINE(bool, DTraceMonitorProbes, true) != Flag::SUCCESS) { 3181 return JNI_EINVAL; 3182 } 3183 #else // defined(DTRACE_ENABLED) 3184 jio_fprintf(defaultStream::error_stream(), 3185 "ExtendedDTraceProbes flag is not applicable for this configuration\n"); 3186 return JNI_EINVAL; 3187 #endif // defined(DTRACE_ENABLED) 3188 #ifdef ASSERT 3189 } else if (match_option(option, "-XX:+FullGCALot")) { 3190 if (FLAG_SET_CMDLINE(bool, FullGCALot, true) != Flag::SUCCESS) { 3191 return JNI_EINVAL; 3192 } 3193 // disable scavenge before parallel mark-compact 3194 if (FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false) != Flag::SUCCESS) { 3195 return JNI_EINVAL; 3196 } 3197 #endif 3198 #if !INCLUDE_MANAGEMENT 3199 } else if (match_option(option, "-XX:+ManagementServer")) { 3200 jio_fprintf(defaultStream::error_stream(), 3201 "ManagementServer is not supported in this VM.\n"); 3202 return JNI_ERR; 3203 #endif // INCLUDE_MANAGEMENT 3204 } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx 3205 // Skip -XX:Flags= and -XX:VMOptionsFile= since those cases have 3206 // already been handled 3207 if ((strncmp(tail, "Flags=", strlen("Flags=")) != 0) && 3208 (strncmp(tail, "VMOptionsFile=", strlen("VMOptionsFile=")) != 0)) { 3209 if (!process_argument(tail, args->ignoreUnrecognized, origin)) { 3210 return JNI_EINVAL; 3211 } 3212 } 3213 // Unknown option 3214 } else if (is_bad_option(option, args->ignoreUnrecognized)) { 3215 return JNI_ERR; 3216 } 3217 } 3218 3219 // PrintSharedArchiveAndExit will turn on 3220 // -Xshare:on 3221 // -Xlog:class+path=info 3222 if (PrintSharedArchiveAndExit) { 3223 if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, true) != Flag::SUCCESS) { 3224 return JNI_EINVAL; 3225 } 3226 if (FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true) != Flag::SUCCESS) { 3227 return JNI_EINVAL; 3228 } 3229 LogConfiguration::configure_stdout(LogLevel::Info, true, LOG_TAGS(class, path)); 3230 } 3231 3232 // Change the default value for flags which have different default values 3233 // when working with older JDKs. 3234 #ifdef LINUX 3235 if (JDK_Version::current().compare_major(6) <= 0 && 3236 FLAG_IS_DEFAULT(UseLinuxPosixThreadCPUClocks)) { 3237 FLAG_SET_DEFAULT(UseLinuxPosixThreadCPUClocks, false); 3238 } 3239 #endif // LINUX 3240 fix_appclasspath(); 3241 return JNI_OK; 3242 } 3243 3244 void Arguments::add_patch_mod_prefix(const char* module_name, const char* path, bool* patch_mod_javabase) { 3245 // For java.base check for duplicate --patch-module options being specified on the command line. 3246 // This check is only required for java.base, all other duplicate module specifications 3247 // will be checked during module system initialization. The module system initialization 3248 // will throw an ExceptionInInitializerError if this situation occurs. 3249 if (strcmp(module_name, JAVA_BASE_NAME) == 0) { 3250 if (*patch_mod_javabase) { 3251 vm_exit_during_initialization("Cannot specify " JAVA_BASE_NAME " more than once to --patch-module"); 3252 } else { 3253 *patch_mod_javabase = true; 3254 } 3255 } 3256 3257 // Create GrowableArray lazily, only if --patch-module has been specified 3258 if (_patch_mod_prefix == NULL) { 3259 _patch_mod_prefix = new (ResourceObj::C_HEAP, mtArguments) GrowableArray<ModulePatchPath*>(10, true); 3260 } 3261 3262 _patch_mod_prefix->push(new ModulePatchPath(module_name, path)); 3263 } 3264 3265 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled) 3266 // 3267 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar 3268 // in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar". 3269 // Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty 3270 // path is treated as the current directory. 3271 // 3272 // This causes problems with CDS, which requires that all directories specified in the classpath 3273 // must be empty. In most cases, applications do NOT want to load classes from the current 3274 // directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up 3275 // scripts compatible with CDS. 3276 void Arguments::fix_appclasspath() { 3277 if (IgnoreEmptyClassPaths) { 3278 const char separator = *os::path_separator(); 3279 const char* src = _java_class_path->value(); 3280 3281 // skip over all the leading empty paths 3282 while (*src == separator) { 3283 src ++; 3284 } 3285 3286 char* copy = os::strdup_check_oom(src, mtArguments); 3287 3288 // trim all trailing empty paths 3289 for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) { 3290 *tail = '\0'; 3291 } 3292 3293 char from[3] = {separator, separator, '\0'}; 3294 char to [2] = {separator, '\0'}; 3295 while (StringUtils::replace_no_expand(copy, from, to) > 0) { 3296 // Keep replacing "::" -> ":" until we have no more "::" (non-windows) 3297 // Keep replacing ";;" -> ";" until we have no more ";;" (windows) 3298 } 3299 3300 _java_class_path->set_writeable_value(copy); 3301 FreeHeap(copy); // a copy was made by set_value, so don't need this anymore 3302 } 3303 } 3304 3305 jint Arguments::finalize_vm_init_args(bool patch_mod_javabase) { 3306 // check if the default lib/endorsed directory exists; if so, error 3307 char path[JVM_MAXPATHLEN]; 3308 const char* fileSep = os::file_separator(); 3309 jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep); 3310 3311 DIR* dir = os::opendir(path); 3312 if (dir != NULL) { 3313 jio_fprintf(defaultStream::output_stream(), 3314 "<JAVA_HOME>/lib/endorsed is not supported. Endorsed standards and standalone APIs\n" 3315 "in modular form will be supported via the concept of upgradeable modules.\n"); 3316 os::closedir(dir); 3317 return JNI_ERR; 3318 } 3319 3320 jio_snprintf(path, JVM_MAXPATHLEN, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep); 3321 dir = os::opendir(path); 3322 if (dir != NULL) { 3323 jio_fprintf(defaultStream::output_stream(), 3324 "<JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; " 3325 "Use -classpath instead.\n."); 3326 os::closedir(dir); 3327 return JNI_ERR; 3328 } 3329 3330 // This must be done after all arguments have been processed 3331 // and the container support has been initialized since AggressiveHeap 3332 // relies on the amount of total memory available. 3333 if (AggressiveHeap) { 3334 jint result = set_aggressive_heap_flags(); 3335 if (result != JNI_OK) { 3336 return result; 3337 } 3338 } 3339 3340 // This must be done after all arguments have been processed. 3341 // java_compiler() true means set to "NONE" or empty. 3342 if (java_compiler() && !xdebug_mode()) { 3343 // For backwards compatibility, we switch to interpreted mode if 3344 // -Djava.compiler="NONE" or "" is specified AND "-Xdebug" was 3345 // not specified. 3346 set_mode_flags(_int); 3347 } 3348 3349 // CompileThresholdScaling == 0.0 is same as -Xint: Disable compilation (enable interpreter-only mode), 3350 // but like -Xint, leave compilation thresholds unaffected. 3351 // With tiered compilation disabled, setting CompileThreshold to 0 disables compilation as well. 3352 if ((CompileThresholdScaling == 0.0) || (!TieredCompilation && CompileThreshold == 0)) { 3353 set_mode_flags(_int); 3354 } 3355 3356 // eventually fix up InitialTenuringThreshold if only MaxTenuringThreshold is set 3357 if (FLAG_IS_DEFAULT(InitialTenuringThreshold) && (InitialTenuringThreshold > MaxTenuringThreshold)) { 3358 FLAG_SET_ERGO(uintx, InitialTenuringThreshold, MaxTenuringThreshold); 3359 } 3360 3361 #if !defined(COMPILER2) && !INCLUDE_JVMCI 3362 // Don't degrade server performance for footprint 3363 if (FLAG_IS_DEFAULT(UseLargePages) && 3364 MaxHeapSize < LargePageHeapSizeThreshold) { 3365 // No need for large granularity pages w/small heaps. 3366 // Note that large pages are enabled/disabled for both the 3367 // Java heap and the code cache. 3368 FLAG_SET_DEFAULT(UseLargePages, false); 3369 } 3370 3371 #elif defined(COMPILER2) 3372 if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) { 3373 FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment-1); 3374 } 3375 #endif 3376 3377 #if !defined(COMPILER2) && !INCLUDE_JVMCI 3378 UNSUPPORTED_OPTION(ProfileInterpreter); 3379 NOT_PRODUCT(UNSUPPORTED_OPTION(TraceProfileInterpreter)); 3380 #endif 3381 3382 #ifndef TIERED 3383 // Tiered compilation is undefined. 3384 UNSUPPORTED_OPTION(TieredCompilation); 3385 #endif 3386 3387 #if INCLUDE_JVMCI 3388 if (EnableJVMCI && 3389 !create_numbered_property("jdk.module.addmods", "jdk.internal.vm.ci", addmods_count++)) { 3390 return JNI_ENOMEM; 3391 } 3392 #endif 3393 3394 if (!check_vm_args_consistency()) { 3395 return JNI_ERR; 3396 } 3397 3398 #if INCLUDE_JVMCI 3399 if (UseJVMCICompiler) { 3400 Compilation_mode = CompMode_server; 3401 } 3402 #endif 3403 3404 #if INCLUDE_CDS 3405 if (DumpSharedSpaces) { 3406 // Disable biased locking now as it interferes with the clean up of 3407 // the archived Klasses and Java string objects (at dump time only). 3408 UseBiasedLocking = false; 3409 } 3410 if (UseSharedSpaces && patch_mod_javabase) { 3411 no_shared_spaces("CDS is disabled when " JAVA_BASE_NAME " module is patched."); 3412 } 3413 #endif 3414 3415 #ifndef CAN_SHOW_REGISTERS_ON_ASSERT 3416 UNSUPPORTED_OPTION(ShowRegistersOnAssert); 3417 #endif // CAN_SHOW_REGISTERS_ON_ASSERT 3418 3419 return JNI_OK; 3420 } 3421 3422 // Helper class for controlling the lifetime of JavaVMInitArgs 3423 // objects. The contents of the JavaVMInitArgs are guaranteed to be 3424 // deleted on the destruction of the ScopedVMInitArgs object. 3425 class ScopedVMInitArgs : public StackObj { 3426 private: 3427 JavaVMInitArgs _args; 3428 char* _container_name; 3429 bool _is_set; 3430 char* _vm_options_file_arg; 3431 3432 public: 3433 ScopedVMInitArgs(const char *container_name) { 3434 _args.version = JNI_VERSION_1_2; 3435 _args.nOptions = 0; 3436 _args.options = NULL; 3437 _args.ignoreUnrecognized = false; 3438 _container_name = (char *)container_name; 3439 _is_set = false; 3440 _vm_options_file_arg = NULL; 3441 } 3442 3443 // Populates the JavaVMInitArgs object represented by this 3444 // ScopedVMInitArgs object with the arguments in options. The 3445 // allocated memory is deleted by the destructor. If this method 3446 // returns anything other than JNI_OK, then this object is in a 3447 // partially constructed state, and should be abandoned. 3448 jint set_args(GrowableArray<JavaVMOption>* options) { 3449 _is_set = true; 3450 JavaVMOption* options_arr = NEW_C_HEAP_ARRAY_RETURN_NULL( 3451 JavaVMOption, options->length(), mtArguments); 3452 if (options_arr == NULL) { 3453 return JNI_ENOMEM; 3454 } 3455 _args.options = options_arr; 3456 3457 for (int i = 0; i < options->length(); i++) { 3458 options_arr[i] = options->at(i); 3459 options_arr[i].optionString = os::strdup(options_arr[i].optionString); 3460 if (options_arr[i].optionString == NULL) { 3461 // Rely on the destructor to do cleanup. 3462 _args.nOptions = i; 3463 return JNI_ENOMEM; 3464 } 3465 } 3466 3467 _args.nOptions = options->length(); 3468 _args.ignoreUnrecognized = IgnoreUnrecognizedVMOptions; 3469 return JNI_OK; 3470 } 3471 3472 JavaVMInitArgs* get() { return &_args; } 3473 char* container_name() { return _container_name; } 3474 bool is_set() { return _is_set; } 3475 bool found_vm_options_file_arg() { return _vm_options_file_arg != NULL; } 3476 char* vm_options_file_arg() { return _vm_options_file_arg; } 3477 3478 void set_vm_options_file_arg(const char *vm_options_file_arg) { 3479 if (_vm_options_file_arg != NULL) { 3480 os::free(_vm_options_file_arg); 3481 } 3482 _vm_options_file_arg = os::strdup_check_oom(vm_options_file_arg); 3483 } 3484 3485 ~ScopedVMInitArgs() { 3486 if (_vm_options_file_arg != NULL) { 3487 os::free(_vm_options_file_arg); 3488 } 3489 if (_args.options == NULL) return; 3490 for (int i = 0; i < _args.nOptions; i++) { 3491 os::free(_args.options[i].optionString); 3492 } 3493 FREE_C_HEAP_ARRAY(JavaVMOption, _args.options); 3494 } 3495 3496 // Insert options into this option list, to replace option at 3497 // vm_options_file_pos (-XX:VMOptionsFile) 3498 jint insert(const JavaVMInitArgs* args, 3499 const JavaVMInitArgs* args_to_insert, 3500 const int vm_options_file_pos) { 3501 assert(_args.options == NULL, "shouldn't be set yet"); 3502 assert(args_to_insert->nOptions != 0, "there should be args to insert"); 3503 assert(vm_options_file_pos != -1, "vm_options_file_pos should be set"); 3504 3505 int length = args->nOptions + args_to_insert->nOptions - 1; 3506 GrowableArray<JavaVMOption> *options = new (ResourceObj::C_HEAP, mtArguments) 3507 GrowableArray<JavaVMOption>(length, true); // Construct new option array 3508 for (int i = 0; i < args->nOptions; i++) { 3509 if (i == vm_options_file_pos) { 3510 // insert the new options starting at the same place as the 3511 // -XX:VMOptionsFile option 3512 for (int j = 0; j < args_to_insert->nOptions; j++) { 3513 options->push(args_to_insert->options[j]); 3514 } 3515 } else { 3516 options->push(args->options[i]); 3517 } 3518 } 3519 // make into options array 3520 jint result = set_args(options); 3521 delete options; 3522 return result; 3523 } 3524 }; 3525 3526 jint Arguments::parse_java_options_environment_variable(ScopedVMInitArgs* args) { 3527 return parse_options_environment_variable("_JAVA_OPTIONS", args); 3528 } 3529 3530 jint Arguments::parse_java_tool_options_environment_variable(ScopedVMInitArgs* args) { 3531 return parse_options_environment_variable("JAVA_TOOL_OPTIONS", args); 3532 } 3533 3534 jint Arguments::parse_options_environment_variable(const char* name, 3535 ScopedVMInitArgs* vm_args) { 3536 char *buffer = ::getenv(name); 3537 3538 // Don't check this environment variable if user has special privileges 3539 // (e.g. unix su command). 3540 if (buffer == NULL || os::have_special_privileges()) { 3541 return JNI_OK; 3542 } 3543 3544 if ((buffer = os::strdup(buffer)) == NULL) { 3545 return JNI_ENOMEM; 3546 } 3547 3548 jio_fprintf(defaultStream::error_stream(), 3549 "Picked up %s: %s\n", name, buffer); 3550 3551 int retcode = parse_options_buffer(name, buffer, strlen(buffer), vm_args); 3552 3553 os::free(buffer); 3554 return retcode; 3555 } 3556 3557 jint Arguments::parse_vm_options_file(const char* file_name, ScopedVMInitArgs* vm_args) { 3558 // read file into buffer 3559 int fd = ::open(file_name, O_RDONLY); 3560 if (fd < 0) { 3561 jio_fprintf(defaultStream::error_stream(), 3562 "Could not open options file '%s'\n", 3563 file_name); 3564 return JNI_ERR; 3565 } 3566 3567 struct stat stbuf; 3568 int retcode = os::stat(file_name, &stbuf); 3569 if (retcode != 0) { 3570 jio_fprintf(defaultStream::error_stream(), 3571 "Could not stat options file '%s'\n", 3572 file_name); 3573 os::close(fd); 3574 return JNI_ERR; 3575 } 3576 3577 if (stbuf.st_size == 0) { 3578 // tell caller there is no option data and that is ok 3579 os::close(fd); 3580 return JNI_OK; 3581 } 3582 3583 // '+ 1' for NULL termination even with max bytes 3584 size_t bytes_alloc = stbuf.st_size + 1; 3585 3586 char *buf = NEW_C_HEAP_ARRAY_RETURN_NULL(char, bytes_alloc, mtArguments); 3587 if (NULL == buf) { 3588 jio_fprintf(defaultStream::error_stream(), 3589 "Could not allocate read buffer for options file parse\n"); 3590 os::close(fd); 3591 return JNI_ENOMEM; 3592 } 3593 3594 memset(buf, 0, bytes_alloc); 3595 3596 // Fill buffer 3597 // Use ::read() instead of os::read because os::read() 3598 // might do a thread state transition 3599 // and it is too early for that here 3600 3601 ssize_t bytes_read = ::read(fd, (void *)buf, (unsigned)bytes_alloc); 3602 os::close(fd); 3603 if (bytes_read < 0) { 3604 FREE_C_HEAP_ARRAY(char, buf); 3605 jio_fprintf(defaultStream::error_stream(), 3606 "Could not read options file '%s'\n", file_name); 3607 return JNI_ERR; 3608 } 3609 3610 if (bytes_read == 0) { 3611 // tell caller there is no option data and that is ok 3612 FREE_C_HEAP_ARRAY(char, buf); 3613 return JNI_OK; 3614 } 3615 3616 retcode = parse_options_buffer(file_name, buf, bytes_read, vm_args); 3617 3618 FREE_C_HEAP_ARRAY(char, buf); 3619 return retcode; 3620 } 3621 3622 jint Arguments::parse_options_buffer(const char* name, char* buffer, const size_t buf_len, ScopedVMInitArgs* vm_args) { 3623 GrowableArray<JavaVMOption> *options = new (ResourceObj::C_HEAP, mtArguments) GrowableArray<JavaVMOption>(2, true); // Construct option array 3624 3625 // some pointers to help with parsing 3626 char *buffer_end = buffer + buf_len; 3627 char *opt_hd = buffer; 3628 char *wrt = buffer; 3629 char *rd = buffer; 3630 3631 // parse all options 3632 while (rd < buffer_end) { 3633 // skip leading white space from the input string 3634 while (rd < buffer_end && isspace(*rd)) { 3635 rd++; 3636 } 3637 3638 if (rd >= buffer_end) { 3639 break; 3640 } 3641 3642 // Remember this is where we found the head of the token. 3643 opt_hd = wrt; 3644 3645 // Tokens are strings of non white space characters separated 3646 // by one or more white spaces. 3647 while (rd < buffer_end && !isspace(*rd)) { 3648 if (*rd == '\'' || *rd == '"') { // handle a quoted string 3649 int quote = *rd; // matching quote to look for 3650 rd++; // don't copy open quote 3651 while (rd < buffer_end && *rd != quote) { 3652 // include everything (even spaces) 3653 // up until the close quote 3654 *wrt++ = *rd++; // copy to option string 3655 } 3656 3657 if (rd < buffer_end) { 3658 rd++; // don't copy close quote 3659 } else { 3660 // did not see closing quote 3661 jio_fprintf(defaultStream::error_stream(), 3662 "Unmatched quote in %s\n", name); 3663 delete options; 3664 return JNI_ERR; 3665 } 3666 } else { 3667 *wrt++ = *rd++; // copy to option string 3668 } 3669 } 3670 3671 // steal a white space character and set it to NULL 3672 *wrt++ = '\0'; 3673 // We now have a complete token 3674 3675 JavaVMOption option; 3676 option.optionString = opt_hd; 3677 option.extraInfo = NULL; 3678 3679 options->append(option); // Fill in option 3680 3681 rd++; // Advance to next character 3682 } 3683 3684 // Fill out JavaVMInitArgs structure. 3685 jint status = vm_args->set_args(options); 3686 3687 delete options; 3688 return status; 3689 } 3690 3691 void Arguments::set_shared_spaces_flags() { 3692 if (DumpSharedSpaces) { 3693 if (FailOverToOldVerifier) { 3694 // Don't fall back to the old verifier on verification failure. If a 3695 // class fails verification with the split verifier, it might fail the 3696 // CDS runtime verifier constraint check. In that case, we don't want 3697 // to share the class. We only archive classes that pass the split verifier. 3698 FLAG_SET_DEFAULT(FailOverToOldVerifier, false); 3699 } 3700 3701 if (RequireSharedSpaces) { 3702 warning("Cannot dump shared archive while using shared archive"); 3703 } 3704 UseSharedSpaces = false; 3705 #ifdef _LP64 3706 if (!UseCompressedOops || !UseCompressedClassPointers) { 3707 vm_exit_during_initialization( 3708 "Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off.", NULL); 3709 } 3710 } else { 3711 if (!UseCompressedOops || !UseCompressedClassPointers) { 3712 no_shared_spaces("UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces."); 3713 } 3714 #endif 3715 } 3716 } 3717 3718 // Sharing support 3719 // Construct the path to the archive 3720 static char* get_shared_archive_path() { 3721 char *shared_archive_path; 3722 if (SharedArchiveFile == NULL) { 3723 char jvm_path[JVM_MAXPATHLEN]; 3724 os::jvm_path(jvm_path, sizeof(jvm_path)); 3725 char *end = strrchr(jvm_path, *os::file_separator()); 3726 if (end != NULL) *end = '\0'; 3727 size_t jvm_path_len = strlen(jvm_path); 3728 size_t file_sep_len = strlen(os::file_separator()); 3729 const size_t len = jvm_path_len + file_sep_len + 20; 3730 shared_archive_path = NEW_C_HEAP_ARRAY(char, len, mtArguments); 3731 if (shared_archive_path != NULL) { 3732 jio_snprintf(shared_archive_path, len, "%s%sclasses.jsa", 3733 jvm_path, os::file_separator()); 3734 } 3735 } else { 3736 shared_archive_path = os::strdup_check_oom(SharedArchiveFile, mtArguments); 3737 } 3738 return shared_archive_path; 3739 } 3740 3741 #ifndef PRODUCT 3742 // Determine whether LogVMOutput should be implicitly turned on. 3743 static bool use_vm_log() { 3744 if (LogCompilation || !FLAG_IS_DEFAULT(LogFile) || 3745 PrintCompilation || PrintInlining || PrintDependencies || PrintNativeNMethods || 3746 PrintDebugInfo || PrintRelocations || PrintNMethods || PrintExceptionHandlers || 3747 PrintAssembly || TraceDeoptimization || TraceDependencies || 3748 (VerifyDependencies && FLAG_IS_CMDLINE(VerifyDependencies))) { 3749 return true; 3750 } 3751 3752 #ifdef COMPILER1 3753 if (PrintC1Statistics) { 3754 return true; 3755 } 3756 #endif // COMPILER1 3757 3758 #ifdef COMPILER2 3759 if (PrintOptoAssembly || PrintOptoStatistics) { 3760 return true; 3761 } 3762 #endif // COMPILER2 3763 3764 return false; 3765 } 3766 3767 #endif // PRODUCT 3768 3769 bool Arguments::args_contains_vm_options_file_arg(const JavaVMInitArgs* args) { 3770 for (int index = 0; index < args->nOptions; index++) { 3771 const JavaVMOption* option = args->options + index; 3772 const char* tail; 3773 if (match_option(option, "-XX:VMOptionsFile=", &tail)) { 3774 return true; 3775 } 3776 } 3777 return false; 3778 } 3779 3780 jint Arguments::insert_vm_options_file(const JavaVMInitArgs* args, 3781 const char* vm_options_file, 3782 const int vm_options_file_pos, 3783 ScopedVMInitArgs* vm_options_file_args, 3784 ScopedVMInitArgs* args_out) { 3785 jint code = parse_vm_options_file(vm_options_file, vm_options_file_args); 3786 if (code != JNI_OK) { 3787 return code; 3788 } 3789 3790 if (vm_options_file_args->get()->nOptions < 1) { 3791 return JNI_OK; 3792 } 3793 3794 if (args_contains_vm_options_file_arg(vm_options_file_args->get())) { 3795 jio_fprintf(defaultStream::error_stream(), 3796 "A VM options file may not refer to a VM options file. " 3797 "Specification of '-XX:VMOptionsFile=<file-name>' in the " 3798 "options file '%s' in options container '%s' is an error.\n", 3799 vm_options_file_args->vm_options_file_arg(), 3800 vm_options_file_args->container_name()); 3801 return JNI_EINVAL; 3802 } 3803 3804 return args_out->insert(args, vm_options_file_args->get(), 3805 vm_options_file_pos); 3806 } 3807 3808 // Expand -XX:VMOptionsFile found in args_in as needed. 3809 // mod_args and args_out parameters may return values as needed. 3810 jint Arguments::expand_vm_options_as_needed(const JavaVMInitArgs* args_in, 3811 ScopedVMInitArgs* mod_args, 3812 JavaVMInitArgs** args_out) { 3813 jint code = match_special_option_and_act(args_in, mod_args); 3814 if (code != JNI_OK) { 3815 return code; 3816 } 3817 3818 if (mod_args->is_set()) { 3819 // args_in contains -XX:VMOptionsFile and mod_args contains the 3820 // original options from args_in along with the options expanded 3821 // from the VMOptionsFile. Return a short-hand to the caller. 3822 *args_out = mod_args->get(); 3823 } else { 3824 *args_out = (JavaVMInitArgs *)args_in; // no changes so use args_in 3825 } 3826 return JNI_OK; 3827 } 3828 3829 jint Arguments::match_special_option_and_act(const JavaVMInitArgs* args, 3830 ScopedVMInitArgs* args_out) { 3831 // Remaining part of option string 3832 const char* tail; 3833 ScopedVMInitArgs vm_options_file_args(args_out->container_name()); 3834 3835 for (int index = 0; index < args->nOptions; index++) { 3836 const JavaVMOption* option = args->options + index; 3837 if (ArgumentsExt::process_options(option)) { 3838 continue; 3839 } 3840 if (match_option(option, "-XX:Flags=", &tail)) { 3841 Arguments::set_jvm_flags_file(tail); 3842 continue; 3843 } 3844 if (match_option(option, "-XX:VMOptionsFile=", &tail)) { 3845 if (vm_options_file_args.found_vm_options_file_arg()) { 3846 jio_fprintf(defaultStream::error_stream(), 3847 "The option '%s' is already specified in the options " 3848 "container '%s' so the specification of '%s' in the " 3849 "same options container is an error.\n", 3850 vm_options_file_args.vm_options_file_arg(), 3851 vm_options_file_args.container_name(), 3852 option->optionString); 3853 return JNI_EINVAL; 3854 } 3855 vm_options_file_args.set_vm_options_file_arg(option->optionString); 3856 // If there's a VMOptionsFile, parse that 3857 jint code = insert_vm_options_file(args, tail, index, 3858 &vm_options_file_args, args_out); 3859 if (code != JNI_OK) { 3860 return code; 3861 } 3862 args_out->set_vm_options_file_arg(vm_options_file_args.vm_options_file_arg()); 3863 if (args_out->is_set()) { 3864 // The VMOptions file inserted some options so switch 'args' 3865 // to the new set of options, and continue processing which 3866 // preserves "last option wins" semantics. 3867 args = args_out->get(); 3868 // The first option from the VMOptionsFile replaces the 3869 // current option. So we back track to process the 3870 // replacement option. 3871 index--; 3872 } 3873 continue; 3874 } 3875 if (match_option(option, "-XX:+PrintVMOptions")) { 3876 PrintVMOptions = true; 3877 continue; 3878 } 3879 if (match_option(option, "-XX:-PrintVMOptions")) { 3880 PrintVMOptions = false; 3881 continue; 3882 } 3883 if (match_option(option, "-XX:+IgnoreUnrecognizedVMOptions")) { 3884 IgnoreUnrecognizedVMOptions = true; 3885 continue; 3886 } 3887 if (match_option(option, "-XX:-IgnoreUnrecognizedVMOptions")) { 3888 IgnoreUnrecognizedVMOptions = false; 3889 continue; 3890 } 3891 if (match_option(option, "-XX:+PrintFlagsInitial")) { 3892 CommandLineFlags::printFlags(tty, false); 3893 vm_exit(0); 3894 } 3895 if (match_option(option, "-XX:NativeMemoryTracking", &tail)) { 3896 #if INCLUDE_NMT 3897 // The launcher did not setup nmt environment variable properly. 3898 if (!MemTracker::check_launcher_nmt_support(tail)) { 3899 warning("Native Memory Tracking did not setup properly, using wrong launcher?"); 3900 } 3901 3902 // Verify if nmt option is valid. 3903 if (MemTracker::verify_nmt_option()) { 3904 // Late initialization, still in single-threaded mode. 3905 if (MemTracker::tracking_level() >= NMT_summary) { 3906 MemTracker::init(); 3907 } 3908 } else { 3909 vm_exit_during_initialization("Syntax error, expecting -XX:NativeMemoryTracking=[off|summary|detail]", NULL); 3910 } 3911 continue; 3912 #else 3913 jio_fprintf(defaultStream::error_stream(), 3914 "Native Memory Tracking is not supported in this VM\n"); 3915 return JNI_ERR; 3916 #endif 3917 } 3918 3919 #ifndef PRODUCT 3920 if (match_option(option, "-XX:+PrintFlagsWithComments")) { 3921 CommandLineFlags::printFlags(tty, true); 3922 vm_exit(0); 3923 } 3924 #endif 3925 3926 if (match_option(option, "-XX:+UseAppCDS")) { 3927 Flag* flag = Flag::find_flag("SharedArchiveFile", 17, true, true); 3928 if (flag->is_diagnostic()) { 3929 flag->clear_diagnostic(); 3930 } 3931 continue; 3932 } 3933 } 3934 return JNI_OK; 3935 } 3936 3937 static void print_options(const JavaVMInitArgs *args) { 3938 const char* tail; 3939 for (int index = 0; index < args->nOptions; index++) { 3940 const JavaVMOption *option = args->options + index; 3941 if (match_option(option, "-XX:", &tail)) { 3942 logOption(tail); 3943 } 3944 } 3945 } 3946 3947 bool Arguments::handle_deprecated_print_gc_flags() { 3948 if (PrintGC) { 3949 log_warning(gc)("-XX:+PrintGC is deprecated. Will use -Xlog:gc instead."); 3950 } 3951 if (PrintGCDetails) { 3952 log_warning(gc)("-XX:+PrintGCDetails is deprecated. Will use -Xlog:gc* instead."); 3953 } 3954 3955 if (_gc_log_filename != NULL) { 3956 // -Xloggc was used to specify a filename 3957 const char* gc_conf = PrintGCDetails ? "gc*" : "gc"; 3958 3959 LogTarget(Error, logging) target; 3960 LogStream errstream(target); 3961 return LogConfiguration::parse_log_arguments(_gc_log_filename, gc_conf, NULL, NULL, &errstream); 3962 } else if (PrintGC || PrintGCDetails) { 3963 LogConfiguration::configure_stdout(LogLevel::Info, !PrintGCDetails, LOG_TAGS(gc)); 3964 } 3965 return true; 3966 } 3967 3968 void Arguments::handle_extra_cms_flags(const char* msg) { 3969 SpecialFlag flag; 3970 const char *flag_name = "UseConcMarkSweepGC"; 3971 if (lookup_special_flag(flag_name, flag)) { 3972 handle_aliases_and_deprecation(flag_name, /* print warning */ true); 3973 warning("%s", msg); 3974 } 3975 } 3976 3977 // Parse entry point called from JNI_CreateJavaVM 3978 3979 jint Arguments::parse(const JavaVMInitArgs* initial_cmd_args) { 3980 assert(verify_special_jvm_flags(), "deprecated and obsolete flag table inconsistent"); 3981 3982 // Initialize ranges, constraints and writeables 3983 CommandLineFlagRangeList::init(); 3984 CommandLineFlagConstraintList::init(); 3985 CommandLineFlagWriteableList::init(); 3986 3987 // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed. 3988 const char* hotspotrc = ".hotspotrc"; 3989 bool settings_file_specified = false; 3990 bool needs_hotspotrc_warning = false; 3991 ScopedVMInitArgs initial_java_tool_options_args("env_var='JAVA_TOOL_OPTIONS'"); 3992 ScopedVMInitArgs initial_java_options_args("env_var='_JAVA_OPTIONS'"); 3993 3994 // Pointers to current working set of containers 3995 JavaVMInitArgs* cur_cmd_args; 3996 JavaVMInitArgs* cur_java_options_args; 3997 JavaVMInitArgs* cur_java_tool_options_args; 3998 3999 // Containers for modified/expanded options 4000 ScopedVMInitArgs mod_cmd_args("cmd_line_args"); 4001 ScopedVMInitArgs mod_java_tool_options_args("env_var='JAVA_TOOL_OPTIONS'"); 4002 ScopedVMInitArgs mod_java_options_args("env_var='_JAVA_OPTIONS'"); 4003 4004 4005 jint code = 4006 parse_java_tool_options_environment_variable(&initial_java_tool_options_args); 4007 if (code != JNI_OK) { 4008 return code; 4009 } 4010 4011 code = parse_java_options_environment_variable(&initial_java_options_args); 4012 if (code != JNI_OK) { 4013 return code; 4014 } 4015 4016 code = expand_vm_options_as_needed(initial_java_tool_options_args.get(), 4017 &mod_java_tool_options_args, 4018 &cur_java_tool_options_args); 4019 if (code != JNI_OK) { 4020 return code; 4021 } 4022 4023 code = expand_vm_options_as_needed(initial_cmd_args, 4024 &mod_cmd_args, 4025 &cur_cmd_args); 4026 if (code != JNI_OK) { 4027 return code; 4028 } 4029 4030 code = expand_vm_options_as_needed(initial_java_options_args.get(), 4031 &mod_java_options_args, 4032 &cur_java_options_args); 4033 if (code != JNI_OK) { 4034 return code; 4035 } 4036 4037 const char* flags_file = Arguments::get_jvm_flags_file(); 4038 settings_file_specified = (flags_file != NULL); 4039 4040 if (IgnoreUnrecognizedVMOptions) { 4041 cur_cmd_args->ignoreUnrecognized = true; 4042 cur_java_tool_options_args->ignoreUnrecognized = true; 4043 cur_java_options_args->ignoreUnrecognized = true; 4044 } 4045 4046 // Parse specified settings file 4047 if (settings_file_specified) { 4048 if (!process_settings_file(flags_file, true, 4049 cur_cmd_args->ignoreUnrecognized)) { 4050 return JNI_EINVAL; 4051 } 4052 } else { 4053 #ifdef ASSERT 4054 // Parse default .hotspotrc settings file 4055 if (!process_settings_file(".hotspotrc", false, 4056 cur_cmd_args->ignoreUnrecognized)) { 4057 return JNI_EINVAL; 4058 } 4059 #else 4060 struct stat buf; 4061 if (os::stat(hotspotrc, &buf) == 0) { 4062 needs_hotspotrc_warning = true; 4063 } 4064 #endif 4065 } 4066 4067 if (PrintVMOptions) { 4068 print_options(cur_java_tool_options_args); 4069 print_options(cur_cmd_args); 4070 print_options(cur_java_options_args); 4071 } 4072 4073 // Parse JavaVMInitArgs structure passed in, as well as JAVA_TOOL_OPTIONS and _JAVA_OPTIONS 4074 jint result = parse_vm_init_args(cur_java_tool_options_args, 4075 cur_java_options_args, 4076 cur_cmd_args); 4077 4078 if (result != JNI_OK) { 4079 return result; 4080 } 4081 4082 // Call get_shared_archive_path() here, after possible SharedArchiveFile option got parsed. 4083 SharedArchivePath = get_shared_archive_path(); 4084 if (SharedArchivePath == NULL) { 4085 return JNI_ENOMEM; 4086 } 4087 4088 // Set up VerifySharedSpaces 4089 if (FLAG_IS_DEFAULT(VerifySharedSpaces) && SharedArchiveFile != NULL) { 4090 VerifySharedSpaces = true; 4091 } 4092 4093 // Delay warning until here so that we've had a chance to process 4094 // the -XX:-PrintWarnings flag 4095 if (needs_hotspotrc_warning) { 4096 warning("%s file is present but has been ignored. " 4097 "Run with -XX:Flags=%s to load the file.", 4098 hotspotrc, hotspotrc); 4099 } 4100 4101 if (needs_module_property_warning) { 4102 warning("Ignoring system property options whose names match the '-Djdk.module.*'." 4103 " names that are reserved for internal use."); 4104 } 4105 4106 #if defined(_ALLBSD_SOURCE) || defined(AIX) // UseLargePages is not yet supported on BSD and AIX. 4107 UNSUPPORTED_OPTION(UseLargePages); 4108 #endif 4109 4110 ArgumentsExt::report_unsupported_options(); 4111 4112 #ifndef PRODUCT 4113 if (TraceBytecodesAt != 0) { 4114 TraceBytecodes = true; 4115 } 4116 if (CountCompiledCalls) { 4117 if (UseCounterDecay) { 4118 warning("UseCounterDecay disabled because CountCalls is set"); 4119 UseCounterDecay = false; 4120 } 4121 } 4122 #endif // PRODUCT 4123 4124 if (ScavengeRootsInCode == 0) { 4125 if (!FLAG_IS_DEFAULT(ScavengeRootsInCode)) { 4126 warning("Forcing ScavengeRootsInCode non-zero"); 4127 } 4128 ScavengeRootsInCode = 1; 4129 } 4130 4131 if (!handle_deprecated_print_gc_flags()) { 4132 return JNI_EINVAL; 4133 } 4134 4135 // Set object alignment values. 4136 set_object_alignment(); 4137 4138 #if !INCLUDE_CDS 4139 if (DumpSharedSpaces || RequireSharedSpaces) { 4140 jio_fprintf(defaultStream::error_stream(), 4141 "Shared spaces are not supported in this VM\n"); 4142 return JNI_ERR; 4143 } 4144 if ((UseSharedSpaces && FLAG_IS_CMDLINE(UseSharedSpaces)) || 4145 log_is_enabled(Info, cds)) { 4146 warning("Shared spaces are not supported in this VM"); 4147 FLAG_SET_DEFAULT(UseSharedSpaces, false); 4148 LogConfiguration::configure_stdout(LogLevel::Off, true, LOG_TAGS(cds)); 4149 } 4150 no_shared_spaces("CDS Disabled"); 4151 #endif // INCLUDE_CDS 4152 4153 return JNI_OK; 4154 } 4155 4156 jint Arguments::apply_ergo() { 4157 // Set flags based on ergonomics. 4158 jint result = set_ergonomics_flags(); 4159 if (result != JNI_OK) return result; 4160 4161 #if INCLUDE_JVMCI 4162 set_jvmci_specific_flags(); 4163 #endif 4164 4165 set_shared_spaces_flags(); 4166 4167 if (TieredCompilation) { 4168 set_tiered_flags(); 4169 } else { 4170 int max_compilation_policy_choice = 1; 4171 #ifdef COMPILER2 4172 if (is_server_compilation_mode_vm()) { 4173 max_compilation_policy_choice = 2; 4174 } 4175 #endif 4176 // Check if the policy is valid. 4177 if (CompilationPolicyChoice >= max_compilation_policy_choice) { 4178 vm_exit_during_initialization( 4179 "Incompatible compilation policy selected", NULL); 4180 } 4181 // Scale CompileThreshold 4182 // CompileThresholdScaling == 0.0 is equivalent to -Xint and leaves CompileThreshold unchanged. 4183 if (!FLAG_IS_DEFAULT(CompileThresholdScaling) && CompileThresholdScaling > 0.0) { 4184 FLAG_SET_ERGO(intx, CompileThreshold, scaled_compile_threshold(CompileThreshold)); 4185 } 4186 } 4187 4188 #ifdef COMPILER2 4189 #ifndef PRODUCT 4190 if (PrintIdealGraphLevel > 0) { 4191 FLAG_SET_ERGO(bool, PrintIdealGraph, true); 4192 } 4193 #endif 4194 #endif 4195 4196 // Set heap size based on available physical memory 4197 set_heap_size(); 4198 4199 GCConfig::arguments()->initialize(); 4200 4201 // Initialize Metaspace flags and alignments 4202 Metaspace::ergo_initialize(); 4203 4204 // Set bytecode rewriting flags 4205 set_bytecode_flags(); 4206 4207 // Set flags if Aggressive optimization flags (-XX:+AggressiveOpts) enabled 4208 jint code = set_aggressive_opts_flags(); 4209 if (code != JNI_OK) { 4210 return code; 4211 } 4212 4213 // Turn off biased locking for locking debug mode flags, 4214 // which are subtly different from each other but neither works with 4215 // biased locking 4216 if (UseHeavyMonitors 4217 #ifdef COMPILER1 4218 || !UseFastLocking 4219 #endif // COMPILER1 4220 #if INCLUDE_JVMCI 4221 || !JVMCIUseFastLocking 4222 #endif 4223 ) { 4224 if (!FLAG_IS_DEFAULT(UseBiasedLocking) && UseBiasedLocking) { 4225 // flag set to true on command line; warn the user that they 4226 // can't enable biased locking here 4227 warning("Biased Locking is not supported with locking debug flags" 4228 "; ignoring UseBiasedLocking flag." ); 4229 } 4230 UseBiasedLocking = false; 4231 } 4232 4233 #ifdef CC_INTERP 4234 // Clear flags not supported on zero. 4235 FLAG_SET_DEFAULT(ProfileInterpreter, false); 4236 FLAG_SET_DEFAULT(UseBiasedLocking, false); 4237 LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedOops, false)); 4238 LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedClassPointers, false)); 4239 #endif // CC_INTERP 4240 4241 #ifdef COMPILER2 4242 if (!EliminateLocks) { 4243 EliminateNestedLocks = false; 4244 } 4245 if (!Inline) { 4246 IncrementalInline = false; 4247 } 4248 #ifndef PRODUCT 4249 if (!IncrementalInline) { 4250 AlwaysIncrementalInline = false; 4251 } 4252 #endif 4253 if (!UseTypeSpeculation && FLAG_IS_DEFAULT(TypeProfileLevel)) { 4254 // nothing to use the profiling, turn if off 4255 FLAG_SET_DEFAULT(TypeProfileLevel, 0); 4256 } 4257 if (FLAG_IS_DEFAULT(LoopStripMiningIterShortLoop)) { 4258 // blind guess 4259 LoopStripMiningIterShortLoop = LoopStripMiningIter / 10; 4260 } 4261 #endif 4262 4263 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) { 4264 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output"); 4265 DebugNonSafepoints = true; 4266 } 4267 4268 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) { 4269 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used"); 4270 } 4271 4272 if (UseOnStackReplacement && !UseLoopCounter) { 4273 warning("On-stack-replacement requires loop counters; enabling loop counters"); 4274 FLAG_SET_DEFAULT(UseLoopCounter, true); 4275 } 4276 4277 #ifndef PRODUCT 4278 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) { 4279 if (use_vm_log()) { 4280 LogVMOutput = true; 4281 } 4282 } 4283 #endif // PRODUCT 4284 4285 if (PrintCommandLineFlags) { 4286 CommandLineFlags::printSetFlags(tty); 4287 } 4288 4289 // Apply CPU specific policy for the BiasedLocking 4290 if (UseBiasedLocking) { 4291 if (!VM_Version::use_biased_locking() && 4292 !(FLAG_IS_CMDLINE(UseBiasedLocking))) { 4293 UseBiasedLocking = false; 4294 } 4295 } 4296 #ifdef COMPILER2 4297 if (!UseBiasedLocking || EmitSync != 0) { 4298 UseOptoBiasInlining = false; 4299 } 4300 #endif 4301 4302 // ThreadLocalHandshakesConstraintFunc handles the constraints. 4303 if (FLAG_IS_DEFAULT(ThreadLocalHandshakes) || !SafepointMechanism::supports_thread_local_poll()) { 4304 log_debug(ergo)("ThreadLocalHandshakes %s", ThreadLocalHandshakes ? "enabled." : "disabled."); 4305 } else { 4306 log_info(ergo)("ThreadLocalHandshakes %s", ThreadLocalHandshakes ? "enabled." : "disabled."); 4307 } 4308 4309 return JNI_OK; 4310 } 4311 4312 jint Arguments::adjust_after_os() { 4313 if (UseNUMA) { 4314 if (!FLAG_IS_DEFAULT(AllocateHeapAt)) { 4315 FLAG_SET_ERGO(bool, UseNUMA, false); 4316 } else if (UseParallelGC || UseParallelOldGC) { 4317 if (FLAG_IS_DEFAULT(MinHeapDeltaBytes)) { 4318 FLAG_SET_DEFAULT(MinHeapDeltaBytes, 64*M); 4319 } 4320 } 4321 // UseNUMAInterleaving is set to ON for all collectors and 4322 // platforms when UseNUMA is set to ON. NUMA-aware collectors 4323 // such as the parallel collector for Linux and Solaris will 4324 // interleave old gen and survivor spaces on top of NUMA 4325 // allocation policy for the eden space. 4326 // Non NUMA-aware collectors such as CMS, G1 and Serial-GC on 4327 // all platforms and ParallelGC on Windows will interleave all 4328 // of the heap spaces across NUMA nodes. 4329 if (FLAG_IS_DEFAULT(UseNUMAInterleaving)) { 4330 FLAG_SET_ERGO(bool, UseNUMAInterleaving, true); 4331 } 4332 } 4333 return JNI_OK; 4334 } 4335 4336 int Arguments::PropertyList_count(SystemProperty* pl) { 4337 int count = 0; 4338 while(pl != NULL) { 4339 count++; 4340 pl = pl->next(); 4341 } 4342 return count; 4343 } 4344 4345 // Return the number of readable properties. 4346 int Arguments::PropertyList_readable_count(SystemProperty* pl) { 4347 int count = 0; 4348 while(pl != NULL) { 4349 if (pl->is_readable()) { 4350 count++; 4351 } 4352 pl = pl->next(); 4353 } 4354 return count; 4355 } 4356 4357 const char* Arguments::PropertyList_get_value(SystemProperty *pl, const char* key) { 4358 assert(key != NULL, "just checking"); 4359 SystemProperty* prop; 4360 for (prop = pl; prop != NULL; prop = prop->next()) { 4361 if (strcmp(key, prop->key()) == 0) return prop->value(); 4362 } 4363 return NULL; 4364 } 4365 4366 // Return the value of the requested property provided that it is a readable property. 4367 const char* Arguments::PropertyList_get_readable_value(SystemProperty *pl, const char* key) { 4368 assert(key != NULL, "just checking"); 4369 SystemProperty* prop; 4370 // Return the property value if the keys match and the property is not internal or 4371 // it's the special internal property "jdk.boot.class.path.append". 4372 for (prop = pl; prop != NULL; prop = prop->next()) { 4373 if (strcmp(key, prop->key()) == 0) { 4374 if (!prop->internal()) { 4375 return prop->value(); 4376 } else if (strcmp(key, "jdk.boot.class.path.append") == 0) { 4377 return prop->value(); 4378 } else { 4379 // Property is internal and not jdk.boot.class.path.append so return NULL. 4380 return NULL; 4381 } 4382 } 4383 } 4384 return NULL; 4385 } 4386 4387 const char* Arguments::PropertyList_get_key_at(SystemProperty *pl, int index) { 4388 int count = 0; 4389 const char* ret_val = NULL; 4390 4391 while(pl != NULL) { 4392 if(count >= index) { 4393 ret_val = pl->key(); 4394 break; 4395 } 4396 count++; 4397 pl = pl->next(); 4398 } 4399 4400 return ret_val; 4401 } 4402 4403 char* Arguments::PropertyList_get_value_at(SystemProperty* pl, int index) { 4404 int count = 0; 4405 char* ret_val = NULL; 4406 4407 while(pl != NULL) { 4408 if(count >= index) { 4409 ret_val = pl->value(); 4410 break; 4411 } 4412 count++; 4413 pl = pl->next(); 4414 } 4415 4416 return ret_val; 4417 } 4418 4419 void Arguments::PropertyList_add(SystemProperty** plist, SystemProperty *new_p) { 4420 SystemProperty* p = *plist; 4421 if (p == NULL) { 4422 *plist = new_p; 4423 } else { 4424 while (p->next() != NULL) { 4425 p = p->next(); 4426 } 4427 p->set_next(new_p); 4428 } 4429 } 4430 4431 void Arguments::PropertyList_add(SystemProperty** plist, const char* k, const char* v, 4432 bool writeable, bool internal) { 4433 if (plist == NULL) 4434 return; 4435 4436 SystemProperty* new_p = new SystemProperty(k, v, writeable, internal); 4437 PropertyList_add(plist, new_p); 4438 } 4439 4440 void Arguments::PropertyList_add(SystemProperty *element) { 4441 PropertyList_add(&_system_properties, element); 4442 } 4443 4444 // This add maintains unique property key in the list. 4445 void Arguments::PropertyList_unique_add(SystemProperty** plist, const char* k, const char* v, 4446 PropertyAppendable append, PropertyWriteable writeable, 4447 PropertyInternal internal) { 4448 if (plist == NULL) 4449 return; 4450 4451 // If property key exist then update with new value. 4452 SystemProperty* prop; 4453 for (prop = *plist; prop != NULL; prop = prop->next()) { 4454 if (strcmp(k, prop->key()) == 0) { 4455 if (append == AppendProperty) { 4456 prop->append_value(v); 4457 } else { 4458 prop->set_value(v); 4459 } 4460 return; 4461 } 4462 } 4463 4464 PropertyList_add(plist, k, v, writeable == WriteableProperty, internal == InternalProperty); 4465 } 4466 4467 // Copies src into buf, replacing "%%" with "%" and "%p" with pid 4468 // Returns true if all of the source pointed by src has been copied over to 4469 // the destination buffer pointed by buf. Otherwise, returns false. 4470 // Notes: 4471 // 1. If the length (buflen) of the destination buffer excluding the 4472 // NULL terminator character is not long enough for holding the expanded 4473 // pid characters, it also returns false instead of returning the partially 4474 // expanded one. 4475 // 2. The passed in "buflen" should be large enough to hold the null terminator. 4476 bool Arguments::copy_expand_pid(const char* src, size_t srclen, 4477 char* buf, size_t buflen) { 4478 const char* p = src; 4479 char* b = buf; 4480 const char* src_end = &src[srclen]; 4481 char* buf_end = &buf[buflen - 1]; 4482 4483 while (p < src_end && b < buf_end) { 4484 if (*p == '%') { 4485 switch (*(++p)) { 4486 case '%': // "%%" ==> "%" 4487 *b++ = *p++; 4488 break; 4489 case 'p': { // "%p" ==> current process id 4490 // buf_end points to the character before the last character so 4491 // that we could write '\0' to the end of the buffer. 4492 size_t buf_sz = buf_end - b + 1; 4493 int ret = jio_snprintf(b, buf_sz, "%d", os::current_process_id()); 4494 4495 // if jio_snprintf fails or the buffer is not long enough to hold 4496 // the expanded pid, returns false. 4497 if (ret < 0 || ret >= (int)buf_sz) { 4498 return false; 4499 } else { 4500 b += ret; 4501 assert(*b == '\0', "fail in copy_expand_pid"); 4502 if (p == src_end && b == buf_end + 1) { 4503 // reach the end of the buffer. 4504 return true; 4505 } 4506 } 4507 p++; 4508 break; 4509 } 4510 default : 4511 *b++ = '%'; 4512 } 4513 } else { 4514 *b++ = *p++; 4515 } 4516 } 4517 *b = '\0'; 4518 return (p == src_end); // return false if not all of the source was copied 4519 }