简体   繁体   中英

How do Java profilers work, internally?

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

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.

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM