# HG changeset patch # User Peter B. Kessler # Date 1363197643 25200 # Node ID 35267b295f74c8960620beb2f80304ecb816553d # Parent f58cfb2d004f213b82fe1efcd18d864626114c95# Parent 0e008317f8ede8b73fc2cc5c7c03865e5518648e Merge diff -r f58cfb2d004f -r 35267b295f74 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Tue Mar 12 16:27:49 2013 -0700 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java Wed Mar 13 11:00:43 2013 -0700 @@ -221,7 +221,7 @@ return method.invoke(receiver, args); } - static class Result { + protected static class Result { final Object returnValue; final Throwable exception; @@ -263,7 +263,10 @@ before(); Object[] executeArgs = argsWithReceiver(receiver, args); - InstalledCode compiledMethod = getCode(runtime.lookupJavaMethod(method), parse(method)); + ResolvedJavaMethod javaMethod = runtime.lookupJavaMethod(method); + checkArgs(javaMethod, executeArgs); + + InstalledCode compiledMethod = getCode(javaMethod, parse(method)); try { return new Result(compiledMethod.executeVarargs(executeArgs), null); } catch (Throwable e) { @@ -273,6 +276,25 @@ } } + protected void checkArgs(ResolvedJavaMethod method, Object[] args) { + JavaType[] sig = MetaUtil.signatureToTypes(method); + Assert.assertEquals(sig.length, args.length); + for (int i = 0; i < args.length; i++) { + JavaType javaType = sig[i]; + Kind kind = javaType.getKind(); + Object arg = args[i]; + if (kind == Kind.Object) { + if (arg != null && javaType instanceof ResolvedJavaType) { + ResolvedJavaType resolvedJavaType = (ResolvedJavaType) javaType; + Assert.assertTrue(resolvedJavaType + " from " + runtime.lookupJavaType(arg.getClass()), resolvedJavaType.isAssignableFrom(runtime.lookupJavaType(arg.getClass()))); + } + } else { + Assert.assertNotNull(arg); + Assert.assertEquals(kind.toBoxedJavaClass(), arg.getClass()); + } + } + } + /** * Prepends a non-null receiver argument to a given list or args. * @@ -296,16 +318,28 @@ Method method = getMethod(name); Object receiver = Modifier.isStatic(method.getModifiers()) ? null : this; + test(method, receiver, args); + } + + protected void test(Method method, Object receiver, Object... args) { Result expect = executeExpected(method, receiver, args); if (runtime == null) { return; } + test(method, expect, receiver, args); + } + + protected void test(Method method, Result expect, Object receiver, Object... args) { Result actual = executeActual(method, receiver, args); if (expect.exception != null) { Assert.assertTrue("expected " + expect.exception, actual.exception != null); Assert.assertEquals(expect.exception.getClass(), actual.exception.getClass()); } else { + if (actual.exception != null) { + actual.exception.printStackTrace(); + Assert.fail("expected " + expect.returnValue + " but got an exception"); + } assertEquals(expect.returnValue, actual.returnValue); } } @@ -360,8 +394,7 @@ GraphBuilderPhase graphBuilderPhase = new GraphBuilderPhase(runtime, GraphBuilderConfiguration.getDefault(), OptimisticOptimizations.ALL); phasePlan.addPhase(PhasePosition.AFTER_PARSING, graphBuilderPhase); editPhasePlan(method, graph, phasePlan); - CompilationResult compResult = GraalCompiler.compileMethod(runtime(), backend, runtime().getTarget(), method, graph, null, phasePlan, OptimisticOptimizations.ALL, - new SpeculationLog()); + CompilationResult compResult = GraalCompiler.compileMethod(runtime(), backend, runtime().getTarget(), method, graph, null, phasePlan, OptimisticOptimizations.ALL, new SpeculationLog()); if (printCompilation) { TTY.println(String.format("@%-6d Graal %-70s %-45s %-50s | %4dms %5dB", id, "", "", "", System.currentTimeMillis() - start, compResult.getTargetCodeSize())); } diff -r f58cfb2d004f -r 35267b295f74 graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Tue Mar 12 16:27:49 2013 -0700 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Wed Mar 13 11:00:43 2013 -0700 @@ -54,7 +54,7 @@ /** * The {@code GraphBuilder} class parses the bytecode of a method and builds the IR graph. */ -public final class GraphBuilderPhase extends Phase { +public class GraphBuilderPhase extends Phase { public static final class RuntimeCalls { @@ -74,7 +74,7 @@ */ public static final int TRACELEVEL_STATE = 2; - private StructuredGraph currentGraph; + protected StructuredGraph currentGraph; private final MetaAccessProvider runtime; private ConstantPool constantPool; @@ -84,7 +84,7 @@ private BytecodeStream stream; // the bytecode stream - private FrameStateBuilder frameState; // the current execution state + protected FrameStateBuilder frameState; // the current execution state private Block currentBlock; private ValueNode methodSynchronizedObject; @@ -827,7 +827,7 @@ /** * Gets the kind of array elements for the array type code that appears in a * {@link Bytecodes#NEWARRAY} bytecode. - * + * * @param code the array type code * @return the kind from the array type code */ @@ -1224,7 +1224,7 @@ /** * Helper function that sums up the probabilities of all keys that lead to a specific successor. - * + * * @return an array of size successorCount with the accumulated probability for each successor. */ private static double[] successorProbabilites(int successorCount, int[] keySuccessors, double[] keyProbabilities) { diff -r f58cfb2d004f -r 35267b295f74 graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/JTTTest.java --- a/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/JTTTest.java Tue Mar 12 16:27:49 2013 -0700 +++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/JTTTest.java Wed Mar 13 11:00:43 2013 -0700 @@ -48,6 +48,10 @@ */ Object[] argsToBind; + public JTTTest() { + Assert.assertNotNull(runtime); + } + @Override protected StructuredGraph parse(Method m) { StructuredGraph graph = super.parse(m); @@ -89,10 +93,14 @@ } protected void runTest(String name, Object... args) { - // System.out.println(getClass().getSimpleName() + "." + name); - super.test(name, args); + Method method = getMethod(name); + Object receiver = Modifier.isStatic(method.getModifiers()) ? null : this; + + Result expect = executeExpected(method, receiver, args); + + test(method, expect, receiver, args); this.argsToBind = args; - super.test(name, args); + test(method, expect, receiver, args); this.argsToBind = null; } } diff -r f58cfb2d004f -r 35267b295f74 graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinterDumpHandler.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinterDumpHandler.java Tue Mar 12 16:27:49 2013 -0700 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/GraphPrinterDumpHandler.java Wed Mar 13 11:00:43 2013 -0700 @@ -82,16 +82,22 @@ if (sdf == null) { sdf = new SimpleDateFormat("YYYY-MM-dd-HHmm"); } - String fileName = "Graphs-" + Thread.currentThread().getName() + "-" + sdf.format(new Date()) + ext; + String prefix = "Graphs-" + Thread.currentThread().getName() + "-" + sdf.format(new Date()); + String num = ""; + File file; + int i = 0; + while ((file = new File(prefix + num + ext)).exists()) { + num = "-" + Integer.toString(++i); + } try { if (GraalOptions.PrintBinaryGraphs) { - printer = new BinaryGraphPrinter(FileChannel.open(new File(fileName).toPath(), StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW)); + printer = new BinaryGraphPrinter(FileChannel.open(file.toPath(), StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW)); } else { - printer = new IdealGraphPrinter(new FileOutputStream(fileName)); + printer = new IdealGraphPrinter(new FileOutputStream(file)); } - TTY.println("Dumping IGV graphs to %s", fileName); + TTY.println("Dumping IGV graphs to %s", file.getName()); } catch (IOException e) { - TTY.println("Failed to open %s to dump IGV graphs : %s", fileName, e); + TTY.println("Failed to open %s to dump IGV graphs : %s", file.getName(), e); failuresCount++; printer = null; }