1 use crate::prelude::*; 2 use serde_derive::{Deserialize, Serialize}; 3 4 /// A map for determining where live GC references live in a stack frame. 5 /// 6 /// Note that this is currently primarily documented as cranelift's 7 /// `binemit::StackMap`, so for detailed documentation about this please read 8 /// the docs over there. 9 #[derive(Debug, Serialize, Deserialize)] 10 pub struct StackMap { 11 bits: Box<[u32]>, 12 mapped_words: u32, 13 } 14 15 impl StackMap { 16 /// Creates a new `StackMap`, typically from a preexisting 17 /// `binemit::StackMap`. 18 pub fn new(mapped_words: u32, bits: impl Iterator<Item = u32>) -> StackMap { 19 StackMap { 20 bits: bits.collect(), 21 mapped_words, 22 } 23 } 24 25 /// Returns a specified bit. 26 pub fn get_bit(&self, bit_index: usize) -> bool { 27 assert!(bit_index < 32 * self.bits.len()); 28 let word_index = bit_index / 32; 29 let word_offset = bit_index % 32; 30 (self.bits[word_index] & (1 << word_offset)) != 0 31 } 32 33 /// Returns the number of words represented by this stack map. 34 pub fn mapped_words(&self) -> u32 { 35 self.mapped_words 36 } 37 } 38