JDK-8211273 : Simplify JFR event posting
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: jfr
  • Affected Version: 12
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • Submitted: 2018-09-28
  • Updated: 2020-02-11
  • Resolved: 2019-11-26
Related Reports
Relates :  
Description
Quite a few places in Hotspot code sending JFR events look like this:

EventXYZ event;
event.set_X(a)
event.set_Y(b);
...
event.commit();

This could be simplified by using the variant of the commit() method taking the arguments directly, ie.

EventXYZ event;
event.commit(a, b, ...)

Maybe even the set_* methods become obsolete by doing this.

Suggested during the discussion of JDK-8211213 on the hotspot-dev mailing list.
Comments
I think the readability is higher with setters and prefer that to method with many arguments.
28-09-2018

Also add RAII-style scoped object that will auto-commit. When the properties of the commit is known at creation time of the event, this solution is somewhat safer. something like: template <typename Event> class ScopedCommit { private: Event _event; public: ScopedCommit(Event e) : _event(e) { } ~ScopedCommit() { _event.commit(); } };
28-09-2018