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