Of all the facets of HN’s title autodestroy, I think removing “How” from titles is the worst one. I believe OP can edit it back in though.
(I passed over this article thinking it was a “look how mysteriously smart the mysteriously smart compiler is” acticle, not a “here’s how the smarts in a compiler work” one.)
I'm working on an interpreter right now, and I'm considering adding JIT support in the future. Are there other blog posts like this, or deep dives that talk about how to implement and tune a JIT?
My main high-level advice would be to have an extensive set of behavioral tests (lots of scripts with assertions on the output). This helps ensure correctness when you flip on your JIT compilation.
You'll eventually run into hard to diagnose bugs - so be able to conditionally JIT parts of your code (per-function control - or even better, per-basic block) to help narrow down problem areas.
The other debugging trick I did was spit out the full state of the runtime after every instruction, and ensure that the same state is seen after every instruction even w/ JIT enabled.
19 comments
(I passed over this article thinking it was a “look how mysteriously smart the mysteriously smart compiler is” acticle, not a “here’s how the smarts in a compiler work” one.)
Maybe you'll find the resources I link to in the documentation for my project helpful.
https://github.com/ZQuestClassic/ZQuestClassic/blob/main/doc...
Or perhaps you'd find reviewing my usage of asmjit helpful:
https://github.com/ZQuestClassic/ZQuestClassic/blob/main/src...
My main high-level advice would be to have an extensive set of behavioral tests (lots of scripts with assertions on the output). This helps ensure correctness when you flip on your JIT compilation.
You'll eventually run into hard to diagnose bugs - so be able to conditionally JIT parts of your code (per-function control - or even better, per-basic block) to help narrow down problem areas.
The other debugging trick I did was spit out the full state of the runtime after every instruction, and ensure that the same state is seen after every instruction even w/ JIT enabled.
Good luck!