@@ -252,9 +252,9 @@ impl TraceJitEngine {
252252 if self . blocked_roots . contains ( & ip) {
253253 return None ;
254254 }
255- if !self . is_loop_header ( program, ip) {
256- return None ;
257- }
255+ if !self . is_loop_header ( program, ip) {
256+ return None ;
257+ }
258258
259259 let count = self . hot_counts . entry ( ip) . or_insert ( 0 ) ;
260260 * count = count. saturating_add ( 1 ) ;
@@ -296,9 +296,57 @@ impl TraceJitEngine {
296296 }
297297 }
298298
299- pub fn trace_clone ( & self , trace_id : usize ) -> Option < JitTrace > {
300- self . traces . get ( trace_id) . cloned ( )
301- }
299+ pub fn trace_clone ( & self , trace_id : usize ) -> Option < JitTrace > {
300+ self . traces . get ( trace_id) . cloned ( )
301+ }
302+
303+ pub fn observe_exit_ip ( & mut self , ip : usize , program : & Program ) -> Option < usize > {
304+ if !self . config . enabled || !native_jit_supported ( ) {
305+ return None ;
306+ }
307+ // Keep default behavior unchanged: only aggressively chain-compile exit roots when the
308+ // user requested the most aggressive hotness policy.
309+ if self . config . hot_loop_threshold > 1 {
310+ return None ;
311+ }
312+ if let Some ( & trace_id) = self . compiled_by_root . get ( & ip) {
313+ return Some ( trace_id) ;
314+ }
315+ if self . blocked_roots . contains ( & ip) {
316+ return None ;
317+ }
318+
319+ let line = program
320+ . debug
321+ . as_ref ( )
322+ . and_then ( |debug| debug. line_for_offset ( ip) ) ;
323+ let result = if self . config . hot_loop_threshold == 0 {
324+ Err ( JitNyiReason :: HotLoopThresholdZero )
325+ } else {
326+ self . compile_trace ( program, ip)
327+ } ;
328+
329+ match result {
330+ Ok ( trace_id) => {
331+ self . attempts . push ( JitAttempt {
332+ root_ip : ip,
333+ line,
334+ result : Ok ( trace_id) ,
335+ } ) ;
336+ self . compiled_by_root . insert ( ip, trace_id) ;
337+ Some ( trace_id)
338+ }
339+ Err ( reason) => {
340+ self . attempts . push ( JitAttempt {
341+ root_ip : ip,
342+ line,
343+ result : Err ( reason) ,
344+ } ) ;
345+ self . blocked_roots . insert ( ip) ;
346+ None
347+ }
348+ }
349+ }
302350
303351 pub fn trace_has_call ( & self , trace_id : usize ) -> bool {
304352 self . traces
0 commit comments