[GR-51654] Add support for JFR jdk.ObjectCount and jdk.ObjectCountAfterGC events.
Summary
These events provide aggregate data about objects on the heap. They also useful for inspecting how the population of objects on the heap changes over time. For each class, the number of instances and total size is reported. The only difference between these two events is that JFR jdk.ObjectCount is periodic and guaranteed to run once per JFR chunk (not on every GC), while JFR jdk.ObjectCountAfterGC runs upon every GC.
Details
After a GC is completed, the heap is walked and live object data is gathered. This all happens during the GC safepoint.
Performance
This is expected to slightly slow down garbage collection and so is off-by-default in JIT mode. I ran an experiment comparing with/without these new events enabled. Hyperfoil was used to make 50 requests/s over 5s to a simple plaintext quarkus app running JFR. See here for the code. The results of 14 paired trials is shown below:
Increase in mean response time after new events enabled
| Â | Mean response time increase (us) |
|---|---|
| Mean | 292.4 |
| Median | 226 |
| STDV | 371.092 |
| MAX | 1238 |
Increase in 99th % response time after new events enabled
| Â | p99 response time increase (us) |
|---|---|
| Mean | 6477.2 |
| Median | 6783 |
| STDV | 5112.92 |
| MAX | 13566 |
(P99 means 99% of responses were faster)
As you can see, the performance hit is much worse for p99. This is expected because the change only happens during a GC. RSS usage and start up time were unaffected by enabling these new events.
I also tried explicitly timing how long the ObjectCountEventSupport.emitEvents() takes to complete. It appears to take about 2.7-3.1 ms on my machine (based on results from only 4 GCs).
Related issue: https://github.com/oracle/graal/issues/7402