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