2

So Java's debug interface is using JVMTI as a backend....but JVMTI needs to be compiled on the target architecture, so are these JVMTI functions which are used by JDI pre-compiled and shipped with the JDK as libraries? This would mean that I can use those pre-compiled libraries without using JDI...is that right? I am assume only a handful of functions are already compiled but if I need exactly those functions then I don't need to go through the hassle of compiling them myself....

Nfff3
  • 321
  • 8
  • 24

1 Answers1

5

Look at Java Platform Debugger Architecture:

                /    |--------------|
               /     |     VM       |
 debuggee ----(      |--------------|  <------- JVM TI - Java VM Tool Interface
               \     |   back-end   |
                \    |--------------|
                /           |
 comm channel -(            |  <--------------- JDWP - Java Debug Wire Protocol
                \           |
                     |--------------|
                     | front-end    |
                     |--------------|  <------- JDI - Java Debug Interface
                     |      UI      |
                     |--------------|
  • JDI works on top of JDWP;
  • from the JVM side, JDWP is provided by jdwp agent, which uses JVM TI to communicate with the JVM.

jdwp agent is a native library, which is compiled for each platform separately, of course. The library is included in the standard JDK package. So, the platform-specific part is already provided by the JDK.

apangin
  • 92,924
  • 10
  • 193
  • 247
  • is there any way to call this native library without using JDI? So without starting the application in debug mode... – Nfff3 Apr 30 '21 at 13:19
  • 3
    @Nfff3 since JVMTI is a native interface, it can be used by native software. When you follow the link given in this answer up to https://docs.oracle.com/en/java/javase/11/docs/specs/jvmti.html you get the description of this interface. This does not imply that you can use it “*without starting the application in debug mode*”. You just exchange “*in debug mode*”, i.e. “*with jdwp agent*”, with “*with my JVMTI agent*”. – Holger Apr 30 '21 at 13:50
  • 2
    @Nfff3 JDWP agent *is* a JVM TI agent, which supports only load-time attaching to the JVM. In order to use the agent, it must be specified in the JVM command line arguments. This is effectively the same as "starting the application in debug mode". – apangin Apr 30 '21 at 14:33
  • Thanks, I get it now. Basically there is nothing special about being in "debug" mode. It just means that a JVTMI agent(called JDWP) is loaded when the application starts. And this native agent communicates with JDI on sockets which is language agnostic. I was interested in this because I have a usecase where I want to call some JDI methods many times in a short amount of time and wanted to reduce the execution time. Maybe I can modify the JDWP agent to be able to call the functions from Java via JNI and do not use sockets. Maybe it will be faster. – Nfff3 May 01 '21 at 15:48