From ca64fbb93ed9cb7aa77b40f51c7e6f118fafc2fb Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Thu, 10 Oct 2024 10:48:51 +0300 Subject: [PATCH] Embed native-image configuration file See https://www.graalvm.org/jdk21/reference-manual/native-image/overview/BuildConfiguration/#embed-a-configuration-file This way consumers of the maven artifact won't need to manually register the said class for runtime initialization (i.e. https://github.com/quarkusio/quarkus/pull/43798 and similar PRs become redundant) --- src/main/java/org/jboss/threads/EnhancedQueueExecutor.java | 5 ++++- .../org.jboss.threads/jboss-threads/native-image.properties | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/META-INF/native-image/org.jboss.threads/jboss-threads/native-image.properties diff --git a/src/main/java/org/jboss/threads/EnhancedQueueExecutor.java b/src/main/java/org/jboss/threads/EnhancedQueueExecutor.java index fa1b29b..3ce0b00 100644 --- a/src/main/java/org/jboss/threads/EnhancedQueueExecutor.java +++ b/src/main/java/org/jboss/threads/EnhancedQueueExecutor.java @@ -322,7 +322,10 @@ public final class EnhancedQueueExecutor extends AbstractExecutorService impleme private static final long activeCountOffset; private static final long peakQueueSizeOffset; - // GraalVM should initialize this class at run time + // GraalVM should initialize this class at run time, which we instruct it to do in + // src/main/resources/META-INF/native-image/org.jboss.threads/jboss-threads/native-image.properties + // Please make sure to update that file if you remove or rename this class, or if runtime + // initialization is no longer needed private static final class RuntimeFields { private static final int unsharedTaskNodesSize; private static final int unsharedLongsSize; diff --git a/src/main/resources/META-INF/native-image/org.jboss.threads/jboss-threads/native-image.properties b/src/main/resources/META-INF/native-image/org.jboss.threads/jboss-threads/native-image.properties new file mode 100644 index 0000000..3fb49b2 --- /dev/null +++ b/src/main/resources/META-INF/native-image/org.jboss.threads/jboss-threads/native-image.properties @@ -0,0 +1 @@ +Args = --initialize-at-run-time=org.jboss.threads.EnhancedQueueExecutor$RuntimeFields