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

Fix memory barriers for @Stable fields

    XMLWordPrintable

Details

    • b12

    Description

      Currently we detect writes to stable fields in Parse::do_put_xxx and then call set_wrote_stable which will lead to a membar being emitted at method exit. This can lead to cases like the one discussed here, where annotating a field with @Stable leads to a regression on aarch64 (and likely some other architectures): https://github.com/openjdk/jdk/pull/19433#discussion_r1619053915

      Basically:

      private @Stable int hash;

      public int hashCode() {
          int hc = hash;
          if (hc == 0) {
              hc = hash = initHashCode();
          }
          return hc;
      }

      [~aboldtch] showed that if the write to the stable field is outlined to a method annotated with @DontInline then the would-be regression (in the specific benchmark) disappears. A good diagnostic, but not a universally compelling workaround if the path that writes to the stable field is reasonably hot. It seems the ideal would be if C2 could emit the membar only for branches where the write happens (with a fallback to emit at the exit in more complex cases).

      Filing this as an enhancement initially, but it's not unreasonable to consider this as a bug/performance regression since we might have inadvertently regressed aarch64 in a few places by applying @Stable backed primarily on evidence from x64 setups.

      Attachments

        Issue Links

          Activity

            People

              shade Aleksey Shipilev
              redestad Claes Redestad
              Votes:
              1 Vote for this issue
              Watchers:
              19 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: