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