Closed Bug 1831030 Opened 1 year ago Closed 10 months ago

Support Wizer snapshotting in JS shell

Categories

(Core :: JavaScript Engine, enhancement, P1)

enhancement

Tracking

()

RESOLVED WONTFIX

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

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!

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
$
Assignee: nobody → chris
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Blocks: 1831399
Severity: -- → N/A
Priority: -- → P1
Blocks: 1832406
Pushed by jdemooij@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/f48b35a6fdce
JS shell on WASI: add basic Wizer integration. r=jandem

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!

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.

Flags: needinfo?(jdemooij)
Flags: needinfo?(chris)

Leaving the NI for Chris who can answer this better.

Flags: needinfo?(jdemooij)

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.

Flags: needinfo?(chris)
Status: ASSIGNED → RESOLVED
Closed: 10 months ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: