This repository was archived by the owner on Sep 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 286
Expand file tree
/
Copy patharguments.cpp
More file actions
4427 lines (3975 loc) · 166 KB
/
arguments.cpp
File metadata and controls
4427 lines (3975 loc) · 166 KB
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, 2019, 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 "classfile/classLoader.hpp"
#include "classfile/javaAssertions.hpp"
#include "classfile/symbolTable.hpp"
#include "compiler/compilerOracle.hpp"
#include "memory/allocation.inline.hpp"
#include "memory/cardTableRS.hpp"
#include "memory/genCollectedHeap.hpp"
#include "memory/referenceProcessor.hpp"
#include "memory/universe.inline.hpp"
#include "oops/oop.inline.hpp"
#include "prims/jvmtiExport.hpp"
#include "runtime/arguments.hpp"
#include "runtime/arguments_ext.hpp"
#include "runtime/globals_extension.hpp"
#include "runtime/java.hpp"
#include "services/management.hpp"
#include "services/memTracker.hpp"
#include "utilities/defaultStream.hpp"
#include "utilities/macros.hpp"
#include "utilities/stringUtils.hpp"
#include "utilities/taskqueue.hpp"
#if INCLUDE_JFR
#include "jfr/jfr.hpp"
#endif
#ifdef TARGET_OS_FAMILY_linux
# include "os_linux.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_solaris
# include "os_solaris.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_windows
# include "os_windows.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_aix
# include "os_aix.inline.hpp"
#endif
#ifdef TARGET_OS_FAMILY_bsd
# include "os_bsd.inline.hpp"
#endif
#if INCLUDE_ALL_GCS
#include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp"
#include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
#include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
#endif // INCLUDE_ALL_GCS
// Note: This is a special bug reporting site for the JVM
#ifdef VENDOR_URL_VM_BUG
# define DEFAULT_VENDOR_URL_BUG VENDOR_URL_VM_BUG
#else
# define DEFAULT_VENDOR_URL_BUG "http://bugreport.java.com/bugreport/crash.jsp"
#endif
#define DEFAULT_JAVA_LAUNCHER "generic"
// Disable options not supported in this release, with a warning if they
// were explicitly requested on the command-line
#define UNSUPPORTED_OPTION(opt, description) \
do { \
if (opt) { \
if (FLAG_IS_CMDLINE(opt)) { \
warning(description " is disabled in this release."); \
} \
FLAG_SET_DEFAULT(opt, false); \
} \
} while(0)
#define UNSUPPORTED_GC_OPTION(gc) \
do { \
if (gc) { \
if (FLAG_IS_CMDLINE(gc)) { \
warning(#gc " is not supported in this VM. Using Serial GC."); \
} \
FLAG_SET_DEFAULT(gc, false); \
} \
} while(0)
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;
bool Arguments::_has_profile = false;
size_t Arguments::_conservative_max_heap_alignment = 0;
uintx Arguments::_min_heap_size = 0;
uintx Arguments::_min_heap_free_ratio = 0;
uintx Arguments::_max_heap_free_ratio = 0;
Arguments::Mode Arguments::_mode = _mixed;
bool Arguments::_java_compiler = false;
bool Arguments::_xdebug_mode = false;
const char* Arguments::_java_vendor_url_bug = DEFAULT_VENDOR_URL_BUG;
const char* Arguments::_sun_java_launcher = DEFAULT_JAVA_LAUNCHER;
int Arguments::_sun_java_launcher_pid = -1;
bool Arguments::_created_by_gamma_launcher = false;
// These parameters are reset in method parse_vm_init_args(JavaVMInitArgs*)
bool Arguments::_AlwaysCompileLoopMethods = AlwaysCompileLoopMethods;
bool Arguments::_UseOnStackReplacement = UseOnStackReplacement;
bool Arguments::_BackgroundCompilation = BackgroundCompilation;
bool Arguments::_ClipInlining = ClipInlining;
char* Arguments::SharedArchivePath = NULL;
AgentLibraryList Arguments::_libraryList;
AgentLibraryList Arguments::_agentList;
abort_hook_t Arguments::_abort_hook = NULL;
exit_hook_t Arguments::_exit_hook = NULL;
vfprintf_hook_t Arguments::_vfprintf_hook = NULL;
SystemProperty *Arguments::_java_ext_dirs = NULL;
SystemProperty *Arguments::_java_endorsed_dirs = 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::_sun_boot_class_path = NULL;
char* Arguments::_meta_index_path = NULL;
char* Arguments::_meta_index_dir = NULL;
// Check if head of 'option' matches 'name', and sets 'tail' remaining part of option string
static bool match_option(const JavaVMOption *option, const char* name,
const char** tail) {
int len = (int)strlen(name);
if (strncmp(option->optionString, name, len) == 0) {
*tail = option->optionString + len;
return true;
} else {
return false;
}
}
#if INCLUDE_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)) {
return Jfr::on_start_flight_recording_option(option, tail);
} else if (match_option(*option, "-XX:FlightRecorderOptions", (const char**)&tail)) {
return Jfr::on_flight_recorder_option(option, tail);
}
return false;
}
#endif
static void logOption(const char* opt) {
if (PrintVMOptions) {
jio_fprintf(defaultStream::output_stream(), "VM option '%s'\n", opt);
}
}
// Process java launcher properties.
void Arguments::process_sun_java_launcher_properties(JavaVMInitArgs* args) {
// See if sun.java.launcher or sun.java.launcher.pid 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.pid=", &tail)) {
_sun_java_launcher_pid = atoi(tail);
continue;
}
}
}
// Initialize system properties key and value.
void Arguments::init_system_properties() {
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("java.vm.info", VM_Version::vm_info_string(), true));
// following are JVMTI agent writeable properties.
// Properties values are set to NULL and they are
// os specific they are initialized in os::init_system_properties_values().
_java_ext_dirs = new SystemProperty("java.ext.dirs", NULL, true);
_java_endorsed_dirs = new SystemProperty("java.endorsed.dirs", NULL, true);
_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);
_sun_boot_class_path = new SystemProperty("sun.boot.class.path", NULL, true);
_java_class_path = new SystemProperty("java.class.path", "", true);
// Add to System Property list.
PropertyList_add(&_system_properties, _java_ext_dirs);
PropertyList_add(&_system_properties, _java_endorsed_dirs);
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, _sun_boot_class_path);
// 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 = "Sun Microsystems Inc.";
uint32_t spec_version = 0;
if (JDK_Version::is_gte_jdk17x_version()) {
spec_vendor = "Oracle Corporation";
spec_version = JDK_Version::current().major_version();
}
jio_snprintf(buffer, bufsz, "1." 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));
}
/**
* Provide a slightly more user-friendly way of eliminating -XX flags.
* When a flag is eliminated, it can be added to this list in order to
* continue accepting this flag on the command-line, while issuing a warning
* and ignoring the value. Once the JDK version reaches the 'accept_until'
* limit, we flatly refuse to admit the existence of the flag. This allows
* a flag to die correctly over JDK releases using HSX.
*/
typedef struct {
const char* name;
JDK_Version obsoleted_in; // when the flag went away
JDK_Version accept_until; // which version to start denying the existence
} ObsoleteFlag;
static ObsoleteFlag obsolete_jvm_flags[] = {
{ "UseTrainGC", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "UseSpecialLargeObjectHandling", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "UseOversizedCarHandling", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "TraceCarAllocation", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "PrintTrainGCProcessingStats", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "LogOfCarSpaceSize", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "OversizedCarThreshold", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "MinTickInterval", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "DefaultTickInterval", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "MaxTickInterval", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "DelayTickAdjustment", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "ProcessingToTenuringRatio", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "MinTrainLength", JDK_Version::jdk(5), JDK_Version::jdk(7) },
{ "AppendRatio", JDK_Version::jdk_update(6,10), JDK_Version::jdk(7) },
{ "DefaultMaxRAM", JDK_Version::jdk_update(6,18), JDK_Version::jdk(7) },
{ "DefaultInitialRAMFraction",
JDK_Version::jdk_update(6,18), JDK_Version::jdk(7) },
{ "UseDepthFirstScavengeOrder",
JDK_Version::jdk_update(6,22), JDK_Version::jdk(7) },
{ "HandlePromotionFailure",
JDK_Version::jdk_update(6,24), JDK_Version::jdk(8) },
{ "MaxLiveObjectEvacuationRatio",
JDK_Version::jdk_update(6,24), JDK_Version::jdk(8) },
{ "ForceSharedSpaces", JDK_Version::jdk_update(6,25), JDK_Version::jdk(8) },
{ "UseParallelOldGCCompacting",
JDK_Version::jdk_update(6,27), JDK_Version::jdk(8) },
{ "UseParallelDensePrefixUpdate",
JDK_Version::jdk_update(6,27), JDK_Version::jdk(8) },
{ "UseParallelOldGCDensePrefix",
JDK_Version::jdk_update(6,27), JDK_Version::jdk(8) },
{ "AllowTransitionalJSR292", JDK_Version::jdk(7), JDK_Version::jdk(8) },
{ "UseCompressedStrings", JDK_Version::jdk(7), JDK_Version::jdk(8) },
{ "CMSPermGenPrecleaningEnabled", JDK_Version::jdk(8), JDK_Version::jdk(9) },
{ "CMSTriggerPermRatio", JDK_Version::jdk(8), JDK_Version::jdk(9) },
{ "CMSInitiatingPermOccupancyFraction", JDK_Version::jdk(8), JDK_Version::jdk(9) },
{ "AdaptivePermSizeWeight", JDK_Version::jdk(8), JDK_Version::jdk(9) },
{ "PermGenPadding", JDK_Version::jdk(8), JDK_Version::jdk(9) },
{ "PermMarkSweepDeadRatio", JDK_Version::jdk(8), JDK_Version::jdk(9) },
{ "PermSize", JDK_Version::jdk(8), JDK_Version::jdk(9) },
{ "MaxPermSize", JDK_Version::jdk(8), JDK_Version::jdk(9) },
{ "MinPermHeapExpansion", JDK_Version::jdk(8), JDK_Version::jdk(9) },
{ "MaxPermHeapExpansion", JDK_Version::jdk(8), JDK_Version::jdk(9) },
{ "CMSRevisitStackSize", JDK_Version::jdk(8), JDK_Version::jdk(9) },
{ "PrintRevisitStats", JDK_Version::jdk(8), JDK_Version::jdk(9) },
{ "UseVectoredExceptions", JDK_Version::jdk(8), JDK_Version::jdk(9) },
{ "UseSplitVerifier", JDK_Version::jdk(8), JDK_Version::jdk(9) },
{ "UseISM", JDK_Version::jdk(8), JDK_Version::jdk(9) },
{ "UsePermISM", JDK_Version::jdk(8), JDK_Version::jdk(9) },
{ "UseMPSS", JDK_Version::jdk(8), JDK_Version::jdk(9) },
{ "UseStringCache", JDK_Version::jdk(8), JDK_Version::jdk(9) },
{ "UseOldInlining", JDK_Version::jdk_update(8, 20), JDK_Version::jdk(10) },
{ "AutoShutdownNMT", JDK_Version::jdk_update(8, 40), JDK_Version::jdk(10) },
{ "CompilationRepeat", JDK_Version::jdk(8), JDK_Version::jdk(9) },
{ "SegmentedHeapDumpThreshold", JDK_Version::jdk_update(8, 252), JDK_Version::jdk(10) },
#ifdef PRODUCT
{ "DesiredMethodLimit",
JDK_Version::jdk_update(7, 2), JDK_Version::jdk(8) },
#endif // PRODUCT
{ NULL, JDK_Version(0), JDK_Version(0) }
};
// Returns true if the flag is obsolete and fits into the range specified
// for being ignored. In the case that the flag is ignored, the 'version'
// value is filled in with the version number when the flag became
// obsolete so that that value can be displayed to the user.
bool Arguments::is_newly_obsolete(const char *s, JDK_Version* version) {
int i = 0;
assert(version != NULL, "Must provide a version buffer");
while (obsolete_jvm_flags[i].name != NULL) {
const ObsoleteFlag& flag_status = obsolete_jvm_flags[i];
// <flag>=xxx form
// [-|+]<flag> form
if ((strncmp(flag_status.name, s, strlen(flag_status.name)) == 0) ||
((s[0] == '+' || s[0] == '-') &&
(strncmp(flag_status.name, &s[1], strlen(flag_status.name)) == 0))) {
if (JDK_Version::current().compare(flag_status.accept_until) == -1) {
*version = flag_status.obsoleted_in;
return true;
}
}
i++;
}
return false;
}
// Constructs the system class path (aka boot class path) from the following
// components, in order:
//
// prefix // from -Xbootclasspath/p:...
// endorsed // the expansion of -Djava.endorsed.dirs=...
// base // from os::get_system_properties() or -Xbootclasspath=
// suffix // from -Xbootclasspath/a:...
//
// java.endorsed.dirs is a list of directories; any jar or zip files in the
// directories are added to the sysclasspath just before the base.
//
// This could be AllStatic, but it isn't needed after argument processing is
// complete.
class SysClassPath: public StackObj {
public:
SysClassPath(const char* base);
~SysClassPath();
inline void set_base(const char* base);
inline void add_prefix(const char* prefix);
inline void add_suffix_to_prefix(const char* suffix);
inline void add_suffix(const char* suffix);
inline void reset_path(const char* base);
// Expand the jar/zip files in each directory listed by the java.endorsed.dirs
// property. Must be called after all command-line arguments have been
// processed (in particular, -Djava.endorsed.dirs=...) and before calling
// combined_path().
void expand_endorsed();
inline const char* get_base() const { return _items[_scp_base]; }
inline const char* get_prefix() const { return _items[_scp_prefix]; }
inline const char* get_suffix() const { return _items[_scp_suffix]; }
inline const char* get_endorsed() const { return _items[_scp_endorsed]; }
// Combine all the components into a single c-heap-allocated string; caller
// must free the string if/when no longer needed.
char* combined_path();
private:
// Utility routines.
static char* add_to_path(const char* path, const char* str, bool prepend);
static char* add_jars_to_path(char* path, const char* directory);
inline void reset_item_at(int index);
// Array indices for the items that make up the sysclasspath. All except the
// base are allocated in the C heap and freed by this class.
enum {
_scp_prefix, // from -Xbootclasspath/p:...
_scp_endorsed, // the expansion of -Djava.endorsed.dirs=...
_scp_base, // the default sysclasspath
_scp_suffix, // from -Xbootclasspath/a:...
_scp_nitems // the number of items, must be last.
};
const char* _items[_scp_nitems];
DEBUG_ONLY(bool _expansion_done;)
};
SysClassPath::SysClassPath(const char* base) {
memset(_items, 0, sizeof(_items));
_items[_scp_base] = base;
DEBUG_ONLY(_expansion_done = false;)
}
SysClassPath::~SysClassPath() {
// Free everything except the base.
for (int i = 0; i < _scp_nitems; ++i) {
if (i != _scp_base) reset_item_at(i);
}
DEBUG_ONLY(_expansion_done = false;)
}
inline void SysClassPath::set_base(const char* base) {
_items[_scp_base] = base;
}
inline void SysClassPath::add_prefix(const char* prefix) {
_items[_scp_prefix] = add_to_path(_items[_scp_prefix], prefix, true);
}
inline void SysClassPath::add_suffix_to_prefix(const char* suffix) {
_items[_scp_prefix] = add_to_path(_items[_scp_prefix], suffix, false);
}
inline void SysClassPath::add_suffix(const char* suffix) {
_items[_scp_suffix] = add_to_path(_items[_scp_suffix], suffix, false);
}
inline void SysClassPath::reset_item_at(int index) {
assert(index < _scp_nitems && index != _scp_base, "just checking");
if (_items[index] != NULL) {
FREE_C_HEAP_ARRAY(char, _items[index], mtInternal);
_items[index] = NULL;
}
}
inline void SysClassPath::reset_path(const char* base) {
// Clear the prefix and suffix.
reset_item_at(_scp_prefix);
reset_item_at(_scp_suffix);
set_base(base);
}
//------------------------------------------------------------------------------
void SysClassPath::expand_endorsed() {
assert(_items[_scp_endorsed] == NULL, "can only be called once.");
const char* path = Arguments::get_property("java.endorsed.dirs");
if (path == NULL) {
path = Arguments::get_endorsed_dir();
assert(path != NULL, "no default for java.endorsed.dirs");
}
char* expanded_path = NULL;
const char separator = *os::path_separator();
const char* const end = path + strlen(path);
while (path < end) {
const char* tmp_end = strchr(path, separator);
if (tmp_end == NULL) {
expanded_path = add_jars_to_path(expanded_path, path);
path = end;
} else {
char* dirpath = NEW_C_HEAP_ARRAY(char, tmp_end - path + 1, mtInternal);
memcpy(dirpath, path, tmp_end - path);
dirpath[tmp_end - path] = '\0';
expanded_path = add_jars_to_path(expanded_path, dirpath);
FREE_C_HEAP_ARRAY(char, dirpath, mtInternal);
path = tmp_end + 1;
}
}
_items[_scp_endorsed] = expanded_path;
DEBUG_ONLY(_expansion_done = true;)
}
// Combine the bootclasspath elements, some of which may be null, into a single
// c-heap-allocated string.
char* SysClassPath::combined_path() {
assert(_items[_scp_base] != NULL, "empty default sysclasspath");
assert(_expansion_done, "must call expand_endorsed() first.");
size_t lengths[_scp_nitems];
size_t total_len = 0;
const char separator = *os::path_separator();
// Get the lengths.
int i;
for (i = 0; i < _scp_nitems; ++i) {
if (_items[i] != NULL) {
lengths[i] = strlen(_items[i]);
// Include space for the separator char (or a NULL for the last item).
total_len += lengths[i] + 1;
}
}
assert(total_len > 0, "empty sysclasspath not allowed");
// Copy the _items to a single string.
char* cp = NEW_C_HEAP_ARRAY(char, total_len, mtInternal);
char* cp_tmp = cp;
for (i = 0; i < _scp_nitems; ++i) {
if (_items[i] != NULL) {
memcpy(cp_tmp, _items[i], lengths[i]);
cp_tmp += lengths[i];
*cp_tmp++ = separator;
}
}
*--cp_tmp = '\0'; // Replace the extra separator.
return cp;
}
// Note: path must be c-heap-allocated (or NULL); it is freed if non-null.
char*
SysClassPath::add_to_path(const char* path, const char* str, bool prepend) {
char *cp;
assert(str != NULL, "just checking");
if (path == NULL) {
size_t len = strlen(str) + 1;
cp = NEW_C_HEAP_ARRAY(char, len, mtInternal);
memcpy(cp, str, len); // copy the trailing null
} else {
const char separator = *os::path_separator();
size_t old_len = strlen(path);
size_t str_len = strlen(str);
size_t len = old_len + str_len + 2;
if (prepend) {
cp = NEW_C_HEAP_ARRAY(char, len, mtInternal);
char* cp_tmp = cp;
memcpy(cp_tmp, str, str_len);
cp_tmp += str_len;
*cp_tmp = separator;
memcpy(++cp_tmp, path, old_len + 1); // copy the trailing null
FREE_C_HEAP_ARRAY(char, path, mtInternal);
} else {
cp = REALLOC_C_HEAP_ARRAY(char, path, len, mtInternal);
char* cp_tmp = cp + old_len;
*cp_tmp = separator;
memcpy(++cp_tmp, str, str_len + 1); // copy the trailing null
}
}
return cp;
}
// Scan the directory and append any jar or zip files found to path.
// Note: path must be c-heap-allocated (or NULL); it is freed if non-null.
char* SysClassPath::add_jars_to_path(char* path, const char* directory) {
DIR* dir = os::opendir(directory);
if (dir == NULL) return path;
char dir_sep[2] = { '\0', '\0' };
size_t directory_len = strlen(directory);
const char fileSep = *os::file_separator();
if (directory[directory_len - 1] != fileSep) dir_sep[0] = fileSep;
/* Scan the directory for jars/zips, appending them to path. */
struct dirent *entry;
while ((entry = os::readdir(dir)) != NULL) {
const char* name = entry->d_name;
const char* ext = name + strlen(name) - 4;
bool isJarOrZip = ext > name &&
(os::file_name_strcmp(ext, ".jar") == 0 ||
os::file_name_strcmp(ext, ".zip") == 0);
if (isJarOrZip) {
size_t length = directory_len + 2 + strlen(name);
char* jarpath = NEW_C_HEAP_ARRAY(char, length, mtInternal);
jio_snprintf(jarpath, length, "%s%s%s", directory, dir_sep, name);
path = add_to_path(path, jarpath, false);
FREE_C_HEAP_ARRAY(char, jarpath, mtInternal);
}
}
os::closedir(dir);
return path;
}
// Parses a memory size specification string.
static bool atomull(const char *s, julong* result) {
julong n = 0;
int args_read = sscanf(s, JULONG_FORMAT, &n);
if (args_read != 1) {
return false;
}
while (*s != '\0' && isdigit(*s)) {
s++;
}
// 4705540: illegal if more characters are found after the first non-digit
if (strlen(s) > 1) {
return false;
}
switch (*s) {
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) {
if (size < min_size) return arg_too_small;
// Check that size will fit in a size_t (only relevant on 32-bit)
if (size > max_uintx) 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(char* name, bool value, Flag::Flags origin) {
return CommandLineFlags::boolAtPut(name, &value, origin);
}
static bool set_fp_numeric_flag(char* name, char* value, Flag::Flags origin) {
double v;
if (sscanf(value, "%lf", &v) != 1) {
return false;
}
if (CommandLineFlags::doubleAtPut(name, &v, origin)) {
return true;
}
return false;
}
static bool set_numeric_flag(char* name, char* value, Flag::Flags origin) {
julong v;
intx intx_v;
bool is_neg = false;
// Check the sign first since atomull() parses only unsigned values.
if (*value == '-') {
if (!CommandLineFlags::intxAt(name, &intx_v)) {
return false;
}
value++;
is_neg = true;
}
if (!atomull(value, &v)) {
return false;
}
intx_v = (intx) v;
if (is_neg) {
intx_v = -intx_v;
}
if (CommandLineFlags::intxAtPut(name, &intx_v, origin)) {
return true;
}
uintx uintx_v = (uintx) v;
if (!is_neg && CommandLineFlags::uintxAtPut(name, &uintx_v, origin)) {
return true;
}
uint64_t uint64_t_v = (uint64_t) v;
if (!is_neg && CommandLineFlags::uint64_tAtPut(name, &uint64_t_v, origin)) {
return true;
}
return false;
}
static bool set_string_flag(char* name, const char* value, Flag::Flags origin) {
if (!CommandLineFlags::ccstrAtPut(name, &value, origin)) return false;
// Contract: CommandLineFlags always returns a pointer that needs freeing.
FREE_C_HEAP_ARRAY(char, value, mtInternal);
return true;
}
static bool append_to_string_flag(char* name, const char* new_value, Flag::Flags origin) {
const char* old_value = "";
if (!CommandLineFlags::ccstrAt(name, &old_value)) 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, mtInternal);
// 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) CommandLineFlags::ccstrAtPut(name, &value, origin);
// CommandLineFlags always returns a pointer that needs freeing.
FREE_C_HEAP_ARRAY(char, value, mtInternal);
if (free_this_too != NULL) {
// CommandLineFlags made its own copy, so I must delete my own temp. buffer.
FREE_C_HEAP_ARRAY(char, free_this_too, mtInternal);
}
return true;
}
bool Arguments::parse_argument(const char* arg, Flag::Flags origin) {
// range of acceptable characters spelled out for portability reasons
#define NAME_RANGE "[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]"
#define BUFLEN 255
char name[BUFLEN+1];
char dummy;
if (sscanf(arg, "-%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
return set_bool_flag(name, false, origin);
}
if (sscanf(arg, "+%" XSTR(BUFLEN) NAME_RANGE "%c", name, &dummy) == 1) {
return set_bool_flag(name, true, origin);
}
char punct;
if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "%c", name, &punct) == 2 && punct == '=') {
const char* value = strchr(arg, '=') + 1;
Flag* flag = Flag::find_flag(name, strlen(name));
if (flag != NULL && flag->is_ccstr()) {
if (flag->ccstr_accumulates()) {
return append_to_string_flag(name, value, origin);
} else {
if (value[0] == '\0') {
value = NULL;
}
return set_string_flag(name, value, origin);
}
}
}
if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE ":%c", name, &punct) == 2 && punct == '=') {
const char* value = strchr(arg, '=') + 1;
// -XX:Foo:=xxx will reset the string flag to the given value.
if (value[0] == '\0') {
value = NULL;
}
return set_string_flag(name, value, origin);
}
#define SIGNED_FP_NUMBER_RANGE "[-0123456789.]"
#define SIGNED_NUMBER_RANGE "[-0123456789]"
#define NUMBER_RANGE "[0123456789]"
char value[BUFLEN + 1];
char value2[BUFLEN + 1];
if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_NUMBER_RANGE "." "%" XSTR(BUFLEN) NUMBER_RANGE "%c", name, value, value2, &dummy) == 3) {
// Looks like a floating-point number -- try again with more lenient format string
if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) SIGNED_FP_NUMBER_RANGE "%c", name, value, &dummy) == 2) {
return set_fp_numeric_flag(name, value, origin);
}
}
#define VALUE_RANGE "[-kmgtKMGT0123456789]"
if (sscanf(arg, "%" XSTR(BUFLEN) NAME_RANGE "=" "%" XSTR(BUFLEN) VALUE_RANGE "%c", name, value, &dummy) == 2) {
return set_numeric_flag(name, value, origin);
}
return false;
}
void Arguments::add_string(char*** bldarray, int* count, const char* arg) {
assert(bldarray != NULL, "illegal argument");
if (arg == NULL) {
return;
}
int new_count = *count + 1;
// expand the array and add arg to the last element
if (*bldarray == NULL) {
*bldarray = NEW_C_HEAP_ARRAY(char*, new_count, mtInternal);
} else {
*bldarray = REALLOC_C_HEAP_ARRAY(char*, *bldarray, new_count, mtInternal);
}
(*bldarray)[*count] = strdup(arg);
*count = new_count;
}
void Arguments::build_jvm_args(const char* arg) {
add_string(&_jvm_args_array, &_num_jvm_args, arg);
}
void Arguments::build_jvm_flags(const char* arg) {
add_string(&_jvm_flags_array, &_num_jvm_flags, arg);
}
// utility function to return a string that concatenates all
// strings in a given char** array
const char* Arguments::build_resource_string(char** args, int count) {
if (args == NULL || count == 0) {
return NULL;
}
size_t length = 0;
for (int i = 0; i < count; i++) {
length += strlen(args[i]) + 1; // add 1 for a space or NULL terminating character
}
char* s = NEW_RESOURCE_ARRAY(char, length);
char* dst = s;
for (int j = 0; j < count; j++) {
size_t offset = strlen(args[j]) + 1; // add 1 for a space or NULL terminating character
jio_snprintf(dst, length, "%s ", args[j]); // jio_snprintf will replace the last space character with NULL character
dst += offset;
length -= offset;
}
return (const char*) s;
}
void Arguments::print_on(outputStream* st) {
st->print_cr("VM Arguments:");
if (num_jvm_flags() > 0) {
st->print("jvm_flags: "); print_jvm_flags_on(st);
}
if (num_jvm_args() > 0) {
st->print("jvm_args: "); print_jvm_args_on(st);
}
st->print_cr("java_command: %s", java_command() ? java_command() : "<unknown>");
if (_java_class_path != NULL) {
char* path = _java_class_path->value();
st->print_cr("java_class_path (initial): %s", strlen(path) == 0 ? "<not set>" : path );
}
st->print_cr("Launcher Type: %s", _sun_java_launcher);
}
void Arguments::print_jvm_flags_on(outputStream* st) {
if (_num_jvm_flags > 0) {
for (int i=0; i < _num_jvm_flags; i++) {
st->print("%s ", _jvm_flags_array[i]);
}
st->cr();
}
}
void Arguments::print_jvm_args_on(outputStream* st) {
if (_num_jvm_args > 0) {
for (int i=0; i < _num_jvm_args; i++) {
st->print("%s ", _jvm_args_array[i]);
}
st->cr();
}
}
bool Arguments::process_argument(const char* arg,
jboolean ignore_unrecognized, Flag::Flags origin) {
JDK_Version since = JDK_Version();
if (parse_argument(arg, origin) || ignore_unrecognized) {
return true;
}
bool has_plus_minus = (*arg == '+' || *arg == '-');
const char* const argname = has_plus_minus ? arg + 1 : arg;
if (is_newly_obsolete(arg, &since)) {
char version[256];
since.to_string(version, sizeof(version));
warning("ignoring option %s; support was removed in %s", argname, version);
return true;
}
// For locked flags, report a custom error message if available.
// Otherwise, report the standard unrecognized VM option.
size_t arg_len;
const char* equal_sign = strchr(argname, '=');
if (equal_sign == NULL) {
arg_len = strlen(argname);
} else {
arg_len = equal_sign - argname;
}
Flag* found_flag = Flag::find_flag((const char*)argname, arg_len, true, true);
if (found_flag != NULL) {
char locked_message_buf[BUFLEN];
found_flag->get_locked_message(locked_message_buf, BUFLEN);
if (strlen(locked_message_buf) == 0) {
if (found_flag->is_bool() && !has_plus_minus) {
jio_fprintf(defaultStream::error_stream(),
"Missing +/- setting for VM option '%s'\n", argname);
} else if (!found_flag->is_bool() && has_plus_minus) {
jio_fprintf(defaultStream::error_stream(),
"Unexpected +/- setting in VM option '%s'\n", argname);
} else {
jio_fprintf(defaultStream::error_stream(),
"Improperly specified VM option '%s'\n", argname);
}
} else {
jio_fprintf(defaultStream::error_stream(), "%s", locked_message_buf);
}
} else {
jio_fprintf(defaultStream::error_stream(),
"Unrecognized VM option '%s'\n", argname);
Flag* fuzzy_matched = Flag::fuzzy_match((const char*)argname, arg_len, true);
if (fuzzy_matched != NULL) {
jio_fprintf(defaultStream::error_stream(),
"Did you mean '%s%s%s'?\n",
(fuzzy_matched->is_bool()) ? "(+/-)" : "",
fuzzy_matched->_name,
(fuzzy_matched->is_bool()) ? "" : "=<value>");
}
}
// allow for commandline "commenting out" options like -XX:#+Verbose
return arg[0] == '#';
}
bool Arguments::process_settings_file(const char* file_name, bool should_exist, jboolean ignore_unrecognized) {
FILE* stream = fopen(file_name, "rb");
if (stream == NULL) {
if (should_exist) {
jio_fprintf(defaultStream::error_stream(),
"Could not open settings file %s\n", file_name);
return false;
} else {
return true;
}
}
char token[1024];
int pos = 0;
bool in_white_space = true;
bool in_comment = false;
bool in_quote = false;
char quote_c = 0;
bool result = true;
int c = getc(stream);
while(c != EOF && pos < (int)(sizeof(token)-1)) {
if (in_white_space) {
if (in_comment) {
if (c == '\n') in_comment = false;
} else {
if (c == '#') in_comment = true;
else if (!isspace(c)) {
in_white_space = false;
token[pos++] = c;
}
}
} else {
if (c == '\n' || (!in_quote && isspace(c))) {
// token ends at newline, or at unquoted whitespace
// this allows a way to include spaces in string-valued options
token[pos] = '\0';
logOption(token);
result &= process_argument(token, ignore_unrecognized, Flag::CONFIG_FILE);
build_jvm_flags(token);
pos = 0;
in_white_space = true;
in_quote = false;
} else if (!in_quote && (c == '\'' || c == '"')) {
in_quote = true;
quote_c = c;
} else if (in_quote && (c == quote_c)) {
in_quote = false;
} else {