{"id":22318622,"url":"https://github.com/no-defun-allowed/baker-gc","last_synced_at":"2025-03-26T04:15:52.784Z","repository":{"id":90114694,"uuid":"292484172","full_name":"no-defun-allowed/baker-gc","owner":"no-defun-allowed","description":"A loose interpretation of an incremental copying collector","archived":false,"fork":false,"pushed_at":"2020-11-29T04:48:17.000Z","size":106,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-31T05:47:21.797Z","etag":null,"topics":["do-not-use","garbage-collector","gc","henry-baker-more-like-henry-based"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/no-defun-allowed.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-03T06:19:13.000Z","updated_at":"2021-06-07T02:38:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"7fdb02f3-93e6-422f-b684-7d81c9a179e9","html_url":"https://github.com/no-defun-allowed/baker-gc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/no-defun-allowed%2Fbaker-gc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/no-defun-allowed%2Fbaker-gc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/no-defun-allowed%2Fbaker-gc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/no-defun-allowed%2Fbaker-gc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/no-defun-allowed","download_url":"https://codeload.github.com/no-defun-allowed/baker-gc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245585811,"owners_count":20639671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["do-not-use","garbage-collector","gc","henry-baker-more-like-henry-based"],"created_at":"2024-12-03T23:42:04.370Z","updated_at":"2025-03-26T04:15:52.779Z","avatar_url":"https://github.com/no-defun-allowed.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"#+BEGIN_QUOTE\n2018-10-08 08:31 \u003cno-defun-allowed\u003e i'm going to create the world's first conservative copying collector\n#+END_QUOTE\n\n2018 =no-defun-allowed= did in fact not create a conservative copying collector,\nnor would she have been /even close/ to being first to do it. But 2020\n=no-defun-allowed= has a conservative copying collector at least.\n\n+This is a rough implementation of \n[[https://www.cs.purdue.edu/homes/hosking/690M/p280-baker.pdf][ /List Processing in Real Time on a Serial Computer/ ]], which can collect\nallocated conses incrementally, and somewhat conservatively (on the stack and\nregisters). However, the client must use a read barrier (as implemented by the\n=car= and =cdr= functions provided.)+\n\nActually, no, it's a replication copying collector. It copies everything \nreachable from the roots to newspace, then updates all the references in\nreferenced conses. This only requires a write barrier to replicate modifications\nif there is a newspace copy of a cons.\n\nThis utterly abuses =setjmp= and how stacks appear to work on my machine, so\nby using this code, you agree to not sue me for limbs lost to it. One can trace\nroots (no pun intended) to [[https://medium.com/@MartinCracauer/llvms-garbage-collection-facilities-and-sbcl-s-generational-gc-a13eedfb1b31][SBCL's semi-conservative copying collector]] and the\n[[https://wiki.openjdk.java.net/display/shenandoah/Main][Shenandoah JVM garbage collector]], which are not likely to blow your limbs off.\nThe stack walking code was also gleaned off \n[[http://clim.rocks/gilbert/mark-sweep.c][Gilbert Baumann's mark-sweep implementation]].\n\n** How it works\n\n#+CAPTION: Pages and some variables that point inside them\n[[./images/pages.png]]\n\n*** Allocation\n\nConses are organised into pages (=struct page= of =pages.h=), with each page \n16KiB wide. Each cons is a triple \u003cforwarding pointer, car, cdr\u003e. We allocate\nfrom the start of a page to its end, as typical for compacting collectors. \n\n*** Scanning\n\nAt the start of a collection cycle, the stack and registers are scanned for \nroots.The registers are scanned by using =setjmp= to \"spill\" the registers into \nthe stack, and the stack can be carefully probed for values that look like \npointers into the heap.\n\nChecking what looks like a pointer can be done better with some heuristics \ninstead of iterating over pages most of the time; provided pages are allocated\nmostly contiguously, we can eliminate most pointers outside the heap by checking\nfor presence in an interval holding all pages. Pages are also cached, so that\nmost searching can be eliminated.\n\nAt the end of a collection cycle, the stack and registers are scanned for \nconses that must be pinned (as we cannot update the conservative roots), and\nhave their slots fixed up, by copying them from the copy. \n\n*** Barriers\n\nEach object has a /forwarding pointer/, either to itself, or its copy in \nnewspace. With /replication copying/, this pointer is only used when writing, to\nreplicate modifications in oldspace to newspace. Checking pointer (physical) \nequality also requires retrieving the forwarding pointer to get canonical\npointers to compare.\n\n*** Scheduling\n\nGarbage collections start after some number of pages, the /threshold/, have \nbeen allocated after the last collection finished. In order of priority, the\nthreshold is chosen so that:\n\n- it is never below 10 pages (about 80kB),\n- stack scanning completes in less than 3 milliseconds (adjustable with \n  =PAUSE_TARGET=), and\n- the heap remains between 0.5x and 1.3x its last size after a collection.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fno-defun-allowed%2Fbaker-gc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fno-defun-allowed%2Fbaker-gc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fno-defun-allowed%2Fbaker-gc/lists"}