From 093a909aa21185e89a6e7ccf3bcb5c173423b592 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Wed, 18 Mar 2026 16:21:57 +0100 Subject: [PATCH 1/4] [GR-74145] Address PR 4321 review comments --- .../src/graalpy_stacktrace.c | 10 ++++++++-- .../com.oracle.graal.python.cext/src/obmalloc.c | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/graalpython/com.oracle.graal.python.cext/src/graalpy_stacktrace.c b/graalpython/com.oracle.graal.python.cext/src/graalpy_stacktrace.c index 817a0cc2d3..82f253f0d7 100644 --- a/graalpython/com.oracle.graal.python.cext/src/graalpy_stacktrace.c +++ b/graalpython/com.oracle.graal.python.cext/src/graalpy_stacktrace.c @@ -55,6 +55,7 @@ #define GRAALPY_NATIVE_STACK_MAX_NAME 1024 #define GRAALPY_NATIVE_STACK_LINE_BUFFER 2048 +#define GRAALPY_NATIVE_STACK_CAPTURE_MAX 128 typedef void (*GraalPyStacktraceWriter)(void *ctx, const char *line); @@ -194,12 +195,17 @@ GraalPyPrivate_CaptureStacktrace(void **frames, size_t max_depth, size_t skip) #if defined(MS_WINDOWS) return (size_t) CaptureStackBackTrace((ULONG) (skip + 1), (ULONG) max_depth, frames, NULL); #elif (defined(__linux__) && defined(__GNU_LIBRARY__)) || defined(__APPLE__) - int raw_depth = backtrace(frames, (int) max_depth); + void *captured_frames[GRAALPY_NATIVE_STACK_CAPTURE_MAX]; + size_t capture_depth = max_depth + skip + 1; + if (capture_depth > (sizeof(captured_frames) / sizeof(captured_frames[0]))) { + capture_depth = sizeof(captured_frames) / sizeof(captured_frames[0]); + } + int raw_depth = backtrace(captured_frames, (int) capture_depth); size_t depth = raw_depth > 0 ? (size_t) raw_depth : 0; size_t start = depth > (skip + 1) ? (skip + 1) : depth; size_t usable_depth = depth - start; if (usable_depth > 0) { - memmove(frames, frames + start, usable_depth * sizeof(void *)); + memmove(frames, captured_frames + start, usable_depth * sizeof(void *)); } return usable_depth; #else diff --git a/graalpython/com.oracle.graal.python.cext/src/obmalloc.c b/graalpython/com.oracle.graal.python.cext/src/obmalloc.c index e03c961bac..4aef28914f 100644 --- a/graalpython/com.oracle.graal.python.cext/src/obmalloc.c +++ b/graalpython/com.oracle.graal.python.cext/src/obmalloc.c @@ -52,7 +52,7 @@ typedef struct { typedef struct { void *ptr; - void *stack[12]; + void *stack[GRAALPY_MEM_SAMPLE_USEFUL_DEPTH]; size_t size; size_t depth; unsigned long long serial; From 4dfe10a18746bd6c9226e476fddf8cd52d505c11 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Wed, 18 Mar 2026 16:27:40 +0100 Subject: [PATCH 2/4] [GR-74145] Simplify POSIX stack depth fix --- .../src/graalpy_stacktrace.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/graalpython/com.oracle.graal.python.cext/src/graalpy_stacktrace.c b/graalpython/com.oracle.graal.python.cext/src/graalpy_stacktrace.c index 82f253f0d7..99e92d0850 100644 --- a/graalpython/com.oracle.graal.python.cext/src/graalpy_stacktrace.c +++ b/graalpython/com.oracle.graal.python.cext/src/graalpy_stacktrace.c @@ -55,8 +55,6 @@ #define GRAALPY_NATIVE_STACK_MAX_NAME 1024 #define GRAALPY_NATIVE_STACK_LINE_BUFFER 2048 -#define GRAALPY_NATIVE_STACK_CAPTURE_MAX 128 - typedef void (*GraalPyStacktraceWriter)(void *ctx, const char *line); static void @@ -195,17 +193,12 @@ GraalPyPrivate_CaptureStacktrace(void **frames, size_t max_depth, size_t skip) #if defined(MS_WINDOWS) return (size_t) CaptureStackBackTrace((ULONG) (skip + 1), (ULONG) max_depth, frames, NULL); #elif (defined(__linux__) && defined(__GNU_LIBRARY__)) || defined(__APPLE__) - void *captured_frames[GRAALPY_NATIVE_STACK_CAPTURE_MAX]; - size_t capture_depth = max_depth + skip + 1; - if (capture_depth > (sizeof(captured_frames) / sizeof(captured_frames[0]))) { - capture_depth = sizeof(captured_frames) / sizeof(captured_frames[0]); - } - int raw_depth = backtrace(captured_frames, (int) capture_depth); + int raw_depth = backtrace(frames, (int) (max_depth + skip + 1)); size_t depth = raw_depth > 0 ? (size_t) raw_depth : 0; size_t start = depth > (skip + 1) ? (skip + 1) : depth; size_t usable_depth = depth - start; if (usable_depth > 0) { - memmove(frames, captured_frames + start, usable_depth * sizeof(void *)); + memmove(frames, frames + start, usable_depth * sizeof(void *)); } return usable_depth; #else From 6ef292cb0040b3a12b8dbce909b3cee8e9f2b74e Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Wed, 18 Mar 2026 22:30:40 +0100 Subject: [PATCH 3/4] [GR-74145] Fix obmalloc sample depth define order --- graalpython/com.oracle.graal.python.cext/src/obmalloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/graalpython/com.oracle.graal.python.cext/src/obmalloc.c b/graalpython/com.oracle.graal.python.cext/src/obmalloc.c index 4aef28914f..a05020235a 100644 --- a/graalpython/com.oracle.graal.python.cext/src/obmalloc.c +++ b/graalpython/com.oracle.graal.python.cext/src/obmalloc.c @@ -50,6 +50,8 @@ typedef struct { size_t dummy; } mem_head_t; +#define GRAALPY_MEM_SAMPLE_USEFUL_DEPTH (10) + typedef struct { void *ptr; void *stack[GRAALPY_MEM_SAMPLE_USEFUL_DEPTH]; @@ -70,7 +72,6 @@ typedef struct { #define GRAALPY_MEM_SAMPLE_RING_SIZE (4096) #define GRAALPY_MEM_SAMPLE_HISTORY (8) #define GRAALPY_MEM_SAMPLE_STACK_SKIP (2) -#define GRAALPY_MEM_SAMPLE_USEFUL_DEPTH (10) #define MAX_COLLECTION_RETRIES (7) #define COLLECTION_DELAY_INCREMENT (50) From f47b9200d1cfa19b76e1cfa5ea2682e04ebd9f75 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Thu, 19 Mar 2026 10:36:53 +0100 Subject: [PATCH 4/4] Split sandboxed gate into two batches --- ci.jsonnet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci.jsonnet b/ci.jsonnet index 89d2695b4d..2c668164f3 100644 --- a/ci.jsonnet +++ b/ci.jsonnet @@ -274,7 +274,7 @@ }), // tests with sandboxed backends for various modules (posix, sha3, compression, pyexpat, ...) "python-unittest-sandboxed": gpgate_ee + platform_spec(no_jobs) + platform_spec({ - "linux:amd64:jdk-latest" : tier2, + "linux:amd64:jdk-latest" : tier2 + batches(2), "linux:aarch64:jdk-latest" : tier3, "darwin:aarch64:jdk-latest" : tier3, }),