From 78a4438cd8a500f8205abe73e81ab42a0fed5571 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Tue, 19 May 2026 21:06:11 +0200 Subject: [PATCH] LibGC: Default-construct RootHashTable from the global heap --- Libraries/LibGC/RootHashTable.cpp | 5 +++++ Libraries/LibGC/RootHashTable.h | 5 +++-- Libraries/LibJS/Bytecode/Interpreter.cpp | 4 ++-- Libraries/LibJS/Module.cpp | 2 +- Libraries/LibJS/Print.cpp | 2 +- Libraries/LibJS/Runtime/Shape.cpp | 2 +- .../CSS/Invalidation/HasMutationInvalidator.cpp | 4 ++-- Libraries/LibWeb/SVG/SVGGradientElement.cpp | 6 +++--- Libraries/LibWeb/SVG/SVGGradientElement.h | 2 +- .../LibWeb/SVG/SVGLinearGradientElement.cpp | 8 ++++---- Libraries/LibWeb/SVG/SVGPatternElement.cpp | 16 ++++++++-------- .../LibWeb/SVG/SVGRadialGradientElement.cpp | 12 ++++++------ .../LibJSGCTests/root_container_non_gc_type.cpp | 2 +- Tests/LibGC/TestGCContainers.cpp | 4 ++-- 14 files changed, 40 insertions(+), 34 deletions(-) diff --git a/Libraries/LibGC/RootHashTable.cpp b/Libraries/LibGC/RootHashTable.cpp index d5be357562..ccfdad893f 100644 --- a/Libraries/LibGC/RootHashTable.cpp +++ b/Libraries/LibGC/RootHashTable.cpp @@ -10,6 +10,11 @@ namespace GC { +RootHashTableBase::RootHashTableBase() + : RootHashTableBase(Heap::the()) +{ +} + RootHashTableBase::RootHashTableBase(Heap& heap) : m_heap(&heap) { diff --git a/Libraries/LibGC/RootHashTable.h b/Libraries/LibGC/RootHashTable.h index 88af7864ca..23d89f9a39 100644 --- a/Libraries/LibGC/RootHashTable.h +++ b/Libraries/LibGC/RootHashTable.h @@ -20,6 +20,7 @@ public: virtual void gather_roots(HashMap&) const = 0; protected: + RootHashTableBase(); explicit RootHashTableBase(Heap&); ~RootHashTableBase(); @@ -38,8 +39,8 @@ class RootHashTable final using HashTableBase = HashTable; public: - explicit RootHashTable(Heap& heap) - : RootHashTableBase(heap) + RootHashTable() + : RootHashTableBase() { } diff --git a/Libraries/LibJS/Bytecode/Interpreter.cpp b/Libraries/LibJS/Bytecode/Interpreter.cpp index 29e6ed67c2..52f040197f 100644 --- a/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -1572,7 +1572,7 @@ static ThrowCompletionOr> try_get_fast_pr result.receiver_has_magical_length_property = object.has_magical_length_property(); result.shape = &object.shape(); - GC::RootHashTable> seen_objects(vm.heap()); + GC::RootHashTable> seen_objects; size_t estimated_properties_count = 0; bool prototype_chain_has_enumerable_named_properties = false; for (auto object_to_check = GC::Ptr { &object }; object_to_check && !seen_objects.contains(*object_to_check); object_to_check = TRY(object_to_check->internal_get_prototype_of())) { @@ -1726,7 +1726,7 @@ inline ThrowCompletionOr> get_object_property_iter } size_t estimated_properties_count = 0; - GC::RootHashTable> seen_objects(vm.heap()); + GC::RootHashTable> seen_objects; for (auto object_to_check = GC::Ptr { object.ptr() }; object_to_check && !seen_objects.contains(*object_to_check); object_to_check = TRY(object_to_check->internal_get_prototype_of())) { seen_objects.set(*object_to_check); estimated_properties_count += object_to_check->own_properties_count(); diff --git a/Libraries/LibJS/Module.cpp b/Libraries/LibJS/Module.cpp index 026a63e362..0ef18e1511 100644 --- a/Libraries/LibJS/Module.cpp +++ b/Libraries/LibJS/Module.cpp @@ -188,7 +188,7 @@ GC::Ref Module::get_module_namespace(VM& vm) Vector Module::get_exported_names(VM& vm) { - GC::RootHashTable> export_star_set(vm.heap()); + GC::RootHashTable> export_star_set; return get_exported_names(vm, export_star_set); } diff --git a/Libraries/LibJS/Print.cpp b/Libraries/LibJS/Print.cpp index 12633f0e0b..76e1a81c8d 100644 --- a/Libraries/LibJS/Print.cpp +++ b/Libraries/LibJS/Print.cpp @@ -1051,7 +1051,7 @@ namespace JS { ErrorOr print(JS::Value value, PrintContext& print_context) { - GC::RootHashTable> seen_objects { print_context.vm.heap() }; + GC::RootHashTable> seen_objects; return print_value(print_context, value, seen_objects); } diff --git a/Libraries/LibJS/Runtime/Shape.cpp b/Libraries/LibJS/Runtime/Shape.cpp index 7bf58a0cff..1a3c5ebda8 100644 --- a/Libraries/LibJS/Runtime/Shape.cpp +++ b/Libraries/LibJS/Runtime/Shape.cpp @@ -535,7 +535,7 @@ void Shape::invalidate_all_prototype_chains_leading_to_this() if (!m_child_prototype_shapes || m_child_prototype_shapes->is_empty()) return; - GC::RootHashTable shapes_to_invalidate(heap()); + GC::RootHashTable shapes_to_invalidate; GC::RootVector worklist; auto enqueue_children_of = [&](Shape& shape) { if (!shape.m_child_prototype_shapes) diff --git a/Libraries/LibWeb/CSS/Invalidation/HasMutationInvalidator.cpp b/Libraries/LibWeb/CSS/Invalidation/HasMutationInvalidator.cpp index 997b985bde..ce32bb2028 100644 --- a/Libraries/LibWeb/CSS/Invalidation/HasMutationInvalidator.cpp +++ b/Libraries/LibWeb/CSS/Invalidation/HasMutationInvalidator.cpp @@ -337,13 +337,13 @@ static void invalidate_style_of_elements_affected_by_pending_has_mutations(Style auto& counters = style_scope.document().style_invalidation_counters(); ++counters.has_ancestor_walk_invocations; - GC::RootHashTable> elements_already_invalidated_for_has { style_scope.node().heap() }; + GC::RootHashTable> elements_already_invalidated_for_has; GC::OrderedRootHashMap, PendingHasInvalidationMutationFeatures> pending_has_invalidations { style_scope.node().heap() }; for (auto& [node, features] : style_scope.m_pending_has_invalidations) pending_has_invalidations.set(node, features); bool should_scan_ancestor_siblings = style_scope.have_has_selectors_with_relative_selector_that_has_sibling_combinator(); for (auto& [node, mutation_features] : pending_has_invalidations) { - GC::RootHashTable> elements_skipped_by_has_feature_filter { style_scope.node().heap() }; + GC::RootHashTable> elements_skipped_by_has_feature_filter; GC::RootVector, 16> has_scope_ancestors; bool should_delay_ancestor_sibling_scans = false; for (GC::Ptr ancestor = node; ancestor; ancestor = ancestor->parent_or_shadow_host()) { diff --git a/Libraries/LibWeb/SVG/SVGGradientElement.cpp b/Libraries/LibWeb/SVG/SVGGradientElement.cpp index 24d16c15ee..89d40a6576 100644 --- a/Libraries/LibWeb/SVG/SVGGradientElement.cpp +++ b/Libraries/LibWeb/SVG/SVGGradientElement.cpp @@ -40,7 +40,7 @@ void SVGGradientElement::attribute_changed(FlyString const& name, Optional seen_gradients(heap()); + GC::RootHashTable seen_gradients; return gradient_units_impl(seen_gradients); } @@ -55,7 +55,7 @@ GradientUnits SVGGradientElement::gradient_units_impl(GC::RootHashTable seen_gradients(heap()); + GC::RootHashTable seen_gradients; return spread_method_impl(seen_gradients); } @@ -83,7 +83,7 @@ Gfx::InterpolationColorSpace SVGGradientElement::color_space() const Optional SVGGradientElement::gradient_transform() const { - GC::RootHashTable seen_gradients(heap()); + GC::RootHashTable seen_gradients; return gradient_transform_impl(seen_gradients); } diff --git a/Libraries/LibWeb/SVG/SVGGradientElement.h b/Libraries/LibWeb/SVG/SVGGradientElement.h index ad2efca572..883fdc49b8 100644 --- a/Libraries/LibWeb/SVG/SVGGradientElement.h +++ b/Libraries/LibWeb/SVG/SVGGradientElement.h @@ -69,7 +69,7 @@ protected: template Callback> void for_each_color_stop(Callback const& callback) const { - GC::RootHashTable seen_gradients(heap()); + GC::RootHashTable seen_gradients; return for_each_color_stop_impl(callback, seen_gradients); } diff --git a/Libraries/LibWeb/SVG/SVGLinearGradientElement.cpp b/Libraries/LibWeb/SVG/SVGLinearGradientElement.cpp index f2c6672436..f91ddfc953 100644 --- a/Libraries/LibWeb/SVG/SVGLinearGradientElement.cpp +++ b/Libraries/LibWeb/SVG/SVGLinearGradientElement.cpp @@ -47,7 +47,7 @@ void SVGLinearGradientElement::attribute_changed(FlyString const& name, Optional // https://www.w3.org/TR/SVG11/pservers.html#LinearGradientElementX1Attribute NumberPercentage SVGLinearGradientElement::start_x() const { - GC::RootHashTable seen_gradients(heap()); + GC::RootHashTable seen_gradients; return start_x_impl(seen_gradients); } @@ -64,7 +64,7 @@ NumberPercentage SVGLinearGradientElement::start_x_impl(GC::RootHashTable seen_gradients(heap()); + GC::RootHashTable seen_gradients; return start_y_impl(seen_gradients); } @@ -81,7 +81,7 @@ NumberPercentage SVGLinearGradientElement::start_y_impl(GC::RootHashTable seen_gradients(heap()); + GC::RootHashTable seen_gradients; return end_x_impl(seen_gradients); } @@ -98,7 +98,7 @@ NumberPercentage SVGLinearGradientElement::end_x_impl(GC::RootHashTable seen_gradients(heap()); + GC::RootHashTable seen_gradients; return end_y_impl(seen_gradients); } diff --git a/Libraries/LibWeb/SVG/SVGPatternElement.cpp b/Libraries/LibWeb/SVG/SVGPatternElement.cpp index 1a4f467a88..d857df9c49 100644 --- a/Libraries/LibWeb/SVG/SVGPatternElement.cpp +++ b/Libraries/LibWeb/SVG/SVGPatternElement.cpp @@ -105,7 +105,7 @@ GC::Ptr SVGPatternElement::linked_pattern(GC::RootHashT GC::Ptr SVGPatternElement::pattern_content_element() const { - GC::RootHashTable seen_patterns(heap()); + GC::RootHashTable seen_patterns; return pattern_content_element_impl(seen_patterns); } @@ -121,7 +121,7 @@ GC::Ptr SVGPatternElement::pattern_content_element_impl // https://svgwg.org/svg2-draft/pservers.html#PatternElementPatternUnitsAttribute SVGUnits SVGPatternElement::pattern_units() const { - GC::RootHashTable seen_patterns(heap()); + GC::RootHashTable seen_patterns; return pattern_units_impl(seen_patterns); } @@ -138,7 +138,7 @@ SVGUnits SVGPatternElement::pattern_units_impl(GC::RootHashTable seen_patterns(heap()); + GC::RootHashTable seen_patterns; return pattern_content_units_impl(seen_patterns); } @@ -155,7 +155,7 @@ SVGUnits SVGPatternElement::pattern_content_units_impl(GC::RootHashTable SVGPatternElement::pattern_transform() const { - GC::RootHashTable seen_patterns(heap()); + GC::RootHashTable seen_patterns; return pattern_transform_impl(seen_patterns); } @@ -171,7 +171,7 @@ Optional SVGPatternElement::pattern_transform_impl(GC::Roo // https://svgwg.org/svg2-draft/pservers.html#PatternElementXAttribute NumberPercentage SVGPatternElement::pattern_x() const { - GC::RootHashTable seen_patterns(heap()); + GC::RootHashTable seen_patterns; return pattern_x_impl(seen_patterns); } @@ -187,7 +187,7 @@ NumberPercentage SVGPatternElement::pattern_x_impl(GC::RootHashTable seen_patterns(heap()); + GC::RootHashTable seen_patterns; return pattern_y_impl(seen_patterns); } @@ -203,7 +203,7 @@ NumberPercentage SVGPatternElement::pattern_y_impl(GC::RootHashTable seen_patterns(heap()); + GC::RootHashTable seen_patterns; return pattern_width_impl(seen_patterns); } @@ -219,7 +219,7 @@ NumberPercentage SVGPatternElement::pattern_width_impl(GC::RootHashTable seen_patterns(heap()); + GC::RootHashTable seen_patterns; return pattern_height_impl(seen_patterns); } diff --git a/Libraries/LibWeb/SVG/SVGRadialGradientElement.cpp b/Libraries/LibWeb/SVG/SVGRadialGradientElement.cpp index f9063e0b73..331d7f510a 100644 --- a/Libraries/LibWeb/SVG/SVGRadialGradientElement.cpp +++ b/Libraries/LibWeb/SVG/SVGRadialGradientElement.cpp @@ -49,7 +49,7 @@ void SVGRadialGradientElement::attribute_changed(FlyString const& name, Optional // https://svgwg.org/svg2-draft/pservers.html#RadialGradientElementFXAttribute NumberPercentage SVGRadialGradientElement::start_circle_x() const { - GC::RootHashTable seen_gradients(heap()); + GC::RootHashTable seen_gradients; return start_circle_x_impl(seen_gradients); } @@ -69,7 +69,7 @@ NumberPercentage SVGRadialGradientElement::start_circle_x_impl(GC::RootHashTable // https://svgwg.org/svg2-draft/pservers.html#RadialGradientElementFYAttribute NumberPercentage SVGRadialGradientElement::start_circle_y() const { - GC::RootHashTable seen_gradients(heap()); + GC::RootHashTable seen_gradients; return start_circle_y_impl(seen_gradients); } @@ -89,7 +89,7 @@ NumberPercentage SVGRadialGradientElement::start_circle_y_impl(GC::RootHashTable // https://svgwg.org/svg2-draft/pservers.html#RadialGradientElementFRAttribute NumberPercentage SVGRadialGradientElement::start_circle_radius() const { - GC::RootHashTable seen_gradients(heap()); + GC::RootHashTable seen_gradients; return start_circle_radius_impl(seen_gradients); } @@ -109,7 +109,7 @@ NumberPercentage SVGRadialGradientElement::start_circle_radius_impl(GC::RootHash // https://svgwg.org/svg2-draft/pservers.html#RadialGradientElementCXAttribute NumberPercentage SVGRadialGradientElement::end_circle_x() const { - GC::RootHashTable seen_gradients(heap()); + GC::RootHashTable seen_gradients; return end_circle_x_impl(seen_gradients); } @@ -125,7 +125,7 @@ NumberPercentage SVGRadialGradientElement::end_circle_x_impl(GC::RootHashTable seen_gradients(heap()); + GC::RootHashTable seen_gradients; return end_circle_y_impl(seen_gradients); } @@ -141,7 +141,7 @@ NumberPercentage SVGRadialGradientElement::end_circle_y_impl(GC::RootHashTable seen_gradients(heap()); + GC::RootHashTable seen_gradients; return end_circle_radius_impl(seen_gradients); } diff --git a/Tests/ClangPlugins/LibJSGCTests/root_container_non_gc_type.cpp b/Tests/ClangPlugins/LibJSGCTests/root_container_non_gc_type.cpp index c88eaf214b..e9656faf45 100644 --- a/Tests/ClangPlugins/LibJSGCTests/root_container_non_gc_type.cpp +++ b/Tests/ClangPlugins/LibJSGCTests/root_container_non_gc_type.cpp @@ -31,5 +31,5 @@ void test_root_hash_table_non_gc_type(GC::Heap& heap) { // expected-error@*{{RootHashTable element type must be convertible to Cell const* or derive from NanBoxedValue}} // expected-note@+1 {{in instantiation of member function}} - GC::RootHashTable bad_table(heap); + GC::RootHashTable bad_table; } diff --git a/Tests/LibGC/TestGCContainers.cpp b/Tests/LibGC/TestGCContainers.cpp index 5535dcf136..d3ac905108 100644 --- a/Tests/LibGC/TestGCContainers.cpp +++ b/Tests/LibGC/TestGCContainers.cpp @@ -229,7 +229,7 @@ TEST_CASE(empty_heap_hash_table_visit_edges_reports_nothing) TEST_CASE(root_hash_table_reports_roots) { auto& heap = test_heap(); - GC::RootHashTable> table(heap); + GC::RootHashTable> table; auto cell = heap.allocate(); table.set(cell); @@ -245,7 +245,7 @@ TEST_CASE(empty_containers_report_no_roots) { auto& heap = test_heap(); GC::RootVector> vector; - GC::RootHashTable> table(heap); + GC::RootHashTable> table; GC::RootHashMap> map(heap); HashMap roots;