changeset 13660:d2976008ce63

Merge.
author Chris Seaton <chris.seaton@oracle.com>
date Thu, 16 Jan 2014 21:47:17 +0000
parents 62bfc12dc9e1 (current diff) 3730b9979305 (diff)
children 434b86962d0d
files graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXTestBase.java graal/com.oracle.graal.hotspot.ptx.test/src/com/oracle/graal/hotspot/ptx/test/PTXLaunchKernelTest.java graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXGraphProducer.java graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXLaunchKernelGraphKit.java
diffstat 21 files changed, 593 insertions(+), 1139 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ArrayPTXTest.java	Wed Jan 15 19:54:48 2014 +0000
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ArrayPTXTest.java	Thu Jan 16 21:47:17 2014 +0000
@@ -24,34 +24,28 @@
 
 import static com.oracle.graal.lir.ptx.ThreadDimension.*;
 
-import java.lang.reflect.*;
-import java.util.*;
-
 import org.junit.*;
 
 import com.oracle.graal.lir.ptx.*;
 
-public class ArrayPTXTest extends PTXTestBase {
+public class ArrayPTXTest extends PTXTest {
 
+    @Ignore("PTXHotSpotForeignCallsProvider.lookupForeignCall() is unimplemented")
     @Test
-    public void testArray() {
-        int[] array1 = {1, 2, 3, 4, 5, 6, 7, 8, 9};
-        int[] array2 = {1, 2, 3, 4, 5, 6, 7, 8, 9};
-        int[] array3 = {1, 2, 3, 4, 5, 6, 7, 8, 9};
+    public void test1() {
+        test("testStoreArray1I", new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, 2);
+    }
 
-        invoke(compile("testStoreArray1I"), array1, 2);
-        if (array1[2] == 42) {
-            printReport("testStoreArray1I: " + Arrays.toString(array1) + " PASSED");
-        } else {
-            printReport("testStoreArray1I: " + Arrays.toString(array1) + " FAILED");
-        }
+    @Ignore("PTXHotSpotForeignCallsProvider.lookupForeignCall() is unimplemented")
+    @Test
+    public void test2() {
+        test("testStoreArrayWarp0", new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, 2);
+    }
 
-        invoke(compile("testStoreArrayWarp0"), array2, 2);
-        printReport("testStoreArrayWarp0: " + Arrays.toString(array2));
-
-        invoke(compile("testStoreArrayWarp1I"), array3, 2);
-        printReport("testStoreArrayWarp1I: " + Arrays.toString(array3));
-
+    @Ignore("PTXHotSpotForeignCallsProvider.lookupForeignCall() is unimplemented")
+    @Test
+    public void test3() {
+        test("testStoreArrayWarp1I", new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, 2);
     }
 
     public static void testStoreArray1I(int[] array, int i) {
@@ -67,12 +61,6 @@
     }
 
     public static void main(String[] args) {
-        ArrayPTXTest test = new ArrayPTXTest();
-        for (Method m : ArrayPTXTest.class.getMethods()) {
-            String name = m.getName();
-            if (m.getAnnotation(Test.class) == null && name.startsWith("test")) {
-                printReport(name + ": \n" + new String(test.compile(name).getTargetCode()));
-            }
-        }
+        compileAndPrintCode(new ArrayPTXTest());
     }
 }
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/BasicPTXTest.java	Wed Jan 15 19:54:48 2014 +0000
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/BasicPTXTest.java	Thu Jan 16 21:47:17 2014 +0000
@@ -22,37 +22,41 @@
  */
 package com.oracle.graal.compiler.ptx.test;
 
-import java.lang.reflect.*;
-
 import org.junit.*;
 
 /**
  * Test class for small Java methods compiled to PTX kernels.
  */
-public class BasicPTXTest extends PTXTestBase {
+public class BasicPTXTest extends PTXTest {
 
     @Test
-    public void testAdd() {
-        invoke(compile("testConstI"));
-    }
-
-    @Test
-    public void testInvoke() {
-        invoke(compile("testConstI"));
+    public void test() {
+        test("testConstI");
     }
 
     public static int testConstI() {
         return 42;
     }
 
+    @Test
+    public void testStaticIntKernel() {
+        test("staticIntKernel", 'a', 42);
+    }
+
+    @Test
+    public void testVirtualIntKernel() {
+        test("virtualIntKernel", 'a', 42);
+    }
+
+    public static int staticIntKernel(char p0, int p1) {
+        return p1 + p0;
+    }
+
+    public int virtualIntKernel(char p0, int p1) {
+        return p1 + p0;
+    }
+
     public static void main(String[] args) {
-        BasicPTXTest test = new BasicPTXTest();
-        Method[] methods = BasicPTXTest.class.getMethods();
-        for (Method m : methods) {
-            String name = m.getName();
-            if (m.getAnnotation(Test.class) == null && name.startsWith("test")) {
-                printReport(name + ": \n" + new String(test.compile(name).getTargetCode()));
-            }
-        }
+        compileAndPrintCode(new BasicPTXTest());
     }
 }
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ControlPTXTest.java	Wed Jan 15 19:54:48 2014 +0000
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ControlPTXTest.java	Thu Jan 16 21:47:17 2014 +0000
@@ -22,96 +22,22 @@
  */
 package com.oracle.graal.compiler.ptx.test;
 
-import java.lang.reflect.*;
-
 import org.junit.*;
 
-public class ControlPTXTest extends PTXTestBase {
+public class ControlPTXTest extends PTXTest {
 
     @Test
     public void testControl() {
-        String testName = "testLoop";
-        int argVal1 = 42;
-        int argVal2;
-        Integer ret = (Integer) invoke(compile(testName), argVal1);
-        int jres = testLoop(argVal1);
-        if (ret != null) {
-            if (ret.intValue() == jres) {
-                printReport(testName + ": PASSED");
-            } else {
-                printReport(testName + ": FAILED " + "Expected " + jres + " Got " + ret);
-            }
-        } else {
-            printReport(testName + ": FAILED (null returned)");
-        }
-
-        testName = "testSwitchDefault1I";
-        argVal1 = 3;
-        ret = (Integer) invoke(compile(testName), argVal1);
-        jres = testSwitchDefault1I(argVal1);
-        if (ret != null) {
-            if (ret.intValue() == jres) {
-                printReport(testName + ": PASSED");
-            } else {
-                printReport(testName + ": FAILED " + "Expected " + jres + " Got " + ret);
-            }
-        } else {
-            printReport(testName + ": FAILED (null returned)");
-        }
+        test("testLoop", 42);
+        test("testSwitchDefault1I", 3);
+        test("testSwitch1I", 2);
+        test("testIfElse1I", 222);
+        test("testIfElse2I", 19, 64);
 
-        testName = "testSwitch1I";
-        argVal1 = 2;
-        ret = (Integer) invoke(compile(testName), argVal1);
-        jres = testSwitch1I(argVal1);
-        if (ret != null) {
-            if (ret.intValue() == jres) {
-                printReport(testName + ": PASSED");
-            } else {
-                printReport(testName + ": FAILED " + "Expected " + jres + " Got " + ret);
-            }
-        } else {
-            printReport(testName + ": FAILED (null returned)");
-        }
-
-        testName = "testIfElse1I";
-        argVal1 = 222;
-        ret = (Integer) invoke(compile(testName), argVal1);
-        jres = testIfElse1I(argVal1);
-        if (ret != null) {
-            if (ret.intValue() == jres) {
-                printReport(testName + ": PASSED");
-            } else {
-                printReport(testName + ": FAILED " + "Expected " + jres + " Got " + ret);
-            }
-        } else {
-            printReport(testName + ": FAILED (null returned)");
-        }
-
-        testName = "testIfElse2I";
-        argVal1 = 19;
-        argVal2 = 64;
-        ret = (Integer) invoke(compile(testName), argVal1, argVal2);
-        jres = testIfElse2I(argVal1, argVal2);
-        if (ret != null) {
-            if (ret.intValue() == jres) {
-                printReport(testName + ": PASSED");
-            } else {
-                printReport(testName + ": FAILED " + "Expected " + jres + " Got " + ret);
-            }
-        } else {
-            printReport(testName + ": FAILED " + "Expected " + jres + " Got " + ret);
-        }
-
-        Boolean bret = (Boolean) invoke(compile("testIntegerTestBranch2I"), 0xff00, 0x00ff);
-        if (bret != null) {
-            printReport("testIntegerTestBranch2I: " + bret);
-            printReport("testIntegerTestBranch2I: actual: " + testIntegerTestBranch2I(0xff00, 0x00ff));
-        } else {
-            printReport("testIntegerTestBranch2I: no VALUE");
-        }
-        compile("testStatic");
-        compile("testCall");
-        compile("testLookupSwitch1I");
+        test("testIntegerTestBranch2I", 0xff00, 0x00ff);
+        compileKernel("testStatic");
+        compileKernel("testCall");
+        compileKernel("testLookupSwitch1I");
     }
 
     public static boolean testIntegerTestBranch2I(int x, int y) {
@@ -210,12 +136,6 @@
     }
 
     public static void main(String[] args) {
-        ControlPTXTest test = new ControlPTXTest();
-        for (Method m : ControlPTXTest.class.getMethods()) {
-            String name = m.getName();
-            if (m.getAnnotation(Test.class) == null && name.startsWith("test")) {
-                printReport(name + ": \n" + new String(test.compile(name).getTargetCode()));
-            }
-        }
+        compileAndPrintCode(new ControlPTXTest());
     }
 }
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/FloatPTXTest.java	Wed Jan 15 19:54:48 2014 +0000
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/FloatPTXTest.java	Thu Jan 16 21:47:17 2014 +0000
@@ -22,45 +22,17 @@
  */
 package com.oracle.graal.compiler.ptx.test;
 
-import java.lang.reflect.Method;
-
 import org.junit.*;
 
-import com.oracle.graal.api.code.CompilationResult;
-
 /* PTX ISA 3.1 - 8.7.3 Floating-Point Instructions */
-public class FloatPTXTest extends PTXTestBase {
+public class FloatPTXTest extends PTXTest {
 
     @Test
     public void testAdd() {
-        Float ret = (Float) invoke(compile("testAdd2I"), 42, 43);
-        if (ret != null) {
-            printReport("testAdd2I: " + ret);
-        } else {
-            printReport("testAdd2I: no VALUE");
-        }
-
-        ret = (Float) invoke(compile("testAdd2F"), 42.1F, 43.5F);
-        if (ret != null) {
-            printReport("testAdd2F: " + ret);
-        } else {
-            printReport("testAdd2F: no VALUE");
-        }
-
-        ret = (Float) invoke(compile("testAddFConst"), 42.1F);
-        if (ret != null) {
-            printReport("testAddFConst: " + ret);
-        } else {
-            printReport("testAddFConst: no VALUE");
-        }
-
-        Double dret = (Double) invoke(compile("testAdd2D"), 42.1, 43.5);
-        if (dret != null) {
-            printReport("testAdd2D: " + dret);
-        } else {
-            printReport("testAdd2D: no VALUE");
-        }
-
+        test("testAdd2I", 42, 43);
+        test("testAdd2F", 42.1F, 43.5F);
+        test("testAddFConst", 42.1F);
+        test("testAdd2D", 42.1, 43.5);
     }
 
     public static float testAdd2I(int a, int b) {
@@ -94,35 +66,12 @@
     @Ignore
     @Test
     public void testSub() {
-        CompilationResult r = compile("testSub2F");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testSub2F FAILED");
-        }
-
-        r = compile("testSub2D");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testSub2D FAILED");
-        }
-
-        r = compile("testSubFConst");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testSubFConst FAILED");
-        }
-
-        r = compile("testSubConstF");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testSubConstF FAILED");
-        }
-
-        r = compile("testSubDConst");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testSubDconst FAILED");
-        }
-
-        r = compile("testSubConstD");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testConstD FAILED");
-        }
+        compileKernel("testSub2F");
+        compileKernel("testSub2D");
+        compileKernel("testSubFConst");
+        compileKernel("testSubConstF");
+        compileKernel("testSubDConst");
+        compileKernel("testSubConstD");
     }
 
     public static float testSub2F(float a, float b) {
@@ -152,35 +101,12 @@
     @Ignore
     @Test
     public void testMul() {
-        CompilationResult r = compile("testMul2F");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testAdd2F FAILED");
-        }
-
-        r = compile("testMul2D");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testAdd2F FAILED");
-        }
-
-        r = compile("testMulFConst");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testAdd2F FAILED");
-        }
-
-        r = compile("testMulConstF");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testAdd2F FAILED");
-        }
-
-        r = compile("testMulDConst");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testAdd2F FAILED");
-        }
-
-        r = compile("testMulConstD");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testAdd2F FAILED");
-        }
+        compileKernel("testMul2F");
+        compileKernel("testMul2D");
+        compileKernel("testMulFConst");
+        compileKernel("testMulConstF");
+        compileKernel("testMulDConst");
+        compileKernel("testMulConstD");
     }
 
     public static float testMul2F(float a, float b) {
@@ -210,35 +136,12 @@
     @Ignore
     @Test
     public void testDiv() {
-        CompilationResult r = compile("testDiv2F");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testDiv2F FAILED");
-        }
-
-        r = compile("testDiv2D");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testDiv2D FAILED");
-        }
-
-        r = compile("testDivFConst");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testDivFConst FAILED");
-        }
-
-        r = compile("testDivConstF");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testDivConstF FAILED");
-        }
-
-        r = compile("testDivDConst");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testDivDConst FAILED");
-        }
-
-        r = compile("testDivConstD");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testDivConstD FAILED");
-        }
+        compileKernel("testDiv2F");
+        compileKernel("testDiv2D");
+        compileKernel("testDivFConst");
+        compileKernel("testDivConstF");
+        compileKernel("testDivDConst");
+        compileKernel("testDivConstD");
     }
 
     public static float testDiv2F(float a, float b) {
@@ -268,15 +171,8 @@
     @Ignore
     @Test
     public void testNeg() {
-        CompilationResult r = compile("testNeg2F");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testNeg2F FAILED");
-        }
-
-        r = compile("testNeg2D");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testNeg2D FAILED");
-        }
+        compileKernel("testNeg2F");
+        compileKernel("testNeg2D");
     }
 
     public static float testNeg2F(float a) {
@@ -291,8 +187,8 @@
     @Test
     public void testRem() {
         // need linkage to PTX remainder()
-        // compile("testRem2F");
-        // compile("testRem2D");
+        // compileKernel("testRem2F");
+        // compileKernel("testRem2D");
     }
 
     public static float testRem2F(float a, float b) {
@@ -306,35 +202,12 @@
     @Ignore
     @Test
     public void testFloatConversion() {
-        CompilationResult r = compile("testF2I");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of tesF2I FAILED");
-        }
-
-        r = compile("testF2L");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testF2L FAILED");
-        }
-
-        r = compile("testF2D");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testF2D FAILED");
-        }
-
-        r = compile("testD2I");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testD2I FAILED");
-        }
-
-        r = compile("testD2L");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testD2L FAILED");
-        }
-
-        r = compile("testD2F");
-        if (r.getTargetCode() == null) {
-            printReport("Compilation of testD2F FAILED");
-        }
+        compileKernel("testF2I");
+        compileKernel("testF2L");
+        compileKernel("testF2D");
+        compileKernel("testD2I");
+        compileKernel("testD2L");
+        compileKernel("testD2F");
     }
 
     public static int testF2I(float a) {
@@ -362,12 +235,6 @@
     }
 
     public static void main(String[] args) {
-        FloatPTXTest test = new FloatPTXTest();
-        for (Method m : FloatPTXTest.class.getMethods()) {
-            String name = m.getName();
-            if (m.getAnnotation(Test.class) == null && name.startsWith("test") && name.startsWith("testRem") == false) {
-                printReport(name + ": \n" + new String(test.compile(name).getTargetCode()));
-            }
-        }
+        compileAndPrintCode(new FloatPTXTest());
     }
 }
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/IntegerPTXTest.java	Wed Jan 15 19:54:48 2014 +0000
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/IntegerPTXTest.java	Thu Jan 16 21:47:17 2014 +0000
@@ -24,59 +24,18 @@
 
 import org.junit.*;
 
+import java.io.*;
 import java.lang.reflect.Method;
 
-public class IntegerPTXTest extends PTXTestBase {
+public class IntegerPTXTest extends PTXTest {
 
     @Test
     public void testAdd() {
-
-        // @formatter:off
-        Integer r4 = (Integer) invoke(compile("testAdd2B"), (byte) 6, (byte) 4);
-        if (r4 == null) {
-            printReport("testAdd2B FAILED");
-        } else if (r4.intValue() == testAdd2B((byte) 6, (byte) 4)) {
-            printReport("testAdd2B PASSED");
-        } else {
-            printReport("testAdd2B FAILED");
-        }
-        // @formatter:on
-
-        r4 = (Integer) invoke(compile("testAdd2I"), 18, 24);
-        if (r4 == null) {
-            printReport("testAdd2I FAILED");
-        } else if (r4.intValue() == testAdd2I(18, 24)) {
-            printReport("testAdd2I PASSED");
-        } else {
-            printReport("testAdd2I FAILED");
-        }
-
-        Long r2 = (Long) invoke(compile("testAdd2L"), (long) 12, (long) 6);
-        if (r2 == null) {
-            printReport("testAdd2L FAILED");
-        } else if (r2.longValue() == testAdd2L(12, 6)) {
-            printReport("testAdd2L PASSED");
-        } else {
-            printReport("testAdd2L FAILED");
-        }
-
-        r4 = (Integer) invoke(compile("testAddIConst"), 5);
-        if (r4 == null) {
-            printReport("testAddIConst FAILED");
-        } else if (r4.intValue() == testAddIConst(5)) {
-            printReport("testAddIConst PASSED");
-        } else {
-            printReport("testAddIConst FAILED");
-        }
-
-        r4 = (Integer) invoke(compile("testAddConstI"), 7);
-        if (r4 == null) {
-            printReport("testAddConstI FAILED");
-        } else if (r4.intValue() == testAddConstI(7)) {
-            printReport("testAddConstI PASSED");
-        } else {
-            printReport("testAddConstI FAILED");
-        }
+        test("testAdd2B", (byte) 6, (byte) 4);
+        test("testAdd2I", 18, 24);
+        test("testAdd2L", (long) 12, (long) 6);
+        test("testAddIConst", 5);
+        test("testAddConstI", 7);
     }
 
     public static int testAdd2I(int a, int b) {
@@ -101,43 +60,10 @@
 
     @Test
     public void testSub() {
-
-        Integer r1 = (Integer) invoke(compile("testSub2I"), 18, 4);
-
-        if (r1 == null) {
-            printReport("testSub2I FAILED");
-        } else if (r1.intValue() == testSub2I(18, 4)) {
-            printReport("testSub2I PASSED");
-        } else {
-            printReport("testSub2I FAILED");
-        }
-
-        Long r2 = (Long) invoke(compile("testSub2L"), (long) 12, (long) 6);
-        if (r2 == null) {
-            printReport("testSub2I FAILED (null return value)");
-        } else if (r2.longValue() == testSub2L(12, 6)) {
-            printReport("testSub2I PASSED");
-        } else {
-            printReport("testSub2I FAILED");
-        }
-
-        r1 = (Integer) invoke(compile("testSubIConst"), 35);
-        if (r1 == null) {
-            printReport("testSubIConst FAILED");
-        } else if (r1.intValue() == testSubIConst(35)) {
-            printReport("testSubIConst PASSED");
-        } else {
-            printReport("testSubIConst FAILED");
-        }
-
-        r1 = (Integer) invoke(compile("testSubConstI"), 12);
-        if (r1 == null) {
-            printReport("testSubConstI FAILED");
-        } else if (r1.intValue() == testSubConstI(12)) {
-            printReport("testSubConstI PASSED");
-        } else {
-            printReport("testSubConstI FAILED");
-        }
+        test("testSub2I", 18, 4);
+        test("testSub2L", (long) 12, (long) 6);
+        test("testSubIConst", 35);
+        test("testSubConstI", 12);
     }
 
     public static int testSub2I(int a, int b) {
@@ -158,42 +84,10 @@
 
     @Test
     public void testMul() {
-
-        Integer r1 = (Integer) invoke(compile("testMul2I"), 8, 4);
-        if (r1 == null) {
-            printReport("testMul2I FAILED");
-        } else if (r1.intValue() == testMul2I(8, 4)) {
-            printReport("testMul2I PASSED");
-        } else {
-            printReport("testMul2I FAILED");
-        }
-
-        Long r2 = (Long) invoke(compile("testMul2L"), (long) 12, (long) 6);
-        if (r2 == null) {
-            printReport("testMul2L FAILED");
-        } else if (r2.longValue() == testMul2L(12, 6)) {
-            printReport("testMul2L PASSED");
-        } else {
-            printReport("testMul2L FAILED");
-        }
-
-        r1 = (Integer) invoke(compile("testMulIConst"), 4);
-        if (r1 == null) {
-            printReport("testMulIConst FAILED");
-        } else if (r1.intValue() == testMulIConst(4)) {
-            printReport("testMulIConst PASSED");
-        } else {
-            printReport("testMulIConst FAILED");
-        }
-
-        r1 = (Integer) invoke(compile("testMulConstI"), 5);
-        if (r1 == null) {
-            printReport("testMulConstI FAILED");
-        } else if (r1.intValue() == testMulConstI(5)) {
-            printReport("testMulConstI PASSED");
-        } else {
-            printReport("testMulConstI FAILED");
-        }
+        test("testMul2I", 8, 4);
+        test("testMul2L", (long) 12, (long) 6);
+        test("testMulIConst", 4);
+        test("testMulConstI", 5);
     }
 
     public static int testMul2I(int a, int b) {
@@ -214,41 +108,10 @@
 
     @Test
     public void testDiv() {
-        Integer r1 = (Integer) invoke(compile("testDiv2I"), 8, 4);
-        if (r1 == null) {
-            printReport("testDiv2I FAILED (null value returned)");
-        } else if (r1.intValue() == testDiv2I(8, 4)) {
-            printReport("testDiv2I PASSED");
-        } else {
-            printReport("testDiv2I FAILED");
-        }
-
-        Long r2 = (Long) invoke(compile("testDiv2L"), (long) 12, (long) 6);
-        if (r2 == null) {
-            printReport("testDiv2L FAILED (null value returned)");
-        } else if (r2.longValue() == testDiv2L(12, 6)) {
-            printReport("testDiv2L PASSED");
-        } else {
-            printReport("testDiv2L FAILED");
-        }
-
-        r1 = (Integer) invoke(compile("testDivIConst"), 64);
-        if (r1 == null) {
-            printReport("testDivIConst FAILED (null value returned)");
-        } else if (r1.intValue() == testDivIConst(64)) {
-            printReport("testDivIConst PASSED");
-        } else {
-            printReport("testDivIConst FAILED");
-        }
-
-        r1 = (Integer) invoke(compile("testDivConstI"), 8);
-        if (r1 == null) {
-            printReport("testDivConstI FAILED (null value returned)");
-        } else if (r1.intValue() == testDivConstI(8)) {
-            printReport("testDivConstI PASSED");
-        } else {
-            printReport("testDivConstI FAILED");
-        }
+        test("testDiv2I", 8, 4);
+        test("testDiv2L", (long) 12, (long) 6);
+        test("testDivIConst", 64);
+        test("testDivConstI", 8);
     }
 
     public static int testDiv2I(int a, int b) {
@@ -269,23 +132,8 @@
 
     @Test
     public void testRem() {
-        Integer r1 = (Integer) invoke(compile("testRem2I"), 8, 4);
-        if (r1 == null) {
-            printReport("testRem2I FAILED (null value returned)");
-        } else if (r1.intValue() == testRem2I(8, 4)) {
-            printReport("testRem2I PASSED");
-        } else {
-            printReport("testRem2I FAILED");
-        }
-
-        Long r2 = (Long) invoke(compile("testRem2L"), (long) 12, (long) 6);
-        if (r2 == null) {
-            printReport("testRem2L FAILED (null value returned)");
-        } else if (r1.longValue() == testRem2L(12, 6)) {
-            printReport("testRem2L PASSED");
-        } else {
-            printReport("testRem2L FAILED");
-        }
+        test("testRem2I", 8, 4);
+        test("testRem2L", (long) 12, (long) 6);
     }
 
     public static int testRem2I(int a, int b) {
@@ -299,28 +147,12 @@
     @Ignore
     @Test
     public void testIntConversion() {
-        Long r1 = (Long) invoke(compile("testI2L"), 8);
-        if (r1 == null) {
-            printReport("testI2L FAILED (null value returned)");
-        } else if (r1.longValue() == testI2L(8)) {
-            printReport("testI2L PASSED");
-        } else {
-            printReport("testI2L FAILED");
-        }
-
-        Integer r2 = (Integer) invoke(compile("testL2I"), (long) 12);
-        if (r2 == null) {
-            printReport("testL2I FAILED (null value returned)");
-        } else if (r1.longValue() == testL2I(12)) {
-            printReport("testL2I PASSED");
-        } else {
-            printReport("testL2I FAILED");
-        }
-
-        // invoke(compile("testI2C"), 65);
-        // invoke(compile("testI2B"), 9);
-        // invoke(compile("testI2F"), 17);
-        // invoke(compile("testI2D"), 22);
+        test("testI2L", 8);
+        test("testL2I", (long) 12);
+        // test("testI2C", 65);
+        // test("testI2B", 9);
+        // test("testI2F", 17);
+        // test("testI2D", 22);
     }
 
     public static long testI2L(int a) {
@@ -352,7 +184,8 @@
         for (Method m : IntegerPTXTest.class.getMethods()) {
             String name = m.getName();
             if (m.getAnnotation(Test.class) == null && name.startsWith("test")) {
-                printReport(name + ": \n" + new String(test.compile(name).getTargetCode()));
+                PrintStream out = System.out;
+                out.println(name + ": \n" + new String(test.compileKernel(name).getTargetCode()));
             }
         }
     }
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/LogicPTXTest.java	Wed Jan 15 19:54:48 2014 +0000
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/LogicPTXTest.java	Thu Jan 16 21:47:17 2014 +0000
@@ -22,17 +22,15 @@
  */
 package com.oracle.graal.compiler.ptx.test;
 
-import java.lang.reflect.Method;
-
-import org.junit.Test;
+import org.junit.*;
 
 /* PTX ISA 3.1 - 8.7.5 Logic and Shift Instructions */
-public class LogicPTXTest extends PTXTestBase {
+public class LogicPTXTest extends PTXTest {
 
     @Test
     public void testAnd() {
-        compile("testAnd2I");
-        compile("testAnd2L");
+        compileKernel("testAnd2I");
+        compileKernel("testAnd2L");
     }
 
     public static int testAnd2I(int a, int b) {
@@ -45,8 +43,8 @@
 
     @Test
     public void testOr() {
-        compile("testOr2I");
-        compile("testOr2L");
+        compileKernel("testOr2I");
+        compileKernel("testOr2L");
     }
 
     public static int testOr2I(int a, int b) {
@@ -59,8 +57,8 @@
 
     @Test
     public void testXor() {
-        compile("testXor2I");
-        compile("testXor2L");
+        compileKernel("testXor2I");
+        compileKernel("testXor2L");
     }
 
     public static int testXor2I(int a, int b) {
@@ -73,8 +71,8 @@
 
     @Test
     public void testNot() {
-        compile("testNot1I");
-        compile("testNot1L");
+        compileKernel("testNot1I");
+        compileKernel("testNot1L");
     }
 
     public static int testNot1I(int a) {
@@ -87,8 +85,8 @@
 
     @Test
     public void testShiftLeft() {
-        compile("testShiftLeft2I");
-        compile("testShiftLeft2L");
+        compileKernel("testShiftLeft2I");
+        compileKernel("testShiftLeft2L");
     }
 
     public static int testShiftLeft2I(int a, int b) {
@@ -101,10 +99,10 @@
 
     @Test
     public void testShiftRight() {
-        compile("testShiftRight2I");
-        compile("testShiftRight2L");
-        compile("testUnsignedShiftRight2I");
-        // compile("testUnsignedShiftRight2L");
+        compileKernel("testShiftRight2I");
+        compileKernel("testShiftRight2L");
+        compileKernel("testUnsignedShiftRight2I");
+        // compileKernel("testUnsignedShiftRight2L");
     }
 
     public static int testShiftRight2I(int a, int b) {
@@ -124,12 +122,6 @@
     }
 
     public static void main(String[] args) {
-        LogicPTXTest test = new LogicPTXTest();
-        for (Method m : LogicPTXTest.class.getMethods()) {
-            String name = m.getName();
-            if (m.getAnnotation(Test.class) == null && name.startsWith("test")) {
-                printReport(name + ": \n" + new String(test.compile(name).getTargetCode()));
-            }
-        }
+        compileAndPrintCode(new LogicPTXTest());
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXTest.java	Thu Jan 16 21:47:17 2014 +0000
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.compiler.ptx.test;
+
+import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*;
+
+import java.io.*;
+import java.lang.reflect.*;
+
+import org.junit.*;
+
+import com.oracle.graal.api.code.*;
+import com.oracle.graal.api.meta.*;
+import com.oracle.graal.compiler.target.*;
+import com.oracle.graal.compiler.test.*;
+import com.oracle.graal.hotspot.meta.*;
+import com.oracle.graal.hotspot.ptx.*;
+import com.oracle.graal.nodes.*;
+import com.oracle.graal.ptx.*;
+
+/**
+ * Base class for PTX tests.
+ */
+public abstract class PTXTest extends GraalCompilerTest {
+
+    private static PTXHotSpotBackend getPTXBackend() {
+        Backend backend = runtime().getBackend(PTX.class);
+        Assume.assumeTrue(backend instanceof PTXHotSpotBackend);
+        return (PTXHotSpotBackend) backend;
+    }
+
+    protected ExternalCompilationResult compileKernel(ResolvedJavaMethod method) {
+        return getPTXBackend().compileKernel(method, getPTXBackend().isDeviceInitialized());
+    }
+
+    protected ExternalCompilationResult compileKernel(String test) {
+        return compileKernel(getMetaAccess().lookupJavaMethod(getMethod(test)));
+    }
+
+    @Override
+    protected InstalledCode getCode(ResolvedJavaMethod method, StructuredGraph graph) {
+        PTXHotSpotBackend ptxBackend = getPTXBackend();
+        ExternalCompilationResult ptxCode = compileKernel(method);
+        Assume.assumeTrue(ptxBackend.isDeviceInitialized());
+        InstalledCode installedPTXCode = ptxBackend.installKernel(method, ptxCode);
+        StructuredGraph wrapper = new PTXWrapperBuilder(method, installedPTXCode.getStart(), (HotSpotProviders) getProviders()).getGraph();
+        return super.getCode(method, wrapper);
+    }
+
+    protected static void compileAndPrintCode(PTXTest test) {
+        for (Method m : test.getClass().getMethods()) {
+            String name = m.getName();
+            if (m.getAnnotation(Test.class) == null && name.startsWith("test")) {
+                PrintStream out = System.out;
+                out.println(name + ": \n" + new String(test.compileKernel(name).getTargetCode()));
+            }
+        }
+    }
+}
--- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXTestBase.java	Wed Jan 15 19:54:48 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,175 +0,0 @@
-/*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.graal.compiler.ptx.test;
-
-import static com.oracle.graal.api.code.CodeUtil.*;
-import static com.oracle.graal.compiler.GraalCompiler.*;
-
-import java.lang.annotation.*;
-import java.lang.reflect.*;
-
-import com.oracle.graal.api.code.*;
-import com.oracle.graal.api.code.CallingConvention.Type;
-import com.oracle.graal.api.meta.*;
-import com.oracle.graal.compiler.target.*;
-import com.oracle.graal.compiler.test.*;
-import com.oracle.graal.debug.*;
-import com.oracle.graal.hotspot.*;
-import com.oracle.graal.hotspot.bridge.*;
-import com.oracle.graal.hotspot.meta.*;
-import com.oracle.graal.hotspot.ptx.*;
-import com.oracle.graal.lir.asm.*;
-import com.oracle.graal.lir.ptx.*;
-import com.oracle.graal.nodes.*;
-import com.oracle.graal.phases.*;
-import com.oracle.graal.phases.tiers.*;
-import com.oracle.graal.ptx.*;
-
-public abstract class PTXTestBase extends GraalCompilerTest {
-
-    private StructuredGraph sg;
-
-    public static void printReport(String message) {
-        // Use -G:Log=Test to see these messages on the console
-        Debug.log(message);
-    }
-
-    public PTXTestBase() {
-        super(PTX.class);
-    }
-
-    private static CompilerToGPU toGPU = HotSpotGraalRuntime.runtime().getCompilerToGPU();
-
-    private static boolean validDevice = toGPU.deviceInit();
-
-    private static final int totalProcessors = (validDevice ? toGPU.availableProcessors() : 0);
-
-    protected CompilationResult compile(String test) {
-        if (getBackend() instanceof PTXHotSpotBackend) {
-            StructuredGraph graph = parse(test);
-            sg = graph;
-            Debug.dump(graph, "Graph");
-            Backend ptxBackend = getBackend();
-            TargetDescription target = ptxBackend.getTarget();
-            PhaseSuite<HighTierContext> graphBuilderSuite = getDefaultGraphBuilderSuite().copy();
-            graphBuilderSuite.appendPhase(new PTXPhase());
-            new PTXPhase().apply(graph);
-            CallingConvention cc = getCallingConvention(getCodeCache(), Type.JavaCallee, graph.method(), false);
-            /*
-             * Use Suites.createDefaultSuites() instead of GraalCompilerTest.suites. The
-             * GraalCompilerTest.suites variable contains the Suites for the HotSpotRuntime. This
-             * code will not run on hotspot, so it should use the plain Graal default suites,
-             * without hotspot specific phases.
-             * 
-             * Ultimately we might want to have both the kernel and the code natively compiled for
-             * GPU fallback to CPU in cases of ECC failure on kernel invocation.
-             */
-            Suites suites = Suites.createDefaultSuites();
-            ExternalCompilationResult result = compileGraph(graph, cc, graph.method(), getProviders(), ptxBackend, target, null, graphBuilderSuite, OptimisticOptimizations.NONE,
-                            getProfilingInfo(graph), new SpeculationLog(), suites, true, new ExternalCompilationResult(), CompilationResultBuilderFactory.Default);
-
-            ResolvedJavaMethod method = graph.method();
-
-            try {
-                if ((validDevice) && (result.getTargetCode() != null)) {
-                    long kernel = toGPU.generateKernel(result.getTargetCode(), method.getName());
-                    result.setEntryPoint(kernel);
-                }
-            } catch (Throwable th) {
-                th.printStackTrace();
-            }
-
-            return result;
-        } else {
-            return null;
-        }
-    }
-
-    protected StructuredGraph getStructuredGraph() {
-        return sg;
-    }
-
-    protected Object invoke(CompilationResult result, Object... args) {
-        if (result == null) {
-            return null;
-        }
-        try {
-            if (((ExternalCompilationResult) result).getEntryPoint() == 0) {
-                Debug.dump(result, "[CUDA] *** Null entry point - Not launching kernel");
-                return null;
-            }
-
-            /* Check if the method compiled is static */
-            HotSpotResolvedJavaMethod compiledMethod = (HotSpotResolvedJavaMethod) sg.method();
-            boolean isStatic = Modifier.isStatic(compiledMethod.getModifiers());
-            Object[] executeArgs = argsWithReceiver((isStatic ? null : this), args);
-            HotSpotCodeCacheProvider codeCache = (HotSpotCodeCacheProvider) getCodeCache();
-            InstalledCode installedCode = codeCache.addExternalMethod(compiledMethod, result);
-            Annotation[][] params = compiledMethod.getParameterAnnotations();
-
-            int dimensionX = 1;
-            int dimensionY = 1;
-            int dimensionZ = 1;
-
-            for (int p = 0; p < params.length; p++) {
-                Annotation[] annos = params[p];
-                if (annos != null) {
-                    for (int a = 0; a < annos.length; a++) {
-                        Annotation aa = annos[a];
-                        if (args[p] instanceof int[] && aa.annotationType().equals(ParallelOver.class)) {
-                            int[] iarray = (int[]) args[p];
-                            ParallelOver threadBlockDimension = (ParallelOver) aa;
-                            switch (threadBlockDimension.dimension()) {
-                                case X:
-                                    dimensionX = iarray.length;
-                                    break;
-                                case Y:
-                                    dimensionY = iarray.length;
-                                    break;
-                                case Z:
-                                    dimensionZ = iarray.length;
-                                    break;
-                            }
-                        }
-                    }
-                }
-            }
-            Object r;
-            if (dimensionX != 1 || dimensionY != 1 || dimensionZ != 1) {
-                /*
-                 * for now assert that the warp array block is no larger than the number of physical
-                 * gpu cores.
-                 */
-                assert dimensionX * dimensionY * dimensionZ < totalProcessors;
-
-                r = ((HotSpotNmethod) installedCode).executeParallel(dimensionX, dimensionY, dimensionZ, executeArgs);
-            } else {
-                r = installedCode.executeVarargs(executeArgs);
-            }
-            return r;
-        } catch (Throwable th) {
-            th.printStackTrace();
-            return null;
-        }
-    }
-}
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java	Wed Jan 15 19:54:48 2014 +0000
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java	Thu Jan 16 21:47:17 2014 +0000
@@ -462,10 +462,14 @@
     }
 
     protected void test(String name, Object... args) {
-        Method method = getMethod(name);
-        Object receiver = Modifier.isStatic(method.getModifiers()) ? null : this;
-
-        test(method, receiver, args);
+        try {
+            Method method = getMethod(name);
+            Object receiver = Modifier.isStatic(method.getModifiers()) ? null : this;
+            test(method, receiver, args);
+        } catch (AssumptionViolatedException e) {
+            // Suppress so that subsequent calls to this method within the
+            // same Junit @Test annotated method can proceed.
+        }
     }
 
     protected void test(Method method, Object receiver, Object... args) {
--- a/graal/com.oracle.graal.hotspot.ptx.test/src/com/oracle/graal/hotspot/ptx/test/PTXLaunchKernelTest.java	Wed Jan 15 19:54:48 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-/*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.graal.hotspot.ptx.test;
-
-import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*;
-
-import org.junit.*;
-
-import com.oracle.graal.api.code.*;
-import com.oracle.graal.api.meta.*;
-import com.oracle.graal.compiler.target.*;
-import com.oracle.graal.compiler.test.*;
-import com.oracle.graal.hotspot.ptx.*;
-import com.oracle.graal.nodes.*;
-import com.oracle.graal.ptx.*;
-
-/**
- * Tests the mechanism for launching a PTX kernel method via wrapper code.
- */
-public class PTXLaunchKernelTest extends GraalCompilerTest {
-
-    /**
-     * Compiles and installs PTX kernel code for a given method.
-     */
-    StructuredGraph getKernelGraph(final ResolvedJavaMethod method) {
-        Backend backend = runtime().getBackend(PTX.class);
-        Assume.assumeTrue(backend instanceof PTXHotSpotBackend);
-        PTXHotSpotBackend ptxBackend = (PTXHotSpotBackend) backend;
-        Assume.assumeTrue(ptxBackend.isDeviceInitialized());
-        return new PTXGraphProducer(runtime().getHostBackend(), ptxBackend) {
-            @Override
-            protected boolean canOffloadToGPU(ResolvedJavaMethod m) {
-                return m == method;
-            }
-        }.getGraphFor(method);
-    }
-
-    @Override
-    protected InstalledCode getCode(ResolvedJavaMethod method, StructuredGraph graph) {
-        return super.getCode(method, getKernelGraph(method));
-    }
-
-    @Test
-    public void testStaticIntKernel() {
-        test("staticIntKernel", 'a', 42);
-    }
-
-    @Test
-    public void testVirtualIntKernel() {
-        test("virtualIntKernel", 'a', 42);
-    }
-
-    public static int staticIntKernel(char p0, int p1) {
-        return p1 + p0;
-    }
-
-    public int virtualIntKernel(char p0, int p1) {
-        return p1 + p0;
-    }
-}
--- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXGraphProducer.java	Wed Jan 15 19:54:48 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.graal.hotspot.ptx;
-
-import static com.oracle.graal.api.code.CodeUtil.*;
-import static com.oracle.graal.compiler.GraalCompiler.*;
-
-import com.oracle.graal.api.code.*;
-import com.oracle.graal.api.code.CallingConvention.Type;
-import com.oracle.graal.api.meta.*;
-import com.oracle.graal.debug.*;
-import com.oracle.graal.debug.Debug.Scope;
-import com.oracle.graal.hotspot.*;
-import com.oracle.graal.hotspot.HotSpotReplacementsImpl.GraphProducer;
-import com.oracle.graal.hotspot.bridge.*;
-import com.oracle.graal.hotspot.meta.*;
-import com.oracle.graal.lir.asm.*;
-import com.oracle.graal.nodes.*;
-import com.oracle.graal.phases.*;
-import com.oracle.graal.phases.tiers.*;
-
-public class PTXGraphProducer implements GraphProducer {
-    private final CompilerToGPU toGPU;
-    private final HotSpotBackend hostBackend;
-    private final HotSpotBackend ptxBackend;
-
-    public PTXGraphProducer(HotSpotBackend hostBackend, HotSpotBackend ptxBackend) {
-        this.hostBackend = hostBackend;
-        this.ptxBackend = ptxBackend;
-        this.toGPU = ptxBackend.getRuntime().getCompilerToGPU();
-    }
-
-    public StructuredGraph getGraphFor(ResolvedJavaMethod method) {
-        if (canOffloadToGPU(method)) {
-
-            StructuredGraph graph = new StructuredGraph(method);
-            HotSpotProviders providers = ptxBackend.getProviders();
-            CallingConvention cc = getCallingConvention(providers.getCodeCache(), Type.JavaCallee, method, false);
-            PhaseSuite<HighTierContext> graphBuilderSuite = providers.getSuites().getDefaultGraphBuilderSuite();
-            Suites suites = providers.getSuites().getDefaultSuites();
-            ExternalCompilationResult kernelResult = compileGraph(graph, cc, method, providers, ptxBackend, ptxBackend.getTarget(), null, graphBuilderSuite, OptimisticOptimizations.NONE,
-                            getProfilingInfo(graph), new SpeculationLog(), suites, true, new ExternalCompilationResult(), CompilationResultBuilderFactory.Default);
-
-            try (Scope ds = Debug.scope("GeneratingKernel")) {
-                long kernel = toGPU.generateKernel(kernelResult.getTargetCode(), method.getName());
-                kernelResult.setEntryPoint(kernel);
-            } catch (Throwable e) {
-                throw Debug.handle(e);
-            }
-
-            InstalledCode installedCode = providers.getCodeCache().addExternalMethod(method, kernelResult);
-            return new PTXLaunchKernelGraphKit(method, installedCode.getStart(), hostBackend.getProviders()).getGraph();
-        }
-        return null;
-    }
-
-    protected boolean canOffloadToGPU(ResolvedJavaMethod method) {
-        return method.getName().contains("lambda$main$") & method.isSynthetic();
-    }
-}
--- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java	Wed Jan 15 19:54:48 2014 +0000
+++ b/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java	Thu Jan 16 21:47:17 2014 +0000
@@ -23,7 +23,9 @@
 package com.oracle.graal.hotspot.ptx;
 
 import static com.oracle.graal.api.code.CallingConvention.Type.*;
+import static com.oracle.graal.api.code.CodeUtil.*;
 import static com.oracle.graal.api.meta.LocationIdentity.*;
+import static com.oracle.graal.compiler.GraalCompiler.*;
 import static com.oracle.graal.hotspot.HotSpotForeignCallLinkage.RegisterEffect.*;
 import static com.oracle.graal.hotspot.HotSpotForeignCallLinkage.Transition.*;
 import static com.oracle.graal.hotspot.meta.HotSpotForeignCallsProviderImpl.*;
@@ -32,11 +34,14 @@
 import java.util.*;
 
 import com.oracle.graal.api.code.*;
+import com.oracle.graal.api.code.CallingConvention.*;
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.asm.*;
 import com.oracle.graal.asm.ptx.*;
 import com.oracle.graal.compiler.gen.*;
 import com.oracle.graal.compiler.ptx.*;
+import com.oracle.graal.debug.*;
+import com.oracle.graal.debug.Debug.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.hotspot.*;
 import com.oracle.graal.hotspot.HotSpotReplacementsImpl.GraphProducer;
@@ -52,6 +57,8 @@
 import com.oracle.graal.lir.ptx.PTXMemOp.LoadReturnAddrOp;
 import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.cfg.*;
+import com.oracle.graal.phases.*;
+import com.oracle.graal.phases.tiers.*;
 import com.oracle.graal.word.*;
 
 /**
@@ -63,10 +70,27 @@
      * Descriptor for the PTX runtime method for launching a kernel. The C++ signature is:
      * 
      * <pre>
-     *     jlong gpu::Ptx::execute_kernel_from_vm(JavaThread* thread, jlong kernel, jlong parametersAndReturnValueBuffer, jint parametersAndReturnValueBufferSize, jint encodedReturnTypeSize)
+     *     jlong (JavaThread* thread,
+     *            jlong kernel,
+     *            jint dimX,
+     *            jint dimY,
+     *            jint dimZ,
+     *            jlong parametersAndReturnValueBuffer,
+     *            jint parametersAndReturnValueBufferSize,
+     *            jint encodedReturnTypeSize)
      * </pre>
      */
-    public static final ForeignCallDescriptor LAUNCH_KERNEL = new ForeignCallDescriptor("execute_kernel_from_vm", long.class, Word.class, long.class, long.class, int.class, int.class);
+    // @formatter:off
+    public static final ForeignCallDescriptor LAUNCH_KERNEL = new ForeignCallDescriptor("execute_kernel_from_vm", long.class,
+                    Word.class, // thread
+                    long.class, // kernel
+                    int.class,  // dimX
+                    int.class,  // dimY
+                    int.class,  // dimZ
+                    long.class, // parametersAndReturnValueBuffer
+                    int.class,  // parametersAndReturnValueBufferSize
+                    int.class); // encodedReturnTypeSize
+    // @formatter:on
 
     public PTXHotSpotBackend(HotSpotGraalRuntime runtime, HotSpotProviders providers) {
         super(runtime, providers);
@@ -77,11 +101,16 @@
         return false;
     }
 
+    /**
+     * Used to omit {@linkplain CompilerToGPU#deviceInit() device initialization}.
+     */
+    private static final boolean OmitDeviceInit = Boolean.getBoolean("graal.ptx.omitDeviceInit");
+
     @Override
     public void completeInitialization() {
         HotSpotHostForeignCallsProvider hostForeignCalls = (HotSpotHostForeignCallsProvider) getRuntime().getHostProviders().getForeignCalls();
         CompilerToGPU compilerToGPU = getRuntime().getCompilerToGPU();
-        deviceInitialized = compilerToGPU.deviceInit();
+        deviceInitialized = OmitDeviceInit || compilerToGPU.deviceInit();
         if (deviceInitialized) {
             long launchKernel = compilerToGPU.getLaunchKernelAddress();
             hostForeignCalls.registerForeignCall(LAUNCH_KERNEL, launchKernel, NativeCall, DESTROYS_REGISTERS, NOT_LEAF, NOT_REEXECUTABLE, ANY_LOCATION);
@@ -106,7 +135,54 @@
             // GPU could not be initialized so offload is disabled
             return null;
         }
-        return new PTXGraphProducer(getRuntime().getHostBackend(), this);
+        return new GraphProducer() {
+
+            public StructuredGraph getGraphFor(ResolvedJavaMethod method) {
+                if (canOffloadToGPU(method)) {
+                    ExternalCompilationResult ptxCode = PTXHotSpotBackend.this.compileKernel(method, true);
+                    InstalledCode installedPTXCode = PTXHotSpotBackend.this.installKernel(method, ptxCode);
+                    return new PTXWrapperBuilder(method, installedPTXCode.getStart(), getRuntime().getHostBackend().getProviders()).getGraph();
+                }
+                return null;
+            }
+
+            private boolean canOffloadToGPU(ResolvedJavaMethod method) {
+                return method.getName().contains("lambda$main$") & method.isSynthetic();
+            }
+        };
+    }
+
+    /**
+     * Compiles a given method to PTX code.
+     * 
+     * @param makeBinary specifies whether a GPU binary should also be generated for the PTX code.
+     *            If true, the returned value is guaranteed to have a non-zero
+     *            {@linkplain ExternalCompilationResult#getEntryPoint() entry point}.
+     * @return the PTX code compiled from {@code method}'s bytecode
+     */
+    public ExternalCompilationResult compileKernel(ResolvedJavaMethod method, boolean makeBinary) {
+        StructuredGraph graph = new StructuredGraph(method);
+        HotSpotProviders providers = getProviders();
+        CallingConvention cc = getCallingConvention(providers.getCodeCache(), Type.JavaCallee, method, false);
+        PhaseSuite<HighTierContext> graphBuilderSuite = providers.getSuites().getDefaultGraphBuilderSuite();
+        Suites suites = providers.getSuites().getDefaultSuites();
+        ExternalCompilationResult ptxCode = compileGraph(graph, cc, method, providers, this, this.getTarget(), null, graphBuilderSuite, OptimisticOptimizations.NONE, getProfilingInfo(graph),
+                        new SpeculationLog(), suites, true, new ExternalCompilationResult(), CompilationResultBuilderFactory.Default);
+        if (makeBinary) {
+            try (Scope ds = Debug.scope("GeneratingKernelBinary")) {
+                long kernel = getRuntime().getCompilerToGPU().generateKernel(ptxCode.getTargetCode(), method.getName());
+                ptxCode.setEntryPoint(kernel);
+            } catch (Throwable e) {
+                throw Debug.handle(e);
+            }
+        }
+        return ptxCode;
+
+    }
+
+    public InstalledCode installKernel(ResolvedJavaMethod method, ExternalCompilationResult ptxCode) {
+        assert ptxCode.getEntryPoint() != 0L;
+        return getProviders().getCodeCache().addExternalMethod(method, ptxCode);
     }
 
     static final class RegisterAnalysis extends ValueProcedure {
--- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXLaunchKernelGraphKit.java	Wed Jan 15 19:54:48 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,222 +0,0 @@
-/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.graal.hotspot.ptx;
-
-import static com.oracle.graal.api.meta.DeoptimizationReason.*;
-import static com.oracle.graal.api.meta.LocationIdentity.*;
-import static com.oracle.graal.asm.NumUtil.*;
-import static com.oracle.graal.hotspot.ptx.PTXHotSpotBackend.*;
-import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*;
-import static java.lang.reflect.Modifier.*;
-
-import java.util.*;
-
-import com.oracle.graal.api.meta.*;
-import com.oracle.graal.debug.*;
-import com.oracle.graal.graph.*;
-import com.oracle.graal.hotspot.meta.*;
-import com.oracle.graal.hotspot.nodes.*;
-import com.oracle.graal.hotspot.stubs.*;
-import com.oracle.graal.java.*;
-import com.oracle.graal.nodes.*;
-import com.oracle.graal.nodes.HeapAccess.BarrierType;
-import com.oracle.graal.nodes.calc.*;
-import com.oracle.graal.nodes.extended.*;
-import com.oracle.graal.nodes.type.*;
-import com.oracle.graal.replacements.nodes.*;
-import com.oracle.graal.word.*;
-
-/**
- * Utility for building a graph for launching a PTX kernel compiled for a method. This graph created
- * is something like the following pseudo code:
- * 
- * <pre>
- *     jlong kernel(p0, p1, ..., pN) {
- *         jint kernelParamsBufSize = SIZE_OF_ALIGNED_PARAMS_WITH_PADDING(p0, p1, ..., pN);
- *         jbyte kernelParamsBuf[kernelParamsBufSize] = {p0, PAD(p1), p1, ..., PAD(pN), pN};
- *         jlong result = PTX_LAUNCH_KERNEL(THREAD_REGISTER, kernelParamsBuf, kernelParamsBuf);
- *         return result;
- *     }
- * </pre>
- */
-public class PTXLaunchKernelGraphKit extends GraphKit {
-
-    /**
-     * The incoming Java arguments to the kernel invocation.
-     */
-    ParameterNode[] javaParameters;
-
-    /**
-     * The size of the buffer holding the parameters and the extra word for storing the pointer to
-     * device memory for the return value. This will be the same as
-     * PTXKernelArguments::device_argument_buffer_size().
-     */
-    int kernelParametersAndReturnValueBufferSize;
-
-    /**
-     * Offsets of each Java argument in the parameters buffer.
-     */
-    int[] javaParameterOffsetsInKernelParametersBuffer;
-
-    /**
-     * Creates a graph implementing the transition from Java to the native routine that launches
-     * some compiled PTX code.
-     * 
-     * @param kernelMethod a method that has been compiled to PTX kernel code
-     * @param kernelAddress the address of the installed PTX code for {@code kernelMethod}
-     */
-    public PTXLaunchKernelGraphKit(ResolvedJavaMethod kernelMethod, long kernelAddress, HotSpotProviders providers) {
-        super(new StructuredGraph(kernelMethod), providers);
-        int wordSize = providers.getCodeCache().getTarget().wordSize;
-        Kind wordKind = providers.getCodeCache().getTarget().wordKind;
-        Signature sig = kernelMethod.getSignature();
-        boolean isStatic = isStatic(kernelMethod.getModifiers());
-        int sigCount = sig.getParameterCount(false);
-        javaParameters = new ParameterNode[(!isStatic ? 1 : 0) + sigCount];
-        javaParameterOffsetsInKernelParametersBuffer = new int[javaParameters.length];
-        int javaParametersIndex = 0;
-        Kind returnKind = sig.getReturnKind();
-
-        BitSet objects = new BitSet();
-        if (!isStatic) {
-            javaParameters[javaParametersIndex] = unique(new ParameterNode(javaParametersIndex, StampFactory.declaredNonNull(kernelMethod.getDeclaringClass())));
-            kernelParametersAndReturnValueBufferSize += wordSize;
-            javaParameterOffsetsInKernelParametersBuffer[javaParametersIndex++] = 0;
-            objects.set(0);
-        }
-        for (int i = 0; i < sigCount; i++) {
-            Kind kind = sig.getParameterKind(i);
-            int kindByteSize = kind.getBitCount() / Byte.SIZE;
-            while ((kernelParametersAndReturnValueBufferSize % kindByteSize) != 0) {
-                kernelParametersAndReturnValueBufferSize++;
-            }
-            javaParameterOffsetsInKernelParametersBuffer[javaParametersIndex] = kernelParametersAndReturnValueBufferSize;
-            Stamp stamp;
-            if (kind == Kind.Object) {
-                stamp = StampFactory.object();
-                int slot = kernelParametersAndReturnValueBufferSize / wordSize;
-                objects.set(slot);
-            } else {
-                stamp = StampFactory.forKind(kind);
-            }
-            ParameterNode param = unique(new ParameterNode(javaParametersIndex, stamp));
-            javaParameters[javaParametersIndex++] = param;
-            kernelParametersAndReturnValueBufferSize += kindByteSize;
-        }
-        kernelParametersAndReturnValueBufferSize = roundUp(kernelParametersAndReturnValueBufferSize, wordSize);
-
-        // Add slot for holding pointer to device memory storing return value
-        int encodedReturnTypeSize = 0;
-        if (returnKind != Kind.Void) {
-            kernelParametersAndReturnValueBufferSize += wordSize;
-            if (returnKind == Kind.Object) {
-                encodedReturnTypeSize = -wordSize;
-            } else {
-                encodedReturnTypeSize = returnKind.getBitCount() / Byte.SIZE;
-            }
-        }
-
-        ReadRegisterNode threadArg = append(new ReadRegisterNode(providers.getRegisters().getThreadRegister(), true, false));
-        ConstantNode kernelAddressArg = ConstantNode.forLong(kernelAddress, getGraph());
-        AllocaNode kernelParametersAndReturnValueBufferArg = append(new AllocaNode(kernelParametersAndReturnValueBufferSize / wordSize, objects));
-        ConstantNode kernelParametersAndReturnValueBufferSizeArg = ConstantNode.forInt(kernelParametersAndReturnValueBufferSize, getGraph());
-        ConstantNode encodedReturnTypeSizeArg = ConstantNode.forInt(encodedReturnTypeSize, getGraph());
-
-        for (javaParametersIndex = 0; javaParametersIndex < javaParameters.length; javaParametersIndex++) {
-            ParameterNode javaParameter = javaParameters[javaParametersIndex];
-            int javaParameterOffset = javaParameterOffsetsInKernelParametersBuffer[javaParametersIndex];
-            LocationNode location = ConstantLocationNode.create(FINAL_LOCATION, javaParameter.kind(), javaParameterOffset, getGraph());
-            append(new WriteNode(kernelParametersAndReturnValueBufferArg, javaParameter, location, BarrierType.NONE, false, false));
-        }
-        if (returnKind != Kind.Void) {
-            LocationNode location = ConstantLocationNode.create(FINAL_LOCATION, wordKind, kernelParametersAndReturnValueBufferSize - wordSize, getGraph());
-            append(new WriteNode(kernelParametersAndReturnValueBufferArg, ConstantNode.forIntegerKind(wordKind, 0L, getGraph()), location, BarrierType.NONE, false, false));
-        }
-
-        FrameStateBuilder fsb = new FrameStateBuilder(kernelMethod, getGraph(), true);
-        FrameState fs = fsb.create(0);
-        getGraph().start().setStateAfter(fs);
-
-        ForeignCallNode result = append(new ForeignCallNode(providers.getForeignCalls(), LAUNCH_KERNEL, threadArg, kernelAddressArg, kernelParametersAndReturnValueBufferArg,
-                        kernelParametersAndReturnValueBufferSizeArg, encodedReturnTypeSizeArg));
-        result.setDeoptimizationState(fs);
-
-        ConstantNode isObjectResultArg = ConstantNode.forBoolean(returnKind == Kind.Object, getGraph());
-        InvokeNode handlePendingException = createInvoke(getClass(), "handlePendingException", threadArg, isObjectResultArg);
-        handlePendingException.setStateAfter(fs);
-        InvokeNode getObjectResult = null;
-
-        ValueNode returnValue;
-        switch (returnKind) {
-            case Void:
-                returnValue = null;
-                break;
-            case Boolean:
-            case Byte:
-            case Short:
-            case Char:
-            case Int:
-                returnValue = unique(new ConvertNode(Kind.Long, Kind.Int, result));
-                break;
-            case Long:
-                returnValue = result;
-                break;
-            case Float:
-            case Double:
-                returnValue = unique(new ReinterpretNode(returnKind, result));
-                break;
-            case Object:
-                getObjectResult = createInvoke(getClass(), "getObjectResult", threadArg);
-                returnValue = append(getObjectResult);
-                break;
-            default:
-                throw new GraalInternalError("%s return kind not supported", returnKind);
-        }
-
-        append(new ReturnNode(returnValue));
-
-        if (Debug.isDumpEnabled()) {
-            Debug.dump(getGraph(), "Initial kernel launch graph");
-        }
-
-        rewriteWordTypes();
-        inlineInvokes();
-
-        if (Debug.isDumpEnabled()) {
-            Debug.dump(getGraph(), "Kernel launch graph before compilation");
-        }
-    }
-
-    public static void handlePendingException(Word thread, boolean isObjectResult) {
-        if (clearPendingException(thread)) {
-            if (isObjectResult) {
-                getAndClearObjectResult(thread);
-            }
-            DeoptimizeNode.deopt(DeoptimizationAction.None, RuntimeConstraint);
-        }
-    }
-
-    public static Object getObjectResult(Word thread) {
-        return getAndClearObjectResult(thread);
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXWrapperBuilder.java	Thu Jan 16 21:47:17 2014 +0000
@@ -0,0 +1,275 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.hotspot.ptx;
+
+import static com.oracle.graal.api.meta.DeoptimizationReason.*;
+import static com.oracle.graal.api.meta.LocationIdentity.*;
+import static com.oracle.graal.api.meta.MetaUtil.*;
+import static com.oracle.graal.asm.NumUtil.*;
+import static com.oracle.graal.hotspot.ptx.PTXHotSpotBackend.*;
+import static com.oracle.graal.hotspot.ptx.PTXWrapperBuilder.LaunchArg.*;
+import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*;
+import static com.oracle.graal.nodes.ConstantNode.*;
+import static java.lang.reflect.Modifier.*;
+
+import java.util.*;
+
+import com.oracle.graal.api.meta.*;
+import com.oracle.graal.debug.*;
+import com.oracle.graal.graph.*;
+import com.oracle.graal.hotspot.meta.*;
+import com.oracle.graal.hotspot.nodes.*;
+import com.oracle.graal.hotspot.stubs.*;
+import com.oracle.graal.java.*;
+import com.oracle.graal.lir.ptx.*;
+import com.oracle.graal.nodes.*;
+import com.oracle.graal.nodes.HeapAccess.BarrierType;
+import com.oracle.graal.nodes.calc.*;
+import com.oracle.graal.nodes.extended.*;
+import com.oracle.graal.nodes.java.*;
+import com.oracle.graal.nodes.type.*;
+import com.oracle.graal.replacements.*;
+import com.oracle.graal.replacements.nodes.*;
+import com.oracle.graal.word.*;
+
+/**
+ * Utility for building a graph that "wraps" the PTX binary compiled for a method. Such a wrapper
+ * handles the transition from the host CPU to the GPU and back. The graph created is something like
+ * the following pseudo code with UPPER CASE denoting compile-time constants:
+ * 
+ * <pre>
+ *     T kernel(p0, p1, ..., pN) {
+ *         jint bufSize = SIZE_OF_ALIGNED_PARAMS_AND_RETURN_VALUE_WITH_PADDING(p0, p1, ..., pN);
+ *         jbyte buf[bufSize] = {p0, PAD(p1), p1, ..., PAD(pN), pN};
+ *         jlong result = PTX_LAUNCH_KERNEL(THREAD_REGISTER, KERNEL_ENTRY_POINT, dimX, dimY, dimZ, buf, bufSize, encodedReturnTypeSize);
+ *         return convert(result);
+ *     }
+ * </pre>
+ */
+public class PTXWrapperBuilder extends GraphKit {
+
+    /**
+     * The incoming Java arguments to the method.
+     */
+    ParameterNode[] javaParameters;
+
+    /**
+     * The size of the buffer holding the kernel parameters and the extra word for storing the
+     * pointer to device memory for the return value.
+     * 
+     * @see LaunchArg#ParametersAndReturnValueBufferSize
+     */
+    int bufSize;
+
+    /**
+     * Offset of each Java argument in the kernel parameters buffer.
+     */
+    int[] javaParameterOffsetsInKernelParametersBuffer;
+
+    /**
+     * Constants denoting the arguments to {@link PTXHotSpotBackend#LAUNCH_KERNEL}.
+     */
+    enum LaunchArg {
+        Thread, Kernel, DimX, DimY, DimZ, ParametersAndReturnValueBuffer, ParametersAndReturnValueBufferSize, EncodedReturnTypeSize
+    }
+
+    /**
+     * Creates the graph implementing the CPU to GPU transition.
+     * 
+     * @param method a method that has been compiled to GPU binary code
+     * @param kernelAddress the entry point of the GPU binary for {@code kernelMethod}
+     */
+    public PTXWrapperBuilder(ResolvedJavaMethod method, long kernelAddress, HotSpotProviders providers) {
+        super(new StructuredGraph(method), providers);
+        int wordSize = providers.getCodeCache().getTarget().wordSize;
+        Kind wordKind = providers.getCodeCache().getTarget().wordKind;
+        Signature sig = method.getSignature();
+        boolean isStatic = isStatic(method.getModifiers());
+        int sigCount = sig.getParameterCount(false);
+        javaParameters = new ParameterNode[(!isStatic ? 1 : 0) + sigCount];
+        javaParameterOffsetsInKernelParametersBuffer = new int[javaParameters.length];
+        int javaParametersIndex = 0;
+        Kind returnKind = sig.getReturnKind();
+
+        BitSet objects = new BitSet();
+        if (!isStatic) {
+            allocateParameter(Kind.Object, javaParametersIndex++, objects, wordSize);
+        }
+        for (int sigIndex = 0; sigIndex < sigCount; sigIndex++) {
+            Kind kind = sig.getParameterKind(sigIndex);
+            allocateParameter(kind, javaParametersIndex++, objects, wordSize);
+        }
+        bufSize = roundUp(bufSize, wordSize);
+
+        // Add slot for holding pointer to device memory storing return value
+        int encodedReturnTypeSize = 0;
+        if (returnKind != Kind.Void) {
+            bufSize += wordSize;
+            if (returnKind == Kind.Object) {
+                encodedReturnTypeSize = -wordSize;
+            } else {
+                encodedReturnTypeSize = returnKind.getBitCount() / Byte.SIZE;
+            }
+        }
+
+        AllocaNode buf = append(new AllocaNode(bufSize / wordSize, objects));
+
+        Map<LaunchArg, ValueNode> args = new EnumMap<>(LaunchArg.class);
+        args.put(Thread, append(new ReadRegisterNode(providers.getRegisters().getThreadRegister(), true, false)));
+        args.put(Kernel, ConstantNode.forLong(kernelAddress, getGraph()));
+        args.put(DimX, forInt(1, getGraph()));
+        args.put(DimY, forInt(1, getGraph()));
+        args.put(DimZ, forInt(1, getGraph()));
+        args.put(ParametersAndReturnValueBuffer, buf);
+        args.put(ParametersAndReturnValueBufferSize, forInt(bufSize, getGraph()));
+        args.put(EncodedReturnTypeSize, forInt(encodedReturnTypeSize, getGraph()));
+
+        int sigIndex = isStatic ? 0 : -1;
+        for (javaParametersIndex = 0; javaParametersIndex < javaParameters.length; javaParametersIndex++) {
+            ParameterNode javaParameter = javaParameters[javaParametersIndex];
+            int javaParameterOffset = javaParameterOffsetsInKernelParametersBuffer[javaParametersIndex];
+            LocationNode location = ConstantLocationNode.create(FINAL_LOCATION, javaParameter.kind(), javaParameterOffset, getGraph());
+            append(new WriteNode(buf, javaParameter, location, BarrierType.NONE, false, false));
+            updateDimArg(method, providers, sig, sigIndex++, args, javaParameter);
+        }
+        if (returnKind != Kind.Void) {
+            LocationNode location = ConstantLocationNode.create(FINAL_LOCATION, wordKind, bufSize - wordSize, getGraph());
+            append(new WriteNode(buf, ConstantNode.forIntegerKind(wordKind, 0L, getGraph()), location, BarrierType.NONE, false, false));
+        }
+
+        FrameStateBuilder fsb = new FrameStateBuilder(method, getGraph(), true);
+        FrameState fs = fsb.create(0);
+        getGraph().start().setStateAfter(fs);
+
+        ValueNode[] launchArgsArray = args.values().toArray(new ValueNode[args.size()]);
+        ForeignCallNode result = append(new ForeignCallNode(providers.getForeignCalls(), LAUNCH_KERNEL, launchArgsArray));
+        result.setDeoptimizationState(fs);
+
+        ConstantNode isObjectResultArg = ConstantNode.forBoolean(returnKind == Kind.Object, getGraph());
+        InvokeNode handlePendingException = createInvoke(getClass(), "handlePendingException", args.get(Thread), isObjectResultArg);
+        handlePendingException.setStateAfter(fs);
+        InvokeNode getObjectResult = null;
+
+        ValueNode returnValue;
+        switch (returnKind) {
+            case Void:
+                returnValue = null;
+                break;
+            case Boolean:
+            case Byte:
+            case Short:
+            case Char:
+            case Int:
+                returnValue = unique(new ConvertNode(Kind.Long, Kind.Int, result));
+                break;
+            case Long:
+                returnValue = result;
+                break;
+            case Float:
+            case Double:
+                returnValue = unique(new ReinterpretNode(returnKind, result));
+                break;
+            case Object:
+                getObjectResult = createInvoke(getClass(), "getObjectResult", args.get(Thread));
+                returnValue = append(getObjectResult);
+                break;
+            default:
+                throw new GraalInternalError("%s return kind not supported", returnKind);
+        }
+
+        append(new ReturnNode(returnValue));
+
+        if (Debug.isDumpEnabled()) {
+            Debug.dump(getGraph(), "Initial kernel launch graph");
+        }
+
+        rewriteWordTypes();
+        inlineInvokes();
+
+        if (Debug.isDumpEnabled()) {
+            Debug.dump(getGraph(), "Kernel launch graph before compilation");
+        }
+    }
+
+    /**
+     * Allocates a slot in the kernel parameters' buffer for a Java parameter.
+     * 
+     * @param kind the kind of the parameter
+     * @param javaParametersIndex the index of the Java parameter
+     */
+    private void allocateParameter(Kind kind, int javaParametersIndex, BitSet objects, int wordSize) {
+        int kindByteSize = kind == Kind.Object ? wordSize : kind.getBitCount() / Byte.SIZE;
+        bufSize = roundUp(bufSize, kindByteSize);
+        javaParameterOffsetsInKernelParametersBuffer[javaParametersIndex] = bufSize;
+        Stamp stamp;
+        if (kind == Kind.Object) {
+            stamp = StampFactory.object();
+            int slot = bufSize / wordSize;
+            objects.set(slot);
+        } else {
+            stamp = StampFactory.forKind(kind);
+        }
+        javaParameters[javaParametersIndex] = unique(new ParameterNode(javaParametersIndex, stamp));
+        bufSize += kindByteSize;
+    }
+
+    /**
+     * Updates the {@code dimX}, {@code dimY} or {@code dimZ} argument passed to the kernel if
+     * {@code javaParameter} is annotated with {@link ParallelOver}.
+     */
+    private void updateDimArg(ResolvedJavaMethod method, HotSpotProviders providers, Signature sig, int sigIndex, Map<LaunchArg, ValueNode> launchArgs, ParameterNode javaParameter) {
+        if (sigIndex >= 0) {
+            ParallelOver parallelOver = getParameterAnnotation(ParallelOver.class, sigIndex, method);
+            if (parallelOver != null && sig.getParameterType(sigIndex, method.getDeclaringClass()).equals(providers.getMetaAccess().lookupJavaType(int[].class))) {
+                ArrayLengthNode dimension = append(new ArrayLengthNode(javaParameter));
+                LaunchArg argKey = LaunchArg.valueOf(LaunchArg.class, "Dim" + parallelOver.dimension());
+                ValueNode existing = launchArgs.put(argKey, dimension);
+                if (existing != null && existing instanceof ArrayLengthNode) {
+                    throw new GraalInternalError("@" + ParallelOver.class.getSimpleName() + " with dimension=" + parallelOver.dimension() + " applied to multiple parameters");
+                }
+            }
+        }
+    }
+
+    /**
+     * Snippet invoked upon return from the kernel to handle any pending exceptions.
+     */
+    @Snippet
+    private static void handlePendingException(Word thread, boolean isObjectResult) {
+        if (clearPendingException(thread)) {
+            if (isObjectResult) {
+                getAndClearObjectResult(thread);
+            }
+            DeoptimizeNode.deopt(DeoptimizationAction.None, RuntimeConstraint);
+        }
+    }
+
+    /**
+     * Snippet invoked upon return from the kernel to retrieve an object return value from the
+     * thread local used for communicating object return values from VM calls.
+     */
+    @Snippet
+    private static Object getObjectResult(Word thread) {
+        return getAndClearObjectResult(thread);
+    }
+}
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Wed Jan 15 19:54:48 2014 +0000
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java	Thu Jan 16 21:47:17 2014 +0000
@@ -519,12 +519,7 @@
 
     @Override
     public void compileMethod(long metaspaceMethod, final int entryBCI, final boolean blocking) {
-        HotSpotVMConfig config = runtime().getConfig();
-        final long metaspaceConstMethod = unsafe.getAddress(metaspaceMethod + config.methodConstMethodOffset);
-        final long metaspaceConstantPool = unsafe.getAddress(metaspaceConstMethod + config.constMethodConstantsOffset);
-        final long metaspaceKlass = unsafe.getAddress(metaspaceConstantPool + config.constantPoolHolderOffset);
-        final HotSpotResolvedObjectType holder = (HotSpotResolvedObjectType) HotSpotResolvedObjectType.fromMetaspaceKlass(metaspaceKlass);
-        final HotSpotResolvedJavaMethod method = holder.createMethod(metaspaceMethod);
+        final HotSpotResolvedJavaMethod method = HotSpotResolvedJavaMethod.fromMetaspace(metaspaceMethod);
         // We have to use a privileged action here because compilations are enqueued from user code
         // which very likely contains unprivileged frames.
         AccessController.doPrivileged(new PrivilegedAction<Void>() {
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotLoweringProvider.java	Wed Jan 15 19:54:48 2014 +0000
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotLoweringProvider.java	Thu Jan 16 21:47:17 2014 +0000
@@ -705,6 +705,9 @@
     }
 
     private static GuardingNode createNullCheck(ValueNode object, FixedNode before, LoweringTool tool) {
+        if (ObjectStamp.isObjectNonNull(object)) {
+            return null;
+        }
         return tool.createGuard(before, before.graph().unique(new IsNullNode(object)), DeoptimizationReason.NullCheckException, DeoptimizationAction.InvalidateReprofile, true);
     }
 
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/AbstractMethodHandleNode.java	Wed Jan 15 19:54:48 2014 +0000
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/AbstractMethodHandleNode.java	Thu Jan 16 21:47:17 2014 +0000
@@ -176,9 +176,9 @@
         // Create a method from the vmtarget pointer
         Class<?> c = (Class<?>) clazz.asObject();
         HotSpotResolvedObjectType holderClass = (HotSpotResolvedObjectType) HotSpotResolvedObjectType.fromClass(c);
-        HotSpotResolvedJavaMethod targetMethod = holderClass.createMethod(vmtarget.asLong());
+        HotSpotResolvedJavaMethod targetMethod = HotSpotResolvedJavaMethod.fromMetaspace(vmtarget.asLong());
 
-        // In lamda forms we erase signature types to avoid resolving issues
+        // In lambda forms we erase signature types to avoid resolving issues
         // involving class loaders. When we optimize a method handle invoke
         // to a direct call we must cast the receiver and arguments to its
         // actual types.
--- a/mx/projects	Wed Jan 15 19:54:48 2014 +0000
+++ b/mx/projects	Thu Jan 16 21:47:17 2014 +0000
@@ -202,14 +202,6 @@
 project@com.oracle.graal.hotspot.ptx@javaCompliance=1.7
 project@com.oracle.graal.hotspot.ptx@workingSets=Graal,HotSpot,PTX
 
-# graal.hotspot.ptx.test
-project@com.oracle.graal.hotspot.ptx.test@subDir=graal
-project@com.oracle.graal.hotspot.ptx.test@sourceDirs=src
-project@com.oracle.graal.hotspot.ptx.test@dependencies=com.oracle.graal.hotspot.ptx,com.oracle.graal.compiler.test
-project@com.oracle.graal.hotspot.ptx.test@checkstyle=com.oracle.graal.graph
-project@com.oracle.graal.hotspot.ptx.test@javaCompliance=1.7
-project@com.oracle.graal.hotspot.ptx.test@workingSets=Graal,HotSpot,PTX
-
 # graal.hotspot.hsail
 project@com.oracle.graal.hotspot.hsail@subDir=graal
 project@com.oracle.graal.hotspot.hsail@sourceDirs=src
--- a/src/gpu/ptx/vm/gpu_ptx.cpp	Wed Jan 15 19:54:48 2014 +0000
+++ b/src/gpu/ptx/vm/gpu_ptx.cpp	Thu Jan 16 21:47:17 2014 +0000
@@ -337,40 +337,20 @@
   return cu_function;
 }
 
-JRT_ENTRY(jlong, gpu::Ptx::execute_kernel_from_vm(JavaThread* thread, jlong kernel, jlong parametersAndReturnValueBuffer, jint parametersAndReturnValueBufferSize, int encodedReturnTypeSize))
-  tty->print_cr("*** gpu::Ptx::execute_kernel_from_vm(kernel=%p, parametersAndReturnValueBuffer=%p, parametersAndReturnValueBufferSize=%d, encodedReturnTypeSize=%d)",
-      kernel, parametersAndReturnValueBuffer, parametersAndReturnValueBufferSize, encodedReturnTypeSize);
-  tty->print("  buffer as bytes: ");
-  for (int i = 0; i < parametersAndReturnValueBufferSize; i++) {
-    tty->print(" 0x%02x", ((jbyte*) (address) parametersAndReturnValueBuffer)[i] & 0xFF);
-  }
-  tty->cr();
-  tty->print("  buffer as ints: ");
-  for (int i = 0; i < (parametersAndReturnValueBufferSize / 4); i++) {
-    tty->print(" %d", ((jint*) (address) parametersAndReturnValueBuffer)[i]);
-  }
-  tty->cr();
-  tty->print("  buffer as words: ");
-  for (unsigned i = 0; i < (parametersAndReturnValueBufferSize / sizeof(void*)); i++) {
-    tty->print(" "INTPTR_FORMAT, ((void**) (address) parametersAndReturnValueBuffer)[i]);
-  }
-  tty->cr();
+JRT_ENTRY(jlong, gpu::Ptx::execute_kernel_from_vm(JavaThread* thread, jlong kernel, jint dimX, jint dimY, jint dimZ,
+                                                  jlong parametersAndReturnValueBuffer,
+                                                  jint parametersAndReturnValueBufferSize,
+                                                  int encodedReturnTypeSize))
   if (kernel == 0L) {
     SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_NullPointerException(), NULL);
     return 0L;
   }
 
-
   // grid dimensionality
   unsigned int gridX = 1;
   unsigned int gridY = 1;
   unsigned int gridZ = 1;
 
-  // thread dimensionality
-  unsigned int blockX = 1;
-  unsigned int blockY = 1;
-  unsigned int blockZ = 1;
-
   struct CUfunc_st* cu_function = (struct CUfunc_st*) (address) kernel;
 
   void * config[5] = {
@@ -391,7 +371,7 @@
     status = _cuda_cu_memalloc(&device_return_value, returnTypeSize);
     if (status != GRAAL_CUDA_SUCCESS) {
       tty->print_cr("[CUDA] *** Error (%d) Failed to allocate memory for return value pointer on device", status);
-      SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_Exception(), "[CUDA] Failed to allocate memory for return value pointer on device");
+      SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_RuntimeException(), "[CUDA] Failed to allocate memory for return value pointer on device");
       return 0L;
     }
     // Push device_return_value to kernelParams
@@ -401,24 +381,24 @@
 
   status = _cuda_cu_launch_kernel(cu_function,
                                       gridX, gridY, gridZ,
-                                      blockX, blockY, blockZ,
+                                      dimX, dimY, dimZ,
                                       0, NULL, NULL, (void **) &config);
 
   if (status != GRAAL_CUDA_SUCCESS) {
     tty->print_cr("[CUDA] Failed to launch kernel");
-    SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_Exception(), "[CUDA] Failed to launch kernel");
+    SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_RuntimeException(), "[CUDA] Failed to launch kernel");
     return 0L;
   }
 
   if (TraceGPUInteraction) {
-    tty->print_cr("[CUDA] Success: Kernel Launch: X: %d Y: %d Z: %d", blockX, blockY, blockZ);
+    tty->print_cr("[CUDA] Success: Kernel Launch: X: %d Y: %d Z: %d", dimX, dimY, dimZ);
   }
 
   status = _cuda_cu_ctx_synchronize();
 
   if (status != GRAAL_CUDA_SUCCESS) {
     tty->print_cr("[CUDA] Failed to synchronize launched kernel (%d)", status);
-    SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_Exception(), "[CUDA] Failed to synchronize launched kernel");
+    SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_RuntimeException(), "[CUDA] Failed to synchronize launched kernel");
     return 0L;
   }
 
@@ -437,7 +417,6 @@
     }
     thread->set_vm_result(return_val);
   } else if (returnTypeSize > 0) {
-    jlong result;
     status = gpu::Ptx::_cuda_cu_memcpy_dtoh(&primitiveReturnValue, device_return_value, T_LONG_BYTE_SIZE);
     if (status != GRAAL_CUDA_SUCCESS) {
       tty->print_cr("[CUDA] *** Error (%d) Failed to copy value from device argument", status);
--- a/src/gpu/ptx/vm/gpu_ptx.hpp	Wed Jan 15 19:54:48 2014 +0000
+++ b/src/gpu/ptx/vm/gpu_ptx.hpp	Thu Jan 16 21:47:17 2014 +0000
@@ -105,7 +105,10 @@
 
 typedef int CUdevice;     /* CUDA device */
 
-  static jlong execute_kernel_from_vm(JavaThread* thread, jlong kernel, jlong parametersAndReturnValueBuffer, jint parametersAndReturnValueBufferSize, int encodedReturnTypeSize);
+  static jlong execute_kernel_from_vm(JavaThread* thread, jlong kernel, jint dimX, jint dimY, jint dimZ,
+                                      jlong parametersAndReturnValueBuffer,
+                                      jint parametersAndReturnValueBufferSize,
+                                      int encodedReturnTypeSize);
 
 private:
   typedef int (*cuda_cu_init_func_t)(unsigned int);
--- a/src/share/vm/graal/graalCompilerToGPU.cpp	Wed Jan 15 19:54:48 2014 +0000
+++ b/src/share/vm/graal/graalCompilerToGPU.cpp	Thu Jan 16 21:47:17 2014 +0000
@@ -48,7 +48,9 @@
 
 C2V_ENTRY(jlong, generateKernel, (JNIEnv *env, jobject, jbyteArray code, jstring name))
   if (gpu::is_available() == false || gpu::has_gpu_linkage() == false && gpu::is_initialized()) {
-    tty->print_cr("generateKernel - not available / no linkage / not initialized");
+    if (TraceGPUInteraction) {
+      tty->print_cr("generateKernel - not available / no linkage / not initialized");
+    }
     return 0;
   }
   jboolean is_copy;
@@ -58,8 +60,7 @@
   void *kernel = gpu::generate_kernel((unsigned char *)bytes, len, namestr);
   if (kernel == NULL) {
     tty->print_cr("[CUDA] *** Error: Failed to compile kernel");
-  }
-  else if (TraceGPUInteraction) {
+  } else if (TraceGPUInteraction) {
     tty->print_cr("[CUDA] Generated kernel");
   }
   env->ReleaseByteArrayElements(code, bytes, 0);