Package rx.internal.util.unsafe
Class UnsafeAccess
java.lang.Object
rx.internal.util.unsafe.UnsafeAccess
All use of this class MUST first check that UnsafeAccess.isUnsafeAvailable() == true
otherwise NPEs will happen in environments without "suc.misc.Unsafe" such as Android.
Note that you can force RxJava to not use Unsafe API by setting any value to System Property
rx.unsafe-disable
.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final boolean
static final sun.misc.Unsafe
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic long
Returns the address of the specific field on the class and wraps a NoSuchFieldException into an internal error.static boolean
compareAndSwapInt
(Object obj, long offset, int expected, int newValue) static int
getAndAddInt
(Object obj, long offset, int n) static int
getAndIncrementInt
(Object obj, long offset) static int
getAndSetInt
(Object obj, long offset, int newValue) static boolean
-
Field Details
-
UNSAFE
public static final sun.misc.Unsafe UNSAFE -
DISABLED_BY_USER
private static final boolean DISABLED_BY_USER
-
-
Constructor Details
-
UnsafeAccess
private UnsafeAccess()
-
-
Method Details
-
isUnsafeAvailable
public static boolean isUnsafeAvailable() -
getAndIncrementInt
-
getAndAddInt
-
getAndSetInt
-
compareAndSwapInt
-
addressOf
Returns the address of the specific field on the class and wraps a NoSuchFieldException into an internal error.One can avoid using static initializers this way and just assign the address directly to the target static field.
- Parameters:
clazz
- the target classfieldName
- the target field name- Returns:
- the address (offset) of the field
-