summaryrefslogtreecommitdiff
path: root/os_dep.c
diff options
context:
space:
mode:
authorJukka Jylanki <jujjyl@gmail.com>2022-11-22 12:07:16 +0200
committerIvan Maidanski <ivmai@mail.ru>2022-11-24 00:08:07 +0300
commit840bbcf603bc75e0b2da21ea9cbd84d1d63f14cf (patch)
tree43f4de57a2a2e920cdba5f4bc47ad9eff8fa9310 /os_dep.c
parent421d2612e45bdc8305a220ee06f93461ed979d6d (diff)
downloadbdwgc-840bbcf603bc75e0b2da21ea9cbd84d1d63f14cf.tar.gz
Make Emscripten Asyncify feature optional
Issue #506 (bdwgc). "-sASYNCIFY" is a relatively rarely used feature of Emscripten, most developers do not use it, and it does not scale well to moderate-to-large codebases. It incurs a heavy impact to code size and performance, and carries other correctness problems that developers must then adhere to regarding event loop message ordering. This commit provides new option in cmake (-Denable_emscripten_asyncify) and configure (--enable-emscripten-asyncify) scripts to turn on Emscripten Asyncify feature on demand. * CMakeLists.txt (enable_emscripten_asyncify): New option (off by default). * CMakeLists.txt (EMSCRIPTEN): Define using check_c_source_compiles. * CMakeLists.txt [EMSCRIPTEN && enable_emscripten_asyncify] (EMSCRIPTEN_ASYNCIFY): Define C macro. * CMakeLists.txt [EMSCRIPTEN && enable_emscripten_asyncify] (CMAKE_EXE_LINKER_FLAGS): Append "-sASYNCIFY" and "-sASYNCIFY_STACK_SIZE=128000". * configure.ac (emscripten): Remove quotes for the error directive message. * configure.ac [emscripten] (gc_cflags): Move comment and assignment down (to be after reporting result for emscripten). * configure.ac (emscripten-asyncify): New AC_ARG_ENABLE option; add comment. * configure.ac [enable_emscripten_asyncify && emscripten] (gc_cflags): Add -D EMSCRIPTEN_ASYNCIFY; remove space after "-s". * configure.ac [emscripten] (gc_cflags): Append "-sASYNCIFY" and "-sASYNCIFY_STACK_SIZE=128000" only if enable_emscripten_asyncify. * doc/README.macros (EMSCRIPTEN_ASYNCIFY): Document. * os_dep.c [!ECOS && !NOSYS && !SYMBIAN && EMSCRIPTEN]: Make USE_EMSCRIPTEN_SCAN_STACK has effect only if EMSCRIPTEN_ASYNCIFY. * os_dep.c [THREADS && EMSCRIPTEN]: Include emscripten.h only if EMSCRIPTEN_ASYNCIFY. * os_dep.c [THREADS && EMSCRIPTEN] (scan_regs_cb, GC_default_push_other_roots): Define as a function only if EMSCRIPTEN_ASYNCIFY; update comment. Co-authored-by: Ivan Maidanski <ivmai@mail.ru>
Diffstat (limited to 'os_dep.c')
-rw-r--r--os_dep.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/os_dep.c b/os_dep.c
index 2fd63e0e..8e140836 100644
--- a/os_dep.c
+++ b/os_dep.c
@@ -1242,7 +1242,7 @@ GC_INNER size_t GC_page_size = 0;
# define GET_MAIN_STACKBASE_SPECIAL
#elif defined(EMSCRIPTEN)
-# ifdef USE_EMSCRIPTEN_SCAN_STACK
+# if defined(USE_EMSCRIPTEN_SCAN_STACK) && defined(EMSCRIPTEN_ASYNCIFY)
/* According to the documentation, emscripten_scan_stack() is only */
/* guaranteed to be available when building with ASYNCIFY. */
# include <emscripten.h>
@@ -1260,7 +1260,7 @@ GC_INNER size_t GC_page_size = 0;
ptr_t GC_get_main_stack_base(void)
{
-# ifdef USE_EMSCRIPTEN_SCAN_STACK
+# if defined(USE_EMSCRIPTEN_SCAN_STACK) && defined(EMSCRIPTEN_ASYNCIFY)
emscripten_scan_stack(scan_stack_cb);
return (ptr_t)emscripten_stack_base;
# else
@@ -2814,7 +2814,7 @@ GC_INNER void GC_unmap_gap(ptr_t start1, size_t bytes1, ptr_t start2,
/* thread stacks. */
#ifndef THREADS
-# ifdef EMSCRIPTEN
+# if defined(EMSCRIPTEN) && defined(EMSCRIPTEN_ASYNCIFY)
# include <emscripten.h>
static void scan_regs_cb(void *begin, void *end)
@@ -2824,8 +2824,7 @@ GC_INNER void GC_unmap_gap(ptr_t start1, size_t bytes1, ptr_t start2,
STATIC void GC_CALLBACK GC_default_push_other_roots(void)
{
- /* This needs "-s ASYNCIFY -s ASYNCIFY_STACK_SIZE=128000" */
- /* but hopefully the latter is only required for gctest. */
+ /* Note: this needs -sASYNCIFY linker flag. */
emscripten_scan_registers(scan_regs_cb);
}