How does the code generation work?

Step 1

\Magento\Framework\Code\Generator\Autoloader::load():

Step 2

Generated entities:

Step 3

\Magento\Framework\Code\Generator::generateClass()

See also: