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