RFR: 8261407: ReflectionFactory.checkInitted() is not thread-safe

liach duke at openjdk.java.net
Sun Dec 19 03:29:48 UTC 2021


Upon review of [8261407](https://bugs.openjdk.java.net/browse/JDK-8261407), by design, duplicate initialization of ReflectionFactory should be safe as it performs side-effect-free property read actions, and the suggesting of making the `initted` field volatile cannot prevent concurrent initialization either; however, having `initted == true` published without the other fields' values is a possibility, which this patch addresses.

This simulates what's done in `CallSite`'s constructor for `ConstantCallSite`. Please feel free to point out the problems with this patch, as I am relatively inexperienced in this field of fences and there are relatively less available documents. (Thanks to https://shipilev.net/blog/2014/on-the-fence-with-dependencies/)

-------------

Commit messages:
 - 8261407: ReflectionFactory.checkInitted() is not thread-safe

Changes: https://git.openjdk.java.net/jdk/pull/6889/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=6889&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8261407
  Stats: 3 lines in 1 file changed: 3 ins; 0 del; 0 mod
  Patch: https://git.openjdk.java.net/jdk/pull/6889.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/6889/head:pull/6889

PR: https://git.openjdk.java.net/jdk/pull/6889


More information about the core-libs-dev mailing list