From e0ceaa5f435eedfd25040cd812aca91b40936934 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 22 Apr 2013 21:17:31 -0600 Subject: [PATCH] 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. --- src/util.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/util.cpp b/src/util.cpp index 248277aef6..1421824919 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -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); }