use of sun.misc.Unsafe in project h2o-3 by h2oai.
the class UtilUnsafe method getUnsafe.
/** Fetch the Unsafe. Use With Caution. */
public static Unsafe getUnsafe() {
// Not on bootclasspath
if (UtilUnsafe.class.getClassLoader() == null)
return Unsafe.getUnsafe();
try {
final Field fld = Unsafe.class.getDeclaredField("theUnsafe");
fld.setAccessible(true);
return (Unsafe) fld.get(UtilUnsafe.class);
} catch (Exception e) {
throw new RuntimeException("Could not obtain access to sun.misc.Unsafe", e);
}
}
use of sun.misc.Unsafe in project hazelcast by hazelcast.
the class UnsafeHelper method findUnsafe.
private static Unsafe findUnsafe() {
try {
return Unsafe.getUnsafe();
} catch (SecurityException se) {
return AccessController.doPrivileged(new PrivilegedAction<Unsafe>() {
@Override
public Unsafe run() {
try {
Class<Unsafe> type = Unsafe.class;
try {
Field field = type.getDeclaredField("theUnsafe");
field.setAccessible(true);
return type.cast(field.get(type));
} catch (Exception e) {
for (Field field : type.getDeclaredFields()) {
if (type.isAssignableFrom(field.getType())) {
field.setAccessible(true);
return type.cast(field.get(type));
}
}
}
} catch (Exception e) {
throw new RuntimeException("Unsafe unavailable", e);
}
throw new RuntimeException("Unsafe unavailable");
}
});
}
}
use of sun.misc.Unsafe in project pjson by gerritjvv.
the class StringUtil method loadUnsafe.
private static Unsafe loadUnsafe() {
try {
Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
unsafeField.setAccessible(true);
return (Unsafe) unsafeField.get(null);
} catch (NoSuchFieldException e) {
return null;
} catch (IllegalAccessException e) {
return null;
}
}
use of sun.misc.Unsafe in project jdk8u_jdk by JetBrains.
the class VMAnonymousClass method getUnsafe.
private static synchronized Unsafe getUnsafe() {
try {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return (Unsafe) f.get(null);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException("Unable to get Unsafe instance.", e);
}
}
use of sun.misc.Unsafe in project jdk8u_jdk by JetBrains.
the class CopyMemory method main.
public static void main(String[] args) throws Exception {
Unsafe unsafe = getUnsafe();
testSetByteArray(unsafe);
testSetRawMemory(unsafe);
testCopyByteArrayToByteArray(unsafe);
testCopyByteArrayToRawMemory(unsafe);
testCopyRawMemoryToByteArray(unsafe);
testCopyRawMemoryToRawMemory(unsafe);
System.out.println("OK");
}
Aggregations