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

Strengthen and optimize oopDesc age methods

    XMLWordPrintable

Details

    • gc
    • b03

    Description

      In a relevant discussion on how Shenandoah strdedup handles ages (JDK-8309956), I spotted that `oopDesc::age` is subtly racy: we read the mark, check it for displaced header, and then reach for the displaced header, reading the mark again. If unlock happened at the same time, we might be reading non-displaced mark the second time, which would fail the assert or even reach `fatal` in `markWord::displaced_mark_helper`. We should really be reading the mark once.

      Note that Shenandoah strdedup code actually protects from this race by checking the mark word for displaced header non-racily, and bailing when displaced header is detected. But it is too late, because it already touched `oopDesc::age`. Other collectors, G1, Serial and Parallel ever enter these methods during STW, where no odd header modification happen. Still, this avoids double read on relatively hot path for them. Mark word load is the relaxed atomic load, so it is not folded automatically.

      Attachments

        Issue Links

          Activity

            People

              shade Aleksey Shipilev
              shade Aleksey Shipilev
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: