-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-148571: [JIT] Preserve family-head recorder layouts for specialized opcode families #148730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ffa4177
13c0603
dcda8e7
e76e002
1004eff
33093df
b513af5
193baf0
83795a6
5b49abd
256d6cd
513f748
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix a crash in the JIT optimizer when specialized opcode families inherited incompatible recorded operand layouts. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -658,6 +658,44 @@ is_terminator(const _PyUOpInstruction *uop) | |
| ); | ||
| } | ||
|
|
||
| static PyObject * | ||
| record_trace_transform_to_type(PyObject *value) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like these to be generated from the recording uops, but that can wait for another PR. |
||
| { | ||
| PyObject *tp = Py_NewRef((PyObject *)Py_TYPE(value)); | ||
| Py_DECREF(value); | ||
| return tp; | ||
| } | ||
|
|
||
| /* _RECORD_NOS_GEN_FUNC and _RECORD_3OS_GEN_FUNC record the raw receiver. | ||
| * If it is a generator, return its function object; otherwise return NULL. | ||
| */ | ||
| static PyObject * | ||
| record_trace_transform_gen_func(PyObject *value) | ||
| { | ||
| PyObject *func = NULL; | ||
| if (PyGen_Check(value)) { | ||
| _PyStackRef f = ((PyGenObject *)value)->gi_iframe.f_funcobj; | ||
| if (!PyStackRef_IsNull(f)) { | ||
| func = Py_NewRef(PyStackRef_AsPyObjectBorrow(f)); | ||
| } | ||
| } | ||
| Py_DECREF(value); | ||
| return func; | ||
| } | ||
|
|
||
| /* _RECORD_BOUND_METHOD records the raw callable. | ||
| * Keep it only for bound methods; otherwise return NULL. | ||
| */ | ||
| static PyObject * | ||
| record_trace_transform_bound_method(PyObject *value) | ||
| { | ||
| if (Py_TYPE(value) == &PyMethod_Type) { | ||
| return value; | ||
| } | ||
| Py_DECREF(value); | ||
| return NULL; | ||
| } | ||
|
|
||
| /* Returns 1 on success (added to trace), 0 on trace end. | ||
| */ | ||
| // gh-142543: inlining this function causes stack overflows | ||
|
|
@@ -831,6 +869,8 @@ _PyJit_translate_single_bytecode_to_trace( | |
| // One for possible _DEOPT, one because _CHECK_VALIDITY itself might _DEOPT | ||
| trace->end -= 2; | ||
|
|
||
| const _PyOpcodeRecordSlotMap *record_slot_map = &_PyOpcode_RecordSlotMaps[opcode]; | ||
|
|
||
| assert(opcode != ENTER_EXECUTOR && opcode != EXTENDED_ARG); | ||
| assert(!_PyErr_Occurred(tstate)); | ||
|
|
||
|
|
@@ -1027,8 +1067,15 @@ _PyJit_translate_single_bytecode_to_trace( | |
| } | ||
| } | ||
| else if (_PyUop_Flags[uop] & HAS_RECORDS_VALUE_FLAG) { | ||
| PyObject *recorded_value = tracer->prev_state.recorded_values[record_idx]; | ||
| tracer->prev_state.recorded_values[record_idx] = NULL; | ||
| assert(record_idx < record_slot_map->count); | ||
| uint8_t record_slot = record_slot_map->slots[record_idx]; | ||
| assert(record_slot < tracer->prev_state.recorded_count); | ||
| PyObject *recorded_value = tracer->prev_state.recorded_values[record_slot]; | ||
| tracer->prev_state.recorded_values[record_slot] = NULL; | ||
| if ((record_slot_map->transform_mask & (1u << record_idx)) && | ||
| recorded_value != NULL) { | ||
| recorded_value = _PyOpcode_RecordTransformValue(uop, recorded_value); | ||
| } | ||
|
Comment on lines
+1074
to
+1078
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We cannot avoid storing the original values in the family record; we can only convert and release them as early as possible during the copy to uop process. |
||
| record_idx++; | ||
| operand = (uintptr_t)recorded_value; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.