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