# HG changeset patch # User Doug Simon # Date 1336383256 -7200 # Node ID 6cc970203f30f6d77e92fe4407edbebb7a028765 # Parent 4bfdf8cf87af3567e48a968ddfda882d30267d79 moved creation of a RiCodeInfo to the runtime side of the CRI diff -r 4bfdf8cf87af -r 6cc970203f30 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 Mon May 07 11:08:58 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Mon May 07 11:34:16 2012 +0200 @@ -153,10 +153,10 @@ Debug.scope("CodeInstall", new Object[] {compiler.getCompiler(), method}, new Runnable() { @Override public void run() { - final HotSpotCodeInfo info = Debug.isDumpEnabled() ? new HotSpotCodeInfo(compiler, tm, method) : null; + final RiCodeInfo[] info = Debug.isDumpEnabled() ? new RiCodeInfo[1] : null; compiler.getRuntime().installMethod(method, tm, info); if (info != null) { - Debug.dump(info, "After code installation"); + Debug.dump(info[0], "After code installation"); } } diff -r 4bfdf8cf87af -r 6cc970203f30 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilerImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilerImpl.java Mon May 07 11:08:58 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilerImpl.java Mon May 07 11:34:16 2012 +0200 @@ -157,12 +157,19 @@ } /** - * Factory method for getting a Graal compiler instance. This method is called via reflection. + * Factory method for getting a {@link GraalRuntime} instance. This method is called via reflection. */ public static GraalRuntime getGraalRuntime() { return getInstance().getRuntime(); } + /** + * Factory method for getting a {@link GraalCompiler} instance. This method is called via reflection. + */ + public static GraalCompiler getGraalCompiler() { + return getInstance().getCompiler(); + } + @Override public GraalCompiler getCompiler() { if (compiler == null) { @@ -238,19 +245,6 @@ @Override public HotSpotRuntime getRuntime() { if (runtime == null) { - if (GraalOptions.PrintCFGToFile) { -// context.addCompilationObserver(new CFGPrinterObserver()); - } - // if (GraalOptions.PrintIdealGraphLevel != 0 || GraalOptions.Plot || GraalOptions.PlotOnError) { - // CompilationObserver observer; - // if (GraalOptions.PrintIdealGraphFile) { - // observer = new IdealGraphPrinterObserver(); - // } else { - // observer = new IdealGraphPrinterObserver(GraalOptions.PrintIdealGraphAddress, GraalOptions.PrintIdealGraphPort); - // } -// context.addCompilationObserver(observer); - // TODO (thomaswue): Install observer. - // } runtime = new HotSpotRuntime(config, this); } return runtime; diff -r 4bfdf8cf87af -r 6cc970203f30 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilerObject.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilerObject.java Mon May 07 11:08:58 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilerObject.java Mon May 07 11:34:16 2012 +0200 @@ -24,11 +24,13 @@ import java.io.*; +import com.oracle.max.cri.ci.CiKind.FormatWithToString; + /** * Parent class for all HotSpot Ri... types. */ -public abstract class CompilerObject implements Serializable { +public abstract class CompilerObject implements Serializable, FormatWithToString { private static final long serialVersionUID = -4551670987101214877L; protected final Compiler compiler; diff -r 4bfdf8cf87af -r 6cc970203f30 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Mon May 07 11:08:58 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Mon May 07 11:34:16 2012 +0200 @@ -63,7 +63,7 @@ void RiConstantPool_loadReferencedType(HotSpotTypeResolved pool, int cpi, byte byteCode); - HotSpotCompiledMethod installMethod(HotSpotTargetMethod targetMethod, boolean installCode, HotSpotCodeInfo info); + HotSpotCompiledMethod installMethod(HotSpotTargetMethod targetMethod, boolean makeDefault, HotSpotCodeInfo info); long installStub(HotSpotTargetMethod targetMethod, HotSpotCodeInfo info); diff -r 4bfdf8cf87af -r 6cc970203f30 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Mon May 07 11:08:58 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Mon May 07 11:34:16 2012 +0200 @@ -78,7 +78,7 @@ public native RiField RiConstantPool_lookupField(HotSpotTypeResolved pool, int cpi, byte byteCode); @Override - public native HotSpotCompiledMethod installMethod(HotSpotTargetMethod targetMethod, boolean installCode, HotSpotCodeInfo info); + public native HotSpotCompiledMethod installMethod(HotSpotTargetMethod targetMethod, boolean makeDefault, HotSpotCodeInfo info); @Override public native long installStub(HotSpotTargetMethod targetMethod, HotSpotCodeInfo info); diff -r 4bfdf8cf87af -r 6cc970203f30 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotKlassOop.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotKlassOop.java Mon May 07 11:08:58 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotKlassOop.java Mon May 07 11:34:16 2012 +0200 @@ -44,4 +44,9 @@ super(compiler); this.javaMirror = javaMirror; } + + @Override + public String toString() { + return "HotSpotKlassOop<" + javaMirror.getName() + ">"; + } } diff -r 4bfdf8cf87af -r 6cc970203f30 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotRuntime.java Mon May 07 11:08:58 2012 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/ri/HotSpotRuntime.java Mon May 07 11:34:16 2012 +0200 @@ -475,14 +475,25 @@ return (RiResolvedMethod) compiler.getCompilerToVM().getRiMethod(reflectionMethod); } - @Override - public void installMethod(RiResolvedMethod method, CiTargetMethod code, RiCodeInfo info) { - compiler.getCompilerToVM().installMethod(new HotSpotTargetMethod(compiler, (HotSpotMethodResolved) method, code), true, (HotSpotCodeInfo) info); + private HotSpotCodeInfo makeInfo(RiResolvedMethod method, CiTargetMethod code, RiCodeInfo[] info) { + HotSpotCodeInfo hsInfo = null; + if (info != null && info.length > 0) { + hsInfo = new HotSpotCodeInfo(compiler, code, (HotSpotMethodResolved) method); + info[0] = hsInfo; + } + return hsInfo; } @Override - public RiCompiledMethod addMethod(RiResolvedMethod method, CiTargetMethod code) { - return compiler.getCompilerToVM().installMethod(new HotSpotTargetMethod(compiler, (HotSpotMethodResolved) method, code), false, null); + public void installMethod(RiResolvedMethod method, CiTargetMethod code, RiCodeInfo[] info) { + HotSpotCodeInfo hsInfo = makeInfo(method, code, info); + compiler.getCompilerToVM().installMethod(new HotSpotTargetMethod(compiler, (HotSpotMethodResolved) method, code), true, hsInfo); + } + + @Override + public RiCompiledMethod addMethod(RiResolvedMethod method, CiTargetMethod code, RiCodeInfo[] info) { + HotSpotCodeInfo hsInfo = makeInfo(method, code, info); + return compiler.getCompilerToVM().installMethod(new HotSpotTargetMethod(compiler, (HotSpotMethodResolved) method, code), false, hsInfo); } @Override diff -r 4bfdf8cf87af -r 6cc970203f30 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 Mon May 07 11:08:58 2012 +0200 +++ b/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/CompiledMethodTest.java Mon May 07 11:34:16 2012 +0200 @@ -69,7 +69,7 @@ final RiResolvedMethod riMethod = runtime.getRiMethod(method); CiTargetMethod targetMethod = runtime.compile(riMethod, graph); - RiCompiledMethod compiledMethod = runtime.addMethod(riMethod, targetMethod); + RiCompiledMethod compiledMethod = addMethod(riMethod, targetMethod); try { Object result = compiledMethod.execute("1", "2", "3"); Assert.assertEquals("1-2-3", result); @@ -84,7 +84,7 @@ final StructuredGraph graph = parse(method); final RiResolvedMethod riMethod = runtime.getRiMethod(method); CiTargetMethod targetMethod = runtime.compile(riMethod, graph); - RiCompiledMethod compiledMethod = runtime.addMethod(riMethod, targetMethod); + RiCompiledMethod compiledMethod = addMethod(riMethod, targetMethod); try { Object result = compiledMethod.executeVarargs("1", "2", "3"); Assert.assertEquals("1 2 3", result); @@ -99,7 +99,7 @@ final StructuredGraph graph = parse(method); final RiResolvedMethod riMethod = runtime.getRiMethod(method); CiTargetMethod targetMethod = runtime.compile(riMethod, graph); - RiCompiledMethod compiledMethod = runtime.addMethod(riMethod, targetMethod); + RiCompiledMethod compiledMethod = addMethod(riMethod, targetMethod); try { f1 = "0"; Object result = compiledMethod.executeVarargs(this, "1", "2", "3"); @@ -128,7 +128,7 @@ } CiTargetMethod targetMethod = runtime.compile(riMethod, graph); - final RiCompiledMethod compiledMethod = runtime.addMethod(riMethod, targetMethod); + final RiCompiledMethod compiledMethod = addMethod(riMethod, targetMethod); final CompilableObject compilableObject = new CompilableObjectImpl(0); diff -r 4bfdf8cf87af -r 6cc970203f30 graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/GraalAccess.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/GraalAccess.java Mon May 07 11:34:16 2012 +0200 @@ -0,0 +1,86 @@ +/* + * 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 java.util.*; + +import com.oracle.graal.compiler.*; + +/** + * Utility for getting a Graal objects from the current execution environment. + */ +class GraalAccess { + + /** + * The known classes declaring a {@code getGraalCompiler()} method. These class names + * have aliases that can be used with the {@code "graal.access"} system property to + * specify the VM environment to try first when getting a Graal compiler instance. + */ + private static Map graalAccessClasses = new LinkedHashMap<>(); + static { + graalAccessClasses.put("HotSpot", "com.oracle.graal.hotspot.CompilerImpl"); + graalAccessClasses.put("Maxine", "com.oracle.max.vm.ext.maxri.MaxRuntime"); + } + + /** + * Gets a {@link GraalCompiler} instance from the current execution environment. + */ + static GraalCompiler getGraalCompiler() { + String vm = System.getProperty("graal.access"); + if (vm != null) { + String cn = graalAccessClasses.get(vm); + if (cn != null) { + GraalCompiler graalCompiler = getGraalCompiler(cn); + if (graalCompiler != null) { + return graalCompiler; + } + } + } + + for (String className : graalAccessClasses.values()) { + GraalCompiler graalCompiler = getGraalCompiler(className); + if (graalCompiler != null) { + return graalCompiler; + } + } + throw new InternalError("Could not create a GraalRuntime instance"); + } + + /** + * Calls {@code getGraalCompiler()} via reflection on a given class. + * + * @return {@code null} if there was an error invoking the method or if the method returns {@code null} itself + */ + private static GraalCompiler getGraalCompiler(String className) { + try { + Class c = Class.forName(className); + Method m = c.getDeclaredMethod("getGraalCompiler"); + return (GraalCompiler) m.invoke(null); + } catch (Exception e) { + //e.printStackTrace(); + System.err.println(e); + return null; + } + } +} diff -r 4bfdf8cf87af -r 6cc970203f30 graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/GraalRuntimeAccess.java --- a/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/GraalRuntimeAccess.java Mon May 07 11:08:58 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +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 java.util.*; - -import com.oracle.graal.cri.*; - -/** - * Utility for getting a {@link GraalRuntime} instance from the current execution environment. - */ -class GraalRuntimeAccess { - - /** - * The known classes declaring a {@code getGraalRuntime()} method. These class names - * have aliases that can be used with the {@code "graal.runtime"} system property to - * specify the VM environment to try first when getting a Graal runtime instance. - */ - private static Map graalRuntimeFactoryClasses = new LinkedHashMap<>(); - static { - graalRuntimeFactoryClasses.put("HotSpot", "com.oracle.graal.hotspot.CompilerImpl"); - graalRuntimeFactoryClasses.put("Maxine", "com.oracle.max.vm.ext.maxri.MaxRuntime"); - } - - /** - * Gets a Graal runtime instance from the current execution environment. - */ - static GraalRuntime getGraalRuntime() { - String vm = System.getProperty("graal.runtime"); - if (vm != null) { - String cn = graalRuntimeFactoryClasses.get(vm); - if (cn != null) { - GraalRuntime graal = getGraalRuntime(cn); - if (graal != null) { - return graal; - } - } - } - - for (String className : graalRuntimeFactoryClasses.values()) { - GraalRuntime graal = getGraalRuntime(className); - if (graal != null) { - return graal; - } - } - throw new InternalError("Could not create a GraalRuntime instance"); - } - - /** - * Calls {@code getGraalRuntime()} via reflection on a given class. - * - * @return {@code null} if there was an error invoking the methodor if the method return {@code null} itself - */ - private static GraalRuntime getGraalRuntime(String className) { - try { - Class c = Class.forName(className); - Method m = c.getDeclaredMethod("getGraalRuntime"); - return (GraalRuntime) m.invoke(null); - } catch (Exception e) { - //e.printStackTrace(); - System.err.println(e); - return null; - } - } -} diff -r 4bfdf8cf87af -r 6cc970203f30 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 Mon May 07 11:08:58 2012 +0200 +++ b/graal/com.oracle.graal.tests/src/com/oracle/graal/compiler/tests/GraphTest.java Mon May 07 11:34:16 2012 +0200 @@ -23,6 +23,7 @@ package com.oracle.graal.compiler.tests; import java.lang.reflect.*; +import java.util.concurrent.*; import junit.framework.*; @@ -33,6 +34,7 @@ import com.oracle.graal.debug.*; import com.oracle.graal.java.*; import com.oracle.graal.nodes.*; +import com.oracle.max.cri.ci.*; import com.oracle.max.cri.ri.*; /** @@ -40,7 +42,7 @@ * for Graal compiler transformations. The general pattern for a test is: *
    *
  1. Create a graph by {@linkplain #parse(String) parsing} a method.
  2. - *
  3. Manually modify the graph (e.g. replace a paramter node with a constant).
  4. + *
  5. Manually modify the graph (e.g. replace a parameter node with a constant).
  6. *
  7. Apply a transformation to the graph.
  8. *
  9. Assert that the transformed graph is equal to an expected graph.
  10. *
@@ -53,11 +55,13 @@ */ public abstract class GraphTest { + protected final GraalCompiler graalCompiler; protected final GraalRuntime runtime; public GraphTest() { Debug.enable(); - this.runtime = GraalRuntimeAccess.getGraalRuntime(); + this.graalCompiler = GraalAccess.getGraalCompiler(); + this.runtime = graalCompiler.runtime; } protected void assertEquals(StructuredGraph expected, StructuredGraph graph) { @@ -96,6 +100,21 @@ } } + protected RiCompiledMethod addMethod(final RiResolvedMethod method, final CiTargetMethod tm) { + Debug.scope("CodeInstall", new Object[] {graalCompiler, method}, new Callable() { + @Override + public RiCompiledMethod call() throws Exception { + final RiCodeInfo[] info = Debug.isDumpEnabled() ? new RiCodeInfo[1] : null; + RiCompiledMethod installedMethod = runtime.addMethod(method, tm, info); + if (info != null) { + Debug.dump(info[0], "After code installation"); + } + return installedMethod; + } + }); + return runtime.addMethod(method, tm, null); + } + /** * Parses a Java method to produce a graph. * diff -r 4bfdf8cf87af -r 6cc970203f30 graal/com.oracle.max.cri/src/com/oracle/max/cri/ri/RiRuntime.java --- a/graal/com.oracle.max.cri/src/com/oracle/max/cri/ri/RiRuntime.java Mon May 07 11:08:58 2012 +0200 +++ b/graal/com.oracle.max.cri/src/com/oracle/max/cri/ri/RiRuntime.java Mon May 07 11:34:16 2012 +0200 @@ -176,17 +176,20 @@ * * @param method a method whose executable code is being modified * @param code the code to be executed when {@code method} is called - * @param info the object into which details of the installed code will be written (ignored if null) + * @param info the object into which details of the installed code will be written. + * Ignored if null, otherwise the info is written to index 0 of this array. */ - void installMethod(RiResolvedMethod method, CiTargetMethod code, RiCodeInfo info); + void installMethod(RiResolvedMethod method, CiTargetMethod code, RiCodeInfo[] info); /** * Adds the given machine code as an implementation of the given method without making it the default implementation. * @param method a method to which the executable code is begin added * @param code the code to be added + * @param info the object into which details of the installed code will be written. + * Ignored if null, otherwise the info is written to index 0 of this array. * @return a reference to the compiled and ready-to-run code */ - RiCompiledMethod addMethod(RiResolvedMethod method, CiTargetMethod code); + RiCompiledMethod addMethod(RiResolvedMethod method, CiTargetMethod code, RiCodeInfo[] info); /** * Encodes a deoptimization action and a deoptimization reason in an integer value.