< prev index next >
src/jdk.attach/share/classes/sun/tools/attach/HotSpotVirtualMachine.java
Print this page
*** 37,46 ****
--- 37,48 ----
import java.io.IOException;
import java.io.InputStreamReader;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Properties;
+ import java.util.regex.Matcher;
+ import java.util.regex.Pattern;
import java.util.stream.Collectors;
/*
* The HotSpot implementation of com.sun.tools.attach.VirtualMachine.
*/
*** 84,105 ****
* name and it will be expended in the target VM.
*/
private void loadAgentLibrary(String agentLibrary, boolean isAbsolute, String options)
throws AgentLoadException, AgentInitializationException, IOException
{
! InputStream in = execute("load",
! agentLibrary,
! isAbsolute ? "true" : "false",
! options);
! try {
! int result = readInt(in);
! if (result != 0) {
! throw new AgentInitializationException("Agent_OnAttach failed", result);
}
- } finally {
- in.close();
-
}
}
/*
* Load agent library - library name will be expanded in target VM
--- 86,115 ----
* name and it will be expended in the target VM.
*/
private void loadAgentLibrary(String agentLibrary, boolean isAbsolute, String options)
throws AgentLoadException, AgentInitializationException, IOException
{
! try (BufferedReader reader = new BufferedReader(
! new InputStreamReader(
! execute("load", agentLibrary,
! Boolean.toString(isAbsolute), options)))) {
! String result = reader.readLine();
! if (result == null) {
! throw new AgentLoadException("Target VM did not respond");
! } else {
! Matcher matcher = Pattern.compile("^return code: (\\d+)$")
! .matcher(result);
! if (matcher.matches()) {
! int retCode = Integer.parseInt(matcher.group(1));
! if (retCode != 0) {
! throw new AgentInitializationException(
! "Agent_OnAttach failed", retCode);
! }
! } else {
! throw new AgentLoadException(result);
! }
}
}
}
/*
* Load agent library - library name will be expanded in target VM
< prev index next >