Value integrity guarantee for concurrent long writes in 64-bit OpenJDK 7/8

前端 未结 2 1469
广开言路
广开言路 2021-02-08 11:32

Note: this question isn\'t related to volatile, AtomicLong, or any perceived deficiency in the described use case.

The property I am trying to prove or rule out is as f

相关标签:
2条回答
  • 2021-02-08 12:13

    https://www.securecoding.cert.org/confluence/display/java/VNA05-J.+Ensure+atomicity+when+reading+and+writing+64-bit+values

    VNA05-J. Ensure atomicity when reading and writing 64-bit values

    ....

    VNA05-EX1: This rule can be ignored for platforms that guarantee that 64-bit long and double values are read and written as atomic operations. Note, however, that such guarantees are not portable across different platforms.

    The link above discusses this issue in the context of security and seems to suggest that on 64 bit platforms you can indeed assume long assignments to be atomic. 32 bit systems are becoming somewhat rare in server environments, so it is not a strange assumption to make. Do note that the exception is a bit vague on which platforms make this guarantee and doesn't explicitly state that 64 bit openjdk on 64 bit intel is fine for example.

    0 讨论(0)
  • 2021-02-08 12:25

    In fact, you've already answered your own question.

    There is no "non-atomic treatment" of double and long on 64-bit HotSpot JVM, because

    1. HotSpot uses 64-bit registers to store 64-bit values (x86_64.ad vs. x86_32.ad).
    2. HotSpot aligns 64-bit fields on 64-bit boundary (universe.inline.hpp)
    0 讨论(0)
提交回复
热议问题