use mm_heapUsed() instead of allocB

This commit is contained in:
dzaima 2021-07-11 22:40:46 +03:00
parent 9982c62526
commit 1b31c88e4c
4 changed files with 13 additions and 14 deletions

View File

@ -1,15 +1,5 @@
#include "../core.h"
u64 heapUsed_ctr;
static void heapUsedFn(Value* p) { heapUsed_ctr+= mm_size(p); }
u64 mm_heapUsed() {
heapUsed_ctr = 0;
mm_forHeap(heapUsedFn);
return heapUsed_ctr;
}
#ifdef HEAP_VERIFY
u32 heapVerify_mode = -1;

View File

@ -61,20 +61,21 @@ void gc_forceGC() {
u64 start = nsTime();
gc_visitBytes = 0; gc_freedBytes = 0;
gc_visitCount = 0; gc_freedCount = 0;
u64 startAllocB = allocB;
u64 startSize = mm_heapUsed();
#endif
gc_visitRoots();
mm_forHeap(gc_tryFree);
gc_tagNew = gc_tagCurr;
gc_tagCurr^= 0x80;
u64 endSize = mm_heapUsed();
#ifdef LOG_GC
fprintf(stderr, "GC kept "N64d"B from "N64d" objects, freed "N64d"B, including directly "N64d"B from "N64d" objects; took %.3fms\n", gc_visitBytes, gc_visitCount, startAllocB-allocB, gc_freedBytes, gc_freedCount, (nsTime()-start)/1e6);
fprintf(stderr, "GC kept "N64d"B from "N64d" objects, freed "N64d"B, including directly "N64d"B from "N64d" objects; took %.3fms\n", gc_visitBytes, gc_visitCount, startSize-endSize, gc_freedBytes, gc_freedCount, (nsTime()-start)/1e6);
#endif
gc_lastAlloc = allocB;
gc_lastAlloc = endSize;
#endif
}
void gc_maybeGC() {
if (!gc_depth && allocB > gc_lastAlloc*2) gc_forceGC();
if (!gc_depth && mm_heapUsed() > gc_lastAlloc*2) gc_forceGC();
}

View File

@ -26,3 +26,7 @@ void mm_forHeap(V2v f) {
b1_forHeap(f);
b3_forHeap(f);
}
u64 mm_heapUsed() {
return allocB;
}

View File

@ -12,3 +12,7 @@ EmptyValue* mm_buckets[64];
#include "mm_buddyTemplate.c"
#undef BN
#undef BSZ
u64 mm_heapUsed() {
return allocB;
}