Typed static memory for late initialization of static class members in Hotspot

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Fixed
    • Priority: P4
    • 25
    • Affects Version/s: None
    • Component/s: hotspot
    • b22

      In Hotspot it is a common design pattern to instantiate one global and static instance of a datatype at some point in the initialization of the program.
      We do not use dynamic static initialization, as this often leads to bugs when combined with non-trivial constructors (see "Static Initialization Order Fiasco."
      Typically, we avoid this issue by instead using a pointer and a `malloc` in the initialization code.
      This requires extra ceremony and an extra malloc call, which is unergonomic.
      We can add a StableValue<T> class, which holds enough memory to initialize exactly one instance of T.
      By using this, we can have global statics which are alive for the entire duration of the program.

            Assignee:
            Johan Sjölen
            Reporter:
            Johan Sjölen
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: