From 69196a998f6d699c54183fd11187a45f180a237c Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Thu, 19 Jan 2012 16:35:36 +0100 Subject: [PATCH] Switching to semi-dynamic discovery of sun.misc.Unsafe entity --- akka-actor/src/main/scala/akka/util/Unsafe.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/akka-actor/src/main/scala/akka/util/Unsafe.java b/akka-actor/src/main/scala/akka/util/Unsafe.java index 4449f045be..b1d7f61290 100644 --- a/akka-actor/src/main/scala/akka/util/Unsafe.java +++ b/akka-actor/src/main/scala/akka/util/Unsafe.java @@ -11,9 +11,16 @@ public final class Unsafe { public final static sun.misc.Unsafe instance; static { try { - Field field = sun.misc.Unsafe.class.getDeclaredField("theUnsafe"); - field.setAccessible(true); - instance = (sun.misc.Unsafe) field.get(null); + sun.misc.Unsafe found = null; + for(Field field : sun.misc.Unsafe.class.getDeclaredFields()) { + if (field.getType() == sun.misc.Unsafe.class) { + field.setAccessible(true); + found = (sun.misc.Unsafe) field.get(null); + break; + } + } + if (found == null) throw new IllegalStateException("Can't find instance of sun.misc.Unsafe"); + else instance = found; } catch(Throwable t) { throw new ExceptionInInitializerError(t); }