How JIT Compilers Work

JIT compilers, by definition, generate on-the-fly code for execution. But, say, on Windows, we have all sorts of protections that prevent self-tuning code or are executed from data memory (DEP).

So how is it possible for JIT compilers to generate code on the fly?

+3
source share
1 answer

They request the OS for some memory that is read, written, and executed.

eg. you can select a memory by means of mmap()using the PROT_READ | PROT_WRITE | PROT_EXEC(POSIX) or VirtualAlloc()using PAGE_EXECUTE_READWRITE(Windows).

For a real example, see LLVM llvm::sys::Memory::AllocateRWX( Unix Implementation Windows Implementation ).

+7

All Articles