Permalink
Browse files

Allow to disable the use of sun.misc.Unsafe via a System property. See

  • Loading branch information...
1 parent e719f23 commit 2ecef07c4a5b1a2d302e7ad5adae9b828370234d @normanmaurer normanmaurer committed Apr 19, 2012
Showing with 14 additions and 0 deletions.
  1. +14 −0 common/src/main/java/io/netty/util/internal/DetectionUtil.java
@@ -26,6 +26,11 @@
* Utility that detects various properties specific to the current runtime
* environment, such as Java version and the availability of the
* {@code sun.misc.Unsafe} object.
+ *
+ * <br>
+ * You can disable the use of {@code sun.misc.Unsafe} if you specify
+ * the System property <strong>io.netty.tryUnsafe</strong> with
+ * value of <code>false</code>. Default is <code>true</code>.
*/
public final class DetectionUtil {
@@ -41,6 +46,15 @@ public static int javaVersion() {
}
private static boolean hasUnsafe(ClassLoader loader) {
+ String value = SystemPropertyUtil.get("io.netty.tryUnsafe");
+ if (value == null) {
+ value = SystemPropertyUtil.get("org.jboss.netty.tryUnsafe", "true");
+ }
+ boolean useUnsafe = Boolean.valueOf(value);
+ if (!useUnsafe) {
+ return false;
+ }
+
try {
Class<?> unsafeClazz = Class.forName("sun.misc.Unsafe", true, loader);
return hasUnsafeField(unsafeClazz);

0 comments on commit 2ecef07

Please sign in to comment.