changeset 3130:a4b0c3df7f80

Canonicalize RegisterFinalizer nodes.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Fri, 01 Jul 2011 19:39:14 +0200
parents acda73820e9b
children 5c696a58e692
files 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/ir/RegisterFinalizer.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotMethodResolvedImpl.java graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotMethodUnresolved.java runfop.sh
diffstat 7 files changed, 105 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java	Fri Jul 01 18:28:26 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java	Fri Jul 01 19:39:14 2011 +0200
@@ -41,6 +41,7 @@
 
     // inlining settings
     public static boolean Inline                             = true;
+    public static boolean Intrinsify                         = true;
     public static boolean CacheGraphs                        = ____;
     public static boolean InlineWithTypeCheck                = ____;
     public static int     MaximumInstructionCount            = 37000;
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/RegisterFinalizer.java	Fri Jul 01 18:28:26 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/RegisterFinalizer.java	Fri Jul 01 19:39:14 2011 +0200
@@ -22,9 +22,13 @@
  */
 package com.oracle.max.graal.compiler.ir;
 
+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.phases.CanonicalizerPhase.CanonicalizerOp;
 import com.oracle.max.graal.graph.*;
 import com.sun.cri.ci.*;
+import com.sun.cri.ri.*;
 
 /**
  * This instruction is used to perform the finalizer registration at the end of the java.lang.Object constructor.
@@ -67,6 +71,57 @@
         v.visitRegisterFinalizer(this);
     }
 
+    @SuppressWarnings("unchecked")
+    @Override
+    public <T extends Op> T lookup(Class<T> clazz) {
+        if (clazz == CanonicalizerOp.class) {
+            return (T) CANONICALIZER;
+        }
+        return super.lookup(clazz);
+    }
+
+    private static final CanonicalizerOp CANONICALIZER = new CanonicalizerOp() {
+
+        @Override
+        public Node canonical(Node node) {
+            RegisterFinalizer finalizer = (RegisterFinalizer) node;
+            Value object = finalizer.object();
+
+            RiType declaredType = object.declaredType();
+            RiType exactType = object.exactType();
+            if (exactType == null && declaredType != null) {
+                exactType = declaredType.exactType();
+            }
+
+            GraalCompilation compilation = ((CompilerGraph) node.graph()).getCompilation();
+            boolean needsCheck = true;
+            if (exactType != null) {
+                // we have an exact type
+                needsCheck = exactType.hasFinalizer();
+            } else {
+                // if either the declared type of receiver or the holder can be assumed to have no finalizers
+                if (declaredType != null && !declaredType.hasFinalizableSubclass()) {
+                    if (compilation.recordNoFinalizableSubclassAssumption(declaredType)) {
+                        needsCheck = false;
+                    }
+                }
+            }
+
+            if (needsCheck) {
+                if (GraalOptions.TraceGVN) {
+                    TTY.println("Could not canonicalize finalizer " + object + " (declaredType=" + declaredType + ", exactType=" + exactType + ")");
+                }
+            } else {
+                if (GraalOptions.TraceGVN) {
+                    TTY.println("Canonicalized finalizer for object " + object);
+                }
+                return finalizer.next();
+            }
+
+            return finalizer;
+        }
+    };
+
     @Override
     public void print(LogStream out) {
         out.print("register finalizer ").print(object());
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java	Fri Jul 01 18:28:26 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java	Fri Jul 01 19:39:14 2011 +0200
@@ -994,42 +994,8 @@
     }
 
     private void callRegisterFinalizer() {
-        Value receiver = frameState.loadLocal(0);
-        RiType declaredType = receiver.declaredType();
-        RiType receiverType = declaredType;
-        RiType exactType = receiver.exactType();
-        if (exactType == null && declaredType != null) {
-            exactType = declaredType.exactType();
-        }
-        if (exactType == null && receiver instanceof Local && ((Local) receiver).index() == 0) {
-            // the exact type isn't known, but the receiver is parameter 0 => use holder
-            receiverType = method.holder();
-            exactType = receiverType.exactType();
-        }
-        boolean needsCheck = true;
-        if (exactType != null) {
-            // we have an exact type
-            needsCheck = exactType.hasFinalizer();
-        } else {
-            // if either the declared type of receiver or the holder can be assumed to have no finalizers
-            if (declaredType != null && !declaredType.hasFinalizableSubclass()) {
-                if (compilation.recordNoFinalizableSubclassAssumption(declaredType)) {
-                    needsCheck = false;
-                }
-            }
-
-            if (receiverType != null && !receiverType.hasFinalizableSubclass()) {
-                if (compilation.recordNoFinalizableSubclassAssumption(receiverType)) {
-                    needsCheck = false;
-                }
-            }
-        }
-
-        if (needsCheck) {
-            // append a call to the finalizer registration
-            append(new RegisterFinalizer(frameState.loadLocal(0), graph));
-            GraalMetrics.InlinedFinalizerChecks++;
-        }
+        // append a call to the finalizer registration
+        append(new RegisterFinalizer(frameState.loadLocal(0), graph));
     }
 
     private void genReturn(Value x) {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java	Fri Jul 01 18:28:26 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java	Fri Jul 01 19:39:14 2011 +0200
@@ -128,6 +128,10 @@
         if (!checkInvokeConditions(invoke)) {
             return null;
         }
+        if (invoke.target.hasIntrinsicGraph() && GraalOptions.Intrinsify) {
+            // Always intrinsify.
+            return invoke.target;
+        }
         if (invoke.opcode() == Bytecodes.INVOKESPECIAL || invoke.target.canBeStaticallyBound()) {
             if (checkTargetConditions(invoke.target, iterations) && checkSizeConditions(invoke.target, invoke, profile, ratio)) {
                 return invoke.target;
@@ -326,21 +330,6 @@
             exceptionEdge = ((Placeholder) exceptionEdge).next();
         }
 
-        CompilerGraph graph;
-        Object stored = GraphBuilderPhase.cachedGraphs.get(method);
-        if (stored != null) {
-            if (GraalOptions.TraceInlining) {
-                TTY.println("Reusing graph for %s, locals: %d, stack: %d", methodName(method, invoke), method.maxLocals(), method.maxStackSize());
-            }
-            graph = (CompilerGraph) stored;
-        } else {
-            if (GraalOptions.TraceInlining) {
-                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, true).apply(graph);
-        }
-
         boolean withReceiver = !Modifier.isStatic(method.accessFlags());
 
         int argumentCount = method.signature().argumentCount(false);
@@ -355,6 +344,28 @@
             parameters[0] = invoke.argument(0);
         }
 
+        CompilerGraph graph = null;
+        if (GraalOptions.Intrinsify) {
+            graph = (CompilerGraph) method.intrinsicGraph(parameters);
+        }
+        if (graph != null) {
+            TTY.println("Using intrinsic graph");
+        } else {
+            graph = GraphBuilderPhase.cachedGraphs.get(method);
+        }
+
+        if (graph != null) {
+            if (GraalOptions.TraceInlining) {
+                TTY.println("Reusing graph for %s, locals: %d, stack: %d", methodName(method, invoke), method.maxLocals(), method.maxStackSize());
+            }
+        } else {
+            if (GraalOptions.TraceInlining) {
+                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, true).apply(graph);
+        }
+
         invoke.inputs().clearAll();
 
         HashMap<Node, Node> replacements = new HashMap<Node, Node>();
--- a/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotMethodResolvedImpl.java	Fri Jul 01 18:28:26 2011 +0200
+++ b/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotMethodResolvedImpl.java	Fri Jul 01 19:39:14 2011 +0200
@@ -223,4 +223,14 @@
             }
         }
     }
+
+    @Override
+    public Graph intrinsicGraph(Node[] parameters) {
+        return null;
+    }
+
+    @Override
+    public boolean hasIntrinsicGraph() {
+        return false;
+    }
 }
--- a/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotMethodUnresolved.java	Fri Jul 01 18:28:26 2011 +0200
+++ b/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotMethodUnresolved.java	Fri Jul 01 19:39:14 2011 +0200
@@ -177,4 +177,14 @@
     public int branchProbability(int bci) {
         return -1;
     }
+
+    @Override
+    public Graph intrinsicGraph(Node[] parameters) {
+        return null;
+    }
+
+    @Override
+    public boolean hasIntrinsicGraph() {
+        return false;
+    }
 }
--- a/runfop.sh	Fri Jul 01 18:28:26 2011 +0200
+++ b/runfop.sh	Fri Jul 01 19:39:14 2011 +0200
@@ -15,4 +15,4 @@
   echo "DACAPO is not defined. It must point to a Dacapo benchmark directory."
   exit 1;
 fi
-${JDK7}/bin/java -client -d64 -graal -Xms1g -Xmx2g -esa -classpath ${DACAPO}/dacapo-9.12-bach.jar -XX:-GraalBailoutIsFatal $* Harness --preserve -n 10 fop 
+${JDK7}/bin/java -client -d64 -graal -Xms1g -Xmx2g -esa -classpath ${DACAPO}/dacapo-9.12-bach.jar -XX:-GraalBailoutIsFatal $* Harness --preserve -n 20 fop