mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-21 04:31:33 +00:00
Get caching working again
This commit is contained in:
@ -1,20 +1,14 @@
|
||||
use crate::relocation::{ExternalRelocation, TrapSink};
|
||||
|
||||
use hashbrown::HashMap;
|
||||
use std::sync::Arc;
|
||||
use wasmer_runtime_core::{
|
||||
backend::{
|
||||
sys::Memory,
|
||||
CacheGen,
|
||||
},
|
||||
backend::{sys::Memory, CacheGen},
|
||||
cache::{Cache, Error},
|
||||
module::{ModuleInfo, ModuleInner},
|
||||
structures::Map,
|
||||
types::{LocalFuncIndex, SigIndex},
|
||||
};
|
||||
use std::{
|
||||
sync::Arc,
|
||||
cell::UnsafeCell,
|
||||
};
|
||||
|
||||
use serde_bench::{deserialize, serialize};
|
||||
|
||||
@ -25,14 +19,29 @@ pub struct CacheGenerator {
|
||||
|
||||
impl CacheGenerator {
|
||||
pub fn new(backend_cache: BackendCache, memory: Arc<Memory>) -> Self {
|
||||
Self { backend_cache, memory }
|
||||
Self {
|
||||
backend_cache,
|
||||
memory,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl CacheGen for CacheGenerator {
|
||||
fn generate_cache(&self, module: &ModuleInner) -> Result<(Box<ModuleInfo>, Box<[u8]>, Arc<Memory>), Error> {
|
||||
fn generate_cache(
|
||||
&self,
|
||||
module: &ModuleInner,
|
||||
) -> Result<(Box<ModuleInfo>, Box<[u8]>, Memory), Error> {
|
||||
let info = Box::new(module.info.clone());
|
||||
Ok((info, self.backend_cache.into_backend_data()?.into_boxed_slice(), Arc::clone(&self.memory)))
|
||||
|
||||
// Clone the memory to a new location. This could take a long time,
|
||||
// depending on the throughput of your memcpy implementation.
|
||||
let compiled_code = (*self.memory).clone();
|
||||
|
||||
Ok((
|
||||
info,
|
||||
self.backend_cache.into_backend_data()?.into_boxed_slice(),
|
||||
compiled_code,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,18 +62,10 @@ pub struct BackendCache {
|
||||
|
||||
impl BackendCache {
|
||||
pub fn from_cache(cache: Cache) -> Result<(ModuleInfo, Memory, Self), Error> {
|
||||
let (info, backend_data, compiled_code_arc) = cache.consume();
|
||||
let (info, backend_data, compiled_code) = cache.consume();
|
||||
|
||||
// If this is the only references to this arc, move the memory out.
|
||||
// else, clone the memory to a new location. This could take a long time,
|
||||
// depending on the throughput of your memcpy implementation.
|
||||
let compiled_code = match Arc::try_unwrap(compiled_code_arc) {
|
||||
Ok(code) => code,
|
||||
Err(arc) => (*arc).clone(),
|
||||
};
|
||||
|
||||
let backend_cache = deserialize(&backend_data)
|
||||
.map_err(|e| Error::DeserializeError(e.to_string()))?;
|
||||
let backend_cache =
|
||||
deserialize(&backend_data).map_err(|e| Error::DeserializeError(e.to_string()))?;
|
||||
|
||||
Ok((info, compiled_code, backend_cache))
|
||||
}
|
||||
|
Reference in New Issue
Block a user