-
Type:
Enhancement
-
Resolution: Unresolved
-
Priority:
P4
-
Affects Version/s: repo-valhalla
-
Component/s: hotspot
Implement a command-line flag to produce diagnostics whenever one of the following occurs:
- During class initialization, a non-strict static field is read before it has been assigned at least once
- During class initialization, a non-strict static *final* field is assigned after it has already been read
These checks mirror the checks implemented for strict static fields, but in this case we don't necessarily want to throw an exception—it should be possible to notify and then keep going.
It's not expected to be useful to check that all fields are set at the end of <clinit>, so that is not one of the proposed checks. (It's safe and fairly common for a class author to declare blank static fields that are not touched until later.)
(The read check may trigger for similar safe cases where the initialization code deliberately reads a default value from a blank non-final field. But in this case it's hard to distinguish between legitimate use cases and bugs, and we'll leave it to the developer to review the diagnostics.)
Potential flags: something like
-XX:CheckAllStaticsStrictly=[warn|error|jfr]
or
-Xlog:strict+static=warning
- During class initialization, a non-strict static field is read before it has been assigned at least once
- During class initialization, a non-strict static *final* field is assigned after it has already been read
These checks mirror the checks implemented for strict static fields, but in this case we don't necessarily want to throw an exception—it should be possible to notify and then keep going.
It's not expected to be useful to check that all fields are set at the end of <clinit>, so that is not one of the proposed checks. (It's safe and fairly common for a class author to declare blank static fields that are not touched until later.)
(The read check may trigger for similar safe cases where the initialization code deliberately reads a default value from a blank non-final field. But in this case it's hard to distinguish between legitimate use cases and bugs, and we'll leave it to the developer to review the diagnostics.)
Potential flags: something like
-XX:CheckAllStaticsStrictly=[warn|error|jfr]
or
-Xlog:strict+static=warning
- relates to
-
JDK-8351990 JVM implementation of strict field initialization
-
- Open
-