Why is reference assignment atomic in Java?

前端 未结 3 1375
太阳男子
太阳男子 2021-02-05 14:09

As far as I know reference assignment is atomic in a 64 bit JVM. Now, I assume the jvm doesn\'t use atomic pointers internally to model this, since otherwise there would be no n

3条回答
  •  遥遥无期
    2021-02-05 14:52

    As the other answer outlines, the Java Memory Model states that references read/writes are atomic.

    But of course, that is the Java language memory model. On the other hand: no matter if we talk Java or Scala or Kotlin or ... in the end everything gets compiled into bytecode.

    There are no special bytecode instructions for Java. Scala in the end uses the very same instructions.

    Leading to: the properties of that memory model must be implemented inside the VM platform. Thus they must apply to other languages running on the platform as well.

提交回复
热议问题