JIT Compiling Code in 5μs

6 points by mpweiher


snej

Nice! It was interesting to see the details of how the generated code is made executable. The text says “we’ll use mmap to allocate a block of memory that is readable, writable, and executable”, but the code shows more subtleties since modern OSs don’t allow VM pages to be both writeable and executable at the same time.

The (macOS) code shows passing a JIT specific flag to mmap, and then calling two special pthread functions to enable/disable writeability of the mapped address range.