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