• mtrofin's avatar
    [wasm] Fix wasm instantiation flakes · b75a0c4a
    mtrofin authored
    The spurious failures were caused by the compiled module
    template and its corresponding owning object getting out of
    sync due to memory allocations (which may trigger GC)
    between the points each were fetched.
    
    Specifically, the {original} was first obtained; then a GC
    may happen when cloning the {code_table}. At this point,
    the {original}'s owner may have been collected, getting us
    down the path of not cloning. When time comes to patch up
    globals, we incorrectly try to patch them assuming the
    global start is at 0 (nullptr), which in fact it isn't.
    
    This change roots early, in a GC-free area, both objects.
    Additionally, it avoids publishing to the instances chain
    the new instance until the very end. This way:
    - the objects used to create the new instance offer a
    consistent view
    - the instances chain does not see the object we try to
    form. If something fails, we can safely retry.
    - since the owner is rooted, the state of the front of the
    instances chain stays unchanged - with the same compiled
    module we started from. So the early belief that we needed
    to clone is not invalidated by any interspersed GC.
    
    This situation suffers from a sub-optimality discussed in
    the design document, in that, in a memory constrained
    system, the following snippet may surprisingly fail:
    
    var m = new WebAssembly.Module(...);
    var i1 = new WebAssembly.Instance(m);
    i1 = null;
    var i2 = new WebAssembly.Instance(m); //may fail.
    
    This will be addressed subsequently.
    
    BUG=v8:5451
    
    Review-Url: https://codereview.chromium.org/2395063002
    Cr-Commit-Position: refs/heads/master@{#40126}
    b75a0c4a
Name
Last commit
Last update
benchmarks Loading commit data...
build_overrides Loading commit data...
docs Loading commit data...
gni Loading commit data...
gypfiles Loading commit data...
include Loading commit data...
infra Loading commit data...
samples Loading commit data...
src Loading commit data...
test Loading commit data...
testing Loading commit data...
third_party/binutils Loading commit data...
tools Loading commit data...
.clang-format Loading commit data...
.gitignore Loading commit data...
.gn Loading commit data...
.ycm_extra_conf.py Loading commit data...
AUTHORS Loading commit data...
BUILD.gn Loading commit data...
CODE_OF_CONDUCT.md Loading commit data...
ChangeLog Loading commit data...
DEPS Loading commit data...
LICENSE Loading commit data...
LICENSE.fdlibm Loading commit data...
LICENSE.strongtalk Loading commit data...
LICENSE.v8 Loading commit data...
LICENSE.valgrind Loading commit data...
Makefile Loading commit data...
Makefile.android Loading commit data...
OWNERS Loading commit data...
PRESUBMIT.py Loading commit data...
README.md Loading commit data...
WATCHLISTS Loading commit data...
codereview.settings Loading commit data...
snapshot_toolchain.gni Loading commit data...