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.

at master 51 lines 1.5 kB view raw
1#ifndef ANT_GC_H 2#define ANT_GC_H 3 4#include "internal.h" 5#include <stdbool.h> 6#include <stdint.h> 7 8#define GC_MIN_TICK 1024 9#define GC_NURSERY_THRESHOLD 32768 10#define GC_FORCE_INTERVAL_MS 50 11#define GC_MAJOR_EVERY_N_MINOR 8 12 13#define GC_OBJ_TYPE_MASK (JS_TPFLG(T_OBJ) \ 14 | JS_TPFLG(T_ARR) \ 15 | JS_TPFLG(T_PROMISE) \ 16 | JS_TPFLG(T_GENERATOR)) 17 18typedef struct gc_func_mark_profile { 19 bool enabled; 20 uint64_t collections; 21 uint64_t func_visits; 22 uint64_t child_edges; 23 uint64_t const_slots; 24 uint64_t time_ns; 25} gc_func_mark_profile_t; 26 27void gc_run(ant_t *js); 28void gc_run_minor(ant_t *js); 29void gc_maybe(ant_t *js); 30void gc_remember_add(ant_t *js, ant_object_t *obj); 31 32size_t gc_live_major_threshold(ant_t *js); 33size_t gc_pool_major_threshold(ant_t *js); 34 35void gc_func_mark_profile_enable(bool enabled); 36void gc_func_mark_profile_reset(void); 37 38extern bool gc_disabled; 39gc_func_mark_profile_t gc_func_mark_profile_get(void); 40 41static inline void gc_write_barrier(ant_t *js, ant_object_t *writer_obj, ant_value_t new_val) { 42 if (writer_obj->generation != 1 || new_val <= NANBOX_PREFIX) return; 43 uint8_t type = (new_val >> NANBOX_TYPE_SHIFT) & NANBOX_TYPE_MASK; 44 if (type == T_FUNC) gc_remember_add(js, writer_obj); 45 else if ((1u << type) & GC_OBJ_TYPE_MASK) { 46 ant_object_t *ref = (ant_object_t *)(uintptr_t)(new_val & NANBOX_DATA_MASK); 47 if (ref && ref->generation == 0) gc_remember_add(js, writer_obj); 48 } 49} 50 51#endif