Skip to content

Fix EXPORT_NAME + MODULARIZE_INSTANCE + pthreads #10449

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

Merged
merged 8 commits into from
Feb 25, 2020

Conversation

kripken
Copy link
Member

@kripken kripken commented Feb 14, 2020

In that case we have just the custom EXPORT_NAME in
the global scope, and must connect to that properly in
the worker.js file which only sees the global scope.

Also we cannot use out()/err() for logging as those are
internals of the emitted code, which in MODULARIZE*
mode are not available to worker.js as well.

fixes #9091

@@ -4954,3 +4954,18 @@ def test_wasm2js_fallback(self):
open('test.html', 'w').write(html)
os.remove('test.wasm') # Also delete the Wasm file to test that it is not attempted to be loaded.
self.run_browser('test.html', 'hello!', '/report_result?0')

# Test that basic thread creation works in combination with MODULARIZE_INSTANCE=1 and EXPORT_NAME=MyModule
@no_fastcomp('more work would be needed for this to work in deprecated fastcomp')
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is the difference with fastcomp that causes this to fail? Iiuc MODULARIZE_INSTANCE is an identical feature in both backends?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fastcomp emits a bunch of code in the HTML to deal with the asm.js memory init file, and that has hardcoded Module in there (instead of the custom export name). From the stack trace I think that's what goes wrong, but I didn't investigate.

@@ -258,7 +272,7 @@ this.onmessage = function(e) {
#if ASSERTIONS
} else {
// else e == 'unwind', and we should fall through here and keep the pthread alive for asynchronous events.
out('Pthread 0x' + threadInfoStruct.toString(16) + ' completed its pthread main entry point with an unwind, keeping the pthread worker alive for asynchronous operation.');
err('Pthread 0x' + threadInfoStruct.toString(16) + ' completed its pthread main entry point with an unwind, keeping the pthread worker alive for asynchronous operation.');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
err('Pthread 0x' + threadInfoStruct.toString(16) + ' completed its pthread main entry point with an unwind, keeping the pthread worker alive for asynchronous operation.');
out('Pthread 0x' + threadInfoStruct.toString(16) + ' completed its pthread main entry point with an unwind, keeping the pthread worker alive for asynchronous operation.');

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since it looks like it's only used for debugging purposes. Correct me if I'm wrong.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is for debugging, yeah. So it actually seems natural to use err instead of out to me? But I guess we don't have a very clear policy on such logging (which doesn't matter much in practice on the web console). I'm happy to do it either way people prefer.

Copy link
Collaborator

@kleisauke kleisauke Feb 19, 2020

Choose a reason for hiding this comment

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

I see. The out / threadPrintOut functions however seems to be unused now in worker.js, so perhaps these can be removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess they can. I added them for completeness, as they may be needed in the future. But I believe we don't DCE this file, so probably best to remove, I'll do that.

@kripken kripken requested a review from juj February 24, 2020 22:02
// in the global scope.
#if MODULARIZE_INSTANCE && EXPORT_NAME != 'Module'
var {{{ EXPORT_NAME }}} = Module;
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it work instead of

var Module = {};


// If we use a custom export name, refer to Module from it as well, so that
// we connect properly to the modularized instance which is the only thing
// in the global scope.
#if MODULARIZE_INSTANCE && EXPORT_NAME != 'Module'
var {{{ EXPORT_NAME }}} = Module;
#endif

to do

var {{{ EXPORT_NAME }}} = {};

and in all places in the worker below, access {{{ EXPORT_NAME }}} instead of Module?

Copy link
Member Author

Choose a reason for hiding this comment

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

That might work too, but I think it makes the code a little less readable, and there's a risk of future changes to the file forgetting and using Module (and then working except for the corner case fixed here).

Copy link
Collaborator

@juj juj left a comment

Choose a reason for hiding this comment

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

lgtm.

@kripken kripken merged commit 4bd0bc3 into master Feb 25, 2020
@kripken kripken deleted the export_modularize_pthread branch February 25, 2020 18:59
kripken added a commit that referenced this pull request Feb 26, 2020
This is a regression from #10566 which renamed that
setting to INITIAL_MEMORY, and #10449 which added
a test using that setting in that way, and landed close
enough that we didn't notice it was doing so. It should
have worked since we tried to support the old name of
the setting, but this uncovered a bug, so it's actually
good that it broke!

The bug is that we have special handling for expanding
things like 64MB into a number, and that handling did
not work on aliases. As a solution, map aliases very
early in parsing.
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.

worker.js: onmessage() captured an uncaught exception: ReferenceError: __register_pthread_ptr is not defined
4 participants