0a1,107 > From 1484f4a4f5a04a83738e6616b926a472d23b8adf Mon Sep 17 00:00:00 2001 > From: Peter Zhu > Date: Tue, 14 Jun 2022 14:37:21 -0400 > Subject: [PATCH] Define the GC compaction support during run time. > > == Summary of the implementation == > > The patch is created by 3 commits on the upstream Ruby master branch in > the chronological order below. > https://github.com/ruby/ruby/commit/52d42e702375446746164a0251e1a10bce813b78 > https://github.com/ruby/ruby/commit/79eaaf2d0b641710613f16525e4b4c439dfe854e > https://github.com/ruby/ruby/commit/2c190863239bee3f54cfb74b16bb6ea4cae6ed20 > > The implementation is basically to replace the wrongly used > `GC_COMPACTION_SUPPORTED` with the `GC_CAN_COMPILE_COMPACTION`. > > * GC_COMPACTION_SUPPORTED macro > only checks whether compaction is supported at compile time. > * GC_CAN_COMPILE_COMPACTION macro > checks whether compaction is supported at both compile and run time. > > == How to create this patch == > > Download Ruby source code. > ``` > $ git clone https://github.com/ruby/ruby.git > $ cd ruby > ``` > > First create a commit squashed from the 3 commits above. > Checkout the second commmit above, and create a temporary branch. > ``` > $ git checkout 79eaaf2d0b641710613f16525e4b4c439dfe854e > $ git checkout -b wip/detect-compaction-runtime-tmp > ``` > > Cherry pick the third commit on the second commit. > ``` > $ git cherry-pick 2c190863239bee3f54cfb74b16bb6ea4cae6ed20 > ``` > > Squash the last 3 commits on the branch. > ``` > $ git rebase -i 2223eb082afa6d05321b69df783d4133b9aacba6 > ``` > > Then checkout Ruby 3.1.2 branch. > Create a new branch. > Merge the Fedora Ruby's ruby-3.2.0-define-unsupported-gc-compaction-methods-as-rb_f_notimplement.patch. > ``` > $ git checkout v3_1_2 > $ git checkout -b wip/detect-compaction-runtime > $ patch -p1 < ~/fed/ruby/ruby-3.2.0-define-unsupported-gc-compaction-methods-as-rb_f_notimplement.patch > $ git add gc.c gc.rb test/ruby/test_gc_compact.rb > $ git commit > ``` > > Merge the squashed on commit on the `wip/detect-compaction-runtime-tmp` branch > into the `wip/detect-compaction-runtime` branch. > ``` > $ git cherry-pick > ``` > > Fix conflicts seeing the difference by `git show ` > on another terminal. > ``` > $ vi gc.c > $ git add gc.c > $ git commit > ``` > > == Original commit messages == > > This is a combination of 3 commits. > This is the 1st commit message: > ~~~ > Rename GC_COMPACTION_SUPPORTED > > Naming this macro GC_COMPACTION_SUPPORTED is misleading because it > only checks whether compaction is supported at compile time. > > [Bug #18829] > ~~~ > > This is the commit message #2: > ~~~ > Include runtime checks for compaction support > > Commit 0c36ba53192c5a0d245c9b626e4346a32d7d144e changed GC compaction > methods to not be implemented when not supported. However, that commit > only does compile time checks (which currently only checks for WASM), > but there are additional compaction support checks during run time. > > This commit changes it so that GC compaction methods aren't defined > during run time if the platform does not support GC compaction. > > [Bug #18829] > ~~~ > > This is the commit message #3: > ~~~ > Suppress code unused unless GC_CAN_COMPILE_COMPACTION > ~~~ > --- > gc.c | 62 ++++++++++++++++++++++++++++++++++++++++-------------------- > 1 file changed, 42 insertions(+), 20 deletions(-) > 2c109 < index 1c35856c44..c80a3de365 100644 --- > index 1c35856c44..3dbb4d156b 100644 10c117 < +#if defined(__wasi__) --- > +#if defined(__wasi__) /* WebAssembly doesn't support signals */ 22c129 < +# define GC_COMPACTION_SUPPORTED (GC_CAN_COMPILE_COMPACTION && USE_MMAP_ALIGNED_ALLOC) --- > +# define GC_COMPACTION_SUPPORTED (GC_CAN_COMPILE_COMPACTION && HEAP_PAGE_ALLOC_USE_MMAP) 97c204,206 < @@ -10816,6 +10828,7 @@ gc_set_auto_compact(VALUE _, VALUE v) --- > @@ -10814,8 +10826,7 @@ gc_disable(rb_execution_context_t *ec, VALUE _) > static VALUE > gc_set_auto_compact(VALUE _, VALUE v) 99,100c208,209 < /* If not MinGW, Windows, or does not have mmap, we cannot use mprotect for < * the read barrier, so we must disable automatic compaction. */ --- > - /* If not MinGW, Windows, or does not have mmap, we cannot use mprotect for > - * the read barrier, so we must disable automatic compaction. */ 105c214 < @@ -10824,7 +10837,8 @@ gc_set_auto_compact(VALUE _, VALUE v) --- > @@ -10824,7 +10835,7 @@ gc_set_auto_compact(VALUE _, VALUE v) 110d218 < + 115c223 < @@ -13696,11 +13710,20 @@ Init_GC(void) --- > @@ -13696,11 +13707,21 @@ Init_GC(void) 123a232 > + 129,130c238,239 < + rb_define_singleton_method(rb_mGC, "verify_compaction_references", gc_verify_compaction_references, -1); < + } else { --- > + } > + else { 141c250 < @@ -13724,6 +13747,7 @@ Init_GC(void) --- > @@ -13724,6 +13745,7 @@ Init_GC(void) 145c254 < + OPT(GC_COMPACTION_SUPPORTED); --- > + OPT(GC_COMPACTION_SUPPORTED); 148a258,260 > -- > 2.36.1 >