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