Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

gnu.classpath
Class Unsafe  view Unsafe download Unsafe.java

java.lang.Object
  extended bygnu.classpath.Unsafe

public final class Unsafe
extends java.lang.Object

This class should provide access to low-level operations and its use should be limited to trusted code. Fields can be accessed using memory addresses, with undefined behaviour occurring if invalid memory addresses are given.


Field Summary
private static Unsafe unsafe
           
 
Constructor Summary
private Unsafe()
          Private default constructor to prevent creation of an arbitrary number of instances.
 
Method Summary
 int arrayBaseOffset(java.lang.Class arrayClass)
          Returns the offset of the first element for a given array class.
 int arrayIndexScale(java.lang.Class arrayClass)
          Returns the scale factor used for addressing elements of the supplied array class.
 boolean compareAndSwapInt(java.lang.Object obj, long offset, int expect, int update)
          Compares the value of the integer field at the specified offset in the supplied object with the given expected value, and updates it if they match.
 boolean compareAndSwapLong(java.lang.Object obj, long offset, long expect, long update)
          Compares the value of the long field at the specified offset in the supplied object with the given expected value, and updates it if they match.
 boolean compareAndSwapObject(java.lang.Object obj, long offset, java.lang.Object expect, java.lang.Object update)
          Compares the value of the object field at the specified offset in the supplied object with the given expected value, and updates it if they match.
 int getIntVolatile(java.lang.Object obj, long offset)
          Retrieves the value of the integer field at the specified offset in the supplied object with volatile load semantics.
 long getLong(java.lang.Object obj, long offset)
          Retrieves the value of the long field at the specified offset in the supplied object.
 long getLongVolatile(java.lang.Object obj, long offset)
          Retrieves the value of the long field at the specified offset in the supplied object with volatile load semantics.
 java.lang.Object getObjectVolatile(java.lang.Object obj, long offset)
          Retrieves the value of the object field at the specified offset in the supplied object with volatile load semantics.
static Unsafe getUnsafe()
          Retrieve the singleton instance of Unsafe.
 long objectFieldOffset(java.lang.reflect.Field field)
          Returns the memory address offset of the given static field.
 void park(boolean isAbsolute, long time)
          Blocks the thread until a matching unpark occurs, the thread is interrupted or the optional timeout expires.
 void putIntVolatile(java.lang.Object obj, long offset, int value)
          Sets the value of the integer field at the specified offset in the supplied object to the given value, with volatile store semantics.
 void putLong(java.lang.Object obj, long offset, long value)
          Sets the value of the long field at the specified offset in the supplied object to the given value.
 void putLongVolatile(java.lang.Object obj, long offset, long value)
          Sets the value of the long field at the specified offset in the supplied object to the given value, with volatile store semantics.
 void putObject(java.lang.Object obj, long offset, java.lang.Object value)
          Sets the value of the object field at the specified offset in the supplied object to the given value.
 void putObjectVolatile(java.lang.Object obj, long offset, java.lang.Object value)
          Sets the value of the object field at the specified offset in the supplied object to the given value, with volatile store semantics.
 void putOrderedInt(java.lang.Object obj, long offset, int value)
          Sets the value of the integer field at the specified offset in the supplied object to the given value.
 void putOrderedLong(java.lang.Object obj, long offset, long value)
          Sets the value of the long field at the specified offset in the supplied object to the given value.
 void putOrderedObject(java.lang.Object obj, long offset, java.lang.Object value)
          Sets the value of the object field at the specified offset in the supplied object to the given value.
 void unpark(java.lang.Thread thread)
          Releases the block on a thread created by park.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

unsafe

private static Unsafe unsafe
Constructor Detail

Unsafe

private Unsafe()
Private default constructor to prevent creation of an arbitrary number of instances.

Method Detail

getUnsafe

public static Unsafe getUnsafe()
Retrieve the singleton instance of Unsafe. The calling method should guard this instance from untrusted code, as it provides access to low-level operations such as direct memory access.


objectFieldOffset

public long objectFieldOffset(java.lang.reflect.Field field)
Returns the memory address offset of the given static field. The offset is merely used as a means to access a particular field in the other methods of this class. The value is unique to the given field and the same value should be returned on each subsequent call.


compareAndSwapInt

public boolean compareAndSwapInt(java.lang.Object obj,
                                 long offset,
                                 int expect,
                                 int update)
Compares the value of the integer field at the specified offset in the supplied object with the given expected value, and updates it if they match. The operation of this method should be atomic, thus providing an uninterruptible way of updating an integer field.


compareAndSwapLong

public boolean compareAndSwapLong(java.lang.Object obj,
                                  long offset,
                                  long expect,
                                  long update)
Compares the value of the long field at the specified offset in the supplied object with the given expected value, and updates it if they match. The operation of this method should be atomic, thus providing an uninterruptible way of updating a long field.


compareAndSwapObject

public boolean compareAndSwapObject(java.lang.Object obj,
                                    long offset,
                                    java.lang.Object expect,
                                    java.lang.Object update)
Compares the value of the object field at the specified offset in the supplied object with the given expected value, and updates it if they match. The operation of this method should be atomic, thus providing an uninterruptible way of updating an object field.


putOrderedInt

public void putOrderedInt(java.lang.Object obj,
                          long offset,
                          int value)
Sets the value of the integer field at the specified offset in the supplied object to the given value. This is an ordered or lazy version of putIntVolatile(Object,long,int), which doesn't guarantee the immediate visibility of the change to other threads. It is only really useful where the integer field is volatile, and is thus expected to change unexpectedly.


putOrderedLong

public void putOrderedLong(java.lang.Object obj,
                           long offset,
                           long value)
Sets the value of the long field at the specified offset in the supplied object to the given value. This is an ordered or lazy version of putLongVolatile(Object,long,long), which doesn't guarantee the immediate visibility of the change to other threads. It is only really useful where the long field is volatile, and is thus expected to change unexpectedly.


putOrderedObject

public void putOrderedObject(java.lang.Object obj,
                             long offset,
                             java.lang.Object value)
Sets the value of the object field at the specified offset in the supplied object to the given value. This is an ordered or lazy version of putObjectVolatile(Object,long,Object), which doesn't guarantee the immediate visibility of the change to other threads. It is only really useful where the object field is volatile, and is thus expected to change unexpectedly.


putIntVolatile

public void putIntVolatile(java.lang.Object obj,
                           long offset,
                           int value)
Sets the value of the integer field at the specified offset in the supplied object to the given value, with volatile store semantics.


getIntVolatile

public int getIntVolatile(java.lang.Object obj,
                          long offset)
Retrieves the value of the integer field at the specified offset in the supplied object with volatile load semantics.


putLongVolatile

public void putLongVolatile(java.lang.Object obj,
                            long offset,
                            long value)
Sets the value of the long field at the specified offset in the supplied object to the given value, with volatile store semantics.


putLong

public void putLong(java.lang.Object obj,
                    long offset,
                    long value)
Sets the value of the long field at the specified offset in the supplied object to the given value.


getLongVolatile

public long getLongVolatile(java.lang.Object obj,
                            long offset)
Retrieves the value of the long field at the specified offset in the supplied object with volatile load semantics.


getLong

public long getLong(java.lang.Object obj,
                    long offset)
Retrieves the value of the long field at the specified offset in the supplied object.


putObjectVolatile

public void putObjectVolatile(java.lang.Object obj,
                              long offset,
                              java.lang.Object value)
Sets the value of the object field at the specified offset in the supplied object to the given value, with volatile store semantics.


putObject

public void putObject(java.lang.Object obj,
                      long offset,
                      java.lang.Object value)
Sets the value of the object field at the specified offset in the supplied object to the given value.


getObjectVolatile

public java.lang.Object getObjectVolatile(java.lang.Object obj,
                                          long offset)
Retrieves the value of the object field at the specified offset in the supplied object with volatile load semantics.


arrayBaseOffset

public int arrayBaseOffset(java.lang.Class arrayClass)
Returns the offset of the first element for a given array class. To access elements of the array class, this value may be used along with that returned by arrayIndexScale, if non-zero.


arrayIndexScale

public int arrayIndexScale(java.lang.Class arrayClass)
Returns the scale factor used for addressing elements of the supplied array class. Where a suitable scale factor can not be returned (e.g. for primitive types), zero should be returned. The returned value can be used with arrayBaseOffset to access elements of the class.


unpark

public void unpark(java.lang.Thread thread)
Releases the block on a thread created by park. This method can also be used to terminate a blockage caused by a prior call to park. This operation is unsafe, as the thread must be guaranteed to be live. This is true of Java, but not native code.


park

public void park(boolean isAbsolute,
                 long time)
Blocks the thread until a matching unpark occurs, the thread is interrupted or the optional timeout expires. If an unpark call has already occurred, this also counts. A timeout value of zero is defined as no timeout. When isAbsolute is true, the timeout is in milliseconds relative to the epoch. Otherwise, the value is the number of nanoseconds which must occur before timeout. This call may also return spuriously (i.e. for no apparent reason).