Skip to content

Commit 6a42915

Browse files
committed
made intellij suggested improvements
1 parent d058af0 commit 6a42915

File tree

1 file changed

+43
-41
lines changed

1 file changed

+43
-41
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/code/ObjdumpDisassemblerProvider.java

+43-41
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,14 @@ static class Options {
7272
}
7373

7474
// cached validity of candidate objdump executables.
75-
private Map<String, Boolean> objdumpCache = new HashMap<>();
75+
private static final Map<String, Boolean> objdumpCache = new HashMap<>();
7676

7777
private static Process createProcess(String[] cmd) {
7878
ProcessBuilder pb = new ProcessBuilder(cmd);
7979
try {
8080
return pb.start();
8181
} catch (IOException e) {
82+
TTY.printf("WARNING: Error executing '%s' (%s)%n", String.join(" ", cmd), e);
8283
}
8384
return null;
8485
}
@@ -129,8 +130,7 @@ public String disassembleCompiledCode(OptionValues options, CodeCacheProvider co
129130
putAnnotation(annotations, a.getPosition(), a.toString());
130131
}
131132
for (Infopoint infopoint : compResult.getInfopoints()) {
132-
if (infopoint instanceof Call) {
133-
Call call = (Call) infopoint;
133+
if (infopoint instanceof Call call) {
134134
if (call.debugInfo != null) {
135135
putAnnotation(annotations, call.pcOffset + call.size, CodeUtil.append(new StringBuilder(100), call.debugInfo, slotFormatter).toString());
136136
}
@@ -170,15 +170,14 @@ public String disassembleCompiledCode(OptionValues options, CodeCacheProvider co
170170
String errLine = ebr.readLine();
171171
if (errLine != null) {
172172
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 {
175174
System.err.println(errLine);
176-
}
175+
} while ((errLine = ebr.readLine()) != null);
177176
}
178177
}
179178
return sb.toString();
180179
} catch (IOException e) {
181-
e.printStackTrace();
180+
e.printStackTrace(TTY.out);
182181
return null;
183182
} finally {
184183
if (tmp != null) {
@@ -188,9 +187,9 @@ public String disassembleCompiledCode(OptionValues options, CodeCacheProvider co
188187
}
189188

190189
/**
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.
192191
*/
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@%_\\-+=:,./]+");
194193

195194
/**
196195
* Reliably quote a string as a single shell command argument.
@@ -215,44 +214,47 @@ private String getObjdump(OptionValues options) {
215214
String candidates = Options.ObjdumpExecutables.getValue(options);
216215
if (candidates != null && !candidates.isEmpty()) {
217216
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+
}
226227
}
227-
}
228-
try {
229228
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;
244235
}
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+
}
250251
}
252+
} catch (IOException | InterruptedException e) {
253+
TTY.printf("WARNING: Error reading input from '%s' (%s)%n", String.join(" ", cmd), e);
251254
}
252-
} catch (IOException | InterruptedException e) {
255+
// bad candidate.
256+
objdumpCache.put(candidate, Boolean.FALSE);
253257
}
254-
// bad candidate.
255-
objdumpCache.put(candidate, Boolean.FALSE);
256258
}
257259
}
258260
return null;

0 commit comments

Comments
 (0)