# HG changeset patch # User Thomas Wuerthinger # Date 1432040571 -7200 # Node ID fe76bf3867f3f868e449ffe7ae09c5cd901e2cb5 # Parent fdf9166e575fbb2ead422e9af42ca1bfc8ff5496 Make CachedGraph generic. Clean up Graph#copy methods. diff -r fdf9166e575f -r fe76bf3867f3 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/GraphChangeMonitoringPhase.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/GraphChangeMonitoringPhase.java Tue May 19 14:24:47 2015 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/GraphChangeMonitoringPhase.java Tue May 19 15:02:51 2015 +0200 @@ -66,7 +66,7 @@ * having their inputs change are the main interesting differences. */ HashSetNodeEventListener listener = new HashSetNodeEventListener().exclude(NodeEvent.NODE_ADDED); - StructuredGraph graphCopy = graph.copy(); + StructuredGraph graphCopy = (StructuredGraph) graph.copy(); try (NodeEventScope s = graphCopy.trackNodeEvents(listener)) { try (Scope s2 = Debug.sandbox("WithoutMonitoring", null)) { super.run(graphCopy, context); diff -r fdf9166e575f -r fe76bf3867f3 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/CachedGraph.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/CachedGraph.java Tue May 19 14:24:47 2015 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/CachedGraph.java Tue May 19 15:02:51 2015 +0200 @@ -29,22 +29,32 @@ * This class is a container of a graph that needs to be readonly and optionally a lazily created * mutable copy of the graph. */ -public class CachedGraph { +public final class CachedGraph { - private final Graph readonlyCopy; - private Graph mutableCopy; + private final G readonlyCopy; + private G mutableCopy; - public CachedGraph(Graph readonlyCopy) { + private CachedGraph(G readonlyCopy, G mutableCopy) { this.readonlyCopy = readonlyCopy; + this.mutableCopy = mutableCopy; } - public Graph getReadonlyCopy() { + public static CachedGraph fromReadonlyCopy(G graph) { + return new CachedGraph<>(graph, null); + } + + public static CachedGraph fromMutableCopy(G graph) { + return new CachedGraph<>(graph, graph); + } + + public G getReadonlyCopy() { return readonlyCopy; } - public Graph getMutableCopy(Consumer> duplicationMapCallback) { + @SuppressWarnings("unchecked") + public G getMutableCopy(Consumer> duplicationMapCallback) { if (mutableCopy == null) { - mutableCopy = readonlyCopy.copy(duplicationMapCallback); + mutableCopy = (G) readonlyCopy.copy(duplicationMapCallback); } return mutableCopy; } diff -r fdf9166e575f -r fe76bf3867f3 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java Tue May 19 14:24:47 2015 +0200 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java Tue May 19 15:02:51 2015 +0200 @@ -220,7 +220,7 @@ /** * Creates a copy of this graph. */ - public Graph copy() { + public final Graph copy() { return copy(name, null); } @@ -229,7 +229,7 @@ * * @param duplicationMapCallback consumer of the duplication map created during the copying */ - public Graph copy(Consumer> duplicationMapCallback) { + public final Graph copy(Consumer> duplicationMapCallback) { return copy(name, duplicationMapCallback); } @@ -238,7 +238,7 @@ * * @param newName the name of the copy, used for debugging purposes (can be null) */ - public Graph copy(String newName) { + public final Graph copy(String newName) { return copy(newName, null); } @@ -248,7 +248,7 @@ * @param newName the name of the copy, used for debugging purposes (can be null) * @param duplicationMapCallback consumer of the duplication map created during the copying */ - public Graph copy(String newName, Consumer> duplicationMapCallback) { + protected Graph copy(String newName, Consumer> duplicationMapCallback) { Graph copy = new Graph(newName); Map duplicates = copy.addDuplicates(getNodes(), this, this.getNodeCount(), (Map) null); if (duplicationMapCallback != null) { diff -r fdf9166e575f -r fe76bf3867f3 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ObjectCloneNode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ObjectCloneNode.java Tue May 19 14:24:47 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ObjectCloneNode.java Tue May 19 15:02:51 2015 +0200 @@ -63,7 +63,7 @@ } assert snippetGraph != null : "ObjectCloneSnippets should be installed"; - return lowerReplacement(snippetGraph.copy(), tool); + return lowerReplacement((StructuredGraph) snippetGraph.copy(), tool); } assert false : "unhandled array type " + type.getComponentType().getKind(); } else { diff -r fdf9166e575f -r fe76bf3867f3 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/arraycopy/ArrayCopyNode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/arraycopy/ArrayCopyNode.java Tue May 19 14:24:47 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/arraycopy/ArrayCopyNode.java Tue May 19 15:02:51 2015 +0200 @@ -98,14 +98,14 @@ } snippetGraph = null; try (Scope s = Debug.scope("ArrayCopySnippet", snippetMethod)) { - snippetGraph = replacements.getSnippet(snippetMethod, getTargetMethod(), null).copy(); + snippetGraph = (StructuredGraph) replacements.getSnippet(snippetMethod, getTargetMethod(), null).copy(); } catch (Throwable e) { throw Debug.handle(e); } replaceSnippetInvokes(snippetGraph); } else { assert snippetGraph != null : "ArrayCopySnippets should be installed"; - snippetGraph = snippetGraph.copy(); + snippetGraph = (StructuredGraph) snippetGraph.copy(); if (shouldUnroll()) { final StructuredGraph copy = snippetGraph; try (Scope s = Debug.scope("ArrayCopySnippetSpecialization", snippetGraph.method())) { diff -r fdf9166e575f -r fe76bf3867f3 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StructuredGraph.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StructuredGraph.java Tue May 19 14:24:47 2015 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StructuredGraph.java Tue May 19 15:02:51 2015 +0200 @@ -24,6 +24,7 @@ import java.util.*; import java.util.concurrent.atomic.*; +import java.util.function.*; import com.oracle.graal.api.meta.Assumptions.Assumption; import com.oracle.graal.api.meta.*; @@ -217,17 +218,17 @@ this.start = start; } + /** + * Creates a copy of this graph. + * + * @param newName the name of the copy, used for debugging purposes (can be null) + * @param duplicationMapCallback consumer of the duplication map created during the copying + */ @Override - public StructuredGraph copy() { - return copy(name); - } - - public StructuredGraph copy(String newName, ResolvedJavaMethod newMethod) { - return copy(newName, newMethod, AllowAssumptions.from(assumptions != null), isInlinedMethodRecordingEnabled()); - } - - public StructuredGraph copy(String newName, ResolvedJavaMethod newMethod, AllowAssumptions allowAssumptions, boolean enableInlinedMethodRecording) { - StructuredGraph copy = new StructuredGraph(newName, newMethod, graphId, entryBCI, allowAssumptions); + protected Graph copy(String newName, Consumer> duplicationMapCallback) { + AllowAssumptions allowAssumptions = AllowAssumptions.from(assumptions != null); + boolean enableInlinedMethodRecording = isInlinedMethodRecordingEnabled(); + StructuredGraph copy = new StructuredGraph(newName, method, graphId, entryBCI, allowAssumptions); if (allowAssumptions == AllowAssumptions.YES && assumptions != null) { copy.assumptions.record(assumptions); } @@ -239,15 +240,13 @@ copy.hasValueProxies = hasValueProxies; Map replacements = Node.newMap(); replacements.put(start, copy.start); - copy.addDuplicates(getNodes(), this, this.getNodeCount(), replacements); + Map duplicates = copy.addDuplicates(getNodes(), this, this.getNodeCount(), replacements); + if (duplicationMapCallback != null) { + duplicationMapCallback.accept(duplicates); + } return copy; } - @Override - public StructuredGraph copy(String newName) { - return copy(newName, method); - } - public ParameterNode getParameter(int index) { for (ParameterNode param : getNodes(ParameterNode.TYPE)) { if (param.index() == index) { diff -r fdf9166e575f -r fe76bf3867f3 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java Tue May 19 14:24:47 2015 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java Tue May 19 15:02:51 2015 +0200 @@ -61,7 +61,7 @@ public InlineableGraph(final ResolvedJavaMethod method, final Invoke invoke, final HighTierContext context, CanonicalizerPhase canonicalizer) { StructuredGraph original = getOriginalGraph(method, context, canonicalizer, invoke.asNode().graph(), invoke.bci()); // TODO copying the graph is only necessary if it is modified or if it contains any invokes - this.graph = original.copy(); + this.graph = (StructuredGraph) original.copy(); specializeGraphToArguments(invoke, context, canonicalizer); } diff -r fdf9166e575f -r fe76bf3867f3 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java Tue May 19 14:24:47 2015 +0200 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java Tue May 19 15:02:51 2015 +0200 @@ -1299,7 +1299,7 @@ * Gets a copy of the specialized graph. */ public StructuredGraph copySpecializedGraph() { - return snippet.copy(); + return (StructuredGraph) snippet.copy(); } /** diff -r fdf9166e575f -r fe76bf3867f3 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/MacroNode.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/MacroNode.java Tue May 19 14:24:47 2015 +0200 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/MacroNode.java Tue May 19 15:02:51 2015 +0200 @@ -112,7 +112,7 @@ protected StructuredGraph getLoweredSubstitutionGraph(LoweringTool tool) { StructuredGraph methodSubstitution = tool.getReplacements().getSubstitution(getTargetMethod(), true, bci); if (methodSubstitution != null) { - methodSubstitution = methodSubstitution.copy(); + methodSubstitution = (StructuredGraph) methodSubstitution.copy(); return lowerReplacement(methodSubstitution, tool); } return null;