Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JDK-8350376] Adapt JDK-8319447: Improve performance of delayed task handling #10744

Open
wants to merge 2 commits into
base: galahad
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "2025-02-20-1115163.josef.eisl.jdk", "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 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
}

Expand All @@ -78,5 +123,6 @@ class CompletableFutureFeature implements InternalFeature {
@Override
public void duringSetup(DuringSetupAccess access) {
RuntimeClassInitialization.initializeAtRunTime(CompletableFutureFieldHolder.class);
RuntimeClassInitialization.initializeAtRunTime(DelaySchedulerNanoTimeOffsetHolder.class);
}
}
Loading