-
Notifications
You must be signed in to change notification settings - Fork 293
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
Allow Wasm module instantiation in host functions called from Wasmi's executor #1116
Merged
Conversation
This file contains 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
This test currently dead locks as expected.
This finally resolves the dead lock when instantiating a Wasm module in a called host function.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1116 +/- ##
==========================================
+ Coverage 80.48% 80.51% +0.03%
==========================================
Files 270 271 +1
Lines 25079 25110 +31
==========================================
+ Hits 20184 20217 +33
+ Misses 4895 4893 -2 ☔ View full report in Codecov by Sentry. |
New enforced maximum parameter and result types per FuncType is 1000. This fits nicely in a u16 value which we will make use of later in the API.
This also make use of u16 in HostFuncEntity to inline cache len_{params,results} as an space optimization.
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.
So far it was not possible to instantiate a Wasm module in a host function that has been called from Wasmi's executor.
This was because of a dead lock that occurred due to a
RwLock<EngineResources>
which contained theFuncTypeRegistry
which was (in the end) mainly used for resolving the number of parameter and result types of a called host function in the Wasmi executor.There are two ways of solving this with the following change:
Remove
EngineResources
and insteadRwLock
bothCodeMap
andFuncTypeRegistry
themselves.&CodeMap
in the Wasmi executor but now also aRwLock<FuncTypeRegistry>
. Unlock the registry very shortly to resolve the number of parameters and results whenever a host function is called which should occur kind of rarely. The downside is that this probably regresses performance of host function calls due to the additional locking per call.HostFuncEntity
with inline information about the number of its parameter types and result types. This acts as chace. SinceHostFuncEntity
has to be resolved anyway for a host function call no performance regressions are expected with this solution. The downside is increased space requirements for theFuncEntity
buffer.This PR chose 2. for its implementation. Before merging we might want to experiment with another PR that tried out 1. Local benchmarks confirmed that there were no significant changes.
ToDo
u16
instead ofusize
to store the inline number of parameters and results inHostFuncEntity
. This is safely possible since we limit the number of both values between0..=1000
similar to Wasmtime.