Re: Unsafe getLong/getLongVolatile has to read 8 bytes. It atomic / synchronized?

2023-06-09 Thread Remi Forax
If you can use Java 11, Take a look to the VarHandle API, using VarHandles is as fast as using Unsafe, but it does not crash. For an explanation of the different order modes, [ https://gee.cs.oswego.edu/dl/html/j9mm.html | https://gee.cs.oswego.edu/dl/html/j9mm.html ] Bonus answer: as far a

Re: Unsafe getLong/getLongVolatile has to read 8 bytes. It atomic / synchronized?

2023-06-09 Thread Chris Vest
The JLS section 17.7 says that plain long and double fields may observe word tearing, but volatile long and double fields will not: https://docs.oracle.com/javase/specs/jls/se20/html/jls-17.html#jls-17.7 How this guarantee is upheld is up to the JVM implementors, but on 64-bit platforms it's usual

Unsafe getLong/getLongVolatile has to read 8 bytes. It atomic / synchronized?

2023-06-09 Thread Fred Castaneras
Hello, So I know the difference between getLong and getLongVolatile => visibility. By using getLongVolatile I avoid any thread/process cache and I can be sure to read the latest contents from memory. Great! But how about synchronization / atomicity? *Do any of these two methods (getLong and