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