@@ -40,57 +40,11 @@ private String[] readProcFsCmdLine() {
40
40
return null ;
41
41
}
42
42
43
- private List <String > findVmOptions () {
44
- return findVmOptions (PROCFS_CMDLINE );
45
- }
46
-
47
43
@ SuppressForbidden // Class.forName() as backup
48
- // Visible for testing
49
- List <String > findVmOptions (String [] procfsCmdline ) {
44
+ private List <String > findVmOptions () {
50
45
// Try ProcFS on Linux
51
- // Be aware that when running a native image, the command line in /proc/self/cmdline is just the
52
- // executable
53
- if (procfsCmdline != null ) {
54
- // Create list of VM options
55
- List <String > vmOptions = new ArrayList <>();
56
- // Start at 1 to skip "java" command itself
57
- int index = 1 ;
58
- // Look for first self-standing argument that is not prefixed with "-" or end of VM options
59
- // Skip "-jar" and the jar file
60
- // Simultaneously, collect all arguments in the VM options
61
- for (; index < procfsCmdline .length ; index ++) {
62
- String argument = procfsCmdline [index ];
63
- if (argument .startsWith ("@" )) {
64
- vmOptions .addAll (getArgumentsFromFile (argument ));
65
- } else {
66
- if ("-jar" .equals (argument )) {
67
- // skip "-jar" and the jar file
68
- index ++;
69
- continue ;
70
- } else if ("-cp" .equals (argument )) {
71
- // slurp '-cp' and the classpath
72
- vmOptions .add (argument );
73
- if (index + 1 < procfsCmdline .length ) {
74
- argument = procfsCmdline [++index ];
75
- }
76
- } else if (!argument .startsWith ("-" )) {
77
- // end of VM options
78
- break ;
79
- }
80
- vmOptions .add (argument );
81
- }
82
- }
83
- // Insert JDK_JAVA_OPTIONS at the start if present and supported
84
- List <String > jdkJavaOptions = getJdkJavaOptions ();
85
- if (!jdkJavaOptions .isEmpty ()) {
86
- vmOptions .addAll (0 , jdkJavaOptions );
87
- }
88
- // Insert JAVA_TOOL_OPTIONS at the start if present
89
- List <String > javaToolOptions = getJavaToolOptions ();
90
- if (!javaToolOptions .isEmpty ()) {
91
- vmOptions .addAll (0 , javaToolOptions );
92
- }
93
- return vmOptions ;
46
+ if (PROCFS_CMDLINE != null ) {
47
+ return findVmOptionsFromProcFs (PROCFS_CMDLINE );
94
48
}
95
49
96
50
// Try Oracle-based
@@ -137,6 +91,48 @@ List<String> findVmOptions(String[] procfsCmdline) {
137
91
return emptyList ();
138
92
}
139
93
94
+ // Be aware that when running a native image, the command line in /proc/self/cmdline is just the
95
+ // executable
96
+ // Visible for testing
97
+ List <String > findVmOptionsFromProcFs (String [] procfsCmdline ) {
98
+ // Create list of VM options
99
+ List <String > vmOptions = new ArrayList <>();
100
+ // Look for first self-standing argument that is not prefixed with "-" or end of VM options
101
+ // while simultaneously, collect all arguments in the VM options
102
+ // Starts from 1 as 0 is the java command itself (or native-image)
103
+ for (int index = 1 ; index < procfsCmdline .length ; index ++) {
104
+ String argument = procfsCmdline [index ];
105
+ // Inflate arg files
106
+ if (argument .startsWith ("@" )) {
107
+ vmOptions .addAll (getArgumentsFromFile (argument ));
108
+ }
109
+ // Skip classpath argument (not part of VM options)
110
+ else if ("-cp" .equals (argument )) {
111
+ index ++;
112
+ }
113
+ // Check "-jar" or class name argument as the end of the VM options
114
+ else if ("-jar" .equals (argument ) || !argument .startsWith ("-" )) {
115
+ // End of VM options
116
+ break ;
117
+ }
118
+ // Otherwise add as VM option
119
+ else {
120
+ vmOptions .add (argument );
121
+ }
122
+ }
123
+ // Insert JDK_JAVA_OPTIONS at the start if present and supported
124
+ List <String > jdkJavaOptions = getJdkJavaOptions ();
125
+ if (!jdkJavaOptions .isEmpty ()) {
126
+ vmOptions .addAll (0 , jdkJavaOptions );
127
+ }
128
+ // Insert JAVA_TOOL_OPTIONS at the start if present
129
+ List <String > javaToolOptions = getJavaToolOptions ();
130
+ if (!javaToolOptions .isEmpty ()) {
131
+ vmOptions .addAll (0 , javaToolOptions );
132
+ }
133
+ return vmOptions ;
134
+ }
135
+
140
136
private static List <String > getArgumentsFromFile (String argFile ) {
141
137
String filename = argFile .substring (1 );
142
138
Path path = Paths .get (filename );
0 commit comments