Skip to content

Commit 5e7d9da

Browse files
authored
Check if an object is in our heap before using VM map during counting live bytes (#1289)
This PR fixes a bug in `increase_live_bytes`. If an object in the VM space is scanned, the method will be called with an object reference into the VM space, which may not be in our heap range. Then we get a space descriptor from the VM map, and we will see panics in the following code. https://github.com/mmtk/mmtk-core/blob/129362d4f39a1191562d276c42f5b03e52aa287a/src/util/heap/layout/map64.rs#L209 https://github.com/mmtk/mmtk-core/blob/129362d4f39a1191562d276c42f5b03e52aa287a/src/util/heap/layout/map32.rs#L258 This PR works around the problem by checking if the object is in our heap range first.
1 parent ce0ba41 commit 5e7d9da

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

src/scheduler/worker.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,17 @@ impl<VM: VMBinding> GCWorkerShared<VM> {
7171
let bytes = VM::VMObjectModel::get_current_size(object);
7272
// Get the space index from descriptor
7373
let space_descriptor = VM_MAP.get_descriptor_for_address(object.to_raw_address());
74-
let space_index = space_descriptor.get_index();
75-
debug_assert!(
76-
space_index < MAX_SPACES,
77-
"Space index {} is not in the range of [0, {})",
78-
space_index,
79-
MAX_SPACES
80-
);
81-
// Accumulate the live bytes for the index
82-
live_bytes_per_space[space_index] += bytes;
74+
if space_descriptor != crate::util::heap::space_descriptor::SpaceDescriptor::UNINITIALIZED {
75+
let space_index = space_descriptor.get_index();
76+
debug_assert!(
77+
space_index < MAX_SPACES,
78+
"Space index {} is not in the range of [0, {})",
79+
space_index,
80+
MAX_SPACES
81+
);
82+
// Accumulate the live bytes for the index
83+
live_bytes_per_space[space_index] += bytes;
84+
}
8385
}
8486
}
8587

src/util/heap/layout/map.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ pub trait VMMap: Sync {
8181

8282
fn is_finalized(&self) -> bool;
8383

84+
/// Get the space descriptor for the given address. Return SpaceDescriptor::UNINITIALIZED if the
85+
/// address is not within the MMTk heap range, or not within MMTk spaces.
8486
fn get_descriptor_for_address(&self, address: Address) -> SpaceDescriptor;
8587

8688
fn add_to_cumulative_committed_pages(&self, pages: usize);

src/util/heap/layout/map32.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,10 @@ impl VMMap for Map32 {
255255

256256
fn get_descriptor_for_address(&self, address: Address) -> SpaceDescriptor {
257257
let index = address.chunk_index();
258-
self.descriptor_map[index]
258+
self.descriptor_map
259+
.get(index)
260+
.copied()
261+
.unwrap_or(SpaceDescriptor::UNINITIALIZED)
259262
}
260263

261264
fn add_to_cumulative_committed_pages(&self, pages: usize) {

src/util/heap/layout/map64.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,11 @@ impl VMMap for Map64 {
206206
}
207207

208208
fn get_descriptor_for_address(&self, address: Address) -> SpaceDescriptor {
209-
let index = Self::space_index(address).unwrap();
210-
self.inner().descriptor_map[index]
209+
if let Some(index) = Self::space_index(address) {
210+
self.inner().descriptor_map[index]
211+
} else {
212+
SpaceDescriptor::UNINITIALIZED
213+
}
211214
}
212215

213216
fn add_to_cumulative_committed_pages(&self, pages: usize) {

0 commit comments

Comments
 (0)