From source text to running machine code

The JVM is not a compiler and not an interpreter — it is both, plus a memory manager, a linker and a security check, wrapped in one process. Click any stage to see what it actually does.

    The machine, in one picture

    The three subsystems below are the whole of a JVM. Everything else in this page is a zoom into one of them.

    JVM process

    The same method, twice

    javac does far less than people expect: it checks types, desugars a little syntax and emits a stack machine program. Almost every optimisation you have heard of happens later, at run time.

    Sum.java source
    javap -c Sum bytecode

    Nothing in the right-hand column mentions a register or an x86 instruction. That is the portability trick: the .class file is a program for a machine that does not exist, and every JVM is an implementation of that machine.