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