Skip to content

Commit e0ceaa5

Browse files
committed
avoid allocating new memory in hashMapRemove when GCing
This ensures that we don't abort when running an internal finalizer that removes from a hash map.
1 parent 68c3b24 commit e0ceaa5

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/util.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,12 @@ hashMapInsert(Thread* t, object map, object key, object value,
449449

450450
set(t, n, TripleThird, arrayBody(t, array, index));
451451
set(t, array, ArrayBody + (index * BytesPerWord), n);
452+
453+
if (hashMapSize(t, map) <= arrayLength(t, array) / 3) {
454+
// this might happen if nodes were removed during GC in which case
455+
// we weren't able to resize at the time
456+
hashMapResize(t, map, hash, arrayLength(t, array) / 2);
457+
}
452458
}
453459

454460
object
@@ -495,7 +501,9 @@ hashMapRemove(Thread* t, object map, object key,
495501
}
496502
}
497503

498-
if (hashMapSize(t, map) <= arrayLength(t, array) / 3) {
504+
if ((not t->m->collecting)
505+
and hashMapSize(t, map) <= arrayLength(t, array) / 3)
506+
{
499507
PROTECT(t, o);
500508
hashMapResize(t, map, hash, arrayLength(t, array) / 2);
501509
}

0 commit comments

Comments
 (0)