Move trap information to a section of the compiled image (#3241)
This commit moves the `traps` field of `FunctionInfo` into a section of the compiled artifact produced by Cranelift. This section is quite large and when previously encoded/decoded with `bincode` this can take quite some time to process. Traps are expected to be relatively rare and it's not necessarily the right tradeoff to spend so much time serializing/deserializing this data, so this commit offloads the section into a custom-encoded binary format located elsewhere in the compiled image. This is similar to #3240 in its goal which is to move very large pieces of metadata to their own sections to avoid decoding anything when we load a precompiled modules. This also has a small benefit that it's slightly more efficient storage for the trap information too, but that's a negligible benefit. This is part of #3230 to make loading modules fast.
This commit is contained in:
@@ -18,7 +18,7 @@ use thiserror::Error;
|
||||
use wasmtime_environ::{
|
||||
CompileError, DefinedFuncIndex, FunctionInfo, InstanceSignature, InstanceTypeIndex, Module,
|
||||
ModuleSignature, ModuleTranslation, ModuleTypeIndex, PrimaryMap, SignatureIndex,
|
||||
StackMapInformation, Tunables, WasmFuncType, ELF_WASMTIME_ADDRMAP,
|
||||
StackMapInformation, Tunables, WasmFuncType, ELF_WASMTIME_ADDRMAP, ELF_WASMTIME_TRAPS,
|
||||
};
|
||||
use wasmtime_runtime::{GdbJitImageRegistration, InstantiationError, VMFunctionBody, VMTrampoline};
|
||||
|
||||
@@ -269,6 +269,7 @@ impl ModuleCode {
|
||||
pub struct CompiledModule {
|
||||
wasm_data: Range<usize>,
|
||||
address_map_data: Range<usize>,
|
||||
trap_data: Range<usize>,
|
||||
artifacts: CompilationArtifacts,
|
||||
module: Arc<Module>,
|
||||
funcs: PrimaryMap<DefinedFuncIndex, FunctionInfo>,
|
||||
@@ -315,6 +316,7 @@ impl CompiledModule {
|
||||
let funcs = info.funcs;
|
||||
let wasm_data = subslice_range(section(ELF_WASM_DATA)?, &artifacts.obj);
|
||||
let address_map_data = subslice_range(section(ELF_WASMTIME_ADDRMAP)?, &artifacts.obj);
|
||||
let trap_data = subslice_range(section(ELF_WASMTIME_TRAPS)?, &artifacts.obj);
|
||||
|
||||
// Allocate all of the compiled functions into executable memory,
|
||||
// copying over their contents.
|
||||
@@ -337,6 +339,7 @@ impl CompiledModule {
|
||||
artifacts,
|
||||
wasm_data,
|
||||
address_map_data,
|
||||
trap_data,
|
||||
code: Arc::new(ModuleCode {
|
||||
range: (start, end),
|
||||
code_memory,
|
||||
@@ -393,6 +396,13 @@ impl CompiledModule {
|
||||
&self.artifacts.obj[self.address_map_data.clone()]
|
||||
}
|
||||
|
||||
/// Returns the encoded trap information for this compiled image.
|
||||
///
|
||||
/// For more information see `wasmtime_environ::trap_encoding`.
|
||||
pub fn trap_data(&self) -> &[u8] {
|
||||
&self.artifacts.obj[self.trap_data.clone()]
|
||||
}
|
||||
|
||||
/// Return a reference-counting pointer to a module.
|
||||
pub fn module(&self) -> &Arc<Module> {
|
||||
&self.module
|
||||
|
||||
Reference in New Issue
Block a user