Today, a mirror class can be created by putting the annotation jdk.jfr.internal.MirrorClass on an event class.
This works, but it has several disadvantages:
1. It complicates the implementation since the bytecode of the mirror class must be inspected to find the annotation when JVMUpcalls::bytesForEagerInstrumentation is called.
2. It could lead to a ClassCircularityError if the mirror class is loaded before the real event class. This can happen if the event is accidentally added to JDKEvents::eventClasses array.
3. It adds unnecessary overhead to startup since the class must go through the normal registration process for an event.
4. It creates confusion about which class is the real event class since both derives from jdk.internal.event.Event.
A better solution is to use a specific base class, i.e. MirrorEvent, to indicate that it is a mirror class, and add the event class name to a lookup without an annotation, and then also check for the base class when deriving event metadata for the type.
This works, but it has several disadvantages:
1. It complicates the implementation since the bytecode of the mirror class must be inspected to find the annotation when JVMUpcalls::bytesForEagerInstrumentation is called.
2. It could lead to a ClassCircularityError if the mirror class is loaded before the real event class. This can happen if the event is accidentally added to JDKEvents::eventClasses array.
3. It adds unnecessary overhead to startup since the class must go through the normal registration process for an event.
4. It creates confusion about which class is the real event class since both derives from jdk.internal.event.Event.
A better solution is to use a specific base class, i.e. MirrorEvent, to indicate that it is a mirror class, and add the event class name to a lookup without an annotation, and then also check for the base class when deriving event metadata for the type.