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