JIT compilation — emitting machine code into executable memory at runtime — is how V8 runs JavaScript within a factor of C, and how the JVM, .NET, and LuaJIT earn their performance. The mmap+mprotect dance you implement is the same one those VMs perform, now constrained by W^X policies on iOS and modern Linux.