changeset 21426:e479ee4aa9aa

Merge.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 19 May 2015 15:35:58 +0200
parents a9b3d1cfdd42 (diff) 178a4927b95c (current diff)
children 4de8827ca59b
files
diffstat 9 files changed, 77 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/GraphChangeMonitoringPhase.java	Tue May 19 14:50:15 2015 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/GraphChangeMonitoringPhase.java	Tue May 19 15:35:58 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);
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/CachedGraph.java	Tue May 19 14:50:15 2015 +0200
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/CachedGraph.java	Tue May 19 15:35:58 2015 +0200
@@ -22,26 +22,46 @@
  */
 package com.oracle.graal.graph;
 
+import java.util.*;
+import java.util.function.*;
+
 /**
  * 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<G extends Graph> {
 
-    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 <G extends Graph> CachedGraph<G> fromReadonlyCopy(G graph) {
+        return new CachedGraph<>(graph, null);
+    }
+
+    public static <G extends Graph> CachedGraph<G> fromMutableCopy(G graph) {
+        return new CachedGraph<>(graph, graph);
+    }
+
+    public G getReadonlyCopy() {
+        if (hasMutableCopy()) {
+            return mutableCopy;
+        }
         return readonlyCopy;
     }
 
-    public Graph getMutableCopy() {
-        if (mutableCopy == null) {
-            mutableCopy = readonlyCopy.copy();
+    public boolean hasMutableCopy() {
+        return mutableCopy != null;
+    }
+
+    @SuppressWarnings("unchecked")
+    public G getMutableCopy(Consumer<Map<Node, Node>> duplicationMapCallback) {
+        if (!hasMutableCopy()) {
+            mutableCopy = (G) readonlyCopy.copy(duplicationMapCallback);
         }
         return mutableCopy;
     }
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java	Tue May 19 14:50:15 2015 +0200
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java	Tue May 19 15:35:58 2015 +0200
@@ -25,6 +25,7 @@
 import static com.oracle.graal.graph.Edges.Type.*;
 
 import java.util.*;
+import java.util.function.*;
 
 import com.oracle.graal.compiler.common.*;
 import com.oracle.graal.debug.*;
@@ -219,8 +220,17 @@
     /**
      * Creates a copy of this graph.
      */
-    public Graph copy() {
-        return copy(name);
+    public final Graph copy() {
+        return copy(name, null);
+    }
+
+    /**
+     * Creates a copy of this graph.
+     *
+     * @param duplicationMapCallback consumer of the duplication map created during the copying
+     */
+    public final Graph copy(Consumer<Map<Node, Node>> duplicationMapCallback) {
+        return copy(name, duplicationMapCallback);
     }
 
     /**
@@ -228,9 +238,22 @@
      *
      * @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);
+    }
+
+    /**
+     * 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
+     */
+    protected Graph copy(String newName, Consumer<Map<Node, Node>> duplicationMapCallback) {
         Graph copy = new Graph(newName);
-        copy.addDuplicates(getNodes(), this, this.getNodeCount(), (Map<Node, Node>) null);
+        Map<Node, Node> duplicates = copy.addDuplicates(getNodes(), this, this.getNodeCount(), (Map<Node, Node>) null);
+        if (duplicationMapCallback != null) {
+            duplicationMapCallback.accept(duplicates);
+        }
         return copy;
     }
 
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ObjectCloneNode.java	Tue May 19 14:50:15 2015 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ObjectCloneNode.java	Tue May 19 15:35:58 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 {
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/arraycopy/ArrayCopyNode.java	Tue May 19 14:50:15 2015 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/arraycopy/ArrayCopyNode.java	Tue May 19 15:35:58 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())) {
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StructuredGraph.java	Tue May 19 14:50:15 2015 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/StructuredGraph.java	Tue May 19 15:35:58 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<Map<Node, Node>> 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<Node, Node> replacements = Node.newMap();
         replacements.put(start, copy.start);
-        copy.addDuplicates(getNodes(), this, this.getNodeCount(), replacements);
+        Map<Node, Node> 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) {
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java	Tue May 19 14:50:15 2015 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/inlining/info/elem/InlineableGraph.java	Tue May 19 15:35:58 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);
     }
 
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java	Tue May 19 14:50:15 2015 +0200
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java	Tue May 19 15:35:58 2015 +0200
@@ -1299,7 +1299,7 @@
      * Gets a copy of the specialized graph.
      */
     public StructuredGraph copySpecializedGraph() {
-        return snippet.copy();
+        return (StructuredGraph) snippet.copy();
     }
 
     /**
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/MacroNode.java	Tue May 19 14:50:15 2015 +0200
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/MacroNode.java	Tue May 19 15:35:58 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;