From 568531f06aef6699c200a29051b7455ea9258cfc Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Fri, 28 Mar 2025 20:09:28 +0000 Subject: [PATCH] Everywhere: Mark `GC::Cell` derived classes as Weakable explicitly Previously, all `GC::Cell` derived classes were Weakable. Marking only those classes that require this functionality as Weakable allows us to reduce the memory footprint of some frequently used classes. --- Libraries/LibGC/Cell.h | 2 +- Libraries/LibJS/Runtime/Object.h | 3 ++- Libraries/LibJS/Runtime/Shape.h | 6 ++++-- Libraries/LibWeb/HTML/BrowsingContext.h | 3 ++- Libraries/LibWeb/HTML/Navigable.h | 3 ++- Libraries/LibWeb/Painting/PaintableBox.h | 1 + Services/WebContent/WebContentConsoleClient.h | 3 ++- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Libraries/LibGC/Cell.h b/Libraries/LibGC/Cell.h index 85eadf0459e..14c64cde808 100644 --- a/Libraries/LibGC/Cell.h +++ b/Libraries/LibGC/Cell.h @@ -36,7 +36,7 @@ public: \ } \ friend class GC::Heap; -class Cell : public Weakable { +class Cell { AK_MAKE_NONCOPYABLE(Cell); AK_MAKE_NONMOVABLE(Cell); diff --git a/Libraries/LibJS/Runtime/Object.h b/Libraries/LibJS/Runtime/Object.h index 5ae213adcb8..34fce27b8f0 100644 --- a/Libraries/LibJS/Runtime/Object.h +++ b/Libraries/LibJS/Runtime/Object.h @@ -51,7 +51,8 @@ struct CacheablePropertyMetadata { GC::Ptr prototype; }; -class Object : public Cell { +class Object : public Cell + , public Weakable { GC_CELL(Object, Cell); GC_DECLARE_ALLOCATOR(Object); diff --git a/Libraries/LibJS/Runtime/Shape.h b/Libraries/LibJS/Runtime/Shape.h index f87702dab50..3ee9fb133e7 100644 --- a/Libraries/LibJS/Runtime/Shape.h +++ b/Libraries/LibJS/Runtime/Shape.h @@ -34,7 +34,8 @@ struct TransitionKey { } }; -class PrototypeChainValidity final : public Cell { +class PrototypeChainValidity final : public Cell + , public Weakable { GC_CELL(PrototypeChainValidity, Cell); GC_DECLARE_ALLOCATOR(PrototypeChainValidity); @@ -47,7 +48,8 @@ private: size_t padding { 0 }; }; -class Shape final : public Cell { +class Shape final : public Cell + , public Weakable { GC_CELL(Shape, Cell); GC_DECLARE_ALLOCATOR(Shape); diff --git a/Libraries/LibWeb/HTML/BrowsingContext.h b/Libraries/LibWeb/HTML/BrowsingContext.h index 466de1f3aa3..88445deb35f 100644 --- a/Libraries/LibWeb/HTML/BrowsingContext.h +++ b/Libraries/LibWeb/HTML/BrowsingContext.h @@ -16,7 +16,8 @@ namespace Web::HTML { -class BrowsingContext final : public JS::Cell { +class BrowsingContext final : public JS::Cell + , public Weakable { GC_CELL(BrowsingContext, JS::Cell); GC_DECLARE_ALLOCATOR(BrowsingContext); diff --git a/Libraries/LibWeb/HTML/Navigable.h b/Libraries/LibWeb/HTML/Navigable.h index 9b77704bd63..8b0f3630b60 100644 --- a/Libraries/LibWeb/HTML/Navigable.h +++ b/Libraries/LibWeb/HTML/Navigable.h @@ -34,7 +34,8 @@ struct TargetSnapshotParams { }; // https://html.spec.whatwg.org/multipage/document-sequences.html#navigable -class Navigable : public JS::Cell { +class Navigable : public JS::Cell + , public Weakable { GC_CELL(Navigable, JS::Cell); GC_DECLARE_ALLOCATOR(Navigable); diff --git a/Libraries/LibWeb/Painting/PaintableBox.h b/Libraries/LibWeb/Painting/PaintableBox.h index d7e7784e3ce..bd114322301 100644 --- a/Libraries/LibWeb/Painting/PaintableBox.h +++ b/Libraries/LibWeb/Painting/PaintableBox.h @@ -27,6 +27,7 @@ namespace Web::Painting { extern bool g_paint_viewport_scrollbars; class PaintableBox : public Paintable + , public Weakable , public ClippableAndScrollable { GC_CELL(PaintableBox, Paintable); diff --git a/Services/WebContent/WebContentConsoleClient.h b/Services/WebContent/WebContentConsoleClient.h index 9c1bce75f61..dc01980600b 100644 --- a/Services/WebContent/WebContentConsoleClient.h +++ b/Services/WebContent/WebContentConsoleClient.h @@ -16,7 +16,8 @@ namespace WebContent { -class WebContentConsoleClient : public JS::ConsoleClient { +class WebContentConsoleClient : public JS::ConsoleClient + , public Weakable { GC_CELL(WebContentConsoleClient, JS::ConsoleClient); GC_DECLARE_ALLOCATOR(WebContentConsoleClient);