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

Add BarrierSet downcast support

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 9
    • Component/s: hotspot
    • Labels:
      None
    • Subcomponent:
      gc
    • Resolved In Build:
      b55
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        The barrier set is typically stored and obtained as a BarrierSet base object, with many users then downcasting to a more specific derived class.

        (1) Sometimes that downcast is known to be safe, from context. An example of this is G1CollectedHeap::g1_barrier_set(). [But that could be pretty limiting if we decide we need more barrier set kinds for G1 variants/options.]

        (2) Sometimes that downcast is checked via a preceding assert using BarrierSet::is_a() with a corresponding tag. It's an assert rather than a guarantee because the present implementation of is_a() is not fast. [I haven't studied all such occurrences to see if they are performance critical.] This is a stand-in for dynamic_cast, in the absence of RTTI support.

        (3) Sometimes the downcast is just blindly done, and hope for the best. Probably at least some of these cases really fall into (1) above, but are not obviously so. And some of them might just be bugs waiting to happen.

        We can do better than this.

        My current thought is to add something like the following:

        template<typename T> T* barrier_set_cast(BarrierSet* bs);
        template<typename T> T const* barrier_set_cast(BarrierSet const* bs);
          Return bs downcasted to corresponding pointer to T, if the actual
          type of *bs is derived from T. Otherwise error.

        template<typename T> struct GetBarrierSetName;
          Provides value member of type BarrierSet::Name corresponding to T.

        For each T that will be used with barrier_set_cast, there must be a corresponding specialization of GetBarrierSetName.

        Add uintx BarrierSet::_kind_set, which is a bitset indicating the BarrierSet::Name tags that apply to the barrier set. Appropriate bits in _kind_set are set by the corresponding derived class constructors.

        The implementation of barrier_set_cast can validate the cast by using GetBarrierSetName to get the corresponding tag value, and test whether the corresponding bit is set in _kind_set. This can be an assert, and is sufficiently light-weight that a guarantee can be considered.

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved: