Generating code at runtime in a platform-agnostic way

52 views
Skip to first unread message

Zaclegarssure

unread,
Mar 11, 2025, 5:20:20 AM3/11/25
to v8-dev
Hi everyone, first time posting here.
As part of my master thesis I'm working on improving the performances of the experimental non-backtracking regex engine of v8. In particular I plan to add native compilation to it, like it's done in Irregexp, to help close the performance gap between the two.
I was wondering if there is a way to generate native code at runtime in a platform-agnostic manner, by leveraging Turbofan. At first glance, the CodeStubAssembler seems to do exactly this, but in the examples I've seen, the code was generated at build time only. Is there a way to invoke it at runtime as well?

Any insights or pointers would be greatly appreciated!

Thanks,
Zacharie Tevaearai


Jakob Kummerow

unread,
Mar 11, 2025, 6:43:44 AM3/11/25
to v8-...@googlegroups.com
The CodeStubAssembler (and all its derived classes) is not compiled into the shipping binaries, so all that infrastructure is indeed only available at V8 build time.

It's probably most instructive to look at the existing entry points to the "Turboshaft" part of the pipeline, such as graph-builder.cc (for JS, taking a Turbofan Sea-of-Nodes graph as input) and turboshaft-graph-interface.cc (for Wasm, individual functions being called for slightly abstract-ified versions of Wasm instructions) for inspiration.

If the compiler doesn't have the infrastructure you need, you can consider following the example of irregexp and using the platform-specific MacroAssembler directly. At least for an initial prototype for just one platform, this may be both simpler and give better results. (For proper productionization, a cross-platform implementation is then likely quite desirable, but it doesn't necessarily need to be the first step.)

Good luck!


--
--
v8-dev mailing list
v8-...@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/v8-dev/95df57ee-db41-4a44-ae14-946cec5be621n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages