-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial WIP work * refactor InstanceStack::push Also remove faulty debug_assert. * fix after merge * add TopVec type * add missing import * use TopVec in InstanceStack * add InstanceStack::reset * rename IndexedInstance -> InstanceAndHeight * rename field: calls -> frames * apply clippy suggestion * improve docs * rename index -> height * return new Instance in CallStack::pop * remove unused TopVec methods * add inline annotations * remove no longer needed import * improve docs * rename top -> last as in Rust's Vec * improve docs * remove commented out code * fix typo * rename TopVec -> HeadVec * refactor CallStack to no longer use InstanceStack This also fixes a bug with instance reuse of tail calls when the call stack was temporarily empty while merging the tail call frames. * add some inline annotations * put cached memory bytes directly into Executor This has fewer indirections when using the default linear memory. Local perf measurements indicated up to 20% improvements for memory-intense workloads. * fix doc link and cleanup code * fix code from merge * add StackOffsets abstraction * add changed_instance field to CallFrame This allows to minimize overhead when returning from a CallFrame that did not adjust the Instance. * add inline annotations * add missing docs to default_memory method * add CachedMemory type * add safety comments * replace InstanceCache with finer grained caches We now have a single MemoryCache and a single GlobalCache each caching the linear memory and global variable at index 0 respectively. The linear memory at index 0 makes sense to cache since Wasmi does not yet support multi-memory. The global at index 0 makes sense since it usually serves as the shadow stack pointer. * add hints to global variable executors * define From for bytecode index type to convert to u32 * use macro to generate get_entity funcs * inline(always) for instance getter * fix doc links * apply clippy suggestions * apply rustfmt * use old docs for memory field * remove invalid code after merge * remove inline annotations not present before this PR * replace some #[inline(always)] with #[inline] * move HeadVec to wasmi_collections * use Option::replace where applicable * add basic derives to HeadVec * swap field ordering in InstanceAndHeight * remove InstanceAndHeight due to redundant information The CallFrame::changed_instance (bool) field already contains all the necessary information for when to pop an Instance.
- Loading branch information
Showing
9 changed files
with
184 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use core::mem; | ||
use std::vec::Vec; | ||
|
||
/// A [`Vec`]-like data structure with fast access to the last item. | ||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] | ||
pub struct HeadVec<T> { | ||
/// The top (or last) item in the [`HeadVec`]. | ||
head: Option<T>, | ||
/// The rest of the items in the [`HeadVec`] excluding the last item. | ||
rest: Vec<T>, | ||
} | ||
|
||
impl<T> Default for HeadVec<T> { | ||
#[inline] | ||
fn default() -> Self { | ||
Self { | ||
head: None, | ||
rest: Vec::new(), | ||
} | ||
} | ||
} | ||
|
||
impl<T> HeadVec<T> { | ||
/// Removes all items from the [`HeadVec`]. | ||
#[inline] | ||
pub fn clear(&mut self) { | ||
self.head = None; | ||
self.rest.clear(); | ||
} | ||
|
||
/// Returns the number of items stored in the [`HeadVec`]. | ||
#[inline] | ||
pub fn len(&self) -> usize { | ||
match self.head { | ||
Some(_) => 1 + self.rest.len(), | ||
None => 0, | ||
} | ||
} | ||
|
||
/// Returns `true` if the [`HeadVec`] contains no items. | ||
#[inline] | ||
pub fn is_empty(&self) -> bool { | ||
self.len() == 0 | ||
} | ||
|
||
/// Returns a shared reference to the last item in the [`HeadVec`] if any. | ||
/// | ||
/// Returns `None` if the [`HeadVec`] is empty. | ||
#[inline] | ||
pub fn last(&self) -> Option<&T> { | ||
self.head.as_ref() | ||
} | ||
|
||
/// Returns an exclusive reference to the last item in the [`HeadVec`] if any. | ||
/// | ||
/// Returns `None` if the [`HeadVec`] is empty. | ||
#[inline] | ||
pub fn last_mut(&mut self) -> Option<&mut T> { | ||
self.head.as_mut() | ||
} | ||
|
||
/// Pushes a new `value` onto the [`HeadVec`]. | ||
#[inline] | ||
pub fn push(&mut self, value: T) { | ||
let prev_head = self.head.replace(value); | ||
if let Some(prev_head) = prev_head { | ||
self.rest.push(prev_head); | ||
} | ||
} | ||
|
||
/// Pops the last `value` from the [`HeadVec`] if any. | ||
#[inline] | ||
pub fn pop(&mut self) -> Option<T> { | ||
let new_top = self.rest.pop(); | ||
mem::replace(&mut self.head, new_top) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.