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