reference leak when a JIT trace is rewound

オープン
#157,875 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
c, python
領域
compilers

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Python
スター
77.2k
フォーク
36k
平均マージ
1日 9時間
マージ済み PR(30日)
558

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python/cpython のほかの issue

python/cpython の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。