use of sun.misc.Unsafe in project SkyBot by duncte123.
the class StringInInt method main.
public static void main(String[] args) throws Throwable {
Constructor<Unsafe> c = Unsafe.class.getDeclaredConstructor();
c.setAccessible(true);
Unsafe u = c.newInstance();
Field field = StringInInt.class.getDeclaredField("integer");
Object b = u.staticFieldBase(field);
long o = u.staticFieldOffset(field);
u.putObject(b, o, "this is a string");
// String s = (String)(Object)integer;
System.out.println(integer);
}
use of sun.misc.Unsafe in project Chronicle-Core by OpenHFT.
the class UnsafePingPointMain method getUnsafe.
@NotNull
public static Unsafe getUnsafe() {
try {
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
theUnsafe.setAccessible(true);
return (Unsafe) theUnsafe.get(null);
} catch (@NotNull NoSuchFieldException | IllegalAccessException e) {
throw new AssertionError(e);
}
}
use of sun.misc.Unsafe in project openj9 by eclipse.
the class Class method acquireReflectCache.
private ReflectCache acquireReflectCache() {
ReflectCache cache = reflectCache;
if (cache == null) {
Unsafe theUnsafe = getUnsafe();
long cacheOffset = getReflectCacheOffset();
ReflectCache newCache = new ReflectCache(this);
do {
/*[IF Sidecar19-SE-OpenJ9]*/
if (theUnsafe.compareAndSetObject(this, cacheOffset, null, newCache)) {
/*[ELSE]
if (theUnsafe.compareAndSwapObject(this, cacheOffset, null, newCache)) {
/*[ENDIF]*/
cache = newCache;
break;
}
cache = (ReflectCache) theUnsafe.getObject(this, cacheOffset);
} while (cache == null);
}
return cache.acquire();
}
use of sun.misc.Unsafe in project quasar by puniverse.
the class UtilUnsafe method getUnsafe1.
public static Unsafe getUnsafe1() {
// Not on bootclasspath
if (UtilUnsafe.class.getClassLoader() == null)
return Unsafe.getUnsafe();
try {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return (Unsafe) f.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 quasar by puniverse.
the class UtilUnsafe method getUnsafe.
public static Unsafe getUnsafe() {
try {
return Unsafe.getUnsafe();
} catch (SecurityException se) {
try {
return java.security.AccessController.doPrivileged(new java.security.PrivilegedExceptionAction<Unsafe>() {
@Override
public Unsafe run() throws Exception {
final Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
if (true) {
final Field f = k.getDeclaredField("theUnsafe");
f.setAccessible(true);
final Object x = f.get(null);
return k.cast(x);
} else {
for (Field f : k.getDeclaredFields()) {
f.setAccessible(true);
final Object x = f.get(null);
if (k.isInstance(x))
return k.cast(x);
}
throw new NoSuchFieldError("the Unsafe");
}
}
});
} catch (java.security.PrivilegedActionException e) {
throw new RuntimeException("Could not initialize intrinsics", e.getCause());
}
}
}
Aggregations