summaryrefslogtreecommitdiff
path: root/alloc.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2021-09-11 12:54:18 +0300
committerIvan Maidanski <ivmai@mail.ru>2021-09-11 12:54:18 +0300
commitb7a182848a85f9663f4d3d3fd5759782fe0cba3b (patch)
tree19f3f94d4f6ff86d480ebfdd0dee32a44f78fdb5 /alloc.c
parent3e30dd469a6da0962b359390bb426b20af422d6a (diff)
downloadbdwgc-b7a182848a85f9663f4d3d3fd5759782fe0cba3b.tar.gz
Fix missing heap limits adjustment if scratch_recycle_inner is called
(fix of commit fde97b79c) * alloc.c (GC_add_to_heap): Reformat comment; rename to add_to_heap_inner and make it static. * alloc.c (GC_expand_hp_inner): Move expansion_slop and portion of code to the new function (GC_add_to_heap). * alloc.c (GC_add_to_heap): New function (which adjusts heap limits and calls add_to_heap_inner).
Diffstat (limited to 'alloc.c')
-rw-r--r--alloc.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/alloc.c b/alloc.c
index 1dc1e80f..97767a9c 100644
--- a/alloc.c
+++ b/alloc.c
@@ -1342,11 +1342,9 @@ GC_API void GC_CALL GC_gcollect_and_unmap(void)
}
#endif
-/*
- * Use the chunk of memory starting at p of size bytes as part of the heap.
- * Assumes p is HBLKSIZE aligned, and bytes is a multiple of HBLKSIZE.
- */
-GC_INNER void GC_add_to_heap(struct hblk *p, size_t bytes)
+/* Use the chunk of memory starting at p of size bytes as part of the heap. */
+/* Assumes p is HBLKSIZE aligned, and bytes is a multiple of HBLKSIZE. */
+static void add_to_heap_inner(struct hblk *p, size_t bytes)
{
hdr * phdr;
word endp;
@@ -1460,8 +1458,6 @@ GC_INNER GC_bool GC_expand_hp_inner(word n)
{
size_t bytes;
struct hblk * space;
- word expansion_slop; /* Number of bytes by which we expect the */
- /* heap to expand soon. */
GC_ASSERT(I_HOLD_LOCK());
GC_ASSERT(GC_page_size != 0);
@@ -1483,10 +1479,19 @@ GC_INNER GC_bool GC_expand_hp_inner(word n)
GC_INFOLOG_PRINTF("Grow heap to %lu KiB after %lu bytes allocated\n",
TO_KiB_UL(GC_heapsize + (word)bytes),
(unsigned long)GC_bytes_allocd);
+ GC_add_to_heap(space, bytes);
+ return TRUE;
+}
+
+GC_INNER void GC_add_to_heap(struct hblk * space, size_t bytes)
+{
+ word expansion_slop = min_bytes_allocd() + 4 * MAXHINCR * HBLKSIZE;
+ /* Number of bytes by which we expect */
+ /* the heap to expand soon. */
+
/* Adjust heap limits generously for blacklisting to work better. */
- /* GC_add_to_heap performs minimal adjustment needed for */
+ /* add_to_heap_inner performs minimal adjustment needed for */
/* correctness. */
- expansion_slop = min_bytes_allocd() + 4*MAXHINCR*HBLKSIZE;
if ((GC_last_heap_addr == 0 && !((word)space & SIGNB))
|| (GC_last_heap_addr != 0
&& (word)GC_last_heap_addr < (word)space)) {
@@ -1508,7 +1513,9 @@ GC_INNER GC_bool GC_expand_hp_inner(word n)
}
GC_prev_heap_addr = GC_last_heap_addr;
GC_last_heap_addr = (ptr_t)space;
- GC_add_to_heap(space, bytes);
+
+ add_to_heap_inner(space, bytes);
+
/* Force GC before we are likely to allocate past expansion_slop */
GC_collect_at_heapsize =
GC_heapsize + expansion_slop - 2*MAXHINCR*HBLKSIZE;
@@ -1516,8 +1523,6 @@ GC_INNER GC_bool GC_expand_hp_inner(word n)
GC_collect_at_heapsize = GC_WORD_MAX;
if (GC_on_heap_resize)
(*GC_on_heap_resize)(GC_heapsize);
-
- return(TRUE);
}
/* Really returns a bool, but it's externally visible, so that's clumsy. */