aa
UtilUnsafe.java
Go to the documentation of this file.
1 package com.cliffc.aa.util;
2 
3 import java.lang.reflect.Field;
4 
5 import sun.misc.Unsafe;
6 
15 public class UtilUnsafe {
16  private UtilUnsafe() { } // dummy private constructor
17  static final Unsafe UNSAFE = getUnsafe();
19  public static Unsafe getUnsafe() {
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  }
31 
32  static final long fieldOffset( Class clz, String field ) {
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  }
38 }
com.cliffc.aa.util.UtilUnsafe.getUnsafe
static Unsafe getUnsafe()
Fetch the Unsafe.
Definition: UtilUnsafe.java:19
com.cliffc.aa.util.UtilUnsafe
Simple class to obtain access to the Unsafe object.
Definition: UtilUnsafe.java:15
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
com.cliffc.aa.util.UtilUnsafe.fieldOffset
static final long fieldOffset(Class clz, String field)
Definition: UtilUnsafe.java:32