Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit db58a2f

Browse filesBrowse files
committed
Use a flag rather than counting externally
1 parent cb80086 commit db58a2f
Copy full SHA for db58a2f

File tree

Expand file treeCollapse file tree

9 files changed

+20
-37
lines changed
Filter options
Expand file treeCollapse file tree

9 files changed

+20
-37
lines changed

‎Include/cpython/optimizer.h

Copy file name to clipboardExpand all lines: Include/cpython/optimizer.h
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,8 @@ void _Py_ExecutorClear(_PyExecutorObject *);
8787
void _Py_BloomFilter_Init(_PyBloomFilter *);
8888
void _Py_BloomFilter_Add(_PyBloomFilter *bloom, void *obj);
8989
PyAPI_FUNC(void) _Py_Executor_DependsOn(_PyExecutorObject *executor, void *obj);
90-
PyAPI_FUNC(int) _Py_Executors_InvalidateDependency(PyInterpreterState *interp, void *obj);
91-
extern void _Py_Executors_InvalidateAll(PyInterpreterState *interp);
92-
int _Py_Executors_Count(PyInterpreterState *interp);
90+
PyAPI_FUNC(void) _Py_Executors_InvalidateDependency(PyInterpreterState *interp, void *obj, int is_invalidation);
91+
extern void _Py_Executors_InvalidateAll(PyInterpreterState *interp, int is_invalidation);
9392

9493
/* For testing */
9594
PyAPI_FUNC(PyObject *)PyUnstable_Optimizer_NewCounter(void);

‎Include/internal/pycore_code.h

Copy file name to clipboardExpand all lines: Include/internal/pycore_code.h
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ extern int _PyStaticCode_Init(PyCodeObject *co);
285285
do { if (_Py_stats && PyFunction_Check(callable)) _Py_stats->call_stats.eval_calls[name]++; } while (0)
286286
#define GC_STAT_ADD(gen, name, n) do { if (_Py_stats) _Py_stats->gc_stats[(gen)].name += (n); } while (0)
287287
#define OPT_STAT_INC(name) do { if (_Py_stats) _Py_stats->optimization_stats.name++; } while (0)
288-
#define OPT_STAT_ADD(name, value) do { if (_Py_stats) _Py_stats->optimization_stats.name += value; } while (0)
289288
#define UOP_STAT_INC(opname, name) do { if (_Py_stats) { assert(opname < 512); _Py_stats->optimization_stats.opcode[opname].name++; } } while (0)
290289
#define OPT_UNSUPPORTED_OPCODE(opname) do { if (_Py_stats) _Py_stats->optimization_stats.unsupported_opcode[opname]++; } while (0)
291290
#define OPT_HIST(length, name) \
@@ -312,7 +311,6 @@ PyAPI_FUNC(PyObject*) _Py_GetSpecializationStats(void);
312311
#define EVAL_CALL_STAT_INC_IF_FUNCTION(name, callable) ((void)0)
313312
#define GC_STAT_ADD(gen, name, n) ((void)0)
314313
#define OPT_STAT_INC(name) ((void)0)
315-
#define OPT_STAT_ADD(name, value) ((void)0)
316314
#define UOP_STAT_INC(opname, name) ((void)0)
317315
#define OPT_UNSUPPORTED_OPCODE(opname) ((void)0)
318316
#define OPT_HIST(length, name) ((void)0)

‎Modules/_testinternalcapi.c

Copy file name to clipboardExpand all lines: Modules/_testinternalcapi.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ static PyObject *
10331033
invalidate_executors(PyObject *self, PyObject *obj)
10341034
{
10351035
PyInterpreterState *interp = PyInterpreterState_Get();
1036-
_Py_Executors_InvalidateDependency(interp, obj);
1036+
_Py_Executors_InvalidateDependency(interp, obj, 1);
10371037
Py_RETURN_NONE;
10381038
}
10391039

‎Python/instrumentation.c

Copy file name to clipboardExpand all lines: Python/instrumentation.c
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,7 @@ _Py_Instrument(PyCodeObject *code, PyInterpreterState *interp)
15741574
if (code->co_executors != NULL) {
15751575
_PyCode_Clear_Executors(code);
15761576
}
1577-
_Py_Executors_InvalidateDependency(interp, code);
1577+
_Py_Executors_InvalidateDependency(interp, code, 1);
15781578
int code_len = (int)Py_SIZE(code);
15791579
/* Exit early to avoid creating instrumentation
15801580
* data for potential statically allocated code
@@ -1794,7 +1794,7 @@ _PyMonitoring_SetEvents(int tool_id, _PyMonitoringEventSet events)
17941794
return -1;
17951795
}
17961796
set_global_version(interp, new_version);
1797-
_Py_Executors_InvalidateAll(interp);
1797+
_Py_Executors_InvalidateAll(interp, 1);
17981798
return instrument_all_executing_code_objects(interp);
17991799
}
18001800

@@ -1824,7 +1824,7 @@ _PyMonitoring_SetLocalEvents(PyCodeObject *code, int tool_id, _PyMonitoringEvent
18241824
/* Force instrumentation update */
18251825
code->_co_instrumentation_version -= MONITORING_VERSION_INCREMENT;
18261826
}
1827-
_Py_Executors_InvalidateDependency(interp, code);
1827+
_Py_Executors_InvalidateDependency(interp, code, 1);
18281828
if (_Py_Instrument(code, interp)) {
18291829
return -1;
18301830
}

‎Python/optimizer.c

Copy file name to clipboardExpand all lines: Python/optimizer.c
+9-22Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,12 +1135,10 @@ _Py_Executor_DependsOn(_PyExecutorObject *executor, void *obj)
11351135

11361136
/* Invalidate all executors that depend on `obj`
11371137
* May cause other executors to be invalidated as well
1138-
* Returns the number of executors that were invalidated.
11391138
*/
1140-
int
1141-
_Py_Executors_InvalidateDependency(PyInterpreterState *interp, void *obj)
1139+
void
1140+
_Py_Executors_InvalidateDependency(PyInterpreterState *interp, void *obj, int is_invalidation)
11421141
{
1143-
int count = 0;
11441142
_PyBloomFilter obj_filter;
11451143
_Py_BloomFilter_Init(&obj_filter);
11461144
_Py_BloomFilter_Add(&obj_filter, obj);
@@ -1151,16 +1149,17 @@ _Py_Executors_InvalidateDependency(PyInterpreterState *interp, void *obj)
11511149
_PyExecutorObject *next = exec->vm_data.links.next;
11521150
if (bloom_filter_may_contain(&exec->vm_data.bloom, &obj_filter)) {
11531151
_Py_ExecutorClear(exec);
1154-
count++;
1152+
if (is_invalidation) {
1153+
OPT_STAT_INC(executors_invalidated);
1154+
}
11551155
}
11561156
exec = next;
11571157
}
1158-
return count;
11591158
}
11601159

11611160
/* Invalidate all executors */
11621161
void
1163-
_Py_Executors_InvalidateAll(PyInterpreterState *interp)
1162+
_Py_Executors_InvalidateAll(PyInterpreterState *interp, int is_invalidation)
11641163
{
11651164
while (interp->executor_list_head) {
11661165
_PyExecutorObject *executor = interp->executor_list_head;
@@ -1171,20 +1170,8 @@ _Py_Executors_InvalidateAll(PyInterpreterState *interp)
11711170
else {
11721171
_Py_ExecutorClear(executor);
11731172
}
1173+
if (is_invalidation) {
1174+
OPT_STAT_INC(executors_invalidated);
1175+
}
11741176
}
11751177
}
1176-
1177-
/* Return the number of executors */
1178-
int
1179-
_Py_Executors_Count(PyInterpreterState *interp)
1180-
{
1181-
int count = 0;
1182-
/* Walk the list of executors */
1183-
for (_PyExecutorObject *exec = interp->executor_list_head;
1184-
exec != NULL;
1185-
exec = exec->vm_data.links.next) {
1186-
count++;
1187-
assert(exec->vm_data.valid);
1188-
}
1189-
return count;
1190-
}

‎Python/optimizer_analysis.c

Copy file name to clipboardExpand all lines: Python/optimizer_analysis.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ globals_watcher_callback(PyDict_WatchEvent event, PyObject* dict,
3939
{
4040
RARE_EVENT_STAT_INC(watched_globals_modification);
4141
assert(get_mutations(dict) < _Py_MAX_ALLOWED_GLOBALS_MODIFICATIONS);
42-
_Py_Executors_InvalidateDependency(_PyInterpreterState_GET(), dict);
42+
_Py_Executors_InvalidateDependency(_PyInterpreterState_GET(), dict, 1);
4343
increment_mutations(dict);
4444
PyDict_Unwatch(GLOBALS_WATCHER_ID, dict);
4545
return 0;

‎Python/pylifecycle.c

Copy file name to clipboardExpand all lines: Python/pylifecycle.c
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ builtins_dict_watcher(PyDict_WatchEvent event, PyObject *dict, PyObject *key, Py
612612
{
613613
PyInterpreterState *interp = _PyInterpreterState_GET();
614614
if (interp->rare_events.builtin_dict < _Py_MAX_ALLOWED_BUILTINS_MODIFICATIONS) {
615-
_Py_Executors_InvalidateAll(interp);
615+
_Py_Executors_InvalidateAll(interp, 1);
616616
}
617617
RARE_EVENT_INTERP_INC(interp, builtin_dict);
618618
return 0;
@@ -1626,7 +1626,7 @@ finalize_modules(PyThreadState *tstate)
16261626
PyInterpreterState *interp = tstate->interp;
16271627

16281628
// Invalidate all executors and turn off tier 2 optimizer
1629-
_Py_Executors_InvalidateAll(interp);
1629+
_Py_Executors_InvalidateAll(interp, 0);
16301630
Py_XDECREF(interp->optimizer);
16311631
interp->optimizer = &_PyOptimizer_Default;
16321632

‎Python/pystate.c

Copy file name to clipboardExpand all lines: Python/pystate.c
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,8 +2624,7 @@ _PyInterpreterState_SetEvalFrameFunc(PyInterpreterState *interp,
26242624
return;
26252625
}
26262626
if (eval_frame != NULL) {
2627-
OPT_STAT_ADD(executors_invalidated, _Py_Executors_Count(interp));
2628-
_Py_Executors_InvalidateAll(interp);
2627+
_Py_Executors_InvalidateAll(interp, 1);
26292628
}
26302629
RARE_EVENT_INC(set_eval_frame_func);
26312630
interp->eval_frame = eval_frame;

‎Python/sysmodule.c

Copy file name to clipboardExpand all lines: Python/sysmodule.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2138,7 +2138,7 @@ sys__clear_internal_caches_impl(PyObject *module)
21382138
/*[clinic end generated code: output=0ee128670a4966d6 input=253e741ca744f6e8]*/
21392139
{
21402140
PyInterpreterState *interp = _PyInterpreterState_GET();
2141-
_Py_Executors_InvalidateAll(interp);
2141+
_Py_Executors_InvalidateAll(interp, 0);
21422142
PyType_ClearCache();
21432143
Py_RETURN_NONE;
21442144
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.