Skip to content

Commit 3b4ae53

Browse files
committed
Refactoring pinning functions and adding comments
1 parent a0c895e commit 3b4ae53

File tree

6 files changed

+36
-20
lines changed

6 files changed

+36
-20
lines changed

src/array.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +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-
if(mmtk_object_is_managed_by_mmtk(owner)) {
243-
mmtk_pin_object(owner);
244-
}
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);
245247
a->flags.how = 3;
246248
a->data = data->data;
247249
a->flags.isshared = 1;
@@ -290,9 +292,11 @@ JL_DLLEXPORT jl_array_t *jl_string_to_array(jl_value_t *str)
290292
a->flags.ptrarray = 0;
291293
a->flags.hasptr = 0;
292294
jl_array_data_owner(a) = str;
293-
if(mmtk_object_is_managed_by_mmtk(str)) {
294-
mmtk_pin_object(str);
295-
}
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);
296300
a->flags.how = 3;
297301
a->flags.isshared = 1;
298302
size_t l = jl_string_len(str);
@@ -689,9 +693,11 @@ static int NOINLINE array_resize_buffer(jl_array_t *a, size_t newlen)
689693
else {
690694
s = jl_gc_realloc_string(jl_array_data_owner(a), nbytes - (elsz == 1));
691695
}
692-
if(mmtk_object_is_managed_by_mmtk(s)) {
693-
mmtk_pin_object(s);
694-
}
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);
695701
jl_array_data_owner(a) = s;
696702
jl_gc_wb(a, s);
697703
a->data = jl_string_data(s);

src/builtins.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +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-
if(mmtk_object_is_managed_by_mmtk(v)) {
348-
mmtk_pin_object(v);
349-
}
347+
// FIXME: Pinning objects that get hashed
348+
// until we implement address space hashing.
349+
mmtk_pin_object(v);
350350
return inthash((uintptr_t)v);
351351
}
352352
if (tv == jl_uniontype_type) {
@@ -395,9 +395,10 @@ static uintptr_t immut_id_(jl_datatype_t *dt, jl_value_t *v, uintptr_t h) JL_NOT
395395
return ~h;
396396
size_t f, nf = jl_datatype_nfields(dt);
397397
if (nf == 0 || (!dt->layout->haspadding && dt->layout->npointers == 0)) {
398-
if(mmtk_object_is_managed_by_mmtk(v)) {
399-
mmtk_pin_object(v);
400-
}
398+
399+
// FIXME: Pinning objects that get hashed
400+
// until we implement address space hashing.
401+
mmtk_pin_object(v);
401402
// operate element-wise if there are unused bits inside,
402403
// otherwise just take the whole data block at once
403404
// a few select pointers (notably symbol) also have special hash values
@@ -459,9 +460,9 @@ static uintptr_t NOINLINE jl_object_id__cold(jl_datatype_t *dt, jl_value_t *v) J
459460
return m->hash;
460461
}
461462
if (dt->name->mutabl) {
462-
if(mmtk_object_is_managed_by_mmtk(v)) {
463-
mmtk_pin_object(v);
464-
}
463+
// FIXME: Pinning objects that get hashed
464+
// until we implement address space hashing.
465+
mmtk_pin_object(v);
465466
return inthash((uintptr_t)v);
466467
}
467468
return immut_id_(dt, v, dt->hash);

src/datatype.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ 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
6870
mmtk_pin_object(tn);
6971
tn->name = name;
7072
tn->module = module;
@@ -97,6 +99,8 @@ jl_datatype_t *jl_new_uninitialized_datatype(void)
9799
{
98100
jl_task_t *ct = jl_current_task;
99101
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
100104
mmtk_pin_object(t);
101105
jl_set_typetagof(t, jl_datatype_tag, 0);
102106
t->hash = 0;

src/julia.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ extern "C" {
99

1010
extern int mmtk_object_is_managed_by_mmtk(void* addr);
1111
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.
1214
#define PTRHASH_PIN(key) \
13-
if (mmtk_object_is_managed_by_mmtk(key)) { \
1415
mmtk_pin_object(key); \
15-
} \
1616

1717
#ifdef __cplusplus
1818
}

src/julia_internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,10 @@ 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
{
535535
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
536540
mmtk_pin_object(buf);
537541
return buf;
538542
}

src/mmtk-gc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ jl_value_t *jl_gc_realloc_string(jl_value_t *s, size_t sz)
432432
jl_value_t *snew = jl_alloc_string(sz);
433433
memcpy(jl_string_data(snew), jl_string_data(s), sz <= len ? sz : len);
434434
if(mmtk_is_pinned(s)) {
435+
// if the source string was pinned, we also pin the new one
435436
mmtk_pin_object(snew);
436437
}
437438
return snew;

0 commit comments

Comments
 (0)