Search in sources :

Example 66 with Unsafe

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);
}
Also used : Field(java.lang.reflect.Field) Unsafe(sun.misc.Unsafe)

Example 67 with Unsafe

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);
    }
}
Also used : Field(java.lang.reflect.Field) Unsafe(sun.misc.Unsafe) NotNull(org.jetbrains.annotations.NotNull)

Example 68 with Unsafe

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();
}
Also used : Unsafe(sun.misc.Unsafe)

Example 69 with Unsafe

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);
    }
}
Also used : Field(java.lang.reflect.Field) Unsafe(sun.misc.Unsafe)

Example 70 with Unsafe

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());
        }
    }
}
Also used : Field(java.lang.reflect.Field) Unsafe(sun.misc.Unsafe)

Aggregations

Unsafe (sun.misc.Unsafe)90 Field (java.lang.reflect.Field)62 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)7 Test (org.testng.annotations.Test)7 PrivilegedActionException (java.security.PrivilegedActionException)5 PrivilegedAction (java.security.PrivilegedAction)4 IOException (java.io.IOException)3 JavaKind (jdk.vm.ci.meta.JavaKind)3 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)3 ValueNode (org.graalvm.compiler.nodes.ValueNode)3 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)3 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)3 Test (org.junit.Test)3 LazyArrayIntTags (edu.columbia.cs.psl.phosphor.struct.LazyArrayIntTags)2 LazyArrayObjTags (edu.columbia.cs.psl.phosphor.struct.LazyArrayObjTags)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)2 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)2 FrameSlotTypeException (com.oracle.truffle.api.frame.FrameSlotTypeException)1 DataSize (io.airlift.units.DataSize)1