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

GlobalCounter padding is too optimistic

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 12
    • 12
    • hotspot
    • None
    • b17

      Defined as follows:

      class GlobalCounter : public AllStatic {
       private:
        // Since do not know what we will end up next to in BSS, we make sure the
        // counter is on a seperate cacheline.
        struct PaddedCounter {
          DEFINE_PAD_MINUS_SIZE(0, DEFAULT_CACHE_LINE_SIZE/2, 0);
          volatile uintx _counter;
          DEFINE_PAD_MINUS_SIZE(1, DEFAULT_CACHE_LINE_SIZE/2, sizeof(volatile uintx));
        };

      Why "/2"? Every other use of DEFINE_PAD_MINUS_SIZE macro uses the full cache line size, and it is sensible: you can have two values *at the same cache line* separated by half of its width, unless the whole thing is cache-line-aligned.

      This also sets up for awkward accidents when others copy-paste this padding block as example for padding elsewhere.

            rehn Robbin Ehn
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: