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