-
Notifications
You must be signed in to change notification settings - Fork 207
/
arguments.cpp
4321 lines (3883 loc) · 158 KB
/
arguments.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "jvm.h"
#include "cds/filemap.hpp"
#include "classfile/classLoader.hpp"
#include "classfile/javaAssertions.hpp"
#include "classfile/moduleEntry.hpp"
#include "classfile/stringTable.hpp"
#include "classfile/symbolTable.hpp"
#include "compiler/compilerDefinitions.hpp"
#include "gc/shared/gcArguments.hpp"
#include "gc/shared/gcConfig.hpp"
#include "gc/shared/stringdedup/stringDedup.hpp"
#include "gc/shared/tlab_globals.hpp"
#include "logging/log.hpp"
#include "logging/logConfiguration.hpp"
#include "logging/logStream.hpp"
#include "logging/logTag.hpp"
#include "memory/allocation.inline.hpp"
#include "oops/oop.inline.hpp"
#include "prims/jvmtiExport.hpp"
#include "runtime/arguments.hpp"
#include "runtime/flags/jvmFlag.hpp"
#include "runtime/flags/jvmFlagAccess.hpp"
#include "runtime/flags/jvmFlagLimit.hpp"
#include "runtime/globals_extension.hpp"
#include "runtime/java.hpp"
#include "runtime/os.hpp"
#include "runtime/safepoint.hpp"
#include "runtime/safepointMechanism.hpp"
#include "runtime/vm_version.hpp"
#include "services/management.hpp"
#include "services/nmtCommon.hpp"
#include "utilities/align.hpp"
#include "utilities/defaultStream.hpp"
#include "utilities/macros.hpp"
#include "utilities/powerOfTwo.hpp"
#include "utilities/stringUtils.hpp"
#if INCLUDE_JFR
#include "jfr/jfr.hpp"
#endif
#define DEFAULT_JAVA_LAUNCHER "generic"
char* Arguments::_jvm_flags_file = NULL;
char** Arguments::_jvm_flags_array = NULL;
int Arguments::_num_jvm_flags = 0;
char** Arguments::_jvm_args_array = NULL;
int Arguments::_num_jvm_args = 0;
char* Arguments::_java_command = NULL;
SystemProperty* Arguments::_system_properties = NULL;
const char* Arguments::_gc_log_filename = NULL;
size_t Arguments::_conservative_max_heap_alignment = 0;
Arguments::Mode Arguments::_mode = _mixed;
bool Arguments::_java_compiler = false;
bool Arguments::_xdebug_mode = false;
const char* Arguments::_java_vendor_url_bug = NULL;
const char* Arguments::_sun_java_launcher = DEFAULT_JAVA_LAUNCHER;
bool Arguments::_sun_java_launcher_is_altjvm = false;
// These parameters are reset in method parse_vm_init_args()
bool Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
bool Arguments::_UseOnStackReplacement = UseOnStackReplacement;
bool Arguments::_BackgroundCompilation = BackgroundCompilation;
bool Arguments::_ClipInlining = ClipInlining;
size_t Arguments::_default_SharedBaseAddress = SharedBaseAddress;
bool Arguments::_enable_preview = false;
char* Arguments::SharedArchivePath = NULL;
char* Arguments::SharedDynamicArchivePath = NULL;
AgentLibraryList Arguments::_libraryList;
AgentLibraryList Arguments::_agentList;
// These are not set by the JDK's built-in launchers, but they can be set by
// programs that embed the JVM using JNI_CreateJavaVM. See comments around
// JavaVMOption in jni.h.
abort_hook_t Arguments::_abort_hook = NULL;
exit_hook_t Arguments::_exit_hook = NULL;
vfprintf_hook_t Arguments::_vfprintf_hook = NULL;
SystemProperty *Arguments::_sun_boot_library_path = NULL;
SystemProperty *Arguments::_java_library_path = NULL;
SystemProperty *Arguments::_java_home = NULL;
SystemProperty *Arguments::_java_class_path = NULL;
SystemProperty *Arguments::_jdk_boot_class_path_append = NULL;
SystemProperty *Arguments::_vm_info = NULL;
GrowableArray<ModulePatchPath*> *Arguments::_patch_mod_prefix = NULL;
PathString *Arguments::_system_boot_class_path = NULL;
bool Arguments::_has_jimage = false;
char* Arguments::_ext_dirs = NULL;
bool PathString::set_value(const char *value) {
if (_value != NULL) {
FreeHeap(_value);
}
_value = AllocateHeap(strlen(value)+1, mtArguments);
assert(_value != NULL, "Unable to allocate space for new path value");
if (_value != NULL) {
strcpy(_value, value);
} else {
// not able to allocate
return false;
}
return true;
}
void PathString::append_value(const char *value) {
char *sp;
size_t len = 0;
if (value != NULL) {
len = strlen(value);
if (_value != NULL) {
len += strlen(_value);
}
sp = AllocateHeap(len+2, mtArguments);
assert(sp != NULL, "Unable to allocate space for new append path value");
if (sp != NULL) {
if (_value != NULL) {
strcpy(sp, _value);
strcat(sp, os::path_separator());
strcat(sp, value);
FreeHeap(_value);
} else {
strcpy(sp, value);
}
_value = sp;
}
}
}
PathString::PathString(const char* value) {
if (value == NULL) {
_value = NULL;
} else {
_value = AllocateHeap(strlen(value)+1, mtArguments);
strcpy(_value, value);
}
}
PathString::~PathString() {
if (_value != NULL) {
FreeHeap(_value);
_value = NULL;
}
}
ModulePatchPath::ModulePatchPath(const char* module_name, const char* path) {
assert(module_name != NULL && path != NULL, "Invalid module name or path value");
size_t len = strlen(module_name) + 1;
_module_name = AllocateHeap(len, mtInternal);
strncpy(_module_name, module_name, len); // copy the trailing null
_path = new PathString(path);
}
ModulePatchPath::~ModulePatchPath() {
if (_module_name != NULL) {
FreeHeap(_module_name);
_module_name = NULL;
}
if (_path != NULL) {
delete _path;
_path = NULL;
}
}
SystemProperty::SystemProperty(const char* key, const char* value, bool writeable, bool internal) : PathString(value) {
if (key == NULL) {
_key = NULL;
} else {
_key = AllocateHeap(strlen(key)+1, mtArguments);
strcpy(_key, key);
}
_next = NULL;
_internal = internal;
_writeable = writeable;
}
AgentLibrary::AgentLibrary(const char* name, const char* options,
bool is_absolute_path, void* os_lib,
bool instrument_lib) {
_name = AllocateHeap(strlen(name)+1, mtArguments);
strcpy(_name, name);
if (options == NULL) {
_options = NULL;
} else {
_options = AllocateHeap(strlen(options)+1, mtArguments);
strcpy(_options, options);
}
_is_absolute_path = is_absolute_path;
_os_lib = os_lib;
_next = NULL;
_state = agent_invalid;
_is_static_lib = false;
_is_instrument_lib = instrument_lib;
}
// Check if head of 'option' matches 'name', and sets 'tail' to the remaining
// part of the option string.
static bool match_option(const JavaVMOption *option, const char* name,
const char** tail) {
size_t len = strlen(name);
if (strncmp(option->optionString, name, len) == 0) {
*tail = option->optionString + len;
return true;
} else {
return false;
}
}
// Check if 'option' matches 'name'. No "tail" is allowed.
static bool match_option(const JavaVMOption *option, const char* name) {
const char* tail = NULL;
bool result = match_option(option, name, &tail);
if (tail != NULL && *tail == '\0') {
return result;
} else {
return false;
}
}
// Return true if any of the strings in null-terminated array 'names' matches.
// If tail_allowed is true, then the tail must begin with a colon; otherwise,
// the option must match exactly.
static bool match_option(const JavaVMOption* option, const char** names, const char** tail,
bool tail_allowed) {
for (/* empty */; *names != NULL; ++names) {
if (match_option(option, *names, tail)) {
if (**tail == '\0' || (tail_allowed && **tail == ':')) {
return true;
}
}
}
return false;
}
#if INCLUDE_JFR
static bool _has_jfr_option = false; // is using JFR
// return true on failure
static bool match_jfr_option(const JavaVMOption** option) {
assert((*option)->optionString != NULL, "invariant");
char* tail = NULL;
if (match_option(*option, "-XX:StartFlightRecording", (const char**)&tail)) {
_has_jfr_option = true;
return Jfr::on_start_flight_recording_option(option, tail);
} else if (match_option(*option, "-XX:FlightRecorderOptions", (const char**)&tail)) {
_has_jfr_option = true;
return Jfr::on_flight_recorder_option(option, tail);
}
return false;
}
bool Arguments::has_jfr_option() {
return _has_jfr_option;
}
#endif
static void logOption(const char* opt) {
if (PrintVMOptions) {
jio_fprintf(defaultStream::output_stream(), "VM option '%s'\n", opt);
}
}
bool needs_module_property_warning = false;
#define MODULE_PROPERTY_PREFIX "jdk.module."
#define MODULE_PROPERTY_PREFIX_LEN 11
#define ADDEXPORTS "addexports"
#define ADDEXPORTS_LEN 10
#define ADDREADS "addreads"
#define ADDREADS_LEN 8
#define ADDOPENS "addopens"
#define ADDOPENS_LEN 8
#define PATCH "patch"
#define PATCH_LEN 5
#define ADDMODS "addmods"
#define ADDMODS_LEN 7
#define LIMITMODS "limitmods"
#define LIMITMODS_LEN 9
#define PATH "path"
#define PATH_LEN 4
#define UPGRADE_PATH "upgrade.path"
#define UPGRADE_PATH_LEN 12
#define ENABLE_NATIVE_ACCESS "enable.native.access"
#define ENABLE_NATIVE_ACCESS_LEN 20
void Arguments::add_init_library(const char* name, char* options) {
_libraryList.add(new AgentLibrary(name, options, false, NULL));
}
void Arguments::add_init_agent(const char* name, char* options, bool absolute_path) {
_agentList.add(new AgentLibrary(name, options, absolute_path, NULL));
}
void Arguments::add_instrument_agent(const char* name, char* options, bool absolute_path) {
_agentList.add(new AgentLibrary(name, options, absolute_path, NULL, true));
}
// Late-binding agents not started via arguments
void Arguments::add_loaded_agent(AgentLibrary *agentLib) {
_agentList.add(agentLib);
}
// Return TRUE if option matches 'property', or 'property=', or 'property.'.
static bool matches_property_suffix(const char* option, const char* property, size_t len) {
return ((strncmp(option, property, len) == 0) &&
(option[len] == '=' || option[len] == '.' || option[len] == '\0'));
}
// Return true if property starts with "jdk.module." and its ensuing chars match
// any of the reserved module properties.
// property should be passed without the leading "-D".
bool Arguments::is_internal_module_property(const char* property) {
assert((strncmp(property, "-D", 2) != 0), "Unexpected leading -D");
if (strncmp(property, MODULE_PROPERTY_PREFIX, MODULE_PROPERTY_PREFIX_LEN) == 0) {
const char* property_suffix = property + MODULE_PROPERTY_PREFIX_LEN;
if (matches_property_suffix(property_suffix, ADDEXPORTS, ADDEXPORTS_LEN) ||
matches_property_suffix(property_suffix, ADDREADS, ADDREADS_LEN) ||
matches_property_suffix(property_suffix, ADDOPENS, ADDOPENS_LEN) ||
matches_property_suffix(property_suffix, PATCH, PATCH_LEN) ||
matches_property_suffix(property_suffix, ADDMODS, ADDMODS_LEN) ||
matches_property_suffix(property_suffix, LIMITMODS, LIMITMODS_LEN) ||
matches_property_suffix(property_suffix, PATH, PATH_LEN) ||
matches_property_suffix(property_suffix, UPGRADE_PATH, UPGRADE_PATH_LEN) ||
matches_property_suffix(property_suffix, ENABLE_NATIVE_ACCESS, ENABLE_NATIVE_ACCESS_LEN)) {
return true;
}
}
return false;
}
// Process java launcher properties.
void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
// See if sun.java.launcher or sun.java.launcher.is_altjvm is defined.
// Must do this before setting up other system properties,
// as some of them may depend on launcher type.
for (int index = 0; index < args->nOptions; index++) {
const JavaVMOption* option = args->options + index;
const char* tail;
if (match_option(option, "-Dsun.java.launcher=", &tail)) {
process_java_launcher_argument(tail, option->extraInfo);
continue;
}
if (match_option(option, "-Dsun.java.launcher.is_altjvm=", &tail)) {
if (strcmp(tail, "true") == 0) {
_sun_java_launcher_is_altjvm = true;
}
continue;
}
}
}
// Initialize system properties key and value.
void Arguments::init_system_properties() {
// Set up _system_boot_class_path which is not a property but
// relies heavily on argument processing and the jdk.boot.class.path.append
// property. It is used to store the underlying system boot class path.
_system_boot_class_path = new PathString(NULL);
PropertyList_add(&_system_properties, new SystemProperty("java.vm.specification.name",
"Java Virtual Machine Specification", false));
PropertyList_add(&_system_properties, new SystemProperty("java.vm.version", VM_Version::vm_release(), false));
PropertyList_add(&_system_properties, new SystemProperty("java.vm.name", VM_Version::vm_name(), false));
PropertyList_add(&_system_properties, new SystemProperty("jdk.debug", VM_Version::jdk_debug_level(), false));
// Initialize the vm.info now, but it will need updating after argument parsing.
_vm_info = new SystemProperty("java.vm.info", VM_Version::vm_info_string(), true);
// Following are JVMTI agent writable properties.
// Properties values are set to NULL and they are
// os specific they are initialized in os::init_system_properties_values().
_sun_boot_library_path = new SystemProperty("sun.boot.library.path", NULL, true);
_java_library_path = new SystemProperty("java.library.path", NULL, true);
_java_home = new SystemProperty("java.home", NULL, true);
_java_class_path = new SystemProperty("java.class.path", "", true);
// jdk.boot.class.path.append is a non-writeable, internal property.
// It can only be set by either:
// - -Xbootclasspath/a:
// - AddToBootstrapClassLoaderSearch during JVMTI OnLoad phase
_jdk_boot_class_path_append = new SystemProperty("jdk.boot.class.path.append", "", false, true);
// Add to System Property list.
PropertyList_add(&_system_properties, _sun_boot_library_path);
PropertyList_add(&_system_properties, _java_library_path);
PropertyList_add(&_system_properties, _java_home);
PropertyList_add(&_system_properties, _java_class_path);
PropertyList_add(&_system_properties, _jdk_boot_class_path_append);
PropertyList_add(&_system_properties, _vm_info);
// Set OS specific system properties values
os::init_system_properties_values();
}
// Update/Initialize System properties after JDK version number is known
void Arguments::init_version_specific_system_properties() {
enum { bufsz = 16 };
char buffer[bufsz];
const char* spec_vendor = "Oracle Corporation";
uint32_t spec_version = JDK_Version::current().major_version();
jio_snprintf(buffer, bufsz, UINT32_FORMAT, spec_version);
PropertyList_add(&_system_properties,
new SystemProperty("java.vm.specification.vendor", spec_vendor, false));
PropertyList_add(&_system_properties,
new SystemProperty("java.vm.specification.version", buffer, false));
PropertyList_add(&_system_properties,
new SystemProperty("java.vm.vendor", VM_Version::vm_vendor(), false));
}
/*
* -XX argument processing:
*
* -XX arguments are defined in several places, such as:
* globals.hpp, globals_<cpu>.hpp, globals_<os>.hpp, <compiler>_globals.hpp, or <gc>_globals.hpp.
* -XX arguments are parsed in parse_argument().
* -XX argument bounds checking is done in check_vm_args_consistency().
*
* Over time -XX arguments may change. There are mechanisms to handle common cases:
*
* ALIASED: An option that is simply another name for another option. This is often
* part of the process of deprecating a flag, but not all aliases need
* to be deprecated.
*
* Create an alias for an option by adding the old and new option names to the
* "aliased_jvm_flags" table. Delete the old variable from globals.hpp (etc).
*
* DEPRECATED: An option that is supported, but a warning is printed to let the user know that
* support may be removed in the future. Both regular and aliased options may be
* deprecated.
*
* Add a deprecation warning for an option (or alias) by adding an entry in the
* "special_jvm_flags" table and setting the "deprecated_in" field.
* Often an option "deprecated" in one major release will
* be made "obsolete" in the next. In this case the entry should also have its
* "obsolete_in" field set.
*
* OBSOLETE: An option that has been removed (and deleted from globals.hpp), but is still accepted
* on the command line. A warning is printed to let the user know that option might not
* be accepted in the future.
*
* Add an obsolete warning for an option by adding an entry in the "special_jvm_flags"
* table and setting the "obsolete_in" field.
*
* EXPIRED: A deprecated or obsolete option that has an "accept_until" version less than or equal
* to the current JDK version. The system will flatly refuse to admit the existence of
* the flag. This allows a flag to die automatically over JDK releases.
*
* Note that manual cleanup of expired options should be done at major JDK version upgrades:
* - Newly expired options should be removed from the special_jvm_flags and aliased_jvm_flags tables.
* - Newly obsolete or expired deprecated options should have their global variable
* definitions removed (from globals.hpp, etc) and related implementations removed.
*
* Recommended approach for removing options:
*
* To remove options commonly used by customers (e.g. product -XX options), use
* the 3-step model adding major release numbers to the deprecate, obsolete and expire columns.
*
* To remove internal options (e.g. diagnostic, experimental, develop options), use
* a 2-step model adding major release numbers to the obsolete and expire columns.
*
* To change the name of an option, use the alias table as well as a 2-step
* model adding major release numbers to the deprecate and expire columns.
* Think twice about aliasing commonly used customer options.
*
* There are times when it is appropriate to leave a future release number as undefined.
*
* Tests: Aliases should be tested in VMAliasOptions.java.
* Deprecated options should be tested in VMDeprecatedOptions.java.
*/
// The special_jvm_flags table declares options that are being deprecated and/or obsoleted. The
// "deprecated_in" or "obsolete_in" fields may be set to "undefined", but not both.
// When the JDK version reaches 'deprecated_in' limit, the JVM will process this flag on
// the command-line as usual, but will issue a warning.
// When the JDK version reaches 'obsolete_in' limit, the JVM will continue accepting this flag on
// the command-line, while issuing a warning and ignoring the flag value.
// Once the JDK version reaches 'expired_in' limit, the JVM will flatly refuse to admit the
// existence of the flag.
//
// MANUAL CLEANUP ON JDK VERSION UPDATES:
// This table ensures that the handling of options will update automatically when the JDK
// version is incremented, but the source code needs to be cleanup up manually:
// - As "deprecated" options age into "obsolete" or "expired" options, the associated "globals"
// variable should be removed, as well as users of the variable.
// - As "deprecated" options age into "obsolete" options, move the entry into the
// "Obsolete Flags" section of the table.
// - All expired options should be removed from the table.
static SpecialFlag const special_jvm_flags[] = {
// -------------- Deprecated Flags --------------
// --- Non-alias flags - sorted by obsolete_in then expired_in:
{ "MaxGCMinorPauseMillis", JDK_Version::jdk(8), JDK_Version::undefined(), JDK_Version::undefined() },
{ "MaxRAMFraction", JDK_Version::jdk(10), JDK_Version::undefined(), JDK_Version::undefined() },
{ "MinRAMFraction", JDK_Version::jdk(10), JDK_Version::undefined(), JDK_Version::undefined() },
{ "InitialRAMFraction", JDK_Version::jdk(10), JDK_Version::undefined(), JDK_Version::undefined() },
{ "AllowRedefinitionToAddDeleteMethods", JDK_Version::jdk(13), JDK_Version::undefined(), JDK_Version::undefined() },
{ "FlightRecorder", JDK_Version::jdk(13), JDK_Version::undefined(), JDK_Version::undefined() },
{ "SuspendRetryCount", JDK_Version::undefined(), JDK_Version::jdk(17), JDK_Version::jdk(18) },
{ "SuspendRetryDelay", JDK_Version::undefined(), JDK_Version::jdk(17), JDK_Version::jdk(18) },
{ "CriticalJNINatives", JDK_Version::jdk(16), JDK_Version::jdk(18), JDK_Version::jdk(19) },
{ "AlwaysLockClassLoader", JDK_Version::jdk(17), JDK_Version::jdk(18), JDK_Version::jdk(19) },
{ "UseBiasedLocking", JDK_Version::jdk(15), JDK_Version::jdk(18), JDK_Version::jdk(19) },
{ "BiasedLockingStartupDelay", JDK_Version::jdk(15), JDK_Version::jdk(18), JDK_Version::jdk(19) },
{ "PrintBiasedLockingStatistics", JDK_Version::jdk(15), JDK_Version::jdk(18), JDK_Version::jdk(19) },
{ "BiasedLockingBulkRebiasThreshold", JDK_Version::jdk(15), JDK_Version::jdk(18), JDK_Version::jdk(19) },
{ "BiasedLockingBulkRevokeThreshold", JDK_Version::jdk(15), JDK_Version::jdk(18), JDK_Version::jdk(19) },
{ "BiasedLockingDecayTime", JDK_Version::jdk(15), JDK_Version::jdk(18), JDK_Version::jdk(19) },
{ "UseOptoBiasInlining", JDK_Version::jdk(15), JDK_Version::jdk(18), JDK_Version::jdk(19) },
{ "PrintPreciseBiasedLockingStatistics", JDK_Version::jdk(15), JDK_Version::jdk(18), JDK_Version::jdk(19) },
// --- Deprecated alias flags (see also aliased_jvm_flags) - sorted by obsolete_in then expired_in:
{ "DefaultMaxRAMFraction", JDK_Version::jdk(8), JDK_Version::undefined(), JDK_Version::undefined() },
{ "CreateMinidumpOnCrash", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::undefined() },
{ "TLABStats", JDK_Version::jdk(12), JDK_Version::undefined(), JDK_Version::undefined() },
// -------------- Obsolete Flags - sorted by expired_in --------------
{ "AssertOnSuspendWaitFailure", JDK_Version::undefined(), JDK_Version::jdk(17), JDK_Version::jdk(18) },
{ "TraceSuspendWaitFailures", JDK_Version::undefined(), JDK_Version::jdk(17), JDK_Version::jdk(18) },
#ifdef ASSERT
{ "DummyObsoleteTestFlag", JDK_Version::undefined(), JDK_Version::jdk(17), JDK_Version::undefined() },
#endif
#ifdef TEST_VERIFY_SPECIAL_JVM_FLAGS
// These entries will generate build errors. Their purpose is to test the macros.
{ "dep > obs", JDK_Version::jdk(9), JDK_Version::jdk(8), JDK_Version::undefined() },
{ "dep > exp ", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::jdk(8) },
{ "obs > exp ", JDK_Version::undefined(), JDK_Version::jdk(9), JDK_Version::jdk(8) },
{ "obs > exp", JDK_Version::jdk(8), JDK_Version::undefined(), JDK_Version::jdk(10) },
{ "not deprecated or obsolete", JDK_Version::undefined(), JDK_Version::undefined(), JDK_Version::jdk(9) },
{ "dup option", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::undefined() },
{ "dup option", JDK_Version::jdk(9), JDK_Version::undefined(), JDK_Version::undefined() },
#endif
{ NULL, JDK_Version(0), JDK_Version(0) }
};
// Flags that are aliases for other flags.
typedef struct {
const char* alias_name;
const char* real_name;
} AliasedFlag;
static AliasedFlag const aliased_jvm_flags[] = {
{ "DefaultMaxRAMFraction", "MaxRAMFraction" },
{ "CreateMinidumpOnCrash", "CreateCoredumpOnCrash" },
{ NULL, NULL}
};
// Return true if "v" is less than "other", where "other" may be "undefined".
static bool version_less_than(JDK_Version v, JDK_Version other) {
assert(!v.is_undefined(), "must be defined");
if (!other.is_undefined() && v.compare(other) >= 0) {
return false;
} else {
return true;
}
}
static bool lookup_special_flag(const char *flag_name, SpecialFlag& flag) {
for (size_t i = 0; special_jvm_flags[i].name != NULL; i++) {
if ((strcmp(special_jvm_flags[i].name, flag_name) == 0)) {
flag = special_jvm_flags[i];
return true;
}
}
return false;
}
bool Arguments::is_obsolete_flag(const char *flag_name, JDK_Version* version) {
assert(version != NULL, "Must provide a version buffer");
SpecialFlag flag;
if (lookup_special_flag(flag_name, flag)) {
if (!flag.obsolete_in.is_undefined()) {
if (!version_less_than(JDK_Version::current(), flag.obsolete_in)) {
*version = flag.obsolete_in;
// This flag may have been marked for obsoletion in this version, but we may not
// have actually removed it yet. Rather than ignoring it as soon as we reach
// this version we allow some time for the removal to happen. So if the flag
// still actually exists we process it as normal, but issue an adjusted warning.
const JVMFlag *real_flag = JVMFlag::find_declared_flag(flag_name);
if (real_flag != NULL) {
char version_str[256];
version->to_string(version_str, sizeof(version_str));
warning("Temporarily processing option %s; support is scheduled for removal in %s",
flag_name, version_str);
return false;
}
return true;
}
}
}
return false;
}
int Arguments::is_deprecated_flag(const char *flag_name, JDK_Version* version) {
assert(version != NULL, "Must provide a version buffer");
SpecialFlag flag;
if (lookup_special_flag(flag_name, flag)) {
if (!flag.deprecated_in.is_undefined()) {
if (version_less_than(JDK_Version::current(), flag.obsolete_in) &&
version_less_than(JDK_Version::current(), flag.expired_in)) {
*version = flag.deprecated_in;
return 1;
} else {
return -1;
}
}
}
return 0;
}
const char* Arguments::real_flag_name(const char *flag_name) {
for (size_t i = 0; aliased_jvm_flags[i].alias_name != NULL; i++) {
const AliasedFlag& flag_status = aliased_jvm_flags[i];
if (strcmp(flag_status.alias_name, flag_name) == 0) {
return flag_status.real_name;
}
}
return flag_name;
}
#ifdef ASSERT
static bool lookup_special_flag(const char *flag_name, size_t skip_index) {
for (size_t i = 0; special_jvm_flags[i].name != NULL; i++) {
if ((i != skip_index) && (strcmp(special_jvm_flags[i].name, flag_name) == 0)) {
return true;
}
}
return false;
}
// Verifies the correctness of the entries in the special_jvm_flags table.
// If there is a semantic error (i.e. a bug in the table) such as the obsoletion
// version being earlier than the deprecation version, then a warning is issued
// and verification fails - by returning false. If it is detected that the table
// is out of date, with respect to the current version, then ideally a warning is
// issued but verification does not fail. This allows the VM to operate when the
// version is first updated, without needing to update all the impacted flags at
// the same time. In practice we can't issue the warning immediately when the version
// is updated as it occurs for every test and some tests are not prepared to handle
// unexpected output - see 8196739. Instead we only check if the table is up-to-date
// if the check_globals flag is true, and in addition allow a grace period and only
// check for stale flags when we hit build 25 (which is far enough into the 6 month
// release cycle that all flag updates should have been processed, whilst still
// leaving time to make the change before RDP2).
// We use a gtest to call this, passing true, so that we can detect stale flags before
// the end of the release cycle.
static const int SPECIAL_FLAG_VALIDATION_BUILD = 25;
bool Arguments::verify_special_jvm_flags(bool check_globals) {
bool success = true;
for (size_t i = 0; special_jvm_flags[i].name != NULL; i++) {
const SpecialFlag& flag = special_jvm_flags[i];
if (lookup_special_flag(flag.name, i)) {
warning("Duplicate special flag declaration \"%s\"", flag.name);
success = false;
}
if (flag.deprecated_in.is_undefined() &&
flag.obsolete_in.is_undefined()) {
warning("Special flag entry \"%s\" must declare version deprecated and/or obsoleted in.", flag.name);
success = false;
}
if (!flag.deprecated_in.is_undefined()) {
if (!version_less_than(flag.deprecated_in, flag.obsolete_in)) {
warning("Special flag entry \"%s\" must be deprecated before obsoleted.", flag.name);
success = false;
}
if (!version_less_than(flag.deprecated_in, flag.expired_in)) {
warning("Special flag entry \"%s\" must be deprecated before expired.", flag.name);
success = false;
}
}
if (!flag.obsolete_in.is_undefined()) {
if (!version_less_than(flag.obsolete_in, flag.expired_in)) {
warning("Special flag entry \"%s\" must be obsoleted before expired.", flag.name);
success = false;
}
// if flag has become obsolete it should not have a "globals" flag defined anymore.
if (check_globals && VM_Version::vm_build_number() >= SPECIAL_FLAG_VALIDATION_BUILD &&
!version_less_than(JDK_Version::current(), flag.obsolete_in)) {
if (JVMFlag::find_declared_flag(flag.name) != NULL) {
warning("Global variable for obsolete special flag entry \"%s\" should be removed", flag.name);
success = false;
}
}
} else if (!flag.expired_in.is_undefined()) {
warning("Special flag entry \"%s\" must be explicitly obsoleted before expired.", flag.name);
success = false;
}
if (!flag.expired_in.is_undefined()) {
// if flag has become expired it should not have a "globals" flag defined anymore.
if (check_globals && VM_Version::vm_build_number() >= SPECIAL_FLAG_VALIDATION_BUILD &&
!version_less_than(JDK_Version::current(), flag.expired_in)) {
if (JVMFlag::find_declared_flag(flag.name) != NULL) {
warning("Global variable for expired flag entry \"%s\" should be removed", flag.name);
success = false;
}
}
}
}
return success;
}
#endif
// Parses a size specification string.
bool Arguments::atojulong(const char *s, julong* result) {
julong n = 0;
// First char must be a digit. Don't allow negative numbers or leading spaces.
if (!isdigit(*s)) {
return false;
}
bool is_hex = (s[0] == '0' && (s[1] == 'x' || s[1] == 'X'));
char* remainder;
errno = 0;
n = strtoull(s, &remainder, (is_hex ? 16 : 10));
if (errno != 0) {
return false;
}
// Fail if no number was read at all or if the remainder contains more than a single non-digit character.
if (remainder == s || strlen(remainder) > 1) {
return false;
}
switch (*remainder) {
case 'T': case 't':
*result = n * G * K;
// Check for overflow.
if (*result/((julong)G * K) != n) return false;
return true;
case 'G': case 'g':
*result = n * G;
if (*result/G != n) return false;
return true;
case 'M': case 'm':
*result = n * M;
if (*result/M != n) return false;
return true;
case 'K': case 'k':
*result = n * K;
if (*result/K != n) return false;
return true;
case '\0':
*result = n;
return true;
default:
return false;
}
}
Arguments::ArgsRange Arguments::check_memory_size(julong size, julong min_size, julong max_size) {
if (size < min_size) return arg_too_small;
if (size > max_size) return arg_too_big;
return arg_in_range;
}
// Describe an argument out of range error
void Arguments::describe_range_error(ArgsRange errcode) {
switch(errcode) {
case arg_too_big:
jio_fprintf(defaultStream::error_stream(),
"The specified size exceeds the maximum "
"representable size.\n");
break;
case arg_too_small:
case arg_unreadable:
case arg_in_range:
// do nothing for now
break;
default:
ShouldNotReachHere();
}
}
static bool set_bool_flag(JVMFlag* flag, bool value, JVMFlagOrigin origin) {
if (JVMFlagAccess::set_bool(flag, &value, origin) == JVMFlag::SUCCESS) {
return true;
} else {
return false;
}
}
static bool set_fp_numeric_flag(JVMFlag* flag, char* value, JVMFlagOrigin origin) {
char* end;
errno = 0;
double v = strtod(value, &end);
if ((errno != 0) || (*end != 0)) {
return false;
}
if (JVMFlagAccess::set_double(flag, &v, origin) == JVMFlag::SUCCESS) {
return true;
}
return false;
}
static bool set_numeric_flag(JVMFlag* flag, char* value, JVMFlagOrigin origin) {
julong v;
int int_v;
intx intx_v;
bool is_neg = false;
if (flag == NULL) {
return false;
}
// Check the sign first since atojulong() parses only unsigned values.
if (*value == '-') {
if (!flag->is_intx() && !flag->is_int()) {
return false;
}
value++;
is_neg = true;
}
if (!Arguments::atojulong(value, &v)) {
return false;
}
if (flag->is_int()) {
int_v = (int) v;
if (is_neg) {
int_v = -int_v;
}
return JVMFlagAccess::set_int(flag, &int_v, origin) == JVMFlag::SUCCESS;
} else if (flag->is_uint()) {
uint uint_v = (uint) v;
return JVMFlagAccess::set_uint(flag, &uint_v, origin) == JVMFlag::SUCCESS;
} else if (flag->is_intx()) {
intx_v = (intx) v;
if (is_neg) {
intx_v = -intx_v;
}
return JVMFlagAccess::set_intx(flag, &intx_v, origin) == JVMFlag::SUCCESS;
} else if (flag->is_uintx()) {
uintx uintx_v = (uintx) v;
return JVMFlagAccess::set_uintx(flag, &uintx_v, origin) == JVMFlag::SUCCESS;
} else if (flag->is_uint64_t()) {
uint64_t uint64_t_v = (uint64_t) v;
return JVMFlagAccess::set_uint64_t(flag, &uint64_t_v, origin) == JVMFlag::SUCCESS;
} else if (flag->is_size_t()) {
size_t size_t_v = (size_t) v;
return JVMFlagAccess::set_size_t(flag, &size_t_v, origin) == JVMFlag::SUCCESS;
} else if (flag->is_double()) {
double double_v = (double) v;
return JVMFlagAccess::set_double(flag, &double_v, origin) == JVMFlag::SUCCESS;
} else {
return false;
}
}
static bool set_string_flag(JVMFlag* flag, const char* value, JVMFlagOrigin origin) {
if (JVMFlagAccess::set_ccstr(flag, &value, origin) != JVMFlag::SUCCESS) return false;
// Contract: JVMFlag always returns a pointer that needs freeing.
FREE_C_HEAP_ARRAY(char, value);
return true;
}
static bool append_to_string_flag(JVMFlag* flag, const char* new_value, JVMFlagOrigin origin) {
const char* old_value = "";
if (JVMFlagAccess::get_ccstr(flag, &old_value) != JVMFlag::SUCCESS) return false;
size_t old_len = old_value != NULL ? strlen(old_value) : 0;
size_t new_len = strlen(new_value);
const char* value;
char* free_this_too = NULL;
if (old_len == 0) {
value = new_value;
} else if (new_len == 0) {
value = old_value;
} else {
size_t length = old_len + 1 + new_len + 1;
char* buf = NEW_C_HEAP_ARRAY(char, length, mtArguments);
// each new setting adds another LINE to the switch:
jio_snprintf(buf, length, "%s\n%s", old_value, new_value);
value = buf;
free_this_too = buf;
}
(void) JVMFlagAccess::set_ccstr(flag, &value, origin);
// JVMFlag always returns a pointer that needs freeing.
FREE_C_HEAP_ARRAY(char, value);
// JVMFlag made its own copy, so I must delete my own temp. buffer.
FREE_C_HEAP_ARRAY(char, free_this_too);
return true;
}
const char* Arguments::handle_aliases_and_deprecation(const char* arg, bool warn) {
const char* real_name = real_flag_name(arg);
JDK_Version since = JDK_Version();
switch (is_deprecated_flag(arg, &since)) {
case -1: {
// Obsolete or expired, so don't process normally,
// but allow for an obsolete flag we're still
// temporarily allowing.
if (!is_obsolete_flag(arg, &since)) {
return real_name;
}
// Note if we're not considered obsolete then we can't be expired either
// as obsoletion must come first.
return NULL;
}
case 0:
return real_name;
case 1: {
if (warn) {
char version[256];
since.to_string(version, sizeof(version));
if (real_name != arg) {
warning("Option %s was deprecated in version %s and will likely be removed in a future release. Use option %s instead.",
arg, version, real_name);
} else {
warning("Option %s was deprecated in version %s and will likely be removed in a future release.",
arg, version);
}
}
return real_name;
}
}
ShouldNotReachHere();
return NULL;
}
bool Arguments::parse_argument(const char* arg, JVMFlagOrigin origin) {
// range of acceptable characters spelled out for portability reasons
#define NAME_RANGE "[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]"
#define BUFLEN 255
char name[BUFLEN+1];
char dummy;
const char* real_name;
bool warn_if_deprecated = true;
if (sscanf(arg, "-%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
real_name = handle_aliases_and_deprecation(name, warn_if_deprecated);
if (real_name == NULL) {
return false;
}
JVMFlag* flag = JVMFlag::find_flag(real_name);
return set_bool_flag(flag, false, origin);
}
if (sscanf(arg, "+%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
real_name = handle_aliases_and_deprecation(name, warn_if_deprecated);
if (real_name == NULL) {
return false;
}
JVMFlag* flag = JVMFlag::find_flag(real_name);
return set_bool_flag(flag, true, origin);
}
char punct;
if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "%c", name, &punct) == 2 && punct == '=') {
const char* value = strchr(arg, '=') + 1;
// this scanf pattern matches both strings (handled here) and numbers (handled later))
real_name = handle_aliases_and_deprecation(name, warn_if_deprecated);
if (real_name == NULL) {
return false;
}
JVMFlag* flag = JVMFlag::find_flag(real_name);
if (flag != NULL && flag->is_ccstr()) {
if (flag->ccstr_accumulates()) {
return append_to_string_flag(flag, value, origin);
} else {
if (value[0] == '\0') {