2011-11-21 17:49:21 +01:00
|
|
|
/**
|
2012-01-19 18:21:06 +01:00
|
|
|
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
|
2011-11-21 17:49:21 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package akka.util;
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
|
|
|
|
|
public final class Unsafe {
|
|
|
|
|
public final static sun.misc.Unsafe instance;
|
|
|
|
|
static {
|
|
|
|
|
try {
|
2012-01-19 16:35:36 +01:00
|
|
|
sun.misc.Unsafe found = null;
|
|
|
|
|
for(Field field : sun.misc.Unsafe.class.getDeclaredFields()) {
|
|
|
|
|
if (field.getType() == sun.misc.Unsafe.class) {
|
|
|
|
|
field.setAccessible(true);
|
|
|
|
|
found = (sun.misc.Unsafe) field.get(null);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (found == null) throw new IllegalStateException("Can't find instance of sun.misc.Unsafe");
|
|
|
|
|
else instance = found;
|
2011-11-21 17:49:21 +01:00
|
|
|
} catch(Throwable t) {
|
|
|
|
|
throw new ExceptionInInitializerError(t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|