Hello gophers, My recent attempt at creating a JIT compiler in Go to speed up my interpreter https://github.com/cosmos72/gomacro hit an early roadblock.
In its current status, it can compile integer arithmetic and struct/array/slice/pointer access for amd64 and arm64, but it cannot allocate memory or call other functions, which severely limits its usefulness (and is thus not yet used by gomacro). The reason is: there is a requirement that Go functions must have a "stack frame descriptors registered with the runtime", in brief a "stack map" that tells which bits on the stack are pointers and which ones are not. See https://github.com/golang/go/issues/20123 for details. But there is no API to associate a stack map to functions generated at runtime and running on the Go stack - currently the only supported mechanism to load Go code at runtime is to open a shared library file with `plugin.Open()` Thus JIT-generated functions must avoid triggering the garbage collector, as it would panic as described in the link above. In turn, this means they cannot: * allocate memory * call other functions * grow the stack or do anything else that may start the GC. Now, I understand *why* Go functions must currently have a stack map, and I see at least two possible solutions: 1. implement an API to associate a stack map to functions generated at runtime - possibly by forking the Go compiler and/or standard library 2. replace Go GC and allocator with an alternative that does not require stack maps - for example Boehm GC https://www.hboehm.info/gc/ Here too, forking the Go compiler and/or standard library if needed. My questions are: a. which one of the two solutions above is easier, and how long could it take to a full-time expert? b. does anyone have an easier solution or workaround to achieve the same goal? Regards, cosmos72 -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/27a00830-e0aa-467f-919b-ace1a5e07e8e%40googlegroups.com.