changeset 11260:064ce0777eba

Merge.
author Doug Simon <doug.simon@oracle.com>
date Wed, 07 Aug 2013 19:52:26 +0200
parents 3245779c0ce2 (current diff) 27a415148090 (diff)
children 51dad16d84c4
files
diffstat 7 files changed, 197 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/EscapeAnalysisTest.java	Wed Aug 07 18:41:00 2013 +0200
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/EscapeAnalysisTest.java	Wed Aug 07 19:52:26 2013 +0200
@@ -30,8 +30,10 @@
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.compiler.test.*;
 import com.oracle.graal.debug.*;
+import com.oracle.graal.graph.*;
 import com.oracle.graal.java.*;
 import com.oracle.graal.nodes.*;
+import com.oracle.graal.nodes.calc.*;
 import com.oracle.graal.nodes.java.*;
 import com.oracle.graal.nodes.virtual.*;
 import com.oracle.graal.phases.*;
@@ -207,6 +209,20 @@
         return obj2.o instanceof TestObject2;
     }
 
+    @SuppressWarnings("unused")
+    public static void testNewNodeSnippet() {
+        new IntegerAddNode(Kind.Int, null, null);
+    }
+
+    /**
+     * This test makes sure that the allocation of a {@link Node} can be removed. It therefore also
+     * tests the intrinsification of {@link Object#getClass()}.
+     */
+    @Test
+    public void testNewNode() {
+        testEscapeAnalysis("testNewNodeSnippet", null, false);
+    }
+
     private ReturnNode testEscapeAnalysis(String snippet, final Constant expectedConstantResult, final boolean iterativeEscapeAnalysis) {
         ResolvedJavaMethod method = runtime.lookupJavaMethod(getMethod(snippet));
         final StructuredGraph graph = new StructuredGraph(method);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ObjectGetClassNode.java	Wed Aug 07 19:52:26 2013 +0200
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2013, 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.hotspot.replacements;
+
+import static com.oracle.graal.phases.GraalOptions.*;
+
+import com.oracle.graal.api.meta.*;
+import com.oracle.graal.api.meta.ResolvedJavaType.Representation;
+import com.oracle.graal.nodes.*;
+import com.oracle.graal.nodes.spi.*;
+import com.oracle.graal.nodes.type.*;
+import com.oracle.graal.replacements.nodes.*;
+
+/**
+ * This macro node will replace itself with the correct Java {@link Class} as soon as the object's
+ * type is known (exact).
+ */
+public class ObjectGetClassNode extends MacroNode implements Virtualizable, Canonicalizable {
+
+    public ObjectGetClassNode(Invoke invoke) {
+        super(invoke);
+    }
+
+    private ValueNode getObject() {
+        return arguments.get(0);
+    }
+
+    @Override
+    public void virtualize(VirtualizerTool tool) {
+        if (AOTCompilation.getValue()) {
+            return;
+        }
+        State state = tool.getObjectState(getObject());
+        if (state != null) {
+            Constant clazz = state.getVirtualObject().type().getEncoding(Representation.JavaClass);
+            tool.replaceWithValue(ConstantNode.forConstant(clazz, tool.getMetaAccessProvider(), graph()));
+        }
+    }
+
+    public ValueNode canonical(CanonicalizerTool tool) {
+        if (AOTCompilation.getValue()) {
+            return this;
+        }
+        if (usages().isEmpty()) {
+            return null;
+        } else {
+            ObjectStamp stamp = getObject().objectStamp();
+            if (stamp.isExactType()) {
+                Constant clazz = stamp.type().getEncoding(Representation.JavaClass);
+                return ConstantNode.forConstant(clazz, tool.runtime(), graph());
+            } else {
+                return this;
+            }
+        }
+    }
+}
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ObjectSubstitutions.java	Wed Aug 07 18:41:00 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ObjectSubstitutions.java	Wed Aug 07 19:52:26 2013 +0200
@@ -37,7 +37,8 @@
 @ClassSubstitution(java.lang.Object.class)
 public class ObjectSubstitutions {
 
-    @MethodSubstitution(isStatic = false)
+    @MacroSubstitution(macro = ObjectGetClassNode.class, isStatic = false, forced = true)
+    @MethodSubstitution(isStatic = false, forced = true)
     public static Class<?> getClass(final Object thisObj) {
         Word hub = loadHub(thisObj);
         return unsafeCast(hub.readObject(Word.signed(classMirrorOffset()), LocationIdentity.FINAL_LOCATION), Class.class, true, true);
@@ -48,7 +49,7 @@
         return computeHashCode(thisObj);
     }
 
-    @MethodSubstitution(value = "<init>", isStatic = false)
+    @MethodSubstitution(value = "<init>", isStatic = false, forced = true)
     public static void init(Object thisObj) {
         RegisterFinalizerNode.register(thisObj);
     }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/SystemSubstitutions.java	Wed Aug 07 18:41:00 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/SystemSubstitutions.java	Wed Aug 07 19:52:26 2013 +0200
@@ -29,8 +29,10 @@
 import com.oracle.graal.api.replacements.*;
 import com.oracle.graal.graph.Node.ConstantNodeParameter;
 import com.oracle.graal.graph.Node.NodeIntrinsic;
+import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.extended.*;
 import com.oracle.graal.nodes.spi.*;
+import com.oracle.graal.replacements.nodes.*;
 
 /**
  * Substitutions for {@link java.lang.System} methods.
@@ -54,6 +56,19 @@
         return callLong(JAVA_TIME_NANOS);
     }
 
+    public static class SystemIdentityHashCodeNode extends PureFunctionMacroNode {
+
+        public SystemIdentityHashCodeNode(Invoke invoke) {
+            super(invoke);
+        }
+
+        @Override
+        protected Constant evaluate(Constant param, MetaAccessProvider metaAccess) {
+            return param.isNull() ? null : Constant.forInt(System.identityHashCode(param.asObject()));
+        }
+    }
+
+    @MacroSubstitution(macro = SystemIdentityHashCodeNode.class)
     @MethodSubstitution
     public static int identityHashCode(Object x) {
         if (probability(NOT_FREQUENT_PROBABILITY, x == null)) {
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/NodeClassSubstitutions.java	Wed Aug 07 18:41:00 2013 +0200
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/NodeClassSubstitutions.java	Wed Aug 07 19:52:26 2013 +0200
@@ -22,10 +22,15 @@
  */
 package com.oracle.graal.replacements;
 
+import static com.oracle.graal.phases.GraalOptions.*;
+
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.api.replacements.*;
 import com.oracle.graal.graph.*;
+import com.oracle.graal.nodes.*;
 import com.oracle.graal.nodes.extended.*;
+import com.oracle.graal.nodes.spi.*;
+import com.oracle.graal.replacements.nodes.*;
 
 /**
  * Substitutions for improving the performance of some critical methods in {@link NodeClass}
@@ -37,6 +42,26 @@
 @ClassSubstitution(NodeClass.class)
 public class NodeClassSubstitutions {
 
+    /**
+     * A macro node for calls to {@link NodeClass#get(Class)}. It can use the compiler's knowledge
+     * about node classes to replace itself with a constant value for a constant {@link Class}
+     * parameter.
+     */
+    public static class NodeClassGetNode extends PureFunctionMacroNode {
+
+        public NodeClassGetNode(Invoke invoke) {
+            super(invoke);
+        }
+
+        @Override
+        protected Constant evaluate(Constant param, MetaAccessProvider metaAccess) {
+            return param.isNull() || AOTCompilation.getValue() ? null : Constant.forObject(NodeClass.get((Class<?>) param.asObject()));
+        }
+    }
+
+    @MacroSubstitution(isStatic = true, forced = true, macro = NodeClassGetNode.class)
+    private static native NodeClass get(Class<?> c);
+
     @MethodSubstitution
     private static Node getNode(Node node, long offset) {
         return UnsafeCastNode.unsafeCast(UnsafeLoadNode.load(node, 0, offset, Kind.Object), Node.class, false, false);
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/MacroNode.java	Wed Aug 07 18:41:00 2013 +0200
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/MacroNode.java	Wed Aug 07 19:52:26 2013 +0200
@@ -80,16 +80,18 @@
 
     @Override
     public void lower(LoweringTool tool, LoweringType loweringType) {
+        boolean nullCheck = false;
         StructuredGraph replacementGraph = getSnippetGraph(tool);
         if (replacementGraph == null) {
             replacementGraph = getSubstitutionGraph(tool);
+            nullCheck = true;
         }
 
         InvokeNode invoke = replaceWithInvoke();
         assert invoke.verify();
 
         if (replacementGraph != null) {
-            InliningUtil.inline(invoke, replacementGraph, false);
+            InliningUtil.inline(invoke, replacementGraph, nullCheck);
         }
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/PureFunctionMacroNode.java	Wed Aug 07 19:52:26 2013 +0200
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2013, 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.replacements.nodes;
+
+import com.oracle.graal.api.meta.*;
+import com.oracle.graal.nodes.*;
+import com.oracle.graal.nodes.spi.*;
+
+/**
+ * This node class can be used to create {@link MacroNode}s for simple pure functions like
+ * {@link Object#getClass()} or {@link System#identityHashCode(Object)}.
+ */
+public abstract class PureFunctionMacroNode extends MacroNode implements Canonicalizable {
+
+    public PureFunctionMacroNode(Invoke invoke) {
+        super(invoke);
+    }
+
+    /**
+     * This method should return either a constant that represents the result of the function, or
+     * null if no such result could be determined.
+     */
+    protected abstract Constant evaluate(Constant param, MetaAccessProvider metaAccess);
+
+    public ValueNode canonical(CanonicalizerTool tool) {
+        if (usages().isEmpty()) {
+            return null;
+        } else {
+            ValueNode param = arguments.get(0);
+            if (param.isConstant()) {
+                Constant constant = evaluate(param.asConstant(), tool.runtime());
+                if (constant != null) {
+                    return ConstantNode.forConstant(constant, tool.runtime(), graph());
+                }
+            }
+        }
+        return this;
+    }
+}