Skip to content

Commit 61bc85c

Browse files
[GR-51007] JFR cleanups.
PullRequest: graal/16415
2 parents bd060d2 + fce46ca commit 61bc85c

File tree

4 files changed

+8
-65
lines changed

4 files changed

+8
-65
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import com.oracle.svm.core.util.UserError;
4848
import com.oracle.svm.core.util.VMError;
4949
import com.oracle.svm.util.LogUtils;
50-
import com.oracle.svm.util.ModuleSupport;
5150
import com.oracle.svm.util.ReflectionUtil;
5251
import com.sun.management.HotSpotDiagnosticMXBean;
5352
import com.sun.management.internal.PlatformMBeanProviderImpl;
@@ -149,8 +148,6 @@ public List<Class<? extends Feature>> getRequiredFeatures() {
149148

150149
@Override
151150
public void afterRegistration(AfterRegistrationAccess access) {
152-
ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, null, false, "jdk.jfr");
153-
ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, null, false, "java.base");
154151

155152
// Initialize some parts of JFR/JFC at image build time.
156153
List<Configuration> knownConfigurations = JFC.getConfigurations();

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545

4646
import jdk.graal.compiler.api.replacements.Fold;
4747
import jdk.jfr.internal.JVM;
48+
import jdk.jfr.internal.LogLevel;
4849
import jdk.jfr.internal.LogTag;
50+
import jdk.jfr.internal.Logger;
4951

5052
@SuppressWarnings({"static-method", "unused"})
5153
@TargetClass(value = jdk.jfr.internal.JVM.class, onlyWith = HasJfrSupport.class)
@@ -168,10 +170,15 @@ public static void unregisterStackFilter(long stackFilterId) {
168170
throw VMError.unimplemented("JFR StackFilters are not yet supported.");
169171
}
170172

173+
/**
174+
* As of 22+27, This method is both used to set cutoff tick values for leak profiling and
175+
* for @Deprecated events.
176+
*/
171177
@Substitute
172178
@TargetElement(onlyWith = JDK22OrLater.class)
173179
public static void setMiscellaneous(long eventTypeId, long value) {
174-
throw VMError.unimplemented("@Deprecated JFR events are not yet supported.");
180+
Logger.log(LogTag.JFR_SETTING, LogLevel.WARN, "@Deprecated JFR events, and leak profiling are not yet supported.");
181+
/* Explicitly don't throw an exception (would result in an unspecific warning). */
175182
}
176183

177184
/** See {@link JVM#getThreadId}. */

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrEventFeature.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import com.oracle.svm.core.meta.SharedType;
4646
import com.oracle.svm.core.util.VMError;
4747
import com.oracle.svm.hosted.FeatureImpl;
48-
import com.oracle.svm.util.ModuleSupport;
4948

5049
import jdk.internal.event.Event;
5150
import jdk.jfr.internal.JVM;
@@ -67,14 +66,6 @@ public List<Class<? extends Feature>> getRequiredFeatures() {
6766
return Collections.singletonList(JfrFeature.class);
6867
}
6968

70-
@Override
71-
public void afterRegistration(AfterRegistrationAccess access) {
72-
ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, JfrEventFeature.class, false, "jdk.jfr", "jdk.jfr.events");
73-
ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, JfrFeature.class, false, "jdk.jfr", "jdk.jfr.events");
74-
ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, JfrEventSubstitution.class, false, "jdk.internal.vm.ci", "jdk.vm.ci.hotspot");
75-
ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, JfrEventFeature.class, false, "java.base", "jdk.internal.event");
76-
}
77-
7869
@Override
7970
public void duringSetup(DuringSetupAccess c) {
8071
FeatureImpl.DuringSetupAccessImpl config = (FeatureImpl.DuringSetupAccessImpl) c;

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jfr/JfrEventSubstitution.java

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
package com.oracle.svm.hosted.jfr;
2626

2727
import java.lang.annotation.Annotation;
28-
import java.lang.reflect.Field;
2928
import java.lang.reflect.Method;
30-
import java.lang.reflect.Modifier;
3129
import java.util.Map;
3230
import java.util.concurrent.ConcurrentHashMap;
3331

@@ -44,7 +42,6 @@
4442
import com.oracle.svm.util.ReflectionUtil;
4543

4644
import jdk.graal.compiler.serviceprovider.JavaVersionUtil;
47-
import jdk.internal.misc.Unsafe;
4845
import jdk.jfr.internal.JVM;
4946
import jdk.jfr.internal.SecuritySupport;
5047
import jdk.jfr.internal.event.EventWriter;
@@ -72,7 +69,6 @@ public class JfrEventSubstitution extends SubstitutionProcessor {
7269
JfrEventSubstitution(MetaAccessProvider metaAccess) {
7370
baseEventType = metaAccess.lookupJavaType(jdk.internal.event.Event.class);
7471
ResolvedJavaType jdkJfrEventWriter = metaAccess.lookupJavaType(EventWriter.class);
75-
changeWriterResetMethod(jdkJfrEventWriter);
7672
typeSubstitution = new ConcurrentHashMap<>();
7773
methodSubstitutions = new ConcurrentHashMap<>();
7874
fieldSubstitutions = new ConcurrentHashMap<>();
@@ -186,54 +182,6 @@ private boolean needsClassRedefinition(ResolvedJavaType type) {
186182
return !type.isAbstract() && baseEventType.isAssignableFrom(type) && !baseEventType.equals(type);
187183
}
188184

189-
/**
190-
* The method EventWriter.reset() is private but it is called by the EventHandler classes, which
191-
* are generated automatically. To prevent bytecode parsing issues, we patch the visibility of
192-
* that method using the hacky way below.
193-
*/
194-
private static void changeWriterResetMethod(ResolvedJavaType eventWriterType) {
195-
for (ResolvedJavaMethod m : eventWriterType.getDeclaredMethods(false)) {
196-
if (m.getName().equals("reset")) {
197-
setPublicModifier(m);
198-
}
199-
}
200-
}
201-
202-
private static void setPublicModifier(ResolvedJavaMethod m) {
203-
try {
204-
Class<?> hotspotMethodClass = m.getClass();
205-
Method metaspaceMethodM = getMethodToFetchMetaspaceMethod(hotspotMethodClass);
206-
metaspaceMethodM.setAccessible(true);
207-
long metaspaceMethod = (Long) metaspaceMethodM.invoke(m);
208-
VMError.guarantee(metaspaceMethod != 0);
209-
Class<?> hotSpotVMConfigC = Class.forName("jdk.vm.ci.hotspot.HotSpotVMConfig");
210-
Method configM = hotSpotVMConfigC.getDeclaredMethod("config");
211-
configM.setAccessible(true);
212-
Field methodAccessFlagsOffsetF = hotSpotVMConfigC.getDeclaredField("methodAccessFlagsOffset");
213-
methodAccessFlagsOffsetF.setAccessible(true);
214-
Object hotSpotVMConfig = configM.invoke(null);
215-
int methodAccessFlagsOffset = methodAccessFlagsOffsetF.getInt(hotSpotVMConfig);
216-
int modifiers = Unsafe.getUnsafe().getInt(metaspaceMethod + methodAccessFlagsOffset);
217-
int newModifiers = modifiers & ~Modifier.PRIVATE | Modifier.PUBLIC;
218-
Unsafe.getUnsafe().putInt(metaspaceMethod + methodAccessFlagsOffset, newModifiers);
219-
} catch (Exception ex) {
220-
throw VMError.shouldNotReachHere(ex);
221-
}
222-
}
223-
224-
private static Method getMethodToFetchMetaspaceMethod(Class<?> method) throws NoSuchMethodException {
225-
// The exact method depends on the JVMCI version.
226-
try {
227-
return method.getDeclaredMethod("getMethodPointer");
228-
} catch (NoSuchMethodException e) {
229-
try {
230-
return method.getDeclaredMethod("getMetaspaceMethod");
231-
} catch (NoSuchMethodException e2) {
232-
return method.getDeclaredMethod("getMetaspacePointer");
233-
}
234-
}
235-
}
236-
237185
/*
238186
* Mirror events contain the JFR-specific annotations. The mirrored event does not have any
239187
* dependency on JFR-specific classes. If the mirrored event is used, we must ensure that the

0 commit comments

Comments
 (0)