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