|
25 | 25 | package com.oracle.svm.hosted.jfr; |
26 | 26 |
|
27 | 27 | import java.lang.annotation.Annotation; |
28 | | -import java.lang.reflect.Field; |
29 | 28 | import java.lang.reflect.Method; |
30 | | -import java.lang.reflect.Modifier; |
31 | 29 | import java.util.Map; |
32 | 30 | import java.util.concurrent.ConcurrentHashMap; |
33 | 31 |
|
|
44 | 42 | import com.oracle.svm.util.ReflectionUtil; |
45 | 43 |
|
46 | 44 | import jdk.graal.compiler.serviceprovider.JavaVersionUtil; |
47 | | -import jdk.internal.misc.Unsafe; |
48 | 45 | import jdk.jfr.internal.JVM; |
49 | 46 | import jdk.jfr.internal.SecuritySupport; |
50 | 47 | import jdk.jfr.internal.event.EventWriter; |
@@ -72,7 +69,6 @@ public class JfrEventSubstitution extends SubstitutionProcessor { |
72 | 69 | JfrEventSubstitution(MetaAccessProvider metaAccess) { |
73 | 70 | baseEventType = metaAccess.lookupJavaType(jdk.internal.event.Event.class); |
74 | 71 | ResolvedJavaType jdkJfrEventWriter = metaAccess.lookupJavaType(EventWriter.class); |
75 | | - changeWriterResetMethod(jdkJfrEventWriter); |
76 | 72 | typeSubstitution = new ConcurrentHashMap<>(); |
77 | 73 | methodSubstitutions = new ConcurrentHashMap<>(); |
78 | 74 | fieldSubstitutions = new ConcurrentHashMap<>(); |
@@ -186,54 +182,6 @@ private boolean needsClassRedefinition(ResolvedJavaType type) { |
186 | 182 | return !type.isAbstract() && baseEventType.isAssignableFrom(type) && !baseEventType.equals(type); |
187 | 183 | } |
188 | 184 |
|
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 | | - |
237 | 185 | /* |
238 | 186 | * Mirror events contain the JFR-specific annotations. The mirrored event does not have any |
239 | 187 | * dependency on JFR-specific classes. If the mirrored event is used, we must ensure that the |
|
0 commit comments