| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Add free-threading support to the JIT. The JIT is only enabled on | ||
| single-threaded code in free-threading, and is disabled when multiple | ||
| threads are spawned. Patch by Ken Jin. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -298,7 +298,7 @@ functions is running. | |
|
|
||
| */ | ||
|
|
||
| #ifndef Py_GIL_DISABLED | ||
| #if _Py_TIER2 | ||
| static inline struct _func_version_cache_item * | ||
| get_cache_item(PyInterpreterState *interp, uint32_t version) | ||
| { | ||
| Expand All | @@ -315,11 +315,13 @@ _PyFunction_SetVersion(PyFunctionObject *func, uint32_t version) | |
| // This should only be called from MAKE_FUNCTION. No code is specialized | ||
| // based on the version, so we do not need to stop the world to set it. | ||
| func->func_version = version; | ||
| #ifndef Py_GIL_DISABLED | ||
| #if _Py_TIER2 | ||
| PyInterpreterState *interp = _PyInterpreterState_GET(); | ||
| FT_MUTEX_LOCK(&interp->func_state.mutex); | ||
| struct _func_version_cache_item *slot = get_cache_item(interp, version); | ||
| slot->func = func; | ||
| slot->code = func->func_code; | ||
| FT_MUTEX_UNLOCK(&interp->func_state.mutex); | ||
| #endif | ||
| } | ||
|
|
||
| Expand All | @@ -330,13 +332,15 @@ func_clear_version(PyInterpreterState *interp, PyFunctionObject *func) | |
| // Version was never set or has already been cleared. | ||
| return; | ||
| } | ||
| #ifndef Py_GIL_DISABLED | ||
| #if _Py_TIER2 | ||
| FT_MUTEX_LOCK(&interp->func_state.mutex); | ||
| struct _func_version_cache_item *slot = | ||
| get_cache_item(interp, func->func_version); | ||
| if (slot->func == func) { | ||
| slot->func = NULL; | ||
| // Leave slot->code alone, there may be use for it. | ||
| } | ||
| FT_MUTEX_UNLOCK(&interp->func_state.mutex); | ||
| #endif | ||
| func->func_version = FUNC_VERSION_CLEARED; | ||
| } | ||
| Expand All | @@ -358,8 +362,9 @@ _PyFunction_ClearVersion(PyFunctionObject *func) | |
| void | ||
| _PyFunction_ClearCodeByVersion(uint32_t version) | ||
| { | ||
| #ifndef Py_GIL_DISABLED | ||
| #if _Py_TIER2 | ||
| PyInterpreterState *interp = _PyInterpreterState_GET(); | ||
| FT_MUTEX_LOCK(&interp->func_state.mutex); | ||
| struct _func_version_cache_item *slot = get_cache_item(interp, version); | ||
| if (slot->code) { | ||
| assert(PyCode_Check(slot->code)); | ||
| Expand All | @@ -369,15 +374,19 @@ _PyFunction_ClearCodeByVersion(uint32_t version) | |
| slot->func = NULL; | ||
| } | ||
| } | ||
| FT_MUTEX_UNLOCK(&interp->func_state.mutex); | ||
| #endif | ||
| } | ||
|
|
||
| PyFunctionObject * | ||
| _PyFunction_LookupByVersion(uint32_t version, PyObject **p_code) | ||
|
Comment thread
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIs this function really used somewhere?
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThat's strange, you're right, it's not used. It's useful for the optimizer though, so we might want to use it in the future.
Sorry, something went wrong.
All reactions
|
||
| { | ||
| #ifdef Py_GIL_DISABLED | ||
| #ifndef _Py_TIER2 | ||
| return NULL; | ||
| #else | ||
| // This function does not need locking/atomics as it can only be | ||
| // called from the optimizer, which is currently disabled | ||
| // when there are multiple threads. | ||
| PyInterpreterState *interp = _PyInterpreterState_GET(); | ||
| struct _func_version_cache_item *slot = get_cache_item(interp, version); | ||
| if (slot->code) { | ||
| Expand All | @@ -401,6 +410,10 @@ _PyFunction_LookupByVersion(uint32_t version, PyObject **p_code) | |
| uint32_t | ||
| _PyFunction_GetVersionForCurrentState(PyFunctionObject *func) | ||
| { | ||
| // This function does not need locking/atomics as it can only be | ||
|
Comment thread
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityWe use the function version in specialized instructions, so it is used in tier 1.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThe use in the specializer is protected because it's accessing a stack variable which holds a strong reference to it. I will clarify that the unsnchronized use is only in the optimizer and it's fine there.
Sorry, something went wrong.
All reactions
|
||
| // called from the specializing interpreter or optimizer. | ||
| // The specializing interpreter holds a strong reference to the function. | ||
| // The optimizer is currently disabled when there are multiple threads. | ||
| return func->func_version; | ||
| } | ||
|
|
||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis changes the tier 1 with-gil behavior.
I don't see why we would need the cache in tier 1, but can you double check?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityYes I double checked.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.