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