WebAssembly doesn't support signals so we can't use read
barriers so we can't use compaction.
This commit is contained in:
Peter Zhu 2022-01-20 16:23:43 -05:00
Родитель 5de62fe37c
Коммит 663833b08f
2 изменённых файлов: 27 добавлений и 12 удалений

38
gc.c
Просмотреть файл

@ -5014,14 +5014,13 @@ gc_unprotect_pages(rb_objspace_t *objspace, rb_heap_t *heap)
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)
}
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)
}
#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
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)
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
}
#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)
}
#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;
}

Просмотреть файл

@ -18,6 +18,7 @@ class TestGCCompact < Test::Unit::TestCase
private
def supports_auto_compact?
return false if /wasm/ =~ RUBY_PLATFORM
return true unless defined?(Etc::SC_PAGE_SIZE)
begin