Skip to content

Commit e80a30c

Browse files
authored
Don't create a pool of GC heaps if it's disabled (bytecodealliance#13139)
A fuzz test case is failing right now on `main` where the validation in `Config` only checks tunables if a collector is enabled, but the GC pool creation unconditionally check the tunables. This also felt a bit odd creating a GC heap pool when the GC itself is disabled, so the code is refactored to avoid creating a GC heap pool at all when a collector is disabled.
1 parent 495df13 commit e80a30c

File tree

1 file changed

+16
-8
lines changed
  • crates/wasmtime/src/runtime/vm/instance/allocator

1 file changed

+16
-8
lines changed

crates/wasmtime/src/runtime/vm/instance/allocator/pooling.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ pub struct PoolingInstanceAllocator {
319319
live_tables: AtomicUsize,
320320

321321
#[cfg(feature = "gc")]
322-
gc_heaps: GcHeapPool,
322+
gc_heaps: Option<GcHeapPool>,
323323
#[cfg(feature = "gc")]
324324
live_gc_heaps: AtomicUsize,
325325

@@ -356,8 +356,8 @@ impl Drop for PoolingInstanceAllocator {
356356
debug_assert!(self.tables.is_empty());
357357

358358
#[cfg(feature = "gc")]
359-
{
360-
debug_assert!(self.gc_heaps.is_empty());
359+
if let Some(gc_heaps) = &self.gc_heaps {
360+
debug_assert!(gc_heaps.is_empty());
361361
debug_assert_eq!(self.live_gc_heaps.load(Ordering::Acquire), 0);
362362
}
363363

@@ -383,7 +383,11 @@ impl PoolingInstanceAllocator {
383383
tables: TablePool::new(config)?,
384384
live_tables: AtomicUsize::new(0),
385385
#[cfg(feature = "gc")]
386-
gc_heaps: GcHeapPool::new(config, tunables)?,
386+
gc_heaps: if tunables.collector.is_some() {
387+
Some(GcHeapPool::new(config, tunables)?)
388+
} else {
389+
None
390+
},
387391
#[cfg(feature = "gc")]
388392
live_gc_heaps: AtomicUsize::new(0),
389393
#[cfg(feature = "async")]
@@ -882,9 +886,12 @@ unsafe impl InstanceAllocator for PoolingInstanceAllocator {
882886
memory_alloc_index: MemoryAllocationIndex,
883887
memory: Memory,
884888
) -> Result<(GcHeapAllocationIndex, Box<dyn GcHeap>)> {
885-
let ret = self
886-
.gc_heaps
887-
.allocate(engine, gc_runtime, memory_alloc_index, memory)?;
889+
let ret = self.gc_heaps.as_ref().unwrap().allocate(
890+
engine,
891+
gc_runtime,
892+
memory_alloc_index,
893+
memory,
894+
)?;
888895
self.live_gc_heaps.fetch_add(1, Ordering::Relaxed);
889896
Ok(ret)
890897
}
@@ -895,8 +902,9 @@ unsafe impl InstanceAllocator for PoolingInstanceAllocator {
895902
allocation_index: GcHeapAllocationIndex,
896903
gc_heap: Box<dyn GcHeap>,
897904
) -> (MemoryAllocationIndex, Memory) {
905+
let gc_heaps = self.gc_heaps.as_ref().unwrap();
898906
self.live_gc_heaps.fetch_sub(1, Ordering::Relaxed);
899-
self.gc_heaps.deallocate(allocation_index, gc_heap)
907+
gc_heaps.deallocate(allocation_index, gc_heap)
900908
}
901909

902910
fn as_pooling(&self) -> Option<&PoolingInstanceAllocator> {

0 commit comments

Comments
 (0)