# HG changeset patch # User Doug Simon # Date 1339417542 -7200 # Node ID 2e2a77f091f2f6770d7bfc968b54b24ab0d7dd38 # Parent 4b47c0898e89b3270edfa0d93b7c8caec65669b8 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 diff -r 4b47c0898e89 -r 2e2a77f091f2 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java --- 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; } } diff -r 4b47c0898e89 -r 2e2a77f091f2 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 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 () { 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() { + GraalCompiler graalCompiler = Graal.getRuntime().getCapability(GraalCompiler.class); + assert graalCompiler != null; + return Debug.scope("CodeInstall", new Object[] {graalCompiler, method}, new Callable() { @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; } diff -r 4b47c0898e89 -r 2e2a77f091f2 graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/NewInstanceTest.java --- /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); + } +} diff -r 4b47c0898e89 -r 2e2a77f091f2 graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/TypeCheckTest.java --- 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; } } }