changeset 5557:2e2a77f091f2

re-enabled disassembler output to C1Visualizer after code installation moved some useful functionality from TypeCheckTest up in GraphTest added NewInstanceTest to test snippets for lowering NewInstanceNode
author Doug Simon <doug.simon@oracle.com>
date Mon, 11 Jun 2012 14:25:42 +0200
parents 4b47c0898e89
children 31bb778a6ec5
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/GraphTest.java graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/NewInstanceTest.java graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/TypeCheckTest.java
diffstat 5 files changed, 121 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java	Mon Jun 11 14:22:03 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java	Mon Jun 11 14:25:42 2012 +0200
@@ -207,6 +207,9 @@
         if (clazz == ExtendedRiRuntime.class) {
             return (T) getRuntime();
         }
+        if (clazz == GraalCompiler.class) {
+            return (T) getCompiler();
+        }
         return null;
     }
 }
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java	Mon Jun 11 14:22:03 2012 +0200
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java	Mon Jun 11 14:25:42 2012 +0200
@@ -25,7 +25,6 @@
 import java.io.*;
 import java.util.*;
 
-import com.oracle.max.criutils.*;
 import com.oracle.graal.alloc.util.*;
 import com.oracle.graal.api.code.*;
 import com.oracle.graal.api.meta.*;
@@ -38,6 +37,7 @@
 import com.oracle.graal.lir.*;
 import com.oracle.graal.lir.cfg.*;
 import com.oracle.graal.nodes.*;
+import com.oracle.max.criutils.*;
 
 /**
  * Observes compilation events and uses {@link CFGPrinter} to produce a control flow graph for the <a
@@ -152,8 +152,9 @@
                 }
             };
             cfgPrinter.printMachineCode(runtime.disassemble(info, tm), message);
-        } else if (object instanceof CodeInfo) {
-            cfgPrinter.printMachineCode(runtime.disassemble((CodeInfo) object, null), message);
+        } else if (isCompilationResultAndCodeInfo(object)) {
+            Object[] tuple = (Object[]) object;
+            cfgPrinter.printMachineCode(runtime.disassemble((CodeInfo) tuple[1], (CompilationResult) tuple[0]), message);
         } else if (object instanceof Interval[]) {
             cfgPrinter.printIntervals(message, (Interval[]) object);
 
@@ -167,4 +168,14 @@
         cfgPrinter.cfg = null;
         cfgPrinter.flush();
     }
+
+    private static boolean isCompilationResultAndCodeInfo(Object object) {
+        if (object instanceof Object[]) {
+            Object[] tuple = (Object[]) object;
+            if (tuple.length == 2 && tuple[0] instanceof CompilationResult && tuple[1] instanceof CodeInfo) {
+                return true;
+            }
+        }
+        return false;
+    }
 }
--- a/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/GraphTest.java	Mon Jun 11 14:22:03 2012 +0200
+++ b/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/GraphTest.java	Mon Jun 11 14:25:42 2012 +0200
@@ -147,6 +147,34 @@
 
     private static int compilationId = 0;
 
+    protected void test(String name, Object... args) {
+        Method method = getMethod(name);
+        Object expect = null;
+        Throwable exception = null;
+        try {
+            // This gives us both the expected return value as well as ensuring that the method to be compiled is fully resolved
+            expect = method.invoke(null, args);
+        } catch (InvocationTargetException e) {
+            exception = e.getTargetException();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        InstalledCode compiledMethod = compile(runtime.getResolvedJavaMethod(method), parse(method));
+        compiledMethod.method();
+
+        if (exception != null) {
+            try {
+                compiledMethod.executeVarargs(args);
+                Assert.fail("expected " + exception);
+            } catch (Throwable e) {
+                Assert.assertEquals(exception.getClass(), e.getClass());
+            }
+        } else {
+            Object actual = compiledMethod.executeVarargs(args);
+            Assert.assertEquals(expect, actual);
+        }
+    }
+
     protected InstalledCode compile(final ResolvedJavaMethod method, final StructuredGraph graph) {
         return Debug.scope("Compiling", new DebugDumpScope(String.valueOf(compilationId++), true), new Callable<InstalledCode>() {
             public InstalledCode call() throws Exception {
@@ -157,13 +185,15 @@
     }
 
     protected InstalledCode addMethod(final ResolvedJavaMethod method, final CompilationResult tm) {
-        return Debug.scope("CodeInstall", new Object[] {method}, new Callable<InstalledCode>() {
+        GraalCompiler graalCompiler = Graal.getRuntime().getCapability(GraalCompiler.class);
+        assert graalCompiler != null;
+        return Debug.scope("CodeInstall", new Object[] {graalCompiler, method}, new Callable<InstalledCode>() {
             @Override
             public InstalledCode call() throws Exception {
                 final CodeInfo[] info = Debug.isDumpEnabled() ? new CodeInfo[1] : null;
                 InstalledCode installedMethod = runtime.addMethod(method, tm, info);
                 if (info != null) {
-                    Debug.dump(info[0], "After code installation");
+                    Debug.dump(new Object[] {tm, info[0]}, "After code installation");
                 }
                 return installedMethod;
             }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/NewInstanceTest.java	Mon Jun 11 14:25:42 2012 +0200
@@ -0,0 +1,59 @@
+/*
+ * 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.tests;
+
+import java.util.*;
+
+import org.junit.*;
+
+import com.oracle.graal.api.meta.*;
+import com.oracle.graal.nodes.*;
+
+/**
+ * Tests the implementation of {@code NEW}.
+ */
+public class NewInstanceTest extends TypeCheckTest {
+
+    @Override
+    protected void replaceProfile(StructuredGraph graph, JavaTypeProfile profile) {
+    }
+
+    @Test
+    public void test1() {
+        test("newEmptyString");
+        test("newString", "value");
+        test("newHashMap", 31);
+    }
+
+    public static String newEmptyString() {
+        return new String();
+    }
+
+    public static String newString(String value) {
+        return new String(value);
+    }
+
+    public static HashMap newHashMap(int initialCapacity) {
+        return new HashMap(initialCapacity);
+    }
+}
--- a/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/TypeCheckTest.java	Mon Jun 11 14:22:03 2012 +0200
+++ b/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/TypeCheckTest.java	Mon Jun 11 14:25:42 2012 +0200
@@ -22,10 +22,6 @@
  */
 package com.oracle.graal.compiler.tests;
 
-import java.lang.reflect.*;
-
-import org.junit.*;
-
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.api.meta.JavaTypeProfile.*;
 import com.oracle.graal.nodes.*;
@@ -37,10 +33,14 @@
 
     protected abstract void replaceProfile(StructuredGraph graph, JavaTypeProfile profile);
 
-    private InstalledCode compile(Method method, JavaTypeProfile profile) {
-        final StructuredGraph graph = parse(method);
-        replaceProfile(graph, profile);
-        return compile(runtime.getResolvedJavaMethod(method), graph);
+    protected JavaTypeProfile currentProfile;
+
+    @Override
+    protected InstalledCode compile(final ResolvedJavaMethod method, final StructuredGraph graph) {
+        if (currentProfile != null) {
+            replaceProfile(graph, currentProfile);
+        }
+        return super.compile(method, graph);
     }
 
     protected JavaTypeProfile profile(Class... types) {
@@ -55,30 +55,12 @@
     }
 
     protected void test(String name, JavaTypeProfile profile, Object... args) {
-        Method method = getMethod(name);
-        Object expect = null;
-        Throwable exception = null;
+        assert currentProfile == null;
+        currentProfile = profile;
         try {
-            // This gives us both the expected return value as well as ensuring that the method to be compiled is fully resolved
-            expect = method.invoke(null, args);
-        } catch (InvocationTargetException e) {
-            exception = e.getTargetException();
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-        InstalledCode compiledMethod = compile(method, profile);
-        compiledMethod.method();
-
-        if (exception != null) {
-            try {
-                compiledMethod.executeVarargs(args);
-                Assert.fail("expected " + exception);
-            } catch (Throwable e) {
-                Assert.assertEquals(exception.getClass(), e.getClass());
-            }
-        } else {
-            Object actual = compiledMethod.executeVarargs(args);
-            Assert.assertEquals(expect, actual);
+            super.test(name, args);
+        } finally {
+            currentProfile = null;
         }
     }
 }