changeset 3218:3d66094eeda1

cleanup, new shell scripts for examples
author Lukas Stadler <lukas.stadler@jku.at>
date Thu, 14 Jul 2011 10:33:35 +0200
parents 1ba9612f6d6e
children e41017cddf3a
files .hgignore graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/debug/IdealGraphPrinter.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/MergeableState.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/PostOrderNodeIterator.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/FixedNode.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/ComputeProbabilityPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/EscapeAnalysisPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/Phase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/extensions/InliningExample.java graal/com.oracle.max.graal.examples/create_examples.xml graal/com.oracle.max.graal.examples/runexample.sh graal/com.oracle.max.graal.examples/runexample_c1.sh graal/com.oracle.max.graal.examples/runexample_c2.sh graal/com.oracle.max.graal.examples/runexamplescompare.sh graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/Main.java graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/simple/SimpleExample.java
diffstat 19 files changed, 416 insertions(+), 257 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Tue Jul 12 18:14:45 2011 +0200
+++ b/.hgignore	Thu Jul 14 10:33:35 2011 +0200
@@ -21,6 +21,7 @@
 ^diff1.txt$
 ^diff2.txt$
 ^examples.jar$
+^graal/com.oracle.max.graal.examples/examples.jar$
 ^test.xml$
 java\.hprof\.txt$
 /nbproject/private/
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java	Tue Jul 12 18:14:45 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java	Thu Jul 14 10:33:35 2011 +0200
@@ -91,6 +91,7 @@
 
     // Ideal graph visualizer output settings
     public static boolean Plot                               = ____;
+    public static boolean PlotVerbose                        = ____;
     public static boolean PlotOnError                        = ____;
     public static int     PrintIdealGraphLevel               = 0;
     public static boolean PrintIdealGraphFile                = ____;
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/debug/IdealGraphPrinter.java	Tue Jul 12 18:14:45 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/debug/IdealGraphPrinter.java	Thu Jul 14 10:33:35 2011 +0200
@@ -123,7 +123,7 @@
         IdentifyBlocksPhase schedule = null;
         try {
             schedule = new IdentifyBlocksPhase(true);
-            schedule.apply(graph, false);
+            schedule.apply(graph, false, false);
         } catch (Throwable t) {
             // nothing to do here...
             //t.printStackTrace();
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java	Tue Jul 12 18:14:45 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java	Thu Jul 14 10:33:35 2011 +0200
@@ -97,6 +97,8 @@
 
         if (GraalOptions.Inline) {
             new InliningPhase(compilation, this, null).apply(compilation.graph);
+            new CanonicalizerPhase().apply(compilation.graph);
+            new DeadCodeEliminationPhase().apply(compilation.graph);
         }
 
         Graph graph = compilation.graph;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/MergeableState.java	Thu Jul 14 10:33:35 2011 +0200
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2011, 2011, 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.max.graal.compiler.graph;
+
+import java.util.*;
+
+import com.oracle.max.graal.compiler.ir.*;
+
+public interface MergeableState <T> {
+    T clone();
+    boolean merge(Merge merge, Collection<T> withStates);
+    void loopBegin(LoopBegin loopBegin);
+    void loopEnd(LoopEnd loopEnd, T loopEndState);
+    void afterSplit(FixedNode node);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/PostOrderNodeIterator.java	Thu Jul 14 10:33:35 2011 +0200
@@ -0,0 +1,194 @@
+/*
+ * Copyright (c) 2011, 2011, 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.max.graal.compiler.graph;
+
+import java.util.*;
+
+import com.oracle.max.graal.compiler.ir.*;
+import com.oracle.max.graal.graph.*;
+
+public abstract class PostOrderNodeIterator<T extends MergeableState<T>> {
+
+    private final NodeBitMap visitedEnds;
+    private final Deque<FixedNode> nodeQueue;
+    private final HashMap<FixedNode, T> nodeStates;
+    private final FixedNode start;
+
+    protected T state;
+
+    public PostOrderNodeIterator(FixedNode start, T initialState) {
+        visitedEnds = start.graph().createNodeBitMap();
+        nodeQueue = new ArrayDeque<FixedNode>();
+        nodeStates = new HashMap<FixedNode, T>();
+        this.start = start;
+        this.state = initialState;
+    }
+
+    public void apply() {
+        FixedNode current = start;
+
+        do {
+            if (current instanceof Invoke) {
+                invoke((Invoke) current);
+                queueSuccessors(current);
+                current = nextQueuedNode();
+            } else if (current instanceof LoopBegin) {
+                state.loopBegin((LoopBegin) current);
+                nodeStates.put(current, state);
+                state = state.clone();
+                loopBegin((LoopBegin) current);
+                current = ((LoopBegin) current).next();
+                assert current != null;
+            } else if (current instanceof LoopEnd) {
+                T loopBeginState = nodeStates.get(((LoopEnd) current).loopBegin());
+                if (loopBeginState != null) {
+                    loopBeginState.loopEnd((LoopEnd) current, state);
+                }
+                loopEnd((LoopEnd) current);
+                current = nextQueuedNode();
+            } else if (current instanceof Merge) {
+                merge((Merge) current);
+                current = ((Merge) current).next();
+                assert current != null;
+            } else if (current instanceof FixedNodeWithNext) {
+                FixedNode next = ((FixedNodeWithNext) current).next();
+                node(current);
+                current = next;
+                assert current != null;
+            } else if (current instanceof EndNode) {
+                end((EndNode) current);
+                queueMerge((EndNode) current);
+                current = nextQueuedNode();
+            } else if (current instanceof Deoptimize) {
+                deoptimize((Deoptimize) current);
+                current = nextQueuedNode();
+            } else if (current instanceof Return) {
+                returnNode((Return) current);
+                current = nextQueuedNode();
+            } else if (current instanceof Unwind) {
+                unwind((Unwind) current);
+                current = nextQueuedNode();
+            } else if (current instanceof ControlSplit) {
+                controlSplit((ControlSplit) current);
+                queueSuccessors(current);
+                current = nextQueuedNode();
+            } else {
+                assert false : current.shortName();
+            }
+        } while(current != null);
+    }
+
+    private void queueSuccessors(FixedNode x) {
+        nodeStates.put(x, state);
+        for (Node node : x.successors()) {
+            if (node != null) {
+                nodeQueue.addFirst((FixedNode) node);
+            }
+        }
+    }
+
+    private FixedNode nextQueuedNode() {
+        int maxIterations = nodeQueue.size();
+        while (maxIterations-- > 0) {
+            FixedNode node = nodeQueue.removeFirst();
+            if (node instanceof Merge) {
+                Merge merge = (Merge) node;
+                state = nodeStates.get(merge.endAt(0)).clone();
+                ArrayList<T> states = new ArrayList<T>(merge.endCount() - 1);
+                for (int i = 1; i < merge.endCount(); i++) {
+                    T other = nodeStates.get(merge.endAt(i));
+                    assert other != null;
+                    states.add(other);
+                }
+                boolean ready = state.merge(merge, states);
+                if (ready) {
+                    return merge;
+                } else {
+                    nodeQueue.addLast(merge);
+                }
+            } else {
+                assert node.predecessors().size() == 1;
+                state = nodeStates.get(node.predecessors().get(0)).clone();
+                state.afterSplit(node);
+                return node;
+            }
+        }
+        return null;
+    }
+
+    private void queueMerge(EndNode end) {
+        assert !visitedEnds.isMarked(end);
+        assert !nodeStates.containsKey(end);
+        nodeStates.put(end, state);
+        visitedEnds.mark(end);
+        Merge merge = end.merge();
+        boolean endsVisited = true;
+        for (int i = 0; i < merge.endCount(); i++) {
+            if (!visitedEnds.isMarked(merge.endAt(i))) {
+                endsVisited = false;
+                break;
+            }
+        }
+        if (endsVisited) {
+            nodeQueue.add(merge);
+        }
+    }
+
+    protected abstract void node(FixedNode node);
+
+    protected void end(EndNode endNode) {
+        node(endNode);
+    }
+
+    protected void merge(Merge merge) {
+        node(merge);
+    }
+
+    protected void loopBegin(LoopBegin loopBegin) {
+        node(loopBegin);
+    }
+
+    protected void loopEnd(LoopEnd loopEnd) {
+        node(loopEnd);
+    }
+
+    protected void deoptimize(Deoptimize deoptimize) {
+        node(deoptimize);
+    }
+
+    protected void controlSplit(ControlSplit controlSplit) {
+        node(controlSplit);
+    }
+
+    protected void returnNode(Return returnNode) {
+        node(returnNode);
+    }
+
+    protected void invoke(Invoke invoke) {
+        node(invoke);
+    }
+
+    protected void unwind(Unwind unwind) {
+        node(unwind);
+    }
+}
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/FixedNode.java	Tue Jul 12 18:14:45 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/FixedNode.java	Thu Jul 14 10:33:35 2011 +0200
@@ -50,7 +50,7 @@
     @Override
     public Map<Object, Object> getDebugProperties() {
         Map<Object, Object> properties = super.getDebugProperties();
-        properties.put("probability", String.format("%7.5f", probability));
+        properties.put("probability", String.format(Locale.ENGLISH, "%7.5f", probability));
         return properties;
     }
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/ComputeProbabilityPhase.java	Tue Jul 12 18:14:45 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/ComputeProbabilityPhase.java	Thu Jul 14 10:33:35 2011 +0200
@@ -26,10 +26,9 @@
 
 import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.debug.*;
+import com.oracle.max.graal.compiler.graph.*;
 import com.oracle.max.graal.compiler.ir.*;
 import com.oracle.max.graal.compiler.observer.*;
-import com.oracle.max.graal.compiler.phases.EscapeAnalysisPhase.MergeableState;
-import com.oracle.max.graal.compiler.phases.EscapeAnalysisPhase.PostOrderNodeIterator;
 import com.oracle.max.graal.graph.*;
 
 public class ComputeProbabilityPhase extends Phase {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/EscapeAnalysisPhase.java	Tue Jul 12 18:14:45 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/EscapeAnalysisPhase.java	Thu Jul 14 10:33:35 2011 +0200
@@ -39,180 +39,6 @@
 
 public class EscapeAnalysisPhase extends Phase {
 
-    public interface MergeableState <T> {
-        T clone();
-        boolean merge(Merge merge, Collection<T> withStates);
-        void loopBegin(LoopBegin loopBegin);
-        void loopEnd(LoopEnd loopEnd, T loopEndState);
-        void afterSplit(FixedNode node);
-    }
-
-    public abstract static class PostOrderNodeIterator<T extends MergeableState<T>> {
-
-        private final NodeBitMap visitedEnds;
-        private final Deque<FixedNode> nodeQueue;
-        private final HashMap<FixedNode, T> nodeStates;
-        private final FixedNode start;
-
-        protected T state;
-
-        public PostOrderNodeIterator(FixedNode start, T initialState) {
-            visitedEnds = start.graph().createNodeBitMap();
-            nodeQueue = new ArrayDeque<FixedNode>();
-            nodeStates = new HashMap<FixedNode, T>();
-            this.start = start;
-            this.state = initialState;
-        }
-
-        public void apply() {
-            FixedNode current = start;
-
-            do {
-                if (current instanceof Invoke) {
-                    invoke((Invoke) current);
-                    queueSuccessors(current);
-                    current = nextQueuedNode();
-                } else if (current instanceof LoopBegin) {
-                    state.loopBegin((LoopBegin) current);
-                    nodeStates.put(current, state);
-                    state = state.clone();
-                    loopBegin((LoopBegin) current);
-                    current = ((LoopBegin) current).next();
-                    assert current != null;
-                } else if (current instanceof LoopEnd) {
-                    T loopBeginState = nodeStates.get(((LoopEnd) current).loopBegin());
-                    if (loopBeginState != null) {
-                        loopBeginState.loopEnd((LoopEnd) current, state);
-                    }
-                    loopEnd((LoopEnd) current);
-                    current = nextQueuedNode();
-                } else if (current instanceof Merge) {
-                    merge((Merge) current);
-                    current = ((Merge) current).next();
-                    assert current != null;
-                } else if (current instanceof FixedNodeWithNext) {
-                    FixedNode next = ((FixedNodeWithNext) current).next();
-                    node(current);
-                    current = next;
-                    assert current != null;
-                } else if (current instanceof EndNode) {
-                    end((EndNode) current);
-                    queueMerge((EndNode) current);
-                    current = nextQueuedNode();
-                } else if (current instanceof Deoptimize) {
-                    deoptimize((Deoptimize) current);
-                    current = nextQueuedNode();
-                } else if (current instanceof Return) {
-                    returnNode((Return) current);
-                    current = nextQueuedNode();
-                } else if (current instanceof Unwind) {
-                    unwind((Unwind) current);
-                    current = nextQueuedNode();
-                } else if (current instanceof ControlSplit) {
-                    controlSplit((ControlSplit) current);
-                    queueSuccessors(current);
-                    current = nextQueuedNode();
-                } else {
-                    assert false : current.shortName();
-                }
-            } while(current != null);
-        }
-
-        private void queueSuccessors(FixedNode x) {
-            nodeStates.put(x, state);
-            for (Node node : x.successors()) {
-                if (node != null) {
-                    nodeQueue.addFirst((FixedNode) node);
-                }
-            }
-        }
-
-        private FixedNode nextQueuedNode() {
-            int maxIterations = nodeQueue.size();
-            while (maxIterations-- > 0) {
-                FixedNode node = nodeQueue.removeFirst();
-                if (node instanceof Merge) {
-                    Merge merge = (Merge) node;
-                    state = nodeStates.get(merge.endAt(0)).clone();
-                    ArrayList<T> states = new ArrayList<T>(merge.endCount() - 1);
-                    for (int i = 1; i < merge.endCount(); i++) {
-                        T other = nodeStates.get(merge.endAt(i));
-                        assert other != null;
-                        states.add(other);
-                    }
-                    boolean ready = state.merge(merge, states);
-                    if (ready) {
-                        return merge;
-                    } else {
-                        nodeQueue.addLast(merge);
-                    }
-                } else {
-                    assert node.predecessors().size() == 1;
-                    state = nodeStates.get(node.predecessors().get(0)).clone();
-                    state.afterSplit(node);
-                    return node;
-                }
-            }
-            return null;
-        }
-
-        private void queueMerge(EndNode end) {
-            assert !visitedEnds.isMarked(end);
-            assert !nodeStates.containsKey(end);
-            nodeStates.put(end, state);
-            visitedEnds.mark(end);
-            Merge merge = end.merge();
-            boolean endsVisited = true;
-            for (int i = 0; i < merge.endCount(); i++) {
-                if (!visitedEnds.isMarked(merge.endAt(i))) {
-                    endsVisited = false;
-                    break;
-                }
-            }
-            if (endsVisited) {
-                nodeQueue.add(merge);
-            }
-        }
-
-        protected abstract void node(FixedNode node);
-
-        protected void end(EndNode endNode) {
-            node(endNode);
-        }
-
-        protected void merge(Merge merge) {
-            node(merge);
-        }
-
-        protected void loopBegin(LoopBegin loopBegin) {
-            node(loopBegin);
-        }
-
-        protected void loopEnd(LoopEnd loopEnd) {
-            node(loopEnd);
-        }
-
-        protected void deoptimize(Deoptimize deoptimize) {
-            node(deoptimize);
-        }
-
-        protected void controlSplit(ControlSplit controlSplit) {
-            node(controlSplit);
-        }
-
-        protected void returnNode(Return returnNode) {
-            node(returnNode);
-        }
-
-        protected void invoke(Invoke invoke) {
-            node(invoke);
-        }
-
-        protected void unwind(Unwind unwind) {
-            node(unwind);
-        }
-    }
-
     public static class BlockExitState implements MergeableState<BlockExitState> {
         public final Value[] fieldState;
         public final VirtualObject virtualObject;
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java	Tue Jul 12 18:14:45 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java	Thu Jul 14 10:33:35 2011 +0200
@@ -446,10 +446,10 @@
                 TTY.println("Building graph for %s, locals: %d, stack: %d", methodName(method, invoke), method.maxLocals(), method.maxStackSize());
             }
             graph = new CompilerGraph(null);
-            new GraphBuilderPhase(compilation, method, true).apply(graph);
+            new GraphBuilderPhase(compilation, method, true).apply(graph, true, false);
             if (GraalOptions.ProbabilityAnalysis) {
-                new DeadCodeEliminationPhase().apply(graph);
-                new ComputeProbabilityPhase().apply(graph);
+                new DeadCodeEliminationPhase().apply(graph, true, false);
+                new ComputeProbabilityPhase().apply(graph, true, false);
             }
         }
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/Phase.java	Tue Jul 12 18:14:45 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/Phase.java	Thu Jul 14 10:33:35 2011 +0200
@@ -34,17 +34,17 @@
     private static final ThreadLocal<Phase> currentPhase = new ThreadLocal<Phase>();
     private final boolean shouldVerify;
 
-    public Phase() {
+    protected Phase() {
         this.name = this.getClass().getSimpleName();
         this.shouldVerify = true;
         this.detailedName = name;
     }
 
-    public Phase(String name) {
+    protected Phase(String name) {
         this(name, true);
     }
 
-    public Phase(String name, boolean shouldVerify) {
+    protected Phase(String name, boolean shouldVerify) {
         this.name = name;
         this.shouldVerify = shouldVerify;
         this.detailedName = name;
@@ -55,10 +55,10 @@
     }
 
     public final void apply(Graph graph) {
-        apply(graph, true);
+        apply(graph, true, true);
     }
 
-    public final void apply(Graph graph, boolean plotOnError) {
+    public final void apply(Graph graph, boolean plotOnError, boolean plot) {
         assert graph != null && (!shouldVerify || graph.verify());
 
         int startDeletedNodeCount = graph.getDeletedNodeCount();
@@ -104,7 +104,7 @@
             GraalMetrics.get(getName().concat(".createdNodes")).increment(createdNodeCount);
         }
         GraalCompilation compilation = GraalCompilation.compilation();
-        if (compilation.compiler.isObserved() && this.getClass() != IdentifyBlocksPhase.class) {
+        if (compilation.compiler.isObserved() && this.getClass() != IdentifyBlocksPhase.class && (plot || GraalOptions.PlotVerbose)) {
             compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, "After " + detailedName, graph, true, false));
         }
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/extensions/InliningExample.java	Tue Jul 12 18:14:45 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2011, 2011, 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.max.graal.extensions;
-
-
-public class InliningExample {
-
-    public static void run() {
-        System.out.println(test());
-        long start = System.currentTimeMillis();
-        System.out.println(testFib());
-        System.out.println(System.currentTimeMillis() - start);
-    }
-
-    public static int testFib() {
-        int sum = 0;
-        for (int i = 0; i < 10000000; ++i) {
-            sum += fib(5);
-        }
-        return sum;
-    }
-
-    private static int test() {
-        return alwaysInline(30);
-    }
-
-    public static int alwaysInline(int value) {
-        if (value < 0) {
-            return neverInline(value);
-        }
-        return alwaysInline(value - 1);
-    }
-
-    public static int neverInline(int value) {
-        return value;
-    }
-
-    public static int fib(int val) {
-        if (val == 0 || val == 1) {
-            return 1;
-        }
-        return fib(val - 1) + fib(val - 2);
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.examples/create_examples.xml	Thu Jul 14 10:33:35 2011 +0200
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<project default="create_run_jar" name="Create Runnable Jar for Project com.oracle.max.graal.examples">
+    <!--this file was created by Eclipse Runnable JAR Export Wizard-->
+    <!--ANT 1.7 is required                                        -->
+    <target name="create_run_jar">
+        <jar destfile="./examples.jar" filesetmanifest="mergewithoutmain">
+            <manifest>
+                <attribute name="Main-Class" value="com.oracle.max.graal.examples.Main"/>
+                <attribute name="Class-Path" value="."/>
+            </manifest>
+            <fileset dir="bin"/>
+        </jar>
+    </target>
+</project>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.examples/runexample.sh	Thu Jul 14 10:33:35 2011 +0200
@@ -0,0 +1,23 @@
+#!/bin/bash
+if [ -z "${JDK7}" ]; then
+  echo "JDK7 is not defined."
+  exit 1;
+fi
+if [ -z "${MAXINE}" ]; then
+  echo "MAXINE is not defined. It must point to a maxine repository directory."
+  exit 1;
+fi
+if [ -z "${GRAAL}" ]; then
+  echo "GRAAL is not defined. It must point to a maxine repository directory."
+  exit 1;
+fi
+if [ -z "${DACAPO}" ]; then
+  echo "DACAPO is not defined. It must point to a Dacapo benchmark directory."
+  exit 1;
+fi
+TEST=$1
+shift
+ant -f create_examples.xml
+COMMAND="${JDK7}/bin/java -client -d64 -graal -Xmx1g -esa -G:Extend -G:Plot -G:CacheGraphs -XX:+PrintCompilation -Xcomp -XX:CompileOnly=examples -XX:CompileCommand=quiet -XX:CompileCommand=exclude,*,<init> -XX:CompileCommand=exclude,*,run -XX:CompileCommand=exclude,com.oracle.max.graal.examples.Main::main $* -jar examples.jar ${TEST}"
+# echo $COMMAND
+$COMMAND
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.examples/runexample_c1.sh	Thu Jul 14 10:33:35 2011 +0200
@@ -0,0 +1,23 @@
+#!/bin/bash
+if [ -z "${JDK7}" ]; then
+  echo "JDK7 is not defined."
+  exit 1;
+fi
+if [ -z "${MAXINE}" ]; then
+  echo "MAXINE is not defined. It must point to a maxine repository directory."
+  exit 1;
+fi
+if [ -z "${GRAAL}" ]; then
+  echo "GRAAL is not defined. It must point to a maxine repository directory."
+  exit 1;
+fi
+if [ -z "${DACAPO}" ]; then
+  echo "DACAPO is not defined. It must point to a Dacapo benchmark directory."
+  exit 1;
+fi
+TEST=$1
+shift
+ant -f create_examples.xml
+COMMAND="${JDK7G}/bin/java -client -d64 -Xmx1g -esa -XX:+PrintCFGToFile -XX:+PrintCompilation -Xcomp -XX:CompileOnly=examples -XX:CompileCommand=quiet -XX:CompileCommand=exclude,*,<init> -XX:CompileCommand=exclude,*,run -XX:CompileCommand=exclude,com.oracle.max.graal.examples.Main::main $* -jar examples.jar ${TEST}"
+# echo $COMMAND
+$COMMAND
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.examples/runexample_c2.sh	Thu Jul 14 10:33:35 2011 +0200
@@ -0,0 +1,23 @@
+#!/bin/bash
+if [ -z "${JDK7}" ]; then
+  echo "JDK7 is not defined."
+  exit 1;
+fi
+if [ -z "${MAXINE}" ]; then
+  echo "MAXINE is not defined. It must point to a maxine repository directory."
+  exit 1;
+fi
+if [ -z "${GRAAL}" ]; then
+  echo "GRAAL is not defined. It must point to a maxine repository directory."
+  exit 1;
+fi
+if [ -z "${DACAPO}" ]; then
+  echo "DACAPO is not defined. It must point to a Dacapo benchmark directory."
+  exit 1;
+fi
+TEST=$1
+shift
+ant -f create_examples.xml
+COMMAND="${JDK7G}/bin/java -d64 -Xmx1g -esa -XX:+PrintCompilation -XX:PrintIdealGraphLevel=1 -Xcomp -XX:CompileOnly=examples -XX:CompileCommand=quiet -XX:CompileCommand=exclude,*,<init> -XX:CompileCommand=exclude,*,run -XX:CompileCommand=exclude,com.oracle.max.graal.examples.Main::main $* -jar examples.jar ${TEST}"
+# echo $COMMAND
+$COMMAND
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.examples/runexamplescompare.sh	Thu Jul 14 10:33:35 2011 +0200
@@ -0,0 +1,29 @@
+#!/bin/bash
+if [ -z "${JDK7}" ]; then
+  echo "JDK7 is not defined."
+  exit 1;
+fi
+if [ -z "${MAXINE}" ]; then
+  echo "MAXINE is not defined. It must point to a maxine repository directory."
+  exit 1;
+fi
+if [ -z "${GRAAL}" ]; then
+  echo "GRAAL is not defined. It must point to a maxine repository directory."
+  exit 1;
+fi
+if [ -z "${DACAPO}" ]; then
+  echo "DACAPO is not defined. It must point to a Dacapo benchmark directory."
+  exit 1;
+fi
+TEST=$1
+shift
+ant -f create_examples.xml
+COMMAND="${JDK7}/bin/java -client -d64 -graal -Xms1g -Xmx2g -esa -G:Extend -Xcomp -XX:CompileOnly=examples $* -jar examples.jar ${TEST}"
+echo $COMMAND
+$COMMAND
+COMMAND="${JDK7}/bin/java -client -d64 -Xms1g -Xmx2g -esa -Xcomp -XX:CompileOnly=examples $* -jar examples.jar ${TEST}"
+echo $COMMAND
+$COMMAND
+COMMAND="${JDK7}/bin/java -server -d64 -Xms1g -Xmx2g -esa -Xcomp -XX:CompileOnly=examples $* -jar examples.jar ${TEST}"
+echo $COMMAND
+$COMMAND
--- a/graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/Main.java	Tue Jul 12 18:14:45 2011 +0200
+++ b/graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/Main.java	Thu Jul 14 10:33:35 2011 +0200
@@ -26,15 +26,28 @@
 import com.oracle.max.graal.examples.inlining.*;
 import com.oracle.max.graal.examples.intrinsics.*;
 import com.oracle.max.graal.examples.opt.*;
-
+import com.oracle.max.graal.examples.simple.*;
 
 public class Main {
 
     public static void main(String[] args) {
-//        InliningExample.run();
-//        SafeAddExample.run();
-//        OptimizationExample.run();
-        DeoptExample.run();
+        System.err.println("== Graal Examples ==");
+        if (args.length == 1) {
+            if (args[0].equals("simple")) {
+                SimpleExample.run();
+            } else if (args[0].equals("inlining")) {
+                InliningExample.run();
+            } else if (args[0].equals("safeadd")) {
+                SafeAddExample.run();
+            } else if (args[0].equals("opt")) {
+                OptimizationExample.run();
+            } else if (args[0].equals("deopt")) {
+                DeoptExample.run();
+            } else {
+                System.out.println("unknown example: " + args[0]);
+            }
+        } else {
+            System.out.println("usage: java " + Main.class.getSimpleName() + " <example>");
+        }
     }
-
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/simple/SimpleExample.java	Thu Jul 14 10:33:35 2011 +0200
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2011, 2011, 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.max.graal.examples.simple;
+
+
+public class SimpleExample {
+
+    public static void run() {
+        System.out.println(mulAdd(1, 2, 3));
+        System.out.println(divAdd(1, 2, 3));
+    }
+
+    private static int mulAdd(int a, int b, int c) {
+        return a * b + c;
+    }
+
+    private static int divAdd(int a, int b, int c) {
+        return a / b + c;
+    }
+}