Skip to content
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

Globals immortal objects flags #9

Closed
wants to merge 7 commits into from

Conversation

ericsnowcurrently
Copy link
Owner

@ericsnowcurrently ericsnowcurrently commented Mar 10, 2021

This is a branch I started in December, before I found python#19474. My approach wasn't actually terribly different from what Eddie proposed. After finding that PR I updated this one a little bit, borrowing some of the details there.

Notable differences from Eddie's PR:

  • as much code as possible limited to the internal header files
  • no touches to _Py_INCREF()
  • instead of trying to keep the refcount at the magic tag, keep it at-or-above it (and reset to the tag occasionally)
  • enabled by default in the runtime and opt-in for the public C-API
  • I left changes to static types out

Note that I haven't looked at this code for a while. There are probably a number of tweaks to make before posting this upstream.

(An alternative approach, albeit probably not ultimately viable, involves sticking a dummy type in ob_type: python/cpython@master...ericsnowcurrently:globals-immortal-objects-obtype)

/* The GC bit-shifts refcounts left by two, and after that shift we still
* need this to be >> 0, so leave three high zero bits (the sign bit and
* room for a shift of two.) */
#define _PyObject_IMMORTAL_BIT (1LL << (8 * sizeof(Py_ssize_t) - 4))
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a higher bit on 32-bit builds?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not, due to the bits used by GC.

@ericsnowcurrently
Copy link
Owner Author

FYI, only one test fails: "test_negative_refcount (test.test_capi.CAPITest)"

@ericsnowcurrently ericsnowcurrently force-pushed the globals-immortal-objects-flags branch from 5f91c94 to a80c213 Compare March 11, 2021 22:10
@ericsnowcurrently
Copy link
Owner Author

I've created a PR upstream: python#24828.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant