# HG changeset patch # User Gilles Duboscq # Date 1337779622 -7200 # Node ID 451327d8543b81dbe704eb508464eca91386c219 # Parent 16c27447923ce431628995785c696773a85aa5bc# Parent d7b5cc23945e35144fbd20e9124e1030c95c1987 Merge diff -r 16c27447923c -r 451327d8543b graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugDumpScope.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugDumpScope.java Wed May 23 11:55:31 2012 +0200 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/DebugDumpScope.java Wed May 23 15:27:02 2012 +0200 @@ -22,16 +22,24 @@ */ package com.oracle.graal.debug; -public final class DebugDumpScope { +public class DebugDumpScope { + + public final String name; - private final String name; + /** + * Specifies if this scope decorates an inner scope. + * A hierarchical or tree representation of nested scopes may choose to represent + * a decorator scope at the same level as the scope it decorates. + */ + public final boolean decorator; public DebugDumpScope(String name) { - this.name = name; + this(name, false); } - public String getName() { - return name; + public DebugDumpScope(String name, boolean decorator) { + this.name = name; + this.decorator = decorator; } @Override diff -r 16c27447923c -r 451327d8543b graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Wed May 23 11:55:31 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Wed May 23 15:27:02 2012 +0200 @@ -111,7 +111,7 @@ CiTargetMethod result = null; TTY.Filter filter = new TTY.Filter(GraalOptions.PrintFilter, method); try { - result = Debug.scope("Compiling", new Callable() { + result = Debug.scope("Compiling", new DebugDumpScope(String.valueOf(id), true), new Callable() { @Override public CiTargetMethod call() throws Exception { @@ -148,7 +148,7 @@ } private void installMethod(final CiTargetMethod tm) { - Debug.scope("CodeInstall", new Object[] {compiler.getCompiler(), method}, new Runnable() { + Debug.scope("CodeInstall", new Object[] {new DebugDumpScope(String.valueOf(id), true), compiler.getCompiler(), method}, new Runnable() { @Override public void run() { final RiCodeInfo[] info = Debug.isDumpEnabled() ? new RiCodeInfo[1] : null; diff -r 16c27447923c -r 451327d8543b graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java Wed May 23 11:55:31 2012 +0200 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/CFGPrinterObserver.java Wed May 23 15:27:02 2012 +0200 @@ -47,6 +47,7 @@ private CFGPrinter cfgPrinter; private RiResolvedMethod curMethod; + private List curDecorators = Collections.emptyList(); @Override public void dump(Object object, String message) { @@ -57,14 +58,37 @@ } } - private static RiResolvedMethod lookupMethod() { - RiResolvedMethod method = Debug.contextLookup(RiResolvedMethod.class); - if (method != null) { - return method; + /** + * Looks for the outer most method and its {@link DebugDumpScope#decorator}s + * in the current debug scope and opens a new compilation scope if this pair + * does not match the current method and decorator pair. + */ + private void checkMethodScope() { + RiResolvedMethod method = null; + ArrayList decorators = new ArrayList<>(); + for (Object o : Debug.context()) { + if (o instanceof RiResolvedMethod) { + method = (RiResolvedMethod) o; + decorators.clear(); + } else if (o instanceof StructuredGraph) { + StructuredGraph graph = (StructuredGraph) o; + assert graph != null && graph.method() != null : "cannot find method context for CFG dump"; + method = graph.method(); + decorators.clear(); + } else if (o instanceof DebugDumpScope) { + DebugDumpScope debugDumpScope = (DebugDumpScope) o; + if (debugDumpScope.decorator) { + decorators.add(debugDumpScope.name); + } + } } - StructuredGraph graph = Debug.contextLookup(StructuredGraph.class); - assert graph != null && graph.method() != null : "cannot find method context for CFG dump"; - return graph.method(); + + if (method != curMethod || !curDecorators.equals(decorators)) { + cfgPrinter.printCompilation(method); + TTY.println("CFGPrinter: Dumping method %s", method); + curMethod = method; + curDecorators = decorators; + } } public void dumpSandboxed(Object object, String message) { @@ -84,13 +108,7 @@ TTY.println("CFGPrinter: Output to file %s", file); } - RiResolvedMethod newMethod = lookupMethod(); - - if (newMethod != curMethod) { - cfgPrinter.printCompilation(newMethod); - TTY.println("CFGPrinter: Dumping method %s", newMethod); - curMethod = newMethod; - } + checkMethodScope(); cfgPrinter.target = compiler.target; if (object instanceof LIR) { diff -r 16c27447923c -r 451327d8543b graal/com.oracle.graal.printer/src/com/oracle/graal/printer/IdealGraphPrinterDumpHandler.java --- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/IdealGraphPrinterDumpHandler.java Wed May 23 11:55:31 2012 +0200 +++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/IdealGraphPrinterDumpHandler.java Wed May 23 15:27:02 2012 +0200 @@ -123,7 +123,7 @@ for (int i = 0; i < inlineContext.size(); ++i) { if (i >= previousInlineContext.size() || !inlineContext.get(i).equals(previousInlineContext.get(i))) { for (int j = i; j < inlineContext.size(); ++j) { - openScope(inlineContext.get(j)); + openScope(inlineContext.get(j), j == 0); } break; } @@ -153,14 +153,19 @@ result.add(CiUtil.format("%H::%n(%p)", method)); } else if (o instanceof DebugDumpScope) { DebugDumpScope debugDumpScope = (DebugDumpScope) o; - result.add(debugDumpScope.getName()); + if (debugDumpScope.decorator && !result.isEmpty()) { + result.set(result.size() - 1, debugDumpScope.name + ":" + result.get(result.size() - 1)); + } else { + result.add(debugDumpScope.name); + } } } return result; } - private void openScope(String name) { - printer.beginGroup(Thread.currentThread().getName() + ":" + name, name, Debug.contextLookup(RiResolvedMethod.class), -1); + private void openScope(String name, boolean showThread) { + String prefix = showThread ? Thread.currentThread().getName() + ":" : ""; + printer.beginGroup(prefix + name, name, Debug.contextLookup(RiResolvedMethod.class), -1); } private void closeScope() { diff -r 16c27447923c -r 451327d8543b graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/CheckCastTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/CheckCastTest.java Wed May 23 15:27:02 2012 +0200 @@ -0,0 +1,121 @@ +/* + * 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 org.junit.*; + +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.java.*; +import com.oracle.max.cri.ri.*; + +/** + * Tests the implementation of checkcast, allowing profiling information to + * be manually specified. + */ +public class CheckCastTest extends TypeCheckTest { + + @Override + protected void replaceProfile(StructuredGraph graph, RiTypeProfile profile) { + CheckCastNode ccn = graph.getNodes(CheckCastNode.class).first(); + if (ccn != null) { + CheckCastNode ccnNew = graph.add(new CheckCastNode(ccn.targetClassInstruction(), ccn.targetClass(), ccn.object(), profile)); + graph.replaceFixedWithFixed(ccn, ccnNew); + } + } + + @Test + public void test1() { + test("asNumber", profile(), 111); + test("asNumber", profile(Integer.class), 111); + test("asNumber", profile(Long.class, Short.class), 111); + test("asNumberExt", profile(), 111); + test("asNumberExt", profile(Integer.class), 111); + test("asNumberExt", profile(Long.class, Short.class), 111); + } + + @Test + public void test2() { + test("asString", profile(), "111"); + test("asString", profile(String.class), "111"); + test("asString", profile(String.class), "111"); + + final String nullString = null; + test("asString", profile(), nullString); + test("asString", profile(String.class), nullString); + test("asString", profile(String.class), nullString); + + test("asStringExt", profile(), "111"); + test("asStringExt", profile(String.class), "111"); + test("asStringExt", profile(String.class), "111"); + } + + @Test + public void test3() { + test("asNumber", profile(), "111"); + } + + @Test + public void test4() { + test("asString", profile(String.class), 111); + } + + @Test + public void test5() { + test("asNumberExt", profile(), "111"); + } + + @Test + public void test6() { + test("asStringExt", profile(String.class), 111); + } + + public static Number asNumber(Object o) { + return (Number) o; + } + + public static String asString(Object o) { + return (String) o; + } + + public static Number asNumberExt(Object o) { + Number n = (Number) o; + return n.intValue() + 10; + } + + public static String asStringExt(Object o) { + String s = (String) o; + return "#" + s; + } + + @Test + public void test7() { + test("arrayFill", profile(), new Object[100], "111"); + } + + public static Object[] arrayFill(Object[] arr, Object value) { + for (int i = 0; i < arr.length; i++) { + arr[i] = value; + } + return arr; + } +} diff -r 16c27447923c -r 451327d8543b graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/CompiledMethodTest.java --- a/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/CompiledMethodTest.java Wed May 23 11:55:31 2012 +0200 +++ b/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/CompiledMethodTest.java Wed May 23 15:27:02 2012 +0200 @@ -68,8 +68,7 @@ } final RiResolvedMethod riMethod = runtime.getRiMethod(method); - CiTargetMethod targetMethod = runtime.compile(riMethod, graph); - RiCompiledMethod compiledMethod = addMethod(riMethod, targetMethod); + RiCompiledMethod compiledMethod = compile(riMethod, graph); try { Object result = compiledMethod.execute("1", "2", "3"); Assert.assertEquals("1-2-3", result); @@ -83,8 +82,7 @@ Method method = getMethod("testMethod"); final StructuredGraph graph = parse(method); final RiResolvedMethod riMethod = runtime.getRiMethod(method); - CiTargetMethod targetMethod = runtime.compile(riMethod, graph); - RiCompiledMethod compiledMethod = addMethod(riMethod, targetMethod); + RiCompiledMethod compiledMethod = compile(riMethod, graph); try { Object result = compiledMethod.executeVarargs("1", "2", "3"); Assert.assertEquals("1 2 3", result); @@ -98,8 +96,7 @@ Method method = getMethod("testMethodVirtual"); final StructuredGraph graph = parse(method); final RiResolvedMethod riMethod = runtime.getRiMethod(method); - CiTargetMethod targetMethod = runtime.compile(riMethod, graph); - RiCompiledMethod compiledMethod = addMethod(riMethod, targetMethod); + RiCompiledMethod compiledMethod = compile(riMethod, graph); try { f1 = "0"; Object result = compiledMethod.executeVarargs(this, "1", "2", "3"); @@ -127,9 +124,7 @@ } } - CiTargetMethod targetMethod = runtime.compile(riMethod, graph); - final RiCompiledMethod compiledMethod = addMethod(riMethod, targetMethod); - + RiCompiledMethod compiledMethod = compile(riMethod, graph); final CompilableObject compilableObject = new CompilableObjectImpl(0); Object result; diff -r 16c27447923c -r 451327d8543b graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/GraphTest.java --- a/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/GraphTest.java Wed May 23 11:55:31 2012 +0200 +++ b/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/GraphTest.java Wed May 23 15:27:02 2012 +0200 @@ -146,6 +146,17 @@ } } + private static int compilationId = 0; + + protected RiCompiledMethod compile(final RiResolvedMethod method, final StructuredGraph graph) { + return Debug.scope("Compiling", new DebugDumpScope(String.valueOf(compilationId++), true), new Callable() { + public RiCompiledMethod call() throws Exception { + CiTargetMethod targetMethod = runtime.compile(method, graph); + return addMethod(method, targetMethod); + } + }); + } + protected RiCompiledMethod addMethod(final RiResolvedMethod method, final CiTargetMethod tm) { Debug.scope("CodeInstall", new Object[] {graalCompiler, method}, new Callable() { @Override diff -r 16c27447923c -r 451327d8543b graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/InstanceOfTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/InstanceOfTest.java Wed May 23 15:27:02 2012 +0200 @@ -0,0 +1,150 @@ +/* + * 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.nodes.*; +import com.oracle.graal.nodes.java.*; +import com.oracle.max.cri.ri.*; + +/** + * Tests the implementation of instanceof, allowing profiling information to + * be manually specified. + */ +public class InstanceOfTest extends TypeCheckTest { + + @Override + protected void replaceProfile(StructuredGraph graph, RiTypeProfile profile) { + InstanceOfNode ion = graph.getNodes().filter(InstanceOfNode.class).first(); + if (ion != null) { + InstanceOfNode ionNew = graph.add(new InstanceOfNode(ion.targetClassInstruction(), ion.targetClass(), ion.object(), profile)); + graph.replaceFloating(ion, ionNew); + } + } + + @Test + public void test1() { + test("isString", profile(), "object"); + test("isString", profile(String.class), "object"); + test("isString", profile(Long.class, Short.class), "object"); + + test("isString", profile(), Object.class); + test("isString", profile(String.class), Object.class); + test("isString", profile(Long.class, Short.class), Object.class); + } + + @Test + public void test2() { + test("isStringInt", profile(), "object"); + test("isStringInt", profile(String.class), "object"); + test("isStringInt", profile(Long.class, Short.class), "object"); + + test("isStringInt", profile(), Object.class); + test("isStringInt", profile(String.class), Object.class); + test("isStringInt", profile(Long.class, Short.class), Object.class); + } + + @Test + public void test3() { + Throwable throwable = new Exception(); + test("isThrowable", profile(), throwable); + test("isThrowable", profile(String.class), throwable); + test("isThrowable", profile(Long.class, Short.class), throwable); + + test("isThrowable", profile(), Object.class); + test("isThrowable", profile(String.class), Object.class); + test("isThrowable", profile(Long.class, Short.class), Object.class); + } + + @Test + public void test4() { + Throwable throwable = new Exception(); + test("isThrowableInt", profile(), throwable); + test("isThrowableInt", profile(String.class), throwable); + test("isThrowableInt", profile(Long.class, Short.class), throwable); + + test("isThrowableInt", profile(), Object.class); + test("isThrowableInt", profile(String.class), Object.class); + test("isThrowableInt", profile(Long.class, Short.class), Object.class); + } + + @Test + public void test5() { + Map map = new HashMap<>(); + test("isMap", profile(), map); + test("isMap", profile(String.class), map); + test("isMap", profile(Long.class, Short.class), map); + + test("isMap", profile(), Object.class); + test("isMap", profile(String.class), Object.class); + test("isMap", profile(Long.class, Short.class), Object.class); + } + + @Test + public void test6() { + Map map = new HashMap<>(); + test("isMapInt", profile(), map); + test("isMapInt", profile(String.class), map); + test("isMapInt", profile(Long.class, Short.class), map); + + test("isMapInt", profile(), Object.class); + test("isMapInt", profile(String.class), Object.class); + test("isMapInt", profile(Long.class, Short.class), Object.class); + } + + public static boolean isString(Object o) { + return o instanceof String; + } + + public static int isStringInt(Object o) { + if (o instanceof String) { + return 1; + } + return 0; + } + + public static boolean isThrowable(Object o) { + return o instanceof Throwable; + } + + public static int isThrowableInt(Object o) { + if (o instanceof Throwable) { + return 1; + } + return 0; + } + + public static boolean isMap(Object o) { + return o instanceof Map; + } + + public static int isMapInt(Object o) { + if (o instanceof Map) { + return 1; + } + return 0; + } +} diff -r 16c27447923c -r 451327d8543b graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/LowerCheckCastTest.java --- a/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/LowerCheckCastTest.java Wed May 23 11:55:31 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,165 +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.compiler.tests; - -import java.lang.reflect.*; - -import org.junit.*; - -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.java.*; -import com.oracle.max.cri.ci.*; -import com.oracle.max.cri.ri.*; -import com.oracle.max.cri.ri.RiTypeProfile.ProfiledType; - -public class LowerCheckCastTest extends GraphTest { - - private RiCompiledMethod compile(Method method, RiTypeProfile profile) { - final StructuredGraph graph = parse(method); - - CheckCastNode ccn = graph.getNodes(CheckCastNode.class).first(); - if (ccn != null) { - CheckCastNode ccnNew = graph.add(new CheckCastNode(ccn.targetClassInstruction(), ccn.targetClass(), ccn.object(), profile)); - graph.replaceFixedWithFixed(ccn, ccnNew); - } - - final RiResolvedMethod riMethod = runtime.getRiMethod(method); - CiTargetMethod targetMethod = runtime.compile(riMethod, graph); - return addMethod(riMethod, targetMethod); - } - - private RiTypeProfile profile(Class... types) { - if (types.length == 0) { - return null; - } - ProfiledType[] ptypes = new ProfiledType[types.length]; - for (int i = 0; i < types.length; i++) { - ptypes[i] = new ProfiledType(runtime.getType(types[i]), 1.0D / types.length); - } - return new RiTypeProfile(0.0D, ptypes); - } - - private void test(String name, RiTypeProfile profile, 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); - } - RiCompiledMethod 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); - } - } - - @Test - public void test1() { - test("asNumber", profile(), 111); - test("asNumber", profile(Integer.class), 111); - test("asNumber", profile(Long.class, Short.class), 111); - test("asNumberExt", profile(), 111); - test("asNumberExt", profile(Integer.class), 111); - test("asNumberExt", profile(Long.class, Short.class), 111); - } - - @Test - public void test2() { - test("asString", profile(), "111"); - test("asString", profile(String.class), "111"); - test("asString", profile(String.class), "111"); - - final String nullString = null; - test("asString", profile(), nullString); - test("asString", profile(String.class), nullString); - test("asString", profile(String.class), nullString); - - test("asStringExt", profile(), "111"); - test("asStringExt", profile(String.class), "111"); - test("asStringExt", profile(String.class), "111"); - } - - @Test - public void test3() { - test("asNumber", profile(), "111"); - } - - @Test - public void test4() { - test("asString", profile(String.class), 111); - } - - @Test - public void test5() { - test("asNumberExt", profile(), "111"); - } - - @Test - public void test6() { - test("asStringExt", profile(String.class), 111); - } - - public static Number asNumber(Object o) { - return (Number) o; - } - - public static String asString(Object o) { - return (String) o; - } - - public static Number asNumberExt(Object o) { - Number n = (Number) o; - return n.intValue() + 10; - } - - public static String asStringExt(Object o) { - String s = (String) o; - return "#" + s; - } - - @Test - public void test7() { - test("arrayFill", profile(), new Object[100], "111"); - } - - public static Object[] arrayFill(Object[] arr, Object value) { - for (int i = 0; i < arr.length; i++) { - arr[i] = value; - } - return arr; - } -} diff -r 16c27447923c -r 451327d8543b graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/TypeCheckTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/TypeCheckTest.java Wed May 23 15:27:02 2012 +0200 @@ -0,0 +1,84 @@ +/* + * 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.lang.reflect.*; + +import org.junit.*; + +import com.oracle.graal.nodes.*; +import com.oracle.max.cri.ri.*; +import com.oracle.max.cri.ri.RiTypeProfile.ProfiledType; + +/** + * Base class for checkcast and instanceof test classes. + */ +public abstract class TypeCheckTest extends GraphTest { + + protected abstract void replaceProfile(StructuredGraph graph, RiTypeProfile profile); + + private RiCompiledMethod compile(Method method, RiTypeProfile profile) { + final StructuredGraph graph = parse(method); + replaceProfile(graph, profile); + return compile(runtime.getRiMethod(method), graph); + } + + protected RiTypeProfile profile(Class... types) { + if (types.length == 0) { + return null; + } + ProfiledType[] ptypes = new ProfiledType[types.length]; + for (int i = 0; i < types.length; i++) { + ptypes[i] = new ProfiledType(runtime.getType(types[i]), 1.0D / types.length); + } + return new RiTypeProfile(0.0D, ptypes); + } + + protected void test(String name, RiTypeProfile profile, 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); + } + RiCompiledMethod 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); + } + } +} diff -r 16c27447923c -r 451327d8543b mx/commands.py --- a/mx/commands.py Wed May 23 11:55:31 2012 +0200 +++ b/mx/commands.py Wed May 23 15:27:02 2012 +0200 @@ -736,6 +736,10 @@ args = parser.parse_args(args) + global _vmbuild + global _vm + global _jacoco + tasks = [] total = Task('Gate') try: @@ -752,9 +756,7 @@ t = Task('BuildJava') build(['--no-native']) tasks.append(t.stop()) - global _jacoco for vmbuild in ['fastdebug', 'product']: - global _vmbuild _vmbuild = vmbuild if args.buildNative: @@ -816,6 +818,18 @@ t = Task('BuildHotSpotVarieties') buildvms(['--vms', 'client,server', '--builds', 'fastdebug,product']) tasks.append(t.stop()) + + for vmbuild in ['product', 'fastdebug']: + _vmbuild = vmbuild + for theVm in ['client', 'server']: + _vm = theVm + # TODO: remove once regression in fastdebug-server has been fixed + if vmbuild == 'fastdebug' and theVm == 'server': + continue + + t = Task('DaCapo_pmd:' + theVm + ':' + vmbuild) + dacapo(['pmd']) + tasks.append(t.stop()) except KeyboardInterrupt: total.abort(1)