From 33dd1ef076963716aa768ca7867c62d318197d2e Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 20 Feb 2025 11:10:13 +0000 Subject: [PATCH 1/2] update galahad-jdk --- common.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.json b/common.json index 6e67ba93708a..099364bbe78f 100644 --- a/common.json +++ b/common.json @@ -8,7 +8,7 @@ "COMMENT.jdks": "When adding or removing JDKs keep in sync with JDKs in ci/common.jsonnet", "jdks": { - "galahad-jdk": {"name": "jpg-jdk", "version": "25", "build_id": "jdk-25+15-1632", "platformspecific": true, "extrabundles": ["static-libs"]}, + "galahad-jdk": {"name": "jpg-jdk", "version": "25", "build_id": "jdk-25+17-1898", "platformspecific": true, "extrabundles": ["static-libs"]}, "oraclejdk17": {"name": "jpg-jdk", "version": "17.0.7", "build_id": "jdk-17.0.7+8", "platformspecific": true, "extrabundles": ["static-libs"]}, "labsjdk-ce-17": {"name": "labsjdk", "version": "ce-17.0.7+4-jvmci-23.1-b02", "platformspecific": true }, From 74fbcaf69b17c4da76bcde126abd2596a19d0e30 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Thu, 20 Feb 2025 12:33:18 +0000 Subject: [PATCH 2/2] svm: adopt "JDK-8319447: Improve performance of delayed task handling" --- ...ava_util_concurrent_CompletableFuture.java | 52 +++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_util_concurrent_CompletableFuture.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_util_concurrent_CompletableFuture.java index 1592ea03f4f9..3bcc2c84bdf3 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_util_concurrent_CompletableFuture.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_util_concurrent_CompletableFuture.java @@ -33,20 +33,54 @@ import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.InjectAccessors; import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.annotate.TargetElement; import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; import com.oracle.svm.core.feature.InternalFeature; +import com.oracle.svm.core.util.VMError; + +import jdk.graal.compiler.serviceprovider.JavaVersionUtil; @TargetClass(java.util.concurrent.CompletableFuture.class) final class Target_java_util_concurrent_CompletableFuture { // Checkstyle: stop @Alias @InjectAccessors(CompletableFutureUseCommonPoolAccessor.class) // + @TargetElement(onlyWith = JDK21OrEarlier.class) // private static boolean USE_COMMON_POOL; @Alias @InjectAccessors(CompletableFutureAsyncPoolAccessor.class) // + @TargetElement(onlyWith = JDK21OrEarlier.class) // private static Executor ASYNC_POOL; // Checkstyle: resume } +@TargetClass(className = "java.util.concurrent.DelayScheduler", onlyWith = JDKLatest.class) +final class Target_java_util_concurrent_DelayScheduler { + @Alias @InjectAccessors(DelaySchedulerNanoTimeOffsetAccessor.class) // + private static long nanoTimeOffset; +} + +class DelaySchedulerNanoTimeOffsetAccessor { + static long get() { + return DelaySchedulerNanoTimeOffsetHolder.NANO_TIME_OFFSET; + } +} + +/** + * Holder for {@link DelaySchedulerNanoTimeOffsetHolder#NANO_TIME_OFFSET}. Initialized at runtime + * via {@link CompletableFutureFeature}. + */ +class DelaySchedulerNanoTimeOffsetHolder { + + public static final long NANO_TIME_OFFSET; + + static { + if (SubstrateUtil.HOSTED) { + throw VMError.shouldNotReachHere(DelaySchedulerNanoTimeOffsetHolder.class.getName() + " must only be initialized at runtime"); + } + NANO_TIME_OFFSET = Math.min(System.nanoTime(), 0L) + Long.MIN_VALUE; + } +} + class CompletableFutureUseCommonPoolAccessor { static boolean get() { return CompletableFutureFieldHolder.USE_COMMON_POOL; @@ -65,11 +99,22 @@ class CompletableFutureFieldHolder { static final boolean USE_COMMON_POOL = ForkJoinPool.getCommonPoolParallelism() > 1; - static final Executor ASYNC_POOL = USE_COMMON_POOL ? ForkJoinPool.commonPool() - : SubstrateUtil.cast(new Target_java_util_concurrent_CompletableFuture_ThreadPerTaskExecutor(), Executor.class); + static final Executor ASYNC_POOL; + + static { + if (JavaVersionUtil.JAVA_SPEC <= 21) { + if (USE_COMMON_POOL) { + ASYNC_POOL = ForkJoinPool.commonPool(); + } else { + ASYNC_POOL = SubstrateUtil.cast(new Target_java_util_concurrent_CompletableFuture_ThreadPerTaskExecutor(), Executor.class); + } + } else { + ASYNC_POOL = null; + } + } } -@TargetClass(value = java.util.concurrent.CompletableFuture.class, innerClass = "ThreadPerTaskExecutor") +@TargetClass(value = java.util.concurrent.CompletableFuture.class, innerClass = "ThreadPerTaskExecutor", onlyWith = JDK21OrEarlier.class) final class Target_java_util_concurrent_CompletableFuture_ThreadPerTaskExecutor { } @@ -78,5 +123,6 @@ class CompletableFutureFeature implements InternalFeature { @Override public void duringSetup(DuringSetupAccess access) { RuntimeClassInitialization.initializeAtRunTime(CompletableFutureFieldHolder.class); + RuntimeClassInitialization.initializeAtRunTime(DelaySchedulerNanoTimeOffsetHolder.class); } }