Search in sources :

Example 26 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 27 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 28 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)

Example 29 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 30 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)39 Field (java.lang.reflect.Field)29 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)5 PrivilegedActionException (java.security.PrivilegedActionException)4 PrivilegedAction (java.security.PrivilegedAction)2 File (java.io.File)1 Options (org.rocksdb.Options)1 RocksDB (org.rocksdb.RocksDB)1 RocksIterator (org.rocksdb.RocksIterator)1 StringAppendOperator (org.rocksdb.StringAppendOperator)1 WriteOptions (org.rocksdb.WriteOptions)1