MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

update GC to respect coro stack bottom

+34 -21
-1
include/ant.h
··· 15 15 #define ANT_LIMIT_SIZE_CACHE 16384 16 16 17 17 struct js; 18 - extern bool executing_coro; 19 18 20 19 typedef uint32_t jsoff_t; 21 20 typedef uint64_t jsval_t;
+24 -5
include/arena.h
··· 2 2 #define ARENA_H 3 3 4 4 #include <gc.h> 5 + #include <string.h> 6 + #include <minicoro.h> 5 7 6 - static inline void ant_gc_init(void) { 8 + static inline void ANT_GC_INIT(void) { 7 9 GC_INIT(); 8 - GC_set_all_interior_pointers(0); 9 - GC_disable(); 10 + GC_enable(); 11 + } 12 + 13 + static inline void ANT_GC_COLLECT(void) { 14 + mco_coro* running = mco_running(); 15 + struct GC_stack_base sb; 16 + int in_coroutine = (running != NULL && running->stack_base != NULL); 17 + 18 + if (in_coroutine) { 19 + memset(&sb, 0, sizeof(sb)); 20 + sb.mem_base = running->stack_base; 21 + GC_set_stackbottom(NULL, &sb); 22 + } 23 + 24 + GC_gcollect(); 25 + 26 + if (in_coroutine) { 27 + memset(&sb, 0, sizeof(sb)); 28 + GC_get_stack_base(&sb); 29 + GC_set_stackbottom(NULL, &sb); 30 + } 10 31 } 11 32 12 - #define ANT_GC_INIT() ant_gc_init() 13 33 #define ANT_GC_MALLOC(size) GC_MALLOC_IGNORE_OFF_PAGE(size) 14 34 #define ANT_GC_MALLOC_ATOMIC(size) GC_MALLOC_ATOMIC_IGNORE_OFF_PAGE(size) 15 35 #define ANT_GC_REALLOC(ptr, size) GC_REALLOC(ptr, size) 16 36 #define ANT_GC_FREE(ptr) GC_FREE(ptr) 17 - #define ANT_GC_COLLECT() do { GC_enable(); GC_gcollect(); GC_disable(); } while(0) 18 37 19 38 #define ANT_GC_REGISTER_ROOT(ptr) 20 39 #define ANT_GC_UNREGISTER_ROOT(ptr)
+6
maidfile.toml
··· 35 35 bash -c 'which ant && cp ./build/ant "$(which ant)" || 36 36 { mkdir -p ~/.local/bin && cp ./build/ant ~/.local/bin/; }' 37 37 '''] 38 + 39 + [tasks.debug] 40 + script = ['meson subprojects download', ''' 41 + bash -c 'CC="ccache $(which clang)" \ 42 + meson setup build --wipe -Doptimization=0 -Db_lto=false -Dstrip=false -Db_lundef=false -Dunity=off -Ddebug=true' 43 + ''']
+1 -1
meson.build
··· 85 85 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 86 86 87 87 version_conf = configuration_data() 88 - version_conf.set('ANT_VERSION', '0.2.3.18') 88 + version_conf.set('ANT_VERSION', '0.2.3.19') 89 89 version_conf.set('ANT_GIT_HASH', git_hash) 90 90 version_conf.set('ANT_BUILD_DATE', build_date) 91 91
-5
src/ant.c
··· 867 867 return 0; 868 868 } 869 869 870 - bool executing_coro = false; 871 - 872 870 static void mco_async_entry(mco_coro* mco) { 873 871 async_exec_context_t *ctx = (async_exec_context_t *)mco_get_user_data(mco); 874 872 875 873 struct js *js = ctx->js; 876 874 coroutine_t *coro = ctx->coro; 877 875 jsval_t result; 878 - executing_coro = true; 879 876 880 877 if (coro && coro->nargs > 0 && coro->args) { 881 878 result = call_js_code_with_args(js, ctx->code, (jsoff_t)ctx->code_len, ctx->closure_scope, coro->args, coro->nargs); ··· 897 894 } else { 898 895 js_resolve_promise(js, ctx->promise, result); 899 896 } 900 - 901 - executing_coro = false; 902 897 } 903 898 904 899 static void enqueue_coroutine(coroutine_t *coro) {
+3 -9
src/modules/builtin.c
··· 65 65 // Ant.gc() 66 66 static jsval_t js_gc_trigger(struct js *js, jsval_t *args, int nargs) { 67 67 (void) args; (void) nargs; 68 - 69 - if (executing_coro) { 70 - jsval_t result = js_mkobj(js); 71 - js_set(js, result, "skipped", js_mktrue()); 72 - return result; 73 - } 74 - 68 + 75 69 size_t heap_before = GC_get_heap_size(); 76 70 size_t used_before = GC_get_heap_size() - GC_get_free_bytes(); 77 71 ··· 80 74 size_t heap_after = GC_get_heap_size(); 81 75 size_t used_after = GC_get_heap_size() - GC_get_free_bytes(); 82 76 size_t freed = (used_before > used_after) ? (used_before - used_after) : 0; 83 - 77 + 84 78 jsval_t result = js_mkobj(js); 85 79 js_set(js, result, "heapBefore", js_mknum((double)heap_before)); 86 80 js_set(js, result, "heapAfter", js_mknum((double)heap_after)); 87 81 js_set(js, result, "usedBefore", js_mknum((double)used_before)); 88 82 js_set(js, result, "usedAfter", js_mknum((double)used_after)); 89 83 js_set(js, result, "freed", js_mknum((double)freed)); 90 - 84 + 91 85 return result; 92 86 } 93 87