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