pharo-project / pharo-vm

This is the VM used by Pharo
http://pharo.org
Other
113 stars 68 forks source link

Change calling convention on closures #761

Closed guillep closed 5 months ago

guillep commented 6 months ago

This PR changes the calling convention of closure activation on JIT compilation. The interpreter->JIT closure activation has been revised too.

This PR depends on https://github.com/pharo-project/pharo-vm/pull/760.

Benchmarks show no noticeable degradation/improvement on ARM64 (on the order of +-1% systematically).

Before:

It was the caller's responsibility to push the closure's receiver/arguments to the stack before activating a closure. The receiver/argument push was made on the primitiveFullBlockClosure, thus all closures shared the code making the push. This made JIT compiled closures shorter by a couple of push instructions each.

Now:

Closures follow the method calling convention. Closures with <=2 arguments will have their arguments passed on registers, and otherwise on the stack. In the first case, it's the callee's responsibility (i.e., the closure) to push the arguments, otherwise it's the caller's responsibility. This makes JIT compiled closures slightly larger by a couple of push instructions.

At the same time, this opens the possibility of frameless closures and eventually unify the code activating closures and methods.