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