Skip to content
Merged
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
14 changes: 7 additions & 7 deletions common.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
"labsjdk-ee-21Debug": {"name": "labsjdk", "version": "ee-21.0.1+11-jvmci-23.1-b22-debug", "platformspecific": true },
"labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21.0.1+11-jvmci-23.1-b22-sulong", "platformspecific": true },

"oraclejdk-latest": {"name": "jpg-jdk", "version": "22", "build_id": "20", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]},
"labsjdk-ce-latest": {"name": "labsjdk", "version": "ce-22+20-jvmci-b02", "platformspecific": true },
"labsjdk-ce-latestDebug": {"name": "labsjdk", "version": "ce-22+20-jvmci-b02-debug", "platformspecific": true },
"labsjdk-ce-latest-llvm": {"name": "labsjdk", "version": "ce-22+20-jvmci-b02-sulong", "platformspecific": true },
"labsjdk-ee-latest": {"name": "labsjdk", "version": "ee-22+20-jvmci-b02", "platformspecific": true },
"labsjdk-ee-latestDebug": {"name": "labsjdk", "version": "ee-22+20-jvmci-b02-debug", "platformspecific": true },
"labsjdk-ee-latest-llvm": {"name": "labsjdk", "version": "ee-22+20-jvmci-b02-sulong", "platformspecific": true }
"oraclejdk-latest": {"name": "jpg-jdk", "version": "22", "build_id": "22", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]},
"labsjdk-ce-latest": {"name": "labsjdk", "version": "ce-22+22-jvmci-b01", "platformspecific": true },
"labsjdk-ce-latestDebug": {"name": "labsjdk", "version": "ce-22+22-jvmci-b01-debug", "platformspecific": true },
"labsjdk-ce-latest-llvm": {"name": "labsjdk", "version": "ce-22+22-jvmci-b01-sulong", "platformspecific": true },
"labsjdk-ee-latest": {"name": "labsjdk", "version": "ee-22+22-jvmci-b01", "platformspecific": true },
"labsjdk-ee-latestDebug": {"name": "labsjdk", "version": "ee-22+22-jvmci-b01-debug", "platformspecific": true },
"labsjdk-ee-latest-llvm": {"name": "labsjdk", "version": "ee-22+22-jvmci-b01-sulong", "platformspecific": true }
},

"eclipse": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public final class JVMCIVersionCheck {
private static final Map<String, Map<String, Version>> JVMCI_MIN_VERSIONS = Map.of(
"21", Map.of(DEFAULT_VENDOR_ENTRY, new Version(23, 1, 22)),
"22", Map.of(
"Oracle Corporation", new Version("22+20", 2),
DEFAULT_VENDOR_ENTRY, new Version("22+20", 2)));
"Oracle Corporation", new Version("22+22", 1),
DEFAULT_VENDOR_ENTRY, new Version("22+22", 1)));
private static final int NA = 0;
/**
* Minimum Java release supported by Graal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import com.oracle.svm.core.util.VMError;
import com.oracle.svm.util.ReflectionUtil;

import jdk.graal.compiler.serviceprovider.JavaVersionUtil;

/**
* Pure delegate implementation to ForkJoinPool.commonPool().
*/
Expand Down Expand Up @@ -79,9 +84,29 @@ public ForkJoinTask<?> submit(Runnable task) {
return ForkJoinPool.commonPool().submit(task);
}

@SuppressWarnings("unchecked")
public <T> List<Future<T>> invokeAllUninterruptibly(Collection<? extends Callable<T>> tasks) {
VMError.guarantee(JavaVersionUtil.JAVA_SPEC >= 22, "invokeAllUninterruptibly only exists in JDK 22+");
var m = ReflectionUtil.lookupMethod(ForkJoinPool.class, "invokeAllUninterruptibly", Collection.class);
try {
return (List<Future<T>>) m.invoke(ForkJoinPool.commonPool(), tasks);
} catch (ReflectiveOperationException e) {
throw VMError.shouldNotReachHere(e);
}
}

@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) {
return ForkJoinPool.commonPool().invokeAll(tasks);
try {
return ForkJoinPool.commonPool().invokeAll(tasks);
} catch (Throwable ex) {
throw rethrow(ex);
}
}

@SuppressWarnings({"unchecked"})
private static <E extends Throwable> RuntimeException rethrow(Throwable ex) throws E {
throw (E) ex;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.RecomputeFieldValue;
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.annotate.TargetElement;
import com.oracle.svm.core.jdk.JDK21OrEarlier;

import jdk.jfr.events.ActiveRecordingEvent;
import jdk.jfr.events.ActiveSettingEvent;
Expand All @@ -42,5 +44,8 @@ final class Target_jdk_jfr_internal_instrument_JDKEvents {
// This is a list of the classes with instrumentation code that should be applied.
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias, isFinal = true) private static Class<?>[] instrumentationClasses = new Class<?>[]{};

@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias, isFinal = true) private static Class<?>[] mirrorEventClasses = new Class<?>[]{};
@Alias //
@TargetElement(onlyWith = JDK21OrEarlier.class) //
@RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias, isFinal = true) //
private static Class<?>[] mirrorEventClasses = new Class<?>[]{};
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.util.ReflectionUtil;

import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
import jdk.internal.misc.Unsafe;
import jdk.jfr.internal.JVM;
import jdk.jfr.internal.SecuritySupport;
Expand All @@ -66,14 +67,20 @@ public class JfrEventSubstitution extends SubstitutionProcessor {
private final ConcurrentHashMap<ResolvedJavaField, ResolvedJavaField> fieldSubstitutions;
private final Map<String, Class<? extends jdk.jfr.Event>> mirrorEventMapping;

private static final Method registerMirror = JavaVersionUtil.JAVA_SPEC < 22 ? ReflectionUtil.lookupMethod(SecuritySupport.class, "registerMirror", Class.class) : null;

JfrEventSubstitution(MetaAccessProvider metaAccess) {
baseEventType = metaAccess.lookupJavaType(jdk.internal.event.Event.class);
ResolvedJavaType jdkJfrEventWriter = metaAccess.lookupJavaType(EventWriter.class);
changeWriterResetMethod(jdkJfrEventWriter);
typeSubstitution = new ConcurrentHashMap<>();
methodSubstitutions = new ConcurrentHashMap<>();
fieldSubstitutions = new ConcurrentHashMap<>();
mirrorEventMapping = createMirrorEventsMapping();
if (JavaVersionUtil.JAVA_SPEC < 22) {
mirrorEventMapping = createMirrorEventsMapping();
} else {
mirrorEventMapping = null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For JDK 22, I think you will still need to call createMirrorEventsMapping(). But createMirrorEventsMapping() will need ReflectionUtil.lookupClass(false, "jdk.jfr.internal.MirrorEvents"); instead of ReflectionUtil.lookupClass(false, "jdk.jfr.internal.instrument.JDKEvents"); depending on what JavaVersionUtil.JAVA_SPEC returns.

Additionally, I think an @Alias will be required for jdk.jfr.internal.instrument.JDKEvents#mirrorEventClasses similar to what already exists in Target_jdk_jfr_internal_instrument_JDKEvents for JDK 21.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for the suggestions @roberttoyonaga! Interestingly, the mirrored events are not covered by our testing.

Since the JDK update is rather critical, we plan to merge this PR as is and deal with the remaining JFR changes in a follow-up PR. We should also add some testing so that we cover these cases in our gate jobs.

If you could prepare a PR, we would very much appreciate it as it would speed up things. I can let you know as soon as the labjdk builds are publicly available, so you can start on top of this PR without waiting for it to merge.

Otherwise, if you don't have time, I can prepare a PR as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The labsJDK 22+22 artifacts are available: https://github.com/graalvm/labs-openjdk/releases

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you could prepare a PR, we would very much appreciate it as it would speed up things.

Hi @zapster! Yes, I'll prepare a PR for these JFR updates

Copy link
Collaborator

@roberttoyonaga roberttoyonaga Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @zapster, on second thought, we may not actually need to do much further to accommodate the changes related to MirrorEvents.java. The new behaviour is that jdk.jfr.internal.MirrorEvents maintains a cache of all the mirror event classes, instead of that cache needing to be built in JDKEvents. This means the extra step of using SecuritySupport#registerMirror is unnecessary in JDK22. So now we also don't have to do this extra step at native image build-time before manually retransforming the JFR event classes in JfrEventSubstitution anymore.

I made a PR that adds a test to verify mirror events are handled correctly and also adds a substitution to reset MirrorEvent#mirrorEventClasses. #7771

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks a lot!

}
}

@Override
Expand Down Expand Up @@ -150,10 +157,12 @@ private Boolean initEventClass(ResolvedJavaType eventType) throws RuntimeExcepti
Class<? extends jdk.internal.event.Event> newEventClass = OriginalClassProvider.getJavaClass(eventType).asSubclass(jdk.internal.event.Event.class);
eventType.initialize();

// It is crucial that mirror events are registered before the actual events.
Class<? extends jdk.jfr.Event> mirrorEventClass = mirrorEventMapping.get(newEventClass.getName());
if (mirrorEventClass != null) {
SecuritySupport.registerMirror(mirrorEventClass);
if (JavaVersionUtil.JAVA_SPEC < 22) {
// It is crucial that mirror events are registered before the actual events.
Class<? extends jdk.jfr.Event> mirrorEventClass = mirrorEventMapping.get(newEventClass.getName());
if (mirrorEventClass != null) {
registerMirror.invoke(null, mirrorEventClass);
}
}

SecuritySupport.registerEvent(newEventClass);
Expand Down