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