Skip to content
Advertisement

OpenJDK 8 interpreter debug

I want to see how the JVM interpreter works. Can I track function calls using NetBeans or GDB? And how will it be more convenient to do this? I’m interested in starting HelloWorld with the -Xint option and see what steps are taken and see the interpreter source code.

I mean not only the result of the interpreter, but also the interpreter code itself in the HotSpot sources.

I built OpenJDK 8 from source with –with-debug-level=slowdebug option.

Advertisement

Answer

If you want to get an idea how JVM interpreter works, you’d better build HotSpot with a C++ interpreter. To do this, pass CC_INTERP=true to the make command.

This is a simplified version of the bytecode interpreter, written mostly in C++. The primary source file (which implements the main interpreter loop and most bytecodes) is in bytecodeInterpreter.cpp. You can easily debug this code in your favorite IDE. However, this interpreter implementation is not actually used in a production JVM; its purpose is to experiment and to prototype new ports quickly.

The real interpeter (aka Template Interpreter) is written in a platform-specific macroassembler, its sources are in src/cpu/<arch>/vm/templateInterpreter_<arch>.cpp and src/cpu/<arch>/vm/templateTable_<arch>.cpp. This interpreter is generated dynamically at JVM startup, so it’s not easy to debug it: first, because this is the assembly code; second, because there is no direct mapping from the generated code to the original source files.

-XX:+PrintInterpreter option will dump the disassembled template interpreter.

Also, there is -XX:+TraceBytecodes flag in debug builds of HotSpot. When enabled, it calls the trace function before executing each bytecode instruction. This can be helpful while debugging the interpreter.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement