Basic question: JVM provides JVMTI which native API for profiling and debugging JVM. JVM instrumentation also does the same (is that correct?). If yes, what is difference between the both?
-
Often profilers use Instrumentation to get additional information. Debuggers just us the JVMTI however you can use Instrumentation for your own debugging eg logging key methods calls. – Peter Lawrey Jun 15 '11 at 09:35
-
I thought profiler tools rely on JVMTI only. If they use instrumentation also (which is Java API for JVM monitoring) is that thing not supported by JVMTI? In other words, more generic questions is, why instrumentation when JVMTI is available? – Sandeep Jindal Jun 15 '11 at 09:41
-
@Sandeep Jindal - obviously they are different, and obviously they do different things. Why don't you just look at the respective APIs? (This Question is a bit like "What is the difference between an Elephant and an Asprin?") – Stephen C Jun 15 '11 at 09:57
-
@Stephen Not sure if both the things are as different as Elephant and Aspirin. What I understand is both can be used for profiling. One provides Native API and other provides Java API. My question is what should be used in what cases! – Sandeep Jindal Jun 15 '11 at 10:54
-
@Sandeep Jindal - If you are trying to write your own profiler you need to understand both APIs, so that you know which one provides which parts of the information that you want to present to the user of your tool. **You need to read the specs for yourself!!** – Stephen C Jun 15 '11 at 22:59
-
By the way. This is not a basic question. Hardly anyone writes their own JVMTI tools ... – Stephen C Jun 15 '11 at 23:02
3 Answers
I dont think that Instrumentation is JVMTI is Superset of Instrumentation.. as Both of these can be used independently.
JVMTI is based on events and in the event handlers we can capture required information about the JVM.
Instrumentation is Something in which we modify the Bytecode and hence in turn add extra piece of code at runtime at required location in the class before it loads in the JVM. this extra piece of code when executed, will help gather required information for the profiler.
Instrumentation can be achieved with the help of various third party jar's like ASM.
As per my knowledge and experience Both of these are for Java profiling and not for Native profiling.
Probably need to read more documents and tryout different samples for better understanding.

- 513
- 9
- 17
JVMTI gives all the functionality the debugger needs, however if you want to more than what the JVMTI provides you need to use Instrumentation.

- 525,659
- 79
- 751
- 1,130
-
I thought JVMTI provides everything one needs to do for profiling. Is there anything instrumentation provides on top of JVMTI? – Sandeep Jindal Jun 15 '11 at 09:43
-
I don't know specificity. The debugger ships with a JDK and the JVMTI supports that. Until recently the profiler came independently and each profiler provided different functionality. To use the debugger, the JVM has to be started in debug mode. This is not required for a profiler. (I suggest you not try to do both at the same times as it will upset your results) – Peter Lawrey Jun 15 '11 at 09:46
-
Other than debugger, if both techniques are similar, which should I use when? Confused :( – Sandeep Jindal Jun 15 '11 at 09:50
-
1If you want to debug, use a debugger. If you want to profile, use a profiler. Unless you have used both of these and have a very good understanding of how they would and they don't do what you want, its likely that Instrumentation is what you need. i.e. its highly unlikely you will find something in JVMTI which you can't do with a debugger or profiler. – Peter Lawrey Jun 15 '11 at 09:53
-
Ok, lets put the question this way. I want to write my own profiler. Shall I use JVMTI or Java instrumentation? – Sandeep Jindal Jun 15 '11 at 10:55
-
1
JVMTI is base functionality that provides all sorts of events for debugging, profiling, etc... One of the areas it provides is access to intercept (and redefine) classes. java.lang.instrument is a Java wrapper on top of JVMTI that provides a nice, easy, accessible way of getting at the class loading events.
Think of JVMTI as a pure superset of java.lang.instrument, but requires the user to write C code.

- 2,286
- 14
- 17
-
The JVMTI specification covers both native c based agents (-agentlib, -agentpath) and java based agents (-javaagent). – William Louth Mar 05 '12 at 12:29
-
William, that's not correct IMHO, but we're really getting deep into semantics here so I won't chase it far. I view the spec as being http://docs.oracle.com/javase/7/docs/platform/jvmti/jvmti.html and there's no mention of -javaagent at that level. – Trent Gray-Donald Mar 16 '12 at 07:48
-
Let me rephrase it...during the development of the JVMTI aimed at replacing JVMPI the engineering team sought to introduce two means of performing BCI: a native version accessible via C and a Java API version. – William Louth Mar 16 '12 at 13:07
-
this work was conducted jointly because of the need to coordinate class load hooks/events across both type of agents though I am not sure it was ever defined how ordering would be done (or defined by the user). – William Louth Mar 16 '12 at 13:09