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) { static NOINLINE void* BN(allocateMore)(i64 bucket, u8 type, i64 from, i64 to) {
u64 sz = BSZ(from); 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; mm_heapAlloc+= sz;
// gc_maybeGC(); // gc_maybeGC();
EmptyValue* c = MMAP(sz); EmptyValue* c = MMAP(sz);

View File

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