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_rootSz; i++) gc_roots[i]();
|
||||||
for (u32 i = 0; i < gc_rootObjSz; i++) mm_visit(gc_rootObjs[i]);
|
for (u32 i = 0; i < gc_rootObjSz; i++) mm_visit(gc_rootObjs[i]);
|
||||||
}
|
}
|
||||||
|
u64 gc_lastAlloc;
|
||||||
void gc_forceGC() {
|
void gc_forceGC() {
|
||||||
#ifdef LOG_GC
|
#ifdef LOG_GC
|
||||||
u64 start = nsTime();
|
u64 start = nsTime();
|
||||||
@ -95,9 +96,10 @@ void gc_forceGC() {
|
|||||||
#ifdef LOG_GC
|
#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);
|
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
|
#endif
|
||||||
|
gc_lastAlloc = allocB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void gc_maybeGC() {
|
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);
|
// clock_gettime(CLOCK_REALTIME, &t);
|
||||||
return t.tv_sec*1000000000ull + t.tv_nsec;
|
return t.tv_sec*1000000000ull + t.tv_nsec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u64 allocB; // currently allocated number of bytes
|
||||||
|
|||||||
@ -239,6 +239,7 @@ int main() {
|
|||||||
// gc_add(comp);
|
// gc_add(comp);
|
||||||
// free(c_src);
|
// free(c_src);
|
||||||
// }
|
// }
|
||||||
|
gc_enable();
|
||||||
|
|
||||||
while (CATCH) {
|
while (CATCH) {
|
||||||
printf("caught: ");
|
printf("caught: ");
|
||||||
@ -276,7 +277,7 @@ int main() {
|
|||||||
#ifdef HEAP_VERIFY
|
#ifdef HEAP_VERIFY
|
||||||
heapVerify();
|
heapVerify();
|
||||||
#endif
|
#endif
|
||||||
gc_forceGC();
|
gc_maybeGC();
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@ -66,6 +66,7 @@ void BN(free)(Value* x) {
|
|||||||
u8 b = x->mmInfo&63;
|
u8 b = x->mmInfo&63;
|
||||||
((EmptyValue*)x)->next = buckets[b];
|
((EmptyValue*)x)->next = buckets[b];
|
||||||
buckets[b] = (EmptyValue*)x;
|
buckets[b] = (EmptyValue*)x;
|
||||||
|
allocB-= BSZ(b);
|
||||||
#endif
|
#endif
|
||||||
x->type = t_empty;
|
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_UNDEFINED(x, BSZ(bucket));
|
||||||
VALGRIND_MAKE_MEM_DEFINED(&x->mmInfo, 1);
|
VALGRIND_MAKE_MEM_DEFINED(&x->mmInfo, 1);
|
||||||
#endif
|
#endif
|
||||||
|
allocB+= BSZ(bucket);
|
||||||
x->mmInfo = (x->mmInfo&0x7f) | gc_tagCurr;
|
x->mmInfo = (x->mmInfo&0x7f) | gc_tagCurr;
|
||||||
x->flags = x->extra = x->type = 0;
|
x->flags = x->extra = x->type = 0;
|
||||||
x->refc = 1;
|
x->refc = 1;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user