[lworld] RFR: 8349945: Implement strict static fields (proposed JVM feature)

Dan Heidinga heidinga at openjdk.org
Thu May 22 11:52:07 UTC 2025


On Tue, 20 May 2025 22:15:29 GMT, Matias Saavedra Silva <matsaave at openjdk.org> wrote:

> This patch enables and implements verification for fields with the ACC_STATIC and ACC_STRICT modifiers. To enforce strictness on static fields, the reads and writes on the field are tracked dynamically to ensure that the field is written before being read and written to before.

src/hotspot/share/c1/c1_Runtime1.cpp line 1171:

> 1169:     // Strict statics may require tracking if their class is not fully initialized.
> 1170:     // For now we can bail out of the compiler and let the interpreter handle it.
> 1171:     deoptimize_for_strict_static = result.is_strict_static_unset();

Deoptimizing on strict fields makes sense when the field is unset as an initial implementation.

As a possible future optimization, we could make some additional checks here to decide whether we need to deopt or not and instead simulate the strict static is_set bits here.  `current` Thread is either the thread initializing the class and therefore able to read/update the set/unset bits or it is some other thread that would need to wait.

If `current` is the initializing thread, and this is a strict static field write, we know we're currently executing the field set or we wouldn't be patching the code.  Given that, it would be possible to avoid the deopt by calling a helper from this code to toggle the bit.

Something to think about for the future when strict statics are more common to avoid spurious deopts

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

PR Review Comment: https://git.openjdk.org/valhalla/pull/1465#discussion_r2102365209


More information about the valhalla-dev mailing list