changeset 6574:ab1333d1d098

removed JumpNode and the non-materializing instanceof snippets that used it
author Doug Simon <doug.simon@oracle.com>
date Thu, 25 Oct 2012 01:22:07 +0200
parents 4eba1a717254
children 65628f3cf973
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/InstanceOfSnippets.java graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/nodes/JumpNode.java
diffstat 3 files changed, 26 insertions(+), 331 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/InstanceOfSnippets.java	Wed Oct 24 22:30:46 2012 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/InstanceOfSnippets.java	Thu Oct 25 01:22:07 2012 +0200
@@ -27,7 +27,6 @@
 import static com.oracle.graal.snippets.Snippet.Varargs.*;
 import static com.oracle.graal.snippets.SnippetTemplate.*;
 import static com.oracle.graal.snippets.SnippetTemplate.Arguments.*;
-import static com.oracle.graal.snippets.nodes.JumpNode.*;
 
 import com.oracle.graal.api.code.*;
 import com.oracle.graal.api.meta.*;
@@ -85,29 +84,6 @@
     }
 
     /**
-     * A test against a final type with the result being {@linkplain IfNode branched} upon.
-     */
-    @Snippet
-    public static void ifExact(
-                    @Parameter("object") Object object,
-                    @Parameter("exactHub") Object exactHub,
-                    @ConstantParameter("checkNull") boolean checkNull) {
-        if (checkNull && object == null) {
-            isNull.inc();
-            jump(IfNode.FALSE_EDGE);
-            return;
-        }
-        Object objectHub = loadHub(object);
-        if (objectHub != exactHub) {
-            exactMiss.inc();
-            jump(IfNode.FALSE_EDGE);
-            return;
-        }
-        exactHit.inc();
-        jump(IfNode.TRUE_EDGE);
-    }
-
-    /**
      * A test against a primary type with the result being {@linkplain ConditionalNode materialized}.
      */
     @Snippet
@@ -132,31 +108,6 @@
     }
 
     /**
-     * A test against a primary type with the result being {@linkplain IfNode branched} upon.
-     */
-    @Snippet
-    public static void ifPrimary(
-                    @Parameter("hub") Object hub,
-                    @Parameter("object") Object object,
-                    @ConstantParameter("checkNull") boolean checkNull,
-                    @ConstantParameter("superCheckOffset") int superCheckOffset) {
-        if (checkNull && object == null) {
-            isNull.inc();
-            jump(IfNode.FALSE_EDGE);
-            return;
-        }
-        Object objectHub = loadHub(object);
-        if (UnsafeLoadNode.loadObject(objectHub, 0, superCheckOffset, true) != hub) {
-            displayMiss.inc();
-            jump(IfNode.FALSE_EDGE);
-            return;
-        }
-        displayHit.inc();
-        jump(IfNode.TRUE_EDGE);
-        return;
-    }
-
-    /**
      * A test against a restricted secondary type type with the result being {@linkplain ConditionalNode materialized}.
      */
     @Snippet
@@ -187,70 +138,6 @@
         return trueValue;
     }
 
-    /**
-     * A test against a restricted secondary type with the result being {@linkplain IfNode branched} upon.
-     */
-    @Snippet
-    public static void ifSecondary(
-                    @Parameter("hub") Object hub,
-                    @Parameter("object") Object object,
-                    @VarargsParameter("hints") Object[] hints,
-                    @ConstantParameter("checkNull") boolean checkNull) {
-        if (checkNull && object == null) {
-            isNull.inc();
-            jump(IfNode.FALSE_EDGE);
-            return;
-        }
-        Object objectHub = loadHub(object);
-        // if we get an exact match: succeed immediately
-        ExplodeLoopNode.explodeLoop();
-        for (int i = 0; i < hints.length; i++) {
-            Object hintHub = hints[i];
-            if (hintHub == objectHub) {
-                hintsHit.inc();
-                jump(IfNode.TRUE_EDGE);
-                return;
-            }
-        }
-        if (!checkSecondarySubType(hub, objectHub)) {
-            jump(IfNode.FALSE_EDGE);
-            return;
-        }
-        jump(IfNode.TRUE_EDGE);
-        return;
-    }
-
-    /**
-     * A test against an unknown (at compile time) type with the result being {@linkplain ConditionalNode materialized}.
-     */
-    @Snippet
-    public static Object materializeUnknown(
-                    @Parameter("hub") Object hub,
-                    @Parameter("object") Object object,
-                    @Parameter("trueValue") Object trueValue,
-                    @Parameter("falseValue") Object falseValue,
-                    @VarargsParameter("hints") Object[] hints,
-                    @ConstantParameter("checkNull") boolean checkNull) {
-        if (checkNull && object == null) {
-            isNull.inc();
-            return falseValue;
-        }
-        Object objectHub = loadHub(object);
-        // if we get an exact match: succeed immediately
-        ExplodeLoopNode.explodeLoop();
-        for (int i = 0; i < hints.length; i++) {
-            Object hintHub = hints[i];
-            if (hintHub == objectHub) {
-                hintsHit.inc();
-                return trueValue;
-            }
-        }
-        if (!checkUnknownSubType(hub, objectHub)) {
-            return falseValue;
-        }
-        return trueValue;
-    }
-
     static boolean checkSecondarySubType(Object t, Object s) {
         // if (S.cache == T) return true
         if (UnsafeLoadNode.loadObject(s, 0, secondarySuperCacheOffset(), true) == t) {
@@ -280,26 +167,17 @@
 
     public static class Templates extends AbstractTemplates<InstanceOfSnippets> {
 
-        private final ResolvedJavaMethod ifExact;
-        private final ResolvedJavaMethod ifPrimary;
-        private final ResolvedJavaMethod ifSecondary;
         private final ResolvedJavaMethod materializeExact;
         private final ResolvedJavaMethod materializePrimary;
         private final ResolvedJavaMethod materializeSecondary;
 
         public Templates(CodeCacheProvider runtime) {
             super(runtime, InstanceOfSnippets.class);
-            ifExact = snippet("ifExact", Object.class, Object.class, boolean.class);
-            ifPrimary = snippet("ifPrimary", Object.class, Object.class, boolean.class, int.class);
-            ifSecondary = snippet("ifSecondary", Object.class, Object.class, Object[].class, boolean.class);
-
             materializeExact = snippet("materializeExact", Object.class, Object.class, Object.class, Object.class, boolean.class);
             materializePrimary = snippet("materializePrimary", Object.class, Object.class, Object.class, Object.class, boolean.class, int.class);
             materializeSecondary = snippet("materializeSecondary", Object.class, Object.class, Object.class, Object.class, Object[].class, boolean.class);
         }
 
-        private static final boolean MATERIALIZE_IF_NODE_USAGES = Boolean.getBoolean("graal.instanceof.disableJumpNodes");
-
         public void lower(InstanceOfNode instanceOf, LoweringTool tool) {
             ValueNode hub = instanceOf.targetClassInstruction();
             ValueNode object = instanceOf.object();
@@ -318,59 +196,35 @@
 
                 if (usage instanceof IfNode) {
                     final StructuredGraph graph = (StructuredGraph) usage.graph();
-                    if (!MATERIALIZE_IF_NODE_USAGES) {
-
-                        IfNode ifNode = (IfNode) usage;
-                        if (hintInfo.exact) {
-                            HotSpotKlassOop[] hints = createHints(hintInfo);
-                            assert hints.length == 1;
-                            key = new Key(ifExact).add("checkNull", checkNull);
-                            arguments = arguments("object", object).add("exactHub", hints[0]);
-                        } else if (target.isPrimaryType()) {
-                            key = new Key(ifPrimary).add("checkNull", checkNull).add("superCheckOffset", target.superCheckOffset());
-                            arguments = arguments("hub", hub).add("object", object);
-                        } else {
-                            HotSpotKlassOop[] hints = createHints(hintInfo);
-                            key = new Key(ifSecondary).add("hints", vargargs(Object.class, hints.length)).add("checkNull", checkNull);
-                            arguments = arguments("hub", hub).add("object", object).add("hints", hints);
-                        }
-
-                        SnippetTemplate template = cache.get(key);
-                        template.instantiate(runtime, duplicate, ifNode, arguments);
-                        assert ifNode.isDeleted();
-
-                    } else {
-
-                        final ValueNode falseValue = ConstantNode.forInt(0, graph);
-                        final ValueNode trueValue = ConstantNode.forInt(1, graph);
+                    final ValueNode falseValue = ConstantNode.forInt(0, graph);
+                    final ValueNode trueValue = ConstantNode.forInt(1, graph);
 
-                        if (hintInfo.exact) {
-                            HotSpotKlassOop[] hints = createHints(hintInfo);
-                            assert hints.length == 1;
-                            key = new Key(materializeExact).add("checkNull", checkNull);
-                            arguments = arguments("object", object).add("exactHub", hints[0]).add("trueValue", trueValue).add("falseValue", falseValue);
-                        } else if (target.isPrimaryType()) {
-                            key = new Key(materializePrimary).add("checkNull", checkNull).add("superCheckOffset", target.superCheckOffset());
-                            arguments = arguments("hub", hub).add("object", object).add("trueValue", trueValue).add("falseValue", falseValue);
-                        } else {
-                            HotSpotKlassOop[] hints = createHints(hintInfo);
-                            key = new Key(materializeSecondary).add("hints", vargargs(Object.class, hints.length)).add("checkNull", checkNull);
-                            arguments = arguments("hub", hub).add("object", object).add("hints", hints).add("trueValue", trueValue).add("falseValue", falseValue);
-                        }
+                    if (hintInfo.exact) {
+                        HotSpotKlassOop[] hints = createHints(hintInfo);
+                        assert hints.length == 1;
+                        key = new Key(materializeExact).add("checkNull", checkNull);
+                        arguments = arguments("object", object).add("exactHub", hints[0]).add("trueValue", trueValue).add("falseValue", falseValue);
+                    } else if (target.isPrimaryType()) {
+                        key = new Key(materializePrimary).add("checkNull", checkNull).add("superCheckOffset", target.superCheckOffset());
+                        arguments = arguments("hub", hub).add("object", object).add("trueValue", trueValue).add("falseValue", falseValue);
+                    } else {
+                        HotSpotKlassOop[] hints = createHints(hintInfo);
+                        key = new Key(materializeSecondary).add("hints", vargargs(Object.class, hints.length)).add("checkNull", checkNull);
+                        arguments = arguments("hub", hub).add("object", object).add("hints", hints).add("trueValue", trueValue).add("falseValue", falseValue);
+                    }
 
-                        UsageReplacer replacer = new UsageReplacer() {
-                            @Override
-                            public void replace(ValueNode oldNode, ValueNode newNode) {
-                                assert oldNode == duplicate;
-                                newNode.inferStamp();
-                                IntegerEqualsNode condition = graph.add(new IntegerEqualsNode(newNode, trueValue));
-                                oldNode.replaceAtUsages(condition);
-                            }
-                        };
+                    UsageReplacer replacer = new UsageReplacer() {
+                        @Override
+                        public void replace(ValueNode oldNode, ValueNode newNode) {
+                            assert oldNode == duplicate;
+                            newNode.inferStamp();
+                            IntegerEqualsNode condition = graph.add(new IntegerEqualsNode(newNode, trueValue));
+                            oldNode.replaceAtUsages(condition);
+                        }
+                    };
 
-                        SnippetTemplate template = cache.get(key);
-                        template.instantiate(runtime, duplicate, replacer, tool.lastFixedNode(), arguments);
-                    }
+                    SnippetTemplate template = cache.get(key);
+                    template.instantiate(runtime, duplicate, replacer, tool.lastFixedNode(), arguments);
 
                 } else if (usage instanceof ConditionalNode) {
 
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java	Wed Oct 24 22:30:46 2012 +0200
+++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java	Thu Oct 25 01:22:07 2012 +0200
@@ -353,31 +353,6 @@
         ReturnNode retNode = null;
         StartNode entryPointNode = snippet.start();
 
-        Map<Integer, JumpNode[]> jumpsMap = new HashMap<>();
-        for (JumpNode jump : snippet.getNodes().filter(JumpNode.class).snapshot()) {
-            FixedNode next = jump.next();
-
-            // Remove the nodes after the jump
-            jump.setNext(null);
-            GraphUtil.killCFG(next);
-            JumpNode[] jumpsForIndex = jumpsMap.get(jump.successorIndex());
-            if (jumpsForIndex == null) {
-                jumpsMap.put(jump.successorIndex(), new JumpNode[] {jump});
-            } else {
-                jumpsForIndex = Arrays.copyOf(jumpsForIndex, jumpsForIndex.length + 1);
-                jumpsForIndex[jumpsForIndex.length - 1] = jump;
-                jumpsMap.put(jump.successorIndex(), jumpsForIndex);
-            }
-        }
-
-        this.jumps = new JumpNode[jumpsMap.size()][];
-        for (Map.Entry<Integer, JumpNode[]> e : jumpsMap.entrySet()) {
-            int successorIndex = e.getKey();
-            assert successorIndex >= 0 && successorIndex < this.jumps.length;
-            assert this.jumps[successorIndex] == null;
-            this.jumps[successorIndex] = e.getValue();
-        }
-
         new DeadCodeEliminationPhase().apply(snippetCopy);
 
         nodes = new ArrayList<>(snippet.getNodeCount());
@@ -387,7 +362,6 @@
             } else {
                 nodes.add(node);
                 if (node instanceof ReturnNode) {
-                    assert this.jumps.length == 0 : "snippet with Jump node(s) cannot have a return node";
                     retNode = (ReturnNode) node;
                 }
             }
@@ -460,12 +434,6 @@
     private final ArrayList<Node> nodes;
 
     /**
-     * The {@link JumpNode}s in the snippet, indexed by {@linkplain ControlSplitNode#blockSuccessor(int) successor} indexes.
-     * There may be more than one jump per successor index which explains why this is a 2-dimensional array.
-     */
-    private final JumpNode[][] jumps;
-
-    /**
      * Gets the instantiation-time bindings to this template's parameters.
      *
      * @return the map that will be used to bind arguments to parameters when inlining this template
@@ -659,68 +627,6 @@
         Debug.dump(replaceeGraph, "After lowering %s with %s", replacee, this);
     }
 
-    /**
-     * Replaces a given floating node that is an input to a {@link ControlSplitNode} with this specialized snippet.
-     * The {@linkplain JumpNode jumps} in the snippet are connected to the successors of the control split node.
-     *
-     * @param replacee the node that will be replaced
-     * @param controlSplitNode the node replaced by this wheCFG of the snippet is inserted after this node
-     * @param args the arguments to be bound to the flattened positional parameters of the snippet
-     */
-    public void instantiate(MetaAccessProvider runtime,
-                    FloatingNode replacee,
-                    ControlSplitNode controlSplitNode,
-                    SnippetTemplate.Arguments args) {
-
-        // Inline the snippet nodes, replacing parameters with the given args in the process
-        String name = snippet.name == null ? "{copy}" : snippet.name + "{copy}";
-        StructuredGraph snippetCopy = new StructuredGraph(name, snippet.method());
-        StartNode entryPointNode = snippet.start();
-        FixedNode firstCFGNode = entryPointNode.next();
-        StructuredGraph replaceeGraph = (StructuredGraph) replacee.graph();
-        IdentityHashMap<Node, Node> replacements = bind(replaceeGraph, runtime, args);
-        Map<Node, Node> duplicates = replaceeGraph.addDuplicates(nodes, replacements);
-        Debug.dump(replaceeGraph, "After inlining snippet %s", snippetCopy.method());
-
-
-        int successorIndex = 0;
-        for (JumpNode[] jumpsForIndex : jumps) {
-            fixEdge(controlSplitNode, jumpsForIndex, successorIndex++, duplicates);
-        }
-
-        FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode);
-        controlSplitNode.replaceAtPredecessor(firstCFGNodeDuplicate);
-        controlSplitNode.replaceAtUsages(null);
-
-        assert sideEffectNode == null;
-        assert stampNode == null;
-        assert returnNode == null : replaceeGraph;
-        GraphUtil.killCFG(controlSplitNode);
-
-        Debug.dump(replaceeGraph, "After lowering %s with %s", replacee, this);
-    }
-
-    private static void fixEdge(ControlSplitNode splitAnchor, JumpNode[] jumpsForIndex, int successorIndex, Map<Node, Node> duplicates) {
-        BeginNode blockSuccessor = splitAnchor.blockSuccessor(successorIndex);
-        splitAnchor.setBlockSuccessor(successorIndex, null);
-        if (jumpsForIndex.length == 1) {
-            JumpNode jump = (JumpNode) duplicates.get(jumpsForIndex[0]);
-            jump.replaceAtPredecessor(blockSuccessor);
-            GraphUtil.killCFG(jump);
-        } else {
-            StructuredGraph graph = (StructuredGraph) splitAnchor.graph();
-            MergeNode merge = graph.add(new MergeNode());
-            for (int i = 0; i < jumpsForIndex.length; i++) {
-                EndNode end = graph.add(new EndNode());
-                JumpNode jump = (JumpNode) duplicates.get(jumpsForIndex[i]);
-                jump.replaceAtPredecessor(end);
-                merge.addForwardEnd(end);
-                GraphUtil.killCFG(jump);
-            }
-            merge.setNext(blockSuccessor);
-        }
-    }
-
     @Override
     public String toString() {
         StringBuilder buf = new StringBuilder(snippet.toString()).append('(');
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/nodes/JumpNode.java	Wed Oct 24 22:30:46 2012 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2012, 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.snippets.nodes;
-
-import com.oracle.graal.nodes.*;
-import com.oracle.graal.nodes.type.*;
-
-/**
- * Delimits a control flow path in a snippet that will be connected to a
- * {@link ControlSplitNode} successor upon snippet instantiation.
- * This node can only appear in snippets with a void return type.
- */
-public class JumpNode extends FixedWithNextNode {
-
-    /**
-     * Index of {@link ControlSplitNode} successor to which this label will be connected.
-     */
-    private final int successorIndex;
-
-    public JumpNode(int successorIndex) {
-        super(StampFactory.forVoid());
-        this.successorIndex = successorIndex;
-    }
-
-    public int successorIndex() {
-        return successorIndex;
-    }
-
-    @Override
-    public String toString(Verbosity verbosity) {
-        if (verbosity == Verbosity.Name) {
-            return super.toString(Verbosity.Name) + "{" + successorIndex() + "}";
-        } else {
-            return super.toString(verbosity);
-        }
-    }
-
-    /**
-     * There must be a return statement immediately following a call to this method.
-     *
-     * @param successorIndex e.g. {@link IfNode#TRUE_EDGE}
-     */
-    @NodeIntrinsic
-    public static native void jump(@ConstantNodeParameter int successorIndex);
-}