Skip to content

Commit 8bb0895

Browse files
committed
Immix working; inlining fastpath allocation is not
1 parent b64c1e4 commit 8bb0895

File tree

9 files changed

+79
-37
lines changed

9 files changed

+79
-37
lines changed

src/datatype.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ static jl_datatype_layout_t *jl_get_layout(uint32_t sz,
291291
if ((void*)ret == HT_NOTFOUND) {
292292
if (!should_malloc) {
293293
char *perm_mem = (char *)jl_gc_perm_alloc(flddesc_sz, 0, 4, 0);
294+
#ifdef MMTK_GC
295+
jl_ptls_t ptls = jl_current_task->ptls;
296+
mmtk_immortal_post_alloc_fast(&ptls->mmtk_mutator, jl_valueof(perm_mem), flddesc_sz);
297+
#endif
294298
assert(perm_mem);
295299
ret = (jl_datatype_layout_t *)perm_mem;
296300
memcpy(perm_mem, flddesc, flddesc_sz);
@@ -968,6 +972,10 @@ JL_DLLEXPORT jl_datatype_t * jl_new_foreign_type(jl_sym_t *name,
968972
jl_datatype_layout_t *layout = (jl_datatype_layout_t *)
969973
jl_gc_perm_alloc(sizeof(jl_datatype_layout_t) + sizeof(jl_fielddescdyn_t),
970974
0, 4, 0);
975+
#ifdef MMTK_GC
976+
jl_ptls_t ptls = jl_current_task->ptls;
977+
mmtk_immortal_post_alloc_fast(&ptls->mmtk_mutator, jl_valueof(layout), sizeof(jl_datatype_layout_t) + sizeof(jl_fielddescdyn_t));
978+
#endif
971979
layout->size = large ? GC_MAX_SZCLASS+1 : 0;
972980
layout->nfields = 0;
973981
layout->alignment = sizeof(void *);

src/gc-common.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -525,18 +525,6 @@ void jl_gc_free_memory(jl_value_t *v, int isaligned) JL_NOTSAFEPOINT
525525
gc_num.freecall++;
526526
}
527527

528-
void jl_free_thread_gc_state(jl_ptls_t ptls)
529-
{
530-
jl_gc_markqueue_t *mq = &ptls->gc_tls.mark_queue;
531-
ws_queue_t *cq = &mq->chunk_queue;
532-
free_ws_array(jl_atomic_load_relaxed(&cq->array));
533-
jl_atomic_store_relaxed(&cq->array, NULL);
534-
ws_queue_t *q = &mq->ptr_queue;
535-
free_ws_array(jl_atomic_load_relaxed(&q->array));
536-
jl_atomic_store_relaxed(&q->array, NULL);
537-
arraylist_free(&mq->reclaim_set);
538-
}
539-
540528
// GCNum, statistics manipulation
541529
// ---
542530
// Only safe to update the heap inside the GC
@@ -642,6 +630,16 @@ JL_DLLEXPORT int jl_gc_is_enabled(void)
642630
return !ptls->disable_gc;
643631
}
644632

633+
int gc_logging_enabled = 0;
634+
635+
JL_DLLEXPORT void jl_enable_gc_logging(int enable) {
636+
gc_logging_enabled = enable;
637+
}
638+
639+
JL_DLLEXPORT int jl_is_gc_logging_enabled(void) {
640+
return gc_logging_enabled;
641+
}
642+
645643
JL_DLLEXPORT void jl_gc_get_total_bytes(int64_t *bytes) JL_NOTSAFEPOINT
646644
{
647645
jl_gc_num_t num = gc_num;

src/gc-debug.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,16 +1142,6 @@ NOINLINE void gc_mark_loop_unwind(jl_ptls_t ptls, jl_gc_markqueue_t *mq, int off
11421142
// return (slot - start) / elsize;
11431143
// }
11441144

1145-
static int gc_logging_enabled = 0;
1146-
1147-
JL_DLLEXPORT void jl_enable_gc_logging(int enable) {
1148-
gc_logging_enabled = enable;
1149-
}
1150-
1151-
JL_DLLEXPORT int jl_is_gc_logging_enabled(void) {
1152-
return gc_logging_enabled;
1153-
}
1154-
11551145
void _report_gc_finished(uint64_t pause, uint64_t freed, int full, int recollect, int64_t live_bytes) JL_NOTSAFEPOINT {
11561146
if (!gc_logging_enabled) {
11571147
return;

src/gc-page-profiler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,4 @@ JL_DLLEXPORT void jl_gc_take_page_profile(ios_t *stream)
180180
}
181181
#endif
182182

183-
#endif // !MMTK_GC
183+
#endif // !MMTK_GC

src/gc.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3345,6 +3345,18 @@ void jl_deinit_thread_heap(jl_ptls_t ptls)
33453345
// Do nothing
33463346
}
33473347

3348+
void jl_free_thread_gc_state(jl_ptls_t ptls)
3349+
{
3350+
jl_gc_markqueue_t *mq = &ptls->gc_tls.mark_queue;
3351+
ws_queue_t *cq = &mq->chunk_queue;
3352+
free_ws_array(jl_atomic_load_relaxed(&cq->array));
3353+
jl_atomic_store_relaxed(&cq->array, NULL);
3354+
ws_queue_t *q = &mq->ptr_queue;
3355+
free_ws_array(jl_atomic_load_relaxed(&q->array));
3356+
jl_atomic_store_relaxed(&q->array, NULL);
3357+
arraylist_free(&mq->reclaim_set);
3358+
}
3359+
33483360
// System-wide initializations
33493361
void jl_gc_init(void)
33503362
{

src/jitlayers.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,12 @@ class MaxAlignedAllocImpl
320320
LLVM_ATTRIBUTE_RETURNS_NONNULL void *Allocate(size_t Size, Align Alignment) {
321321
Align MaxAlign = alignment(Size);
322322
assert(Alignment < MaxAlign); (void)Alignment;
323-
return jl_gc_perm_alloc(Size, 0, MaxAlign.value(), offset);
323+
void* result = jl_gc_perm_alloc(Size, 0, MaxAlign.value(), offset);
324+
#ifdef MMTK_GC
325+
jl_ptls_t ptls = jl_current_task->ptls;
326+
mmtk_immortal_post_alloc_fast(&ptls->mmtk_mutator, jl_valueof(result), Size);
327+
#endif
328+
return result;
324329
}
325330

326331
inline LLVM_ATTRIBUTE_RETURNS_NONNULL

src/llvm-final-gc-lowering.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,12 @@ void FinalLowerGC::lowerGCAllocBytes(CallInst *target, Function &F)
302302
builder.CreateStore(new_cursor, cursor_ptr);
303303

304304
// ptls->gc_num.allocd += osize;
305-
// auto pool_alloc_pos = ConstantInt::get(Type::getInt64Ty(target->getContext()), offsetof(jl_tls_states_t, gc_tls) + offsetof(jl_gc_tls_states_t, gc_num));
306-
// auto pool_alloc_i8 = builder.CreateGEP(Type::getInt8Ty(target->getContext()), ptls, pool_alloc_pos);
307-
// auto pool_alloc_tls = builder.CreateBitCast(pool_alloc_i8, PointerType::get(Type::getInt64Ty(target->getContext()), 0), "pool_alloc");
308-
// auto pool_allocd = builder.CreateLoad(Type::getInt64Ty(target->getContext()), pool_alloc_tls);
309-
// auto pool_allocd_total = builder.CreateAdd(pool_allocd, pool_osize);
310-
// builder.CreateStore(pool_allocd_total, pool_alloc_tls);
305+
auto pool_alloc_pos = ConstantInt::get(Type::getInt64Ty(target->getContext()), offsetof(jl_tls_states_t, gc_tls) + offsetof(jl_gc_tls_states_t, gc_num));
306+
auto pool_alloc_i8 = builder.CreateGEP(Type::getInt8Ty(target->getContext()), ptls, pool_alloc_pos);
307+
auto pool_alloc_tls = builder.CreateBitCast(pool_alloc_i8, PointerType::get(Type::getInt64Ty(target->getContext()), 0), "pool_alloc");
308+
auto pool_allocd = builder.CreateLoad(Type::getInt64Ty(target->getContext()), pool_alloc_tls);
309+
auto pool_allocd_total = builder.CreateAdd(pool_allocd, pool_osize);
310+
builder.CreateStore(pool_allocd_total, pool_alloc_tls);
311311

312312
auto v_raw = builder.CreateNSWAdd(result, ConstantInt::get(Type::getInt64Ty(target->getContext()), sizeof(jl_taggedvalue_t)));
313313
auto v_as_ptr = builder.CreateIntToPtr(v_raw, poolAllocFunc->getReturnType());
@@ -316,7 +316,7 @@ void FinalLowerGC::lowerGCAllocBytes(CallInst *target, Function &F)
316316
phiNode->addIncoming(new_call, slowpath);
317317
phiNode->addIncoming(v_as_ptr, fastpath);
318318
phiNode->takeName(target);
319-
319+
320320
target->replaceAllUsesWith(phiNode);
321321
return;
322322
} else {
@@ -364,6 +364,13 @@ bool FinalLowerGC::runOnFunction(Function &F)
364364
allocTypedFunc = getOrDeclare(jl_well_known::GCAllocTyped);
365365
T_size = F.getParent()->getDataLayout().getIntPtrType(F.getContext());
366366

367+
#ifdef MMTK_GC
368+
writeBarrier1Func = getOrDeclare(jl_well_known::GCWriteBarrier1);
369+
writeBarrier2Func = getOrDeclare(jl_well_known::GCWriteBarrier2);
370+
writeBarrier1SlowFunc = getOrDeclare(jl_well_known::GCWriteBarrier1Slow);
371+
writeBarrier2SlowFunc = getOrDeclare(jl_well_known::GCWriteBarrier2Slow);
372+
#endif
373+
367374
// Lower all calls to supported intrinsics.
368375
for (auto &BB : F) {
369376
for (auto it = BB.begin(); it != BB.end();) {

src/llvm-late-gc-lowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2617,7 +2617,7 @@ bool LateLowerGCFrame::CleanupIR(Function &F, State *S, bool *CFGModified) {
26172617
// FIXME: Currently we call write barrier with the src object (parent).
26182618
// This works fine for object barrier for generational plans (such as stickyimmix), which does not use the target object at all.
26192619
// But for other MMTk plans, we need to be careful.
2620-
const bool INLINE_WRITE_BARRIER = true;
2620+
const bool INLINE_WRITE_BARRIER = false;
26212621
if (CI->getCalledOperand() == write_barrier_func) {
26222622
if (MMTK_NEEDS_WRITE_BARRIER == MMTK_OBJECT_BARRIER) {
26232623
if (INLINE_WRITE_BARRIER) {

src/mmtk-gc.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,23 @@ JL_DLLEXPORT void jl_gc_set_cb_notify_external_free(jl_gc_cb_notify_external_fre
3232
JL_DLLEXPORT void jl_gc_set_cb_notify_gc_pressure(jl_gc_cb_notify_gc_pressure_t cb, int enable)
3333
{
3434
}
35+
JL_DLLEXPORT void jl_gc_take_page_profile(ios_t *stream)
36+
{
37+
}
38+
39+
JL_DLLEXPORT double jl_gc_page_utilization_stats[JL_GC_N_MAX_POOLS];
40+
41+
STATIC_INLINE void gc_dump_page_utilization_data(void) JL_NOTSAFEPOINT
42+
{
43+
// FIXME: MMTk would have to provide its own stats
44+
}
3545

46+
#define MMTK_GC_PAGE_SZ (1 << 12) // MMTk's page size is defined in mmtk-core constants
47+
48+
JL_DLLEXPORT uint64_t jl_get_pg_size(void)
49+
{
50+
return MMTK_GC_PAGE_SZ;
51+
}
3652

3753
inline void maybe_collect(jl_ptls_t ptls)
3854
{
@@ -271,6 +287,10 @@ void jl_init_thread_heap(jl_ptls_t ptls)
271287
mmtk_post_bind_mutator(&ptls->mmtk_mutator, mmtk_mutator);
272288
}
273289

290+
void jl_free_thread_gc_state(jl_ptls_t ptls)
291+
{
292+
}
293+
274294
void jl_deinit_thread_heap(jl_ptls_t ptls)
275295
{
276296
mmtk_destroy_mutator(&ptls->mmtk_mutator);
@@ -380,32 +400,34 @@ JL_DLLEXPORT void *jl_gc_counted_malloc(size_t sz)
380400
{
381401
jl_gcframe_t **pgcstack = jl_get_pgcstack();
382402
jl_task_t *ct = jl_current_task;
383-
if (pgcstack && ct->world_age) {
403+
void *data = malloc(sz);
404+
if (data != NULL && pgcstack != NULL && ct->world_age) {
384405
jl_ptls_t ptls = ct->ptls;
385406
malloc_maybe_collect(ptls, sz);
386407
jl_atomic_fetch_add_relaxed(&JULIA_MALLOC_BYTES, sz);
387408
}
388-
return malloc(sz);
409+
return data;
389410
}
390411

391412
JL_DLLEXPORT void *jl_gc_counted_calloc(size_t nm, size_t sz)
392413
{
393414
jl_gcframe_t **pgcstack = jl_get_pgcstack();
394415
jl_task_t *ct = jl_current_task;
395-
if (pgcstack && ct->world_age) {
416+
void *data = calloc(nm, sz);
417+
if (data != NULL && pgcstack != NULL && ct->world_age) {
396418
jl_ptls_t ptls = ct->ptls;
397419
malloc_maybe_collect(ptls, nm * sz);
398420
jl_atomic_fetch_add_relaxed(&JULIA_MALLOC_BYTES, nm * sz);
399421
}
400-
return calloc(nm, sz);
422+
return data;
401423
}
402424

403425
JL_DLLEXPORT void jl_gc_counted_free_with_size(void *p, size_t sz)
404426
{
405427
jl_gcframe_t **pgcstack = jl_get_pgcstack();
406428
jl_task_t *ct = jl_current_task;
407429
free(p);
408-
if (pgcstack && ct->world_age) {
430+
if (pgcstack != NULL && ct->world_age) {
409431
jl_atomic_fetch_add_relaxed(&JULIA_MALLOC_BYTES, -sz);
410432
}
411433
}

0 commit comments

Comments
 (0)