Commit graph

380 commits

Author SHA1 Message Date
Justin Ethier
62250cf5d7 Run formatting job 2025-01-20 18:54:18 -08:00
yorickhardy
71e5aa2dd6
Improve garbage collection for terminated threads (#550)
* gc: add a function to force the collector to run

This requires adding a "forced" stage for the collector,
which is the initial stage for a forced collection.
Thereafter, the collector continues to the usual stages
of collection.

* runtime: force the garbage collector to run when a thread exits

This is a first attempt to improve the memory usage reported in
issue #534.

* srfi-18: call Cyc_end_thread on thread exits

This ensures that the collector has a chance to run whenever
a thread exits. Attempts to partially address issue #534.

* gc: free unused parts of the heap before merging

When a thread exits, the heap is merged into the main thread.
Before doing so, free any unused parts of the heap to reduce
memory usage. Attempts to partially address issue #534.

* srfi-18: thread-terminate! takes a thread as argument

* gc: revert adding STAGE_FORCING

Use gc_start_major_collection() instead. Partial work towards
addressing issue #534.

* gc: free empty pages in gc_heap_merge()

Moving the code from gc_merge_all_heaps to gc_heap_merge removes
special handling of the start of the list and is (hopefully)
easier to read.

Partial work towards addressing issue #534.

* gc: oops, forgot the "freed" count

Partial work towards addressing issue #534.

* gc: oops, forgot the "freed" count (again)

Partial work towards addressing issue #534.

* types: update forward declaration of gc_heap_merge()

Partial work towards addressing issue #534.

* gc: remove accidental double counting

* runtime: small (cosmetic) simplification

* srfi-18: add a slot for thread context in the thread object

Partial work towards addressing issue #534.

* srfi-18: do a minor gc when terminating a thread

This ensures that any objects which are part of the
thread context are transferred to the heap.

Partial work towards addressing issue #534.

* types.h: make gc_alloc_pair public

This will be used to create the thread context.
Partial work towards addressing issue #534.

* gc: prepare heap objects for sweeping

Also introduce a global variable to track whether merged
heaps need to be swept.

Partial work towards addressing issue #534.

* gc: create a context for terminated thread objects

The context ensures that parametrised objects, continuations
and exception handlers can still be traced but are no longer
root objects (after thread terminations) and can be GCd eventually.

Partial work towards addressing issue #534.

* gc: sweep and free empty heaps for the primordial thread

The primordial thread may not have an opportunity to sweep
heap pages which have been merged from terminated threads.
So sweep any unswept pages during the cooperation phase.

Partial work towards addressing issue #534.

* srfi-18: revert thread-terminate! changes

These changes need to be revisited, and are not suitable for
the threads garbage collection pull request.
2025-01-20 21:10:49 -05:00
Justin Ethier
3b921e7389 Re-format code 2024-01-17 19:43:47 -08:00
Justin Ethier
bb861334f6 Simplify heap type definitions
This is the first step in making it easier to change the number and/or size of heap pages.
2021-08-17 15:03:53 -04:00
Justin Ethier
71dc9341a7 Remove dead code 2021-08-17 11:12:36 -04:00
Justin Ethier
fbc92258df Bring back gc_word_align for 8-byte alignment 2021-08-17 09:39:16 -04:00
Justin Ethier
62b05528a2 Issue #471 - Ensure atomics are properly traced 2021-07-28 22:39:18 -04:00
Justin Ethier
543ce4f4be Initiate major GC after a huge heap allocation
This allows us to reclaim the memory faster and keep memory usage lower.
2021-07-28 21:57:48 -04:00
Justin Ethier
da718dcac3 Fix off-by-one error with non-closure GC arg 2021-07-23 15:46:42 -04:00
Justin Ethier
e9ebfb8dcb Use new calling convention 2021-02-21 21:40:39 -05:00
Justin Ethier
c3075a6396 Added record_tag 2020-12-20 22:39:28 -05:00
Justin Ethier
9eb67e28e8 Issue #82 - Clean up 2020-06-17 22:54:08 -04:00
Justin Ethier
cf6ccc25d9 Issue #377 2020-05-18 18:18:33 -04:00
Justin Ethier
479e880b30 Allow optional collection of opaque pointers 2020-03-05 13:26:17 -05:00
Justin Ethier
648b14571c Log block size 2020-02-06 13:15:51 -05:00
Justin Ethier
2878138fd7 Add more logging 2020-02-05 18:08:44 -05:00
Justin Ethier
d051b81d80 Added more GC trace logging 2020-02-05 17:55:24 -05:00
Justin Ethier
81a3cf9c2f Additional HRT logging 2020-02-05 12:59:33 -05:00
Justin Ethier
3eaa2331d2 Avoid compiler warning 2019-11-14 15:10:56 -05:00
Justin Ethier
caf1dc23ef Keep track of heap page when growing the heap 2019-11-06 17:18:47 -05:00
Justin Ethier
26b426c307 Mark internal functions as static 2019-11-06 12:16:21 -05:00
Justin Ethier
e0388e892a Cleanup: Removed dead code, added comments 2019-11-04 14:10:46 -05:00
Justin Ethier
1551c9a8b7 Fix spelling 2019-10-09 17:47:55 -04:00
Justin Ethier
f7e6c11108 Port gc_is_stack_obj to a macro
This avoids function calls and can improve performance in extreme cases.
2019-09-26 17:24:27 -04:00
Justin Ethier
cdbf81c56a Forgot to lock for new_mutators 2019-06-11 15:54:12 -04:00
Justin Ethier
d1dbd7fae9 Issue #320 - Track threads that have not yet run
This allows (thread-join!) to be able to wait on these new threads
2019-06-10 13:16:39 -04:00
Justin Ethier
2202b3844f Mark child of atomic_type during tracing 2019-05-30 18:10:40 -04:00
Justin Ethier
d3e679fd03 Added atomic_type 2019-05-29 18:53:53 -04:00
Justin Ethier
4bc8bf1899 Copy immutable fields 2019-04-30 18:43:04 -04:00
Justin Ethier
3706647583 Refactoring 2019-03-21 17:16:21 -04:00
Justin Ethier
102244be21 Issue #304 - gc_copy_obj must to populate bignums
Even without bignums in the nursery we still need this code in place since gc_alloc calls it, and otherwise all of the callers would need to ensure bignums are properly initialized. There may be an opportunity here for optimization, but let's make sure everything works first!
2019-02-18 12:09:31 -05:00
Justin Ethier
e4085b2f1e Cleanup garbage chars 2018-11-29 17:59:01 -05:00
Justin Ethier
2ff11b1ace Experimental: remove unnecessary bignum code 2018-11-09 10:57:11 -05:00
Justin Ethier
b69f4f7233 Prevent segfault on ARM 2018-10-02 18:59:33 -04:00
Justin Ethier
388759853d Add docs 2018-08-24 12:52:23 -04:00
Justin Ethier
92a0160383 Simplify logic to match gc_sweep 2018-08-06 22:35:07 -04:00
Justin Ethier
2045df4932 Cleanup 2018-08-06 21:28:34 -04:00
Justin Ethier
79e21b64e0 Revise header comments 2018-08-08 17:25:06 -04:00
Justin Ethier
f0f071d3e2 Staging debug line 2018-08-08 12:19:16 -04:00
Justin Ethier
40c73203ce Issue #270 - Working through a solution 2018-08-06 20:15:06 -04:00
Justin Ethier
386e208eb8 Revert previous changed
noticed an intermittent crash running read1
2018-08-06 14:48:37 -04:00
Justin Ethier
219cdf2d66 Unify remaining/p math in gc_sweep_fixed_size 2018-08-06 13:58:16 -04:00
Justin Ethier
e383b45381 Do a better job of flagging free fixed-size pages 2018-08-03 13:24:57 -04:00
Justin Ethier
f8b409a8b9 Convert empty fixed-size page to bump&pop 2018-08-03 10:17:56 -04:00
Justin Ethier
e78a3e29bf Remove printf 2018-08-02 17:33:17 -04:00
Justin Ethier
c82223d0f4 Account for unswept heaps from last cycle 2018-08-02 17:45:01 -04:00
Justin Ethier
68a26e507b WIP, trying to cache unswept counts accurately 2018-08-02 13:46:25 -04:00
Justin Ethier
bb52f8db40 Issue #267 - Update free_size when sweeping bump&pop 2018-08-01 18:23:53 -04:00
Justin Ethier
6274eb2652 WIP 2018-08-01 16:58:14 -04:00
Justin Ethier
3ff33cbcb8 WIP - debugging cache of unswept count 2018-08-01 13:38:55 -04:00