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