Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using Julia's size classes when using MMTk #31

Merged
merged 6 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -450,16 +450,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 @@ -902,6 +902,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 @@ -337,7 +337,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 @@ -491,9 +491,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 @@ -53,6 +53,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)
qinsoon marked this conversation as resolved.
Show resolved Hide resolved
{
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.

Expand Down Expand Up @@ -157,7 +167,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