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.
This commit is contained in:
Joel Dice 2013-04-22 21:17:31 -06:00
parent 68c3b241ce
commit e0ceaa5f43

View File

@ -449,6 +449,12 @@ hashMapInsert(Thread* t, object map, object key, object value,
set(t, n, TripleThird, arrayBody(t, array, index));
set(t, array, ArrayBody + (index * BytesPerWord), n);
if (hashMapSize(t, map) <= arrayLength(t, array) / 3) {
// this might happen if nodes were removed during GC in which case
// we weren't able to resize at the time
hashMapResize(t, map, hash, arrayLength(t, array) / 2);
}
}
object
@ -495,7 +501,9 @@ hashMapRemove(Thread* t, object map, object key,
}
}
if (hashMapSize(t, map) <= arrayLength(t, array) / 3) {
if ((not t->m->collecting)
and hashMapSize(t, map) <= arrayLength(t, array) / 3)
{
PROTECT(t, o);
hashMapResize(t, map, hash, arrayLength(t, array) / 2);
}