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