# HG changeset patch # User Doug Simon # Date 1441807949 -7200 # Node ID 9f0e536ee3854ef60d6eca34c693cdaaf362be1c # Parent f08fed409c49483bf82e298dca895f24f974cfc8 restricted Unsafe capability access to package or class scope (GRAAL-1257) diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.asm.amd64.test/src/com/oracle/graal/asm/amd64/test/BitOpsTest.java --- a/graal/com.oracle.graal.asm.amd64.test/src/com/oracle/graal/asm/amd64/test/BitOpsTest.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.asm.amd64.test/src/com/oracle/graal/asm/amd64/test/BitOpsTest.java Wed Sep 09 16:12:29 2015 +0200 @@ -23,24 +23,31 @@ package com.oracle.graal.asm.amd64.test; -import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.asm.test.*; +import static com.oracle.graal.asm.amd64.AMD64Assembler.AMD64RMOp.LZCNT; +import static com.oracle.graal.asm.amd64.AMD64Assembler.AMD64RMOp.TZCNT; +import static com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize.DWORD; +import static com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize.QWORD; +import static jdk.internal.jvmci.code.ValueUtil.asRegister; +import static org.junit.Assume.assumeTrue; -import static com.oracle.graal.asm.amd64.AMD64Assembler.AMD64RMOp.*; -import static com.oracle.graal.asm.amd64.AMD64Assembler.OperandSize.*; -import static jdk.internal.jvmci.code.ValueUtil.*; -import static jdk.internal.jvmci.common.UnsafeAccess.*; -import static org.junit.Assume.*; +import java.lang.reflect.Field; +import java.util.EnumSet; -import java.lang.reflect.*; -import java.util.*; +import jdk.internal.jvmci.amd64.AMD64; +import jdk.internal.jvmci.amd64.AMD64.CPUFeature; +import jdk.internal.jvmci.code.CallingConvention; +import jdk.internal.jvmci.code.CompilationResult; +import jdk.internal.jvmci.code.Register; +import jdk.internal.jvmci.code.RegisterConfig; +import jdk.internal.jvmci.code.TargetDescription; +import jdk.internal.jvmci.meta.JavaKind; -import jdk.internal.jvmci.amd64.*; -import jdk.internal.jvmci.amd64.AMD64.*; -import jdk.internal.jvmci.code.*; -import jdk.internal.jvmci.meta.*; +import org.junit.Before; +import org.junit.Test; -import org.junit.*; +import com.oracle.graal.asm.amd64.AMD64Address; +import com.oracle.graal.asm.amd64.AMD64Assembler; +import com.oracle.graal.asm.test.AssemblerTest; public class BitOpsTest extends AssemblerTest { private static boolean lzcntSupported; @@ -84,7 +91,7 @@ Register ret = registerConfig.getReturnRegister(JavaKind.Int); try { Field f = IntField.class.getDeclaredField("x"); - AMD64Address arg = new AMD64Address(asRegister(cc.getArgument(0)), (int) unsafe.objectFieldOffset(f)); + AMD64Address arg = new AMD64Address(asRegister(cc.getArgument(0)), (int) UNSAFE.objectFieldOffset(f)); LZCNT.emit(asm, DWORD, ret, arg); asm.ret(0); return asm.close(true); @@ -127,7 +134,7 @@ Register ret = registerConfig.getReturnRegister(JavaKind.Int); try { Field f = LongField.class.getDeclaredField("x"); - AMD64Address arg = new AMD64Address(asRegister(cc.getArgument(0)), (int) unsafe.objectFieldOffset(f)); + AMD64Address arg = new AMD64Address(asRegister(cc.getArgument(0)), (int) UNSAFE.objectFieldOffset(f)); LZCNT.emit(asm, QWORD, ret, arg); asm.ret(0); return asm.close(true); @@ -170,7 +177,7 @@ Register ret = registerConfig.getReturnRegister(JavaKind.Int); try { Field f = IntField.class.getDeclaredField("x"); - AMD64Address arg = new AMD64Address(asRegister(cc.getArgument(0)), (int) unsafe.objectFieldOffset(f)); + AMD64Address arg = new AMD64Address(asRegister(cc.getArgument(0)), (int) UNSAFE.objectFieldOffset(f)); TZCNT.emit(asm, DWORD, ret, arg); asm.ret(0); return asm.close(true); @@ -213,7 +220,7 @@ Register ret = registerConfig.getReturnRegister(JavaKind.Int); try { Field f = LongField.class.getDeclaredField("x"); - AMD64Address arg = new AMD64Address(asRegister(cc.getArgument(0)), (int) unsafe.objectFieldOffset(f)); + AMD64Address arg = new AMD64Address(asRegister(cc.getArgument(0)), (int) UNSAFE.objectFieldOffset(f)); TZCNT.emit(asm, QWORD, ret, arg); asm.ret(0); return asm.close(true); diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.asm.amd64.test/src/com/oracle/graal/asm/amd64/test/IncrementDecrementMacroTest.java --- a/graal/com.oracle.graal.asm.amd64.test/src/com/oracle/graal/asm/amd64/test/IncrementDecrementMacroTest.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.asm.amd64.test/src/com/oracle/graal/asm/amd64/test/IncrementDecrementMacroTest.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,20 +22,25 @@ */ package com.oracle.graal.asm.amd64.test; -import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.asm.test.*; +import static jdk.internal.jvmci.code.ValueUtil.asRegister; +import static org.junit.Assume.assumeTrue; -import static jdk.internal.jvmci.code.ValueUtil.*; -import static jdk.internal.jvmci.common.UnsafeAccess.*; -import static org.junit.Assume.*; +import java.lang.reflect.Field; -import java.lang.reflect.*; +import jdk.internal.jvmci.amd64.AMD64; +import jdk.internal.jvmci.code.CallingConvention; +import jdk.internal.jvmci.code.CompilationResult; +import jdk.internal.jvmci.code.Register; +import jdk.internal.jvmci.code.RegisterConfig; +import jdk.internal.jvmci.code.TargetDescription; +import jdk.internal.jvmci.meta.JavaKind; -import jdk.internal.jvmci.amd64.*; -import jdk.internal.jvmci.code.*; -import jdk.internal.jvmci.meta.*; +import org.junit.Before; +import org.junit.Test; -import org.junit.*; +import com.oracle.graal.asm.amd64.AMD64Address; +import com.oracle.graal.asm.amd64.AMD64MacroAssembler; +import com.oracle.graal.asm.test.AssemblerTest; public class IncrementDecrementMacroTest extends AssemblerTest { @@ -65,7 +70,7 @@ Register ret = registerConfig.getReturnRegister(JavaKind.Int); try { Field f = LongField.class.getDeclaredField("x"); - AMD64Address arg = new AMD64Address(asRegister(cc.getArgument(0)), (int) unsafe.objectFieldOffset(f)); + AMD64Address arg = new AMD64Address(asRegister(cc.getArgument(0)), (int) UNSAFE.objectFieldOffset(f)); asm.incrementq(arg, value); asm.movq(ret, arg); asm.ret(0); @@ -102,7 +107,7 @@ Register ret = registerConfig.getReturnRegister(JavaKind.Int); try { Field f = LongField.class.getDeclaredField("x"); - AMD64Address arg = new AMD64Address(asRegister(cc.getArgument(0)), (int) unsafe.objectFieldOffset(f)); + AMD64Address arg = new AMD64Address(asRegister(cc.getArgument(0)), (int) UNSAFE.objectFieldOffset(f)); asm.decrementq(arg, value); asm.movq(ret, arg); asm.ret(0); diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/FieldIntrospection.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/FieldIntrospection.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/FieldIntrospection.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,9 +22,7 @@ */ package com.oracle.graal.compiler.common; -import jdk.internal.jvmci.common.*; - -public abstract class FieldIntrospection extends UnsafeAccess { +public abstract class FieldIntrospection { private final Class clazz; diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/Fields.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/Fields.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/Fields.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,12 +22,13 @@ */ package com.oracle.graal.compiler.common; -import static jdk.internal.jvmci.common.UnsafeAccess.*; +import static com.oracle.graal.compiler.common.UnsafeAccess.UNSAFE; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; -import jdk.internal.jvmci.common.*; -import sun.misc.*; +import jdk.internal.jvmci.common.JVMCIError; +import sun.misc.Unsafe; /** * Describes fields in a class, primarily for access via {@link Unsafe}. @@ -120,27 +121,27 @@ Class type = types[index]; if (type.isPrimitive()) { if (type == Integer.TYPE) { - unsafe.putInt(to, offset, unsafe.getInt(from, offset)); + UNSAFE.putInt(to, offset, UNSAFE.getInt(from, offset)); } else if (type == Long.TYPE) { - unsafe.putLong(to, offset, unsafe.getLong(from, offset)); + UNSAFE.putLong(to, offset, UNSAFE.getLong(from, offset)); } else if (type == Boolean.TYPE) { - unsafe.putBoolean(to, offset, unsafe.getBoolean(from, offset)); + UNSAFE.putBoolean(to, offset, UNSAFE.getBoolean(from, offset)); } else if (type == Float.TYPE) { - unsafe.putFloat(to, offset, unsafe.getFloat(from, offset)); + UNSAFE.putFloat(to, offset, UNSAFE.getFloat(from, offset)); } else if (type == Double.TYPE) { - unsafe.putDouble(to, offset, unsafe.getDouble(from, offset)); + UNSAFE.putDouble(to, offset, UNSAFE.getDouble(from, offset)); } else if (type == Short.TYPE) { - unsafe.putShort(to, offset, unsafe.getShort(from, offset)); + UNSAFE.putShort(to, offset, UNSAFE.getShort(from, offset)); } else if (type == Character.TYPE) { - unsafe.putChar(to, offset, unsafe.getChar(from, offset)); + UNSAFE.putChar(to, offset, UNSAFE.getChar(from, offset)); } else if (type == Byte.TYPE) { - unsafe.putByte(to, offset, unsafe.getByte(from, offset)); + UNSAFE.putByte(to, offset, UNSAFE.getByte(from, offset)); } else { assert false : "unhandled property type: " + type; } } else { - Object obj = unsafe.getObject(from, offset); - unsafe.putObject(to, offset, trans == null ? obj : trans.apply(index, obj)); + Object obj = UNSAFE.getObject(from, offset); + UNSAFE.putObject(to, offset, trans == null ? obj : trans.apply(index, obj)); } } } @@ -158,26 +159,26 @@ Object value = null; if (type.isPrimitive()) { if (type == Integer.TYPE) { - value = unsafe.getInt(object, offset); + value = UNSAFE.getInt(object, offset); } else if (type == Long.TYPE) { - value = unsafe.getLong(object, offset); + value = UNSAFE.getLong(object, offset); } else if (type == Boolean.TYPE) { - value = unsafe.getBoolean(object, offset); + value = UNSAFE.getBoolean(object, offset); } else if (type == Float.TYPE) { - value = unsafe.getFloat(object, offset); + value = UNSAFE.getFloat(object, offset); } else if (type == Double.TYPE) { - value = unsafe.getDouble(object, offset); + value = UNSAFE.getDouble(object, offset); } else if (type == Short.TYPE) { - value = unsafe.getShort(object, offset); + value = UNSAFE.getShort(object, offset); } else if (type == Character.TYPE) { - value = unsafe.getChar(object, offset); + value = UNSAFE.getChar(object, offset); } else if (type == Byte.TYPE) { - value = unsafe.getByte(object, offset); + value = UNSAFE.getByte(object, offset); } else { assert false : "unhandled property type: " + type; } } else { - value = unsafe.getObject(object, offset); + value = UNSAFE.getObject(object, offset); } return value; } @@ -194,21 +195,21 @@ Class type = types[index]; if (type == Integer.TYPE) { - return unsafe.getInt(object, offset); + return UNSAFE.getInt(object, offset); } else if (type == Long.TYPE) { - return unsafe.getLong(object, offset); + return UNSAFE.getLong(object, offset); } else if (type == Boolean.TYPE) { - return unsafe.getBoolean(object, offset) ? 1 : 0; + return UNSAFE.getBoolean(object, offset) ? 1 : 0; } else if (type == Float.TYPE) { - return Float.floatToRawIntBits(unsafe.getFloat(object, offset)); + return Float.floatToRawIntBits(UNSAFE.getFloat(object, offset)); } else if (type == Double.TYPE) { - return Double.doubleToRawLongBits(unsafe.getDouble(object, offset)); + return Double.doubleToRawLongBits(UNSAFE.getDouble(object, offset)); } else if (type == Short.TYPE) { - return unsafe.getShort(object, offset); + return UNSAFE.getShort(object, offset); } else if (type == Character.TYPE) { - return unsafe.getChar(object, offset); + return UNSAFE.getChar(object, offset); } else if (type == Byte.TYPE) { - return unsafe.getByte(object, offset); + return UNSAFE.getByte(object, offset); } else { throw JVMCIError.shouldNotReachHere(); } @@ -265,27 +266,27 @@ Class type = types[index]; if (type.isPrimitive()) { if (type == Integer.TYPE) { - unsafe.putInt(object, offset, (Integer) value); + UNSAFE.putInt(object, offset, (Integer) value); } else if (type == Long.TYPE) { - unsafe.putLong(object, offset, (Long) value); + UNSAFE.putLong(object, offset, (Long) value); } else if (type == Boolean.TYPE) { - unsafe.putBoolean(object, offset, (Boolean) value); + UNSAFE.putBoolean(object, offset, (Boolean) value); } else if (type == Float.TYPE) { - unsafe.putFloat(object, offset, (Float) value); + UNSAFE.putFloat(object, offset, (Float) value); } else if (type == Double.TYPE) { - unsafe.putDouble(object, offset, (Double) value); + UNSAFE.putDouble(object, offset, (Double) value); } else if (type == Short.TYPE) { - unsafe.putShort(object, offset, (Short) value); + UNSAFE.putShort(object, offset, (Short) value); } else if (type == Character.TYPE) { - unsafe.putChar(object, offset, (Character) value); + UNSAFE.putChar(object, offset, (Character) value); } else if (type == Byte.TYPE) { - unsafe.putByte(object, offset, (Byte) value); + UNSAFE.putByte(object, offset, (Byte) value); } else { assert false : "unhandled property type: " + type; } } else { assert checkAssignableFrom(object, index, value); - unsafe.putObject(object, offset, value); + UNSAFE.putObject(object, offset, value); } } @@ -293,21 +294,21 @@ long offset = offsets[index]; Class type = types[index]; if (type == Integer.TYPE) { - unsafe.putInt(object, offset, (int) value); + UNSAFE.putInt(object, offset, (int) value); } else if (type == Long.TYPE) { - unsafe.putLong(object, offset, value); + UNSAFE.putLong(object, offset, value); } else if (type == Boolean.TYPE) { - unsafe.putBoolean(object, offset, value != 0); + UNSAFE.putBoolean(object, offset, value != 0); } else if (type == Float.TYPE) { - unsafe.putFloat(object, offset, Float.intBitsToFloat((int) value)); + UNSAFE.putFloat(object, offset, Float.intBitsToFloat((int) value)); } else if (type == Double.TYPE) { - unsafe.putDouble(object, offset, Double.longBitsToDouble(value)); + UNSAFE.putDouble(object, offset, Double.longBitsToDouble(value)); } else if (type == Short.TYPE) { - unsafe.putShort(object, offset, (short) value); + UNSAFE.putShort(object, offset, (short) value); } else if (type == Character.TYPE) { - unsafe.putChar(object, offset, (char) value); + UNSAFE.putChar(object, offset, (char) value); } else if (type == Byte.TYPE) { - unsafe.putByte(object, offset, (byte) value); + UNSAFE.putByte(object, offset, (byte) value); } else { throw JVMCIError.shouldNotReachHere(); } @@ -328,51 +329,51 @@ public boolean getBoolean(Object n, int i) { assert types[i] == boolean.class; - return unsafe.getBoolean(n, offsets[i]); + return UNSAFE.getBoolean(n, offsets[i]); } public byte getByte(Object n, int i) { assert types[i] == byte.class; - return unsafe.getByte(n, offsets[i]); + return UNSAFE.getByte(n, offsets[i]); } public short getShort(Object n, int i) { assert types[i] == short.class; - return unsafe.getShort(n, offsets[i]); + return UNSAFE.getShort(n, offsets[i]); } public char getChar(Object n, int i) { assert types[i] == char.class; - return unsafe.getChar(n, offsets[i]); + return UNSAFE.getChar(n, offsets[i]); } public int getInt(Object n, int i) { assert types[i] == int.class; - return unsafe.getInt(n, offsets[i]); + return UNSAFE.getInt(n, offsets[i]); } public long getLong(Object n, int i) { assert types[i] == long.class; - return unsafe.getLong(n, offsets[i]); + return UNSAFE.getLong(n, offsets[i]); } public float getFloat(Object n, int i) { assert types[i] == float.class; - return unsafe.getFloat(n, offsets[i]); + return UNSAFE.getFloat(n, offsets[i]); } public double getDouble(Object n, int i) { assert types[i] == double.class; - return unsafe.getDouble(n, offsets[i]); + return UNSAFE.getDouble(n, offsets[i]); } public Object getObject(Object object, int i) { assert !types[i].isPrimitive(); - return unsafe.getObject(object, offsets[i]); + return UNSAFE.getObject(object, offsets[i]); } public void putObject(Object object, int i, Object value) { assert checkAssignableFrom(object, i, value); - unsafe.putObject(object, offsets[i], value); + UNSAFE.putObject(object, offsets[i], value); } } diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/FieldsScanner.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/FieldsScanner.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/FieldsScanner.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,12 +22,13 @@ */ package com.oracle.graal.compiler.common; -import static jdk.internal.jvmci.common.UnsafeAccess.*; +import static com.oracle.graal.compiler.common.UnsafeAccess.UNSAFE; -import java.lang.reflect.*; -import java.util.*; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; -import sun.misc.*; +import sun.misc.Unsafe; /** * Scans the fields in a class hierarchy. @@ -49,7 +50,7 @@ @Override public long getOffset(Field field) { - return unsafe.objectFieldOffset(field); + return UNSAFE.objectFieldOffset(field); } } diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/UnsafeAccess.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/UnsafeAccess.java Wed Sep 09 16:12:29 2015 +0200 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.compiler.common; + +import java.lang.reflect.Field; + +import sun.misc.Unsafe; + +/** + * Package private access to the {@link Unsafe} capability. + */ +class UnsafeAccess { + + static final Unsafe UNSAFE = initUnsafe(); + + private static Unsafe initUnsafe() { + try { + // Fast path when we are trusted. + return Unsafe.getUnsafe(); + } catch (SecurityException se) { + // Slow path when we are not trusted. + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + return (Unsafe) theUnsafe.get(Unsafe.class); + } catch (Exception e) { + throw new RuntimeException("exception while trying to get Unsafe", e); + } + } + } +} diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/UnsafeAccess.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/UnsafeAccess.java Wed Sep 09 16:12:29 2015 +0200 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.compiler.common.util; + +import java.lang.reflect.Field; + +import sun.misc.Unsafe; + +/** + * Package private access to the {@link Unsafe} capability. + */ +class UnsafeAccess { + + static final Unsafe UNSAFE = initUnsafe(); + + private static Unsafe initUnsafe() { + try { + // Fast path when we are trusted. + return Unsafe.getUnsafe(); + } catch (SecurityException se) { + // Slow path when we are not trusted. + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + return (Unsafe) theUnsafe.get(Unsafe.class); + } catch (Exception e) { + throw new RuntimeException("exception while trying to get Unsafe", e); + } + } + } +} diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/UnsafeArrayTypeReader.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/UnsafeArrayTypeReader.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/UnsafeArrayTypeReader.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,8 +22,8 @@ */ package com.oracle.graal.compiler.common.util; -import jdk.internal.jvmci.common.*; -import sun.misc.*; +import static com.oracle.graal.compiler.common.util.UnsafeAccess.UNSAFE; +import sun.misc.Unsafe; /** * Provides low-level read access from a byte[] array for signed and unsigned values of size 1, 2, @@ -40,11 +40,11 @@ public abstract class UnsafeArrayTypeReader implements TypeReader { public static int getS1(byte[] data, long byteIndex) { - return UnsafeAccess.unsafe.getByte(data, readOffset(data, byteIndex, Byte.BYTES)); + return UNSAFE.getByte(data, readOffset(data, byteIndex, Byte.BYTES)); } public static int getU1(byte[] data, long byteIndex) { - return UnsafeAccess.unsafe.getByte(data, readOffset(data, byteIndex, Byte.BYTES)) & 0xFF; + return UNSAFE.getByte(data, readOffset(data, byteIndex, Byte.BYTES)) & 0xFF; } public static int getS2(byte[] data, long byteIndex, boolean supportsUnalignedMemoryAccess) { @@ -141,15 +141,15 @@ final class UnalignedUnsafeArrayTypeReader extends UnsafeArrayTypeReader { protected static int getS2(byte[] data, long byteIndex) { - return UnsafeAccess.unsafe.getShort(data, readOffset(data, byteIndex, Short.BYTES)); + return UNSAFE.getShort(data, readOffset(data, byteIndex, Short.BYTES)); } protected static int getS4(byte[] data, long byteIndex) { - return UnsafeAccess.unsafe.getInt(data, readOffset(data, byteIndex, Integer.BYTES)); + return UNSAFE.getInt(data, readOffset(data, byteIndex, Integer.BYTES)); } protected static long getS8(byte[] data, long byteIndex) { - return UnsafeAccess.unsafe.getLong(data, readOffset(data, byteIndex, Long.BYTES)); + return UNSAFE.getLong(data, readOffset(data, byteIndex, Long.BYTES)); } protected UnalignedUnsafeArrayTypeReader(byte[] data, long byteIndex) { @@ -181,28 +181,28 @@ class AlignedUnsafeArrayTypeReader extends UnsafeArrayTypeReader { protected static int getS2(byte[] data, long byteIndex) { long offset = readOffset(data, byteIndex, Short.BYTES); - return ((UnsafeAccess.unsafe.getByte(data, offset + 0) & 0xFF) << 0) | // - (UnsafeAccess.unsafe.getByte(data, offset + 1) << 8); + return ((UNSAFE.getByte(data, offset + 0) & 0xFF) << 0) | // + (UNSAFE.getByte(data, offset + 1) << 8); } protected static int getS4(byte[] data, long byteIndex) { long offset = readOffset(data, byteIndex, Integer.BYTES); - return ((UnsafeAccess.unsafe.getByte(data, offset + 0) & 0xFF) << 0) | // - ((UnsafeAccess.unsafe.getByte(data, offset + 1) & 0xFF) << 8) | // - ((UnsafeAccess.unsafe.getByte(data, offset + 2) & 0xFF) << 16) | // - (UnsafeAccess.unsafe.getByte(data, offset + 3) << 24); + return ((UNSAFE.getByte(data, offset + 0) & 0xFF) << 0) | // + ((UNSAFE.getByte(data, offset + 1) & 0xFF) << 8) | // + ((UNSAFE.getByte(data, offset + 2) & 0xFF) << 16) | // + (UNSAFE.getByte(data, offset + 3) << 24); } protected static long getS8(byte[] data, long byteIndex) { long offset = readOffset(data, byteIndex, Long.BYTES); - return ((long) ((UnsafeAccess.unsafe.getByte(data, offset + 0) & 0xFF)) << 0) | // - ((long) ((UnsafeAccess.unsafe.getByte(data, offset + 1) & 0xFF)) << 8) | // - ((long) ((UnsafeAccess.unsafe.getByte(data, offset + 2) & 0xFF)) << 16) | // - ((long) ((UnsafeAccess.unsafe.getByte(data, offset + 3) & 0xFF)) << 24) | // - ((long) ((UnsafeAccess.unsafe.getByte(data, offset + 4) & 0xFF)) << 32) | // - ((long) ((UnsafeAccess.unsafe.getByte(data, offset + 5) & 0xFF)) << 40) | // - ((long) ((UnsafeAccess.unsafe.getByte(data, offset + 6) & 0xFF)) << 48) | // - ((long) (UnsafeAccess.unsafe.getByte(data, offset + 7)) << 56); + return ((long) ((UNSAFE.getByte(data, offset + 0) & 0xFF)) << 0) | // + ((long) ((UNSAFE.getByte(data, offset + 1) & 0xFF)) << 8) | // + ((long) ((UNSAFE.getByte(data, offset + 2) & 0xFF)) << 16) | // + ((long) ((UNSAFE.getByte(data, offset + 3) & 0xFF)) << 24) | // + ((long) ((UNSAFE.getByte(data, offset + 4) & 0xFF)) << 32) | // + ((long) ((UNSAFE.getByte(data, offset + 5) & 0xFF)) << 40) | // + ((long) ((UNSAFE.getByte(data, offset + 6) & 0xFF)) << 48) | // + ((long) (UNSAFE.getByte(data, offset + 7)) << 56); } protected AlignedUnsafeArrayTypeReader(byte[] data, long byteIndex) { diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/UnsafeArrayTypeWriter.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/UnsafeArrayTypeWriter.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/util/UnsafeArrayTypeWriter.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,9 +22,13 @@ */ package com.oracle.graal.compiler.common.util; -import static com.oracle.graal.compiler.common.util.TypeConversion.*; -import jdk.internal.jvmci.common.*; -import sun.misc.*; +import static com.oracle.graal.compiler.common.util.TypeConversion.asS1; +import static com.oracle.graal.compiler.common.util.TypeConversion.asS2; +import static com.oracle.graal.compiler.common.util.TypeConversion.asS4; +import static com.oracle.graal.compiler.common.util.TypeConversion.asU1; +import static com.oracle.graal.compiler.common.util.TypeConversion.asU2; +import static com.oracle.graal.compiler.common.util.TypeConversion.asU4; +import sun.misc.Unsafe; /** * Provides low-level sequential write access to a byte[] array for signed and unsigned values of @@ -90,13 +94,13 @@ @Override public final void putS1(long value) { long offset = writeOffset(Byte.BYTES); - UnsafeAccess.unsafe.putByte(writeChunk.data, offset, asS1(value)); + UnsafeAccess.UNSAFE.putByte(writeChunk.data, offset, asS1(value)); } @Override public final void putU1(long value) { long offset = writeOffset(Byte.BYTES); - UnsafeAccess.unsafe.putByte(writeChunk.data, offset, asU1(value)); + UnsafeAccess.UNSAFE.putByte(writeChunk.data, offset, asU1(value)); } @Override @@ -131,19 +135,19 @@ @Override public void putS2(long value) { long offset = writeOffset(Short.BYTES); - UnsafeAccess.unsafe.putShort(writeChunk.data, offset, asS2(value)); + UnsafeAccess.UNSAFE.putShort(writeChunk.data, offset, asS2(value)); } @Override public void putS4(long value) { long offset = writeOffset(Integer.BYTES); - UnsafeAccess.unsafe.putInt(writeChunk.data, offset, asS4(value)); + UnsafeAccess.UNSAFE.putInt(writeChunk.data, offset, asS4(value)); } @Override public void putS8(long value) { long offset = writeOffset(Long.BYTES); - UnsafeAccess.unsafe.putLong(writeChunk.data, offset, value); + UnsafeAccess.UNSAFE.putLong(writeChunk.data, offset, value); } } @@ -151,29 +155,29 @@ @Override public void putS2(long value) { long offset = writeOffset(Short.BYTES); - UnsafeAccess.unsafe.putByte(writeChunk.data, offset + 0, (byte) (value >> 0)); - UnsafeAccess.unsafe.putByte(writeChunk.data, offset + 1, (byte) (value >> 8)); + UnsafeAccess.UNSAFE.putByte(writeChunk.data, offset + 0, (byte) (value >> 0)); + UnsafeAccess.UNSAFE.putByte(writeChunk.data, offset + 1, (byte) (value >> 8)); } @Override public void putS4(long value) { long offset = writeOffset(Integer.BYTES); - UnsafeAccess.unsafe.putByte(writeChunk.data, offset + 0, (byte) (value >> 0)); - UnsafeAccess.unsafe.putByte(writeChunk.data, offset + 1, (byte) (value >> 8)); - UnsafeAccess.unsafe.putByte(writeChunk.data, offset + 2, (byte) (value >> 16)); - UnsafeAccess.unsafe.putByte(writeChunk.data, offset + 3, (byte) (value >> 24)); + UnsafeAccess.UNSAFE.putByte(writeChunk.data, offset + 0, (byte) (value >> 0)); + UnsafeAccess.UNSAFE.putByte(writeChunk.data, offset + 1, (byte) (value >> 8)); + UnsafeAccess.UNSAFE.putByte(writeChunk.data, offset + 2, (byte) (value >> 16)); + UnsafeAccess.UNSAFE.putByte(writeChunk.data, offset + 3, (byte) (value >> 24)); } @Override public void putS8(long value) { long offset = writeOffset(Long.BYTES); - UnsafeAccess.unsafe.putByte(writeChunk.data, offset + 0, (byte) (value >> 0)); - UnsafeAccess.unsafe.putByte(writeChunk.data, offset + 1, (byte) (value >> 8)); - UnsafeAccess.unsafe.putByte(writeChunk.data, offset + 2, (byte) (value >> 16)); - UnsafeAccess.unsafe.putByte(writeChunk.data, offset + 3, (byte) (value >> 24)); - UnsafeAccess.unsafe.putByte(writeChunk.data, offset + 4, (byte) (value >> 32)); - UnsafeAccess.unsafe.putByte(writeChunk.data, offset + 5, (byte) (value >> 40)); - UnsafeAccess.unsafe.putByte(writeChunk.data, offset + 6, (byte) (value >> 48)); - UnsafeAccess.unsafe.putByte(writeChunk.data, offset + 7, (byte) (value >> 56)); + UnsafeAccess.UNSAFE.putByte(writeChunk.data, offset + 0, (byte) (value >> 0)); + UnsafeAccess.UNSAFE.putByte(writeChunk.data, offset + 1, (byte) (value >> 8)); + UnsafeAccess.UNSAFE.putByte(writeChunk.data, offset + 2, (byte) (value >> 16)); + UnsafeAccess.UNSAFE.putByte(writeChunk.data, offset + 3, (byte) (value >> 24)); + UnsafeAccess.UNSAFE.putByte(writeChunk.data, offset + 4, (byte) (value >> 32)); + UnsafeAccess.UNSAFE.putByte(writeChunk.data, offset + 5, (byte) (value >> 40)); + UnsafeAccess.UNSAFE.putByte(writeChunk.data, offset + 6, (byte) (value >> 48)); + UnsafeAccess.UNSAFE.putByte(writeChunk.data, offset + 7, (byte) (value >> 56)); } } diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/PEAReadEliminationTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/PEAReadEliminationTest.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/PEAReadEliminationTest.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,19 +22,18 @@ */ package com.oracle.graal.compiler.test.ea; -import jdk.internal.jvmci.common.*; +import org.junit.Test; -import org.junit.*; - -import sun.misc.*; +import sun.misc.Unsafe; import com.oracle.graal.nodes.StructuredGraph.AllowAssumptions; -import com.oracle.graal.nodes.extended.*; -import com.oracle.graal.nodes.java.*; -import com.oracle.graal.phases.common.*; -import com.oracle.graal.phases.common.inlining.*; -import com.oracle.graal.phases.tiers.*; -import com.oracle.graal.virtual.phases.ea.*; +import com.oracle.graal.nodes.extended.UnsafeLoadNode; +import com.oracle.graal.nodes.java.LoadIndexedNode; +import com.oracle.graal.nodes.java.StoreIndexedNode; +import com.oracle.graal.phases.common.CanonicalizerPhase; +import com.oracle.graal.phases.common.inlining.InliningPhase; +import com.oracle.graal.phases.tiers.HighTierContext; +import com.oracle.graal.virtual.phases.ea.PartialEscapePhase; public class PEAReadEliminationTest extends EarlyReadEliminationTest { @@ -121,10 +120,10 @@ private static final long offsetInt2 = Unsafe.ARRAY_INT_BASE_OFFSET + Unsafe.ARRAY_INT_INDEX_SCALE * 2; public static int testUnsafe1Snippet(int v, int[] array) { - int s = UnsafeAccess.unsafe.getInt(array, offsetInt1); - UnsafeAccess.unsafe.putInt(array, offsetInt1, v); - UnsafeAccess.unsafe.putInt(array, offsetInt2, v); - return s + UnsafeAccess.unsafe.getInt(array, offsetInt1) + UnsafeAccess.unsafe.getInt(array, offsetInt2); + int s = UNSAFE.getInt(array, offsetInt1); + UNSAFE.putInt(array, offsetInt1, v); + UNSAFE.putInt(array, offsetInt2, v); + return s + UNSAFE.getInt(array, offsetInt1) + UNSAFE.getInt(array, offsetInt2); } @Test @@ -134,10 +133,10 @@ } public static int testUnsafe2Snippet(int v, Object array) { - int s = UnsafeAccess.unsafe.getInt(array, offsetInt1); - UnsafeAccess.unsafe.putInt(array, offsetInt1, v); - UnsafeAccess.unsafe.putInt(array, offsetInt2, v); - return s + UnsafeAccess.unsafe.getInt(array, offsetInt1) + UnsafeAccess.unsafe.getInt(array, offsetInt2); + int s = UNSAFE.getInt(array, offsetInt1); + UNSAFE.putInt(array, offsetInt1, v); + UNSAFE.putInt(array, offsetInt2, v); + return s + UNSAFE.getInt(array, offsetInt1) + UNSAFE.getInt(array, offsetInt2); } @Test @@ -150,10 +149,10 @@ private static final long offsetObject2 = Unsafe.ARRAY_OBJECT_BASE_OFFSET + Unsafe.ARRAY_OBJECT_INDEX_SCALE * 2; public static int testUnsafe3Snippet(int v, Object[] array) { - int s = (Integer) UnsafeAccess.unsafe.getObject(array, offsetObject1); - UnsafeAccess.unsafe.putObject(array, offsetObject1, v); - UnsafeAccess.unsafe.putObject(array, offsetObject2, v); - return s + (Integer) UnsafeAccess.unsafe.getObject(array, offsetObject1) + (Integer) UnsafeAccess.unsafe.getObject(array, offsetObject2); + int s = (Integer) UNSAFE.getObject(array, offsetObject1); + UNSAFE.putObject(array, offsetObject1, v); + UNSAFE.putObject(array, offsetObject2, v); + return s + (Integer) UNSAFE.getObject(array, offsetObject1) + (Integer) UNSAFE.getObject(array, offsetObject2); } @Test @@ -163,11 +162,11 @@ } public static int testUnsafe4Snippet(int v, Object[] array) { - int s = (Integer) UnsafeAccess.unsafe.getObject(array, offsetObject1); - UnsafeAccess.unsafe.putObject(array, offsetObject1, v); - UnsafeAccess.unsafe.putObject(array, offsetObject2, v); + int s = (Integer) UNSAFE.getObject(array, offsetObject1); + UNSAFE.putObject(array, offsetObject1, v); + UNSAFE.putObject(array, offsetObject2, v); array[v] = null; - return s + (Integer) UnsafeAccess.unsafe.getObject(array, offsetObject1) + (Integer) UnsafeAccess.unsafe.getObject(array, offsetObject2); + return s + (Integer) UNSAFE.getObject(array, offsetObject1) + (Integer) UNSAFE.getObject(array, offsetObject2); } @Test @@ -180,10 +179,10 @@ private static final long offsetLong2 = Unsafe.ARRAY_LONG_BASE_OFFSET + Unsafe.ARRAY_LONG_INDEX_SCALE * 2; public static int testUnsafe5Snippet(int v, long[] array) { - int s = UnsafeAccess.unsafe.getInt(array, offsetLong1); - UnsafeAccess.unsafe.putInt(array, offsetLong1, v); - UnsafeAccess.unsafe.putInt(array, offsetLong2, v); - return s + UnsafeAccess.unsafe.getInt(array, offsetLong1) + UnsafeAccess.unsafe.getInt(array, offsetLong2); + int s = UNSAFE.getInt(array, offsetLong1); + UNSAFE.putInt(array, offsetLong1, v); + UNSAFE.putInt(array, offsetLong2, v); + return s + UNSAFE.getInt(array, offsetLong1) + UNSAFE.getInt(array, offsetLong2); } @Test diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/UnsafeEATest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/UnsafeEATest.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/UnsafeEATest.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,36 +22,33 @@ */ package com.oracle.graal.compiler.test.ea; -import jdk.internal.jvmci.common.*; -import jdk.internal.jvmci.meta.*; - -import org.junit.*; +import jdk.internal.jvmci.meta.JavaConstant; -import sun.misc.*; +import org.junit.Assert; +import org.junit.Test; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.java.*; +import com.oracle.graal.nodes.PhiNode; +import com.oracle.graal.nodes.ValuePhiNode; +import com.oracle.graal.nodes.java.LoadFieldNode; public class UnsafeEATest extends EATestBase { public static int zero = 0; - private static final Unsafe unsafe; private static final long fieldOffset1; private static final long fieldOffset2; static { - unsafe = UnsafeAccess.unsafe; try { - long localFieldOffset1 = unsafe.objectFieldOffset(TestClassInt.class.getField("x")); + long localFieldOffset1 = UNSAFE.objectFieldOffset(TestClassInt.class.getField("x")); // Make the fields 8 byte aligned (Required for testing setLong on Architectures which // does not support unaligned memory access if (localFieldOffset1 % 8 == 0) { fieldOffset1 = localFieldOffset1; - fieldOffset2 = unsafe.objectFieldOffset(TestClassInt.class.getField("y")); + fieldOffset2 = UNSAFE.objectFieldOffset(TestClassInt.class.getField("y")); } else { - fieldOffset1 = unsafe.objectFieldOffset(TestClassInt.class.getField("y")); - fieldOffset2 = unsafe.objectFieldOffset(TestClassInt.class.getField("z")); + fieldOffset1 = UNSAFE.objectFieldOffset(TestClassInt.class.getField("y")); + fieldOffset2 = UNSAFE.objectFieldOffset(TestClassInt.class.getField("z")); } assert fieldOffset2 == fieldOffset1 + 4; } catch (Exception e) { @@ -66,8 +63,8 @@ public static int testSimpleIntSnippet() { TestClassInt x = new TestClassInt(); - unsafe.putInt(x, fieldOffset1, 101); - return unsafe.getInt(x, fieldOffset1); + UNSAFE.putInt(x, fieldOffset1, 101); + return UNSAFE.getInt(x, fieldOffset1); } @Test @@ -77,7 +74,7 @@ public static TestClassInt testMaterializedIntSnippet() { TestClassInt x = new TestClassInt(); - unsafe.putInt(x, fieldOffset1, 101); + UNSAFE.putInt(x, fieldOffset1, 101); return x; } @@ -88,8 +85,8 @@ public static double testSimpleDoubleSnippet() { TestClassInt x = new TestClassInt(); - unsafe.putDouble(x, fieldOffset1, 10.1); - return unsafe.getDouble(x, fieldOffset1); + UNSAFE.putDouble(x, fieldOffset1, 10.1); + return UNSAFE.getDouble(x, fieldOffset1); } @Test @@ -106,12 +103,12 @@ TestClassInt x; if (a) { x = new TestClassInt(0, 0); - unsafe.putDouble(x, fieldOffset1, doubleField); + UNSAFE.putDouble(x, fieldOffset1, doubleField); } else { x = new TestClassInt(); - unsafe.putDouble(x, fieldOffset1, doubleField2); + UNSAFE.putDouble(x, fieldOffset1, doubleField2); } - return unsafe.getDouble(x, fieldOffset1); + return UNSAFE.getDouble(x, fieldOffset1); } @Test @@ -121,7 +118,7 @@ public static TestClassInt testMaterializedDoubleSnippet() { TestClassInt x = new TestClassInt(); - unsafe.putDouble(x, fieldOffset1, 10.1); + UNSAFE.putDouble(x, fieldOffset1, 10.1); return x; } @@ -135,10 +132,10 @@ public static TestClassInt testDeoptDoubleVarSnippet() { TestClassInt x = new TestClassInt(); - unsafe.putDouble(x, fieldOffset1, doubleField); + UNSAFE.putDouble(x, fieldOffset1, doubleField); doubleField2 = 123; try { - doubleField = ((int) unsafe.getDouble(x, fieldOffset1)) / zero; + doubleField = ((int) UNSAFE.getDouble(x, fieldOffset1)) / zero; } catch (RuntimeException e) { return x; } @@ -152,10 +149,10 @@ public static TestClassInt testDeoptDoubleConstantSnippet() { TestClassInt x = new TestClassInt(); - unsafe.putDouble(x, fieldOffset1, 10.123); + UNSAFE.putDouble(x, fieldOffset1, 10.123); doubleField2 = 123; try { - doubleField = ((int) unsafe.getDouble(x, fieldOffset1)) / zero; + doubleField = ((int) UNSAFE.getDouble(x, fieldOffset1)) / zero; } catch (RuntimeException e) { return x; } @@ -172,10 +169,10 @@ public static TestClassInt testDeoptLongVarSnippet() { TestClassInt x = new TestClassInt(); - unsafe.putLong(x, fieldOffset1, longField); + UNSAFE.putLong(x, fieldOffset1, longField); longField2 = 123; try { - longField = unsafe.getLong(x, fieldOffset1) / zero; + longField = UNSAFE.getLong(x, fieldOffset1) / zero; } catch (RuntimeException e) { return x; } @@ -189,10 +186,10 @@ public static TestClassInt testDeoptLongConstantSnippet() { TestClassInt x = new TestClassInt(); - unsafe.putLong(x, fieldOffset1, 0x2222222210123L); + UNSAFE.putLong(x, fieldOffset1, 0x2222222210123L); longField2 = 123; try { - longField = unsafe.getLong(x, fieldOffset1) / zero; + longField = UNSAFE.getLong(x, fieldOffset1) / zero; } catch (RuntimeException e) { return x; } diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Edges.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Edges.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Edges.java Wed Sep 09 16:12:29 2015 +0200 @@ -24,7 +24,7 @@ import static com.oracle.graal.graph.Graph.*; import static com.oracle.graal.graph.Node.*; -import static jdk.internal.jvmci.common.UnsafeAccess.*; +import static com.oracle.graal.graph.UnsafeAccess.UNSAFE; import java.util.*; import java.util.function.*; @@ -62,20 +62,20 @@ } private static Node getNodeUnsafe(Node node, long offset) { - return (Node) unsafe.getObject(node, offset); + return (Node) UNSAFE.getObject(node, offset); } @SuppressWarnings("unchecked") private static NodeList getNodeListUnsafe(Node node, long offset) { - return (NodeList) unsafe.getObject(node, offset); + return (NodeList) UNSAFE.getObject(node, offset); } private static void putNodeUnsafe(Node node, long offset, Node value) { - unsafe.putObject(node, offset, value); + UNSAFE.putObject(node, offset, value); } private static void putNodeListUnsafe(Node node, long offset, NodeList value) { - unsafe.putObject(node, offset, value); + UNSAFE.putObject(node, offset, value); } /** diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,24 +22,42 @@ */ package com.oracle.graal.graph; -import static com.oracle.graal.graph.Edges.Type.*; -import static com.oracle.graal.graph.Graph.*; +import static com.oracle.graal.graph.Edges.Type.Inputs; +import static com.oracle.graal.graph.Edges.Type.Successors; +import static com.oracle.graal.graph.Graph.MODIFICATION_COUNTS_ENABLED; +import static com.oracle.graal.graph.UnsafeAccess.UNSAFE; -import java.lang.annotation.*; -import java.util.*; -import java.util.function.*; +import java.lang.annotation.ElementType; +import java.lang.annotation.RetentionPolicy; +import java.util.Collection; +import java.util.Collections; +import java.util.EnumSet; +import java.util.Formattable; +import java.util.FormattableFlags; +import java.util.Formatter; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.function.BiConsumer; +import java.util.function.Predicate; -import jdk.internal.jvmci.common.*; -import com.oracle.graal.debug.*; -import sun.misc.*; +import sun.misc.Unsafe; -import com.oracle.graal.compiler.common.*; +import com.oracle.graal.compiler.common.CollectionsFactory; +import com.oracle.graal.compiler.common.Fields; +import com.oracle.graal.debug.Fingerprint; import com.oracle.graal.graph.Graph.NodeEvent; import com.oracle.graal.graph.Graph.NodeEventListener; import com.oracle.graal.graph.Graph.Options; -import com.oracle.graal.graph.iterators.*; -import com.oracle.graal.graph.spi.*; -import com.oracle.graal.nodeinfo.*; +import com.oracle.graal.graph.iterators.NodeIterable; +import com.oracle.graal.graph.iterators.NodePredicate; +import com.oracle.graal.graph.spi.Simplifiable; +import com.oracle.graal.graph.spi.SimplifierTool; +import com.oracle.graal.nodeinfo.InputType; +import com.oracle.graal.nodeinfo.NodeInfo; +import com.oracle.graal.nodeinfo.Verbosity; /** * This class is the base class for all nodes. It represents a node that can be inserted in a @@ -814,7 +832,7 @@ Node newNode = null; try { if (USE_UNSAFE_TO_CLONE) { - newNode = (Node) UnsafeAccess.unsafe.allocateInstance(getClass()); + newNode = (Node) UNSAFE.allocateInstance(getClass()); newNode.nodeClass = nodeClassTmp; nodeClassTmp.getData().copy(this, newNode); copyOrClearEdgesForClone(newNode, Inputs, edgesToCopy); diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,29 +22,45 @@ */ package com.oracle.graal.graph; -import static com.oracle.graal.compiler.common.Fields.*; -import static com.oracle.graal.graph.Edges.*; -import static com.oracle.graal.graph.InputEdges.*; -import static com.oracle.graal.graph.Node.*; -import static jdk.internal.jvmci.common.JVMCIError.*; +import static com.oracle.graal.compiler.common.Fields.translateInto; +import static com.oracle.graal.graph.Edges.translateInto; +import static com.oracle.graal.graph.InputEdges.translateInto; +import static com.oracle.graal.graph.Node.WithAllEdges; +import static com.oracle.graal.graph.Node.newIdentityMap; +import static com.oracle.graal.graph.UnsafeAccess.UNSAFE; +import static jdk.internal.jvmci.common.JVMCIError.shouldNotReachHere; -import java.lang.annotation.*; -import java.lang.reflect.*; -import java.util.*; -import java.util.concurrent.atomic.*; +import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.EnumSet; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; -import jdk.internal.jvmci.common.*; -import com.oracle.graal.debug.*; +import jdk.internal.jvmci.common.JVMCIError; -import com.oracle.graal.compiler.common.*; +import com.oracle.graal.compiler.common.FieldIntrospection; +import com.oracle.graal.compiler.common.Fields; +import com.oracle.graal.compiler.common.FieldsScanner; +import com.oracle.graal.debug.Debug; +import com.oracle.graal.debug.DebugCloseable; +import com.oracle.graal.debug.DebugMetric; +import com.oracle.graal.debug.DebugTimer; +import com.oracle.graal.debug.Fingerprint; import com.oracle.graal.graph.Edges.Type; import com.oracle.graal.graph.Graph.DuplicationReplacement; import com.oracle.graal.graph.Node.Input; import com.oracle.graal.graph.Node.OptionalInput; import com.oracle.graal.graph.Node.Successor; -import com.oracle.graal.graph.spi.*; +import com.oracle.graal.graph.spi.Canonicalizable; import com.oracle.graal.graph.spi.Canonicalizable.BinaryCommutative; -import com.oracle.graal.nodeinfo.*; +import com.oracle.graal.graph.spi.Simplifiable; +import com.oracle.graal.nodeinfo.InputType; +import com.oracle.graal.nodeinfo.NodeInfo; +import com.oracle.graal.nodeinfo.Verbosity; /** * Metadata for every {@link Node} type. The metadata includes: @@ -681,7 +697,7 @@ @SuppressWarnings("unchecked") public Node allocateInstance() { try { - Node node = (Node) UnsafeAccess.unsafe.allocateInstance(getJavaClass()); + Node node = (Node) UNSAFE.allocateInstance(getJavaClass()); node.init((NodeClass) this); return node; } catch (InstantiationException ex) { diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/UnsafeAccess.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/UnsafeAccess.java Wed Sep 09 16:12:29 2015 +0200 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.graph; + +import java.lang.reflect.Field; + +import sun.misc.Unsafe; + +/** + * Package private access to the {@link Unsafe} capability. + */ +class UnsafeAccess { + + static final Unsafe UNSAFE = initUnsafe(); + + private static Unsafe initUnsafe() { + try { + // Fast path when we are trusted. + return Unsafe.getUnsafe(); + } catch (SecurityException se) { + // Slow path when we are not trusted. + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + return (Unsafe) theUnsafe.get(Unsafe.class); + } catch (Exception e) { + throw new RuntimeException("exception while trying to get Unsafe", e); + } + } + } +} diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,35 +22,55 @@ */ package com.oracle.graal.hotspot.amd64; -import static com.oracle.graal.compiler.common.GraalOptions.*; -import static jdk.internal.jvmci.amd64.AMD64.*; -import static jdk.internal.jvmci.code.CallingConvention.Type.*; -import static jdk.internal.jvmci.code.ValueUtil.*; -import static jdk.internal.jvmci.common.UnsafeAccess.*; +import static com.oracle.graal.compiler.common.GraalOptions.CanOmitFrame; +import static com.oracle.graal.compiler.common.GraalOptions.ZapStackOnMethodEntry; +import static jdk.internal.jvmci.amd64.AMD64.r10; +import static jdk.internal.jvmci.amd64.AMD64.rax; +import static jdk.internal.jvmci.amd64.AMD64.rsp; +import static jdk.internal.jvmci.code.CallingConvention.Type.JavaCallee; +import static jdk.internal.jvmci.code.ValueUtil.asRegister; + +import java.lang.reflect.Field; +import java.util.Set; -import java.util.*; - -import jdk.internal.jvmci.amd64.*; -import jdk.internal.jvmci.code.*; -import jdk.internal.jvmci.hotspot.*; -import jdk.internal.jvmci.meta.*; +import jdk.internal.jvmci.amd64.AMD64; +import jdk.internal.jvmci.code.CallingConvention; +import jdk.internal.jvmci.code.CompilationResult; +import jdk.internal.jvmci.code.Register; +import jdk.internal.jvmci.code.RegisterConfig; +import jdk.internal.jvmci.code.StackSlot; +import jdk.internal.jvmci.hotspot.HotSpotVMConfig; +import jdk.internal.jvmci.meta.JavaType; +import jdk.internal.jvmci.meta.ResolvedJavaMethod; +import sun.misc.Unsafe; -import com.oracle.graal.asm.*; -import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.asm.amd64.AMD64Assembler.*; -import com.oracle.graal.compiler.common.alloc.*; -import com.oracle.graal.compiler.gen.*; -import com.oracle.graal.compiler.target.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.hotspot.stubs.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.amd64.*; -import com.oracle.graal.lir.asm.*; -import com.oracle.graal.lir.framemap.*; -import com.oracle.graal.lir.gen.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.asm.Assembler; +import com.oracle.graal.asm.Label; +import com.oracle.graal.asm.amd64.AMD64Address; +import com.oracle.graal.asm.amd64.AMD64Assembler.ConditionFlag; +import com.oracle.graal.asm.amd64.AMD64MacroAssembler; +import com.oracle.graal.compiler.common.alloc.RegisterAllocationConfig; +import com.oracle.graal.compiler.gen.BytecodeLIRBuilder; +import com.oracle.graal.compiler.gen.BytecodeParserTool; +import com.oracle.graal.compiler.target.Backend; +import com.oracle.graal.hotspot.HotSpotGraalRuntimeProvider; +import com.oracle.graal.hotspot.HotSpotHostBackend; +import com.oracle.graal.hotspot.meta.HotSpotForeignCallsProvider; +import com.oracle.graal.hotspot.meta.HotSpotProviders; +import com.oracle.graal.hotspot.stubs.Stub; +import com.oracle.graal.lir.LIR; +import com.oracle.graal.lir.amd64.AMD64Call; +import com.oracle.graal.lir.amd64.AMD64FrameMap; +import com.oracle.graal.lir.amd64.AMD64FrameMapBuilder; +import com.oracle.graal.lir.asm.CompilationResultBuilder; +import com.oracle.graal.lir.asm.CompilationResultBuilderFactory; +import com.oracle.graal.lir.asm.FrameContext; +import com.oracle.graal.lir.framemap.FrameMap; +import com.oracle.graal.lir.framemap.FrameMapBuilder; +import com.oracle.graal.lir.gen.LIRGenerationResult; +import com.oracle.graal.lir.gen.LIRGeneratorTool; +import com.oracle.graal.nodes.StructuredGraph; +import com.oracle.graal.nodes.spi.NodeLIRBuilderTool; /** * HotSpot AMD64 specific backend. @@ -107,10 +127,10 @@ AMD64MacroAssembler asm = (AMD64MacroAssembler) crb.asm; int frameSize = crb.frameMap.frameSize(); if (frameSize > 0) { - int lastFramePage = frameSize / unsafe.pageSize(); + int lastFramePage = frameSize / UNSAFE.pageSize(); // emit multiple stack bangs for methods with frames larger than a page for (int i = 0; i <= lastFramePage; i++) { - int disp = (i + pagesToBang) * unsafe.pageSize(); + int disp = (i + pagesToBang) * UNSAFE.pageSize(); if (afterFrameInit) { disp -= frameSize; } @@ -322,4 +342,19 @@ return new AMD64HotSpotRegisterAllocationConfig(registerConfigNonNull); } + private static final Unsafe UNSAFE = initUnsafe(); + + private static Unsafe initUnsafe() { + try { + return Unsafe.getUnsafe(); + } catch (SecurityException se) { + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + return (Unsafe) theUnsafe.get(Unsafe.class); + } catch (Exception e) { + throw new RuntimeException("exception while trying to get Unsafe", e); + } + } + } } diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackend.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackend.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,43 +22,75 @@ */ package com.oracle.graal.hotspot.sparc; -import static com.oracle.graal.asm.sparc.SPARCAssembler.Annul.*; -import static com.oracle.graal.asm.sparc.SPARCAssembler.BranchPredict.*; -import static com.oracle.graal.asm.sparc.SPARCAssembler.CC.*; -import static com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag.*; -import static com.oracle.graal.compiler.common.GraalOptions.*; -import static jdk.internal.jvmci.code.CallingConvention.Type.*; -import static jdk.internal.jvmci.code.ValueUtil.*; -import static jdk.internal.jvmci.common.UnsafeAccess.*; -import static jdk.internal.jvmci.sparc.SPARC.*; +import static com.oracle.graal.asm.sparc.SPARCAssembler.Annul.NOT_ANNUL; +import static com.oracle.graal.asm.sparc.SPARCAssembler.BranchPredict.PREDICT_NOT_TAKEN; +import static com.oracle.graal.asm.sparc.SPARCAssembler.CC.Xcc; +import static com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag.NotEqual; +import static com.oracle.graal.compiler.common.GraalOptions.ZapStackOnMethodEntry; +import static jdk.internal.jvmci.code.CallingConvention.Type.JavaCall; +import static jdk.internal.jvmci.code.ValueUtil.asRegister; +import static jdk.internal.jvmci.code.ValueUtil.isRegister; +import static jdk.internal.jvmci.sparc.SPARC.g0; +import static jdk.internal.jvmci.sparc.SPARC.g5; +import static jdk.internal.jvmci.sparc.SPARC.isGlobalRegister; +import static jdk.internal.jvmci.sparc.SPARC.sp; -import java.util.*; -import java.util.concurrent.*; +import java.lang.reflect.Field; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; -import jdk.internal.jvmci.code.*; +import jdk.internal.jvmci.code.CallingConvention; +import jdk.internal.jvmci.code.CompilationResult; +import jdk.internal.jvmci.code.DataSection; import jdk.internal.jvmci.code.DataSection.Data; -import jdk.internal.jvmci.hotspot.*; -import jdk.internal.jvmci.meta.*; +import jdk.internal.jvmci.code.Register; +import jdk.internal.jvmci.code.RegisterConfig; +import jdk.internal.jvmci.code.StackSlot; +import jdk.internal.jvmci.hotspot.HotSpotVMConfig; +import jdk.internal.jvmci.meta.JavaType; +import jdk.internal.jvmci.meta.ResolvedJavaMethod; +import sun.misc.Unsafe; -import com.oracle.graal.asm.*; -import com.oracle.graal.asm.sparc.*; +import com.oracle.graal.asm.Assembler; +import com.oracle.graal.asm.Label; +import com.oracle.graal.asm.sparc.SPARCAddress; +import com.oracle.graal.asm.sparc.SPARCAssembler; +import com.oracle.graal.asm.sparc.SPARCMacroAssembler; import com.oracle.graal.asm.sparc.SPARCMacroAssembler.ScratchRegister; import com.oracle.graal.asm.sparc.SPARCMacroAssembler.Setx; -import com.oracle.graal.compiler.common.alloc.*; -import com.oracle.graal.compiler.common.cfg.*; -import com.oracle.graal.debug.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.hotspot.stubs.*; -import com.oracle.graal.lir.*; +import com.oracle.graal.compiler.common.alloc.RegisterAllocationConfig; +import com.oracle.graal.compiler.common.cfg.AbstractBlockBase; +import com.oracle.graal.debug.Debug; +import com.oracle.graal.debug.DebugMetric; +import com.oracle.graal.hotspot.HotSpotGraalRuntimeProvider; +import com.oracle.graal.hotspot.HotSpotHostBackend; +import com.oracle.graal.hotspot.meta.HotSpotForeignCallsProvider; +import com.oracle.graal.hotspot.meta.HotSpotProviders; +import com.oracle.graal.hotspot.stubs.Stub; +import com.oracle.graal.lir.InstructionValueConsumer; +import com.oracle.graal.lir.LIR; +import com.oracle.graal.lir.LIRFrameState; +import com.oracle.graal.lir.LIRInstruction; import com.oracle.graal.lir.StandardOp.SaveRegistersOp; -import com.oracle.graal.lir.asm.*; -import com.oracle.graal.lir.framemap.*; -import com.oracle.graal.lir.gen.*; -import com.oracle.graal.lir.sparc.*; +import com.oracle.graal.lir.asm.CompilationResultBuilder; +import com.oracle.graal.lir.asm.CompilationResultBuilderFactory; +import com.oracle.graal.lir.asm.FrameContext; +import com.oracle.graal.lir.framemap.FrameMap; +import com.oracle.graal.lir.framemap.FrameMapBuilder; +import com.oracle.graal.lir.gen.LIRGenerationResult; +import com.oracle.graal.lir.gen.LIRGeneratorTool; +import com.oracle.graal.lir.sparc.SPARCCall; +import com.oracle.graal.lir.sparc.SPARCDelayedControlTransfer; +import com.oracle.graal.lir.sparc.SPARCFrameMap; +import com.oracle.graal.lir.sparc.SPARCFrameMapBuilder; +import com.oracle.graal.lir.sparc.SPARCLIRInstructionMixin; import com.oracle.graal.lir.sparc.SPARCLIRInstructionMixin.SizeEstimate; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.lir.sparc.SPARCTailDelayedLIRInstruction; +import com.oracle.graal.nodes.StructuredGraph; +import com.oracle.graal.nodes.spi.NodeLIRBuilderTool; /** * HotSpot SPARC specific backend. @@ -125,10 +157,10 @@ SPARCMacroAssembler masm = (SPARCMacroAssembler) crb.asm; final int frameSize = crb.frameMap.totalFrameSize(); if (frameSize > 0) { - int lastFramePage = frameSize / unsafe.pageSize(); + int lastFramePage = frameSize / UNSAFE.pageSize(); // emit multiple stack bangs for methods with frames larger than a page for (int i = 0; i <= lastFramePage; i++) { - int disp = (i + pagesToBang) * unsafe.pageSize(); + int disp = (i + pagesToBang) * UNSAFE.pageSize(); if (afterFrameInit) { disp -= frameSize; } @@ -475,4 +507,20 @@ RegisterConfig registerConfigNonNull = registerConfig == null ? getCodeCache().getRegisterConfig() : registerConfig; return new RegisterAllocationConfig(registerConfigNonNull); } + + private static final Unsafe UNSAFE = initUnsafe(); + + private static Unsafe initUnsafe() { + try { + return Unsafe.getUnsafe(); + } catch (SecurityException se) { + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + return (Unsafe) theUnsafe.get(Unsafe.class); + } catch (Exception e) { + throw new RuntimeException("exception while trying to get Unsafe", e); + } + } + } } diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/WriteBarrierAdditionTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/WriteBarrierAdditionTest.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/WriteBarrierAdditionTest.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,8 +22,6 @@ */ package com.oracle.graal.hotspot.test; -import static jdk.internal.jvmci.common.UnsafeAccess.*; - import java.lang.ref.*; import com.oracle.graal.debug.*; @@ -162,7 +160,7 @@ } public static Object test5Snippet() throws Exception { - return unsafe.getObject(wr, config.useCompressedOops ? 12L : 16L); + return UNSAFE.getObject(wr, config.useCompressedOops ? 12L : 16L); } /** @@ -171,7 +169,7 @@ */ @Test public void test6() throws Exception { - test2("testUnsafeLoad", unsafe, wr, new Long(referentOffset), null); + test2("testUnsafeLoad", UNSAFE, wr, new Long(referentOffset), null); } /** @@ -180,7 +178,7 @@ */ @Test public void test7() throws Exception { - test2("testUnsafeLoad", unsafe, con, new Long(referentOffset), null); + test2("testUnsafeLoad", UNSAFE, con, new Long(referentOffset), null); } /** @@ -190,7 +188,7 @@ */ @Test public void test8() throws Exception { - test2("testUnsafeLoad", unsafe, wr, new Long(config.useCompressedOops ? 20 : 32), null); + test2("testUnsafeLoad", UNSAFE, wr, new Long(config.useCompressedOops ? 20 : 32), null); } /** @@ -200,7 +198,7 @@ */ @Test public void test10() throws Exception { - test2("testUnsafeLoad", unsafe, wr, new Long(config.useCompressedOops ? 6 : 8), new Integer(config.useCompressedOops ? 6 : 8)); + test2("testUnsafeLoad", UNSAFE, wr, new Long(config.useCompressedOops ? 6 : 8), new Integer(config.useCompressedOops ? 6 : 8)); } /** @@ -210,7 +208,7 @@ */ @Test public void test9() throws Exception { - test2("testUnsafeLoad", unsafe, wr, new Long(config.useCompressedOops ? 10 : 16), new Integer(config.useCompressedOops ? 10 : 16)); + test2("testUnsafeLoad", UNSAFE, wr, new Long(config.useCompressedOops ? 10 : 16), new Integer(config.useCompressedOops ? 10 : 16)); } static Object[] src = new Object[1]; diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,11 +22,13 @@ */ package com.oracle.graal.hotspot; -import static jdk.internal.jvmci.common.UnsafeAccess.*; import static jdk.internal.jvmci.compiler.Compiler.*; +import java.lang.reflect.Field; import java.util.concurrent.*; +import sun.misc.Unsafe; + import com.oracle.graal.debug.*; import com.oracle.graal.debug.Debug.*; @@ -42,6 +44,22 @@ public class CompilationTask { + private static final Unsafe UNSAFE = initUnsafe(); + + private static Unsafe initUnsafe() { + try { + return Unsafe.getUnsafe(); + } catch (SecurityException se) { + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + return (Unsafe) theUnsafe.get(Unsafe.class); + } catch (Exception e) { + throw new RuntimeException("exception while trying to get Unsafe", e); + } + } + } + private static final DebugMetric BAILOUTS = Debug.metric("Bailouts"); private static final EventProvider eventProvider; @@ -242,9 +260,9 @@ } if (jvmciEnv != 0) { - long ctask = unsafe.getAddress(jvmciEnv + config.jvmciEnvTaskOffset); + long ctask = UNSAFE.getAddress(jvmciEnv + config.jvmciEnvTaskOffset); assert ctask != 0L; - unsafe.putInt(ctask + config.compileTaskNumInlinedBytecodesOffset, compiledBytecodes); + UNSAFE.putInt(ctask + config.compileTaskNumInlinedBytecodesOffset, compiledBytecodes); } long compilationTime = System.nanoTime() - startCompilationTime; if ((config.ciTime || config.ciTimeEach) && installedCode != null) { @@ -263,7 +281,7 @@ if (config.ciTime || config.ciTimeEach || CompiledBytecodes.isEnabled()) { return true; } - if (jvmciEnv == 0 || unsafe.getByte(jvmciEnv + config.jvmciEnvJvmtiCanHotswapOrPostBreakpointOffset) != 0) { + if (jvmciEnv == 0 || UNSAFE.getByte(jvmciEnv + config.jvmciEnvJvmtiCanHotswapOrPostBreakpointOffset) != 0) { return true; } return false; diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/AESCryptSubstitutions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/AESCryptSubstitutions.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/AESCryptSubstitutions.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,23 +22,31 @@ */ package com.oracle.graal.hotspot.replacements; -import static com.oracle.graal.hotspot.HotSpotBackend.*; -import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; -import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; +import static com.oracle.graal.hotspot.HotSpotBackend.DECRYPT_BLOCK; +import static com.oracle.graal.hotspot.HotSpotBackend.ENCRYPT_BLOCK; +import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.arrayBaseOffset; +import static com.oracle.graal.nodes.extended.BranchProbabilityNode.VERY_SLOW_PATH_PROBABILITY; +import static com.oracle.graal.nodes.extended.BranchProbabilityNode.probability; -import java.lang.reflect.*; +import java.lang.reflect.Field; -import jdk.internal.jvmci.common.*; -import jdk.internal.jvmci.meta.*; -import sun.misc.*; +import jdk.internal.jvmci.common.JVMCIError; +import jdk.internal.jvmci.meta.DeoptimizationAction; +import jdk.internal.jvmci.meta.DeoptimizationReason; +import jdk.internal.jvmci.meta.JavaKind; +import jdk.internal.jvmci.meta.LocationIdentity; +import sun.misc.Launcher; -import com.oracle.graal.compiler.common.spi.*; +import com.oracle.graal.compiler.common.spi.ForeignCallDescriptor; import com.oracle.graal.graph.Node.ConstantNodeParameter; import com.oracle.graal.graph.Node.NodeIntrinsic; -import com.oracle.graal.hotspot.nodes.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.extended.*; -import com.oracle.graal.word.*; +import com.oracle.graal.hotspot.nodes.ComputeObjectAddressNode; +import com.oracle.graal.nodes.DeoptimizeNode; +import com.oracle.graal.nodes.PiNode; +import com.oracle.graal.nodes.extended.ForeignCallNode; +import com.oracle.graal.nodes.extended.UnsafeLoadNode; +import com.oracle.graal.word.Pointer; +import com.oracle.graal.word.Word; // JaCoCo Exclude @@ -57,7 +65,7 @@ // is normally not on the boot class path ClassLoader cl = Launcher.getLauncher().getClassLoader(); AESCryptClass = Class.forName("com.sun.crypto.provider.AESCrypt", true, cl); - kOffset = UnsafeAccess.unsafe.objectFieldOffset(AESCryptClass.getDeclaredField("K")); + kOffset = UnsafeAccess.UNSAFE.objectFieldOffset(AESCryptClass.getDeclaredField("K")); Field aesBlockSizeField = Class.forName("com.sun.crypto.provider.AESConstants", true, cl).getDeclaredField("AES_BLOCK_SIZE"); aesBlockSizeField.setAccessible(true); AES_BLOCK_SIZE = aesBlockSizeField.getInt(null); diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CipherBlockChainingSubstitutions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CipherBlockChainingSubstitutions.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CipherBlockChainingSubstitutions.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,20 +22,25 @@ */ package com.oracle.graal.hotspot.replacements; -import static com.oracle.graal.hotspot.HotSpotBackend.*; -import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; -import jdk.internal.jvmci.common.*; -import jdk.internal.jvmci.meta.*; -import sun.misc.*; +import static com.oracle.graal.hotspot.HotSpotBackend.DECRYPT; +import static com.oracle.graal.hotspot.HotSpotBackend.ENCRYPT; +import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.arrayBaseOffset; +import static com.oracle.graal.hotspot.replacements.UnsafeAccess.UNSAFE; +import jdk.internal.jvmci.common.JVMCIError; +import jdk.internal.jvmci.meta.JavaKind; +import jdk.internal.jvmci.meta.LocationIdentity; +import sun.misc.Launcher; -import com.oracle.graal.api.replacements.*; -import com.oracle.graal.compiler.common.spi.*; +import com.oracle.graal.api.replacements.Fold; +import com.oracle.graal.compiler.common.spi.ForeignCallDescriptor; import com.oracle.graal.graph.Node.ConstantNodeParameter; import com.oracle.graal.graph.Node.NodeIntrinsic; -import com.oracle.graal.hotspot.nodes.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.extended.*; -import com.oracle.graal.word.*; +import com.oracle.graal.hotspot.nodes.ComputeObjectAddressNode; +import com.oracle.graal.nodes.PiNode; +import com.oracle.graal.nodes.extended.ForeignCallNode; +import com.oracle.graal.nodes.extended.UnsafeLoadNode; +import com.oracle.graal.word.Pointer; +import com.oracle.graal.word.Word; // JaCoCo Exclude @@ -55,10 +60,10 @@ ClassLoader cl = Launcher.getLauncher().getClassLoader(); feedbackCipherClass = Class.forName("com.sun.crypto.provider.FeedbackCipher", true, cl); - embeddedCipherOffset = UnsafeAccess.unsafe.objectFieldOffset(feedbackCipherClass.getDeclaredField("embeddedCipher")); + embeddedCipherOffset = UNSAFE.objectFieldOffset(feedbackCipherClass.getDeclaredField("embeddedCipher")); cipherBlockChainingClass = Class.forName("com.sun.crypto.provider.CipherBlockChaining", true, cl); - rOffset = UnsafeAccess.unsafe.objectFieldOffset(cipherBlockChainingClass.getDeclaredField("r")); + rOffset = UNSAFE.objectFieldOffset(cipherBlockChainingClass.getDeclaredField("r")); } catch (Exception ex) { throw new JVMCIError(ex); } diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,33 +22,52 @@ */ package com.oracle.graal.hotspot.replacements; -import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; -import static com.oracle.graal.hotspot.meta.HotSpotForeignCallsProviderImpl.*; -import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; -import static jdk.internal.jvmci.common.UnsafeAccess.*; -import jdk.internal.jvmci.code.*; -import jdk.internal.jvmci.common.*; -import jdk.internal.jvmci.hotspot.*; +import static com.oracle.graal.hotspot.HotSpotGraalRuntime.runtime; +import static com.oracle.graal.hotspot.meta.HotSpotForeignCallsProviderImpl.IDENTITY_HASHCODE; +import static com.oracle.graal.hotspot.meta.HotSpotForeignCallsProviderImpl.VERIFY_OOP; +import static com.oracle.graal.hotspot.replacements.UnsafeAccess.UNSAFE; +import static com.oracle.graal.nodes.extended.BranchProbabilityNode.FAST_PATH_PROBABILITY; +import static com.oracle.graal.nodes.extended.BranchProbabilityNode.probability; +import jdk.internal.jvmci.code.CodeUtil; +import jdk.internal.jvmci.code.Register; +import jdk.internal.jvmci.common.JVMCIError; +import jdk.internal.jvmci.hotspot.HotSpotMetaspaceConstant; +import jdk.internal.jvmci.hotspot.HotSpotResolvedObjectType; +import jdk.internal.jvmci.hotspot.HotSpotResolvedObjectTypeImpl; +import jdk.internal.jvmci.hotspot.HotSpotVMConfig; +import jdk.internal.jvmci.meta.Assumptions; import jdk.internal.jvmci.meta.Assumptions.AssumptionResult; -import jdk.internal.jvmci.meta.*; +import jdk.internal.jvmci.meta.JavaKind; +import jdk.internal.jvmci.meta.LocationIdentity; +import jdk.internal.jvmci.meta.ResolvedJavaType; -import com.oracle.graal.api.replacements.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.common.spi.*; -import com.oracle.graal.compiler.common.type.*; +import com.oracle.graal.api.replacements.Fold; +import com.oracle.graal.compiler.common.GraalOptions; +import com.oracle.graal.compiler.common.spi.ForeignCallDescriptor; +import com.oracle.graal.compiler.common.type.ObjectStamp; import com.oracle.graal.graph.Node.ConstantNodeParameter; import com.oracle.graal.graph.Node.NodeIntrinsic; -import com.oracle.graal.graph.spi.*; -import com.oracle.graal.hotspot.nodes.*; -import com.oracle.graal.hotspot.word.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.extended.*; -import com.oracle.graal.nodes.memory.*; -import com.oracle.graal.nodes.memory.address.*; -import com.oracle.graal.nodes.type.*; -import com.oracle.graal.replacements.*; -import com.oracle.graal.replacements.nodes.*; -import com.oracle.graal.word.*; +import com.oracle.graal.graph.spi.CanonicalizerTool; +import com.oracle.graal.hotspot.nodes.CompressionNode; +import com.oracle.graal.hotspot.nodes.SnippetAnchorNode; +import com.oracle.graal.hotspot.word.KlassPointer; +import com.oracle.graal.nodes.CanonicalizableLocation; +import com.oracle.graal.nodes.ConstantNode; +import com.oracle.graal.nodes.NamedLocationIdentity; +import com.oracle.graal.nodes.ValueNode; +import com.oracle.graal.nodes.extended.ForeignCallNode; +import com.oracle.graal.nodes.extended.GuardingNode; +import com.oracle.graal.nodes.extended.LoadHubNode; +import com.oracle.graal.nodes.extended.StoreHubNode; +import com.oracle.graal.nodes.extended.UnsafeLoadNode; +import com.oracle.graal.nodes.memory.Access; +import com.oracle.graal.nodes.memory.address.AddressNode; +import com.oracle.graal.nodes.memory.address.OffsetAddressNode; +import com.oracle.graal.nodes.type.StampTool; +import com.oracle.graal.replacements.ReplacementsUtil; +import com.oracle.graal.replacements.nodes.ReadRegisterNode; +import com.oracle.graal.replacements.nodes.WriteRegisterNode; +import com.oracle.graal.word.Word; //JaCoCo Exclude @@ -326,7 +345,7 @@ @Fold public static int pageSize() { - return unsafe.pageSize(); + return UNSAFE.pageSize(); } @Fold @@ -949,7 +968,7 @@ @Fold public static long referentOffset() { try { - return unsafe.objectFieldOffset(java.lang.ref.Reference.class.getDeclaredField("referent")); + return UNSAFE.objectFieldOffset(java.lang.ref.Reference.class.getDeclaredField("referent")); } catch (Exception e) { throw new JVMCIError(e); } diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/UnsafeAccess.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/UnsafeAccess.java Wed Sep 09 16:12:29 2015 +0200 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.hotspot.replacements; + +import java.lang.reflect.Field; + +import sun.misc.Unsafe; + +/** + * Package private access to the {@link Unsafe} capability. + */ +class UnsafeAccess { + + static final Unsafe UNSAFE = initUnsafe(); + + private static Unsafe initUnsafe() { + try { + // Fast path when we are trusted. + return Unsafe.getUnsafe(); + } catch (SecurityException se) { + // Slow path when we are not trusted. + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + return (Unsafe) theUnsafe.get(Unsafe.class); + } catch (Exception e) { + throw new RuntimeException("exception while trying to get Unsafe", e); + } + } + } +} diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/jdk/UnsafeAllocateInstance01.java --- a/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/jdk/UnsafeAllocateInstance01.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/jdk/UnsafeAllocateInstance01.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,14 +22,13 @@ */ package com.oracle.graal.jtt.jdk; -import java.lang.reflect.*; -import java.util.*; +import java.util.AbstractList; +import java.util.List; -import org.junit.*; +import org.junit.Ignore; +import org.junit.Test; -import sun.misc.*; - -import com.oracle.graal.jtt.*; +import com.oracle.graal.jtt.JTTTest; /* */ @@ -38,24 +37,12 @@ int field01 = 42; public static int testInstance() throws SecurityException, InstantiationException { - final Unsafe unsafe = getUnsafe(); - UnsafeAllocateInstance01 newObject = (UnsafeAllocateInstance01) unsafe.allocateInstance(UnsafeAllocateInstance01.class); + UnsafeAllocateInstance01 newObject = (UnsafeAllocateInstance01) UNSAFE.allocateInstance(UnsafeAllocateInstance01.class); return newObject.field01; } public static void testClassForException(Class clazz) throws SecurityException, InstantiationException { - final Unsafe unsafe = getUnsafe(); - unsafe.allocateInstance(clazz); - } - - static Unsafe getUnsafe() { - try { - final Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe"); - unsafeField.setAccessible(true); - return (Unsafe) unsafeField.get(null); - } catch (Exception e) { - throw new Error(e); - } + UNSAFE.allocateInstance(clazz); } @Test diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ArrayEqualsOp.java --- a/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ArrayEqualsOp.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64ArrayEqualsOp.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,24 +22,31 @@ */ package com.oracle.graal.lir.amd64; -import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static jdk.internal.jvmci.code.ValueUtil.*; -import static jdk.internal.jvmci.common.UnsafeAccess.*; +import static com.oracle.graal.lir.LIRInstruction.OperandFlag.ILLEGAL; +import static com.oracle.graal.lir.LIRInstruction.OperandFlag.REG; +import static jdk.internal.jvmci.code.ValueUtil.asRegister; -import java.lang.reflect.*; +import java.lang.reflect.Array; +import java.lang.reflect.Field; -import jdk.internal.jvmci.amd64.*; -import jdk.internal.jvmci.amd64.AMD64.*; -import jdk.internal.jvmci.code.*; -import jdk.internal.jvmci.meta.*; +import jdk.internal.jvmci.amd64.AMD64; +import jdk.internal.jvmci.amd64.AMD64.CPUFeature; +import jdk.internal.jvmci.code.Register; +import jdk.internal.jvmci.code.TargetDescription; +import jdk.internal.jvmci.meta.JavaKind; +import jdk.internal.jvmci.meta.LIRKind; +import jdk.internal.jvmci.meta.Value; +import sun.misc.Unsafe; -import com.oracle.graal.asm.*; -import com.oracle.graal.asm.amd64.*; -import com.oracle.graal.asm.amd64.AMD64Address.*; -import com.oracle.graal.asm.amd64.AMD64Assembler.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.asm.*; -import com.oracle.graal.lir.gen.*; +import com.oracle.graal.asm.Label; +import com.oracle.graal.asm.amd64.AMD64Address; +import com.oracle.graal.asm.amd64.AMD64Address.Scale; +import com.oracle.graal.asm.amd64.AMD64Assembler.ConditionFlag; +import com.oracle.graal.asm.amd64.AMD64MacroAssembler; +import com.oracle.graal.lir.LIRInstructionClass; +import com.oracle.graal.lir.Opcode; +import com.oracle.graal.lir.asm.CompilationResultBuilder; +import com.oracle.graal.lir.gen.LIRGeneratorTool; /** * Emits code which compares two arrays of the same length. If the CPU supports any vector @@ -69,8 +76,8 @@ this.kind = kind; Class arrayClass = Array.newInstance(kind.toJavaClass(), 0).getClass(); - this.arrayBaseOffset = unsafe.arrayBaseOffset(arrayClass); - this.arrayIndexScale = unsafe.arrayIndexScale(arrayClass); + this.arrayBaseOffset = UNSAFE.arrayBaseOffset(arrayClass); + this.arrayIndexScale = UNSAFE.arrayIndexScale(arrayClass); this.resultValue = result; this.array1Value = array1; @@ -298,4 +305,20 @@ } } } + + private static final Unsafe UNSAFE = initUnsafe(); + + private static Unsafe initUnsafe() { + try { + return Unsafe.getUnsafe(); + } catch (SecurityException se) { + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + return (Unsafe) theUnsafe.get(Unsafe.class); + } catch (Exception e) { + throw new RuntimeException("exception while trying to get Unsafe", e); + } + } + } } diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArrayEqualsOp.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArrayEqualsOp.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArrayEqualsOp.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,27 +22,37 @@ */ package com.oracle.graal.lir.sparc; -import static com.oracle.graal.asm.sparc.SPARCAssembler.Annul.*; -import static com.oracle.graal.asm.sparc.SPARCAssembler.BranchPredict.*; -import static com.oracle.graal.asm.sparc.SPARCAssembler.CC.*; -import static com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag.*; -import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static jdk.internal.jvmci.code.ValueUtil.*; -import static jdk.internal.jvmci.common.UnsafeAccess.*; -import static jdk.internal.jvmci.sparc.SPARC.*; +import static com.oracle.graal.asm.sparc.SPARCAssembler.Annul.ANNUL; +import static com.oracle.graal.asm.sparc.SPARCAssembler.Annul.NOT_ANNUL; +import static com.oracle.graal.asm.sparc.SPARCAssembler.BranchPredict.PREDICT_NOT_TAKEN; +import static com.oracle.graal.asm.sparc.SPARCAssembler.BranchPredict.PREDICT_TAKEN; +import static com.oracle.graal.asm.sparc.SPARCAssembler.CC.Xcc; +import static com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag.Always; +import static com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag.Equal; +import static com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag.Less; +import static com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag.NotEqual; +import static com.oracle.graal.lir.LIRInstruction.OperandFlag.REG; +import static jdk.internal.jvmci.code.ValueUtil.asRegister; +import static jdk.internal.jvmci.sparc.SPARC.g0; -import java.lang.reflect.*; +import java.lang.reflect.Array; +import java.lang.reflect.Field; -import jdk.internal.jvmci.code.*; -import jdk.internal.jvmci.meta.*; +import jdk.internal.jvmci.code.Register; +import jdk.internal.jvmci.meta.JavaKind; +import jdk.internal.jvmci.meta.LIRKind; +import jdk.internal.jvmci.meta.Value; +import sun.misc.Unsafe; -import com.oracle.graal.asm.*; -import com.oracle.graal.asm.sparc.*; +import com.oracle.graal.asm.Label; +import com.oracle.graal.asm.sparc.SPARCAddress; import com.oracle.graal.asm.sparc.SPARCAssembler.CC; import com.oracle.graal.asm.sparc.SPARCAssembler.ConditionFlag; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.asm.*; -import com.oracle.graal.lir.gen.*; +import com.oracle.graal.asm.sparc.SPARCMacroAssembler; +import com.oracle.graal.lir.LIRInstructionClass; +import com.oracle.graal.lir.Opcode; +import com.oracle.graal.lir.asm.CompilationResultBuilder; +import com.oracle.graal.lir.gen.LIRGeneratorTool; /** * Emits code which compares two arrays of the same length. @@ -71,8 +81,8 @@ this.kind = kind; Class arrayClass = Array.newInstance(kind.toJavaClass(), 0).getClass(); - this.arrayBaseOffset = unsafe.arrayBaseOffset(arrayClass); - this.arrayIndexScale = unsafe.arrayIndexScale(arrayClass); + this.arrayBaseOffset = UNSAFE.arrayBaseOffset(arrayClass); + this.arrayIndexScale = UNSAFE.arrayIndexScale(arrayClass); this.resultValue = result; this.array1Value = array1; @@ -235,4 +245,20 @@ } } } + + private static final Unsafe UNSAFE = initUnsafe(); + + private static Unsafe initUnsafe() { + try { + return Unsafe.getUnsafe(); + } catch (SecurityException se) { + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + return (Unsafe) theUnsafe.get(Unsafe.class); + } catch (Exception e) { + throw new RuntimeException("exception while trying to get Unsafe", e); + } + } + } } diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/UnsafeSubstitutionsTest.java --- a/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/UnsafeSubstitutionsTest.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/UnsafeSubstitutionsTest.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,7 +22,6 @@ */ package com.oracle.graal.replacements.test; -import static jdk.internal.jvmci.common.UnsafeAccess.*; import jdk.internal.jvmci.code.*; import jdk.internal.jvmci.meta.*; @@ -57,7 +56,7 @@ static long off(Object o, String name) { try { - return unsafe.objectFieldOffset(o.getClass().getDeclaredField(name)); + return UNSAFE.objectFieldOffset(o.getClass().getDeclaredField(name)); } catch (Exception e) { Assert.fail(e.toString()); return 0L; @@ -78,7 +77,7 @@ @Test public void testUnsafeSubstitutions() throws Exception { - test("unsafeCompareAndSwapInt", unsafe, supply(() -> new Foo()), fooOffset("i")); + test("unsafeCompareAndSwapInt", UNSAFE, supply(() -> new Foo()), fooOffset("i")); testGraph("unsafeCompareAndSwapInt"); testGraph("unsafeCompareAndSwapLong"); @@ -110,8 +109,8 @@ testGraph("unsafeDirectMemoryRead"); testGraph("unsafeDirectMemoryWrite"); - long address = unsafe.allocateMemory(8 * JavaKind.values().length); - for (Unsafe unsafeArg : new Unsafe[]{unsafe, null}) { + long address = UNSAFE.allocateMemory(8 * JavaKind.values().length); + for (Unsafe unsafeArg : new Unsafe[]{UNSAFE, null}) { test("unsafeCompareAndSwapInt", unsafeArg, supply(() -> new Foo()), fooOffset("i")); test("unsafeCompareAndSwapLong", unsafeArg, supply(() -> new Foo()), fooOffset("l")); test("unsafeCompareAndSwapObject", unsafeArg, supply(() -> new Foo()), fooOffset("o")); @@ -142,12 +141,12 @@ test("unsafeDirectMemoryRead", unsafeArg, address); test("unsafeDirectMemoryWrite", unsafeArg, address, 0xCAFE_BABE_DEAD_BABEL); } - unsafe.freeMemory(address); + UNSAFE.freeMemory(address); } private static long fooOffset(String name) { try { - return unsafe.objectFieldOffset(Foo.class.getDeclaredField(name)); + return UNSAFE.objectFieldOffset(Foo.class.getDeclaredField(name)); } catch (NoSuchFieldException | SecurityException e) { throw new AssertionError(e); } @@ -373,8 +372,8 @@ @Test public void testAllocateInstance() throws Exception { - System.out.println("result: " + unsafeAllocateInstance(unsafe)); - test("unsafeAllocateInstance", unsafe); + System.out.println("result: " + unsafeAllocateInstance(UNSAFE)); + test("unsafeAllocateInstance", UNSAFE); test("unsafeAllocateInstance", (Object) null); } @@ -387,12 +386,12 @@ for (int delta = Integer.MAX_VALUE - 10; delta < Integer.MAX_VALUE; delta++) { Object[] args1 = new Object[]{f1, offset, delta}; Object[] args2 = new Object[]{f2, offset, delta}; - testSubstitution("getAndAddInt", Unsafe.class, "getAndAddInt", parameterTypes, unsafe, args1, args2); + testSubstitution("getAndAddInt", Unsafe.class, "getAndAddInt", parameterTypes, UNSAFE, args1, args2); } } public static int getAndAddInt(Object obj, long offset, int delta) { - return unsafe.getAndAddInt(obj, offset, delta); + return UNSAFE.getAndAddInt(obj, offset, delta); } @Test @@ -404,12 +403,12 @@ for (long delta = Long.MAX_VALUE - 10; delta < Long.MAX_VALUE; delta++) { Object[] args1 = new Object[]{f1, offset, delta}; Object[] args2 = new Object[]{f2, offset, delta}; - testSubstitution("getAndAddLong", Unsafe.class, "getAndAddLong", parameterTypes, unsafe, args1, args2); + testSubstitution("getAndAddLong", Unsafe.class, "getAndAddLong", parameterTypes, UNSAFE, args1, args2); } } public static long getAndAddLong(Object obj, long offset, long delta) { - return unsafe.getAndAddLong(obj, offset, delta); + return UNSAFE.getAndAddLong(obj, offset, delta); } @Test @@ -421,12 +420,12 @@ for (int delta = Integer.MAX_VALUE - 10; delta < Integer.MAX_VALUE; delta++) { Object[] args1 = new Object[]{f1, offset, delta}; Object[] args2 = new Object[]{f2, offset, delta}; - testSubstitution("getAndSetInt", Unsafe.class, "getAndSetInt", parameterTypes, unsafe, args1, args2); + testSubstitution("getAndSetInt", Unsafe.class, "getAndSetInt", parameterTypes, UNSAFE, args1, args2); } } public static int getAndSetInt(Object obj, long offset, int newValue) { - return unsafe.getAndSetInt(obj, offset, newValue); + return UNSAFE.getAndSetInt(obj, offset, newValue); } @Test @@ -438,12 +437,12 @@ for (long newValue = Long.MAX_VALUE - 10; newValue < Long.MAX_VALUE; newValue++) { Object[] args1 = new Object[]{f1, offset, newValue}; Object[] args2 = new Object[]{f2, offset, newValue}; - testSubstitution("getAndSetLong", Unsafe.class, "getAndSetLong", parameterTypes, unsafe, args1, args2); + testSubstitution("getAndSetLong", Unsafe.class, "getAndSetLong", parameterTypes, UNSAFE, args1, args2); } } public static long getAndSetLong(Object obj, long offset, long newValue) { - return unsafe.getAndSetLong(obj, offset, newValue); + return UNSAFE.getAndSetLong(obj, offset, newValue); } @Test @@ -456,13 +455,13 @@ Object o = new Object(); Object[] args1 = new Object[]{f1, offset, o}; Object[] args2 = new Object[]{f2, offset, o}; - testSubstitution("getAndSetObject", Unsafe.class, "getAndSetObject", parameterTypes, unsafe, args1, args2); + testSubstitution("getAndSetObject", Unsafe.class, "getAndSetObject", parameterTypes, UNSAFE, args1, args2); System.gc(); } } public static Object getAndSetObject(Object obj, long offset, Object newValue) { - return unsafe.getAndSetObject(obj, offset, newValue); + return UNSAFE.getAndSetObject(obj, offset, newValue); } } diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetCounterNode.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetCounterNode.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetCounterNode.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,28 +22,34 @@ */ package com.oracle.graal.replacements; -import static com.oracle.graal.compiler.common.GraalOptions.*; -import static com.oracle.graal.replacements.SnippetTemplate.*; -import static jdk.internal.jvmci.common.UnsafeAccess.*; +import static com.oracle.graal.compiler.common.GraalOptions.SnippetCounters; +import static com.oracle.graal.replacements.SnippetTemplate.DEFAULT_REPLACER; -import java.util.*; +import java.lang.reflect.Field; +import java.util.Arrays; + +import jdk.internal.jvmci.code.TargetDescription; +import jdk.internal.jvmci.common.JVMCIError; +import jdk.internal.jvmci.meta.LocationIdentity; +import sun.misc.Unsafe; -import jdk.internal.jvmci.code.*; -import jdk.internal.jvmci.common.*; -import jdk.internal.jvmci.meta.*; - -import com.oracle.graal.api.replacements.*; -import com.oracle.graal.compiler.common.type.*; -import com.oracle.graal.graph.*; -import com.oracle.graal.nodeinfo.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.phases.util.*; +import com.oracle.graal.api.replacements.Fold; +import com.oracle.graal.api.replacements.SnippetReflectionProvider; +import com.oracle.graal.compiler.common.type.StampFactory; +import com.oracle.graal.graph.NodeClass; +import com.oracle.graal.nodeinfo.NodeInfo; +import com.oracle.graal.nodes.FixedWithNextNode; +import com.oracle.graal.nodes.NamedLocationIdentity; +import com.oracle.graal.nodes.StructuredGraph; +import com.oracle.graal.nodes.ValueNode; +import com.oracle.graal.nodes.spi.Lowerable; +import com.oracle.graal.nodes.spi.LoweringTool; +import com.oracle.graal.phases.util.Providers; import com.oracle.graal.replacements.Snippet.ConstantParameter; import com.oracle.graal.replacements.SnippetTemplate.AbstractTemplates; import com.oracle.graal.replacements.SnippetTemplate.Arguments; import com.oracle.graal.replacements.SnippetTemplate.SnippetInfo; -import com.oracle.graal.word.*; +import com.oracle.graal.word.ObjectAccess; /** * This node can be used to add a counter to the code that will estimate the dynamic number of calls @@ -123,7 +129,7 @@ @Fold private static int countOffset() { try { - return (int) unsafe.objectFieldOffset(SnippetCounter.class.getDeclaredField("value")); + return (int) UNSAFE.objectFieldOffset(SnippetCounter.class.getDeclaredField("value")); } catch (Exception e) { throw new JVMCIError(e); } @@ -154,4 +160,19 @@ } } + private static final Unsafe UNSAFE = initUnsafe(); + + private static Unsafe initUnsafe() { + try { + return Unsafe.getUnsafe(); + } catch (SecurityException se) { + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + return (Unsafe) theUnsafe.get(Unsafe.class); + } catch (Exception e) { + throw new RuntimeException("exception while trying to get Unsafe", e); + } + } + } } diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalTest.java --- a/graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalTest.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.test/src/com/oracle/graal/test/GraalTest.java Wed Sep 09 16:12:29 2015 +0200 @@ -29,11 +29,24 @@ import org.junit.*; import org.junit.internal.*; +import sun.misc.Unsafe; + /** * Base class that contains common utility methods and classes useful in unit tests. */ public class GraalTest { + public static final Unsafe UNSAFE; + static { + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + UNSAFE = (Unsafe) theUnsafe.get(Unsafe.class); + } catch (Exception e) { + throw new RuntimeException("exception while trying to get Unsafe", e); + } + } + protected Method getMethod(String methodName) { return getMethod(getClass(), methodName); } diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java --- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/HotSpotTruffleRuntime.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,47 +22,90 @@ */ package com.oracle.graal.truffle.hotspot; -import static com.oracle.graal.compiler.GraalCompiler.*; -import static com.oracle.graal.graph.util.CollectionsAccess.*; -import static com.oracle.graal.hotspot.meta.HotSpotSuitesProvider.*; -import static com.oracle.graal.truffle.TruffleCompilerOptions.*; -import static jdk.internal.jvmci.code.CodeUtil.*; +import static com.oracle.graal.compiler.GraalCompiler.compileGraph; +import static com.oracle.graal.compiler.GraalCompiler.getProfilingInfo; +import static com.oracle.graal.graph.util.CollectionsAccess.newIdentityMap; +import static com.oracle.graal.hotspot.meta.HotSpotSuitesProvider.withSimpleDebugInfoIfRequested; +import static com.oracle.graal.truffle.TruffleCompilerOptions.TraceTruffleStackTraceLimit; +import static com.oracle.graal.truffle.TruffleCompilerOptions.TraceTruffleTransferToInterpreter; +import static com.oracle.graal.truffle.TruffleCompilerOptions.TruffleCompilationExceptionsAreThrown; +import static com.oracle.graal.truffle.hotspot.UnsafeAccess.UNSAFE; +import static jdk.internal.jvmci.code.CodeUtil.getCallingConvention; -import java.util.*; -import java.util.concurrent.*; -import java.util.stream.*; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.ListIterator; +import java.util.Map; +import java.util.WeakHashMap; +import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.stream.Collectors; -import jdk.internal.jvmci.code.*; +import jdk.internal.jvmci.code.BailoutException; +import jdk.internal.jvmci.code.CallingConvention; import jdk.internal.jvmci.code.CallingConvention.Type; -import jdk.internal.jvmci.common.*; -import jdk.internal.jvmci.hotspot.*; -import jdk.internal.jvmci.meta.*; -import jdk.internal.jvmci.service.*; +import jdk.internal.jvmci.code.CodeCacheProvider; +import jdk.internal.jvmci.code.CompilationResult; +import jdk.internal.jvmci.common.JVMCIError; +import jdk.internal.jvmci.hotspot.HotSpotResolvedJavaMethod; +import jdk.internal.jvmci.hotspot.HotSpotSpeculationLog; +import jdk.internal.jvmci.hotspot.HotSpotVMConfig; +import jdk.internal.jvmci.meta.MetaAccessProvider; +import jdk.internal.jvmci.meta.ResolvedJavaMethod; +import jdk.internal.jvmci.meta.ResolvedJavaType; +import jdk.internal.jvmci.service.Services; -import com.oracle.graal.api.runtime.*; -import com.oracle.graal.compiler.*; -import com.oracle.graal.compiler.target.*; -import com.oracle.graal.debug.*; +import com.oracle.graal.api.runtime.Graal; +import com.oracle.graal.compiler.CompilerThreadFactory; +import com.oracle.graal.compiler.target.Backend; +import com.oracle.graal.debug.Debug; import com.oracle.graal.debug.Debug.Scope; -import com.oracle.graal.graphbuilderconf.*; +import com.oracle.graal.debug.DebugEnvironment; +import com.oracle.graal.debug.GraalDebugConfig; +import com.oracle.graal.debug.TTY; +import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration; import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.java.*; -import com.oracle.graal.lir.asm.*; -import com.oracle.graal.lir.phases.*; -import com.oracle.graal.nodes.*; +import com.oracle.graal.graphbuilderconf.InvocationPlugins; +import com.oracle.graal.hotspot.HotSpotGraalRuntime; +import com.oracle.graal.hotspot.meta.HotSpotProviders; +import com.oracle.graal.java.GraphBuilderPhase; +import com.oracle.graal.lir.asm.CompilationResultBuilderFactory; +import com.oracle.graal.lir.phases.LIRSuites; +import com.oracle.graal.nodes.StructuredGraph; import com.oracle.graal.nodes.StructuredGraph.AllowAssumptions; -import com.oracle.graal.phases.*; -import com.oracle.graal.phases.common.inlining.*; -import com.oracle.graal.phases.tiers.*; -import com.oracle.graal.phases.util.*; -import com.oracle.graal.runtime.*; -import com.oracle.graal.truffle.*; -import com.oracle.graal.truffle.hotspot.nfi.*; -import com.oracle.nfi.api.*; -import com.oracle.truffle.api.*; -import com.oracle.truffle.api.nodes.*; +import com.oracle.graal.phases.BasePhase; +import com.oracle.graal.phases.OptimisticOptimizations; +import com.oracle.graal.phases.PhaseSuite; +import com.oracle.graal.phases.common.inlining.InliningPhase; +import com.oracle.graal.phases.tiers.HighTierContext; +import com.oracle.graal.phases.tiers.Suites; +import com.oracle.graal.phases.tiers.SuitesProvider; +import com.oracle.graal.phases.util.Providers; +import com.oracle.graal.runtime.RuntimeProvider; +import com.oracle.graal.truffle.CompilationPolicy; +import com.oracle.graal.truffle.CounterAndTimeBasedCompilationPolicy; +import com.oracle.graal.truffle.DefaultTruffleCompiler; +import com.oracle.graal.truffle.GraalTruffleRuntime; +import com.oracle.graal.truffle.InterpreterOnlyCompilationPolicy; +import com.oracle.graal.truffle.OptimizedCallTarget; +import com.oracle.graal.truffle.OptimizedCallTargetInstrumentationFactory; +import com.oracle.graal.truffle.TruffleCallBoundary; +import com.oracle.graal.truffle.TruffleCompiler; +import com.oracle.graal.truffle.TruffleCompilerOptions; +import com.oracle.graal.truffle.TruffleTreeDumpHandler; +import com.oracle.graal.truffle.hotspot.nfi.HotSpotNativeFunctionInterface; +import com.oracle.graal.truffle.hotspot.nfi.RawNativeCallNodeFactory; +import com.oracle.nfi.api.NativeFunctionInterface; +import com.oracle.truffle.api.CompilerAsserts; +import com.oracle.truffle.api.RootCallTarget; +import com.oracle.truffle.api.TruffleRuntime; +import com.oracle.truffle.api.nodes.RootNode; /** * Implementation of the Truffle runtime when running on top of Graal. @@ -353,18 +396,18 @@ static { try { - THREAD_EETOP_OFFSET = UnsafeAccess.unsafe.objectFieldOffset(Thread.class.getDeclaredField("eetop")); + THREAD_EETOP_OFFSET = UNSAFE.objectFieldOffset(Thread.class.getDeclaredField("eetop")); } catch (Exception e) { throw new JVMCIError(e); } } static void traceTransferToInterpreter() { - long thread = UnsafeAccess.unsafe.getLong(Thread.currentThread(), THREAD_EETOP_OFFSET); + long thread = UNSAFE.getLong(Thread.currentThread(), THREAD_EETOP_OFFSET); long pendingTransferToInterpreterAddress = thread + HotSpotGraalRuntime.runtime().getConfig().pendingTransferToInterpreterOffset; - boolean deoptimized = UnsafeAccess.unsafe.getByte(pendingTransferToInterpreterAddress) != 0; + boolean deoptimized = UNSAFE.getByte(pendingTransferToInterpreterAddress) != 0; if (deoptimized) { - UnsafeAccess.unsafe.putByte(pendingTransferToInterpreterAddress, (byte) 0); + UNSAFE.putByte(pendingTransferToInterpreterAddress, (byte) 0); logTransferToInterpreter(); } diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/OptimizedCallTargetInstrumentation.java --- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/OptimizedCallTargetInstrumentation.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/OptimizedCallTargetInstrumentation.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,20 +22,25 @@ */ package com.oracle.graal.truffle.hotspot; -import java.lang.reflect.*; +import static com.oracle.graal.truffle.hotspot.UnsafeAccess.UNSAFE; -import jdk.internal.jvmci.code.*; -import jdk.internal.jvmci.code.CompilationResult.*; -import jdk.internal.jvmci.common.*; -import jdk.internal.jvmci.hotspot.*; +import java.lang.reflect.Field; -import com.oracle.graal.asm.*; -import com.oracle.graal.compiler.common.spi.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.lir.asm.*; -import com.oracle.graal.lir.framemap.*; -import com.oracle.graal.truffle.*; +import jdk.internal.jvmci.code.CodeCacheProvider; +import jdk.internal.jvmci.code.CompilationResult; +import jdk.internal.jvmci.code.CompilationResult.Mark; +import jdk.internal.jvmci.common.JVMCIError; +import jdk.internal.jvmci.hotspot.HotSpotCodeCacheProvider; +import jdk.internal.jvmci.hotspot.HotSpotVMConfig; + +import com.oracle.graal.asm.Assembler; +import com.oracle.graal.compiler.common.spi.ForeignCallsProvider; +import com.oracle.graal.hotspot.HotSpotGraalRuntime; +import com.oracle.graal.hotspot.meta.HotSpotRegistersProvider; +import com.oracle.graal.lir.asm.CompilationResultBuilder; +import com.oracle.graal.lir.asm.FrameContext; +import com.oracle.graal.lir.framemap.FrameMap; +import com.oracle.graal.truffle.OptimizedCallTarget; /** * Mechanism for injecting special code into {@link OptimizedCallTarget#call(Object[])} . @@ -62,7 +67,7 @@ try { declaringClass.getDeclaredField(name).setAccessible(true); Field field = declaringClass.getDeclaredField(name); - return (int) UnsafeAccess.unsafe.objectFieldOffset(field); + return (int) UNSAFE.objectFieldOffset(field); } catch (NoSuchFieldException | SecurityException e) { throw JVMCIError.shouldNotReachHere(); } diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/UnsafeAccess.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/UnsafeAccess.java Wed Sep 09 16:12:29 2015 +0200 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.truffle.hotspot; + +import java.lang.reflect.Field; + +import sun.misc.Unsafe; + +/** + * Package private access to the {@link Unsafe} capability. + */ +class UnsafeAccess { + + static final Unsafe UNSAFE = initUnsafe(); + + private static Unsafe initUnsafe() { + try { + // Fast path when we are trusted. + return Unsafe.getUnsafe(); + } catch (SecurityException se) { + // Slow path when we are not trusted. + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + return (Unsafe) theUnsafe.get(Unsafe.class); + } catch (Exception e) { + throw new RuntimeException("exception while trying to get Unsafe", e); + } + } + } +} diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/nfi/HotSpotNativeFunctionInterface.java --- a/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/nfi/HotSpotNativeFunctionInterface.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.truffle.hotspot/src/com/oracle/graal/truffle/hotspot/nfi/HotSpotNativeFunctionInterface.java Wed Sep 09 16:12:29 2015 +0200 @@ -24,9 +24,11 @@ import static com.oracle.graal.truffle.hotspot.nfi.NativeCallStubGraphBuilder.getGraph; import static jdk.internal.jvmci.code.CodeUtil.getCallingConvention; -import static jdk.internal.jvmci.common.UnsafeAccess.unsafe; import static jdk.internal.jvmci.common.UnsafeUtil.createCString; import static jdk.internal.jvmci.common.UnsafeUtil.writeCString; + +import java.lang.reflect.Field; + import jdk.internal.jvmci.code.CallingConvention; import jdk.internal.jvmci.code.CallingConvention.Type; import jdk.internal.jvmci.code.CompilationResult; @@ -34,6 +36,7 @@ import jdk.internal.jvmci.hotspot.HotSpotVMConfig; import jdk.internal.jvmci.meta.DefaultProfilingInfo; import jdk.internal.jvmci.meta.TriState; +import sun.misc.Unsafe; import com.oracle.graal.compiler.GraalCompiler; import com.oracle.graal.compiler.target.Backend; @@ -82,9 +85,9 @@ int ebufLen = 1024; // Allocating a single chunk for both the error message buffer and the // file name simplifies deallocation below. - long buffer = unsafe.allocateMemory(ebufLen + libPath.length() + 1); + long buffer = UNSAFE.allocateMemory(ebufLen + libPath.length() + 1); long ebuf = buffer; - long libPathCString = writeCString(unsafe, libPath, buffer + ebufLen); + long libPathCString = writeCString(UNSAFE, libPath, buffer + ebufLen); try { long handle = (long) libraryLookupFunctionHandle.call(libPathCString, ebuf, ebufLen); if (handle == 0) { @@ -92,7 +95,7 @@ } return new HotSpotNativeLibraryHandle(libPath, handle); } finally { - unsafe.freeMemory(buffer); + UNSAFE.freeMemory(buffer); } } @@ -132,7 +135,7 @@ dllLookupFunctionHandle = createHandle(functionLookupFunctionPointer, long.class, long.class, long.class); } - long nameCString = createCString(unsafe, name); + long nameCString = createCString(UNSAFE, name); try { long functionPointer = (long) dllLookupFunctionHandle.call(((HotSpotNativeLibraryHandle) library).value, nameCString); if (functionPointer == 0L) { @@ -143,7 +146,7 @@ } return new HotSpotNativeFunctionPointer(functionPointer, name); } finally { - unsafe.freeMemory(nameCString); + UNSAFE.freeMemory(nameCString); } } @@ -209,4 +212,20 @@ public NativeFunctionPointer getNativeFunctionPointerFromRawValue(long rawValue) { return new HotSpotNativeFunctionPointer(rawValue, null); } + + private static final Unsafe UNSAFE = initUnsafe(); + + private static Unsafe initUnsafe() { + try { + return Unsafe.getUnsafe(); + } catch (SecurityException se) { + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + return (Unsafe) theUnsafe.get(Unsafe.class); + } catch (Exception e) { + throw new RuntimeException("exception while trying to get Unsafe", e); + } + } + } } diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/ConditionAnchoringTest.java --- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/ConditionAnchoringTest.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/ConditionAnchoringTest.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,39 +22,50 @@ */ package com.oracle.graal.truffle.test; -import static com.oracle.graal.graph.test.matchers.NodeIterableCount.*; -import static com.oracle.graal.graph.test.matchers.NodeIterableIsEmpty.*; -import static org.hamcrest.core.IsInstanceOf.*; -import static org.junit.Assert.*; -import jdk.internal.jvmci.meta.*; +import static com.oracle.graal.graph.test.matchers.NodeIterableCount.hasCount; +import static com.oracle.graal.graph.test.matchers.NodeIterableIsEmpty.isEmpty; +import static org.hamcrest.core.IsInstanceOf.instanceOf; +import static org.junit.Assert.assertThat; +import jdk.internal.jvmci.meta.JavaKind; +import jdk.internal.jvmci.meta.JavaType; +import jdk.internal.jvmci.meta.ResolvedJavaMethod; -import org.junit.*; +import org.junit.Test; -import sun.misc.*; +import sun.misc.Unsafe; -import com.oracle.graal.compiler.test.*; -import com.oracle.graal.graph.iterators.*; -import com.oracle.graal.graphbuilderconf.*; +import com.oracle.graal.compiler.test.GraalCompilerTest; +import com.oracle.graal.graph.iterators.NodeIterable; +import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration; +import com.oracle.graal.graphbuilderconf.GraphBuilderContext; +import com.oracle.graal.graphbuilderconf.InlineInvokePlugin; import com.oracle.graal.graphbuilderconf.InvocationPlugins.Registration; -import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.BeginNode; +import com.oracle.graal.nodes.ConditionAnchorNode; +import com.oracle.graal.nodes.IfNode; +import com.oracle.graal.nodes.StructuredGraph; import com.oracle.graal.nodes.StructuredGraph.AllowAssumptions; -import com.oracle.graal.nodes.extended.*; -import com.oracle.graal.nodes.memory.*; +import com.oracle.graal.nodes.ValueNode; +import com.oracle.graal.nodes.extended.UnsafeLoadNode; +import com.oracle.graal.nodes.memory.FloatingReadNode; +import com.oracle.graal.nodes.memory.ReadNode; import com.oracle.graal.nodes.spi.LoweringTool.StandardLoweringStage; -import com.oracle.graal.phases.common.*; -import com.oracle.graal.phases.tiers.*; -import com.oracle.graal.truffle.nodes.*; -import com.oracle.graal.truffle.substitutions.*; +import com.oracle.graal.phases.common.CanonicalizerPhase; +import com.oracle.graal.phases.common.DominatorConditionalEliminationPhase; +import com.oracle.graal.phases.common.FloatingReadPhase; +import com.oracle.graal.phases.common.LoweringPhase; +import com.oracle.graal.phases.tiers.PhaseContext; +import com.oracle.graal.truffle.nodes.ObjectLocationIdentity; +import com.oracle.graal.truffle.substitutions.TruffleGraphBuilderPlugins; public class ConditionAnchoringTest extends GraalCompilerTest { private static final long offset; private static final Object location = new Object(); static { - Unsafe unsafe = jdk.internal.jvmci.common.UnsafeAccess.unsafe; long fieldOffset = 0; try { - fieldOffset = unsafe.objectFieldOffset(CheckedObject.class.getDeclaredField("field")); + fieldOffset = UNSAFE.objectFieldOffset(CheckedObject.class.getDeclaredField("field")); } catch (NoSuchFieldException | SecurityException e) { e.printStackTrace(); } @@ -69,7 +80,7 @@ public int checkedAccess(CheckedObject o) { if (o.id == 42) { - return UnsafeAccess.unsafeGetInt(o, offset, o.id == 42, location); + return MyUnsafeAccess.unsafeGetInt(o, offset, o.id == 42, location); } return -1; } @@ -77,7 +88,7 @@ // test with a different kind of condition (not a comparison against a constant) public int checkedAccess2(CheckedObject o) { if (o.id == o.iid) { - return UnsafeAccess.unsafeGetInt(o, offset, o.id == o.iid, location); + return MyUnsafeAccess.unsafeGetInt(o, offset, o.id == o.iid, location); } return -1; } @@ -135,7 +146,7 @@ @Override protected GraphBuilderConfiguration editGraphBuilderConfiguration(GraphBuilderConfiguration conf) { // get UnsafeAccessImpl.unsafeGetInt intrinsified - Registration r = new Registration(conf.getPlugins().getInvocationPlugins(), UnsafeAccess.class); + Registration r = new Registration(conf.getPlugins().getInvocationPlugins(), MyUnsafeAccess.class); TruffleGraphBuilderPlugins.registerUnsafeLoadStorePlugins(r, JavaKind.Int); // get UnsafeAccess.getInt inlined conf.getPlugins().appendInlineInvokePlugin(new InlineEverythingPlugin()); @@ -151,15 +162,15 @@ } @SuppressWarnings({"unused", "hiding"}) - private static final class UnsafeAccess { - private static final Unsafe UNSAFE = jdk.internal.jvmci.common.UnsafeAccess.unsafe; + private static final class MyUnsafeAccess { + private static final Unsafe MY_UNSAFE = UNSAFE; static int unsafeGetInt(Object receiver, long offset, boolean condition, Object locationIdentity) { - return UNSAFE.getInt(receiver, offset); + return MY_UNSAFE.getInt(receiver, offset); } static void unsafePutInt(Object receiver, long offset, int value, Object locationIdentity) { - UNSAFE.putInt(receiver, offset, value); + MY_UNSAFE.putInt(receiver, offset, value); } } } diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.word/src/com/oracle/graal/word/UnsafeAccess.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/UnsafeAccess.java Wed Sep 09 16:12:29 2015 +0200 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2012, 2012, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.word; + +import java.lang.reflect.Field; + +import sun.misc.Unsafe; + +/** + * Package private access to the {@link Unsafe} capability. + */ +class UnsafeAccess { + + static final Unsafe UNSAFE = initUnsafe(); + + private static Unsafe initUnsafe() { + try { + // Fast path when we are trusted. + return Unsafe.getUnsafe(); + } catch (SecurityException se) { + // Slow path when we are not trusted. + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + return (Unsafe) theUnsafe.get(Unsafe.class); + } catch (Exception e) { + throw new RuntimeException("exception while trying to get Unsafe", e); + } + } + } +} diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.graal.word/src/com/oracle/graal/word/Word.java --- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/Word.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/Word.java Wed Sep 09 16:12:29 2015 +0200 @@ -22,17 +22,32 @@ */ package com.oracle.graal.word; -import static jdk.internal.jvmci.common.UnsafeAccess.*; +import static com.oracle.graal.word.UnsafeAccess.UNSAFE; -import java.lang.annotation.*; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import jdk.internal.jvmci.code.UnsignedMath; +import jdk.internal.jvmci.common.JVMCIError; +import jdk.internal.jvmci.meta.LocationIdentity; -import jdk.internal.jvmci.code.*; -import jdk.internal.jvmci.common.*; -import jdk.internal.jvmci.meta.*; - -import com.oracle.graal.compiler.common.calc.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.calc.*; +import com.oracle.graal.compiler.common.calc.Condition; +import com.oracle.graal.nodes.ValueNode; +import com.oracle.graal.nodes.calc.AddNode; +import com.oracle.graal.nodes.calc.AndNode; +import com.oracle.graal.nodes.calc.IntegerDivNode; +import com.oracle.graal.nodes.calc.IntegerRemNode; +import com.oracle.graal.nodes.calc.LeftShiftNode; +import com.oracle.graal.nodes.calc.MulNode; +import com.oracle.graal.nodes.calc.OrNode; +import com.oracle.graal.nodes.calc.RightShiftNode; +import com.oracle.graal.nodes.calc.SubNode; +import com.oracle.graal.nodes.calc.UnsignedDivNode; +import com.oracle.graal.nodes.calc.UnsignedRemNode; +import com.oracle.graal.nodes.calc.UnsignedRightShiftNode; +import com.oracle.graal.nodes.calc.XorNode; import com.oracle.graal.nodes.memory.HeapAccess.BarrierType; import com.oracle.graal.nodes.memory.address.AddressNode.Address; @@ -664,49 +679,49 @@ @Override @Operation(opcode = Opcode.READ_POINTER) public byte readByte(WordBase offset, LocationIdentity locationIdentity) { - return unsafe.getByte(add((Word) offset).unbox()); + return UNSAFE.getByte(add((Word) offset).unbox()); } @Override @Operation(opcode = Opcode.READ_POINTER) public char readChar(WordBase offset, LocationIdentity locationIdentity) { - return unsafe.getChar(add((Word) offset).unbox()); + return UNSAFE.getChar(add((Word) offset).unbox()); } @Override @Operation(opcode = Opcode.READ_POINTER) public short readShort(WordBase offset, LocationIdentity locationIdentity) { - return unsafe.getShort(add((Word) offset).unbox()); + return UNSAFE.getShort(add((Word) offset).unbox()); } @Override @Operation(opcode = Opcode.READ_POINTER) public int readInt(WordBase offset, LocationIdentity locationIdentity) { - return unsafe.getInt(add((Word) offset).unbox()); + return UNSAFE.getInt(add((Word) offset).unbox()); } @Override @Operation(opcode = Opcode.READ_POINTER) public long readLong(WordBase offset, LocationIdentity locationIdentity) { - return unsafe.getLong(add((Word) offset).unbox()); + return UNSAFE.getLong(add((Word) offset).unbox()); } @Override @Operation(opcode = Opcode.READ_POINTER) public float readFloat(WordBase offset, LocationIdentity locationIdentity) { - return unsafe.getFloat(add((Word) offset).unbox()); + return UNSAFE.getFloat(add((Word) offset).unbox()); } @Override @Operation(opcode = Opcode.READ_POINTER) public double readDouble(WordBase offset, LocationIdentity locationIdentity) { - return unsafe.getDouble(add((Word) offset).unbox()); + return UNSAFE.getDouble(add((Word) offset).unbox()); } @Override @Operation(opcode = Opcode.READ_POINTER) public Word readWord(WordBase offset, LocationIdentity locationIdentity) { - return box(unsafe.getAddress(add((Word) offset).unbox())); + return box(UNSAFE.getAddress(add((Word) offset).unbox())); } @Override @@ -770,55 +785,55 @@ @Override @Operation(opcode = Opcode.WRITE_POINTER) public void writeByte(WordBase offset, byte val, LocationIdentity locationIdentity) { - unsafe.putByte(add((Word) offset).unbox(), val); + UNSAFE.putByte(add((Word) offset).unbox(), val); } @Override @Operation(opcode = Opcode.WRITE_POINTER) public void writeChar(WordBase offset, char val, LocationIdentity locationIdentity) { - unsafe.putChar(add((Word) offset).unbox(), val); + UNSAFE.putChar(add((Word) offset).unbox(), val); } @Override @Operation(opcode = Opcode.WRITE_POINTER) public void writeShort(WordBase offset, short val, LocationIdentity locationIdentity) { - unsafe.putShort(add((Word) offset).unbox(), val); + UNSAFE.putShort(add((Word) offset).unbox(), val); } @Override @Operation(opcode = Opcode.WRITE_POINTER) public void writeInt(WordBase offset, int val, LocationIdentity locationIdentity) { - unsafe.putInt(add((Word) offset).unbox(), val); + UNSAFE.putInt(add((Word) offset).unbox(), val); } @Override @Operation(opcode = Opcode.WRITE_POINTER) public void writeLong(WordBase offset, long val, LocationIdentity locationIdentity) { - unsafe.putLong(add((Word) offset).unbox(), val); + UNSAFE.putLong(add((Word) offset).unbox(), val); } @Override @Operation(opcode = Opcode.WRITE_POINTER) public void writeFloat(WordBase offset, float val, LocationIdentity locationIdentity) { - unsafe.putFloat(add((Word) offset).unbox(), val); + UNSAFE.putFloat(add((Word) offset).unbox(), val); } @Override @Operation(opcode = Opcode.WRITE_POINTER) public void writeDouble(WordBase offset, double val, LocationIdentity locationIdentity) { - unsafe.putDouble(add((Word) offset).unbox(), val); + UNSAFE.putDouble(add((Word) offset).unbox(), val); } @Override @Operation(opcode = Opcode.WRITE_POINTER) public void writeWord(WordBase offset, WordBase val, LocationIdentity locationIdentity) { - unsafe.putAddress(add((Word) offset).unbox(), ((Word) val).unbox()); + UNSAFE.putAddress(add((Word) offset).unbox(), ((Word) val).unbox()); } @Override @Operation(opcode = Opcode.INITIALIZE) public void initializeLong(WordBase offset, long val, LocationIdentity locationIdentity) { - unsafe.putLong(add((Word) offset).unbox(), val); + UNSAFE.putLong(add((Word) offset).unbox(), val); } @Override @@ -888,49 +903,49 @@ @Override @Operation(opcode = Opcode.READ_POINTER) public byte readByte(WordBase offset) { - return unsafe.getByte(add((Word) offset).unbox()); + return UNSAFE.getByte(add((Word) offset).unbox()); } @Override @Operation(opcode = Opcode.READ_POINTER) public char readChar(WordBase offset) { - return unsafe.getChar(add((Word) offset).unbox()); + return UNSAFE.getChar(add((Word) offset).unbox()); } @Override @Operation(opcode = Opcode.READ_POINTER) public short readShort(WordBase offset) { - return unsafe.getShort(add((Word) offset).unbox()); + return UNSAFE.getShort(add((Word) offset).unbox()); } @Override @Operation(opcode = Opcode.READ_POINTER) public int readInt(WordBase offset) { - return unsafe.getInt(add((Word) offset).unbox()); + return UNSAFE.getInt(add((Word) offset).unbox()); } @Override @Operation(opcode = Opcode.READ_POINTER) public long readLong(WordBase offset) { - return unsafe.getLong(add((Word) offset).unbox()); + return UNSAFE.getLong(add((Word) offset).unbox()); } @Override @Operation(opcode = Opcode.READ_POINTER) public float readFloat(WordBase offset) { - return unsafe.getFloat(add((Word) offset).unbox()); + return UNSAFE.getFloat(add((Word) offset).unbox()); } @Override @Operation(opcode = Opcode.READ_POINTER) public double readDouble(WordBase offset) { - return unsafe.getDouble(add((Word) offset).unbox()); + return UNSAFE.getDouble(add((Word) offset).unbox()); } @Override @Operation(opcode = Opcode.READ_POINTER) public Word readWord(WordBase offset) { - return box(unsafe.getAddress(add((Word) offset).unbox())); + return box(UNSAFE.getAddress(add((Word) offset).unbox())); } @Override @@ -1002,49 +1017,49 @@ @Override @Operation(opcode = Opcode.WRITE_POINTER) public void writeByte(WordBase offset, byte val) { - unsafe.putByte(add((Word) offset).unbox(), val); + UNSAFE.putByte(add((Word) offset).unbox(), val); } @Override @Operation(opcode = Opcode.WRITE_POINTER) public void writeChar(WordBase offset, char val) { - unsafe.putChar(add((Word) offset).unbox(), val); + UNSAFE.putChar(add((Word) offset).unbox(), val); } @Override @Operation(opcode = Opcode.WRITE_POINTER) public void writeShort(WordBase offset, short val) { - unsafe.putShort(add((Word) offset).unbox(), val); + UNSAFE.putShort(add((Word) offset).unbox(), val); } @Override @Operation(opcode = Opcode.WRITE_POINTER) public void writeInt(WordBase offset, int val) { - unsafe.putInt(add((Word) offset).unbox(), val); + UNSAFE.putInt(add((Word) offset).unbox(), val); } @Override @Operation(opcode = Opcode.WRITE_POINTER) public void writeLong(WordBase offset, long val) { - unsafe.putLong(add((Word) offset).unbox(), val); + UNSAFE.putLong(add((Word) offset).unbox(), val); } @Override @Operation(opcode = Opcode.WRITE_POINTER) public void writeFloat(WordBase offset, float val) { - unsafe.putFloat(add((Word) offset).unbox(), val); + UNSAFE.putFloat(add((Word) offset).unbox(), val); } @Override @Operation(opcode = Opcode.WRITE_POINTER) public void writeDouble(WordBase offset, double val) { - unsafe.putDouble(add((Word) offset).unbox(), val); + UNSAFE.putDouble(add((Word) offset).unbox(), val); } @Override @Operation(opcode = Opcode.WRITE_POINTER) public void writeWord(WordBase offset, WordBase val) { - unsafe.putAddress(add((Word) offset).unbox(), ((Word) val).unbox()); + UNSAFE.putAddress(add((Word) offset).unbox(), ((Word) val).unbox()); } @Override diff -r f08fed409c49 -r 9f0e536ee385 graal/com.oracle.nfi.test/test/com/oracle/nfi/test/NativeFunctionInterfaceTest.java --- a/graal/com.oracle.nfi.test/test/com/oracle/nfi/test/NativeFunctionInterfaceTest.java Wed Sep 09 13:38:21 2015 +0200 +++ b/graal/com.oracle.nfi.test/test/com/oracle/nfi/test/NativeFunctionInterfaceTest.java Wed Sep 09 16:12:29 2015 +0200 @@ -25,7 +25,6 @@ import static java.io.File.separatorChar; import static java.lang.System.getProperty; import static java.lang.System.mapLibraryName; -import static jdk.internal.jvmci.common.UnsafeAccess.unsafe; import static jdk.internal.jvmci.common.UnsafeUtil.writeCString; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -34,6 +33,7 @@ import static org.junit.Assume.assumeTrue; import java.io.File; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; @@ -43,6 +43,8 @@ import org.junit.Before; import org.junit.Test; +import sun.misc.Unsafe; + import com.oracle.nfi.NativeFunctionInterfaceRuntime; import com.oracle.nfi.api.NativeFunctionHandle; import com.oracle.nfi.api.NativeFunctionInterface; @@ -51,6 +53,18 @@ public class NativeFunctionInterfaceTest { + private static final Unsafe unsafe = initUnsafe(); + + private static Unsafe initUnsafe() { + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + return (Unsafe) theUnsafe.get(Unsafe.class); + } catch (Exception e) { + throw new RuntimeException("exception while trying to get Unsafe", e); + } + } + public final NativeFunctionInterface nfi; public NativeFunctionInterfaceTest() { diff -r f08fed409c49 -r 9f0e536ee385 mx.graal/suite.py --- a/mx.graal/suite.py Wed Sep 09 13:38:21 2015 +0200 +++ b/mx.graal/suite.py Wed Sep 09 16:12:29 2015 +0200 @@ -6,7 +6,7 @@ "suites": [ { "name" : "jvmci", - "version" : "df2764d92a3c36d9f2de05c6c24db818184c7b7c", + "version" : "15579668ec3aedb968b0bb4ecb26b596e6b123b3", "urls" : [ {"url" : "http://lafo.ssw.uni-linz.ac.at/hg/graal-jvmci-8", "kind" : "hg"}, {"url" : "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind" : "binary"},