From 5c0230ea5a77f85de77ad4354788cd6c27aa1ef6 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 13 Nov 2026 09:28:38 -0300 Subject: debugger: follow natural V8 deoptimization with adaptive live views --- gui/targets/jit.js | 25 +++++++++++-------------- gui/targets/segments.c | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 gui/targets/segments.c (limited to 'gui/targets') diff --git a/gui/targets/jit.js b/gui/targets/jit.js index 57a1218..b0ea360 100644 --- a/gui/targets/jit.js +++ b/gui/targets/jit.js @@ -1,16 +1,13 @@ -// Print the optimized function's machine code, then let the native debugger -// install a breakpoint before the next invocation. No V8 inspector required. -function jitWork(n) { - let sum = 0; - for (let i = 0; i < n; i++) { - sum = (sum + (i ^ n)) | 0; - } +// Ordinary warmup: V8 chooses its tiers and schedules optimization itself. +function jitWork(object) { + let sum = object.value; + for (let i = 0; i < 1000; i++) sum = (sum + i) | 0; return sum; } -%PrepareFunctionForOptimization(jitWork); -jitWork(10); -jitWork(20); -%OptimizeFunctionOnNextCall(jitWork); -jitWork(30); -%SystemBreak(); -print(jitWork(10000)); +const same = {value: 7}; +let total = 0; +for (let i = 0; i < 200000; i++) total = (total + jitWork(same)) | 0; +print('warm', total, jitWork(same)); +// A second shape invalidates the optimized property access's map guard. +print('mismatch', jitWork({extra: 1, value: 9})); +print('fallback', jitWork(same)); diff --git a/gui/targets/segments.c b/gui/targets/segments.c new file mode 100644 index 0000000..0fdc25f --- /dev/null +++ b/gui/targets/segments.c @@ -0,0 +1,25 @@ +#define _GNU_SOURCE +#include +#include +#include +#include + +struct node { struct node *next; uint64_t value; }; +struct node head, middle, tail; +volatile uint64_t counter; +__attribute__((noinline)) void checkpoint(void) { __asm__ volatile("" ::: "memory"); } + +int main(void) { + const size_t size = (size_t)1 << 32; + int fd = memfd_create("ztrace-test-segment", 0); + assert(fd >= 0 && ftruncate(fd, size) == 0); + unsigned char *bytes = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + assert(bytes != MAP_FAILED); + close(fd); + bytes[0] = 'A'; + bytes[size - 1] = 'Z'; + head = (struct node){&middle, 1}; + middle = (struct node){&tail, 2}; + tail = (struct node){&head, 3}; + for (;;) { ++counter; checkpoint(); } +} -- cgit v1.3