Class JfrEventRegistration
- java.lang.Object
-
- io.netty.buffer.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, soEvent.isEnabled()is a constantfalseand 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
PlatformRecorderclass 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,
addListenerstores the caller'sAccessControlContextwith it, which references Netty's protection domain and so its class loader. Set-Dio.netty.jfr.enabled=falseto avoid this.This must not be initialized from an event class initializer: registration initializes the event classes.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.Class<?>[]EVENT_CLASSESprivate static InternalLoggerlogger
-
Constructor Summary
Constructors Modifier Constructor Description privateJfrEventRegistration()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static voidinit()Make sure the allocator events are registered once a Flight Recorder exists.voidrecorderInitialized(FlightRecorder recorder)
-
-
-
Field Detail
-
logger
private static final InternalLogger logger
-
EVENT_CLASSES
private static final java.lang.Class<?>[] EVENT_CLASSES
-
-
Method Detail
-
init
static void init()
Make sure the allocator events are registered once a Flight Recorder exists. Allocators call this, guarded byPlatformDependent.isJfrEnabled(), before they can emit events. The class initializer does the work.
-
recorderInitialized
public void recorderInitialized(FlightRecorder recorder)
- Specified by:
recorderInitializedin interfaceFlightRecorderListener
-
-