The following methods are synchronized using a global monitor:
- Unsafe.putValueVolatile()
- Unsafe.getValueVolatile()
which means that methods calling those methods are also subject to global synchronization:
- Unsafe.putValueRelease()
- Unsafe.getValueAcquire()
- Unsafe.putValueOpaque()
- Unsafe.getValueOpaque()
- Unsafe.getAndSetValue()
- Unsafe.compareAndSetReference() (in some cases)
- Unsafe.compareAndSetValue()
- Unsafe.compareAndExchangeReference() (in some cases)
- Unsafe.compareAndExchangeValue()
Use of a single global lock is likely to become a performance bottleneck in applications making heavy use (directly or indirectly) of those APIs.
Note: volatile is used to ensure proper visibility of a value change by inserting a memory barrier. Volatile also has a semantic to make long and double access atomic. In the case of a flat value with a non-atomic layout, such locking mechanism would not guarantee atomicity because the other ways to access the value (interpreter, runtime, compiled code, JNI) are not aware of this lock.
- Unsafe.putValueVolatile()
- Unsafe.getValueVolatile()
which means that methods calling those methods are also subject to global synchronization:
- Unsafe.putValueRelease()
- Unsafe.getValueAcquire()
- Unsafe.putValueOpaque()
- Unsafe.getValueOpaque()
- Unsafe.getAndSetValue()
- Unsafe.compareAndSetReference() (in some cases)
- Unsafe.compareAndSetValue()
- Unsafe.compareAndExchangeReference() (in some cases)
- Unsafe.compareAndExchangeValue()
Use of a single global lock is likely to become a performance bottleneck in applications making heavy use (directly or indirectly) of those APIs.
Note: volatile is used to ensure proper visibility of a value change by inserting a memory barrier. Volatile also has a semantic to make long and double access atomic. In the case of a flat value with a non-atomic layout, such locking mechanism would not guarantee atomicity because the other ways to access the value (interpreter, runtime, compiled code, JNI) are not aware of this lock.
- is blocked by
-
JDK-8348607 [lworld] Calls to Unsafe.getValue() / Unsafe.putValue() must be updated
-
- Resolved
-