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