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