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