changeset 20143:3424e06e4951

Merge.
author Doug Simon <doug.simon@oracle.com>
date Thu, 02 Apr 2015 16:56:27 +0200
parents 6d51420ee69f (diff) d7d33c72fdc8 (current diff)
children 921eeb012866
files
diffstat 10 files changed, 174 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/DefaultHotSpotLoweringProvider.java	Thu Apr 02 16:30:52 2015 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/DefaultHotSpotLoweringProvider.java	Thu Apr 02 16:56:27 2015 +0200
@@ -100,6 +100,8 @@
             lowerInvoke((Invoke) n, tool, graph);
         } else if (n instanceof LoadMethodNode) {
             lowerLoadMethodNode((LoadMethodNode) n);
+        } else if (n instanceof GetClassNode) {
+            lowerGetClassNode((GetClassNode) n, tool, graph);
         } else if (n instanceof StoreHubNode) {
             lowerStoreHubNode((StoreHubNode) n, graph);
         } else if (n instanceof OSRStartNode) {
@@ -326,6 +328,15 @@
         graph.replaceFixed(loadMethodNode, metaspaceMethod);
     }
 
+    private static void lowerGetClassNode(GetClassNode getClass, LoweringTool tool, StructuredGraph graph) {
+        StampProvider stampProvider = tool.getStampProvider();
+        LoadHubNode hub = graph.unique(new LoadHubNode(stampProvider, getClass.getObject()));
+        HubGetClassNode hubGetClass = graph.unique(new HubGetClassNode(tool.getMetaAccess(), hub));
+        graph.replaceFloating(getClass, hubGetClass);
+        hub.lower(tool);
+        hubGetClass.lower(tool);
+    }
+
     private void lowerStoreHubNode(StoreHubNode storeHub, StructuredGraph graph) {
         WriteNode hub = createWriteHub(graph, storeHub.getObject(), storeHub.getValue());
         graph.replaceFixed(storeHub, hub);
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java	Thu Apr 02 16:30:52 2015 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java	Thu Apr 02 16:56:27 2015 +0200
@@ -31,7 +31,6 @@
 import com.oracle.graal.api.code.*;
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.api.replacements.*;
-import com.oracle.graal.compiler.common.*;
 import com.oracle.graal.compiler.common.type.*;
 import com.oracle.graal.graphbuilderconf.GraphBuilderConfiguration.Plugins;
 import com.oracle.graal.graphbuilderconf.*;
@@ -93,22 +92,6 @@
 
     private static void registerObjectPlugins(InvocationPlugins plugins) {
         Registration r = new Registration(plugins, Object.class);
-        r.register1("getClass", Receiver.class, new InvocationPlugin() {
-            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
-                ValueNode rcvr = receiver.get();
-                ObjectStamp objectStamp = (ObjectStamp) rcvr.stamp();
-                ValueNode mirror;
-                if (objectStamp.isExactType() && objectStamp.nonNull() && !GraalOptions.ImmutableCode.getValue()) {
-                    mirror = ConstantNode.forConstant(objectStamp.type().getJavaClass(), b.getMetaAccess());
-                } else {
-                    StampProvider stampProvider = b.getStampProvider();
-                    LoadHubNode hub = b.add(new LoadHubNode(stampProvider, rcvr));
-                    mirror = new HubGetClassNode(b.getMetaAccess(), hub);
-                }
-                b.addPush(Kind.Object, mirror);
-                return true;
-            }
-        });
         r.register1("clone", Receiver.class, new InvocationPlugin() {
             public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
                 ValueNode object = receiver.get();
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSnippetReflectionProvider.java	Thu Apr 02 16:30:52 2015 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSnippetReflectionProvider.java	Thu Apr 02 16:56:27 2015 +0200
@@ -72,14 +72,26 @@
         return null;
     }
 
+    // Lazily initialized
+    private ResolvedJavaType wordTypesType;
+    private ResolvedJavaType runtimeType;
+    private ResolvedJavaType configType;
+
     public Object getInjectedNodeIntrinsicParameter(ResolvedJavaType type) {
-        if (type.isInstance(forObject(runtime.getHostProviders().getWordTypes()))) {
+        if (wordTypesType == null) {
+            MetaAccessProvider metaAccess = runtime.getHostProviders().getMetaAccess();
+            wordTypesType = metaAccess.lookupJavaType(runtime.getHostProviders().getWordTypes().getClass());
+            runtimeType = metaAccess.lookupJavaType(runtime.getClass());
+            configType = metaAccess.lookupJavaType(runtime.getConfig().getClass());
+        }
+
+        if (type.isAssignableFrom(wordTypesType)) {
             return runtime.getHostProviders().getWordTypes();
         }
-        if (type.isInstance(forObject(runtime))) {
+        if (type.isAssignableFrom(runtimeType)) {
             return runtime;
         }
-        if (type.isInstance(forObject(runtime.getConfig()))) {
+        if (type.isAssignableFrom(configType)) {
             return runtime.getConfig();
         }
         return null;
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ClassGetHubNode.java	Thu Apr 02 16:30:52 2015 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ClassGetHubNode.java	Thu Apr 02 16:56:27 2015 +0200
@@ -73,6 +73,10 @@
                     }
                 }
             }
+            if (clazz instanceof GetClassNode) {
+                GetClassNode getClass = (GetClassNode) clazz;
+                return new LoadHubNode(KlassPointerStamp.klass(), getClass.getObject(), null);
+            }
             if (clazz instanceof HubGetClassNode) {
                 // replace _klass._java_mirror._klass -> _klass
                 return ((HubGetClassNode) clazz).getHub();
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ObjectEqualsNode.java	Thu Apr 02 16:30:52 2015 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ObjectEqualsNode.java	Thu Apr 02 16:56:27 2015 +0200
@@ -22,13 +22,17 @@
  */
 package com.oracle.graal.nodes.calc;
 
+import com.oracle.graal.api.meta.Assumptions.AssumptionResult;
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.compiler.common.*;
 import com.oracle.graal.compiler.common.calc.*;
 import com.oracle.graal.compiler.common.type.*;
 import com.oracle.graal.graph.*;
+import com.oracle.graal.graph.spi.*;
 import com.oracle.graal.nodeinfo.*;
 import com.oracle.graal.nodes.*;
+import com.oracle.graal.nodes.extended.*;
+import com.oracle.graal.nodes.java.*;
 import com.oracle.graal.nodes.spi.*;
 
 @NodeInfo(shortName = "==")
@@ -55,6 +59,29 @@
         }
     }
 
+    @Override
+    protected ValueNode canonicalizeSymmetricConstant(CanonicalizerTool tool, Constant constant, ValueNode nonConstant, boolean mirrored) {
+        ResolvedJavaType type = tool.getConstantReflection().asJavaType(constant);
+        if (type != null && nonConstant instanceof GetClassNode) {
+            if (type.isPrimitive()) {
+                return LogicConstantNode.forBoolean(false);
+            }
+            ResolvedJavaType exactType = type.asExactType();
+            if (exactType == null) {
+                AssumptionResult<ResolvedJavaType> leafConcreteSubtype = type.findLeafConcreteSubtype();
+                if (leafConcreteSubtype != null) {
+                    graph().getAssumptions().record(leafConcreteSubtype);
+                    exactType = leafConcreteSubtype.getResult();
+                }
+            }
+
+            if (type.equals(exactType)) {
+                return TypeCheckNode.create(exactType, ((GetClassNode) nonConstant).getObject());
+            }
+        }
+        return super.canonicalizeSymmetricConstant(tool, constant, nonConstant, mirrored);
+    }
+
     private void virtualizeNonVirtualComparison(State state, ValueNode other, VirtualizerTool tool) {
         if (!state.getVirtualObject().hasIdentity() && state.getVirtualObject().entryKind(0) == Kind.Boolean) {
             if (other.isConstant()) {
@@ -92,7 +119,7 @@
                 /*
                  * One of the two objects has identity, the other doesn't. In code, this looks like
                  * "Integer.valueOf(a) == new Integer(b)", which is always false.
-                 *
+                 * 
                  * In other words: an object created via valueOf can never be equal to one created
                  * by new in the same compilation unit.
                  */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/GetClassNode.java	Thu Apr 02 16:56:27 2015 +0200
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2011, 2015, 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.nodes.extended;
+
+import com.oracle.graal.api.meta.Assumptions.AssumptionResult;
+import com.oracle.graal.api.meta.*;
+import com.oracle.graal.compiler.common.type.*;
+import com.oracle.graal.graph.*;
+import com.oracle.graal.graph.spi.*;
+import com.oracle.graal.nodeinfo.*;
+import com.oracle.graal.nodes.*;
+import com.oracle.graal.nodes.calc.*;
+import com.oracle.graal.nodes.spi.*;
+
+/**
+ * Loads an object's class (i.e., this node can be created for {@code object.getClass()}).
+ */
+@NodeInfo
+public final class GetClassNode extends FloatingNode implements Lowerable, Canonicalizable, Virtualizable {
+
+    public static final NodeClass<GetClassNode> TYPE = NodeClass.create(GetClassNode.class);
+    @Input ValueNode object;
+
+    public ValueNode getObject() {
+        return object;
+    }
+
+    public GetClassNode(Stamp stamp, ValueNode object) {
+        super(TYPE, stamp);
+        this.object = object;
+    }
+
+    @Override
+    public void lower(LoweringTool tool) {
+        tool.getLowerer().lower(this, tool);
+    }
+
+    public static ValueNode tryFold(MetaAccessProvider metaAccess, ValueNode object) {
+        if (metaAccess != null && object != null && object.stamp() instanceof ObjectStamp) {
+            ObjectStamp objectStamp = (ObjectStamp) object.stamp();
+
+            ResolvedJavaType exactType = null;
+            if (objectStamp.isExactType()) {
+                exactType = objectStamp.type();
+            } else if (objectStamp.type() != null && object.graph().getAssumptions() != null) {
+                AssumptionResult<ResolvedJavaType> leafConcreteSubtype = objectStamp.type().findLeafConcreteSubtype();
+                if (leafConcreteSubtype != null) {
+                    exactType = leafConcreteSubtype.getResult();
+                    object.graph().getAssumptions().record(leafConcreteSubtype);
+                }
+            }
+
+            if (exactType != null) {
+                return ConstantNode.forConstant(exactType.getJavaClass(), metaAccess);
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public ValueNode canonical(CanonicalizerTool tool) {
+        ValueNode folded = tryFold(tool.getMetaAccess(), getObject());
+        return folded == null ? this : folded;
+    }
+
+    @Override
+    public void virtualize(VirtualizerTool tool) {
+        State state = tool.getObjectState(object);
+        if (state != null) {
+            Constant javaClass = state.getVirtualObject().type().getJavaClass();
+            tool.replaceWithValue(ConstantNode.forConstant(stamp(), javaClass, tool.getMetaAccessProvider(), graph()));
+        }
+    }
+}
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/LoadHubNode.java	Thu Apr 02 16:30:52 2015 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/LoadHubNode.java	Thu Apr 02 16:56:27 2015 +0200
@@ -54,7 +54,11 @@
     }
 
     public LoadHubNode(@InjectedNodeParameter StampProvider stampProvider, ValueNode value, ValueNode guard) {
-        super(TYPE, hubStamp(stampProvider, value), (GuardingNode) guard);
+        this(hubStamp(stampProvider, value), value, guard);
+    }
+
+    public LoadHubNode(Stamp stamp, ValueNode value, ValueNode guard) {
+        super(TYPE, stamp, (GuardingNode) guard);
         assert value != guard;
         this.value = value;
     }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/TypeCheckNode.java	Thu Apr 02 16:30:52 2015 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/TypeCheckNode.java	Thu Apr 02 16:56:27 2015 +0200
@@ -41,7 +41,7 @@
 
     protected final ResolvedJavaType type;
 
-    protected TypeCheckNode(ResolvedJavaType type, ValueNode object) {
+    public TypeCheckNode(ResolvedJavaType type, ValueNode object) {
         super(TYPE, object);
         this.type = type;
         assert type != null;
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/LoweringPhase.java	Thu Apr 02 16:30:52 2015 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/LoweringPhase.java	Thu Apr 02 16:56:27 2015 +0200
@@ -357,8 +357,7 @@
             if (node instanceof FloatingNode) {
                 for (Node usage : node.usages()) {
                     if (usage instanceof ValueNode) {
-                        Block usageBlock = schedule.getCFG().blockFor(usage);
-                        if (usageBlock == null) {
+                        if (schedule.getCFG().getNodeToBlock().isNew(usage) || schedule.getCFG().blockFor(usage) == null) {
                             unscheduledUsages.add(usage);
                         }
                     }
--- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/StandardGraphBuilderPlugins.java	Thu Apr 02 16:30:52 2015 +0200
+++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/StandardGraphBuilderPlugins.java	Thu Apr 02 16:56:27 2015 +0200
@@ -30,6 +30,7 @@
 import com.oracle.graal.api.directives.*;
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.compiler.common.calc.*;
+import com.oracle.graal.compiler.common.type.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.graphbuilderconf.*;
 import com.oracle.graal.graphbuilderconf.InvocationPlugins.Receiver;
@@ -39,6 +40,7 @@
 import com.oracle.graal.nodes.debug.*;
 import com.oracle.graal.nodes.extended.*;
 import com.oracle.graal.nodes.java.*;
+import com.oracle.graal.nodes.util.*;
 import com.oracle.graal.options.*;
 import com.oracle.graal.replacements.nodes.*;
 
@@ -368,6 +370,19 @@
                 return true;
             }
         });
+        r.register1("getClass", Receiver.class, new InvocationPlugin() {
+            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
+                ValueNode object = receiver.get();
+                ValueNode folded = GetClassNode.tryFold(b.getMetaAccess(), GraphUtil.originalValue(object));
+                if (folded != null) {
+                    b.addPush(Kind.Object, folded);
+                } else {
+                    Stamp stamp = StampFactory.declaredNonNull(b.getMetaAccess().lookupJavaType(Class.class));
+                    b.addPush(Kind.Object, new GetClassNode(stamp, object));
+                }
+                return true;
+            }
+        });
     }
 
     private static void registerClassPlugins(InvocationPlugins plugins) {