arguments.cpp revision 8746:7f39700be72a
1169689Skan/* 2169689Skan * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. 3169689Skan * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4169689Skan * 5169689Skan * This code is free software; you can redistribute it and/or modify it 6169689Skan * under the terms of the GNU General Public License version 2 only, as 7169689Skan * published by the Free Software Foundation. 8169689Skan * 9169689Skan * This code is distributed in the hope that it will be useful, but WITHOUT 10169689Skan * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11169689Skan * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12169689Skan * version 2 for more details (a copy is included in the LICENSE file that 13169689Skan * accompanied this code). 14169689Skan * 15169689Skan * You should have received a copy of the GNU General Public License version 16169689Skan * 2 along with this work; if not, write to the Free Software Foundation, 17169689Skan * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18169689Skan * 19169689Skan * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20169689Skan * or visit www.oracle.com if you need additional information or have any 21169689Skan * questions. 22169689Skan * 23169689Skan */ 24169689Skan 25169689Skan#include "precompiled.hpp" 26169689Skan#include "classfile/classLoader.hpp" 27169689Skan#include "classfile/javaAssertions.hpp" 28169689Skan#include "classfile/stringTable.hpp" 29169689Skan#include "classfile/symbolTable.hpp" 30169689Skan#include "code/codeCacheExtensions.hpp" 31169689Skan#include "compiler/compilerOracle.hpp" 32169689Skan#include "gc/shared/cardTableRS.hpp" 33169689Skan#include "gc/shared/genCollectedHeap.hpp" 34169689Skan#include "gc/shared/referenceProcessor.hpp" 35169689Skan#include "gc/shared/taskqueue.hpp" 36169689Skan#include "memory/allocation.inline.hpp" 37169689Skan#include "memory/universe.inline.hpp" 38169689Skan#include "oops/oop.inline.hpp" 39169689Skan#include "prims/jvmtiExport.hpp" 40169689Skan#include "runtime/arguments.hpp" 41169689Skan#include "runtime/arguments_ext.hpp" 42169689Skan#include "runtime/commandLineFlagConstraintList.hpp" 43169689Skan#include "runtime/commandLineFlagRangeList.hpp" 44169689Skan#include "runtime/globals.hpp" 45169689Skan#include "runtime/globals_extension.hpp" 46169689Skan#include "runtime/java.hpp" 47169689Skan#include "runtime/os.hpp" 48169689Skan#include "runtime/vm_version.hpp" 49169689Skan#include "services/management.hpp" 50169689Skan#include "services/memTracker.hpp" 51169689Skan#include "utilities/defaultStream.hpp" 52169689Skan#include "utilities/macros.hpp" 53169689Skan#include "utilities/stringUtils.hpp" 54169689Skan#if INCLUDE_ALL_GCS 55169689Skan#include "gc/cms/compactibleFreeListSpace.hpp" 56169689Skan#include "gc/g1/g1CollectedHeap.inline.hpp" 57169689Skan#include "gc/parallel/parallelScavengeHeap.hpp" 58169689Skan#endif // INCLUDE_ALL_GCS 59169689Skan 60169689Skan// Note: This is a special bug reporting site for the JVM 61169689Skan#define DEFAULT_VENDOR_URL_BUG "http://bugreport.java.com/bugreport/crash.jsp" 62169689Skan#define DEFAULT_JAVA_LAUNCHER "generic" 63169689Skan 64169689Skan#define UNSUPPORTED_GC_OPTION(gc) \ 65169689Skando { \ 66169689Skan if (gc) { \ 67169689Skan if (FLAG_IS_CMDLINE(gc)) { \ 68169689Skan warning(#gc " is not supported in this VM. Using Serial GC."); \ 69169689Skan } \ 70169689Skan FLAG_SET_DEFAULT(gc, false); \ 71169689Skan } \ 72169689Skan} while(0) 73169689Skan 74169689Skanchar** Arguments::_jvm_flags_array = NULL; 75169689Skanint Arguments::_num_jvm_flags = 0; 76169689Skanchar** Arguments::_jvm_args_array = NULL; 77169689Skanint Arguments::_num_jvm_args = 0; 78169689Skanchar* Arguments::_java_command = NULL; 79169689SkanSystemProperty* Arguments::_system_properties = NULL; 80169689Skanconst char* Arguments::_gc_log_filename = NULL; 81169689Skanbool Arguments::_has_profile = false; 82169689Skansize_t Arguments::_conservative_max_heap_alignment = 0; 83169689Skansize_t Arguments::_min_heap_size = 0; 84169689Skanuintx Arguments::_min_heap_free_ratio = 0; 85169689Skanuintx Arguments::_max_heap_free_ratio = 0; 86169689SkanArguments::Mode Arguments::_mode = _mixed; 87169689Skanbool Arguments::_java_compiler = false; 88169689Skanbool Arguments::_xdebug_mode = false; 89169689Skanconst char* Arguments::_java_vendor_url_bug = DEFAULT_VENDOR_URL_BUG; 90169689Skanconst char* Arguments::_sun_java_launcher = DEFAULT_JAVA_LAUNCHER; 91169689Skanint Arguments::_sun_java_launcher_pid = -1; 92169689Skanbool Arguments::_sun_java_launcher_is_altjvm = false; 93169689Skan 94169689Skan// These parameters are reset in method parse_vm_init_args() 95169689Skanbool Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods; 96169689Skanbool Arguments::_UseOnStackReplacement = UseOnStackReplacement; 97169689Skanbool Arguments::_BackgroundCompilation = BackgroundCompilation; 98169689Skanbool Arguments::_ClipInlining = ClipInlining; 99169689Skanintx Arguments::_Tier3InvokeNotifyFreqLog = Tier3InvokeNotifyFreqLog; 100169689Skanintx Arguments::_Tier4InvocationThreshold = Tier4InvocationThreshold; 101169689Skan 102169689Skanchar* Arguments::SharedArchivePath = NULL; 103169689Skan 104169689SkanAgentLibraryList Arguments::_libraryList; 105169689SkanAgentLibraryList Arguments::_agentList; 106169689Skan 107169689Skanabort_hook_t Arguments::_abort_hook = NULL; 108169689Skanexit_hook_t Arguments::_exit_hook = NULL; 109169689Skanvfprintf_hook_t Arguments::_vfprintf_hook = NULL; 110169689Skan 111169689Skan 112169689SkanSystemProperty *Arguments::_sun_boot_library_path = NULL; 113169689SkanSystemProperty *Arguments::_java_library_path = NULL; 114169689SkanSystemProperty *Arguments::_java_home = NULL; 115169689SkanSystemProperty *Arguments::_java_class_path = NULL; 116169689SkanSystemProperty *Arguments::_sun_boot_class_path = NULL; 117169689Skan 118169689Skanchar* Arguments::_ext_dirs = NULL; 119169689Skan 120169689Skan// Check if head of 'option' matches 'name', and sets 'tail' to the remaining 121169689Skan// part of the option string. 122169689Skanstatic bool match_option(const JavaVMOption *option, const char* name, 123169689Skan const char** tail) { 124169689Skan int len = (int)strlen(name); 125169689Skan if (strncmp(option->optionString, name, len) == 0) { 126169689Skan *tail = option->optionString + len; 127169689Skan return true; 128169689Skan } else { 129169689Skan return false; 130169689Skan } 131169689Skan} 132169689Skan 133169689Skan// Check if 'option' matches 'name'. No "tail" is allowed. 134169689Skanstatic bool match_option(const JavaVMOption *option, const char* name) { 135169689Skan const char* tail = NULL; 136169689Skan bool result = match_option(option, name, &tail); 137169689Skan if (tail != NULL && *tail == '\0') { 138169689Skan return result; 139169689Skan } else { 140169689Skan return false; 141169689Skan } 142169689Skan} 143169689Skan 144169689Skan// Return true if any of the strings in null-terminated array 'names' matches. 145169689Skan// If tail_allowed is true, then the tail must begin with a colon; otherwise, 146169689Skan// the option must match exactly. 147169689Skanstatic bool match_option(const JavaVMOption* option, const char** names, const char** tail, 148169689Skan bool tail_allowed) { 149169689Skan for (/* empty */; *names != NULL; ++names) { 150169689Skan if (match_option(option, *names, tail)) { 151169689Skan if (**tail == '\0' || tail_allowed && **tail == ':') { 152169689Skan return true; 153169689Skan } 154169689Skan } 155169689Skan } 156169689Skan return false; 157169689Skan} 158169689Skan 159169689Skanstatic void logOption(const char* opt) { 160169689Skan if (PrintVMOptions) { 161169689Skan jio_fprintf(defaultStream::output_stream(), "VM option '%s'\n", opt); 162169689Skan } 163169689Skan} 164169689Skan 165169689Skan// Process java launcher properties. 166169689Skanvoid Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) { 167169689Skan // See if sun.java.launcher, sun.java.launcher.is_altjvm or 168169689Skan // sun.java.launcher.pid is defined. 169169689Skan // Must do this before setting up other system properties, 170169689Skan // as some of them may depend on launcher type. 171169689Skan for (int index = 0; index < args->nOptions; index++) { 172169689Skan const JavaVMOption* option = args->options + index; 173169689Skan const char* tail; 174169689Skan 175169689Skan if (match_option(option, "-Dsun.java.launcher=", &tail)) { 176169689Skan process_java_launcher_argument(tail, option->extraInfo); 177169689Skan continue; 178169689Skan } 179169689Skan if (match_option(option, "-Dsun.java.launcher.is_altjvm=", &tail)) { 180169689Skan if (strcmp(tail, "true") == 0) { 181169689Skan _sun_java_launcher_is_altjvm = true; 182169689Skan } 183169689Skan continue; 184169689Skan } 185169689Skan if (match_option(option, "-Dsun.java.launcher.pid=", &tail)) { 186169689Skan _sun_java_launcher_pid = atoi(tail); 187169689Skan continue; 188169689Skan } 189169689Skan } 190169689Skan} 191169689Skan 192169689Skan// Initialize system properties key and value. 193169689Skanvoid Arguments::init_system_properties() { 194169689Skan PropertyList_add(&_system_properties, new SystemProperty("java.vm.specification.name", 195169689Skan "Java Virtual Machine Specification", false)); 196169689Skan PropertyList_add(&_system_properties, new SystemProperty("java.vm.version", VM_Version::vm_release(), false)); 197169689Skan PropertyList_add(&_system_properties, new SystemProperty("java.vm.name", VM_Version::vm_name(), false)); 198169689Skan PropertyList_add(&_system_properties, new SystemProperty("java.vm.info", VM_Version::vm_info_string(), true)); 199169689Skan 200169689Skan // Following are JVMTI agent writable properties. 201169689Skan // Properties values are set to NULL and they are 202169689Skan // os specific they are initialized in os::init_system_properties_values(). 203169689Skan _sun_boot_library_path = new SystemProperty("sun.boot.library.path", NULL, true); 204169689Skan _java_library_path = new SystemProperty("java.library.path", NULL, true); 205169689Skan _java_home = new SystemProperty("java.home", NULL, true); 206169689Skan _sun_boot_class_path = new SystemProperty("sun.boot.class.path", NULL, true); 207169689Skan 208169689Skan _java_class_path = new SystemProperty("java.class.path", "", true); 209169689Skan 210169689Skan // Add to System Property list. 211169689Skan PropertyList_add(&_system_properties, _sun_boot_library_path); 212169689Skan PropertyList_add(&_system_properties, _java_library_path); 213169689Skan PropertyList_add(&_system_properties, _java_home); 214169689Skan PropertyList_add(&_system_properties, _java_class_path); 215169689Skan PropertyList_add(&_system_properties, _sun_boot_class_path); 216169689Skan 217169689Skan // Set OS specific system properties values 218169689Skan os::init_system_properties_values(); 219169689Skan} 220169689Skan 221169689Skan// Update/Initialize System properties after JDK version number is known 222169689Skanvoid Arguments::init_version_specific_system_properties() { 223169689Skan enum { bufsz = 16 }; 224169689Skan char buffer[bufsz]; 225169689Skan const char* spec_vendor = "Sun Microsystems Inc."; 226169689Skan uint32_t spec_version = 0; 227169689Skan 228169689Skan spec_vendor = "Oracle Corporation"; 229169689Skan spec_version = JDK_Version::current().major_version(); 230169689Skan jio_snprintf(buffer, bufsz, "1." UINT32_FORMAT, spec_version); 231169689Skan 232169689Skan PropertyList_add(&_system_properties, 233169689Skan new SystemProperty("java.vm.specification.vendor", spec_vendor, false)); 234169689Skan PropertyList_add(&_system_properties, 235169689Skan new SystemProperty("java.vm.specification.version", buffer, false)); 236169689Skan PropertyList_add(&_system_properties, 237169689Skan new SystemProperty("java.vm.vendor", VM_Version::vm_vendor(), false)); 238169689Skan} 239169689Skan 240169689Skan/** 241169689Skan * Provide a slightly more user-friendly way of eliminating -XX flags. 242169689Skan * When a flag is eliminated, it can be added to this list in order to 243169689Skan * continue accepting this flag on the command-line, while issuing a warning 244169689Skan * and ignoring the value. Once the JDK version reaches the 'accept_until' 245169689Skan * limit, we flatly refuse to admit the existence of the flag. This allows 246169689Skan * a flag to die correctly over JDK releases using HSX. 247169689Skan * But now that HSX is no longer supported only options with a future 248169689Skan * accept_until value need to be listed, and the list can be pruned 249169689Skan * on each major release. 250169689Skan */ 251169689Skantypedef struct { 252169689Skan const char* name; 253169689Skan JDK_Version obsoleted_in; // when the flag went away 254169689Skan JDK_Version accept_until; // which version to start denying the existence 255169689Skan} ObsoleteFlag; 256169689Skan 257169689Skanstatic ObsoleteFlag obsolete_jvm_flags[] = { 258169689Skan { "UseOldInlining", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 259169689Skan { "SafepointPollOffset", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 260169689Skan { "UseBoundThreads", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 261169689Skan { "DefaultThreadPriority", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 262169689Skan { "NoYieldsInMicrolock", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 263169689Skan { "BackEdgeThreshold", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 264169689Skan { "UseNewReflection", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 265169689Skan { "ReflectionWrapResolutionErrors",JDK_Version::jdk(9), JDK_Version::jdk(10) }, 266169689Skan { "VerifyReflectionBytecodes", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 267169689Skan { "AutoShutdownNMT", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 268169689Skan { "NmethodSweepFraction", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 269169689Skan { "NmethodSweepCheckInterval", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 270169689Skan { "CodeCacheMinimumFreeSpace", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 271169689Skan#ifndef ZERO 272169689Skan { "UseFastAccessorMethods", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 273169689Skan { "UseFastEmptyMethods", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 274169689Skan#endif // ZERO 275169689Skan { "UseCompilerSafepoints", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 276169689Skan { "AdaptiveSizePausePolicy", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 277169689Skan { "ParallelGCRetainPLAB", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 278169689Skan { "ThreadSafetyMargin", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 279169689Skan { "LazyBootClassLoader", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 280169689Skan { "StarvationMonitorInterval", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 281169689Skan { "PreInflateSpin", JDK_Version::jdk(9), JDK_Version::jdk(10) }, 282169689Skan { NULL, JDK_Version(0), JDK_Version(0) } 283169689Skan}; 284169689Skan 285169689Skan// Returns true if the flag is obsolete and fits into the range specified 286169689Skan// for being ignored. In the case that the flag is ignored, the 'version' 287169689Skan// value is filled in with the version number when the flag became 288169689Skan// obsolete so that that value can be displayed to the user. 289169689Skanbool Arguments::is_newly_obsolete(const char *s, JDK_Version* version) { 290169689Skan int i = 0; 291169689Skan assert(version != NULL, "Must provide a version buffer"); 292169689Skan while (obsolete_jvm_flags[i].name != NULL) { 293169689Skan const ObsoleteFlag& flag_status = obsolete_jvm_flags[i]; 294169689Skan // <flag>=xxx form 295169689Skan // [-|+]<flag> form 296169689Skan size_t len = strlen(flag_status.name); 297169689Skan if ((strncmp(flag_status.name, s, len) == 0) && 298169689Skan (strlen(s) == len)){ 299169689Skan if (JDK_Version::current().compare(flag_status.accept_until) == -1) { 300169689Skan *version = flag_status.obsoleted_in; 301169689Skan return true; 302169689Skan } 303169689Skan } 304169689Skan i++; 305169689Skan } 306169689Skan return false; 307169689Skan} 308169689Skan 309169689Skan// Constructs the system class path (aka boot class path) from the following 310169689Skan// components, in order: 311169689Skan// 312169689Skan// prefix // from -Xbootclasspath/p:... 313169689Skan// base // from os::get_system_properties() or -Xbootclasspath= 314169689Skan// suffix // from -Xbootclasspath/a:... 315169689Skan// 316169689Skan// This could be AllStatic, but it isn't needed after argument processing is 317169689Skan// complete. 318169689Skanclass SysClassPath: public StackObj { 319169689Skanpublic: 320169689Skan SysClassPath(const char* base); 321169689Skan ~SysClassPath(); 322169689Skan 323169689Skan inline void set_base(const char* base); 324169689Skan inline void add_prefix(const char* prefix); 325169689Skan inline void add_suffix_to_prefix(const char* suffix); 326169689Skan inline void add_suffix(const char* suffix); 327169689Skan inline void reset_path(const char* base); 328169689Skan 329169689Skan inline const char* get_base() const { return _items[_scp_base]; } 330169689Skan inline const char* get_prefix() const { return _items[_scp_prefix]; } 331169689Skan inline const char* get_suffix() const { return _items[_scp_suffix]; } 332169689Skan 333169689Skan // Combine all the components into a single c-heap-allocated string; caller 334169689Skan // must free the string if/when no longer needed. 335169689Skan char* combined_path(); 336169689Skan 337169689Skanprivate: 338169689Skan // Utility routines. 339169689Skan static char* add_to_path(const char* path, const char* str, bool prepend); 340169689Skan static char* add_jars_to_path(char* path, const char* directory); 341169689Skan 342169689Skan inline void reset_item_at(int index); 343169689Skan 344169689Skan // Array indices for the items that make up the sysclasspath. All except the 345169689Skan // base are allocated in the C heap and freed by this class. 346169689Skan enum { 347169689Skan _scp_prefix, // from -Xbootclasspath/p:... 348169689Skan _scp_base, // the default sysclasspath 349169689Skan _scp_suffix, // from -Xbootclasspath/a:... 350169689Skan _scp_nitems // the number of items, must be last. 351169689Skan }; 352169689Skan 353169689Skan const char* _items[_scp_nitems]; 354169689Skan}; 355169689Skan 356169689SkanSysClassPath::SysClassPath(const char* base) { 357169689Skan memset(_items, 0, sizeof(_items)); 358169689Skan _items[_scp_base] = base; 359169689Skan} 360169689Skan 361169689SkanSysClassPath::~SysClassPath() { 362169689Skan // Free everything except the base. 363169689Skan for (int i = 0; i < _scp_nitems; ++i) { 364169689Skan if (i != _scp_base) reset_item_at(i); 365169689Skan } 366169689Skan} 367169689Skan 368169689Skaninline void SysClassPath::set_base(const char* base) { 369169689Skan _items[_scp_base] = base; 370169689Skan} 371169689Skan 372169689Skaninline void SysClassPath::add_prefix(const char* prefix) { 373169689Skan _items[_scp_prefix] = add_to_path(_items[_scp_prefix], prefix, true); 374169689Skan} 375169689Skan 376169689Skaninline void SysClassPath::add_suffix_to_prefix(const char* suffix) { 377169689Skan _items[_scp_prefix] = add_to_path(_items[_scp_prefix], suffix, false); 378169689Skan} 379169689Skan 380169689Skaninline void SysClassPath::add_suffix(const char* suffix) { 381169689Skan _items[_scp_suffix] = add_to_path(_items[_scp_suffix], suffix, false); 382169689Skan} 383169689Skan 384169689Skaninline void SysClassPath::reset_item_at(int index) { 385169689Skan assert(index < _scp_nitems && index != _scp_base, "just checking"); 386169689Skan if (_items[index] != NULL) { 387169689Skan FREE_C_HEAP_ARRAY(char, _items[index]); 388169689Skan _items[index] = NULL; 389169689Skan } 390169689Skan} 391169689Skan 392169689Skaninline void SysClassPath::reset_path(const char* base) { 393169689Skan // Clear the prefix and suffix. 394169689Skan reset_item_at(_scp_prefix); 395169689Skan reset_item_at(_scp_suffix); 396169689Skan set_base(base); 397169689Skan} 398169689Skan 399169689Skan//------------------------------------------------------------------------------ 400169689Skan 401169689Skan 402169689Skan// Combine the bootclasspath elements, some of which may be null, into a single 403169689Skan// c-heap-allocated string. 404169689Skanchar* SysClassPath::combined_path() { 405169689Skan assert(_items[_scp_base] != NULL, "empty default sysclasspath"); 406169689Skan 407169689Skan size_t lengths[_scp_nitems]; 408169689Skan size_t total_len = 0; 409169689Skan 410169689Skan const char separator = *os::path_separator(); 411169689Skan 412169689Skan // Get the lengths. 413169689Skan int i; 414169689Skan for (i = 0; i < _scp_nitems; ++i) { 415169689Skan if (_items[i] != NULL) { 416169689Skan lengths[i] = strlen(_items[i]); 417169689Skan // Include space for the separator char (or a NULL for the last item). 418169689Skan total_len += lengths[i] + 1; 419169689Skan } 420169689Skan } 421169689Skan assert(total_len > 0, "empty sysclasspath not allowed"); 422169689Skan 423169689Skan // Copy the _items to a single string. 424169689Skan char* cp = NEW_C_HEAP_ARRAY(char, total_len, mtInternal); 425169689Skan char* cp_tmp = cp; 426169689Skan for (i = 0; i < _scp_nitems; ++i) { 427169689Skan if (_items[i] != NULL) { 428169689Skan memcpy(cp_tmp, _items[i], lengths[i]); 429169689Skan cp_tmp += lengths[i]; 430169689Skan *cp_tmp++ = separator; 431169689Skan } 432169689Skan } 433169689Skan *--cp_tmp = '\0'; // Replace the extra separator. 434169689Skan return cp; 435169689Skan} 436169689Skan 437169689Skan// Note: path must be c-heap-allocated (or NULL); it is freed if non-null. 438169689Skanchar* 439169689SkanSysClassPath::add_to_path(const char* path, const char* str, bool prepend) { 440169689Skan char *cp; 441169689Skan 442169689Skan assert(str != NULL, "just checking"); 443169689Skan if (path == NULL) { 444169689Skan size_t len = strlen(str) + 1; 445169689Skan cp = NEW_C_HEAP_ARRAY(char, len, mtInternal); 446169689Skan memcpy(cp, str, len); // copy the trailing null 447169689Skan } else { 448169689Skan const char separator = *os::path_separator(); 449169689Skan size_t old_len = strlen(path); 450169689Skan size_t str_len = strlen(str); 451169689Skan size_t len = old_len + str_len + 2; 452169689Skan 453169689Skan if (prepend) { 454169689Skan cp = NEW_C_HEAP_ARRAY(char, len, mtInternal); 455169689Skan char* cp_tmp = cp; 456169689Skan memcpy(cp_tmp, str, str_len); 457169689Skan cp_tmp += str_len; 458169689Skan *cp_tmp = separator; 459169689Skan memcpy(++cp_tmp, path, old_len + 1); // copy the trailing null 460169689Skan FREE_C_HEAP_ARRAY(char, path); 461169689Skan } else { 462169689Skan cp = REALLOC_C_HEAP_ARRAY(char, path, len, mtInternal); 463169689Skan char* cp_tmp = cp + old_len; 464169689Skan *cp_tmp = separator; 465169689Skan memcpy(++cp_tmp, str, str_len + 1); // copy the trailing null 466169689Skan } 467169689Skan } 468169689Skan return cp; 469169689Skan} 470169689Skan 471169689Skan// Scan the directory and append any jar or zip files found to path. 472169689Skan// Note: path must be c-heap-allocated (or NULL); it is freed if non-null. 473169689Skanchar* SysClassPath::add_jars_to_path(char* path, const char* directory) { 474169689Skan DIR* dir = os::opendir(directory); 475169689Skan if (dir == NULL) return path; 476169689Skan 477169689Skan char dir_sep[2] = { '\0', '\0' }; 478169689Skan size_t directory_len = strlen(directory); 479169689Skan const char fileSep = *os::file_separator(); 480169689Skan if (directory[directory_len - 1] != fileSep) dir_sep[0] = fileSep; 481169689Skan 482169689Skan /* Scan the directory for jars/zips, appending them to path. */ 483169689Skan struct dirent *entry; 484169689Skan char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory), mtInternal); 485169689Skan while ((entry = os::readdir(dir, (dirent *) dbuf)) != NULL) { 486169689Skan const char* name = entry->d_name; 487169689Skan const char* ext = name + strlen(name) - 4; 488169689Skan bool isJarOrZip = ext > name && 489169689Skan (os::file_name_strcmp(ext, ".jar") == 0 || 490169689Skan os::file_name_strcmp(ext, ".zip") == 0); 491169689Skan if (isJarOrZip) { 492169689Skan char* jarpath = NEW_C_HEAP_ARRAY(char, directory_len + 2 + strlen(name), mtInternal); 493169689Skan sprintf(jarpath, "%s%s%s", directory, dir_sep, name); 494169689Skan path = add_to_path(path, jarpath, false); 495169689Skan FREE_C_HEAP_ARRAY(char, jarpath); 496169689Skan } 497169689Skan } 498169689Skan FREE_C_HEAP_ARRAY(char, dbuf); 499169689Skan os::closedir(dir); 500169689Skan return path; 501169689Skan} 502169689Skan 503169689Skan// Parses a memory size specification string. 504169689Skanstatic bool atomull(const char *s, julong* result) { 505169689Skan julong n = 0; 506169689Skan int args_read = 0; 507169689Skan bool is_hex = false; 508169689Skan // Skip leading 0[xX] for hexadecimal 509169689Skan if (*s =='0' && (*(s+1) == 'x' || *(s+1) == 'X')) { 510169689Skan s += 2; 511169689Skan is_hex = true; 512169689Skan args_read = sscanf(s, JULONG_FORMAT_X, &n); 513169689Skan } else { 514169689Skan args_read = sscanf(s, JULONG_FORMAT, &n); 515169689Skan } 516169689Skan if (args_read != 1) { 517169689Skan return false; 518169689Skan } 519169689Skan while (*s != '\0' && (isdigit(*s) || (is_hex && isxdigit(*s)))) { 520169689Skan s++; 521169689Skan } 522169689Skan // 4705540: illegal if more characters are found after the first non-digit 523169689Skan if (strlen(s) > 1) { 524169689Skan return false; 525169689Skan } 526169689Skan switch (*s) { 527169689Skan case 'T': case 't': 528169689Skan *result = n * G * K; 529169689Skan // Check for overflow. 530169689Skan if (*result/((julong)G * K) != n) return false; 531169689Skan return true; 532169689Skan case 'G': case 'g': 533169689Skan *result = n * G; 534169689Skan if (*result/G != n) return false; 535169689Skan return true; 536169689Skan case 'M': case 'm': 537169689Skan *result = n * M; 538169689Skan if (*result/M != n) return false; 539169689Skan return true; 540169689Skan case 'K': case 'k': 541169689Skan *result = n * K; 542169689Skan if (*result/K != n) return false; 543169689Skan return true; 544169689Skan case '\0': 545169689Skan *result = n; 546169689Skan return true; 547169689Skan default: 548169689Skan return false; 549169689Skan } 550169689Skan} 551169689Skan 552169689SkanArguments::ArgsRange Arguments::check_memory_size(julong size, julong min_size) { 553169689Skan if (size < min_size) return arg_too_small; 554169689Skan // Check that size will fit in a size_t (only relevant on 32-bit) 555169689Skan if (size > max_uintx) return arg_too_big; 556169689Skan return arg_in_range; 557169689Skan} 558169689Skan 559169689Skan// Describe an argument out of range error 560169689Skanvoid Arguments::describe_range_error(ArgsRange errcode) { 561169689Skan switch(errcode) { 562169689Skan case arg_too_big: 563169689Skan jio_fprintf(defaultStream::error_stream(), 564169689Skan "The specified size exceeds the maximum " 565169689Skan "representable size.\n"); 566169689Skan break; 567169689Skan case arg_too_small: 568169689Skan case arg_unreadable: 569169689Skan case arg_in_range: 570169689Skan // do nothing for now 571169689Skan break; 572169689Skan default: 573169689Skan ShouldNotReachHere(); 574169689Skan } 575169689Skan} 576169689Skan 577169689Skanstatic bool set_bool_flag(char* name, bool value, Flag::Flags origin) { 578169689Skan if (CommandLineFlags::boolAtPut(name, &value, origin) == Flag::SUCCESS) { 579169689Skan return true; 580169689Skan } else { 581169689Skan return false; 582169689Skan } 583169689Skan} 584169689Skan 585169689Skanstatic bool set_fp_numeric_flag(char* name, char* value, Flag::Flags origin) { 586169689Skan double v; 587169689Skan if (sscanf(value, "%lf", &v) != 1) { 588169689Skan return false; 589169689Skan } 590169689Skan 591169689Skan if (CommandLineFlags::doubleAtPut(name, &v, origin) == Flag::SUCCESS) { 592169689Skan return true; 593169689Skan } 594169689Skan return false; 595169689Skan} 596169689Skan 597169689Skanstatic bool set_numeric_flag(char* name, char* value, Flag::Flags origin) { 598169689Skan julong v; 599169689Skan int int_v; 600169689Skan intx intx_v; 601169689Skan bool is_neg = false; 602169689Skan // Check the sign first since atomull() parses only unsigned values. 603169689Skan if (*value == '-') { 604169689Skan if ((CommandLineFlags::intxAt(name, &intx_v) != Flag::SUCCESS) && (CommandLineFlags::intAt(name, &int_v) != Flag::SUCCESS)) { 605169689Skan return false; 606169689Skan } 607169689Skan value++; 608169689Skan is_neg = true; 609169689Skan } 610169689Skan if (!atomull(value, &v)) { 611169689Skan return false; 612169689Skan } 613169689Skan int_v = (int) v; 614169689Skan if (is_neg) { 615169689Skan int_v = -int_v; 616169689Skan } 617169689Skan if (CommandLineFlags::intAtPut(name, &int_v, origin) == Flag::SUCCESS) { 618169689Skan return true; 619169689Skan } 620169689Skan uint uint_v = (uint) v; 621169689Skan if (!is_neg && CommandLineFlags::uintAtPut(name, &uint_v, origin) == Flag::SUCCESS) { 622169689Skan return true; 623169689Skan } 624169689Skan intx_v = (intx) v; 625169689Skan if (is_neg) { 626169689Skan intx_v = -intx_v; 627169689Skan } 628169689Skan if (CommandLineFlags::intxAtPut(name, &intx_v, origin) == Flag::SUCCESS) { 629169689Skan return true; 630169689Skan } 631169689Skan uintx uintx_v = (uintx) v; 632169689Skan if (!is_neg && (CommandLineFlags::uintxAtPut(name, &uintx_v, origin) == Flag::SUCCESS)) { 633169689Skan return true; 634169689Skan } 635169689Skan uint64_t uint64_t_v = (uint64_t) v; 636169689Skan if (!is_neg && (CommandLineFlags::uint64_tAtPut(name, &uint64_t_v, origin) == Flag::SUCCESS)) { 637169689Skan return true; 638169689Skan } 639169689Skan size_t size_t_v = (size_t) v; 640169689Skan if (!is_neg && (CommandLineFlags::size_tAtPut(name, &size_t_v, origin) == Flag::SUCCESS)) { 641169689Skan return true; 642169689Skan } 643169689Skan return false; 644169689Skan} 645169689Skan 646169689Skanstatic bool set_string_flag(char* name, const char* value, Flag::Flags origin) { 647169689Skan if (CommandLineFlags::ccstrAtPut(name, &value, origin) != Flag::SUCCESS) return false; 648169689Skan // Contract: CommandLineFlags always returns a pointer that needs freeing. 649169689Skan FREE_C_HEAP_ARRAY(char, value); 650169689Skan return true; 651169689Skan} 652169689Skan 653169689Skanstatic bool append_to_string_flag(char* name, const char* new_value, Flag::Flags origin) { 654169689Skan const char* old_value = ""; 655169689Skan if (CommandLineFlags::ccstrAt(name, &old_value) != Flag::SUCCESS) return false; 656169689Skan size_t old_len = old_value != NULL ? strlen(old_value) : 0; 657169689Skan size_t new_len = strlen(new_value); 658169689Skan const char* value; 659169689Skan char* free_this_too = NULL; 660169689Skan if (old_len == 0) { 661169689Skan value = new_value; 662169689Skan } else if (new_len == 0) { 663169689Skan value = old_value; 664169689Skan } else { 665169689Skan char* buf = NEW_C_HEAP_ARRAY(char, old_len + 1 + new_len + 1, mtInternal); 666169689Skan // each new setting adds another LINE to the switch: 667169689Skan sprintf(buf, "%s\n%s", old_value, new_value); 668169689Skan value = buf; 669169689Skan free_this_too = buf; 670169689Skan } 671169689Skan (void) CommandLineFlags::ccstrAtPut(name, &value, origin); 672169689Skan // CommandLineFlags always returns a pointer that needs freeing. 673169689Skan FREE_C_HEAP_ARRAY(char, value); 674169689Skan if (free_this_too != NULL) { 675169689Skan // CommandLineFlags made its own copy, so I must delete my own temp. buffer. 676169689Skan FREE_C_HEAP_ARRAY(char, free_this_too); 677169689Skan } 678169689Skan return true; 679169689Skan} 680169689Skan 681169689Skanbool Arguments::parse_argument(const char* arg, Flag::Flags origin) { 682169689Skan 683169689Skan // range of acceptable characters spelled out for portability reasons 684169689Skan#define NAME_RANGE "[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]" 685169689Skan#define BUFLEN 255 686169689Skan char name[BUFLEN+1]; 687169689Skan char dummy; 688169689Skan 689169689Skan if (sscanf(arg, "-%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) { 690169689Skan return set_bool_flag(name, false, origin); 691169689Skan } 692169689Skan if (sscanf(arg, "+%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) { 693169689Skan return set_bool_flag(name, true, origin); 694169689Skan } 695169689Skan 696169689Skan char punct; 697171825Skan if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "%c", name, &punct) == 2 && punct == '=') { 698171825Skan const char* value = strchr(arg, '=') + 1; 699171825Skan Flag* flag = Flag::find_flag(name, strlen(name)); 700169689Skan if (flag != NULL && flag->is_ccstr()) { 701169689Skan if (flag->ccstr_accumulates()) { 702169689Skan return append_to_string_flag(name, value, origin); 703169689Skan } else { 704169689Skan if (value[0] == '\0') { 705169689Skan value = NULL; 706169689Skan } 707169689Skan return set_string_flag(name, value, origin); 708169689Skan } 709169689Skan } 710169689Skan } 711169689Skan 712169689Skan if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE ":%c", name, &punct) == 2 && punct == '=') { 713169689Skan const char* value = strchr(arg, '=') + 1; 714169689Skan // -XX:Foo:=xxx will reset the string flag to the given value. 715169689Skan if (value[0] == '\0') { 716169689Skan value = NULL; 717169689Skan } 718169689Skan return set_string_flag(name, value, origin); 719169689Skan } 720169689Skan 721169689Skan#define SIGNED_FP_NUMBER_RANGE "[-0123456789.]" 722169689Skan#define SIGNED_NUMBER_RANGE "[-0123456789]" 723169689Skan#define NUMBER_RANGE "[0123456789]" 724169689Skan char value[BUFLEN + 1]; 725169689Skan char value2[BUFLEN + 1]; 726169689Skan if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_NUMBER_RANGE "." "%" XSTR(BUFLEN) NUMBER_RANGE "%c", name, value, value2, &dummy) == 3) { 727169689Skan // Looks like a floating-point number -- try again with more lenient format string 728169689Skan if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_FP_NUMBER_RANGE "%c", name, value, &dummy) == 2) { 729169689Skan return set_fp_numeric_flag(name, value, origin); 730169689Skan } 731169689Skan } 732169689Skan 733169689Skan#define VALUE_RANGE "[-kmgtxKMGTX0123456789abcdefABCDEF]" 734169689Skan if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) VALUE_RANGE "%c", name, value, &dummy) == 2) { 735169689Skan return set_numeric_flag(name, value, origin); 736169689Skan } 737169689Skan 738169689Skan return false; 739169689Skan} 740169689Skan 741169689Skanvoid Arguments::add_string(char*** bldarray, int* count, const char* arg) { 742169689Skan assert(bldarray != NULL, "illegal argument"); 743169689Skan 744169689Skan if (arg == NULL) { 745169689Skan return; 746169689Skan } 747169689Skan 748169689Skan int new_count = *count + 1; 749169689Skan 750169689Skan // expand the array and add arg to the last element 751169689Skan if (*bldarray == NULL) { 752169689Skan *bldarray = NEW_C_HEAP_ARRAY(char*, new_count, mtInternal); 753169689Skan } else { 754169689Skan *bldarray = REALLOC_C_HEAP_ARRAY(char*, *bldarray, new_count, mtInternal); 755169689Skan } 756169689Skan (*bldarray)[*count] = os::strdup_check_oom(arg); 757169689Skan *count = new_count; 758169689Skan} 759169689Skan 760169689Skanvoid Arguments::build_jvm_args(const char* arg) { 761169689Skan add_string(&_jvm_args_array, &_num_jvm_args, arg); 762169689Skan} 763169689Skan 764169689Skanvoid Arguments::build_jvm_flags(const char* arg) { 765169689Skan add_string(&_jvm_flags_array, &_num_jvm_flags, arg); 766169689Skan} 767169689Skan 768169689Skan// utility function to return a string that concatenates all 769169689Skan// strings in a given char** array 770169689Skanconst char* Arguments::build_resource_string(char** args, int count) { 771169689Skan if (args == NULL || count == 0) { 772169689Skan return NULL; 773169689Skan } 774169689Skan size_t length = strlen(args[0]) + 1; // add 1 for the null terminator 775169689Skan for (int i = 1; i < count; i++) { 776169689Skan length += strlen(args[i]) + 1; // add 1 for a space 777169689Skan } 778169689Skan char* s = NEW_RESOURCE_ARRAY(char, length); 779169689Skan strcpy(s, args[0]); 780169689Skan for (int j = 1; j < count; j++) { 781169689Skan strcat(s, " "); 782169689Skan strcat(s, args[j]); 783169689Skan } 784169689Skan return (const char*) s; 785169689Skan} 786169689Skan 787169689Skanvoid Arguments::print_on(outputStream* st) { 788169689Skan st->print_cr("VM Arguments:"); 789169689Skan if (num_jvm_flags() > 0) { 790169689Skan st->print("jvm_flags: "); print_jvm_flags_on(st); 791169689Skan st->cr(); 792169689Skan } 793169689Skan if (num_jvm_args() > 0) { 794169689Skan st->print("jvm_args: "); print_jvm_args_on(st); 795169689Skan st->cr(); 796169689Skan } 797169689Skan st->print_cr("java_command: %s", java_command() ? java_command() : "<unknown>"); 798169689Skan if (_java_class_path != NULL) { 799169689Skan char* path = _java_class_path->value(); 800169689Skan st->print_cr("java_class_path (initial): %s", strlen(path) == 0 ? "<not set>" : path ); 801169689Skan } 802169689Skan st->print_cr("Launcher Type: %s", _sun_java_launcher); 803169689Skan} 804169689Skan 805169689Skanvoid Arguments::print_summary_on(outputStream* st) { 806169689Skan // Print the command line. Environment variables that are helpful for 807169689Skan // reproducing the problem are written later in the hs_err file. 808169689Skan // flags are from setting file 809169689Skan if (num_jvm_flags() > 0) { 810169689Skan st->print_raw("Settings File: "); 811169689Skan print_jvm_flags_on(st); 812169689Skan st->cr(); 813169689Skan } 814169689Skan // args are the command line and environment variable arguments. 815169689Skan st->print_raw("Command Line: "); 816169689Skan if (num_jvm_args() > 0) { 817169689Skan print_jvm_args_on(st); 818169689Skan } 819169689Skan // this is the classfile and any arguments to the java program 820169689Skan if (java_command() != NULL) { 821169689Skan st->print("%s", java_command()); 822169689Skan } 823169689Skan st->cr(); 824169689Skan} 825169689Skan 826169689Skanvoid Arguments::print_jvm_flags_on(outputStream* st) { 827169689Skan if (_num_jvm_flags > 0) { 828169689Skan for (int i=0; i < _num_jvm_flags; i++) { 829169689Skan st->print("%s ", _jvm_flags_array[i]); 830169689Skan } 831169689Skan } 832169689Skan} 833169689Skan 834169689Skanvoid Arguments::print_jvm_args_on(outputStream* st) { 835169689Skan if (_num_jvm_args > 0) { 836169689Skan for (int i=0; i < _num_jvm_args; i++) { 837169689Skan st->print("%s ", _jvm_args_array[i]); 838169689Skan } 839169689Skan } 840169689Skan} 841169689Skan 842169689Skanbool Arguments::process_argument(const char* arg, 843169689Skan jboolean ignore_unrecognized, Flag::Flags origin) { 844169689Skan 845169689Skan JDK_Version since = JDK_Version(); 846169689Skan 847169689Skan if (parse_argument(arg, origin) || ignore_unrecognized) { 848169689Skan return true; 849169689Skan } 850169689Skan 851169689Skan // Determine if the flag has '+', '-', or '=' characters. 852169689Skan bool has_plus_minus = (*arg == '+' || *arg == '-'); 853169689Skan const char* const argname = has_plus_minus ? arg + 1 : arg; 854169689Skan 855169689Skan size_t arg_len; 856169689Skan const char* equal_sign = strchr(argname, '='); 857169689Skan if (equal_sign == NULL) { 858169689Skan arg_len = strlen(argname); 859169689Skan } else { 860169689Skan arg_len = equal_sign - argname; 861169689Skan } 862169689Skan 863169689Skan // Only make the obsolete check for valid arguments. 864169689Skan if (arg_len <= BUFLEN) { 865169689Skan // Construct a string which consists only of the argument name without '+', '-', or '='. 866169689Skan char stripped_argname[BUFLEN+1]; 867169689Skan strncpy(stripped_argname, argname, arg_len); 868169689Skan stripped_argname[arg_len] = '\0'; // strncpy may not null terminate. 869169689Skan 870169689Skan if (is_newly_obsolete(stripped_argname, &since)) { 871169689Skan char version[256]; 872169689Skan since.to_string(version, sizeof(version)); 873169689Skan warning("ignoring option %s; support was removed in %s", stripped_argname, version); 874169689Skan return true; 875169689Skan } 876169689Skan } 877169689Skan 878169689Skan // For locked flags, report a custom error message if available. 879169689Skan // Otherwise, report the standard unrecognized VM option. 880169689Skan Flag* found_flag = Flag::find_flag((const char*)argname, arg_len, true, true); 881169689Skan if (found_flag != NULL) { 882169689Skan char locked_message_buf[BUFLEN]; 883169689Skan found_flag->get_locked_message(locked_message_buf, BUFLEN); 884169689Skan if (strlen(locked_message_buf) == 0) { 885169689Skan if (found_flag->is_bool() && !has_plus_minus) { 886169689Skan jio_fprintf(defaultStream::error_stream(), 887169689Skan "Missing +/- setting for VM option '%s'\n", argname); 888169689Skan } else if (!found_flag->is_bool() && has_plus_minus) { 889169689Skan jio_fprintf(defaultStream::error_stream(), 890169689Skan "Unexpected +/- setting in VM option '%s'\n", argname); 891169689Skan } else { 892169689Skan jio_fprintf(defaultStream::error_stream(), 893169689Skan "Improperly specified VM option '%s'\n", argname); 894169689Skan } 895169689Skan } else { 896169689Skan jio_fprintf(defaultStream::error_stream(), "%s", locked_message_buf); 897169689Skan } 898169689Skan } else { 899169689Skan jio_fprintf(defaultStream::error_stream(), 900169689Skan "Unrecognized VM option '%s'\n", argname); 901169689Skan Flag* fuzzy_matched = Flag::fuzzy_match((const char*)argname, arg_len, true); 902169689Skan if (fuzzy_matched != NULL) { 903169689Skan jio_fprintf(defaultStream::error_stream(), 904169689Skan "Did you mean '%s%s%s'? ", 905169689Skan (fuzzy_matched->is_bool()) ? "(+/-)" : "", 906169689Skan fuzzy_matched->_name, 907169689Skan (fuzzy_matched->is_bool()) ? "" : "=<value>"); 908169689Skan } 909169689Skan } 910169689Skan 911169689Skan // allow for commandline "commenting out" options like -XX:#+Verbose 912169689Skan return arg[0] == '#'; 913169689Skan} 914169689Skan 915169689Skanbool Arguments::process_settings_file(const char* file_name, bool should_exist, jboolean ignore_unrecognized) { 916169689Skan FILE* stream = fopen(file_name, "rb"); 917169689Skan if (stream == NULL) { 918169689Skan if (should_exist) { 919169689Skan jio_fprintf(defaultStream::error_stream(), 920169689Skan "Could not open settings file %s\n", file_name); 921169689Skan return false; 922169689Skan } else { 923169689Skan return true; 924169689Skan } 925169689Skan } 926169689Skan 927169689Skan char token[1024]; 928169689Skan int pos = 0; 929169689Skan 930169689Skan bool in_white_space = true; 931169689Skan bool in_comment = false; 932169689Skan bool in_quote = false; 933169689Skan char quote_c = 0; 934169689Skan bool result = true; 935169689Skan 936169689Skan int c = getc(stream); 937169689Skan while(c != EOF && pos < (int)(sizeof(token)-1)) { 938169689Skan if (in_white_space) { 939169689Skan if (in_comment) { 940169689Skan if (c == '\n') in_comment = false; 941169689Skan } else { 942169689Skan if (c == '#') in_comment = true; 943169689Skan else if (!isspace(c)) { 944169689Skan in_white_space = false; 945169689Skan token[pos++] = c; 946169689Skan } 947169689Skan } 948169689Skan } else { 949169689Skan if (c == '\n' || (!in_quote && isspace(c))) { 950169689Skan // token ends at newline, or at unquoted whitespace 951169689Skan // this allows a way to include spaces in string-valued options 952169689Skan token[pos] = '\0'; 953169689Skan logOption(token); 954169689Skan result &= process_argument(token, ignore_unrecognized, Flag::CONFIG_FILE); 955169689Skan build_jvm_flags(token); 956169689Skan pos = 0; 957169689Skan in_white_space = true; 958169689Skan in_quote = false; 959169689Skan } else if (!in_quote && (c == '\'' || c == '"')) { 960169689Skan in_quote = true; 961169689Skan quote_c = c; 962169689Skan } else if (in_quote && (c == quote_c)) { 963169689Skan in_quote = false; 964169689Skan } else { 965169689Skan token[pos++] = c; 966169689Skan } 967169689Skan } 968169689Skan c = getc(stream); 969169689Skan } 970169689Skan if (pos > 0) { 971169689Skan token[pos] = '\0'; 972169689Skan result &= process_argument(token, ignore_unrecognized, Flag::CONFIG_FILE); 973169689Skan build_jvm_flags(token); 974169689Skan } 975169689Skan fclose(stream); 976169689Skan return result; 977169689Skan} 978169689Skan 979169689Skan//============================================================================================================= 980169689Skan// Parsing of properties (-D) 981169689Skan 982169689Skanconst char* Arguments::get_property(const char* key) { 983169689Skan return PropertyList_get_value(system_properties(), key); 984169689Skan} 985169689Skan 986169689Skanbool Arguments::add_property(const char* prop) { 987169689Skan const char* eq = strchr(prop, '='); 988169689Skan char* key; 989169689Skan // ns must be static--its address may be stored in a SystemProperty object. 990169689Skan const static char ns[1] = {0}; 991169689Skan char* value = (char *)ns; 992169689Skan 993169689Skan size_t key_len = (eq == NULL) ? strlen(prop) : (eq - prop); 994169689Skan key = AllocateHeap(key_len + 1, mtInternal); 995169689Skan strncpy(key, prop, key_len); 996169689Skan key[key_len] = '\0'; 997169689Skan 998169689Skan if (eq != NULL) { 999169689Skan size_t value_len = strlen(prop) - key_len - 1; 1000169689Skan value = AllocateHeap(value_len + 1, mtInternal); 1001169689Skan strncpy(value, &prop[key_len + 1], value_len + 1); 1002169689Skan } 1003169689Skan 1004169689Skan if (strcmp(key, "java.compiler") == 0) { 1005169689Skan process_java_compiler_argument(value); 1006169689Skan FreeHeap(key); 1007169689Skan if (eq != NULL) { 1008169689Skan FreeHeap(value); 1009169689Skan } 1010169689Skan return true; 1011169689Skan } else if (strcmp(key, "sun.java.command") == 0) { 1012169689Skan _java_command = value; 1013169689Skan 1014169689Skan // Record value in Arguments, but let it get passed to Java. 1015169689Skan } else if (strcmp(key, "sun.java.launcher.is_altjvm") == 0 || 1016169689Skan strcmp(key, "sun.java.launcher.pid") == 0) { 1017169689Skan // sun.java.launcher.is_altjvm and sun.java.launcher.pid property are 1018169689Skan // private and are processed in process_sun_java_launcher_properties(); 1019169689Skan // the sun.java.launcher property is passed on to the java application 1020169689Skan FreeHeap(key); 1021169689Skan if (eq != NULL) { 1022169689Skan FreeHeap(value); 1023169689Skan } 1024169689Skan return true; 1025169689Skan } else if (strcmp(key, "java.vendor.url.bug") == 0) { 1026169689Skan // save it in _java_vendor_url_bug, so JVM fatal error handler can access 1027169689Skan // its value without going through the property list or making a Java call. 1028169689Skan _java_vendor_url_bug = value; 1029169689Skan } else if (strcmp(key, "sun.boot.library.path") == 0) { 1030169689Skan PropertyList_unique_add(&_system_properties, key, value, true); 1031169689Skan return true; 1032169689Skan } 1033169689Skan // Create new property and add at the end of the list 1034169689Skan PropertyList_unique_add(&_system_properties, key, value); 1035169689Skan return true; 1036169689Skan} 1037169689Skan 1038169689Skan//=========================================================================================================== 1039169689Skan// Setting int/mixed/comp mode flags 1040169689Skan 1041169689Skanvoid Arguments::set_mode_flags(Mode mode) { 1042169689Skan // Set up default values for all flags. 1043169689Skan // If you add a flag to any of the branches below, 1044169689Skan // add a default value for it here. 1045169689Skan set_java_compiler(false); 1046169689Skan _mode = mode; 1047169689Skan 1048169689Skan // Ensure Agent_OnLoad has the correct initial values. 1049169689Skan // This may not be the final mode; mode may change later in onload phase. 1050169689Skan PropertyList_unique_add(&_system_properties, "java.vm.info", 1051169689Skan (char*)VM_Version::vm_info_string(), false); 1052169689Skan 1053169689Skan UseInterpreter = true; 1054169689Skan UseCompiler = true; 1055169689Skan UseLoopCounter = true; 1056169689Skan 1057169689Skan // Default values may be platform/compiler dependent - 1058169689Skan // use the saved values 1059169689Skan ClipInlining = Arguments::_ClipInlining; 1060169689Skan AlwaysCompileLoopMethods = Arguments::_AlwaysCompileLoopMethods; 1061169689Skan UseOnStackReplacement = Arguments::_UseOnStackReplacement; 1062169689Skan BackgroundCompilation = Arguments::_BackgroundCompilation; 1063169689Skan if (TieredCompilation) { 1064169689Skan if (FLAG_IS_DEFAULT(Tier3InvokeNotifyFreqLog)) { 1065169689Skan Tier3InvokeNotifyFreqLog = Arguments::_Tier3InvokeNotifyFreqLog; 1066169689Skan } 1067169689Skan if (FLAG_IS_DEFAULT(Tier4InvocationThreshold)) { 1068169689Skan Tier4InvocationThreshold = Arguments::_Tier4InvocationThreshold; 1069169689Skan } 1070169689Skan } 1071169689Skan 1072169689Skan // Change from defaults based on mode 1073169689Skan switch (mode) { 1074169689Skan default: 1075169689Skan ShouldNotReachHere(); 1076169689Skan break; 1077169689Skan case _int: 1078169689Skan UseCompiler = false; 1079169689Skan UseLoopCounter = false; 1080169689Skan AlwaysCompileLoopMethods = false; 1081169689Skan UseOnStackReplacement = false; 1082169689Skan break; 1083169689Skan case _mixed: 1084169689Skan // same as default 1085169689Skan break; 1086169689Skan case _comp: 1087169689Skan UseInterpreter = false; 1088169689Skan BackgroundCompilation = false; 1089169689Skan ClipInlining = false; 1090169689Skan // Be much more aggressive in tiered mode with -Xcomp and exercise C2 more. 1091169689Skan // We will first compile a level 3 version (C1 with full profiling), then do one invocation of it and 1092169689Skan // compile a level 4 (C2) and then continue executing it. 1093169689Skan if (TieredCompilation) { 1094169689Skan Tier3InvokeNotifyFreqLog = 0; 1095169689Skan Tier4InvocationThreshold = 0; 1096169689Skan } 1097169689Skan break; 1098169689Skan } 1099169689Skan} 1100169689Skan 1101169689Skan#if defined(COMPILER2) || defined(_LP64) || !INCLUDE_CDS 1102169689Skan// Conflict: required to use shared spaces (-Xshare:on), but 1103169689Skan// incompatible command line options were chosen. 1104169689Skan 1105169689Skanstatic void no_shared_spaces(const char* message) { 1106169689Skan if (RequireSharedSpaces) { 1107169689Skan jio_fprintf(defaultStream::error_stream(), 1108169689Skan "Class data sharing is inconsistent with other specified options.\n"); 1109169689Skan vm_exit_during_initialization("Unable to use shared archive.", message); 1110169689Skan } else { 1111169689Skan FLAG_SET_DEFAULT(UseSharedSpaces, false); 1112169689Skan } 1113169689Skan} 1114169689Skan#endif 1115169689Skan 1116169689Skan// Returns threshold scaled with the value of scale. 1117169689Skan// If scale < 0.0, threshold is returned without scaling. 1118169689Skanintx Arguments::scaled_compile_threshold(intx threshold, double scale) { 1119169689Skan if (scale == 1.0 || scale < 0.0) { 1120169689Skan return threshold; 1121169689Skan } else { 1122169689Skan return (intx)(threshold * scale); 1123169689Skan } 1124169689Skan} 1125169689Skan 1126169689Skan// Returns freq_log scaled with the value of scale. 1127169689Skan// Returned values are in the range of [0, InvocationCounter::number_of_count_bits + 1]. 1128169689Skan// If scale < 0.0, freq_log is returned without scaling. 1129169689Skanintx Arguments::scaled_freq_log(intx freq_log, double scale) { 1130169689Skan // Check if scaling is necessary or if negative value was specified. 1131169689Skan if (scale == 1.0 || scale < 0.0) { 1132169689Skan return freq_log; 1133169689Skan } 1134169689Skan // Check values to avoid calculating log2 of 0. 1135169689Skan if (scale == 0.0 || freq_log == 0) { 1136169689Skan return 0; 1137169689Skan } 1138169689Skan // Determine the maximum notification frequency value currently supported. 1139169689Skan // The largest mask value that the interpreter/C1 can handle is 1140169689Skan // of length InvocationCounter::number_of_count_bits. Mask values are always 1141169689Skan // one bit shorter then the value of the notification frequency. Set 1142169689Skan // max_freq_bits accordingly. 1143169689Skan intx max_freq_bits = InvocationCounter::number_of_count_bits + 1; 1144169689Skan intx scaled_freq = scaled_compile_threshold((intx)1 << freq_log, scale); 1145169689Skan if (scaled_freq == 0) { 1146169689Skan // Return 0 right away to avoid calculating log2 of 0. 1147169689Skan return 0; 1148169689Skan } else if (scaled_freq > nth_bit(max_freq_bits)) { 1149169689Skan return max_freq_bits; 1150169689Skan } else { 1151169689Skan return log2_intptr(scaled_freq); 1152169689Skan } 1153169689Skan} 1154169689Skan 1155169689Skanvoid Arguments::set_tiered_flags() { 1156169689Skan // With tiered, set default policy to AdvancedThresholdPolicy, which is 3. 1157169689Skan if (FLAG_IS_DEFAULT(CompilationPolicyChoice)) { 1158169689Skan FLAG_SET_DEFAULT(CompilationPolicyChoice, 3); 1159169689Skan } 1160169689Skan if (CompilationPolicyChoice < 2) { 1161169689Skan vm_exit_during_initialization( 1162169689Skan "Incompatible compilation policy selected", NULL); 1163169689Skan } 1164169689Skan // Increase the code cache size - tiered compiles a lot more. 1165169689Skan if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) { 1166169689Skan FLAG_SET_ERGO(uintx, ReservedCodeCacheSize, 1167169689Skan MIN2(CODE_CACHE_DEFAULT_LIMIT, ReservedCodeCacheSize * 5)); 1168169689Skan } 1169169689Skan // Enable SegmentedCodeCache if TieredCompilation is enabled and ReservedCodeCacheSize >= 240M 1170169689Skan if (FLAG_IS_DEFAULT(SegmentedCodeCache) && ReservedCodeCacheSize >= 240*M) { 1171169689Skan FLAG_SET_ERGO(bool, SegmentedCodeCache, true); 1172169689Skan 1173169689Skan if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) { 1174169689Skan // Multiply sizes by 5 but fix NonNMethodCodeHeapSize (distribute among non-profiled and profiled code heap) 1175169689Skan if (FLAG_IS_DEFAULT(ProfiledCodeHeapSize)) { 1176169689Skan FLAG_SET_ERGO(uintx, ProfiledCodeHeapSize, ProfiledCodeHeapSize * 5 + NonNMethodCodeHeapSize * 2); 1177169689Skan } 1178169689Skan if (FLAG_IS_DEFAULT(NonProfiledCodeHeapSize)) { 1179169689Skan FLAG_SET_ERGO(uintx, NonProfiledCodeHeapSize, NonProfiledCodeHeapSize * 5 + NonNMethodCodeHeapSize * 2); 1180169689Skan } 1181169689Skan // Check consistency of code heap sizes 1182169689Skan if ((NonNMethodCodeHeapSize + NonProfiledCodeHeapSize + ProfiledCodeHeapSize) != ReservedCodeCacheSize) { 1183169689Skan jio_fprintf(defaultStream::error_stream(), 1184169689Skan "Invalid code heap sizes: NonNMethodCodeHeapSize(%dK) + ProfiledCodeHeapSize(%dK) + NonProfiledCodeHeapSize(%dK) = %dK. Must be equal to ReservedCodeCacheSize = %uK.\n", 1185169689Skan NonNMethodCodeHeapSize/K, ProfiledCodeHeapSize/K, NonProfiledCodeHeapSize/K, 1186169689Skan (NonNMethodCodeHeapSize + ProfiledCodeHeapSize + NonProfiledCodeHeapSize)/K, ReservedCodeCacheSize/K); 1187169689Skan vm_exit(1); 1188169689Skan } 1189169689Skan } 1190169689Skan } 1191169689Skan if (!UseInterpreter) { // -Xcomp 1192169689Skan Tier3InvokeNotifyFreqLog = 0; 1193169689Skan Tier4InvocationThreshold = 0; 1194169689Skan } 1195169689Skan 1196169689Skan if (CompileThresholdScaling < 0) { 1197169689Skan vm_exit_during_initialization("Negative value specified for CompileThresholdScaling", NULL); 1198169689Skan } 1199169689Skan 1200169689Skan // Scale tiered compilation thresholds. 1201169689Skan // CompileThresholdScaling == 0.0 is equivalent to -Xint and leaves compilation thresholds unchanged. 1202169689Skan if (!FLAG_IS_DEFAULT(CompileThresholdScaling) && CompileThresholdScaling > 0.0) { 1203169689Skan FLAG_SET_ERGO(intx, Tier0InvokeNotifyFreqLog, scaled_freq_log(Tier0InvokeNotifyFreqLog)); 1204169689Skan FLAG_SET_ERGO(intx, Tier0BackedgeNotifyFreqLog, scaled_freq_log(Tier0BackedgeNotifyFreqLog)); 1205169689Skan 1206169689Skan FLAG_SET_ERGO(intx, Tier3InvocationThreshold, scaled_compile_threshold(Tier3InvocationThreshold)); 1207169689Skan FLAG_SET_ERGO(intx, Tier3MinInvocationThreshold, scaled_compile_threshold(Tier3MinInvocationThreshold)); 1208169689Skan FLAG_SET_ERGO(intx, Tier3CompileThreshold, scaled_compile_threshold(Tier3CompileThreshold)); 1209169689Skan FLAG_SET_ERGO(intx, Tier3BackEdgeThreshold, scaled_compile_threshold(Tier3BackEdgeThreshold)); 1210169689Skan 1211169689Skan // Tier2{Invocation,MinInvocation,Compile,Backedge}Threshold should be scaled here 1212169689Skan // once these thresholds become supported. 1213169689Skan 1214169689Skan FLAG_SET_ERGO(intx, Tier2InvokeNotifyFreqLog, scaled_freq_log(Tier2InvokeNotifyFreqLog)); 1215169689Skan FLAG_SET_ERGO(intx, Tier2BackedgeNotifyFreqLog, scaled_freq_log(Tier2BackedgeNotifyFreqLog)); 1216169689Skan 1217169689Skan FLAG_SET_ERGO(intx, Tier3InvokeNotifyFreqLog, scaled_freq_log(Tier3InvokeNotifyFreqLog)); 1218169689Skan FLAG_SET_ERGO(intx, Tier3BackedgeNotifyFreqLog, scaled_freq_log(Tier3BackedgeNotifyFreqLog)); 1219169689Skan 1220169689Skan FLAG_SET_ERGO(intx, Tier23InlineeNotifyFreqLog, scaled_freq_log(Tier23InlineeNotifyFreqLog)); 1221169689Skan 1222169689Skan FLAG_SET_ERGO(intx, Tier4InvocationThreshold, scaled_compile_threshold(Tier4InvocationThreshold)); 1223169689Skan FLAG_SET_ERGO(intx, Tier4MinInvocationThreshold, scaled_compile_threshold(Tier4MinInvocationThreshold)); 1224169689Skan FLAG_SET_ERGO(intx, Tier4CompileThreshold, scaled_compile_threshold(Tier4CompileThreshold)); 1225169689Skan FLAG_SET_ERGO(intx, Tier4BackEdgeThreshold, scaled_compile_threshold(Tier4BackEdgeThreshold)); 1226169689Skan } 1227169689Skan} 1228169689Skan 1229169689Skan/** 1230169689Skan * Returns the minimum number of compiler threads needed to run the JVM. The following 1231169689Skan * configurations are possible. 1232169689Skan * 1233169689Skan * 1) The JVM is build using an interpreter only. As a result, the minimum number of 1234169689Skan * compiler threads is 0. 1235169689Skan * 2) The JVM is build using the compiler(s) and tiered compilation is disabled. As 1236169689Skan * a result, either C1 or C2 is used, so the minimum number of compiler threads is 1. 1237169689Skan * 3) The JVM is build using the compiler(s) and tiered compilation is enabled. However, 1238169689Skan * the option "TieredStopAtLevel < CompLevel_full_optimization". As a result, only 1239169689Skan * C1 can be used, so the minimum number of compiler threads is 1. 1240169689Skan * 4) The JVM is build using the compilers and tiered compilation is enabled. The option 1241169689Skan * 'TieredStopAtLevel = CompLevel_full_optimization' (the default value). As a result, 1242169689Skan * the minimum number of compiler threads is 2. 1243169689Skan */ 1244169689Skanint Arguments::get_min_number_of_compiler_threads() { 1245169689Skan#if !defined(COMPILER1) && !defined(COMPILER2) && !defined(SHARK) 1246169689Skan return 0; // case 1 1247169689Skan#else 1248169689Skan if (!TieredCompilation || (TieredStopAtLevel < CompLevel_full_optimization)) { 1249169689Skan return 1; // case 2 or case 3 1250169689Skan } 1251169689Skan return 2; // case 4 (tiered) 1252169689Skan#endif 1253169689Skan} 1254169689Skan 1255169689Skan#if INCLUDE_ALL_GCS 1256169689Skanstatic void disable_adaptive_size_policy(const char* collector_name) { 1257169689Skan if (UseAdaptiveSizePolicy) { 1258169689Skan if (FLAG_IS_CMDLINE(UseAdaptiveSizePolicy)) { 1259169689Skan warning("disabling UseAdaptiveSizePolicy; it is incompatible with %s.", 1260169689Skan collector_name); 1261169689Skan } 1262169689Skan FLAG_SET_DEFAULT(UseAdaptiveSizePolicy, false); 1263169689Skan } 1264169689Skan} 1265169689Skan 1266169689Skanvoid Arguments::set_parnew_gc_flags() { 1267169689Skan assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC && !UseG1GC, 1268169689Skan "control point invariant"); 1269169689Skan assert(UseConcMarkSweepGC, "CMS is expected to be on here"); 1270169689Skan assert(UseParNewGC, "ParNew should always be used with CMS"); 1271169689Skan 1272169689Skan if (FLAG_IS_DEFAULT(ParallelGCThreads)) { 1273169689Skan FLAG_SET_DEFAULT(ParallelGCThreads, Abstract_VM_Version::parallel_worker_threads()); 1274169689Skan assert(ParallelGCThreads > 0, "We should always have at least one thread by default"); 1275169689Skan } else if (ParallelGCThreads == 0) { 1276169689Skan jio_fprintf(defaultStream::error_stream(), 1277169689Skan "The ParNew GC can not be combined with -XX:ParallelGCThreads=0\n"); 1278169689Skan vm_exit(1); 1279169689Skan } 1280169689Skan 1281169689Skan // By default YoungPLABSize and OldPLABSize are set to 4096 and 1024 respectively, 1282169689Skan // these settings are default for Parallel Scavenger. For ParNew+Tenured configuration 1283169689Skan // we set them to 1024 and 1024. 1284169689Skan // See CR 6362902. 1285169689Skan if (FLAG_IS_DEFAULT(YoungPLABSize)) { 1286169689Skan FLAG_SET_DEFAULT(YoungPLABSize, (intx)1024); 1287169689Skan } 1288169689Skan if (FLAG_IS_DEFAULT(OldPLABSize)) { 1289169689Skan FLAG_SET_DEFAULT(OldPLABSize, (intx)1024); 1290169689Skan } 1291169689Skan 1292169689Skan // When using compressed oops, we use local overflow stacks, 1293169689Skan // rather than using a global overflow list chained through 1294169689Skan // the klass word of the object's pre-image. 1295169689Skan if (UseCompressedOops && !ParGCUseLocalOverflow) { 1296169689Skan if (!FLAG_IS_DEFAULT(ParGCUseLocalOverflow)) { 1297169689Skan warning("Forcing +ParGCUseLocalOverflow: needed if using compressed references"); 1298169689Skan } 1299169689Skan FLAG_SET_DEFAULT(ParGCUseLocalOverflow, true); 1300169689Skan } 1301169689Skan assert(ParGCUseLocalOverflow || !UseCompressedOops, "Error"); 1302169689Skan} 1303169689Skan 1304169689Skan// Adjust some sizes to suit CMS and/or ParNew needs; these work well on 1305169689Skan// sparc/solaris for certain applications, but would gain from 1306169689Skan// further optimization and tuning efforts, and would almost 1307169689Skan// certainly gain from analysis of platform and environment. 1308169689Skanvoid Arguments::set_cms_and_parnew_gc_flags() { 1309169689Skan assert(!UseSerialGC && !UseParallelOldGC && !UseParallelGC, "Error"); 1310 assert(UseConcMarkSweepGC, "CMS is expected to be on here"); 1311 assert(UseParNewGC, "ParNew should always be used with CMS"); 1312 1313 // Turn off AdaptiveSizePolicy by default for cms until it is complete. 1314 disable_adaptive_size_policy("UseConcMarkSweepGC"); 1315 1316 set_parnew_gc_flags(); 1317 1318 size_t max_heap = align_size_down(MaxHeapSize, 1319 CardTableRS::ct_max_alignment_constraint()); 1320 1321 // Now make adjustments for CMS 1322 intx tenuring_default = (intx)6; 1323 size_t young_gen_per_worker = CMSYoungGenPerWorker; 1324 1325 // Preferred young gen size for "short" pauses: 1326 // upper bound depends on # of threads and NewRatio. 1327 const size_t preferred_max_new_size_unaligned = 1328 MIN2(max_heap/(NewRatio+1), ScaleForWordSize(young_gen_per_worker * ParallelGCThreads)); 1329 size_t preferred_max_new_size = 1330 align_size_up(preferred_max_new_size_unaligned, os::vm_page_size()); 1331 1332 // Unless explicitly requested otherwise, size young gen 1333 // for "short" pauses ~ CMSYoungGenPerWorker*ParallelGCThreads 1334 1335 // If either MaxNewSize or NewRatio is set on the command line, 1336 // assume the user is trying to set the size of the young gen. 1337 if (FLAG_IS_DEFAULT(MaxNewSize) && FLAG_IS_DEFAULT(NewRatio)) { 1338 1339 // Set MaxNewSize to our calculated preferred_max_new_size unless 1340 // NewSize was set on the command line and it is larger than 1341 // preferred_max_new_size. 1342 if (!FLAG_IS_DEFAULT(NewSize)) { // NewSize explicitly set at command-line 1343 FLAG_SET_ERGO(size_t, MaxNewSize, MAX2(NewSize, preferred_max_new_size)); 1344 } else { 1345 FLAG_SET_ERGO(size_t, MaxNewSize, preferred_max_new_size); 1346 } 1347 if (PrintGCDetails && Verbose) { 1348 // Too early to use gclog_or_tty 1349 tty->print_cr("CMS ergo set MaxNewSize: " SIZE_FORMAT, MaxNewSize); 1350 } 1351 1352 // Code along this path potentially sets NewSize and OldSize 1353 if (PrintGCDetails && Verbose) { 1354 // Too early to use gclog_or_tty 1355 tty->print_cr("CMS set min_heap_size: " SIZE_FORMAT 1356 " initial_heap_size: " SIZE_FORMAT 1357 " max_heap: " SIZE_FORMAT, 1358 min_heap_size(), InitialHeapSize, max_heap); 1359 } 1360 size_t min_new = preferred_max_new_size; 1361 if (FLAG_IS_CMDLINE(NewSize)) { 1362 min_new = NewSize; 1363 } 1364 if (max_heap > min_new && min_heap_size() > min_new) { 1365 // Unless explicitly requested otherwise, make young gen 1366 // at least min_new, and at most preferred_max_new_size. 1367 if (FLAG_IS_DEFAULT(NewSize)) { 1368 FLAG_SET_ERGO(size_t, NewSize, MAX2(NewSize, min_new)); 1369 FLAG_SET_ERGO(size_t, NewSize, MIN2(preferred_max_new_size, NewSize)); 1370 if (PrintGCDetails && Verbose) { 1371 // Too early to use gclog_or_tty 1372 tty->print_cr("CMS ergo set NewSize: " SIZE_FORMAT, NewSize); 1373 } 1374 } 1375 // Unless explicitly requested otherwise, size old gen 1376 // so it's NewRatio x of NewSize. 1377 if (FLAG_IS_DEFAULT(OldSize)) { 1378 if (max_heap > NewSize) { 1379 FLAG_SET_ERGO(size_t, OldSize, MIN2(NewRatio*NewSize, max_heap - NewSize)); 1380 if (PrintGCDetails && Verbose) { 1381 // Too early to use gclog_or_tty 1382 tty->print_cr("CMS ergo set OldSize: " SIZE_FORMAT, OldSize); 1383 } 1384 } 1385 } 1386 } 1387 } 1388 // Unless explicitly requested otherwise, definitely 1389 // promote all objects surviving "tenuring_default" scavenges. 1390 if (FLAG_IS_DEFAULT(MaxTenuringThreshold) && 1391 FLAG_IS_DEFAULT(SurvivorRatio)) { 1392 FLAG_SET_ERGO(uintx, MaxTenuringThreshold, tenuring_default); 1393 } 1394 // If we decided above (or user explicitly requested) 1395 // `promote all' (via MaxTenuringThreshold := 0), 1396 // prefer minuscule survivor spaces so as not to waste 1397 // space for (non-existent) survivors 1398 if (FLAG_IS_DEFAULT(SurvivorRatio) && MaxTenuringThreshold == 0) { 1399 FLAG_SET_ERGO(uintx, SurvivorRatio, MAX2((uintx)1024, SurvivorRatio)); 1400 } 1401 1402 // OldPLABSize is interpreted in CMS as not the size of the PLAB in words, 1403 // but rather the number of free blocks of a given size that are used when 1404 // replenishing the local per-worker free list caches. 1405 if (FLAG_IS_DEFAULT(OldPLABSize)) { 1406 if (!FLAG_IS_DEFAULT(ResizeOldPLAB) && !ResizeOldPLAB) { 1407 // OldPLAB sizing manually turned off: Use a larger default setting, 1408 // unless it was manually specified. This is because a too-low value 1409 // will slow down scavenges. 1410 FLAG_SET_ERGO(size_t, OldPLABSize, CFLS_LAB::_default_static_old_plab_size); // default value before 6631166 1411 } else { 1412 FLAG_SET_DEFAULT(OldPLABSize, CFLS_LAB::_default_dynamic_old_plab_size); // old CMSParPromoteBlocksToClaim default 1413 } 1414 } 1415 1416 // If either of the static initialization defaults have changed, note this 1417 // modification. 1418 if (!FLAG_IS_DEFAULT(OldPLABSize) || !FLAG_IS_DEFAULT(OldPLABWeight)) { 1419 CFLS_LAB::modify_initialization(OldPLABSize, OldPLABWeight); 1420 } 1421 1422 if (!ClassUnloading) { 1423 FLAG_SET_CMDLINE(bool, CMSClassUnloadingEnabled, false); 1424 FLAG_SET_CMDLINE(bool, ExplicitGCInvokesConcurrentAndUnloadsClasses, false); 1425 } 1426 1427 if (PrintGCDetails && Verbose) { 1428 tty->print_cr("MarkStackSize: %uk MarkStackSizeMax: %uk", 1429 (unsigned int) (MarkStackSize / K), (uint) (MarkStackSizeMax / K)); 1430 tty->print_cr("ConcGCThreads: %u", ConcGCThreads); 1431 } 1432} 1433#endif // INCLUDE_ALL_GCS 1434 1435void set_object_alignment() { 1436 // Object alignment. 1437 assert(is_power_of_2(ObjectAlignmentInBytes), "ObjectAlignmentInBytes must be power of 2"); 1438 MinObjAlignmentInBytes = ObjectAlignmentInBytes; 1439 assert(MinObjAlignmentInBytes >= HeapWordsPerLong * HeapWordSize, "ObjectAlignmentInBytes value is too small"); 1440 MinObjAlignment = MinObjAlignmentInBytes / HeapWordSize; 1441 assert(MinObjAlignmentInBytes == MinObjAlignment * HeapWordSize, "ObjectAlignmentInBytes value is incorrect"); 1442 MinObjAlignmentInBytesMask = MinObjAlignmentInBytes - 1; 1443 1444 LogMinObjAlignmentInBytes = exact_log2(ObjectAlignmentInBytes); 1445 LogMinObjAlignment = LogMinObjAlignmentInBytes - LogHeapWordSize; 1446 1447 // Oop encoding heap max 1448 OopEncodingHeapMax = (uint64_t(max_juint) + 1) << LogMinObjAlignmentInBytes; 1449 1450 if (SurvivorAlignmentInBytes == 0) { 1451 SurvivorAlignmentInBytes = ObjectAlignmentInBytes; 1452 } 1453 1454#if INCLUDE_ALL_GCS 1455 // Set CMS global values 1456 CompactibleFreeListSpace::set_cms_values(); 1457#endif // INCLUDE_ALL_GCS 1458} 1459 1460size_t Arguments::max_heap_for_compressed_oops() { 1461 // Avoid sign flip. 1462 assert(OopEncodingHeapMax > (uint64_t)os::vm_page_size(), "Unusual page size"); 1463 // We need to fit both the NULL page and the heap into the memory budget, while 1464 // keeping alignment constraints of the heap. To guarantee the latter, as the 1465 // NULL page is located before the heap, we pad the NULL page to the conservative 1466 // maximum alignment that the GC may ever impose upon the heap. 1467 size_t displacement_due_to_null_page = align_size_up_(os::vm_page_size(), 1468 _conservative_max_heap_alignment); 1469 1470 LP64_ONLY(return OopEncodingHeapMax - displacement_due_to_null_page); 1471 NOT_LP64(ShouldNotReachHere(); return 0); 1472} 1473 1474bool Arguments::should_auto_select_low_pause_collector() { 1475 if (UseAutoGCSelectPolicy && 1476 !FLAG_IS_DEFAULT(MaxGCPauseMillis) && 1477 (MaxGCPauseMillis <= AutoGCSelectPauseMillis)) { 1478 if (PrintGCDetails) { 1479 // Cannot use gclog_or_tty yet. 1480 tty->print_cr("Automatic selection of the low pause collector" 1481 " based on pause goal of %d (ms)", (int) MaxGCPauseMillis); 1482 } 1483 return true; 1484 } 1485 return false; 1486} 1487 1488void Arguments::set_use_compressed_oops() { 1489#ifndef ZERO 1490#ifdef _LP64 1491 // MaxHeapSize is not set up properly at this point, but 1492 // the only value that can override MaxHeapSize if we are 1493 // to use UseCompressedOops is InitialHeapSize. 1494 size_t max_heap_size = MAX2(MaxHeapSize, InitialHeapSize); 1495 1496 if (max_heap_size <= max_heap_for_compressed_oops()) { 1497#if !defined(COMPILER1) || defined(TIERED) 1498 if (FLAG_IS_DEFAULT(UseCompressedOops)) { 1499 FLAG_SET_ERGO(bool, UseCompressedOops, true); 1500 } 1501#endif 1502 } else { 1503 if (UseCompressedOops && !FLAG_IS_DEFAULT(UseCompressedOops)) { 1504 warning("Max heap size too large for Compressed Oops"); 1505 FLAG_SET_DEFAULT(UseCompressedOops, false); 1506 FLAG_SET_DEFAULT(UseCompressedClassPointers, false); 1507 } 1508 } 1509#endif // _LP64 1510#endif // ZERO 1511} 1512 1513 1514// NOTE: set_use_compressed_klass_ptrs() must be called after calling 1515// set_use_compressed_oops(). 1516void Arguments::set_use_compressed_klass_ptrs() { 1517#ifndef ZERO 1518#ifdef _LP64 1519 // UseCompressedOops must be on for UseCompressedClassPointers to be on. 1520 if (!UseCompressedOops) { 1521 if (UseCompressedClassPointers) { 1522 warning("UseCompressedClassPointers requires UseCompressedOops"); 1523 } 1524 FLAG_SET_DEFAULT(UseCompressedClassPointers, false); 1525 } else { 1526 // Turn on UseCompressedClassPointers too 1527 if (FLAG_IS_DEFAULT(UseCompressedClassPointers)) { 1528 FLAG_SET_ERGO(bool, UseCompressedClassPointers, true); 1529 } 1530 // Check the CompressedClassSpaceSize to make sure we use compressed klass ptrs. 1531 if (UseCompressedClassPointers) { 1532 if (CompressedClassSpaceSize > KlassEncodingMetaspaceMax) { 1533 warning("CompressedClassSpaceSize is too large for UseCompressedClassPointers"); 1534 FLAG_SET_DEFAULT(UseCompressedClassPointers, false); 1535 } 1536 } 1537 } 1538#endif // _LP64 1539#endif // !ZERO 1540} 1541 1542void Arguments::set_conservative_max_heap_alignment() { 1543 // The conservative maximum required alignment for the heap is the maximum of 1544 // the alignments imposed by several sources: any requirements from the heap 1545 // itself, the collector policy and the maximum page size we may run the VM 1546 // with. 1547 size_t heap_alignment = GenCollectedHeap::conservative_max_heap_alignment(); 1548#if INCLUDE_ALL_GCS 1549 if (UseParallelGC) { 1550 heap_alignment = ParallelScavengeHeap::conservative_max_heap_alignment(); 1551 } else if (UseG1GC) { 1552 heap_alignment = G1CollectedHeap::conservative_max_heap_alignment(); 1553 } 1554#endif // INCLUDE_ALL_GCS 1555 _conservative_max_heap_alignment = MAX4(heap_alignment, 1556 (size_t)os::vm_allocation_granularity(), 1557 os::max_page_size(), 1558 CollectorPolicy::compute_heap_alignment()); 1559} 1560 1561void Arguments::select_gc_ergonomically() { 1562 if (os::is_server_class_machine()) { 1563 if (should_auto_select_low_pause_collector()) { 1564 FLAG_SET_ERGO(bool, UseConcMarkSweepGC, true); 1565 } else { 1566#if defined(JAVASE_EMBEDDED) 1567 FLAG_SET_ERGO(bool, UseParallelGC, true); 1568#else 1569 FLAG_SET_ERGO(bool, UseG1GC, true); 1570#endif 1571 } 1572 } else { 1573 FLAG_SET_ERGO(bool, UseSerialGC, true); 1574 } 1575} 1576 1577void Arguments::select_gc() { 1578 if (!gc_selected()) { 1579 select_gc_ergonomically(); 1580 guarantee(gc_selected(), "No GC selected"); 1581 } 1582} 1583 1584void Arguments::set_ergonomics_flags() { 1585 select_gc(); 1586 1587#ifdef COMPILER2 1588 // Shared spaces work fine with other GCs but causes bytecode rewriting 1589 // to be disabled, which hurts interpreter performance and decreases 1590 // server performance. When -server is specified, keep the default off 1591 // unless it is asked for. Future work: either add bytecode rewriting 1592 // at link time, or rewrite bytecodes in non-shared methods. 1593 if (!DumpSharedSpaces && !RequireSharedSpaces && 1594 (FLAG_IS_DEFAULT(UseSharedSpaces) || !UseSharedSpaces)) { 1595 no_shared_spaces("COMPILER2 default: -Xshare:auto | off, have to manually setup to on."); 1596 } 1597#endif 1598 1599 set_conservative_max_heap_alignment(); 1600 1601#ifndef ZERO 1602#ifdef _LP64 1603 set_use_compressed_oops(); 1604 1605 // set_use_compressed_klass_ptrs() must be called after calling 1606 // set_use_compressed_oops(). 1607 set_use_compressed_klass_ptrs(); 1608 1609 // Also checks that certain machines are slower with compressed oops 1610 // in vm_version initialization code. 1611#endif // _LP64 1612#endif // !ZERO 1613 1614 // Set up runtime image flags. 1615 set_runtime_image_flags(); 1616 1617 CodeCacheExtensions::set_ergonomics_flags(); 1618} 1619 1620void Arguments::set_parallel_gc_flags() { 1621 assert(UseParallelGC || UseParallelOldGC, "Error"); 1622 // Enable ParallelOld unless it was explicitly disabled (cmd line or rc file). 1623 if (FLAG_IS_DEFAULT(UseParallelOldGC)) { 1624 FLAG_SET_DEFAULT(UseParallelOldGC, true); 1625 } 1626 FLAG_SET_DEFAULT(UseParallelGC, true); 1627 1628 // If no heap maximum was requested explicitly, use some reasonable fraction 1629 // of the physical memory, up to a maximum of 1GB. 1630 FLAG_SET_DEFAULT(ParallelGCThreads, 1631 Abstract_VM_Version::parallel_worker_threads()); 1632 if (ParallelGCThreads == 0) { 1633 jio_fprintf(defaultStream::error_stream(), 1634 "The Parallel GC can not be combined with -XX:ParallelGCThreads=0\n"); 1635 vm_exit(1); 1636 } 1637 1638 if (UseAdaptiveSizePolicy) { 1639 // We don't want to limit adaptive heap sizing's freedom to adjust the heap 1640 // unless the user actually sets these flags. 1641 if (FLAG_IS_DEFAULT(MinHeapFreeRatio)) { 1642 FLAG_SET_DEFAULT(MinHeapFreeRatio, 0); 1643 _min_heap_free_ratio = MinHeapFreeRatio; 1644 } 1645 if (FLAG_IS_DEFAULT(MaxHeapFreeRatio)) { 1646 FLAG_SET_DEFAULT(MaxHeapFreeRatio, 100); 1647 _max_heap_free_ratio = MaxHeapFreeRatio; 1648 } 1649 } 1650 1651 // If InitialSurvivorRatio or MinSurvivorRatio were not specified, but the 1652 // SurvivorRatio has been set, reset their default values to SurvivorRatio + 1653 // 2. By doing this we make SurvivorRatio also work for Parallel Scavenger. 1654 // See CR 6362902 for details. 1655 if (!FLAG_IS_DEFAULT(SurvivorRatio)) { 1656 if (FLAG_IS_DEFAULT(InitialSurvivorRatio)) { 1657 FLAG_SET_DEFAULT(InitialSurvivorRatio, SurvivorRatio + 2); 1658 } 1659 if (FLAG_IS_DEFAULT(MinSurvivorRatio)) { 1660 FLAG_SET_DEFAULT(MinSurvivorRatio, SurvivorRatio + 2); 1661 } 1662 } 1663 1664 if (UseParallelOldGC) { 1665 // Par compact uses lower default values since they are treated as 1666 // minimums. These are different defaults because of the different 1667 // interpretation and are not ergonomically set. 1668 if (FLAG_IS_DEFAULT(MarkSweepDeadRatio)) { 1669 FLAG_SET_DEFAULT(MarkSweepDeadRatio, 1); 1670 } 1671 } 1672} 1673 1674void Arguments::set_g1_gc_flags() { 1675 assert(UseG1GC, "Error"); 1676#ifdef COMPILER1 1677 FastTLABRefill = false; 1678#endif 1679 FLAG_SET_DEFAULT(ParallelGCThreads, Abstract_VM_Version::parallel_worker_threads()); 1680 if (ParallelGCThreads == 0) { 1681 assert(!FLAG_IS_DEFAULT(ParallelGCThreads), "The default value for ParallelGCThreads should not be 0."); 1682 vm_exit_during_initialization("The flag -XX:+UseG1GC can not be combined with -XX:ParallelGCThreads=0", NULL); 1683 } 1684 1685#if INCLUDE_ALL_GCS 1686 if (G1ConcRefinementThreads == 0) { 1687 FLAG_SET_DEFAULT(G1ConcRefinementThreads, ParallelGCThreads); 1688 } 1689#endif 1690 1691 // MarkStackSize will be set (if it hasn't been set by the user) 1692 // when concurrent marking is initialized. 1693 // Its value will be based upon the number of parallel marking threads. 1694 // But we do set the maximum mark stack size here. 1695 if (FLAG_IS_DEFAULT(MarkStackSizeMax)) { 1696 FLAG_SET_DEFAULT(MarkStackSizeMax, 128 * TASKQUEUE_SIZE); 1697 } 1698 1699 if (FLAG_IS_DEFAULT(GCTimeRatio) || GCTimeRatio == 0) { 1700 // In G1, we want the default GC overhead goal to be higher than 1701 // say in PS. So we set it here to 10%. Otherwise the heap might 1702 // be expanded more aggressively than we would like it to. In 1703 // fact, even 10% seems to not be high enough in some cases 1704 // (especially small GC stress tests that the main thing they do 1705 // is allocation). We might consider increase it further. 1706 FLAG_SET_DEFAULT(GCTimeRatio, 9); 1707 } 1708 1709 if (PrintGCDetails && Verbose) { 1710 tty->print_cr("MarkStackSize: %uk MarkStackSizeMax: %uk", 1711 (unsigned int) (MarkStackSize / K), (uint) (MarkStackSizeMax / K)); 1712 tty->print_cr("ConcGCThreads: %u", ConcGCThreads); 1713 } 1714} 1715 1716#if !INCLUDE_ALL_GCS 1717#ifdef ASSERT 1718static bool verify_serial_gc_flags() { 1719 return (UseSerialGC && 1720 !(UseParNewGC || (UseConcMarkSweepGC) || UseG1GC || 1721 UseParallelGC || UseParallelOldGC)); 1722} 1723#endif // ASSERT 1724#endif // INCLUDE_ALL_GCS 1725 1726void Arguments::set_gc_specific_flags() { 1727#if INCLUDE_ALL_GCS 1728 // Set per-collector flags 1729 if (UseParallelGC || UseParallelOldGC) { 1730 set_parallel_gc_flags(); 1731 } else if (UseConcMarkSweepGC) { 1732 set_cms_and_parnew_gc_flags(); 1733 } else if (UseG1GC) { 1734 set_g1_gc_flags(); 1735 } 1736 check_deprecated_gc_flags(); 1737 if (AssumeMP && !UseSerialGC) { 1738 if (FLAG_IS_DEFAULT(ParallelGCThreads) && ParallelGCThreads == 1) { 1739 warning("If the number of processors is expected to increase from one, then" 1740 " you should configure the number of parallel GC threads appropriately" 1741 " using -XX:ParallelGCThreads=N"); 1742 } 1743 } 1744 if (MinHeapFreeRatio == 100) { 1745 // Keeping the heap 100% free is hard ;-) so limit it to 99%. 1746 FLAG_SET_ERGO(uintx, MinHeapFreeRatio, 99); 1747 } 1748#else // INCLUDE_ALL_GCS 1749 assert(verify_serial_gc_flags(), "SerialGC unset"); 1750#endif // INCLUDE_ALL_GCS 1751} 1752 1753julong Arguments::limit_by_allocatable_memory(julong limit) { 1754 julong max_allocatable; 1755 julong result = limit; 1756 if (os::has_allocatable_memory_limit(&max_allocatable)) { 1757 result = MIN2(result, max_allocatable / MaxVirtMemFraction); 1758 } 1759 return result; 1760} 1761 1762// Use static initialization to get the default before parsing 1763static const size_t DefaultHeapBaseMinAddress = HeapBaseMinAddress; 1764 1765void Arguments::set_heap_size() { 1766 if (!FLAG_IS_DEFAULT(DefaultMaxRAMFraction)) { 1767 // Deprecated flag 1768 FLAG_SET_CMDLINE(uintx, MaxRAMFraction, DefaultMaxRAMFraction); 1769 } 1770 1771 const julong phys_mem = 1772 FLAG_IS_DEFAULT(MaxRAM) ? MIN2(os::physical_memory(), (julong)MaxRAM) 1773 : (julong)MaxRAM; 1774 1775 // If the maximum heap size has not been set with -Xmx, 1776 // then set it as fraction of the size of physical memory, 1777 // respecting the maximum and minimum sizes of the heap. 1778 if (FLAG_IS_DEFAULT(MaxHeapSize)) { 1779 julong reasonable_max = phys_mem / MaxRAMFraction; 1780 1781 if (phys_mem <= MaxHeapSize * MinRAMFraction) { 1782 // Small physical memory, so use a minimum fraction of it for the heap 1783 reasonable_max = phys_mem / MinRAMFraction; 1784 } else { 1785 // Not-small physical memory, so require a heap at least 1786 // as large as MaxHeapSize 1787 reasonable_max = MAX2(reasonable_max, (julong)MaxHeapSize); 1788 } 1789 if (!FLAG_IS_DEFAULT(ErgoHeapSizeLimit) && ErgoHeapSizeLimit != 0) { 1790 // Limit the heap size to ErgoHeapSizeLimit 1791 reasonable_max = MIN2(reasonable_max, (julong)ErgoHeapSizeLimit); 1792 } 1793 if (UseCompressedOops) { 1794 // Limit the heap size to the maximum possible when using compressed oops 1795 julong max_coop_heap = (julong)max_heap_for_compressed_oops(); 1796 1797 // HeapBaseMinAddress can be greater than default but not less than. 1798 if (!FLAG_IS_DEFAULT(HeapBaseMinAddress)) { 1799 if (HeapBaseMinAddress < DefaultHeapBaseMinAddress) { 1800 // matches compressed oops printing flags 1801 if (PrintCompressedOopsMode || (PrintMiscellaneous && Verbose)) { 1802 jio_fprintf(defaultStream::error_stream(), 1803 "HeapBaseMinAddress must be at least " SIZE_FORMAT 1804 " (" SIZE_FORMAT "G) which is greater than value given " 1805 SIZE_FORMAT "\n", 1806 DefaultHeapBaseMinAddress, 1807 DefaultHeapBaseMinAddress/G, 1808 HeapBaseMinAddress); 1809 } 1810 FLAG_SET_ERGO(size_t, HeapBaseMinAddress, DefaultHeapBaseMinAddress); 1811 } 1812 } 1813 1814 if (HeapBaseMinAddress + MaxHeapSize < max_coop_heap) { 1815 // Heap should be above HeapBaseMinAddress to get zero based compressed oops 1816 // but it should be not less than default MaxHeapSize. 1817 max_coop_heap -= HeapBaseMinAddress; 1818 } 1819 reasonable_max = MIN2(reasonable_max, max_coop_heap); 1820 } 1821 reasonable_max = limit_by_allocatable_memory(reasonable_max); 1822 1823 if (!FLAG_IS_DEFAULT(InitialHeapSize)) { 1824 // An initial heap size was specified on the command line, 1825 // so be sure that the maximum size is consistent. Done 1826 // after call to limit_by_allocatable_memory because that 1827 // method might reduce the allocation size. 1828 reasonable_max = MAX2(reasonable_max, (julong)InitialHeapSize); 1829 } 1830 1831 if (PrintGCDetails && Verbose) { 1832 // Cannot use gclog_or_tty yet. 1833 tty->print_cr(" Maximum heap size " SIZE_FORMAT, (size_t) reasonable_max); 1834 } 1835 FLAG_SET_ERGO(size_t, MaxHeapSize, (size_t)reasonable_max); 1836 } 1837 1838 // If the minimum or initial heap_size have not been set or requested to be set 1839 // ergonomically, set them accordingly. 1840 if (InitialHeapSize == 0 || min_heap_size() == 0) { 1841 julong reasonable_minimum = (julong)(OldSize + NewSize); 1842 1843 reasonable_minimum = MIN2(reasonable_minimum, (julong)MaxHeapSize); 1844 1845 reasonable_minimum = limit_by_allocatable_memory(reasonable_minimum); 1846 1847 if (InitialHeapSize == 0) { 1848 julong reasonable_initial = phys_mem / InitialRAMFraction; 1849 1850 reasonable_initial = MAX3(reasonable_initial, reasonable_minimum, (julong)min_heap_size()); 1851 reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize); 1852 1853 reasonable_initial = limit_by_allocatable_memory(reasonable_initial); 1854 1855 if (PrintGCDetails && Verbose) { 1856 // Cannot use gclog_or_tty yet. 1857 tty->print_cr(" Initial heap size " SIZE_FORMAT, (size_t)reasonable_initial); 1858 } 1859 FLAG_SET_ERGO(size_t, InitialHeapSize, (size_t)reasonable_initial); 1860 } 1861 // If the minimum heap size has not been set (via -Xms), 1862 // synchronize with InitialHeapSize to avoid errors with the default value. 1863 if (min_heap_size() == 0) { 1864 set_min_heap_size(MIN2((size_t)reasonable_minimum, InitialHeapSize)); 1865 if (PrintGCDetails && Verbose) { 1866 // Cannot use gclog_or_tty yet. 1867 tty->print_cr(" Minimum heap size " SIZE_FORMAT, min_heap_size()); 1868 } 1869 } 1870 } 1871} 1872 1873 // Set up runtime image flags 1874void Arguments::set_runtime_image_flags() { 1875#ifdef _LP64 1876 // Memory map image file by default on 64 bit machines. 1877 if (FLAG_IS_DEFAULT(MemoryMapImage)) { 1878 FLAG_SET_ERGO(bool, MemoryMapImage, true); 1879 } 1880#endif 1881} 1882 1883// This must be called after ergonomics. 1884void Arguments::set_bytecode_flags() { 1885 if (!RewriteBytecodes) { 1886 FLAG_SET_DEFAULT(RewriteFrequentPairs, false); 1887 } 1888} 1889 1890// Aggressive optimization flags -XX:+AggressiveOpts 1891void Arguments::set_aggressive_opts_flags() { 1892#ifdef COMPILER2 1893 if (AggressiveUnboxing) { 1894 if (FLAG_IS_DEFAULT(EliminateAutoBox)) { 1895 FLAG_SET_DEFAULT(EliminateAutoBox, true); 1896 } else if (!EliminateAutoBox) { 1897 // warning("AggressiveUnboxing is disabled because EliminateAutoBox is disabled"); 1898 AggressiveUnboxing = false; 1899 } 1900 if (FLAG_IS_DEFAULT(DoEscapeAnalysis)) { 1901 FLAG_SET_DEFAULT(DoEscapeAnalysis, true); 1902 } else if (!DoEscapeAnalysis) { 1903 // warning("AggressiveUnboxing is disabled because DoEscapeAnalysis is disabled"); 1904 AggressiveUnboxing = false; 1905 } 1906 } 1907 if (AggressiveOpts || !FLAG_IS_DEFAULT(AutoBoxCacheMax)) { 1908 if (FLAG_IS_DEFAULT(EliminateAutoBox)) { 1909 FLAG_SET_DEFAULT(EliminateAutoBox, true); 1910 } 1911 if (FLAG_IS_DEFAULT(AutoBoxCacheMax)) { 1912 FLAG_SET_DEFAULT(AutoBoxCacheMax, 20000); 1913 } 1914 1915 // Feed the cache size setting into the JDK 1916 char buffer[1024]; 1917 sprintf(buffer, "java.lang.Integer.IntegerCache.high=" INTX_FORMAT, AutoBoxCacheMax); 1918 add_property(buffer); 1919 } 1920 if (AggressiveOpts && FLAG_IS_DEFAULT(BiasedLockingStartupDelay)) { 1921 FLAG_SET_DEFAULT(BiasedLockingStartupDelay, 500); 1922 } 1923#endif 1924 1925 if (AggressiveOpts) { 1926// Sample flag setting code 1927// if (FLAG_IS_DEFAULT(EliminateZeroing)) { 1928// FLAG_SET_DEFAULT(EliminateZeroing, true); 1929// } 1930 } 1931} 1932 1933//=========================================================================================================== 1934// Parsing of java.compiler property 1935 1936void Arguments::process_java_compiler_argument(char* arg) { 1937 // For backwards compatibility, Djava.compiler=NONE or "" 1938 // causes us to switch to -Xint mode UNLESS -Xdebug 1939 // is also specified. 1940 if (strlen(arg) == 0 || strcasecmp(arg, "NONE") == 0) { 1941 set_java_compiler(true); // "-Djava.compiler[=...]" most recently seen. 1942 } 1943} 1944 1945void Arguments::process_java_launcher_argument(const char* launcher, void* extra_info) { 1946 _sun_java_launcher = os::strdup_check_oom(launcher); 1947} 1948 1949bool Arguments::created_by_java_launcher() { 1950 assert(_sun_java_launcher != NULL, "property must have value"); 1951 return strcmp(DEFAULT_JAVA_LAUNCHER, _sun_java_launcher) != 0; 1952} 1953 1954bool Arguments::sun_java_launcher_is_altjvm() { 1955 return _sun_java_launcher_is_altjvm; 1956} 1957 1958//=========================================================================================================== 1959// Parsing of main arguments 1960 1961// check if do gclog rotation 1962// +UseGCLogFileRotation is a must, 1963// no gc log rotation when log file not supplied or 1964// NumberOfGCLogFiles is 0 1965void check_gclog_consistency() { 1966 if (UseGCLogFileRotation) { 1967 if ((Arguments::gc_log_filename() == NULL) || (NumberOfGCLogFiles == 0)) { 1968 jio_fprintf(defaultStream::output_stream(), 1969 "To enable GC log rotation, use -Xloggc:<filename> -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=<num_of_files>\n" 1970 "where num_of_file > 0\n" 1971 "GC log rotation is turned off\n"); 1972 UseGCLogFileRotation = false; 1973 } 1974 } 1975 1976 if (UseGCLogFileRotation && (GCLogFileSize != 0) && (GCLogFileSize < 8*K)) { 1977 if (FLAG_SET_CMDLINE(size_t, GCLogFileSize, 8*K) == Flag::SUCCESS) { 1978 jio_fprintf(defaultStream::output_stream(), 1979 "GCLogFileSize changed to minimum 8K\n"); 1980 } 1981 } 1982} 1983 1984// This function is called for -Xloggc:<filename>, it can be used 1985// to check if a given file name(or string) conforms to the following 1986// specification: 1987// A valid string only contains "[A-Z][a-z][0-9].-_%[p|t]" 1988// %p and %t only allowed once. We only limit usage of filename not path 1989bool is_filename_valid(const char *file_name) { 1990 const char* p = file_name; 1991 char file_sep = os::file_separator()[0]; 1992 const char* cp; 1993 // skip prefix path 1994 for (cp = file_name; *cp != '\0'; cp++) { 1995 if (*cp == '/' || *cp == file_sep) { 1996 p = cp + 1; 1997 } 1998 } 1999 2000 int count_p = 0; 2001 int count_t = 0; 2002 while (*p != '\0') { 2003 if ((*p >= '0' && *p <= '9') || 2004 (*p >= 'A' && *p <= 'Z') || 2005 (*p >= 'a' && *p <= 'z') || 2006 *p == '-' || 2007 *p == '_' || 2008 *p == '.') { 2009 p++; 2010 continue; 2011 } 2012 if (*p == '%') { 2013 if(*(p + 1) == 'p') { 2014 p += 2; 2015 count_p ++; 2016 continue; 2017 } 2018 if (*(p + 1) == 't') { 2019 p += 2; 2020 count_t ++; 2021 continue; 2022 } 2023 } 2024 return false; 2025 } 2026 return count_p < 2 && count_t < 2; 2027} 2028 2029// Check consistency of GC selection 2030bool Arguments::check_gc_consistency() { 2031 check_gclog_consistency(); 2032 // Ensure that the user has not selected conflicting sets 2033 // of collectors. 2034 uint i = 0; 2035 if (UseSerialGC) i++; 2036 if (UseConcMarkSweepGC) i++; 2037 if (UseParallelGC || UseParallelOldGC) i++; 2038 if (UseG1GC) i++; 2039 if (i > 1) { 2040 jio_fprintf(defaultStream::error_stream(), 2041 "Conflicting collector combinations in option list; " 2042 "please refer to the release notes for the combinations " 2043 "allowed\n"); 2044 return false; 2045 } 2046 2047 if (UseConcMarkSweepGC && !UseParNewGC) { 2048 jio_fprintf(defaultStream::error_stream(), 2049 "It is not possible to combine the DefNew young collector with the CMS collector.\n"); 2050 return false; 2051 } 2052 2053 if (UseParNewGC && !UseConcMarkSweepGC) { 2054 jio_fprintf(defaultStream::error_stream(), 2055 "It is not possible to combine the ParNew young collector with any collector other than CMS.\n"); 2056 return false; 2057 } 2058 2059 return true; 2060} 2061 2062void Arguments::check_deprecated_gc_flags() { 2063 if (FLAG_IS_CMDLINE(UseParNewGC)) { 2064 warning("The UseParNewGC flag is deprecated and will likely be removed in a future release"); 2065 } 2066 if (FLAG_IS_CMDLINE(MaxGCMinorPauseMillis)) { 2067 warning("Using MaxGCMinorPauseMillis as minor pause goal is deprecated" 2068 "and will likely be removed in future release"); 2069 } 2070 if (FLAG_IS_CMDLINE(DefaultMaxRAMFraction)) { 2071 warning("DefaultMaxRAMFraction is deprecated and will likely be removed in a future release. " 2072 "Use MaxRAMFraction instead."); 2073 } 2074} 2075 2076// Check the consistency of vm_init_args 2077bool Arguments::check_vm_args_consistency() { 2078 // Method for adding checks for flag consistency. 2079 // The intent is to warn the user of all possible conflicts, 2080 // before returning an error. 2081 // Note: Needs platform-dependent factoring. 2082 bool status = true; 2083 2084 if (TLABRefillWasteFraction == 0) { 2085 jio_fprintf(defaultStream::error_stream(), 2086 "TLABRefillWasteFraction should be a denominator, " 2087 "not " SIZE_FORMAT "\n", 2088 TLABRefillWasteFraction); 2089 status = false; 2090 } 2091 2092 if (FullGCALot && FLAG_IS_DEFAULT(MarkSweepAlwaysCompactCount)) { 2093 MarkSweepAlwaysCompactCount = 1; // Move objects every gc. 2094 } 2095 2096 if (UseParallelOldGC && ParallelOldGCSplitALot) { 2097 // Settings to encourage splitting. 2098 if (!FLAG_IS_CMDLINE(NewRatio)) { 2099 if (FLAG_SET_CMDLINE(uintx, NewRatio, 2) != Flag::SUCCESS) { 2100 status = false; 2101 } 2102 } 2103 if (!FLAG_IS_CMDLINE(ScavengeBeforeFullGC)) { 2104 if (FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false) != Flag::SUCCESS) { 2105 status = false; 2106 } 2107 } 2108 } 2109 2110 if (!(UseParallelGC || UseParallelOldGC) && FLAG_IS_DEFAULT(ScavengeBeforeFullGC)) { 2111 FLAG_SET_DEFAULT(ScavengeBeforeFullGC, false); 2112 } 2113 2114 if (GCTimeLimit == 100) { 2115 // Turn off gc-overhead-limit-exceeded checks 2116 FLAG_SET_DEFAULT(UseGCOverheadLimit, false); 2117 } 2118 2119 status = status && check_gc_consistency(); 2120 2121 // CMS space iteration, which FLSVerifyAllHeapreferences entails, 2122 // insists that we hold the requisite locks so that the iteration is 2123 // MT-safe. For the verification at start-up and shut-down, we don't 2124 // yet have a good way of acquiring and releasing these locks, 2125 // which are not visible at the CollectedHeap level. We want to 2126 // be able to acquire these locks and then do the iteration rather 2127 // than just disable the lock verification. This will be fixed under 2128 // bug 4788986. 2129 if (UseConcMarkSweepGC && FLSVerifyAllHeapReferences) { 2130 if (VerifyDuringStartup) { 2131 warning("Heap verification at start-up disabled " 2132 "(due to current incompatibility with FLSVerifyAllHeapReferences)"); 2133 VerifyDuringStartup = false; // Disable verification at start-up 2134 } 2135 2136 if (VerifyBeforeExit) { 2137 warning("Heap verification at shutdown disabled " 2138 "(due to current incompatibility with FLSVerifyAllHeapReferences)"); 2139 VerifyBeforeExit = false; // Disable verification at shutdown 2140 } 2141 } 2142 2143 // Note: only executed in non-PRODUCT mode 2144 if (!UseAsyncConcMarkSweepGC && 2145 (ExplicitGCInvokesConcurrent || 2146 ExplicitGCInvokesConcurrentAndUnloadsClasses)) { 2147 jio_fprintf(defaultStream::error_stream(), 2148 "error: +ExplicitGCInvokesConcurrent[AndUnloadsClasses] conflicts" 2149 " with -UseAsyncConcMarkSweepGC"); 2150 status = false; 2151 } 2152 2153 if (PrintNMTStatistics) { 2154#if INCLUDE_NMT 2155 if (MemTracker::tracking_level() == NMT_off) { 2156#endif // INCLUDE_NMT 2157 warning("PrintNMTStatistics is disabled, because native memory tracking is not enabled"); 2158 PrintNMTStatistics = false; 2159#if INCLUDE_NMT 2160 } 2161#endif 2162 } 2163 2164 // Check lower bounds of the code cache 2165 // Template Interpreter code is approximately 3X larger in debug builds. 2166 uint min_code_cache_size = CodeCacheMinimumUseSpace DEBUG_ONLY(* 3); 2167 if (InitialCodeCacheSize < (uintx)os::vm_page_size()) { 2168 jio_fprintf(defaultStream::error_stream(), 2169 "Invalid InitialCodeCacheSize=%dK. Must be at least %dK.\n", InitialCodeCacheSize/K, 2170 os::vm_page_size()/K); 2171 status = false; 2172 } else if (ReservedCodeCacheSize < InitialCodeCacheSize) { 2173 jio_fprintf(defaultStream::error_stream(), 2174 "Invalid ReservedCodeCacheSize: %dK. Must be at least InitialCodeCacheSize=%dK.\n", 2175 ReservedCodeCacheSize/K, InitialCodeCacheSize/K); 2176 status = false; 2177 } else if (ReservedCodeCacheSize < min_code_cache_size) { 2178 jio_fprintf(defaultStream::error_stream(), 2179 "Invalid ReservedCodeCacheSize=%dK. Must be at least %uK.\n", ReservedCodeCacheSize/K, 2180 min_code_cache_size/K); 2181 status = false; 2182 } else if (ReservedCodeCacheSize > CODE_CACHE_SIZE_LIMIT) { 2183 // Code cache size larger than CODE_CACHE_SIZE_LIMIT is not supported. 2184 jio_fprintf(defaultStream::error_stream(), 2185 "Invalid ReservedCodeCacheSize=%dM. Must be at most %uM.\n", ReservedCodeCacheSize/M, 2186 CODE_CACHE_SIZE_LIMIT/M); 2187 status = false; 2188 } else if (NonNMethodCodeHeapSize < min_code_cache_size){ 2189 jio_fprintf(defaultStream::error_stream(), 2190 "Invalid NonNMethodCodeHeapSize=%dK. Must be at least %uK.\n", NonNMethodCodeHeapSize/K, 2191 min_code_cache_size/K); 2192 status = false; 2193 } else if ((!FLAG_IS_DEFAULT(NonNMethodCodeHeapSize) || !FLAG_IS_DEFAULT(ProfiledCodeHeapSize) || !FLAG_IS_DEFAULT(NonProfiledCodeHeapSize)) 2194 && (NonNMethodCodeHeapSize + NonProfiledCodeHeapSize + ProfiledCodeHeapSize) != ReservedCodeCacheSize) { 2195 jio_fprintf(defaultStream::error_stream(), 2196 "Invalid code heap sizes: NonNMethodCodeHeapSize(%dK) + ProfiledCodeHeapSize(%dK) + NonProfiledCodeHeapSize(%dK) = %dK. Must be equal to ReservedCodeCacheSize = %uK.\n", 2197 NonNMethodCodeHeapSize/K, ProfiledCodeHeapSize/K, NonProfiledCodeHeapSize/K, 2198 (NonNMethodCodeHeapSize + ProfiledCodeHeapSize + NonProfiledCodeHeapSize)/K, ReservedCodeCacheSize/K); 2199 status = false; 2200 } 2201 2202 int min_number_of_compiler_threads = get_min_number_of_compiler_threads(); 2203 // The default CICompilerCount's value is CI_COMPILER_COUNT. 2204 assert(min_number_of_compiler_threads <= CI_COMPILER_COUNT, "minimum should be less or equal default number"); 2205 2206 if (!FLAG_IS_DEFAULT(CICompilerCount) && !FLAG_IS_DEFAULT(CICompilerCountPerCPU) && CICompilerCountPerCPU) { 2207 warning("The VM option CICompilerCountPerCPU overrides CICompilerCount."); 2208 } 2209 2210 return status; 2211} 2212 2213bool Arguments::is_bad_option(const JavaVMOption* option, jboolean ignore, 2214 const char* option_type) { 2215 if (ignore) return false; 2216 2217 const char* spacer = " "; 2218 if (option_type == NULL) { 2219 option_type = ++spacer; // Set both to the empty string. 2220 } 2221 2222 if (os::obsolete_option(option)) { 2223 jio_fprintf(defaultStream::error_stream(), 2224 "Obsolete %s%soption: %s\n", option_type, spacer, 2225 option->optionString); 2226 return false; 2227 } else { 2228 jio_fprintf(defaultStream::error_stream(), 2229 "Unrecognized %s%soption: %s\n", option_type, spacer, 2230 option->optionString); 2231 return true; 2232 } 2233} 2234 2235static const char* user_assertion_options[] = { 2236 "-da", "-ea", "-disableassertions", "-enableassertions", 0 2237}; 2238 2239static const char* system_assertion_options[] = { 2240 "-dsa", "-esa", "-disablesystemassertions", "-enablesystemassertions", 0 2241}; 2242 2243bool Arguments::parse_uintx(const char* value, 2244 uintx* uintx_arg, 2245 uintx min_size) { 2246 2247 // Check the sign first since atomull() parses only unsigned values. 2248 bool value_is_positive = !(*value == '-'); 2249 2250 if (value_is_positive) { 2251 julong n; 2252 bool good_return = atomull(value, &n); 2253 if (good_return) { 2254 bool above_minimum = n >= min_size; 2255 bool value_is_too_large = n > max_uintx; 2256 2257 if (above_minimum && !value_is_too_large) { 2258 *uintx_arg = n; 2259 return true; 2260 } 2261 } 2262 } 2263 return false; 2264} 2265 2266Arguments::ArgsRange Arguments::parse_memory_size(const char* s, 2267 julong* long_arg, 2268 julong min_size) { 2269 if (!atomull(s, long_arg)) return arg_unreadable; 2270 return check_memory_size(*long_arg, min_size); 2271} 2272 2273// Parse JavaVMInitArgs structure 2274 2275jint Arguments::parse_vm_init_args(const JavaVMInitArgs *java_tool_options_args, 2276 const JavaVMInitArgs *java_options_args, 2277 const JavaVMInitArgs *cmd_line_args) { 2278 // For components of the system classpath. 2279 SysClassPath scp(Arguments::get_sysclasspath()); 2280 bool scp_assembly_required = false; 2281 2282 // Save default settings for some mode flags 2283 Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods; 2284 Arguments::_UseOnStackReplacement = UseOnStackReplacement; 2285 Arguments::_ClipInlining = ClipInlining; 2286 Arguments::_BackgroundCompilation = BackgroundCompilation; 2287 if (TieredCompilation) { 2288 Arguments::_Tier3InvokeNotifyFreqLog = Tier3InvokeNotifyFreqLog; 2289 Arguments::_Tier4InvocationThreshold = Tier4InvocationThreshold; 2290 } 2291 2292 // Setup flags for mixed which is the default 2293 set_mode_flags(_mixed); 2294 2295 // Parse args structure generated from JAVA_TOOL_OPTIONS environment 2296 // variable (if present). 2297 jint result = parse_each_vm_init_arg( 2298 java_tool_options_args, &scp, &scp_assembly_required, Flag::ENVIRON_VAR); 2299 if (result != JNI_OK) { 2300 return result; 2301 } 2302 2303 // Parse args structure generated from the command line flags. 2304 result = parse_each_vm_init_arg(cmd_line_args, &scp, &scp_assembly_required, 2305 Flag::COMMAND_LINE); 2306 if (result != JNI_OK) { 2307 return result; 2308 } 2309 2310 // Parse args structure generated from the _JAVA_OPTIONS environment 2311 // variable (if present) (mimics classic VM) 2312 result = parse_each_vm_init_arg( 2313 java_options_args, &scp, &scp_assembly_required, Flag::ENVIRON_VAR); 2314 if (result != JNI_OK) { 2315 return result; 2316 } 2317 2318 // Do final processing now that all arguments have been parsed 2319 result = finalize_vm_init_args(&scp, scp_assembly_required); 2320 if (result != JNI_OK) { 2321 return result; 2322 } 2323 2324 return JNI_OK; 2325} 2326 2327// Checks if name in command-line argument -agent{lib,path}:name[=options] 2328// represents a valid HPROF of JDWP agent. is_path==true denotes that we 2329// are dealing with -agentpath (case where name is a path), otherwise with 2330// -agentlib 2331bool valid_hprof_or_jdwp_agent(char *name, bool is_path) { 2332 char *_name; 2333 const char *_hprof = "hprof", *_jdwp = "jdwp"; 2334 size_t _len_hprof, _len_jdwp, _len_prefix; 2335 2336 if (is_path) { 2337 if ((_name = strrchr(name, (int) *os::file_separator())) == NULL) { 2338 return false; 2339 } 2340 2341 _name++; // skip past last path separator 2342 _len_prefix = strlen(JNI_LIB_PREFIX); 2343 2344 if (strncmp(_name, JNI_LIB_PREFIX, _len_prefix) != 0) { 2345 return false; 2346 } 2347 2348 _name += _len_prefix; 2349 _len_hprof = strlen(_hprof); 2350 _len_jdwp = strlen(_jdwp); 2351 2352 if (strncmp(_name, _hprof, _len_hprof) == 0) { 2353 _name += _len_hprof; 2354 } 2355 else if (strncmp(_name, _jdwp, _len_jdwp) == 0) { 2356 _name += _len_jdwp; 2357 } 2358 else { 2359 return false; 2360 } 2361 2362 if (strcmp(_name, JNI_LIB_SUFFIX) != 0) { 2363 return false; 2364 } 2365 2366 return true; 2367 } 2368 2369 if (strcmp(name, _hprof) == 0 || strcmp(name, _jdwp) == 0) { 2370 return true; 2371 } 2372 2373 return false; 2374} 2375 2376jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, 2377 SysClassPath* scp_p, 2378 bool* scp_assembly_required_p, 2379 Flag::Flags origin) { 2380 // Remaining part of option string 2381 const char* tail; 2382 2383 // iterate over arguments 2384 for (int index = 0; index < args->nOptions; index++) { 2385 bool is_absolute_path = false; // for -agentpath vs -agentlib 2386 2387 const JavaVMOption* option = args->options + index; 2388 2389 if (!match_option(option, "-Djava.class.path", &tail) && 2390 !match_option(option, "-Dsun.java.command", &tail) && 2391 !match_option(option, "-Dsun.java.launcher", &tail)) { 2392 2393 // add all jvm options to the jvm_args string. This string 2394 // is used later to set the java.vm.args PerfData string constant. 2395 // the -Djava.class.path and the -Dsun.java.command options are 2396 // omitted from jvm_args string as each have their own PerfData 2397 // string constant object. 2398 build_jvm_args(option->optionString); 2399 } 2400 2401 // -verbose:[class/gc/jni] 2402 if (match_option(option, "-verbose", &tail)) { 2403 if (!strcmp(tail, ":class") || !strcmp(tail, "")) { 2404 if (FLAG_SET_CMDLINE(bool, TraceClassLoading, true) != Flag::SUCCESS) { 2405 return JNI_EINVAL; 2406 } 2407 if (FLAG_SET_CMDLINE(bool, TraceClassUnloading, true) != Flag::SUCCESS) { 2408 return JNI_EINVAL; 2409 } 2410 } else if (!strcmp(tail, ":gc")) { 2411 if (FLAG_SET_CMDLINE(bool, PrintGC, true) != Flag::SUCCESS) { 2412 return JNI_EINVAL; 2413 } 2414 } else if (!strcmp(tail, ":jni")) { 2415 if (FLAG_SET_CMDLINE(bool, PrintJNIResolving, true) != Flag::SUCCESS) { 2416 return JNI_EINVAL; 2417 } 2418 } 2419 // -da / -ea / -disableassertions / -enableassertions 2420 // These accept an optional class/package name separated by a colon, e.g., 2421 // -da:java.lang.Thread. 2422 } else if (match_option(option, user_assertion_options, &tail, true)) { 2423 bool enable = option->optionString[1] == 'e'; // char after '-' is 'e' 2424 if (*tail == '\0') { 2425 JavaAssertions::setUserClassDefault(enable); 2426 } else { 2427 assert(*tail == ':', "bogus match by match_option()"); 2428 JavaAssertions::addOption(tail + 1, enable); 2429 } 2430 // -dsa / -esa / -disablesystemassertions / -enablesystemassertions 2431 } else if (match_option(option, system_assertion_options, &tail, false)) { 2432 bool enable = option->optionString[1] == 'e'; // char after '-' is 'e' 2433 JavaAssertions::setSystemClassDefault(enable); 2434 // -bootclasspath: 2435 } else if (match_option(option, "-Xbootclasspath:", &tail)) { 2436 scp_p->reset_path(tail); 2437 *scp_assembly_required_p = true; 2438 // -bootclasspath/a: 2439 } else if (match_option(option, "-Xbootclasspath/a:", &tail)) { 2440 scp_p->add_suffix(tail); 2441 *scp_assembly_required_p = true; 2442 // -bootclasspath/p: 2443 } else if (match_option(option, "-Xbootclasspath/p:", &tail)) { 2444 scp_p->add_prefix(tail); 2445 *scp_assembly_required_p = true; 2446 // -Xrun 2447 } else if (match_option(option, "-Xrun", &tail)) { 2448 if (tail != NULL) { 2449 const char* pos = strchr(tail, ':'); 2450 size_t len = (pos == NULL) ? strlen(tail) : pos - tail; 2451 char* name = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len + 1, mtInternal), tail, len); 2452 name[len] = '\0'; 2453 2454 char *options = NULL; 2455 if(pos != NULL) { 2456 size_t len2 = strlen(pos+1) + 1; // options start after ':'. Final zero must be copied. 2457 options = (char*)memcpy(NEW_C_HEAP_ARRAY(char, len2, mtInternal), pos+1, len2); 2458 } 2459#if !INCLUDE_JVMTI 2460 if ((strcmp(name, "hprof") == 0) || (strcmp(name, "jdwp") == 0)) { 2461 jio_fprintf(defaultStream::error_stream(), 2462 "Profiling and debugging agents are not supported in this VM\n"); 2463 return JNI_ERR; 2464 } 2465#endif // !INCLUDE_JVMTI 2466 add_init_library(name, options); 2467 } 2468 // -agentlib and -agentpath 2469 } else if (match_option(option, "-agentlib:", &tail) || 2470 (is_absolute_path = match_option(option, "-agentpath:", &tail))) { 2471 if(tail != NULL) { 2472 const char* pos = strchr(tail, '='); 2473 size_t len = (pos == NULL) ? strlen(tail) : pos - tail; 2474 char* name = strncpy(NEW_C_HEAP_ARRAY(char, len + 1, mtInternal), tail, len); 2475 name[len] = '\0'; 2476 2477 char *options = NULL; 2478 if(pos != NULL) { 2479 options = os::strdup_check_oom(pos + 1, mtInternal); 2480 } 2481#if !INCLUDE_JVMTI 2482 if (valid_hprof_or_jdwp_agent(name, is_absolute_path)) { 2483 jio_fprintf(defaultStream::error_stream(), 2484 "Profiling and debugging agents are not supported in this VM\n"); 2485 return JNI_ERR; 2486 } 2487#endif // !INCLUDE_JVMTI 2488 add_init_agent(name, options, is_absolute_path); 2489 } 2490 // -javaagent 2491 } else if (match_option(option, "-javaagent:", &tail)) { 2492#if !INCLUDE_JVMTI 2493 jio_fprintf(defaultStream::error_stream(), 2494 "Instrumentation agents are not supported in this VM\n"); 2495 return JNI_ERR; 2496#else 2497 if(tail != NULL) { 2498 char *options = strcpy(NEW_C_HEAP_ARRAY(char, strlen(tail) + 1, mtInternal), tail); 2499 add_init_agent("instrument", options, false); 2500 } 2501#endif // !INCLUDE_JVMTI 2502 // -Xnoclassgc 2503 } else if (match_option(option, "-Xnoclassgc")) { 2504 if (FLAG_SET_CMDLINE(bool, ClassUnloading, false) != Flag::SUCCESS) { 2505 return JNI_EINVAL; 2506 } 2507 // -Xconcgc 2508 } else if (match_option(option, "-Xconcgc")) { 2509 if (FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, true) != Flag::SUCCESS) { 2510 return JNI_EINVAL; 2511 } 2512 // -Xnoconcgc 2513 } else if (match_option(option, "-Xnoconcgc")) { 2514 if (FLAG_SET_CMDLINE(bool, UseConcMarkSweepGC, false) != Flag::SUCCESS) { 2515 return JNI_EINVAL; 2516 } 2517 // -Xbatch 2518 } else if (match_option(option, "-Xbatch")) { 2519 if (FLAG_SET_CMDLINE(bool, BackgroundCompilation, false) != Flag::SUCCESS) { 2520 return JNI_EINVAL; 2521 } 2522 // -Xmn for compatibility with other JVM vendors 2523 } else if (match_option(option, "-Xmn", &tail)) { 2524 julong long_initial_young_size = 0; 2525 ArgsRange errcode = parse_memory_size(tail, &long_initial_young_size, 1); 2526 if (errcode != arg_in_range) { 2527 jio_fprintf(defaultStream::error_stream(), 2528 "Invalid initial young generation size: %s\n", option->optionString); 2529 describe_range_error(errcode); 2530 return JNI_EINVAL; 2531 } 2532 if (FLAG_SET_CMDLINE(size_t, MaxNewSize, (size_t)long_initial_young_size) != Flag::SUCCESS) { 2533 return JNI_EINVAL; 2534 } 2535 if (FLAG_SET_CMDLINE(size_t, NewSize, (size_t)long_initial_young_size) != Flag::SUCCESS) { 2536 return JNI_EINVAL; 2537 } 2538 // -Xms 2539 } else if (match_option(option, "-Xms", &tail)) { 2540 julong long_initial_heap_size = 0; 2541 // an initial heap size of 0 means automatically determine 2542 ArgsRange errcode = parse_memory_size(tail, &long_initial_heap_size, 0); 2543 if (errcode != arg_in_range) { 2544 jio_fprintf(defaultStream::error_stream(), 2545 "Invalid initial heap size: %s\n", option->optionString); 2546 describe_range_error(errcode); 2547 return JNI_EINVAL; 2548 } 2549 set_min_heap_size((size_t)long_initial_heap_size); 2550 // Currently the minimum size and the initial heap sizes are the same. 2551 // Can be overridden with -XX:InitialHeapSize. 2552 if (FLAG_SET_CMDLINE(size_t, InitialHeapSize, (size_t)long_initial_heap_size) != Flag::SUCCESS) { 2553 return JNI_EINVAL; 2554 } 2555 // -Xmx 2556 } else if (match_option(option, "-Xmx", &tail) || match_option(option, "-XX:MaxHeapSize=", &tail)) { 2557 julong long_max_heap_size = 0; 2558 ArgsRange errcode = parse_memory_size(tail, &long_max_heap_size, 1); 2559 if (errcode != arg_in_range) { 2560 jio_fprintf(defaultStream::error_stream(), 2561 "Invalid maximum heap size: %s\n", option->optionString); 2562 describe_range_error(errcode); 2563 return JNI_EINVAL; 2564 } 2565 if (FLAG_SET_CMDLINE(size_t, MaxHeapSize, (size_t)long_max_heap_size) != Flag::SUCCESS) { 2566 return JNI_EINVAL; 2567 } 2568 // Xmaxf 2569 } else if (match_option(option, "-Xmaxf", &tail)) { 2570 char* err; 2571 int maxf = (int)(strtod(tail, &err) * 100); 2572 if (*err != '\0' || *tail == '\0') { 2573 jio_fprintf(defaultStream::error_stream(), 2574 "Bad max heap free percentage size: %s\n", 2575 option->optionString); 2576 return JNI_EINVAL; 2577 } else { 2578 if (FLAG_SET_CMDLINE(uintx, MaxHeapFreeRatio, maxf) != Flag::SUCCESS) { 2579 return JNI_EINVAL; 2580 } 2581 } 2582 // Xminf 2583 } else if (match_option(option, "-Xminf", &tail)) { 2584 char* err; 2585 int minf = (int)(strtod(tail, &err) * 100); 2586 if (*err != '\0' || *tail == '\0') { 2587 jio_fprintf(defaultStream::error_stream(), 2588 "Bad min heap free percentage size: %s\n", 2589 option->optionString); 2590 return JNI_EINVAL; 2591 } else { 2592 if (FLAG_SET_CMDLINE(uintx, MinHeapFreeRatio, minf) != Flag::SUCCESS) { 2593 return JNI_EINVAL; 2594 } 2595 } 2596 // -Xss 2597 } else if (match_option(option, "-Xss", &tail)) { 2598 julong long_ThreadStackSize = 0; 2599 ArgsRange errcode = parse_memory_size(tail, &long_ThreadStackSize, 1000); 2600 if (errcode != arg_in_range) { 2601 jio_fprintf(defaultStream::error_stream(), 2602 "Invalid thread stack size: %s\n", option->optionString); 2603 describe_range_error(errcode); 2604 return JNI_EINVAL; 2605 } 2606 // Internally track ThreadStackSize in units of 1024 bytes. 2607 if (FLAG_SET_CMDLINE(intx, ThreadStackSize, 2608 round_to((int)long_ThreadStackSize, K) / K) != Flag::SUCCESS) { 2609 return JNI_EINVAL; 2610 } 2611 // -Xoss, -Xsqnopause, -Xoptimize, -Xboundthreads 2612 } else if (match_option(option, "-Xoss", &tail) || 2613 match_option(option, "-Xsqnopause") || 2614 match_option(option, "-Xoptimize") || 2615 match_option(option, "-Xboundthreads")) { 2616 // All these options are deprecated in JDK 9 and will be removed in a future release 2617 char version[256]; 2618 JDK_Version::jdk(9).to_string(version, sizeof(version)); 2619 warning("ignoring option %s; support was removed in %s", option->optionString, version); 2620 } else if (match_option(option, "-XX:CodeCacheExpansionSize=", &tail)) { 2621 julong long_CodeCacheExpansionSize = 0; 2622 ArgsRange errcode = parse_memory_size(tail, &long_CodeCacheExpansionSize, os::vm_page_size()); 2623 if (errcode != arg_in_range) { 2624 jio_fprintf(defaultStream::error_stream(), 2625 "Invalid argument: %s. Must be at least %luK.\n", option->optionString, 2626 os::vm_page_size()/K); 2627 return JNI_EINVAL; 2628 } 2629 if (FLAG_SET_CMDLINE(uintx, CodeCacheExpansionSize, (uintx)long_CodeCacheExpansionSize) != Flag::SUCCESS) { 2630 return JNI_EINVAL; 2631 } 2632 } else if (match_option(option, "-Xmaxjitcodesize", &tail) || 2633 match_option(option, "-XX:ReservedCodeCacheSize=", &tail)) { 2634 julong long_ReservedCodeCacheSize = 0; 2635 2636 ArgsRange errcode = parse_memory_size(tail, &long_ReservedCodeCacheSize, 1); 2637 if (errcode != arg_in_range) { 2638 jio_fprintf(defaultStream::error_stream(), 2639 "Invalid maximum code cache size: %s.\n", option->optionString); 2640 return JNI_EINVAL; 2641 } 2642 if (FLAG_SET_CMDLINE(uintx, ReservedCodeCacheSize, (uintx)long_ReservedCodeCacheSize) != Flag::SUCCESS) { 2643 return JNI_EINVAL; 2644 } 2645 // -XX:NonNMethodCodeHeapSize= 2646 } else if (match_option(option, "-XX:NonNMethodCodeHeapSize=", &tail)) { 2647 julong long_NonNMethodCodeHeapSize = 0; 2648 2649 ArgsRange errcode = parse_memory_size(tail, &long_NonNMethodCodeHeapSize, 1); 2650 if (errcode != arg_in_range) { 2651 jio_fprintf(defaultStream::error_stream(), 2652 "Invalid maximum non-nmethod code heap size: %s.\n", option->optionString); 2653 return JNI_EINVAL; 2654 } 2655 if (FLAG_SET_CMDLINE(uintx, NonNMethodCodeHeapSize, (uintx)long_NonNMethodCodeHeapSize) != Flag::SUCCESS) { 2656 return JNI_EINVAL; 2657 } 2658 // -XX:ProfiledCodeHeapSize= 2659 } else if (match_option(option, "-XX:ProfiledCodeHeapSize=", &tail)) { 2660 julong long_ProfiledCodeHeapSize = 0; 2661 2662 ArgsRange errcode = parse_memory_size(tail, &long_ProfiledCodeHeapSize, 1); 2663 if (errcode != arg_in_range) { 2664 jio_fprintf(defaultStream::error_stream(), 2665 "Invalid maximum profiled code heap size: %s.\n", option->optionString); 2666 return JNI_EINVAL; 2667 } 2668 if (FLAG_SET_CMDLINE(uintx, ProfiledCodeHeapSize, (uintx)long_ProfiledCodeHeapSize) != Flag::SUCCESS) { 2669 return JNI_EINVAL; 2670 } 2671 // -XX:NonProfiledCodeHeapSizee= 2672 } else if (match_option(option, "-XX:NonProfiledCodeHeapSize=", &tail)) { 2673 julong long_NonProfiledCodeHeapSize = 0; 2674 2675 ArgsRange errcode = parse_memory_size(tail, &long_NonProfiledCodeHeapSize, 1); 2676 if (errcode != arg_in_range) { 2677 jio_fprintf(defaultStream::error_stream(), 2678 "Invalid maximum non-profiled code heap size: %s.\n", option->optionString); 2679 return JNI_EINVAL; 2680 } 2681 if (FLAG_SET_CMDLINE(uintx, NonProfiledCodeHeapSize, (uintx)long_NonProfiledCodeHeapSize) != Flag::SUCCESS) { 2682 return JNI_EINVAL; 2683 } 2684 // -green 2685 } else if (match_option(option, "-green")) { 2686 jio_fprintf(defaultStream::error_stream(), 2687 "Green threads support not available\n"); 2688 return JNI_EINVAL; 2689 // -native 2690 } else if (match_option(option, "-native")) { 2691 // HotSpot always uses native threads, ignore silently for compatibility 2692 // -Xrs 2693 } else if (match_option(option, "-Xrs")) { 2694 // Classic/EVM option, new functionality 2695 if (FLAG_SET_CMDLINE(bool, ReduceSignalUsage, true) != Flag::SUCCESS) { 2696 return JNI_EINVAL; 2697 } 2698 } else if (match_option(option, "-Xusealtsigs")) { 2699 // change default internal VM signals used - lower case for back compat 2700 if (FLAG_SET_CMDLINE(bool, UseAltSigs, true) != Flag::SUCCESS) { 2701 return JNI_EINVAL; 2702 } 2703 // -Xprof 2704 } else if (match_option(option, "-Xprof")) { 2705#if INCLUDE_FPROF 2706 _has_profile = true; 2707#else // INCLUDE_FPROF 2708 jio_fprintf(defaultStream::error_stream(), 2709 "Flat profiling is not supported in this VM.\n"); 2710 return JNI_ERR; 2711#endif // INCLUDE_FPROF 2712 // -Xconcurrentio 2713 } else if (match_option(option, "-Xconcurrentio")) { 2714 if (FLAG_SET_CMDLINE(bool, UseLWPSynchronization, true) != Flag::SUCCESS) { 2715 return JNI_EINVAL; 2716 } 2717 if (FLAG_SET_CMDLINE(bool, BackgroundCompilation, false) != Flag::SUCCESS) { 2718 return JNI_EINVAL; 2719 } 2720 if (FLAG_SET_CMDLINE(intx, DeferThrSuspendLoopCount, 1) != Flag::SUCCESS) { 2721 return JNI_EINVAL; 2722 } 2723 if (FLAG_SET_CMDLINE(bool, UseTLAB, false) != Flag::SUCCESS) { 2724 return JNI_EINVAL; 2725 } 2726 if (FLAG_SET_CMDLINE(size_t, NewSizeThreadIncrease, 16 * K) != Flag::SUCCESS) { // 20Kb per thread added to new generation 2727 return JNI_EINVAL; 2728 } 2729 2730 // -Xinternalversion 2731 } else if (match_option(option, "-Xinternalversion")) { 2732 jio_fprintf(defaultStream::output_stream(), "%s\n", 2733 VM_Version::internal_vm_info_string()); 2734 vm_exit(0); 2735#ifndef PRODUCT 2736 // -Xprintflags 2737 } else if (match_option(option, "-Xprintflags")) { 2738 CommandLineFlags::printFlags(tty, false); 2739 vm_exit(0); 2740#endif 2741 // -D 2742 } else if (match_option(option, "-D", &tail)) { 2743 const char* value; 2744 if (match_option(option, "-Djava.endorsed.dirs=", &value) && 2745 *value!= '\0' && strcmp(value, "\"\"") != 0) { 2746 // abort if -Djava.endorsed.dirs is set 2747 jio_fprintf(defaultStream::output_stream(), 2748 "-Djava.endorsed.dirs=%s is not supported. Endorsed standards and standalone APIs\n" 2749 "in modular form will be supported via the concept of upgradeable modules.\n", value); 2750 return JNI_EINVAL; 2751 } 2752 if (match_option(option, "-Djava.ext.dirs=", &value) && 2753 *value != '\0' && strcmp(value, "\"\"") != 0) { 2754 // abort if -Djava.ext.dirs is set 2755 jio_fprintf(defaultStream::output_stream(), 2756 "-Djava.ext.dirs=%s is not supported. Use -classpath instead.\n", value); 2757 return JNI_EINVAL; 2758 } 2759 2760 if (!add_property(tail)) { 2761 return JNI_ENOMEM; 2762 } 2763 // Out of the box management support 2764 if (match_option(option, "-Dcom.sun.management", &tail)) { 2765#if INCLUDE_MANAGEMENT 2766 if (FLAG_SET_CMDLINE(bool, ManagementServer, true) != Flag::SUCCESS) { 2767 return JNI_EINVAL; 2768 } 2769#else 2770 jio_fprintf(defaultStream::output_stream(), 2771 "-Dcom.sun.management is not supported in this VM.\n"); 2772 return JNI_ERR; 2773#endif 2774 } 2775 // -Xint 2776 } else if (match_option(option, "-Xint")) { 2777 set_mode_flags(_int); 2778 // -Xmixed 2779 } else if (match_option(option, "-Xmixed")) { 2780 set_mode_flags(_mixed); 2781 // -Xcomp 2782 } else if (match_option(option, "-Xcomp")) { 2783 // for testing the compiler; turn off all flags that inhibit compilation 2784 set_mode_flags(_comp); 2785 // -Xshare:dump 2786 } else if (match_option(option, "-Xshare:dump")) { 2787 if (FLAG_SET_CMDLINE(bool, DumpSharedSpaces, true) != Flag::SUCCESS) { 2788 return JNI_EINVAL; 2789 } 2790 set_mode_flags(_int); // Prevent compilation, which creates objects 2791 // -Xshare:on 2792 } else if (match_option(option, "-Xshare:on")) { 2793 if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, true) != Flag::SUCCESS) { 2794 return JNI_EINVAL; 2795 } 2796 if (FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true) != Flag::SUCCESS) { 2797 return JNI_EINVAL; 2798 } 2799 // -Xshare:auto 2800 } else if (match_option(option, "-Xshare:auto")) { 2801 if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, true) != Flag::SUCCESS) { 2802 return JNI_EINVAL; 2803 } 2804 if (FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false) != Flag::SUCCESS) { 2805 return JNI_EINVAL; 2806 } 2807 // -Xshare:off 2808 } else if (match_option(option, "-Xshare:off")) { 2809 if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, false) != Flag::SUCCESS) { 2810 return JNI_EINVAL; 2811 } 2812 if (FLAG_SET_CMDLINE(bool, RequireSharedSpaces, false) != Flag::SUCCESS) { 2813 return JNI_EINVAL; 2814 } 2815 // -Xverify 2816 } else if (match_option(option, "-Xverify", &tail)) { 2817 if (strcmp(tail, ":all") == 0 || strcmp(tail, "") == 0) { 2818 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, true) != Flag::SUCCESS) { 2819 return JNI_EINVAL; 2820 } 2821 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true) != Flag::SUCCESS) { 2822 return JNI_EINVAL; 2823 } 2824 } else if (strcmp(tail, ":remote") == 0) { 2825 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false) != Flag::SUCCESS) { 2826 return JNI_EINVAL; 2827 } 2828 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, true) != Flag::SUCCESS) { 2829 return JNI_EINVAL; 2830 } 2831 } else if (strcmp(tail, ":none") == 0) { 2832 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationLocal, false) != Flag::SUCCESS) { 2833 return JNI_EINVAL; 2834 } 2835 if (FLAG_SET_CMDLINE(bool, BytecodeVerificationRemote, false) != Flag::SUCCESS) { 2836 return JNI_EINVAL; 2837 } 2838 } else if (is_bad_option(option, args->ignoreUnrecognized, "verification")) { 2839 return JNI_EINVAL; 2840 } 2841 // -Xdebug 2842 } else if (match_option(option, "-Xdebug")) { 2843 // note this flag has been used, then ignore 2844 set_xdebug_mode(true); 2845 // -Xnoagent 2846 } else if (match_option(option, "-Xnoagent")) { 2847 // For compatibility with classic. HotSpot refuses to load the old style agent.dll. 2848 } else if (match_option(option, "-Xloggc:", &tail)) { 2849 // Redirect GC output to the file. -Xloggc:<filename> 2850 // ostream_init_log(), when called will use this filename 2851 // to initialize a fileStream. 2852 _gc_log_filename = os::strdup_check_oom(tail); 2853 if (!is_filename_valid(_gc_log_filename)) { 2854 jio_fprintf(defaultStream::output_stream(), 2855 "Invalid file name for use with -Xloggc: Filename can only contain the " 2856 "characters [A-Z][a-z][0-9]-_.%%[p|t] but it has been %s\n" 2857 "Note %%p or %%t can only be used once\n", _gc_log_filename); 2858 return JNI_EINVAL; 2859 } 2860 if (FLAG_SET_CMDLINE(bool, PrintGC, true) != Flag::SUCCESS) { 2861 return JNI_EINVAL; 2862 } 2863 if (FLAG_SET_CMDLINE(bool, PrintGCTimeStamps, true) != Flag::SUCCESS) { 2864 return JNI_EINVAL; 2865 } 2866 // JNI hooks 2867 } else if (match_option(option, "-Xcheck", &tail)) { 2868 if (!strcmp(tail, ":jni")) { 2869#if !INCLUDE_JNI_CHECK 2870 warning("JNI CHECKING is not supported in this VM"); 2871#else 2872 CheckJNICalls = true; 2873#endif // INCLUDE_JNI_CHECK 2874 } else if (is_bad_option(option, args->ignoreUnrecognized, 2875 "check")) { 2876 return JNI_EINVAL; 2877 } 2878 } else if (match_option(option, "vfprintf")) { 2879 _vfprintf_hook = CAST_TO_FN_PTR(vfprintf_hook_t, option->extraInfo); 2880 } else if (match_option(option, "exit")) { 2881 _exit_hook = CAST_TO_FN_PTR(exit_hook_t, option->extraInfo); 2882 } else if (match_option(option, "abort")) { 2883 _abort_hook = CAST_TO_FN_PTR(abort_hook_t, option->extraInfo); 2884 // -XX:+AggressiveHeap 2885 } else if (match_option(option, "-XX:+AggressiveHeap")) { 2886 2887 // This option inspects the machine and attempts to set various 2888 // parameters to be optimal for long-running, memory allocation 2889 // intensive jobs. It is intended for machines with large 2890 // amounts of cpu and memory. 2891 2892 // initHeapSize is needed since _initial_heap_size is 4 bytes on a 32 bit 2893 // VM, but we may not be able to represent the total physical memory 2894 // available (like having 8gb of memory on a box but using a 32bit VM). 2895 // Thus, we need to make sure we're using a julong for intermediate 2896 // calculations. 2897 julong initHeapSize; 2898 julong total_memory = os::physical_memory(); 2899 2900 if (total_memory < (julong)256*M) { 2901 jio_fprintf(defaultStream::error_stream(), 2902 "You need at least 256mb of memory to use -XX:+AggressiveHeap\n"); 2903 vm_exit(1); 2904 } 2905 2906 // The heap size is half of available memory, or (at most) 2907 // all of possible memory less 160mb (leaving room for the OS 2908 // when using ISM). This is the maximum; because adaptive sizing 2909 // is turned on below, the actual space used may be smaller. 2910 2911 initHeapSize = MIN2(total_memory / (julong)2, 2912 total_memory - (julong)160*M); 2913 2914 initHeapSize = limit_by_allocatable_memory(initHeapSize); 2915 2916 if (FLAG_IS_DEFAULT(MaxHeapSize)) { 2917 if (FLAG_SET_CMDLINE(size_t, MaxHeapSize, initHeapSize) != Flag::SUCCESS) { 2918 return JNI_EINVAL; 2919 } 2920 if (FLAG_SET_CMDLINE(size_t, InitialHeapSize, initHeapSize) != Flag::SUCCESS) { 2921 return JNI_EINVAL; 2922 } 2923 // Currently the minimum size and the initial heap sizes are the same. 2924 set_min_heap_size(initHeapSize); 2925 } 2926 if (FLAG_IS_DEFAULT(NewSize)) { 2927 // Make the young generation 3/8ths of the total heap. 2928 if (FLAG_SET_CMDLINE(size_t, NewSize, 2929 ((julong)MaxHeapSize / (julong)8) * (julong)3) != Flag::SUCCESS) { 2930 return JNI_EINVAL; 2931 } 2932 if (FLAG_SET_CMDLINE(size_t, MaxNewSize, NewSize) != Flag::SUCCESS) { 2933 return JNI_EINVAL; 2934 } 2935 } 2936 2937#if !defined(_ALLBSD_SOURCE) && !defined(AIX) // UseLargePages is not yet supported on BSD and AIX. 2938 FLAG_SET_DEFAULT(UseLargePages, true); 2939#endif 2940 2941 // Increase some data structure sizes for efficiency 2942 if (FLAG_SET_CMDLINE(size_t, BaseFootPrintEstimate, MaxHeapSize) != Flag::SUCCESS) { 2943 return JNI_EINVAL; 2944 } 2945 if (FLAG_SET_CMDLINE(bool, ResizeTLAB, false) != Flag::SUCCESS) { 2946 return JNI_EINVAL; 2947 } 2948 if (FLAG_SET_CMDLINE(size_t, TLABSize, 256*K) != Flag::SUCCESS) { 2949 return JNI_EINVAL; 2950 } 2951 2952 // See the OldPLABSize comment below, but replace 'after promotion' 2953 // with 'after copying'. YoungPLABSize is the size of the survivor 2954 // space per-gc-thread buffers. The default is 4kw. 2955 if (FLAG_SET_CMDLINE(size_t, YoungPLABSize, 256*K) != Flag::SUCCESS) { // Note: this is in words 2956 return JNI_EINVAL; 2957 } 2958 2959 // OldPLABSize is the size of the buffers in the old gen that 2960 // UseParallelGC uses to promote live data that doesn't fit in the 2961 // survivor spaces. At any given time, there's one for each gc thread. 2962 // The default size is 1kw. These buffers are rarely used, since the 2963 // survivor spaces are usually big enough. For specjbb, however, there 2964 // are occasions when there's lots of live data in the young gen 2965 // and we end up promoting some of it. We don't have a definite 2966 // explanation for why bumping OldPLABSize helps, but the theory 2967 // is that a bigger PLAB results in retaining something like the 2968 // original allocation order after promotion, which improves mutator 2969 // locality. A minor effect may be that larger PLABs reduce the 2970 // number of PLAB allocation events during gc. The value of 8kw 2971 // was arrived at by experimenting with specjbb. 2972 if (FLAG_SET_CMDLINE(size_t, OldPLABSize, 8*K) != Flag::SUCCESS) { // Note: this is in words 2973 return JNI_EINVAL; 2974 } 2975 2976 // Enable parallel GC and adaptive generation sizing 2977 if (FLAG_SET_CMDLINE(bool, UseParallelGC, true) != Flag::SUCCESS) { 2978 return JNI_EINVAL; 2979 } 2980 FLAG_SET_DEFAULT(ParallelGCThreads, 2981 Abstract_VM_Version::parallel_worker_threads()); 2982 2983 // Encourage steady state memory management 2984 if (FLAG_SET_CMDLINE(uintx, ThresholdTolerance, 100) != Flag::SUCCESS) { 2985 return JNI_EINVAL; 2986 } 2987 2988 // This appears to improve mutator locality 2989 if (FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false) != Flag::SUCCESS) { 2990 return JNI_EINVAL; 2991 } 2992 2993 // Get around early Solaris scheduling bug 2994 // (affinity vs other jobs on system) 2995 // but disallow DR and offlining (5008695). 2996 if (FLAG_SET_CMDLINE(bool, BindGCTaskThreadsToCPUs, true) != Flag::SUCCESS) { 2997 return JNI_EINVAL; 2998 } 2999 3000 // Need to keep consistency of MaxTenuringThreshold and AlwaysTenure/NeverTenure; 3001 // and the last option wins. 3002 } else if (match_option(option, "-XX:+NeverTenure")) { 3003 if (FLAG_SET_CMDLINE(bool, NeverTenure, true) != Flag::SUCCESS) { 3004 return JNI_EINVAL; 3005 } 3006 if (FLAG_SET_CMDLINE(bool, AlwaysTenure, false) != Flag::SUCCESS) { 3007 return JNI_EINVAL; 3008 } 3009 if (FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, markOopDesc::max_age + 1) != Flag::SUCCESS) { 3010 return JNI_EINVAL; 3011 } 3012 } else if (match_option(option, "-XX:+AlwaysTenure")) { 3013 if (FLAG_SET_CMDLINE(bool, NeverTenure, false) != Flag::SUCCESS) { 3014 return JNI_EINVAL; 3015 } 3016 if (FLAG_SET_CMDLINE(bool, AlwaysTenure, true) != Flag::SUCCESS) { 3017 return JNI_EINVAL; 3018 } 3019 if (FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, 0) != Flag::SUCCESS) { 3020 return JNI_EINVAL; 3021 } 3022 } else if (match_option(option, "-XX:MaxTenuringThreshold=", &tail)) { 3023 uintx max_tenuring_thresh = 0; 3024 if (!parse_uintx(tail, &max_tenuring_thresh, 0)) { 3025 jio_fprintf(defaultStream::error_stream(), 3026 "Improperly specified VM option \'MaxTenuringThreshold=%s\'\n", tail); 3027 return JNI_EINVAL; 3028 } 3029 3030 if (FLAG_SET_CMDLINE(uintx, MaxTenuringThreshold, max_tenuring_thresh) != Flag::SUCCESS) { 3031 return JNI_EINVAL; 3032 } 3033 3034 if (MaxTenuringThreshold == 0) { 3035 if (FLAG_SET_CMDLINE(bool, NeverTenure, false) != Flag::SUCCESS) { 3036 return JNI_EINVAL; 3037 } 3038 if (FLAG_SET_CMDLINE(bool, AlwaysTenure, true) != Flag::SUCCESS) { 3039 return JNI_EINVAL; 3040 } 3041 } else { 3042 if (FLAG_SET_CMDLINE(bool, NeverTenure, false) != Flag::SUCCESS) { 3043 return JNI_EINVAL; 3044 } 3045 if (FLAG_SET_CMDLINE(bool, AlwaysTenure, false) != Flag::SUCCESS) { 3046 return JNI_EINVAL; 3047 } 3048 } 3049 } else if (match_option(option, "-XX:+DisplayVMOutputToStderr")) { 3050 if (FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, false) != Flag::SUCCESS) { 3051 return JNI_EINVAL; 3052 } 3053 if (FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, true) != Flag::SUCCESS) { 3054 return JNI_EINVAL; 3055 } 3056 } else if (match_option(option, "-XX:+DisplayVMOutputToStdout")) { 3057 if (FLAG_SET_CMDLINE(bool, DisplayVMOutputToStderr, false) != Flag::SUCCESS) { 3058 return JNI_EINVAL; 3059 } 3060 if (FLAG_SET_CMDLINE(bool, DisplayVMOutputToStdout, true) != Flag::SUCCESS) { 3061 return JNI_EINVAL; 3062 } 3063 } else if (match_option(option, "-XX:+ExtendedDTraceProbes")) { 3064#if defined(DTRACE_ENABLED) 3065 if (FLAG_SET_CMDLINE(bool, ExtendedDTraceProbes, true) != Flag::SUCCESS) { 3066 return JNI_EINVAL; 3067 } 3068 if (FLAG_SET_CMDLINE(bool, DTraceMethodProbes, true) != Flag::SUCCESS) { 3069 return JNI_EINVAL; 3070 } 3071 if (FLAG_SET_CMDLINE(bool, DTraceAllocProbes, true) != Flag::SUCCESS) { 3072 return JNI_EINVAL; 3073 } 3074 if (FLAG_SET_CMDLINE(bool, DTraceMonitorProbes, true) != Flag::SUCCESS) { 3075 return JNI_EINVAL; 3076 } 3077#else // defined(DTRACE_ENABLED) 3078 jio_fprintf(defaultStream::error_stream(), 3079 "ExtendedDTraceProbes flag is not applicable for this configuration\n"); 3080 return JNI_EINVAL; 3081#endif // defined(DTRACE_ENABLED) 3082#ifdef ASSERT 3083 } else if (match_option(option, "-XX:+FullGCALot")) { 3084 if (FLAG_SET_CMDLINE(bool, FullGCALot, true) != Flag::SUCCESS) { 3085 return JNI_EINVAL; 3086 } 3087 // disable scavenge before parallel mark-compact 3088 if (FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false) != Flag::SUCCESS) { 3089 return JNI_EINVAL; 3090 } 3091#endif 3092 } else if (match_option(option, "-XX:CMSMarkStackSize=", &tail) || 3093 match_option(option, "-XX:G1MarkStackSize=", &tail)) { 3094 julong stack_size = 0; 3095 ArgsRange errcode = parse_memory_size(tail, &stack_size, 1); 3096 if (errcode != arg_in_range) { 3097 jio_fprintf(defaultStream::error_stream(), 3098 "Invalid mark stack size: %s\n", option->optionString); 3099 describe_range_error(errcode); 3100 return JNI_EINVAL; 3101 } 3102 jio_fprintf(defaultStream::error_stream(), 3103 "Please use -XX:MarkStackSize in place of " 3104 "-XX:CMSMarkStackSize or -XX:G1MarkStackSize in the future\n"); 3105 if (FLAG_SET_CMDLINE(size_t, MarkStackSize, stack_size) != Flag::SUCCESS) { 3106 return JNI_EINVAL; 3107 } 3108 } else if (match_option(option, "-XX:CMSMarkStackSizeMax=", &tail)) { 3109 julong max_stack_size = 0; 3110 ArgsRange errcode = parse_memory_size(tail, &max_stack_size, 1); 3111 if (errcode != arg_in_range) { 3112 jio_fprintf(defaultStream::error_stream(), 3113 "Invalid maximum mark stack size: %s\n", 3114 option->optionString); 3115 describe_range_error(errcode); 3116 return JNI_EINVAL; 3117 } 3118 jio_fprintf(defaultStream::error_stream(), 3119 "Please use -XX:MarkStackSizeMax in place of " 3120 "-XX:CMSMarkStackSizeMax in the future\n"); 3121 if (FLAG_SET_CMDLINE(size_t, MarkStackSizeMax, max_stack_size) != Flag::SUCCESS) { 3122 return JNI_EINVAL; 3123 } 3124 } else if (match_option(option, "-XX:ParallelMarkingThreads=", &tail) || 3125 match_option(option, "-XX:ParallelCMSThreads=", &tail)) { 3126 uintx conc_threads = 0; 3127 if (!parse_uintx(tail, &conc_threads, 1)) { 3128 jio_fprintf(defaultStream::error_stream(), 3129 "Invalid concurrent threads: %s\n", option->optionString); 3130 return JNI_EINVAL; 3131 } 3132 jio_fprintf(defaultStream::error_stream(), 3133 "Please use -XX:ConcGCThreads in place of " 3134 "-XX:ParallelMarkingThreads or -XX:ParallelCMSThreads in the future\n"); 3135 if (FLAG_SET_CMDLINE(uint, ConcGCThreads, conc_threads) != Flag::SUCCESS) { 3136 return JNI_EINVAL; 3137 } 3138 } else if (match_option(option, "-XX:MaxDirectMemorySize=", &tail)) { 3139 julong max_direct_memory_size = 0; 3140 ArgsRange errcode = parse_memory_size(tail, &max_direct_memory_size, 0); 3141 if (errcode != arg_in_range) { 3142 jio_fprintf(defaultStream::error_stream(), 3143 "Invalid maximum direct memory size: %s\n", 3144 option->optionString); 3145 describe_range_error(errcode); 3146 return JNI_EINVAL; 3147 } 3148 if (FLAG_SET_CMDLINE(size_t, MaxDirectMemorySize, max_direct_memory_size) != Flag::SUCCESS) { 3149 return JNI_EINVAL; 3150 } 3151#if !INCLUDE_MANAGEMENT 3152 } else if (match_option(option, "-XX:+ManagementServer")) { 3153 jio_fprintf(defaultStream::error_stream(), 3154 "ManagementServer is not supported in this VM.\n"); 3155 return JNI_ERR; 3156#endif // INCLUDE_MANAGEMENT 3157 // CreateMinidumpOnCrash is removed, and replaced by CreateCoredumpOnCrash 3158 } else if (match_option(option, "-XX:+CreateMinidumpOnCrash")) { 3159 if (FLAG_SET_CMDLINE(bool, CreateCoredumpOnCrash, true) != Flag::SUCCESS) { 3160 return JNI_EINVAL; 3161 } 3162 jio_fprintf(defaultStream::output_stream(), 3163 "CreateMinidumpOnCrash is replaced by CreateCoredumpOnCrash: CreateCoredumpOnCrash is on\n"); 3164 } else if (match_option(option, "-XX:-CreateMinidumpOnCrash")) { 3165 if (FLAG_SET_CMDLINE(bool, CreateCoredumpOnCrash, false) != Flag::SUCCESS) { 3166 return JNI_EINVAL; 3167 } 3168 jio_fprintf(defaultStream::output_stream(), 3169 "CreateMinidumpOnCrash is replaced by CreateCoredumpOnCrash: CreateCoredumpOnCrash is off\n"); 3170 } else if (match_option(option, "-XX:", &tail)) { // -XX:xxxx 3171 // Skip -XX:Flags= since that case has already been handled 3172 if (strncmp(tail, "Flags=", strlen("Flags=")) != 0) { 3173 if (!process_argument(tail, args->ignoreUnrecognized, origin)) { 3174 return JNI_EINVAL; 3175 } 3176 } 3177 // Unknown option 3178 } else if (is_bad_option(option, args->ignoreUnrecognized)) { 3179 return JNI_ERR; 3180 } 3181 } 3182 3183 // PrintSharedArchiveAndExit will turn on 3184 // -Xshare:on 3185 // -XX:+TraceClassPaths 3186 if (PrintSharedArchiveAndExit) { 3187 if (FLAG_SET_CMDLINE(bool, UseSharedSpaces, true) != Flag::SUCCESS) { 3188 return JNI_EINVAL; 3189 } 3190 if (FLAG_SET_CMDLINE(bool, RequireSharedSpaces, true) != Flag::SUCCESS) { 3191 return JNI_EINVAL; 3192 } 3193 if (FLAG_SET_CMDLINE(bool, TraceClassPaths, true) != Flag::SUCCESS) { 3194 return JNI_EINVAL; 3195 } 3196 } 3197 3198 // Change the default value for flags which have different default values 3199 // when working with older JDKs. 3200#ifdef LINUX 3201 if (JDK_Version::current().compare_major(6) <= 0 && 3202 FLAG_IS_DEFAULT(UseLinuxPosixThreadCPUClocks)) { 3203 FLAG_SET_DEFAULT(UseLinuxPosixThreadCPUClocks, false); 3204 } 3205#endif // LINUX 3206 fix_appclasspath(); 3207 return JNI_OK; 3208} 3209 3210// Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled) 3211// 3212// This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar 3213// in their start-up scripts. If XYZ is empty, the classpath will look like "-cp foo.jar::bar.jar". 3214// Java treats such empty paths as if the user specified "-cp foo.jar:.:bar.jar". I.e., an empty 3215// path is treated as the current directory. 3216// 3217// This causes problems with CDS, which requires that all directories specified in the classpath 3218// must be empty. In most cases, applications do NOT want to load classes from the current 3219// directory anyway. Adding -XX:+IgnoreEmptyClassPaths will make these applications' start-up 3220// scripts compatible with CDS. 3221void Arguments::fix_appclasspath() { 3222 if (IgnoreEmptyClassPaths) { 3223 const char separator = *os::path_separator(); 3224 const char* src = _java_class_path->value(); 3225 3226 // skip over all the leading empty paths 3227 while (*src == separator) { 3228 src ++; 3229 } 3230 3231 char* copy = os::strdup_check_oom(src, mtInternal); 3232 3233 // trim all trailing empty paths 3234 for (char* tail = copy + strlen(copy) - 1; tail >= copy && *tail == separator; tail--) { 3235 *tail = '\0'; 3236 } 3237 3238 char from[3] = {separator, separator, '\0'}; 3239 char to [2] = {separator, '\0'}; 3240 while (StringUtils::replace_no_expand(copy, from, to) > 0) { 3241 // Keep replacing "::" -> ":" until we have no more "::" (non-windows) 3242 // Keep replacing ";;" -> ";" until we have no more ";;" (windows) 3243 } 3244 3245 _java_class_path->set_value(copy); 3246 FreeHeap(copy); // a copy was made by set_value, so don't need this anymore 3247 } 3248 3249 if (!PrintSharedArchiveAndExit) { 3250 ClassLoader::trace_class_path("[classpath: ", _java_class_path->value()); 3251 } 3252} 3253 3254static bool has_jar_files(const char* directory) { 3255 DIR* dir = os::opendir(directory); 3256 if (dir == NULL) return false; 3257 3258 struct dirent *entry; 3259 char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(directory), mtInternal); 3260 bool hasJarFile = false; 3261 while (!hasJarFile && (entry = os::readdir(dir, (dirent *) dbuf)) != NULL) { 3262 const char* name = entry->d_name; 3263 const char* ext = name + strlen(name) - 4; 3264 hasJarFile = ext > name && (os::file_name_strcmp(ext, ".jar") == 0); 3265 } 3266 FREE_C_HEAP_ARRAY(char, dbuf); 3267 os::closedir(dir); 3268 return hasJarFile ; 3269} 3270 3271static int check_non_empty_dirs(const char* path) { 3272 const char separator = *os::path_separator(); 3273 const char* const end = path + strlen(path); 3274 int nonEmptyDirs = 0; 3275 while (path < end) { 3276 const char* tmp_end = strchr(path, separator); 3277 if (tmp_end == NULL) { 3278 if (has_jar_files(path)) { 3279 nonEmptyDirs++; 3280 jio_fprintf(defaultStream::output_stream(), 3281 "Non-empty directory: %s\n", path); 3282 } 3283 path = end; 3284 } else { 3285 char* dirpath = NEW_C_HEAP_ARRAY(char, tmp_end - path + 1, mtInternal); 3286 memcpy(dirpath, path, tmp_end - path); 3287 dirpath[tmp_end - path] = '\0'; 3288 if (has_jar_files(dirpath)) { 3289 nonEmptyDirs++; 3290 jio_fprintf(defaultStream::output_stream(), 3291 "Non-empty directory: %s\n", dirpath); 3292 } 3293 FREE_C_HEAP_ARRAY(char, dirpath); 3294 path = tmp_end + 1; 3295 } 3296 } 3297 return nonEmptyDirs; 3298} 3299 3300jint Arguments::finalize_vm_init_args(SysClassPath* scp_p, bool scp_assembly_required) { 3301 // check if the default lib/endorsed directory exists; if so, error 3302 char path[JVM_MAXPATHLEN]; 3303 const char* fileSep = os::file_separator(); 3304 sprintf(path, "%s%slib%sendorsed", Arguments::get_java_home(), fileSep, fileSep); 3305 3306 if (CheckEndorsedAndExtDirs) { 3307 int nonEmptyDirs = 0; 3308 // check endorsed directory 3309 nonEmptyDirs += check_non_empty_dirs(path); 3310 // check the extension directories 3311 nonEmptyDirs += check_non_empty_dirs(Arguments::get_ext_dirs()); 3312 if (nonEmptyDirs > 0) { 3313 return JNI_ERR; 3314 } 3315 } 3316 3317 DIR* dir = os::opendir(path); 3318 if (dir != NULL) { 3319 jio_fprintf(defaultStream::output_stream(), 3320 "<JAVA_HOME>/lib/endorsed is not supported. Endorsed standards and standalone APIs\n" 3321 "in modular form will be supported via the concept of upgradeable modules.\n"); 3322 os::closedir(dir); 3323 return JNI_ERR; 3324 } 3325 3326 sprintf(path, "%s%slib%sext", Arguments::get_java_home(), fileSep, fileSep); 3327 dir = os::opendir(path); 3328 if (dir != NULL) { 3329 jio_fprintf(defaultStream::output_stream(), 3330 "<JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; " 3331 "Use -classpath instead.\n."); 3332 os::closedir(dir); 3333 return JNI_ERR; 3334 } 3335 3336 if (scp_assembly_required) { 3337 // Assemble the bootclasspath elements into the final path. 3338 Arguments::set_sysclasspath(scp_p->combined_path()); 3339 } 3340 3341 // This must be done after all arguments have been processed. 3342 // java_compiler() true means set to "NONE" or empty. 3343 if (java_compiler() && !xdebug_mode()) { 3344 // For backwards compatibility, we switch to interpreted mode if 3345 // -Djava.compiler="NONE" or "" is specified AND "-Xdebug" was 3346 // not specified. 3347 set_mode_flags(_int); 3348 } 3349 3350 // CompileThresholdScaling == 0.0 is same as -Xint: Disable compilation (enable interpreter-only mode), 3351 // but like -Xint, leave compilation thresholds unaffected. 3352 // With tiered compilation disabled, setting CompileThreshold to 0 disables compilation as well. 3353 if ((CompileThresholdScaling == 0.0) || (!TieredCompilation && CompileThreshold == 0)) { 3354 set_mode_flags(_int); 3355 } 3356 3357 // eventually fix up InitialTenuringThreshold if only MaxTenuringThreshold is set 3358 if (FLAG_IS_DEFAULT(InitialTenuringThreshold) && (InitialTenuringThreshold > MaxTenuringThreshold)) { 3359 FLAG_SET_ERGO(uintx, InitialTenuringThreshold, MaxTenuringThreshold); 3360 } 3361 3362#ifndef COMPILER2 3363 // Don't degrade server performance for footprint 3364 if (FLAG_IS_DEFAULT(UseLargePages) && 3365 MaxHeapSize < LargePageHeapSizeThreshold) { 3366 // No need for large granularity pages w/small heaps. 3367 // Note that large pages are enabled/disabled for both the 3368 // Java heap and the code cache. 3369 FLAG_SET_DEFAULT(UseLargePages, false); 3370 } 3371 3372#else 3373 if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) { 3374 FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment-1); 3375 } 3376#endif 3377 3378#ifndef TIERED 3379 // Tiered compilation is undefined. 3380 UNSUPPORTED_OPTION(TieredCompilation, "TieredCompilation"); 3381#endif 3382 3383 // If we are running in a headless jre, force java.awt.headless property 3384 // to be true unless the property has already been set. 3385 // Also allow the OS environment variable JAVA_AWT_HEADLESS to set headless state. 3386 if (os::is_headless_jre()) { 3387 const char* headless = Arguments::get_property("java.awt.headless"); 3388 if (headless == NULL) { 3389 const char *headless_env = ::getenv("JAVA_AWT_HEADLESS"); 3390 if (headless_env == NULL) { 3391 if (!add_property("java.awt.headless=true")) { 3392 return JNI_ENOMEM; 3393 } 3394 } else { 3395 char buffer[256]; 3396 jio_snprintf(buffer, sizeof(buffer), "java.awt.headless=%s", headless_env); 3397 if (!add_property(buffer)) { 3398 return JNI_ENOMEM; 3399 } 3400 } 3401 } 3402 } 3403 3404 if (UseConcMarkSweepGC && FLAG_IS_DEFAULT(UseParNewGC) && !UseParNewGC) { 3405 // CMS can only be used with ParNew 3406 FLAG_SET_ERGO(bool, UseParNewGC, true); 3407 } 3408 3409 if (!check_vm_args_consistency()) { 3410 return JNI_ERR; 3411 } 3412 3413 return JNI_OK; 3414} 3415 3416// Helper class for controlling the lifetime of JavaVMInitArgs 3417// objects. The contents of the JavaVMInitArgs are guaranteed to be 3418// deleted on the destruction of the ScopedVMInitArgs object. 3419class ScopedVMInitArgs : public StackObj { 3420 private: 3421 JavaVMInitArgs _args; 3422 3423 public: 3424 ScopedVMInitArgs() { 3425 _args.version = JNI_VERSION_1_2; 3426 _args.nOptions = 0; 3427 _args.options = NULL; 3428 _args.ignoreUnrecognized = false; 3429 } 3430 3431 // Populates the JavaVMInitArgs object represented by this 3432 // ScopedVMInitArgs object with the arguments in options. The 3433 // allocated memory is deleted by the destructor. If this method 3434 // returns anything other than JNI_OK, then this object is in a 3435 // partially constructed state, and should be abandoned. 3436 jint set_args(GrowableArray<JavaVMOption>* options) { 3437 JavaVMOption* options_arr = NEW_C_HEAP_ARRAY_RETURN_NULL( 3438 JavaVMOption, options->length(), mtInternal); 3439 if (options_arr == NULL) { 3440 return JNI_ENOMEM; 3441 } 3442 _args.options = options_arr; 3443 3444 for (int i = 0; i < options->length(); i++) { 3445 options_arr[i] = options->at(i); 3446 options_arr[i].optionString = os::strdup(options_arr[i].optionString); 3447 if (options_arr[i].optionString == NULL) { 3448 // Rely on the destructor to do cleanup. 3449 _args.nOptions = i; 3450 return JNI_ENOMEM; 3451 } 3452 } 3453 3454 _args.nOptions = options->length(); 3455 _args.ignoreUnrecognized = IgnoreUnrecognizedVMOptions; 3456 return JNI_OK; 3457 } 3458 3459 JavaVMInitArgs* get() { return &_args; } 3460 3461 ~ScopedVMInitArgs() { 3462 if (_args.options == NULL) return; 3463 for (int i = 0; i < _args.nOptions; i++) { 3464 os::free(_args.options[i].optionString); 3465 } 3466 FREE_C_HEAP_ARRAY(JavaVMOption, _args.options); 3467 } 3468}; 3469 3470jint Arguments::parse_java_options_environment_variable(ScopedVMInitArgs* args) { 3471 return parse_options_environment_variable("_JAVA_OPTIONS", args); 3472} 3473 3474jint Arguments::parse_java_tool_options_environment_variable(ScopedVMInitArgs* args) { 3475 return parse_options_environment_variable("JAVA_TOOL_OPTIONS", args); 3476} 3477 3478jint Arguments::parse_options_environment_variable(const char* name, 3479 ScopedVMInitArgs* vm_args) { 3480 char *buffer = ::getenv(name); 3481 3482 // Don't check this environment variable if user has special privileges 3483 // (e.g. unix su command). 3484 if (buffer == NULL || os::have_special_privileges()) { 3485 return JNI_OK; 3486 } 3487 3488 if ((buffer = os::strdup(buffer)) == NULL) { 3489 return JNI_ENOMEM; 3490 } 3491 3492 GrowableArray<JavaVMOption> *options = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<JavaVMOption>(2, true); // Construct option array 3493 jio_fprintf(defaultStream::error_stream(), 3494 "Picked up %s: %s\n", name, buffer); 3495 char* rd = buffer; // pointer to the input string (rd) 3496 while (true) { // repeat for all options in the input string 3497 while (isspace(*rd)) rd++; // skip whitespace 3498 if (*rd == 0) break; // we re done when the input string is read completely 3499 3500 // The output, option string, overwrites the input string. 3501 // Because of quoting, the pointer to the option string (wrt) may lag the pointer to 3502 // input string (rd). 3503 char* wrt = rd; 3504 3505 JavaVMOption option; 3506 option.optionString = wrt; 3507 options->append(option); // Fill in option 3508 while (*rd != 0 && !isspace(*rd)) { // unquoted strings terminate with a space or NULL 3509 if (*rd == '\'' || *rd == '"') { // handle a quoted string 3510 int quote = *rd; // matching quote to look for 3511 rd++; // don't copy open quote 3512 while (*rd != quote) { // include everything (even spaces) up until quote 3513 if (*rd == 0) { // string termination means unmatched string 3514 jio_fprintf(defaultStream::error_stream(), 3515 "Unmatched quote in %s\n", name); 3516 delete options; 3517 os::free(buffer); 3518 return JNI_ERR; 3519 } 3520 *wrt++ = *rd++; // copy to option string 3521 } 3522 rd++; // don't copy close quote 3523 } else { 3524 *wrt++ = *rd++; // copy to option string 3525 } 3526 } 3527 if (*rd != 0) { 3528 // In this case, the assignment to wrt below will make *rd nul, 3529 // which will interfere with the next loop iteration. 3530 rd++; 3531 } 3532 *wrt = 0; // Zero terminate option 3533 } 3534 3535 // Fill out JavaVMInitArgs structure. 3536 jint status = vm_args->set_args(options); 3537 3538 delete options; 3539 os::free(buffer); 3540 return status; 3541} 3542 3543void Arguments::set_shared_spaces_flags() { 3544 if (DumpSharedSpaces) { 3545 if (RequireSharedSpaces) { 3546 warning("cannot dump shared archive while using shared archive"); 3547 } 3548 UseSharedSpaces = false; 3549#ifdef _LP64 3550 if (!UseCompressedOops || !UseCompressedClassPointers) { 3551 vm_exit_during_initialization( 3552 "Cannot dump shared archive when UseCompressedOops or UseCompressedClassPointers is off.", NULL); 3553 } 3554 } else { 3555 if (!UseCompressedOops || !UseCompressedClassPointers) { 3556 no_shared_spaces("UseCompressedOops and UseCompressedClassPointers must be on for UseSharedSpaces."); 3557 } 3558#endif 3559 } 3560} 3561 3562#if !INCLUDE_ALL_GCS 3563static void force_serial_gc() { 3564 FLAG_SET_DEFAULT(UseSerialGC, true); 3565 UNSUPPORTED_GC_OPTION(UseG1GC); 3566 UNSUPPORTED_GC_OPTION(UseParallelGC); 3567 UNSUPPORTED_GC_OPTION(UseParallelOldGC); 3568 UNSUPPORTED_GC_OPTION(UseConcMarkSweepGC); 3569 UNSUPPORTED_GC_OPTION(UseParNewGC); 3570} 3571#endif // INCLUDE_ALL_GCS 3572 3573// Sharing support 3574// Construct the path to the archive 3575static char* get_shared_archive_path() { 3576 char *shared_archive_path; 3577 if (SharedArchiveFile == NULL) { 3578 char jvm_path[JVM_MAXPATHLEN]; 3579 os::jvm_path(jvm_path, sizeof(jvm_path)); 3580 char *end = strrchr(jvm_path, *os::file_separator()); 3581 if (end != NULL) *end = '\0'; 3582 size_t jvm_path_len = strlen(jvm_path); 3583 size_t file_sep_len = strlen(os::file_separator()); 3584 const size_t len = jvm_path_len + file_sep_len + 20; 3585 shared_archive_path = NEW_C_HEAP_ARRAY(char, len, mtInternal); 3586 if (shared_archive_path != NULL) { 3587 jio_snprintf(shared_archive_path, len, "%s%sclasses.jsa", 3588 jvm_path, os::file_separator()); 3589 } 3590 } else { 3591 shared_archive_path = os::strdup_check_oom(SharedArchiveFile, mtInternal); 3592 } 3593 return shared_archive_path; 3594} 3595 3596#ifndef PRODUCT 3597// Determine whether LogVMOutput should be implicitly turned on. 3598static bool use_vm_log() { 3599 if (LogCompilation || !FLAG_IS_DEFAULT(LogFile) || 3600 PrintCompilation || PrintInlining || PrintDependencies || PrintNativeNMethods || 3601 PrintDebugInfo || PrintRelocations || PrintNMethods || PrintExceptionHandlers || 3602 PrintAssembly || TraceDeoptimization || TraceDependencies || 3603 (VerifyDependencies && FLAG_IS_CMDLINE(VerifyDependencies))) { 3604 return true; 3605 } 3606 3607#ifdef COMPILER1 3608 if (PrintC1Statistics) { 3609 return true; 3610 } 3611#endif // COMPILER1 3612 3613#ifdef COMPILER2 3614 if (PrintOptoAssembly || PrintOptoStatistics) { 3615 return true; 3616 } 3617#endif // COMPILER2 3618 3619 return false; 3620} 3621#endif // PRODUCT 3622 3623static jint match_special_option_and_act(const JavaVMInitArgs* args, 3624 char** flags_file) { 3625 // Remaining part of option string 3626 const char* tail; 3627 3628 for (int index = 0; index < args->nOptions; index++) { 3629 const JavaVMOption* option = args->options + index; 3630 if (ArgumentsExt::process_options(option)) { 3631 continue; 3632 } 3633 if (match_option(option, "-XX:Flags=", &tail)) { 3634 *flags_file = (char *) tail; 3635 continue; 3636 } 3637 if (match_option(option, "-XX:+PrintVMOptions")) { 3638 PrintVMOptions = true; 3639 continue; 3640 } 3641 if (match_option(option, "-XX:-PrintVMOptions")) { 3642 PrintVMOptions = false; 3643 continue; 3644 } 3645 if (match_option(option, "-XX:+IgnoreUnrecognizedVMOptions")) { 3646 IgnoreUnrecognizedVMOptions = true; 3647 continue; 3648 } 3649 if (match_option(option, "-XX:-IgnoreUnrecognizedVMOptions")) { 3650 IgnoreUnrecognizedVMOptions = false; 3651 continue; 3652 } 3653 if (match_option(option, "-XX:+PrintFlagsInitial")) { 3654 CommandLineFlags::printFlags(tty, false); 3655 vm_exit(0); 3656 } 3657 if (match_option(option, "-XX:NativeMemoryTracking", &tail)) { 3658#if INCLUDE_NMT 3659 // The launcher did not setup nmt environment variable properly. 3660 if (!MemTracker::check_launcher_nmt_support(tail)) { 3661 warning("Native Memory Tracking did not setup properly, using wrong launcher?"); 3662 } 3663 3664 // Verify if nmt option is valid. 3665 if (MemTracker::verify_nmt_option()) { 3666 // Late initialization, still in single-threaded mode. 3667 if (MemTracker::tracking_level() >= NMT_summary) { 3668 MemTracker::init(); 3669 } 3670 } else { 3671 vm_exit_during_initialization("Syntax error, expecting -XX:NativeMemoryTracking=[off|summary|detail]", NULL); 3672 } 3673 continue; 3674#else 3675 jio_fprintf(defaultStream::error_stream(), 3676 "Native Memory Tracking is not supported in this VM\n"); 3677 return JNI_ERR; 3678#endif 3679 } 3680 3681#ifndef PRODUCT 3682 if (match_option(option, "-XX:+PrintFlagsWithComments")) { 3683 CommandLineFlags::printFlags(tty, true); 3684 vm_exit(0); 3685 } 3686#endif 3687 } 3688 return JNI_OK; 3689} 3690 3691static void print_options(const JavaVMInitArgs *args) { 3692 const char* tail; 3693 for (int index = 0; index < args->nOptions; index++) { 3694 const JavaVMOption *option = args->options + index; 3695 if (match_option(option, "-XX:", &tail)) { 3696 logOption(tail); 3697 } 3698 } 3699} 3700 3701// Parse entry point called from JNI_CreateJavaVM 3702 3703jint Arguments::parse(const JavaVMInitArgs* args) { 3704 3705 // Initialize ranges and constraints 3706 CommandLineFlagRangeList::init(); 3707 CommandLineFlagConstraintList::init(); 3708 3709 // If flag "-XX:Flags=flags-file" is used it will be the first option to be processed. 3710 const char* hotspotrc = ".hotspotrc"; 3711 char* flags_file = NULL; 3712 bool settings_file_specified = false; 3713 bool needs_hotspotrc_warning = false; 3714 ScopedVMInitArgs java_tool_options_args; 3715 ScopedVMInitArgs java_options_args; 3716 3717 jint code = 3718 parse_java_tool_options_environment_variable(&java_tool_options_args); 3719 if (code != JNI_OK) { 3720 return code; 3721 } 3722 3723 code = parse_java_options_environment_variable(&java_options_args); 3724 if (code != JNI_OK) { 3725 return code; 3726 } 3727 3728 code = 3729 match_special_option_and_act(java_tool_options_args.get(), &flags_file); 3730 if (code != JNI_OK) { 3731 return code; 3732 } 3733 3734 code = match_special_option_and_act(args, &flags_file); 3735 if (code != JNI_OK) { 3736 return code; 3737 } 3738 3739 code = match_special_option_and_act(java_options_args.get(), &flags_file); 3740 if (code != JNI_OK) { 3741 return code; 3742 } 3743 3744 settings_file_specified = (flags_file != NULL); 3745 3746 if (IgnoreUnrecognizedVMOptions) { 3747 // uncast const to modify the flag args->ignoreUnrecognized 3748 *(jboolean*)(&args->ignoreUnrecognized) = true; 3749 java_tool_options_args.get()->ignoreUnrecognized = true; 3750 java_options_args.get()->ignoreUnrecognized = true; 3751 } 3752 3753 // Parse specified settings file 3754 if (settings_file_specified) { 3755 if (!process_settings_file(flags_file, true, args->ignoreUnrecognized)) { 3756 return JNI_EINVAL; 3757 } 3758 } else { 3759#ifdef ASSERT 3760 // Parse default .hotspotrc settings file 3761 if (!process_settings_file(".hotspotrc", false, args->ignoreUnrecognized)) { 3762 return JNI_EINVAL; 3763 } 3764#else 3765 struct stat buf; 3766 if (os::stat(hotspotrc, &buf) == 0) { 3767 needs_hotspotrc_warning = true; 3768 } 3769#endif 3770 } 3771 3772 if (PrintVMOptions) { 3773 print_options(java_tool_options_args.get()); 3774 print_options(args); 3775 print_options(java_options_args.get()); 3776 } 3777 3778 // Parse JavaVMInitArgs structure passed in, as well as JAVA_TOOL_OPTIONS and _JAVA_OPTIONS 3779 jint result = parse_vm_init_args(java_tool_options_args.get(), 3780 java_options_args.get(), args); 3781 3782 if (result != JNI_OK) { 3783 return result; 3784 } 3785 3786 // Call get_shared_archive_path() here, after possible SharedArchiveFile option got parsed. 3787 SharedArchivePath = get_shared_archive_path(); 3788 if (SharedArchivePath == NULL) { 3789 return JNI_ENOMEM; 3790 } 3791 3792 // Set up VerifySharedSpaces 3793 if (FLAG_IS_DEFAULT(VerifySharedSpaces) && SharedArchiveFile != NULL) { 3794 VerifySharedSpaces = true; 3795 } 3796 3797 // Delay warning until here so that we've had a chance to process 3798 // the -XX:-PrintWarnings flag 3799 if (needs_hotspotrc_warning) { 3800 warning("%s file is present but has been ignored. " 3801 "Run with -XX:Flags=%s to load the file.", 3802 hotspotrc, hotspotrc); 3803 } 3804 3805#if defined(_ALLBSD_SOURCE) || defined(AIX) // UseLargePages is not yet supported on BSD and AIX. 3806 UNSUPPORTED_OPTION(UseLargePages, "-XX:+UseLargePages"); 3807#endif 3808 3809 ArgumentsExt::report_unsupported_options(); 3810 3811#ifndef PRODUCT 3812 if (TraceBytecodesAt != 0) { 3813 TraceBytecodes = true; 3814 } 3815 if (CountCompiledCalls) { 3816 if (UseCounterDecay) { 3817 warning("UseCounterDecay disabled because CountCalls is set"); 3818 UseCounterDecay = false; 3819 } 3820 } 3821#endif // PRODUCT 3822 3823 if (ScavengeRootsInCode == 0) { 3824 if (!FLAG_IS_DEFAULT(ScavengeRootsInCode)) { 3825 warning("forcing ScavengeRootsInCode non-zero"); 3826 } 3827 ScavengeRootsInCode = 1; 3828 } 3829 3830 if (PrintGCDetails) { 3831 // Turn on -verbose:gc options as well 3832 PrintGC = true; 3833 } 3834 3835 // Set object alignment values. 3836 set_object_alignment(); 3837 3838#if !INCLUDE_ALL_GCS 3839 force_serial_gc(); 3840#endif // INCLUDE_ALL_GCS 3841#if !INCLUDE_CDS 3842 if (DumpSharedSpaces || RequireSharedSpaces) { 3843 jio_fprintf(defaultStream::error_stream(), 3844 "Shared spaces are not supported in this VM\n"); 3845 return JNI_ERR; 3846 } 3847 if ((UseSharedSpaces && FLAG_IS_CMDLINE(UseSharedSpaces)) || PrintSharedSpaces) { 3848 warning("Shared spaces are not supported in this VM"); 3849 FLAG_SET_DEFAULT(UseSharedSpaces, false); 3850 FLAG_SET_DEFAULT(PrintSharedSpaces, false); 3851 } 3852 no_shared_spaces("CDS Disabled"); 3853#endif // INCLUDE_CDS 3854 3855 return JNI_OK; 3856} 3857 3858jint Arguments::apply_ergo() { 3859 3860 // Set flags based on ergonomics. 3861 set_ergonomics_flags(); 3862 3863 set_shared_spaces_flags(); 3864 3865 // Check the GC selections again. 3866 if (!check_gc_consistency()) { 3867 return JNI_EINVAL; 3868 } 3869 3870 if (TieredCompilation) { 3871 set_tiered_flags(); 3872 } else { 3873 int max_compilation_policy_choice = 1; 3874#ifdef COMPILER2 3875 max_compilation_policy_choice = 2; 3876#endif 3877 // Check if the policy is valid. 3878 if (CompilationPolicyChoice >= max_compilation_policy_choice) { 3879 vm_exit_during_initialization( 3880 "Incompatible compilation policy selected", NULL); 3881 } 3882 // Scale CompileThreshold 3883 // CompileThresholdScaling == 0.0 is equivalent to -Xint and leaves CompileThreshold unchanged. 3884 if (!FLAG_IS_DEFAULT(CompileThresholdScaling) && CompileThresholdScaling > 0.0) { 3885 FLAG_SET_ERGO(intx, CompileThreshold, scaled_compile_threshold(CompileThreshold)); 3886 } 3887 } 3888 3889#ifdef COMPILER2 3890#ifndef PRODUCT 3891 if (PrintIdealGraphLevel > 0) { 3892 FLAG_SET_ERGO(bool, PrintIdealGraph, true); 3893 } 3894#endif 3895#endif 3896 3897 // Set heap size based on available physical memory 3898 set_heap_size(); 3899 3900 ArgumentsExt::set_gc_specific_flags(); 3901 3902 // Initialize Metaspace flags and alignments 3903 Metaspace::ergo_initialize(); 3904 3905 // Set bytecode rewriting flags 3906 set_bytecode_flags(); 3907 3908 // Set flags if Aggressive optimization flags (-XX:+AggressiveOpts) enabled 3909 set_aggressive_opts_flags(); 3910 3911 // Turn off biased locking for locking debug mode flags, 3912 // which are subtly different from each other but neither works with 3913 // biased locking 3914 if (UseHeavyMonitors 3915#ifdef COMPILER1 3916 || !UseFastLocking 3917#endif // COMPILER1 3918 ) { 3919 if (!FLAG_IS_DEFAULT(UseBiasedLocking) && UseBiasedLocking) { 3920 // flag set to true on command line; warn the user that they 3921 // can't enable biased locking here 3922 warning("Biased Locking is not supported with locking debug flags" 3923 "; ignoring UseBiasedLocking flag." ); 3924 } 3925 UseBiasedLocking = false; 3926 } 3927 3928#ifdef ZERO 3929 // Clear flags not supported on zero. 3930 FLAG_SET_DEFAULT(ProfileInterpreter, false); 3931 FLAG_SET_DEFAULT(UseBiasedLocking, false); 3932 LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedOops, false)); 3933 LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedClassPointers, false)); 3934#endif // CC_INTERP 3935 3936#ifdef COMPILER2 3937 if (!EliminateLocks) { 3938 EliminateNestedLocks = false; 3939 } 3940 if (!Inline) { 3941 IncrementalInline = false; 3942 } 3943#ifndef PRODUCT 3944 if (!IncrementalInline) { 3945 AlwaysIncrementalInline = false; 3946 } 3947#endif 3948 if (!UseTypeSpeculation && FLAG_IS_DEFAULT(TypeProfileLevel)) { 3949 // nothing to use the profiling, turn if off 3950 FLAG_SET_DEFAULT(TypeProfileLevel, 0); 3951 } 3952#endif 3953 3954 if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) { 3955 warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output"); 3956 DebugNonSafepoints = true; 3957 } 3958 3959 if (FLAG_IS_CMDLINE(CompressedClassSpaceSize) && !UseCompressedClassPointers) { 3960 warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used"); 3961 } 3962 3963#ifndef PRODUCT 3964 if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) { 3965 if (use_vm_log()) { 3966 LogVMOutput = true; 3967 } 3968 } 3969#endif // PRODUCT 3970 3971 if (PrintCommandLineFlags) { 3972 CommandLineFlags::printSetFlags(tty); 3973 } 3974 3975 // Apply CPU specific policy for the BiasedLocking 3976 if (UseBiasedLocking) { 3977 if (!VM_Version::use_biased_locking() && 3978 !(FLAG_IS_CMDLINE(UseBiasedLocking))) { 3979 UseBiasedLocking = false; 3980 } 3981 } 3982#ifdef COMPILER2 3983 if (!UseBiasedLocking || EmitSync != 0) { 3984 UseOptoBiasInlining = false; 3985 } 3986#endif 3987 3988 return JNI_OK; 3989} 3990 3991jint Arguments::adjust_after_os() { 3992 if (UseNUMA) { 3993 if (UseParallelGC || UseParallelOldGC) { 3994 if (FLAG_IS_DEFAULT(MinHeapDeltaBytes)) { 3995 FLAG_SET_DEFAULT(MinHeapDeltaBytes, 64*M); 3996 } 3997 } 3998 // UseNUMAInterleaving is set to ON for all collectors and 3999 // platforms when UseNUMA is set to ON. NUMA-aware collectors 4000 // such as the parallel collector for Linux and Solaris will 4001 // interleave old gen and survivor spaces on top of NUMA 4002 // allocation policy for the eden space. 4003 // Non NUMA-aware collectors such as CMS, G1 and Serial-GC on 4004 // all platforms and ParallelGC on Windows will interleave all 4005 // of the heap spaces across NUMA nodes. 4006 if (FLAG_IS_DEFAULT(UseNUMAInterleaving)) { 4007 FLAG_SET_ERGO(bool, UseNUMAInterleaving, true); 4008 } 4009 } 4010 return JNI_OK; 4011} 4012 4013// Any custom code post the final range and constraint check 4014// can be done here. We pass a flag that specifies whether 4015// the check passed successfully 4016void Arguments::post_final_range_and_constraint_check(bool check_passed) { 4017 // This does not set the flag itself, but stores the value in a safe place for later usage. 4018 _min_heap_free_ratio = MinHeapFreeRatio; 4019 _max_heap_free_ratio = MaxHeapFreeRatio; 4020} 4021 4022int Arguments::PropertyList_count(SystemProperty* pl) { 4023 int count = 0; 4024 while(pl != NULL) { 4025 count++; 4026 pl = pl->next(); 4027 } 4028 return count; 4029} 4030 4031const char* Arguments::PropertyList_get_value(SystemProperty *pl, const char* key) { 4032 assert(key != NULL, "just checking"); 4033 SystemProperty* prop; 4034 for (prop = pl; prop != NULL; prop = prop->next()) { 4035 if (strcmp(key, prop->key()) == 0) return prop->value(); 4036 } 4037 return NULL; 4038} 4039 4040const char* Arguments::PropertyList_get_key_at(SystemProperty *pl, int index) { 4041 int count = 0; 4042 const char* ret_val = NULL; 4043 4044 while(pl != NULL) { 4045 if(count >= index) { 4046 ret_val = pl->key(); 4047 break; 4048 } 4049 count++; 4050 pl = pl->next(); 4051 } 4052 4053 return ret_val; 4054} 4055 4056char* Arguments::PropertyList_get_value_at(SystemProperty* pl, int index) { 4057 int count = 0; 4058 char* ret_val = NULL; 4059 4060 while(pl != NULL) { 4061 if(count >= index) { 4062 ret_val = pl->value(); 4063 break; 4064 } 4065 count++; 4066 pl = pl->next(); 4067 } 4068 4069 return ret_val; 4070} 4071 4072void Arguments::PropertyList_add(SystemProperty** plist, SystemProperty *new_p) { 4073 SystemProperty* p = *plist; 4074 if (p == NULL) { 4075 *plist = new_p; 4076 } else { 4077 while (p->next() != NULL) { 4078 p = p->next(); 4079 } 4080 p->set_next(new_p); 4081 } 4082} 4083 4084void Arguments::PropertyList_add(SystemProperty** plist, const char* k, char* v) { 4085 if (plist == NULL) 4086 return; 4087 4088 SystemProperty* new_p = new SystemProperty(k, v, true); 4089 PropertyList_add(plist, new_p); 4090} 4091 4092void Arguments::PropertyList_add(SystemProperty *element) { 4093 PropertyList_add(&_system_properties, element); 4094} 4095 4096// This add maintains unique property key in the list. 4097void Arguments::PropertyList_unique_add(SystemProperty** plist, const char* k, char* v, jboolean append) { 4098 if (plist == NULL) 4099 return; 4100 4101 // If property key exist then update with new value. 4102 SystemProperty* prop; 4103 for (prop = *plist; prop != NULL; prop = prop->next()) { 4104 if (strcmp(k, prop->key()) == 0) { 4105 if (append) { 4106 prop->append_value(v); 4107 } else { 4108 prop->set_value(v); 4109 } 4110 return; 4111 } 4112 } 4113 4114 PropertyList_add(plist, k, v); 4115} 4116 4117// Copies src into buf, replacing "%%" with "%" and "%p" with pid 4118// Returns true if all of the source pointed by src has been copied over to 4119// the destination buffer pointed by buf. Otherwise, returns false. 4120// Notes: 4121// 1. If the length (buflen) of the destination buffer excluding the 4122// NULL terminator character is not long enough for holding the expanded 4123// pid characters, it also returns false instead of returning the partially 4124// expanded one. 4125// 2. The passed in "buflen" should be large enough to hold the null terminator. 4126bool Arguments::copy_expand_pid(const char* src, size_t srclen, 4127 char* buf, size_t buflen) { 4128 const char* p = src; 4129 char* b = buf; 4130 const char* src_end = &src[srclen]; 4131 char* buf_end = &buf[buflen - 1]; 4132 4133 while (p < src_end && b < buf_end) { 4134 if (*p == '%') { 4135 switch (*(++p)) { 4136 case '%': // "%%" ==> "%" 4137 *b++ = *p++; 4138 break; 4139 case 'p': { // "%p" ==> current process id 4140 // buf_end points to the character before the last character so 4141 // that we could write '\0' to the end of the buffer. 4142 size_t buf_sz = buf_end - b + 1; 4143 int ret = jio_snprintf(b, buf_sz, "%d", os::current_process_id()); 4144 4145 // if jio_snprintf fails or the buffer is not long enough to hold 4146 // the expanded pid, returns false. 4147 if (ret < 0 || ret >= (int)buf_sz) { 4148 return false; 4149 } else { 4150 b += ret; 4151 assert(*b == '\0', "fail in copy_expand_pid"); 4152 if (p == src_end && b == buf_end + 1) { 4153 // reach the end of the buffer. 4154 return true; 4155 } 4156 } 4157 p++; 4158 break; 4159 } 4160 default : 4161 *b++ = '%'; 4162 } 4163 } else { 4164 *b++ = *p++; 4165 } 4166 } 4167 *b = '\0'; 4168 return (p == src_end); // return false if not all of the source was copied 4169} 4170