1 /* 2 * Copyright (c) 2015, 2018, 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.amd64.AMD64Kind; 41 import jdk.vm.ci.meta.JavaConstant; 42 import jdk.vm.ci.meta.Value; 43 44 public class StackStoreTest extends LIRTest { 45 @Before 46 public void checkAMD64() { 47 assumeTrue("skipping AMD64 specific test", getTarget().arch instanceof AMD64); 48 } 49 50 private static final LIRTestSpecification stackCopy0 = new LIRTestSpecification() { 51 @Override 52 public void generate(LIRGeneratorTool gen, Value a) { 53 FrameMapBuilder frameMapBuilder = gen.getResult().getFrameMapBuilder(); 54 // create slots 55 VirtualStackSlot s1 = frameMapBuilder.allocateSpillSlot(a.getValueKind()); 56 VirtualStackSlot s2 = frameMapBuilder.allocateSpillSlot(LIRKind.value(AMD64Kind.WORD)); 57 // move stuff around 58 gen.emitMove(s1, a); 59 gen.emitMoveConstant(s2, JavaConstant.forShort(Short.MIN_VALUE)); 60 setResult(gen.emitMove(s1)); 61 gen.emitBlackhole(s1); 62 gen.emitBlackhole(s2); 63 } 64 }; 65 66 private static final LIRTestSpecification stackCopy1 = new LIRTestSpecification() { 67 @Override 68 public void generate(LIRGeneratorTool gen, Value a) { 69 FrameMapBuilder frameMapBuilder = gen.getResult().getFrameMapBuilder(); 70 // create slots 71 VirtualStackSlot s1 = frameMapBuilder.allocateSpillSlot(a.getValueKind()); 72 VirtualStackSlot s2 = frameMapBuilder.allocateSpillSlot(LIRKind.value(AMD64Kind.WORD)); 73 // move stuff around 74 gen.emitMove(s1, a); 75 Value v = gen.emitLoadConstant(LIRKind.value(AMD64Kind.WORD), JavaConstant.forShort(Short.MIN_VALUE)); 76 gen.emitMove(s2, v); 77 setResult(gen.emitMove(s1)); 78 gen.emitBlackhole(s1); 79 gen.emitBlackhole(s2); 80 } 81 }; 82 83 private static final LIRTestSpecification stackCopy2 = new LIRTestSpecification() { 84 @Override 85 public void generate(LIRGeneratorTool gen, Value a) { 86 FrameMapBuilder frameMapBuilder = gen.getResult().getFrameMapBuilder(); 87 // create slots 88 VirtualStackSlot s1 = frameMapBuilder.allocateSpillSlot(a.getValueKind()); 89 VirtualStackSlot s2 = frameMapBuilder.allocateSpillSlot(LIRKind.value(AMD64Kind.WORD)); 90 // move stuff around 91 gen.emitMoveConstant(s2, JavaConstant.forShort(Short.MIN_VALUE)); 92 gen.emitMove(s1, a); 93 setResult(gen.emitMove(s2)); 94 gen.emitBlackhole(s1); 95 gen.emitBlackhole(s2); 96 } 97 }; 98 99 @SuppressWarnings("unused") 100 @LIRIntrinsic 101 public static int testShortStackSlot(LIRTestSpecification spec, int a) { 102 return a; 103 } 104 105 @SuppressWarnings("unused") 106 @LIRIntrinsic 107 public static short testShortStackSlot2(LIRTestSpecification spec, int a) { 108 return Short.MIN_VALUE; 109 } 110 111 public int test0(int a) { 112 return testShortStackSlot(stackCopy0, a); 113 } 114 115 @Test 116 public void run0() throws Throwable { 117 runTest("test0", 0xDEADDEAD); 118 } 119 120 public int test1(int a) { 121 return testShortStackSlot(stackCopy1, a); 122 } 123 124 @Test 125 public void run1() throws Throwable { 126 runTest("test1", 0xDEADDEAD); 127 } 128 129 public int test2(int a) { 130 return testShortStackSlot2(stackCopy2, a); 131 } 132 133 @Test 134 public void run2() throws Throwable { 135 runTest("test2", 0xDEADDEAD); 136 } 137 138 }