How do you analyze fatal -javaagent errors?
Asked Answered
F

1

3

I am trying to add a static method call to the java.lang.Object constructor using the java.lang.instrument API. I know I have the basics right because it works if I make the method call System.gc(). I verified this by running -verbosegc with and without the instrumentation. If I change the method call to a static class/method in my own package I get a fatal error:

Exception in thread "main" FATAL ERROR in native method: processing of -javaagent failed

No dump files are created in the working directory so I am finding it hard to figure out what's wrong. Other info:

  • I ensure the static method class is loaded in the premain method before transformation
  • The static method call does not result in creation of new objects
  • The last class loaded is InterruptedIOException although I think that's just a side-effect

Thanks in advance.

Facelift answered 2/5, 2012 at 23:54 Comment(1)
Turns out that I had to add bytecode generation libs to the boot classpath in agent jar manifest as documented here docs.oracle.com/javase/6/docs/api/java/lang/instrument/…Facelift
N
1

Yes, as @barry noted in his comment, you have to add to the Java Agent's manifest the Boot-Class-Pathdefinition. For me, I used javassist within my agent to create the bytecode, so my manifest looks like this:

Manifest-Version: 1.0
Premain-Class: com.company.agent.Agent
Agent-Class: com.company.agent.Agent
Boot-Class-Path: javassist-3.18.2-GA.jar agent.jar

I have all my application's jar files in the same lib directory as the javassist and agent jars. With everything on the classpath, in the same folder, it works.

Nika answered 30/10, 2014 at 20:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.