alexcrichton updated PR #957 from local-trampolines to master:
The
wasmtimecrate supports calling arbitrary function signatures in
wasm code, and to do this it generates "trampoline functions" which have
a known ABI that then internally convert to a particular signature's ABI
and call it. These trampoline functions are currently generated
on-the-fly and are cached in the globalStorestructure. This,
however, is suboptimal for a few reasons:
Due to how code memory is managed each trampoline resides in its own
64kb allocation of memory. This means if you have N trampolines you're
using N * 64kb of memory, which is quite a lot of overhead!Trampolines are never free'd, even if the referencing module goes
away. This is similar to #925.Trampolines are a source of shared state which prevents
Storefrom
being easily thread safe.This commit refactors how trampolines are managed inside of the
wasmtimecrate and jit/runtime internals. All trampolines are now
allocated in the same pass ofCodeMemorythat the main module is
allocated into. A trampoline is generated per-signature in a module as
well, instead of per-function. This cache of trampolines is stored
directly inside of anInstance. Trampolines are stored based on
VMSharedSignatureIndexso they can be looked up from the internals of
theExportFunctionvalue.The
FuncAPI has been updated with various bits and pieces to ensure
the right trampolines are registered in the right places. Overall this
should ensure that all trampolines necessary are generated up-front
rather than lazily. This allows us to remove the trampoline cache from
theCompilertype, and move one step closer to makingCompiler
threadsafe for usage across multiple threads.Note that as one small caveat the
Func::wrap*family of functions
don't need to generate a trampoline at runtime, they actually generate
the trampoline at compile time which gets passed in.Also in addition to shuffling a lot of code around this fixes one minor
bug found incode_memory.rs, whereself.positionwas loaded before
allocation, but the allocation may push a new chunk which would cause
self.positionto be zero instead.
sunfishcode submitted PR Review.
sunfishcode submitted PR Review.
sunfishcode created PR Review Comment:
Here and in the other
loadimplementations, it looks like this is dereferencing the wrong thing.
alexcrichton updated PR #957 from local-trampolines to master:
The
wasmtimecrate supports calling arbitrary function signatures in
wasm code, and to do this it generates "trampoline functions" which have
a known ABI that then internally convert to a particular signature's ABI
and call it. These trampoline functions are currently generated
on-the-fly and are cached in the globalStorestructure. This,
however, is suboptimal for a few reasons:
Due to how code memory is managed each trampoline resides in its own
64kb allocation of memory. This means if you have N trampolines you're
using N * 64kb of memory, which is quite a lot of overhead!Trampolines are never free'd, even if the referencing module goes
away. This is similar to #925.Trampolines are a source of shared state which prevents
Storefrom
being easily thread safe.This commit refactors how trampolines are managed inside of the
wasmtimecrate and jit/runtime internals. All trampolines are now
allocated in the same pass ofCodeMemorythat the main module is
allocated into. A trampoline is generated per-signature in a module as
well, instead of per-function. This cache of trampolines is stored
directly inside of anInstance. Trampolines are stored based on
VMSharedSignatureIndexso they can be looked up from the internals of
theExportFunctionvalue.The
FuncAPI has been updated with various bits and pieces to ensure
the right trampolines are registered in the right places. Overall this
should ensure that all trampolines necessary are generated up-front
rather than lazily. This allows us to remove the trampoline cache from
theCompilertype, and move one step closer to makingCompiler
threadsafe for usage across multiple threads.Note that as one small caveat the
Func::wrap*family of functions
don't need to generate a trampoline at runtime, they actually generate
the trampoline at compile time which gets passed in.Also in addition to shuffling a lot of code around this fixes one minor
bug found incode_memory.rs, whereself.positionwas loaded before
allocation, but the allocation may push a new chunk which would cause
self.positionto be zero instead.
alexcrichton submitted PR Review.
alexcrichton created PR Review Comment:
Oh dear good catch! Made sure to add tests to catch this
alexcrichton updated PR #957 from local-trampolines to master:
The
wasmtimecrate supports calling arbitrary function signatures in
wasm code, and to do this it generates "trampoline functions" which have
a known ABI that then internally convert to a particular signature's ABI
and call it. These trampoline functions are currently generated
on-the-fly and are cached in the globalStorestructure. This,
however, is suboptimal for a few reasons:
Due to how code memory is managed each trampoline resides in its own
64kb allocation of memory. This means if you have N trampolines you're
using N * 64kb of memory, which is quite a lot of overhead!Trampolines are never free'd, even if the referencing module goes
away. This is similar to #925.Trampolines are a source of shared state which prevents
Storefrom
being easily thread safe.This commit refactors how trampolines are managed inside of the
wasmtimecrate and jit/runtime internals. All trampolines are now
allocated in the same pass ofCodeMemorythat the main module is
allocated into. A trampoline is generated per-signature in a module as
well, instead of per-function. This cache of trampolines is stored
directly inside of anInstance. Trampolines are stored based on
VMSharedSignatureIndexso they can be looked up from the internals of
theExportFunctionvalue.The
FuncAPI has been updated with various bits and pieces to ensure
the right trampolines are registered in the right places. Overall this
should ensure that all trampolines necessary are generated up-front
rather than lazily. This allows us to remove the trampoline cache from
theCompilertype, and move one step closer to makingCompiler
threadsafe for usage across multiple threads.Note that as one small caveat the
Func::wrap*family of functions
don't need to generate a trampoline at runtime, they actually generate
the trampoline at compile time which gets passed in.Also in addition to shuffling a lot of code around this fixes one minor
bug found incode_memory.rs, whereself.positionwas loaded before
allocation, but the allocation may push a new chunk which would cause
self.positionto be zero instead.
alexcrichton updated PR #957 from local-trampolines to master:
The
wasmtimecrate supports calling arbitrary function signatures in
wasm code, and to do this it generates "trampoline functions" which have
a known ABI that then internally convert to a particular signature's ABI
and call it. These trampoline functions are currently generated
on-the-fly and are cached in the globalStorestructure. This,
however, is suboptimal for a few reasons:
Due to how code memory is managed each trampoline resides in its own
64kb allocation of memory. This means if you have N trampolines you're
using N * 64kb of memory, which is quite a lot of overhead!Trampolines are never free'd, even if the referencing module goes
away. This is similar to #925.Trampolines are a source of shared state which prevents
Storefrom
being easily thread safe.This commit refactors how trampolines are managed inside of the
wasmtimecrate and jit/runtime internals. All trampolines are now
allocated in the same pass ofCodeMemorythat the main module is
allocated into. A trampoline is generated per-signature in a module as
well, instead of per-function. This cache of trampolines is stored
directly inside of anInstance. Trampolines are stored based on
VMSharedSignatureIndexso they can be looked up from the internals of
theExportFunctionvalue.The
FuncAPI has been updated with various bits and pieces to ensure
the right trampolines are registered in the right places. Overall this
should ensure that all trampolines necessary are generated up-front
rather than lazily. This allows us to remove the trampoline cache from
theCompilertype, and move one step closer to makingCompiler
threadsafe for usage across multiple threads.Note that as one small caveat the
Func::wrap*family of functions
don't need to generate a trampoline at runtime, they actually generate
the trampoline at compile time which gets passed in.Also in addition to shuffling a lot of code around this fixes one minor
bug found incode_memory.rs, whereself.positionwas loaded before
allocation, but the allocation may push a new chunk which would cause
self.positionto be zero instead.
sunfishcode submitted PR Review.
alexcrichton updated PR #957 from local-trampolines to master:
The
wasmtimecrate supports calling arbitrary function signatures in
wasm code, and to do this it generates "trampoline functions" which have
a known ABI that then internally convert to a particular signature's ABI
and call it. These trampoline functions are currently generated
on-the-fly and are cached in the globalStorestructure. This,
however, is suboptimal for a few reasons:
Due to how code memory is managed each trampoline resides in its own
64kb allocation of memory. This means if you have N trampolines you're
using N * 64kb of memory, which is quite a lot of overhead!Trampolines are never free'd, even if the referencing module goes
away. This is similar to #925.Trampolines are a source of shared state which prevents
Storefrom
being easily thread safe.This commit refactors how trampolines are managed inside of the
wasmtimecrate and jit/runtime internals. All trampolines are now
allocated in the same pass ofCodeMemorythat the main module is
allocated into. A trampoline is generated per-signature in a module as
well, instead of per-function. This cache of trampolines is stored
directly inside of anInstance. Trampolines are stored based on
VMSharedSignatureIndexso they can be looked up from the internals of
theExportFunctionvalue.The
FuncAPI has been updated with various bits and pieces to ensure
the right trampolines are registered in the right places. Overall this
should ensure that all trampolines necessary are generated up-front
rather than lazily. This allows us to remove the trampoline cache from
theCompilertype, and move one step closer to makingCompiler
threadsafe for usage across multiple threads.Note that as one small caveat the
Func::wrap*family of functions
don't need to generate a trampoline at runtime, they actually generate
the trampoline at compile time which gets passed in.Also in addition to shuffling a lot of code around this fixes one minor
bug found incode_memory.rs, whereself.positionwas loaded before
allocation, but the allocation may push a new chunk which would cause
self.positionto be zero instead.
alexcrichton updated PR #957 from local-trampolines to master:
The
wasmtimecrate supports calling arbitrary function signatures in
wasm code, and to do this it generates "trampoline functions" which have
a known ABI that then internally convert to a particular signature's ABI
and call it. These trampoline functions are currently generated
on-the-fly and are cached in the globalStorestructure. This,
however, is suboptimal for a few reasons:
Due to how code memory is managed each trampoline resides in its own
64kb allocation of memory. This means if you have N trampolines you're
using N * 64kb of memory, which is quite a lot of overhead!Trampolines are never free'd, even if the referencing module goes
away. This is similar to #925.Trampolines are a source of shared state which prevents
Storefrom
being easily thread safe.This commit refactors how trampolines are managed inside of the
wasmtimecrate and jit/runtime internals. All trampolines are now
allocated in the same pass ofCodeMemorythat the main module is
allocated into. A trampoline is generated per-signature in a module as
well, instead of per-function. This cache of trampolines is stored
directly inside of anInstance. Trampolines are stored based on
VMSharedSignatureIndexso they can be looked up from the internals of
theExportFunctionvalue.The
FuncAPI has been updated with various bits and pieces to ensure
the right trampolines are registered in the right places. Overall this
should ensure that all trampolines necessary are generated up-front
rather than lazily. This allows us to remove the trampoline cache from
theCompilertype, and move one step closer to makingCompiler
threadsafe for usage across multiple threads.Note that as one small caveat the
Func::wrap*family of functions
don't need to generate a trampoline at runtime, they actually generate
the trampoline at compile time which gets passed in.Also in addition to shuffling a lot of code around this fixes one minor
bug found incode_memory.rs, whereself.positionwas loaded before
allocation, but the allocation may push a new chunk which would cause
self.positionto be zero instead.
alexcrichton updated PR #957 from local-trampolines to master:
The
wasmtimecrate supports calling arbitrary function signatures in
wasm code, and to do this it generates "trampoline functions" which have
a known ABI that then internally convert to a particular signature's ABI
and call it. These trampoline functions are currently generated
on-the-fly and are cached in the globalStorestructure. This,
however, is suboptimal for a few reasons:
Due to how code memory is managed each trampoline resides in its own
64kb allocation of memory. This means if you have N trampolines you're
using N * 64kb of memory, which is quite a lot of overhead!Trampolines are never free'd, even if the referencing module goes
away. This is similar to #925.Trampolines are a source of shared state which prevents
Storefrom
being easily thread safe.This commit refactors how trampolines are managed inside of the
wasmtimecrate and jit/runtime internals. All trampolines are now
allocated in the same pass ofCodeMemorythat the main module is
allocated into. A trampoline is generated per-signature in a module as
well, instead of per-function. This cache of trampolines is stored
directly inside of anInstance. Trampolines are stored based on
VMSharedSignatureIndexso they can be looked up from the internals of
theExportFunctionvalue.The
FuncAPI has been updated with various bits and pieces to ensure
the right trampolines are registered in the right places. Overall this
should ensure that all trampolines necessary are generated up-front
rather than lazily. This allows us to remove the trampoline cache from
theCompilertype, and move one step closer to makingCompiler
threadsafe for usage across multiple threads.Note that as one small caveat the
Func::wrap*family of functions
don't need to generate a trampoline at runtime, they actually generate
the trampoline at compile time which gets passed in.Also in addition to shuffling a lot of code around this fixes one minor
bug found incode_memory.rs, whereself.positionwas loaded before
allocation, but the allocation may push a new chunk which would cause
self.positionto be zero instead.
alexcrichton merged PR #957.
Last updated: Dec 06 2025 at 06:05 UTC