@Registered(false) staticclass PackageUnlockEvent extends Event {
} publicstaticvoid main(String... args) throws Throwable { // --add-opens jdk.jfr/jdk.jfr.events=ALL-UNNAMED gives access to // the FileReadEvent class in the jdk.jfr module. // When JFR is initialized the FileReadEvent is registered and an EventConfiguration object // assigned to its static field eventConfiguration try (Recording r = new Recording()) {
r.start();
} // The tests gets the EventConfiguration object from the class Class<?>c = Class.forName("jdk.jfr.events.FileReadEvent");
Field f = c.getDeclaredField("eventConfiguration");
f.setAccessible(true);
Object o = f.get(null); Class<?> clazz = Class.forName("jdk.jfr.internal.event.EventConfiguration");
Method m = clazz.getDeclaredMethod("isRegistered", newClass[0]); // it then tries to execute a method on the object from the unnamed module try {
System.out.println("Is registered: " + m.invoke(o, new Object[0])); thrownew Exception("Did NOT expect unnamed module to be able to execute method in EventConfiguration object before event registration");
} catch (IllegalAccessException iae) { // OK, as expected
} // The registration makes the jdk.jfr.internal.event accessible
FlightRecorder.register(PackageUnlockEvent.class); try {
System.out.println("Is registered: " + m.invoke(o, new Object[0]));
} catch (IllegalAccessException iae) { thrownew Exception("Did expect unnamed module to be able to execute method in EventConfiguration object efter event registration", iae);
} // If a Security Manager would be present, the caller would need // to have FlightRecorderPermission("registerEvent")
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.