changeset 18340:a0381103324b

More folding of constant classes and NodeClass references
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Tue, 11 Nov 2014 12:45:26 -0800
parents f212e8329825
children 8169f68e9530
files graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantReflectionProvider.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaFieldImpl.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ClassSubstitutions.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/InstanceOfSnippets.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/JavaReadNode.java
diffstat 8 files changed, 39 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java	Tue Nov 11 15:15:19 2014 +0100
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeClass.java	Tue Nov 11 12:45:26 2014 -0800
@@ -170,6 +170,7 @@
         startGVNNumber = clazz.hashCode();
 
         NodeInfo info = getAnnotationTimed(clazz, NodeInfo.class);
+        assert info != null : "Missing NodeInfo annotation on " + clazz;
         this.nameTemplate = info.nameTemplate();
 
         try (TimerCloseable t1 = Init_AllowedUsages.start()) {
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantReflectionProvider.java	Tue Nov 11 15:15:19 2014 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantReflectionProvider.java	Tue Nov 11 12:45:26 2014 -0800
@@ -29,6 +29,7 @@
 
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.compiler.common.*;
+import com.oracle.graal.graph.*;
 import com.oracle.graal.hotspot.*;
 
 /**
@@ -114,6 +115,10 @@
                     Object metaspaceObject = HotSpotMetaspaceConstantImpl.getMetaspaceObject(baseConstant);
                     if (metaspaceObject instanceof HotSpotResolvedObjectTypeImpl && initialDisplacement == runtime.getConfig().classMirrorOffset) {
                         o = ((HotSpotResolvedObjectTypeImpl) metaspaceObject).mirror();
+                    } else if (metaspaceObject instanceof HotSpotResolvedObjectTypeImpl && initialDisplacement == runtime.getConfig().arrayKlassComponentMirrorOffset) {
+                        o = ((HotSpotResolvedObjectTypeImpl) metaspaceObject).mirror().getComponentType();
+                    } else if (metaspaceObject instanceof HotSpotResolvedObjectTypeImpl && initialDisplacement == runtime.getConfig().instanceKlassNodeClassOffset) {
+                        o = NodeClass.get(((HotSpotResolvedObjectTypeImpl) metaspaceObject).mirror());
                     } else {
                         throw GraalInternalError.shouldNotReachHere();
                     }
@@ -176,6 +181,9 @@
                 assert bits == 64 && kind == Kind.Long;
                 return HotSpotMetaspaceConstantImpl.forMetaspaceObject(kind, rawValue, HotSpotResolvedObjectTypeImpl.fromMetaspaceKlass(rawValue), false);
             }
+        } else if (displacement == config().klassOffset && base instanceof Class) {
+            long value = unsafe.getLong(base, displacement);
+            return HotSpotMetaspaceConstantImpl.forMetaspaceObject(kind, value, runtime.getHostProviders().getMetaAccess().lookupJavaType((Class<?>) base), false);
         } else {
             switch (kind) {
                 case Int:
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaFieldImpl.java	Tue Nov 11 15:15:19 2014 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaFieldImpl.java	Tue Nov 11 12:45:26 2014 -0800
@@ -32,6 +32,7 @@
 
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.compiler.common.*;
+import com.oracle.graal.graph.*;
 import com.oracle.graal.hotspot.*;
 import com.oracle.graal.options.*;
 import com.oracle.graal.replacements.*;
@@ -274,7 +275,7 @@
     }
 
     private static boolean assumeNonStaticFinalFieldsAsFinal(Class<?> clazz) {
-        return clazz == SnippetCounter.class;
+        return clazz == SnippetCounter.class || clazz == NodeClass.class;
     }
 
     /**
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ClassSubstitutions.java	Tue Nov 11 15:15:19 2014 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ClassSubstitutions.java	Tue Nov 11 12:45:26 2014 -0800
@@ -42,7 +42,7 @@
     @MacroSubstitution(macro = ClassGetModifiersNode.class, isStatic = false)
     @MethodSubstitution(isStatic = false)
     public static int getModifiers(final Class<?> thisObj) {
-        Word klass = loadWordFromObject(thisObj, klassOffset());
+        Word klass = loadWordFromObject(thisObj, klassOffset(), CLASS_KLASS_LOCATION);
         if (klass.equal(0)) {
             // Class for primitive type
             return Modifier.ABSTRACT | Modifier.FINAL | Modifier.PUBLIC;
@@ -54,7 +54,7 @@
     @MacroSubstitution(macro = ClassIsInterfaceNode.class, isStatic = false)
     @MethodSubstitution(isStatic = false)
     public static boolean isInterface(final Class<?> thisObj) {
-        Word klass = loadWordFromObject(thisObj, klassOffset());
+        Word klass = loadWordFromObject(thisObj, klassOffset(), CLASS_KLASS_LOCATION);
         if (klass.equal(0)) {
             return false;
         } else {
@@ -66,7 +66,7 @@
     @MacroSubstitution(macro = ClassIsArrayNode.class, isStatic = false)
     @MethodSubstitution(isStatic = false)
     public static boolean isArray(final Class<?> thisObj) {
-        Word klass = loadWordFromObject(thisObj, klassOffset());
+        Word klass = loadWordFromObject(thisObj, klassOffset(), CLASS_KLASS_LOCATION);
         if (klass.equal(0)) {
             return false;
         } else {
@@ -77,7 +77,7 @@
     @MacroSubstitution(macro = ClassIsPrimitiveNode.class, isStatic = false)
     @MethodSubstitution(isStatic = false)
     public static boolean isPrimitive(final Class<?> thisObj) {
-        Word klass = loadWordFromObject(thisObj, klassOffset());
+        Word klass = loadWordFromObject(thisObj, klassOffset(), CLASS_KLASS_LOCATION);
         return klass.equal(0);
     }
 
@@ -87,7 +87,7 @@
     @MacroSubstitution(macro = ClassGetSuperclassNode.class, isStatic = false)
     @MethodSubstitution(isStatic = false)
     public static Class<?> getSuperclass(final Class<?> thisObj) {
-        Word klass = loadWordFromObject(thisObj, klassOffset());
+        Word klass = loadWordFromObject(thisObj, klassOffset(), CLASS_KLASS_LOCATION);
         if (klass.notEqual(0)) {
             int accessFlags = klass.readInt(klassAccessFlagsOffset(), KLASS_ACCESS_FLAGS_LOCATION);
             if ((accessFlags & Modifier.INTERFACE) == 0) {
@@ -109,7 +109,7 @@
     @MacroSubstitution(macro = ClassGetComponentTypeNode.class, isStatic = false)
     @MethodSubstitution(isStatic = false)
     public static Class<?> getComponentType(final Class<?> thisObj) {
-        Word klass = loadWordFromObject(thisObj, klassOffset());
+        Word klass = loadWordFromObject(thisObj, klassOffset(), CLASS_KLASS_LOCATION);
         if (klass.notEqual(0)) {
             if (klassIsArray(klass)) {
                 return piCastExactNonNull(klass.readObject(arrayKlassComponentMirrorOffset(), ARRAY_KLASS_COMPONENT_MIRROR), Class.class);
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java	Tue Nov 11 15:15:19 2014 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java	Tue Nov 11 12:45:26 2014 -0800
@@ -493,7 +493,7 @@
         return config().secondarySuperCacheOffset;
     }
 
-    public static final LocationIdentity SECONDARY_SUPERS_LOCATION = NamedLocationIdentity.mutable("SecondarySupers");
+    public static final LocationIdentity SECONDARY_SUPERS_LOCATION = NamedLocationIdentity.immutable("SecondarySupers");
 
     @Fold
     public static int secondarySupersOffset() {
@@ -559,6 +559,11 @@
         return loadWordFromObjectIntrinsic(object, offset, getWordKind(), LocationIdentity.ANY_LOCATION);
     }
 
+    public static Word loadWordFromObject(Object object, int offset, LocationIdentity identity) {
+        ReplacementsUtil.staticAssert(offset != hubOffset(), "Use loadHubIntrinsic instead of loadWordFromObject");
+        return loadWordFromObjectIntrinsic(object, offset, getWordKind(), identity);
+    }
+
     /**
      * Reads the value of a given register.
      *
@@ -630,17 +635,21 @@
         return config().klassModifierFlagsOffset;
     }
 
+    public static final LocationIdentity CLASS_KLASS_LOCATION = NamedLocationIdentity.immutable("Class._klass");
+
     @Fold
     public static int klassOffset() {
         return config().klassOffset;
     }
 
+    public static final LocationIdentity CLASS_ARRAY_KLASS_LOCATION = NamedLocationIdentity.immutable("Class._array_klass");
+
     @Fold
     public static int arrayKlassOffset() {
         return config().arrayKlassOffset;
     }
 
-    public static final LocationIdentity KLASS_NODE_CLASS = NamedLocationIdentity.mutable("KlassNodeClass");
+    public static final LocationIdentity KLASS_NODE_CLASS = NamedLocationIdentity.immutable("KlassNodeClass");
 
     @Fold
     public static int instanceKlassNodeClassOffset() {
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/InstanceOfSnippets.java	Tue Nov 11 15:15:19 2014 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/InstanceOfSnippets.java	Tue Nov 11 12:45:26 2014 -0800
@@ -186,7 +186,7 @@
             return falseValue;
         }
         GuardingNode anchorNode = SnippetAnchorNode.anchor();
-        Word hub = loadWordFromObject(mirror, klassOffset());
+        Word hub = loadWordFromObject(mirror, klassOffset(), CLASS_KLASS_LOCATION);
         Word objectHub = loadHubIntrinsic(object, getWordKind(), anchorNode);
         if (hub.equal(0) || !checkUnknownSubType(hub, objectHub)) {
             return falseValue;
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java	Tue Nov 11 15:15:19 2014 +0100
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java	Tue Nov 11 12:45:26 2014 -0800
@@ -151,7 +151,7 @@
 
     @Snippet
     public static Object allocateInstanceDynamic(Class<?> type, @ConstantParameter boolean fillContents, @ConstantParameter Register threadRegister, @ConstantParameter String typeContext) {
-        Word hub = loadWordFromObject(type, klassOffset());
+        Word hub = loadWordFromObject(type, klassOffset(), CLASS_KLASS_LOCATION);
         if (probability(FAST_PATH_PROBABILITY, !hub.equal(Word.zero()))) {
             if (probability(FAST_PATH_PROBABILITY, isInstanceKlassFullyInitialized(hub))) {
                 int layoutHelper = readLayoutHelper(hub);
@@ -218,7 +218,7 @@
 
     @Snippet
     public static Object allocateArrayDynamic(Class<?> elementType, int length, @ConstantParameter boolean fillContents, @ConstantParameter Register threadRegister) {
-        Word hub = loadWordFromObject(elementType, arrayKlassOffset());
+        Word hub = loadWordFromObject(elementType, arrayKlassOffset(), CLASS_ARRAY_KLASS_LOCATION);
         if (hub.equal(Word.zero()) || !belowThan(length, MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH)) {
             return dynamicNewArrayStub(DYNAMIC_NEW_ARRAY, elementType, length);
         }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/JavaReadNode.java	Tue Nov 11 15:15:19 2014 +0100
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/JavaReadNode.java	Tue Nov 11 12:45:26 2014 -0800
@@ -23,6 +23,8 @@
 package com.oracle.graal.nodes.extended;
 
 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.spi.*;
@@ -32,7 +34,7 @@
  * barriers, implicit conversions and optionally oop uncompression.
  */
 @NodeInfo
-public class JavaReadNode extends FixedAccessNode implements Lowerable, GuardingNode {
+public class JavaReadNode extends FixedAccessNode implements Lowerable, GuardingNode, Canonicalizable {
 
     protected final boolean compressible;
 
@@ -56,4 +58,9 @@
     public boolean isCompressible() {
         return compressible;
     }
+
+    @Override
+    public Node canonical(CanonicalizerTool tool) {
+        return ReadNode.canonicalizeRead(this, location(), object(), tool);
+    }
 }