< prev index next >
src/jdk.attach/share/classes/sun/tools/attach/HotSpotVirtualMachine.java
Print this page
@@ -84,22 +84,28 @@
* name and it will be expended in the target VM.
*/
private void loadAgentLibrary(String agentLibrary, boolean isAbsolute, String options)
throws AgentLoadException, AgentInitializationException, IOException
{
+ String msgPrefix = "return code: ";
InputStream in = execute("load",
agentLibrary,
isAbsolute ? "true" : "false",
options);
- try {
- int result = readInt(in);
- if (result != 0) {
- throw new AgentInitializationException("Agent_OnAttach failed", result);
+ BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+ try (reader) {
+ String result = reader.readLine();
+ if (result == null) {
+ throw new AgentLoadException("Target VM did not respond");
+ } else if (result.startsWith(msgPrefix)) {
+ int retCode = Integer.parseInt(result.substring(msgPrefix.length()));
+ if (retCode != 0) {
+ throw new AgentInitializationException("Agent_OnAttach failed", retCode);
+ }
+ } else {
+ throw new AgentLoadException(result);
}
- } finally {
- in.close();
-
}
}
/*
* Load agent library - library name will be expanded in target VM
< prev index next >