# HG changeset patch # User Doug Simon # Date 1382546705 -7200 # Node ID c69d0a705553517cbaddc1f984eae281c72d16a6 # Parent 37207d7e9056205a1000f0b763e09c3828041935 improved debug scope context when compiling Truffle IR graphs by making a Truffle compilable masquerade as a JavaMethod diff -r 37207d7e9056 -r c69d0a705553 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Wed Oct 23 17:50:58 2013 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Wed Oct 23 18:45:05 2013 +0200 @@ -138,32 +138,44 @@ Debug.scope("GraalCompiler", new Object[]{graph, providers.getCodeCache()}, new Runnable() { public void run() { - final Assumptions assumptions = new Assumptions(OptAssumptions.getValue()); - final LIR lir = Debug.scope("FrontEnd", new Callable() { + compileGraphNoScope(graph, cc, installedCodeOwner, providers, backend, target, cache, plan, optimisticOpts, speculationLog, suites, compilationResult); + } + }); - public LIR call() { - try (TimerCloseable a = FrontEnd.start()) { - return emitHIR(providers, target, graph, assumptions, cache, plan, optimisticOpts, speculationLog, suites); - } - } - }); - try (TimerCloseable a = BackEnd.start()) { - final LIRGenerator lirGen = Debug.scope("BackEnd", lir, new Callable() { + return compilationResult; + } - public LIRGenerator call() { - return emitLIR(backend, target, lir, graph, cc); - } - }); - Debug.scope("CodeGen", lirGen, new Runnable() { + /** + * Same as {@link #compileGraph} but without entering a + * {@linkplain Debug#scope(String, Object[], Runnable) debug scope}. + */ + public static T compileGraphNoScope(final StructuredGraph graph, final CallingConvention cc, final ResolvedJavaMethod installedCodeOwner, final Providers providers, + final Backend backend, final TargetDescription target, final GraphCache cache, final PhasePlan plan, final OptimisticOptimizations optimisticOpts, + final SpeculationLog speculationLog, final Suites suites, final T compilationResult) { + final Assumptions assumptions = new Assumptions(OptAssumptions.getValue()); + final LIR lir = Debug.scope("FrontEnd", new Callable() { - public void run() { - emitCode(backend, getLeafGraphIdArray(graph), assumptions, lirGen, compilationResult, installedCodeOwner); - } - - }); + public LIR call() { + try (TimerCloseable a = FrontEnd.start()) { + return emitHIR(providers, target, graph, assumptions, cache, plan, optimisticOpts, speculationLog, suites); } } }); + try (TimerCloseable a = BackEnd.start()) { + final LIRGenerator lirGen = Debug.scope("BackEnd", lir, new Callable() { + + public LIRGenerator call() { + return emitLIR(backend, target, lir, graph, cc); + } + }); + Debug.scope("CodeGen", lirGen, new Runnable() { + + public void run() { + emitCode(backend, getLeafGraphIdArray(graph), assumptions, lirGen, compilationResult, installedCodeOwner); + } + + }); + } return compilationResult; } diff -r 37207d7e9056 -r c69d0a705553 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java Wed Oct 23 17:50:58 2013 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerImpl.java Wed Oct 23 18:45:05 2013 +0200 @@ -137,6 +137,7 @@ public InstalledCode compileMethodHelper(final StructuredGraph graph, final GraphBuilderConfiguration config, final OptimizedCallTarget compilable, final Assumptions assumptions) { final PhasePlan plan = createPhasePlan(config); + final TruffleIRJavaMethod truffleJavaMethod = new TruffleIRJavaMethod(providers.getMetaAccess(), compilable); Debug.scope("TruffleFinal", graph, new Runnable() { @@ -151,10 +152,15 @@ @Override public CompilationResult call() { try (TimerCloseable a = CompilationTime.start()) { - CodeCacheProvider codeCache = providers.getCodeCache(); - CallingConvention cc = getCallingConvention(codeCache, Type.JavaCallee, graph.method(), false); - return GraalCompiler.compileGraph(graph, cc, graph.method(), providers, backend, codeCache.getTarget(), null, plan, OptimisticOptimizations.ALL, new SpeculationLog(), suites, - new CompilationResult(compilable.toString())); + return Debug.scope("GraalCompiler", new Object[]{truffleJavaMethod, providers.getCodeCache()}, new Callable() { + public CompilationResult call() { + CodeCacheProvider codeCache = providers.getCodeCache(); + CallingConvention cc = getCallingConvention(codeCache, Type.JavaCallee, graph.method(), false); + CompilationResult compilationResult = new CompilationResult(compilable.toString()); + return GraalCompiler.compileGraphNoScope(graph, cc, graph.method(), providers, backend, codeCache.getTarget(), null, plan, OptimisticOptimizations.ALL, + new SpeculationLog(), suites, compilationResult); + } + }); } } }); @@ -175,7 +181,7 @@ result.setAssumptions(newAssumptions); - InstalledCode compiledMethod = Debug.scope("CodeInstall", new Object[]{graph.method()}, new Callable() { + InstalledCode compiledMethod = Debug.scope("CodeInstall", new Object[]{truffleJavaMethod, providers.getCodeCache()}, new Callable() { @Override public InstalledCode call() throws Exception { diff -r 37207d7e9056 -r c69d0a705553 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleIRJavaMethod.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleIRJavaMethod.java Wed Oct 23 18:45:05 2013 +0200 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2013, 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.truffle; + +import static com.oracle.graal.api.meta.MetaUtil.*; + +import com.oracle.graal.api.meta.*; +import com.oracle.graal.debug.*; +import com.oracle.truffle.api.impl.*; + +/** + * Enables a Truffle compilable to masquerade as a {@link JavaMethod} for use as a context value in + * {@linkplain Debug#scope(String, Object[], Runnable) debug scopes}. + */ +class TruffleIRJavaMethod implements JavaMethod { + private final MetaAccessProvider metaAccess; + private final DefaultCallTarget compilable; + + public TruffleIRJavaMethod(MetaAccessProvider metaAccess, DefaultCallTarget compilable) { + this.metaAccess = metaAccess; + this.compilable = compilable; + } + + public Signature getSignature() { + return metaAccess.parseMethodDescriptor("()V"); + } + + public String getName() { + return compilable.toString().replace('.', '_').replace(' ', '_'); + } + + public JavaType getDeclaringClass() { + return metaAccess.lookupJavaType(getClass()); + } + + @Override + public String toString() { + return format(getClass().getSimpleName() + "<%n(%p)>", this); + } +}