]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-116760: Fix pystats for trace attempts (GH-116761)
authorMichael Droettboom <mdboom@gmail.com>
Wed, 13 Mar 2024 22:13:33 +0000 (18:13 -0400)
committerGitHub <noreply@github.com>
Wed, 13 Mar 2024 22:13:33 +0000 (22:13 +0000)
There are now at least two bytecodes that may attempt to optimize,
JUMP_BACK, and more recently, COLD_EXIT.

Only the JUMP_BACK was counting the attempt in the stats.
This moves that counter to uop_optimize itself so it should
always happen no matter where it is called from.

Python/bytecodes.c
Python/generated_cases.c.h
Python/optimizer.c

index ec05e40bd23fcb50fdb3410cecfa27a08fedbef6..af2e2c8f52ee29c6017ba5260803f9884e47c9ac 100644 (file)
@@ -2349,7 +2349,6 @@ dummy_func(
             // Use '>=' not '>' so that the optimizer/backoff bits do not effect the result.
             // Double-check that the opcode isn't instrumented or something:
             if (offset_counter >= threshold && this_instr->op.code == JUMP_BACKWARD) {
-                OPT_STAT_INC(attempts);
                 _Py_CODEUNIT *start = this_instr;
                 /* Back up over EXTENDED_ARGs so optimizer sees the whole instruction */
                 while (oparg > 255) {
index 72892725fb25d82593b7b1b88de0ca76f8fafdf1..7d02e49d040c231c2f6c910f51a46b66edbed12b 100644 (file)
             // Use '>=' not '>' so that the optimizer/backoff bits do not effect the result.
             // Double-check that the opcode isn't instrumented or something:
             if (offset_counter >= threshold && this_instr->op.code == JUMP_BACKWARD) {
-                OPT_STAT_INC(attempts);
                 _Py_CODEUNIT *start = this_instr;
                 /* Back up over EXTENDED_ARGs so optimizer sees the whole instruction */
                 while (oparg > 255) {
index aaf75b2339cd2e5cbf2d0731e2dfa3471fe7f22a..88c45f2e73c68214fcdbf022b82e6be8fb883ac5 100644 (file)
@@ -1003,6 +1003,7 @@ uop_optimize(
     _PyBloomFilter dependencies;
     _Py_BloomFilter_Init(&dependencies);
     _PyUOpInstruction buffer[UOP_MAX_TRACE_LENGTH];
+    OPT_STAT_INC(attempts);
     int err = translate_bytecode_to_trace(frame, instr, buffer, UOP_MAX_TRACE_LENGTH, &dependencies);
     if (err <= 0) {
         // Error or nothing translated