From a522c5a9da1dbb0a5c4708191f7fe4ffaa425dd1 Mon Sep 17 00:00:00 2001 From: Mario Toffia Date: Fri, 16 Oct 2026 05:49:31 +0200 Subject: [PATCH] fix(build): keep build-time Jackson cache locks out of the native image heap (#5065) Catalogs parsed while the native image is built, such as AwsManagedPolicies, add entries to Jackson caches every mapper shares and briefly take their lock. A heap scan inside that window follows the lock's owner to the builder thread and fails the build. Recompute PrivateMaxEntriesMap.evictionLock and InternCache.lock as new, unlocked locks in the image heap. Closes #5062 --- .../common/JacksonCacheSubstitutions.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/main/java/io/github/hectorvent/floci/core/common/JacksonCacheSubstitutions.java diff --git a/src/main/java/io/github/hectorvent/floci/core/common/JacksonCacheSubstitutions.java b/src/main/java/io/github/hectorvent/floci/core/common/JacksonCacheSubstitutions.java new file mode 100644 index 0000000000..a61dfbbcd2 --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/core/common/JacksonCacheSubstitutions.java @@ -0,0 +1,40 @@ +package io.github.hectorvent.floci.core.common; + +import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.RecomputeFieldValue; +import com.oracle.svm.core.annotate.TargetClass; + +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +/** + * Native image substitutions that give the shared Jackson caches in the image heap a new, unlocked + * lock. The catalogs parsed while the image is built, such as AwsManagedPolicies, write to caches + * every mapper shares: the type cache of TypeFactory.defaultInstance(), the annotation cache of the + * default introspector, the mapper behind JsonNode.toString() and the field name InternCache. Adding + * an entry to the first three, or a field name once InternCache is full, tries to take the cache's lock + * for a moment. A heap scan inside that moment reaches the builder thread through the lock's owner and + * fails the build. Giving each parse its own TypeFactory leaves the other shared caches, so the lock is + * replaced in the two classes that own one. + */ +final class JacksonCacheSubstitutions { + + private JacksonCacheSubstitutions() { + } +} + +@TargetClass(className = "com.fasterxml.jackson.databind.util.internal.PrivateMaxEntriesMap") +final class Target_PrivateMaxEntriesMap { + + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClass = ReentrantLock.class) + Lock evictionLock; +} + +@TargetClass(className = "com.fasterxml.jackson.core.util.InternCache") +final class Target_InternCache { + + @Alias + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClass = ReentrantLock.class) + ReentrantLock lock; +}