# HG changeset patch # User Doug Simon # Date 1406758761 -7200 # Node ID 7ce626e1952cfa4991f1158fbba96a3f8a579c90 # Parent d2aa48d54db5fc43200784ba3da5d5d2eba4f3ee removed direct use of Unsafe.getUnsafe() since graal.jar is no longer on boot class path and so reflection method of accessed Unsafe must be used diff -r d2aa48d54db5 -r 7ce626e1952c graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/UnsafeAccess.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/UnsafeAccess.java Wed Jul 30 21:48:03 2014 +0200 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/UnsafeAccess.java Thu Jul 31 00:19:21 2014 +0200 @@ -31,22 +31,15 @@ /** * An instance of {@link Unsafe} for use within Graal. */ - public static final Unsafe unsafe = getUnsafe(); + public static final Unsafe unsafe; - private static Unsafe getUnsafe() { - try { - // this will fail if Graal is not part of the boot class path - return Unsafe.getUnsafe(); - } catch (SecurityException e) { - // nothing to do - } + static { try { Field theUnsafeInstance = Unsafe.class.getDeclaredField("theUnsafe"); theUnsafeInstance.setAccessible(true); - return (Unsafe) theUnsafeInstance.get(Unsafe.class); + unsafe = (Unsafe) theUnsafeInstance.get(Unsafe.class); } catch (Exception e) { - // currently we rely on being able to use Unsafe... - throw new RuntimeException("exception while trying to get Unsafe.theUnsafe via reflection:", e); + throw new RuntimeException("exception while trying to get Unsafe", e); } } @@ -55,7 +48,7 @@ * terminated C string. The native memory buffer is allocated via * {@link Unsafe#allocateMemory(long)}. The caller is responsible for releasing the buffer when * it is no longer needed via {@link Unsafe#freeMemory(long)}. - * + * * @return the native memory pointer of the C string created from {@code s} */ public static long createCString(String s) { @@ -65,7 +58,7 @@ /** * Reads a {@code '\0'} terminated C string from native memory and converts it to a * {@link String}. - * + * * @return a Java string */ public static String readCString(long address) { @@ -88,7 +81,7 @@ * terminated C string. The caller is responsible for ensuring the buffer is at least * {@code s.length() + 1} bytes long. The caller is also responsible for releasing the buffer * when it is no longer. - * + * * @return the value of {@code buf} */ public static long writeCString(String s, long buf) {