mirror of
https://github.com/fluencelabs/wasmer
synced 2025-04-21 16:32:13 +00:00
Auto-release trampolines.
This commit is contained in:
parent
b7c9c1843a
commit
80f824e708
@ -360,11 +360,25 @@ impl<'a> ErasedFunc<'a> {
|
|||||||
(signature.params().len() + 1) as u32, // +vmctx
|
(signature.params().len() + 1) as u32, // +vmctx
|
||||||
);
|
);
|
||||||
let ptr = builder
|
let ptr = builder
|
||||||
.append_global()
|
.insert_global()
|
||||||
.expect("cannot bump-allocate global trampoline memory");
|
.expect("cannot bump-allocate global trampoline memory");
|
||||||
|
|
||||||
|
struct AutoRelease {
|
||||||
|
ptr: NonNull<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for AutoRelease {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
TrampolineBufferBuilder::remove_global(self.ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Kind for AutoRelease {}
|
||||||
|
|
||||||
ErasedFunc {
|
ErasedFunc {
|
||||||
inner: Box::new(Host(())),
|
inner: Box::new(AutoRelease { ptr }),
|
||||||
func: ptr.cast::<vm::Func>(),
|
func: ptr.cast::<vm::Func>(),
|
||||||
func_env: None,
|
func_env: None,
|
||||||
vmctx: ptr::null_mut(),
|
vmctx: ptr::null_mut(),
|
||||||
@ -941,4 +955,18 @@ mod tests {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_many_new_polymorphics() {
|
||||||
|
use crate::types::{FuncSig, Type};
|
||||||
|
|
||||||
|
// Check that generating a lot (1M) of polymorphic functions doesn't use up the executable buffer.
|
||||||
|
for _ in 0..1000000 {
|
||||||
|
let arglist = vec![Type::I32; 100];
|
||||||
|
ErasedFunc::new_polymorphic(
|
||||||
|
Arc::new(FuncSig::new(arglist, vec![Type::I32])),
|
||||||
|
|_, _| unreachable!(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user