Skip to content

Commit d865daa

Browse files
christianhaeubldougxc
authored andcommitted
JFR-related fixes for JDK21 (GR-45303)
1 parent e868b09 commit d865daa

File tree

5 files changed

+33
-34
lines changed

5 files changed

+33
-34
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDKContainerSubstitutions.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import java.util.List;
2929
import java.util.concurrent.CopyOnWriteArrayList;
30+
import java.util.concurrent.locks.Lock;
3031
import java.util.concurrent.locks.ReentrantLock;
3132

3233
import org.graalvm.nativeimage.Platform.LINUX;
@@ -66,7 +67,7 @@ final class Target_jdk_jfr_internal_instrument_JDKEvents {
6667
private static boolean initializationTriggered;
6768
}
6869

69-
@TargetClass(className = "jdk.jfr.internal.RequestEngine", onlyWith = JDK17OrLater.class)
70+
@TargetClass(className = "jdk.jfr.internal.RequestEngine", onlyWith = {JDK17OrLater.class, JDK20OrEarlier.class})
7071
@Platforms(LINUX.class)
7172
final class Target_jdk_jfr_internal_RequestEngine {
7273
@Alias //
@@ -79,6 +80,15 @@ final class Target_jdk_jfr_internal_RequestEngine {
7980
private static List<?> entries;
8081
}
8182

83+
@TargetClass(className = "jdk.jfr.internal.periodic.JVMEventTask", onlyWith = JDK21OrLater.class)
84+
@Platforms(LINUX.class)
85+
final class Target_jdk_jfr_internal_JVMEventTask {
86+
@Alias //
87+
@RecomputeFieldValue(kind = Kind.NewInstance, declClass = ReentrantLock.class) //
88+
private static Lock lock;
89+
90+
}
91+
8292
// Only present in JDKs without JDK-8268398
8393
@TargetClass(className = "jdk.jfr.internal.Utils", onlyWith = {JDK17OrEarlier.class, JDK17OrLater.class})
8494
@Platforms(LINUX.class)

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/JfrMetadataTypeLibrary.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.oracle.svm.core.util.VMError;
3838
import com.oracle.svm.util.ReflectionUtil;
3939

40+
import jdk.jfr.internal.MetadataRepository;
4041
import jdk.jfr.internal.PlatformEventType;
4142
import jdk.jfr.internal.Type;
4243
import jdk.jfr.internal.TypeLibrary;
@@ -62,6 +63,12 @@ private static synchronized HashMap<String, Type> getTypes() {
6263
@SuppressWarnings("unchecked")
6364
private static Collection<Type> getTypes0() {
6465
try {
66+
/*
67+
* Initialize the MetadataRepository class, to ensure that large parts of the JFR
68+
* infrastructure are initialized (e.g., the TypeLibrary that we access below).
69+
*/
70+
MetadataRepository.getInstance();
71+
6572
Method getTypes = ReflectionUtil.lookupMethod(TypeLibrary.class, "getTypes");
6673
if (JavaVersionUtil.JAVA_SPEC >= 21) {
6774
return (Collection<Type>) getTypes.invoke(null);

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/logging/JfrLogConfiguration.java

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.Map;
3131
import java.util.Set;
3232

33-
import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
3433
import org.graalvm.nativeimage.Platform;
3534
import org.graalvm.nativeimage.Platforms;
3635

@@ -44,15 +43,15 @@
4443
* Parses the flight recorder logging configuration and enables the logging according to that
4544
* configuration.
4645
*/
47-
class JfrLogConfiguration {
46+
final class JfrLogConfiguration {
4847
private static final String EMPTY_STRING_DEFAULT_CONFIG = "all=info";
4948
static final Map<LogTag, Set<JfrLogTag>> LOG_TAG_SETS = createLogTagSets();
5049

5150
@Platforms(Platform.HOSTED_ONLY.class)
52-
JfrLogConfiguration() {
51+
private JfrLogConfiguration() {
5352
}
5453

55-
void parse(String str) {
54+
static void parse(String str) {
5655
if (str.equalsIgnoreCase("disable")) {
5756
return;
5857
}
@@ -98,34 +97,18 @@ private static void verifySelections(JfrLogSelection[] selections) {
9897
}
9998
}
10099

100+
@Platforms(Platform.HOSTED_ONLY.class)
101101
private static Map<LogTag, Set<JfrLogTag>> createLogTagSets() {
102102
Map<LogTag, Set<JfrLogTag>> result = new EnumMap<>(LogTag.class);
103-
result.put(LogTag.JFR, EnumSet.of(JfrLogTag.JFR));
104-
result.put(LogTag.JFR_SYSTEM, EnumSet.of(JfrLogTag.JFR, JfrLogTag.SYSTEM));
105-
result.put(LogTag.JFR_SYSTEM_EVENT, EnumSet.of(JfrLogTag.JFR, JfrLogTag.SYSTEM, JfrLogTag.EVENT));
106-
result.put(LogTag.JFR_SYSTEM_SETTING, EnumSet.of(JfrLogTag.JFR, JfrLogTag.SYSTEM, JfrLogTag.SETTING));
107-
result.put(LogTag.JFR_SYSTEM_BYTECODE, EnumSet.of(JfrLogTag.JFR, JfrLogTag.SYSTEM, JfrLogTag.BYTECODE));
108-
result.put(LogTag.JFR_SYSTEM_PARSER, EnumSet.of(JfrLogTag.JFR, JfrLogTag.SYSTEM, JfrLogTag.PARSER));
109-
result.put(LogTag.JFR_SYSTEM_METADATA, EnumSet.of(JfrLogTag.JFR, JfrLogTag.SYSTEM, JfrLogTag.METADATA));
110-
result.put(LogTag.JFR_METADATA, EnumSet.of(JfrLogTag.JFR, JfrLogTag.METADATA));
111-
result.put(LogTag.JFR_EVENT, EnumSet.of(JfrLogTag.JFR, JfrLogTag.EVENT));
112-
result.put(LogTag.JFR_SETTING, EnumSet.of(JfrLogTag.JFR, JfrLogTag.SETTING));
113-
result.put(LogTag.JFR_DCMD, EnumSet.of(JfrLogTag.JFR, JfrLogTag.DCMD));
114-
115-
// JDK17 support
116-
if (JavaVersionUtil.JAVA_SPEC >= 17) {
117-
try {
118-
LogTag jfrSystemStreaming = Enum.valueOf(LogTag.class, "JFR_SYSTEM_STREAMING");
119-
LogTag jfrSystemThrottle = Enum.valueOf(LogTag.class, "JFR_SYSTEM_THROTTLE");
120-
result.put(jfrSystemStreaming, EnumSet.of(JfrLogTag.JFR, JfrLogTag.SYSTEM, JfrLogTag.STREAMING));
121-
result.put(jfrSystemThrottle, EnumSet.of(JfrLogTag.JFR, JfrLogTag.SYSTEM, JfrLogTag.THROTTLE));
122-
LogTag jfrStart = Enum.valueOf(LogTag.class, "JFR_START");
123-
result.put(jfrStart, EnumSet.of(JfrLogTag.JFR, JfrLogTag.START));
124-
} catch (IllegalArgumentException | NullPointerException e) {
125-
throw VMError.shouldNotReachHere("Should be defined", e);
103+
for (LogTag logTag : LogTag.values()) {
104+
EnumSet<JfrLogTag> logTagSet = EnumSet.noneOf(JfrLogTag.class);
105+
for (String t : logTag.name().split("_")) {
106+
/* This fails if a new JDK version adds entries to jdk.jfr.internal. */
107+
logTagSet.add(JfrLogTag.valueOf(t));
126108
}
109+
VMError.guarantee(!logTagSet.isEmpty());
110+
result.put(logTag, logTagSet);
127111
}
128-
129112
return result;
130113
}
131114

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/logging/JfrLogTag.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ enum JfrLogTag {
4040
METADATA,
4141
STREAMING,
4242
THROTTLE,
43+
PERIODIC,
4344
DCMD,
4445
START
4546
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/logging/JfrLogging.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,19 @@
3838
import jdk.jfr.internal.LogTag;
3939

4040
public class JfrLogging {
41-
private final JfrLogConfiguration configuration;
4241
private final String[] logLevels;
4342
private final String[] logTagSets;
4443
private int levelDecorationFill = 0;
4544
private int tagSetDecorationFill = 0;
4645

4746
@Platforms(Platform.HOSTED_ONLY.class)
4847
public JfrLogging() {
49-
configuration = new JfrLogConfiguration();
5048
logLevels = createLogLevels();
5149
logTagSets = createLogTagSets();
5250
}
5351

5452
public void parseConfiguration(String config) {
55-
configuration.parse(config);
53+
JfrLogConfiguration.parse(config);
5654
}
5755

5856
public void warnInternal(String message) {
@@ -94,8 +92,8 @@ public void logEvent(int level, String[] lines, boolean system) {
9492

9593
LogTag logTag = system ? LogTag.JFR_SYSTEM_EVENT : LogTag.JFR_EVENT;
9694
int tagSetId = SubstrateUtil.cast(logTag, Target_jdk_jfr_internal_LogTag.class).id;
97-
for (int i = 0; i < lines.length; i++) {
98-
log(tagSetId, level, lines[i]);
95+
for (String line : lines) {
96+
log(tagSetId, level, line);
9997
}
10098
}
10199

0 commit comments

Comments
 (0)