ruby-changes:70999
From: Peter <ko1@a...>
Date: Mon, 24 Jan 2022 23:21:36 +0900 (JST)
Subject: [ruby-changes:70999] 663833b08f (master): [wasm] Disallow compaction
https://git.ruby-lang.org/ruby.git/commit/?id=663833b08f From 663833b08fbae8d92cb2245a729312b86aa33a35 Mon Sep 17 00:00:00 2001 From: Peter Zhu <peter@p...> Date: Thu, 20 Jan 2022 16:23:43 -0500 Subject: [wasm] Disallow compaction WebAssembly doesn't support signals so we can't use read barriers so we can't use compaction. --- gc.c | 38 ++++++++++++++++++++++++++------------ test/ruby/test_gc_compact.rb | 1 + 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/gc.c b/gc.c index 860accd951d..96a99cc81a2 100644 --- a/gc.c +++ b/gc.c @@ -5014,14 +5014,13 @@ gc_unprotect_pages(rb_objspace_t *objspace, rb_heap_t *heap) https://github.com/ruby/ruby/blob/trunk/gc.c#L5014 static void gc_update_references(rb_objspace_t * objspace); static void invalidate_moved_page(rb_objspace_t *objspace, struct heap_page *page); -#if !defined(__wasi__) -// read barrier for pages containing MOVED objects -# define GC_ENABLE_READ_SIGNAL_BARRIER 1 +#if defined(__wasi__) /* WebAssembly doesn't support signals */ +# define GC_COMPACTION_SUPPORTED 0 #else -# define GC_ENABLE_READ_SIGNAL_BARRIER 0 +# define GC_COMPACTION_SUPPORTED 1 #endif -#if GC_ENABLE_READ_SIGNAL_BARRIER +#if GC_COMPACTION_SUPPORTED static void read_barrier_handler(uintptr_t address) { @@ -5042,8 +5041,21 @@ read_barrier_handler(uintptr_t address) https://github.com/ruby/ruby/blob/trunk/gc.c#L5041 } RB_VM_LOCK_LEAVE(); } +#endif -#if defined(_WIN32) +#if !GC_COMPACTION_SUPPORTED +static void +uninstall_handlers(void) +{ + /* no-op */ +} + +static void +install_handlers(void) +{ + /* no-op */ +} +#elif defined(_WIN32) static LPTOP_LEVEL_EXCEPTION_FILTER old_handler; typedef void (*signal_handler)(int); static signal_handler old_sigsegv_handler; @@ -5130,8 +5142,6 @@ install_handlers(void) https://github.com/ruby/ruby/blob/trunk/gc.c#L5142 } #endif -#endif // GC_ENABLE_READ_SIGNAL_BARRIER - static void revert_stack_objects(VALUE stack_obj, void *ctx) { @@ -5178,9 +5188,7 @@ gc_compact_finish(rb_objspace_t *objspace, rb_size_pool_t *pool, rb_heap_t *heap https://github.com/ruby/ruby/blob/trunk/gc.c#L5188 gc_unprotect_pages(objspace, heap); } -#if GC_ENABLE_READ_SIGNAL_BARRIER uninstall_handlers(); -#endif /* The mutator is allowed to run during incremental sweeping. T_MOVED * objects can get pushed on the stack and when the compaction process @@ -5902,9 +5910,7 @@ gc_compact_start(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L5910 memset(objspace->rcompactor.moved_count_table, 0, T_MASK * sizeof(size_t)); /* Set up read barrier for pages containing MOVED objects */ -#if GC_ENABLE_READ_SIGNAL_BARRIER install_handlers(); -#endif } static void @@ -9324,6 +9330,10 @@ gc_start_internal(rb_execution_context_t *ec, VALUE self, VALUE full_mark, VALUE https://github.com/ruby/ruby/blob/trunk/gc.c#L9330 } #endif +#if !GC_COMPACTION_SUPPORTED + rb_raise(rb_eNotImpError, "Compaction isn't available on this platform"); +#endif + reason |= GPR_FLAG_COMPACT; } else { @@ -10921,6 +10931,10 @@ gc_set_auto_compact(rb_execution_context_t *ec, VALUE _, VALUE v) https://github.com/ruby/ruby/blob/trunk/gc.c#L10931 } #endif +#if !GC_COMPACTION_SUPPORTED + rb_raise(rb_eNotImpError, "Automatic compaction isn't available on this platform"); +#endif + ruby_enable_autocompact = RTEST(v); return v; } diff --git a/test/ruby/test_gc_compact.rb b/test/ruby/test_gc_compact.rb index 50abd28ad33..16b15b39ac8 100644 --- a/test/ruby/test_gc_compact.rb +++ b/test/ruby/test_gc_compact.rb @@ -18,6 +18,7 @@ class TestGCCompact < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_gc_compact.rb#L18 private def supports_auto_compact? + return false if /wasm/ =~ RUBY_PLATFORM return true unless defined?(Etc::SC_PAGE_SIZE) begin -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/