How patchpoint intrinsic actually patches?

Dear All

I have some questions about how to use patchpoint intrinsic:

1- The function that is provided as argument to the intrinsic call, where does it belong? I’m making a pass to change a given IR file and add call to patchpoint. Where should I put this function? In the pass or in the same IR file or in another IR and include it or what?

2- When actually this code is patched into the original code and executed? Upon some condition or signal or it’s patched by default whenever it’s met in code? If it’s patched automatically, what is its advantage then?

Thanks in advance.

Hi,
The patchpoint intrinsic just takes a pointer to the function it should call. It doesn’t care where the address points to e.g. could by a function in the same module or the address of some functions inside the application. When the machine code gets emitted the patchpoint will get replaced with a call instruction to the address specified inside the intrinsic before + additional nop instructions depending on the numBytes param of the patchpoint. So you don’t actually have to patch the patchpoint if calling the supplied address is fine.

Pyston uses the patchpoint intrinsic to emit a call to the slowpath function (e.g. a function which can handle all object types). This function when called will determine from where it got called to retrieve the corresponding stackmap entry and determine the actual types of the args it got called. It will then replace the call+nop from the patchpoint with a type check and a call to the faster type dependent function and a call to the slowpath function in case the types change. You will have to do the patching on you own.

Hope this helps.