Skip to content

Commit

Permalink
Merge pull request mmtk#31 from udesou/fix/remove-sizeclasses
Browse files Browse the repository at this point in the history
Stop using Julia's size classes when using MMTk
  • Loading branch information
udesou committed Feb 28, 2024
1 parent 75ac661 commit 507dd4e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
4 changes: 1 addition & 3 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,7 @@ JL_DLLEXPORT jl_value_t *jl_alloc_string(size_t len)
// the Allocations Profiler. (See https://github.com/JuliaLang/julia/pull/43868 for more details.)
s = jl_gc_pool_alloc_noinline(ptls, (char*)p - (char*)ptls, osize);
#else
int pool_id = jl_gc_szclass_align8(allocsz);
int osize = jl_gc_sizeclasses[pool_id];
s = jl_mmtk_gc_alloc_default(ptls, pool_id, osize, jl_string_type);
s = jl_mmtk_gc_alloc_default(ptls, allocsz, 8, jl_string_type);
#endif
}
else {
Expand Down
10 changes: 0 additions & 10 deletions src/gc-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,16 +462,6 @@ jl_value_t *jl_gc_pool_alloc_noinline(jl_ptls_t ptls, int pool_offset, int osize
return jl_gc_pool_alloc_inner(ptls, pool_offset, osize);
}

int jl_gc_classify_pools(size_t sz, int *osize)
{
if (sz > GC_MAX_SZCLASS)
return -1;
size_t allocsz = sz + sizeof(jl_taggedvalue_t);
int klass = jl_gc_szclass(allocsz);
*osize = jl_gc_sizeclasses[klass];
return (int)(intptr_t)(&((jl_ptls_t)0)->heap.norm_pools[klass]);
}

// TODO: jl_gc_track_malloced_array needed? Eliminate heap.mallocarrays,
// heap.mafreelist, mallocarray_t?
void jl_gc_track_malloced_array(jl_ptls_t ptls, jl_array_t *a) JL_NOTSAFEPOINT
Expand Down
10 changes: 10 additions & 0 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,16 @@ static NOINLINE jl_taggedvalue_t *gc_add_page(jl_gc_pool_t *p) JL_NOTSAFEPOINT
return fl;
}

int jl_gc_classify_pools(size_t sz, int *osize)
{
if (sz > GC_MAX_SZCLASS)
return -1;
size_t allocsz = sz + sizeof(jl_taggedvalue_t);
int klass = jl_gc_szclass(allocsz);
*osize = jl_gc_sizeclasses[klass];
return (int)(intptr_t)(&((jl_ptls_t)0)->heap.norm_pools[klass]);
}

// Size includes the tag and the tag is not cleared!!
inline jl_value_t *jl_gc_pool_alloc_inner(jl_ptls_t ptls, int pool_offset,
int osize)
Expand Down
6 changes: 2 additions & 4 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ jl_value_t *jl_gc_pool_alloc_noinline(jl_ptls_t ptls, int pool_offset,
int osize);
jl_value_t *jl_gc_big_alloc_noinline(jl_ptls_t ptls, size_t allocsz);
#ifdef MMTK_GC
JL_DLLIMPORT jl_value_t *jl_mmtk_gc_alloc_default(jl_ptls_t ptls, int pool_offset, int osize, void* ty);
JL_DLLIMPORT jl_value_t *jl_mmtk_gc_alloc_default(jl_ptls_t ptls, int osize, size_t align, void* ty);
JL_DLLIMPORT jl_value_t *jl_mmtk_gc_alloc_big(jl_ptls_t ptls, size_t allocsz);
JL_DLLIMPORT extern void mmtk_post_alloc(void* mutator, void* obj, size_t bytes, int allocator);
JL_DLLIMPORT extern void mmtk_initialize_collection(void* tls);
Expand Down Expand Up @@ -488,9 +488,7 @@ STATIC_INLINE jl_value_t *jl_gc_alloc_(jl_ptls_t ptls, size_t sz, void *ty)
jl_value_t *v;
const size_t allocsz = sz + sizeof(jl_taggedvalue_t);
if (sz <= GC_MAX_SZCLASS) {
int pool_id = jl_gc_szclass(allocsz);
int osize = jl_gc_sizeclasses[pool_id];
v = jl_mmtk_gc_alloc_default(ptls, pool_id, osize, ty);
v = jl_mmtk_gc_alloc_default(ptls, allocsz, 16, ty);
}
else {
if (allocsz < sz) // overflow in adding offs, size was "negative"
Expand Down
12 changes: 11 additions & 1 deletion src/mmtk-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ static inline void malloc_maybe_collect(jl_ptls_t ptls, size_t sz)
}
}

// allocation
int jl_gc_classify_pools(size_t sz, int *osize)
{
if (sz > GC_MAX_SZCLASS)
return -1; // call big alloc function
size_t allocsz = sz + sizeof(jl_taggedvalue_t);
*osize = LLT_ALIGN(allocsz, 16);
return 0; // use MMTk's fastpath logic
}

// malloc wrappers, aligned allocation
// We currently just duplicate what Julia GC does. We will in the future replace the malloc calls with MMTK's malloc.
#if defined(_OS_WINDOWS_)
Expand Down Expand Up @@ -212,7 +222,7 @@ inline jl_value_t *jl_gc_pool_alloc_inner(jl_ptls_t ptls, int pool_offset, int o
// TODO: drop this okay?
// maybe_collect(ptls);

jl_value_t *v = jl_mmtk_gc_alloc_default(ptls, pool_offset, osize, NULL);
jl_value_t *v = jl_mmtk_gc_alloc_default(ptls, osize, 16, NULL);
// TODO: this is done (without atomic operations) in jl_mmtk_gc_alloc_default; enable
// here when that's edited?
/*
Expand Down

0 comments on commit 507dd4e

Please sign in to comment.