Where is sun.misc.Unsafe documented?

UnsafeJava

Unsafe Problem Overview


Does anyone know of any comprehensive documentation for sun.misc.Unsafe?

I'm looking for documentation on Unsafe.putOrderedInt(). This was all I was able to find.

public native  void putOrderedInt(Object o,
    long offset,
    int x)

     Ordered/Lazy version of #putIntVolatile(Object, long, int) 

Does anyone know of a better source?

Unsafe Solutions


Solution 1 - Unsafe

There is a nice post about it on mishadoff's blog here.

The class is officially undocumented though.

Solution 2 - Unsafe

Regarding the putOrdered methods..

You can call this method to set the volatile field without using a volatile store.. If you execute a volatile store, you basically have a store memory barrier which ensures that all store instruction prior the barrier, happen before barrier and that memory is visible by ensuring the data is propagated to the cache sub-system.. So when you have the volatile store you must wait for the store buffer to drain.. With putOrdered thread executing will not wait for the store buffer to drain and this can improve performance.. However as a consequence stored value will not be visible to other threads immediately..

If you have a look on AtomicLong (or other Atomic classes) there is a lazySet method that actually executes putOrderedLong. The javadoc on this method is:

> Eventually sets to the given value.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJames RaitsevView Question on Stackoverflow
Solution 1 - UnsafemwerschyView Answer on Stackoverflow
Solution 2 - UnsafeIvan SenicView Answer on Stackoverflow