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.

add deferred garbage collection flag and update GC logic

+28 -6
+2
include/ant.h
··· 163 163 jsoff_t js_loadoff(struct js *js, jsoff_t off); 164 164 165 165 void js_print_stack_trace(FILE *stream); 166 + void js_set_needs_gc(struct js *js, bool needs); 167 + 166 168 size_t js_gc_compact(struct js *js); 167 169 168 170 #endif
+2
include/internal.h
··· 43 43 jsval_t thrown_value; // stores the actual thrown value for catch blocks 44 44 bool is_hoisting; // true during function declaration hoisting pass 45 45 uint64_t sym_counter; // counter for generating unique symbol IDs 46 + bool needs_gc; // deferred GC flag, checked at statement boundaries 47 + int eval_depth; // recursion depth of js_eval calls 46 48 }; 47 49 48 50 #define JS_T_OBJ 0
+1 -1
meson.build
··· 86 86 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 87 87 88 88 version_conf = configuration_data() 89 - version_conf.set('ANT_VERSION', '0.3.1.16') 89 + version_conf.set('ANT_VERSION', '0.3.1.17') 90 90 version_conf.set('ANT_GIT_HASH', git_hash) 91 91 version_conf.set('ANT_BUILD_DATE', build_date) 92 92
+19 -5
src/ant.c
··· 512 512 return typestr_raw(t); 513 513 } 514 514 515 + void js_set_needs_gc(struct js *js, bool needs) { 516 + js->needs_gc = needs; 517 + } 518 + 515 519 uint8_t vtype(jsval_t v) { 516 520 return is_tagged(v) ? ((v >> NANBOX_TYPE_SHIFT) & NANBOX_TYPE_MASK) : (uint8_t)T_NUM; 517 521 } ··· 7672 7676 7673 7677 saveoff(js, target, (deleted_next & ~3U) | (current & (FLAGMASK | 3U))); 7674 7678 increment_version(js, obj_off); 7679 + js->needs_gc = true; 7675 7680 } 7676 7681 7677 7682 static jsval_t check_frozen_sealed(struct js *js, jsval_t obj, const char *action) { ··· 7862 7867 jsoff_t first_prop = loadoff(js, obj_off) & ~(3U | FLAGMASK); 7863 7868 if (first_prop == prop_off) { 7864 7869 unlink_prop(js, obj_off, prop_off, 0); 7865 - js_gc_compact(js); return js_mktrue(); 7870 + return js_mktrue(); 7866 7871 } 7867 7872 for (jsoff_t prev = first_prop; prev != 0; ) { 7868 7873 jsoff_t next_prop = loadoff(js, prev) & ~(3U | FLAGMASK); 7869 7874 if (next_prop == prop_off) { 7870 7875 unlink_prop(js, obj_off, prop_off, prev); 7871 - js_gc_compact(js); return js_mktrue(); 7876 + return js_mktrue(); 7872 7877 } 7873 7878 prev = next_prop; 7874 7879 } ··· 14005 14010 jsval_t len_key = js_mkstr(js, "length", 6); 14006 14011 jsval_t len_val = tov((double) len); 14007 14012 setprop(js, arr, len_key, len_val); 14013 + js->needs_gc = true; 14008 14014 14009 14015 return result; 14010 14016 } ··· 14970 14976 14971 14977 jsval_t len_key = js_mkstr(js, "length", 6); 14972 14978 setprop(js, arr, len_key, tov((double)(len - 1))); 14979 + js->needs_gc = true; 14973 14980 return first; 14974 14981 } 14975 14982 ··· 15161 15168 15162 15169 jsval_t len_key = js_mkstr(js, "length", 6); 15163 15170 setprop(js, arr, len_key, tov((double)((int)len + shift))); 15171 + if (deleteCount > 0) js->needs_gc = true; 15164 15172 return mkval(T_ARR, vdata(removed)); 15165 15173 } 15166 15174 ··· 20623 20631 jsoff_t current = loadoff(js, obj_off); 20624 20632 saveoff(js, obj_off, (deleted_next & ~3U) | (current & (FLAGMASK | 3U))); 20625 20633 increment_version(js, obj_off); 20626 - js_gc_compact(js); 20634 + js->needs_gc = true; 20627 20635 return true; 20628 20636 } 20629 20637 ··· 20635 20643 jsoff_t prev_flags = loadoff(js, prev) & FLAGMASK; 20636 20644 saveoff(js, prev, deleted_next | prev_flags); 20637 20645 increment_version(js, obj_off); 20638 - js_gc_compact(js); 20646 + js->needs_gc = true; 20639 20647 return true; 20640 20648 } 20641 20649 prev = next_prop; ··· 20862 20870 static jsval_t js_eval_inherit_strict(struct js *js, const char *buf, size_t len, bool inherit_strict) { 20863 20871 jsval_t res = js_mkundef(); 20864 20872 if (len == (size_t) ~0U) len = strlen(buf); 20873 + js->eval_depth++; 20865 20874 js->consumed = 1; 20866 20875 js->tok = TOK_ERR; 20867 20876 js->code = buf; ··· 20899 20908 20900 20909 while (next(js) != TOK_EOF && !is_err(res)) { 20901 20910 res = js_stmt(js); 20911 + if (js->needs_gc && js->eval_depth == 1) { 20912 + js->needs_gc = false; 20913 + js_gc_compact(js); 20914 + } 20902 20915 if (js->flags & F_RETURN) break; 20903 20916 } 20904 20917 20905 - if (is_strict) delscope(js); 20918 + if (is_strict) delscope(js); 20919 + js->eval_depth--; 20906 20920 return res; 20907 20921 } 20908 20922
+3
src/gc.c
··· 367 367 js->tval = gc_update_val(&ctx, js->tval); 368 368 js_gc_update_roots(js, gc_fwd_off_callback, gc_fwd_val_callback, &ctx); 369 369 370 + uint8_t *old_mem = js->mem; 370 371 js->mem = new_mem; 371 372 js->brk = ctx.new_brk; 373 + 374 + ANT_GC_FREE(old_mem); 372 375 373 376 jsoff_t free_space = js->size - js->brk; 374 377 if (free_space < js->lwm || js->lwm == 0) {
+1
src/modules/url.c
··· 497 497 498 498 js_set(js, this_val, "_entries", new_entries); 499 499 usp_sync_url(js, this_val); 500 + js_set_needs_gc(js, true); 500 501 return js_mkundef(); 501 502 } 502 503