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