feat: Add deep copy functionality to Instance and related runtime cla…#946
Draft
chirino wants to merge 2 commits intodylibso:mainfrom
Draft
feat: Add deep copy functionality to Instance and related runtime cla…#946chirino wants to merge 2 commits intodylibso:mainfrom
chirino wants to merge 2 commits intodylibso:mainfrom
Conversation
…sses - Add copy() method to Instance class for creating deep copies of WebAssembly runtime state - Implement copy() methods in GlobalInstance, TableInstance, and TagInstance classes - Add copy() interface method to Memory with implementations in ByteArrayMemory and ByteBufferMemory - Extend ImportValues with copy() method for deep copying import state - Create comprehensive InstanceCopyTest with test cases for all copy scenarios - Add global-counter.wat test module with compiled WASM binary for testing global state copying - Update wasm-corpus Dockerfile to include wabt tools for WebAssembly compilation - Add copyWithOptions() method that allows you to change the listen or imports for the new instance copy. This implementation enables creating independent copies of WebAssembly runtime instances with fully isolated state, including memory contents, global variables, tables, tags, and import values. This is essential for scenarios requiring instance isolation, snapshotting, or parallel execution contexts. Signed-off-by: Hiram Chirino <hiram@hiramchirino.com>
…name it Experimental And document that it’s dangerous to use. Signed-off-by: Hiram Chirino <hiram@hiramchirino.com>
andreaTP
reviewed
Jun 20, 2025
| GlobalInstance copy = | ||
| new GlobalInstance( | ||
| this.valueLow, this.valueHigh, this.valType, this.mutabilityType); | ||
| // The instance field will be set by the calling code |
Collaborator
There was a problem hiding this comment.
The need of resetting/recomputing fields shows that this is a leaky abstraction.
Collaborator
|
For reference, wasmtime experimented with those things: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…sses
This implementation enables creating independent copies of WebAssembly runtime instances with fully isolated state, including memory contents, global variables, tables, tags, and import values. This is essential for scenarios requiring instance isolation, snapshotting, or parallel execution contexts.