LibGC: Default-construct RootHashTable from the global heap

This commit is contained in:
Shannon Booth 2026-05-19 21:06:11 +02:00 committed by Shannon Booth
parent de6aec04e8
commit 78a4438cd8
14 changed files with 40 additions and 34 deletions

View file

@ -10,6 +10,11 @@
namespace GC {
RootHashTableBase::RootHashTableBase()
: RootHashTableBase(Heap::the())
{
}
RootHashTableBase::RootHashTableBase(Heap& heap)
: m_heap(&heap)
{

View file

@ -20,6 +20,7 @@ public:
virtual void gather_roots(HashMap<Cell*, GC::HeapRoot>&) const = 0;
protected:
RootHashTableBase();
explicit RootHashTableBase(Heap&);
~RootHashTableBase();
@ -38,8 +39,8 @@ class RootHashTable final
using HashTableBase = HashTable<T, TraitsForT, IsOrdered>;
public:
explicit RootHashTable(Heap& heap)
: RootHashTableBase(heap)
RootHashTable()
: RootHashTableBase()
{
}

View file

@ -1572,7 +1572,7 @@ static ThrowCompletionOr<Optional<FastPropertyNameIteratorData>> try_get_fast_pr
result.receiver_has_magical_length_property = object.has_magical_length_property();
result.shape = &object.shape();
GC::RootHashTable<GC::Ref<Object>> seen_objects(vm.heap());
GC::RootHashTable<GC::Ref<Object>> 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<GC::Ref<PropertyNameIterator>> get_object_property_iter
}
size_t estimated_properties_count = 0;
GC::RootHashTable<GC::Ref<Object>> seen_objects(vm.heap());
GC::RootHashTable<GC::Ref<Object>> 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();

View file

@ -188,7 +188,7 @@ GC::Ref<Object> Module::get_module_namespace(VM& vm)
Vector<Utf16FlyString> Module::get_exported_names(VM& vm)
{
GC::RootHashTable<GC::Ref<Module const>> export_star_set(vm.heap());
GC::RootHashTable<GC::Ref<Module const>> export_star_set;
return get_exported_names(vm, export_star_set);
}

View file

@ -1051,7 +1051,7 @@ namespace JS {
ErrorOr<void> print(JS::Value value, PrintContext& print_context)
{
GC::RootHashTable<GC::Ref<JS::Object>> seen_objects { print_context.vm.heap() };
GC::RootHashTable<GC::Ref<JS::Object>> seen_objects;
return print_value(print_context, value, seen_objects);
}

View file

@ -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<Shape*> shapes_to_invalidate(heap());
GC::RootHashTable<Shape*> shapes_to_invalidate;
GC::RootVector<Shape*> worklist;
auto enqueue_children_of = [&](Shape& shape) {
if (!shape.m_child_prototype_shapes)

View file

@ -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<GC::Ref<DOM::Element>> elements_already_invalidated_for_has { style_scope.node().heap() };
GC::RootHashTable<GC::Ref<DOM::Element>> elements_already_invalidated_for_has;
GC::OrderedRootHashMap<GC::Ref<DOM::Node>, 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<GC::Ref<DOM::Element>> elements_skipped_by_has_feature_filter { style_scope.node().heap() };
GC::RootHashTable<GC::Ref<DOM::Element>> elements_skipped_by_has_feature_filter;
GC::RootVector<GC::Ref<DOM::Element>, 16> has_scope_ancestors;
bool should_delay_ancestor_sibling_scans = false;
for (GC::Ptr<DOM::Node> ancestor = node; ancestor; ancestor = ancestor->parent_or_shadow_host()) {

View file

@ -40,7 +40,7 @@ void SVGGradientElement::attribute_changed(FlyString const& name, Optional<Strin
GradientUnits SVGGradientElement::gradient_units() const
{
GC::RootHashTable<SVGGradientElement const*> seen_gradients(heap());
GC::RootHashTable<SVGGradientElement const*> seen_gradients;
return gradient_units_impl(seen_gradients);
}
@ -55,7 +55,7 @@ GradientUnits SVGGradientElement::gradient_units_impl(GC::RootHashTable<SVGGradi
SpreadMethod SVGGradientElement::spread_method() const
{
GC::RootHashTable<SVGGradientElement const*> seen_gradients(heap());
GC::RootHashTable<SVGGradientElement const*> seen_gradients;
return spread_method_impl(seen_gradients);
}
@ -83,7 +83,7 @@ Gfx::InterpolationColorSpace SVGGradientElement::color_space() const
Optional<Gfx::AffineTransform> SVGGradientElement::gradient_transform() const
{
GC::RootHashTable<SVGGradientElement const*> seen_gradients(heap());
GC::RootHashTable<SVGGradientElement const*> seen_gradients;
return gradient_transform_impl(seen_gradients);
}

View file

@ -69,7 +69,7 @@ protected:
template<VoidFunction<SVGStopElement> Callback>
void for_each_color_stop(Callback const& callback) const
{
GC::RootHashTable<SVGGradientElement const*> seen_gradients(heap());
GC::RootHashTable<SVGGradientElement const*> seen_gradients;
return for_each_color_stop_impl(callback, seen_gradients);
}

View file

@ -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<SVGGradientElement const*> seen_gradients(heap());
GC::RootHashTable<SVGGradientElement const*> seen_gradients;
return start_x_impl(seen_gradients);
}
@ -64,7 +64,7 @@ NumberPercentage SVGLinearGradientElement::start_x_impl(GC::RootHashTable<SVGGra
// https://www.w3.org/TR/SVG11/pservers.html#LinearGradientElementY1Attribute
NumberPercentage SVGLinearGradientElement::start_y() const
{
GC::RootHashTable<SVGGradientElement const*> seen_gradients(heap());
GC::RootHashTable<SVGGradientElement const*> seen_gradients;
return start_y_impl(seen_gradients);
}
@ -81,7 +81,7 @@ NumberPercentage SVGLinearGradientElement::start_y_impl(GC::RootHashTable<SVGGra
// https://www.w3.org/TR/SVG11/pservers.html#LinearGradientElementX2Attribute
NumberPercentage SVGLinearGradientElement::end_x() const
{
GC::RootHashTable<SVGGradientElement const*> seen_gradients(heap());
GC::RootHashTable<SVGGradientElement const*> seen_gradients;
return end_x_impl(seen_gradients);
}
@ -98,7 +98,7 @@ NumberPercentage SVGLinearGradientElement::end_x_impl(GC::RootHashTable<SVGGradi
// https://www.w3.org/TR/SVG11/pservers.html#LinearGradientElementY2Attribute
NumberPercentage SVGLinearGradientElement::end_y() const
{
GC::RootHashTable<SVGGradientElement const*> seen_gradients(heap());
GC::RootHashTable<SVGGradientElement const*> seen_gradients;
return end_y_impl(seen_gradients);
}

View file

@ -105,7 +105,7 @@ GC::Ptr<SVGPatternElement const> SVGPatternElement::linked_pattern(GC::RootHashT
GC::Ptr<SVGPatternElement const> SVGPatternElement::pattern_content_element() const
{
GC::RootHashTable<SVGPatternElement const*> seen_patterns(heap());
GC::RootHashTable<SVGPatternElement const*> seen_patterns;
return pattern_content_element_impl(seen_patterns);
}
@ -121,7 +121,7 @@ GC::Ptr<SVGPatternElement const> SVGPatternElement::pattern_content_element_impl
// https://svgwg.org/svg2-draft/pservers.html#PatternElementPatternUnitsAttribute
SVGUnits SVGPatternElement::pattern_units() const
{
GC::RootHashTable<SVGPatternElement const*> seen_patterns(heap());
GC::RootHashTable<SVGPatternElement const*> seen_patterns;
return pattern_units_impl(seen_patterns);
}
@ -138,7 +138,7 @@ SVGUnits SVGPatternElement::pattern_units_impl(GC::RootHashTable<SVGPatternEleme
// https://svgwg.org/svg2-draft/pservers.html#PatternElementPatternContentUnitsAttribute
SVGUnits SVGPatternElement::pattern_content_units() const
{
GC::RootHashTable<SVGPatternElement const*> seen_patterns(heap());
GC::RootHashTable<SVGPatternElement const*> seen_patterns;
return pattern_content_units_impl(seen_patterns);
}
@ -155,7 +155,7 @@ SVGUnits SVGPatternElement::pattern_content_units_impl(GC::RootHashTable<SVGPatt
// https://svgwg.org/svg2-draft/pservers.html#PatternElementPatternTransformAttribute
Optional<Gfx::AffineTransform> SVGPatternElement::pattern_transform() const
{
GC::RootHashTable<SVGPatternElement const*> seen_patterns(heap());
GC::RootHashTable<SVGPatternElement const*> seen_patterns;
return pattern_transform_impl(seen_patterns);
}
@ -171,7 +171,7 @@ Optional<Gfx::AffineTransform> SVGPatternElement::pattern_transform_impl(GC::Roo
// https://svgwg.org/svg2-draft/pservers.html#PatternElementXAttribute
NumberPercentage SVGPatternElement::pattern_x() const
{
GC::RootHashTable<SVGPatternElement const*> seen_patterns(heap());
GC::RootHashTable<SVGPatternElement const*> seen_patterns;
return pattern_x_impl(seen_patterns);
}
@ -187,7 +187,7 @@ NumberPercentage SVGPatternElement::pattern_x_impl(GC::RootHashTable<SVGPatternE
// https://svgwg.org/svg2-draft/pservers.html#PatternElementYAttribute
NumberPercentage SVGPatternElement::pattern_y() const
{
GC::RootHashTable<SVGPatternElement const*> seen_patterns(heap());
GC::RootHashTable<SVGPatternElement const*> seen_patterns;
return pattern_y_impl(seen_patterns);
}
@ -203,7 +203,7 @@ NumberPercentage SVGPatternElement::pattern_y_impl(GC::RootHashTable<SVGPatternE
// https://svgwg.org/svg2-draft/pservers.html#PatternElementWidthAttribute
NumberPercentage SVGPatternElement::pattern_width() const
{
GC::RootHashTable<SVGPatternElement const*> seen_patterns(heap());
GC::RootHashTable<SVGPatternElement const*> seen_patterns;
return pattern_width_impl(seen_patterns);
}
@ -219,7 +219,7 @@ NumberPercentage SVGPatternElement::pattern_width_impl(GC::RootHashTable<SVGPatt
// https://svgwg.org/svg2-draft/pservers.html#PatternElementHeightAttribute
NumberPercentage SVGPatternElement::pattern_height() const
{
GC::RootHashTable<SVGPatternElement const*> seen_patterns(heap());
GC::RootHashTable<SVGPatternElement const*> seen_patterns;
return pattern_height_impl(seen_patterns);
}

View file

@ -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<SVGGradientElement const*> seen_gradients(heap());
GC::RootHashTable<SVGGradientElement const*> 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<SVGGradientElement const*> seen_gradients(heap());
GC::RootHashTable<SVGGradientElement const*> 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<SVGGradientElement const*> seen_gradients(heap());
GC::RootHashTable<SVGGradientElement const*> 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<SVGGradientElement const*> seen_gradients(heap());
GC::RootHashTable<SVGGradientElement const*> seen_gradients;
return end_circle_x_impl(seen_gradients);
}
@ -125,7 +125,7 @@ NumberPercentage SVGRadialGradientElement::end_circle_x_impl(GC::RootHashTable<S
// https://svgwg.org/svg2-draft/pservers.html#RadialGradientElementCYAttribute
NumberPercentage SVGRadialGradientElement::end_circle_y() const
{
GC::RootHashTable<SVGGradientElement const*> seen_gradients(heap());
GC::RootHashTable<SVGGradientElement const*> seen_gradients;
return end_circle_y_impl(seen_gradients);
}
@ -141,7 +141,7 @@ NumberPercentage SVGRadialGradientElement::end_circle_y_impl(GC::RootHashTable<S
// https://svgwg.org/svg2-draft/pservers.html#RadialGradientElementRAttribute
NumberPercentage SVGRadialGradientElement::end_circle_radius() const
{
GC::RootHashTable<SVGGradientElement const*> seen_gradients(heap());
GC::RootHashTable<SVGGradientElement const*> seen_gradients;
return end_circle_radius_impl(seen_gradients);
}

View file

@ -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<int> bad_table(heap);
GC::RootHashTable<int> bad_table;
}

View file

@ -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<GC::Ref<TestCell>> table(heap);
GC::RootHashTable<GC::Ref<TestCell>> table;
auto cell = heap.allocate<TestCell>();
table.set(cell);
@ -245,7 +245,7 @@ TEST_CASE(empty_containers_report_no_roots)
{
auto& heap = test_heap();
GC::RootVector<GC::Ref<TestCell>> vector;
GC::RootHashTable<GC::Ref<TestCell>> table(heap);
GC::RootHashTable<GC::Ref<TestCell>> table;
GC::RootHashMap<int, GC::Ref<TestCell>> map(heap);
HashMap<GC::Cell*, GC::HeapRoot> roots;