diff --git a/src/racket/src/jit.c b/src/racket/src/jit.c index 05a3fa89e3..e3ffa81ca7 100644 --- a/src/racket/src/jit.c +++ b/src/racket/src/jit.c @@ -3312,7 +3312,7 @@ static void on_demand_generate_lambda(Scheme_Native_Closure *nc, int argc, Schem if (ndata->code != scheme_on_demand_jit_code) return; - ndata->arity_code = NULL; /* => in progress */ + ndata->arity_code = sjc.in_progress_on_demand_jit_arity_code; /* => in progress */ scheme_generate_one(NULL, do_generate_closure, &gdata, 1, data->name, ndata); diff --git a/src/racket/src/jit.h b/src/racket/src/jit.h index 5d0ae881f9..27753a79d2 100644 --- a/src/racket/src/jit.h +++ b/src/racket/src/jit.h @@ -227,7 +227,7 @@ struct scheme_jit_common_record { void *fxvector_ref_code, *fxvector_ref_check_index_code, *fxvector_set_code, *fxvector_set_check_index_code; void *struct_raw_ref_code, *struct_raw_set_code; void *syntax_e_code; - void *on_demand_jit_arity_code; + void *on_demand_jit_arity_code, *in_progress_on_demand_jit_arity_code; void *get_stack_pointer_code; void *stack_cache_pop_code; void *struct_pred_code, *struct_pred_multi_code; diff --git a/src/racket/src/jitcall.c b/src/racket/src/jitcall.c index 23762634c9..9fee1ee2d9 100644 --- a/src/racket/src/jitcall.c +++ b/src/racket/src/jitcall.c @@ -1454,7 +1454,7 @@ int scheme_generate_app(Scheme_App_Rec *app, Scheme_Object **alt_rands, int num_ Scheme_Native_Closure *nc; nc = (Scheme_Native_Closure *)scheme_jit_closure((Scheme_Object *)data, NULL); if (nc->code->code == scheme_on_demand_jit_code) { - if (nc->code->arity_code) { /* i.e., not in progress */ + if (nc->code->arity_code != sjc.in_progress_on_demand_jit_arity_code) { scheme_on_demand_generate_lambda(nc, 0, NULL); } } diff --git a/src/racket/src/jitcommon.c b/src/racket/src/jitcommon.c index bcd89ad733..72987b7522 100644 --- a/src/racket/src/jitcommon.c +++ b/src/racket/src/jitcommon.c @@ -729,6 +729,12 @@ static int common2(mz_jit_state *jitter, void *_data) CHECK_LIMIT(); scheme_jit_register_helper_func(jitter, scheme_on_demand_jit_code); + /* Used for the state of a function that is being JITted + (for a kind of cycle detection) without breaking concurrent + future threads that might try to call the function. */ + sjc.in_progress_on_demand_jit_arity_code = jit_get_ip().ptr; + (void)jit_jmpi(sjc.on_demand_jit_arity_code); + /* *** app_values_tail_slow_code *** */ /* RELIES ON jit_prolog(NATIVE_ARG_COUNT) FROM ABOVE */ /* Rator in V1, arguments are in thread's multiple-values cells. */