diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2021-03-19 12:35:48 +0900 |
---|---|---|
committer | Yusuke Endoh <mame@ruby-lang.org> | 2021-03-19 12:35:48 +0900 |
commit | c576e63ee752f2c7ce865b1cb1398d013d55f153 (patch) | |
tree | 3b82dd3c61389c5167ada65c1f6992a98d32cbb8 /gc.c | |
parent | e79b42c9b21abbd73aa97aec21f817704d37fd7d (diff) |
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.
Diffstat (limited to 'gc.c')
-rw-r--r-- | gc.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -71,6 +71,10 @@ #include <sys/types.h> +#ifdef __EMSCRIPTEN__ +#include <emscripten.h> +#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) |