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