|
9 | 9 | #include "julia_atomics.h" |
10 | 10 | #include "julia_gcext.h" |
11 | 11 | #include "julia_assert.h" |
12 | | -#ifdef __GLIBC__ |
13 | | -#include <malloc.h> // for malloc_trim |
14 | | -#endif |
15 | 12 |
|
16 | 13 | #ifdef __cplusplus |
17 | 14 | extern "C" { |
@@ -579,11 +576,6 @@ void jl_gc_count_allocd(size_t sz) JL_NOTSAFEPOINT |
579 | 576 | jl_batch_accum_heap_size(ptls, sz); |
580 | 577 | } |
581 | 578 |
|
582 | | -void jl_gc_count_freed(size_t sz) JL_NOTSAFEPOINT |
583 | | -{ |
584 | | - jl_batch_accum_free_size(jl_current_task->ptls, sz); |
585 | | -} |
586 | | - |
587 | 579 | // Only safe to update the heap inside the GC |
588 | 580 | static void combine_thread_gc_counts(jl_gc_num_t *dest, int update_heap) JL_NOTSAFEPOINT |
589 | 581 | { |
@@ -664,13 +656,15 @@ static void jl_gc_free_memory(jl_value_t *v, int isaligned) JL_NOTSAFEPOINT |
664 | 656 | jl_genericmemory_t *m = (jl_genericmemory_t*)v; |
665 | 657 | assert(jl_genericmemory_how(m) == 1 || jl_genericmemory_how(m) == 2); |
666 | 658 | char *d = (char*)m->ptr; |
| 659 | + size_t freed_bytes = memory_block_usable_size(d); |
| 660 | + assert(freed_bytes != 0); |
667 | 661 | if (isaligned) |
668 | 662 | jl_free_aligned(d); |
669 | 663 | else |
670 | 664 | free(d); |
671 | 665 | jl_atomic_store_relaxed(&gc_heap_stats.heap_size, |
672 | | - jl_atomic_load_relaxed(&gc_heap_stats.heap_size) - jl_genericmemory_nbytes(m)); |
673 | | - gc_num.freed += jl_genericmemory_nbytes(m); |
| 666 | + jl_atomic_load_relaxed(&gc_heap_stats.heap_size) - freed_bytes); |
| 667 | + gc_num.freed += freed_bytes; |
674 | 668 | gc_num.freecall++; |
675 | 669 | } |
676 | 670 |
|
@@ -3739,11 +3733,13 @@ JL_DLLEXPORT void *jl_gc_managed_malloc(size_t sz) |
3739 | 3733 | if (b == NULL) |
3740 | 3734 | jl_throw(jl_memory_exception); |
3741 | 3735 |
|
| 3736 | + size_t allocated_bytes = memory_block_usable_size(b); |
| 3737 | + assert(allocated_bytes >= allocsz); |
3742 | 3738 | jl_atomic_store_relaxed(&ptls->gc_tls.gc_num.allocd, |
3743 | | - jl_atomic_load_relaxed(&ptls->gc_tls.gc_num.allocd) + allocsz); |
| 3739 | + jl_atomic_load_relaxed(&ptls->gc_tls.gc_num.allocd) + allocated_bytes); |
3744 | 3740 | jl_atomic_store_relaxed(&ptls->gc_tls.gc_num.malloc, |
3745 | 3741 | jl_atomic_load_relaxed(&ptls->gc_tls.gc_num.malloc) + 1); |
3746 | | - jl_batch_accum_heap_size(ptls, allocsz); |
| 3742 | + jl_batch_accum_heap_size(ptls, allocated_bytes); |
3747 | 3743 | #ifdef _OS_WINDOWS_ |
3748 | 3744 | SetLastError(last_error); |
3749 | 3745 | #endif |
|
0 commit comments