<antocuni>
I remember I wanted to try something like that for vmprof, but I think I never tidd
<antocuni>
*did
<antocuni>
in particular, I think that a JIT is not necessarily needed: in theory, all these trampolines are the same, so you could just compile a "template" C trampoline and memcpy it around, I *think*
<cfbolz>
antocuni: yes but that depends on a huge amount of details too
<cfbolz>
antocuni: why would that help for vmprof, btw?
<antocuni>
yes; for example, it's easy to find the start of a function, but it's hard to find its end :)
<antocuni>
cfbolz: the original implementation of vmprof used a hack to determine the python code object from the C stack frame: IIRC, the first argument of PyEval_EvalFrame was a PyFrameObject*, so we walked it until we found the name of the python function
<cfbolz>
antocuni: ah, for the cpython version
<antocuni>
like, doing f->f_code->co_name or something along those lines
<antocuni>
yes
<antocuni>
but if you have a trampoline, you can basically kill vmprof and use perf :). As they did now
<antocuni>
I guess that at the time having a JIT inside CPython was considered a heresy. Things change :)
<cfbolz>
Perf stack maps are quite a hack, fwiw
<cfbolz>
They aren't easy to use for 'proper' jits
<antocuni>
ah, according to this comment they to exactly what I described above: Notice that for this to work, there must be a unique copied of the trampoline
<antocuni>
per Python code object even if the code in the trampoline is the same. To
<antocuni>
achieve this we have a assembly template in Objects/asm_trampiline.S that is
<antocuni>
compiled into the Python executable/shared library. This template generates a
<antocuni>
symbol that maps the start of the assembly code and another that marks the end
<antocuni>
of the assembly code for the trampoline. Then, every time we need a unique
<antocuni>
trampoline for a Python code object, we copy the assembly code into a mmaped
<antocuni>
area that has executable permissions and we return the start of that area as
<antocuni>
our trampoline function.
<antocuni>
ops sorry, I wanted to copy the link and not the full text :(
<antocuni>
with the difference that they write the trampoline in assembler instead of C
<antocuni>
ah, I see. By writing it in assembler they can put a global symbol which marks the *end* of the function, which was exactly the problem which I stumbled upon too\
dmalcolm_ has joined #pypy
<cfbolz>
antocuni: you can get that in C too with some tricks
<cfbolz>
But yes, all somewhat messy
<cfbolz>
antocuni: I suppose the trampolines leak in cpython?
dmalcolm has quit [Ping timeout: 252 seconds]
<cfbolz>
antocuni: I think they have to, perf jit maps don't support reusing an address for a different function later
<antocuni>
I suppose that in theory they could free trampolines when they are not needed and try to remember the address to avoid reusing it. But they are allocated in big arena blocks, so in practice I guess they will always survive and leak (but didn't look at the actual implementation)
<cfbolz>
It's a tiny amount of bytes only of course
derpydoo has joined #pypy
jcea has joined #pypy
derpydoo has quit [Ping timeout: 268 seconds]
glyph has quit [Quit: End of line.]
glyph has joined #pypy
[m]alice is now known as alice
<cfbolz>
mattip: wow, bpnn.py
<cfbolz>
That takes me back
<cfbolz>
That was really before the AI resurgence :-)
<mattip>
someone on stack overflow asked about python ./rpython/translator/goal/translate.py program.py
<mattip>
which got me to try to find where in the documentation we mention that
<mattip>
bpnn was the only place I found
<mattip>
and it isn't even part of the html documentation