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