Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable GC loading from a shared library #10456

Merged
merged 3 commits into from
Apr 15, 2024

Conversation

eightbitraptor
Copy link
Contributor

This PR replaces #10302 as a method for dynamically loading a shared GC library. This new approach has been guided by feedback from @kateinoigakukun and @nobu

The approach taken here is as follows:

  • Enable this feature by configuring with --with-shared-gc
  • When enabled, Ruby will check for the presence of the environment variable RUBY_GC_LIBRARY_PATH
  • If that path exists and points to a valid shared object
    • Open the shared object (using dln_open), and map the Init_GC function to a function map
    • call Init_GC as part of rb_objspace_alloc when initialising the GC
  • If that path does not point to a valid shared object
    • Degrade gracefully to initialising the existing Ruby objspace and GC

When Ruby is configured without the --with-shared-gc flag, no extra code is compiled and so existing behaviour is maintained without any performance penalty.

Enabling this feature, but not populating RUBY_GC_LIBRARY_PATH will incur a small performance penalty due to the overhead of using getenv to check for the environment variable.

The use of dln.c rather than using dlopen directly, should enable this feature to be supported on all platforms that support loading shared libraries, rather than the initial implementation, which explicitly only supported Linux and MacOS.

gc.c Outdated Show resolved Hide resolved
gc.c Outdated Show resolved Hide resolved
dln.h Outdated Show resolved Hide resolved
configure.ac Outdated Show resolved Hide resolved
@eightbitraptor eightbitraptor force-pushed the mvh-share-gc-dlopen2 branch 2 times, most recently from f6c9d96 to 30c84de Compare April 5, 2024 19:07
tool/m4/ruby_shared_gc.m4 Outdated Show resolved Hide resolved
configure.ac Outdated Show resolved Hide resolved
@eightbitraptor eightbitraptor merged commit f5d8926 into ruby:master Apr 15, 2024
100 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants