Java JVMTI doesn't work alongside -Xdebug -Xrunjdwp
Asked Answered
K

3

13

I spent the last 4 hours trying to set up Eclipse TPTP memory profiling on a Tomcat instance that must be run remotely (i.e. not in Eclipse). This should be possible according to the TPTP and Agent Controller docs.

I installed the TPTP components (4.6.0) into my Eclipse (Galileo) workbench, along with the Agent Controller according to the instructions on the website. To enable the agent, I added the following options to the command line that starts the Tomcat instance:

-agentlib:JPIBootLoader=JPIAgent:server=enabled;HeapProf:allocsites=true

and added the following directories to the front of the PATH:

D:\dev\tools\ac\plugins\org.eclipse.tptp.javaprofiler
D:\dev\tools\ac\bin

When attempting to start Tomcat I consistently got the following error message:

ERROR: JDWP unable to get necessary JVMTI capabilities. ["debugInit.c",L279]

I did a lot of Googling but found nothing relevant; I tried reinstalling TPTP and various versions of the Agent Controller.

In the end the problem turned out to be that I was starting Tomcat with the "jpda" option, which catalina.bat translates into

-Xdebug -Xrunjdwp:transport=.....

Removing the "jpda" command argument caused JVMTI to start working.

SO, the question is: I found nothing during any of my searches to indicate that a JVMTI agent is incompatible with debugging. Can someone explain what is going on and why JVMTI + JDWP is not a valid setup?

Keely answered 13/10, 2009 at 21:22 Comment(0)
S
21

None of the answers so far are correct and this is the first hit that comes up on Google if you query the error mentioned, so I feel some clarification is needed.

JVMTI and JDWP do work together, in fact they generally must be used together. You will get ERROR: JDWP unable to get necessary JVMTI capabilities if -Xrunjdwp (and/or possibly -agentlib:jdwp) is specified more than once on the command line. To fix it, make sure you only have one of -Xrunjdwp or -agentlib:jdwp in your command line.

For more details, read on...

JVMTI (Java Virtual Machine Tool Interface) is the successor to JVMDI (Java Virtual Machine Debug Interface) and JVMPI (Java Virtual Machine Profiling Interface). It incorporates the functionality of both JVMDI and JVMPI, both of which were deprecated in Java 5 and removed in Java 6. It is the API that exposes the internals of the JVM for the purposes of debugging and profiling.

JDWP (Java Debug Wire Protocol) is a protocol that describes a simple mechanism for transmitting commands and responses. As far as I know, it is the only way for a debugger sitting outside the JVM to communicate with it and to interface with the JVMTI.

JDI (Java Debugger Interface) is a client-side (debugger-side) API which exposes some of the features of JVMTI while making use of JDWP more or less transparently.

The bug mentioned in Bob Dobbs's answer concerns the misleading error message, and the fact that the JVM will try to load JDWP once for every time it is specified on the command line. It doesn't state anywhere that JDWP and JVMTI cannot be used together.

More info here: https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzaha/jpdebuga.htm

Sirmons answered 17/5, 2011 at 21:31 Comment(6)
so, is it possible to use remote debugging with profiling simultaneously?Legnica
@michael I believe so, but unless you're trying to mimic some strange conditions in an attempt to reproduce a memory leak or giant CPU spike, doesn't profiling while debugging sound like a bad idea?Sirmons
Great answer. Was getting this error. I had to disable debug mode on my ancient Sun App Server before I could get the YourKit profiler configuration to work with it. Thank you!Linoel
@michaelnesterenko Actually the answer is "it depends". It depends on the capabilities the profiling agent requests from the jvmti. E.g. Breakpoint capabilities may only be possessed by only one environment at a time (and each agent get its own environment); docs.oracle.com/javase/7/docs/platform/jvmti/… . So if a profiler agent needs the capabilities to set breakpoints your debugger agent won't be able to obtain them (or the other way round). That means whenever you get such an error there is nothing you can do about it, you won't be able to debug in those cases.Valoniah
except you cannot assign a JVMTI agent AND enable remote debugging interface because that requires at least both -agentpath=jdvmi.so AND -Xrunjdwp:transport.... There's no way to specify the jdvmi agent plus the jwp transport options without using both.Winker
@Winker wait, what do you want to do? This is a really old answerSirmons
F
3

I ran into the same problem as you, but I came up with a JVM bug report (https://bugs.java.com/bugdatabase/view_bug?bug_id=6354345) that cast some light on the issue. It basically comes down to the Java agent library not ever being intended to be loaded twice into the same VM. Sucks, but seems like it's basic limitation of the agent system that you can't do both at the same time.

Fess answered 8/11, 2010 at 5:14 Comment(0)
O
1

For me it was the same issue as Code Bling post, they were duplicate -Xrunjdwp didn't realize there were a second -Xrunjdwp as it was hidden in the variable %JAVA_OPTIONS%, check your Application Server start script.

Ollayos answered 22/1, 2014 at 6:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.