Top Description Fields Constructors Methods
rx.internal.util.unsafe

public final Class UnsafeAccess

extends Object
Class Inheritance
Annotations
@SuppressAnimalSniffer
Imports
java.lang.reflect.Field, rx.internal.util.SuppressAnimalSniffer, sun.misc.Unsafe

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

Modifier and TypeField and Description
private static final boolean
public static final Unsafe

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static long

Returns:

the address (offset) of the field
addressOf
(Class<?>
the target class
clazz
,
String
the target field name
fieldName
)

Returns the address of the specific field on the class and wraps a NoSuchFieldException into an internal error.

public static boolean
compareAndSwapInt(Object obj, long offset, int expected, int newValue)

public static int
getAndAddInt(Object obj, long offset, int n)

public static int
getAndIncrementInt(Object obj, long offset)

public static int
getAndSetInt(Object obj, long offset, int newValue)

public static boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DISABLED_BY_USERback to summary
private static final boolean DISABLED_BY_USER
UNSAFEback to summary
public static final Unsafe UNSAFE

Constructor Detail

UnsafeAccessback to summary
private UnsafeAccess()

Method Detail

addressOfback to summary
public static long addressOf(Class<?> clazz, String fieldName)

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:Class<?>

the target class

fieldName:String

the target field name

Returns:long

the address (offset) of the field

compareAndSwapIntback to summary
public static boolean compareAndSwapInt(Object obj, long offset, int expected, int newValue)
getAndAddIntback to summary
public static int getAndAddInt(Object obj, long offset, int n)
getAndIncrementIntback to summary
public static int getAndIncrementInt(Object obj, long offset)
getAndSetIntback to summary
public static int getAndSetInt(Object obj, long offset, int newValue)
isUnsafeAvailableback to summary
public static boolean isUnsafeAvailable()