Skip to content

Commit 5bd9e03

Browse files
author
Luis Eduardo de Souza Amorim
committed
Allocating weak references, genericmemory and buffers into a non-moving space
1 parent 331b616 commit 5bd9e03

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

src/gc-mmtk.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ JL_DLLEXPORT void jl_gc_collect(jl_gc_collection_t collection) {
240240
return;
241241
}
242242
mmtk_handle_user_collection_request(ptls, collection);
243+
// print_fragmentation();
243244
}
244245

245246

@@ -330,6 +331,7 @@ JL_DLLEXPORT void jl_gc_prepare_to_collect(void)
330331
SetLastError(last_error);
331332
#endif
332333
errno = last_errno;
334+
// print_fragmentation();
333335
}
334336

335337
JL_DLLEXPORT unsigned char jl_gc_pin_object(void* obj) {
@@ -1064,9 +1066,8 @@ JL_DLLEXPORT size_t jl_gc_genericmemory_how(void *arg) JL_NOTSAFEPOINT
10641066

10651067
JL_DLLEXPORT jl_weakref_t *jl_gc_new_weakref_th(jl_ptls_t ptls, jl_value_t *value)
10661068
{
1067-
jl_weakref_t *wr = (jl_weakref_t*)jl_gc_alloc(ptls, sizeof(void*), jl_weakref_type);
1069+
jl_weakref_t *wr = (jl_weakref_t*)jl_gc_alloc_nonmoving(ptls, sizeof(void*), jl_weakref_type);
10681070
wr->value = value; // NOTE: wb not needed here
1069-
OBJ_PIN(wr)
10701071
// Note: we are using MMTk's weak ref processing. If we switch to Julia's weak ref processing,
10711072
// we need to make sure the value and the weak ref won't be moved (e.g. pin them)
10721073
mmtk_add_weak_candidate(wr);

src/genericmemory.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,13 @@ JL_DLLEXPORT jl_genericmemory_t *jl_alloc_genericmemory_unchecked(jl_ptls_t ptls
3838
data = (char*)jl_gc_managed_malloc(nbytes);
3939
tot = sizeof(jl_genericmemory_t) + sizeof(void*);
4040
}
41-
m = (jl_genericmemory_t*)jl_gc_alloc(ptls, tot, mtype);
41+
m = (jl_genericmemory_t*)jl_gc_alloc_nonmoving(ptls, tot, mtype);
4242
if (pooled) {
4343
data = (char*)m + JL_SMALL_BYTE_ALIGNMENT;
44-
// Data is inlined and ptr is an internal pointer. We pin the object so the ptr will not be invalid.
45-
OBJ_PIN(m);
4644
}
4745
else {
4846
int isaligned = 1; // jl_gc_managed_malloc is always aligned
4947
jl_gc_track_malloced_genericmemory(ptls, m, isaligned);
50-
OBJ_PIN(m);
5148
jl_genericmemory_data_owner_field(m) = (jl_value_t*)m;
5249
}
5350
// length set by codegen
@@ -110,12 +107,11 @@ JL_DLLEXPORT jl_genericmemory_t *jl_string_to_genericmemory(jl_value_t *str)
110107
return (jl_genericmemory_t*)((jl_datatype_t*)jl_memory_uint8_type)->instance;
111108
jl_task_t *ct = jl_current_task;
112109
int tsz = sizeof(jl_genericmemory_t) + sizeof(void*);
113-
jl_genericmemory_t *m = (jl_genericmemory_t*)jl_gc_alloc(ct->ptls, tsz, jl_memory_uint8_type);
110+
jl_genericmemory_t *m = (jl_genericmemory_t*)jl_gc_alloc_nonmoving(ct->ptls, tsz, jl_memory_uint8_type);
114111
m->length = jl_string_len(str);
115112
m->ptr = jl_string_data(str);
116113
jl_genericmemory_data_owner_field(m) = str;
117114
OBJ_PIN(str);
118-
OBJ_PIN(m); // FIXME: without this pin, make test-Tar fail with stress copying
119115
return m;
120116
}
121117

src/julia_internal.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,9 @@ JL_DLLEXPORT uintptr_t jl_get_buff_tag(void) JL_NOTSAFEPOINT;
585585
typedef void jl_gc_tracked_buffer_t; // For the benefit of the static analyzer
586586
STATIC_INLINE jl_gc_tracked_buffer_t *jl_gc_alloc_buf(jl_ptls_t ptls, size_t sz)
587587
{
588-
jl_gc_tracked_buffer_t *buf = jl_gc_alloc(ptls, sz, (void*)jl_buff_tag);
588+
jl_gc_tracked_buffer_t *buf = jl_gc_alloc_nonmoving(ptls, sz, (void*)jl_buff_tag);
589589
// FIXME: we might not need to pin buffers since the introduction of jl_genericmemory_t objects
590590
// but removing the pin below will currently fail an assertion in the binding
591-
OBJ_PIN(buf);
592591
return buf;
593592
}
594593

0 commit comments

Comments
 (0)