Why does pypy include my code three times in the JIT-capable executable?
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
Hi, On 16 December 2016 at 23:41, <hgualandi@inf.puc-rio.br> wrote:
Apparently when I compile my program with --opt=JIT, my code gets included 3 times in the resulting executable.
Likely, you are seeing two C copies of the function because of the way the JIT is built. You may get two very similar copies, but only of the function that contains jitdriver.jit_merge_point(). You only get one copy of all the rest. The reason is that there is the normal function, and another reorganized copy which can be called in some cases, like when execution needs to exit the JIT and jump back to the interpreter. This copy starts from the jit_merge_point instead of starting from the normal entry point of the function. In some cases the two versions can be very similar, but for example, if the function does things before entering the loop, then these things will not be found in the JIT-generated copy. A bientôt, Armin.
participants (2)
-
Armin Rigo
-
hgualandi@inf.puc-rio.br