diff --git a/src/README.md b/src/README.md index 9acf7ce7..db777496 100644 --- a/src/README.md +++ b/src/README.md @@ -445,6 +445,7 @@ Most toggles require a value of `1` to be enabled. #define VERIFY_TAIL (u) // number of bytes after the end of an array to verify not being improperly modified; 64 in DEBUG #define NEEQUAL_NEGZERO 0 // make negative zero not equal zero for •internal.EEqual #define RT_VERIFY_ARGS 1 // rtverify: preserve arguments for printing on failure +#define GC_EVERY_NTH_ALLOC (u) // force a GC on every n'th allocation (<=1 to GC on every alloc) // some somewhat-outdated/unmaintained things: #define RT_PERF 0 // time runtime primitives diff --git a/src/core/stuff.h b/src/core/stuff.h index 6d45e56a..99930a34 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -340,10 +340,24 @@ static FC2 c2fn(B f) { NOINLINE NORETURN void thrOOMTest(void); #endif +#ifdef GC_EVERY_NTH_ALLOC + extern u64 gc_depth; + extern u64 nth_alloc; +#endif FORCE_INLINE void preAlloc(usz sz, u8 type) { #ifdef OOM_TEST if (--oomTestLeft==0) thrOOMTest(); #endif + #ifdef GC_EVERY_NTH_ALLOC + #if GC_EVERY_NTH_ALLOC<=1 + if (gc_depth==0) gc_forceGC(false); + #else + if (gc_depth==0 && --nth_alloc == 0) { + gc_forceGC(false); + nth_alloc = GC_EVERY_NTH_ALLOC; + } + #endif + #endif #if ALLOC_STAT if (!ctr_a) { #if ALLOC_SIZES diff --git a/src/opt/gc.c b/src/opt/gc.c index 83bd6268..cf2c81e6 100644 --- a/src/opt/gc.c +++ b/src/opt/gc.c @@ -12,6 +12,9 @@ u64 gc_depth = 1; +#ifdef GC_EVERY_NTH_ALLOC + u64 nth_alloc = 1; +#endif vfn gc_roots[8];