Skip to content

Commit

Permalink
Port PR mmtk#42 and mmtk#44 to master (mmtk#48)
Browse files Browse the repository at this point in the history
* Call initialize_collection before enabling GC (mmtk#44)
* Fix build with stock GC: mmtk_pin_object is conditionaly compiled (mmtk#42)
  • Loading branch information
qinsoon authored May 10, 2024
1 parent 6f5f685 commit d907a06
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ JL_DLLEXPORT jl_array_t *jl_reshape_array(jl_value_t *atype, jl_array_t *data,
// introspect the object to update the a->data field. To avoid doing that and
// making scan_object much more complex we simply enforce that both owner and
// buffers are always pinned
mmtk_pin_object(owner);
PTR_PIN(owner);
a->flags.how = 3;
a->data = data->data;
a->flags.isshared = 1;
Expand Down Expand Up @@ -296,7 +296,7 @@ JL_DLLEXPORT jl_array_t *jl_string_to_array(jl_value_t *str)
// introspect the object to update the a->data field. To avoid doing that and
// making scan_object much more complex we simply enforce that both owner and
// buffers are always pinned
mmtk_pin_object(str);
PTR_PIN(str);
a->flags.how = 3;
a->flags.isshared = 1;
size_t l = jl_string_len(str);
Expand Down Expand Up @@ -695,7 +695,7 @@ static int NOINLINE array_resize_buffer(jl_array_t *a, size_t newlen)
// introspect the object to update the a->data field. To avoid doing that and
// making scan_object much more complex we simply enforce that both owner and
// buffers are always pinned
mmtk_pin_object(s);
PTR_PIN(s);
jl_array_data_owner(a) = s;
jl_gc_wb(a, s);
a->data = jl_string_data(s);
Expand Down
6 changes: 3 additions & 3 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ static uintptr_t type_object_id_(jl_value_t *v, jl_varidx_t *env) JL_NOTSAFEPOIN
}
// FIXME: Pinning objects that get hashed
// until we implement address space hashing.
mmtk_pin_object(v);
PTR_PIN(v);
return inthash((uintptr_t)v);
}
if (tv == jl_uniontype_type) {
Expand Down Expand Up @@ -398,7 +398,7 @@ static uintptr_t immut_id_(jl_datatype_t *dt, jl_value_t *v, uintptr_t h) JL_NOT

// FIXME: Pinning objects that get hashed
// until we implement address space hashing.
mmtk_pin_object(v);
PTR_PIN(v);
// operate element-wise if there are unused bits inside,
// otherwise just take the whole data block at once
// a few select pointers (notably symbol) also have special hash values
Expand Down Expand Up @@ -462,7 +462,7 @@ static uintptr_t NOINLINE jl_object_id__cold(jl_datatype_t *dt, jl_value_t *v) J
if (dt->name->mutabl) {
// FIXME: Pinning objects that get hashed
// until we implement address space hashing.
mmtk_pin_object(v);
PTR_PIN(v);
return inthash((uintptr_t)v);
}
return immut_id_(dt, v, dt->hash);
Expand Down
4 changes: 2 additions & 2 deletions src/datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ JL_DLLEXPORT jl_typename_t *jl_new_typename_in(jl_sym_t *name, jl_module_t *modu
jl_typename_type);
// Typenames should be pinned since they are used as metadata, and are
// read during scan_object
mmtk_pin_object(tn);
PTR_PIN(tn);
tn->name = name;
tn->module = module;
tn->wrapper = NULL;
Expand Down Expand Up @@ -101,7 +101,7 @@ jl_datatype_t *jl_new_uninitialized_datatype(void)
jl_datatype_t *t = (jl_datatype_t*)jl_gc_alloc(ct->ptls, sizeof(jl_datatype_t), jl_datatype_type);
// Types should be pinned since they are used as metadata, and are
// read during scan_object
mmtk_pin_object(t);
PTR_PIN(t);
jl_set_typetagof(t, jl_datatype_tag, 0);
t->hash = 0;
t->hasfreetypevars = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,9 +833,6 @@ JL_DLLEXPORT void julia_init(JL_IMAGE_SEARCH rel)
#pragma GCC diagnostic pop
JL_GC_PROMISE_ROOTED(ct);
_finish_julia_init(rel, ptls, ct);
#ifdef MMTK_GC
mmtk_initialize_collection((void *)ptls);
#endif
}

static NOINLINE void _finish_julia_init(JL_IMAGE_SEARCH rel, jl_ptls_t ptls, jl_task_t *ct)
Expand Down Expand Up @@ -883,6 +880,9 @@ static NOINLINE void _finish_julia_init(JL_IMAGE_SEARCH rel, jl_ptls_t ptls, jl_
}
jl_start_threads();

#ifdef MMTK_GC
mmtk_initialize_collection((void *)ptls);
#endif
jl_gc_enable(1);

if (jl_options.image_file && (!jl_generating_output() || jl_options.incremental) && jl_module_init_order) {
Expand Down
7 changes: 5 additions & 2 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ extern int mmtk_object_is_managed_by_mmtk(void* addr);
extern unsigned char mmtk_pin_object(void* obj);
// FIXME: Pinning objects that get hashed in the ptrhash table
// until we implement address space hashing.
#define PTRHASH_PIN(key) \
mmtk_pin_object(key); \
#ifdef MMTK_GC
#define PTRHASH_PIN(key) mmtk_pin_object(key);
#else
#define PTRHASH_PIN(key)
#endif

#ifdef __cplusplus
}
Expand Down
18 changes: 17 additions & 1 deletion src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
#ifndef JL_INTERNAL_H
#define JL_INTERNAL_H

#ifdef __cplusplus
extern "C" {
#endif

extern int mmtk_object_is_managed_by_mmtk(void* addr);
extern unsigned char mmtk_pin_object(void* obj);
#ifdef MMTK_GC
#define PTR_PIN(key) mmtk_pin_object(key);
#else
#define PTR_PIN(key)
#endif

#ifdef __cplusplus
}
#endif

#include "options.h"
#include "julia_assert.h"
#include "julia_locks.h"
Expand Down Expand Up @@ -535,7 +551,7 @@ STATIC_INLINE jl_gc_tracked_buffer_t *jl_gc_alloc_buf(jl_ptls_t ptls, size_t sz)
// introspect the object to update the a->data field. To avoid doing that and
// making scan_object much more complex we simply enforce that both owner and
// buffers are always pinned
mmtk_pin_object(buf);
PTR_PIN(buf);
return buf;
}

Expand Down

0 comments on commit d907a06

Please sign in to comment.