Skip to content

Module#remove_const: cleanup vm->defined_module_hash#10143

Closed
casperisfine wants to merge 4 commits intoruby:masterfrom
Shopify:clean-defined_module_hash
Closed

Module#remove_const: cleanup vm->defined_module_hash#10143
casperisfine wants to merge 4 commits intoruby:masterfrom
Shopify:clean-defined_module_hash

Conversation

@casperisfine
Copy link
Copy Markdown
Contributor

[Bug #20311]

All module and classes defined from C are stored in this table to ensure they are pinned and won't be moved by the compactor.

However this means we need to remove them from it whenever a constant referencing them is removed.

But since a same class or module may be referenced under multiple names, we have to do some ref counting.

@launchable-app
Copy link
Copy Markdown

launchable-app bot commented Feb 29, 2024

Launchable Report

❌ Test session #2670190 failedos:macos-arm-oss test_opts:--repeat-count:2 test_task:test-all
🔔 no issues ✖️3 tests failed ✔️49738 tests passed

❌ Test session #2670224 failedos:ubuntu-20.04 test_opts:cppflags:-DVM_CHECK_MODE test_task:check
🔔 no issues ✖️1 test failed ✔️24804 tests passed

❌ Test session #2670236 failedos:ubuntu-20.04 test_opts: test_task:check
🔔 no issues ✖️1 test failed ✔️23778 tests passed

❌ Test session #2670241 failedos:macos-12 test_opts: test_task:check
🔔 no issues ✖️190 tests failed ✔️24679 tests passed

Passed test sessions

✅ Test session #2670186 passed os:macos-arm-oss test_opts: test_task:check
✅ Test session #2670206 passed os:ubuntu-20.04 test_opts:--disable-yjit test_task:check
✅ Test session #2670218 passed os:ubuntu-20.04 test_opts:--enable-shared--enable-load-relative test_task:check
✅ Test session #2670247 passed os:macos-13 test_opts: test_task:check

Build: refs_pull_10143_merge_96be457649dbb8f759159899d851a073753445fe

@byroot byroot requested review from nobu and peterzhu2118 February 29, 2024 12:07
@casperisfine casperisfine force-pushed the clean-defined_module_hash branch 2 times, most recently from ee97604 to df5b171 Compare February 29, 2024 12:41
[Bug #20311]

All module and classes defined from C are stored in this table
to ensure they are pinned and won't be moved by the compactor.

However this means we need to remove them from it whenever a constant
referencing them is removed.

But since a same class or module may be referenced under multiple
names, we have to do some ref counting.
@casperisfine casperisfine force-pushed the clean-defined_module_hash branch from df5b171 to 88bf9f5 Compare February 29, 2024 12:49
@casperisfine
Copy link
Copy Markdown
Contributor Author

looks like I introduced a bug that cause some classes not to be pinned. Trying to figure it out.

@casperisfine
Copy link
Copy Markdown
Contributor Author

Alright, so the initial patch would break because some code in Ruby rely on this bug. e.g. rb_cNilClass ins't declared and some test unreference ::NilClass causing it to be GCed. That isn't to hard to fix.

But that also means removing modules from the root set can't be done when they are de-referenced, it must be done when they are GCed. Currently my patch does that, but now the problem is that a lot of core, including inside Ruby itself rely on classes and module define from C being immortal.

For the most part it's fine, but it means if their const is removed it then become trivial to crash the VM. So I'd need to add a whole lot of rb_global_variable in tons of places.

@casperisfine casperisfine force-pushed the clean-defined_module_hash branch from dd413bd to 2fac641 Compare February 29, 2024 14:33
@casperisfine casperisfine force-pushed the clean-defined_module_hash branch from 2fac641 to 96be457 Compare February 29, 2024 14:56
@casperisfine
Copy link
Copy Markdown
Contributor Author

Closing in favor of #10144

@casperisfine casperisfine deleted the clean-defined_module_hash branch February 29, 2024 15:59
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.

2 participants