gc on 2×previous
This commit is contained in:
parent
9f824483eb
commit
494c13f3d8
4
src/gc.c
4
src/gc.c
@ -82,6 +82,7 @@ void gc_visitRoots() {
|
||||
for (u32 i = 0; i < gc_rootSz; i++) gc_roots[i]();
|
||||
for (u32 i = 0; i < gc_rootObjSz; i++) mm_visit(gc_rootObjs[i]);
|
||||
}
|
||||
u64 gc_lastAlloc;
|
||||
void gc_forceGC() {
|
||||
#ifdef LOG_GC
|
||||
u64 start = nsTime();
|
||||
@ -95,9 +96,10 @@ void gc_forceGC() {
|
||||
#ifdef LOG_GC
|
||||
fprintf(stderr, "GC kept %ldB from %ld objects, freed %ldB from %ld objects; took %.3fms\n", gc_visitBytes, gc_visitCount, gc_freedBytes, gc_freedCount, (nsTime()-start)/1e6);
|
||||
#endif
|
||||
gc_lastAlloc = allocB;
|
||||
}
|
||||
|
||||
|
||||
void gc_maybeGC() {
|
||||
if (!gc_depth) gc_forceGC();
|
||||
if (!gc_depth && allocB > gc_lastAlloc*2) gc_forceGC();
|
||||
}
|
||||
|
||||
2
src/h.h
2
src/h.h
@ -480,3 +480,5 @@ static inline u64 nsTime() {
|
||||
// clock_gettime(CLOCK_REALTIME, &t);
|
||||
return t.tv_sec*1000000000ull + t.tv_nsec;
|
||||
}
|
||||
|
||||
u64 allocB; // currently allocated number of bytes
|
||||
|
||||
@ -239,6 +239,7 @@ int main() {
|
||||
// gc_add(comp);
|
||||
// free(c_src);
|
||||
// }
|
||||
gc_enable();
|
||||
|
||||
while (CATCH) {
|
||||
printf("caught: ");
|
||||
@ -276,7 +277,7 @@ int main() {
|
||||
#ifdef HEAP_VERIFY
|
||||
heapVerify();
|
||||
#endif
|
||||
gc_forceGC();
|
||||
gc_maybeGC();
|
||||
#ifdef DEBUG
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -66,6 +66,7 @@ void BN(free)(Value* x) {
|
||||
u8 b = x->mmInfo&63;
|
||||
((EmptyValue*)x)->next = buckets[b];
|
||||
buckets[b] = (EmptyValue*)x;
|
||||
allocB-= BSZ(b);
|
||||
#endif
|
||||
x->type = t_empty;
|
||||
}
|
||||
@ -78,6 +79,7 @@ void* BN(allocL)(u8 bucket, u8 type) {
|
||||
VALGRIND_MAKE_MEM_UNDEFINED(x, BSZ(bucket));
|
||||
VALGRIND_MAKE_MEM_DEFINED(&x->mmInfo, 1);
|
||||
#endif
|
||||
allocB+= BSZ(bucket);
|
||||
x->mmInfo = (x->mmInfo&0x7f) | gc_tagCurr;
|
||||
x->flags = x->extra = x->type = 0;
|
||||
x->refc = 1;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user