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