Skip to content

Commit

Permalink
remove unused managed realloc (JuliaLang#55050)
Browse files Browse the repository at this point in the history
Follow-up to JuliaLang#54949.

Again, motivation is to clean up the GC interface a bit by removing
unused functions (particularly after the Memory work).
  • Loading branch information
d-netto committed Jul 6, 2024
1 parent 7d4afba commit 082e142
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 80 deletions.
77 changes: 0 additions & 77 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,6 @@ STATIC_INLINE void *jl_malloc_aligned(size_t sz, size_t align)
{
return _aligned_malloc(sz ? sz : 1, align);
}
STATIC_INLINE void *jl_realloc_aligned(void *p, size_t sz, size_t oldsz,
size_t align)
{
(void)oldsz;
return _aligned_realloc(p, sz ? sz : 1, align);
}
STATIC_INLINE void jl_free_aligned(void *p) JL_NOTSAFEPOINT
{
_aligned_free(p);
Expand All @@ -254,27 +248,12 @@ STATIC_INLINE void *jl_malloc_aligned(size_t sz, size_t align)
return NULL;
return ptr;
}
STATIC_INLINE void *jl_realloc_aligned(void *d, size_t sz, size_t oldsz,
size_t align)
{
#if defined(_P64) || defined(__APPLE__)
if (align <= 16)
return realloc(d, sz);
#endif
void *b = jl_malloc_aligned(sz, align);
if (b != NULL) {
memcpy(b, d, oldsz > sz ? sz : oldsz);
free(d);
}
return b;
}
STATIC_INLINE void jl_free_aligned(void *p) JL_NOTSAFEPOINT
{
free(p);
}
#endif
#define malloc_cache_align(sz) jl_malloc_aligned(sz, JL_CACHE_BYTE_ALIGNMENT)
#define realloc_cache_align(p, sz, oldsz) jl_realloc_aligned(p, sz, oldsz, JL_CACHE_BYTE_ALIGNMENT)

static void schedule_finalization(void *o, void *f) JL_NOTSAFEPOINT
{
Expand Down Expand Up @@ -4232,62 +4211,6 @@ JL_DLLEXPORT void *jl_gc_managed_malloc(size_t sz)
return b;
}

static void *gc_managed_realloc_(jl_ptls_t ptls, void *d, size_t sz, size_t oldsz,
int isaligned, jl_value_t *owner, int8_t can_collect)
{
if (can_collect)
maybe_collect(ptls);
int is_old_marked = jl_astaggedvalue(owner)->bits.gc == GC_OLD_MARKED;
size_t allocsz = LLT_ALIGN(sz, JL_CACHE_BYTE_ALIGNMENT);
if (allocsz < sz) // overflow in adding offs, size was "negative"
jl_throw(jl_memory_exception);

int last_errno = errno;
#ifdef _OS_WINDOWS_
DWORD last_error = GetLastError();
#endif
void *b;
if (isaligned)
b = realloc_cache_align(d, allocsz, oldsz);
else
b = realloc(d, allocsz);
if (b == NULL)
jl_throw(jl_memory_exception);
#ifdef _OS_WINDOWS_
SetLastError(last_error);
#endif
errno = last_errno;
// gc_managed_realloc_ is currently used exclusively for resizing array buffers.
if (is_old_marked) {
ptls->gc_cache.perm_scanned_bytes += allocsz - oldsz;
inc_live_bytes(allocsz - oldsz);
}
else if (!(allocsz < oldsz))
jl_atomic_store_relaxed(&ptls->gc_num.allocd,
jl_atomic_load_relaxed(&ptls->gc_num.allocd) + (allocsz - oldsz));
jl_atomic_store_relaxed(&ptls->gc_num.realloc,
jl_atomic_load_relaxed(&ptls->gc_num.realloc) + 1);

int64_t diff = allocsz - oldsz;
if (diff < 0) {
jl_batch_accum_free_size(ptls, -diff);
}
else {
jl_batch_accum_heap_size(ptls, diff);
}
if (allocsz > oldsz) {
maybe_record_alloc_to_profile((jl_value_t*)b, allocsz - oldsz, (jl_datatype_t*)jl_buff_tag);
}
return b;
}

JL_DLLEXPORT void *jl_gc_managed_realloc(void *d, size_t sz, size_t oldsz,
int isaligned, jl_value_t *owner)
{
jl_ptls_t ptls = jl_current_task->ptls;
return gc_managed_realloc_(ptls, d, sz, oldsz, isaligned, owner, 1);
}

// Perm gen allocator
// 2M pool
#define GC_PERM_POOL_SIZE (2 * 1024 * 1024)
Expand Down
1 change: 0 additions & 1 deletion src/jl_exported_funcs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@
XX(jl_gc_pool_live_bytes) \
XX(jl_gc_live_bytes) \
XX(jl_gc_managed_malloc) \
XX(jl_gc_managed_realloc) \
XX(jl_gc_mark_queue_obj) \
XX(jl_gc_mark_queue_objarray) \
XX(jl_gc_max_internal_obj_size) \
Expand Down
2 changes: 0 additions & 2 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1105,8 +1105,6 @@ STATIC_INLINE void jl_gc_multi_wb(const void *parent, const jl_value_t *ptr) JL_
}

JL_DLLEXPORT void *jl_gc_managed_malloc(size_t sz);
JL_DLLEXPORT void *jl_gc_managed_realloc(void *d, size_t sz, size_t oldsz,
int isaligned, jl_value_t *owner);
JL_DLLEXPORT void jl_gc_safepoint(void);
JL_DLLEXPORT int jl_safepoint_suspend_thread(int tid, int waitstate);
JL_DLLEXPORT int jl_safepoint_resume_thread(int tid) JL_NOTSAFEPOINT;
Expand Down

0 comments on commit 082e142

Please sign in to comment.