preallocate oom message

This commit is contained in:
dzaima 2022-01-12 14:05:08 +02:00
parent c4136d4a53
commit 3536c351fa
2 changed files with 5 additions and 3 deletions

View File

@ -37,7 +37,7 @@ 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) {
if (sz>100000) thrM("Heap size limit reached"); // if allocating a large thing, it should be possible to recover
if (sz>100000) thrOOM(); // if allocating a large thing, it may be possible to recover
printf("Heap size limit reached\n"); abort();
}
mm_heapAlloc+= sz;

View File

@ -988,7 +988,7 @@ void print_vmStack() {
#endif
}
B oomMessage;
void comp_init() {
TIi(t_comp ,freeO) = comp_freeO; TIi(t_comp ,freeF) = comp_freeF; TIi(t_comp ,visit) = comp_visit; TIi(t_comp ,print) = comp_print;
@ -1007,6 +1007,8 @@ void comp_init() {
TIi(t_funBl,fn_iw) = funBl_iw; TIi(t_md1Bl,m1_iw) = md1Bl_iw; TIi(t_md2Bl,m2_iw) = md2Bl_iw;
TIi(t_funBl,fn_ix) = funBl_ix; TIi(t_md1Bl,m1_ix) = md1Bl_ix; TIi(t_md2Bl,m2_ix) = md2Bl_ix;
oomMessage = m_str8l("Out of memory"); gc_add(oomMessage);
#ifndef GS_REALLOC
allocStack((void**)&gStack, (void**)&gStackStart, (void**)&gStackEnd, sizeof(B), GS_SIZE);
#endif
@ -1254,4 +1256,4 @@ NOINLINE void freeThrown() {
NOINLINE NORETURN void thrM(char* s) {
thr(fromUTF8(s, strlen(s)));
}
NOINLINE NORETURN void thrOOM() { thrM("Out of memory"); }
NOINLINE NORETURN void thrOOM() { thr(inc(oomMessage)); }