Skip to content

Commit b67cb36

Browse files
committed
optimize object pinning in ast.c
1 parent b048d20 commit b67cb36

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

src/ast.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,11 +778,10 @@ static value_t julia_to_list2_noalloc(fl_context_t *fl_ctx, jl_value_t *a, jl_va
778778
return l;
779779
}
780780

781-
static value_t julia_to_scm_(fl_context_t *fl_ctx, jl_value_t *v, int check_valid)
781+
static value_t julia_to_scm__(fl_context_t *fl_ctx, jl_value_t *v, int check_valid)
782782
{
783783
// The following code will take internal pointers to v's fields. We need to make sure
784784
// that v will not be moved by GC.
785-
OBJ_PIN(v);
786785
value_t retval;
787786
if (julia_to_scm_noalloc1(fl_ctx, v, &retval))
788787
return retval;
@@ -840,6 +839,14 @@ static value_t julia_to_scm_(fl_context_t *fl_ctx, jl_value_t *v, int check_vali
840839
return julia_to_scm_noalloc2(fl_ctx, v, check_valid);
841840
}
842841

842+
static value_t julia_to_scm_(fl_context_t *fl_ctx, jl_value_t *v, int check_valid)
843+
{
844+
arraylist_push(&objects_pinned_by_compiler_frontend, v);
845+
value_t scm_v = julia_to_scm__(fl_ctx, v, check_valid);
846+
arraylist_pop(&objects_pinned_by_compiler_frontend);
847+
return scm_v;
848+
}
849+
843850
// Parse `text` starting at 0-based `offset` and attributing the content to
844851
// `filename`. Return an svec of (parsed_expr, final_offset)
845852
JL_DLLEXPORT jl_value_t *jl_fl_parse(const char *text, size_t text_len,

src/engine.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ jl_code_instance_t *jl_engine_reserve(jl_method_instance_t *m, jl_value_t *owner
6464
auto tid = jl_atomic_load_relaxed(&ct->tid);
6565
if (([tid, m, owner, ci] () -> bool { // necessary scope block / lambda for unique_lock
6666
jl_unique_gcsafe_lock lock(engine_lock);
67-
arraylist_push(&objects_pinned_by_inference_engine, owner);
67+
arraylist_push(&objects_pinned_by_compiler_frontend, owner);
6868
InferKey key{m, owner};
6969
if ((signed)Awaiting.size() < tid + 1)
7070
Awaiting.resize(tid + 1);
7171
while (1) {
7272
auto record = Reservations.find(key);
7373
if (record == Reservations.end()) {
7474
Reservations[key] = ReservationInfo{tid, ci};
75-
arraylist_pop(&objects_pinned_by_inference_engine);
75+
arraylist_pop(&objects_pinned_by_compiler_frontend);
7676
return false;
7777
}
7878
// before waiting, need to run deadlock/cycle detection
@@ -81,7 +81,7 @@ jl_code_instance_t *jl_engine_reserve(jl_method_instance_t *m, jl_value_t *owner
8181
auto wait_tid = record->second.tid;
8282
while (1) {
8383
if (wait_tid == tid) {
84-
arraylist_pop(&objects_pinned_by_inference_engine);
84+
arraylist_pop(&objects_pinned_by_compiler_frontend);
8585
return true;
8686
}
8787
if ((signed)Awaiting.size() <= wait_tid)
@@ -99,7 +99,7 @@ jl_code_instance_t *jl_engine_reserve(jl_method_instance_t *m, jl_value_t *owner
9999
lock.wait(engine_wait);
100100
Awaiting[tid] = InferKey{};
101101
}
102-
arraylist_pop(&objects_pinned_by_inference_engine);
102+
arraylist_pop(&objects_pinned_by_compiler_frontend);
103103
})())
104104
ct->ptls->engine_nqueued--;
105105
JL_GC_POP();

src/gc-common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ JL_DLLEXPORT int jl_gc_enable(int on)
687687
// MISC
688688
// =========================================================================== //
689689

690-
arraylist_t objects_pinned_by_inference_engine;
690+
arraylist_t objects_pinned_by_compiler_frontend;
691691

692692
JL_DLLEXPORT jl_weakref_t *jl_gc_new_weakref(jl_value_t *value)
693693
{

src/gc-mmtk.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void jl_gc_init(void) {
7474

7575
jl_set_check_alive_type(mmtk_is_reachable_object);
7676

77-
arraylist_new(&objects_pinned_by_inference_engine, 0);
77+
arraylist_new(&objects_pinned_by_compiler_frontend, 0);
7878
arraylist_new(&to_finalize, 0);
7979
arraylist_new(&finalizer_list_marked, 0);
8080
gc_num.interval = default_collect_interval;
@@ -249,18 +249,18 @@ JL_DLLEXPORT void jl_gc_collect(jl_gc_collection_t collection) {
249249
// print_fragmentation();
250250
}
251251

252-
void gc_pin_objects_from_inference_engine(arraylist_t *objects_pinned_by_call)
252+
void gc_pin_objects_from_compiler_frontend(arraylist_t *objects_pinned_by_call)
253253
{
254-
for (size_t i = 0; i < objects_pinned_by_inference_engine.len; i++) {
255-
void *obj = objects_pinned_by_inference_engine.items[i];
254+
for (size_t i = 0; i < objects_pinned_by_compiler_frontend.len; i++) {
255+
void *obj = objects_pinned_by_compiler_frontend.items[i];
256256
unsigned char got_pinned = mmtk_pin_object(obj);
257257
if (got_pinned) {
258258
arraylist_push(objects_pinned_by_call, obj);
259259
}
260260
}
261261
}
262262

263-
void gc_unpin_objects_from_inference_engine(arraylist_t *objects_pinned_by_call)
263+
void gc_unpin_objects_from_compiler_frontend(arraylist_t *objects_pinned_by_call)
264264
{
265265
for (size_t i = 0; i < objects_pinned_by_call->len; i++) {
266266
void *obj = objects_pinned_by_call->items[i];
@@ -332,9 +332,9 @@ JL_DLLEXPORT void jl_gc_prepare_to_collect(void)
332332
#ifndef __clang_gcanalyzer__
333333
arraylist_t objects_pinned_by_call;
334334
arraylist_new(&objects_pinned_by_call, 0);
335-
gc_pin_objects_from_inference_engine(&objects_pinned_by_call);
335+
gc_pin_objects_from_compiler_frontend(&objects_pinned_by_call);
336336
mmtk_block_thread_for_gc();
337-
gc_unpin_objects_from_inference_engine(&objects_pinned_by_call);
337+
gc_unpin_objects_from_compiler_frontend(&objects_pinned_by_call);
338338
arraylist_free(&objects_pinned_by_call);
339339
#endif
340340
JL_UNLOCK_NOGC(&finalizers_lock);

src/julia.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ JL_DLLEXPORT JL_CONST_FUNC jl_gcframe_t **(jl_get_pgcstack)(void) JL_GLOBALLY_RO
13461346

13471347
// object pinning ------------------------------------------------------------
13481348

1349-
extern arraylist_t objects_pinned_by_inference_engine;
1349+
extern arraylist_t objects_pinned_by_compiler_frontend;
13501350
typedef bool (*check_alive_fn_type)(void *);
13511351
JL_DLLEXPORT void jl_set_check_alive_type(check_alive_fn_type fn);
13521352
JL_DLLEXPORT void jl_log_pinning_event(void *pinned_object, const char *filename, int lineno);

0 commit comments

Comments
 (0)