On Thu, 9 May 2024 15:41:42 GMT, Erik Gahlin <egah...@openjdk.org> wrote:

>> src/java.base/share/classes/jdk/internal/event/JFRTracing.java line 51:
>> 
>>> 49:       field.setAccessible(true);
>>> 50:       field.setBoolean(null, true);
>>> 51:   }
>> 
>> Using reflection with `Field` seems expedient - a more modern way could be 
>> to use `VarHandle` but I guess it would require more setup to obtain a 
>> `Lookup` with the proper capabilities?
>
> The field is only used once and a VarHandle implementation loads three 
> additional classes during startup and in my measurements add about 0.6 ms to 
> startup.

A compromise between performance and readability is:

if (JFRTracing.isEnabled()) {
      ...
}

One additional class is loaded, but it's more clear where it comes from. I 
didn't want to do that for the ThrowableTracer class since it had a clinit.

This could potentially cause problems if JFRTracing is loaded early from 
Throwable or other class in the future. The static boolean flag is more safe, 
so probably better.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/19129#discussion_r1595656857

Reply via email to