Skip to content

Commit d907a06

Browse files
authored
Port PR #42 and #44 to master (#48)
* Call initialize_collection before enabling GC (#44) * Fix build with stock GC: mmtk_pin_object is conditionaly compiled (#42)
1 parent 6f5f685 commit d907a06

File tree

6 files changed

+33
-14
lines changed

6 files changed

+33
-14
lines changed

src/array.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ JL_DLLEXPORT jl_array_t *jl_reshape_array(jl_value_t *atype, jl_array_t *data,
243243
// introspect the object to update the a->data field. To avoid doing that and
244244
// making scan_object much more complex we simply enforce that both owner and
245245
// buffers are always pinned
246-
mmtk_pin_object(owner);
246+
PTR_PIN(owner);
247247
a->flags.how = 3;
248248
a->data = data->data;
249249
a->flags.isshared = 1;
@@ -296,7 +296,7 @@ JL_DLLEXPORT jl_array_t *jl_string_to_array(jl_value_t *str)
296296
// introspect the object to update the a->data field. To avoid doing that and
297297
// making scan_object much more complex we simply enforce that both owner and
298298
// buffers are always pinned
299-
mmtk_pin_object(str);
299+
PTR_PIN(str);
300300
a->flags.how = 3;
301301
a->flags.isshared = 1;
302302
size_t l = jl_string_len(str);
@@ -695,7 +695,7 @@ static int NOINLINE array_resize_buffer(jl_array_t *a, size_t newlen)
695695
// introspect the object to update the a->data field. To avoid doing that and
696696
// making scan_object much more complex we simply enforce that both owner and
697697
// buffers are always pinned
698-
mmtk_pin_object(s);
698+
PTR_PIN(s);
699699
jl_array_data_owner(a) = s;
700700
jl_gc_wb(a, s);
701701
a->data = jl_string_data(s);

src/builtins.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ static uintptr_t type_object_id_(jl_value_t *v, jl_varidx_t *env) JL_NOTSAFEPOIN
346346
}
347347
// FIXME: Pinning objects that get hashed
348348
// until we implement address space hashing.
349-
mmtk_pin_object(v);
349+
PTR_PIN(v);
350350
return inthash((uintptr_t)v);
351351
}
352352
if (tv == jl_uniontype_type) {
@@ -398,7 +398,7 @@ static uintptr_t immut_id_(jl_datatype_t *dt, jl_value_t *v, uintptr_t h) JL_NOT
398398

399399
// FIXME: Pinning objects that get hashed
400400
// until we implement address space hashing.
401-
mmtk_pin_object(v);
401+
PTR_PIN(v);
402402
// operate element-wise if there are unused bits inside,
403403
// otherwise just take the whole data block at once
404404
// a few select pointers (notably symbol) also have special hash values
@@ -462,7 +462,7 @@ static uintptr_t NOINLINE jl_object_id__cold(jl_datatype_t *dt, jl_value_t *v) J
462462
if (dt->name->mutabl) {
463463
// FIXME: Pinning objects that get hashed
464464
// until we implement address space hashing.
465-
mmtk_pin_object(v);
465+
PTR_PIN(v);
466466
return inthash((uintptr_t)v);
467467
}
468468
return immut_id_(dt, v, dt->hash);

src/datatype.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ JL_DLLEXPORT jl_typename_t *jl_new_typename_in(jl_sym_t *name, jl_module_t *modu
6767
jl_typename_type);
6868
// Typenames should be pinned since they are used as metadata, and are
6969
// read during scan_object
70-
mmtk_pin_object(tn);
70+
PTR_PIN(tn);
7171
tn->name = name;
7272
tn->module = module;
7373
tn->wrapper = NULL;
@@ -101,7 +101,7 @@ jl_datatype_t *jl_new_uninitialized_datatype(void)
101101
jl_datatype_t *t = (jl_datatype_t*)jl_gc_alloc(ct->ptls, sizeof(jl_datatype_t), jl_datatype_type);
102102
// Types should be pinned since they are used as metadata, and are
103103
// read during scan_object
104-
mmtk_pin_object(t);
104+
PTR_PIN(t);
105105
jl_set_typetagof(t, jl_datatype_tag, 0);
106106
t->hash = 0;
107107
t->hasfreetypevars = 0;

src/init.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -833,9 +833,6 @@ JL_DLLEXPORT void julia_init(JL_IMAGE_SEARCH rel)
833833
#pragma GCC diagnostic pop
834834
JL_GC_PROMISE_ROOTED(ct);
835835
_finish_julia_init(rel, ptls, ct);
836-
#ifdef MMTK_GC
837-
mmtk_initialize_collection((void *)ptls);
838-
#endif
839836
}
840837

841838
static NOINLINE void _finish_julia_init(JL_IMAGE_SEARCH rel, jl_ptls_t ptls, jl_task_t *ct)
@@ -883,6 +880,9 @@ static NOINLINE void _finish_julia_init(JL_IMAGE_SEARCH rel, jl_ptls_t ptls, jl_
883880
}
884881
jl_start_threads();
885882

883+
#ifdef MMTK_GC
884+
mmtk_initialize_collection((void *)ptls);
885+
#endif
886886
jl_gc_enable(1);
887887

888888
if (jl_options.image_file && (!jl_generating_output() || jl_options.incremental) && jl_module_init_order) {

src/julia.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ extern int mmtk_object_is_managed_by_mmtk(void* addr);
1111
extern unsigned char mmtk_pin_object(void* obj);
1212
// FIXME: Pinning objects that get hashed in the ptrhash table
1313
// until we implement address space hashing.
14-
#define PTRHASH_PIN(key) \
15-
mmtk_pin_object(key); \
14+
#ifdef MMTK_GC
15+
#define PTRHASH_PIN(key) mmtk_pin_object(key);
16+
#else
17+
#define PTRHASH_PIN(key)
18+
#endif
1619

1720
#ifdef __cplusplus
1821
}

src/julia_internal.h

+17-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
#ifndef JL_INTERNAL_H
44
#define JL_INTERNAL_H
55

6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
extern int mmtk_object_is_managed_by_mmtk(void* addr);
11+
extern unsigned char mmtk_pin_object(void* obj);
12+
#ifdef MMTK_GC
13+
#define PTR_PIN(key) mmtk_pin_object(key);
14+
#else
15+
#define PTR_PIN(key)
16+
#endif
17+
18+
#ifdef __cplusplus
19+
}
20+
#endif
21+
622
#include "options.h"
723
#include "julia_assert.h"
824
#include "julia_locks.h"
@@ -535,7 +551,7 @@ STATIC_INLINE jl_gc_tracked_buffer_t *jl_gc_alloc_buf(jl_ptls_t ptls, size_t sz)
535551
// introspect the object to update the a->data field. To avoid doing that and
536552
// making scan_object much more complex we simply enforce that both owner and
537553
// buffers are always pinned
538-
mmtk_pin_object(buf);
554+
PTR_PIN(buf);
539555
return buf;
540556
}
541557

0 commit comments

Comments
 (0)