mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-04 19:56:34 +02:00
gc: free unused parts of the heap before merging
When a thread exits, the heap is merged into the main thread. Before doing so, free any unused parts of the heap to reduce memory usage. Attempts to partially address issue #534.
This commit is contained in:
parent
bf9dda2fed
commit
20fc3c6646
1 changed files with 21 additions and 1 deletions
22
gc.c
22
gc.c
|
@ -2762,12 +2762,32 @@ void gc_heap_merge(gc_heap * hdest, gc_heap * hsrc)
|
||||||
*/
|
*/
|
||||||
void gc_merge_all_heaps(gc_thread_data * dest, gc_thread_data * src)
|
void gc_merge_all_heaps(gc_thread_data * dest, gc_thread_data * src)
|
||||||
{
|
{
|
||||||
gc_heap *hdest, *hsrc;
|
gc_heap *hdest, *hsrc, *cur, *prev;
|
||||||
int heap_type;
|
int heap_type;
|
||||||
|
|
||||||
for (heap_type = 0; heap_type < NUM_HEAP_TYPES; heap_type++) {
|
for (heap_type = 0; heap_type < NUM_HEAP_TYPES; heap_type++) {
|
||||||
hdest = dest->heap->heap[heap_type];
|
hdest = dest->heap->heap[heap_type];
|
||||||
hsrc = src->heap->heap[heap_type];
|
hsrc = src->heap->heap[heap_type];
|
||||||
|
if (!hdest) {
|
||||||
|
fprintf(stderr, "WARNING !!!!! merging heap type %d does not happen: hdest = %p hsrc = %p size = %d\n",
|
||||||
|
heap_type, hdest, hsrc, hsrc->size);
|
||||||
|
fflush(stderr);
|
||||||
|
}
|
||||||
|
if (hsrc) {
|
||||||
|
prev = hsrc;
|
||||||
|
cur = hsrc->next;
|
||||||
|
while (cur != NULL) {
|
||||||
|
if (gc_is_heap_empty(cur)) {
|
||||||
|
gc_heap_free(cur, prev);
|
||||||
|
}
|
||||||
|
prev = prev->next;
|
||||||
|
cur = prev->next;
|
||||||
|
}
|
||||||
|
if (gc_is_heap_empty(hsrc) && hsrc->next == NULL) {
|
||||||
|
free(hsrc);
|
||||||
|
hsrc = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (hdest && hsrc) {
|
if (hdest && hsrc) {
|
||||||
gc_heap_merge(hdest, hsrc);
|
gc_heap_merge(hdest, hsrc);
|
||||||
ck_pr_add_ptr(&(dest->cached_heap_total_sizes[heap_type]),
|
ck_pr_add_ptr(&(dest->cached_heap_total_sizes[heap_type]),
|
||||||
|
|
Loading…
Add table
Reference in a new issue