Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8354954

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

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 25
    • None
    • hotspot
    • master

      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.

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

              Created:
              Updated:
              Resolved: