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