In Linux, a memory segment can be set up to be writable and executable (and can be later changed on its protections). Look at the mmap(2) and mprotect(2) syscalls.
The JVM will probably produce machine code in memory, without using any disk files. Its JIT machinery probably just write bytes in executable memory.
Notice that the JVM might not want to change the generated machine code protection (it probably could generate all the machine code inside writable and executable memory segments), because since it is generating itself that code, it can be made sure to not doing nasty things (read about proof-carrying code).
Read the Just-in-time compilation and HotSpot and Virtual Memory wiki pages, and try strace
-ing some java
process...
Some JVMs are free software (e.g. the one inside OpenJdk), you could study their source code.