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