ruby/gc
Alan Wu 92b218fbc3 YJIT: ZJIT: Allow both JITs in the same build
This commit allows building YJIT and ZJIT simultaneously, a "combo
build". Previously, `./configure --enable-yjit --enable-zjit` failed. At
runtime, though, only one of the two can be enabled at a time.

Add a root Cargo workspace that contains both the yjit and zjit crate.
The common Rust build integration mechanisms are factored out into
defs/jit.mk.

Combo YJIT+ZJIT dev builds are supported; if either JIT uses
`--enable-*=dev`, both of them are built in dev mode.

The combo build requires Cargo, but building one JIT at a time with only
rustc in release build remains supported.
2025-05-15 00:39:03 +09:00
..
default Only clear Ractor cache in child 2025-05-09 16:15:54 -07:00
mmtk YJIT: ZJIT: Allow both JITs in the same build 2025-05-15 00:39:03 +09:00
extconf_base.rb Simplify gc/mmtk/extconf.rb 2025-01-14 10:21:57 -05:00
gc.h Rename id_to_obj_tbl -> id2ref_tbl 2025-05-14 11:41:14 +02:00
gc_impl.h Move object_id in object fields. 2025-05-08 07:58:05 +02:00
README.md [DOC] Use install-modular-gc in gc/README.md 2025-03-25 08:49:31 -04:00

Ruby's Garbage Collectors

This directory contains implementations for Ruby's garbage collector (GC). The GC implementations use the Modular GC API to interact with Ruby. For more details about this API, see the Modular GC API section.

Two GC implementations are included in Ruby:

  • Default: The GC implementation that is used by default in Ruby. This GC is stable and production ready. The implementation uses a mark-sweep-compact algorithm.
  • MMTk: An experimental implementation using the MMTk framework. The code lives in the ruby/mmtk repository and is synchronized here. MMTk provides a wide variety of GC algorithms to choose from. For usage instructions and current progress, refer to the ruby/mmtk repository.

Building guide

Tip

If you are not sure how to build Ruby, follow the Building Ruby guide.

Important

Ruby's modular GC feature is experimental and subject to change. There may be bugs or performance impacts. Use at your own risk.

  1. Configure Ruby with the --with-modular-gc=<dir> option, where dir is the directory you want to place the built GC libraries into.
  2. Build Ruby as usual.
  3. Build your desired GC implementation with make install-modular-gc MODULAR_GC=<impl>. This will build the GC implementation and place the built library into the dir specified in step 1. impl can be one of:
    • default: The default GC that Ruby ships with.
    • mmtk: The GC that uses MMTk as the back-end. See Ruby-specific details in the ruby/mmtk repository.
  4. Run your desired GC implementation by setting the RUBY_GC_LIBRARY=<lib> environment variable, where lib could be default, mmtk, or your own implementation (as long as you place it in the dir specified in step 1).

Modular GC API

Warning

The Modular GC API is experimental and subject to change without notice.

GC implementations interact with Ruby via the Modular GC API. All implementations must provide the functions in gc/gc_impl.h for Ruby to hook into. GC implementations can use any public C API in Ruby, along with additional APIs defined in gc/gc.h.

Additionally, create an extconf.rb file to build the GC library. This file must use gc/extconf_base.rb and the create_gc_makefile method.