Skip to content

Commit

Permalink
Pin jl_genericmemory_t if its data is inlined (internal pointer).
Browse files Browse the repository at this point in the history
Differentiate ptr pin and obj pin for hash maps
  • Loading branch information
qinsoon committed Jan 13, 2025
1 parent c81fe48 commit 7aa7e24
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/genericmemory.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ jl_genericmemory_t *_new_genericmemory_(jl_value_t *mtype, size_t nel, int8_t is
m = (jl_genericmemory_t*)jl_gc_alloc(ct->ptls, tot, mtype);
if (pooled) {
data = (char*)m + JL_SMALL_BYTE_ALIGNMENT;
// Data is inlined and ptr is an internal pointer. We pin the object so the ptr will not be invalid.
OBJ_PIN(m);
}
else {
int isaligned = 1; // jl_gc_managed_malloc is always aligned
Expand Down
4 changes: 2 additions & 2 deletions src/ircode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1501,14 +1501,14 @@ void jl_init_serializer(void)

for (i = 2; i < 256; i++) {
if (deser_tag[i]) {
PTRHASH_PIN(deser_tag[i])
OBJHASH_PIN(deser_tag[i])
ptrhash_put(&ser_tag, deser_tag[i], (void*)i);
}
}

i = 2;
while (common_symbols[i-2] != NULL) {
PTRHASH_PIN(common_symbols[i-2])
OBJHASH_PIN(common_symbols[i-2])
ptrhash_put(&common_symbol_tag, common_symbols[i-2], (void*)i);
deser_symbols[i] = (jl_value_t*)common_symbols[i-2];
i += 1;
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ extern "C" {

// FIXME: Pinning objects that get hashed in the ptrhash table
// until we implement address space hashing.
#define OBJHASH_PIN(key) if (key) jl_gc_pin_object(key);
#define PTRHASH_PIN(key) if (key) jl_gc_pin_pointer(key);

// Called when pinning objects that would cause an error if moved
Expand Down
4 changes: 2 additions & 2 deletions src/runtime_ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ jl_value_t *jl_get_cfunction_trampoline(
tramp = trampoline_alloc();
((void**)result)[0] = tramp;
init_trampoline(tramp, nval);
PTRHASH_PIN((void*)fobj)
PTRHASH_PIN(result)
OBJHASH_PIN((void*)fobj)
OBJHASH_PIN(result)
ptrhash_put(cache, (void*)fobj, result);
uv_mutex_unlock(&trampoline_lock);
return result;
Expand Down
14 changes: 7 additions & 7 deletions src/staticdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,8 @@ static int needs_uniquing(jl_value_t *v) JL_NOTSAFEPOINT
static void record_field_change(jl_value_t **addr, jl_value_t *newval) JL_NOTSAFEPOINT
{
if (*addr != newval) {
PTRHASH_PIN((void*)addr)
PTRHASH_PIN((void*)newval)
OBJHASH_PIN((void*)addr)
OBJHASH_PIN((void*)newval)
ptrhash_put(&field_replace, (void*)addr, newval);
}
}
Expand Down Expand Up @@ -2473,8 +2473,8 @@ static jl_svec_t *jl_prune_type_cache_hash(jl_svec_t *cache) JL_GC_DISABLED
assert(serialization_queue.items[from_seroder_entry(idx)] == cache);
cache = cache_rehash_set(cache, sz);
// redirect all references to the old cache to relocate to the new cache object
PTRHASH_PIN((void*)cache)
PTRHASH_PIN((void*)idx)
OBJHASH_PIN((void*)cache)
// OBJHASH_PIN((void*)idx)
ptrhash_put(&serialization_order, cache, idx);
serialization_queue.items[from_seroder_entry(idx)] = cache;
return cache;
Expand Down Expand Up @@ -3676,7 +3676,7 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl
assert(tag == 0);
arraylist_push(&delay_list, obj);
arraylist_push(&delay_list, pfld);
PTRHASH_PIN(obj)
OBJHASH_PIN(obj)
ptrhash_put(&new_dt_objs, (void*)obj, obj); // mark obj as invalid
*pfld = (uintptr_t)NULL;
continue;
Expand Down Expand Up @@ -3711,8 +3711,8 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl
}
static_assert(offsetof(jl_datatype_t, name) == 0, "");
newdt->name = dt->name;
PTRHASH_PIN(newdt)
PTRHASH_PIN(dt)
OBJHASH_PIN(newdt)
OBJHASH_PIN(dt)
ptrhash_put(&new_dt_objs, (void*)newdt, dt);
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/staticdata_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ static void jl_collect_new_roots(htable_t *relocatable_ext_cis, jl_array_t *root
assert(jl_is_code_instance(ci));
jl_method_t *m = ci->def->def.method;
assert(jl_is_method(m));
PTRHASH_PIN(m)
OBJHASH_PIN(m)
ptrhash_put(&mset, (void*)m, (void*)m);
ptrhash_put(relocatable_ext_cis, (void*)ci, (void*)ci);
}
Expand Down
4 changes: 2 additions & 2 deletions src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ static jl_value_t *jl_eval_module_expr(jl_module_t *parent_module, jl_expr_t *ex
jl_value_t *form = (jl_value_t*)newm;
JL_GC_PUSH1(&form);
JL_LOCK(&jl_modules_mutex);
PTRHASH_PIN(newm)
// PTRHASH_PIN((void*)((uintptr_t)HT_NOTFOUND + 1))
OBJHASH_PIN(newm)
// OBJHASH_PIN((void*)((uintptr_t)HT_NOTFOUND + 1))
ptrhash_put(&jl_current_modules, (void*)newm, (void*)((uintptr_t)HT_NOTFOUND + 1));
JL_UNLOCK(&jl_modules_mutex);

Expand Down

0 comments on commit 7aa7e24

Please sign in to comment.