Skip to content

Commit f470eb4

Browse files
committed
Merge branch 'master' into fix/remove-sizeclasses
2 parents 1d97f5d + 861f151 commit f470eb4

19 files changed

+96
-31
lines changed

src/array.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ JL_DLLEXPORT jl_array_t *jl_reshape_array(jl_value_t *atype, jl_array_t *data,
239239
jl_array_t *owner = (jl_array_t*)jl_array_owner(data);
240240
jl_array_data_owner(a) = (jl_value_t*)owner;
241241

242+
// For array objects with an owner point (a->flags.how == 3), we would need to
243+
// introspect the object to update the a->data field. To avoid doing that and
244+
// making scan_object much more complex we simply enforce that both owner and
245+
// buffers are always pinned
246+
mmtk_pin_object(owner);
242247
a->flags.how = 3;
243248
a->data = data->data;
244249
a->flags.isshared = 1;
@@ -287,6 +292,11 @@ JL_DLLEXPORT jl_array_t *jl_string_to_array(jl_value_t *str)
287292
a->flags.ptrarray = 0;
288293
a->flags.hasptr = 0;
289294
jl_array_data_owner(a) = str;
295+
// For array objects with an owner point (a->flags.how == 3), we would need to
296+
// introspect the object to update the a->data field. To avoid doing that and
297+
// making scan_object much more complex we simply enforce that both owner and
298+
// buffers are always pinned
299+
mmtk_pin_object(str);
290300
a->flags.how = 3;
291301
a->flags.isshared = 1;
292302
size_t l = jl_string_len(str);
@@ -681,6 +691,11 @@ static int NOINLINE array_resize_buffer(jl_array_t *a, size_t newlen)
681691
else {
682692
s = jl_gc_realloc_string(jl_array_data_owner(a), nbytes - (elsz == 1));
683693
}
694+
// For array objects with an owner point (a->flags.how == 3), we would need to
695+
// introspect the object to update the a->data field. To avoid doing that and
696+
// making scan_object much more complex we simply enforce that both owner and
697+
// buffers are always pinned
698+
mmtk_pin_object(s);
684699
jl_array_data_owner(a) = s;
685700
jl_gc_wb(a, s);
686701
a->data = jl_string_data(s);

src/builtins.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ static uintptr_t type_object_id_(jl_value_t *v, jl_varidx_t *env) JL_NOTSAFEPOIN
344344
i++;
345345
pe = pe->prev;
346346
}
347+
// FIXME: Pinning objects that get hashed
348+
// until we implement address space hashing.
349+
mmtk_pin_object(v);
347350
return inthash((uintptr_t)v);
348351
}
349352
if (tv == jl_uniontype_type) {
@@ -392,6 +395,10 @@ static uintptr_t immut_id_(jl_datatype_t *dt, jl_value_t *v, uintptr_t h) JL_NOT
392395
return ~h;
393396
size_t f, nf = jl_datatype_nfields(dt);
394397
if (nf == 0 || (!dt->layout->haspadding && dt->layout->npointers == 0)) {
398+
399+
// FIXME: Pinning objects that get hashed
400+
// until we implement address space hashing.
401+
mmtk_pin_object(v);
395402
// operate element-wise if there are unused bits inside,
396403
// otherwise just take the whole data block at once
397404
// a few select pointers (notably symbol) also have special hash values
@@ -452,8 +459,12 @@ static uintptr_t NOINLINE jl_object_id__cold(jl_datatype_t *dt, jl_value_t *v) J
452459
jl_module_t *m = (jl_module_t*)v;
453460
return m->hash;
454461
}
455-
if (dt->name->mutabl)
462+
if (dt->name->mutabl) {
463+
// FIXME: Pinning objects that get hashed
464+
// until we implement address space hashing.
465+
mmtk_pin_object(v);
456466
return inthash((uintptr_t)v);
467+
}
457468
return immut_id_(dt, v, dt->hash);
458469
}
459470

src/datatype.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ JL_DLLEXPORT jl_typename_t *jl_new_typename_in(jl_sym_t *name, jl_module_t *modu
6565
jl_typename_t *tn =
6666
(jl_typename_t*)jl_gc_alloc(ct->ptls, sizeof(jl_typename_t),
6767
jl_typename_type);
68+
// Typenames should be pinned since they are used as metadata, and are
69+
// read during scan_object
70+
mmtk_pin_object(tn);
6871
tn->name = name;
6972
tn->module = module;
7073
tn->wrapper = NULL;
@@ -96,6 +99,9 @@ jl_datatype_t *jl_new_uninitialized_datatype(void)
9699
{
97100
jl_task_t *ct = jl_current_task;
98101
jl_datatype_t *t = (jl_datatype_t*)jl_gc_alloc(ct->ptls, sizeof(jl_datatype_t), jl_datatype_type);
102+
// Types should be pinned since they are used as metadata, and are
103+
// read during scan_object
104+
mmtk_pin_object(t);
99105
jl_set_typetagof(t, jl_datatype_tag, 0);
100106
t->hash = 0;
101107
t->hasfreetypevars = 0;

src/gc-common.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ void gc_premark(jl_ptls_t ptls2)
566566
// GC control
567567
// ---
568568

569-
_Atomic(uint32_t) jl_gc_disable_counter = 1;
569+
JL_DLLEXPORT _Atomic(uint32_t) jl_gc_disable_counter = 1;
570570

571571
JL_DLLEXPORT int jl_gc_enable(int on)
572572
{
@@ -578,11 +578,9 @@ JL_DLLEXPORT int jl_gc_enable(int on)
578578
if (jl_atomic_fetch_add(&jl_gc_disable_counter, -1) == 1) {
579579
gc_num.allocd += gc_num.deferred_alloc;
580580
gc_num.deferred_alloc = 0;
581-
enable_collection();
582581
}
583582
}
584583
else if (prev && !on) {
585-
disable_collection();
586584
// enable -> disable
587585
jl_atomic_fetch_add(&jl_gc_disable_counter, 1);
588586
// check if the GC is running and wait for it to finish

src/gc-stacks.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static void *malloc_stack(size_t bufsz) JL_NOTSAFEPOINT
6666
return stk;
6767
}
6868

69-
static void free_stack(void *stkbuf, size_t bufsz)
69+
void free_stack(void *stkbuf, size_t bufsz)
7070
{
7171
munmap(stkbuf, bufsz);
7272
jl_atomic_fetch_add(&num_stack_mappings, -1);
@@ -104,7 +104,7 @@ static unsigned select_pool(size_t nb) JL_NOTSAFEPOINT
104104
}
105105

106106

107-
static void _jl_free_stack(jl_ptls_t ptls, void *stkbuf, size_t bufsz)
107+
void _jl_free_stack(jl_ptls_t ptls, void *stkbuf, size_t bufsz)
108108
{
109109
#ifdef _COMPILER_ASAN_ENABLED_
110110
__asan_unpoison_stack_memory((uintptr_t)stkbuf, bufsz);

src/gc.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3448,12 +3448,6 @@ void jl_gc_threadfun(void *arg)
34483448
}
34493449

34503450
// added for MMTk integration
3451-
void enable_collection(void)
3452-
{
3453-
}
3454-
void disable_collection(void)
3455-
{
3456-
}
34573451

34583452
JL_DLLEXPORT void jl_gc_wb1_noinline(const void *parent) JL_NOTSAFEPOINT
34593453
{

src/gc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ extern const size_t max_collect_interval;
8383
extern size_t last_long_collect_interval;
8484
extern size_t total_mem;
8585
extern memsize_t max_total_memory;
86-
extern _Atomic(uint32_t) jl_gc_disable_counter;
86+
extern JL_DLLEXPORT _Atomic(uint32_t) jl_gc_disable_counter;
8787
extern jl_mutex_t heapsnapshot_lock;
8888
extern uint64_t finalizer_rngState[];
8989
extern int gc_n_threads;

src/interpreter.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@ jl_value_t *NOINLINE jl_interpret_toplevel_thunk(jl_module_t *m, jl_code_info_t
762762
unsigned nroots = jl_source_nslots(src) + jl_source_nssavalues(src);
763763
JL_GC_PUSHFRAME(s, s->locals, nroots);
764764
jl_array_t *stmts = src->code;
765+
JL_GC_PUSH1(&stmts);
765766
assert(jl_typetagis(stmts, jl_array_any_type));
766767
s->src = src;
767768
s->module = m;
@@ -774,6 +775,7 @@ jl_value_t *NOINLINE jl_interpret_toplevel_thunk(jl_module_t *m, jl_code_info_t
774775
jl_value_t *r = eval_body(stmts, s, 0, 1);
775776
ct->world_age = last_age;
776777
JL_GC_POP();
778+
JL_GC_POP();
777779
return r;
778780
}
779781

src/ircode.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,12 +1164,15 @@ void jl_init_serializer(void)
11641164
assert(LAST_TAG+1+i < 256);
11651165

11661166
for (i = 2; i < 256; i++) {
1167-
if (deser_tag[i])
1167+
if (deser_tag[i]) {
1168+
PTRHASH_PIN(deser_tag[i])
11681169
ptrhash_put(&ser_tag, deser_tag[i], (void*)i);
1170+
}
11691171
}
11701172

11711173
i = 2;
11721174
while (common_symbols[i-2] != NULL) {
1175+
PTRHASH_PIN(common_symbols[i-2])
11731176
ptrhash_put(&common_symbol_tag, common_symbols[i-2], (void*)i);
11741177
deser_symbols[i] = (jl_value_t*)common_symbols[i-2];
11751178
i += 1;

src/julia.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@
33
#ifndef JULIA_H
44
#define JULIA_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+
// FIXME: Pinning objects that get hashed in the ptrhash table
13+
// until we implement address space hashing.
14+
#define PTRHASH_PIN(key) \
15+
mmtk_pin_object(key); \
16+
17+
#ifdef __cplusplus
18+
}
19+
#endif
20+
621
#if defined(JL_LIBRARY_EXPORTS_INTERNAL) || defined(JL_LIBRARY_EXPORTS_CODEGEN)
722
#define JL_LIBRARY_EXPORTS
823
#endif

0 commit comments

Comments
 (0)