001/* 002 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023package com.oracle.graal.compiler.amd64.test; 024 025import jdk.internal.jvmci.amd64.*; 026import jdk.internal.jvmci.code.*; 027import jdk.internal.jvmci.meta.*; 028import static org.junit.Assume.*; 029 030import org.junit.*; 031 032import com.oracle.graal.lir.framemap.*; 033import com.oracle.graal.lir.gen.*; 034import com.oracle.graal.lir.jtt.*; 035 036public class StackStoreTest extends LIRTest { 037 @Before 038 public void checkAMD64() { 039 assumeTrue("skipping AMD64 specific test", getTarget().arch instanceof AMD64); 040 } 041 042 private static final LIRTestSpecification stackCopy0 = new LIRTestSpecification() { 043 @Override 044 public void generate(LIRGeneratorTool gen, Value a) { 045 FrameMapBuilder frameMapBuilder = gen.getResult().getFrameMapBuilder(); 046 // create slots 047 StackSlotValue s1 = frameMapBuilder.allocateSpillSlot(a.getLIRKind()); 048 StackSlotValue s2 = frameMapBuilder.allocateSpillSlot(LIRKind.value(Kind.Short)); 049 // move stuff around 050 gen.emitMove(s1, a); 051 gen.emitMove(s2, JavaConstant.forShort(Short.MIN_VALUE)); 052 setResult(gen.emitMove(s1)); 053 gen.emitBlackhole(s1); 054 gen.emitBlackhole(s2); 055 } 056 }; 057 058 private static final LIRTestSpecification stackCopy1 = new LIRTestSpecification() { 059 @Override 060 public void generate(LIRGeneratorTool gen, Value a) { 061 FrameMapBuilder frameMapBuilder = gen.getResult().getFrameMapBuilder(); 062 // create slots 063 StackSlotValue s1 = frameMapBuilder.allocateSpillSlot(a.getLIRKind()); 064 StackSlotValue s2 = frameMapBuilder.allocateSpillSlot(LIRKind.value(Kind.Short)); 065 // move stuff around 066 gen.emitMove(s1, a); 067 Value v = gen.emitMove(JavaConstant.forShort(Short.MIN_VALUE)); 068 gen.emitMove(s2, v); 069 setResult(gen.emitMove(s1)); 070 gen.emitBlackhole(s1); 071 gen.emitBlackhole(s2); 072 } 073 }; 074 075 private static final LIRTestSpecification stackCopy2 = new LIRTestSpecification() { 076 @Override 077 public void generate(LIRGeneratorTool gen, Value a) { 078 FrameMapBuilder frameMapBuilder = gen.getResult().getFrameMapBuilder(); 079 // create slots 080 StackSlotValue s1 = frameMapBuilder.allocateSpillSlot(a.getLIRKind()); 081 StackSlotValue s2 = frameMapBuilder.allocateSpillSlot(LIRKind.value(Kind.Short)); 082 // move stuff around 083 gen.emitMove(s2, JavaConstant.forShort(Short.MIN_VALUE)); 084 gen.emitMove(s1, a); 085 setResult(gen.emitMove(s2)); 086 gen.emitBlackhole(s1); 087 gen.emitBlackhole(s2); 088 } 089 }; 090 091 @SuppressWarnings("unused") 092 @LIRIntrinsic 093 public static int testShortStackSlot(LIRTestSpecification spec, int a) { 094 return a; 095 } 096 097 @SuppressWarnings("unused") 098 @LIRIntrinsic 099 public static short testShortStackSlot2(LIRTestSpecification spec, int a) { 100 return Short.MIN_VALUE; 101 } 102 103 public int test0(int a) { 104 return testShortStackSlot(stackCopy0, a); 105 } 106 107 @Test 108 public void run0() throws Throwable { 109 runTest("test0", 0xDEADDEAD); 110 } 111 112 public int test1(int a) { 113 return testShortStackSlot(stackCopy1, a); 114 } 115 116 @Test 117 public void run1() throws Throwable { 118 runTest("test1", 0xDEADDEAD); 119 } 120 121 public int test2(int a) { 122 return testShortStackSlot2(stackCopy2, a); 123 } 124 125 @Test 126 public void run2() throws Throwable { 127 runTest("test2", 0xDEADDEAD); 128 } 129 130}