JIT area allocation techniques
By Kamil Rytarowski
- 1 minutes read - 172 wordsJIT (also known as Dynamic Translation) is compilation of a program that is done during the execution of a program, rather than before execution. JIT is kind of code inlining known from static compilation and shares the same advantages and disadvantages. A proper use of JIT is to get a balance between code size generation, time of code generation and performance win. A complex code processed by a JIT compiler might decrease the final efficiency, and statically compiled C/C++/Rust code with such algorithm usually performs better.
In order to use the Just-in-time technique, we need to have a special memory allocator, bypassing the standard C routines (malloc(3), calloc(3), free(3), realloc(3)) and relying on low-level Operating System specific raw routines allocating memory with physical page granularity (usually of 4096 bytes on a modern hardware) with exact protection properties. The UNIX family of Operating Systems provides the mmap(2) system call, that maps anonymous memory, files and devices into memory. The Windows counterpart of mmap(2), used for reserving memory for a JIT area is VirtualAlloc.