throw error on reaching heap size limit if reasonable

This commit is contained in:
dzaima 2021-12-12 23:28:58 +02:00
parent cd07af4e8b
commit 9e6b8ecaae
2 changed files with 17 additions and 12 deletions

View File

@ -36,7 +36,10 @@ FORCE_INLINE void BN(splitTo)(EmptyValue* c, i64 from, i64 to, bool notEqual) {
static NOINLINE void* BN(allocateMore)(i64 bucket, u8 type, i64 from, i64 to) {
u64 sz = BSZ(from);
if (mm_heapAlloc+sz >= mm_heapMax) { printf("Heap size limit reached\n"); exit(1); }
if (mm_heapAlloc+sz >= mm_heapMax) {
if (sz>100000) thrM("Heap size limit reached"); // if allocating a large thing, it should be possible to recover
printf("Heap size limit reached\n"); abort();
}
mm_heapAlloc+= sz;
// gc_maybeGC();
EmptyValue* c = MMAP(sz);

View File

@ -1193,7 +1193,8 @@ NOINLINE void printErrMsg(B msg) {
NOINLINE NORETURN void thr(B msg) {
// printf("gStack %p-%p:\n", gStackStart, gStack); B* c = gStack;
// while (c>gStackStart) { print(*--c); putchar('\n'); } printf("gStack printed\n");
if (cf>cfStart) {
if (cf>cfStart) { // something wants to catch errors
catchMessage = msg;
cf--;
@ -1207,17 +1208,18 @@ NOINLINE NORETURN void thr(B msg) {
if (cfStart+cf->cfDepth > cf) err("bad catch cfDepth");
cf = cfStart+cf->cfDepth;
longjmp(cf->jmp, 1);
} else { // uncaught error
assert(cf==cfStart);
printf("Error: "); printErrMsg(msg); putchar('\n'); fflush(stdout);
Env* envEnd = envCurr+1;
unwindEnv(envStart-1);
vm_pst(envCurr+1, envEnd);
#ifdef DEBUG
__builtin_trap();
#else
exit(1);
#endif
}
assert(cf==cfStart);
printf("Error: "); printErrMsg(msg); putchar('\n'); fflush(stdout);
Env* envEnd = envCurr+1;
unwindEnv(envStart-1);
vm_pst(envCurr+1, envEnd);
#ifdef DEBUG
__builtin_trap();
#else
exit(1);
#endif
}
NOINLINE NORETURN void thrM(char* s) {