Support Wizer snapshotting in JS shell
Categories
(Core :: JavaScript Engine, enhancement, P1)
Tracking
()
People
(Reporter: cfallin, Assigned: cfallin)
References
Details
Attachments
(1 file)
Steps to reproduce:
When building the JS shell for wasm32-wasi
(i.e., as a WebAssembly module using the WASI ABI), it would be useful to be able to create a snapshot of the interpreter in a Wasm module together with fixed JS source, such that the JS runs when the Wasm module is instantiated and executed.
The Wizer tool supports snapshotting WebAssembly modules: given a function to call to "pre-initialize", it will then generate a new Wasm module with the heap exactly as it was left, and with the entry point set to a new function to "resume". This requires some (minimal) hooks to be provided, however, and the JS shell doesn't have these yet.
Actual results:
Currently, Wizer cannot snapshot the JS-shell-as-Wasm-module because the necessary hooks are not implemented.
Expected results:
With the proper support, we should be able to do the following:
$ echo "function main() { print('hello world'); }" | \
wizer --allow-wasi -r _start=wizer.resume obj-release/dist/bin/js \
-o snapshotted.wasm
$ wasmtime snapshotted.wasm
hello world
Assignee | ||
Comment 1•2 years ago
|
||
Note that there exist third-party integrations that do this already (e.g., server-side FaaS SDKs) and there are also plans related to the Wasm component model to build out a generic toolchain for this; however while working on interpreter-related tools I've found it useful to have a simple Wizer mode integrated directly into the vanilla upstream JS shell, so I don't have to carry a local patch. Hopefully this is agreeable to upstream!
Assignee | ||
Comment 2•2 years ago
|
||
This patch allows the use of a JS shell binary, compiled to
wasm32-wasi
(WASI ABI on WebAssembly), to make use of the Wizer
snapshotting tool to embed JavaScript source with SpiderMonkey to run in
a standalone Wasm module.
If enabled with --enable-js-shell-wizer
, the shell no longer provides
an interactive REPL; instead, when invoked during the "initialization"
phase of Wizer, it reads JS source on standard input, then
saves JS state (the global, the context, etc) for later. When the
execution is snapshotted and the snapshot is later executed as an
ordinary WASI command, the resume entry-point invokes a JS function
named main
in the global scope, if any.
An example of how to use this follows:
$ echo "function main() { print('hello world'); }" | \
wizer --allow-wasi -r _start=wizer.resume obj-release/dist/bin/js \
-o snapshotted.wasm
$ wasmtime snapshotted.wasm
hello world
$
Updated•2 years ago
|
Updated•2 years ago
|
Comment 4•2 years ago
•
|
||
Backed out for Linting failure
Backout link: https://hg.mozilla.org/integration/autoland/rev/035ec5b47a72282b1f615b30e2baae6490ceda41
Log link: https://treeherder.mozilla.org/logviewer?job_id=417785407&repo=autoland&lineNumber=185
Please alos check this SM bustage
Assignee | ||
Comment 5•2 years ago
|
||
It looks like both failures are due to missing metadata somehow around the /third_party/wizer
directory addition. I don't have time to look into this now (in the next few weeks) but can revisit later, unless someone more experienced than me with mozbuild stuff can point out the issue!
Comment 6•2 years ago
|
||
There is an r+ patch which didn't land and no activity in this bug for 2 weeks.
:cfallin, could you have a look please?
If you still have some work to do, you can add an action "Plan Changes" in Phabricator.
For more information, please visit BugBot documentation.
Comment 7•2 years ago
|
||
Leaving the NI for Chris who can answer this better.
Assignee | ||
Comment 8•2 years ago
|
||
I'll go ahead and close this for now: unfortunately I can't justify spending more time tilting against the build-system windmill here and this feature isn't an urgent need at the moment.
Assignee | ||
Updated•2 years ago
|
Description
•