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