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