4 ms·
This is so awesome. My dream is to understand JIT compiler tech. Does anybody have any resources? I've read the documentation of Pypy but I don't understand e
by samsquire 4y ago
This is so awesome.
My dream is to understand JIT compiler tech. Does anybody have any resources?
I've read the documentation of Pypy but I don't understand everything. And I've looked at dynasm for luajit.
I also read about Ruby's YJIT.
Do JIT compilers create machine code templates of bytecode instructions and then emit that? Or do they create basic blocks and then emit that as machine code?
My amd64 compiler is toy barebones that can evaluate ADD and MUL expressions https://github.com/samsquire/compiler https://github.com/samsquire/compiler I would love for it to become a JIT compiler!
- pjmlp 4y agoDepends like everything in computing. Clever ones are even multiple layers, with cache between runs and PGO metadata, or use a JIT server even. Java and .NET runtimes across various implementations is where you will find these techniques.
- masklinn 4y ago> My dream is to understand JIT compiler tech. Does anybody have any resources? Mike Pall's posts and LuaJIT is probably a good bet. For a higher-level overview, I dimly remember that Mozilla used to have a number of posts on the subject. V8 / Chrome as well, especially as they moved back, forth, and sideways on the subkect. > Do JIT compilers create machine code templates of bytecode instructions and then emit that? Or do they create basic blocks and then emit that as machine code? That very much depends on the JIT. It can go from just swapping in precompiled code templates to type-directed compilation and AOT-style optimisations (loop unrolling, inlining, devirtualisation, ...), as well as things AOT compilers don't usually do (to my knowledge) like runtime-dispatched specialisation.
- zellyn 4y agoI haven't had a chance to dig into it yet, but I assumed tenderjit would probably be a good place to start…
- jacobmartin 4y agoI'm no expert, but you might be interested in: https://llvm.org/docs/tutorial/ https://llvm.org/docs/tutorial/ There's also a Haskell version if you'd prefer: https://www.stephendiehl.com/llvm/ https://www.stephendiehl.com/llvm/ Idk how to do this in python as I'm not really good with it, but in C, to make your compiler a JIT, you would `mmap` a region as writeable, write the machine code to it that you already know how to generate, `mprotect` it as PROT_EXEC instead of PROC_WRITE, cast the pointer to the region to a function pointer, and then call it. These functions may be available in the python sys package but I don't really know. I've implemented a "JIT" that takes machine code as hex and does this. Warning: it's complete garbage with no error checking but is a good proof of concept. https://gist.github.com/martinjacobd/3ee56f3c7b7ce621034ec3ecbc8e13f1 https://gist.github.com/martinjacobd/3ee56f3c7b7ce621034ec3e...
- webnrrd2k 4y agoThere was a post on hn about this: https://news.ycombinator.com/item?id=29566249 https://news.ycombinator.com/item?id=29566249