Mercurial > hg > truffle
changeset 16626:7ce626e1952c
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
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 31 Jul 2014 00:19:21 +0200 |
parents | d2aa48d54db5 |
children | 68deb37eed70 |
files | graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/UnsafeAccess.java |
diffstat | 1 files changed, 7 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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) {