aa
com.cliffc.aa.util.UtilUnsafe Class Reference

Simple class to obtain access to the Unsafe object. More...

Collaboration diagram for com.cliffc.aa.util.UtilUnsafe:
[legend]

Static Public Member Functions

static Unsafe getUnsafe ()
 Fetch the Unsafe. More...
 

Static Package Functions

static final long fieldOffset (Class clz, String field)
 

Static Package Attributes

static final Unsafe UNSAFE = getUnsafe()
 

Private Member Functions

 UtilUnsafe ()
 

Detailed Description

Simple class to obtain access to the Unsafe object.

Unsafe is required to allow efficient CAS operations on arrays. Note that the versions in java.util.concurrent.atomic, such as {}, require extra memory ordering guarantees which are generally not needed in these algorithms and are also expensive on most processors.

Definition at line 15 of file UtilUnsafe.java.

Constructor & Destructor Documentation

◆ UtilUnsafe()

com.cliffc.aa.util.UtilUnsafe.UtilUnsafe ( )
private

Definition at line 16 of file UtilUnsafe.java.

16 { } // dummy private constructor

Member Function Documentation

◆ fieldOffset()

static final long com.cliffc.aa.util.UtilUnsafe.fieldOffset ( Class  clz,
String  field 
)
staticpackage

Definition at line 32 of file UtilUnsafe.java.

32  {
33  Field f = null;
34  try { f = clz.getDeclaredField(field); }
35  catch( java.lang.NoSuchFieldException e ) { throw new RuntimeException(e); }
36  return UNSAFE.objectFieldOffset(f);
37  }

References com.cliffc.aa.util.UtilUnsafe.UNSAFE.

◆ getUnsafe()

static Unsafe com.cliffc.aa.util.UtilUnsafe.getUnsafe ( )
static

Fetch the Unsafe.

Use With Caution.

Definition at line 19 of file UtilUnsafe.java.

19  {
20  // Not on bootclasspath
21  if( UtilUnsafe.class.getClassLoader() == null )
22  return Unsafe.getUnsafe();
23  try {
24  final Field fld = Unsafe.class.getDeclaredField("theUnsafe");
25  fld.setAccessible(true);
26  return (Unsafe) fld.get(UtilUnsafe.class);
27  } catch (Exception e) {
28  throw new RuntimeException("Could not obtain access to sun.misc.Unsafe", e);
29  }
30  }

Member Data Documentation

◆ UNSAFE

final Unsafe com.cliffc.aa.util.UtilUnsafe.UNSAFE = getUnsafe()
staticpackage

Definition at line 17 of file UtilUnsafe.java.

Referenced by com.cliffc.aa.util.UtilUnsafe.fieldOffset().


The documentation for this class was generated from the following file:
com.cliffc.aa.util.UtilUnsafe.UNSAFE
static final Unsafe UNSAFE
Definition: UtilUnsafe.java:17
com.cliffc.aa.util.UtilUnsafe.UtilUnsafe
UtilUnsafe()
Definition: UtilUnsafe.java:16