Structure of the HotSpot Interpreter
Andrew Haley
aph-open at littlepinkcloud.com
Thu May 30 14:18:18 UTC 2024
On 5/30/24 14:47, Julian Waters wrote:
> I've recently been trying to learn more about HotSpot and studying its
> internals, but the structure of the Interpreter seems to elude me
> still. I'm aware that HotSpot doesn't use a traditional switch case
> (Well, at least not usually, looking at you Zero Port), but how it
> functions is more or less still a black box to me. What kind of
> dispatch mechanism does it use, for instance? Is it Direct Threaded,
> Indirect Threaded, Token Threaded, or something else entirely? Is
> there somewhere I can learn about how everything connects together?
> I've tried reading the HotSpot documentation online but there doesn't
> seem to be an in-depth explanation in them for how it all fits
> together, I'd greatly appreciate if someone points me in the right
> direction
It's a bytecode interpreter, so token threaded.
Print it out with -XX:+PrintInterpreter. Here's lmul (for Arm).
lmul 105 lmul [0x0000ffff785428c0, 0x0000ffff785428e0] 32 bytes
--------------------------------------------------------------------------------
0x0000ffff785428c0: ldr x0, [x20], #0x10 ;;@FILE: /home/aph/theRealAph-jdk/src/hotspot/share/interpreter/templateInterpreterGenerator.cpp
;; 359: case ltos: vep = __ pc(); __ pop(ltos); lep = __ pc(); generate_and_dispatch(t); break;
0x0000ffff785428c4: ldr x1, [x20], #0x10 ;; 359: case ltos: vep = __ pc(); __ pop(ltos); lep = __ pc(); generate_and_dispatch(t); break;
;; 378: __ verify_FPU(1, t->tos_in());
;; 391: __ dispatch_prolog(tos_out, step);
0x0000ffff785428c8: mul x0, x0, x1
Fetch the next bytecode. x22 is the bytecode pointer:
0x0000ffff785428cc: ldrb w8, [x22, #1]! ;; 403: __ dispatch_epilog(tos_out, step);
Offset to the dispatch table:
0x0000ffff785428d0: add w9, w8, #0x500
Load the address of the next action, and jump to it:
0x0000ffff785428d4: ldr x9, [x21, w9, uxtw #3]
0x0000ffff785428d8: br x9
The interesting source is in the various templateInterpreter and templateTable files.
--
Andrew Haley (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671
More information about the hotspot-dev
mailing list