Skip to content

Conversation

eightbitraptor
Copy link
Contributor

@eightbitraptor eightbitraptor commented Oct 10, 2024

This PR adds information about the currently loaded GC module to RUBY_DESCRIPTION and hence the output of ruby -v when --with-shared-gc is enabled at compile time.

Additionally, when a shared GC module is loaded with RUBY_GC_LIBRARY the reported name of the GC library will also be displayed in RUBY_DESCRIPTION.

This PR also introduces a readonly GC.config key called implementation to expose this information to Ruby. It can be in three states:

  1. Ruby compiled without shared GC support. GC.config[:implementation] => "default"
  2. Ruby compiled with shared GC support but no GC module loaded. GC.config[:implementation] => "default"
  3. Ruby compiled with shared GC support and an active GC module loaded using RUBY_GC_LIBRARY: GC.config[:implementation] => "gc_name"

The intention of this PR is to give users of the modular GC system, GC developers, and Ruby users better tooling to introspect the state of the currently CG. It will also make writing tests that work accurately with different GC configurations easier.

@eightbitraptor eightbitraptor force-pushed the mvh-active-gc-name branch 2 times, most recently from e98cc3d to 8b616ae Compare October 10, 2024 20:25

This comment has been minimized.

@eightbitraptor eightbitraptor force-pushed the mvh-active-gc-name branch 2 times, most recently from f4e9902 to 13ea2f1 Compare November 7, 2024 14:26
@eightbitraptor eightbitraptor force-pushed the mvh-active-gc-name branch 3 times, most recently from e63db7e to a4d9c2b Compare November 11, 2024 13:56
@eightbitraptor eightbitraptor force-pushed the mvh-active-gc-name branch 4 times, most recently from b0f6b94 to 36eab5c Compare November 13, 2024 22:22
And a default and readonly key to the GC.config hash that names the
current GC implementation.

This is provided by each implementation by the API function
rb_gc_impl_active_gc_name
This will add +MOD_GC to the version string and Ruby description when
Ruby is compiled with shared gc support.

When shared GC support is compiled in and a GC module has been loaded
using RUBY_GC_LIBRARY, the version string will include the name of
the currently active GC as reported by the rb_gc_active_gc_name function
in the form

+MOD_GC[gc_name]

[Feature #20794]
This avoids the need to malloc, and reduces the complexity of truncating
the long string for display in RUBY_DESCRIPTION.

The developer of a GC implementation should be responsible for giving it
a succinct name.
Instead of silently ignoring the key, we should raise to clearly tell
the user that this key is read-only.
@eightbitraptor eightbitraptor merged commit 4250101 into ruby:master Nov 14, 2024
73 checks passed
@eightbitraptor eightbitraptor deleted the mvh-active-gc-name branch November 14, 2024 10:46
// Assume the active GC name can not be longer than 20 chars
// so that we don't have to use strlen and remove the static
// qualifier from desc.
+ RB_GC_MAX_NAME_LEN + 3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is 3, [] and what?

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.

3 participants