# HG changeset patch # User Thomas Wuerthinger # Date 1373393364 -7200 # Node ID 759415ed915a5a2e65c85752105272a58d8f3057 # Parent 3bbe14e492fba120d22a4c74d53c9653f9a4d698# Parent 853a894e0d97f6818eb1727bd231475e2905b05e Merge. diff -r 853a894e0d97 -r 759415ed915a graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java Tue Jul 09 17:55:02 2013 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java Tue Jul 09 20:09:24 2013 +0200 @@ -237,27 +237,21 @@ } } } + + if (graph.getNodeCount() > TruffleCompilerOptions.TruffleGraphMaxNodes.getValue()) { + throw new BailoutException("Truffle compilation is exceeding maximum node count: " + graph.getNodeCount()); + } } } while (changed && newFrameNode.isAlive() && newFrameNode.usages().isNotEmpty()); } private StructuredGraph parseGraph(final ResolvedJavaMethod targetMethod, final NodeInputList arguments, final Assumptions assumptions, final boolean canonicalizeReads) { - final StructuredGraph graph = truffleCache.lookup(targetMethod, arguments).copy(); + final StructuredGraph graph = truffleCache.lookup(targetMethod, arguments, assumptions); Debug.scope("parseGraph", targetMethod, new Runnable() { @Override public void run() { - // Pass on constant arguments. - for (LocalNode local : graph.getNodes(LocalNode.class)) { - ValueNode arg = arguments.get(local.index()); - if (arg.isConstant()) { - Constant constant = arg.asConstant(); - local.replaceAndDelete(ConstantNode.forConstant(constant, metaAccessProvider, graph)); - } else { - local.setStamp(arg.stamp()); - } - } // Canonicalize / constant propagate. new CanonicalizerPhase.Instance(metaAccessProvider, assumptions, canonicalizeReads, null, customCanonicalizer).apply(graph); diff -r 853a894e0d97 -r 759415ed915a graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCache.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCache.java Tue Jul 09 17:55:02 2013 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCache.java Tue Jul 09 20:09:24 2013 +0200 @@ -66,60 +66,90 @@ this.replacements = replacements; } - public StructuredGraph lookup(final ResolvedJavaMethod method, final NodeInputList arguments) { + public StructuredGraph lookup(final ResolvedJavaMethod method, final NodeInputList arguments, final Assumptions assumptions) { + StructuredGraph resultGraph = null; if (cache.containsKey(method)) { StructuredGraph graph = cache.get(method); if (checkArgumentStamps(graph, arguments)) { - return graph; + resultGraph = graph; } } - StructuredGraph resultGraph = Debug.sandbox("TruffleCache", new Object[]{metaAccessProvider, method}, DebugScope.getConfig(), new Callable() { + if (resultGraph == null) { + resultGraph = Debug.sandbox("TruffleCache", new Object[]{metaAccessProvider, method}, DebugScope.getConfig(), new Callable() { + + public StructuredGraph call() { + StructuredGraph newGraph = parseGraph(method); - public StructuredGraph call() { - StructuredGraph newGraph = parseGraph(method); + // Get stamps from actual arguments. + List stamps = new ArrayList<>(); + for (ValueNode arg : arguments) { + stamps.add(arg.stamp()); + } - // Get stamps from actual arguments. - List stamps = new ArrayList<>(); - for (ValueNode arg : arguments) { - stamps.add(arg.stamp()); - } + if (cache.containsKey(method)) { + // Make sure stamps are generalized based on previous stamps. + StructuredGraph graph = cache.get(method); + for (LocalNode localNode : graph.getNodes(LocalNode.class)) { + int index = localNode.index(); + Stamp stamp = stamps.get(index); + stamps.set(index, stamp.meet(localNode.stamp())); + } + } - if (cache.containsKey(method)) { - // Make sure stamps are generalized based on previous stamps. - StructuredGraph graph = cache.get(method); - for (LocalNode localNode : graph.getNodes(LocalNode.class)) { + // Set stamps into graph before optimizing. + for (LocalNode localNode : newGraph.getNodes(LocalNode.class)) { int index = localNode.index(); Stamp stamp = stamps.get(index); - stamps.set(index, stamp.meet(localNode.stamp())); + localNode.setStamp(stamp); + } + + Assumptions tmpAssumptions = new Assumptions(false); + optimizeGraph(newGraph, tmpAssumptions); + + HighTierContext context = new HighTierContext(metaAccessProvider, tmpAssumptions, replacements); + PartialEscapePhase partialEscapePhase = new PartialEscapePhase(false, new CanonicalizerPhase(true)); + partialEscapePhase.apply(newGraph, context); + + cache.put(method, newGraph); + if (TruffleCompilerOptions.TraceTruffleCacheDetails.getValue()) { + TTY.println(String.format("[truffle] added to graph cache method %s with %d nodes.", method, newGraph.getNodeCount())); + } + return newGraph; + } + }); + } + + final StructuredGraph clonedResultGraph = resultGraph.copy(); + + Debug.sandbox("TruffleCacheConstants", new Object[]{metaAccessProvider, method}, DebugScope.getConfig(), new Runnable() { + + public void run() { + + Debug.dump(clonedResultGraph, "before applying constants"); + // Pass on constant arguments. + for (LocalNode local : clonedResultGraph.getNodes(LocalNode.class)) { + ValueNode arg = arguments.get(local.index()); + if (arg.isConstant()) { + Constant constant = arg.asConstant(); + local.replaceAndDelete(ConstantNode.forConstant(constant, metaAccessProvider, clonedResultGraph)); + } else { + local.setStamp(arg.stamp()); } } - - // Set stamps into graph before optimizing. - for (LocalNode localNode : newGraph.getNodes(LocalNode.class)) { - int index = localNode.index(); - Stamp stamp = stamps.get(index); - localNode.setStamp(stamp); - } - - optimizeGraph(newGraph); - cache.put(method, newGraph); - if (TruffleCompilerOptions.TraceTruffleCacheDetails.getValue()) { - TTY.println(String.format("[truffle] added to graph cache method %s with %d nodes.", method, newGraph.getNodeCount())); - } - return newGraph; + Debug.dump(clonedResultGraph, "after applying constants"); + optimizeGraph(clonedResultGraph, assumptions); } }); - return resultGraph; + return clonedResultGraph; } - private void optimizeGraph(StructuredGraph newGraph) { + private void optimizeGraph(StructuredGraph newGraph, Assumptions assumptions) { ConditionalEliminationPhase eliminate = new ConditionalEliminationPhase(metaAccessProvider); ConvertDeoptimizeToGuardPhase convertDeoptimizeToGuardPhase = new ConvertDeoptimizeToGuardPhase(); - Assumptions assumptions = new Assumptions(false); CanonicalizerPhase.Instance canonicalizerPhase = new CanonicalizerPhase.Instance(metaAccessProvider, assumptions, !AOTCompilation.getValue(), null, null); Integer maxNodes = TruffleCompilerOptions.TruffleOperationCacheMaxNodes.getValue(); @@ -140,10 +170,6 @@ contractGraph(newGraph, eliminate, convertDeoptimizeToGuardPhase, canonicalizerPhase); } - HighTierContext context = new HighTierContext(metaAccessProvider, assumptions, replacements); - PartialEscapePhase partialEscapePhase = new PartialEscapePhase(false, new CanonicalizerPhase(true)); - partialEscapePhase.apply(newGraph, context); - if (newGraph.getNodeCount() > maxNodes && (TruffleCompilerOptions.TraceTruffleCacheDetails.getValue() || TruffleCompilerOptions.TraceTrufflePerformanceWarnings.getValue())) { TTY.println(String.format("[truffle] PERFORMANCE WARNING: method %s got too large with %d nodes.", newGraph.method(), newGraph.getNodeCount())); } diff -r 853a894e0d97 -r 759415ed915a graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java Tue Jul 09 17:55:02 2013 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCompilerOptions.java Tue Jul 09 20:09:24 2013 +0200 @@ -55,6 +55,8 @@ public static final OptionValue TruffleConstantUnrollLimit = new OptionValue<>(32); @Option(help = "") public static final OptionValue TruffleOperationCacheMaxNodes = new OptionValue<>(200); + @Option(help = "") + public static final OptionValue TruffleGraphMaxNodes = new OptionValue<>(10000); // tracing @Option(help = "") diff -r 853a894e0d97 -r 759415ed915a graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleOptions.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleOptions.java Tue Jul 09 17:55:02 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleOptions.java Tue Jul 09 20:09:24 2013 +0200 @@ -31,24 +31,24 @@ public class TruffleOptions { /** Enables/disables the rewriting of traces in the truffle runtime to stdout. */ - public static final boolean TraceRewrites = false; + public static boolean TraceRewrites = false; /** * Filters rewrites that do not contain the given string in the qualified name of the source or * target class hierarchy. */ - public static final String TraceRewritesFilterClass = null; + public static String TraceRewritesFilterClass = null; /** * Filters rewrites which does not contain the {@link Kind} in its source {@link NodeInfo}. If * no {@link NodeInfo} is defined the element is filtered if the filter value is set. */ - public static final NodeInfo.Kind TraceRewritesFilterFromKind = null; + public static NodeInfo.Kind TraceRewritesFilterFromKind = null; /** * Filters rewrites which does not contain the {@link Kind} in its target {@link NodeInfo}. If * no {@link NodeInfo} is defined the element is filtered if the filter value is set. */ - public static final NodeInfo.Kind TraceRewritesFilterToKind = null; + public static NodeInfo.Kind TraceRewritesFilterToKind = null; } diff -r 853a894e0d97 -r 759415ed915a graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/SlowPathException.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/SlowPathException.java Tue Jul 09 17:55:02 2013 +0200 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/SlowPathException.java Tue Jul 09 20:09:24 2013 +0200 @@ -22,6 +22,8 @@ */ package com.oracle.truffle.api.nodes; +import com.oracle.truffle.api.*; + /** * An exception thrown to enter a slow path. The Truffle optimizer has special knowledge of this * exception class and will never compile a catch block that catches this exception type. @@ -34,6 +36,7 @@ * Creates an exception thrown to enter a slow path. */ public SlowPathException() { + CompilerDirectives.transferToInterpreter(); } /** @@ -41,6 +44,7 @@ */ public SlowPathException(String message, Throwable cause) { super(message, cause); + CompilerDirectives.transferToInterpreter(); } /** @@ -48,6 +52,7 @@ */ public SlowPathException(String message) { super(message); + CompilerDirectives.transferToInterpreter(); } /** @@ -55,6 +60,7 @@ */ public SlowPathException(Throwable cause) { super(cause); + CompilerDirectives.transferToInterpreter(); } /**