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