-
Enhancement
-
Resolution: Fixed
-
P4
-
17, 20, 21
-
b03
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.
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.
- relates to
-
JDK-8309956 Shenandoah: Strengthen the mark word check in string dedup
- Resolved