Class UnsafeAccess
java.lang.Object
org.jctools.util.UnsafeAccess
Why should we resort to using Unsafe?
- To construct class fields which allow volatile/ordered/plain access: This requirement is covered by
AtomicReferenceFieldUpdaterand similar but their performance is arguably worse than the DIY approach (depending on JVM version) while Unsafe intrinsification is a far lesser challenge for JIT compilers. - To construct flavors of
AtomicReferenceArray. - Other use cases exist but are not present in this library yet.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanstatic final booleanstatic final sun.misc.Unsafe -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longfieldOffset(Class clz, String fieldName) private static sun.misc.Unsafeprivate static booleanprivate static boolean
-
Field Details
-
SUPPORTS_GET_AND_SET_REF
public static final boolean SUPPORTS_GET_AND_SET_REF -
SUPPORTS_GET_AND_ADD_LONG
public static final boolean SUPPORTS_GET_AND_ADD_LONG -
UNSAFE
public static final sun.misc.Unsafe UNSAFE
-
-
Constructor Details
-
UnsafeAccess
public UnsafeAccess()
-
-
Method Details
-
getUnsafe
private static sun.misc.Unsafe getUnsafe() -
hasGetAndSetSupport
private static boolean hasGetAndSetSupport() -
hasGetAndAddLongSupport
private static boolean hasGetAndAddLongSupport() -
fieldOffset
- Throws:
RuntimeException
-