Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/java/AttachOnce.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,21 @@ static void loadAgent(String pid, String options) throws Exception {
File lib = new File("libperfmap.so");
String fullPath = lib.getAbsolutePath();
if (!lib.exists()) {
System.out.printf("Expected libperfmap.so at '%s' but it didn't exist.\n", fullPath);
System.exit(1);
String [] javaLibPath = System.getProperty("java.library.path").split(":");
boolean foundInLibPath = false;
for (String path: javaLibPath) {
File f = new File(path + File.separator + "libperfmap.so");
if(f.exists()) {
foundInLibPath = true;
fullPath = f.getAbsolutePath();
}
}
if (!foundInLibPath) {
System.out.printf("Expected libperfmap.so at '%s' or within java.library.path but it didn't exist in either.\n", fullPath);
System.exit(1);
}
}
else vm.loadAgentPath(fullPath, options);
vm.loadAgentPath(fullPath, options);
} catch(com.sun.tools.attach.AgentInitializationException e) {
// rethrow all but the expected exception
if (!e.getMessage().equals("Agent_OnAttach failed")) throw e;
Expand Down