rev 52889 : 8214023: Update Graal

   1 /*
   2  * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 
  25 package org.graalvm.compiler.core.amd64.test;
  26 
  27 import static org.junit.Assume.assumeTrue;
  28 
  29 import org.junit.Before;
  30 import org.junit.Test;
  31 
  32 import org.graalvm.compiler.core.common.LIRKind;
  33 import org.graalvm.compiler.lir.VirtualStackSlot;
  34 import org.graalvm.compiler.lir.framemap.FrameMapBuilder;
  35 import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
  36 import org.graalvm.compiler.lir.jtt.LIRTest;
  37 import org.graalvm.compiler.lir.jtt.LIRTestSpecification;
  38 
  39 import jdk.vm.ci.amd64.AMD64;
  40 import jdk.vm.ci.meta.JavaConstant;
  41 import jdk.vm.ci.meta.PrimitiveConstant;
  42 
  43 public class ConstantStackMoveTest extends LIRTest {
  44     @Before
  45     public void checkAMD64() {
  46         assumeTrue("skipping AMD64 specific test", getTarget().arch instanceof AMD64);
  47     }
  48 
  49     private static class LoadConstantStackSpec extends LIRTestSpecification {
  50         protected final Object primitive;
  51 
  52         LoadConstantStackSpec(Object primitive) {
  53             this.primitive = primitive;
  54         }
  55 
  56         @Override
  57         public void generate(LIRGeneratorTool gen) {
  58             FrameMapBuilder frameMapBuilder = gen.getResult().getFrameMapBuilder();
  59             // create slots
  60             PrimitiveConstant constantValue = JavaConstant.forBoxedPrimitive(primitive);
  61             VirtualStackSlot s1 = frameMapBuilder.allocateSpillSlot(LIRKind.fromJavaKind(gen.target().arch, constantValue.getJavaKind()));
  62             // move stuff around
  63             gen.emitMoveConstant(s1, constantValue);
  64             gen.emitBlackhole(s1);
  65             setResult(gen.emitMove(s1));
  66         }
  67     }
  68 
  69     private static final class LoadConstantStackSpecByte extends LoadConstantStackSpec {
  70         LoadConstantStackSpecByte(byte primitive) {
  71             super(primitive);
  72         }
  73 
  74         byte get() {
  75             return (Byte) primitive;
  76         }
  77     }
  78 
  79     private static final class LoadConstantStackSpecShort extends LoadConstantStackSpec {
  80         LoadConstantStackSpecShort(short primitive) {
  81             super(primitive);
  82         }
  83 
  84         short get() {
  85             return (Short) primitive;
  86         }
  87     }
  88 
  89     private static final class LoadConstantStackSpecInteger extends LoadConstantStackSpec {
  90         LoadConstantStackSpecInteger(int primitive) {
  91             super(primitive);
  92         }
  93 
  94         int get() {
  95             return (Integer) primitive;
  96         }
  97     }
  98 
  99     private static final class LoadConstantStackSpecLong extends LoadConstantStackSpec {
 100         LoadConstantStackSpecLong(long primitive) {
 101             super(primitive);
 102         }
 103 
 104         long get() {
 105             return (Long) primitive;
 106         }
 107     }
 108 
 109     private static final class LoadConstantStackSpecFloat extends LoadConstantStackSpec {
 110         LoadConstantStackSpecFloat(float primitive) {
 111             super(primitive);
 112         }
 113 
 114         float get() {
 115             return (Float) primitive;
 116         }
 117     }
 118 
 119     private static final class LoadConstantStackSpecDouble extends LoadConstantStackSpec {
 120         LoadConstantStackSpecDouble(double primitive) {
 121             super(primitive);
 122         }
 123 
 124         double get() {
 125             return (Double) primitive;
 126         }
 127     }
 128 
 129     private static final LoadConstantStackSpecByte stackCopyByte = new LoadConstantStackSpecByte(Byte.MAX_VALUE);
 130     private static final LoadConstantStackSpecShort stackCopyShort = new LoadConstantStackSpecShort(Short.MAX_VALUE);
 131     private static final LoadConstantStackSpecInteger stackCopyInt = new LoadConstantStackSpecInteger(Integer.MAX_VALUE);
 132     private static final LoadConstantStackSpecLong stackCopyLong = new LoadConstantStackSpecLong(Long.MAX_VALUE);
 133     private static final LoadConstantStackSpecFloat stackCopyFloat = new LoadConstantStackSpecFloat(Float.MAX_VALUE);
 134     private static final LoadConstantStackSpecDouble stackCopyDouble = new LoadConstantStackSpecDouble(Double.MAX_VALUE);
 135 
 136     @LIRIntrinsic
 137     public static byte testCopyByte(LoadConstantStackSpecByte spec) {
 138         return spec.get();
 139     }
 140 
 141     public byte testByte() {
 142         return testCopyByte(stackCopyByte);
 143     }
 144 
 145     @Test
 146     public void runByte() throws Throwable {
 147         runTest("testByte");
 148     }
 149 
 150     @LIRIntrinsic
 151     public static short testCopyShort(LoadConstantStackSpecShort spec) {
 152         return spec.get();
 153     }
 154 
 155     public short testShort() {
 156         return testCopyShort(stackCopyShort);
 157     }
 158 
 159     @Test
 160     public void runShort() throws Throwable {
 161         runTest("testShort");
 162     }
 163 
 164     @LIRIntrinsic
 165     public static int testCopyInt(LoadConstantStackSpecInteger spec) {
 166         return spec.get();
 167     }
 168 
 169     public int testInt() {
 170         return testCopyInt(stackCopyInt);
 171     }
 172 
 173     @Test
 174     public void runInt() throws Throwable {
 175         runTest("testInt");
 176     }
 177 
 178     @LIRIntrinsic
 179     public static long testCopyLong(LoadConstantStackSpecLong spec) {
 180         return spec.get();
 181     }
 182 
 183     public long testLong() {
 184         return testCopyLong(stackCopyLong);
 185     }
 186 
 187     @Test
 188     public void runLong() throws Throwable {
 189         runTest("testLong");
 190     }
 191 
 192     @LIRIntrinsic
 193     public static float testCopyFloat(LoadConstantStackSpecFloat spec) {
 194         return spec.get();
 195     }
 196 
 197     public float testFloat() {
 198         return testCopyFloat(stackCopyFloat);
 199     }
 200 
 201     @Test
 202     public void runFloat() throws Throwable {
 203         runTest("testFloat");
 204     }
 205 
 206     @LIRIntrinsic
 207     public static double testCopyDouble(LoadConstantStackSpecDouble spec) {
 208         return spec.get();
 209     }
 210 
 211     public double testDouble() {
 212         return testCopyDouble(stackCopyDouble);
 213     }
 214 
 215     @Test
 216     public void runDouble() throws Throwable {
 217         runTest("testDouble");
 218     }
 219 
 220 }
--- EOF ---