RFR: 8358318: JFR: Tighten up PlatformTracer initialization
Chen Liang
liach at openjdk.org
Mon Jun 2 15:30:54 UTC 2025
On Mon, 2 Jun 2025 11:19:52 GMT, Aleksey Shipilev <shade 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?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25584#discussion_r2121506115
More information about the hotspot-jfr-dev
mailing list