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