Commit Graph

99 Commits

Author SHA1 Message Date
Pablo Galindo Salgado 02918aa961
gh-116604: Correctly honor the gc status when calling _Py_RunGC (#116628) 2024-03-12 12:00:49 +00:00
Sam Gross b24c9161a6
gh-112529: Make the GC scheduling thread-safe (#114880)
The GC keeps track of the number of allocations (less deallocations)
since the last GC. This buffers the count in thread-local state and uses
atomic operations to modify the per-interpreter count. The thread-local
buffering avoids contention on shared state.

A consequence is that the GC scheduling is not as precise, so
"test_sneaky_frame_object" is skipped because it requires that the GC be
run exactly after allocating a frame object.
2024-02-16 11:22:27 -05:00
Mark Shannon 8a3c499ffe
GH-108362: Revert "GH-108362: Incremental GC implementation (GH-108038)" (#115132)
Revert "GH-108362: Incremental GC implementation (GH-108038)"

This reverts commit 36518e69d7.
2024-02-07 12:38:34 +00:00
Mark Shannon 36518e69d7
GH-108362: Incremental GC implementation (GH-108038) 2024-02-05 18:28:51 +00:00
Sam Gross b52fc70d1a
gh-112529: Implement GC for free-threaded builds (#114262)
* gh-112529: Implement GC for free-threaded builds

This implements a mark and sweep GC for the free-threaded builds of
CPython. The implementation relies on mimalloc to find GC tracked
objects (i.e., "containers").
2024-01-25 10:27:36 -08:00
Sam Gross 99854ce170
gh-113688: Split up gcmodule.c (gh-113715)
This splits part of Modules/gcmodule.c of into Python/gc.c, which
now contains the core garbage collection implementation. The Python
module remain in the Modules/gcmodule.c file.
2024-01-05 12:17:16 -08:00
Nikita Sobolev d329f859b9
gh-99430: Remove duplicated tests for old-styled classes (#99432)
python 1 & 2 were a loong time ago.
2022-11-13 10:30:00 -08:00
Victor Stinner 7b2064b4b9
gh-93353: Add test.support.late_deletion() (#93774) 2022-06-14 01:09:23 +02:00
Dennis Sweeney f2b4e458b3
gh-91636: Don't clear required fields of function objects (GH-91651) 2022-04-21 02:06:35 -04:00
Christian Heimes 2b16a08bc7
bpo-40280: Detect missing threading on WASM platforms (GH-32352)
Co-authored-by: Brett Cannon <brett@python.org>
2022-04-07 09:22:47 +02:00
Christian Heimes 8464fbc42e
bpo-40280: Skip subprocess-based tests on wasm32-emscripten (GH-30615) 2022-01-25 08:09:06 +01:00
Mark Shannon a8b9350964
bpo-45340: Don't create object dictionaries unless actually needed (GH-28802)
* Never change types' cached keys. It could invalidate inline attribute objects.

* Lazily create object dictionaries.

* Update specialization of LOAD/STORE_ATTR.

* Don't update shared keys version for deletion of value.

* Update gdb support to handle instance values.

* Rename SPLIT_KEYS opcodes to INSTANCE_VALUE.
2021-10-13 14:19:34 +01:00
Serhiy Storchaka 40348acc18
bpo-45229: Remove test_main in many tests (GH-28405)
Instead of explicitly enumerate test classes for run_unittest()
use the unittest ability to discover tests. This also makes these
tests discoverable and runnable with unittest.

load_tests() can be used for dynamic generating tests and adding
doctests. setUpModule(), tearDownModule() and addModuleCleanup()
can be used for running code before and after all module tests.
2021-09-19 15:27:33 +03:00
Victor Stinner 615069eb08
bpo-44184: Fix subtype_dealloc() for freed type (GH-26274)
Fix a crash at Python exit when a deallocator function removes the
last strong reference to a heap type.

Don't read type memory after calling basedealloc() since
basedealloc() can deallocate the type and free its memory.

_PyMem_IsPtrFreed() argument is now constant.
2021-05-21 19:19:54 +02:00
Inada Naoki 3caea9adda
bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25171)
* Fix test_float
* Fix _osx_support
* Fix test_fstring
* Fix test_gc
* Fix test_gzip
* Fix test_hashlib
* Fix unrelated whitespace issue

Co-authored-by: Ned Deily <nad@python.org>
2021-04-04 17:01:10 +09:00
Brandt Bucher c13b847a6f
bpo-41984: GC track all user classes (GH-22701) 2020-10-14 18:44:07 -07:00
Hai Shi 4660597b51
bpo-40275: Use new test.support helper submodules in tests (GH-21448) 2020-08-03 18:49:18 +02:00
Hai Shi e80697d687
bpo-40275: Adding threading_helper submodule in test.support (GH-20263) 2020-05-28 00:10:27 +02:00
Victor Stinner c6e5c1123b
bpo-39489: Remove COUNT_ALLOCS special build (GH-18259)
Remove:

* COUNT_ALLOCS macro
* sys.getcounts() function
* SHOW_ALLOC_COUNT code in listobject.c
* SHOW_TRACK_COUNT code in tupleobject.c
* PyConfig.show_alloc_count field
* -X showalloccount command line option
* @test.support.requires_type_collecting decorator
2020-02-03 15:17:15 +01:00
Pablo Galindo a2ec3f07f7
bpo-39322: Add gc.is_finalized to check if an object has been finalised by the gc (GH-17989) 2020-01-14 12:06:45 +00:00
Victor Stinner 6cac113666
bpo-38991: Remove test.support.strip_python_stderr() (GH-17490)
test.support: run_python_until_end(), assert_python_ok() and
assert_python_failure() functions no longer strip whitespaces from
stderr.
2019-12-08 08:38:16 +01:00
Neil Schemenauer 392a13bb93
bpo-38006: Add unit test for weakref clear bug (GH-16788) 2019-10-15 20:56:48 -07:00
Pablo Galindo 466326dcdf
bpo-38379: Don't block collection of unreachable objects when some objects resurrect (GH-16687)
Currently if any finalizer invoked during garbage collection resurrects any object, the gc gives up and aborts the collection. Although finalizers are assured to only run once per object, this behaviour of the gc can lead to an ever-increasing memory situation if new resurrecting objects are allocated in every new gc collection.

To avoid this, recompute what objects among the unreachable set need to be resurrected and what objects can be safely collected. In this way, resurrecting objects will not block the collection of other objects in the unreachable set.
2019-10-13 16:48:59 +01:00
Tim Peters ecbf35f933
bpo-38379: don't claim objects are collected when they aren't (#16658)
* bpo-38379:  when a finalizer resurrects an object,
nothing is actually collected in this run of gc.
Change the stats to relect that truth.
2019-10-09 12:37:30 -05:00
Victor Stinner 6876257eaa
bpo-36389: _PyObject_CheckConsistency() available in release mode (GH-16612)
bpo-36389, bpo-38376: The _PyObject_CheckConsistency() function is
now also available in release mode. For example, it can be used to
debug a crash in the visit_decref() function of the GC.

Modify the following functions to also work in release mode:

* _PyDict_CheckConsistency()
* _PyObject_CheckConsistency()
* _PyType_CheckConsistency()
* _PyUnicode_CheckConsistency()

Other changes:

* _PyMem_IsPtrFreed(ptr) now also returns 1 if ptr is NULL
  (equals to 0).
* _PyBytesWriter_CheckConsistency() now returns 1 and is only used
  with assert().
* Reorder _PyObject_Dump() to write safe fields first, and only
  attempt to render repr() at the end.
2019-10-07 18:42:01 +02:00
Min ho Kim 39d87b5471 Fix typos mostly in comments, docs and test names (GH-15209) 2019-08-30 16:21:19 -04:00
Pablo Galindo d60a79a101
bpo-36155: Check for identity on test_gc.test_get_objects (GH-12116) 2019-03-01 01:12:27 -08:00
Pablo Galindo 175421b58c bpo-36016: Add generation option to gc.getobjects() (GH-11909) 2019-02-23 12:02:06 +09:00
Victor Stinner 626bff8568
bpo-9263: Dump Python object on GC assertion failure (GH-10062)
Changes:

* Add _PyObject_AssertFailed() function.
* Add _PyObject_ASSERT() and _PyObject_ASSERT_WITH_MSG() macros.
* gc_decref(): replace assert() with _PyObject_ASSERT_WITH_MSG() to
  dump the faulty object if the assertion fails.

_PyObject_AssertFailed() calls:

* _PyMem_DumpTraceback(): try to log the traceback where the object
  memory has been allocated if tracemalloc is enabled.
* _PyObject_Dump(): log repr(obj).
* Py_FatalError(): log the current Python traceback.

_PyObject_AssertFailed() uses _PyObject_IsFreed() heuristic to check
if the object memory has been freed by a debug hook on Python memory
allocators.

Initial patch written by David Malcolm.

Co-Authored-By: David Malcolm <dmalcolm@redhat.com>
2018-10-25 17:31:10 +02:00
Zackery Spytz d8cba5d16f bpo-24596: Decref module in PyRun_SimpleFileExFlags() on SystemExit (GH-7918)
PyErr_Print() will not return when the exception is a SystemExit, so
decref the __main__ module object in that case.
2018-07-03 21:47:22 +02:00
Yury Selivanov 383b32fe10
Revert "bpo-31356: Add context manager to temporarily disable GC GH-5495
This reverts commit 72a0d218dc.

The reverted commit had a few issues so it was unanimously decided
to undo it. See the bpo issue for details.
2018-02-02 09:31:06 -05:00
Pablo Galindo 72a0d218dc bpo-31356: Add context manager to temporarily disable GC (GH-4224) 2018-01-29 12:37:09 -08:00
brainfvck c75edabbb6 bpo-31558: Add gc.freeze() (#3705)
Freeze all the objects tracked by gc - move them to a permanent generation
and ignore all the future collections. This can be used before a POSIX
fork() call to make the gc copy-on-write friendly or to speed up collection.
2017-10-16 12:49:41 -07:00
Antoine Pitrou a6a4dc816d bpo-31370: Remove support for threads-less builds (#3385)
* Remove Setup.config
* Always define WITH_THREAD for compatibility.
2017-09-07 18:56:24 +02:00
Serhiy Storchaka bae75cf3fe Issue #19527: Fixed tests with defined COUNT_ALLOCS. 2016-07-03 22:30:49 +03:00
Serhiy Storchaka a793037d80 Issue #19527: Fixed tests with defined COUNT_ALLOCS. 2016-07-03 22:27:26 +03:00
Victor Stinner 843a1fb1e7 test_gc: remove unused imports 2016-01-23 13:29:02 +01:00
Berker Peksag ce643913a9 Issue #9517: Move script_helper to the support package.
Patch by Christie Wilson.
2015-05-06 06:33:17 +03:00
Antoine Pitrou a63cc21234 Issue #23726: Don't enable GC for user subclasses of non-GC types that don't add any new fields.
Patch by Eugene Toder.
2015-04-13 20:10:06 +02:00
Serhiy Storchaka 263dcd20a3 Issue #23799: Added test.support.start_threads() for running and cleaning up
multiple threads.
2015-04-01 13:01:14 +03:00
Serhiy Storchaka 9db55004a1 Make some tests more frienly to MemoryError.
Free memory, unlock hanging threads.
2015-03-28 20:38:37 +02:00
Tim Peters 5fbc7b12f7 Issue #21435: Segfault in gc with cyclic trash
Changed the iteration logic in finalize_garbage() to tolerate objects vanishing
from the list as a side effect of executing a finalizer.
2014-05-08 17:42:19 -05:00
Serhiy Storchaka f28ba369dd Issue #20532: Tests which use _testcapi now are marked as CPython only. 2014-02-07 10:10:55 +02:00
Antoine Pitrou 796564c27b Issue #18112: PEP 442 implementation (safe object finalization). 2013-07-30 19:59:21 +02:00
Antoine Pitrou 5f454a07a0 Issue #1545463: Global variables caught in reference cycles are now garbage-collected at shutdown. 2013-05-06 21:15:57 +02:00
Antoine Pitrou d4156c1693 Issue #16351: New function gc.get_stats() returns per-generation collection statistics. 2012-10-30 22:43:19 +01:00
Antoine Pitrou 2b0218a259 Issue #13992: The trashcan mechanism is now thread-safe. This eliminates
sporadic crashes in multi-thread programs when several long deallocator
chains ran concurrently and involved subclasses of built-in container
types.

Because of this change, a couple extension modules compiled for 3.2.4
(those which use the trashcan mechanism, despite it being undocumented)
will not be loadable by 3.2.3 and earlier. However, extension modules
compiled for 3.2.3 and earlier will be loadable by 3.2.4.
2012-09-06 00:59:49 +02:00
Antoine Pitrou de3c73b57c pep8-ize test names 2012-04-16 21:29:58 +02:00
Antoine Pitrou 6b64fc6bff Fix refleak in test_gc 2012-04-16 21:29:02 +02:00
Kristján Valur Jónsson 69c635266e Issue #10576: Add a progress callback to gcmodule 2012-04-15 11:41:32 +00:00