[前][次][番号順一覧][スレッド一覧]

ruby-changes:65481

From: Yusuke <ko1@a...>
Date: Fri, 19 Mar 2021 12:43:20 +0900 (JST)
Subject: [ruby-changes:65481] c576e63ee7 (master): gc.c: Use dedicated APIs for conservative GC in Emscripten

https://git.ruby-lang.org/ruby.git/commit/?id=c576e63ee7

From c576e63ee752f2c7ce865b1cb1398d013d55f153 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
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 5ec317d..f4c8a94 100644
--- a/gc.c
+++ b/gc.c
@@ -71,6 +71,10 @@ https://github.com/ruby/ruby/blob/trunk/gc.c#L71
 
 #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) https://github.com/ruby/ruby/blob/trunk/gc.c#L5899
 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 https://github.com/ruby/ruby/blob/trunk/gc.c#L5924
 
     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.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]