gh-100227: Only Use deepfreeze for the Main Interpreter (gh-103794)

Deep-frozen code objects are cannot be shared (currently) by
interpreters, due to how adaptive specialization can modify the
bytecodes. We work around this by only using the deep-frozen objects in
the main interpreter. This does incur a performance penalty for
subinterpreters, which we may be able to resolve later.
This commit is contained in:
Eric Snow 2023-04-24 15:48:05 -06:00 committed by GitHub
parent ae25855045
commit 19e4f757de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 34 deletions

View file

@ -2021,9 +2021,9 @@ find_frozen(PyObject *nameobj, struct frozen_info *info)
}
static PyObject *
unmarshal_frozen_code(struct frozen_info *info)
unmarshal_frozen_code(PyInterpreterState *interp, struct frozen_info *info)
{
if (info->get_code) {
if (info->get_code && _Py_IsMainInterpreter(interp)) {
PyObject *code = info->get_code();
assert(code != NULL);
return code;
@ -2070,7 +2070,7 @@ PyImport_ImportFrozenModuleObject(PyObject *name)
set_frozen_error(status, name);
return -1;
}
co = unmarshal_frozen_code(&info);
co = unmarshal_frozen_code(tstate->interp, &info);
if (co == NULL) {
return -1;
}
@ -3528,7 +3528,8 @@ _imp_get_frozen_object_impl(PyObject *module, PyObject *name,
return NULL;
}
PyObject *codeobj = unmarshal_frozen_code(&info);
PyInterpreterState *interp = _PyInterpreterState_GET();
PyObject *codeobj = unmarshal_frozen_code(interp, &info);
if (dataobj != Py_None) {
PyBuffer_Release(&buf);
}