Mercurial > hg > graal-compiler
changeset 22004:85a6fc0b4129
StackMoveTest: verify stack integrity.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Thu, 18 Jun 2015 11:42:07 +0200 |
parents | ebc9990ec12d |
children | f00f1f9df48e |
files | graal/com.oracle.graal.lir.jtt/src/com/oracle/graal/lir/jtt/StackMoveTest.java |
diffstat | 1 files changed, 128 insertions(+), 72 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.lir.jtt/src/com/oracle/graal/lir/jtt/StackMoveTest.java Tue Jun 16 17:55:27 2015 +0200 +++ b/graal/com.oracle.graal.lir.jtt/src/com/oracle/graal/lir/jtt/StackMoveTest.java Thu Jun 18 11:42:07 2015 +0200 @@ -24,25 +24,47 @@ import org.junit.*; +import com.oracle.graal.lir.*; import com.oracle.graal.lir.framemap.*; import com.oracle.graal.lir.gen.*; import com.oracle.jvmci.code.*; import com.oracle.jvmci.meta.*; public class StackMoveTest extends LIRTest { - private static final LIRTestSpecification stackCopy = new LIRTestSpecification() { + private static class StackCopySpec extends LIRTestSpecification { @Override public void generate(LIRGeneratorTool gen, Value a) { FrameMapBuilder frameMapBuilder = gen.getResult().getFrameMapBuilder(); + LIRKind lirKind = getLIRKind(a); + // create slots - StackSlotValue s1 = frameMapBuilder.allocateSpillSlot(a.getLIRKind()); - StackSlotValue s2 = frameMapBuilder.allocateSpillSlot(a.getLIRKind()); - // move stuff around + StackSlotValue s1 = frameMapBuilder.allocateSpillSlot(lirKind); + StackSlotValue s2 = frameMapBuilder.allocateSpillSlot(lirKind); + + // start emit gen.emitMove(s1, a); + Value copy1 = gen.emitMove(s1); gen.append(gen.getSpillMoveFactory().createStackMove(s2, s1)); - setResult(gen.emitMove(s2)); + Variable result = gen.emitMove(s2); + // end emit + + // set output and result + setResult(result); + setOutput("slotcopy", copy1); + setOutput("slot1", s1); + setOutput("slot2", s2); } - }; + + protected LIRKind getLIRKind(Value value) { + return value.getLIRKind(); + } + } + + private static final LIRTestSpecification stackCopy = new StackCopySpec(); + + /* + * int + */ @SuppressWarnings("unused") @LIRIntrinsic @@ -50,103 +72,118 @@ return a; } - public int testInt(int a) { - return copyInt(stackCopy, a); + public int[] testInt(int a, int[] out) { + out[0] = copyInt(stackCopy, a); + out[1] = getOutput(stackCopy, "slotcopy", a); + out[2] = getOutput(stackCopy, "slot1", a); + out[3] = getOutput(stackCopy, "slot2", a); + return out; } @Test public void runInt() throws Throwable { - runTest("testInt", Integer.MIN_VALUE); - runTest("testInt", -1); - runTest("testInt", 0); - runTest("testInt", 1); - runTest("testInt", Integer.MAX_VALUE); + runTest("testInt", Integer.MIN_VALUE, supply(() -> new int[3])); + runTest("testInt", -1, supply(() -> new int[4])); + runTest("testInt", 0, supply(() -> new int[3])); + runTest("testInt", 1, supply(() -> new int[3])); + runTest("testInt", Integer.MAX_VALUE, supply(() -> new int[3])); } + /* + * long + */ + @SuppressWarnings("unused") @LIRIntrinsic public static long copyLong(LIRTestSpecification spec, long a) { return a; } - public long testLong(long a) { - return copyLong(stackCopy, a); + public long[] testLong(long a, long[] out) { + out[0] = copyLong(stackCopy, a); + out[1] = getOutput(stackCopy, "slotcopy", a); + out[2] = getOutput(stackCopy, "slot1", a); + out[3] = getOutput(stackCopy, "slot2", a); + return out; } @Test public void runLong() throws Throwable { - runTest("testLong", Long.MIN_VALUE); - runTest("testLong", -1L); - runTest("testLong", 0L); - runTest("testLong", 1L); - runTest("testLong", Long.MAX_VALUE); + runTest("testLong", Long.MIN_VALUE, supply(() -> new long[3])); + runTest("testLong", -1L, supply(() -> new long[3])); + runTest("testLong", 0L, supply(() -> new long[3])); + runTest("testLong", 1L, supply(() -> new long[3])); + runTest("testLong", Long.MAX_VALUE, supply(() -> new long[3])); } + /* + * float + */ + @SuppressWarnings("unused") @LIRIntrinsic public static float copyFloat(LIRTestSpecification spec, float a) { return a; } - public float testFloat(float a) { - return copyFloat(stackCopy, a); + public float[] testFloat(float a, float[] out) { + out[0] = copyFloat(stackCopy, a); + out[1] = getOutput(stackCopy, "slotcopy", a); + out[2] = getOutput(stackCopy, "slot1", a); + out[3] = getOutput(stackCopy, "slot2", a); + return out; } @Test public void runFloat() throws Throwable { - runTest("testFloat", Float.MIN_VALUE); - runTest("testFloat", -1f); - runTest("testFloat", -0.1f); - runTest("testFloat", 0f); - runTest("testFloat", 0.1f); - runTest("testFloat", 1f); - runTest("testFloat", Float.MAX_VALUE); + runTest("testFloat", Float.MIN_VALUE, supply(() -> new float[3])); + runTest("testFloat", -1f, supply(() -> new float[3])); + runTest("testFloat", -0.1f, supply(() -> new float[3])); + runTest("testFloat", 0f, supply(() -> new float[3])); + runTest("testFloat", 0.1f, supply(() -> new float[3])); + runTest("testFloat", 1f, supply(() -> new float[3])); + runTest("testFloat", Float.MAX_VALUE, supply(() -> new float[3])); } + /* + * double + */ + @SuppressWarnings("unused") @LIRIntrinsic public static double copyDouble(LIRTestSpecification spec, double a) { return a; } - public double testDouble(double a) { - return copyDouble(stackCopy, a); + public double[] testDouble(double a, double[] out) { + out[0] = copyDouble(stackCopy, a); + out[1] = getOutput(stackCopy, "slotcopy", a); + out[2] = getOutput(stackCopy, "slot1", a); + out[3] = getOutput(stackCopy, "slot2", a); + return out; } @Test public void runDouble() throws Throwable { - runTest("testDouble", Double.MIN_VALUE); - runTest("testDouble", -1.); - runTest("testDouble", -0.1); - runTest("testDouble", 0.); - runTest("testDouble", 0.1); - runTest("testDouble", 1.); - runTest("testDouble", Double.MAX_VALUE); + runTest("testDouble", Double.MIN_VALUE, supply(() -> new double[3])); + runTest("testDouble", -1., supply(() -> new double[3])); + runTest("testDouble", -0.1, supply(() -> new double[3])); + runTest("testDouble", 0., supply(() -> new double[3])); + runTest("testDouble", 0.1, supply(() -> new double[3])); + runTest("testDouble", 1., supply(() -> new double[3])); + runTest("testDouble", Double.MAX_VALUE, supply(() -> new double[3])); } - private static final class SubIntStackCopySpec extends LIRTestSpecification { - private final Kind kind; + /* + * short + */ - public SubIntStackCopySpec(Kind kind) { - this.kind = kind; - } - + private static final LIRTestSpecification shortStackCopy = new StackCopySpec() { @Override - public void generate(LIRGeneratorTool gen, Value a) { - FrameMapBuilder frameMapBuilder = gen.getResult().getFrameMapBuilder(); - // create slots - LIRKind lirKind = LIRKind.value(kind); - StackSlotValue s1 = frameMapBuilder.allocateSpillSlot(lirKind); - StackSlotValue s2 = frameMapBuilder.allocateSpillSlot(lirKind); - // move stuff around - gen.emitMove(s1, a); - gen.append(gen.getSpillMoveFactory().createStackMove(s2, s1)); - setResult(gen.emitMove(s2)); + protected LIRKind getLIRKind(Value value) { + return LIRKind.value(Kind.Short); } - } - - private static final LIRTestSpecification shortStackCopy = new SubIntStackCopySpec(Kind.Short); - private static final LIRTestSpecification byteStackCopy = new SubIntStackCopySpec(Kind.Byte); + }; @SuppressWarnings("unused") @LIRIntrinsic @@ -154,35 +191,54 @@ return a; } - public int testShort(short a) { - return copyInt(shortStackCopy, a); + public short[] testShort(short a, short[] out) { + out[0] = copyShort(shortStackCopy, a); + out[1] = getOutput(shortStackCopy, "slotcopy", a); + out[2] = getOutput(shortStackCopy, "slot1", a); + out[3] = getOutput(shortStackCopy, "slot2", a); + return out; } @Test public void runShort() throws Throwable { - runTest("testShort", Short.MIN_VALUE); - runTest("testShort", (short) -1); - runTest("testShort", (short) 0); - runTest("testShort", (short) 1); - runTest("testShort", Short.MAX_VALUE); + runTest("testShort", Short.MIN_VALUE, supply(() -> new short[3])); + runTest("testShort", (short) -1, supply(() -> new short[3])); + runTest("testShort", (short) 0, supply(() -> new short[3])); + runTest("testShort", (short) 1, supply(() -> new short[3])); + runTest("testShort", Short.MAX_VALUE, supply(() -> new short[3])); } + /* + * byte + */ + + private static final LIRTestSpecification byteStackCopy = new StackCopySpec() { + @Override + protected LIRKind getLIRKind(Value value) { + return LIRKind.value(Kind.Byte); + } + }; + @SuppressWarnings("unused") @LIRIntrinsic public static byte copyByte(LIRTestSpecification spec, byte a) { return a; } - public int testByte(byte a) { - return copyInt(byteStackCopy, a); + public byte[] testByte(byte a, byte[] out) { + out[0] = copyByte(byteStackCopy, a); + out[1] = getOutput(byteStackCopy, "slotcopy", a); + out[2] = getOutput(byteStackCopy, "slot1", a); + out[3] = getOutput(byteStackCopy, "slot2", a); + return out; } @Test public void runByte() throws Throwable { - runTest("testByte", Byte.MIN_VALUE); - runTest("testByte", (byte) -1); - runTest("testByte", (byte) 0); - runTest("testByte", (byte) 1); - runTest("testByte", Byte.MAX_VALUE); + runTest("testByte", Byte.MIN_VALUE, supply(() -> new byte[3])); + runTest("testByte", (byte) -1, supply(() -> new byte[3])); + runTest("testByte", (byte) 0, supply(() -> new byte[3])); + runTest("testByte", (byte) 1, supply(() -> new byte[3])); + runTest("testByte", Byte.MAX_VALUE, supply(() -> new byte[3])); } }