JDK Flight Recorder (JFR) provides support for custom events as a profiler. Around two years ago, I wrote a blog post on this very topic: Custom JFR Events: A Short Introduction. These custom events are beneficial because they enable us to record additional project-specific information alongside the standard JFR events, all in the same file. We can then view and process this information with the JFR tools. You can freely specify these events in Java.
There is only one tiny problem nobody talks about: Array support (and, in more general, the support of complex types).
Take the following event:
class ArrayEvent extends Event {
@Label("String Array")
String[] stringArray;
@Label("Int Array")
int[] intArray;
@Label("Long Array")
long[] longArray;
@Label("Non array field")
String nonArrayField = "default";
}
What would you expect to happen when we create the event using the following code?
ArrayEvent event = new ArrayEvent();
event.stringArray = new String[]{"one", "two", "three"};
event.intArray = new int[]{1, 2, 3, 4, 5};
event.longArray = new long[]{100L, 200L, 300L};
event.commit();
Continue reading












