[lworld] Initialization diagnostics for non-strict static fields

XMLWordPrintable

      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

            Assignee:
            Matias Saavedra Silva
            Reporter:
            Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: