| java.lang.Object sun.misc.Unsafe
Unsafe | public class Unsafe (Code) | | The Unsafe service.
|
Method Summary | |
public int | arrayBaseOffset(Class> clazz)
Retrieves the base offset for the array Class given. | public int | arrayIndexScale(Class> clazz)
Retrieves the array index scale for the array Class given. | public boolean | compareAndSwapInt(Object object, long fieldOffset, int expected, int update)
Compares and swaps the value of an int-typed field on an Object instance.
Parameters: object - The instance containing the field. Parameters: fieldOffset - The offset value of the field. Parameters: expected - The expected value of the field. Parameters: update - The new value to write to the field. | public boolean | compareAndSwapLong(Object object, long fieldOffset, long expected, long update)
Compares and swaps the value of a long-typed field on an Object instance.
Parameters: object - The instance containing the field. Parameters: fieldOffset - The offset value of the field. Parameters: expected - The expected value of the field. Parameters: update - The new value to write to the field. | public boolean | compareAndSwapObject(Object object, long fieldOffset, Object expected, Object update)
Compares and swaps the value of an Object-typed field on an Object
instance.
Parameters: object - The instance containing the field. Parameters: fieldOffset - The offset value of the field. Parameters: expected - The expected value of the field. Parameters: update - The new value to write to the field. | public int | getIntVolatile(Object object, long fieldOffset)
Reads an int value from an Object's field as though it were declared
volatile .
Parameters: object - The instance containing the field to read from. Parameters: fieldOffset - The offset of the field to read from. | public long | getLong(Object object, long fieldOffset)
Reads a long value from an Object's field.
Parameters: object - The instance containing the field to read from. Parameters: fieldOffset - The offset of the field to read from. | public long | getLongVolatile(Object object, long fieldOffset)
Reads a long value from an Object's field as though it were declared
volatile .
Parameters: object - The instance containing the field to read from. Parameters: fieldOffset - The offset of the field to read from. | public Object | getObjectVolatile(Object object, long fieldOffset)
Writes an int value to an Object's field as though it were declared
volatile . | public static Unsafe | getUnsafe()
Retrieves an instance of this service. | public long | objectFieldOffset(Field field)
Retrieves the offset value of the
Field for use by other methods
in this class.
Parameters: field - The Field to retrieve the offset for. | public void | park(boolean timestamp, long nanosOrTimestamp)
Parks the
Thread.currentThread current thread either for a set
number of nanoseconds or until a future point in time.
Parameters: timestamp - If true nanosOrTimestamp should be consider as a timestamp based onSystem.currentTimeMillis. | public void | putIntVolatile(Object object, long fieldOffset, int newValue)
Writes an int value to an Object's field as though it were declared
volatile . | public void | putLong(Object object, long fieldOffset, long newValue)
Writes a long value to an Object's field. | public void | putLongVolatile(Object object, long fieldOffset, long newValue)
Writes a long value to an Object's field as though it were declared
volatile . | public void | putObjectVolatile(Object object, long fieldOffset, Object newValue)
Writes an Object reference value to an Object's field as though it were
declared volatile . | public void | unpark(Thread thread)
Unparks the
Thread that's passed. |
arrayBaseOffset | public int arrayBaseOffset(Class> clazz)(Code) | |
Retrieves the base offset for the array Class given. The Class passed
MUST me any array type, such that the method
Class.isArray returns true . For example, int[].class .
Parameters: clazz - The array Class object. The base offset value. |
arrayIndexScale | public int arrayIndexScale(Class> clazz)(Code) | |
Retrieves the array index scale for the array Class given. The index
scale is the value used to determine the offset of a particular element
in the array given the array's base offset and an index. The following
code snippet illustrates the usage.
int base = unsafe.arrayBaseOffset(int[].class);
int scale = unsafe.arrayIndexScale(int[].class);
int elementIdx = 1;
int[] array = { 0, 1, 2 };
long offsetForIdx = base + (elementIdx * scale);
The Class passed MUST me any array type, such that the method
Class.isArray returns true . For example,
int[].class .
Parameters: clazz - The array Class object. The index scale value. |
compareAndSwapInt | public boolean compareAndSwapInt(Object object, long fieldOffset, int expected, int update)(Code) | |
Compares and swaps the value of an int-typed field on an Object instance.
Parameters: object - The instance containing the field. Parameters: fieldOffset - The offset value of the field. Parameters: expected - The expected value of the field. Parameters: update - The new value to write to the field. true if the field was updated, false otherwise. |
compareAndSwapLong | public boolean compareAndSwapLong(Object object, long fieldOffset, long expected, long update)(Code) | |
Compares and swaps the value of a long-typed field on an Object instance.
Parameters: object - The instance containing the field. Parameters: fieldOffset - The offset value of the field. Parameters: expected - The expected value of the field. Parameters: update - The new value to write to the field. true if the field was updated, false otherwise. |
compareAndSwapObject | public boolean compareAndSwapObject(Object object, long fieldOffset, Object expected, Object update)(Code) | |
Compares and swaps the value of an Object-typed field on an Object
instance.
Parameters: object - The instance containing the field. Parameters: fieldOffset - The offset value of the field. Parameters: expected - The expected value of the field. Parameters: update - The new value to write to the field. true if the field was updated, false otherwise. |
getIntVolatile | public int getIntVolatile(Object object, long fieldOffset)(Code) | |
Reads an int value from an Object's field as though it were declared
volatile .
Parameters: object - The instance containing the field to read from. Parameters: fieldOffset - The offset of the field to read from. The value that was read. |
getLong | public long getLong(Object object, long fieldOffset)(Code) | |
Reads a long value from an Object's field.
Parameters: object - The instance containing the field to read from. Parameters: fieldOffset - The offset of the field to read from. The value that was read. |
getLongVolatile | public long getLongVolatile(Object object, long fieldOffset)(Code) | |
Reads a long value from an Object's field as though it were declared
volatile .
Parameters: object - The instance containing the field to read from. Parameters: fieldOffset - The offset of the field to read from. The value that was read. |
getObjectVolatile | public Object getObjectVolatile(Object object, long fieldOffset)(Code) | |
Writes an int value to an Object's field as though it were declared
volatile .
Parameters: object - The instance containing the field to write to. Parameters: fieldOffset - The offset of the field to write to. Parameters: newValue - The value to write. |
getUnsafe | public static Unsafe getUnsafe()(Code) | |
Retrieves an instance of this service.
An instance of Unsafe. |
objectFieldOffset | public long objectFieldOffset(Field field)(Code) | |
Retrieves the offset value of the
Field for use by other methods
in this class.
Parameters: field - The Field to retrieve the offset for. The offset value. |
park | public void park(boolean timestamp, long nanosOrTimestamp)(Code) | |
Parks the
Thread.currentThread current thread either for a set
number of nanoseconds or until a future point in time.
Parameters: timestamp - If true nanosOrTimestamp should be consider as a timestamp based onSystem.currentTimeMillis. If false ,then nanosOrTimestamp should be considered as arelative number of nanoseconds from when this method was called;the value 0L can be used in conjunction with thisto indicate that time is not a factor when parking the thread. Parameters: nanosOrTimestamp - Either a relative number of nanoseconds or atimestamp in milliseconds as defined bySystem.currentTimeMillis. |
putIntVolatile | public void putIntVolatile(Object object, long fieldOffset, int newValue)(Code) | |
Writes an int value to an Object's field as though it were declared
volatile .
Parameters: object - The instance containing the field to write to. Parameters: fieldOffset - The offset of the field to write to. Parameters: newValue - The value to write. |
putLong | public void putLong(Object object, long fieldOffset, long newValue)(Code) | |
Writes a long value to an Object's field.
Parameters: object - The instance containing the field to write to. Parameters: fieldOffset - The offset of the field to write to. Parameters: newValue - The value to write. |
putLongVolatile | public void putLongVolatile(Object object, long fieldOffset, long newValue)(Code) | |
Writes a long value to an Object's field as though it were declared
volatile .
Parameters: object - The instance containing the field to write to. Parameters: fieldOffset - The offset of the field to write to. Parameters: newValue - The value to write. |
putObjectVolatile | public void putObjectVolatile(Object object, long fieldOffset, Object newValue)(Code) | |
Writes an Object reference value to an Object's field as though it were
declared volatile .
Parameters: object - The instance containing the field to write to. Parameters: fieldOffset - The offset of the field to write to. Parameters: newValue - The value to write. |
unpark | public void unpark(Thread thread)(Code) | |
Unparks the
Thread that's passed.
Parameters: thread - The Thread to unpark. |
|
|