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

Refactoring code in mk_symbol to remove stock specific code #57214

Merged
merged 2 commits into from
Feb 6, 2025
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
16 changes: 8 additions & 8 deletions src/datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ STATIC_INLINE void jl_maybe_allocate_singleton_instance(jl_datatype_t *st) JL_NO
if (st->instance)
return;
if (jl_is_datatype_make_singleton(st)) {
st->instance = jl_gc_permobj(0, st);
st->instance = jl_gc_permobj(0, st, 0);
}
}

Expand Down Expand Up @@ -575,7 +575,7 @@ void jl_get_genericmemory_layout(jl_datatype_t *st)

if (jl_is_addrspacecore(addrspace) && jl_unbox_uint8(addrspace) == 0) {
if (kind == (jl_value_t*)jl_not_atomic_sym || kind == (jl_value_t*)jl_atomic_sym) {
jl_genericmemory_t *zeroinst = (jl_genericmemory_t*)jl_gc_permobj(LLT_ALIGN(sizeof(jl_genericmemory_t), JL_SMALL_BYTE_ALIGNMENT) + (elsz ? elsz : isunion), st);
jl_genericmemory_t *zeroinst = (jl_genericmemory_t*)jl_gc_permobj(LLT_ALIGN(sizeof(jl_genericmemory_t), JL_SMALL_BYTE_ALIGNMENT) + (elsz ? elsz : isunion), st, 0);
zeroinst->length = 0;
zeroinst->ptr = (char*)zeroinst + JL_SMALL_BYTE_ALIGNMENT;
memset(zeroinst->ptr, 0, elsz ? elsz : isunion);
Expand Down Expand Up @@ -1385,13 +1385,13 @@ JL_DLLEXPORT int jl_atomic_storeonce_bits(jl_datatype_t *dt, char *dst, const jl
return success;
}

#define PERMBOXN_FUNC(nb) \
#define PERMBOXN_FUNC(nb) \
jl_value_t *jl_permbox##nb(jl_datatype_t *t, uintptr_t tag, uint##nb##_t x) \
{ /* n.b. t must be a concrete isbits datatype of the right size */ \
jl_value_t *v = jl_gc_permobj(LLT_ALIGN(nb, sizeof(void*)), t); \
if (tag) jl_set_typetagof(v, tag, GC_OLD_MARKED); \
*(uint##nb##_t*)jl_data_ptr(v) = x; \
return v; \
{ /* n.b. t must be a concrete isbits datatype of the right size */ \
jl_value_t *v = jl_gc_permobj(LLT_ALIGN(nb, sizeof(void*)), t, 0); \
if (tag) jl_set_typetagof(v, tag, GC_OLD_MARKED); \
*(uint##nb##_t*)jl_data_ptr(v) = x; \
return v; \
}
PERMBOXN_FUNC(8)
PERMBOXN_FUNC(16)
Expand Down
5 changes: 4 additions & 1 deletion src/gc-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,15 @@ JL_DLLEXPORT void *jl_gc_perm_alloc(size_t sz, int zero, unsigned align,
// object header must be included in the object size. This object is allocated in an
// immortal region that is never swept. The second parameter specifies the type of the
// object being allocated and will be used to set the object header.
// If the value passed as alignment is 0, then the result will be aligned according to the object
// size: if sz is 0 it will be aligned to pointer size, to 2x pointer size if sz < 2*sizeof(void*),
// or to 16 otherwise.
//
// !!! warning: Because permanently allocated objects are not swept, the GC will not
// necessarily mark any objects that would have ordinarily been rooted by
// the allocated object. All objects stored in fields of this object
// must be either permanently allocated or have other roots.
struct _jl_value_t *jl_gc_permobj(size_t sz, void *ty) JL_NOTSAFEPOINT;
struct _jl_value_t *jl_gc_permobj(size_t sz, void *ty, unsigned align) JL_NOTSAFEPOINT;
// This function notifies the GC about memory addresses that are set when loading the boot image.
// The GC may use that information to, for instance, determine that such objects should
// be treated as marked and belonged to the old generation in nursery collections.
Expand Down
6 changes: 4 additions & 2 deletions src/gc-mmtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,11 +1028,13 @@ void *jl_gc_perm_alloc(size_t sz, int zero, unsigned align, unsigned offset)
return jl_gc_perm_alloc_nolock(sz, zero, align, offset);
}

jl_value_t *jl_gc_permobj(size_t sz, void *ty) JL_NOTSAFEPOINT
jl_value_t *jl_gc_permobj(size_t sz, void *ty, unsigned align) JL_NOTSAFEPOINT
{
const size_t allocsz = sz + sizeof(jl_taggedvalue_t);
unsigned align = (sz == 0 ? sizeof(void*) : (allocsz <= sizeof(void*) * 2 ?
if (align == 0) {
align = ((sz == 0) ? sizeof(void*) : (allocsz <= sizeof(void*) * 2 ?
sizeof(void*) * 2 : 16));
}
jl_taggedvalue_t *o = (jl_taggedvalue_t*)jl_gc_perm_alloc(allocsz, 0, align,
sizeof(void*) % align);

Expand Down
12 changes: 7 additions & 5 deletions src/gc-stock.c
Original file line number Diff line number Diff line change
Expand Up @@ -3928,16 +3928,18 @@ void *jl_gc_perm_alloc(size_t sz, int zero, unsigned align, unsigned offset)
return p;
}

jl_value_t *jl_gc_permobj(size_t sz, void *ty) JL_NOTSAFEPOINT
jl_value_t *jl_gc_permobj(size_t sz, void *ty, unsigned align) JL_NOTSAFEPOINT
{
const size_t allocsz = sz + sizeof(jl_taggedvalue_t);
unsigned align = (sz == 0 ? sizeof(void*) : (allocsz <= sizeof(void*) * 2 ?
if (align == 0) {
align = ((sz == 0) ? sizeof(void*) : (allocsz <= sizeof(void*) * 2 ?
sizeof(void*) * 2 : 16));
}
jl_taggedvalue_t *o = (jl_taggedvalue_t*)jl_gc_perm_alloc(allocsz, 0, align,
sizeof(void*) % align);
uintptr_t tag = (uintptr_t)ty;
o->header = tag | GC_OLD_MARKED;
return jl_valueof(o);
jl_value_t* v = jl_valueof(o);
jl_set_typeof(v, (void*)(((uintptr_t)(ty) | GC_OLD_MARKED)));
return v;
}

JL_DLLEXPORT int jl_gc_enable_conservative_gc_support(void)
Expand Down
6 changes: 3 additions & 3 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2956,7 +2956,7 @@ void jl_init_types(void) JL_GC_DISABLED
XX(simplevector);
jl_methtable_type = jl_new_uninitialized_datatype();

jl_emptysvec = (jl_svec_t*)jl_gc_permobj(sizeof(void*), jl_simplevector_type);
jl_emptysvec = (jl_svec_t*)jl_gc_permobj(sizeof(void*), jl_simplevector_type, 0);
jl_set_typetagof(jl_emptysvec, jl_simplevector_tag, GC_OLD_MARKED);
jl_svec_set_len_unsafe(jl_emptysvec, 0);

Expand Down Expand Up @@ -3088,7 +3088,7 @@ void jl_init_types(void) JL_GC_DISABLED
jl_typeofbottom_type = jl_new_datatype(jl_symbol("TypeofBottom"), core, type_type, jl_emptysvec,
jl_emptysvec, jl_emptysvec, jl_emptysvec, 0, 0, 0);
XX(typeofbottom);
jl_bottom_type = jl_gc_permobj(0, jl_typeofbottom_type);
jl_bottom_type = jl_gc_permobj(0, jl_typeofbottom_type, 0);
jl_set_typetagof(jl_bottom_type, jl_typeofbottom_tag, GC_OLD_MARKED);
jl_typeofbottom_type->instance = jl_bottom_type;

Expand Down Expand Up @@ -3138,7 +3138,7 @@ void jl_init_types(void) JL_GC_DISABLED
jl_typeofbottom_type->super = jl_wrap_Type(jl_bottom_type);
jl_typeofbottom_type->super->layout = jl_typeofbottom_type->layout; // the only abstract type with a layout
jl_emptytuple_type = (jl_datatype_t*)jl_apply_tuple_type(jl_emptysvec, 0);
jl_emptytuple = jl_gc_permobj(0, jl_emptytuple_type);
jl_emptytuple = jl_gc_permobj(0, jl_emptytuple_type, 0);
jl_emptytuple_type->instance = jl_emptytuple;

// non-primitive definitions follow
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ jl_value_t *jl_get_cfunction_trampoline(
permanent = true;
}
if (permanent) {
result = jl_gc_permobj(sizeof(jl_taggedvalue_t) + jl_datatype_size(result_type), result_type);
result = jl_gc_permobj(sizeof(jl_taggedvalue_t) + jl_datatype_size(result_type), result_type, 0);
memset(result, 0, jl_datatype_size(result_type));
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/simplevector.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ JL_DLLEXPORT jl_svec_t *(ijl_svec)(size_t n, ...)
jl_svec_t *(jl_perm_symsvec)(size_t n, ...)
{
if (n == 0) return jl_emptysvec;
jl_svec_t *jv = (jl_svec_t*)jl_gc_permobj((n + 1) * sizeof(void*), jl_simplevector_type);
jl_svec_t *jv = (jl_svec_t*)jl_gc_permobj((n + 1) * sizeof(void*), jl_simplevector_type, 0);
jl_set_typetagof(jv, jl_simplevector_tag, jl_astaggedvalue(jv)->bits.gc);
jl_svec_set_len_unsafe(jv, n);
va_list args;
Expand Down
2 changes: 1 addition & 1 deletion src/staticdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -3750,7 +3750,7 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl
// and we overwrite the name field (field 0) now so preserve it too
if (dt->instance) {
if (dt->instance == jl_nothing)
dt->instance = jl_gc_permobj(0, newdt);
dt->instance = jl_gc_permobj(0, newdt, 0);
newdt->instance = dt->instance;
}
static_assert(offsetof(jl_datatype_t, name) == 0, "");
Expand Down
10 changes: 5 additions & 5 deletions src/symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ static uintptr_t hash_symbol(const char *str, size_t len) JL_NOTSAFEPOINT

static size_t symbol_nbytes(size_t len) JL_NOTSAFEPOINT
{
return (sizeof(jl_taggedvalue_t) + sizeof(jl_sym_t) + len + 1 + 7) & -8;
return ((sizeof(jl_sym_t) + len + 1 + 7) & -8);
}

static jl_sym_t *mk_symbol(const char *str, size_t len) JL_NOTSAFEPOINT
{
jl_sym_t *sym;
size_t nb = symbol_nbytes(len);
jl_taggedvalue_t *tag = (jl_taggedvalue_t*)jl_gc_perm_alloc(nb, 0, sizeof(void*), 0);
sym = (jl_sym_t*)jl_valueof(tag);
// set to old marked so that we won't look at it in the GC or write barrier.
// jl_sym_t is an object and needs to be allocated with jl_gc_permobj
// but its type is set below with jl_set_typetagof since
// jl_symbol_type might not have been initialized
jl_sym_t *sym = (jl_sym_t*)jl_gc_permobj(nb, NULL, sizeof(void*));
jl_set_typetagof(sym, jl_symbol_tag, GC_OLD_MARKED);
jl_atomic_store_relaxed(&sym->left, NULL);
jl_atomic_store_relaxed(&sym->right, NULL);
Expand Down
2 changes: 1 addition & 1 deletion src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ jl_task_t *jl_init_root_task(jl_ptls_t ptls, void *stack_lo, void *stack_hi)
jl_set_pgcstack(&bootstrap_task.value.gcstack);
bootstrap_task.value.ptls = ptls;
if (jl_nothing == NULL) // make a placeholder
jl_nothing = jl_gc_permobj(0, jl_nothing_type);
jl_nothing = jl_gc_permobj(0, jl_nothing_type, 0);
jl_task_t *ct = (jl_task_t*)jl_gc_alloc(ptls, sizeof(jl_task_t), jl_task_type);
jl_set_typetagof(ct, jl_task_tag, 0);
memset(ct, 0, sizeof(jl_task_t));
Expand Down