src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/AMD64ArrayEqualsOp.java
changeset 48861 47f19ff9903c
parent 47798 9fe9292f5931
child 50858 2d3e99a72541
equal deleted inserted replaced
48860:5bce1b7e7800 48861:47f19ff9903c
    20  * or visit www.oracle.com if you need additional information or have any
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 package org.graalvm.compiler.lir.amd64;
    23 package org.graalvm.compiler.lir.amd64;
    24 
    24 
       
    25 import static jdk.vm.ci.code.ValueUtil.asRegister;
    25 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.ILLEGAL;
    26 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.ILLEGAL;
    26 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;
    27 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;
    27 import static jdk.vm.ci.code.ValueUtil.asRegister;
       
    28 
       
    29 import java.lang.reflect.Array;
       
    30 import java.lang.reflect.Field;
       
    31 
    28 
    32 import org.graalvm.compiler.asm.Label;
    29 import org.graalvm.compiler.asm.Label;
    33 import org.graalvm.compiler.asm.amd64.AMD64Address;
    30 import org.graalvm.compiler.asm.amd64.AMD64Address;
    34 import org.graalvm.compiler.asm.amd64.AMD64Address.Scale;
    31 import org.graalvm.compiler.asm.amd64.AMD64Address.Scale;
    35 import org.graalvm.compiler.asm.amd64.AMD64Assembler.ConditionFlag;
    32 import org.graalvm.compiler.asm.amd64.AMD64Assembler.ConditionFlag;
    48 import jdk.vm.ci.amd64.AMD64Kind;
    45 import jdk.vm.ci.amd64.AMD64Kind;
    49 import jdk.vm.ci.code.Register;
    46 import jdk.vm.ci.code.Register;
    50 import jdk.vm.ci.code.TargetDescription;
    47 import jdk.vm.ci.code.TargetDescription;
    51 import jdk.vm.ci.meta.JavaKind;
    48 import jdk.vm.ci.meta.JavaKind;
    52 import jdk.vm.ci.meta.Value;
    49 import jdk.vm.ci.meta.Value;
    53 import sun.misc.Unsafe;
       
    54 
    50 
    55 /**
    51 /**
    56  * Emits code which compares two arrays of the same length. If the CPU supports any vector
    52  * Emits code which compares two arrays of the same length. If the CPU supports any vector
    57  * instructions specialized code is emitted to leverage these instructions.
    53  * instructions specialized code is emitted to leverage these instructions.
    58  */
    54  */
    81 
    77 
    82     public AMD64ArrayEqualsOp(LIRGeneratorTool tool, JavaKind kind, Value result, Value array1, Value array2, Value length) {
    78     public AMD64ArrayEqualsOp(LIRGeneratorTool tool, JavaKind kind, Value result, Value array1, Value array2, Value length) {
    83         super(TYPE);
    79         super(TYPE);
    84         this.kind = kind;
    80         this.kind = kind;
    85 
    81 
    86         Class<?> arrayClass = Array.newInstance(kind.toJavaClass(), 0).getClass();
    82         this.arrayBaseOffset = tool.getProviders().getArrayOffsetProvider().arrayBaseOffset(kind);
    87         this.arrayBaseOffset = UNSAFE.arrayBaseOffset(arrayClass);
    83         this.arrayIndexScale = tool.getProviders().getArrayOffsetProvider().arrayScalingFactor(kind);
    88         this.arrayIndexScale = UNSAFE.arrayIndexScale(arrayClass);
       
    89 
    84 
    90         this.resultValue = result;
    85         this.resultValue = result;
    91         this.array1Value = array1;
    86         this.array1Value = array1;
    92         this.array2Value = array2;
    87         this.array2Value = array2;
    93         this.lengthValue = length;
    88         this.lengthValue = length;
   529         masm.addq(i, kind.getByteCount());
   524         masm.addq(i, kind.getByteCount());
   530         masm.jccb(ConditionFlag.NotZero, loop);
   525         masm.jccb(ConditionFlag.NotZero, loop);
   531         // Floats within the range are equal, revert change to the register index
   526         // Floats within the range are equal, revert change to the register index
   532         masm.subq(index, range);
   527         masm.subq(index, range);
   533     }
   528     }
   534 
       
   535     private static final Unsafe UNSAFE = initUnsafe();
       
   536 
       
   537     private static Unsafe initUnsafe() {
       
   538         try {
       
   539             return Unsafe.getUnsafe();
       
   540         } catch (SecurityException se) {
       
   541             try {
       
   542                 Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
       
   543                 theUnsafe.setAccessible(true);
       
   544                 return (Unsafe) theUnsafe.get(Unsafe.class);
       
   545             } catch (Exception e) {
       
   546                 throw new RuntimeException("exception while trying to get Unsafe", e);
       
   547             }
       
   548         }
       
   549     }
       
   550 }
   529 }