Skip to content

Commit 662d383

Browse files
christianhaeubljerboaa
authored andcommitted
Fix JFR-related UnsatisfiedLinkErrors.
(cherry picked from commit 5a5abc7e67492f919aeede68bad450f3743a3572)
1 parent 7332df5 commit 662d383

File tree

7 files changed

+224
-59
lines changed

7 files changed

+224
-59
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspectionOptions.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ public static String getHeapdumpsCommandArgument() {
9393
return SubstrateOptionsParser.commandArgument(EnableMonitoringFeatures, MONITORING_HEAPDUMP_NAME);
9494
}
9595

96+
@Fold
97+
public static String getJfrNotSupportedMessage() {
98+
return "JFR is only supported on Linux and MacOS for native binaries built with '" +
99+
SubstrateOptionsParser.commandArgument(EnableMonitoringFeatures, MONITORING_JFR_NAME) + "'.";
100+
}
101+
96102
private static Set<String> getEnabledMonitoringFeatures() {
97103
return new HashSet<>(EnableMonitoringFeatures.getValue().values());
98104
}

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,13 @@
3535
*/
3636
public class JfrJavaEvents {
3737
private static final List<Class<? extends jdk.internal.event.Event>> EVENT_CLASSES = new ArrayList<>();
38-
private static final List<Class<? extends jdk.jfr.Event>> JFR_EVENT_CLASSES = new ArrayList<>();
3938

4039
@Platforms(Platform.HOSTED_ONLY.class)
41-
@SuppressWarnings("unchecked")
4240
public static synchronized void registerEventClass(Class<? extends jdk.internal.event.Event> eventClass) {
4341
EVENT_CLASSES.add(eventClass);
44-
if (jdk.jfr.Event.class.isAssignableFrom(eventClass)) {
45-
JFR_EVENT_CLASSES.add((Class<? extends jdk.jfr.Event>) eventClass);
46-
}
4742
}
4843

4944
public static List<Class<? extends jdk.internal.event.Event>> getAllEventClasses() {
5045
return EVENT_CLASSES;
5146
}
52-
53-
public static List<Class<? extends jdk.jfr.Event>> getJfrEventClasses() {
54-
return JFR_EVENT_CLASSES;
55-
}
5647
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.jfr;
26+
27+
import org.graalvm.nativeimage.hosted.FieldValueTransformer;
28+
29+
import com.oracle.svm.core.annotate.Alias;
30+
import com.oracle.svm.core.annotate.RecomputeFieldValue;
31+
import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind;
32+
import com.oracle.svm.core.annotate.TargetClass;
33+
34+
@TargetClass(className = "jdk.jfr.internal.JVMSupport")
35+
final class Target_jdk_jfr_internal_JVMSupport {
36+
@Alias //
37+
@RecomputeFieldValue(kind = Kind.Custom, declClass = JfrNotAvailableTransformer.class, isFinal = true) //
38+
private static boolean notAvailable;
39+
40+
}
41+
42+
final class JfrNotAvailableTransformer implements FieldValueTransformer {
43+
@Override
44+
public Object transform(Object receiver, Object originalValue) {
45+
return !HasJfrSupport.get();
46+
}
47+
}

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,13 @@ private void persistBuffers(JfrChunkWriter chunkWriter) {
151151
}
152152

153153
if (chunkWriter.shouldRotateDisk()) {
154-
Object chunkRotationMonitor = getChunkRotationMonitor();
154+
Object chunkRotationMonitor = Target_jdk_jfr_internal_JVM.CHUNK_ROTATION_MONITOR;
155155
synchronized (chunkRotationMonitor) {
156156
chunkRotationMonitor.notifyAll();
157157
}
158158
}
159159
}
160160

161-
private static Object getChunkRotationMonitor() {
162-
if (HasChunkRotationMonitorField.get()) {
163-
return Target_jdk_jfr_internal_JVM.CHUNK_ROTATION_MONITOR;
164-
} else {
165-
return Target_jdk_jfr_internal_JVM.FILE_DELTA_CHANGE;
166-
}
167-
}
168-
169161
@Uninterruptible(reason = "Locking without transition requires that the whole critical section is uninterruptible.")
170162
private static void tryPersistBuffer(JfrChunkWriter chunkWriter, JfrBufferNode node) {
171163
if (JfrBufferNodeAccess.tryLock(node)) {

0 commit comments

Comments
 (0)