Class JfrEventRegistration

  • All Implemented Interfaces:
    FlightRecorderListener

    final class JfrEventRegistration
    extends java.lang.Object
    implements FlightRecorderListener
    Registers the allocator events with JFR once a Flight Recorder has been initialized.

    The events are @Registered(false), because registering the first event class sets up JFR's metadata repository, which is expensive and pointless in processes that never record. Until an event class is registered, JFR does not instrument it, so Event.isEnabled() is a constant false and the JIT removes the allocation path guards entirely. Registering it later retransforms the class, which deoptimizes the guards, exactly like starting a recording in a running process.

    JFR notifies listeners while it holds the PlatformRecorder class lock. It registers its own JDK events under the same lock, and the event classes are loaded by this class's initializer and have trivial initializers, so registering from the callback does not wait for anything that may in turn wait for that lock.

    A Flight Recorder is initialized at most once per JVM, so the listener removes itself after registering the events. Otherwise JFR's static listener list would keep this class, and with it the class loader that loaded Netty, reachable for the lifetime of the JVM. JFR iterates over a copy of the list, so this is safe from the callback.

    If no Flight Recorder is ever initialized, the listener stays in that list, so the class loader that loaded Netty can't be unloaded, for example on a webapp redeploy. Holding the listener weakly doesn't help: before JDK 25, addListener stores the caller's AccessControlContext with it, which references Netty's protection domain and so its class loader. Set -Dio.netty.jfr.enabled=false to avoid this.

    This must not be initialized from an event class initializer: registration initializes the event classes.

    • Field Detail

      • EVENT_CLASSES

        private static final java.lang.Class<?>[] EVENT_CLASSES
    • Constructor Detail

      • JfrEventRegistration

        private JfrEventRegistration()