@@ -72,13 +72,14 @@ static class Options {
72
72
}
73
73
74
74
// cached validity of candidate objdump executables.
75
- private Map <String , Boolean > objdumpCache = new HashMap <>();
75
+ private static final Map <String , Boolean > objdumpCache = new HashMap <>();
76
76
77
77
private static Process createProcess (String [] cmd ) {
78
78
ProcessBuilder pb = new ProcessBuilder (cmd );
79
79
try {
80
80
return pb .start ();
81
81
} catch (IOException e ) {
82
+ TTY .printf ("WARNING: Error executing '%s' (%s)%n" , String .join (" " , cmd ), e );
82
83
}
83
84
return null ;
84
85
}
@@ -129,8 +130,7 @@ public String disassembleCompiledCode(OptionValues options, CodeCacheProvider co
129
130
putAnnotation (annotations , a .getPosition (), a .toString ());
130
131
}
131
132
for (Infopoint infopoint : compResult .getInfopoints ()) {
132
- if (infopoint instanceof Call ) {
133
- Call call = (Call ) infopoint ;
133
+ if (infopoint instanceof Call call ) {
134
134
if (call .debugInfo != null ) {
135
135
putAnnotation (annotations , call .pcOffset + call .size , CodeUtil .append (new StringBuilder (100 ), call .debugInfo , slotFormatter ).toString ());
136
136
}
@@ -170,15 +170,14 @@ public String disassembleCompiledCode(OptionValues options, CodeCacheProvider co
170
170
String errLine = ebr .readLine ();
171
171
if (errLine != null ) {
172
172
System .err .println ("Error output from executing: " + CollectionsUtil .mapAndJoin (cmdline , e -> quoteShellArg (String .valueOf (e )), " " ));
173
- System .err .println (errLine );
174
- while ((errLine = ebr .readLine ()) != null ) {
173
+ do {
175
174
System .err .println (errLine );
176
- }
175
+ } while (( errLine = ebr . readLine ()) != null );
177
176
}
178
177
}
179
178
return sb .toString ();
180
179
} catch (IOException e ) {
181
- e .printStackTrace ();
180
+ e .printStackTrace (TTY . out );
182
181
return null ;
183
182
} finally {
184
183
if (tmp != null ) {
@@ -188,9 +187,9 @@ public String disassembleCompiledCode(OptionValues options, CodeCacheProvider co
188
187
}
189
188
190
189
/**
191
- * Pattern for a single shell command argument that does not need to quoted.
190
+ * Pattern for a single shell command argument that does not need to be quoted.
192
191
*/
193
- private static final Pattern SAFE_SHELL_ARG = Pattern .compile ("[A-Za-z0-9@%_\\ -\\ +=:,\\ ./]+" );
192
+ private static final Pattern SAFE_SHELL_ARG = Pattern .compile ("[A-Za-z0-9@%_\\ -+=:,./]+" );
194
193
195
194
/**
196
195
* Reliably quote a string as a single shell command argument.
@@ -215,44 +214,47 @@ private String getObjdump(OptionValues options) {
215
214
String candidates = Options .ObjdumpExecutables .getValue (options );
216
215
if (candidates != null && !candidates .isEmpty ()) {
217
216
for (String candidate : candidates .split ("," )) {
218
- // first checking to see if a cached verdict for this candidate exists.
219
- Boolean cachedQuery = objdumpCache .get (candidate );
220
- if (cachedQuery != null ) {
221
- if (cachedQuery .booleanValue ()) {
222
- return candidate ;
223
- } else {
224
- // this candidate was previously determined to not be acceptable.
225
- continue ;
217
+ synchronized (objdumpCache ) {
218
+ // first checking to see if a cached verdict for this candidate exists.
219
+ Boolean cachedQuery = objdumpCache .get (candidate );
220
+ if (cachedQuery != null ) {
221
+ if (cachedQuery ) {
222
+ return candidate ;
223
+ } else {
224
+ // this candidate was previously determined to not be acceptable.
225
+ continue ;
226
+ }
226
227
}
227
- }
228
- try {
229
228
String [] cmd = {candidate , "--version" };
230
- Process proc = createProcess (cmd );
231
- if (proc == null ) {
232
- // bad candidate.
233
- objdumpCache .put (candidate , Boolean .FALSE );
234
- return null ;
235
- }
236
- InputStream is = proc .getInputStream ();
237
- int exitValue = proc .waitFor ();
238
- if (exitValue == 0 ) {
239
- byte [] buf = new byte [is .available ()];
240
- int pos = 0 ;
241
- while (pos < buf .length ) {
242
- int read = is .read (buf , pos , buf .length - pos );
243
- pos += read ;
229
+ try {
230
+ Process proc = createProcess (cmd );
231
+ if (proc == null ) {
232
+ // bad candidate.
233
+ objdumpCache .put (candidate , Boolean .FALSE );
234
+ return null ;
244
235
}
245
- String output = new String (buf );
246
- if (output .contains ("GNU objdump" )) {
247
- // this candidate meets the criteria.
248
- objdumpCache .put (candidate , Boolean .TRUE );
249
- return candidate ;
236
+ InputStream is = proc .getInputStream ();
237
+ int exitValue = proc .waitFor ();
238
+ if (exitValue == 0 ) {
239
+ byte [] buf = new byte [is .available ()];
240
+ int pos = 0 ;
241
+ while (pos < buf .length ) {
242
+ int read = is .read (buf , pos , buf .length - pos );
243
+ pos += read ;
244
+ }
245
+ String output = new String (buf );
246
+ if (output .contains ("GNU objdump" )) {
247
+ // this candidate meets the criteria.
248
+ objdumpCache .put (candidate , Boolean .TRUE );
249
+ return candidate ;
250
+ }
250
251
}
252
+ } catch (IOException | InterruptedException e ) {
253
+ TTY .printf ("WARNING: Error reading input from '%s' (%s)%n" , String .join (" " , cmd ), e );
251
254
}
252
- } catch (IOException | InterruptedException e ) {
255
+ // bad candidate.
256
+ objdumpCache .put (candidate , Boolean .FALSE );
253
257
}
254
- // bad candidate.
255
- objdumpCache .put (candidate , Boolean .FALSE );
256
258
}
257
259
}
258
260
return null ;
0 commit comments