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 }, 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); } }