One dispatch table covers the whole 4 GiB guest address space. A guest address the table has no host function for
sends the generated code to the runtime, which compiles the code there with the host's native back end (the
recompiler library's snx_recompile_from) and runs it. One step is the function execution reached and the functions
it calls, breadth first, up to 64Ki instructions, split into pieces of at most 4096 instructions and compiled on every
core. Each step is a module: its pieces, the descriptor that fills the
table, and the runtime library, linked into a shared object and loaded with dlopen. On PowerPC64 the steps share
one code arena and its TOC instead, the runtime library loaded into it once (PowerPC64).
Compiled modules are kept in the cache, named by a hash of the code, its addresses and
entries, the backend's settings, SNX_ABI and the host CPU, together with the compiled
runtime library every module links. A program run again (or a toolchain run on another
file) loads instead of compiling. The first run of a large program is mostly compiling:
the first compile of a C file with GCC (cc1, as, collect2, ld) spent about seven
minutes compiling on six cores, and the same compile then took 6 seconds.
mmap, munmap and mprotect over executable pages drop their compiled code, and a
syscall that changed the code it returns into resumes through the dispatch table.
Code on a writable and executable page is compiled one function at a time, so its calls
go through the table, and the page is write-protected on the host: a write to it drops
its code, and the store is retried. tests/gnuabi/self_modify.S and rewrite.S exit
42 in both modes. Fetching from a page without execute permission faults.
Guest calls are host calls in the generated code, so each guest thread runs on a host thread with a 1 GiB stack reservation.
The guest's threads share the dispatch table, the memory map and the descriptor table. One compile runs at a time (the JIT's lock), and a thread that misses code another thread compiles waits for it. The table's slots are published with release stores and read with relaxed loads, as generated code reads them. The memory map changes under its own lock; a guest access reads the page flags without it. A system call holds the descriptor table's lock, and lets it go around a host call that can block (a pipe, a terminal, a socket), with a reference that keeps the open file.
Made from docs/platforms/gnuabi/README.md at 69237645142c. GPL-3.0-or-later.