1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 18:07:34 +00:00

LibJS+js+test-js: Add GC debug mode that keeps cells "alive" as zombies

This patch adds a `-z` option to js and test-js. When run in this mode,
garbage cells are never actually destroyed. We instead keep them around
in a special zombie state.

This allows us to validate that zombies don't get marked in future GC
scans (since there were not supposed to be any more references!) :^)

Cells get notified when they become a zombie (via did_become_zombie())
and this is used by WeakContainer cells to deregister themselves from
the heap.
This commit is contained in:
Andreas Kling 2021-09-11 16:44:40 +02:00
parent 57371f7608
commit c364520c24
10 changed files with 33 additions and 1 deletions

View file

@ -111,6 +111,7 @@ static consteval size_t __testjs_last() { return (AK::Detail::IntegralConstant<s
static constexpr auto TOP_LEVEL_TEST_NAME = "__$$TOP_LEVEL$$__";
extern RefPtr<JS::VM> g_vm;
extern bool g_collect_on_every_allocation;
extern bool g_zombify_dead_cells;
extern bool g_run_bytecode;
extern bool g_dump_bytecode;
extern String g_currently_running_test;
@ -266,6 +267,7 @@ inline JSFileResult TestRunner::run_file_test(const String& test_path)
JS::VM::InterpreterExecutionScope scope(*interpreter);
interpreter->heap().set_should_collect_on_every_allocation(g_collect_on_every_allocation);
interpreter->heap().set_zombify_dead_cells(g_zombify_dead_cells);
if (g_run_file) {
auto result = g_run_file(test_path, *interpreter);

View file

@ -18,6 +18,7 @@ namespace JS {
RefPtr<::JS::VM> g_vm;
bool g_collect_on_every_allocation = false;
bool g_zombify_dead_cells = false;
bool g_run_bytecode = false;
bool g_dump_bytecode = false;
String g_currently_running_test;
@ -109,6 +110,7 @@ int main(int argc, char** argv)
});
args_parser.add_option(print_json, "Show results as JSON", "json", 'j');
args_parser.add_option(g_collect_on_every_allocation, "Collect garbage after every allocation", "collect-often", 'g');
args_parser.add_option(g_zombify_dead_cells, "Zombify dead cells (to catch missing GC marks)", "zombify-dead-cells", 'z');
args_parser.add_option(g_run_bytecode, "Use the bytecode interpreter", "run-bytecode", 'b');
args_parser.add_option(g_dump_bytecode, "Dump the bytecode", "dump-bytecode", 'd');
args_parser.add_option(test_glob, "Only run tests matching the given glob", "filter", 'f', "glob");