Skip to content

Reintorduce gc_disable/enable API#1457

Draft
qinsoon wants to merge 2 commits into
mmtk:masterfrom
qinsoon:reintroduce-gc-disable-api
Draft

Reintorduce gc_disable/enable API#1457
qinsoon wants to merge 2 commits into
mmtk:masterfrom
qinsoon:reintroduce-gc-disable-api

Conversation

@qinsoon

@qinsoon qinsoon commented Mar 11, 2026

Copy link
Copy Markdown
Member

No description provided.

…g gap

Bindings previously had to implement VMCollection::is_collection_enabled()
and synchronize enabling/disabling collection across threads themselves.
Replace that callback with disable_collection()/enable_collection()/
is_collection_enabled() on MMTK, backed by a nestable, lock-guarded
counter in GCTrigger so a GC is never requested while collection is
disabled.

Also add wait_for_no_collection_in_progress(), which blocks until no GC
is pending, mid-pause, or (for concurrent plans, via the existing
ConcurrentPlan::concurrent_work_in_progress() hook) concurrently
marking. Bindings that need a hard guarantee that no GC touches memory
during some unsafe window (e.g. adopting a foreign thread, or recovering
from a fatal signal) should call disable_collection() followed by
wait_for_no_collection_in_progress(), the MMTk-native equivalent of
waiting for an in-flight GC to finish. Without it, a collection that is
already mid-cycle when collection is disabled is not affected until it
completes, and for concurrent plans that includes the whole concurrent
marking phase, not just a stop-the-world pause.

Co-authored-by: Claude <noreply@anthropic.com>
@qinsoon qinsoon force-pushed the reintroduce-gc-disable-api branch from 79b14b1 to 3180d70 Compare July 8, 2026 01:02
Poll with a yield instead of a fixed sleep between checks, so the
calling thread gives up its timeslice without imposing a fixed latency
floor on how quickly it notices the collection has finished.

Add a regression test: one thread triggers a GC and blocks in
block_for_gc (simulating an in-progress collection), while a second
thread calls disable_collection() followed by
wait_for_no_collection_in_progress() and must remain blocked until the
first thread's GC finishes.

Also fix two benchmarks (mock_bench/alloc.rs,
mock_bench/internal_pointer.rs) that configured the now-removed
MockVM::is_collection_enabled field to keep GC out of the way; they
now call memory_manager::disable_collection() directly.

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant