diff --git a/src/scheduler/worker.rs b/src/scheduler/worker.rs index cc1b28e23b..40a54e4046 100644 --- a/src/scheduler/worker.rs +++ b/src/scheduler/worker.rs @@ -71,15 +71,17 @@ impl GCWorkerShared { let bytes = VM::VMObjectModel::get_current_size(object); // Get the space index from descriptor let space_descriptor = VM_MAP.get_descriptor_for_address(object.to_raw_address()); - let space_index = space_descriptor.get_index(); - debug_assert!( - space_index < MAX_SPACES, - "Space index {} is not in the range of [0, {})", - space_index, - MAX_SPACES - ); - // Accumulate the live bytes for the index - live_bytes_per_space[space_index] += bytes; + if space_descriptor != crate::util::heap::space_descriptor::SpaceDescriptor::UNINITIALIZED { + let space_index = space_descriptor.get_index(); + debug_assert!( + space_index < MAX_SPACES, + "Space index {} is not in the range of [0, {})", + space_index, + MAX_SPACES + ); + // Accumulate the live bytes for the index + live_bytes_per_space[space_index] += bytes; + } } } diff --git a/src/util/heap/layout/map.rs b/src/util/heap/layout/map.rs index afb336cf61..ccb46be19b 100644 --- a/src/util/heap/layout/map.rs +++ b/src/util/heap/layout/map.rs @@ -81,6 +81,8 @@ pub trait VMMap: Sync { fn is_finalized(&self) -> bool; + /// Get the space descriptor for the given address. Return SpaceDescriptor::UNINITIALIZED if the + /// address is not within the MMTk heap range, or not within MMTk spaces. fn get_descriptor_for_address(&self, address: Address) -> SpaceDescriptor; fn add_to_cumulative_committed_pages(&self, pages: usize); diff --git a/src/util/heap/layout/map32.rs b/src/util/heap/layout/map32.rs index cf209f1186..67a27d7a51 100644 --- a/src/util/heap/layout/map32.rs +++ b/src/util/heap/layout/map32.rs @@ -255,7 +255,10 @@ impl VMMap for Map32 { fn get_descriptor_for_address(&self, address: Address) -> SpaceDescriptor { let index = address.chunk_index(); - self.descriptor_map[index] + self.descriptor_map + .get(index) + .copied() + .unwrap_or(SpaceDescriptor::UNINITIALIZED) } fn add_to_cumulative_committed_pages(&self, pages: usize) { diff --git a/src/util/heap/layout/map64.rs b/src/util/heap/layout/map64.rs index 08de2cde37..609cd05c7c 100644 --- a/src/util/heap/layout/map64.rs +++ b/src/util/heap/layout/map64.rs @@ -206,8 +206,11 @@ impl VMMap for Map64 { } fn get_descriptor_for_address(&self, address: Address) -> SpaceDescriptor { - let index = Self::space_index(address).unwrap(); - self.inner().descriptor_map[index] + if let Some(index) = Self::space_index(address) { + self.inner().descriptor_map[index] + } else { + SpaceDescriptor::UNINITIALIZED + } } fn add_to_cumulative_committed_pages(&self, pages: usize) {