JVMTI (JVM Tool Interface) is a Java virtual machine provided by the native programming interface, is JVMPI (Java Virtual Machine Profiler Interface) and JVMDI (Java Virtual Machine Debug Interface) is an updated version. From the development of this historical trajectory of API, we can know, JVMTI provides an interface can be used to debug, and the profiler; at the same time, in Java 5/6, the virtual machine interface is also increased monitor (Monitoring), thread analysis (Thread analysis) and coverage analysis (coverage analysis) and so on. It is because of the power of JVMTI, it is the implementation of the Java debugger, and basic operation of state testing and other analysis tools Java, such as Visual VM, Eclipse TPTP (Test and Performance Tools Platform) The CPU Profiler and Memory Profiler. In addition, JVM PI has been abandoned in JDK6 but there are still a lot of analysis tools are based on JVM PI development, such as JProfiler, TPTP support JVM PI.
JVMTI not necessarily have all implemented on the Java virtual machine to achieve different virtual machines are not the same. However, in some mainstream virtual machine, such as Sun and IBM, as well as some of the open source Apache Harmony DRLVM, the standard provides JVMTI implementation.
JVMTI is a native code interfaces, so using JVMTI we need to deal with C / C ++ and JNI. In fact, the establishment of a commonly used when developing Agent (Agent that is JVMTI clients, it and execute Java programs on a virtual machine running in the same process, it is often their implementations are very compact, they are usually independent of the process by another intermediary between the control, process and serve as the independent current virtual machine, through a call interface and interact with the virtual machine provided by JVMTI, responsible for obtaining and returns the current state of the virtual machine or forward manifestation is a control command .Agent to c / c ++ written in the language of dynamic shared libraries.
When the java launcher or run an external module dynamically loaded into the Java-based dynamic process written JVM TI, and then trigger source JVM native threads Attach Listener to perform this dynamic module callback function. In the body of the function, you can get a wide variety of VM-level information, event registration VM interest, and even control VM behavior. ) Way to use JVMTI, it uses JVMTI function, set some callbacks, and get the information from the current operating state of the Java virtual machine and make their own judgments, may eventually also run operating state of the virtual machine. After the Agent compiled into a dynamic link library, we will be able to load it when the Java program starts (boot loader mode), you can load (active load mode) after 5 using Java run time.
- -agentlib:agent-lib-name=options
- -agentpath:path-to-agent=options
JVMTI Java virtual machine provided by a set of functions to help users manage virtual machines running state is detected, it achieved interoperability with the user by way of the main Agent. Users can not only use by Agent this way, in fact, JDK inside many tools, such as Instrumentation and JDI, we have adopted this approach. In this way these tools do not need to bind on a virtual machine, the virtual machine to reduce load and memory usage.