Mercurial > hg > truffle
changeset 10675:41362ec88331
Improve Truffle graph cache.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 09 Jul 2013 14:33:24 +0200 |
parents | b25a07ad3678 |
children | 9db1377b0580 |
files | graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCache.java |
diffstat | 2 files changed, 60 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java Tue Jul 09 01:27:40 2013 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/PartialEvaluator.java Tue Jul 09 14:33:24 2013 +0200 @@ -243,21 +243,11 @@ private StructuredGraph parseGraph(final ResolvedJavaMethod targetMethod, final NodeInputList<ValueNode> arguments, final Assumptions assumptions, final boolean canonicalizeReads) { - final StructuredGraph graph = truffleCache.lookup(targetMethod, arguments).copy(); + final StructuredGraph graph = truffleCache.lookup(targetMethod, arguments); 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);
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCache.java Tue Jul 09 01:27:40 2013 +0200 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/TruffleCache.java Tue Jul 09 14:33:24 2013 +0200 @@ -68,50 +68,80 @@ public StructuredGraph lookup(final ResolvedJavaMethod method, final NodeInputList<ValueNode> arguments) { + 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<StructuredGraph>() { + if (resultGraph == null) { + resultGraph = Debug.sandbox("TruffleCache", new Object[]{metaAccessProvider, method}, DebugScope.getConfig(), new Callable<StructuredGraph>() { + + public StructuredGraph call() { + StructuredGraph newGraph = parseGraph(method); - public StructuredGraph call() { - StructuredGraph newGraph = parseGraph(method); + // Get stamps from actual arguments. + List<Stamp> stamps = new ArrayList<>(); + for (ValueNode arg : arguments) { + stamps.add(arg.stamp()); + } - // Get stamps from actual arguments. - List<Stamp> 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); + } + + optimizeGraph(newGraph); + + HighTierContext context = new HighTierContext(metaAccessProvider, new Assumptions(false), 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); } }); - return resultGraph; + return clonedResultGraph; } private void optimizeGraph(StructuredGraph newGraph) { @@ -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())); }