RFR: 8358318: JFR: Tighten up PlatformTracer initialization

Aleksey Shipilev shade at openjdk.org
Mon Jun 2 15:51:50 UTC 2025


On Mon, 2 Jun 2025 15:27:52 GMT, Chen Liang <liach at openjdk.org> wrote:

>> Started as SonarCloud complaint that MethodSetting.apply initializes a static field. But I think there is a larger problem here, which I completely missed during [JDK-8352738](https://bugs.openjdk.org/browse/JDK-8352738) review: the `PlatformTracer` initialization can technically run several times, AFAICS. This PR tightens up the initialization. It also allows us to call `ensureInitialized` from other places, if we ever find a need.
>> 
>> Additional testing:
>>  - [x] Linux x86_64 server fastdebug, `jdk_jfr`
>
> src/jdk.jfr/share/classes/jdk/jfr/internal/tracing/PlatformTracer.java line 49:
> 
>> 47:  */
>> 48: public final class PlatformTracer {
>> 49:     private static volatile boolean INITIALIZED;
> 
> Can we make this a static final field in a holder class, so we call `PlatformTracer::initialize` from that holder class's `<clinit>`, and after initialization, the check to `INITIALIZED` field can be constant-folded instead of being a volatile read?

As @egahlin mentions, it might be unnecessary, as this code is supposed to run in single-thread mode, and we do not need `volatile` at all.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25584#discussion_r2121565935


More information about the hotspot-jfr-dev mailing list