reference leak when a JIT trace is rewound

Aperta
#157,875 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
c, python
Ambito
compilers

Direzione di ricerca

Start by running the supplied Python reproducer with the JIT enabled, then inspect the rewind loop shown in the report and the value-recording RECORD uops. Trace whether the recorded object is released when the trace is rewound; done means gc.collect() allows ref() to return None without regressing JIT behavior.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

type-bug

Bug report

Bug description:
import gc
import sys
import weakref

def run():
    class C:
        def __iter__(self):
            return self
        def __next__(self):
            raise StopIteration

    obj = C()
    for _ in range(10_000):
        for _ in obj:
            pass
    return weakref.ref(C)


ref = run()
gc.collect()
print("jit enabled:", sys._jit.is_enabled())
print("leaked:", ref() is not None)

This looks to be caused by value-recording uop (in the RECORD family) taking a strong reference to an object not being decref'd when traces are rewound

{
            _PyUOpInstruction *curr = uop_buffer_last(trace);
            while (curr->opcode != _SET_IP && uop_buffer_length(trace) > 2) {
                trace->next--;
                curr = uop_buffer_last(trace);
            }
            if (curr->opcode == _SET_IP) {
                int32_t old_target = (int32_t)uop_get_target(curr);
                curr->opcode = _DEOPT;
                curr->format = UOP_FORMAT_TARGET;
                curr->target = old_target;
            }
            goto done;
        }
CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Lingua principale
Python
Stelle
77.2k
Fork
36k
Merge medio
1g 9h
PR unite (30g)
558

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python/cpython

Tutte le issue di python/cpython

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.