Understanding templateInterpreter

Coleen Phillimore coleen.phillimore at oracle.com
Tue Aug 11 14:23:53 UTC 2015


Start with the C++ code in 
src/share/vm/interpreter/templateInterpreter.hpp/cpp which generates the 
dispatch table.
Then look at src/share/vm/interpreter/templateTable.hpp/cpp which has 
the TemplateTable:: function mappings for each bytecode.
Then look at the assembly code in templateTable_x86.cpp, 
interp_masm_x86.cpp and templateInterpreter_x86_32/64.cpp (or whichever 
platform you are interested in).  Each bytecode has multiple entry 
points for each type that can be on the top of the stack (the tos 
optimization caches the result of some bytecodes in register, rather 
than storing them in the expression stack).  This sort of complicates 
the code.

The files src/share/vm/interpreter/bytecodeInterpreter* are for the Zero 
interpreter and now broken/unused "C++" interpreter, but they give you a 
good idea of how each bytecode are interpreted.  The dispatch there of 
course is the C++ case statement (or goto/label optimization).

As Andrew suggested, there's a PrintInterpreter option which will show 
the generated code for each bytecode.

Hope this helps.

On 8/11/15 10:08 AM, Manas Thakur wrote:
> Thanks Andrew. I would try it and get back, if needed.
> Regards,
> Manas
>> On 11-Aug-2015, at 7:13 pm, Andrew Haley <aph at redhat.com> wrote:
>> On 08/11/2015 02:23 PM, Manas Thakur wrote:
>>> I am trying to understand the working of HotSpot, and I am stuck
>>> with the template interpreter.
>>> I was wondering if there a document available on the detailed
>>> working of template interpreter. The main thing I want to find out
>>> is that once the templates for different byte codes are generated
>>> during startup, where is the code that is responsible to select the
>>> templates by scanning over the bytecode?
>> You're probably looking in the wrong place.  The group of functions
>> that dispatch to the code for the next bytecode is
>> InterpreterMacroAssembler::dispatch_*.
>> I suggest you print the interpreter and then step through some very
>> simple methods.  It should become clear soon enough once you do that.
>> Andrew.

More information about the hotspot-dev mailing list