Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undo assertion on STANDALONE_WASM not working with memory growth #9588

Merged
merged 10 commits into from
Oct 9, 2019

Conversation

kripken
Copy link
Member

@kripken kripken commented Oct 7, 2019

While it isn't 100% standalone (there is an import to grow the memory), it is usable for people that implement that import, so don't break them.

fixes #9587

…le it isn't 100% standalone (there is an import to grow the memory), it is usable for people that implement that import, so don't break them. fixes #9587
zeux added a commit to zeux/meshoptimizer that referenced this pull request Oct 7, 2019
This change updates the js build to Emscripten 1.38.47. This version
changes the behavior of standalone .wasm modules - instead of importing
a few symbols, including memory, externally, the standard library now
creates and exports the memory object. Because of this the JS embedding
structure needed to change a bit.

Additionally, the ChakraCore workaround is not necessary anymore because
the bug isn't being hit with LLVM upstream codegen.

As a result, the JS is ~2% smaller after these updates.

Note that because of a regression in .47, building this locally requires
patching Emscripten with this change:

emscripten-core/emscripten#9588
@zeux
Copy link

zeux commented Oct 7, 2019

Just a minor comment, "there is an import to grow the memory" - there actually isn't :) emscripten_resize_heap is implemented in standalone_wasm.c without any callouts to JS.

@kripken
Copy link
Member Author

kripken commented Oct 7, 2019

Thanks @zeux! Actually that's more than a minor comment, it showed I missed something important here, and had to rework this PR.

We don't support memory growth in pure wasm runtimes yet, because of WebAssembly/WASI#82 My goal was for this PR to make it work outside of those runtimes - that is, when standalone mode is enabled, but still running with the JS. And my assumption was that wasm runtimes would show an error on emscripten_resize_heap being missing, would let people know why it doesn't work (because extra non-wasi stuff is needed). But you're right, that function was already included in the wasm...

I rewrote this PR to do things properly, and added a test for growth as well:

  • Remove the assertion on memory growth not being allowed in standalone mode.
  • Add emscripten_notify_memory_growth which is just called to notify. That will show an error in wasm runtimes that don't support it.
  • Add a variation on libstandalone that calls that notification if growth is enabled. That lets programs not using growth still be 100% pure.
  • Add a test for memory growth in "impure" standalone wasm (i.e., standalone mode does not emit a 100% pure wasm yet).
  • Fix some bugs in emscripten_resize_heap and the preamble memory loading code, that the test uncovered.

@kripken kripken requested a review from sbc100 October 7, 2019 20:36
@VirtualTim
Copy link
Collaborator

Hey would this change also fix #9190?

@kripken
Copy link
Member Author

kripken commented Oct 8, 2019

@VirtualTim this is separate from that, as this PR is just for standalone wasm mode - in which there is no JS. We don't have support for pthreads in that case, but on the plus side, without JS the problem in #9190 won't exist, if/when we do have standalone wasm pthreads.

@kripken
Copy link
Member Author

kripken commented Oct 9, 2019

I also added docs for the new API.

@sbc100 maybe you want to take another look here, as it changed since the lgtm?

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunate that we need another library variant but seems reasonable I suppose

def get_base_name(self):
name = super(libstandalonewasm, self).get_base_name()
if self.is_mem_grow:
name += '-mem_grow'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems odd to mix hyphen and underscore here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I'll make it memgrow (no underscore).

@kripken kripken merged commit 56f692f into incoming Oct 9, 2019
@kripken kripken deleted the stgrow branch October 9, 2019 23:31
belraquib pushed a commit to belraquib/emscripten that referenced this pull request Dec 23, 2020
Remove the assertion on memory growth not being allowed in standalone mode.

Add emscripten_notify_memory_growth which is just called to notify. That will
show an error in wasm runtimes that don't support it.

Add a variation on libstandalone that calls that notification if growth is
enabled. That lets programs not using growth still be 100% pure.

Add a test for memory growth in "impure" standalone wasm (i.e., standalone mode
does not emit a 100% pure wasm yet).

Fix some bugs in emscripten_resize_heap and the preamble memory loading code,
that the test uncovered.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build regression: "STANDALONE_WASM does not support memory growth yet"
4 participants