Commit 5f3b67e
authored
Move most module initialization to compiled code (bytecodealliance#13487)
* Don't panic in `Slab::{get,get_mut}`
Instead return `None`. This helps prevent corruption of the GC heap from
causing panics.
* Don't allow memset with funcref arrays
Even `ref.null func` is intern'd, so nothing is candidate for memset on
a `funcref` array. Overall just ban memset on all reference-typed arrays
for now to optimize the easy case of scalar data, but leave optimizing
reference types for later.
* Move most module initialization to compiled code
This commit is a large refactoring of how modules are initialized in
Wasmtime. Notably all of the work done post-allocation, but pre-start,
is now done in compiled code instead. This means that global
initialization, active table segments, passive segment evaluation, etc,
now all happens in compiled code. The primary motivation for this is to
resolve some GC-related fuzz-bugs where initialization on the host is
taking an excessively long time. A secondary motivation is to apply fuel
metering and epoch yielding to these constructs in the same manner that
normal wasm code has these applied.
Much refactoring was needed in this commit to achieve this goal. Many
primitives were transitioned from runtime state to exclusively
compile-time state for example. Infrastructure was additionally added
for a new kind of `FuncKey` corresponding to this one-off-use startup
function. Overall though the net effect of this change is to mostly
delete code since so much of the runtime is now no longer necessary. An
example of this is that const-eval is now completely removed from the
runtime as the fully-general const-evaluation now happens exclusively
through compiled code.
Special care was needed here for the static table and memory
initialization that Wasmtime performs. For example there's a small dance
between compile-time and run-time where at compile-time we don't know if
static data segments should be applied, and it's only at run-time where
we know if CoW is in effect. Additionally care was taken throughout this
refactoring to avoid generating this new startup function unless it's
necessary. It's hypothesized that skipping this function is going to be
a worthwhile optimization, which means that one mode of startup is
configured as "only necessary if memories say `needs_init()`". This is a
bit tricky to document and it's a bit non-standard, but it should get
the job done (and existing tests exercise this already).
* Review comments1 parent 96b5b82 commit 5f3b67e
71 files changed
Lines changed: 2899 additions & 2696 deletions
File tree
- crates
- core/src
- cranelift/src
- compiler
- func_environ
- gc/enabled
- translate
- environ/src
- compile
- component
- wasmtime/src
- runtime
- component
- gc/disabled
- vm
- gc/enabled
- instance
- winch/src
- src/commands
- tests
- all
- disas
- gc
- winch/x64/table
- misc_testsuite/gc
- winch/codegen/src/codegen
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
393 | | - | |
394 | | - | |
| 393 | + | |
| 394 | + | |
395 | 395 | | |
396 | 396 | | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
| 397 | + | |
402 | 398 | | |
403 | 399 | | |
404 | 400 | | |
| |||
408 | 404 | | |
409 | 405 | | |
410 | 406 | | |
411 | | - | |
412 | | - | |
| 407 | + | |
| 408 | + | |
413 | 409 | | |
414 | 410 | | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
| 411 | + | |
420 | 412 | | |
421 | 413 | | |
422 | 414 | | |
| |||
0 commit comments