Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search for libperfmap.so in java.library.path if not found in CWD #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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