Commit graph

20 commits

Author SHA1 Message Date
Ali Mohammad Pur
76f17f7703 LibGC: Add support for coordinated multi-heap collection
Allow having separate GC heaps and implement coordinated marking between
them; this is useful for keeping wasm and js GC heaps separated with a
clear boundary.
2026-06-19 17:01:47 +02:00
Luke Wilde
85fd3bb7b0 LibGC: Introduce ConservativeHashTable 2026-05-28 21:16:23 +02:00
Luke Wilde
b6219c0673 LibGC: Introduce WeakHashMap
Mirrors `WeakHashSet` for map shapes. Cell-typed key and/or value
slots are stored as `Weak<T>` so entries vanish when their referent
is collected; non-cell slots are stored directly.
2026-05-27 02:56:27 +01:00
Luke Wilde
f955d4e8a4 LibGC: Introduce ConservativeHashMap 2026-05-21 18:29:41 +02:00
Shannon Booth
a24af35ca1 LibGC: Default-construct RootHashMap from the global heap 2026-05-20 20:37:55 +02:00
Shannon Booth
78a4438cd8 LibGC: Default-construct RootHashTable from the global heap 2026-05-20 20:37:55 +02:00
Shannon Booth
de6aec04e8 LibGC: Default-construct ConservativeVector from the global heap 2026-05-20 20:37:55 +02:00
Shannon Booth
387cd6e2e2 LibGC: Default-construct RootVector from the global heap
Similar to GC::Root<T>, make GC::RootVector<T> constructible without
explicitly passing a Heap.

This is implemented by having RootVectorBase use GC::Heap::the() for
heap-free construction.
2026-05-20 20:37:55 +02:00
Shannon Booth
3897f6efb9 LibGC+Tests: Allow overriding Heap::the() for tests
Add a test-only helper for setting the default GC heap, and use it
from LibGC tests that create their own test heap.
2026-05-20 20:37:55 +02:00
Luke Wilde
d911b79ec9 LibGC: Introduce RootHashTable 2026-05-19 19:24:08 +02:00
Andreas Kling
f8b031b9fc Tests/LibGC: Keep test heaps alive until process exit
The LibGC container and visitor tests share one heap per test binary.
A function-local static heap runs its destructor during C++ static
teardown. That makes sanitizer-only results depend on process shutdown
ordering.

Use NeverDestroyed for these process-lifetime test heaps. This matches
the intended lifetime and avoids destructor-time GC work during final
LSan checking.
2026-05-15 17:02:49 +02:00
Andreas Kling
2a67d3702a LibGC: Proactively collect garbage when the mutator goes idle
Collection was purely allocation-driven: a GC only ran once
allocation since the last collection passed a threshold of 7/4 of
the live set (floored at 8 MiB). A page that allocated garbage but
never reached that threshold held onto it indefinitely once it went
idle, so we never handed memory back to the system promptly.

Run a 4-second repeating timer while the mutator is allocating; on
each tick IdleCollectionPolicy picks one of three actions:

- Park the timer when nothing has been allocated since the last
  collection. The next allocation re-arms it, so a fully idle heap
  costs nothing.

- Collect when this tick's allocation rate fell below 1/4 of the
  peak rate seen this episode (the mutator left an active phase),
  provided at least threshold/16 of garbage has piled up, so we
  don't mark the whole live heap to reclaim a trivial amount.

- Otherwise let a watchdog collect after 15 ticks (60 seconds), so
  garbage cannot sit indefinitely on a heap that allocates too
  steadily to show a rate drop, or too slowly to clear the gate.

The GC heap is never completely silent in practice, since event-loop
housekeeping keeps queuing small objects like HTML tasks; that is
why the trigger watches for a relative rate drop rather than for
zero allocation.

The per-tick decision lives in IdleCollectionPolicy, separate from
the timer plumbing, with a unit test covering the rate-drop trigger,
the minimum-garbage gate, the watchdog, and parking when idle.
2026-05-15 15:55:12 +02:00
Luke Wilde
369ed74bd1 LibGC: Add a Variant overload to Cell::Visitor
This requires the Variant to contain at least one visitable type.
For example, requiring them all to be visitable wouldn't allow types
such as `Variant<Empty, GC::Ref<Document>>`.
2026-05-15 08:51:17 +02:00
Luke Wilde
33a5f4868d LibGC: Only allow visitable types for Visitor's container helpers 2026-05-15 08:51:17 +02:00
Luke Wilde
3c64e1dbbc LibGC: Add tests for GC containers 2026-05-07 13:00:52 +02:00
Andreas Kling
e87f889e31 Everywhere: Abandon Swift adoption
After making no progress on this for a very long time, let's acknowledge
it's not going anywhere and remove it from the codebase.
2026-02-17 10:48:09 -05:00
Andrew Kaster
8fd81c3338 LibGC+LibWeb+LibJS: Remove workaround for Swift boolean bitfield issue
We're using a main snapshot everywhere, so we can yeet the workaround.
2025-04-04 13:06:53 -06:00
Andrew Kaster
8554ee386e LibGC: Teach Swift bindings about Cell and Cell::Visitor
Add the proper annotations for the Cell and Cell::Visitor classes to be
visible in Swift. This lets us remove some OpaquePointer shinangians in
the Swift bindings.
2025-04-03 16:47:48 -06:00
Timothy Flynn
27478ec7d4 Everywhere: Run clang-format
The following command was used to clang-format these files:

    clang-format-19 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.mm" -o -name "*.h")
2024-12-28 05:39:32 -08:00
Andrew Kaster
fca6fd0b85 LibGC: Add Swift bindings to the GC heap
This includes a protocol for creating LibGC Heap allocated Swift
objects. Pay no attention to the Unmanaged shenanigans, they are
all behind the curtain.
2024-11-19 14:32:11 -07:00