mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:27:43 +00:00
LibJS: Put zombie cell tracking code behind a compile-time flag
Since this is a debug-only feature, let's not have it impact GC marking performance when you don't need it.
This commit is contained in:
parent
f290c59dd8
commit
6a1b82df2b
13 changed files with 76 additions and 8 deletions
|
@ -24,12 +24,18 @@ public:
|
|||
bool is_marked() const { return m_mark; }
|
||||
void set_marked(bool b) { m_mark = b; }
|
||||
|
||||
virtual void did_become_zombie() { }
|
||||
#ifdef JS_TRACK_ZOMBIE_CELLS
|
||||
virtual void did_become_zombie()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
enum class State {
|
||||
Live,
|
||||
Dead,
|
||||
#ifdef JS_TRACK_ZOMBIE_CELLS
|
||||
Zombie,
|
||||
#endif
|
||||
};
|
||||
|
||||
State state() const { return m_state; }
|
||||
|
|
|
@ -184,11 +184,13 @@ public:
|
|||
return;
|
||||
dbgln_if(HEAP_DEBUG, " ! {}", &cell);
|
||||
|
||||
#ifdef JS_TRACK_ZOMBIE_CELLS
|
||||
if (cell.state() == Cell::State::Zombie) {
|
||||
dbgln("BUG! Marking a zombie cell, {} @ {:p}", cell.class_name(), &cell);
|
||||
cell.vm().dump_backtrace();
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
#endif
|
||||
|
||||
cell.set_marked(true);
|
||||
cell.visit_edges(*this);
|
||||
|
@ -230,12 +232,16 @@ void Heap::sweep_dead_cells(bool print_report, const Core::ElapsedTimer& measure
|
|||
dbgln_if(HEAP_DEBUG, " ~ {}", cell);
|
||||
if (should_store_swept_cells)
|
||||
swept_cells.append(cell);
|
||||
#ifdef JS_TRACK_ZOMBIE_CELLS
|
||||
if (m_zombify_dead_cells) {
|
||||
cell->set_state(Cell::State::Zombie);
|
||||
cell->did_become_zombie();
|
||||
} else {
|
||||
#endif
|
||||
block.deallocate(cell);
|
||||
#ifdef JS_TRACK_ZOMBIE_CELLS
|
||||
}
|
||||
#endif
|
||||
++collected_cells;
|
||||
collected_cell_bytes += block.cell_size();
|
||||
} else {
|
||||
|
|
|
@ -62,7 +62,12 @@ public:
|
|||
bool should_collect_on_every_allocation() const { return m_should_collect_on_every_allocation; }
|
||||
void set_should_collect_on_every_allocation(bool b) { m_should_collect_on_every_allocation = b; }
|
||||
|
||||
void set_zombify_dead_cells(bool b) { m_zombify_dead_cells = b; }
|
||||
#ifdef JS_TRACK_ZOMBIE_CELLS
|
||||
void set_zombify_dead_cells(bool b)
|
||||
{
|
||||
m_zombify_dead_cells = b;
|
||||
}
|
||||
#endif
|
||||
|
||||
void did_create_handle(Badge<HandleImpl>, HandleImpl&);
|
||||
void did_destroy_handle(Badge<HandleImpl>, HandleImpl&);
|
||||
|
@ -122,7 +127,10 @@ private:
|
|||
bool m_should_gc_when_deferral_ends { false };
|
||||
|
||||
bool m_collecting_garbage { false };
|
||||
|
||||
#ifdef JS_TRACK_ZOMBIE_CELLS
|
||||
bool m_zombify_dead_cells { false };
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,13 @@ public:
|
|||
|
||||
private:
|
||||
virtual void visit_edges(Visitor& visitor) override;
|
||||
virtual void did_become_zombie() override { deregister(); }
|
||||
|
||||
#ifdef JS_TRACK_ZOMBIE_CELLS
|
||||
virtual void did_become_zombie() override
|
||||
{
|
||||
deregister();
|
||||
}
|
||||
#endif
|
||||
|
||||
FunctionObject* m_cleanup_callback { nullptr };
|
||||
|
||||
|
|
|
@ -238,9 +238,11 @@ FLATTEN void Shape::add_property_without_transition(PropertyName const& property
|
|||
add_property_without_transition(property_name.to_string_or_symbol(), attributes);
|
||||
}
|
||||
|
||||
#ifdef JS_TRACK_ZOMBIE_CELLS
|
||||
void Shape::did_become_zombie()
|
||||
{
|
||||
revoke_weak_ptrs();
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
|
@ -88,7 +88,10 @@ public:
|
|||
private:
|
||||
virtual const char* class_name() const override { return "Shape"; }
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
#ifdef JS_TRACK_ZOMBIE_CELLS
|
||||
virtual void did_become_zombie() override;
|
||||
#endif
|
||||
|
||||
Shape* get_or_prune_cached_forward_transition(TransitionKey const&);
|
||||
Shape* get_or_prune_cached_prototype_transition(Object* prototype);
|
||||
|
|
|
@ -30,7 +30,13 @@ public:
|
|||
virtual void remove_swept_cells(Badge<Heap>, Span<Cell*>) override;
|
||||
|
||||
private:
|
||||
virtual void did_become_zombie() override { deregister(); }
|
||||
#ifdef JS_TRACK_ZOMBIE_CELLS
|
||||
virtual void did_become_zombie() override
|
||||
{
|
||||
deregister();
|
||||
}
|
||||
#endif
|
||||
|
||||
void visit_edges(Visitor&) override;
|
||||
|
||||
HashMap<Cell*, Value> m_values; // This stores Cell pointers instead of Object pointers to aide with sweeping
|
||||
|
|
|
@ -31,7 +31,13 @@ public:
|
|||
|
||||
private:
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
virtual void did_become_zombie() override { deregister(); }
|
||||
|
||||
#ifdef JS_TRACK_ZOMBIE_CELLS
|
||||
virtual void did_become_zombie() override
|
||||
{
|
||||
deregister();
|
||||
}
|
||||
#endif
|
||||
|
||||
Object* m_value { nullptr };
|
||||
u32 m_last_execution_generation { 0 };
|
||||
|
|
|
@ -30,7 +30,12 @@ public:
|
|||
virtual void remove_swept_cells(Badge<Heap>, Span<Cell*>) override;
|
||||
|
||||
private:
|
||||
virtual void did_become_zombie() override { deregister(); }
|
||||
#ifdef JS_TRACK_ZOMBIE_CELLS
|
||||
virtual void did_become_zombie() override
|
||||
{
|
||||
deregister();
|
||||
}
|
||||
#endif
|
||||
|
||||
HashTable<Cell*> m_values; // This stores Cell pointers instead of Object pointers to aide with sweeping
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue