Self-modifying code is sometimes used to allow you to update an inline cache for a method dispatch as the program is running. Rather than having to recompile and produce new machine code to update an inline cache.
Neat idea. Presumably a dynamic JIT like HotSpot would use this technique.
In C you can have a global function pointer, and mutate it, but presumably that still has an additional indirection compared to the self-modifying approach.
> Presumably a dynamic JIT like HotSpot would use this technique.
Not in practice in HotSpot no, but it could do and similar VMs do. execute|write is not fashionable these days! Some systems enforce execute^write, so you can't do it.