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

Fix ThreadsSMRSupport::_bootstrap_list

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b05

      Description

      Currently, ThreadsSMRSupport::_bootstrap_list is a class static variable of type ThreadsList, with the following initializer.

      ThreadsList ThreadsSMRSupport::_bootstrap_list = ThreadsList(0);

      There are a couple of problems with this.

      First, that is technically a copy initialization (C++03 8.5/14), with copy elision being applicable (C++03 12.8/15). The copy assignment operator must be accessible and defined, even if copy elision eliminates the reference. The copy ctor and assignment operator for ThreadsList are currently the defaults, so are not definitions one should be using (see below; ThreadsList should perhaps be noncopyable). The only reason we don't see crashes here is copy elision, but that's an optional optimization; though widely implemented, elimination of the copy isn't required until C++17.

      The copy initialization and associated reliance on copy elision can be eliminated by using direct initialization, e.g.

      ThreadsList ThreadsSMRSupport::_bootstrap_list(0);

      Note that declaring ThreadsList noncopyable via the technique of giving it declared but undefined copy ctor and assignment operator may not catch this specific case; ThreadsSMRSupport is a friend of ThreadsList, so has private access, and copy elision may then eliminate the reference. Using C++11 deleted definitions would catch that.

      However, there's a second issue here. A ThreadsList contains an array managed via NEW/FREE_C_HEAP_ARRAY. (This is why the default copy ctor and assignment operator shouldn't be used.) We normally avoid static initialization of allocation or (other) things which depend on VM initialization. It may be that the current implementation only works by accident of static initializer ordering.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              kbarrett Kim Barrett
              Reporter:
              kbarrett Kim Barrett
              Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: