Skip to content

Commit 861f151

Browse files
authored
Merge pull request #27 from udesou/feature/rb-roots
Changes to support moving immix
2 parents 22524a8 + 3b4ae53 commit 861f151

15 files changed

+92
-6
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);
@@ -683,6 +693,11 @@ static int NOINLINE array_resize_buffer(jl_array_t *a, size_t newlen)
683693
else {
684694
s = jl_gc_realloc_string(jl_array_data_owner(a), nbytes - (elsz == 1));
685695
}
696+
// For array objects with an owner point (a->flags.how == 3), we would need to
697+
// introspect the object to update the a->data field. To avoid doing that and
698+
// making scan_object much more complex we simply enforce that both owner and
699+
// buffers are always pinned
700+
mmtk_pin_object(s);
686701
jl_array_data_owner(a) = s;
687702
jl_gc_wb(a, s);
688703
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-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/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

src/julia_internal.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,13 @@ JL_DLLEXPORT uintptr_t jl_get_buff_tag(void);
532532
typedef void jl_gc_tracked_buffer_t; // For the benefit of the static analyzer
533533
STATIC_INLINE jl_gc_tracked_buffer_t *jl_gc_alloc_buf(jl_ptls_t ptls, size_t sz)
534534
{
535-
return jl_gc_alloc(ptls, sz, (void*)jl_buff_tag);
535+
jl_gc_tracked_buffer_t *buf = jl_gc_alloc(ptls, sz, (void*)jl_buff_tag);
536+
// For array objects with an owner point (a->flags.how == 3), we would need to
537+
// introspect the object to update the a->data field. To avoid doing that and
538+
// making scan_object much more complex we simply enforce that both owner and
539+
// buffers are always pinned
540+
mmtk_pin_object(buf);
541+
return buf;
536542
}
537543

538544
STATIC_INLINE jl_value_t *jl_gc_permobj(size_t sz, void *ty) JL_NOTSAFEPOINT

src/mmtk-gc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,10 @@ jl_value_t *jl_gc_realloc_string(jl_value_t *s, size_t sz)
431431
size_t len = jl_string_len(s);
432432
jl_value_t *snew = jl_alloc_string(sz);
433433
memcpy(jl_string_data(snew), jl_string_data(s), sz <= len ? sz : len);
434+
if(mmtk_is_pinned(s)) {
435+
// if the source string was pinned, we also pin the new one
436+
mmtk_pin_object(snew);
437+
}
434438
return snew;
435439
}
436440

src/runtime_ccall.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ jl_value_t *jl_get_cfunction_trampoline(
352352
tramp = trampoline_alloc();
353353
((void**)result)[0] = tramp;
354354
tramp = init_trampoline(tramp, nval);
355+
PTRHASH_PIN((void*)fobj)
356+
PTRHASH_PIN(result)
355357
ptrhash_put(cache, (void*)fobj, result);
356358
uv_mutex_unlock(&trampoline_lock);
357359
return result;

0 commit comments

Comments
 (0)