Reputation: 105067
I'm in the process of investigating how profilers work internally.
It seems there is an old API named JVMPI, as well as a "new" API based on java.lang.instrument
. I had the idea that profilers instrument all the classes' bytecode and insert hooks that call via sockets info to a given program's open-point, so establishing a communication with the profiler. Is this the standard approach? Do they differ considerably in approach?
Thanks
Upvotes: 4
Views: 1946
Reputation: 718798
I'm not an expert on this, but it seems that JVMPI and JVMTI work differently.
JVMPI seems to work by the agent processing "events" that the JVM emits when profiling is enabled. It seems the event emitting logic is built into the JVM.
JVMTI seems to work (for profiling) by having the agent inject bytecodes into the methods as they are loaded.
(This is from a brief read of the respective specs, as linked above.)
Upvotes: 1
Reputation: 205785
For reference, "JVM TI was introduced at JDK 5.0. JVM TI replaces the Java Virtual Machine Profiler Interface (JVMPI) and the Java Virtual Machine Debug Interface (JVMDI)." The standard profiler, jvisualvm
, uses the API extensively, for example to perform and monitor garbage collection, as suggested here. Java Management Extensions (JMX) is the common communications layer.
Upvotes: 2