← Back to Pull requests

codegen: pin call-target CodeInstances that are not cache-reachable #62468

Open
gbaraldi opened this pull request with 8 lines diff across 1 files
View on GitHub
gbaraldi gbaraldi commented on Jul 22, 2026 19:10 UTC
Author

The linking metadata of an emitted module holds raw pointers to its
call-target CodeInstances, and JuliaOJIT::linkCallTarget dereferences
them when the module is materialized. Compiler.add_codeinsts_to_jit!
maintains the rooting invariant by cache-inserting the CIs it compiles,
but callees with invalid ABI sparams are skipped without rooting while
the caller still records them as call targets. Upstream the pending
window is a few statements (materialization happens within the same
jl_compile_method_internal call); under tiered batching, materialization
is deferred to the compiled code's first call, so the collected CI is
dereferenced on a JIT dispatcher thread arbitrarily later. Observed at
test/core.jl's issue-#47476 tests (exactly the invalid-sparams shape) on
both macOS architectures:
https://buildkite.com/julialang/julia-pr/builds/316#019f4d6f-5f10-406d-9aff-2bdb6bc7717f

Pin such CIs as global roots at emission. TODO: scope the root to the
pending materialization instead.

This commit was written with the assistance of generative AI (Claude).

Diff: 8 lines (+8 / -0) across 1 files Reviewer: xal-0 Review duration: 159877m
All Vouch review confidence checks passed
Residual risk 0.03 = Change Risk (0.23) × (1 − Review Confidence (0.87)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.23 · 8 lines diff across 1 files
0.23
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.89 · 3 substantive comment(s)
0.89
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
87%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.131
Real PR Conversation Timeline
4 items
gbaraldi gbaraldi commented on Jul 22, 2026 19:11 UTC
Author

This is that discussion we had a while back where these CIs are never put into caches but codegen expects them too @xal-0. Not sure if this is the best way

xal-0 xal-0 commented on code on Jul 24, 2026 00:23 UTC
Code Review
src/jitlayers.cpp:1
@@ -268,6 +268,14 @@ StringRef jl_codegen_output_t::get_call_target(jl_code_instance_t *ci, bool spec
     }
     std::string protoname = make_name(JL_SYMBOL_SPECPTR_PROTO, api,
                                       name_from_method_instance(jl_get_ci_mi(ci)));
+    // The linking metadata holds this CodeInstance until the module is
+    // materialized, and linkCallTarget dereferences it on the dispatcher
+    // thread at that point. CIs in their MI's cache are rooted through the
+    // method table, but inference-local edge CIs have no other root once
+    // inference drops its results, and the pending window is arbitrarily
+    // long. Pin those. TODO: scope this root to the pending materialization.
+    if (!jl_mi_cache_has_ci(jl_get_ci_mi(ci), ci) && !jl_is_globally_rooted((jl_value_t*)ci))

The jl_is_globally_rooted call is redundant.

xal-0 xal-0 commented on code on Jul 24, 2026 00:26 UTC
Code Review
src/jitlayers.cpp:1
@@ -268,6 +268,14 @@ StringRef jl_codegen_output_t::get_call_target(jl_code_instance_t *ci, bool spec
     }
     std::string protoname = make_name(JL_SYMBOL_SPECPTR_PROTO, api,
                                       name_from_method_instance(jl_get_ci_mi(ci)));
+    // The linking metadata holds this CodeInstance until the module is
+    // materialized, and linkCallTarget dereferences it on the dispatcher
+    // thread at that point. CIs in their MI's cache are rooted through the
+    // method table, but inference-local edge CIs have no other root once
+    // inference drops its results, and the pending window is arbitrarily
+    // long. Pin those. TODO: scope this root to the pending materialization.

I would like a better explanation of why we produce these invokes now (since #61915?). We know the target of invokes need to be rooted before being added to the JIT, but why are we getting these in the first place?

Reviewers
Assignees
gbaraldi gbaraldi
Labels
risk: low confidence: 87.1% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 23.1% (LOW) · Higher = larger blast radius
23.1%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 87.1% · Lower = rushed or shallow review
87.1%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 3.0% · Safe to merge
3.0%