Skip to content

Commit

Permalink
make jl_methtable_t->frozen an atomic field
Browse files Browse the repository at this point in the history
  • Loading branch information
fatteneder committed Oct 18, 2024
1 parent ebb4150 commit 7eb6711
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion base/runtime_internals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ function morespecific!(m::Method)
# check that all Methods in this table are morespecific than m
# so we might avoid disabling a table that might get used for more than just subsets of m
all(m2 -> m === m2 || morespecific(m2, m), MethodList(mt)) || error("unsupported Method to disable")
setfield!(mt, nfields(mt), 0x1)
setfield!(mt, :frozen, 0x1, :monotonic)
end

"""
Expand Down
2 changes: 1 addition & 1 deletion src/datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ JL_DLLEXPORT jl_methtable_t *jl_new_method_table(jl_sym_t *name, jl_module_t *mo
mt->backedges = NULL;
JL_MUTEX_INIT(&mt->writelock, "methodtable->writelock");
mt->offs = 0;
mt->frozen = 0;
jl_atomic_store_relaxed(&mt->frozen, 0);
return mt;
}

Expand Down
4 changes: 2 additions & 2 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ jl_datatype_t *jl_mk_builtin_func(jl_datatype_t *dt, const char *name, jl_fptr_a
(jl_value_t*)mi, 1, ~(size_t)0);
jl_typemap_insert(&mt->cache, (jl_value_t*)mt, newentry, 0);

mt->frozen = 1;
jl_atomic_store_relaxed(&mt->frozen, 1);
JL_GC_POP();
return dt;
}
Expand Down Expand Up @@ -772,7 +772,7 @@ static int reset_mt_caches(jl_methtable_t *mt, void *env)
{
// removes all method caches
// this might not be entirely safe (GC or MT), thus we only do it very early in bootstrapping
if (!mt->frozen) { // make sure not to reset frozen functions
if (!jl_atomic_load_relaxed(&mt->frozen)) { // make sure not to reset frozen functions
jl_atomic_store_release(&mt->leafcache, (jl_genericmemory_t*)jl_an_empty_memory_any);
jl_atomic_store_release(&mt->cache, jl_nothing);
}
Expand Down
4 changes: 2 additions & 2 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3038,9 +3038,9 @@ void jl_init_types(void) JL_GC_DISABLED
jl_methtable_type->name->names = jl_perm_symsvec(11, "name", "defs",
"leafcache", "cache", "max_args",
"module", "backedges",
"", "", "offs", "");
"", "", "offs", "frozen");
const static uint32_t methtable_constfields[1] = { 0x00000020 }; // (1<<5);
const static uint32_t methtable_atomicfields[1] = { 0x0000001e }; // (1<<1)|(1<<2)|(1<<3)|(1<<4);
const static uint32_t methtable_atomicfields[1] = { 0x00000041e }; // (1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<10);
jl_methtable_type->name->constfields = methtable_constfields;
jl_methtable_type->name->atomicfields = methtable_atomicfields;
jl_precompute_memoized_dt(jl_methtable_type, 1);
Expand Down
2 changes: 1 addition & 1 deletion src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ typedef struct _jl_methtable_t {
jl_array_t *backedges; // (sig, caller::MethodInstance) pairs
jl_mutex_t writelock;
uint8_t offs; // 0, or 1 to skip splitting typemap on first (function) argument
uint8_t frozen; // whether this accepts adding new methods
_Atomic(uint8_t) frozen; // whether this accepts adding new methods
} jl_methtable_t;

typedef struct {
Expand Down
2 changes: 1 addition & 1 deletion src/staticdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ static void jl_insert_into_serialization_queue(jl_serializer_state *s, jl_value_
}
else if (jl_typetagis(v, jl_typename_type)) {
jl_typename_t *tn = (jl_typename_t*)v;
if (tn->mt != NULL && !tn->mt->frozen) {
if (tn->mt != NULL && !jl_atomic_load_relaxed(&tn->mt->frozen)) {
jl_methtable_t * new_methtable = (jl_methtable_t *)ptrhash_get(&new_methtables, tn->mt);
if (new_methtable != HT_NOTFOUND)
record_field_change((jl_value_t **)&tn->mt, (jl_value_t*)new_methtable);
Expand Down

0 comments on commit 7eb6711

Please sign in to comment.