[pypy-dev] Why does pypy include my code three times in the JIT-capable executable?

hgualandi at inf.puc-rio.br hgualandi at inf.puc-rio.br
Fri Dec 16 17:41:10 EST 2016


Hi there,

I have a question about pypy's compilation process when producing an
executable from an RPython source program.

Apparently when I compile my program with --opt=JIT, my code gets included
3 times in the resulting executable. I made a little experiment where I
included a magic number in my RPython code and counted how often it showed
up in the generated executable.

With ahead of time compilation (--opt=3) my magic number appeared once:

    $ PERLIO=:raw perl -nE '$c++ while m/\xef\xbe\xad\xde/g; END{say $c}'
./rpython-deadbeef.aot
    1

And with --opt=JIT it appeared 3 times:

    $ PERLIO=:raw perl -nE '$c++ while m/\xef\xbe\xad\xde/g; END{say $c}'
./rpython-deadbeef.jit
    3

When I investigated, it turns out that the JIT-capable executable has one
copy of my program in bytecode form and two copies in machine code form.
To understand the machine-code copies I inspected the intermediate
"implement.c" file that pypy generated and found out that my interpreter
code appears in two functions, one named pypy_g_mainloop_1 and one named
pypy_g_portal. These two functions were completely identical, other than
the function names that show up in the debugging messages.

I understand why pypy would create a separate bytecode version of my
program but why is it generating two seemingly-identical machine code
versions of it?


Thanks in advance,
Hugo


More information about the pypy-dev mailing list