sun.misc.Unsafe.getUnsafe()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中sun.misc.Unsafe.getUnsafe()方法的一些代码示例,展示了Unsafe.getUnsafe()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Unsafe.getUnsafe()方法的具体详情如下:
包路径:sun.misc.Unsafe
类名称:Unsafe
方法名:getUnsafe

Unsafe.getUnsafe介绍

[英]Gets the unique instance of this class. This is only allowed in very limited situations.
[中]获取该类的唯一实例。只有在非常有限的情况下才允许这样做。

代码示例

代码示例来源:origin: google/guava

/**
  * Returns a sun.misc.Unsafe. Suitable for use in a 3rd party package. Replace with a simple call
  * to Unsafe.getUnsafe when integrating into a jdk.
  *
  * @return a sun.misc.Unsafe
  */
 private static sun.misc.Unsafe getUnsafe() {
  try {
   return sun.misc.Unsafe.getUnsafe();
  } catch (SecurityException tryReflectionInstead) {
  }
  try {
   return java.security.AccessController.doPrivileged(
     new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
      public sun.misc.Unsafe run() throws Exception {
       Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
       for (java.lang.reflect.Field f : k.getDeclaredFields()) {
        f.setAccessible(true);
        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());
  }
 }
}

代码示例来源:origin: alibaba/Sentinel

private static sun.misc.Unsafe doGetUnsafe() {
  try {
    return sun.misc.Unsafe.getUnsafe();
  } catch (Throwable tryReflectionInstead) {
      .doPrivileged(new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
        @Override
        public sun.misc.Unsafe run() throws Exception {

代码示例来源:origin: google/guava

/**
  * Returns a sun.misc.Unsafe. Suitable for use in a 3rd party package. Replace with a simple call
  * to Unsafe.getUnsafe when integrating into a jdk.
  *
  * @return a sun.misc.Unsafe
  */
 private static sun.misc.Unsafe getUnsafe() {
  try {
   return sun.misc.Unsafe.getUnsafe();
  } catch (SecurityException tryReflectionInstead) {
  }
  try {
   return java.security.AccessController.doPrivileged(
     new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
      public sun.misc.Unsafe run() throws Exception {
       Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
       for (java.lang.reflect.Field f : k.getDeclaredFields()) {
        f.setAccessible(true);
        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());
  }
 }
}

代码示例来源:origin: neo4j/neo4j

return Unsafe.getUnsafe();
return AccessController.doPrivileged( getUnsafe );

代码示例来源:origin: google/guava

return sun.misc.Unsafe.getUnsafe();
} catch (SecurityException tryReflectionInstead) {
 return java.security.AccessController.doPrivileged(
   new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
    @Override
 throw new RuntimeException("Could not initialize intrinsics", e.getCause());

代码示例来源:origin: com.github.jnthnclt/os.lab.base

private static Unsafe getUnsafe() {
  try {
    return Unsafe.getUnsafe();
  } catch (SecurityException var2) {
    try {
      return (Unsafe) AccessController.doPrivileged((PrivilegedExceptionAction) () -> {
        Class k = Unsafe.class;
        Field[] arr = k.getDeclaredFields();
        for (Field f : arr) {
          f.setAccessible(true);
          Object x = f.get(null);
          if (k.isInstance(x)) {
            return (Unsafe) k.cast(x);
          }
        }
        return null;
      });
    } catch (PrivilegedActionException var1) {
      return null;
    }
  } catch (Throwable t) {
    return null;
  }
}

代码示例来源:origin: google/guava

return sun.misc.Unsafe.getUnsafe();
} catch (SecurityException e) {
 return java.security.AccessController.doPrivileged(
   new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
    @Override
 throw new RuntimeException("Could not initialize intrinsics", e.getCause());

代码示例来源:origin: prestodb/presto

/**
  * Returns a sun.misc.Unsafe. Suitable for use in a 3rd party package. Replace with a simple call
  * to Unsafe.getUnsafe when integrating into a jdk.
  *
  * @return a sun.misc.Unsafe
  */
 private static sun.misc.Unsafe getUnsafe() {
  try {
   return sun.misc.Unsafe.getUnsafe();
  } catch (SecurityException tryReflectionInstead) {
  }
  try {
   return java.security.AccessController.doPrivileged(
     new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
      public sun.misc.Unsafe run() throws Exception {
       Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
       for (java.lang.reflect.Field f : k.getDeclaredFields()) {
        f.setAccessible(true);
        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());
  }
 }
}

代码示例来源:origin: prestodb/presto

/**
  * Returns a sun.misc.Unsafe. Suitable for use in a 3rd party package. Replace with a simple call
  * to Unsafe.getUnsafe when integrating into a jdk.
  *
  * @return a sun.misc.Unsafe
  */
 private static sun.misc.Unsafe getUnsafe() {
  try {
   return sun.misc.Unsafe.getUnsafe();
  } catch (SecurityException tryReflectionInstead) {
  }
  try {
   return java.security.AccessController.doPrivileged(
     new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
      public sun.misc.Unsafe run() throws Exception {
       Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
       for (java.lang.reflect.Field f : k.getDeclaredFields()) {
        f.setAccessible(true);
        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());
  }
 }
}

代码示例来源:origin: prestodb/presto

return sun.misc.Unsafe.getUnsafe();
} catch (SecurityException e) {
 return java.security.AccessController.doPrivileged(
   new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
    @Override
 throw new RuntimeException("Could not initialize intrinsics", e.getCause());

代码示例来源:origin: prestodb/presto

return sun.misc.Unsafe.getUnsafe();
} catch (SecurityException tryReflectionInstead) {
 return java.security.AccessController.doPrivileged(
   new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
    @Override
 throw new RuntimeException("Could not initialize intrinsics", e.getCause());

代码示例来源:origin: alibaba/Sentinel

/**
 * Returns a sun.misc.Unsafe.  Suitable for use in a 3rd party package.
 * Replace with a simple call to Unsafe.getUnsafe when integrating
 * into a jdk.
 *
 * @return a sun.misc.Unsafe
 */
private static sun.misc.Unsafe getUnsafe() {
  try {
    return sun.misc.Unsafe.getUnsafe();
  } catch (SecurityException se) {
    try {
      return java.security.AccessController.doPrivileged
        (new java.security
          .PrivilegedExceptionAction<sun.misc.Unsafe>() {
          public sun.misc.Unsafe run() throws Exception {
            java.lang.reflect.Field f = sun.misc
              .Unsafe.class.getDeclaredField("theUnsafe");
            f.setAccessible(true);
            return (sun.misc.Unsafe)f.get(null);
          }
        });
    } catch (java.security.PrivilegedActionException e) {
      throw new RuntimeException("Could not initialize intrinsics",
        e.getCause());
    }
  }
}

代码示例来源:origin: google/j2objc

/**
  * Returns a sun.misc.Unsafe. Suitable for use in a 3rd party package. Replace with a simple call
  * to Unsafe.getUnsafe when integrating into a jdk.
  *
  * @return a sun.misc.Unsafe
  */
 private static sun.misc.Unsafe getUnsafe() {
  try {
   return sun.misc.Unsafe.getUnsafe();
  } catch (SecurityException tryReflectionInstead) {
  }
  try {
   return java.security.AccessController.doPrivileged(
     new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
      public sun.misc.Unsafe run() throws Exception {
       Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
       for (java.lang.reflect.Field f : k.getDeclaredFields()) {
        f.setAccessible(true);
        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());
  }
 }
}

代码示例来源:origin: google/j2objc

/**
  * Returns a sun.misc.Unsafe. Suitable for use in a 3rd party package. Replace with a simple call
  * to Unsafe.getUnsafe when integrating into a jdk.
  *
  * @return a sun.misc.Unsafe
  */
 private static sun.misc.Unsafe getUnsafe() {
  try {
   return sun.misc.Unsafe.getUnsafe();
  } catch (SecurityException tryReflectionInstead) {
  }
  try {
   return java.security.AccessController.doPrivileged(
     new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
      public sun.misc.Unsafe run() throws Exception {
       Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
       for (java.lang.reflect.Field f : k.getDeclaredFields()) {
        f.setAccessible(true);
        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());
  }
 }
}

代码示例来源:origin: springside/springside4

/**
   * Returns a sun.misc.Unsafe.  Suitable for use in a 3rd party package.
   * Replace with a simple call to Unsafe.getUnsafe when integrating
   * into a jdk.
   *
   * @return a sun.misc.Unsafe
   */
  private static sun.misc.Unsafe getUnsafe() {
    try {
      return sun.misc.Unsafe.getUnsafe();
    } catch (SecurityException tryReflectionInstead) {}
    try {
      return java.security.AccessController.doPrivileged
      (new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
        public sun.misc.Unsafe run() throws Exception {
          Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
          for (java.lang.reflect.Field f : k.getDeclaredFields()) {
            f.setAccessible(true);
            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());
    }
  }
}

代码示例来源:origin: google/j2objc

return sun.misc.Unsafe.getUnsafe();
} catch (SecurityException e) {
 return java.security.AccessController.doPrivileged(
   new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
    @Override
 throw new RuntimeException("Could not initialize intrinsics", e.getCause());

代码示例来源:origin: vipshop/vjtools

/**
   * Returns a sun.misc.Unsafe.  Suitable for use in a 3rd party package.
   * Replace with a simple call to Unsafe.getUnsafe when integrating
   * into a jdk.
   *
   * @return a sun.misc.Unsafe
   */
  private static sun.misc.Unsafe getUnsafe() {
    try {
      return sun.misc.Unsafe.getUnsafe();
    } catch (SecurityException tryReflectionInstead) {
    }
    try {
      return java.security.AccessController
          .doPrivileged(new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
            public sun.misc.Unsafe run() throws Exception {
              Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
              for (java.lang.reflect.Field f : k.getDeclaredFields()) {
                f.setAccessible(true);
                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());
    }
  }
}

代码示例来源:origin: google/j2objc

return sun.misc.Unsafe.getUnsafe();
} catch (SecurityException tryReflectionInstead) {
 return java.security.AccessController.doPrivileged(
   new java.security.PrivilegedExceptionAction<sun.misc.Unsafe>() {
    @Override
 throw new RuntimeException("Could not initialize intrinsics", e.getCause());

代码示例来源:origin: PipelineAI/pipeline

/**
 * Returns a sun.misc.Unsafe.  Suitable for use in a 3rd party package.
 * Replace with a simple call to Unsafe.getUnsafe when integrating
 * into a jdk.
 *
 * @return a sun.misc.Unsafe
 */
private static sun.misc.Unsafe getUnsafe() {
  try {
    return sun.misc.Unsafe.getUnsafe();
  } catch (SecurityException se) {
    try {
      return java.security.AccessController.doPrivileged
        (new java.security
         .PrivilegedExceptionAction<sun.misc.Unsafe>() {
          public sun.misc.Unsafe run() throws Exception {
            java.lang.reflect.Field f = sun.misc
              .Unsafe.class.getDeclaredField("theUnsafe");
            f.setAccessible(true);
            return (sun.misc.Unsafe) f.get(null);
          }});
    } catch (java.security.PrivilegedActionException e) {
      throw new RuntimeException("Could not initialize intrinsics",
                    e.getCause());
    }
  }
}

代码示例来源:origin: apache/ignite

/**
 * @return Instance of Unsafe class.
 */
private static Unsafe unsafe() {
  try {
    return Unsafe.getUnsafe();
  }
  catch (SecurityException ignored) {
    try {
      return AccessController.doPrivileged
        (new PrivilegedExceptionAction<Unsafe>() {
          @Override public Unsafe run() throws Exception {
            Field f = Unsafe.class.getDeclaredField("theUnsafe");
            f.setAccessible(true);
            return (Unsafe)f.get(null);
          }
        });
    }
    catch (PrivilegedActionException e) {
      throw new RuntimeException("Could not initialize intrinsics.", e.getCause());
    }
  }
}

相关文章

微信公众号

最新文章

更多

Unsafe类方法