Search in sources :

Example 46 with Unsafe

use of sun.misc.Unsafe in project caffeine by ben-manes.

the class UnsafeAccess method load.

static Unsafe load(String openJdk, String android) throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    Field field;
    try {
        // try OpenJDK field name
        field = Unsafe.class.getDeclaredField(openJdk);
    } catch (NoSuchFieldException e) {
        try {
            // try Android field name
            field = Unsafe.class.getDeclaredField(android);
        } catch (NoSuchFieldException e2) {
            // try to create a new instance
            Constructor<Unsafe> unsafeConstructor = Unsafe.class.getDeclaredConstructor();
            unsafeConstructor.setAccessible(true);
            return unsafeConstructor.newInstance();
        }
    }
    field.setAccessible(true);
    return (Unsafe) field.get(null);
}
Also used : Field(java.lang.reflect.Field) Unsafe(sun.misc.Unsafe)

Example 47 with Unsafe

use of sun.misc.Unsafe in project es6draft by anba.

the class UnsafeHolder method initializeUnsafe.

private static Unsafe initializeUnsafe() {
    try {
        return Unsafe.getUnsafe();
    } catch (SecurityException e) {
        try {
            return AccessController.doPrivileged((PrivilegedExceptionAction<Unsafe>) () -> {
                Field f = Unsafe.class.getDeclaredField("theUnsafe");
                f.setAccessible(true);
                return (Unsafe) f.get(null);
            });
        } catch (PrivilegedActionException e2) {
            throw new ExceptionInInitializerError(e2.getException());
        }
    }
}
Also used : Field(java.lang.reflect.Field) PrivilegedActionException(java.security.PrivilegedActionException) Unsafe(sun.misc.Unsafe) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction)

Example 48 with Unsafe

use of sun.misc.Unsafe in project es6draft by anba.

the class UnsafeHolder method initializeUnsafe.

private static Unsafe initializeUnsafe() {
    try {
        return Unsafe.getUnsafe();
    } catch (SecurityException e) {
        try {
            return AccessController.doPrivileged((PrivilegedExceptionAction<Unsafe>) () -> {
                Field f = Unsafe.class.getDeclaredField("theUnsafe");
                f.setAccessible(true);
                return (Unsafe) f.get(null);
            });
        } catch (PrivilegedActionException e2) {
            throw new ExceptionInInitializerError(e2.getException());
        }
    }
}
Also used : Field(java.lang.reflect.Field) PrivilegedActionException(java.security.PrivilegedActionException) Unsafe(sun.misc.Unsafe) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction)

Example 49 with Unsafe

use of sun.misc.Unsafe in project hadoop by apache.

the class NativeIO method getOperatingSystemPageSize.

/**
   * @return the operating system's page size.
   */
static long getOperatingSystemPageSize() {
    try {
        Field f = Unsafe.class.getDeclaredField("theUnsafe");
        f.setAccessible(true);
        Unsafe unsafe = (Unsafe) f.get(null);
        return unsafe.pageSize();
    } catch (Throwable e) {
        LOG.warn("Unable to get operating system page size.  Guessing 4096.", e);
        return 4096;
    }
}
Also used : Field(java.lang.reflect.Field) Unsafe(sun.misc.Unsafe)

Example 50 with Unsafe

use of sun.misc.Unsafe in project wildfly by wildfly.

the class FastConcurrentDirectDeque method getUnsafe0.

private static Unsafe getUnsafe0() {
    try {
        Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
        theUnsafe.setAccessible(true);
        return (Unsafe) theUnsafe.get(null);
    } catch (Throwable t) {
        throw new RuntimeException("JDK did not allow accessing unsafe", t);
    }
}
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