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