From c576e63ee752f2c7ce865b1cb1398d013d55f153 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Fri, 19 Mar 2021 12:35:48 +0900 Subject: gc.c: Use dedicated APIs for conservative GC in Emscripten Emscripten provides "emscripten_scan_stack" to get the beginning and end pointers of the stack for conservative GC. Also, "emscripten_scan_registers" allows the GC to mark local variables in WASM. --- gc.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/gc.c b/gc.c index 5ec317ddc7..f4c8a948c9 100644 --- a/gc.c +++ b/gc.c @@ -71,6 +71,10 @@ #include +#ifdef __EMSCRIPTEN__ +#include +#endif + #include "constant.h" #include "debug_counter.h" #include "eval_intern.h" @@ -5895,6 +5899,7 @@ mark_const_tbl(rb_objspace_t *objspace, struct rb_id_table *tbl) static void mark_stack_locations(rb_objspace_t *objspace, const rb_execution_context_t *ec, const VALUE *stack_start, const VALUE *stack_end); +#ifndef __EMSCRIPTEN__ static void mark_current_machine_context(rb_objspace_t *objspace, rb_execution_context_t *ec) { @@ -5919,6 +5924,27 @@ mark_current_machine_context(rb_objspace_t *objspace, rb_execution_context_t *ec mark_stack_locations(objspace, ec, stack_start, stack_end); } +#else + +static VALUE *rb_emscripten_stack_range_tmp[2]; + +static void +rb_emscripten_mark_locations(void *begin, void *end) +{ + rb_emscripten_stack_range_tmp[0] = begin; + rb_emscripten_stack_range_tmp[1] = end; +} + +static void +mark_current_machine_context(rb_objspace_t *objspace, rb_execution_context_t *ec) +{ + emscripten_scan_stack(rb_emscripten_mark_locations); + mark_stack_locations(objspace, ec, rb_emscripten_stack_range_tmp[0], rb_emscripten_stack_range_tmp[1]); + + emscripten_scan_registers(rb_emscripten_mark_locations); + mark_stack_locations(objspace, ec, rb_emscripten_stack_range_tmp[0], rb_emscripten_stack_range_tmp[1]); +} +#endif void rb_gc_mark_machine_stack(const rb_execution_context_t *ec) -- cgit v1.2.3