Allow instance allocators control over module compilation.

This commit introduces two new methods on `InstanceAllocator`:

* `validate_module` - this method is used to validate a module after
  translation but before compilation. It will be used for the upcoming pooling
  allocator to ensure a module being compiled adheres to the limits of the
  allocator.

* `adjust_tunables` - this method is used to adjust the `Tunables` given the
  JIT compiler.  The pooling allocator will use this to force all memories to
  be static during compilation.
This commit is contained in:
Peter Huene
2020-12-07 22:12:33 -08:00
parent b58afbf849
commit c8871ee1e6
9 changed files with 112 additions and 45 deletions

View File

@@ -764,7 +764,9 @@ impl Config {
pub(crate) fn build_compiler(&self) -> Compiler {
let isa = self.target_isa();
Compiler::new(isa, self.strategy, self.tunables.clone(), self.features)
let mut tunables = self.tunables.clone();
self.instance_allocator().adjust_tunables(&mut tunables);
Compiler::new(isa, self.strategy, tunables, self.features)
}
pub(crate) fn instance_allocator(&self) -> &dyn InstanceAllocator {

View File

@@ -307,15 +307,22 @@ impl Module {
/// # }
/// ```
pub fn from_binary(engine: &Engine, binary: &[u8]) -> Result<Module> {
// Check with the instance allocator to see if the given module is supported
let allocator = engine.config().instance_allocator();
#[cfg(feature = "cache")]
let (main_module, artifacts, types) =
ModuleCacheEntry::new("wasmtime", engine.cache_config())
.get_data((engine.compiler(), binary), |(compiler, binary)| {
CompilationArtifacts::build(compiler, binary)
})?;
let (main_module, artifacts, types) = ModuleCacheEntry::new(
"wasmtime",
engine.cache_config(),
)
.get_data((engine.compiler(), binary), |(compiler, binary)| {
CompilationArtifacts::build(compiler, binary, |m| allocator.validate_module(m))
})?;
#[cfg(not(feature = "cache"))]
let (main_module, artifacts, types) =
CompilationArtifacts::build(engine.compiler(), binary)?;
CompilationArtifacts::build(engine.compiler(), binary, |m| {
allocator.validate_module(m)
})?;
let mut modules = CompiledModule::from_artifacts_list(
artifacts,