Skip to content

store wasm globals in execution context such that a single parsed module can be shared by multiple threads#16

Merged
linh2931 merged 4 commits intomainfrom
make_globals_threaded_safe
Jul 26, 2023
Merged

store wasm globals in execution context such that a single parsed module can be shared by multiple threads#16
linh2931 merged 4 commits intomainfrom
make_globals_threaded_safe

Conversation

@linh2931
Copy link
Contributor

Resolves #7.
A part of VaultaFoundation/product#149.

Currently globals are stored in a compiled module. This prevents the module from being shared by multiple execution threads, as multiple threads can modify the same global. To enable the same compiled module to be shared,
globals are moved out of module and into the execution context.

This opens possibilities for further parallelism and memory reduction for cached instantiated modules.

Change Description

API Changes

  • API Changes

Documentation Additions

  • Documentation Additions

auto icount = variable_size_instr(13, 14);
auto icount = variable_size_instr(24, 42); // emit_setup_backtrace can be 0 or 9, and emit_restore_backtrace 0 or 9, the total of the rest 24
auto& gl = _mod.globals[globalidx];
void *ptr = &gl.current.value;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason for using get_global_* and set_global_* instead of just _globals[globalidx].value ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a reason for using get_global_* and set_global_* instead of just _globals[globalidx].value ?

At the time when emit_get_global and emit_set_global are called, execution_conetxt is not constructed yet; we don't have access to _globals. We also want to decouple the generated instructions from physical address of execution_context.

@linh2931 linh2931 merged commit 4d5415f into main Jul 26, 2023
@linh2931 linh2931 deleted the make_globals_threaded_safe branch July 26, 2023 21:18
@linh2931 linh2931 mentioned this pull request Jul 27, 2023
2 tasks
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.

Make compiled module sharable in multi-threaded EOS-VM-Interpreter and EOS-VM-Jit execution

3 participants