是jvm原子中的所有指令吗? [英] are all instructions in jvm atomic?
问题描述
我记得我以前读过某个地方,但是现在找不到正式文档.
I remember I read the somewhere before,but I can't find the offical document now.
jvm中的所有指令都是原子的吗?
are all instructions in jvm all atomic?
喜欢:
iinc
iload
aload
所有原子?
推荐答案
您提到的字节码指令(iinc
,iload
,aload
等)对操作数堆栈中的值进行操作和局部变量.这些区域是线程局部的(请参阅JVMS 2.5 , 2.6 ),也就是说,在这里谈论原子性是没有意义的. IE.不能使用lock xadd
之类的原子CPU指令来实现它们,但是没有人应该在意.
The bytecode instructions you mentioned (iinc
, iload
, aload
etc.) operate on the values from the operand stack and on the local variables. These areas are thread-local (see JVMS 2.5, 2.6), that is, speaking about atomicity here is meaningless. I.e. they are NOT implemented using atomic CPU instructions like lock xadd
, but nobody should care.
读取或写入字段和数组元素(getfield
,putfiled
,iastore
等)的字节码指令是原子的,但long
和double
类型除外(请参见JLS
The bytecode instructions that read or write fields and array elements (getfield
, putfiled
, iastore
etc.) are atomic except for long
and double
types (see JLS 17.7). 32-bit JVM may implement (actually, HotSpot JVM does implement) reading and writing of 64-bit fields with two 32-bit loads or stores, unless the field is declared volatile
.
这篇关于是jvm原子中的所有指令吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!