Skip to content

Commit 45dd1c6

Browse files
authored
Merge branch 'master' into add-memoryref-addrspace-test
2 parents e46aef5 + 172125b commit 45dd1c6

File tree

10 files changed

+35
-26
lines changed

10 files changed

+35
-26
lines changed

src/datatype.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ STATIC_INLINE void jl_maybe_allocate_singleton_instance(jl_datatype_t *st) JL_NO
354354
if (st->instance)
355355
return;
356356
if (jl_is_datatype_make_singleton(st)) {
357-
st->instance = jl_gc_permobj(0, st, 0);
357+
jl_task_t *ct = jl_current_task;
358+
st->instance = jl_gc_permobj(ct->ptls, 0, st, 0);
358359
}
359360
}
360361

@@ -616,7 +617,8 @@ void jl_get_genericmemory_layout(jl_datatype_t *st)
616617

617618
if (jl_is_addrspacecore(addrspace) && jl_unbox_uint8(addrspace) == 0) {
618619
if (kind == (jl_value_t*)jl_not_atomic_sym || kind == (jl_value_t*)jl_atomic_sym) {
619-
jl_genericmemory_t *zeroinst = (jl_genericmemory_t*)jl_gc_permobj(LLT_ALIGN(sizeof(jl_genericmemory_t), JL_SMALL_BYTE_ALIGNMENT) + (elsz ? elsz : isunion), st, 0);
620+
jl_task_t *ct = jl_current_task;
621+
jl_genericmemory_t *zeroinst = (jl_genericmemory_t*)jl_gc_permobj(ct->ptls, LLT_ALIGN(sizeof(jl_genericmemory_t), JL_SMALL_BYTE_ALIGNMENT) + (elsz ? elsz : isunion), st, 0);
620622
zeroinst->length = 0;
621623
zeroinst->ptr = (char*)zeroinst + JL_SMALL_BYTE_ALIGNMENT;
622624
memset(zeroinst->ptr, 0, elsz ? elsz : isunion);
@@ -1458,12 +1460,13 @@ JL_DLLEXPORT int jl_atomic_storeonce_bits(jl_datatype_t *dt, char *dst, const jl
14581460

14591461
#define PERMBOXN_FUNC(nb) \
14601462
jl_value_t *jl_permbox##nb(jl_datatype_t *t, uintptr_t tag, uint##nb##_t x) JL_NOTSAFEPOINT \
1461-
{ /* n.b. t must be a concrete isbits datatype of the right size */ \
1462-
jl_value_t *v = jl_gc_permobj(LLT_ALIGN(nb, sizeof(void*)), t, 0); \
1463-
assert(tag); \
1464-
jl_set_typetagof(v, tag, GC_OLD_MARKED); \
1465-
*(uint##nb##_t*)jl_data_ptr(v) = x; \
1466-
return v; \
1463+
{ /* n.b. t must be a concrete isbits datatype of the right size */ \
1464+
jl_task_t *ct = jl_current_task; \
1465+
jl_value_t *v = jl_gc_permobj(ct->ptls, LLT_ALIGN(nb, sizeof(void*)), t, 0); \
1466+
assert(tag); \
1467+
jl_set_typetagof(v, tag, GC_OLD_MARKED); \
1468+
*(uint##nb##_t*)jl_data_ptr(v) = x; \
1469+
return v; \
14671470
}
14681471
PERMBOXN_FUNC(8)
14691472
PERMBOXN_FUNC(16)

src/gc-interface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ JL_DLLEXPORT void *jl_gc_perm_alloc(size_t sz, int zero, unsigned align,
209209
// necessarily mark any objects that would have ordinarily been rooted by
210210
// the allocated object. All objects stored in fields of this object
211211
// must be either permanently allocated or have other roots.
212-
struct _jl_value_t *jl_gc_permobj(size_t sz, void *ty, unsigned align) JL_NOTSAFEPOINT;
212+
struct _jl_value_t *jl_gc_permobj(struct _jl_tls_states_t *ptls, size_t sz, void *ty, unsigned align) JL_NOTSAFEPOINT;
213213
// This function notifies the GC about memory addresses that are set when loading the boot image.
214214
// The GC may use that information to, for instance, determine that such objects should
215215
// be treated as marked and belonged to the old generation in nursery collections.

src/gc-mmtk.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,9 @@ JL_DLLEXPORT void jl_gc_scan_vm_specific_roots(RootsWorkClosure* closure)
506506
// add module
507507
add_node_to_roots_buffer(closure, &buf, &len, jl_main_module);
508508

509+
// add global_method_table
510+
add_node_to_roots_buffer(closure, &buf, &len, jl_method_table);
511+
509512
// buildin values
510513
add_node_to_roots_buffer(closure, &buf, &len, jl_an_empty_vec_any);
511514
add_node_to_roots_buffer(closure, &buf, &len, jl_module_init_order);
@@ -1019,30 +1022,29 @@ JL_DLLEXPORT void *jl_gc_counted_realloc_with_old_size(void *p, size_t old, size
10191022
return realloc(p, sz);
10201023
}
10211024

1022-
void *jl_gc_perm_alloc_nolock(size_t sz, int zero, unsigned align, unsigned offset)
1025+
void *jl_gc_perm_alloc_nolock(jl_ptls_t ptls, size_t sz, int zero, unsigned align, unsigned offset)
10231026
{
1024-
jl_ptls_t ptls = jl_current_task->ptls;
10251027
size_t allocsz = mmtk_align_alloc_sz(sz);
10261028
void* addr = mmtk_immortal_alloc_fast(&ptls->gc_tls.mmtk_mutator, allocsz, align, offset);
10271029
return addr;
10281030
}
10291031

10301032
void *jl_gc_perm_alloc(size_t sz, int zero, unsigned align, unsigned offset)
10311033
{
1032-
return jl_gc_perm_alloc_nolock(sz, zero, align, offset);
1034+
jl_ptls_t ptls = jl_current_task->ptls;
1035+
return jl_gc_perm_alloc_nolock(ptls, sz, zero, align, offset);
10331036
}
10341037

1035-
jl_value_t *jl_gc_permobj(size_t sz, void *ty, unsigned align) JL_NOTSAFEPOINT
1038+
jl_value_t *jl_gc_permobj(jl_ptls_t ptls, size_t sz, void *ty, unsigned align) JL_NOTSAFEPOINT
10361039
{
10371040
const size_t allocsz = sz + sizeof(jl_taggedvalue_t);
10381041
if (align == 0) {
10391042
align = ((sz == 0) ? sizeof(void*) : (allocsz <= sizeof(void*) * 2 ?
10401043
sizeof(void*) * 2 : 16));
10411044
}
1042-
jl_taggedvalue_t *o = (jl_taggedvalue_t*)jl_gc_perm_alloc(allocsz, 0, align,
1045+
jl_taggedvalue_t *o = (jl_taggedvalue_t*)jl_gc_perm_alloc_nolock(ptls, allocsz, 0, align,
10431046
sizeof(void*) % align);
10441047

1045-
jl_ptls_t ptls = jl_current_task->ptls;
10461048
mmtk_immortal_post_alloc_fast(&ptls->gc_tls.mmtk_mutator, jl_valueof(o), allocsz);
10471049
o->header = (uintptr_t)ty;
10481050
return jl_valueof(o);

src/gc-stock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3957,7 +3957,7 @@ void *jl_gc_perm_alloc(size_t sz, int zero, unsigned align, unsigned offset)
39573957
return p;
39583958
}
39593959

3960-
jl_value_t *jl_gc_permobj(size_t sz, void *ty, unsigned align) JL_NOTSAFEPOINT
3960+
jl_value_t *jl_gc_permobj(jl_ptls_t _ptls, size_t sz, void *ty, unsigned align) JL_NOTSAFEPOINT
39613961
{
39623962
const size_t allocsz = sz + sizeof(jl_taggedvalue_t);
39633963
if (align == 0) {

src/init.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,12 +776,12 @@ JL_DLLEXPORT void jl_init_(jl_image_buf_t sysimage)
776776
jl_atomic_fetch_add(&jl_task_metrics_enabled, 1);
777777
}
778778
// Initialize constant objects
779-
jl_nothing = jl_gc_permobj(0, jl_nothing_type, 0);
779+
jl_nothing = jl_gc_permobj(ptls, 0, jl_nothing_type, 0);
780780
jl_set_typetagof(jl_nothing, jl_nothing_tag, GC_OLD_MARKED);
781-
jl_init_box_caches();
782-
jl_init_common_symbols();
783781
// warning: this changes `jl_current_task`, so be careful not to call that from this function
784782
jl_task_t *ct = jl_init_root_task(ptls, stack_lo, stack_hi);
783+
jl_init_box_caches();
784+
jl_init_common_symbols();
785785
#pragma GCC diagnostic pop
786786
JL_GC_PROMISE_ROOTED(ct);
787787
_finish_jl_init_(sysimage, ptls, ct);

src/jltypes.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,6 +2972,7 @@ void export_jl_sysimg_globals(void)
29722972
void jl_init_types(void) JL_GC_DISABLED
29732973
{
29742974
jl_module_t *core = NULL; // will need to be assigned later
2975+
jl_task_t *ct = jl_current_task;
29752976

29762977
// create base objects
29772978
jl_datatype_type = jl_new_uninitialized_datatype();
@@ -2985,7 +2986,7 @@ void jl_init_types(void) JL_GC_DISABLED
29852986
jl_methtable_type = jl_new_uninitialized_datatype();
29862987
jl_method_table = jl_new_method_table(jl_symbol("methodtable"), core);
29872988

2988-
jl_emptysvec = (jl_svec_t*)jl_gc_permobj(sizeof(void*), jl_simplevector_type, 0);
2989+
jl_emptysvec = (jl_svec_t*)jl_gc_permobj(ct->ptls, sizeof(void*), jl_simplevector_type, 0);
29892990
jl_set_typetagof(jl_emptysvec, jl_simplevector_tag, GC_OLD_MARKED);
29902991
jl_svec_set_len_unsafe(jl_emptysvec, 0);
29912992

@@ -3115,7 +3116,7 @@ void jl_init_types(void) JL_GC_DISABLED
31153116
jl_typeofbottom_type = jl_new_datatype(jl_symbol("TypeofBottom"), core, type_type, jl_emptysvec,
31163117
jl_emptysvec, jl_emptysvec, jl_emptysvec, 0, 0, 0);
31173118
XX(typeofbottom);
3118-
jl_bottom_type = jl_gc_permobj(0, jl_typeofbottom_type, 0);
3119+
jl_bottom_type = jl_gc_permobj(ct->ptls, 0, jl_typeofbottom_type, 0);
31193120
jl_set_typetagof(jl_bottom_type, jl_typeofbottom_tag, GC_OLD_MARKED);
31203121
jl_typeofbottom_type->instance = jl_bottom_type;
31213122

@@ -3165,7 +3166,7 @@ void jl_init_types(void) JL_GC_DISABLED
31653166
jl_typeofbottom_type->super = jl_wrap_Type(jl_bottom_type);
31663167
jl_typeofbottom_type->super->layout = jl_typeofbottom_type->layout; // the only abstract type with a layout
31673168
jl_emptytuple_type = (jl_datatype_t*)jl_apply_tuple_type(jl_emptysvec, 0);
3168-
jl_emptytuple = jl_gc_permobj(0, jl_emptytuple_type, 0);
3169+
jl_emptytuple = jl_gc_permobj(ct->ptls, 0, jl_emptytuple_type, 0);
31693170
jl_emptytuple_type->instance = jl_emptytuple;
31703171

31713172
// non-primitive definitions follow

src/runtime_ccall.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ jl_value_t *jl_get_cfunction_trampoline(
296296
permanent = true;
297297
}
298298
if (permanent) {
299-
result = jl_gc_permobj(sizeof(jl_taggedvalue_t) + jl_datatype_size(result_type), result_type, 0);
299+
jl_task_t *ct = jl_current_task;
300+
result = jl_gc_permobj(ct->ptls, sizeof(jl_taggedvalue_t) + jl_datatype_size(result_type), result_type, 0);
300301
memset(result, 0, jl_datatype_size(result_type));
301302
}
302303
else {

src/simplevector.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ JL_DLLEXPORT jl_svec_t *(ijl_svec)(size_t n, ...)
2222
jl_svec_t *(jl_perm_symsvec)(size_t n, ...)
2323
{
2424
if (n == 0) return jl_emptysvec;
25-
jl_svec_t *jv = (jl_svec_t*)jl_gc_permobj((n + 1) * sizeof(void*), jl_simplevector_type, 0);
25+
jl_task_t *ct = jl_current_task;
26+
jl_svec_t *jv = (jl_svec_t*)jl_gc_permobj(ct->ptls, (n + 1) * sizeof(void*), jl_simplevector_type, 0);
2627
jl_set_typetagof(jv, jl_simplevector_tag, jl_astaggedvalue(jv)->bits.gc);
2728
jl_svec_set_len_unsafe(jv, n);
2829
va_list args;

src/staticdata.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3993,7 +3993,7 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image,
39933993
// and we overwrite the name field (field 0) now so preserve it too
39943994
if (dt->instance) {
39953995
if (dt->instance == jl_nothing)
3996-
dt->instance = jl_gc_permobj(0, newdt, 0);
3996+
dt->instance = jl_gc_permobj(ct->ptls, 0, newdt, 0);
39973997
newdt->instance = dt->instance;
39983998
}
39993999
static_assert(offsetof(jl_datatype_t, name) == 0, "");

src/symbol.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ static size_t symbol_nbytes(size_t len) JL_NOTSAFEPOINT
3535
static jl_sym_t *mk_symbol(const char *str, size_t len) JL_NOTSAFEPOINT
3636
{
3737
size_t nb = symbol_nbytes(len);
38+
jl_task_t *ct = jl_current_task;
3839
// jl_sym_t is an object and needs to be allocated with jl_gc_permobj
3940
// but its type is set below with jl_set_typetagof since
4041
// jl_symbol_type might not have been initialized
41-
jl_sym_t *sym = (jl_sym_t*)jl_gc_permobj(nb, NULL, sizeof(void*));
42+
jl_sym_t *sym = (jl_sym_t*)jl_gc_permobj(ct->ptls, nb, NULL, sizeof(void*));
4243
jl_set_typetagof(sym, jl_symbol_tag, GC_OLD_MARKED);
4344
jl_atomic_store_relaxed(&sym->left, NULL);
4445
jl_atomic_store_relaxed(&sym->right, NULL);

0 commit comments

Comments
 (0)