I remember I read the somewhere before,but I can't find the offical document now.
are all instructions in jvm all atomic?
like:
iinc
iload
aload
all atomic?
I remember I read the somewhere before,but I can't find the offical document now.
are all instructions in jvm all atomic?
like:
iinc
iload
aload
all atomic?
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.
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
.